ECMA-262 in Lean

Reading 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.

inductive

NumView

Model.lean:22

The case view of a Number value (§6.1.6.1).

inductive NumView (Math : Type) where

a finite non-zero value: its mathematical value

| finite (m : Math)
structure

ParseCx

Model.lean:35

A 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 where
annexB : Grammar.AnnexB.Set
inductive

NormForm

Model.lean:43

The Unicode Normalization Forms (UAX #15).

inductive NormForm where
| NFC | NFD | NFKC | NFKD
structure

Model

Model.lean:48

A model of the spec's sorts and their primitive operations.

structure Model where

mathematical values (§5.2.6)

Math : Type

Number values (§6.1.6.1)

Num : Type

BigInt values (§6.1.6.2)

Big : Type

String values: sequences of 16-bit code units (§6.1.4)

Str : Type

Symbol values: identities (§6.1.5)

Sym : Type

identities of store cells: objects, Records and Lists

Addr : Type

Parse Nodes (§5.1.2)

Node : Type

finite sequences: List contents (§6.2.2)

Seq : Type → Type

byte sequences: Data Block contents (§6.2.9)

Bytes : Type

finite maps from field names: Record contents and internal slots (§6.2.1)

Rec : Type → Type

own-property tables: maps from property keys, in creation order (§6.1.7)

Props : Type → Type

the store

Heap : Type → Type

a numeral

ofNat : Nat → Math
add : Math → Math → Math
sub : Math → Math → Math
mul : Math → Math → Math
div : Math → Math → Math
neg : Math → Math

x<sup>y</sup>: for an integer y, or for x > 0 and any y

pow : Math → Math → Math
lt : Math → Math → Bool
eq : Math → Math → Bool

the largest integer ≤ x

floor : Math → Math

"x is an integer"

isInt : Math → Bool

the 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 → Math

the square root of a non-negative mathematical value

sqrt : Math → Math

π

pi : Math

a §21.3 function at x, on the domain the calling steps guard; opaque: every use is implementation-approximated

fn : MathFn → Math → Math

𝔽(x) for finite x: roundTiesToEven to the nearest Number value (§6.1.6.1)

numOf : Math → Num

+∞𝔽 (false) or -∞𝔽 (true)

numInf : Bool → Num

+0𝔽 (false) or -0𝔽 (true)

numZero : Bool → Num

IEEE 754-2019 addition, roundTiesToEven (§5.2.6: operators on Numbers)

numAdd : Num → Num → Num
numSub : Num → Num → Num
numMul : Num → Num → Num
numDiv : Num → Num → Num

IEEE 754-2019 compareQuietLess

numLt : Num → Num → Bool

IEEE 754-2019 compareQuietEqual

numEq : Num → Num → Bool

Number::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 → Math

a String literal of the text

strLit : String → Str

the code unit at an index, as a mathematical value

strAt : Str → Math → Option Math

the substring from i to j

strSub : Str → Math → Math → Str

the String of one code unit

strOfUnit : Math → Str

the String made from n copies of s appended together (n ≥ 0)

strRepeat : Math → Str → Str

the representation of non-negative integer n using radix r (2 ≤ r ≤ 36)

intToRadix : Math → Math → Str
strEq : Str → Str → Bool

the code units, first to last

strUnits : Str → Seq Math
symEq : Sym → Sym → Bool

a Symbol's [[Description]]: a String, or none for undefined (§6.1.5)

symDesc : Sym → Option Str

the Symbol made by the kth creation, with the description

symNew : Nat → Option Str → Sym
addrEq : Addr → Addr → Bool

the 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 Node

the proper descendants, in pre-order

nodeDescendants : Node → Seq Node

the nonterminal the node is an instance of

nodeNt : Node → NtId

the code points of the source text it matched (§11)

nodeSource : Node → Seq Math

the 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 → Nat

the span of source text it matched, in code points

nodeSpan : Node → Nat × Nat

nodeParent 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 Node

nodeAncestors 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 Node

whether two Parse Nodes are the same one

nodeEq : Node → Node → Bool
seqNil : {α : Type} → Seq α
seqPush : {α : Type} → Seq α → α → Seq α
seqCons : {α : Type} → α → Seq α → Seq α
seqLen : {α : Type} → Seq α → Math
seqGet : {α : 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 FieldId
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)

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 Math

toLowercase (Unicode §3.13, Default Case Conversion): full lowercase mappings, Final_Sigma in context

toLower : Seq Math → Seq Math

toUppercase (Unicode §3.13, Default Case Conversion): full uppercase mappings

toUpper : Seq Math → Seq Math

the 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 Math
csAdd : CharSet → Seq Math → CharSet
csUnion : CharSet → CharSet → CharSet
csInter : CharSet → CharSet → CharSet
csDiff : CharSet → CharSet → CharSet
csHas : CharSet → Seq Math → Bool
csSize : CharSet → Math
csGet : CharSet → Math → Option (Seq Math)
csFromProp : Seq Math → Seq Math → Option CharSet
csHasCanon : CharSet → Math → Bool → Bool → Bool

a Data Block of n zero bytes (§6.2.9, empty if not a non-negative integer)

bytesZero : Math → Bytes
bytesGet : Bytes → Math → Option Math
bytesSet : Bytes → Math → Math → Bytes
bytesFill : Bytes → Math → Bytes
def

seqList

Model.lean:270

A List's elements, first to last.

def seqList {M : Model} {α : Type} (sq : M.Seq α) : List α := M.seqFoldl (fun l x => l ++ [x]) [] sq
def

Model.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.

def

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]
def

