let gauss_elim (a : int array array) (b : int array array) =
  let height  = Array.length(a)     in
  let ro      = generate_row_ordering height  in
  if height=0 then
    ro
  else
    let row = ref 0
    in
    for col = 0 to (min (Array.length(a.(0))) height)-1 do
      (* do pivot search and test if it was successful *)
      if pivot ro a !row !row col then
        begin
          (* pivot search was succesfull, otherwise all elements in this column
           * are 0 and nothing has to be done *)

          for row2 = !row+1 to height-1 do
            (* eliminate 1's in column ", i.e. add line !row to every line
             * with a 1 in col ", except to itself *)

            if lookup ro a row2 col = 1 then
              add_lines ro a b row2 !row
          done;
          (* proceed to next row *)
          row := !row + 1
        end
    done;
    (* return the row ordering " *)
    ro