# How can I get back an expression for free variables in solve function.

I have a number of linear equations on some symbols A,B,C,D,E,F,G. When I solve them in Sagemath, I get some free variables in the solution.

$A,B,C,D,E,F,G=var('A,B,C,D,E,F,G')$

$eqns=[A+B==0,C+D+E==0,F+G==0,A+E-F==0]$

$solution=solve(eqns,A,B,C,D,E,F,G)$

Sage gives the following solution: $[[A == r1, B == -r1, C == r1 - r2 - r3, D == r3, E == -r1 + r2, F == r2, G == -r2]]$

Now I can ask Sage to give me an expression of any combination of the symbols, for example: $(A+C).subs(solution)$, then I get $2*r1 - r2 - r3$. For my purpose I would now like to have an expression for any of the free variables. If I assign $r1=var('r1')$ and ask Sage $s1.subs(solution)$ I get back $r1$ again. But I would lik to get back an expression in terms of $A,B,C,D,E,F,G$. Any suggestions on how to do this?

I am not sure to fully understand your question, but I also think that it is not well-defined. In your example, you want to express

`r1`

in terms of the variables`A`

to`G`

. But you can write`r1`

in several manners:`r1 = A`

works, as well as`r1 = -B`

or`r1 = C + D - F`

, etc. So it is not clear to me which answer you are looking for.Yes, I can see that. And I would just like to have one of these solutions, but probably this is not possible. The reason I am looking for this is that I have a C-vectorspace defined over some symbols (in this case, just a random example, the symbols A,B,C,D,E,F,G) and I want to quotient this space by a space spanned by some linear combinations of these symbols (in this case A+B==0, etc). When I did this by hand, I used the solved function, and could then see that a basis for my quotient space would be <a,-g,d>. To implement this process, I thought of also using the solve function, but it needs to give me an expression for the free variables. But probably this is not really the right approach :)

You may use the

`VectorSpace`

constructions (I do not know this well...) :See more in the doc.

Yes that sounds nice. Any idea how to get rid of the many zeros?

Do you mean the trailing zeroes in each value? Using the field

`CC`

, this is the standard display. There has been an attempt to make this standard display customizable but it never converged. Two options for you if you want a different way of displaying the results: Either you work over another field, such as`CDF`

(Complex Double Field) or`CIF`

(Complex Interval Field) which have different behaviors, including a different display. Or you print yourself the result, using`format`

. For instance, if you have the element`x = 1.00000000000000`

,`print("{:.4}".format(x))`

prints`x`

as a string of length 4, that is`1.00`

.