strLitUnits

Laws.lean:23

The 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.toNat

The Number type (§6.1.6.1): its value set, the Number value for a real, and IEEE 754-2019's operations on it.

def

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 x
def

Model.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
def

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))
def

Model.candidate

Laws.lean:47

The 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)
def

Model.nearest

Laws.lean:52

y 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)
def

Model.viewFor

Laws.lean:59

The 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
def

Model.realOf

Laws.lean:66

The 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
def

Model.digitsOf

Laws.lean:74

Number::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
structure

Model.NumLaws

Laws.lean:82

The 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 where

12 laws

6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

representing the double-precision floating point IEEE 754-2019 binary64 values

A view determines the Number value.

numView_inj
Lean
numView_inj : ∀ a b, M.numView a = M.numView b → a = b
6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

non-zero finite Numbers are partitioned into two groups

Every finite view is a normalized or denormalized value (finiteNum).

numView_finite
Lean
numView_finite : ∀ a m, M.numView a = .finite m → ∃ ev, M.finiteNum m ev

Every normalized or denormalized value is a Number value.

finiteNum_view
Lean
finiteNum_view : ∀ m ev, M.finiteNum m ev → ∃ a, M.numView a = .finite m
6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

Choose 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_nearest
Lean
numOf_nearest : ∀ x, ∃ y, M.nearest x y ∧ M.numView (M.numOf x) = M.viewFor x y
6.1.6.1.1 Number::unaryMinus sec-numeric-types-number-unaryMinus

Return the negation of number; that is, compute a Number with the same magnitude but opposite sign.

Negation flips the sign; NaN stays.

numNeg_view
Lean
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)
6.1.6.1.7 Number::add sec-numeric-types-number-add

If x is -0𝔽 and y is -0𝔽, return -0𝔽. 1. Return 𝔽(ℝ(x) + ℝ(y)).

Number::add's steps, a row each.

numAdd_view
Lean
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
6.1.6.1.8 Number::subtract sec-numeric-types-number-subtract

Return Number::add(x, Number::unaryMinus(y)).

Subtraction is addition of the negation.

numSub_def
Lean
numSub_def : ∀ a b, M.numSub a b = M.numAdd a (M.numNeg b)
6.1.6.1.4 Number::multiply sec-numeric-types-number-multiply

Return 𝔽(ℝ(x) × ℝ(y)).

Number::multiply's steps, a row each.

numMul_view
Lean
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
6.1.6.1.5 Number::divide sec-numeric-types-number-divide

