Explicit array factor tables and tensor-network correspondence #
This module provides a concrete array-backed representation FactorTable R V of weighted
finite-domain constraints, together with exact bridges to both Cslib.Logic.PL.CSP (over any
finite domain D of size d) and Cslib.Circuits.Frontier.ExplicitTensorNetwork /
Cslib.Circuits.Frontier.TensorNetwork (at domain size d = 2).
Constraint scopes are arbitrary lists of variables: repeated variables inside a scope (for example
[v, v]), empty scopes ([]), isolated declared variables, and disconnected constraint components
are all handled uniformly by evaluating mixed-radix least-significant-digit indices
(Nat.ofDigits) against an assignment σ : V → ℕ.
Main definitions #
Cslib.Logic.PL.CSP.lsbDecode: fixed-width least-significant-digit mixed-radix decoding from indices< d ^ lentoList ℕtuples belowd, paired with Mathlib'sNat.ofDigits.Cslib.Logic.PL.CSP.FactorTable: factor table pairingscope : List Vwithentries : Array R.Cslib.Logic.PL.CSP.FactorTable.contractionOn,Cslib.Logic.PL.CSP.FactorTable.contraction: partition functions of lists of factor tables over declared or occurring variables.Cslib.Logic.PL.CSP.FactorTable.ofCSP: compileCSP Rel Vinto well-formedFactorTables.Cslib.Logic.PL.CSP.FactorTable.toExplicitTensorNetwork,Cslib.Logic.PL.CSP.FactorTable.ofExplicitTensorNetwork: round-trip conversions withExplicitTensorNetwork.
Main results #
Cslib.Logic.PL.CSP.lsbDecode_ofDigits,Cslib.Logic.PL.CSP.ofDigits_lsbDecode: radix round-trip identities;ofDigits_two_eq_lsbValuerecoversCslib.BitString.lsbValue.Cslib.Logic.PL.CSP.FactorTable.contractionOn_ofCSP,Cslib.Logic.PL.CSP.FactorTable.contraction_ofCSP: exact agreement withCSP.partitionFunctionOnandCSP.partitionFunctionover any finite domain.Cslib.Logic.PL.CSP.FactorTable.contraction_toExplicitTensorNetwork,Cslib.Logic.PL.CSP.FactorTable.contractionOn_ofExplicitTensorNetwork: exact agreement atd = 2withExplicitTensorNetwork.contraction(including repeated ports, empty scopes, isolated edges, and disconnected vertices).
Mixed-radix least-significant-digit indexing #
Evaluating Nat.ofDigits on an all-zero coordinate tuple yields 0.
Nat.ofDigits d xs is strictly below d ^ xs.length for every d (including degenerate
bases d ≤ 1) whenever every digit is below d.
Decoding Nat.ofDigits d xs at length xs.length recovers xs when digits are below d.
Encoding the first len decoded digits recovers idx when idx < d ^ len.
At radix 2, Nat.ofDigits on Bool.toNat digits equals Cslib.BitString.lsbValue.
Explicit factor tables #
A weighted constraint factor represented by an ordered variable scope and an explicit table
of ring entries indexed in base-d least-significant-digit order.
- scope : List V
Ordered variable list of the factor (may contain duplicates or be empty).
- entries : Array R
Flat array of weights of expected length
d ^ scope.length.
Instances For
A factor table is well-formed at domain size d when it stores all d ^ scope.length
entries.
Evaluate a factor table at a ℕ-valued assignment σ, looking up its LSB base-d index
with 0 outside bounds.
All variables occurring in a list of factor tables.
Contract a list of factor tables over domain {0, ..., d - 1} for declared variables
declared, fixing variables outside declared to 0.
Contract a list of factor tables over its occurring variables FactorTable.vars.
The empty factor list contracts to d ^ declared.card over declared.
Enlarging the declared universe multiplies contractionOn by d ^ (T \ S).card whenever
all factor variables already lie in S.
Disconnected lists of factor tables multiply over a commutative semiring.
Disconnected factor tables multiply over contraction.
Relabeling factor scopes through a variable equivalence preserves contractionOn.
Bridge from CSP over any finite domain #
Compile one constraint into an explicit factor table at domain size d using bijection
e : D ≃ Fin d.
Evaluating ofConstraint at fun v => (e (σ v)).1 recovers the original constraint weight,
preserving arbitrary repeated variables and empty scopes.
Contracting ofCSP over declared (containing F.vars.toFinset) equals
F.partitionFunctionOn wt declared.
Contracting ofCSP over its occurring variables equals F.partitionFunction wt.
Bridge to ExplicitTensorNetwork and TensorNetwork at d = 2 #
Convert a list of factor tables on ℕ-named variables into an ExplicitTensorNetwork R
with m declared edges 0, ..., m - 1.
Convert an ExplicitTensorNetwork R into a list of FactorTable R ℕ tables.
Contracting an ExplicitTensorNetwork R equals FactorTable.contractionOn 2 of
ofExplicitTensorNetwork on Finset.range net.numEdges.
Contracting toExplicitTensorNetwork m factors equals FactorTable.contractionOn 2 on
Finset.range m.
Contracting a DescribedNetwork T whose vertex evaluator eval agrees with table lookup
matches FactorTable.contractionOn 2.
Contracting an arbitrary TensorNetwork R Bool V E matches FactorTable.contractionOn 2
of its explicit table representation.