| nanReading page · generated from spec/spectec/prose/01-model.spectec, 02-value.spectec, 05-model-laws.spectec
The model and its laws
A model (syntax Model record) 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, over which specification values (syntax Val) and store cells (syntax Cell) are defined. Every object cites its governing ECMA-262 clause, and the SpecTec laws blocks state what the prose assumes of them: 148 laws, each quoting the sentence it reads.
The model
From spec/spectec/prose/01-model.spectec
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
01-model.spectec:16The case view of a Number value (§6.1.6.1, sec-ecmascript-language-types-number-type).
syntax NumView (Math : Type)ParseCx
01-model.spectec:31A parser invocation's context (§5.1.2, sec-parsing): the Annex B sections whose grammar applies (those the host supports, B.1 and B.3, sec-additional-ecmascript-features-for-web-browsers), whether the source text is strict mode code from outside (§11.2.2, sec-strict-mode-code: 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.
syntax ParseCx recordderiving [Repr, BEq, Inhabited]
NormForm
01-model.spectec:40The Unicode Normalization Forms (UAX #15; §22.1.3.15, sec-string.prototype.normalize).
syntax NormFormderiving [Repr, BEq, DecidableEq, Inhabited]
Model
01-model.spectec:50A model of the spec's sorts and their primitive operations (§5.2, sec-algorithm-conventions; §6, sec-ecmascript-data-types-and-values).
syntax Model record122 constructors
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;numView : Num -> NumView(Math);𝔽(x) for finite x: roundTiesToEven to the nearest Number value (§6.1.6.1)
numOf : Math -> Num;numNaN : 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;numNeg : 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 times Nat times Math;ℤ(x) for an integer x
bigOf : Math -> Big;ℝ(x)
bigVal : Big -> Math;a String literal of the text
strLit : String -> Str;strLen : Str -> Math;the code unit at an index, as a mathematical value
strAt : Str -> Math -> Option(Math);strConcat : Str -> Str -> Str;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;nodeProd : Node -> ProdId;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: 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 : ParseCx -> Nat -> Seq(Math) -> NtId -> List(ParamId times Bool) -> Option(Option(Node));§5.1.5 "P must cover K": the covered Parse Node of parser invocation k: 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 : ParseCx -> Nat -> Node -> NtId -> List(ParamId times 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 times 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);a bound on the depth of the tree below it: more than each child's (Model.ParentLaws)
nodeHeight : Node -> Nat;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);propsEmpty : {α : Type} -> Props(α);propsGet : {α : Type} -> Props(α) -> Str sum Sym -> Option(α);update in place, or add at the end of creation order
propsPut : {α : Type} -> Props(α) -> Str sum Sym -> α -> Props(α);propsDel : {α : Type} -> Props(α) -> Str sum Sym -> Props(α);the keys in creation order
propsKeys : {α : Type} -> Props(α) -> Seq(Str sum Sym);heapEmpty : {α : Type} -> Heap(α);a fresh address
heapAlloc : {α : Type} -> Heap(α) -> α -> Addr times 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);CharSet : Type;csEmpty : CharSet;csAdd : CharSet -> Seq(Math) -> CharSet;csInterval : Math -> 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));csAllSingle : CharSet -> Bool;csSingles : CharSet -> CharSet;csFromProp : Seq(Math) -> Seq(Math) -> Option(CharSet);csNoScf : CharSet;csCanonExtra : CharSet -> Bool -> 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;bytesLen : Bytes -> Math;bytesGet : Bytes -> Math -> Option(Math);bytesSet : Bytes -> Math -> Math -> Bytes;bytesFill : Bytes -> Math -> Bytes;Auxiliary definitions (2): seqList, Model.canonChar
seqList
01-model.spectec:259A List's elements, first to last.
def seqList {M : Model} {α : Type} (sq : M.Seq(α)) : List(α) := M.seqFoldl(fun l x => l ++ [x], [], sq)Model.canonChar
01-model.spectec:263§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)) in 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 => cend else c
Values, cells and stops
From spec/spectec/prose/02-value.spectec
The values algorithms compute with (Val), a cell of the store (Cell: a Record, a List, an object, an Environment Record), a call of the host as the host-call log records it (HostCall), and why a run stops without a result (Stop).
CloSite
02-value.spectec:16An Abstract Closure literal (§6.2.8, sec-abstract-closure): its algorithm and its index there.
syntax CloSite recordderiving [Repr, BEq, Inhabited]
Val
02-value.spectec:24The values algorithms compute with, by sort (§6.1, sec-ecmascript-language-types; §6.2, sec-ecmascript-specification-types).
syntax Valinhabited Val(M) := .absent
33 constructors
an optional parameter not passed; an absent optional child
| absenta built-in function's parameter not passed: undefined to every use but is present (§18)
| missing| undefined| null| bool (b : Bool)| str (s : M.Str)| sym (s : M.Sym)| num (n : M.Num)| big (b : M.Big)| obj (a : M.Addr)| math (m : M.Math)| posInf| negInf| enum (e : EnumId)a Record or a List, by identity
| ref (a : M.Addr)a Completion Record
| comp (type : EnumId) (value : Val) (target : Val)| clo (site : CloSite) (caps : List(Val))an algorithm: an internal method or a function's behaviour
| alg (a : AlgId)| node (n : M.Node)the Parse Node of the terminal t, at position i of n's present right-hand side
| leaf (n : M.Node) (i : Nat) (t : String)a terminal symbol, by its text
| term (t : String)a type hole's value: the type, with the algorithm, Parse Node and variables it is written in
| ty (t : TyExpr) (self : AlgId) (node : Option(M.Node)) (env : List(Val))a condition over bound variables: the condition, the slots it binds, and the algorithm, Parse Node and variables it is written in; applied to values, it holds of them or not
| cond (c : Cond) (xs : List(Slot)) (self : AlgId) (node : Option(M.Node)) (env : List(Val))| field (f : FieldId)a grammar symbol and its parameters (true: +)
| nt (n : NtId) (args : List(ParamId times Bool))a grammar parameter
| param (p : ParamId)a written production: its GL productions (one per presence of its optional symbols)
| prod (ps : List(ProdId))| sort (s : SortId)a phrase's choice of words
| choice (i : Nat)a clause, as an emu-xref names it
| clause (c : ClauseId)an emu-table, as an emu-xref names it
| table (t : TableId)a variable not yet bound: a read of it stops
| unboundvalues held together, without identity: a rule's early errors, before they are a List
| tuple (vs : List(Val))Cell
02-value.spectec:88A store cell: an Object (§6.1.7, sec-object-type), a Record or List (§6.2.2, sec-list-and-record-specification-type), a Data Block (§6.2.9, sec-data-blocks), a RegExp CharSet (§22.2.2, sec-pattern-semantics), or an Environment Record (§9.1, sec-environment-records).
syntax Cell| record (kind : SortId) (fs : M.Rec(Val(M)))a List; origin is its first index ("indexed 1 through N")
| list (xs : M.Seq(Val(M))) (origin : Nat)a Data Block (§6.2.9): a sequence of byte values (integers 0 to 255)
| block (bs : M.Bytes)a CharSet (§22.2.2.1): a mathematical set of CharSetElements
| charSet (cs : M.CharSet)internal slots, and own properties: each an attribute Record of the store
| object (slots : M.Rec(Val(M))) (props : M.Props(Val(M)))an Environment Record: its fields, and its bindings by name, each a binding Record of the store
| env (kind : SortId) (fs : M.Rec(Val(M))) (binds : M.Props(Val(M)))HostCall
02-value.spectec:105A call of the host, as the host-call log records it so that host laws can relate answers across a run (§4.2, sec-hosts-and-implementations; §9.5, sec-jobs; §9.6, sec-agents; §9.9.3, sec-weakref-execution; §9.10, sec-clear-kept-objects).
syntax HostCalla host-defined operation: its clause, its arguments, the active script or module at the call (§9.4.1), the running execution context's Realm (§9.4), and its answer
| hook (c : ClauseId) (args : List(Val(M))) (active : Val(M)) (realm : Val(M)) (answer : Val(M))a choice at a primitive the host decides: its arguments and answer
| choice (q : PrimId) (args : List(Val(M))) (answer : Val(M))the next job the host runs (§9.5): the log position of the call that scheduled it, or none; and the milliseconds elapsed by the host's own clock as it takes it
| next (answer : Option(Nat)) (elapsed : M.Math)the host ends its jobs with a promise, generic or timeout job scheduled and not taken: the embedding terminates the agent (§9.6)
| terminatethe host-defined preparation steps of the job scheduled at that log position (§9.5)
| prepare (job : Nat)the host-defined cleanup steps of the job scheduled at that log position (§9.5)
| cleanup (job : Nat)whether the host performs ClearKeptObjects now (§9.10)
| kept (answer : Bool)the objects and symbols whose WeakRefs and cells the host emptied at a job boundary (§9.9.3)
| collect (answer : List(Val(M)))ShapeChange
02-value.spectec:130A change to an object's shape (§14.7.5.9, sec-enumerate-object-properties), as the shape log records it: a property added (added), or a property removed, replaced or its [[Enumerable]] changed, or its [[Prototype]] changed; before is the host's calls before it.
syntax ShapeChange recordStop
02-value.spectec:137Why a run stops without a result (§2, sec-conformance; §5.2, sec-algorithm-conventions; §9.6, sec-agents).
syntax Stopderiving [Repr, BEq, Inhabited]
every agent waits and none will be woken
| blockeda value of the wrong sort
| sortErroran Assert, or ! on an abrupt completion
| assertFailedresidual prose without an assigned meaning
| residuethe end of an algorithm without Return
| noReturnan implementation limit of the host
| implLimitThe laws of a model
From spec/spectec/prose/05-model-laws.spectec
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.
Auxiliary definitions (2): utf16Units, strLitUnits
utf16Units
05-model-laws.spectec:13§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
05-model-laws.spectec:16The 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.
Auxiliary definitions (8): Model.abs, Model.form, Model.finiteNum, Model.candidate, …
Model.abs
05-model-laws.spectec:25|x|
def Model.abs (x : M.Math) : M.Math := if M.lt(x, M.ofNat(0)) then M.neg(x) else xModel.form
05-model-laws.spectec:28±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))) in if neg then M.neg(v) else vModel.finiteNum
05-model-laws.spectec:32§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 := exists (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
05-model-laws.spectec:36The 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 = trueModel.nearest
05-model-laws.spectec:39y 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 := exists ev, M.candidate(y, ev) /\ forall 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
05-model-laws.spectec:43The 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
05-model-laws.spectec:46The 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)) | _ => noneend
Model.digitsOf
05-model-laws.spectec:55Number::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))))) = xModel.NumLaws
05-model-laws.spectec:60The laws of the Number type: its value set (§6.1.6.1, sec-ecmascript-language-types-number-type), "the Number value for x" as roundTiesToEven, and IEEE 754-2019's operations.
Proved as part of Model.Laws (its field num).
laws Model.NumLaws (M : Model)12 laws
representing the double-precision floating point IEEE 754-2019 binary64 values
A view determines the Number value.
non-zero finite Numbers are partitioned into two groups
Every finite view is a normalized or denormalized value (finiteNum).
numView_finiteSpecTec
law numView_finite : forall a m, M.numView(a) = .finite(m) -> (exists ev, M.finiteNum(m, ev));Every normalized or denormalized value is a Number value.
finiteNum_viewSpecTec
law finiteNum_view : forall m ev, M.finiteNum(m, ev) -> (exists a, M.numView(a) = .finite(m));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.
Return the negation of number; that is, compute a Number with the same magnitude but opposite sign.
Negation flips the sign; NaN stays.
If x is -0𝔽 and y is -0𝔽, return -0𝔽. 1. Return 𝔽(ℝ(x) + ℝ(y)).
Number::add's steps, a row each.
numAdd_viewSpecTec
law numAdd_view : forall 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 end end;
Return Number::add(x, Number::unaryMinus(y)).
Subtraction is addition of the negation.
Return 𝔽(ℝ(x) × ℝ(y)).
Number::multiply's steps, a row each.
numMul_viewSpecTec
law numMul_view : forall 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 end) != (match vb with | .negInf | .negZero => true | .finite(m) => M.lt(m, M.ofNat(0)) | _ => false end) in 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 end end;
Return 𝔽(ℝ(x) / ℝ(y)).
Number::divide's steps, a row each.
numDiv_viewSpecTec
law numDiv_view : forall 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 end) != (match vb with | .negInf | .negZero => true | .finite(m) => M.lt(m, M.ofNat(0)) | _ => false end) in 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 end end end;
If ℝ(x) < ℝ(y), return true.
Number::lessThan's steps, undefined read as false.
numLt_defSpecTec
law numLt_def : forall 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 end end;
If x is +0𝔽 and y is -0𝔽, return true.
Number::equal's steps.
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_leastSpecTec
law numDigits_least : forall 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) /\ forall n k s, M.digitsOf(x, M.ofNat(r), n, k, s) -> M.numDigits(x, M.ofNat(r)).2.1 <= k;Auxiliary definitions (3): Model.isPoint, Model.allPoints, Model.isByte
Model.isPoint
05-model-laws.spectec:206§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) = falseModel.allPoints
05-model-laws.spectec:209Every element of xs is a code point.
def Model.allPoints (M : Model) (xs : M.Seq(M.Math)) : Prop := forall i x, M.seqGet(xs, i) = some(x) -> M.isPoint(x)Model.isByte
05-model-laws.spectec:212§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)) = trueModel.ByteLaws
05-model-laws.spectec:215The laws of Data Block byte sequences (§6.2.9, sec-data-blocks).
Proved as part of Model.Laws (its field bytes).
laws Model.ByteLaws (M : Model)9 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_nonnegSpecTec
law bytesLen_nonneg : forall 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_boundsSpecTec
law bytesGet_bounds : forall 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_byteSpecTec
law bytesGet_byte : forall 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_lenSpecTec
law bytesZero_len : forall 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_getSpecTec
law bytesZero_get : forall n i b, M.bytesGet(M.bytesZero(n), i) = some(b) -> b = M.ofNat(0);Writing a byte preserves the block length.
bytesSet_lenSpecTec
law bytesSet_len : forall 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_getSpecTec
law bytesSet_get : forall 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_lenSpecTec
law bytesFill_len : forall 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_getSpecTec
law bytesFill_get : forall 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
05-model-laws.spectec:256The laws a model of the spec's sorts satisfies (§5.2, sec-mathematical-operations; §6, sec-ecmascript-data-types-and-values).
Proved of the engine's model: Engine.Impl.laws, the first part of Implements.model.
laws Model.Laws (M : Model)116 laws
When applied to mathematical values, the operators refer to the usual mathematical operations.
Addition is associative.
Addition is commutative.
0 is the additive identity.
Negation is the additive inverse.
Subtraction adds the negation.
Multiplication is associative.
Multiplication is commutative.
1 is the multiplicative identity.
Multiplication distributes over addition.
Division by a non-zero value inverts multiplication.
Mathematical values: Arbitrary real numbers, used as the default numeric type.
0 and 1 differ.
When applied to mathematical values, the operators refer to the usual mathematical operations.
< is irreflexive.
< is transitive.
Mathematical values: Arbitrary real numbers, used as the default numeric type.
< is total, as on the reals.
When applied to mathematical values, the operators refer to the usual mathematical operations.
< is preserved by addition.
A product of positive values is positive.
= on mathematical values is equality.
Numerals add as natural numbers.
X⁰ = 1.
Xⁿ⁺¹ = xⁿ × x.
The mathematical function floor(x) produces the largest integer (closest to +∞) that is not larger than x.
Floor(x) is an integer.
Floor(x) ≤ x.
X < floor(x) + 1: no larger integer is ≤ x.
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.
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.
are represented in ECMAScript as a single special NaN ("not a number") value.
NaN's view.
There are two other special values, called positive Infinity and negative Infinity.
+∞𝔽 and -∞𝔽's views.
Note that there is both a positive zero and a negative zero.
+0𝔽 and -0𝔽's views.
representing the double-precision floating point IEEE 754-2019 binary64 values
The Number type's value set, 𝔽 and the operations (NumLaws).
BigInts: ECMAScript language values representing arbitrary integers in a one-to-one correspondence.
ℝ(ℤ(x)) = x for an integer x.
A BigInt's value is an integer.
A BigInt is its value.
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].
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.
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_lenSpecTec
law strConcat_len : forall 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.
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.
The substring from i has the code units from i.
(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_lenSpecTec
law strOfUnit_len : forall 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_atSpecTec
law strOfUnit_at : forall 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_zeroSpecTec
law strRepeat_zero : forall 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_succSpecTec
law strRepeat_succ : forall 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.
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_divSpecTec
law intToRadix_div : forall 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.
each 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_unitsSpecTec
law strLit_units : forall t, seqList(M.strUnits(M.strLit(t))) = strLitUnits(t).map(M.ofNat);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_lenSpecTec
law strUnits_len : forall s, M.ofNat(seqList(M.strUnits(s)).length) = M.strLen(s);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_atSpecTec
law strUnits_at : forall s k, seqList(M.strUnits(s))[k]? = M.strAt(s, M.ofNat(k));Each Symbol is unique and immutable.
Symbol equality is identity.
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.
Each Symbol is unique and immutable.
Each creation makes a different Symbol.
each value with identity is unique and therefore only equal to itself.
An object is its identity.
addrEq_iffSpecTec
law addrEq_iff : forall a b, M.addrEq(a, b) = true <=> a = b;A Parse Node, a value with identity, is equal only to itself.
nodeEq_iffSpecTec
law nodeEq_iff : forall a b, M.nodeEq(a, b) = true <=> a = b;The elements of a list may be randomly accessed using 0-origin indices.
A List's length is a non-negative integer.
An element is at a non-negative integer index below the length.
Every index below the length has an element.
Values of the List type are simply ordered sequences of list elements containing the individual values.
A List is its sequence of elements.
A new empty List can be expressed as « ».
« » has length 0.
« » has no elements.
Values of the List type are simply ordered sequences of list elements containing the individual values.
Appending adds one to the length.
Appending puts the element last.
Prepending adds one to the length.
Prepending puts the element first.
Replacing an element keeps the length.
Replacing the element at an index below the length (read-over-write).
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.
List-concatenation's elements are the first List's, then the second's.
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.
Removing the element at an index below the length shifts the later ones.
Removing at an index with no element changes nothing.
seqRemove_noneSpecTec
law seqRemove_none : forall {α} (xs : M.Seq(α)) i, M.seqGet(xs, i) = none -> M.seqRemove(xs, i) = xs;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_repeatSpecTec
law seqLen_repeat : forall {α} k (a : α), M.seqLen(M.seqRepeat(M.ofNat(k), a)) = M.ofNat(k);Each of k copies of a value is that value.
seqGet_repeatSpecTec
law seqGet_repeat : forall {α} k (a : α) i x, M.seqGet(M.seqRepeat(M.ofNat(k), a), i) = some(x) -> x = a;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_nilSpecTec
law seqFoldl_nil : forall {α β} (f : β -> α -> β) (b : β), M.seqFoldl(f, b, M.seqNil(α := α)) = b;A fold visits the elements first to last.
seqFoldl_pushSpecTec
law seqFoldl_push : forall {α β} (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_emptySpecTec
law recGet_empty : forall {α} f, M.recGet(M.recEmpty(α := α), f) = none;A Record type value consists of one or more named fields.
Setting a field (read-over-write).
Any fields that are not explicitly listed are considered to be absent.
Deleting a field makes it absent.
A Record type value consists of one or more named fields.
The listed fields are the present ones.
Each field is listed once.
The properties of an object are uniquely identified using property keys.
The empty table has no properties.
propsGet_emptySpecTec
law propsGet_empty : forall {α} k, M.propsGet(M.propsEmpty(α := α), k) = none;Putting a property reads it back.
propsGet_put_selfSpecTec
law propsGet_put_self : forall {α} (p : M.Props(α)) k a, M.propsGet(M.propsPut(p, k, a), k) = some(a);Putting a property leaves the others.
propsGet_put_otherSpecTec
law propsGet_put_other : forall {α} (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_selfSpecTec
law propsGet_del_self : forall {α} (p : M.Props(α)) k, M.propsGet(M.propsDel(p, k), k) = none;Deleting a property leaves the others.
propsGet_del_otherSpecTec
law propsGet_del_other : forall {α} (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_memSpecTec
law propsKeys_mem : forall {α} (p : M.Props(α)) k, M.propsGet(p, k).isSome = true <=> exists i, M.seqGet(M.propsKeys(p), i) = some(k);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_onceSpecTec
law propsKeys_once : forall {α} (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_newSpecTec
law propsKeys_put_new : forall {α} (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_oldSpecTec
law propsKeys_put_old : forall {α} (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_delSpecTec
law propsKeys_del : forall {α} (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_absentSpecTec
law propsDel_absent : forall {α} (p : M.Props(α)) k, M.propsGet(p, k) = none -> M.propsDel(p, k) = p;References to existing values with identity cannot be manifest simply by describing them
The empty store refers to no value.
heapGet_emptySpecTec
law heapGet_empty : forall {α} a, M.heapGet(M.heapEmpty(α := α), a) = none;each value with identity is unique and therefore only equal to itself.
An allocated address is fresh.
heapAlloc_freshSpecTec
law heapAlloc_fresh : forall {α} (h : M.Heap(α)) v, M.heapGet(h, M.heapAlloc(h, v).1) = none;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_selfSpecTec
law heapAlloc_get_self : forall {α} (h : M.Heap(α)) v, M.heapGet(M.heapAlloc(h, v).2, M.heapAlloc(h, v).1) = some(v);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_otherSpecTec
law heapAlloc_get_other : forall {α} (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).
Writing a cell leaves the others.
References to existing values with identity cannot be manifest simply by describing them
Writing an unallocated cell changes nothing.
A CharSet is a mathematical set of CharSetElements.
CsSize is the non-negative integer count of elements in the CharSet.
Every index csGet reads is a valid index into the CharSet and yields a sequence of code points in it.
Every index below csSize holds an element.
The CharSet has no duplicate elements at distinct indices.
Every element in csHas appears at some index of csGet.
csHas_existsSpecTec
law csHas_exists : forall cs e, M.allPoints(e) -> M.csHas(cs, e) = true -> (exists i e', M.csGet(cs, i) = some(e') /\ seqList(e') = seqList(e));The empty CharSet has no elements.
CsAdd inserts a CharSetElement of code points into the CharSet.
csHas_addSpecTec
law csHas_add : forall 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));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_intervalSpecTec
law csHas_interval : forall lo hi e, M.isPoint(lo) -> M.isPoint(hi) -> M.allPoints(e) -> (M.csHas(M.csInterval(lo, hi), e) = true <=> exists c, seqList(e) = [c] /\ M.isPoint(c) /\ not M.lt(c, lo) /\ not M.lt(hi, c));A CharSet is a mathematical set of CharSetElements.
CsUnion is set union of CharSets.
csHas_unionSpecTec
law csHas_union : forall 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_interSpecTec
law csHas_inter : forall 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_diffSpecTec
law csHas_diff : forall 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_iffSpecTec
law csAllSingle_iff : forall cs, M.csAllSingle(cs) = true <=> forall i e, M.csGet(cs, i) = some(e) -> M.seqLen(e) = M.ofNat(1);CsSingles restricts a CharSet to its single-character elements.
csHas_singlesSpecTec
law csHas_singles : forall 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_someSpecTec
law csFromProp_some : forall p v, M.csFromProp(p, v).isSome = M.propSet(p, v).isSome;CsFromProp holds the CharSetElements that propSet returns.
csHas_fromPropSpecTec
law csHas_fromProp : forall p v cs e, M.csFromProp(p, v) = some(cs) -> M.allPoints(e) -> (M.csHas(cs, e) = true <=> exists es i e', M.propSet(p, v) = some(es) /\ M.seqGet(es, i) = some(e') /\ seqList(e') = seqList(e));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.
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_canonExtraSpecTec
law csHas_canonExtra : forall cs u e, M.allPoints(e) -> (M.csHas(M.csCanonExtra(cs, u), e) = true <=> exists 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_iffSpecTec
law csHasCanon_iff : forall cs cc u ic, M.isPoint(cc) -> (M.csHasCanon(cs, cc, u, ic) = true <=> exists 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).
bytesSpecTec
law bytes : M.ByteLaws;Auxiliary definitions (2): Model.stringPropertyNames, Model.codePointsOf
Model.stringPropertyNames
05-model-laws.spectec:725The 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
05-model-laws.spectec:728A 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
05-model-laws.spectec:732The laws of the Unicode operations (§6.1.4, sec-ecmascript-language-types-string-type; §22.1.3.15, sec-string.prototype.normalize): only what the text relies on.
Proved of the engine's model: Engine.Impl.unicodeLaws, part of Implements.model.
laws Model.UnicodeLaws (M : Model)7 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.
Let lowerText be toLowercase(sText), according to the Unicode Default Case Conversion algorithm.
ToLowercase gives code points.
toLower_pointsSpecTec
law toLower_points : forall 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_pointsSpecTec
law toUpper_points : forall 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_charsSpecTec
law propSet_chars : forall 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.
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_stringsSpecTec
law propSet_strings : forall 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 -> (exists n mem Model.stringPropertyNames, forall 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_pointsSpecTec
law normalize_points : forall f xs, M.allPoints(xs) -> M.allPoints(M.normalize(f, xs));Auxiliary definitions (2): Model.InSeq, Model.KidOf
Model.InSeq
05-model-laws.spectec:764c 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
05-model-laws.spectec:767n 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 := exists c, Model.InSeq(c, M.nodeKids(p)) /\ M.nodeEq(c, n) = trueModel.Within
05-model-laws.spectec:770p is r or a Parse Node in the tree below r, at any depth (§5.1.2, sec-parsing).
relation Model.Within {M : Model} : M.Node -> M.Node -> Proprule root (r : M.Node) : Model.Within(r, r);rule kid {r c p : M.Node} : Model.Within(r, p) :- Model.InSeq(c, M.nodeKids(r)), Model.Within(c, p);Model.ParentLaws
05-model-laws.spectec:777Model.nodeParent's laws (§5.1.2, sec-parsing): 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.
laws Model.ParentLaws (M : Model)4 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.
soundSpecTec
law sound : forall 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.
completeSpecTec
law complete : forall 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.
ancestorsSpecTec
law ancestors : forall r n, M.nodeAncestors(r, n) = match M.nodeParent(r, n) with | some(p) => p :: M.nodeAncestors(r, p) | none => [] end;
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.
heightSpecTec
law height : forall n c, Model.InSeq(c, M.nodeKids(n)) -> M.nodeHeight(c) < M.nodeHeight(n);UTF-16 code points (§6.1.4)
From lean/Ecma/Prims/Strings.lean
The prose notation of §6.1.4 and §11 over Strings, code units and code points. A code unit or a code point is a mathematical value: an integer 0–0xFFFF or 0–0x10FFFF. A String is M.Str; where the text allows "a sequence of code units", a List of code units stands for the String. Source text is a List of code points (§11).
Auxiliary definitions (6): Prims.Strings.inRange, Prims.Strings.isPoint, Prims.Strings.isLead, Prims.Strings.isTrail, …
Prims.Strings.inRange
Strings.lean:23An integer in [0, hi].
def inRange (hi : Nat) (m : M.Math) : Bool := M.isInt m && !M.lt m (M.ofNat 0) && !M.lt (M.ofNat hi) m
Prims.Strings.isPoint
Strings.lean:30A code point's value (§6.1.4, sec-ecmascript-language-types-string-type).
def isPoint (m : M.Math) : Bool := inRange 0x10FFFF mPrims.Strings.isLead
Strings.lean:190Whether a code unit is a leading surrogate (§6.1.4, sec-ecmascript-language-types-string-type).
def isLead (u : M.Math) : Bool := !M.lt u (M.ofNat 0xD800) && !M.lt (M.ofNat 0xDBFF) uPrims.Strings.isTrail
Strings.lean:193Whether a code unit is a trailing surrogate (§6.1.4, sec-ecmascript-language-types-string-type).
def isTrail (u : M.Math) : Bool := !M.lt u (M.ofNat 0xDC00) && !M.lt (M.ofNat 0xDFFF) uPrims.Strings.pairValue
Strings.lean:196§11.1.4 (sec-utf16decodesurrogatepair): the code point of a surrogate pair.
def pairValue (c1 c2 : M.Math) : M.Math := M.add (M.add (M.mul (M.sub c1 (M.ofNat 0xD800)) (M.ofNat 0x400)) (M.sub c2 (M.ofNat 0xDC00))) (M.ofNat 0x10000)
Prims.Strings.strPoints
Strings.lean:202§6.1.4 (sec-ecmascript-language-types-string-type): a String's code points: a lead and trail surrogate pair as one, any other code unit as itself.
def strPoints (t : M.Str) : M.Seq M.Math := let (acc, pend) := M.seqFoldl (fun (st : M.Seq M.Math × Option M.Math) u => match st with | (acc, some l) => if isTrail u then (M.seqPush acc (pairValue l u), none) else if isLead u then (M.seqPush acc l, some u) else (M.seqPush (M.seqPush acc l) u, none) | (acc, none) => if isLead u then (acc, some u) else (M.seqPush acc u, none)) (M.seqNil, none) (M.strUnits t) match pend with | some l => M.seqPush acc l | none => acc