Ask Your Question
0

exact factorting

asked 2013-10-20 19:43:06 +0200

anonymous user

Anonymous

How do you get sage to factor into exact values. For instance, I want it to factor x^2-2 and return (x-sqrt(2))*(x+sqrt(2))

However, when I input

realpoly.<x> = PolynomialRing(CC) factor(x^2-2,x)

Sage returns

(x - 1.41421356237310) * (x + 1.41421356237310)

Any ideas?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2013-10-20 20:13:40 +0200

tmonteil gravatar image

updated 2013-10-20 20:21:21 +0200

The notation CC (as well for RR) is misleading: CC does not corresponds to genuine complex numbers (unlike for NN, ZZ, QQ, AA, QQbar), but only refers to floating-point approximation of complex numbers.

In your case, if you want exact computations, you should work on the algebraic field QQbar instead of CC:

sage: QQbar
Algebraic Field
sage: realpoly.<x> = PolynomialRing(QQbar)
sage: factor(x^2-2,x)
(x - 1.414213562373095?) * (x + 1.414213562373095?)

This looks the same, but you should notice the question mark after 1.414213562373095, which means that 1.414213562373095? is only a representation of some algebraic number. You can check that it is really sqrt(2) as follows:

sage: s2 = x-factor(x^2-2,x)[0][0]
sage: s2
1.414213562373095?
sage: s2 == sqrt(QQbar(2))
True

sage: QQbar(s2).as_number_field_element()
(Number Field in a with defining polynomial y^2 - 2,
 a,
 Ring morphism:
  From: Number Field in a with defining polynomial y^2 - 2
  To:   Algebraic Real Field
  Defn: a |--> 1.414213562373095?)
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: 2013-10-20 19:43:06 +0200

Seen: 289 times

Last updated: Oct 20 '13