Return 𝔽(ℝ(x) / ℝ(y)).

Number::divide's steps, a row each.

numDiv_view
Lean
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
6.1.6.1.12 Number::lessThan sec-numeric-types-number-lessThan

If ℝ(x) < ℝ(y), return true.

Number::lessThan's steps, undefined read as false.

numLt_def
Lean
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
6.1.6.1.13 Number::equal sec-numeric-types-number-equal

If x is +0𝔽 and y is -0𝔽, return true.

Number::equal's steps.

numEq_def
Lean
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
6.1.6.1.20 Number::toString sec-numeric-types-number-tostring

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_least
Lean
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
def

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
def

Model.allPoints

Laws.lean:191

Every 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
def

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
structure

Model.ByteLaws

Laws.lean:199

The laws of Data Block byte sequences (§6.2.9).

Proved as part of Model.Laws (its field bytes).

structure Model.ByteLaws (M : Model) : Prop where

9 laws

6.2.9 Data Blocks sec-data-blocks

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_nonneg
Lean
bytesLen_nonneg : ∀ bs, M.isInt (M.bytesLen bs) = true ∧ M.lt (M.bytesLen bs) (M.ofNat 0) = false

A byte exists at index i iff i is a non-negative integer less than the block length.

bytesGet_bounds
Lean
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_byte
Lean
bytesGet_byte : ∀ bs i b, M.bytesGet bs i = some b → M.isByte b

BytesZero n has n bytes when n is a non-negative integer.

bytesZero_len
Lean
bytesZero_len : ∀ n, M.isInt n = true → M.lt n (M.ofNat 0) = false → M.bytesLen (M.bytesZero n) = n

Every byte of bytesZero n is 0.

bytesZero_get
Lean
bytesZero_get : ∀ n i b, M.bytesGet (M.bytesZero n) i = some b → b = M.ofNat 0

Writing a byte preserves the block length.

bytesSet_len
Lean
bytesSet_len : ∀ bs i v, M.bytesLen (M.bytesSet bs i v) = M.bytesLen bs

Writing a byte v at an in-bounds index i updates only index i.

bytesSet_get
Lean
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_len
Lean
bytesFill_len : ∀ bs v, M.bytesLen (M.bytesFill bs v) = M.bytesLen bs

Filling a Data Block with byte v sets every in-bounds index to v.

bytesFill_get
Lean
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
structure

Model.Laws

Laws.lean:244

The 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 where

116 laws

5.2.6 Mathematical Operations sec-mathematical-operations

When applied to mathematical values, the operators refer to the usual mathematical operations.

Addition is associative.

add_assoc
Lean
add_assoc : ∀ a b c, M.add (M.add a b) c = M.add a (M.add b c)

Addition is commutative.

add_comm
Lean
add_comm : ∀ a b, M.add a b = M.add b a

0 is the additive identity.

add_zero
Lean
add_zero : ∀ a, M.add a (M.ofNat 0) = a

Negation is the additive inverse.

add_neg
Lean
add_neg : ∀ a, M.add a (M.neg a) = M.ofNat 0

Subtraction adds the negation.

sub_def
Lean
sub_def : ∀ a b, M.sub a b = M.add a (M.neg b)

Multiplication is associative.

mul_assoc
Lean
mul_assoc : ∀ a b c, M.mul (M.mul a b) c = M.mul a (M.mul b c)

Multiplication is commutative.

mul_comm
Lean
mul_comm : ∀ a b, M.mul a b = M.mul b a

1 is the multiplicative identity.

mul_one
Lean
mul_one : ∀ a, M.mul a (M.ofNat 1) = a

Multiplication distributes over addition.

mul_add
Lean
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_mul
Lean
div_mul : ∀ a b, b ≠ M.ofNat 0 → M.mul (M.div a b) b = a
5.2.6 Mathematical Operations sec-mathematical-operations

Mathematical values: Arbitrary real numbers, used as the default numeric type.

0 and 1 differ.

