Ask Your Question
1

convert expression to function

asked 2012-05-19 23:52:44 -0500

Mathemage gravatar image

Hola,

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
2

answered 2012-05-20 02:55:23 -0500

updated 2012-05-20 02:56:43 -0500

Does it answer the question ?

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

Comments

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

Mathemage gravatar imageMathemage ( 2012-05-20 10:47:03 -0500 )edit
3

answered 2012-05-21 03:25:35 -0500

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

Comments

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 11:59:00 -0500 )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 02:16:15 -0500 )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

2 followers

Stats

Asked: 2012-05-19 23:52:44 -0500

Seen: 522 times

Last updated: May 21 '12