Skip to content

Feature request: Reduced Row Echelon Form #35

Open

Description

Reduced Row Ecehelon form is a common linear algebra expression that I was surprised was not included in the Matrix gem already. I came upon the need for it while solving today's Advent of Code problem.

Proposed use:

matrix = Matrix[
  [94, 22, 8400],
  [34, 67, 5400]
]

matrix.rref # =>
[ 
  [1, 0, 80],
  [0, 1, 40]
]

Edge cases:

  • Infinite/multiple solutions
  • No solution
  • Invalid Matrixes containing non-numbers

Before we put in the efforts to add this instance method, I'm wondering if this is something worth adding and how we would want to handle the outputs of the edge cases.

Activity

  1. wtn commented on Nov 16, 2026

    @wtn

    The example above can already be solved using Matrix#lup:

    a = Matrix[[94, 22], [34, 67]]
    b = [8400, 5400]
    
    a.lup.solve(b) #=> Vector[(80/1), (40/1)]

    With Integer entries the result is exact. solve raises Matrix::ErrNotRegular when the system has no solution or more than one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions