First time here? Check out the FAQ!

Ask Your Question
0

substitution in expression

asked 11 years ago

vdelecroix gravatar image

updated 11 years ago

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 !

Preview: (hide)

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 ( 11 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 11 years ago

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.

Preview: (hide)
link

Comments

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

vdelecroix gravatar imagevdelecroix ( 11 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

Stats

Asked: 11 years ago

Seen: 2,386 times

Last updated: May 22 '13