# Why use symbolic functions?

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?

edit retag close merge delete

Sort by ยป oldest newest most voted

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)

more

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.

( 2016-12-27 13:24:49 -0600 )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.

( 2017-01-10 05:08:56 -0600 )edit