>>> tan(10**100 + Ball(0, 1, -60))
0.40123196199081435418575434365329495832387026112924406831944154~161
>>> x = B("2.5000000~1")
>>> exp(log(x)*x) # That is x**x
9.88211769~216
>>> exp(log(x)*exp(log(x)*x)) # That is x**(x**x)
8560.3200~297
>>> exp(log(x)*exp(log(x)*exp(log(x)*x))) # That is x**(x**(x**x))
3.1176~885e3406
>>> x = B("2.5" + "0"*3500 + "~1")
>>> y = log(x)
>>> z = exp(y*x) # x**x
>>> z = exp(y*z) # x**(x**x)
>>> z = exp(y*z) # x**(x**(x**x))
>>> z - floor(z)
0.2650151911484744424~657
>>> for i in range(1, 10):
... Ball.radius_precision = i
... print(i, ":", sqrt(B("0.111111111111~1")))
...
1 : 0.4~3
2 : 0.33333333336~13
3 : 0.33333333333325~349
4 : 0.333333333333175~1716
5 : 0.3333333333331677~15229
6 : 0.33333333333316676~150243
7 : 0.333333333333166669~1500260
8 : 0.3333333333331666673~15000277
9 : 0.33333333333316666669~150000289
def _taylor_sqrt1m(x):
...
# End of 'while' loop
print("(", m//2, " terms:)", sep="", end=" ")
return result
>>> for i in range(1, 10):
... Ball.radius_precision = i
... print(i, ":", sqrt(B("0.111111111111~1")))
...
(8 terms:) 1 : 0.4~3
(152 terms:) 2 : 0.33333333336~13
(201 terms:) 3 : 0.33333333333325~349
(217 terms:) 4 : 0.333333333333175~1716
(236 terms:) 5 : 0.3333333333331677~15229
(256 terms:) 6 : 0.33333333333316676~150243
(274 terms:) 7 : 0.333333333333166669~1500260
(292 terms:) 8 : 0.3333333333331666673~15000277
(312 terms:) 9 : 0.33333333333316666669~150000289
quickfur wrote:There's a theorem in algebra that you can perform exact arithmetic with algebraic numbers of degree n using vectors of 2n integer coordinates.
This can be done for all field operations (addition, subtraction, multiplication, division).
mr_e_man wrote:Right.
Except...quickfur wrote:There's a theorem in algebra that you can perform exact arithmetic with algebraic numbers of degree n using vectors of 2n integer coordinates.
I think only n rational coordinates are needed, or up to n2 if the two numbers are in different fields.
(As you noted, rational vs. integral is no issue; n rational numbers can be encoded as 2n integers, or just n+1 integers using a common denominator.)
[...]
But how do you compare two algebraic numbers? E.g. how can you tell whether one is positive or negative?
It is doable if you only have square roots (possibly nested). But I don't see anything you can do with higher degrees.
mr_e_man wrote:It is doable if you only have square roots (possibly nested).
quickfur wrote:I have managed to figure out how to do it for the golden ratio, and probably for arbitrary roots of quadratics by extension. Basically it revolves around finding polynomial factors that annihilate the linear term in your polynomial, so that you end up with a square on one side which must be non-negative, and a linear expression on the other side. Use the inequality of rationals and the presumed irrationality of the algebraic number to exit early from your decision tree in the more obvious cases.
quickfur wrote:For a simple quadratic extension Q(√r) with square-free r>1, the procedure is very simple:
[...]
quickfur wrote:I haven't confirmed this, but I suspect that a similar procedure can be used for determining the sign of a cubic algebraic number (p + q·s1/3 + r·s2/3). IIRC there isn't a single conjugate in the cubic case, but two potentially different conjugates. Probably some combination of multiplying by these two conjugates would eliminate the cube roots and squared cube roots, yielding an expression whose sign can be determined by integer arithmetic alone.
mr_e_man wrote:Three digits in the radius is a bit too much for readability.
[...]
So, I think different variables should have different degrees of precision. Ordinary variables could have 2 digits in the radius. The main variable used in a very long calculation could have 4 digits, or even 10, in case you want to add a billion terms. And at the end of the calculation it could be reduced to 2.
It's still not efficient; e.g. it often recalculates π or log(10) with varying precision, even if it was calculated before with higher precision.
Users browsing this forum: No registered users and 1 guest