zero_ne_one
Lean
zero_ne_one : M.ofNat 0 ≠ M.ofNat 1
5.2.6 Mathematical Operations sec-mathematical-operations

When applied to mathematical values, the operators refer to the usual mathematical operations.

< is irreflexive.

lt_irrefl
Lean
lt_irrefl : ∀ a, M.lt a a = false

< is transitive.

lt_trans
Lean
lt_trans : ∀ a b c, M.lt a b = true → M.lt b c = true → M.lt a c = true
5.2.6 Mathematical Operations sec-mathematical-operations

Mathematical values: Arbitrary real numbers, used as the default numeric type.

< is total, as on the reals.

lt_total
Lean
lt_total : ∀ a b, M.lt a b = true ∨ a = b ∨ M.lt b a = true
5.2.6 Mathematical Operations sec-mathematical-operations

When applied to mathematical values, the operators refer to the usual mathematical operations.

< is preserved by addition.

add_lt_add
Lean
add_lt_add : ∀ a b c, M.lt a b = true → M.lt (M.add a c) (M.add b c) = true

A product of positive values is positive.

mul_pos
Lean
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_iff
Lean
eq_iff : ∀ a b, M.eq a b = true ↔ a = b

Numerals add as natural numbers.

ofNat_add
Lean
ofNat_add : ∀ m n, M.ofNat (m + n) = M.add (M.ofNat m) (M.ofNat n)

X⁰ = 1.

pow_zero
Lean
pow_zero : ∀ x, M.pow x (M.ofNat 0) = M.ofNat 1

Xⁿ⁺¹ = xⁿ × x.

pow_succ
Lean
pow_succ : ∀ x n, M.pow x (M.ofNat (n + 1)) = M.mul (M.pow x (M.ofNat n)) x
5.2.6 Mathematical Operations sec-mathematical-operations

The mathematical function floor(x) produces the largest integer (closest to +∞) that is not larger than x.

Floor(x) is an integer.

floor_isInt
Lean
floor_isInt : ∀ x, M.isInt (M.floor x) = true

Floor(x) ≤ x.

floor_le
Lean
floor_le : ∀ x, M.lt x (M.floor x) = false

X < floor(x) + 1: no larger integer is ≤ x.

lt_floor_add_one
Lean
lt_floor_add_one : ∀ x, M.lt x (M.add (M.floor x) (M.ofNat 1)) = true
7.1.4.1.3 RoundMVResult sec-roundmvresult

a 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_spec
Lean
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
5.2.6 Mathematical Operations sec-mathematical-operations

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_iff
Lean
isInt_iff : ∀ x, M.isInt x = true ↔ ∃ n, x = M.ofNat n ∨ x = M.neg (M.ofNat n)
6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

are represented in ECMAScript as a single special NaN ("not a number") value.

NaN's view.

numView_nan
Lean
numView_nan : M.numView M.numNaN = .nan
6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

There are two other special values, called positive Infinity and negative Infinity.

+∞𝔽 and -∞𝔽's views.

numView_inf
Lean
numView_inf : ∀ b, M.numView (M.numInf b) = if b then .negInf else .posInf
6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

Note that there is both a positive zero and a negative zero.

+0𝔽 and -0𝔽's views.

numView_zero
Lean
numView_zero : ∀ b, M.numView (M.numZero b) = if b then .negZero else .posZero
6.1.6.1 The Number Type sec-ecmascript-language-types-number-type

representing the double-precision floating point IEEE 754-2019 binary64 values

The Number type's value set, 𝔽 and the operations (NumLaws).

num
Lean
num : M.NumLaws
5.2.6 Mathematical Operations sec-mathematical-operations

BigInts: ECMAScript language values representing arbitrary integers in a one-to-one correspondence.

ℝ(ℤ(x)) = x for an integer x.

bigVal_bigOf
Lean
bigVal_bigOf : ∀ x, M.isInt x = true → M.bigVal (M.bigOf x) = x

A BigInt's value is an integer.

bigVal_isInt
Lean
bigVal_isInt : ∀ b, M.isInt (M.bigVal b) = true

