From 491177dd1fa5331d9e60bde9bd2f6c6491f22bd4 Mon Sep 17 00:00:00 2001 From: Joey Beauvais-Feisthauer Date: Thu, 6 Jul 2023 13:31:08 -0400 Subject: [PATCH] Add `Subspace::complement` --- ext/crates/fp/src/matrix/subspace.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ext/crates/fp/src/matrix/subspace.rs b/ext/crates/fp/src/matrix/subspace.rs index 29223cd26..4255c2989 100644 --- a/ext/crates/fp/src/matrix/subspace.rs +++ b/ext/crates/fp/src/matrix/subspace.rs @@ -134,6 +134,24 @@ impl Subspace { } } + /// Returns a complementary space to `self`. + pub fn complement(&self) -> Subspace { + let dimension = self.ambient_dimension() - self.dimension(); + let mut complement = Subspace::new(self.prime(), dimension, self.ambient_dimension()); + let mut i = 0; + complement.add_vectors(|mut row| { + while i < self.ambient_dimension() { + i += 1; + if self.pivots()[i - 1] < 0 { + row.set_entry(i - 1, 1); + return Some(()); + } + } + None + }); + complement + } + pub fn contains(&self, vector: Slice) -> bool { let mut vector: FpVector = vector.into_owned(); self.reduce(vector.as_slice_mut());