Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Numerical values VS symbolic values ?

This question might be related with link text

I have to perform some numerical calculation using constants like pi and e. What happens is that computing a simple expression of pi is evaluated numerically (eg, cos(pi) returns -1) but when I use a random function (eg, random()pi), I have a symbolic expression like "0.123456789pi". In a for loop with this expression I obtain at the end something like "0.123456789pi + 0.987654321pi + ..." and so on.

My question aims to clarify the way to use symbolic expression (SE) and/or numerical values (NV) within a code (either in sage shell or script file). I think we have different cases to think about :

  1. I want to use only NV in my code, how can I specify once for all that constants I will use will be evaluated numerically ?
  2. I want to use only SE in my code, this one seems straightforward as Sage uses a preparser structure with symbolic expression.
  3. I want to use both in my code, a function using constants need to return NV but also SE. Of course calculation will use NV from this function and analysis will use SE (eg, derivation, integration, series expansion, etc...).

I hope this thread will be useful. I think I know how to use case 1, for example with NV of pi as PI=RDF.pi() or PI=pi.n(). In case of random()*PI, we have indeed a numerical result, as wanted.

Case 3 is more interesting, I remember having a lots of problem with python.sympy with SE and NV. I struggled to use SE for analysis then trying to obtain NV. I'd like to see what you think about this, Sage seems more powerful than sympy about that. I read documentation but maybe I missed something. I'm not working on this case for now (so no code example...) but if needed for clarity I can dig one of my old sympy code.

(sorry for my english, it is sometimes "random" )