Theorem W, option (A), stage A1: the generic bound on an expression's peak #
The lemma of approach (i′) (docs/WORD.md §4): if every leaf of an expression is small, and
every shift amount is at most S, then its value and its peak (Exp.pk, the machine's maxv of
the compiled form) are below 2^w for a width w computed from the syntax alone.
Exp.wv Γ K KH S e: the width ofe's value. A localxhas widthΓ x; a field read has widthK(KHfor the handleElem.h); a parameter, size, length, list or path entry or optional record has widthK; a literalnhas widthn. Thena + badds one bit,a * badds the widths,a <<< baddsS,−,/,%,>>>andmsbkeep the width ofa, and a comparison or connective has width 1.Exp.wp Γ K KH S e: the width of the peak, the maximum ofwvover the subexpressions, andKfor the compiled index arithmetic.Exp.wd_sound: underMemW(the leaves read from the core),CapsW(the capacities), the local widthsΓandShOK(every shift amount at mostS), an expression that evaluates tovhasv < 2^wvandpk < 2^wp.Exp.wp_le_depth: when every local and handle has width at mostKand every literal is at mostK,wp e ≤ 2^(depth e) · (K + S).
wv and wp are plain structural recursions: for a concrete expression, simp [Exp.wv, Exp.wp]
computes them as a term in K, S and the Γ of the locals involved, and omega compares it
with a target width. This is how stage A2 is meant to use it.
Widths #
The width of a field: KH for the handle Elem.h, K for every other field.
Equations
Instances For
The width of a binary operation's result from the widths of its operands.
Equations
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.add x✝¹ x✝ = max x✝¹ x✝ + 1
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.sub x✝¹ x✝ = x✝¹
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.mul x✝¹ x✝ = x✝¹ + x✝
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.div x✝¹ x✝ = x✝¹
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.mod x✝¹ x✝ = x✝¹
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.shl x✝¹ x✝ = x✝¹ + S
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.shr x✝¹ x✝ = x✝¹
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.lt x✝¹ x✝ = 1
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.le x✝¹ x✝ = 1
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.eq x✝¹ x✝ = 1
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.and x✝¹ x✝ = 1
- OrderMaintenance.Machine.BinOp.wd S OrderMaintenance.Machine.BinOp.or x✝¹ x✝ = 1
Instances For
Bound the intermediate values of a unary primitive from an input-value bound.
Equations
Instances For
The width of an expression's value.
Equations
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.lit n) = n
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.var x_1) = Γ x_1
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.rd f i) = OrderMaintenance.Impl.Fld.wd K KH f
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.size t) = K
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.prm k) = K
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.un op a) = op.wd (OrderMaintenance.Impl.Exp.wv Γ K KH S a)
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.lrd k snd i j) = K
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.llen k i) = K
- OrderMaintenance.Impl.Exp.wv Γ K KH S (c.prd j) = K
- OrderMaintenance.Impl.Exp.wv Γ K KH S (OrderMaintenance.Impl.Exp.opt f) = K
Instances For
The width of an expression's peak.
Equations
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.lit n) = n
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.var x_1) = Γ x_1
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.rd f i) = max (OrderMaintenance.Impl.Exp.wp Γ K KH S i) (OrderMaintenance.Impl.Fld.wd K KH f)
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.size t) = K
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.prm k) = K
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.un op a) = max (OrderMaintenance.Impl.Exp.wp Γ K KH S a) (op.wd (OrderMaintenance.Impl.Exp.wv Γ K KH S a))
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.lrd k snd i j) = max (max (OrderMaintenance.Impl.Exp.wp Γ K KH S i) (OrderMaintenance.Impl.Exp.wp Γ K KH S j)) K
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.llen k i) = max (OrderMaintenance.Impl.Exp.wp Γ K KH S i) K
- OrderMaintenance.Impl.Exp.wp Γ K KH S (c.prd j) = max (max (OrderMaintenance.Impl.Exp.wp Γ K KH S c) (OrderMaintenance.Impl.Exp.wp Γ K KH S j)) K
- OrderMaintenance.Impl.Exp.wp Γ K KH S (OrderMaintenance.Impl.Exp.opt f) = K
Instances For
Every shift amount of e (as evaluated) is at most S.
Equations
- One or more equations did not get rendered due to their size.
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.lit n) = True
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.var x_1) = True
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.size t) = True
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.prm k) = True
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.opt f) = True
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.rd f i) = OrderMaintenance.Impl.Exp.ShOK κ s L S i
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.llen k i) = OrderMaintenance.Impl.Exp.ShOK κ s L S i
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.un op a) = OrderMaintenance.Impl.Exp.ShOK κ s L S a
- OrderMaintenance.Impl.Exp.ShOK κ s L S (OrderMaintenance.Impl.Exp.lrd k snd i j) = (OrderMaintenance.Impl.Exp.ShOK κ s L S i ∧ OrderMaintenance.Impl.Exp.ShOK κ s L S j)
- OrderMaintenance.Impl.Exp.ShOK κ s L S (c.prd j) = (OrderMaintenance.Impl.Exp.ShOK κ s L S c ∧ OrderMaintenance.Impl.Exp.ShOK κ s L S j)
Instances For
An expression without shifts satisfies ShOK for every S.
Equations
- (OrderMaintenance.Impl.Exp.lit n).noShl = true
- (OrderMaintenance.Impl.Exp.var x_1).noShl = true
- (OrderMaintenance.Impl.Exp.size t).noShl = true
- (OrderMaintenance.Impl.Exp.prm k).noShl = true
- (OrderMaintenance.Impl.Exp.opt f).noShl = true
- (OrderMaintenance.Impl.Exp.rd f i).noShl = i.noShl
- (OrderMaintenance.Impl.Exp.llen k i).noShl = i.noShl
- (OrderMaintenance.Impl.Exp.un op i).noShl = i.noShl
- (OrderMaintenance.Impl.Exp.bin op a b).noShl = (op != OrderMaintenance.Machine.BinOp.shl && a.noShl && b.noShl)
- (OrderMaintenance.Impl.Exp.lrd k snd i j).noShl = (i.noShl && j.noShl)
- (i.prd j).noShl = (i.noShl && j.noShl)
Instances For
The leaves #
The leaves read from the core are small: every field below 2^K (the handle below
2^KH), every size, parameter, list entry, path entry and optional field below 2^K, the lists
within their capacity, and the row width H + 1 below 2^K. PeakLeaf.lean derives it from
option (B)'s WB.
Instances For
The capacities are small: the compiled index arithmetic stays below 2^K.
Instances For
Soundness #
The generic expression lemma. Under small leaves, small capacities and bounded shift
amounts, the value of an expression is below 2^wv and its peak below 2^wp.
The peak alone.
The peak of an argument list.
A closed form in the depth #
Structural nesting depth used to bound expression intermediates.
Equations
- (OrderMaintenance.Impl.Exp.lit n).depth = 0
- (OrderMaintenance.Impl.Exp.var x_1).depth = 0
- (OrderMaintenance.Impl.Exp.size t).depth = 0
- (OrderMaintenance.Impl.Exp.prm k).depth = 0
- (OrderMaintenance.Impl.Exp.opt f).depth = 0
- (OrderMaintenance.Impl.Exp.rd f i).depth = i.depth + 1
- (OrderMaintenance.Impl.Exp.llen k i).depth = i.depth + 1
- (OrderMaintenance.Impl.Exp.un op i).depth = i.depth + 1
- (OrderMaintenance.Impl.Exp.bin op a b).depth = max a.depth b.depth + 1
- (OrderMaintenance.Impl.Exp.lrd k snd i j).depth = max i.depth j.depth + 1
- (i.prd j).depth = max i.depth j.depth + 1
Instances For
Every literal of e is at most K.
Equations
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.lit n) = (n ≤ K)
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.var x_1) = True
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.size t) = True
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.prm k) = True
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.opt f) = True
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.rd f i) = OrderMaintenance.Impl.Exp.litLe K i
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.llen k i) = OrderMaintenance.Impl.Exp.litLe K i
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.un op i) = OrderMaintenance.Impl.Exp.litLe K i
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.bin op a b) = (OrderMaintenance.Impl.Exp.litLe K a ∧ OrderMaintenance.Impl.Exp.litLe K b)
- OrderMaintenance.Impl.Exp.litLe K (OrderMaintenance.Impl.Exp.lrd k snd i j) = (OrderMaintenance.Impl.Exp.litLe K i ∧ OrderMaintenance.Impl.Exp.litLe K j)
- OrderMaintenance.Impl.Exp.litLe K (i.prd j) = (OrderMaintenance.Impl.Exp.litLe K i ∧ OrderMaintenance.Impl.Exp.litLe K j)
Instances For
The closed form: with every local, handle and literal of width at most K (and
K ≥ 1), an expression of depth d has peak width at most 2^d · (K + S).
A value below 2^(max a b) is below 2^a + 2^b: a width bound max K KH with KH the width
of a handle splits into "below 2^K, or at most about twice the handle bound" (the convention
of docs/WORD.md §1).