Variable elimination in a supplied order over explicit factor tables #
This module implements pure bucket (variable) elimination in an arbitrary supplied order
order : List V over explicit FactorTable R V tables, together with intermediate-scope width,
bucket-count, and peak live-table size bounds expressed in terms of the actual intermediate scopes
and live tables produced along order. Machine-level Word-RAM running-time bounds over
materialized radix-indexed factor tables live in
CslibFrontier.Algorithms.WordRAM.VariableElimination.
An elimination state ElimState R V records an accumulated scalar factor scalar : R (for
eliminated isolated variables), the current list of live factor tables live, and the list of
variables remaining not yet summed out. Eliminating a variable x ∈ remaining partitions
live into bucket := live.filter (x ∈ ·.scope) and rest := live.filter (x ∉ ·.scope). If
bucket is empty (an isolated variable), scalar is multiplied by (d : R) with zero new
tables; otherwise a new table on outScope := (bucket.flatMap scope).dedup.filter (· != x) is
materialized by summing over 0, ..., d - 1 the product of bucket, replacing bucket in
live.
Main definitions #
Cslib.Algorithms.Lean.CSP.ElimState: live tables, scalar accumulator, and uneliminated variables.Cslib.Algorithms.Lean.CSP.ElimStepStats: exact intermediate-scope and live-table statistics for one elimination step.Cslib.Algorithms.Lean.CSP.elimVar,Cslib.Algorithms.Lean.CSP.eliminateOrder: pure variable elimination alongorder : List V.Cslib.Algorithms.Lean.CSP.traceOrder,Cslib.Algorithms.Lean.CSP.maxJointScopeLen,Cslib.Algorithms.Lean.CSP.maxOutScopeLen,Cslib.Algorithms.Lean.CSP.peakLiveEntries: exact intermediate-scope width and peak live-table memory metrics alongorder.
Main results #
Cslib.Algorithms.Lean.CSP.eval_elimVar,Cslib.Algorithms.Lean.CSP.eval_eliminateOrder,Cslib.Algorithms.Lean.CSP.result_eliminateOrder_ofCSP: invariance of the contracted value for arbitrary elimination ordersorder, matchingCSP.partitionFunctionOn/CSP.partitionFunction.Cslib.Algorithms.Lean.CSP.sum_bucketFactors_le,Cslib.Algorithms.Lean.CSP.totalArithOps_le_of_intermediate: amortized bucket-count invariant and scalar operation bounds in terms of the actual intermediate scopes.Cslib.Algorithms.Lean.CSP.liveLength_eliminateOrder_le,Cslib.Algorithms.Lean.CSP.peakLiveEntries_le: live table count never increases and peak live-table entry count is bounded byinit.live.length * max maxInitEntries (d ^ maxOutScopeLen).
Elimination state and intermediate-scope statistics #
State of variable elimination: accumulated scalar from isolated variables, current list of live factor tables, and variables still to be summed out.
- scalar : R
Scalar contribution from isolated variables eliminated so far.
- live : List (Logic.PL.CSP.FactorTable R V)
Currently active factor tables.
- remaining : List V
Variables not yet eliminated.
Instances For
Intermediate-scope and live-memory statistics recorded at a single elimination step.
- bucketFactors : ℕ
Number of live factors participating in this variable's bucket.
- jointScopeVars : ℕ
Distinct variables in the joint intermediate bucket scope (0 if inactive/isolated).
- outScopeVars : ℕ
Distinct variables in the produced table's scope (
jointScopeVars - 1if active). - liveFactorsAfter : ℕ
Number of live factors after the step.
- liveEntriesAfter : ℕ
Total stored entries across all live tables after the step.
- arithOps : ℕ
Number of scalar arithmetic operations (multiplications and additions) performed at step.
Instances For
Evaluate a list of base-d digits aligned with a variable list into an assignment V → ℕ
(defaulting to 0 outside bounds).
Total number of stored entries across all live tables.
Maximum single-table entry count in live.
Maximum factor scope length in live.
Initial elimination state for a factor list over a declared variable list.
Joint deduplicated scope of the factors in a bucket.
Scope of the output table produced by eliminating x from bucket.
Build the output factor table for eliminating x from a nonempty bucket at domain
size d.
Perform one elementary variable elimination step on x.
Statistics for a single elimination step elimVar d x s.
Sequence of intermediate step statistics produced along order.
Maximum joint scope size across all steps along order.
Maximum output table scope size (outScope.length) across all steps along order.
Peak total entries stored simultaneously in live tables across order (including init).
Total arithmetic operations recorded along order.
Correctness and algebraic invariance #
Eliminating one variable preserves ElimState.eval.
Sequential variable elimination preserves ElimState.eval for every supplied order.
Variable elimination removes exactly the variables appearing in order from remaining.
If order covers all initial declared variables init.remaining, eliminating along order
leaves remaining = [] and its scalar result recovers init.eval d.
Contracting a weighted CSP by variable elimination in ANY supplied order order covering
declared recovers F.partitionFunctionOn wt declared.
Contracting a weighted CSP in ANY order covering F.vars recovers F.partitionFunction wt.
Live-table size and intermediate-scope operation bounds #
The number of live factor tables never increases along any elimination order.
Amortized bucket-count bound: the sum of bucket sizes across order is at most
init.live.length + order.length.
Every step along order has joint scope size at most maxJointScopeLen d order init.
Total scalar arithmetic operations along order are bounded by the maximum actual
intermediate bucket scope width maxJointScopeLen d order init and the amortized bucket factor
sum.
Output table dimension never exceeds the joint bucket dimension along any order.
For a nonempty bucket of factors containing x, the output scope has one fewer variable than
the joint scope.
Every factor in live has scope length at most maxScopeLen live.
One elimination step preserves the scope-length envelope max S W whenever its joint scope has
at most W variables.
Peak live-table entry count across order is bounded strictly by init.live.length times the
maximum of initial single-table sizes and the maximum output table size d ^ maxOutScopeLen.
At every prefix order.take k, live-table entry count is bounded by peakLiveEntries.