| nanReading page · generated from lean/Ecma/Model.lean, lean/Ecma/Model/Laws.lean
The model and its laws
A model gives each sort of the specification (mathematical values, Numbers, BigInts, Strings, Symbols, Parse Nodes, Lists, Data Blocks, CharSets, Records, the store) a carrier and its operations. The laws say what the specification assumes of them: 148 laws, each quoting the sentence it reads. Laws that quote the same sentence share one quotation.
The model
From lean/Ecma/Model.lean
A Model gives each sort of the specification a carrier and its operations. The machine is defined over every model; the laws a model must satisfy are a separate statement (Model.Laws). No carrier is fixed here: mathematical values form an ordered field with "is an integer" a predicate; Strings are sequences of code units; Lists, Records and objects live in a store and have identity.
NumView
Model.lean:22The case view of a Number value (§6.1.6.1).
inductive NumView (Math : Type) whereParseCx
Model.lean:35A parser invocation's context (§5.1.2): the Annex B sections whose grammar applies (those the host supports, B.1 and B.3), whether the source text is strict mode code from outside (§11.2.2: eval code of a direct eval in strict mode code), whether it is parsed for ParseJSON (§25.5.1), and whether it is source text parsed with the goal symbol Module (B.1.1), or a reparse of tokens such a parse matched.
structure ParseCx whereNormForm
Model.lean:43The Unicode Normalization Forms (UAX #15).
inductive NormForm where| NFC | NFD | NFKC | NFKDModel
Model.lean:48A model of the spec's sorts and their primitive operations.
structure Model wheremathematical values (§5.2.6)
Math : TypeNumber values (§6.1.6.1)
Num : TypeBigInt values (§6.1.6.2)
Big : TypeString values: sequences of 16-bit code units (§6.1.4)
Str : TypeSymbol values: identities (§6.1.5)
Sym : Typeidentities of store cells: objects, Records and Lists
Addr : TypeParse Nodes (§5.1.2)
Node : Typefinite sequences: List contents (§6.2.2)
Seq : Type → Typebyte sequences: Data Block contents (§6.2.9)
Bytes : Typefinite maps from field names: Record contents and internal slots (§6.2.1)
Rec : Type → Typeown-property tables: maps from property keys, in creation order (§6.1.7)
Props : Type → Typethe store
Heap : Type → Typea numeral
ofNat : Nat → Mathadd : Math → Math → Mathsub : Math → Math → Mathmul : Math → Math → Mathdiv : Math → Math → Mathneg : Math → Mathx<sup>y</sup>: for an integer y, or for x > 0 and any y
pow : Math → Math → Mathlt : Math → Math → Booleq : Math → Math → Boolthe largest integer ≤ x
floor : Math → Math"x is an integer"
isInt : Math → Boolthe integer e with 10^e ≤ x < 10^(e+1), for x > 0: the place of the first significant digit of x's decimal representation (Model.Laws)
decExp : Math → Maththe square root of a non-negative mathematical value
sqrt : Math → Mathπ
pi : Matha §21.3 function at x, on the domain the calling steps guard; opaque: every use is implementation-approximated
fn : MathFn → Math → MathnumView : Num → NumView Math𝔽(x) for finite x: roundTiesToEven to the nearest Number value (§6.1.6.1)
numOf : Math → NumnumNaN : Num+∞𝔽 (false) or -∞𝔽 (true)
numInf : Bool → Num+0𝔽 (false) or -0𝔽 (true)
numZero : Bool → NumIEEE 754-2019 addition, roundTiesToEven (§5.2.6: operators on Numbers)
numAdd : Num → Num → NumnumSub : Num → Num → NumnumMul : Num → Num → NumnumDiv : Num → Num → NumnumNeg : Num → NumIEEE 754-2019 compareQuietLess
numLt : Num → Num → BoolIEEE 754-2019 compareQuietEqual
numEq : Num → Num → BoolNumber::toString's integers n, k and s for a finite positive Number and a radix from 2 to 36 (§6.1.6.1.20 step 5): s has k digits, 𝔽(s × radix^(n-k)) is the Number, and k is as small as possible (Model.NumLaws)
numDigits : Num → Math → Math × Nat × Mathℤ(x) for an integer x
bigOf : Math → Bigℝ(x)
bigVal : Big → Matha String literal of the text
strLit : String → StrstrLen : Str → Maththe code unit at an index, as a mathematical value
strAt : Str → Math → Option MathstrConcat : Str → Str → Strthe substring from i to j
strSub : Str → Math → Math → Strthe String of one code unit
strOfUnit : Math → Strthe String made from n copies of s appended together (n ≥ 0)
strRepeat : Math → Str → Strthe representation of non-negative integer n using radix r (2 ≤ r ≤ 36)
intToRadix : Math → Math → StrstrEq : Str → Str → Boolthe code units, first to last
strUnits : Str → Seq MathsymEq : Sym → Sym → Boola Symbol's [[Description]]: a String, or none for undefined (§6.1.5)
symDesc : Sym → Option Strthe Symbol made by the kth creation, with the description
symNew : Nat → Option Str → SymaddrEq : Addr → Addr → BoolnodeProd : Node → ProdIdthe k-th written occurrence of a nonterminal on the production's right-hand side, absent optional items counted: some (some c) its child, some none an optional item that is absent, none no such occurrence
nodeChild : Node → NtId → Nat → Option (Option Node)the children, left to right (§5.1.2)
nodeKids : Node → Seq Nodethe proper descendants, in pre-order
nodeDescendants : Node → Seq Nodethe nonterminal the node is an instance of
nodeNt : Node → NtIdthe code points of the source text it matched (§11)
nodeSource : Node → Seq Maththe grammatical parameters it was parsed with (§5.1.6)
nodeArgs : Node → List Grammar.Param§5.1.2 parser invocation k, the errata read as rd: a parse of code points with a goal symbol and its parameters, some (some n) the Parse Node, some none no parse, none where the model does not decide (Model.ParseLaws)
parse : (ErratumId → Reading) → ParseCx → Nat → Seq Math → NtId → List (ParamId × Bool) → Option (Option Node)§5.1.5 "P must cover K": the covered Parse Node of parser invocation k, the errata read as rd: the Parse Node the cover's source text parses to with the goal symbol and its parameters, given from the cover itself; none where the model gives none from the cover, and its source text is parsed (Model.CoverLaws)
cover : (ErratumId → Reading) → ParseCx → Nat → Node → NtId → List (ParamId × Bool) → Option Node := fun _ _ _ _ _ _ => none
the parser invocation a Parse Node resulted from (§5.1.2: never reused across invocations)
nodeStamp : Node → Natthe span of source text it matched, in code points
nodeSpan : Node → Nat × NatnodeParent r n: the Parse Node of which n is a child, in the tree below r; none where there is none (Model.ParentLaws)
nodeParent : Node → Node → Option NodenodeAncestors r n: the Parse Nodes of the tree below r that contain n, the nearest first: its parent, that node's parent, and so on to r (Model.ParentLaws)
nodeAncestors : Node → Node → List Nodea bound on the depth of the tree below it: more than each child's (Model.ParentLaws)
nodeHeight : Node → Natwhether two Parse Nodes are the same one
nodeEq : Node → Node → BoolseqNil : {α : Type} → Seq αseqPush : {α : Type} → Seq α → α → Seq αseqCons : {α : Type} → α → Seq α → Seq αseqLen : {α : Type} → Seq α → MathseqGet : {α : Type} → Seq α → Math → Option αseqSet : {α : Type} → Seq α → Math → α → Seq αseqConcat : {α : Type} → Seq α → Seq α → Seq αseqRemove : {α : Type} → Seq α → Math → Seq αn copies of a value, for a non-negative integer n
seqRepeat : {α : Type} → Math → α → Seq αthe elements, first to last, folded
seqFoldl : {α β : Type} → (β → α → β) → β → Seq α → βrecEmpty : {α : Type} → Rec αrecGet : {α : Type} → Rec α → FieldId → Option αrecSet : {α : Type} → Rec α → FieldId → α → Rec αrecDel : {α : Type} → Rec α → FieldId → Rec αrecKeys : {α : Type} → Rec α → Seq FieldIdpropsEmpty : {α : Type} → Props αpropsGet : {α : Type} → Props α → Str ⊕ Sym → Option αupdate in place, or add at the end of creation order
propsPut : {α : Type} → Props α → Str ⊕ Sym → α → Props αpropsDel : {α : Type} → Props α → Str ⊕ Sym → Props αthe keys in creation order
propsKeys : {α : Type} → Props α → Seq (Str ⊕ Sym)heapEmpty : {α : Type} → Heap αa fresh address
heapAlloc : {α : Type} → Heap α → α → Addr × Heap αheapGet : {α : Type} → Heap α → Addr → Option αheapSet : {α : Type} → Heap α → Addr → α → Heap αthe simple case folding of a code point: its CaseFolding.txt mapping of status C or S, if any (UAX #44 Simple_Case_Folding)
scf? : Math → Option MathtoLowercase (Unicode §3.13, Default Case Conversion): full lowercase mappings, Final_Sigma in context
toLower : Seq Math → Seq MathtoUppercase (Unicode §3.13, Default Case Conversion): full uppercase mappings
toUpper : Seq Math → Seq Maththe CharSetElements, each a sequence of code points, whose Unicode Character Database definition includes the property named p with the value named v (names or aliases, as code points; §22.2.2.9); none where p and v name no property value, or one with infinitely many elements (False of a property of strings)
propSet : Seq Math → Seq Math → Option (Seq (Seq Math))the long name, as code points, of the value named v of the Unicode property named p (names or aliases, compared exactly; PropertyValueAliases.txt); none where p and v name none
propValue : Seq Math → Seq Math → Option (Seq Math)the code points normalized into the form, as the Unicode Standard's Normalization Forms specify (UAX #15); opaque
normalize : NormForm → Seq Math → Seq MathCharSet : TypecsEmpty : CharSetcsAdd : CharSet → Seq Math → CharSetcsInterval : Math → Math → CharSetcsUnion : CharSet → CharSet → CharSetcsInter : CharSet → CharSet → CharSetcsDiff : CharSet → CharSet → CharSetcsHas : CharSet → Seq Math → BoolcsSize : CharSet → MathcsGet : CharSet → Math → Option (Seq Math)csAllSingle : CharSet → BoolcsSingles : CharSet → CharSetcsFromProp : Seq Math → Seq Math → Option CharSetcsNoScf : CharSetcsCanonExtra : CharSet → Bool → CharSetcsHasCanon : CharSet → Math → Bool → Bool → Boola Data Block of n zero bytes (§6.2.9, empty if not a non-negative integer)
bytesZero : Math → BytesbytesLen : Bytes → MathbytesGet : Bytes → Math → Option MathbytesSet : Bytes → Math → Math → BytesbytesFill : Bytes → Math → BytesseqList
Model.lean:270A List's elements, first to last.
def seqList {M : Model} {α : Type} (sq : M.Seq α) : List α := M.seqFoldl (fun l x => l ++ [x]) [] sqModel.canonChar
Model.lean:274§22.2.2.7.3 Canonicalize(rer, ch) on a character c, with [[IgnoreCase]] ignoreCase and HasEitherUnicodeFlag u.
def Model.canonChar (M : Model) (ignoreCase u : Bool) (c : M.Math) : M.Math := if !ignoreCase then c else if u then (M.scf? c).getD c else let mapped := M.toUpper (M.seqPush M.seqNil c) if M.eq (M.seqLen mapped) (M.ofNat 1) then match M.seqGet mapped (M.ofNat 0) with | some d => if M.lt (M.ofNat 0xFFFF) d || (!M.lt c (M.ofNat 128) && M.lt d (M.ofNat 128)) then c else d | none => c else c
The laws of a model
From lean/Ecma/Model/Laws.lean
What the specification assumes of its sorts, stated over a Model's operations. Indices, lengths and code units are mathematical values that are non-negative integers, written M.ofNat k. The laws about Parse Nodes are Model.NodeLaws, Model.ParseLaws, Model.CoverLaws and Model.ParentLaws.
utf16Units
Laws.lean:19§11.1.1 UTF16EncodeCodePoint: the code units of a code point.
def utf16Units (c : Nat) : List Nat := if c < 0x10000 then [c] else [0xD800 + (c - 0x10000) / 0x400, 0xDC00 + (c - 0x10000) % 0x400]
strLitUnits
Laws.lean:23The code units of a text: its code points encoded in UTF-16.
def strLitUnits (t : String) : List Nat := t.toList.flatMap fun c => utf16Units c.toNatThe Number type (§6.1.6.1): its value set, the Number value for a real, and IEEE 754-2019's operations on it.
Model.abs
Laws.lean:32|x|
def Model.abs (x : M.Math) : M.Math := if M.lt x (M.ofNat 0) then M.neg x else xModel.form
Laws.lean:35±m × 2^k / 2^1074: a finite non-zero Number value's magnitude form, with e = k − 1074.
def Model.form (neg : Bool) (m k : Nat) : M.Math := let v := M.div (M.mul (M.ofNat m) (M.pow (M.ofNat 2) (M.ofNat k))) (M.pow (M.ofNat 2) (M.ofNat 1074)) if neg then M.neg v else v
Model.finiteNum
Laws.lean:41§6.1.6.1: the finite non-zero Number values, normalized (2^52 ≤ m < 2^53, −1074 ≤ e ≤ 971) or denormalized (0 < m < 2^52, e = −1074); even when the significand m is even.
def Model.finiteNum (x : M.Math) (even : Bool) : Prop := ∃ (neg : Bool) (m k : Nat), x = M.form neg m k ∧ (m % 2 == 0) = even ∧ ((2 ^ 52 ≤ m ∧ m < 2 ^ 53 ∧ k ≤ 2045) ∨ (0 < m ∧ m < 2 ^ 52 ∧ k = 0))
Model.candidate
Laws.lean:47The candidates of "the Number value for x": the finite values without −0, i.e. the non-zero ones and 0, and ±2^1024 (even); with the parity of each significand.
def Model.candidate (y : M.Math) (even : Bool) : Prop := M.finiteNum y even ∨ (y = M.ofNat 0 ∧ even = true) ∨ ((y = M.pow (M.ofNat 2) (M.ofNat 1024) ∨ y = M.neg (M.pow (M.ofNat 2) (M.ofNat 1024))) ∧ even = true)
Model.nearest
Laws.lean:52y is "the member of the set closest in value to x", with ties to the even significand.
def Model.nearest (x y : M.Math) : Prop := ∃ ev, M.candidate y ev ∧ ∀ z ez, M.candidate z ez → M.lt (M.abs (M.sub x z)) (M.abs (M.sub x y)) = false ∧ (M.abs (M.sub x z) = M.abs (M.sub x y) → z ≠ y → ev = true)
Model.viewFor
Laws.lean:59The view of the Number value for a non-zero chosen member y of x: ±∞ for ±2^1024, ±0 by x's sign for 0, else y.
def Model.viewFor (x y : M.Math) : NumView M.Math := if M.eq y (M.pow (M.ofNat 2) (M.ofNat 1024)) then .posInf else if M.eq y (M.neg (M.pow (M.ofNat 2) (M.ofNat 1024))) then .negInf else if M.eq y (M.ofNat 0) then (if M.lt x (M.ofNat 0) then .negZero else .posZero) else .finite y
Model.realOf
Laws.lean:66The real value of a finite Number view (both zeros are 0).
def Model.realOf : NumView M.Math → Option M.Math | .finite m => some m | .posZero => some (M.ofNat 0) | .negZero => some (M.ofNat 0) | _ => none
Model.digitsOf
Laws.lean:74Number::toString step 5's condition on n, k and s for x at radix r: k ≥ 1, n and s integers, r^(k-1) ≤ s < r^k, and 𝔽(s × r^(n-k)) is x.
def Model.digitsOf (x : M.Num) (r n : M.Math) (k : Nat) (s : M.Math) : Prop := 1 ≤ k ∧ M.isInt n = true ∧ M.isInt s = true ∧ M.lt s (M.pow r (M.ofNat (k - 1))) = false ∧ M.lt s (M.pow r (M.ofNat k)) = true ∧ M.numOf (M.mul s (M.pow r (M.sub n (M.ofNat k)))) = x
Model.NumLaws
Laws.lean:82The laws of the Number type: its value set (§6.1.6.1), "the Number value for x" as roundTiesToEven, and IEEE 754-2019's operations.
Proved as part of Model.Laws (its field num).
structure Model.NumLaws (M : Model) : Prop where12 laws
representing the double-precision floating point IEEE 754-2019 binary64 values
A view determines the Number value.
numView_injLean
numView_inj : ∀ a b, M.numView a = M.numView b → a = bnon-zero finite Numbers are partitioned into two groups
Every finite view is a normalized or denormalized value (finiteNum).
numView_finiteLean
numView_finite : ∀ a m, M.numView a = .finite m → ∃ ev, M.finiteNum m evEvery normalized or denormalized value is a Number value.
finiteNum_viewLean
finiteNum_view : ∀ m ev, M.finiteNum m ev → ∃ a, M.numView a = .finite mChoose the member of this set that is closest in value to x. If two values of the set are equally close, then the one with an even significand is chosen
𝔽(x) is the nearest candidate, ties to even, ±2^1024 read as ±∞ and 0 as a zero of x's sign.
numOf_nearestLean
numOf_nearest : ∀ x, ∃ y, M.nearest x y ∧ M.numView (M.numOf x) = M.viewFor x yReturn the negation of number; that is, compute a Number with the same magnitude but opposite sign.
Negation flips the sign; NaN stays.
numNeg_viewLean
numNeg_view : ∀ a, M.numView (M.numNeg a) = match M.numView a with | .nan => .nan | .posInf => .negInf | .negInf => .posInf | .posZero => .negZero | .negZero => .posZero | .finite m => .finite (M.neg m)
If x is -0𝔽 and y is -0𝔽, return -0𝔽. 1. Return 𝔽(ℝ(x) + ℝ(y)).
Number::add's steps, a row each.
numAdd_viewLean
numAdd_view : ∀ a b, M.numView (M.numAdd a b) = match M.numView a, M.numView b with | .nan, _ => .nan | _, .nan => .nan | .posInf, .negInf => .nan | .negInf, .posInf => .nan | .posInf, _ => .posInf | .negInf, _ => .negInf | _, .posInf => .posInf | _, .negInf => .negInf | .negZero, .negZero => .negZero | va, vb => match M.realOf va, M.realOf vb with | some x, some y => M.numView (M.numOf (M.add x y)) | _, _ => .nan
Return Number::add(x, Number::unaryMinus(y)).
Subtraction is addition of the negation.
numSub_defLean
numSub_def : ∀ a b, M.numSub a b = M.numAdd a (M.numNeg b)Return 𝔽(ℝ(x) × ℝ(y)).
Number::multiply's steps, a row each.
numMul_viewLean
numMul_view : ∀ a b, M.numView (M.numMul a b) = match M.numView a, M.numView b with | .nan, _ => .nan | _, .nan => .nan | .posInf, .posZero => .nan | .posInf, .negZero => .nan | .negInf, .posZero => .nan | .negInf, .negZero => .nan | .posZero, .posInf => .nan | .negZero, .posInf => .nan | .posZero, .negInf => .nan | .negZero, .negInf => .nan | va, vb => let neg := (match va with | .negInf | .negZero => true | .finite m => M.lt m (M.ofNat 0) | _ => false) != (match vb with | .negInf | .negZero => true | .finite m => M.lt m (M.ofNat 0) | _ => false) match M.realOf va, M.realOf vb with | some x, some y => if M.eq (M.mul x y) (M.ofNat 0) then (if neg then .negZero else .posZero) else M.numView (M.numOf (M.mul x y)) | _, _ => if neg then .negInf else .posInf
Return 𝔽(ℝ(x) / ℝ(y)).
Number::divide's steps, a row each.
numDiv_viewLean
numDiv_view : ∀ a b, M.numView (M.numDiv a b) = match M.numView a, M.numView b with | .nan, _ => .nan | _, .nan => .nan | .posInf, .posInf => .nan | .posInf, .negInf => .nan | .negInf, .posInf => .nan | .negInf, .negInf => .nan | .posZero, .posZero => .nan | .posZero, .negZero => .nan | .negZero, .posZero => .nan | .negZero, .negZero => .nan | va, vb => let neg := (match va with | .negInf | .negZero => true | .finite m => M.lt m (M.ofNat 0) | _ => false) != (match vb with | .negInf | .negZero => true | .finite m => M.lt m (M.ofNat 0) | _ => false) match va, vb with | .posInf, _ | .negInf, _ => if neg then .negInf else .posInf | _, .posInf | _, .negInf => if neg then .negZero else .posZero | _, .posZero | _, .negZero => if neg then .negInf else .posInf | _, _ => match M.realOf va, M.realOf vb with | some x, some y => if M.eq (M.div x y) (M.ofNat 0) then (if neg then .negZero else .posZero) else M.numView (M.numOf (M.div x y)) | _, _ => .nan
If ℝ(x) < ℝ(y), return true.
Number::lessThan's steps, undefined read as false.
numLt_defLean
numLt_def : ∀ a b, M.numLt a b = match M.numView a, M.numView b with | .nan, _ => false | _, .nan => false | .negInf, .negInf => false | .negInf, _ => true | _, .negInf => false | .posInf, _ => false | _, .posInf => true | va, vb => match M.realOf va, M.realOf vb with | some x, some y => M.lt x y | _, _ => false
If x is +0𝔽 and y is -0𝔽, return true.
Number::equal's steps.
numEq_defLean
numEq_def : ∀ a b, M.numEq a b = match M.numView a, M.numView b with | .nan, _ => false | _, .nan => false | .posInf, .posInf => true | .negInf, .negInf => true | va, vb => match M.realOf va, M.realOf vb with | some x, some y => M.eq x y | _, _ => false
Let n, k, and s be integers such that k ≥ 1, … and k is as small as possible.
For a finite positive x and a radix from 2 to 36, numDigits meets the step's condition (digitsOf), and no n, k and s that meet it have a smaller k.
numDigits_leastLean
numDigits_least : ∀ x m (r : Nat), M.numView x = .finite m → M.lt (M.ofNat 0) m = true → 2 ≤ r → r ≤ 36 → M.digitsOf x (M.ofNat r) (M.numDigits x (M.ofNat r)).1 (M.numDigits x (M.ofNat r)).2.1 (M.numDigits x (M.ofNat r)).2.2 ∧ ∀ n k s, M.digitsOf x (M.ofNat r) n k s → (M.numDigits x (M.ofNat r)).2.1 ≤ k
Model.isPoint
Laws.lean:187§6.1.4: m is a code point's value, an integer in [0, 0x10FFFF].
def Model.isPoint (M : Model) (m : M.Math) : Prop := M.isInt m = true ∧ M.lt m (M.ofNat 0) = false ∧ M.lt (M.ofNat 0x10FFFF) m = false
Model.allPoints
Laws.lean:191Every element of xs is a code point.
def Model.allPoints (M : Model) (xs : M.Seq M.Math) : Prop := ∀ i x, M.seqGet xs i = some x → M.isPoint x
Model.isByte
Laws.lean:195§6.2.9: b is a byte value, an integer in [0, 255].
def Model.isByte (M : Model) (b : M.Math) : Prop := M.isInt b = true ∧ M.lt b (M.ofNat 0) = false ∧ M.lt b (M.ofNat 256) = true
Model.ByteLaws
Laws.lean:199The laws of Data Block byte sequences (§6.2.9).
Proved as part of Model.Laws (its field bytes).
structure Model.ByteLaws (M : Model) : Prop where9 laws
A Data Block value is created with a fixed number of bytes that each have the initial value 0.
Every Data Block has a non-negative integer number of bytes.
bytesLen_nonnegLean
bytesLen_nonneg : ∀ bs, M.isInt (M.bytesLen bs) = true ∧ M.lt (M.bytesLen bs) (M.ofNat 0) = falseA byte exists at index i iff i is a non-negative integer less than the block length.
bytesGet_boundsLean
bytesGet_bounds : ∀ bs i, (M.isInt i = true ∧ M.lt i (M.ofNat 0) = false ∧ M.lt i (M.bytesLen bs) = true) ↔ (M.bytesGet bs i).isSome = true
Every byte read from a Data Block is an integer from 0 to 255.
bytesGet_byteLean
bytesGet_byte : ∀ bs i b, M.bytesGet bs i = some b → M.isByte bBytesZero n has n bytes when n is a non-negative integer.
bytesZero_lenLean
bytesZero_len : ∀ n, M.isInt n = true → M.lt n (M.ofNat 0) = false → M.bytesLen (M.bytesZero n) = nEvery byte of bytesZero n is 0.
bytesZero_getLean
bytesZero_get : ∀ n i b, M.bytesGet (M.bytesZero n) i = some b → b = M.ofNat 0Writing a byte preserves the block length.
bytesSet_lenLean
bytesSet_len : ∀ bs i v, M.bytesLen (M.bytesSet bs i v) = M.bytesLen bsWriting a byte v at an in-bounds index i updates only index i.
bytesSet_getLean
bytesSet_get : ∀ bs i v j, M.isInt i = true → M.lt i (M.ofNat 0) = false → M.lt i (M.bytesLen bs) = true → M.isByte v → M.bytesGet (M.bytesSet bs i v) j = if M.eq j i then some v else M.bytesGet bs j
Filling a Data Block with a byte preserves its length.
bytesFill_lenLean
bytesFill_len : ∀ bs v, M.bytesLen (M.bytesFill bs v) = M.bytesLen bsFilling a Data Block with byte v sets every in-bounds index to v.
bytesFill_getLean
bytesFill_get : ∀ bs v i, M.isByte v → M.isInt i = true → M.lt i (M.ofNat 0) = false → M.lt i (M.bytesLen bs) = true → M.bytesGet (M.bytesFill bs v) i = some v
Model.Laws
Laws.lean:244The laws a model of the spec's sorts satisfies.
Proved of the engine's model: Engine.Impl.laws, the first part of Implements.model.
structure Model.Laws (M : Model) : Prop where116 laws
When applied to mathematical values, the operators refer to the usual mathematical operations.
Addition is associative.
add_assocLean
add_assoc : ∀ a b c, M.add (M.add a b) c = M.add a (M.add b c)Addition is commutative.
add_commLean
add_comm : ∀ a b, M.add a b = M.add b a0 is the additive identity.
add_zeroLean
add_zero : ∀ a, M.add a (M.ofNat 0) = aNegation is the additive inverse.
add_negLean
add_neg : ∀ a, M.add a (M.neg a) = M.ofNat 0Subtraction adds the negation.
sub_defLean
sub_def : ∀ a b, M.sub a b = M.add a (M.neg b)Multiplication is associative.
mul_assocLean
mul_assoc : ∀ a b c, M.mul (M.mul a b) c = M.mul a (M.mul b c)Multiplication is commutative.
mul_commLean
mul_comm : ∀ a b, M.mul a b = M.mul b a1 is the multiplicative identity.
mul_oneLean
mul_one : ∀ a, M.mul a (M.ofNat 1) = aMultiplication distributes over addition.
mul_addLean
mul_add : ∀ a b c, M.mul a (M.add b c) = M.add (M.mul a b) (M.mul a c)Division by a non-zero value inverts multiplication.
div_mulLean
div_mul : ∀ a b, b ≠ M.ofNat 0 → M.mul (M.div a b) b = aMathematical values: Arbitrary real numbers, used as the default numeric type.
0 and 1 differ.
zero_ne_oneLean
zero_ne_one : M.ofNat 0 ≠ M.ofNat 1When applied to mathematical values, the operators refer to the usual mathematical operations.
< is irreflexive.
lt_irreflLean
lt_irrefl : ∀ a, M.lt a a = false< is transitive.
lt_transLean
lt_trans : ∀ a b c, M.lt a b = true → M.lt b c = true → M.lt a c = trueMathematical values: Arbitrary real numbers, used as the default numeric type.
< is total, as on the reals.
lt_totalLean
lt_total : ∀ a b, M.lt a b = true ∨ a = b ∨ M.lt b a = trueWhen applied to mathematical values, the operators refer to the usual mathematical operations.
< is preserved by addition.
add_lt_addLean
add_lt_add : ∀ a b c, M.lt a b = true → M.lt (M.add a c) (M.add b c) = trueA product of positive values is positive.
mul_posLean
mul_pos : ∀ a b, M.lt (M.ofNat 0) a = true → M.lt (M.ofNat 0) b = true → M.lt (M.ofNat 0) (M.mul a b) = true
= on mathematical values is equality.
eq_iffLean
eq_iff : ∀ a b, M.eq a b = true ↔ a = bNumerals add as natural numbers.
ofNat_addLean
ofNat_add : ∀ m n, M.ofNat (m + n) = M.add (M.ofNat m) (M.ofNat n)X⁰ = 1.
pow_zeroLean
pow_zero : ∀ x, M.pow x (M.ofNat 0) = M.ofNat 1Xⁿ⁺¹ = xⁿ × x.
pow_succLean
pow_succ : ∀ x n, M.pow x (M.ofNat (n + 1)) = M.mul (M.pow x (M.ofNat n)) xThe mathematical function floor(x) produces the largest integer (closest to +∞) that is not larger than x.
Floor(x) is an integer.
floor_isIntLean
floor_isInt : ∀ x, M.isInt (M.floor x) = trueFloor(x) ≤ x.
floor_leLean
floor_le : ∀ x, M.lt x (M.floor x) = falseX < floor(x) + 1: no larger integer is ≤ x.
lt_floor_add_oneLean
lt_floor_add_one : ∀ x, M.lt x (M.add (M.floor x) (M.ofNat 1)) = truea digit is significant if it is not zero or there is a non-zero digit to its left and there is a non-zero digit to its right
For x > 0, decExp x is the integer e with 10^e ≤ x < 10^(e+1), the place of x's first significant digit.
decExp_specLean
decExp_spec : ∀ x, M.lt (M.ofNat 0) x = true → M.isInt (M.decExp x) = true ∧ M.lt x (M.pow (M.ofNat 10) (M.decExp x)) = false ∧ M.lt x (M.pow (M.ofNat 10) (M.add (M.decExp x) (M.ofNat 1))) = true
When the term integer is used in this specification, it refers to a mathematical value which is in the set of integers, unless otherwise stated.
The integers are ±n.
isInt_iffLean
isInt_iff : ∀ x, M.isInt x = true ↔ ∃ n, x = M.ofNat n ∨ x = M.neg (M.ofNat n)are represented in ECMAScript as a single special NaN ("not a number") value.
NaN's view.
numView_nanLean
numView_nan : M.numView M.numNaN = .nanThere are two other special values, called positive Infinity and negative Infinity.
+∞𝔽 and -∞𝔽's views.
numView_infLean
numView_inf : ∀ b, M.numView (M.numInf b) = if b then .negInf else .posInfNote that there is both a positive zero and a negative zero.
+0𝔽 and -0𝔽's views.
numView_zeroLean
numView_zero : ∀ b, M.numView (M.numZero b) = if b then .negZero else .posZerorepresenting the double-precision floating point IEEE 754-2019 binary64 values
The Number type's value set, 𝔽 and the operations (NumLaws).
numLean
num : M.NumLawsBigInts: ECMAScript language values representing arbitrary integers in a one-to-one correspondence.
ℝ(ℤ(x)) = x for an integer x.
bigVal_bigOfLean
bigVal_bigOf : ∀ x, M.isInt x = true → M.bigVal (M.bigOf x) = xA BigInt's value is an integer.
bigVal_isIntLean
bigVal_isInt : ∀ b, M.isInt (M.bigVal b) = trueA BigInt is its value.
bigVal_injLean
bigVal_inj : ∀ a b, M.bigVal a = M.bigVal b → a = bThese positions are indexed with non-negative integers. The first element (if any) is at index 0, the next element (if any) at index 1, and so on.
A code unit is at a non-negative integer index below the length and is in [0, 65535].
strAt_someLean
strAt_some : ∀ s i c, M.strAt s i = some c → (∃ k, i = M.ofNat k ∧ M.lt i (M.strLen s) = true) ∧ ∃ u, u < 65536 ∧ c = M.ofNat u
The String type is the set of all ordered sequences of zero or more 16-bit unsigned integer values
A String is its sequence of code units.
str_extLean
str_ext : ∀ s t, M.strLen s = M.strLen t → (∀ k, M.strAt s (M.ofNat k) = M.strAt t (M.ofNat k)) → s = t
denotes the String value whose sequence of code units is the concatenation of the code units (in order) of each of the arguments (in order)
String-concatenation adds lengths.
strConcat_lenLean
strConcat_len : ∀ s t, M.strLen (M.strConcat s t) = M.add (M.strLen s) (M.strLen t)String-concatenation's code units are the first String's, then the second's.
strConcat_atLean
strConcat_at : ∀ s t i, M.strAt (M.strConcat s t) i = if M.lt i (M.strLen s) then M.strAt s i else M.strAt t (M.sub i (M.strLen s))
denotes the String value consisting of the consecutive code units of string beginning at index inclusiveStart and ending immediately before index exclusiveEnd
The substring from i to j has length j - i.
strSub_lenLean
strSub_len : ∀ s i j, i ≤ j → M.lt (M.strLen s) (M.ofNat j) = false → M.strLen (M.strSub s (M.ofNat i) (M.ofNat j)) = M.ofNat (j - i)
The substring from i has the code units from i.
strSub_atLean
strSub_at : ∀ s i j k, i ≤ j → M.lt (M.strLen s) (M.ofNat j) = false → k < j - i → M.strAt (M.strSub s (M.ofNat i) (M.ofNat j)) (M.ofNat k) = M.strAt s (M.ofNat (i + k))
(where each argument is a String value, a code unit, or a sequence of code units)
The String of one code unit has length 1.
strOfUnit_lenLean
strOfUnit_len : ∀ u, u < 65536 → M.strLen (M.strOfUnit (M.ofNat u)) = M.ofNat 1The String of one code unit has it at index 0.
strOfUnit_atLean
strOfUnit_at : ∀ u, u < 65536 → M.strAt (M.strOfUnit (M.ofNat u)) (M.ofNat 0) = some (M.ofNat u)If n = 0, return the empty String.
Repeating a String zero times is the empty String.
strRepeat_zeroLean
strRepeat_zero : ∀ s, M.strRepeat (M.ofNat 0) s = M.strLit ""Return the String value that is made from n copies of string appended together.
Repeating n + 1 times appends another copy.
strRepeat_succLean
strRepeat_succ : ∀ n s, M.strRepeat (M.ofNat (n + 1)) s = M.strConcat (M.strRepeat (M.ofNat n) s) s
The digits used in the representation of a number using radix r are taken from the first r code units of "0123456789abcdefghijklmnopqrstuvwxyz" in order.
A single radix-r digit n < r has that code unit as its representation.
intToRadix_digitLean
intToRadix_digit : ∀ n r, 2 ≤ r → r ≤ 36 → n < r → M.intToRadix (M.ofNat n) (M.ofNat r) = M.strSub (M.strLit "0123456789abcdefghijklmnopqrstuvwxyz") (M.ofNat n) (M.ofNat (n + 1))
It represents x as a String using a positional numeral system with radix radix.
The representation of numbers with magnitude greater than or equal to 1𝔽 never includes leading zeroes.
For n ≥ r, the radix-r representation of n is that of n / r followed by the digit n % r.
intToRadix_divLean
intToRadix_div : ∀ n r, 2 ≤ r → r ≤ 36 → r ≤ n → M.intToRadix (M.ofNat n) (M.ofNat r) = M.strConcat (M.intToRadix (M.ofNat (n / r)) (M.ofNat r)) (M.intToRadix (M.ofNat (n % r)) (M.ofNat r))
Values without identity are equal to other values without identity if all of their innate characteristics are the same
String equality is equality of code-unit sequences.
strEq_iffLean
strEq_iff : ∀ s t, M.strEq s t = true ↔ s = teach element in the String is treated as a UTF-16 code unit value
A String literal is the UTF-16 code units of its text (strLitUnits).
strLit_unitsLean
strLit_units : ∀ t, seqList (M.strUnits (M.strLit t)) = (strLitUnits t).map M.ofNatThe length of a String is the number of elements (i.e., 16-bit values) within it.
A String has as many code units as its length.
strUnits_lenLean
strUnits_len : ∀ s, M.ofNat (seqList (M.strUnits s)).length = M.strLen sThese positions are indexed with non-negative integers. The first element (if any) is at index 0, the next element (if any) at index 1, and so on.
A String's code units, first to last, are those at its indices.
strUnits_atLean
strUnits_at : ∀ s k, (seqList (M.strUnits s))[k]? = M.strAt s (M.ofNat k)Each Symbol is unique and immutable.
Symbol equality is identity.
symEq_iffLean
symEq_iff : ∀ a b, M.symEq a b = true ↔ a = bEach Symbol has an immutable [[Description]] internal slot whose value is either a String or undefined.
A new Symbol has the description it is made with.
symDesc_newLean
symDesc_new : ∀ k d, M.symDesc (M.symNew k d) = dEach Symbol is unique and immutable.
Each creation makes a different Symbol.
symNew_injLean
symNew_inj : ∀ k d k' d', M.symNew k d = M.symNew k' d' → k = k'each value with identity is unique and therefore only equal to itself.
An object is its identity.
addrEq_iffLean
addrEq_iff : ∀ a b, M.addrEq a b = true ↔ a = bA Parse Node, a value with identity, is equal only to itself.
nodeEq_iffLean
nodeEq_iff : ∀ a b, M.nodeEq a b = true ↔ a = bThe elements of a list may be randomly accessed using 0-origin indices.
A List's length is a non-negative integer.
seqLen_natLean
seqLen_nat : ∀ {α} (xs : M.Seq α), ∃ n, M.seqLen xs = M.ofNat nAn element is at a non-negative integer index below the length.
seqGet_someLean
seqGet_some : ∀ {α} (xs : M.Seq α) i (a : α), M.seqGet xs i = some a → ∃ k, i = M.ofNat k ∧ M.lt i (M.seqLen xs) = true
Every index below the length has an element.
seqGet_ltLean
seqGet_lt : ∀ {α} (xs : M.Seq α) k, M.lt (M.ofNat k) (M.seqLen xs) = true → (M.seqGet xs (M.ofNat k)).isSome = true
Values of the List type are simply ordered sequences of list elements containing the individual values.
A List is its sequence of elements.
seq_extLean
seq_ext : ∀ {α} (xs ys : M.Seq α), (∀ i, M.seqGet xs i = M.seqGet ys i) → xs = ysA new empty List can be expressed as « ».
« » has length 0.
seqLen_nilLean
seqLen_nil : ∀ {α}, M.seqLen (M.seqNil (α := α)) = M.ofNat 0« » has no elements.
seqGet_nilLean
seqGet_nil : ∀ {α} i, M.seqGet (M.seqNil (α := α)) i = noneValues of the List type are simply ordered sequences of list elements containing the individual values.
Appending adds one to the length.
seqLen_pushLean
seqLen_push : ∀ {α} (xs : M.Seq α) a, M.seqLen (M.seqPush xs a) = M.add (M.seqLen xs) (M.ofNat 1)Appending puts the element last.
seqGet_pushLean
seqGet_push : ∀ {α} (xs : M.Seq α) a i, M.seqGet (M.seqPush xs a) i = if M.eq i (M.seqLen xs) then some a else M.seqGet xs i
Prepending adds one to the length.
seqLen_consLean
seqLen_cons : ∀ {α} (a : α) xs, M.seqLen (M.seqCons a xs) = M.add (M.seqLen xs) (M.ofNat 1)Prepending puts the element first.
seqGet_consLean
seqGet_cons : ∀ {α} (a : α) xs i, M.seqGet (M.seqCons a xs) i = if M.eq i (M.ofNat 0) then some a else M.seqGet xs (M.sub i (M.ofNat 1))
Replacing an element keeps the length.
seqLen_setLean
seqLen_set : ∀ {α} (xs : M.Seq α) i a, M.seqLen (M.seqSet xs i a) = M.seqLen xsReplacing the element at an index below the length (read-over-write).
seqGet_setLean
seqGet_set : ∀ {α} (xs : M.Seq α) i a j, M.seqGet (M.seqSet xs i a) j = if M.eq j i && (M.seqGet xs i).isSome then some a else M.seqGet xs j
denotes a new List value whose elements are the concatenation of the elements (in order) of each of the arguments (in order)
List-concatenation adds lengths.
seqLen_concatLean
seqLen_concat : ∀ {α} (xs ys : M.Seq α), M.seqLen (M.seqConcat xs ys) = M.add (M.seqLen xs) (M.seqLen ys)List-concatenation's elements are the first List's, then the second's.
seqGet_concatLean
seqGet_concat : ∀ {α} (xs ys : M.Seq α) i, M.seqGet (M.seqConcat xs ys) i = if M.lt i (M.seqLen xs) then M.seqGet xs i else M.seqGet ys (M.sub i (M.seqLen xs))
Values of the List type are simply ordered sequences of list elements containing the individual values.
Removing the element at an index below the length shortens by one.
seqLen_removeLean
seqLen_remove : ∀ {α} (xs : M.Seq α) i, (M.seqGet xs i).isSome = true → M.seqLen (M.seqRemove xs i) = M.sub (M.seqLen xs) (M.ofNat 1)
Removing the element at an index below the length shifts the later ones.
seqGet_removeLean
seqGet_remove : ∀ {α} (xs : M.Seq α) i j, (M.seqGet xs i).isSome = true → M.seqGet (M.seqRemove xs i) j = if M.lt j i then M.seqGet xs j else M.seqGet xs (M.add j (M.ofNat 1))
Removing at an index with no element changes nothing.
seqRemove_noneLean
seqRemove_none : ∀ {α} (xs : M.Seq α) i, M.seqGet xs i = none → M.seqRemove xs i = xsA Data Block value is created with a fixed number of bytes that each have the initial value 0.
k copies of a value are k elements.
seqLen_repeatLean
seqLen_repeat : ∀ {α} k (a : α), M.seqLen (M.seqRepeat (M.ofNat k) a) = M.ofNat kEach of k copies of a value is that value.
seqGet_repeatLean
seqGet_repeat : ∀ {α} k (a : α) i x, M.seqGet (M.seqRepeat (M.ofNat k) a) i = some x → x = aWhen an algorithm iterates over the elements of a List without specifying an order, the order used is the order of the elements in the List.
A fold of « » is its start.
seqFoldl_nilLean
seqFoldl_nil : ∀ {α β} (f : β → α → β) (b : β), M.seqFoldl f b (M.seqNil (α := α)) = bA fold visits the elements first to last.
seqFoldl_pushLean
seqFoldl_push : ∀ {α β} (f : β → α → β) (b : β) (xs : M.Seq α) a, M.seqFoldl f b (M.seqPush xs a) = f (M.seqFoldl f b xs) a
Any fields that are not explicitly listed are considered to be absent.
The empty Record has no fields.
recGet_emptyLean
recGet_empty : ∀ {α} f, M.recGet (M.recEmpty (α := α)) f = noneA Record type value consists of one or more named fields.
Setting a field (read-over-write).
recGet_setLean
recGet_set : ∀ {α} (r : M.Rec α) f a g, M.recGet (M.recSet r f a) g = if g = f then some a else M.recGet r gAny fields that are not explicitly listed are considered to be absent.
Deleting a field makes it absent.
recGet_delLean
recGet_del : ∀ {α} (r : M.Rec α) f g, M.recGet (M.recDel r f) g = if g = f then none else M.recGet r gA Record type value consists of one or more named fields.
The listed fields are the present ones.
recKeys_memLean
recKeys_mem : ∀ {α} (r : M.Rec α) f, (M.recGet r f).isSome = true ↔ ∃ i, M.seqGet (M.recKeys r) i = some fEach field is listed once.
recKeys_onceLean
recKeys_once : ∀ {α} (r : M.Rec α) f i j, M.seqGet (M.recKeys r) i = some f → M.seqGet (M.recKeys r) j = some f → i = j
The properties of an object are uniquely identified using property keys.
The empty table has no properties.
propsGet_emptyLean
propsGet_empty : ∀ {α} k, M.propsGet (M.propsEmpty (α := α)) k = nonePutting a property reads it back.
propsGet_put_selfLean
propsGet_put_self : ∀ {α} (p : M.Props α) k a, M.propsGet (M.propsPut p k a) k = some aPutting a property leaves the others.
propsGet_put_otherLean
propsGet_put_other : ∀ {α} (p : M.Props α) k a k', k' ≠ k → M.propsGet (M.propsPut p k a) k' = M.propsGet p k'Deleting a property removes it.
propsGet_del_selfLean
propsGet_del_self : ∀ {α} (p : M.Props α) k, M.propsGet (M.propsDel p k) k = noneDeleting a property leaves the others.
propsGet_del_otherLean
propsGet_del_other : ∀ {α} (p : M.Props α) k k', k' ≠ k → M.propsGet (M.propsDel p k) k' = M.propsGet p k'The listed keys are the present ones.
propsKeys_memLean
propsKeys_mem : ∀ {α} (p : M.Props α) k, (M.propsGet p k).isSome = true ↔ ∃ i, M.seqGet (M.propsKeys p) i = some kEach own property of an object must have a key that is distinct from the keys of the other own properties of that object.
Each key is listed once.
propsKeys_onceLean
propsKeys_once : ∀ {α} (p : M.Props α) k i j, M.seqGet (M.propsKeys p) i = some k → M.seqGet (M.propsKeys p) j = some k → i = j
in ascending chronological order of property creation
A new key goes last in creation order.
propsKeys_put_newLean
propsKeys_put_new : ∀ {α} (p : M.Props α) k a, M.propsGet p k = none → M.propsKeys (M.propsPut p k a) = M.seqPush (M.propsKeys p) k
Updating a present key keeps creation order.
propsKeys_put_oldLean
propsKeys_put_old : ∀ {α} (p : M.Props α) k a, (M.propsGet p k).isSome = true → M.propsKeys (M.propsPut p k a) = M.propsKeys p
Deleting a key removes it from creation order.
propsKeys_delLean
propsKeys_del : ∀ {α} (p : M.Props α) k i, M.seqGet (M.propsKeys p) i = some k → M.propsKeys (M.propsDel p k) = M.seqRemove (M.propsKeys p) i
The properties of an object are uniquely identified using property keys.
Deleting an absent key changes nothing.
propsDel_absentLean
propsDel_absent : ∀ {α} (p : M.Props α) k, M.propsGet p k = none → M.propsDel p k = pReferences to existing values with identity cannot be manifest simply by describing them
The empty store refers to no value.
heapGet_emptyLean
heapGet_empty : ∀ {α} a, M.heapGet (M.heapEmpty (α := α)) a = noneeach value with identity is unique and therefore only equal to itself.
An allocated address is fresh.
heapAlloc_freshLean
heapAlloc_fresh : ∀ {α} (h : M.Heap α) v, M.heapGet h (M.heapAlloc h v).1 = noneReferences to existing values with identity cannot be manifest simply by describing them
The allocated cell holds the value it is made with.
heapAlloc_get_selfLean
heapAlloc_get_self : ∀ {α} (h : M.Heap α) v, M.heapGet (M.heapAlloc h v).2 (M.heapAlloc h v).1 = some vSome values with identity are mutable and therefore can have their characteristics (except their identity) changed in-place, causing all holders of the value to observe the new characteristics.
Allocating leaves the other cells.
heapAlloc_get_otherLean
heapAlloc_get_other : ∀ {α} (h : M.Heap α) v a, a ≠ (M.heapAlloc h v).1 → M.heapGet (M.heapAlloc h v).2 a = M.heapGet h a
Writing an allocated cell (read-over-write).
heapGet_set_selfLean
heapGet_set_self : ∀ {α} (h : M.Heap α) a v, (M.heapGet h a).isSome = true → M.heapGet (M.heapSet h a v) a = some vWriting a cell leaves the others.
heapGet_set_otherLean
heapGet_set_other : ∀ {α} (h : M.Heap α) a v b, b ≠ a → M.heapGet (M.heapSet h a v) b = M.heapGet h bReferences to existing values with identity cannot be manifest simply by describing them
Writing an unallocated cell changes nothing.
heapSet_noneLean
heapSet_none : ∀ {α} (h : M.Heap α) a v, M.heapGet h a = none → M.heapSet h a v = hA CharSet is a mathematical set of CharSetElements.
CsSize is the non-negative integer count of elements in the CharSet.
csSize_natLean
csSize_nat : ∀ cs, M.isInt (M.csSize cs) = true ∧ ¬ M.lt (M.csSize cs) (M.ofNat 0)Every index csGet reads is a valid index into the CharSet and yields a sequence of code points in it.
csGet_someLean
csGet_some : ∀ cs i e, M.csGet cs i = some e → M.isInt i = true ∧ ¬ M.lt i (M.ofNat 0) ∧ M.lt i (M.csSize cs) = true ∧ M.allPoints e ∧ M.csHas cs e = true
Every index below csSize holds an element.
csGet_ltLean
csGet_lt : ∀ cs i, M.isInt i = true → ¬ M.lt i (M.ofNat 0) → M.lt i (M.csSize cs) = true → (M.csGet cs i).isSome = trueThe CharSet has no duplicate elements at distinct indices.
Every element in csHas appears at some index of csGet.
The empty CharSet has no elements.
csHas_emptyLean
csHas_empty : ∀ e, M.csHas M.csEmpty e = falseCsAdd inserts a CharSetElement of code points into the CharSet.
For convenience, when working with CharSetElements of this kind, an individual character is treated interchangeably with a sequence of one character.
CsInterval contains the one-character CharSetElements between lo and hi inclusive.
csHas_intervalLean
csHas_interval : ∀ lo hi e, M.isPoint lo → M.isPoint hi → M.allPoints e → (M.csHas (M.csInterval lo hi) e = true ↔ ∃ c, seqList e = [c] ∧ M.isPoint c ∧ ¬ M.lt c lo ∧ ¬ M.lt hi c)
A CharSet is a mathematical set of CharSetElements.
CsUnion is set union of CharSets.
csHas_unionLean
csHas_union : ∀ a b e, M.allPoints e → (M.csHas (M.csUnion a b) e = true ↔ M.csHas a e = true ∨ M.csHas b e = true)CsInter is set intersection of CharSets.
csHas_interLean
csHas_inter : ∀ a b e, M.allPoints e → (M.csHas (M.csInter a b) e = true ↔ M.csHas a e = true ∧ M.csHas b e = true)CsDiff is set difference of CharSets.
csHas_diffLean
csHas_diff : ∀ a b e, M.allPoints e → (M.csHas (M.csDiff a b) e = true ↔ M.csHas a e = true ∧ M.csHas b e = false)For convenience, when working with CharSetElements of this kind, an individual character is treated interchangeably with a sequence of one character.
CsAllSingle holds iff every element of the CharSet is a single character.
csAllSingle_iffLean
csAllSingle_iff : ∀ cs, M.csAllSingle cs = true ↔ ∀ i e, M.csGet cs i = some e → M.seqLen e = M.ofNat 1CsSingles restricts a CharSet to its single-character elements.
csHas_singlesLean
csHas_singles : ∀ cs e, M.allPoints e → (M.csHas (M.csSingles cs) e = true ↔ M.csHas cs e = true ∧ M.seqLen e = M.ofNat 1)
Let charSet be the CharSet containing all CharSetElements whose character database definition includes the property p with value “True”.
CsFromProp succeeds on the exact same property-value queries as propSet.
csFromProp_someLean
csFromProp_some : ∀ p v, (M.csFromProp p v).isSome = (M.propSet p v).isSomeCsFromProp holds the CharSetElements that propSet returns.
Return the CharSet containing all Unicode code points c that do not have a Simple Case Folding mapping (that is, scf(c)=c).
CsNoScf contains every Unicode code point whose simple case folding is itself.
csHas_noScfLean
csHas_noScf : ∀ e, M.allPoints e → (M.csHas M.csNoScf e = true ↔ ∃ c, seqList e = [c] ∧ M.isPoint c ∧ (M.scf? c).getD c = c)
Let extraWordChars be the CharSet containing all characters c such that c is not in basicWordChars but Canonicalize(regexpRecord, c) is in basicWordChars.
CsCanonExtra contains every character outside cs whose case-folded Canonicalize maps into cs.
csHas_canonExtraLean
csHas_canonExtra : ∀ cs u e, M.allPoints e → (M.csHas (M.csCanonExtra cs u) e = true ↔ ∃ c, seqList e = [c] ∧ M.isPoint c ∧ M.csHas cs (M.seqPush M.seqNil c) = false ∧ M.csHas cs (M.seqPush M.seqNil (M.canonChar true u c)) = true)
If there exists a CharSetElement in charSet containing exactly one character a such that Canonicalize(regexpRecord, a) is cc, let found be true; else let found be false.
CsHasCanon tests whether any single character a in cs canonicalizes to cc.
csHasCanon_iffLean
csHasCanon_iff : ∀ cs cc u ic, M.isPoint cc → (M.csHasCanon cs cc u ic = true ↔ ∃ a, M.isPoint a ∧ M.csHas cs (M.seqPush M.seqNil a) = true ∧ M.canonChar ic u a = cc)
A Data Block value is created with a fixed number of bytes that each have the initial value 0.
Data Block byte sequences (ByteLaws).
bytesLean
bytes : M.ByteLawsModel.stringPropertyNames
Laws.lean:761The names of Table 67's binary properties of strings.
def Model.stringPropertyNames : List String := ["Basic_Emoji", "Emoji_Keycap_Sequence", "RGI_Emoji_Modifier_Sequence", "RGI_Emoji_Flag_Sequence", "RGI_Emoji_Tag_Sequence", "RGI_Emoji_ZWJ_Sequence", "RGI_Emoji"]
Model.codePointsOf
Laws.lean:766A name's code points.
def Model.codePointsOf (M : Model) (s : String) : M.Seq M.Math := s.toList.foldr (fun c q => M.seqCons (M.ofNat c.toNat) q) M.seqNil
Model.UnicodeLaws
Laws.lean:770The laws of the Unicode operations: only what the text relies on.
Proved of the engine's model: Engine.Impl.unicodeLaws, part of Implements.model.
structure Model.UnicodeLaws (M : Model) : Prop where7 laws
If the file CaseFolding.txt of the Unicode Character Database provides a simple or common case folding mapping for char, return the result of applying that mapping to char.
Simple case folding gives a code point.
scf_pointLean
scf_point : ∀ c d, M.isPoint c → M.scf? c = some d → M.isPoint dLet lowerText be toLowercase(sText), according to the Unicode Default Case Conversion algorithm.
ToLowercase gives code points.
toLower_pointsLean
toLower_points : ∀ xs, M.allPoints xs → M.allPoints (M.toLower xs)except that the String is mapped using the toUppercase algorithm of the Unicode Default Case Conversion
ToUppercase gives code points.
toUpper_pointsLean
toUpper_points : ∀ xs, M.allPoints xs → M.allPoints (M.toUpper xs)Let charSet be the CharSet containing all CharSetElements whose character database definition includes the property p with value “True”.
A property value's elements are sequences of code points.
propSet_charsLean
propSet_chars : ∀ p v es i e, M.propSet p v = some es → M.seqGet es i = some e → M.allPoints eA property value's elements are distinct.
propSet_distinctLean
propSet_distinct : ∀ p v es i j e f, M.propSet p v = some es → M.seqGet es i = some e → M.seqGet es j = some f → M.eq i j = false → ∃ k, M.seqGet e k ≠ M.seqGet f k
or a binary Unicode property of strings listed in the “ Property name ” column of
An element of two or more code points only for a property of strings.
propSet_stringsLean
propSet_strings : ∀ p v es i e, M.propSet p v = some es → M.seqGet es i = some e → M.eq (M.seqLen e) (M.ofNat 1) = false → ∃ n ∈ Model.stringPropertyNames, ∀ k, M.seqGet p k = M.seqGet (M.codePointsOf n) k
Let normal be the String value that is the result of normalizing string into the normalization form named by form as specified in the latest Unicode Standard, Normalization Forms.
Normalization gives code points.
normalize_pointsLean
normalize_points : ∀ f xs, M.allPoints xs → M.allPoints (M.normalize f xs)Model.InSeq
Laws.lean:804c is an element of the List s.
def Model.InSeq {M : Model} {α : Type} (c : α) (s : M.Seq α) : Prop := M.seqFoldl (fun P x => P ∨ x = c) False s
Model.KidOf
Laws.lean:808n is a child of p: one of p's children is n by identity (nodeEq).
def Model.KidOf {M : Model} (n p : M.Node) : Prop := ∃ c, Model.InSeq c (M.nodeKids p) ∧ M.nodeEq c n = true
Model.Within
Laws.lean:812p is r or a Parse Node in the tree below r, at any depth.
inductive Model.Within {M : Model} : M.Node → M.Node → Prop | root (r : M.Node) : Model.Within r r | kid {r c p : M.Node} : Model.InSeq c (M.nodeKids r) → Model.Within c p → Model.Within r p
Model.ParentLaws
Laws.lean:818Model.nodeParent's laws (§5.1.2 Parent): an answer is a node at or below r of which n is a child, and there is one wherever such a node is; with them nodeAncestors' and nodeHeight's.
Proved of the engine's model: Engine.Impl.parentLaws, part of Implements.model.
structure Model.ParentLaws (M : Model) : Prop where4 laws
Moreover, it has zero or more children, one for each symbol on the production's right-hand side: each child is a Parse Node that is an instance of the corresponding symbol.
The parent the model gives of n in the tree rooted at r is a node at or below r of which n is a child.
soundLean
sound : ∀ r n p, M.nodeParent r n = some p → Model.Within r p ∧ Model.KidOf n pWherever a node at or below r has n as a child, the model gives a parent of n.
completeLean
complete : ∀ r n p, Model.Within r p → Model.KidOf n p → (M.nodeParent r n).isSome = trueThe ancestors of n in the tree rooted at r are its parent, then the parent's ancestors; none for a node without a parent.
ancestorsLean
ancestors : ∀ r n, M.nodeAncestors r n = match M.nodeParent r n with | some p => p :: M.nodeAncestors r p | none => []
A Parse Node's height the model gives is more than each of its children's: the tree below it is no deeper than its height.
heightLean
height : ∀ n c, Model.InSeq c (M.nodeKids n) → M.nodeHeight c < M.nodeHeight n