Unable to calculate numeric output of calculation with RIFs? Bug?

asked 2019-02-14 18:09:01 +0200

stockh0lm gravatar image

updated 2019-02-16 12:58:24 +0200

reworked question, same worksheet in cocalc.

this is my code:

g=solve(e_Ersatz/(2*d_k)==e_s/d_e, d_k)
print g
show(g[0].subs({
        d_e: RIF(.999,1.001),
        d_m: RIF(.25,.1),
        e_m: e_0 * RIF(80.5,81.5),
        e_s: e_0 * RIF(3,4)
    }))
f=g[0].subs({
        d_e: RIF(.999,1.001),
        d_m: RIF(.25,.1),
        e_m: e_0 * RIF(80.5,81.5),
        e_s: e_0 * RIF(3,4)
    })
#show( n(f) )

this is g:

[
d_k == (d_e*d_m*e_m - (d_e*d_m + 2*d_m^2)*e_s)/(d_e*e_m - 2*d_m*e_s)
]

So its not really complicated, a little summation, some factors, a square. Nothing I could not do manually, even with the error propagtion.

But when trying to get the RIF equvalent I get

*** WARNING: Code contains possible implicit multiplication    ***
*** Check if any of [ 5e, 5e ] need a "*" sign for multiplication, e.g. 5x should be 5*x ! ***

Error in lines 82-82
Traceback (most recent call last):
  File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute
    flags=compile_flags) in namespace, locals
  File "", line 1, in <module>
  File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/misc/functional.py", line 1419, in numerical_approx
    return n(prec, algorithm=algorithm)
  File "sage/symbolic/expression.pyx", line 5981, in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:34636)
    raise TypeError("cannot evaluate symbolic expression numerically")
TypeError: cannot evaluate symbolic expression numerically

Hu? Am I missing something fundamental? Is this a bug?

================ old question:

This is my worksheet: https://cocalc.com/share/f7766c5e-2f4...

I have an equation that I insert some numeric values into. Because I need to estimate the range of uncertainty, I specify the values as RIF numbers:

d[0].subs(
        d_e == RIF(.999,1.001),
        x ==.25,
        d_m == RIF(.05,.15),
        U == RIF(10^-9,1.02*10^-9),
        e_m == e_0 * RIF(80.5,81.5),
        e_s == e_0 * RIF(3,4)
    )

However, in the output that range is not expressed. Is that becaues there are remaining symbolic parameters?

edit retag flag offensive close merge delete

Comments

It is very hard to start an answer. Please try to isolate the "same error" in a simpler case. Or simply develop code in a debugger. For instance, explain in words what is d[0] (conceptually and as a python object) and why should subs work in the given case.

dan_fulea gravatar imagedan_fulea ( 2019-02-15 17:42:42 +0200 )edit

ah, i was under the impression that it was customary to point to the cocalc worksheets. I dont feel confident explaining what d[0] is as a python object or otherwise - i know nothing about the inner workings of sage. Also i thought subs would be the common way to insert values into code in a temporary way. I will fiddle a little and rephrase the question.

stockh0lm gravatar imagestockh0lm ( 2019-02-15 18:13:11 +0200 )edit

pointing to a well documented cocalc sheet may be ok, in this case, people try to copy+paste the code into the own debugger to get closer to the error. They further try to get closer to the error by setting some values or cutting them, try to inspect the types of the variables, and so on. To get a fair share of the effort, it would be in my view easier for a potential helper to already get the question at the point, without needing to get rid of the irrelevant python objects landscape. In our case it is really hard to get to the point. What is for instance e_Ersatz in the new post? (I will still try to put an answer in here below.)

dan_fulea gravatar imagedan_fulea ( 2019-02-18 16:23:10 +0200 )edit

The following works for me:

var('d_e d_m e_m e_s U x');
g = \
[
d_k == (d_e*d_m*e_m - (d_e*d_m + 2*d_m^2)*e_s)/(d_e*e_m - 2*d_m*e_s)
]
d = g
d[0].subs(
        d_e == RIF(.999,1.001),
        x ==.25,
        d_m == RIF(.05,.15),
        U == RIF(10^-9,1.02*10^-9),
        e_m == e_0 * RIF(80.5,81.5),
        e_s == e_0 * RIF(3,4)
    )

This gives d_k == 0.1? .

dan_fulea gravatar imagedan_fulea ( 2019-02-18 17:27:21 +0200 )edit