First time here? Check out the FAQ!

Ask Your Question
1

convert expression to function

asked 12 years ago

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=...)

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

updated 12 years ago

Does it answer the question ?

sage:s=sin(x)                                                                  
sage: s
sin(x)
sage: f=s.function(x)
sage: f
x |--> sin(x)
Preview: (hide)
link

Comments

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

Mathemage gravatar imageMathemage ( 12 years ago )
3

answered 12 years ago

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.

Preview: (hide)
link

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 ( 12 years ago )

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 ( 12 years ago )

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: 12 years ago

Seen: 2,195 times

Last updated: May 21 '12