For solve the current output format depends on the input:
sage: var('x y') sage: eq1=x+4==0 sage: eq2=x^2+4*x+2==0 sage: sys1=x+y==1 sage: sys2=x-2*y==-2 sage: solve(eq1,x) [x == -4] A list containing solutions (even when there is only one solution).
sage: solve(eq2,x) [x == -sqrt(2) - 2, x == sqrt(2) - 2] A list containing solutions when there is more than one solution
solve([sys1,sys2],x,y) [[x == 0, y == 1]] A list containing a list containing solutions (this is the worst)
The format I would like to see is:
sage: solve(eq1,x) x == -4 A single equation
sage: solve(eq2,x) [x == -sqrt(2) - 2, x == sqrt(2) - 2] This one is fine
solve([sys1,sys2],x,y) [x == 0, y == 1] Just a list of solutions. It is harder to work with the solutions if they are inside another list.
I would like all of this changes to become standard outputs, although I imagine that that would produce some backwards compatibility issues.
> For solve the current output format depends on the input:
> sage: var('x y') > sage: eq1=x+4==0 > sage: eq2=x^2+4*x+2==0 > sage: sys1=x+y==1 > sage: sys2=x-2*y==-2 > sage: solve(eq1,x) > [x == -4] > A list containing solutions (even when there is only one solution).
> sage: solve(eq2,x) > [x == -sqrt(2) - 2, x == sqrt(2) - 2] > A list containing solutions when there is more than one solution
> solve([sys1,sys2],x,y) > [[x == 0, y == 1]] > A list containing a list containing solutions (this is the worst)
> The format I would like to see is:
> sage: solve(eq1,x) > x == -4 > A single equation
> sage: solve(eq2,x) > [x == -sqrt(2) - 2, x == sqrt(2) - 2] > This one is fine
> solve([sys1,sys2],x,y) > [x == 0, y == 1] > Just a list of solutions. It is harder to work with the solutions if > they are inside another list.
What if there are two different solutions, like (x=0, y=0) and (x=0,y=1)?
Personally, I think returning an equation is okay for situations where I am just checking something, and don't plan on using the solution again. Returning a list of equations is horrible for actually doing anything with the results, which is my intent in the vast majority of situations. Having to always append the not-very-obvious "solution_dict=True" to use solve in the common case is not very user-friendly. If we're changing the output of solve, I'd propose returning either a single dictionary (a single solution) or a list of dictionaries (multiple solutions). Solve seems like it would be much more useful that way.
> Why not make solution_dict=True the default, since then you could say:
> fit=find_fit(data,model)
> model.subs(fit)
> to get the model with those parameters?
> In fact, it would be great if this worked too:
> fit=find_fit(data,model)
> model(**fit)
> but (even if solution_dict=True is the default) that complains that the
> keys in the dictionary are not strings.
> However, we could make this work:
> fit=find_fit(data,model)
> model(fit)
> but it require changes to the __call__ method to allow a dictionary
> input that would do the same as .subs() would do if handed a dictionary.
> > For solve the current output format depends on the input:
> > sage: var('x y')
> > sage: eq1=x+4==0
> > sage: eq2=x^2+4*x+2==0
> > sage: sys1=x+y==1
> > sage: sys2=x-2*y==-2
> > sage: solve(eq1,x)
> > [x == -4]
> > A list containing solutions (even when there is only one solution).
> > sage: solve(eq2,x)
> > [x == -sqrt(2) - 2, x == sqrt(2) - 2]
> > A list containing solutions when there is more than one solution
> > solve([sys1,sys2],x,y)
> > [[x == 0, y == 1]]
> > A list containing a list containing solutions (this is the worst)
> > The format I would like to see is:
> > sage: solve(eq1,x)
> > x == -4
> > A single equation
> > sage: solve(eq2,x)
> > [x == -sqrt(2) - 2, x == sqrt(2) - 2]
> > This one is fine
> > solve([sys1,sys2],x,y)
> > [x == 0, y == 1]
> > Just a list of solutions. It is harder to work with the solutions if
> > they are inside another list.
> What if there are two different solutions, like (x=0, y=0) and (x=0,y=1)?
> Personally, I think returning an equation is okay for situations where I
> am just checking something, and don't plan on using the solution again.
> Returning a list of equations is horrible for actually doing anything
> with the results, which is my intent in the vast majority of situations.
> Having to always append the not-very-obvious "solution_dict=True" to
> use solve in the common case is not very user-friendly. If we're
> changing the output of solve, I'd propose returning either a single
> dictionary (a single solution) or a list of dictionaries (multiple
> solutions). Solve seems like it would be much more useful that way.
> Thanks,
> Jason
Making solution_dict the default seems apropiate for find_fit and
solve. I still would prefer a symbolic result for find_fit though (at
least an option to get that). Usually when one fits some data to a
model what one is trying to do is to interpolate data in between the
current data (plot the fitted function etc). Mathematica uses this two
outputs in two different functions:
As for solve, I agree, we should return a single dictionary when
there's just one solution and a list of dictionaries when there's more
than one solution.
> Making solution_dict the default seems apropiate for find_fit and > solve. I still would prefer a symbolic result for find_fit though (at > least an option to get that). Usually when one fits some data to a > model what one is trying to do is to interpolate data in between the > current data (plot the fitted function etc). Mathematica uses this two > outputs in two different functions:
>> Making solution_dict the default seems apropiate for find_fit and >> solve. I still would prefer a symbolic result for find_fit though (at >> least an option to get that). Usually when one fits some data to a >> model what one is trying to do is to interpolate data in between the >> current data (plot the fitted function etc). Mathematica uses this two >> outputs in two different functions: