Documentation

CslibFrontier.Algorithms.Lean.CSP.WeightCost

Weight-cost, bit-length bounds, and encoded factor tables for variable elimination #

This module analyses weight growth and binary representation cost of variable elimination (Cslib.Algorithms.Lean.CSP.eliminateOrder) over integer (ℤ), rational (ℚ), and finite-field (ZMod p) weights, together with concrete enc_structure-encoded factor table records:

Main definitions #

Main results #

Integer (ℤ) weight growth and encIntBin bounds #

theorem Cslib.Algorithms.Lean.CSP.natAbs_result_eliminateOrder_le {V : Type u_1} [DecidableEq V] {d W : ℕ} (hd : 0 < d) (hW : 0 < W) (factors : List (Logic.PL.CSP.FactorTable ℤ V)) (declared order : List V) (hinit : ∀ f ∈ factors, ∀ z ∈ f.entries.toList, z.natAbs ≤ W) :
(eliminateOrder d order (ElimState.ofFactors factors declared)).result.natAbs ≤ d ^ order.length * W ^ factors.length

Final ℤ scalar contraction result has magnitude at most d ^ order.length * W ^ factors.length.

theorem Cslib.Algorithms.Lean.CSP.natAbs_entry_eliminateOrder_le {V : Type u_1} [DecidableEq V] {d W : ℕ} (hd : 0 < d) (hW : 0 < W) (factors : List (Logic.PL.CSP.FactorTable ℤ V)) (declared order : List V) (hinit : ∀ f ∈ factors, ∀ z ∈ f.entries.toList, z.natAbs ≤ W) {f : Logic.PL.CSP.FactorTable ℤ V} (hf : f ∈ (eliminateOrder d order (ElimState.ofFactors factors declared)).live) {z : ℤ} (hz : z ∈ f.entries.toList) :
z.natAbs ≤ d ^ order.length * W ^ factors.length

Every live ℤ entry produced at any step along order has magnitude at most d ^ order.length * W ^ factors.length.

theorem Cslib.Algorithms.Lean.CSP.length_encIntBin_entry_eliminateOrder_le {V : Type u_1} [DecidableEq V] {d W : ℕ} (hd : 0 < d) (hW : 0 < W) (factors : List (Logic.PL.CSP.FactorTable ℤ V)) (declared order : List V) (hinit : ∀ f ∈ factors, ∀ z ∈ f.entries.toList, z.natAbs ≤ W) {f : Logic.PL.CSP.FactorTable ℤ V} (hf : f ∈ (eliminateOrder d order (ElimState.ofFactors factors declared)).live) {z : ℤ} (hz : z ∈ f.entries.toList) :

Every live ℤ entry throughout order has binary code length at most order.length * d.size + factors.length * W.size + 3 under encIntBin.

Finite-field (ZMod p) weight and bit-storage bounds #

Total encoded bit length across all live ZMod p factor tables using Cslib.TreeEval.Ary.Iter.encField p.

Any list of ZMod p factor tables has total encField bit length at most liveEntries live * p.size.

theorem Cslib.Algorithms.Lean.CSP.liveFieldBits_eliminateOrder_take_le_peak {V : Type u_1} [DecidableEq V] (d : ℕ) {p : ℕ} [NeZero p] (order : List V) (init : ElimState (ZMod p) V) (k : ℕ) :
liveFieldBits p (eliminateOrder d (List.take k order) init).live ≤ peakLiveEntries d order init * p.size

Encoded bit storage across all live ZMod p factor tables at every prefix order.take k is bounded by peakLiveEntries d order init * p.size.

theorem Cslib.Algorithms.Lean.CSP.liveFieldBits_eliminateOrder_le {V : Type u_1} [DecidableEq V] {d p : ℕ} [NeZero p] (hd : 0 < d) (order : List V) (init : ElimState (ZMod p) V) (k : ℕ) :
liveFieldBits p (eliminateOrder d (List.take k order) init).live ≤ init.live.length * max (maxTableEntries init.live) (d ^ maxOutScopeLen d order init) * p.size

Encoded bit storage across all live ZMod p factor tables at every prefix order.take k is bounded by init.live.length times the intermediate-scope table bound times p.size.

Rational (ℚ) direct step bounds and denominator-cleared polynomial bounds #

Reduced rational multiplication bounds: |(a * b).num| ≤ |a.num| * |b.num| and (a * b).den ≤ a.den * b.den.

Reduced rational addition bounds: |(a + b).num| ≤ |a.num| * b.den + |b.num| * a.den and (a + b).den ≤ a.den * b.den.

theorem Cslib.Algorithms.Lean.CSP.rat_list_prod_bounds {A B : ℕ} (rs : List ℚ) :
(∀ r ∈ rs, r.num.natAbs ≤ A ∧ r.den ≤ B) → rs.prod.num.natAbs ≤ A ^ rs.length ∧ rs.prod.den ≤ B ^ rs.length

Height and denominator bounds for a rational list product.

theorem Cslib.Algorithms.Lean.CSP.rat_sum_finset_bounds {P Q : ℕ} (hQ : 1 ≤ Q) (f : ℕ → ℚ) (c : ℕ) :
(∀ i < c, (f i).num.natAbs ≤ P ∧ (f i).den ≤ Q) → (∑ i ∈ Finset.range c, f i).num.natAbs ≤ c * P * Q ^ (c - 1) ∧ (∑ i ∈ Finset.range c, f i).den ≤ Q ^ c

Height and denominator bounds for a sum over Finset.range c of bounded rationals.

theorem Cslib.Algorithms.Lean.CSP.rat_elimBucketTable_bounds {V : Type u_1} [DecidableEq V] {d A B : ℕ} (hB : 1 ≤ B) (x : V) (bucket : List (Logic.PL.CSP.FactorTable ℚ V)) (hb : ∀ f ∈ bucket, ∀ q ∈ f.entries.toList, q.num.natAbs ≤ A ∧ q.den ≤ B) {q : ℚ} (hq : q ∈ (elimBucketTable d x bucket).entries.toList) :
q.num.natAbs ≤ d * A ^ bucket.length * B ^ (bucket.length * (d - 1)) ∧ q.den ≤ B ^ (bucket.length * d)

Single-step direct rational elimination bounds on elimBucketTable d x bucket.

Ring-homomorphism transport on factor tables (entries.map φ).

Uniform scaling of every entry of a factor table (c * ·).

def Cslib.Algorithms.Lean.CSP.ElimState.mapHom {R : Type u_1} {S : Type u_2} {V : Type u_3} [Semiring R] [Semiring S] (φ : R →+* S) (s : ElimState R V) :

Ring-homomorphism transport on ElimState.

theorem Cslib.Algorithms.Lean.CSP.contractionOn_zipWith_scale {R : Type u_1} {V : Type u_2} [CommSemiring R] [DecidableEq V] (d : ℕ) (scales : List R) (factors : List (Logic.PL.CSP.FactorTable R V)) (declared : Finset V) :
scales.length = factors.length → Logic.PL.CSP.FactorTable.contractionOn d (List.zipWith scaleFactor scales factors) declared = scales.prod * Logic.PL.CSP.FactorTable.contractionOn d factors declared

Scaling a factor list entrywise multiplies contractionOn by the product of the scales.

theorem Cslib.Algorithms.Lean.CSP.eliminateOrder_mapHom {R : Type u_1} {S : Type u_2} {V : Type u_3} [Semiring R] [Semiring S] [DecidableEq V] (φ : R →+* S) (d : ℕ) (order : List V) (s : ElimState R V) :

eliminateOrder commutes with any ring homomorphism φ : R →+* S.

theorem Cslib.Algorithms.Lean.CSP.result_eliminateOrder_ratScaled {V : Type u_1} [DecidableEq V] (d : ℕ) (denoms : List ℕ) (factorsℤ : List (Logic.PL.CSP.FactorTable ℤ V)) (declared order : List V) (hlen : denoms.length = factorsℤ.length) (hcover : declared.toFinset ⊆ order.toFinset) :
have factorsℚ := List.zipWith (fun (D : ℕ) (f : Logic.PL.CSP.FactorTable ℤ V) => scaleFactor (↑D)⁻¹ (mapFactorHom (Int.castRingHom ℚ) f)) denoms factorsℤ; (eliminateOrder d order (ElimState.ofFactors factorsℚ declared)).result = ↑(eliminateOrder d order (ElimState.ofFactors factorsℤ declared)).result / ↑denoms.prod

Denominator-cleared rational variable elimination: scaling integer factor tables factorsℤ by positive denominators denoms preserves the exact rational contraction modulo a single division by denoms.prod.

theorem Cslib.Algorithms.Lean.CSP.rat_cleared_result_bounds {V : Type u_1} [DecidableEq V] {d W D : ℕ} (hd : 0 < d) (hW : 0 < W) (denoms : List ℕ) (factorsℤ : List (Logic.PL.CSP.FactorTable ℤ V)) (declared order : List V) (hlen : denoms.length = factorsℤ.length) (hDpos : ∀ q ∈ denoms, 0 < q) (hDle : ∀ q ∈ denoms, q ≤ D) (hWle : ∀ f ∈ factorsℤ, ∀ z ∈ f.entries.toList, z.natAbs ≤ W) (hcover : declared.toFinset ⊆ order.toFinset) :
have factorsℚ := List.zipWith (fun (q : ℕ) (f : Logic.PL.CSP.FactorTable ℤ V) => scaleFactor (↑q)⁻¹ (mapFactorHom (Int.castRingHom ℚ) f)) denoms factorsℤ; have res := (eliminateOrder d order (ElimState.ofFactors factorsℚ declared)).result; res.num.natAbs ≤ d ^ order.length * W ^ factorsℤ.length ∧ res.den ≤ D ^ factorsℤ.length

Cleared-denominator rational contraction height and denominator bounds.

theorem Cslib.Algorithms.Lean.CSP.length_encRat_cleared_result_le {V : Type u_1} [DecidableEq V] {d W D : ℕ} (hd : 0 < d) (hW : 0 < W) (denoms : List ℕ) (factorsℤ : List (Logic.PL.CSP.FactorTable ℤ V)) (declared order : List V) (hlen : denoms.length = factorsℤ.length) (hDpos : ∀ q ∈ denoms, 0 < q) (hDle : ∀ q ∈ denoms, q ≤ D) (hWle : ∀ f ∈ factorsℤ, ∀ z ∈ f.entries.toList, z.natAbs ≤ W) (hcover : declared.toFinset ⊆ order.toFinset) :
have factorsℚ := List.zipWith (fun (q : ℕ) (f : Logic.PL.CSP.FactorTable ℤ V) => scaleFactor (↑q)⁻¹ (mapFactorHom (Int.castRingHom ℚ) f)) denoms factorsℤ; have res := (eliminateOrder d order (ElimState.ofFactors factorsℚ declared)).result; (Turing.MultiTapeTM.encRat res).length ≤ 2 * (order.length * d.size + factorsℤ.length * W.size) + factorsℤ.length * D.size + 8

Under cleared denominators, the encRat bit length of the final contraction result is linear in order.length and factorsℤ.length.

Documented encoded factor-table records (enc_structure) #

Explicit natural-number factor table record with list-backed entries for multi-tape encodings.

  • scope : List ℕ

    Ordered scope variable indices.

  • entries : List ℕ

    Table entries in LSB base-d order.

Instances For

    Explicit integer factor table record using sign-magnitude binary weights (encIntBin).

    • scope : List ℕ

      Ordered scope variable indices.

    • entries : List ℤ

      Integer table entries in LSB base-d order.

    Instances For

      Explicit rational factor table record using reduced rational encodings (encRat).

      • scope : List ℕ

        Ordered scope variable indices.

      • entries : List ℚ

        Rational table entries in LSB base-d order.

      Instances For

        Explicit modular factor table record over ZMod modulus with binary residue entries.

        • modulus : ℕ

          Modulus p (positive for ZMod p).

        • scope : List ℕ

          Ordered scope variable indices.

        • entries : List ℕ

          Residue table entries in LSB base-d order.

        Instances For
          theorem Cslib.Algorithms.Lean.CSP.encNatFactorRecord_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List ℕ} {T0 S0 : γ → ℕ} {x1 : γ → List ℕ} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T1 S1) :
          Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { scope := x0 x, entries := x1 x }) encIn encNatFactorRecord (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
          theorem Cslib.Algorithms.Lean.CSP.encIntFactorRecord_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List ℕ} {T0 S0 : γ → ℕ} {x1 : γ → List ℤ} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encIntBin) T1 S1) :
          Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { scope := x0 x, entries := x1 x }) encIn encIntFactorRecord (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
          theorem Cslib.Algorithms.Lean.CSP.encRatFactorRecord_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List ℕ} {T0 S0 : γ → ℕ} {x1 : γ → List ℚ} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encRat) T1 S1) :
          Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { scope := x0 x, entries := x1 x }) encIn encRatFactorRecord (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
          theorem Cslib.Algorithms.Lean.CSP.encModFactorRecord_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 T0 S0 : γ → ℕ} {x1 : γ → List ℕ} {T1 S1 : γ → ℕ} {x2 : γ → List ℕ} {T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encNat T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) T2 S2) :
          Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { modulus := x0 x, scope := x1 x, entries := x2 x }) encIn encModFactorRecord (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)
          theorem Cslib.Algorithms.Lean.CSP.encModFactorRecord_modulus_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → ModFactorRecord} :
          theorem Cslib.Algorithms.Lean.CSP.length_encIntFactorRecord_le (rec : IntFactorRecord) {VBits WBits : ℕ} (hv : ∀ v ∈ rec.scope, v.size ≤ VBits) (hw : ∀ z ∈ rec.entries, z.natAbs.size + 1 ≤ WBits) :
          (encIntFactorRecord rec).length ≤ 2 * (rec.scope.length * (2 * VBits + 1)) + 1 + rec.entries.length * (2 * WBits + 1)

          Encoded bit length of an IntFactorRecord bounded by variable and entry bit lengths.

          theorem Cslib.Algorithms.Lean.CSP.length_encRatFactorRecord_le (rec : RatFactorRecord) {VBits RBits : ℕ} (hv : ∀ v ∈ rec.scope, v.size ≤ VBits) (hq : ∀ q ∈ rec.entries, (Turing.MultiTapeTM.encRat q).length ≤ RBits) :
          (encRatFactorRecord rec).length ≤ 2 * (rec.scope.length * (2 * VBits + 1)) + 1 + rec.entries.length * (2 * RBits + 1)

          Encoded bit length of a RatFactorRecord bounded by scope variable and encRat entry lengths.

          theorem Cslib.Algorithms.Lean.CSP.length_encModFactorRecord_le (rec : ModFactorRecord) {VBits : ℕ} (hv : ∀ v ∈ rec.scope, v.size ≤ VBits) (hw : ∀ k ∈ rec.entries, k < rec.modulus) :
          (encModFactorRecord rec).length ≤ 2 * rec.modulus.size + 1 + 2 * (rec.scope.length * (2 * VBits + 1)) + 1 + rec.entries.length * (2 * rec.modulus.size + 1)

          Encoded bit length of a ModFactorRecord bounded by modulus, scope variable, and residue bit lengths.