check reduced grobner basis

This commit is contained in:
2026-04-22 23:45:43 +02:00
parent e22a45926a
commit fb12ec3819
5 changed files with 192 additions and 1 deletions

View File

@@ -24,6 +24,30 @@ pub fn groebner_basis<V: Var>(generators: Vec<Poly<V>>) -> Vec<Poly<V>> {
i += 1;
}
// Minimize: remove any g whose LM is divisible by LM(h) for some other h.
let mut i = 0;
while i < g.len() {
let lm_i = g[i].leading_term_lex().unwrap().0.clone();
let redundant =
(0..g.len()).any(|j| j != i && lm_i.contains(&g[j].leading_term_lex().unwrap().0));
if redundant {
g.remove(i);
} else {
i += 1;
}
}
// Interreduce: replace each generator with its normal form modulo the others.
for i in 0..g.len() {
let others: Vec<Poly<V>> = g
.iter()
.enumerate()
.filter(|(j, _)| *j != i)
.map(|(_, p)| p.clone())
.collect();
g[i] = reduce(&g[i], &others);
}
g
}
@@ -47,7 +71,7 @@ pub fn is_groebner_basis<V: Var>(basis: &[Poly<V>]) -> bool {
/// by the leading monomial of any element in `basis`.
///
/// Uses the pseudo-division remainder and repeats until stable.
fn reduce<V: Var>(f: &Poly<V>, basis: &[Poly<V>]) -> Poly<V> {
pub(crate) fn reduce<V: Var>(f: &Poly<V>, basis: &[Poly<V>]) -> Poly<V> {
let mut p = f.clone();
'outer: loop {