dimforge / dimforge/alga

Instructions incomplete/incorrect on how to define an additive group

Open
#63 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
201
Forks
40
PR merge metrics
No merged PRs in 30d

Description

If I define an additive group according to the instructions in the documentation, it still will not satisfy the AdditiveGroup trait, and I can't do addition with it (e.g. `element + element`).

```
use alga::general::{AbstractMagma, Additive, AdditiveGroup, Identity, Inverse}; // 0.7.2
use alga_derive::Alga; // 0.7.1

#[derive(Alga, Clone, Copy, PartialEq, Debug)]
#[alga_traits(Group(Additive))]
pub struct TrivialGroup;

impl AbstractMagma for TrivialGroup {
fn operate(&self, _right: &Self) -> Self {
TrivialGroup {}
}
}

impl Identity for TrivialGroup {
fn identity() -> Self {
TrivialGroup {}
}
}

impl Inverse for TrivialGroup {
fn inverse(&self) -> Self {
TrivialGroup {}
}
}

struct Bar {
t: T,
}

fn main() {
let foo = Bar:: { t: TrivialGroup {} };
}
```
Gives the error:
```
error[E0277]: the trait bound `TrivialGroup: num_traits::identities::Zero` is not satisfied
--> src/main.rs:31:15
|
31 | let foo = Bar:: { t: TrivialGroup {} };
| ^^^^^^^^^^^^^^^^^^^ the trait `num_traits::identities::Zero` is not implemented for `TrivialGroup`
|
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
--> src/main.rs:26:1
|
26 | struct Bar {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `TrivialGroup: std::ops::Neg` is not satisfied
--> src/main.rs:31:15
|
31 | let foo = Bar:: { t: TrivialGroup {} };
| ^^^^^^^^^^^^^^^^^^^ the trait `std::ops::Neg` is not implemented for `TrivialGroup`
|
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedNeg` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
--> src/main.rs:26:1
|
26 | struct Bar {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot subtract `TrivialGroup` from `TrivialGroup`
--> src/main.rs:31:15
|
31 | let foo = Bar:: { t: TrivialGroup {} };
| ^^^^^^^^^^^^^^^^^^^ no implementation for `TrivialGroup - TrivialGroup`
|
= help: the trait `std::ops::Sub` is not implemented for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedSub` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveQuasigroup` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
--> src/main.rs:26:1
|
26 | struct Bar {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot subtract-assign `TrivialGroup` from `TrivialGroup`
--> src/main.rs:31:15
|
31 | let foo = Bar:: { t: TrivialGroup {} };
| ^^^^^^^^^^^^^^^^^^^ no implementation for `TrivialGroup -= TrivialGroup`
|
= help: the trait `std::ops::SubAssign` is not implemented for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedSub` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveQuasigroup` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveLoop` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
--> src/main.rs:26:1
|
26 | struct Bar {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: cannot add-assign `TrivialGroup` to `TrivialGroup`
--> src/main.rs:31:15
|
31 | let foo = Bar:: { t: TrivialGroup {} };
| ^^^^^^^^^^^^^^^^^^^ no implementation for `TrivialGroup += TrivialGroup`
|
= help: the trait `std::ops::AddAssign` is not implemented for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::ClosedAdd` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveSemigroup` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveMonoid` for `TrivialGroup`
= note: required because of the requirements on the impl of `_ALGA_DERIVE_TrivialGroup::_alga::general::AdditiveGroup` for `TrivialGroup`
note: required by `Bar`
--> src/main.rs:26:1
|
26 | struct Bar {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

See also: https://stackoverflow.com/questions/54303935/defining-additivegroup-with-alga-crate

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.