Ask Your Question

substitution in expression

asked 2013-05-17 23:57:53 -0500

updated 2013-05-18 03:23:18 -0500


After reading Simplify shenanigans, I am very confused about the possibility of doing

sage: sin(x).subs(sin(x) == 3)

Which becomes even more funny with

sage: SR(2).subs(SR(2) == pi)

I thought one may only set values to variable but no: I can set value to integers !

Is there a concrete example where this is useful ? Or this is just one more argument to avoid the use of the symbolic ring ?

Anyway the substitution is not at all consistent with the behavior of the symbolic ring. If such substitutions are allowed, then the expression SR(2) + SR(2) should not be simplified !

edit retag flag offensive close merge delete


Perhaps such a feature could be used for the [variation of constants]( method :p

tmonteil gravatar imagetmonteil ( 2013-05-19 00:52:42 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-05-22 00:12:29 -0500

The substitute command is a generic interface to the rewrite engine in Pynac/GiNaC. You can replace an arbitrary subexpression, also containing wildcards (see the documentation of the match() method of symbolic expressions), with another expression.

Consider the case where a subexpression occurs in several places and you have a better formula or value for it derived from other sources. You can just replace the existing subexpression with the new formula using the substitute() function.

edit flag offensive delete link more


Thanks for the precision of the implementation. And I see how it may be used.

vdelecroix gravatar imagevdelecroix ( 2013-05-22 02:37:47 -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


Asked: 2013-05-17 23:57:53 -0500

Seen: 1,246 times

Last updated: May 22 '13