Ask Your Question
1

Direct substitution vs "subs" method

asked 6 years ago

dsejas gravatar image

updated 3 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

tmonteil gravatar image

updated 5 years ago

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)
Preview: (hide)
link

Comments

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

dsejas gravatar imagedsejas ( 5 years ago )

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: 6 years ago

Seen: 3,234 times

Last updated: Apr 11 '19