Ask Your Question
0

substitution in expression

asked 2013-05-18 06:57:53 +0100

vdelecroix gravatar image

updated 2013-05-18 10:23:18 +0100

Hi,

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

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

Which becomes even more funny with

sage: SR(2).subs(SR(2) == pi)
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

Comments

Perhaps such a feature could be used for the [variation of constants](http://en.wikipedia.org/wiki/Variation_of_constants) method :p

tmonteil gravatar imagetmonteil ( 2013-05-19 07:52:42 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-05-22 07:12:29 +0100

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

Comments

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

vdelecroix gravatar imagevdelecroix ( 2013-05-22 09:37:47 +0100 )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

Stats

Asked: 2013-05-18 06:57:53 +0100

Seen: 2,363 times

Last updated: May 22 '13