Ask Your Question
1

exact computations with algebraic numbers

asked 2020-07-06 14:18:17 -0500

b897069 gravatar image

updated 2020-07-11 20:10:09 -0500

slelievre gravatar image

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.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2020-07-06 15:23:25 -0500

rburing gravatar image

Yes, it is exact. To check:

sage: c.minpoly() # minimal polynomial over QQ
x - 1
sage: c.radical_expression()
1
edit flag offensive delete link more
1

answered 2020-07-11 20:12:28 -0500

slelievre gravatar image

Computations in algebraic numbers are costly so Sage computes the product of a and b "lazily".

Some computations force it to realise the exact value of c.

Here are the one I would favour.

sage: c = AA(r) * AA(1/r)
sage: c
1.000000000000000?
sage: c.exactify()
sage: c
1

For the sake of completeness I also include those from @rburing's answer:

sage: c = AA(r) * AA(1/r)
sage: c
1.000000000000000?
sage: c.radical_expression()
1

sage: c = AA(r) * AA(1/r)
sage: c
1.000000000000000?
sage: c.minpoly()
x - 1
sage: c
1
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-06 14:18:17 -0500

Seen: 87 times

Last updated: Jul 11