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

Add Ord trait to Fe32 (derived) #186

Closed
wants to merge 1 commit into from

Conversation

optout21
Copy link
Contributor

@optout21 optout21 commented Jul 16, 2024

See #187 .
Add derived Ord trait to Fe32, and tests.
Implementation is trivial (derived), but this can be useful.

@apoelstra
Copy link
Member

We have a crate ordered with a trait ArbitraryOrd for things like this where it would be "useful" to have an ordering, but there isn't any (or there are multiple) sensible orderings for the type.

I'd prefer you add an optional dependency on that, which implements the ArbitraryOrd trait.

Though cc @clarkmoody to see what he thinks.

In any case, I do not think that Fe32 should implement the Ord trait because it is not an ordered field.

@optout21
Copy link
Contributor Author

Indeed, ordering may be confusing, as the char order is different than the numerical.
The ordered crate workaround looks useful.
Closing.

@optout21 optout21 closed this Jul 16, 2024
@optout21
Copy link
Contributor Author

A note just for completeness:

In version 0.9.1 the type u5 (the predecessor of Fe32 before the rewrite) did support Ord, in the default way, based on the underlying byte value.

#[derive(PartialEq, Eq, Debug, Copy, Clone, Default, PartialOrd, Ord, Hash)]
pub struct u5(u8);

@apoelstra
Copy link
Member

Yes, but u5 was intended to be analagous to u8, u16, etc., which pretend to be integers even though they are actually integers mod 2^n. We never took a principled approach to its API but if we did it would have implemented arithmetic ops in the "ordinary" way where they behaved like integers except in cases of overflow and underflow. We manually simulated field arithmetic using this type by using bit operations.

Fe32 directly represents a field element in an unordered field, where there is no "overflow" or "underflow", and where no matter how you defined an ordering, x + 1 > x could be true at most half the time, etc.

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