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

Make solution_dict the default output for solve #10213

Open
sagetrac-olazo mannequin opened this issue Nov 4, 2010 · 4 comments
Open

Make solution_dict the default output for solve #10213

sagetrac-olazo mannequin opened this issue Nov 4, 2010 · 4 comments

Comments

@sagetrac-olazo
Copy link
Mannequin

sagetrac-olazo mannequin commented Nov 4, 2010

This is what mathematica does, and a much easier way to work with the results than getting an equation.

This has been discussed in:

http://groups.google.com/group/sage-devel/browse_thread/thread/93a9897c35ea0d80

Component: symbolics

Keywords: solve, solution_dict

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

@sagetrac-olazo sagetrac-olazo mannequin added this to the sage-5.11 milestone Nov 4, 2010
@sagetrac-olazo sagetrac-olazo mannequin self-assigned this Nov 4, 2010
@kcrisman
Copy link
Member

kcrisman commented Nov 4, 2010

comment:1

Question: will this confused people who have never seen a dict before? After all, that is a large part of who is using this functionality (based on sage-support requests).

@mwhansen
Copy link
Contributor

mwhansen commented Nov 4, 2010

comment:2

Also, it possibly breaks a lot of existing code. There should be some thought put in before this happens.

@jasongrout
Copy link
Member

comment:3

+1 to thinking. I think it probably warrants a different function name than solve, or maybe just a different syntax for calling solve.

I don't think it will confuse people who haven't seen a dict. The output would look like this:

[{x: 3, y: 4}, {x: 1, y: 5}]

which I think is very understandable.

@kcrisman
Copy link
Member

comment:4

Here is an idea from Jeff Denny which is related.

def get_solns(eqtns,vars):
   return map(lambda t: map(lambda x: x.rhs(), t),solve(eqtns,vars))

With examples here:


var('x,y,z') 
       	
(x, y, z)
Usual method for getting solutions out of the solve command

 s=solve([x+y==1,-2*x+y==0],[x,y])
s 
       	
[[x == (1/3), y == (2/3)]]
s[0] 
       	
[x == (1/3), y == (2/3)]
s[0][0].rhs(),s[0][1].rhs() 
       	
(1/3, 2/3)
Another approach to get solutions out of the solve command

Produces a list of solutions (order corresponds to that of the variables input into vars).

 def get_solns(eqtns,vars):
    return map(lambda t: map(lambda x: x.rhs(), t),solve(eqtns,vars)) 
       	
get_solns([x^2+y==1,-2*x+y==0],[x,y]) 
       	
[[-sqrt(2) - 1, -2*sqrt(2) - 2], [sqrt(2) - 1, 2*sqrt(2) - 2]]
get_solns([3*x+y+z==1,x+y==5,7*x^3-y+2*z==4],[x,y,z]) 
       	
[[-0.725116922845 - 1.0718265843*I, 5.72511692285 + 1.0718265843*I,
-2.54976615431 + 2.14365316861*I], [-0.725116922845 +
1.0718265843*I, 5.72511692285 - 1.0718265843*I, -2.54976615431 -
2.14365316861*I], [1.45023380094, 3.54976619906, -6.90046760187]]

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@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

5 participants