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

solve of equation system misses trivial simplifications #16753

Open
rwst opened this issue Aug 4, 2014 · 14 comments
Open

solve of equation system misses trivial simplifications #16753

rwst opened this issue Aug 4, 2014 · 14 comments

Comments

@rwst
Copy link

rwst commented Aug 4, 2014

Some trivial substitutions are not done by solve:

sage: x,y=var('x,y')
sage: solve([y==exp(x),2*y-exp(x)==1],x,y)
[y == e^x, 2*y - e^x == 1]

and, as reported in http://ask.sagemath.org/question/23652/solve-equations-with-sinx/

sage: solve([y==sin(x),y+4*sin(x)==5],x,y)
[y == sin(x), y + 4*sin(x) == 5]

Component: calculus

Author: Akshay Ajagekar

Branch/Commit: u/ajagekar.akshay/Trac16753 @ 88dec5a

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

@rwst rwst added this to the sage-6.3 milestone Aug 4, 2014
@rwst
Copy link
Author

rwst commented Aug 4, 2014

comment:1

Set to critical because it makes Sage look really stupid.

@rwst

This comment has been minimized.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@sagetrac-ajagekar-akshay
Copy link
Mannequin

comment:3

I think it is maxima which is unable to solve the equations and returns

%solve([y = sin(x), y + 4*sin(x) = 5],[x,y])

in this case. Sage converts this to list of solutions. Can we condition sage to return "Unable to solve" instead of returning the equations? while reporting this upstream.

@rwst
Copy link
Author

rwst commented Mar 3, 2016

comment:4

You mean a general change for unsolved equations/relations? That would be a different ticket which you would have to open. I'm not against a change but I'd rather have solve return a set, and in case of unsolved an empty set.

@sagetrac-ajagekar-akshay
Copy link
Mannequin

comment:5

A test which returned initial function instead of solutions was failing

solve([sin(x)==x,y^2==x],x,y)
Expected:
    [sin(x) == x, y^2 == x]
Got:
    []

I have changed that test. Please have a look.

@sagetrac-ajagekar-akshay
Copy link
Mannequin

Branch: u/ajagekar.akshay/Trac16753

@rwst
Copy link
Author

rwst commented Mar 3, 2016

comment:7

Your ticket branch shows MeatAxe changes. Probably you branched not from develop. Use git trac checkout to have a proper start.

@rwst
Copy link
Author

rwst commented Mar 3, 2016

Commit: 1961f94

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 3, 2016

Changed commit from 1961f94 to 88dec5a

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Mar 3, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

88dec5aTrac 16753 : solve of equation system misses trivial simplifications

@sagetrac-ajagekar-akshay
Copy link
Mannequin

comment:9

Sorry for that mistake.

@sagetrac-ajagekar-akshay
Copy link
Mannequin

Author: Akshay Ajagekar

@nbruin
Copy link
Contributor

nbruin commented Mar 4, 2016

comment:11

This solution doesn't fly. Presently:

sage: solve([x==5],[x])
[x == 5]

with this patch, it would return []. That's bad.

In general, I think it's bad to silently returning an empty list in a case where we know we failed to "solve" the system. An empty list can be interpreted as an inconsistent system of equations.

The original behaviour, returning the original system, indicates better a failure to solve than an empty solution list does. Therefore, I think that is preferable.

You could argue that returning the original system would be "invalid" output, because usually it means that the LH sides of the equations aren't the to-be-solved-for variables and/or the RH sides won't be free of them.

In that case, returning an error is a better solution.

I think the parsing that happens for solution_dict=True is definitely broken:

sage: solve([y == sin(x), y + 4*sin(x) == 5],[x,y],solution_dict=True)
[{y: sin(x)}, {y + 4*sin(x): 5}]

Compared with

sage: solve([x^2==5,y==6],[x,y],solution_dict=True)
[{y: 6, x: -sqrt(5)}, {y: 6, x: sqrt(5)}]

it's clearly very misleading output. So for solution_dict=True I think we have a good case for an error. Without it, I think the current output is misleading. But so is:

sage: solve(x-1,x)
[x == 1]
sage: solve([x-1],[x])
[x == 1]
sage: solve([x-1,y-1],[x,y])
[[x == 1, y == 1]]
sage: solve([x-1],[x],solution_dict=True)
TypeError: 'sage.symbolic.expression.Expression' object is not iterable

(we'd probably be better off if also in the single-variable case we'd also return list-of-lists etc.)

Beware of legacy, though. There might be users out there that have grown fond of this bad behaviour and somehow depend on it.

@sagetrac-ajagekar-akshay
Copy link
Mannequin

comment:12
sage: solve([x==5],[x])

returns [x == 5] as expected, the changed code gets executed only for system of equations.
Even for cases like

sage: solve([x==5,y==2],x,y) 

maxima returns list of list as solution [[x == 5, y == 2]], so an empty set is not returned. I also think returning error would be better for unsolved equations. For TypeError, the parsing for solution_dict = True
can be fixed by checking length of variables list and adding appropriate condition.

@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
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

4 participants