Executable pairwise-coprimality check.
Equations
- Hex.Modular.CrtPlan.checkPairwise [] = true
- Hex.Modular.CrtPlan.checkPairwise (modulus :: moduli) = ((moduli.all fun (other : Nat) => decide (modulus.gcd other = 1)) && Hex.Modular.CrtPlan.checkPairwise moduli)
Instances For
Executable validation check for a batch CRT plan.
Equations
- Hex.Modular.CrtPlan.check moduli = ((moduli.toList.all fun (modulus : Nat) => decide (1 < modulus)) && Hex.Modular.CrtPlan.checkPairwise moduli.toList)
Instances For
The validation condition for a batch CRT plan.
Equations
- Hex.Modular.CrtPlan.Valid moduli = (Hex.Modular.CrtPlan.check moduli = true)
Instances For
Equations
Validation means precisely that every modulus is greater than one and that the moduli are pairwise coprime.
Equations
Merge adjacent nodes of one product-tree level.
Equations
- Hex.Modular.CrtPlan.Tree.mergeLevel [] = []
- Hex.Modular.CrtPlan.Tree.mergeLevel [tree] = [tree]
- Hex.Modular.CrtPlan.Tree.mergeLevel (left :: right :: rest) = left.merge right :: Hex.Modular.CrtPlan.Tree.mergeLevel rest
Instances For
Repeatedly merge levels. The initial leaf count is sufficient fuel: every nontrivial level strictly decreases the number of nodes.
Equations
- Hex.Modular.CrtPlan.Tree.finish 0 [] = Hex.Modular.CrtPlan.Tree.empty
- Hex.Modular.CrtPlan.Tree.finish 0 (tree :: tail) = tree
- Hex.Modular.CrtPlan.Tree.finish n.succ [] = Hex.Modular.CrtPlan.Tree.empty
- Hex.Modular.CrtPlan.Tree.finish n.succ [tree] = tree
- Hex.Modular.CrtPlan.Tree.finish fuel.succ x✝ = Hex.Modular.CrtPlan.Tree.finish fuel (Hex.Modular.CrtPlan.Tree.mergeLevel x✝)
Instances For
Build the balanced tree for a list of moduli.
Equations
- Hex.Modular.CrtPlan.Tree.ofList moduli = Hex.Modular.CrtPlan.Tree.finish moduli.length (List.map Hex.Modular.CrtPlan.Tree.leaf moduli)
Instances For
Combine two symmetric representatives using a precomputed sibling inverse.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluate a scalar reconstruction tree, consuming one residue per leaf.
Equations
Instances For
Evaluate all lanes of a reconstruction tree together. Every branch uses its stored inverse once for the whole vector.
Equations
- One or more equations did not get rendered due to their size.
- Hex.Modular.CrtPlan.Tree.evalVec k Hex.Modular.CrtPlan.Tree.empty x✝ = (Vector.replicate k 0, x✝)
- Hex.Modular.CrtPlan.Tree.evalVec k (Hex.Modular.CrtPlan.Tree.leaf modulus) [] = (Vector.replicate k 0, [])
- Hex.Modular.CrtPlan.Tree.evalVec k (Hex.Modular.CrtPlan.Tree.leaf modulus) (residue :: residues) = (Vector.map (fun (value : Int) => Hex.Modular.symMod value modulus) residue, residues)
Instances For
A validated balanced product tree of pairwise-coprime moduli greater than one. The tree contains all extended-GCD work needed by reconstruction.
Moduli in residue input order.
- tree : Tree
Balanced product tree with precomputed sibling inverses.
All moduli are greater than one and pairwise coprime.
Instances For
The root modulus of a validated plan is positive.
Validate moduli and precompute a balanced product tree.
Equations
- Hex.Modular.CrtPlan.build? moduli = if h : Hex.Modular.CrtPlan.Valid moduli then some { moduli := moduli, tree := Hex.Modular.CrtPlan.Tree.ofList moduli.toList, valid := h } else none
Instances For
Reconstruct one residue for every modulus. A count mismatch is rejected; the final linear congruence check makes the public result self-validating.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reconstruct k lanes sharing one plan. Tree inverses are reused across
every lane; reconstruction does not invoke extended GCD.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A successful scalar reconstruction is congruent to every input residue.
Every lane of a successful vector reconstruction is already reduced to the symmetric interval of the complete modulus.
Strictly half-bounded candidates that match every input residue are recovered exactly by scalar reconstruction.
Strictly half-bounded candidate lanes that match every input residue are recovered exactly by batch reconstruction.