A BigInt is its value.

bigVal_inj
Lean
bigVal_inj : ∀ a b, M.bigVal a = M.bigVal b → a = b
6.1.4 The String Type sec-ecmascript-language-types-string-type

These 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_some
Lean
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
6.1.4 The String Type sec-ecmascript-language-types-string-type

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_ext
Lean
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
6.1.4 The String Type sec-ecmascript-language-types-string-type

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_len
Lean
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_at
Lean
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))
6.1.4 The String Type sec-ecmascript-language-types-string-type

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_len
Lean
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_at
Lean
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))
6.1.4 The String Type sec-ecmascript-language-types-string-type

(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_len
Lean
strOfUnit_len : ∀ u, u < 65536 → M.strLen (M.strOfUnit (M.ofNat u)) = M.ofNat 1

The String of one code unit has it at index 0.

strOfUnit_at
Lean
strOfUnit_at : ∀ u, u < 65536 → M.strAt (M.strOfUnit (M.ofNat u)) (M.ofNat 0) = some (M.ofNat u)
22.1.3.18 String.prototype.repeat sec-string.prototype.repeat

If n = 0, return the empty String.

Repeating a String zero times is the empty String.

strRepeat_zero
Lean
strRepeat_zero : ∀ s, M.strRepeat (M.ofNat 0) s = M.strLit ""
22.1.3.18 String.prototype.repeat sec-string.prototype.repeat

Return the String value that is made from n copies of string appended together.

Repeating n + 1 times appends another copy.

strRepeat_succ
Lean
strRepeat_succ : ∀ n s,  M.strRepeat (M.ofNat (n + 1)) s = M.strConcat (M.strRepeat (M.ofNat n) s) s
6.1.6.1.20 Number::toString sec-numeric-types-number-tostring

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_digit
Lean
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))
6.1.6.1.20 Number::toString sec-numeric-types-number-tostring

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_div
Lean
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))
5.2.8 Identity sec-identity

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_iff
Lean
strEq_iff : ∀ s t, M.strEq s t = true ↔ s = t
6.1.4 The String Type sec-ecmascript-language-types-string-type

each element in the String is treated as a UTF-16 code unit value

6.1.4 The String Type sec-ecmascript-language-types-string-type

The 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_len
Lean
strUnits_len : ∀ s, M.ofNat (seqList (M.strUnits s)).length = M.strLen s
6.1.4 The String Type sec-ecmascript-language-types-string-type

These 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_at
Lean
strUnits_at : ∀ s k, (seqList (M.strUnits s))[k]? = M.strAt s (M.ofNat k)
6.1.5 The Symbol Type sec-ecmascript-language-types-symbol-type

Each Symbol is unique and immutable.

Symbol equality is identity.

symEq_iff
Lean
symEq_iff : ∀ a b, M.symEq a b = true ↔ a = b
6.1.5 The Symbol Type sec-ecmascript-language-types-symbol-type

Each 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_new
Lean
symDesc_new : ∀ k d, M.symDesc (M.symNew k d) = d
6.1.5 The Symbol Type sec-ecmascript-language-types-symbol-type

Each Symbol is unique and immutable.

Each creation makes a different Symbol.

symNew_inj
Lean
symNew_inj : ∀ k d k' d', M.symNew k d = M.symNew k' d' → k = k'
5.2.8 Identity sec-identity

each value with identity is unique and therefore only equal to itself.

An object is its identity.

addrEq_iff
Lean
addrEq_iff : ∀ a b, M.addrEq a b = true ↔ a = b

A Parse Node, a value with identity, is equal only to itself.

nodeEq_iff
Lean
nodeEq_iff : ∀ a b, M.nodeEq a b = true ↔ a = b
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

The elements of a list may be randomly accessed using 0-origin indices.

A List's length is a non-negative integer.

seqLen_nat
Lean
seqLen_nat : ∀ {α} (xs : M.Seq α), ∃ n, M.seqLen xs = M.ofNat n

An element is at a non-negative integer index below the length.

