From fe163b74b48b0fd187a90ed50c004b70b6a38441 Mon Sep 17 00:00:00 2001 From: asteri Date: Wed, 22 Apr 2026 23:53:21 +0200 Subject: [PATCH] update quotient to ensure ideal defined with a grobner basis --- src/circuit/quotient.rs | 28 ++++++++++++++++++---------- src/poly/ideal.rs | 3 +++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/circuit/quotient.rs b/src/circuit/quotient.rs index 1328ee5..f5c86c4 100644 --- a/src/circuit/quotient.rs +++ b/src/circuit/quotient.rs @@ -1,20 +1,32 @@ use super::dag::{Circuit, Node, NodeId}; -use crate::poly::{flat::Poly, var::Var}; - -use itertools::Itertools; +use crate::poly::{ + flat::Poly, + ideal::{Generators, GroebnerBasis, Ideal}, + var::Var, +}; use std::fmt::{self, Display}; #[derive(Clone, Debug)] pub struct Quotient { - basis: Vec>, + basis: Ideal, circuit: Circuit, } +impl From> for Quotient { + fn from(basis: Ideal) -> Self { + Quotient { + basis, + circuit: Default::default(), + } + } +} + impl FromIterator> for Quotient { fn from_iter>>(iter: T) -> Self { + let ideal: Ideal = iter.into_iter().collect(); Quotient { - basis: iter.into_iter().collect(), + basis: ideal.groebner_basis(), circuit: Default::default(), } } @@ -22,11 +34,7 @@ impl FromIterator> for Quotient { impl Display for Quotient { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!( - fmt, - "C/<{}>", - self.basis.iter().map(|p| format!("{p}")).join(",") - ) + write!(fmt, "C/{}", self.basis) } } diff --git a/src/poly/ideal.rs b/src/poly/ideal.rs index 718148e..04c9a11 100644 --- a/src/poly/ideal.rs +++ b/src/poly/ideal.rs @@ -5,11 +5,14 @@ use super::flat::Poly; use super::var::Var; /// Marker: the ideal's generators are arbitrary polynomials. +#[derive(Clone, Debug)] pub struct Generators; /// Marker: the ideal's generators form a Gröbner basis. +#[derive(Clone, Debug)] pub struct GroebnerBasis; +#[derive(Clone, Debug)] pub struct Ideal { generators: Vec>, _state: PhantomData,