ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 24 Jul 2014 13:59:58 +0200Any way to get numeric result of part of symbolic expresssion?https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/ If I have a symbolic expression `sqrt(2) + x`, is it possible to get this to show as `1,414.... + x`?
*Edit:*
I should probably add that my symbolic expression can be any arbitrary composition of numbers and symbols.Mon, 21 Jul 2014 16:53:33 +0200https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/Comment by FrédéricC for <p>If I have a symbolic expression <code>sqrt(2) + x</code>, is it possible to get this to show as <code>1,414.... + x</code>?</p>
<p><em>Edit:</em></p>
<p>I should probably add that my symbolic expression can be any arbitrary composition of numbers and symbols.</p>
https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?comment=23564#post-id-23564Could you give us a more serious (real) example of what you want, please ?Thu, 24 Jul 2014 13:59:58 +0200https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?comment=23564#post-id-23564Answer by Vasile for <p>If I have a symbolic expression <code>sqrt(2) + x</code>, is it possible to get this to show as <code>1,414.... + x</code>?</p>
<p><em>Edit:</em></p>
<p>I should probably add that my symbolic expression can be any arbitrary composition of numbers and symbols.</p>
https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?answer=23515#post-id-23515Hello,
I would try n(sqrt(2)) + x.
This results in x + 1.41421356237310
Mon, 21 Jul 2014 17:49:52 +0200https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?answer=23515#post-id-23515Comment by Woodgnome for <p>Hello,</p>
<p>I would try n(sqrt(2)) + x.</p>
<p>This results in x + 1.41421356237310</p>
https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?comment=23520#post-id-23520I've edited my question for clarity.Mon, 21 Jul 2014 20:46:16 +0200https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?comment=23520#post-id-23520Answer by slelievre for <p>If I have a symbolic expression <code>sqrt(2) + x</code>, is it possible to get this to show as <code>1,414.... + x</code>?</p>
<p><em>Edit:</em></p>
<p>I should probably add that my symbolic expression can be any arbitrary composition of numbers and symbols.</p>
https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?answer=23517#post-id-23517If your symbolic expression is a polynomial and your constants are algebraic numbers, work in a polynomial ring with coefficients in AA or QQbar.
sage: R.<x> = PolynomialRing(AA)
sage: a = AA(2).sqrt()
sage: x - a
x - 1.414213562373095?
Elements of AA or QQbar are exact. Compare:
sage: a = AA(2).sqrt()
sage: b = sqrt(2)
sage: c = n(sqrt(2))
sage: aa = a^2
sage: bb = b^2
sage: cc = c^2
sage: aa == 2
True
sage: bb == 2
2 == 2
sage: cc == 2
False
Mon, 21 Jul 2014 18:25:32 +0200https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?answer=23517#post-id-23517Comment by Woodgnome for <p>If your symbolic expression is a polynomial and your constants are algebraic numbers, work in a polynomial ring with coefficients in AA or QQbar.</p>
<pre><code>sage: R.<x> = PolynomialRing(AA)
sage: a = AA(2).sqrt()
sage: x - a
x - 1.414213562373095?
</code></pre>
<p>Elements of AA or QQbar are exact. Compare:</p>
<pre><code>sage: a = AA(2).sqrt()
sage: b = sqrt(2)
sage: c = n(sqrt(2))
sage: aa = a^2
sage: bb = b^2
sage: cc = c^2
sage: aa == 2
True
sage: bb == 2
2 == 2
sage: cc == 2
False
</code></pre>
https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?comment=23521#post-id-23521Not sure I understand this, but can your principle still be applied with my latest of the question?Mon, 21 Jul 2014 20:46:40 +0200https://ask.sagemath.org/question/23514/any-way-to-get-numeric-result-of-part-of-symbolic-expresssion/?comment=23521#post-id-23521