This blog post is about my first python package, RationalAlgebra. I made it for a small project I’m working on that requires some linear algebra operations. Specifically it requires forming a large square matrix of integers, and finding the matrix inverse of it. However, Python’s main matrix package numpy returns the result as floating point numbers.

These floating point numbers have small errors, which are undesirable. To remedy this, I wrote a Python package that performs matrix operations but returns the results as rational numbers.

These results are exact, so no rounding or estimating is required!

The package provides other features, such as:

  • Row and column vectors of rational numbers
  • Operations between matricies and vectors (as well as other combinations).
    • Addition
    • Scalar multiplication
    • Matrix multiplication
  • LU decomposition
  • Testing
    • Automatic testing is provided by the test_basic.py script.

In the future, I want to add features such as:

  • Non-square matrices
  • Convenience functions
    • Getters and setters
    • Transpose
    • Matrix/vectors of zeros/ones

Feel free to try out the package, and let me know how it goes!

References

Cover photo by Chris Liverani on Unsplash