1 | initial version |
You can use function
to define the functions you wish. For example,
sage: hexp = "g(x)=" + "x**3"
sage: func, value = hexp.split("(x)=")
sage: function(func, nargs=1, eval_func=lambda self,x: eval(value))
g
sage: print(g(x))
x^3
sage: print(g(3))
27
Another example:
sage: hexp = "f(x)="+"(-1*x**0+4*x**1-1*x**2) * (-5*x**0+5*x**1+4*x**2) * (2*x**0-5*x**1-5*x**2)"
sage: func, value = hexp.split("(x)=")
sage: function(func, nargs=1, eval_func=lambda self,x: eval(value))
f
sage: print(f(x))
(5*x^2 + 5*x - 2)*(4*x^2 + 5*x - 5)*(x^2 - 4*x + 1)
sage: print(f(3))
-5336
Type function?
on the Sage prompt or read the docs for more details.