Hello everyone,

(This is my first post on sage-devel. I hope I will not break any unwritten 
rules, please be forgiving if I do!)

When I run the following code:

x1 = AA(2^(1/100))
x2 = AA(2^(1/100))
x1 == x2

Sage quickly and correctly replies "True". Also,

1/(x1-x2)

quickly raises a ZeroDivisionError. So far, so good. But now try running

sign(x1-x2)

Sage does not seem to terminate in any reasonable time.

After looking at the code, it turns out that both the _richcmp_ method 
called by "x1 == x2", and the __bool__() method (which checks nonzeroness) 
called by "1/(x1-x2)", include a check that makes them realize that x1 and 
x2 are equal, hence obtain the result. For __bool__(), this is quite clever 
as it involves extracting the _left and _right parts from an ANBinaryExpr 
representing a sum or difference.

But inexplicably, the sign() method does not include a similar check, and 
(as traceback shows) tries instead to exactify x1-x2 which takes forever. 
Wouldn't it be an improvement if it did? In fact, I think it would make 
sense for the sign() method to call __bool__() first. This way, if it 
returns False (as in this case), we have the result immediately; and if it 
returns True, we can simply repeatedly add _more_precision() until we can 
resolve the number from zero (with the guarantee that this will eventually 
terminate). Do you see any reason not to do this?

Also, I wonder why exactification even takes so long in this case. 
Traceback shows that Sage tries to take a union of the two fields, which it 
defers to PARI, which then stalls. But even admitting that Sage fails to 
immediately see equality of the elements themselves, presumably it should 
at least detect equality of the fields they generate; and it should not 
take long to unify a field (even a complicated one) with itself, should it?

My configuration: SageMath version 9.1, running on Ubuntu 18.04.3 LTS 
(64-bit).

Best
-- 
Ilia

-- 
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 sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/229c9d03-e607-40c9-bba7-6ff3873f1cf6n%40googlegroups.com.

Reply via email to