# Two questions about parameters in solutions

In the Sage documentation, this example is given:

 sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols


of a solution which includes an extra parameter:

[[x=?r1+3,y=r1]]

1. If I run this comand again, the solution is given with r2, then again with r3 etc. Is it possible to "reset" the parameter number?
2. How does one substitute a particular value for this parameter? I can do it by iterating through the list and using rhs():

[i.rhs().subs(r1=1/2) for i in sols]


or by setting solution_dict=True and fiddling another way:

[sols[i].subs(r1=1/2) for i in [x,y]]


Neither of these seem particularly elegant - is there a more "natural" way?

edit retag close merge delete

Sort by ยป oldest newest most voted

Tab-completion was my friend for this:

sage: var("y")
y
sage: sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
[[x == -r1 + 3, y == r1]]
sage: sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
[[x == -r2 + 3, y == r2]]
sage: maxima_calculus.reset()
[multiplicities,%rnum,lispdisp,%rnum_list]
sage: sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
[[x == -r1 + 3, y == r1]]


Note that you may get different things in the reset depending on how many computations you've done already. I suppose one could even go into the depths of the lisp interface and reset just %rnum and %rnumlist but I didn't want to do that.

Unfortunately, I don't think there is any more elegant way to do what you want - the solutions are lists by design. In some sense this is a feature, not a bug... though one it would be nice to do more easily. Maybe map is your friend here, though I doubt it would be fewer characters to type.

more