Sage: Ticket #18396: Handle substitutions of partial sums and products
https://trac.sagemath.org/ticket/18396
<p>
Sage is not able to identify partial sum in a substitution
</p>
<pre class="wiki">sage: var('x,y')
sage: f = x + x^2 + x^4
sage: f.subs(x^2 == y) # one term is fine
x^4 + x + y
sage: f.subs(x + x^2 == y) # partial sum does not work
x^4 + x^2 + x
sage: f.subs(x + x^2 + x^4 == y) # whole sum is fine
y
</pre><p>
Similarly with products
</p>
<pre class="wiki">sage: f = x * cos(x) * sin(x)
sage: f.subs( cos(x) * sin(x) == y)
x*cos(x)*sin(x)
</pre><p>
As mentioned in the doc, this is the same behavior as in Maple but differ from Mathematica. We should be clearer on the semantic of <code>substitute</code> and potentially implement partial sum and product substitutions.
</p>
<p>
See also <a class="closed ticket" href="https://trac.sagemath.org/ticket/10049" title="enhancement: improve documentation of substitute for symbolic expressions (closed: fixed)">#10049</a> and <a class="ext-link" href="http://ask.sagemath.org/question/25972/substitute-xy-by-u/"><span class="icon"></span>http://ask.sagemath.org/question/25972/substitute-xy-by-u/</a> (with related ticket <a class="closed ticket" href="https://trac.sagemath.org/ticket/17879" title="defect: wrong ex.substitution of x*y (closed: wontfix)">#17879</a>)
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/18396
Trac 1.1.6vdelecroixSun, 10 May 2015 16:24:16 GMTdescription changed
https://trac.sagemath.org/ticket/18396#comment:1
https://trac.sagemath.org/ticket/18396#comment:1
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/18396?action=diff&version=1">diff</a>)
</li>
</ul>
TicketnbruinSun, 10 May 2015 16:47:22 GMT
https://trac.sagemath.org/ticket/18396#comment:2
https://trac.sagemath.org/ticket/18396#comment:2
<p>
I'm not so sure we have to do more than document it. Obviously you cannot expect substitutions to happen on any "equal" subexpression, since that concept isn't well-defined.
</p>
<p>
The thing is: <code>x+x^2</code> isn't a syntactical subunit of <code>x + x^2 + x^4</code> for the internal representation, which is roughly <code>('+',x,('^',x,2))</code> versus <code>('+',x,('^',x,2),('^',x,4))</code>
</p>
<p>
You'll have to decide how much tricks are worthwhile to implement before you just add the relation <code>y-(x^2+x)</code> and ask for elimination of x via groebner bases.
</p>
TicketvdelecroixSun, 10 May 2015 18:52:47 GMT
https://trac.sagemath.org/ticket/18396#comment:3
https://trac.sagemath.org/ticket/18396#comment:3
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/18396#comment:2" title="Comment 2">nbruin</a>:
</p>
<blockquote class="citation">
<p>
I'm not so sure we have to do more than document it. Obviously you cannot expect substitutions to happen on any "equal" subexpression, since that concept isn't well-defined.
</p>
</blockquote>
<p>
I do not want to substitute "equal" subexpression but only identical ones. And doing so, I want to consider 'a+c' as a unit of 'a+b+c+d' and 'a*c' as a unit in 'a*b*c*d'. This is perhaps not desirable though.
</p>
<blockquote class="citation">
<p>
The thing is: <code>x+x^2</code> isn't a syntactical subunit of <code>x + x^2 + x^4</code> for the internal representation, which is roughly <code>('+',x,('^',x,2))</code> versus <code>('+',x,('^',x,2),('^',x,4))</code>
</p>
</blockquote>
<p>
I know, and this is precisely the purpose of the ticket.
</p>
<blockquote class="citation">
<p>
You'll have to decide how much tricks are worthwhile to implement before you just add the relation <code>y-(x^2+x)</code> and ask for elimination of x via groebner bases.
</p>
</blockquote>
<p>
Note that <code>x + y - (u + v)</code> does not exist. But I agree that there is an ambiguous <code>+/-</code> issue (as far as the ticket description is concerned).
</p>
TicketmmezzarobbaThu, 03 Sep 2015 12:35:36 GMTdescription changed
https://trac.sagemath.org/ticket/18396#comment:4
https://trac.sagemath.org/ticket/18396#comment:4
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/18396?action=diff&version=4">diff</a>)
</li>
</ul>
TicketrwsThu, 10 Aug 2017 13:19:05 GMT
https://trac.sagemath.org/ticket/18396#comment:5
https://trac.sagemath.org/ticket/18396#comment:5
<p>
However, even the <code>whole matching</code> does not work consistently. See <a class="ext-link" href="https://github.com/pynac/pynac/issues/269"><span class="icon"></span>https://github.com/pynac/pynac/issues/269</a>
</p>
TicketvdelecroixThu, 10 Aug 2017 14:26:59 GMTdescription changed
https://trac.sagemath.org/ticket/18396#comment:6
https://trac.sagemath.org/ticket/18396#comment:6
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/18396?action=diff&version=6">diff</a>)
</li>
</ul>
Ticket