Ask Your Question
1

Direct substitution vs "subs" method

asked 2019-04-09 14:33:04 -0500

dsejas gravatar image

updated 2019-04-09 14:34:15 -0500

Suppose I define

var('a b c')
formula = a^2 + 5*b + c

Then I would like to substitute some values, like a=2, b=2 and c=4. As far as I'm aware, there are two options to do this:

formula(a=2, b=2, c=4)

and

formula.subs(a=2, b=2, c=4)

In this particular case, is there any difference between this two options? Is there any difference in some other case(s)?

Thanks in advance for you answers!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-04-09 15:49:25 -0500

tmonteil gravatar image

updated 2019-04-11 12:13:10 -0500

There basically no difference. Indeed, if you look at the source code of the __call__ method of formula by typing:

sage: formula.__call__??

you can see that there is :

return self._parent._call_element_(self, *args, **kwds)

So, if you look at the _call_element_ element of the parent of formula (which is the symbolic ring) by typing:

sage: SR._call_element_??

besides some deprecation warnings, there is:

return _the_element.subs(d, **kwds)
edit flag offensive delete link more

Comments

Thank you very much for your answer, @tmonteil. This is exactly what I was expecting when I asked the question!

dsejas gravatar imagedsejas ( 2019-04-10 23:32:39 -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: 2019-04-09 14:33:04 -0500

Seen: 55 times

Last updated: Apr 11