Pure Scope Deduplication, sumScopeLen, and flattenScopes #
Computes total concatenated bucket-scope length (sumScopeLen) and copies all bucket scopes into a
contiguous flat array (flattenScopes), paired with the foldr characterization of
bucketOutScope.
Main definitions #
Cslib.Algorithms.WordRAM.VariableElimination.dedupStepPure: pure scope deduplication step.Cslib.Algorithms.WordRAM.VariableElimination.sumScopeLen: total bucket-scope length reader.Cslib.Algorithms.WordRAM.VariableElimination.flattenScopes: bucket-scope concatenator.
Output scope materialization (buildOutScope) #
theorem Cslib.Algorithms.WordRAM.VariableElimination.length_le_foldr_dedupStepPure (x : ℕ) (ys acc : List ℕ) :
theorem Cslib.Algorithms.WordRAM.VariableElimination.bucketOutScope_eq_foldr (x : ℕ) (bucket : List (Logic.PL.CSP.FactorTable ℕ ℕ)) :
Lean.CSP.bucketOutScope x bucket = List.foldr (dedupStepPure x) [] (List.flatMap Logic.PL.CSP.FactorTable.scope bucket)
Arguments (bucketPtr, bucketLen) for sumScopeLen.
- bucketPtr : ℕ
Field
bucketPtrofSumScopeArgs. - bucketLen : ℕ
Field
bucketLenofSumScopeArgs.
Instances For
Product equivalence encoding SumScopeArgs as words.
@[instance_reducible]
Compute the total length of all scopes inside a bucket descriptor array.
theorem Cslib.Algorithms.WordRAM.VariableElimination.sumScopeLen_state (args : SumScopeArgs) (s : DataStructure.Memory.State) :
theorem Cslib.Algorithms.WordRAM.VariableElimination.sumScopeLen_cost (args : SumScopeArgs) (s : DataStructure.Memory.State) :
theorem Cslib.Algorithms.WordRAM.VariableElimination.sumScopeLen_valid {w : ℕ} {args : SumScopeArgs} {bucket : List (Logic.PL.CSP.FactorTable ℕ ℕ)} {s : DataStructure.Memory.State} (hb : HoldsFactorList args.bucketPtr bucket s) (hlen : bucket.length = args.bucketLen) :
(DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (sumScopeLen args))
theorem Cslib.Algorithms.WordRAM.VariableElimination.sumScopeLen_result {args : SumScopeArgs} {bucket : List (Logic.PL.CSP.FactorTable ℕ ℕ)} {s : DataStructure.Memory.State} (hb : HoldsFactorList args.bucketPtr bucket s) (hlen : bucket.length = args.bucketLen) :
(DataStructure.Memory.spec 0).clientResult s (sumScopeLen args) = (List.flatMap Logic.PL.CSP.FactorTable.scope bucket).length
theorem Cslib.Algorithms.WordRAM.VariableElimination.sumScopeLen_realizes :
WordRAM.Realization.Realizes WordRAM.Basis.exact sumScopeLen WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (args : SumScopeArgs) (s : DataStructure.Memory.State) =>
∃ (bucket : List (Logic.PL.CSP.FactorTable ℕ ℕ)),
bucket.length = args.bucketLen ∧ HoldsFactorList args.bucketPtr bucket s ∧ WordRAM.Fits w (List.flatMap Logic.PL.CSP.FactorTable.scope bucket).length)
fun (x : SumScopeArgs) (x_1 : DataStructure.Memory.State) => 0
Arguments for concatenating all bucket scopes into a scratch buffer.
- bucketPtr : ℕ
Field
bucketPtrofFlattenArgs. - bucketLen : ℕ
Field
bucketLenofFlattenArgs. - flatLen : ℕ
Field
flatLenofFlattenArgs.
Instances For
Product equivalence encoding FlattenArgs as words.
@[instance_reducible]
Concatenate every factor scope in a bucket into one flat word buffer.
theorem Cslib.Algorithms.WordRAM.VariableElimination.flattenScopes_spec {w : ℕ} {args : FlattenArgs} {bucket : List (Logic.PL.CSP.FactorTable ℕ ℕ)} {maxScope : ℕ} {s : DataStructure.Memory.State} (hwf : DataStructure.Memory.WellFormed w s) (hb : HoldsFactorList args.bucketPtr bucket s) (hlen : bucket.length = args.bucketLen) (hflat : (List.flatMap Logic.PL.CSP.FactorTable.scope bucket).length = args.flatLen) (hmax : ∀ f ∈ bucket, f.scope.length ≤ maxScope) (hfit : WordRAM.Fits w (s.frontier + args.flatLen)) :
have res := (DataStructure.Memory.spec 0).clientResult s (flattenScopes args);
have s' := (DataStructure.Memory.spec 0).clientState s (flattenScopes args);
(DataStructure.Memory.spec w).ValidHistory s ((DataStructure.Memory.spec w).clientHistory s (flattenScopes args)) ∧ s'.frontier = s.frontier + args.flatLen ∧ WordRAM.Realization.PreservesBelow s.frontier s s' ∧ res = s.frontier ∧ WordRAM.Realization.HoldsIn res (List.flatMap Logic.PL.CSP.FactorTable.scope bucket) s' ∧ WordRAM.Realization.memoryCost (flattenScopes args) s ≤ 1 + args.bucketLen * (2 + 2 * maxScope)
theorem Cslib.Algorithms.WordRAM.VariableElimination.flattenScopes_realizes :
WordRAM.Realization.Realizes WordRAM.Basis.exact flattenScopes WordRAM.Realization.WordEncoding.encode
WordRAM.Realization.WordEncoding.encode
(fun (w : ℕ) (args : FlattenArgs) (s : DataStructure.Memory.State) =>
WordRAM.Fits w (s.frontier + args.flatLen) ∧ ∃ (bucket : List (Logic.PL.CSP.FactorTable ℕ ℕ)),
bucket.length = args.bucketLen ∧ HoldsFactorList args.bucketPtr bucket s ∧ (List.flatMap Logic.PL.CSP.FactorTable.scope bucket).length = args.flatLen)
fun (x : FlattenArgs) (x_1 : DataStructure.Memory.State) => 0