From 413ac5b8211297249cefea00c542c4b7bb7a9263 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..6a0a41f4e 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()); + complement.add_vectors(|mut row| { + let mut i = 0; + while i < self.ambient_dimension() { + i += 1; + if !self.pivots().contains(&(i as isize - 1)) { + 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());