def reduced_row_echelon_form(ary)
      lead = 0
      rows = ary.size
      cols = ary[0].size
      rary = convert_to_rational(ary)  # use rational arithmetic
      catch :done  do
        rows.times do |r|
        throw :done  if cols <= lead
          i = r
          while rary[i][lead] == 0
            i += 1
            if rows == i
              i = r
              lead += 1
              throw :done  if cols == lead
            end
          end
          # swap rows i and r 
          rary[i], rary[r] = rary[r], rary[i]
          # normalize row r
          v = rary[r][lead]
          rary[r].collect! {|x| x /= v}
          # reduce other rows
          rows.times do |i|
            next if i == r
            v = rary[i][lead]
            rary[i].each_index {|j| rary[i][j] -= v * rary[r][j]}
          end
          lead += 1
        end
      end
      rary
    end
def reduced_row_echelon_form(ary)
      lead = 0
      rows = ary.size
      cols = ary[0].size
      rary = convert_to_rational(ary)  # use rational arithmetic
      catch :done  do
        rows.times do |r|
        throw :done  if cols <= lead
          i = r
          while rary[i][lead] == 0
            i += 1
            if rows == i
              i = r
              lead += 1
              throw :done  if cols == lead
            end
          end
          # swap rows i and r 
          rary[i], rary[r] = rary[r], rary[i]
          # normalize row r
          v = rary[r][lead]
          rary[r].collect! {|x| x /= v}
          # reduce other rows
          rows.times do |i|
            next if i == r
            v = rary[i][lead]
            rary[i].each_index {|j| rary[i][j] -= v * rary[r][j]}
          end
          lead += 1
        end
      end
      rary
    end
returns an 2-D array where each element is a Rational