update quotient to ensure ideal defined with a grobner basis

This commit is contained in:
2026-04-22 23:53:21 +02:00
parent fb12ec3819
commit fe163b74b4
2 changed files with 21 additions and 10 deletions

View File

@@ -1,20 +1,32 @@
use super::dag::{Circuit, Node, NodeId}; use super::dag::{Circuit, Node, NodeId};
use crate::poly::{flat::Poly, var::Var}; use crate::poly::{
flat::Poly,
use itertools::Itertools; ideal::{Generators, GroebnerBasis, Ideal},
var::Var,
};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Quotient<V: Var> { pub struct Quotient<V: Var> {
basis: Vec<Poly<V>>, basis: Ideal<V, GroebnerBasis>,
circuit: Circuit<V>, circuit: Circuit<V>,
} }
impl<V: Var> From<Ideal<V, GroebnerBasis>> for Quotient<V> {
fn from(basis: Ideal<V, GroebnerBasis>) -> Self {
Quotient {
basis,
circuit: Default::default(),
}
}
}
impl<V: Var> FromIterator<Poly<V>> for Quotient<V> { impl<V: Var> FromIterator<Poly<V>> for Quotient<V> {
fn from_iter<T: IntoIterator<Item = Poly<V>>>(iter: T) -> Self { fn from_iter<T: IntoIterator<Item = Poly<V>>>(iter: T) -> Self {
let ideal: Ideal<V, Generators> = iter.into_iter().collect();
Quotient { Quotient {
basis: iter.into_iter().collect(), basis: ideal.groebner_basis(),
circuit: Default::default(), circuit: Default::default(),
} }
} }
@@ -22,11 +34,7 @@ impl<V: Var> FromIterator<Poly<V>> for Quotient<V> {
impl<V: Var> Display for Quotient<V> { impl<V: Var> Display for Quotient<V> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!( write!(fmt, "C/{}", self.basis)
fmt,
"C/<{}>",
self.basis.iter().map(|p| format!("{p}")).join(",")
)
} }
} }

View File

@@ -5,11 +5,14 @@ use super::flat::Poly;
use super::var::Var; use super::var::Var;
/// Marker: the ideal's generators are arbitrary polynomials. /// Marker: the ideal's generators are arbitrary polynomials.
#[derive(Clone, Debug)]
pub struct Generators; pub struct Generators;
/// Marker: the ideal's generators form a Gröbner basis. /// Marker: the ideal's generators form a Gröbner basis.
#[derive(Clone, Debug)]
pub struct GroebnerBasis; pub struct GroebnerBasis;
#[derive(Clone, Debug)]
pub struct Ideal<V: Var, S> { pub struct Ideal<V: Var, S> {
generators: Vec<Poly<V>>, generators: Vec<Poly<V>>,
_state: PhantomData<S>, _state: PhantomData<S>,