(* Elementary Matrices programmed by C C Heckman,
    Spring 1993 for M314H class. *)

EM::usage = "EM performs row operations on a matrix.  See
RowOperations notebook for details."

EM[x_,y_:Infinity,z_:Infinity,a_List] := Block [{b,n=Length[a],i,c},
    Do [b[i] = a [[i]], {i,n}];
    If [y == Infinity && z == Infinity,
        If [Length[x] == 2,
           If [x[[1]] <= n && x[[2]] <= n,
              b[0] = True;
              t = b [x[[1]]];
              b[x[[1]]] = b[x[[2]]];
              b[x[[2]]] = t
              ,
              (* else *) Print ["Exchange routine; invalid rows"]; 
                 b[0] = False
              ]
           ,
           (* else *) Print ["Exchange routine; too many rows"];
           b[0] = False
    ]
    ,
    If [z == Infinity,
        If [y != 0,
            b[x] = y b[x];b[0]=True
            ,
            Print ["Can't multiply row by 0"]; b[0] = False
    ]
    ,
    b[0] = True;
    b[x] = b[x] + z b[y]
    ]];       
If [!b[0], Return[a], c = Table[b[i],{i,n}]; 
                   Print[TableForm[c]];Return[c]]          
]

Print ["Elementary Matrices program CCH, version 93.1.0"]