seqGet_some
Lean
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_lt
Lean
seqGet_lt : ∀ {α} (xs : M.Seq α) k, M.lt (M.ofNat k) (M.seqLen xs) = true →  (M.seqGet xs (M.ofNat k)).isSome = true
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

Values of the List type are simply ordered sequences of list elements containing the individual values.

A List is its sequence of elements.

seq_ext
Lean
seq_ext : ∀ {α} (xs ys : M.Seq α), (∀ i, M.seqGet xs i = M.seqGet ys i) → xs = ys
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

A new empty List can be expressed as « ».

« » has length 0.

seqLen_nil
Lean
seqLen_nil : ∀ {α}, M.seqLen (M.seqNil (α := α)) = M.ofNat 0

« » has no elements.

seqGet_nil
Lean
seqGet_nil : ∀ {α} i, M.seqGet (M.seqNil (α := α)) i = none
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

Values of the List type are simply ordered sequences of list elements containing the individual values.

Appending adds one to the length.

seqLen_push
Lean
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_push
Lean
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_cons
Lean
seqLen_cons : ∀ {α} (a : α) xs, M.seqLen (M.seqCons a xs) = M.add (M.seqLen xs) (M.ofNat 1)

Prepending puts the element first.

seqGet_cons
Lean
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_set
Lean
seqLen_set : ∀ {α} (xs : M.Seq α) i a, M.seqLen (M.seqSet xs i a) = M.seqLen xs

Replacing the element at an index below the length (read-over-write).

seqGet_set
Lean
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
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

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_concat
Lean
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_concat
Lean
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))
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

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_remove
Lean
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_remove
Lean
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_none
Lean
seqRemove_none : ∀ {α} (xs : M.Seq α) i, M.seqGet xs i = none → M.seqRemove xs i = xs
6.2.9 Data Blocks sec-data-blocks

A 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_repeat
Lean
seqLen_repeat : ∀ {α} k (a : α), M.seqLen (M.seqRepeat (M.ofNat k) a) = M.ofNat k

Each of k copies of a value is that value.

seqGet_repeat
Lean
seqGet_repeat : ∀ {α} k (a : α) i x, M.seqGet (M.seqRepeat (M.ofNat k) a) i = some x → x = a
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

When 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_nil
Lean
seqFoldl_nil : ∀ {α β} (f : β → α → β) (b : β), M.seqFoldl f b (M.seqNil (α := α)) = b

A fold visits the elements first to last.

seqFoldl_push
Lean
seqFoldl_push : ∀ {α β} (f : β → α → β) (b : β) (xs : M.Seq α) a,  M.seqFoldl f b (M.seqPush xs a) = f (M.seqFoldl f b xs) a
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

Any fields that are not explicitly listed are considered to be absent.

The empty Record has no fields.

recGet_empty
Lean
recGet_empty : ∀ {α} f, M.recGet (M.recEmpty (α := α)) f = none
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

A Record type value consists of one or more named fields.

Setting a field (read-over-write).

recGet_set
Lean
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 g
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

Any fields that are not explicitly listed are considered to be absent.

Deleting a field makes it absent.

recGet_del
Lean
recGet_del : ∀ {α} (r : M.Rec α) f g, M.recGet (M.recDel r f) g = if g = f then none else M.recGet r g
6.2.2 The List and Record Specification Types sec-list-and-record-specification-type

A Record type value consists of one or more named fields.

The listed fields are the present ones.

recKeys_mem
Lean
recKeys_mem : ∀ {α} (r : M.Rec α) f, (M.recGet r f).isSome = true ↔ ∃ i, M.seqGet (M.recKeys r) i = some f

Each field is listed once.

recKeys_once
Lean
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
6.1.7 The Object Type sec-object-type

The properties of an object are uniquely identified using property keys.

The empty table has no properties.

propsGet_empty
Lean
propsGet_empty : ∀ {α} k, M.propsGet (M.propsEmpty (α := α)) k = none

Putting a property reads it back.

