Ask Your Question

# Difference between f and f(r) I was experimenting with symbolic functions, and I was wondering what is the difference between these two forms of creating one:

sage: f1 = function('f', r)
sage: f2(r) = function('f', r)


I have made some experiments in this Sage worksheet, but except for some output differences, I don't know what will happen if I try to differentiate them, integrate them, put them into an equation, etc.

Any ideas?

edit retag close merge delete

## 1 answer

Sort by » oldest newest most voted First off, what is missing here (but is in your worksheet) is var("r") at the beginning. Otherwise your first one is calling R!

As to the others, as you see on the worksheet, the difference is that the first one is a "symbolic expression", in which variables have to be substituted, while the second is a "callable symbolic expression", where you don't have to do this. Compare:

sage: f1.subs(r=3)
f(3)
sage: f2(3)
f(3)

sage: preparse("f2(r) = function('f', r)")
'__tmp__=var("r"); f2 = symbolic_expression(function(\'f\', r)).function(r)'


What happens is that the .function method turns it into something with a specific variable r that is the input. If you had 'constants' like 'a' or 'b' in your function, this would make more sense, e.g.

sage: var('a,b,c')
(a, b, c)
sage: f3(r)=a*b*c*function('f',r)
sage: f3
r |--> a*b*c*f(r)


So you could only substitute r with the function syntax; for the rest you'd need the .subs method.

Otherwise, they should be pretty much identical, I think. You have to be a little careful with whether you call the second one f2(r) or just f2, I think, in things like numerical integration, maybe. I can't remember the exact contexts in which that matters, but it is not frequent.

more

## Comments

Hmm very subtle differences. Anyway, great answer, thanks!

## Your Answer

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

Add Answer

## Stats

Asked: 2011-05-20 23:14:49 -0500

Seen: 397 times

Last updated: May 21 '11