Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle substitutions of partial sums and products #18396

Open
videlec opened this issue May 10, 2015 · 7 comments
Open

Handle substitutions of partial sums and products #18396

videlec opened this issue May 10, 2015 · 7 comments

Comments

@videlec
Copy link
Contributor

videlec commented May 10, 2015

Sage is not able to identify partial sum in a substitution

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

Similarly with products

sage: f = x * cos(x) * sin(x)
sage: f.subs( cos(x) * sin(x) == y)
x*cos(x)*sin(x)

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 substitute and potentially implement partial sum and product substitutions.

See also #10049 and ​http://ask.sagemath.org/question/25972/substitute-xy-by-u/ (with related ticket #17879)

CC: @orlitzky @mezzarobba

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/18396

@videlec videlec added this to the sage-6.7 milestone May 10, 2015
@videlec

This comment has been minimized.

@nbruin
Copy link
Contributor

nbruin commented May 10, 2015

comment:2

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.

The thing is: x+x^2 isn't a syntactical subunit of x + x^2 + x^4 for the internal representation, which is roughly ('+',x,('^',x,2)) versus ('+',x,('<sup>',x,2),('</sup>',x,4))

You'll have to decide how much tricks are worthwhile to implement before you just add the relation y-(x^2+x) and ask for elimination of x via groebner bases.

@videlec
Copy link
Contributor Author

videlec commented May 10, 2015

comment:3

Replying to @nbruin:

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.

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 'ac' as a unit in 'abcd'. This is perhaps not desirable though.

The thing is: x+x^2 isn't a syntactical subunit of x + x^2 + x^4 for the internal representation, which is roughly ('+',x,('^',x,2)) versus ('+',x,('<sup>',x,2),('</sup>',x,4))

I know, and this is precisely the purpose of the ticket.

You'll have to decide how much tricks are worthwhile to implement before you just add the relation y-(x^2+x) and ask for elimination of x via groebner bases.

Note that x + y - (u + v) does not exist. But I agree that there is an ambiguous +/- issue (as far as the ticket description is concerned).

@mezzarobba

This comment has been minimized.

@rwst
Copy link

rwst commented Aug 10, 2017

comment:5

However, even the whole matching does not work consistently. See pynac/pynac#269

@videlec

This comment has been minimized.

@mkoeppe mkoeppe removed this from the sage-6.7 milestone Dec 29, 2022
@EmmanuelCharpentier
Copy link
Contributor

EmmanuelCharpentier commented Feb 19, 2024

Of note :

sage: f=x+x^2+x^4
sage: f.subs(x+x^2==y)
x^4 + x^2 + x
sage: f._sympy_().subs(sympy.sympify({x+x^2:y}))._sage_()
x^4 + y

This suggests that an algorithm="sympy" keyword (or alternatively deep=True) might switch to the behavious expected by Maple/Sympy/Mathematica users...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants