-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Next steps/guidelines for AbstractIrrational #26550
Comments
On the one hand, it seems like unnecessary purism to restrict However, I think that the default methods like |
On the other hand, it is also perfectly reasonable to give an error for a √4 "irrational" value. The main purpose of irrational types is to enter irrational constants, and there is no reason anyone should ever need this for √4, since they can always use the exact literal |
My understanding is that most irrational types should define: ==(::MyIrrational, ::MyIrrational)
hash(x::MyIrrational, h::UInt)
convert(::Type{F}, x::MyIrrational) # for at least F in {BigFloat,Float32,Float64} and probably also If |
Thanks, that's a useful definition of the interface. My use case is returning exact Clebsch Gordan coefficients, which is the square root of a rational number. I thought |
No, in that use-case I think |
I think it's best to focus concretely on the intended use cases. So far, those mentioned mentioned include rational multiples or roots of an Because I believe types that can also represent rational values will be the most common use case for Other thoughtsIt seems we agree that it would be undesirable for My main concern can be summarized as follows: I believe many of the methods should not have been generalized to
|
Ping @stevengj (any thoughts on my post above?) |
I think that if you subtype |
On this we agree. However, the some of the fallback methods are incorrect for all potential use cases mentioned to date (other than for
Very good point. |
Could we make a new type called |
I would prefer keeping the interface here as small as possible and defer more elaborate symbolic manipulations to packages. |
The reason to want a |
I agree with @garrison that I would think that most useful subtypes of That's just my 2 cents, I don't actually have a strong opinion as long as it is clear what needs to be implemented. |
I would like to resay my point that if we want to allow these numbers to sure rationals, we really should not have the type be named AbstractIrational. We can still fix this non breaking fassion by making AbstractIrational a subtype of a new symbolic type. Having 2 be a valid irrational, seems like a bad idea |
* document AbstractIrrational interface Fixes #26550. * note hash
I am very excited about
AbstractIrrational
and am hoping to understand the intended guidelines for implementing subtypes of it. The abstract type itself was introduced by @stevengj in #24245, e.g. for representing exact multiples of π. @Jutho also mentioned a use case for square roots of rational numbers.One concern/confusion I have is that in the both cases, not all possible values are actually irrational. For instance, 0π is rational, as is √4. Are types that derive from
AbstractIrrational
supposed to error when such values are given?In my (tentative) opinion, it will be much more elegant for these types to allow any multiple of π, including 0π, as well as the square root of any rational number, including perfect squares. However, this suggests that a value represented by
AbstractIrrational
need not actually be irrational, and thus some of the overloads introduced in #24245 are not true in general: for instance, it is claimed that==(x::AbstractIrrational, y::Real) = false
because "Irrationals, by definition, can't have a finite representation equal them exactly." Other comparison functions, as well asiszero
andisone
, have similar issues in general.Assuming it is agreed that even rational values can be represented by an
AbstractIrrational
, one path forward is to narrow the definition of some of the above methods to be only forIrrational
rather thanAbstractIrrational
. And in any case, some documentation/guidelines on what methods somebody should overload for a newAbstractIrrational
type would be very helpful.The text was updated successfully, but these errors were encountered: