Ask Your Question
2

Why use symbolic functions?

asked 2016-12-24 13:44:49 -0500

omoplata gravatar image

So, I can do the following by introducing x as a symbolic function.

sage: var('b,c,t')
(b, c, t)
sage: x(t) = sqrt(b^2 + c^2*t^2) - b
sage: x
t |--> -b + sqrt(c^2*t^2 + b^2)
sage: diff(x,t)
t |--> c^2*t/sqrt(c^2*t^2 + b^2)

I can introduce x as a variable with assigned symbolic values, and get the same result.

sage: var('b,c,t')
(b, c, t)
sage: x = sqrt(b^2 + c^2*t^2) - b
sage: x
-b + sqrt(c^2*t^2 + b^2)
sage: diff(x,t)
c^2*t/sqrt(c^2*t^2 + b^2)

So, since I can do the same thing using variables, why use symbolic functions at all? Can symbolic functions do things that variables can't do?

Thanks in advance.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2016-12-25 11:53:21 -0500

eric_g gravatar image

The main difference between symbolic functions and symbolic variables is that symbolic functions are callable, i.e. you can evaluate the value of the function at any given argument via the parentheses operator:

sage: x(t) = sqrt(b^2 + c^2*t^2) - b
sage: x(0)
-b + sqrt(b^2)
sage: x(pi)
-b + sqrt(pi^2*c^2 + b^2)

whereas for a symbolic variable, you have to use the subs method:

sage: x = sqrt(b^2 + c^2*t^2) - b
sage: x.subs(t=0)
-b + sqrt(b^2)
edit flag offensive delete link more

Comments

Thanks. I noted also noted that I can declare the variables I need inside the parentheses on the left hand side. For example, I can define,

sage:  x(b,c,t) = sqrt(b^2 + c^2*t^2) - b

without declaring b,c and t to be variables beforehand. But it appears that sage defines these variables in the background while defining the function x(t). So, afterwards, I can input

a

and not get an error, because it appears to have been defined in the background. But inputting a hitherto unused value, such as y, will give an error. Also, if I did not put b and c within parentheses on the left hand side without declaring them beforehand, that would also be an error.

omoplata gravatar imageomoplata ( 2016-12-27 13:24:49 -0500 )edit

Yes, if you want to see what Sage is doing "in the background" when you type x(b,c,t) = sqrt(b^2 + c^2*t^2) - b, use the preparse command:

sage: preparse("x(b,c,t) = sqrt(b^2 + c^2*t^2) - b")
'__tmp__=var("b,c,t"); x = symbolic_expression(sqrt(b**Integer(2) + c**Integer(2)*t**Integer(2)) - b).function(b,c,t)'

As you can see, Sage is running var("b,c,t") for you.

eric_g gravatar imageeric_g ( 2017-01-10 05:08:56 -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

1 follower

Stats

Asked: 2016-12-24 13:44:49 -0500

Seen: 101 times

Last updated: Dec 25 '16