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.Sun, 18 Nov 2018 18:21:18 +0100Evaluate from string an equation that has integer divisionhttps://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 18:21:18 +0100https://ask.sagemath.org/question/44328/How to cast a string with an exponent from sys.argv to an Integer ?https://ask.sagemath.org/question/29597/how-to-cast-a-string-with-an-exponent-from-sysargv-to-an-integer/Hi,
For an exercise, I have written a Python script that takes an integer argument. Of course, the input in sys.argv is of type 'str', so I cast it to an Integer. It works, but I am supposed to accept numbers written like '123^1237' too, with a hat for the exponent. And I cannot find how to do that. In the sage interpreter, I can type "n = Integer(123^1237)" without any problem, but in my script it fails with a "TypeError: unable to convert '123^1237' to an integer". ThanksOnoxSat, 26 Sep 2015 17:00:01 +0200https://ask.sagemath.org/question/29597/