First time here? Check out the FAQ!

Ask Your Question
1

exact computations with algebraic numbers

asked 4 years ago

b897069 gravatar image

updated 4 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
3

answered 4 years ago

rburing gravatar image

Yes, it is exact. To check:

sage: c.minpoly() # minimal polynomial over QQ
x - 1
sage: c.radical_expression()
1
Preview: (hide)
link
1

answered 4 years ago

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
Preview: (hide)
link

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: 4 years ago

Seen: 622 times

Last updated: Jul 12 '20