| 1 | initial version |
The max function in Sage is the Python built-in function
max,
which relies on comparisons.
This stackoverflow answer
explains roughly how it works. To compute max(a, b),
a.b > a, change the result to b.In step 2, comparing objects of different types is tricky.
One would expect objects representing real numbers to compare well even if they are of different types. In your example, this fails.
As a practical suggestion: to compare numbers using < and >, first
take them to a common parent where such comparison is defined properly.
In your case, if a = Integer(0) and b = mpmath.mpf(-1), you could
compare RDF(a)and RDF(b) instead of comparing a and b.
(Note: RDF stands for "real double field", a fast and reliable approximation
to the field of real numbers, recommended in many contexts.)
sage: import mpmath
sage: a, b = Integer(0), mpmath.mpf(-1)
sage: max(a, b)
0
sage: max(b, a)
mpf('-1.0')
sage: max(RDF(a), RDF(b))
0.0
sage: max(RDF(b), RDF(a))
0.0
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.