Expr helpers #
Equations
Instances For
Equations
Instances For
Equations
Instances For
Types #
Equations
Instances For
Bitvector operations that we perform AC canonicalization on.
Instances For
The identity / neutral element of given operation
Equations
Instances For
- op : Op
The associative and commutative operator we are currently canonicalizing with respect to.
- exprToVarIndex : Std.HashMap Expr VarIndex
Map from atomic expressions to an index.
Inverse of
exprToVarIndex, which maps aVarIndexto the expression it represents.
Instances For
We don't verify the state manipulations, but if we would, these are the invariants:
structure LegalVarState extends VarState where
/-- `varToExpr` and `exprToVarIndex` have the same number of elements. -/
h_size : varToExpr.size = exprToVarIndex.size
/-- `exprToVarIndex` is the inverse of `varToExpr`. -/
h_elems : ∀ h_lt : i < varToExpr.size, exprToVarIndex[varToExpr[i]]? = some i
A representation of an expression as a map from variable index to the number of occurrences of the expression represented by that variable.
See CoefficientsMap.toExpr for the explicit conversion.
Equations
Instances For
VarState monadic boilerplate #
Equations
Instances For
Implementation #
Return the unique variable index for an expression, or none if the expression
is a neutral element (see isNeutral).
Modifies the monadic state to add a new mapping, if needed.
Equations
Instances For
Return the expression that is represented by a specific variable index.
Equations
Instances For
Given a binary, associative and commutative operation op,
decompose expression e into its variable coefficients.
For example a ⊕ b ⊕ (a ⊕ c) will give the coefficients:
a => 2
b => 1
c => 1
Any compound expression which is not an application of the given op will be
abstracted away and treated as a variable (see VarStateM.exprToVar).
Equations
Instances For
Equations
Instances For
Equations
Instances For
Compute the canonical expression for a given set of coefficients.
Returns none if all coefficients are zero.
Equations
Instances For
Given an expression P lhs rhs, where lhs, rhs : ty and P : $ty → $ty → _,
canonicalize top-level applications of a recognized associative and commutative
operation on both the lhs and the rhs such that the final expression is:
P ($common ⊕ $lhs') ($common ⊕ $rhs')
That is, in a way that exposes terms that are shared between the lhs and rhs.
For example, x₁ * (y₁ * z) == x₂ * (y₂ * z) is normalized to
z * (x₁ * y₁) == z * (x₂ * y₂), pulling the shared variable z to the front on
both sides.
See Op.fromExpr? to see which operations are recognized.
Other operations are ignored, even if they are associative and commutative.