propsGet_put_self
Lean
propsGet_put_self : ∀ {α} (p : M.Props α) k a, M.propsGet (M.propsPut p k a) k = some a

Putting a property leaves the others.

propsGet_put_other
Lean
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_self
Lean
propsGet_del_self : ∀ {α} (p : M.Props α) k, M.propsGet (M.propsDel p k) k = none

Deleting a property leaves the others.

propsGet_del_other
Lean
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_mem
Lean
propsKeys_mem : ∀ {α} (p : M.Props α) k, (M.propsGet p k).isSome = true ↔ ∃ i, M.seqGet (M.propsKeys p) i = some k
6.1.7 The Object Type sec-object-type

Each 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_once
Lean
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
10.1.11.1 OrdinaryOwnPropertyKeys sec-ordinaryownpropertykeys

in ascending chronological order of property creation

A new key goes last in creation order.

propsKeys_put_new
Lean
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_old
Lean
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_del
Lean
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
6.1.7 The Object Type sec-object-type

The properties of an object are uniquely identified using property keys.

Deleting an absent key changes nothing.

propsDel_absent
Lean
propsDel_absent : ∀ {α} (p : M.Props α) k, M.propsGet p k = none → M.propsDel p k = p
5.2.8 Identity sec-identity

References to existing values with identity cannot be manifest simply by describing them

The empty store refers to no value.

heapGet_empty
Lean
heapGet_empty : ∀ {α} a, M.heapGet (M.heapEmpty (α := α)) a = none
5.2.8 Identity sec-identity

each value with identity is unique and therefore only equal to itself.

An allocated address is fresh.

heapAlloc_fresh
Lean
heapAlloc_fresh : ∀ {α} (h : M.Heap α) v, M.heapGet h (M.heapAlloc h v).1 = none
5.2.8 Identity sec-identity

References to existing values with identity cannot be manifest simply by describing them

The allocated cell holds the value it is made with.

heapAlloc_get_self
Lean
heapAlloc_get_self : ∀ {α} (h : M.Heap α) v, M.heapGet (M.heapAlloc h v).2 (M.heapAlloc h v).1 = some v
5.2.8 Identity sec-identity

Some 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_other
Lean
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_self
Lean
heapGet_set_self : ∀ {α} (h : M.Heap α) a v, (M.heapGet h a).isSome = true → M.heapGet (M.heapSet h a v) a = some v

Writing a cell leaves the others.

heapGet_set_other
Lean
heapGet_set_other : ∀ {α} (h : M.Heap α) a v b, b ≠ a → M.heapGet (M.heapSet h a v) b = M.heapGet h b
5.2.8 Identity sec-identity

References to existing values with identity cannot be manifest simply by describing them

Writing an unallocated cell changes nothing.

heapSet_none
Lean
heapSet_none : ∀ {α} (h : M.Heap α) a v, M.heapGet h a = none → M.heapSet h a v = h
22.2.2.1 Notation sec-pattern-notation

A CharSet is a mathematical set of CharSetElements.

CsSize is the non-negative integer count of elements in the CharSet.

csSize_nat
Lean
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_some
Lean
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_lt
Lean
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 = true

The CharSet has no duplicate elements at distinct indices.

csGet_distinct
Lean
csGet_distinct : ∀ cs i j e f, M.csGet cs i = some e → M.csGet cs j = some f → seqList e = seqList f → i = j

Every element in csHas appears at some index of csGet.

csHas_exists
Lean
csHas_exists : ∀ cs e, M.allPoints e → M.csHas cs e = true → ∃ i e', M.csGet cs i = some e' ∧ seqList e' = seqList e

The empty CharSet has no elements.

csHas_empty
Lean
csHas_empty : ∀ e, M.csHas M.csEmpty e = false

CsAdd inserts a CharSetElement of code points into the CharSet.

csHas_add
Lean
csHas_add : ∀ cs s e, M.allPoints s → M.allPoints e →  (M.csHas (M.csAdd cs s) e = true ↔ M.csHas cs e = true ∨ seqList e = seqList s)
22.2.2.1 Notation sec-pattern-notation

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_interval
Lean
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)
22.2.2.1 Notation sec-pattern-notation

