Ask Your Question

.is_real function

asked 2014-02-13 16:29:11 -0600

jstroud gravatar image

updated 2014-02-16 11:35:38 -0600

tmonteil gravatar image

Why does "sqrt(5).is_real()" come up false when it is obviously not? This seems to happen with any square root.

edit retag flag offensive close merge delete


There are many problems with this function. - sqrt(5).real_part() -> sqrt(5) - sqrt(5).imag_part() ->0 - sqrt(25).is_real() -> AttributeError: 'sage.rings.integer.Integer' object has no attribute 'is_real' - SR(sqrt(25)).is_real() -> True - SR(sqrt(5)).is_real() -> False - CC(sqrt(5)).is_real -> True

moroplogo gravatar imagemoroplogo ( 2014-02-14 03:25:40 -0600 )edit

I think this is because `sqrt` gives a symbolic thing, which Sage would have to exert possibly significant computational effort to decide whether it is real (think of showing whether an arbitrary expression is zero) and so answers `False` since it can't prove `True`.

kcrisman gravatar imagekcrisman ( 2014-02-14 06:29:56 -0600 )edit

"sqrt gives a symbolic thing, ..." perhaps , but Sage knows that sqrt(5).imag_part() is 0 then it isn't so difficult to answer True at this question. But I have only notions of programming.

moroplogo gravatar imagemoroplogo ( 2014-02-14 12:46:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-06-29 08:06:19 -0600

vdelecroix gravatar image

updated 2014-06-29 09:55:33 -0600


Never believe the symbolic ring as it can answer False when the result is True (hopefully a True is real True). To get the answer to your question, you would better do:

sage: QQbar(5).sqrt() in AA

Note: QQbar is the set of algebraic number and AA is the set of real algebraic numbers.


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


Asked: 2014-02-13 16:29:11 -0600

Seen: 302 times

Last updated: Jun 29 '14