# pi and e not evaluated when i use my own classes

 0 This question might be related to this question: http://ask.sagemath.org/question/966/problem-with-sign-sgn-and-n I have a symbolic calculation and I do evaluate it numerically. Within one of my classes (within my notebook; no external files) I evaluate this term -1/e^(1/10*abs(-0.0555555555556*pi - 26714619/51021164)) + 1  within a for loop. I am getting the following error: File "", line 1, in File "/tmp/tmpkItECC/___code___.py", line 113, in __temp=MuObject.calcValue((mu_enlacement[i])(**param_dict)) File "/tmp/tmpJuxeqk/___code___.py", line 97, in calcValue self._result[self._k,_sage_const_0 ]=R(self._value(theta_1=item[_sage_const_0 ],mu_t=item[_sage_const_1 ],mu_j=item[_sage_const_1 ])) File "parent.pyx", line 988, in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:7326) File "coerce_maps.pyx", line 156, in sage.structure.coerce_maps.NamedConvertMap._call_ (sage/structure/coerce_maps.c:4235) File "expression.pyx", line 862, in sage.symbolic.expression.Expression._mpfr_ (sage/symbolic/expression.cpp:5117) File "expression.pyx", line 796, in sage.symbolic.expression.Expression._eval_self (sage/symbolic/expression.cpp:4912) TypeError: Cannot evaluate symbolic expression to a numeric value. If I copy paste the expression print (-1/e^(1/10*abs(-0.0555555555556*pi - 26714619/51021164)) + 1).n()  to my notebook it evaluates fine to: 0.0674319647572598  I even tried to replace pi and e using a dictionary but I can't get it working. Any ideas what i am doing wrong? Thanks in advance, Markus P.S.: I can make the notebook public if usefull asked Dec 22 '11 Louis Cypher 3 ● 2 John Palmieri 2700 ● 9 ● 23 ● 60 http://www.math.washingto... The problem seems to be related to what is imported. Another version where the object calculating the values are created earlier works fine. I imported matplotlib as plt and numpy as np so no modules of these should be conflicting, right?Louis Cypher (Dec 22 '11)1I'm not sure what's happening. If you make the notebook public, or simply make a small self-contained example (always useful!) showing the problem, we can have a look.DSM (Dec 22 '11)2def expr():return -1/exp(1/10*abs(-0.0555555555556*n(pi) - 26714619/51021164)) + 1 (I'm often using workarounds of this type. Does it work for you?) achrzesz (Dec 23 '11)@achrzesz: if this is an answer, make it an answer and get karma (as well as make it easier to search for)!kcrisman (Dec 23 '11)@kcrisman As DSM stated without a self-contained code snippet it is difficult to give a definite answer. My guess is that to obtain a numerical result, the symbolic arguments pi,e should be replaced by n(pi),n(e) or RR(pi),RR(e)achrzesz (Dec 24 '11) see 2 more comments

 1 I don't know why this is happening, but here are some workarounds: one option is to replace self._value(theta_1=item[0],mu_t=item[1],mu_j=item[1])  by self._value(theta_1=item[0],mu_t=item[1],mu_j=item[1], e=e, pi=pi)  A second option: right after the line self._value=self._value(**self.th1_dict)(**self.pre10_dict)(**self.constants).trig_reduce().simplify() #set dictionary values  add the line self._value = self._value(**self.constants)  By the way, you can also replace the "constants" dictionary with  self.constants={ "pi": pi, "e": e }  to give better precision. posted Dec 30 '11 John Palmieri 2700 ● 9 ● 23 ● 60 http://www.math.washingto... Thanks a million time for this indeed helpfull answer. BTW: that behaviour seems like a bug to me. After adding e=e... in the first of the if loops all the others also work fine. Looks like sage forgets about the constants. Should I try to file a bug here?Louis Cypher (Jan 01 '12)File a bug if you can come up with a small example which displays the behavior. Your current worksheet is too complicated to figure out exactly where the bug lies.John Palmieri (Jan 02 '12)

[hide preview]