The classification of a type as a (commutative) ring or semiring, its instances, and its
cached operator functions live in Sym.Arith.State, a SymExtension shared by the whole
grind run. This module only stores per-goal solver state, in the structures below, indexed
by the ids assigned by Sym.Arith.classify?.
- p : Poly
- h : EqCnstrProof
- sugar : Nat
- id : Nat
Instances For
- core (a b : Expr) (ra rb : RingExpr) : EqCnstrProof
- coreS (a b : Expr) (sa sb : SemiringExpr) (ra rb : RingExpr) : EqCnstrProof
- superpose (k₁ : Int) (m₁ : Mon) (c₁ : EqCnstr) (k₂ : Int) (m₂ : Mon) (c₂ : EqCnstr) : EqCnstrProof
- simp (k₁ : Int) (c₁ : EqCnstr) (k₂ : Int) (m₂ : Mon) (c₂ : EqCnstr) : EqCnstrProof
- mul (k : Int) (e : EqCnstr) : EqCnstrProof
- div (k : Int) (e : EqCnstr) : EqCnstrProof
- gcd (a b : Int) (c₁ c₂ : EqCnstr) : EqCnstrProof
- numEq0 (k : Nat) (c₁ c₂ : EqCnstr) : EqCnstrProof
Instances For
A polynomial p equipped with a chain of rewrite steps that justifies p = C * input, where
input is the original polynomial and C is the product of the multipliers k₁ of the
.steps in the chain (C = 1 when every step is monic). C ≠ 1 is possible in any ring,
including those with NoNatZeroDivisors; the instance only lets C be cancelled.
From an input polynomial, we use equations (i.e., EqCnstr) as rewriting rules.
For example, consider the following sequence of rewrites for the input polynomial 2*x^2 + x*y
using the equations x - 1 = 0 (c₁) and y - 2 = 0 (c₂).
2*x^2 + x*y | s₁ := .input (2*x^2 + x*y)
= - 2*x*(x - 1)
(2*x + x*y) | s₂ := .step (2*x + x*y) 1 s₁ (-2) x c₁
= - 2*1*(x - 1)
(x*y + 2) | s₃ := .step (x*y + 2) 1 s₂ (-2) 1 c₁
= - 1*y*(x - 1)
(y + 2) | s₄ := .step (y+2) 1 s₃ (-1) y c₁
= - 1*1*(y - 2)
4 | s₅ := .step 4 1 s₄ (-1) 1 c₂
From the chain above, we build the certificate
(-2*x - y - 2)*(x-1) + (-1)*(y-2)
for
4 = (2*x^2 + x*y)
because x-1 = 0 and y-2=0
- input (p : Poly) : PolyDerivation
- step (p : Poly) (k₁ : Int) (d : PolyDerivation) (k₂ : Int) (m₂ : Mon) (c : EqCnstr) : PolyDerivation
p = k₁*d.p + k₂*m₂*c.pThe coefficient
k₁is used because the leading monomial incmay not be monic. Thus, if we follow the chain back to the input polynomial, we have thatp = C * input_pfor aCthat is equal to the product of allk₁s in the chain.C ≠ 1can happen in any ring, butCcan be cancelled only if the ring implementsNoNatZeroDivisors. That is,p = 0impliesinput_p = 0only ifC = 1or the ring implementsNoNatZeroDivisors. Simplifying withcheckCoeffDvd := trueguaranteesC = 1in rings withoutNoNatZeroDivisors, seeMon.findSimp?. Here is a small example where we simplifyx+yusing the equations2*x - 1 = 0(c₁),3*y - 1 = 0(c₂), and6*z + 5 = 0(c₃)x + y + z | s₁ := .input (x + y + z) *2 = - 1*1*(2*x - 1) 2*y + 2*z + 1 | s₂ := .step (2*y + 2*z + 1) 2 s₁ (-1) 1 c₁ *3 = - 2*1*(3*y - 1) 6*z + 5 | s₃ := .step (6*z + 5) 3 s₂ (-2) 1 c₂ = - 1*1*(6*z + 5) 0 | s₄ := .step (0) 1 s₃ (-1) 1 c₃For this chain, we build the certificate
(-3)*(2*x - 1) + (-2)*(3*y - 1) + (-1)*(6*z + 5)for
0 = 6*(x + y + z)Recall that if the ring implement
NoNatZeroDivisors, then the following property holds:∀ (k : Int) (a : α), k ≠ 0 → (intCast k) * a = 0 → a = 0grind can deduce that
x+y+z = 0 - normEq0 (p : Poly) (d : PolyDerivation) (c : EqCnstr) : PolyDerivation
Instances For
A disequality lhs ≠ rhs asserted by the core.
- lhs : Expr
- rhs : Expr
- rlhs : RingExpr
Reified
lhs - rrhs : RingExpr
Reified
rhs - d : PolyDerivation
- ofSemiring? : Option (SemiringExpr × SemiringExpr)
Instances For
Per-goal solver state of a (commutative or not) semiring classified by Sym.Arith.
- denote : PHashMap ExprPtr SemiringExpr
Mapping from Lean expressions to their representations as
SemiringExpr Mapping from variables to their denotations. Remark each variable can be in only one ring.
Mapping from
Exprto a variable representing it.
Instances For
Per-goal solver state of a (commutative or not) ring classified by Sym.Arith.
Mapping from variables to their denotations. Remark each variable can be in only one ring.
Mapping from
Exprto a variable representing it.Mapping from Lean expressions to their representations as
RingExpr
Instances For
Per-goal solver state of a commutative ring: the Gröbner basis machinery.
denoteEntriesisdenoteas aPArrayfor deterministic traversal.- nextId : Nat
Next unique id for
EqCnstrs. - steps : Nat
Number of "steps": simplification and superposition.
- queue : Queue
Equations to process.
The basis is currently just a list. If this is a performance bottleneck, we should use a better data-structure. For examples, we could use a simple indexing for the linear case where we map variable in the leading monomial to
EqCnstr.- diseqs : PArray DiseqCnstr
Disequalities.
- recheck : Bool
If
recheckistrue, then new equalities have been added to the basis since we checked disequalities and implied equalities. Inverse theorems that have been already asserted.
- powIdentityVarCount : Nat
Number of variables for which
PowIdentityequations have been pushed. An equality of the form
c = 0. It is used to simplify polynomial coefficients.- numEq0Updated : Bool
Flag indicating whether
numEq0?has been updated.
Instances For
Per-goal state of the ring solver.
The four arrays are indexed by the ids assigned by Sym.Arith.classify?: rings[i] is the
solver state for Sym.Arith.State.rings[i], and likewise for semirings, ncRings, and
ncSemirings. The Sym.Arith arrays are shared by every goal of the run and only grow, while
a goal uses only some of the rings. To keep the two indexings aligned, an array here is padded
with empty states up to the id being written (see State.modifyRing), and reading an id beyond
the array returns the empty state. Rings a goal never used therefore cost at most an empty
entry, and rings.size ≤ Sym.Arith.State.rings.size always holds.
- rings : Array CommRingState
Solver state of the commutative rings, indexed by
Sym.Arithring id. - semirings : Array SemiringState
Solver state of the commutative semirings, indexed by
Sym.Arithsemiring id. Solver state of the non-commutative rings, indexed by
Sym.Arithid.- ncSemirings : Array SemiringState
Solver state of the non-commutative semirings, indexed by
Sym.Arithid. - steps : Nat
- reportedMaxDegreeIssue : Bool
trueif solver has already reported max degree issue.
Instances For
Solver state of the commutative ring ringId; empty if this goal has not used it yet.
Instances For
Instances For
Solver state of the commutative semiring semiringId; empty if this goal has not used it yet.
Instances For
Instances For
Solver state of the non-commutative ring ringId; empty if this goal has not used it yet.
Instances For
Solver state of the non-commutative semiring semiringId; empty if this goal has not used it yet.
Instances For
Instances For
Access to the per-goal state of the current commutative ring.
- getCommRingState : m CommRingState
- modifyCommRingState : (CommRingState → CommRingState) → m Unit
Instances
Access to the per-goal state of the current (commutative or not) semiring.
- getSemiringState : m SemiringState
- modifySemiringState : (SemiringState → SemiringState) → m Unit