A CharSet is a mathematical set of CharSetElements.

CsUnion is set union of CharSets.

csHas_union
Lean
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_inter
Lean
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_diff
Lean
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)
22.2.2.1 Notation sec-pattern-notation

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_iff
Lean
csAllSingle_iff : ∀ cs, M.csAllSingle cs = true ↔ ∀ i e, M.csGet cs i = some e → M.seqLen e = M.ofNat 1

CsSingles restricts a CharSet to its single-character elements.

csHas_singles
Lean
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_some
Lean
csFromProp_some : ∀ p v, (M.csFromProp p v).isSome = (M.propSet p v).isSome

CsFromProp holds the CharSetElements that propSet returns.

csHas_fromProp
Lean
csHas_fromProp : ∀ p v cs e, M.csFromProp p v = some cs → M.allPoints e →  (M.csHas cs e = true ↔ ∃ es i e', M.propSet p v = some es ∧ M.seqGet es i = some e' ∧ seqList e' = seqList e)
22.2.2.9.4 AllCharacters sec-allcharacters

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_noScf
Lean
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)
22.2.2.9.3 WordCharacters sec-wordcharacters

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_canonExtra
Lean
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)
22.2.2.7.1 CharacterSetMatcher sec-runtime-semantics-charactersetmatcher-abstract-operation

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_iff
Lean
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)
6.2.9 Data Blocks sec-data-blocks

A Data Block value is created with a fixed number of bytes that each have the initial value 0.

Data Block byte sequences (ByteLaws).

bytes
Lean
bytes : M.ByteLaws
def

Model.stringPropertyNames

Laws.lean:761

The 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"]
def

Model.codePointsOf

Laws.lean:766

A 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
structure

Model.UnicodeLaws

Laws.lean:770

The 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 where

7 laws

22.2.2.7.3 Canonicalize sec-runtime-semantics-canonicalize-ch

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_point
Lean
scf_point : ∀ c d, M.isPoint c → M.scf? c = some d → M.isPoint d
22.1.3.28 String.prototype.toLowerCase sec-string.prototype.tolowercase

Let lowerText be toLowercase(sText), according to the Unicode Default Case Conversion algorithm.

ToLowercase gives code points.

toLower_points
Lean
toLower_points : ∀ xs, M.allPoints xs → M.allPoints (M.toLower xs)
22.1.3.30 String.prototype.toUpperCase sec-string.prototype.touppercase

except that the String is mapped using the toUppercase algorithm of the Unicode Default Case Conversion

ToUppercase gives code points.

toUpper_points
Lean
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_chars
Lean
propSet_chars : ∀ p v es i e, M.propSet p v = some es → M.seqGet es i = some e → M.allPoints e

A property value's elements are distinct.

propSet_distinct
Lean
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_strings
Lean
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
22.1.3.15 String.prototype.normalize sec-string.prototype.normalize

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_points
Lean
normalize_points : ∀ f xs, M.allPoints xs → M.allPoints (M.normalize f xs)
def

Model.InSeq

Laws.lean:804

c 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
def

Model.KidOf

Laws.lean:808

n 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
inductive

Model.Within

Laws.lean:812

p 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
structure

Model.ParentLaws

Laws.lean:818

Model.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 where

4 laws

5.1.2 Parsing sec-parsing

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.

sound
Lean
sound : ∀ r n p, M.nodeParent r n = some p → Model.Within r p ∧ Model.KidOf n p

Wherever a node at or below r has n as a child, the model gives a parent of n.

complete
Lean
complete : ∀ r n p, Model.Within r p → Model.KidOf n p → (M.nodeParent r n).isSome = true

The ancestors of n in the tree rooted at r are its parent, then the parent's ancestors; none for a node without a parent.

ancestors
Lean
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.

height
Lean
height : ∀ n c, Model.InSeq c (M.nodeKids n) → M.nodeHeight c < M.nodeHeight n