A packed checker for Farkas certificates #
A Farkas certificate for a system of real linear inequalities rᵢ(v) ≤ bᵢ in a box
lo k ≤ v k ≤ hi k is a family of natural multipliers zᵢ such that the combined row
∑ zᵢ rᵢ = ∑ₖ cₖ v k satisfies ∑ₖ min(cₖ lo k, cₖ hi k) > ∑ zᵢ bᵢ. Then no v in the box
satisfies every row.
This file gives a checker check for such certificates and its soundness theorem
check_sound. The checker is meant to be run by the kernel (decide +kernel) on certificates
with thousands of rows and variables, so it is written for kernel evaluation:
- The rows are tags
t : Tat the leaves of a balanced treeWTree Ttogether with their multipliers; a caller-supplied builderbuild : T → Option Rowturns a tag into a row. - The coefficient vector
∑ zᵢ rᵢis kept as two natural numbers per chunk of variables (positive and negative parts), with the coefficient of variablekin a fixed-width slot ofWbits. The chunks sit at the leaves of a sparse binary trie of depthD(PackTrie), so that no single natural number covers all variables. Rows and trees are summed over balanced trees, because the kernel evaluates lazily and a linear fold nests deeply. - All kernel-evaluated functions are defined directly by recursors (in scratch measurements,
structural recursion through
brecOntook about 1.6 times as long to reduce) and are thereforenoncomputable; they are evaluated only by the kernel. - One pass computes
∑ zᵢ · (sum of the row's coefficients)plus a penalty2 ^ Wfor every missing row and every variable index≥ nv. If this total is< 2 ^ W, every row builds, every index is in range and no slot sum overflows itsWbits. - The box sum is accumulated as an unnormalized fraction (
Frac) by divide and conquer over the slots.
checkWith W D takes the trie depth D as a parameter (2 ^ D chunks of nv / 2 ^ D + 1
slots each); check W is checkWith W 4, and checkWith_sound holds for every D.
The soundness proof is geometry-free: hrow gives the rows, hbox the box, and
check_sound derives False.
Rows, weighted trees and boxes #
The left-hand side ∑_{(k,c) ∈ pos} c * v k - ∑_{(k,c) ∈ neg} c * v k of a row.
Equations
Instances For
Kernel-evaluated functions #
Leafwise sum of two tries.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The left subtree (a zero or a leaf is its own subtree).
Equations
- t.left = Esgk.FarkasPackedCheck.PackTrie.rec Esgk.FarkasPackedCheck.PackTrie.zero Esgk.FarkasPackedCheck.PackTrie.leaf (fun (l x x_1 x_2 : Esgk.FarkasPackedCheck.PackTrie) => l) t
Instances For
The right subtree (a zero or a leaf is its own subtree).
Equations
- t.right = Esgk.FarkasPackedCheck.PackTrie.rec Esgk.FarkasPackedCheck.PackTrie.zero Esgk.FarkasPackedCheck.PackTrie.leaf (fun (x r x_1 x_2 : Esgk.FarkasPackedCheck.PackTrie) => r) t
Instances For
The value of the leftmost leaf.
Equations
- t.val = Esgk.FarkasPackedCheck.PackTrie.rec 0 (fun (x : ℕ) => x) (fun (x x_1 : Esgk.FarkasPackedCheck.PackTrie) (il x_2 : ℕ) => il) t
Instances For
Whether the trie is zero.
Equations
- t.isZero = Esgk.FarkasPackedCheck.PackTrie.rec true (fun (x : ℕ) => false) (fun (x x_1 : Esgk.FarkasPackedCheck.PackTrie) (x_2 x_3 : Bool) => false) t
Instances For
The chunk q of a trie of depth d (proof-side semantics; a leaf above depth 0 is the
same value on all its chunks).
Equations
- Esgk.FarkasPackedCheck.PackTrie.get x✝¹ Esgk.FarkasPackedCheck.PackTrie.zero x✝ = 0
- Esgk.FarkasPackedCheck.PackTrie.get x✝¹ (Esgk.FarkasPackedCheck.PackTrie.leaf x_4) x✝ = x_4
- Esgk.FarkasPackedCheck.PackTrie.get 0 (l.node r) x✝ = Esgk.FarkasPackedCheck.PackTrie.get 0 l x✝
- Esgk.FarkasPackedCheck.PackTrie.get d.succ (l.node r) x✝ = if x✝ < 2 ^ d then Esgk.FarkasPackedCheck.PackTrie.get d l x✝ else Esgk.FarkasPackedCheck.PackTrie.get d r (x✝ - 2 ^ d)
Instances For
∑_{(k,c) ∈ E} (z * c + [k ≥ nv] * 2 ^ W).
Equations
- Esgk.FarkasPackedCheck.costEntries W nv z E = Esgk.FarkasPackedCheck.balFold Nat.add 0 64 (Esgk.FarkasPackedCheck.listMap (fun (e : ℕ × ℕ) => z * e.2 + bif e.1.blt nv then 0 else 2 ^ W) E)
Instances For
Sum of tries over the leaves of a weighted tree.
Equations
- Esgk.FarkasPackedCheck.WTree.sumTrie f w = Esgk.FarkasPackedCheck.WTree.rec f (fun (x x_1 : Esgk.FarkasPackedCheck.WTree T) (il ir : Esgk.FarkasPackedCheck.PackTrie) => il.add ir) w
Instances For
Sum of natural numbers over the leaves of a weighted tree.
Equations
- Esgk.FarkasPackedCheck.WTree.sumNat f w = Esgk.FarkasPackedCheck.WTree.rec f (fun (x x_1 : Esgk.FarkasPackedCheck.WTree T) (il ir : ℕ) => il.add ir) w
Instances For
Sum of integers over the leaves of a weighted tree.
Equations
- Esgk.FarkasPackedCheck.WTree.sumInt f w = Esgk.FarkasPackedCheck.WTree.rec f (fun (x x_1 : Esgk.FarkasPackedCheck.WTree T) (il ir : ℤ) => il.add ir) w
Instances For
The cost of a leaf: ∑ z * c over its entries, plus 2 ^ W for a missing row and for
every variable index ≥ nv.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The packed trie of a leaf (sel picks the positive or the negative entries).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The weighted right-hand side z * rhs of a leaf.
Equations
- Esgk.FarkasPackedCheck.leafRhs build z t = Option.rec 0 (fun (r : Esgk.FarkasPackedCheck.Row) => ↑z * r.rhs) (build t)
Instances For
The checker with trie depth D: the leaf costs sum to less than 2 ^ W, and the box sum
of the combined row exceeds β = ∑ z * rhs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The checker with slot width W bits and trie depth 4.
Equations
- Esgk.FarkasPackedCheck.check W B build w = Esgk.FarkasPackedCheck.checkWith W 4 B build w
Instances For
Soundness: tries #
Soundness: balanced folds #
Soundness: entry lists #
Soundness: fractions and the slot decode #
Soundness: base-b digits #
Soundness: weighted trees #
Sum over the leaves of a weighted tree (proof-side).
Equations
Instances For
P holds at every leaf of a weighted tree (proof-side).
Equations
Instances For
Soundness: the checker #
Soundness of checkWith: if it accepts, no point v of the box satisfies every row.
Soundness of check: if it accepts, no point v of the box satisfies every row.