Ask Your Question
1

Direct substitution vs "subs" method

asked 2019-04-09 21:33:04 +0200

dsejas gravatar image

updated 2022-01-22 09:24:21 +0200

FrédéricC gravatar image

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 22:49:25 +0200

tmonteil gravatar image

updated 2019-04-11 19:13:10 +0200

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-11 06:32:39 +0200 )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 21:33:04 +0200

Seen: 2,215 times

Last updated: Apr 11 '19