Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: algebra #135

Merged
merged 16 commits into from
Jul 31, 2024
Merged

feat: algebra #135

merged 16 commits into from
Jul 31, 2024

Conversation

lonerapier
Copy link
Collaborator

It changes the following:

  • FiniteGroup trait
  • MultiplicativePrimeGroup struct
  • CurveGroup trait
  • refactor ECDSA to generic group

@lonerapier lonerapier changed the title Feat/groups feat: group trait Jul 24, 2024
Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments, nothing major.

Given those comments and the general structure, may I suggest the following refactor and generalization?

Consider creating an algebra module with:

  • group
  • ring
  • field
    As submodules. (You can leave ring as TODO).

Now, it is probably reasonable to then define the abstract notion of group and field and then use these as super traits for the more refined items such as FiniteGroup, FiniteCyclicGroup, FiniteField, etc.

src/field/group.rs Outdated Show resolved Hide resolved
src/field/group.rs Outdated Show resolved Hide resolved
@lonerapier
Copy link
Collaborator Author

@Autoparallel Thanks for the review.

  • refactored as algebra module with separate submodules for group, field, ring (in future).
  • Tried adding Group, Field trait separately, but we need function overriding in derived traits because operation in Group and FiniteGroup can be done in different ways.
    • Is there any other way that we can define Group trait's operation and FiniteGroup trait's operation separately?

@Autoparallel
Copy link
Contributor

@lonerapier let me take a look.

One thing we could also consider is making the ring/field + op be a AbelianGroup. Food for thought.

Give me a sec to go look through this.

Comment on lines 5 to 10
1. Closure: $a\oplus b=c\in G$
2. Associative: $(a\oplus b)\oplus c = a\oplus(b\oplus c)$
3. Existence of Identity element: $a\oplus 0 = 0\oplus a = a$
4. Existence of inverse element for every element of the set: $a\oplus b=0$
5. Commutativity: Groups which satisfy an additional property: *commutativity* on the set of
elements are known as **Abelian groups**.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nitpick, so don't feel compelled to change this (i love your documentation always) but I have a disdain for the $\oplus$ as a group op. Why?

$\oplus$ is used, usually, as a direct sum or coproduct so it is a bit weird. It also carries connotation of commutivity which is usually not guaranteed in groups! (most groups are not commutative)

Instead consider just using concatenation: $ab = c$, $(ab)c=a(bc)$, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to learn more abstract algebra :)

I think concatenation is mostly substituted as multiplication, at least in my head, so might create confusion. does using \cdot make more sense?

Found it used in Ben Lynn's notes as well: https://crypto.stanford.edu/pbc/notes/group/group.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified it to $\cdot$, does this work?

if not can just simplify it to concatenation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$\cdot$ is fine. For a group, we just don't want to convey the operation is + as that implies commutativity in math people's heads. Concatenation is actually really general as you are thinking of group elements as strings of chars with rules in how to reduce the strings into other strings. Strings of minimal length given the reduction rules are considered canonical representatives (this, at least, is the way group presentations define a group). All groups can be given via a presentation, albeit that they may not be finite presentations (that is really not a problem for us lol)

Comment on lines 13 to 16
1. Abelian group under $\oplus$.
2. Monoid under $\cdot$.
3. Distributive with respect to $\oplus$.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again here $\oplus$ if you care to change :)

2. Monoid under $\cdot$.
3. Distributive with respect to $\oplus$.

[Finite fields](https://en.wikipedia.org/wiki/Finite_field) are instrumental in cryptographic systems.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a touch here about how fields exist as special instances of rings (where there is division and no zero-divisors).

Adding a commented TODO is also okay.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, will change it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@lonerapier lonerapier changed the title feat: group trait feat: algebra Jul 31, 2024
@lonerapier
Copy link
Collaborator Author

One thing we could also consider is making the ring/field + op be a AbelianGroup. Food for thought.

Regarding this suggestion, I can't find a way to add this without complicating the traits and structs more

Like it wouldn't be easy for a beginner to implement 5 traits just to have a PrimeField implementation

@Autoparallel
Copy link
Contributor

Like it wouldn't be easy for a beginner to implement 5 traits just to have a PrimeField implementation

That's true... it would introduce having some wrapper types and what not. The only benefit it would give is that if you did something like:

let element: impl FiniteField = ...;
let (element as impl AbelianGroup) + ... 

but that's probably not worth it.

Another option is something like

trait FiniteField {
    type Monoid: ...
    type AbelianGroup: ...
    ...
}

but then I think we are hitting abstraction for the sake of abstraction.

You're right, let's not make the implementation needs abusive to beginners.

Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename here is misleading, but if you are wanting to learn more abstract algebra, every finite group is a subgroup of a permutation (symmetric) group and the dihedral group is an especially nice subgroup of it which is implied by Lagrange's theorem

Inside of the dihedral group is then two cyclic groups. One of order n, and one of order 2. Also implied by lagrange's theorem.

If you don't implement those (don't have to at all), i'd suggest changing the filename :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though i guess in this case D6 is S3

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have changed to symmetric_group


/// Defines a group with commutative operation: `a·b=b·a`
pub trait AbelianGroup: Group {
/// Returns whether the group is an abelian group
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little misleading. This returns true if a pair of elements commutes.

Sadly an (almost) impossible task for Rust to handle is that there exists a proof that your impl of this trait is actually abelian (rip)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, IDK why I put it this way. Have changed this to an assertion

@lonerapier
Copy link
Collaborator Author

That's true... it would introduce having some wrapper types and what not.

Maybe we can implement this as an example demonstration with Ring implementation. Like showing a ring with inverse and commutativity forms a field, and then comparing it with the actual Field implementation.

@lonerapier lonerapier merged commit 3fd764b into pluto:main Jul 31, 2024
5 checks passed
@lonerapier lonerapier deleted the feat/groups branch July 31, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants