Nemocas / AbstractAlgebra.jl

Generic abstract algebra functionality in pure Julia (no C dependencies)
https://nemocas.github.io/AbstractAlgebra.jl/dev/index.html
Other
172 stars 63 forks source link

Move `src/Infinity.jl` (and tests) from Nemo to AbstractAlgebra #1841

Open fingolfin opened 1 month ago

nsajko commented 3 weeks ago

Another package that features a singleton real infinity is Infinities.jl.

IMO it'd be nice to extract Nemo's src/Infinity.jl into a new package, then have all mentioned packages depend on it, for greater compatibility within the ecosystem. This would ensure the comparisons and hashing all are correct across packages.

cc @dlfivefifty @jishnub

There's one thing that I'd say needs to be changed in src/Infinity.jl, the supertype should be Real instead of Any:

https://github.com/Nemocas/Nemo.jl/blob/6848ca3c61abd6aa67d55902b826a2b404587765/src/Infinity.jl#L9-L10

While mathematically an infinity isn't a real number, in the context of the Number type hierarchy Real should supertype the infinities, because the positive infinity is defined as being equal to Inf, which is Float64, which subtypes Real, similarly with the negative infinity type. This would also be necessary for compatibility with Infinities.jl, I guess.

I guess the new package would most appropriately live under JuliaMath?

Thoughts?

nsajko commented 3 weeks ago

Proposals for package name:

dlfivefifty commented 3 weeks ago

While mathematically an infinity isn't a real number

As you mentioned: Julia types are not the same as mathematical sets. I think they are best thought of as encoding an "interface" and anything that follows the rules of the interface can be subtype. Eg. in ForwardDiff.jl we also have Dual <: Real which of course is mathematically nonsense but makes perfect sense (and is essential) in terms of the interface.

I don't exactly remember why we defined Infinity <: Real instead of Infinity <: Number or indeed Infinity <: Any. This can probably be changed without any serious side-effects.

fingolfin commented 3 weeks ago

No we have no interest in that. It just makes maintenance harder for us with no real benefit. As you pointed out, there is already a package for infinites that people who don't want to use AA/Nemo/Oscar can use, and which deliberately are not using.

In particular our infinity is not a subtype of Real. That's not a bug, it's a feature.

"Consistent hashing" of infinities to me also sounds like a red herring, not a useful feature in itself.

nsajko commented 3 weeks ago

Sorry, I just checked, and equality, and I guess also other comparisons and hashing, are already correct.