Naming a set of equality equations Python
<p>I am currently working on solving a system of equations. </p>

<p>A subset of the equations are: </p>

<pre><code>eq1  = pi1  * q[0+1] == pi0 * r[0+1]
eq2  = pi2  * q[0+1] == pi0 * r[1+1]  + pi1 * r[1+1]
eq3  = pi3  * q[0+1] == pi0 * r[2+1]  + pi1 * r[2+1]  + pi2 * r[1+1]
eq4  = pi4  * q[0+1] == pi0 * r[3+1]  + pi1 * r[3+1]  + pi2 * r[2+1]  + pi3 * r[1+1]
eq5  = pi5  * q[0+1] == pi0 * r[4+1]  + pi1 * r[4+1]  + pi2 * r[3+1]  + pi3 * r[2+1]  + pi4 * r[1+1]
eq6  = pi6  * q[0+1] == pi0 * r[5+1]  + pi1 * r[5+1]  + pi2 * r[4+1]  + pi3 * r[3+1]  + pi4 * r[2+1]  + pi5 * r[1+1]
eq7  = pi7  * q[0+1] == pi0 * r[6+1]  + pi1 * r[6+1]  + pi2 * r[5+1]  + pi3 * r[4+1]  + pi4 * r[3+1]  + pi5 * r[2+1]  + pi6 * r[1+1]
</code></pre>

<p>Unfortunately, this is not working the way I want it to be working. I want it to be read as follows: the first equation has the name 'eq1' and has a certain equality equation. The other lines should be read similarly. In my code I have 14 more equations which are even longer. I want to give them a name to avoid really long expressions in "solve([], [])" . </p>

<p>Is this possible? And if so, how should it be done?</p>

<p>You can store the equations in a dictionary - you will be mapping index of the equation (1, 2, etc) to a tuple, which will contain two items representing two sides of the equation. </p>

<pre><code>equations = dict()
equations[1]  = (pi1  * q[0+1], pi0 * r[0+1])
</code></pre>

<p>You can then call <code>solve(equations[1])</code> and in the <code>solve()</code> fuction do something like this:</p>

<pre><code>def solve(equation):
    left_side_of_equation = equation[0]
    right_side_of_equation = equation[1]
    # Here do everything you need with this equation values.
</code></pre>

<p>Or call function like this: <code>solve(equations[1][0], equations[1][1])</code> and have two parameters in the <code>solve()</code> function.</p>

<p>Edit to answer comment:</p>

<p>If you want to have more than equations with just <code>==</code> (greater, greater equal etc.) you need to save this information in the tuple as well. It can look like this:</p>

<pre><code>equations[42] = (pi1, 0, "ge")
</code></pre>

<p>and implement <code>solve()</code> function like this:</p>

<pre><code>def solve(equation):
    left_side_of_equation = equation[0]
    right_side_of_equation = equation[1]
    operator = equation[2]
    if operator == "ge": # Greater or equal
        # Do your comparison
    elif operator == "g": # Greater
        # Do your comparison
    # Add all remaining possibilities.
</code></pre>

python equality sympy equation