Ask Your Question

convert expression to function

asked 2012-05-20 06:52:44 +0200

Mathemage gravatar image


is there a way to convert symbolic expression to proper functions?

E. g. s = sin(x) into x |--> sin(x)

So far I've been using f(x) = s(x), however, deprection warnings occur:

DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-05-20 09:55:23 +0200

updated 2012-05-20 09:56:43 +0200

Does it answer the question ?

sage: s
sage: f=s.function(x)
sage: f
x |--> sin(x)
edit flag offensive delete link more


Still giving out same DeprecationWarning but seems to be proper method...

Mathemage gravatar imageMathemage ( 2012-05-20 17:47:03 +0200 )edit

answered 2012-05-21 10:25:35 +0200

kcrisman gravatar image
sage: s = sin(x)
sage: f(x) = s
sage: f
x |--> sin(x)

No deprecation warning! What's going on here is that s(x) was really trying to evaluate your symbolic expression s at the point x - which happened to be a variable, but is still deprecated. If you use the transitive property, the above is just saying

sage: f(x) = sin(x)

which is what you want, as opposed to

sage: f(x) = sin(x)(x)

in your first attempt, which is perhaps ambiguous.

edit flag offensive delete link more


Great, sounds perfect!! Any way to do this without knowledge of expression's default variable? Say, if I get only the "s", can I do a makeover to function in a universal way?

Mathemage gravatar imageMathemage ( 2012-05-31 18:59:00 +0200 )edit

You could use `s.variables()` and `s.variables()[0]` to find out what the variable was. Only if you are sure there is only one variable - expressions like `a*sin(x)` wouldn't work, even if `a` is a "constant", since Sage can't tell the difference without the function notation. Also, the "obvious" thing to do `f(s.variables()[0]) = s`, or even to name that and then plug it in, doesn't work because of the way the preparser works. In short, it's mostly not worth the effort.

kcrisman gravatar imagekcrisman ( 2012-06-01 09:16:15 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2012-05-20 06:52:44 +0200

Seen: 1,869 times

Last updated: May 21 '12