Skip to main content

GF2Matrix

Struct GF2Matrix 

Source
pub struct GF2Matrix { /* private fields */ }
Expand description

A matrix over GF(2), stored as row vectors.

Supports Gaussian elimination, rank computation, null space extraction, and matrix-vector multiplication — all via bitwise operations.

Implementations§

Source§

impl GF2Matrix

Source

pub fn zero(nrows: usize, ncols: usize) -> Self

Create a zero matrix.

Source

pub fn identity(n: usize) -> Self

Create an identity matrix.

Source

pub fn from_rows(rows: Vec<GF2Vector>) -> Self

Create from row vectors. All rows must have the same dimension.

Source

pub fn nrows(&self) -> usize

Number of rows.

Source

pub fn ncols(&self) -> usize

Number of columns.

Source

pub fn get(&self, row: usize, col: usize) -> GF2

Get element at (row, col).

Source

pub fn set(&mut self, row: usize, col: usize, value: GF2)

Set element at (row, col).

Source

pub fn row(&self, i: usize) -> &GF2Vector

Get a reference to row i.

Source

pub fn mul_vec(&self, v: &GF2Vector) -> GF2Vector

Matrix-vector product over GF(2).

Source

pub fn mul_mat(&self, other: &Self) -> Self

Matrix-matrix product over GF(2).

Source

pub fn transpose(&self) -> Self

Transpose.

Source

pub fn reduced_row_echelon(&mut self) -> Vec<usize>

Reduced row echelon form (in-place). Returns pivot column indices.

Source

pub fn row_echelon(&mut self) -> Vec<usize>

Row echelon form (in-place). Returns pivot column indices.

Over GF(2), this produces the same result as reduced_row_echelon since the elimination above and below is equivalent when the only nonzero scalar is 1.

Source

pub fn rank(&self) -> usize

Rank = number of pivots.

Source

pub fn null_space(&self) -> Vec<GF2Vector>

Null space basis vectors (kernel of the matrix).

Source

pub fn determinant(&self) -> CoreResult<GF2>

Determinant (only for square matrices).

Source

pub fn column_space(&self) -> Vec<GF2Vector>

Column space basis vectors (image of the matrix).

Source

pub fn in_column_space(&self, v: &GF2Vector) -> bool

Check if a vector is in the column space.

Source

pub fn solve(&self, b: &GF2Vector) -> Option<GF2Vector>

Solve Ax = b over GF(2). Returns None if no solution exists.

Source

pub fn augment(&self, b: &GF2Vector) -> Self

Augmented matrix [A | b].

Source

pub fn hcat(&self, other: &Self) -> Self

Horizontal concatenation [A | B].

Trait Implementations§

Source§

impl Clone for GF2Matrix

Source§

fn clone(&self) -> GF2Matrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GF2Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for GF2Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GF2Matrix

Source§

fn eq(&self, other: &GF2Matrix) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for GF2Matrix

Source§

impl StructuralPartialEq for GF2Matrix

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.