On 9/13/07, Justin C. Walker <[EMAIL PROTECTED]> wrote:
\> > Yes, there are two more, which might be fine, depending on
> > your application:
> >
> > def h(x,y):
> >        return x^2 + y^2
> > and
> > h = lambda x,y: x^2 + y^2
> >
> > Probably the very last one is exactly what you really want,
> > unless you want to do arithmetic with it (h^2 doesn't make
> > any sense).
>
> This seems to work well for me.  While "h^2" may make no sense, "h
> (x,y)^2" does, and works as I expect.  Does this mean that 'h' is a
> "second-class citizen"?  :-}

I don't know what that means exactly. That h is just a normal
old-fashioned computer programmer Python function, that don't
have anything to do with math.  It so happens one can pass
them around to functions etc.,  but if you create them on the
fly you can *not* pickle them.  This may or may not be a problem
for you, depending on your application.

> > sage: preparse('h(x,y) = x^2 + y^2')
> > '_=var("x,y");h=symbolic_expression(x**Integer(2) +
> > y**Integer(2)).function(x,y)'
> >
> > I.e., make x and y symbolic, make the expression x^2 + y^2, and
> > finally make it into a function of x and y.
>
> I don't see what's going on here.  When I try this, I get a string
> that I can't "eval".  What am I missing?  Or was this not intended as
> a solution, but rather an explanation?

If you past the code in quotes into a .py file (without the quotes) it
should work.  I had thought you were trying to avoid using the preparser
or something, but maybe I misunderstood your question.

william

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to