Hi, all,
A question about callable functions: I would like to create one, say
"f(x,y)=x^2+y^2". There are several ways to do this:
- f = x^2+y^2
This works but "f(a,b)" fails (it's not really "callable")
- R.<x,y> = PolynomialRing(ZZ)
g = x^2+y^2
This works and "g(a,b)" does what I want. It seems kind
of heavy-weight, though (I've now got a polynomial ring
floating around when I don't really need it).
- h(x,y) = x^2+y^2
This also works and does what I want, with some glitches.
The following shows what I mean:
sage: var('y')
y
sage: f = x^2+y^2
sage: f(0,1)
------------------------------------------------------------------------
---
<type 'exceptions.TypeError'> Traceback (most recent call
last)
/SandBox/Justin/sb/sage-2.8.2/<ipython console> in <module>()
<type 'exceptions.TypeError'>: __call__() takes at most 2 arguments
(3 given)
sage: R.<x,y> = PolynomialRing(ZZ)
sage: g = x^2+y^2
sage: g
x^2 + y^2
sage: g(0,1)
1
sage: print g(0,1)
1
sage: type(g(0,1))
<type 'sage.rings.integer.Integer'>
sage: h(x,y)=x^2+y^2
sage: h
(x, y) |--> y^2 + x^2
sage: h(0,1)
1
sage: print h(0,1)
1
sage: type(h(0,1))
<class 'sage.calculus.calculus.SymbolicArithmetic'>
So, questions:
- why is h(0,1) not an 'Integer'? Does that matter? I have some
code (hacks, admittedly) that wants to be sure it's dealing with
integers.
- The fact that 'print h(0,1)' produces a bizarre result is really
a bother, because I can't bank on formatting (unless I am missing
something; it wouldn't be the first time, of course).
- Is there some 4th alternative that I missed?
To complicate matters, I want to create these things in code, and
return the result, to be used later, either directly or in other code.
Comments?
Thanks for the help, in advance.
Justin
--
Justin C. Walker, Curmudgeon-At-Large, Director
Institute for the Enhancement of the Director's Income
--------
The path of least resistance:
it's not just for electricity any more.
--------
--~--~---------~--~----~------------~-------~--~----~
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/
-~----------~----~----~----~------~----~------~--~---