Skip to content

Add hash function for type AlgebraicNumber#41

Merged
fkastner merged 1 commit intoanj1:masterfrom
TZdyrski:master
Dec 11, 2025
Merged

Add hash function for type AlgebraicNumber#41
fkastner merged 1 commit intoanj1:masterfrom
TZdyrski:master

Conversation

@TZdyrski
Copy link
Contributor

@TZdyrski TZdyrski commented Dec 11, 2025

Add a hash function for AlgebraicNumber; it is required that any custom type defining its own == (as AlgebraicNumber does) also define its own hash so that isequal(an1, an2) imples hash(an1) == hash(an2).

This also fixes Base functions like unique; previously, unique([AlgebraicNumber(1), AlgebraicNumber(1)]) produces two elements when it should only produce one (since unique internally uses hash). Now, it correctly returns only a single element.

I only hashed the coefficients (appropriately scaled); this does satisfy the requirement that isequal(an1, an2) imples hash(an1) == hash(an2). However, because hash doesn't use apprx or prec, different AlgebraicNumbers can result in the same hash.

@coveralls
Copy link

Coverage Status

coverage: 92.531% (+0.4%) from 92.149%
when pulling 9068845 on TZdyrski:master
into b623480 on anj1:master.

@fkastner
Copy link
Collaborator

Thank you for this addition!

@fkastner fkastner merged commit 91d8a56 into anj1:master Dec 11, 2025
3 checks passed
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.

4 participants