Late binding and lazy symbolic thence numeric math
Being a newbie to Sage, after growing weary of wxMaxima, perhaps this is already supported but bear with me...
It seems the programming principle of "late binding" should apply, in particular, to systems in which numeric and symbolic math are seamlessly integrated.
For example, let's say I:
from scipy.constants import epsilon_0, c
...define an identity like:
mu_0*epsilon_0=1/c^2
...and then define a function, say, for the vector potential of a Hertzian dipole:
norm(x,y,z)=sqrt(x*x+y*y+z*z)
Idipole(t)=I0*cos(omega*t)
A(x,y,z,t)=[0,0,(1/(4*pi*epsilon_0*c^2)*L*Idipole(t-norm(x,y,z)/c)/norm(x,y,z))]
If (after defining other symbols) I then demand a numeric value, say, in a plot:
plot(A(0,0,z,0),z,1,4)
It should be able to, in service of this demand, lazily invoke an optimization by first solving for mu_0 thence symbolic simplification to:
A(x,y,z,t)=[0,0,(mu_0/(4*pi)*L*Idipole(t-norm(x,y,z)/c)/norm(x,y,z))]
...prior to substituting numeric values or other presumptive substitutions.
Is this kind of late binding with lazy symbolic thence numeric math supported by Sage?
Do you have a reason to assume that the constant
is better computed via the formula
and would sage have enough information to come to that conclusion as well? With a little bit of work it should be able to let sage rewrite one into the other, but without extra information I don't think you can expect a computer algebra system to decide that such a rewrite is advantageous.
The few symbols (formal elegance) and a few arithmetic operations (computational optimization) saved by the transformation are in principle applicable to a broad range of mathematics. A bit more thought on my part might have come up with better examples to bypass your query -- a query that misses the more fundamental point about lazy evaluation (which may be thought of as subsuming late binding, demand driven computation, just in time compilation, memoization, tabling, caching/voiding, incremental view maintenance etc.).
plot would normally put the to-be-plotted expression through "fast_callable", which basically constructs a straight-line program to determine numerical values of the to-be-plotted expression. In the process of constructing that straight-line-program, the constant
mu_0/(4*pi)=1/(4*pi*epsilon_0*c^2)
would get folded.There is RealLazyField which stores enough information to first construct an expression and then evaluate it numerically to get a certain number of digits.
Python is not a lazily evaluated programming language. So any lazy evaluation functionality needs to come from specifically implemented behaviour.
I don't understand: what does lazy evaluation have to do with symbolic simplifications? By the way, your second line of code fails in my Sage
although this works