PR #6453: the event-level invoice of the word
DefinitionPr6453_InvoiceEventsThe event-level invoice of the PR #6453 word.
assemble walks the word's events and accumulates the two counters exactly as pricing.py does: a LOCAL event adds the whole local helper histogram to the targets and the whole local paid histogram to the paid calls; a QUERY event adds paid jobs at rank ; a whole idle job adds paid jobs at rank , where is the number of idle leaves; an individual idle job adds at rank ; a normalisation is free. After the fold, each diagonal term adds productive fields at rank , where is the index sum of the term.
wordEvents records the census of the PR #6453 word in the only two fields the invoice reads — native calls, binary queries, whole idle jobs of sizes , individual idle jobs of size , and normalisations — and wordDiagonal records the index sums of its diagonal terms, as listed in physical.main_targets. Both are data extracted from the certificate, not assumptions about it.
/-
PR #6453: the event-level invoice.
`assemble` folds over the word's events; `wordEvents` and `wordDiagonal` are the census of the
PR #6453 word (18 `LOCAL`, 17 `QUERY`, 14 `IDLE` of sizes 2,3,4,7, 2 `IDLE_ONE`, 20 `LAMBDA`,
and 34 diagonal terms of index sums 0,2,3,4,7,9), in the only two fields the invoice reads.
-/
import Definitions.Def_Pr6453_Invoice
set_option autoImplicit false
namespace Pr6453
/-- The five event tags of the word. -/
inductive Tag : Type
| local
| query
| idle
| idleOne
| lambda
deriving DecidableEq, Repr
/-- An event, recorded by the only two fields the invoice reads. -/
structure Ev where
tag : Tag
size : ℕ
deriving DecidableEq, Repr
/-- The fold of `pricing.py → assemble` over the events, plus the diagonal contribution. -/
def assemble (evs : List Ev) (diag : List ℕ) (helpers paidLoc : List (ℕ × ℕ)) : (ℕ → ℕ) × (ℕ → ℕ) :=
let step : (ℕ → ℕ) × (ℕ → ℕ) → Ev → (ℕ → ℕ) × (ℕ → ℕ) := fun acc e =>
match e.tag with
| .local => (fun r => acc.1 r + countIn helpers r, fun r => acc.2 r + countIn paidLoc r)
| .query => (acc.1, fun r => acc.2 r + (if r = 1 then 104 else 0))
| .idle => (acc.1, fun r => acc.2 r + (if r = 8 * e.size then 208 else 0))
| .idleOne => (acc.1, fun r => acc.2 r + (if r = 8 * e.size then 104 else 0))
| .lambda => acc
let base := evs.foldl step (fun _ => 0, fun _ => 0)
(fun r => base.1 r + (diag.map fun s => if 1 + 8 * s = r then 104 else 0).sum, base.2)
/-- The census of the PR #6453 word, in the order the tags occur (`LOCAL` calls, then the
binary queries, then the idle jobs, then the normalisations). -/
def wordEvents : List Ev :=
List.replicate 18 ⟨.local, 0⟩
++ List.replicate 17 ⟨.query, 0⟩
++ List.replicate 8 ⟨.idle, 2⟩
++ List.replicate 2 ⟨.idle, 3⟩
++ List.replicate 2 ⟨.idle, 4⟩
++ List.replicate 2 ⟨.idle, 7⟩
++ List.replicate 2 ⟨.idleOne, 2⟩
++ List.replicate 20 ⟨.lambda, 0⟩
/-- The index sums of the diagonal terms (`1 + 8·sum` is the target rank). -/
def wordDiagonal : List ℕ :=
[0] ++ List.replicate 18 2 ++ [18] ++ List.replicate 4 3 ++ List.replicate 4 4
++ List.replicate 4 7 ++ List.replicate 2 9
end Pr6453