Ask Your Question

b897069's profile - activity

2020-07-06 21:19:10 +0100 received badge  Editor (source)
2020-07-06 21:18:17 +0100 asked a question exact computations with algebraic numbers

I'm trying to do exact computations with algebraic numbers. In particular, I know to expect integer answers like 1, 0, and 3 at the end of my computations, but I'm getting something slightly off.

I noticed that if I run

sage: r = sqrt(2)
sage: a = AA(r)
sage: b = AA(1/r)
sage: c = a*b

Then I get:

sage: c
1.000000000000000?

Is this being handled in the computer as exactly 1? Otherwise, how can I do exact computations with algebraic numbers in Sage? I obtain the algebraic numbers I'm working with using algdep() to find a polynomial and .roots(QQbar) to find the roots of that polynomial.

2020-06-30 23:43:20 +0100 received badge  Student (source)
2020-06-30 22:23:58 +0100 asked a question nearby algebraic number / convert polynomial type to expression type

Given a real number, I am trying to find a nearby algebraic number. This can be done in Mathematica with the RootApproximant function.

I couldn't find a similar function in Sage, so I am using algdep() to find an irreducible polynomial that is approximately satisfied by that number. Then I am using roots() to find the roots of that polynomial, and I can identify which root is closest to my number.

The problem is that the output of algdep() has a type that seems to be incompatible with roots().

When I execute this code, p.roots() returns an empty list:

p=algdep(sqrt(5), 10);
print(p.roots())

When I execute this code, a list of the roots is returned:

q = x^2 - 5
print(q.roots())

The output of algdep() has type sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint

In the second block of code, q has type sage.symbolic.expression.Expression

Is there a way to convert the first type into the Expression type?