Sage FDV Free and Dependent Variables

Sage has the matrix method .pivot() to quickly and easily identify the pivot columns of the reduced row-echelon form of a matrix. Notice that we do not have to row-reduce the matrix first, we just ask which columns of a matrix $A$ would be the pivot columns of the matrix $B$ that is row-equivalent to $A$ and in reduced row-echelon form. By Definition IDV, the indices of the pivot columns for an augmented matrix of a system of equations are the indices of the dependent variables. And the remainder are free variables. But be careful, Sage numbers columns starting from zero and mathematicians typically number variables starting from one.

Let us reprise Example ISSI.



So, incrementing each column index by 1 gives us the same set $D$ of indices for the dependent variables. To get the free variables, we can use the following code. Study it and then read the explanation following.



This is a Python programming construction known as a “list comprehension” but in this setting I prefer to call it “set builder notation.” Let us dissect the command in pieces. The brackets ([,]) create a new list. The items in the list will be values of the variable index. range(7) is another list, integers starting at 0 and stopping just before 7. (While perhaps a bit odd, this works very well when we consistently start counting at zero.) So range(7) is the list [0,1,2,3,4,5,6]. Think of these as candidate values for index, which are generated by for index in range(7). Then we test each candidate, and keep it in the new list if it is not in the list dependent.

This is entirely analogous to the following mathematics:

\begin{align*} F &= \setparts{f}{1\leq f\leq 7, f\not\in D} \end{align*}

where $F$ is free, $f$ is index, and $D$ is dependent, and we make the 0/1 counting adjustments. This ability to construct sets in Sage with notation so closely mirroring the mathematics is a powerful feature worth mastering. We will use it repeatedly.

It was a good exercise to use a list comprehension to form the list of columns that are not pivot columns. However, Sage has us covered.



Can you use this new matrix method to make a simpler version of the consistent() function we designed above?