lin_algebra

Crates.iolin_algebra
lib.rslin_algebra
version0.3.1
created_at2025-06-30 00:33:12.730934+00
updated_at2026-01-13 13:06:45.995042+00
descriptionA linear algebra package to compute image, kernel and rank of linear applications.
homepagehttps://github.com/LucaBonamino/lin_algebra
repositoryhttps://github.com/LucaBonamino/lin_algebra
max_upload_size
id1731268
size30,282
Luca (LucaBonamino)

documentation

README

lin_algebra

A Rust library for linear algebra.

Features

All operations are currently implemented for matrices over GF(2):

  • Compute the echelon form of a matrix along with the history of all the row operations applied.
  • Compute the rank of the linear application represented by a matrix.
  • Compute the kernel of the linear application represented by a matrix.
  • Compute the image of the linear application represented by a matrix.
  • Solve system of equations in GF(2).

Installation

Add the dependency to your Cargo.toml:

[dependencies]
lin_algebra = "0.3.1"

Usage

use lin_algebra::gf2_matrix::GF2Matrix;
use lin_algebra::matrix::MatrixTrait;

fn main() {
    // Reduces echelon form

    let gf2_mat = gf2_matrix::GF2Matrix::new(
        vec![vec![1,0,0,0], vec![0,1,0,1], vec![0,1,0,1]]
    )
    let (educed_echelon_form, row_operations) = gf2_mat.echelon_form();

    println!("Reduces echelon form {:?}", educed_echelon_form);
    println!(
        "Row operation applied to reach the reduces echelon form {:?}", row_operations
    );

    // Kernel
    println!("Kenel {:?}", gf2_mat.kernel());

    // Image
    println!("Image {:?}", gf2_mat.image());

    // Rank
    println!("Rank {}", gf2_mat.rank());

    // Solve M x = b
    let b = vec![1,0,0,1]
    println!("x: {:?}", gf2_mat.solve(&b));

    // Solve A X = Y
    let y_matrix = gf2_matrix::GF2Matrix::new(
        vec![vec![1,0,0,1], vec![1,1,0,1], vec![0,1,0,1]]
    )
    println!("x: {:?}", gf2_mat.solve_matrix_system(&y_matrix));

}

License

MIT

Python bindings

Python bindings are provided in the separate project gf2_lin_algebra.

They are intentionally limited to GF(2) and focus on performance and simplicity. The Rust crate lin_algebra is designed to be more general.

Roadmap

This project is under active development, with a focus on both research and practical use.

Current and planned directions include:

  • improving the internal design of GF(2) matrices
  • adding optimized representations (e.g. bit-packed storage)
  • generalizing the Rust core to support linear algebra over arbitrary fields

The Python bindings (gf2_lin_algebra) are intentionally limited to GF(2), while the Rust crate (lin_algebra) aims to be more general.

For a detailed list of planned improvements and areas where help is welcome, see ROADMAP.md.

Contributing

Contributions are welcome!

Please see CONTRIBUTING.md for guidelines.

Commit count: 28

cargo fmt