Documentation

LeanPool.DistinctDistances.FarkasPackedCheck

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:

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 row ∑_{(k,c) ∈ pos} c * v k - ∑_{(k,c) ∈ neg} c * v k ≤ rhs.

  • pos : List (ℕ × ℕ)

    entries (k, c) with coefficient +c on variable k

  • neg : List (ℕ × ℕ)

    entries (k, c) with coefficient -c on variable k

  • rhs : ℤ

    the right-hand side

Instances For
    noncomputable def Esgk.FarkasPackedCheck.entrySum (E : List (ℕ × ℕ)) (v : ℕ → ℝ) :

    ∑_{(k,c) ∈ E} c * v k.

    Equations
    Instances For
      noncomputable def Esgk.FarkasPackedCheck.Row.lhs (r : Row) (v : ℕ → ℝ) :

      The left-hand side ∑_{(k,c) ∈ pos} c * v k - ∑_{(k,c) ∈ neg} c * v k of a row.

      Equations
      Instances For

        The point v satisfies the row r.

        Equations
        Instances For

          Weighted rows (multiplier z, row tag t), as a balanced tree.

          Instances For

            Rational bounds for the variables 0, …, nv - 1.

            • nv : ℕ

              the number of variables

            • lo : ℕ → ℚ

              the lower bounds

            • hi : ℕ → ℚ

              the upper bounds

            Instances For

              Kernel-evaluated functions #

              A sparse binary trie of natural numbers: zero stands for a subtree of zeros. A trie of depth d holds the chunks 0, …, 2 ^ d - 1 (see PackTrie.get).

              Instances For

                Add x to every leaf of t (a zero subtree becomes the leaf x).

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Leafwise sum of two tries.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    The trie of depth D with value x at chunk q and zeros elsewhere.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For

                      The value of the leftmost leaf.

                      Equations
                      Instances For

                        Whether the trie is zero.

                        Equations
                        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
                          Instances For
                            noncomputable def Esgk.FarkasPackedCheck.pairUp {α : Type} (f : α → α → α) (l : List α) :
                            Option α → List α

                            Combine adjacent elements with f; p is a pending element.

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              noncomputable def Esgk.FarkasPackedCheck.balFold {α : Type} (f : α → α → α) (e : α) (d : ℕ) :
                              List α → α

                              Fold a list with f over a balanced tree (d rounds of pairUp, then a linear fold).

                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                noncomputable def Esgk.FarkasPackedCheck.listMap {α β : Type} (f : α → β) (l : List α) :
                                List β

                                List.map, by the recursor.

                                Equations
                                Instances For
                                  noncomputable def Esgk.FarkasPackedCheck.packEntries (W L D z : ℕ) (E : List (ℕ × ℕ)) :

                                  The packed trie of z times the entries E: entry (k, c) adds z * c to slot k % L of chunk k / L, slot i sitting at bit W * i.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For
                                    noncomputable def Esgk.FarkasPackedCheck.costEntries (W nv z : ℕ) (E : List (ℕ × ℕ)) :

                                    ∑_{(k,c) ∈ E} (z * c + [k ≥ nv] * 2 ^ W).

                                    Equations
                                    Instances For
                                      noncomputable def Esgk.FarkasPackedCheck.WTree.sumTrie {T : Type} (f : ℕ → T → PackTrie) (w : WTree T) :

                                      Sum of tries over the leaves of a weighted tree.

                                      Equations
                                      Instances For
                                        noncomputable def Esgk.FarkasPackedCheck.WTree.sumNat {T : Type} (f : ℕ → T → ℕ) (w : WTree T) :

                                        Sum of natural numbers over the leaves of a weighted tree.

                                        Equations
                                        Instances For
                                          noncomputable def Esgk.FarkasPackedCheck.WTree.sumInt {T : Type} (f : ℕ → T → ℤ) (w : WTree T) :

                                          Sum of integers over the leaves of a weighted tree.

                                          Equations
                                          Instances For
                                            noncomputable def Esgk.FarkasPackedCheck.leafCost {T : Type} (W nv : ℕ) (build : T → Option Row) (z : ℕ) (t : T) :

                                            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
                                              noncomputable def Esgk.FarkasPackedCheck.leafPack {T : Type} (W L D : ℕ) (build : T → Option Row) (sel : Row → List (ℕ × ℕ)) (z : ℕ) (t : T) :

                                              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
                                                noncomputable def Esgk.FarkasPackedCheck.leafRhs {T : Type} (build : T → Option Row) (z : ℕ) (t : T) :

                                                The weighted right-hand side z * rhs of a leaf.

                                                Equations
                                                Instances For

                                                  An unnormalized fraction num / den.

                                                  • num : ℤ

                                                    the numerator

                                                  • den : ℕ

                                                    the denominator

                                                  Instances For

                                                    Sum of fractions; the denominators are multiplied only when they differ.

                                                    Equations
                                                    Instances For

                                                      The box minimum of (p - n) * v k: (p - n) * lo k if p > n, (p - n) * hi k if p < n, and 0 if p = n.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        noncomputable def Esgk.FarkasPackedCheck.linSum (W : ℕ) (B : Box) (c : ℕ) :
                                                        ℕ → ℕ → ℕ → Frac

                                                        Box sum over the slots k, …, k + c - 1 of the packed pair (p, n), linearly.

                                                        Equations
                                                        • One or more equations did not get rendered due to their size.
                                                        Instances For
                                                          noncomputable def Esgk.FarkasPackedCheck.boxSum (W : ℕ) (B : Box) (d : ℕ) :
                                                          ℕ → ℕ → ℕ → ℕ → Frac

                                                          Box sum over the slots k, …, k + cnt - 1 of the packed pair (p, n), by divide and conquer (d is fuel; linSum takes over when it runs out).

                                                          Equations
                                                          • One or more equations did not get rendered due to their size.
                                                          Instances For
                                                            noncomputable def Esgk.FarkasPackedCheck.decodeTrie (W L : ℕ) (B : Box) (d : ℕ) :

                                                            Box sum over the chunks q, …, q + 2 ^ d - 1 of a pair of tries of depth d, with L slots per chunk.

                                                            Equations
                                                            • One or more equations did not get rendered due to their size.
                                                            Instances For

                                                              The number of slots per chunk for nv variables in 2 ^ D chunks.

                                                              Equations
                                                              Instances For

                                                                β < num / den (for den > 0).

                                                                Equations
                                                                Instances For
                                                                  noncomputable def Esgk.FarkasPackedCheck.checkWith {T : Type} (W D : ℕ) (B : Box) (build : T → Option Row) (w : WTree T) :

                                                                  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
                                                                    noncomputable def Esgk.FarkasPackedCheck.check {T : Type} (W : ℕ) (B : Box) (build : T → Option Row) (w : WTree T) :

                                                                    The checker with slot width W bits and trie depth 4.

                                                                    Equations
                                                                    Instances For

                                                                      Soundness: tries #

                                                                      Soundness: balanced folds #

                                                                      Soundness: entry lists #

                                                                      The coefficient of variable k in the entries E (proof-side).

                                                                      Equations
                                                                      Instances For

                                                                        Soundness: fractions and the slot decode #

                                                                        noncomputable def Esgk.FarkasPackedCheck.Frac.val (F : Frac) :

                                                                        The real value num / den of a fraction.

                                                                        Equations
                                                                        Instances For
                                                                          noncomputable def Esgk.FarkasPackedCheck.chunkVal (W L : ℕ) (B : Box) (q x y : ℕ) :

                                                                          The box sum of chunk q with packed parts x and y (proof-side).

                                                                          Equations
                                                                          Instances For

                                                                            Soundness: base-b digits #

                                                                            Soundness: weighted trees #

                                                                            def Esgk.FarkasPackedCheck.WTree.sum {T : Type} {M : Type u_1} [AddCommMonoid M] (f : ℕ → T → M) :
                                                                            WTree T → M

                                                                            Sum over the leaves of a weighted tree (proof-side).

                                                                            Equations
                                                                            Instances For
                                                                              def Esgk.FarkasPackedCheck.LeafOK {T : Type} (nv : ℕ) (build : T → Option Row) (_z : ℕ) (t : T) :

                                                                              The leaf's row builds and every variable index in it is < nv (proof-side).

                                                                              Equations
                                                                              Instances For
                                                                                def Esgk.FarkasPackedCheck.coefT {T : Type} (build : T → Option Row) (sel : Row → List (ℕ × ℕ)) (k : ℕ) (w : WTree T) :

                                                                                ∑_{leaves} z * coeff (sel r) k (proof-side).

                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For

                                                                                  Soundness: the checker #

                                                                                  theorem Esgk.FarkasPackedCheck.checkWith_sound {T : Type} {W D : ℕ} {B : Box} {build : T → Option Row} {w : WTree T} (v : ℕ → ℝ) (hrow : ∀ (t : T) (r : Row), build t = some r → r.Holds v) (hbox : ∀ k < B.nv, ↑(B.lo k) ≤ v k ∧ v k ≤ ↑(B.hi k)) (hc : checkWith W D B build w = true) :

                                                                                  Soundness of checkWith: if it accepts, no point v of the box satisfies every row.

                                                                                  theorem Esgk.FarkasPackedCheck.check_sound {T : Type} {W : ℕ} {B : Box} {build : T → Option Row} {w : WTree T} (v : ℕ → ℝ) (hrow : ∀ (t : T) (r : Row), build t = some r → r.Holds v) (hbox : ∀ k < B.nv, ↑(B.lo k) ≤ v k ∧ v k ≤ ↑(B.hi k)) (hc : check W B build w = true) :

                                                                                  Soundness of check: if it accepts, no point v of the box satisfies every row.