Thanks for the answers.

I didn't realize this whole issue was this involved. It's certainly 
interesting.

For now I think there is nothing wrong with registering 
`NumberFieldElement` as `numbers.Numbers`, see 
https://trac.sagemath.org/ticket/32206.

Jonathan


mathzeta2 schrieb am Donnerstag, 15. Juli 2021 um 23:58:45 UTC+2:

> On 15/07/2021 22:11, William Stein wrote:
> > On Thu, Jul 15, 2021 at 11:05 AM William Stein <[email protected]> wrote:
> >>
> >> On Thu, Jul 15, 2021 at 9:13 AM Nils Bruin <[email protected]> wrote:
> >>>
> >>> Following up: while sage's "RationalNumber" is indeed a 
> numbers.Rational according to "isinstance", it does not actually adhere to 
> the stated API: "numerator" and "denominator" are supposed to be 
> properties, but in sage they are methods. So even in places where we are 
> trying to fit into "Number" we are already failing. Changing the way that 
> "numerator" and "denominator" behave would break a *LOT* of sage code.
> >>
> >> It's 100% my fault that numerator and denominator are function calls
> >> instead of properties. Here's why I made that choice, both for
> >> rational numbers and for a lot of other things. The reason is that I
> >> watched lots of grad students struggling to use Sage/Python around
> >> 2006 (e.g., at Arizona Winter School, in classes, etc.), and having
> >> two different concepts -- methods *and* attributes -- with no easy way
> >> to know which is which, just made things much more difficult for
> >> people. People would do things like:
> >>
> >> sage: A = matrix(...)
> >> sage: A.det
> >> <built-in method det of
> >> sage.matrix.matrix_integer_dense.Matrix_integer_dense object at
> >> 0x7f7fca0c2ca0>
> >>
> >> and be like "WTF?", and I would explain "A.det is a function. You
> >> have to call it.", and they woud then do
> >>
> >> sage: A.det()
> >> number
> >>
> >> and think "OK, sage makes sense." If basically at random half of the
> >> things listed in tab completion needed parens after them and half
> >> didn't, that would confuse the hell out of my poor potential users.
> >> And with Sage there is really no clear way to decide whether or not
> >> something should be a property or a method, since it's really a
> >> function of "how hard is it to compute? are there different inputs to
> >> computing it?" The answer to the second question is unknown when you
> >> write the thing, e.g., an input could be the algorithm or whether
> >> proof is True. The thing that really convinced me was that
> >> "A.det?" would give help on a number (not the det function) in IPython
> >> back then at least -- well definitely "help(A.det)" would "not work"
> >> at all in a helpful way.
> >>
> >> Please keep in mind that I made this choice over 15 years ago when
> >> Sage had only a few users, and it would today have no users if I
> >> hadn't made many design choices based on "what will confuse new users
> >> less in 2005"...
> >>
> >> -- William
>
> For one more attempt by Jeroen Demeyer at solving this issue, please see
>
> https://discuss.python.org/t/pep-3141-ratio-instead-of-numerator-denominator/2037
> I find the history of this topic quiet interesting.
>
> Using methods for all public API of Sage still seems to me as the better 
> choice. The reasons given above for this (no need to guess if 
> parentheses are required and the expectation that properties are very 
> efficient) are still relevant today.
>
> In addition, it is possible that in the future numerator/denominator 
> might get new arguments (e.g. reduce, canonicalize, or normalize as in 
> SR). One more reason is that the numerator/denominator methods are used 
> for more complicated mathematical objects in Sage, where calling them 
> with arguments is sensible. In the python-ideas discussion Vincent 
> Delecroix mentions that also real and imag methods/properties have the 
> same problem, like calling `1j.real` in Sage compared to Python.
>
> Regards,
> TB
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/bb4d13d1-4607-4bf2-b779-c1a75741224fn%40googlegroups.com.

Reply via email to