On Mon, May 3, 2021 at 9:46 AM Ilia <ilia.smi...@orange.fr> wrote: > > Thanks for the quick fix! I still have a question about the proposed patch: > > Suppose we have two algebraic numbers x and y whose minimal polynomials are > distinct, but whose values are very close together, e.g. x = > AA(1+2*2^(-1000))^(1/2); y = AA(1+3*2^(-1000))^(1/3). This guarantees that x > and y are distinct, but does not tell the sign of x-y yet. With the proposed > patch, sign(x-y) will try to exactify x-y, which will be very long. Is there > any reason not simply add _more_precision() to both until the intervals > separate (as I suggested above)?
How does one know where to stop? Or you'd want to let it run out of memory? practically speaking, these computations should be done with a much more efficient RBF: sage: x = AA(1+2*2^(-1000))^(1/2); y = AA(1+3*2^(-1000))^(1/3) sage: R=RealBallField(10000) sage: R(y)>R(x) False sage: R(y)<R(x) True note that if precision is insufficient, both tests will return False sage: R=RealBallField(1000) sage: R(y)>R(x) False sage: R(y)<R(x) False > > Best > -- > Ilia > > On Monday, May 3, 2021 at 5:28:46 AM UTC+2 Travis Scrimshaw wrote: >> >> Hi Ilia, >> It would be possible to improve the QQbar element sign() method to check >> the case when they have the same minimum polynomials. See >> https://trac.sagemath.org/ticket/31767 for a proposal. >> >> Best, >> Travis >> >> >> On Thursday, April 29, 2021 at 9:43:49 PM UTC+10 Ilia wrote: >>> >>> >>> 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/95976c4e-67e9-4011-a188-962c66fa75efn%40googlegroups.com. -- 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/CAAWYfq0%3D282odMHpgPkkr390D%3DJyK_YuPqs089FvqJgtr5_ppA%40mail.gmail.com.