ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 18 Nov 2018 11:21:18 -0600Evaluate from string an equation that has integer divisionhttp://ask.sagemath.org/question/44328/evaluate-from-string-an-equation-that-has-integer-division/ I have the following Python list that contains strings of equations.
L = ['651/349*t + 5382747/9778631000', 't + 57879/196133000', '1000/349*t + 57879/68450417']
You can see that all of the equations have integer division. Because this is obtained by some program, I can not edit the strings.
When I evaluate for `t=1.0` with the following code in SageMath (for example), it does not evaluate as an Euclidean division.
F = function('F')(t)
for k in L:
F(t) = eval(k)
Fc = fast_callable(F, vars=[t])
val2eval = 1.0
print(Fc(val2eval).n(13))
It gives
1.00000000000000
1.00000000000000
2.00000000000000
And should be give
1.86587997307599
1.00029510077345
2.86617507384944
Of course I can solve this by modifying MANUALLY the strings of the equations by indicating that the denominator is a real number and not an integer (I put a decimal point at the end of the integer in the denominator) as following.
L = ['651/349.*t + 5382747/9778631000.', 't + 57879/196133000.', '1000/349.*t + 57879/68450417.']
But this is not the idea, the strings of the equations are generated automatically and one can not modify by editing manually, because it will be implemented in a process where it should be create at least 2000 equations.
Is there some elegant solution for this? --Many thanks!loSuarezBSun, 18 Nov 2018 11:21:18 -0600http://ask.sagemath.org/question/44328/problems with sage_eval and evalhttp://ask.sagemath.org/question/36337/problems-with-sage_eval-and-eval/Dear all,
I am trying to construct and evaluate sage code, but what used to work in previous versions does not seem to work in SageMath 7.3 any more. Apparently `eval('opr(16*a^2*x^2)')` does not pre-parse the exponent properly:
var('a x')
term1 = 16*a^2*x^2
print (opr(term1))
print eval('opr(term1)')
print eval('opr(16*a^2*x^2)')
gives:
16*a^2*x^2
16*a^2*x^2
RuntimeError: Use ** for exponentiation, not '^', which means xor
in Python, and has the wrong precedence.
In contrast, if I use `sage_eval`, I get a different error:
term1 = 16*a^2*x^2
print (opr(term1))
print sage_eval('opr(term1)')
print sage_eval('opr(16*a^2*x^2)')
gives:
16*a^2*x^2
NameError: name 'opr' is not defined
What would be the correct way of evaluating a text string in a similar way as if it had been entered directly into a code cell?
stanWed, 18 Jan 2017 07:30:26 -0600http://ask.sagemath.org/question/36337/Evaluate a listhttp://ask.sagemath.org/question/32537/evaluate-a-list/Hi,
Suppose for example `E =[x,x^2,x+1]` is a list of elements in `ZZ[x]`. Let `K` be a number field defined in Sage
K.<a> = NumberField(f(x))
for some irreducible polynomial $f(x)$. Then how can one evaluate the list `E` by setting $x=a$ and $x=\sigma(a)$ (conjugate of a) in Sage?
Dianbin BaoThu, 11 Feb 2016 13:57:56 -0600http://ask.sagemath.org/question/32537/Bug or desired behavior of eval?http://ask.sagemath.org/question/8504/bug-or-desired-behavior-of-eval/I am fairly certain this is a bug, but I wanted to ask here before reporting it on trac. I understand that when we enter something in sage, like
sage: 5/3
5/3
We want to receive 5/3 instead of the normal python output:
>>> 5/3
1.6666666666666667
However, eval in sage seems to be rounding down:
sage: eval('5/3')
1
Where I would expect it to return 5/3 again, or at the very least 1.6666666666666667 (if eval ran through python first and had already returned 1.6666666666666667). The standard eval in python does return 1.6666666666666667.process91Tue, 22 Nov 2011 11:00:07 -0600http://ask.sagemath.org/question/8504/