Hello,

This question is about good / best practices for creating a "symbolic 
wrapper" for a purely numerical function.

I have a rather nice function that I've written as a class (with __call__ 
overloading, etc.) called RiemannTheta that at the moment can only handle 
numerical input. In particular, an instance of this class is a function, 
which I will call theta, from C^g --> C. This function can also numerically 
compute directional derivatives. For example, for g=3 I can compute the 
value of the first derivative in the [0,1,0] direction at the point [2,4,8] 
like so:

sage: theta = RiemannTheta( <initializing arguments that define a specific 
Riemann Theta function> )
sage: theta([2,4,8], derivs=[[0,1,0]])
<complex number output>

What I would like to have is the ability to "lazily" evaluate symbolic 
expressions like:

sage: f = theta([x,x^2,x^3])

So that

sage: f(x=2) == theta([2,4,8])
True

I also want to be able to write

sage: f010 = theta([x,x^2,x^3], derivs=[0,1,0])
sage: f010(x=2) == theta([2,4,8], derivs=[[0,1,0]])
True

and I want to write a RiemannTheta.derivative(x) that will compute the 
symbolic derivative via the chain rule for vector to scalar-valued 
functions. Again, the key issue here is that *theta can only accept 
numerical input. *
*
*
So *my main question is*: what would be a / the Pythonic or Sage-thonic 
approach to appending this kind of behavior? The first step would be to 
detect symbolic expression input in RiemannTheta.__call__(). (In such a way 
that it's as fast as possible.) My thoughts were to create a new class, 
RiemannTheta_symbolic, with a RiemannTheta object stored as an attribute. 
There would be a layer of lazy symbolic expression handling to make it such 
that RiemannTheta isn't called until all unknown variables are given complex 
subs. I'm afraid to inherit anything in sage.symbolic (or whatever is 
relevant in this case) since it seems rather complicated. (But I'm willing 
to dive into it if necessary.)

Thanks for any insight or information.

--
Chris Swierczewski

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to