Opened 10 years ago

# Make solution_dict the default output for solve

Reported by: Owned by: olazo olazo minor sage-6.4 symbolics solve, solution_dict N/A

### Description

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

This has been discussed in:

### comment:1 Changed 10 years ago by kcrisman

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).

### comment:2 Changed 10 years ago by mhansen

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

### comment:3 Changed 10 years ago by jason

+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.

### comment:4 Changed 10 years ago by kcrisman

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]]
```

### comment:5 Changed 8 years ago by jdemeyer

• Milestone changed from sage-5.11 to sage-5.12

### comment:6 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.1 to sage-6.2

### comment:7 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

### comment:8 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.3 to sage-6.4
Note: See TracTickets for help on using tickets.