tla-ts 0.0.3-dev.366c320 → 0.0.3-dev.3c70a97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/transfer.cjs +1 -1
- package/dist/transfer.js +1 -1
- package/package.json +1 -1
- package/src/tlc-ext.ts +2 -27
- package/src/tlc-module.ts +28 -3
package/dist/transfer.cjs
CHANGED
|
@@ -90,7 +90,7 @@ _TEPosition ==
|
|
|
90
90
|
ELSE IF TLCGet("level") = 0 THEN 1 ELSE TLCGet("level")
|
|
91
91
|
|
|
92
92
|
=============================================================================`]]),js=`tlc2/value/impl/`,Ms=e=>{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n={offset:0},r=e=>{let t=n.offset;return n.offset+=e,t};return{readUint8:()=>t.getUint8(r(1)),readUint16:()=>t.getUint16(r(2)),readUint32:()=>t.getUint32(r(4)),readInt32:()=>t.getInt32(r(4)),readBytes:t=>e.subarray(r(t),n.offset)}},Ns=e=>[...e.slice(1,e.indexOf(`)`)).matchAll(/\[*(?:L[^;]*;|[BCDFIJSZ])/g)].length,Ps=e=>{let t=Ms(e);if(t.readUint32()!==3405691582)throw new c(`A module override is not a class file`);t.readUint16(),t.readUint16();let n=[],r=t.readUint16(),i=new TextDecoder;for(let e=1;e<r;e++){let r=t.readUint8(),a={tag:r,text:``,value:0,first:0,second:0};n[e]=a,r===1?a.text=i.decode(t.readBytes(t.readUint16())):r===3?a.value=t.readInt32():r===4?t.readUint32():r===5||r===6?(t.readBytes(8),e++):r===7||r===8||r===16||r===19||r===20?a.first=t.readUint16():r===15?(t.readUint8(),a.first=t.readUint16()):(a.first=t.readUint16(),a.second=t.readUint16())}t.readUint16(),t.readUint16(),t.readUint16(),t.readBytes(t.readUint16()*2);for(let e=t.readUint16();e>0;e--){t.readBytes(6);for(let e=t.readUint16();e>0;e--)t.readUint16(),t.readBytes(t.readUint32())}let a=[];for(let e=t.readUint16();e>0;e--){let e=t.readUint16(),r=n[t.readUint16()].text,i=n[t.readUint16()].text,o={name:r,arity:Ns(i),code:void 0};for(let e=t.readUint16();e>0;e--){let e=n[t.readUint16()].text,r=t.readBytes(t.readUint32());if(e===`Code`){let e=new DataView(r.buffer,r.byteOffset+4,4).getUint32(0);o.code=r.subarray(8,8+e)}}e&1&&e&8&&a.push(o)}return{pool:n,methods:a}},Fs=(e,t)=>e[e[t].first].text,Is=(e,t)=>{let n=e[t],r=e[n.second];return{className:Fs(e,n.first),name:e[r.first].text}},Ls=(e,t,n,r)=>{let i=()=>new m(`The Java override ${n}.${e.name} computes its value, which tla-ts cannot run`),a=e.code;if(!a)throw i();let o=[],s=()=>{let e=o.pop();if(e===void 0)throw i();return e},c=e=>{let n=t[e];if(n.tag===3)return n.value;if(n.tag===8)return t[n.first].text;throw i()};for(let e=0;e<a.length;){let n=a[e],l=()=>a[e+1]<<8|a[e+2];if(n>=2&&n<=8)o.push(n-3),e+=1;else if(n===16)o.push(a[e+1]<<24>>24),e+=2;else if(n===17)o.push(l()<<16>>16),e+=3;else if(n===18)o.push(c(a[e+1])),e+=2;else if(n===19)o.push(c(l())),e+=3;else if(n===89){let t=s();o.push(t,t),e+=1}else if(n===178){let n=Is(t,l());if(n.className!==`${js}BoolValue`||n.name!==`ValTrue`&&n.name!==`ValFalse`)throw i();o.push({kind:`Identifier`,name:n.name===`ValTrue`?`TRUE`:`FALSE`,location:r}),e+=3}else if(n===184){let n=Is(t,l()),a=s();if(n.className!==`${js}IntValue`||n.name!==`gen`||typeof a!=`number`)throw i();o.push({kind:`Number`,value:a,location:r}),e+=3}else if(n===187)o.push({className:Fs(t,l()),value:void 0}),e+=3;else if(n===183){let n=Is(t,l()),a=s(),o=s();if(!(n.className===`${js}StringValue`&&n.name===`<init>`&&typeof a==`string`&&typeof o==`object`&&`className`in o))throw i();o.value={kind:`String`,value:a,location:r},e+=3}else if(n===176){let e=s();if(typeof e!=`object`)throw i();if(`className`in e){if(!e.value)throw i();return e.value}return e}else throw i()}throw i()},Rs=(e,t)=>{if(!t)return e;let n=Ps(t),r=e.definitions.map(t=>{if(t.kind!==`Operator`)return t;let r=n.methods.find(e=>e.name===t.name&&e.arity===t.params.length);return r?{...t,body:Ls(r,n.pool,e.name,t.location)}:t});return{...e,definitions:r}},Z=(e,t,n)=>({low:e,high:t,isAssociative:n}),zs=new Map([[`=>`,Z(1,1,!1)],[`<=>`,Z(2,2,!1)],[`~>`,Z(2,2,!1)],[`-+->`,Z(2,2,!1)],[`/\\`,Z(3,3,!0)],[`\\/`,Z(3,3,!0)],...(/* @__PURE__ */ `=.#.<.>.<=.>=.\\in.\\notin.\\subseteq.\\subset.\\supseteq.\\supset.\\sqsubseteq.\\sqsupseteq.\\sqsubset.\\sqsupset.\\prec.\\preceq.\\succ.\\succeq.\\sim.\\simeq.\\approx.\\cong.\\asymp.\\doteq.\\propto.\\ll.\\gg.|-.-|.|=.=|.:=.::=`.split(`.`)).map(e=>[e,Z(5,5,!1)]),[`\\cdot`,Z(5,14,!0)],[`@@`,Z(6,6,!0)],[`:>`,Z(7,7,!1)],[`<:`,Z(7,7,!1)],[`\\cup`,Z(8,8,!0)],[`\\cap`,Z(8,8,!0)],[`\\`,Z(8,8,!1)],[`..`,Z(9,9,!1)],[`...`,Z(9,9,!1)],[`##`,Z(9,13,!0)],[`$`,Z(9,13,!0)],[`$$`,Z(9,13,!0)],[`??`,Z(9,13,!0)],[`!!`,Z(9,13,!1)],[`\\sqcap`,Z(9,13,!0)],[`\\sqcup`,Z(9,13,!0)],[`\\uplus`,Z(9,13,!0)],[`\\wr`,Z(9,14,!1)],[`+`,Z(10,10,!0)],[`++`,Z(10,10,!0)],[`(+)`,Z(10,10,!0)],[`\\oplus`,Z(10,10,!0)],[`%`,Z(10,11,!1)],[`%%`,Z(10,11,!0)],[`|`,Z(10,11,!0)],[`||`,Z(10,11,!0)],[`\\X`,Z(10,13,!1)],[`-`,Z(11,11,!0)],[`--`,Z(11,11,!0)],[`(-)`,Z(11,11,!0)],[`\\ominus`,Z(11,11,!0)],[`*`,Z(13,13,!0)],[`**`,Z(13,13,!0)],[`/`,Z(13,13,!1)],[`//`,Z(13,13,!1)],[`\\div`,Z(13,13,!1)],[`\\o`,Z(13,13,!0)],[`(.)`,Z(13,13,!0)],[`\\odot`,Z(13,13,!0)],[`(/)`,Z(13,13,!1)],[`\\oslash`,Z(13,13,!1)],[`(\\X)`,Z(13,13,!0)],[`\\otimes`,Z(13,13,!0)],[`&`,Z(13,13,!0)],[`&&`,Z(13,13,!0)],[`\\star`,Z(13,13,!0)],[`\\bullet`,Z(13,13,!0)],[`\\bigcirc`,Z(13,13,!0)],[`^`,Z(14,14,!1)],[`^^`,Z(14,14,!1)]]),Bs=/* @__PURE__ */ new Set([`^+`,`^*`,`^#`]),Vs=/* @__PURE__ */ new Set([`-`,`~`,`-.`]),Hs=/* @__PURE__ */ new Set([`-`,`~`,`/\\`,`\\/`,`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`]),Us=/* @__PURE__ */ new Set([`+`,`-`,`/`,`\\X`]),Ws=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`,`'`,...Bs]),Gs=e=>zs.has(e)||Bs.has(e)||e===`-.`,Ks=(e,t,n)=>{switch(e){case`ENABLED`:return{kind:`Enabled`,expression:t,location:n};case`UNCHANGED`:return{kind:`Unchanged`,expression:t,location:n};case`[]`:return{kind:`Always`,expression:t,location:n};case`<>`:return{kind:`Eventually`,expression:t,location:n};case`'`:return{kind:`Prime`,expression:t,location:n};default:return{kind:`Apply`,operator:e,args:[t],location:n}}},qs=/* @__PURE__ */ new Set([`<<`,`>>`,`:`,`@`,`(`]),Js=/* @__PURE__ */ new Set([`ASSUME`,`ASSUMPTION`,`AXIOM`,`CONSTANT`,`CONSTANTS`,`COROLLARY`,`INSTANCE`,`LEMMA`,`LOCAL`,`PROPOSITION`,`RECURSIVE`,`THEOREM`,`VARIABLE`,`VARIABLES`]),Ys=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Xs=/* @__PURE__ */ new Set([`BY`,`PROOF`,`OBVIOUS`,`OMITTED`]),Zs=/* @__PURE__ */ new Set([`Qed`,`Pick`,`Case`,`Assert`]),Qs=/* @__PURE__ */ new Set(/* @__PURE__ */ `, . _ ( ) [ ] { } << >> ]_ >>_ == ! @ : :: ; -> <- |-> \\A \\AA \\E \\EE \\forall \\exists WF_ SF_ (*{ }*)`.split(` `)),$s=/* @__PURE__ */ new Set([``,`*`,`-`]),ec=/* @__PURE__ */ new Set([`CASE`,`CHOOSE`,`DOMAIN`,`ENABLED`,`IF`,`LAMBDA`,`LET`,`SF_`,`SUBSET`,`UNCHANGED`,`UNION`,`WF_`]),tc=/* @__PURE__ */ new Map([[`CONSTANT`,`Constant`],[`CONSTANTS`,`Constant`],[`VARIABLE`,`Variable`],[`VARIABLES`,`Variable`],[`STATE`,`State`],[`ACTION`,`Action`],[`ACTIONS`,`Action`],[`TEMPORAL`,`Temporal`],[`TEMPORALS`,`Temporal`]]),nc=/* @__PURE__ */ new Set([`NEW`,...tc.keys()]),rc=/* @__PURE__ */ new Set([`(`,`[`,`{`,`<<`]),ic=/* @__PURE__ */ new Set([`)`,`]`,`}`,`>>`,`]_`,`>>_`]),ac=/* @__PURE__ */ new Set([`TRUE`,`FALSE`,`BOOLEAN`,`STRING`]),oc=e=>RegExp(`^-{4,}\\s*MODULE\\s+${e}\\s*-{3,}$`),sc=(e,t)=>{let n=e.split(/\r?\n/),r=n.findIndex(e=>oc(t).test(e));if(r===-1)return;let i=n.findIndex((e,t)=>t>r&&e.startsWith(`====`));return n.slice(r,i===-1?void 0:i+1).join(`
|
|
93
|
-
`)},cc=(e,t)=>{let n=oe(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},l=[],u=e=>i[i.length-1].has(e),d=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),f=[],p=[],m=[],h=e=>{let t=r.index-1,i=e===t?m[e]:void 0;if(i)return i;let a=n[t];f[e]??=d(n[e]),p[t]??={line:a.line,column:a.endColumn};let o={module:l[l.length-1].name,start:f[e],end:p[t]};return e===t&&(m[e]=o),o},g=(e,t)=>(e.location.range=h(t),e),_=(e=0)=>n[Math.min(r.index+e,n.length-1)],v=(e=0)=>{let t=_(e),n=r.offsideColumns[r.offsideColumns.length-1];return n===void 0||n===-1||t.kind===`End`?t:t.column<=n?{...t,kind:`End`,text:``}:t},y=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),ee={index:0},b=e=>{let t=n.slice(ee.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},te=e=>t&&(e.kind===`Keyword`||ac.has(e.text)),re=e=>{let t=n.findLast(t=>t.kind!==`End`&&(t.line<e.line||t.line===e.line&&t.column<e.column));return t?{line:t.line,column:t.endColumn+1}:e},x=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Qs.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):te(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,S=(e,t=_(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new c(`${e} at line ${t.line}, column ${t.column}`,void 0,ie(e,t,a,r))},ie=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...b(re(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${x(a)}`,...re(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},C=(e,t=_())=>S(e,t,t),ae=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!te(e),w=(e,t=0)=>{let n=v(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},T=()=>{let e=v();if(e.kind===`End`)throw S(`Unexpected end of expression`);return r.index++,e},E=e=>w(e)?(r.index++,!0):!1,D=e=>{if(!w(e))throw C(`Expected ${JSON.stringify(e)} but found ${y(v())}`);return T()},O=()=>{let e=v();if(e.kind!==`Identifier`)throw C(`Expected an identifier but found ${y(e)}`);if(te(e))throw C(`Unexpected keyword ${e.text}`);return r.index++,e.text},se=e=>{r.offsideColumns.push(-1);let t=e();return r.offsideColumns.pop(),t},k=(e,t=`,`)=>{let n=[e()];for(;E(t);)n.push(e());return n},ce=()=>{if(w(`<<`)){let e={value:1};for(;v(e.value).kind===`Identifier`||w(`,`,e.value);)e.value++;return w(`>>`,e.value)&&w(`\\in`,e.value+1)}let e={value:0};for(;v(e.value).kind===`Identifier`;){if(w(`\\in`,e.value+1))return!0;if(!w(`,`,e.value+1))return!1;e.value+=2}return!1},le=()=>{if(w(`::`))return!0;if(!w(`(`))return!1;let e={value:1};for(;v(e.value).kind===`Identifier`&&w(`,`,e.value+1);)e.value+=2;return v(e.value).kind===`Identifier`&&w(`)`,e.value+1)&&w(`::`,e.value+2)},ue=()=>{if(!E(`<<`))return{kind:`Name`,name:O()};let e=k(O);return D(`>>`),{kind:`Tuple`,names:e}},de=()=>k(()=>{let e=k(ue);D(`\\in`);let t=N();return e.map(e=>({pattern:e,set:t}))}).flat(),A=()=>{let e=v();if(e.kind===`Identifier`){let t=r.index,n=[T().text];for(;w(`!`)&&v(1).kind===`Identifier`;)T(),n.push(O());return g({kind:`Identifier`,name:n.join(`!`),location:d(e)},t)}if(w(`<<`)||w(`(`))return Se();throw C(`Expected a subscript but found ${y(e)}`)},j=e=>{let t=v(1),n=v(2);return t.kind===`Identifier`&&n.text===`==`?!0:t.line===e.line?!1:t.text===`-.`||t.kind===`Identifier`&&(n.text===`(`||n.text===`[`||n.kind===`Operator`&&w(`==`,Bs.has(n.text)?3:4))},M=e=>{if(!Hs.has(e.text))return!0;let t=v(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||w(`,`,1)||w(`)`,1)||t.kind===`Keyword`&&Js.has(t.text)||j(e)},fe=()=>{let e=v(),n=e.kind===`Operator`&&(zs.has(e.text)||Vs.has(e.text))&&M(e);if(t&&e.kind!==`String`&&(Vs.has(e.text)||Ws.has(e.text)&&e.text!==`'`&&!Bs.has(e.text)||Us.has(e.text)&&v(-1).text===`(`&&v(-1).line===e.line&&v(-1).endColumn+1===e.column&&v(1).text===`)`&&v(1).line===e.line&&v(1).column===e.endColumn+1)&&M(e))throw S(`incomplete expression`,e);if(n)return r.index++,g({kind:`OperatorReference`,operator:e.text,location:d(e)},r.index-1);if(e.kind!==`String`&&Ws.has(e.text)&&M(e)){r.index++;let t=d(e);if(Bs.has(e.text))return{kind:`OperatorReference`,operator:e.text,location:t};let n={kind:`Identifier`,name:`argument`,location:t};return{kind:`Lambda`,params:[n.name],body:Ks(e.text,n,t),location:t}}if(w(`LAMBDA`)){let t=r.index;T();let n=k(O);D(`:`);let i=N();return g({kind:`Lambda`,params:n,body:i,location:d(e)},t)}return N()},pe=()=>se(()=>{D(`(`);let e=k(fe);return D(`)`),e}),me=()=>{let e=T();r.offsideColumns.push(e.column);let t=[N()];for(;_().text===e.text&&_().column===e.column;)r.index++,t.push(N());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:d(e)}},he=e=>se(()=>{let t=d(e);if(v().kind===`Identifier`&&(w(`|->`,1)||w(`:`,1))){let e=w(`|->`,1)?`Record`:`RecordSet`,n=k(()=>{let t=O();return D(e===`Record`?`|->`:`:`),{name:t,value:N()}});return D(`]`),{kind:e,fields:n,location:t}}if(ce()){let e=de();D(`|->`);let n=N();return D(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=N();if(E(`->`)){let e=N();return D(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(E(`EXCEPT`)){let e=k(()=>{D(`!`);let e=[];for(;w(`.`)||w(`[`);)if(E(`.`)){if(!ae(v()))throw C(`Expected a field name but found ${y(v())}`);e.push({kind:`Field`,name:T().text})}else D(`[`),e.push({kind:`Index`,args:k(()=>N())}),D(`]`);return D(`=`),{path:e,value:N()}});return D(`]`),{kind:`Except`,function:n,updates:e,location:t}}return D(`]_`),{kind:`BoxAction`,action:n,subscript:A(),location:t}}),ge=e=>se(()=>{let t=d(e);if(E(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(ce()&&(v(1).text===`\\in`||w(`<<`))){let e=r.index,n=ue();D(`\\in`);let i=N();if(E(`:`)){let e=N();return D(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=N();if(E(`:`)){let e=de();return D(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;E(`,`);)i.push(N());return D(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),_e=e=>{let t=d(e),n=se(()=>w(`>>`)||w(`>>_`)?[]:k(()=>N()));if(E(`>>_`)){if(n.length!==1)throw S(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:A(),location:t}}return D(`>>`),{kind:`Tuple`,elements:n,location:t}},ve=e=>{let t=d(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&ce()){let e=de();return D(`:`),{kind:n,bounds:e,body:N(),location:t}}let i=k(O);return D(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:N(),isTemporal:r,location:t}},ye=e=>{let t=[];do{if(E(`OTHER`))return D(`->`),{kind:`Case`,arms:t,other:N(),location:d(e)};let n=N();D(`->`),t.push({condition:n,body:N()})}while(E(`[]`));return{kind:`Case`,arms:t,other:void 0,location:d(e)}},be=()=>{let e=v(1);return w(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||qs.has(e.text)||e.kind===`Operator`&&(zs.has(e.text)||Bs.has(e.text)||Vs.has(e.text)))},xe=()=>{let e=T();if(e.kind===`Number`)return{kind:`Operand`,operand:ne(e.text)};switch(e.text){case`<<`:case`>>`:return{kind:`Operand`,operand:e.text};case`:`:return{kind:`Colon`};case`@`:return{kind:`At`};case`(`:return r.index--,{kind:`Bound`,args:pe()}}return{kind:`Name`,name:e.text,args:w(`(`)?pe():[]}},Se=()=>{let e=r.index===s.index,n=T(),a=d(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=k(O);return D(`:`),{kind:`Lambda`,params:e,body:N(),location:a}}if(n.kind===`Number`){if(t&&/^\\[BOH]/.test(n.text))throw S(`incomplete expression`,n);return{kind:`Number`,value:ne(n.text),text:n.text,location:a}}if(n.kind===`Decimal`)return{kind:`Decimal`,text:n.text,location:a};if(n.kind===`String`)return{kind:`String`,value:n.text,location:a};let o=n.kind===`Step`&&Fe(n);if(o&&I()<0&&Me.length<=1)throw S(`Step number used outside proof`,n);if(o&&n.text[1]===`+`)throw S(`<+> step number used in an expression`,n);if(n.kind===`Identifier`||o){let r=o?L(n)??n.text:n.text;if(le()){let e=E(`(`)?k(O):[];return e.length>0&&D(`)`),D(`::`),{kind:`Label`,name:r,params:e,body:N(),location:a}}let i=w(`(`),s=i?pe():[];if(!be())return i?{kind:`Apply`,operator:r,args:s,location:a}:{kind:`Identifier`,name:r,location:a};let c=l.flatMap(e=>e.instances).find(e=>e.name===r);if(c&&!e&&!t&&c.params.length!==s.length)throw S(`The operator ${r} requires ${c.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;be();)T(),u.push(xe());let d=u.flatMap(e=>e.kind===`Name`?[e.name]:[]);if(d.length<u.length)return{kind:`Subexpression`,selectors:u,location:a};let f=d.join(`!`),p=u.flatMap(e=>`args`in e?e.args:[]);if(p.length===0)return{kind:`Identifier`,name:f,location:a};let m=u.map(e=>`args`in e?e.args.length:0);return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,location:a}:{kind:`Apply`,operator:f,args:p,location:a}}if(n.kind===`Operator`&&Gs(n.text)&&w(`(`))return{kind:`Apply`,operator:n.text,args:pe(),location:a};switch(n.text){case`(`:{let e=se(()=>N());return D(`)`),e}case`[`:return he(n);case`{`:return ge(n);case`<<`:return _e(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return ve(n);case`IF`:{let e=N();D(`THEN`);let t=N();return D(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:N(),location:a}}case`CASE`:return ye(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!E(`IN`);){if(t&&w(`RECURSIVE`))throw S(`Unexpected keyword RECURSIVE`,b(_()));if(E(`RECURSIVE`)){ke();continue}let r=P(!1);r.kind===`Instance`?n.push(r):e.push(r)}i.pop();let r=N();return n.length===0?{kind:`Let`,definitions:e,body:r,location:a}:{kind:`Let`,definitions:e,instances:n,body:r,location:a}}case`CHOOSE`:{let e=ue(),t=E(`\\in`)?N():void 0;return D(`:`),{kind:`Choose`,pattern:e,set:t,body:N(),location:a}}case`WF_`:case`SF_`:{let e=A(),t=se(()=>{D(`(`);let e=N();return D(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw C(`Unexpected ${y(n)}`,n)},Ce=()=>{let e=v(),t=d(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return me();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return T(),{kind:`Apply`,operator:`~`,args:[N(5)],location:t};case`-`:return T(),{kind:`Apply`,operator:`-.`,args:[N(13)],location:t};case`[]`:return T(),{kind:`Always`,expression:N(16),location:t};case`<>`:return T(),{kind:`Eventually`,expression:N(16),location:t};case`ENABLED`:return T(),{kind:`Enabled`,expression:N(16),location:t};case`UNCHANGED`:return T(),{kind:`Unchanged`,expression:N(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return T(),{kind:`Apply`,operator:e.text,args:[N(9)],location:t}}return Se()},N=(e=0)=>{let t=r.index,n=Ce(),i={left:n.location.range?n:g(n,t),previous:void 0};for(;;){let n=v();if(n.kind!==`Operator`)break;let r=d(n);if(n.text===`'`&&e<=15){T(),i.left=g({kind:`Prime`,expression:i.left,location:r},t);continue}if(Bs.has(n.text)&&e<=15){T(),i.left=g({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){T();let e=se(()=>k(()=>N()));se(()=>D(`]`)),i.left=g({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&ae(v(1))){T();let e=T().text;i.left=g({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=zs.get(n.text);if(!a||a.low<e)break;let o=i.previous;if(o){let e=!(o.low>a.high||o.high<a.low),t=o.text===n.text&&a.isAssociative;if(e&&!t&&(o.text!==`\\X`||n.text!==`\\X`))throw S(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(T(),a.low>12&&w(`-`))throw S(`Precedence conflict between ${n.text} and -`,v());let s=N(a.high+1),c=i.left;if(n.text===`/\\`||n.text===`\\/`){let e=n.text===`/\\`?`And`:`Or`;i.left=c.kind===e&&o?.text===n.text?{...c,operands:[...c.operands,s]}:{kind:e,operands:[c,s],location:r}}else i.left=n.text===`\\X`?c.kind===`Product`&&o?.text===`\\X`?{...c,factors:[...c.factors,s]}:{kind:`Product`,factors:[c,s],location:r}:{kind:`Apply`,operator:n.text,args:[c,s],location:r};i.left=g(i.left,t),i.previous={...a,text:n.text}}return i.left},we=()=>{if(!E(`(`))return[];let e=F();return D(`)`),e},Te=()=>{let e=d(v()),t=N(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:l[l.length-1].name,start:e,end:a}}},P=e=>{let t=r.index;return g(Ee(e),t)},Ee=e=>{let t=v(),n=d(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...Te(),isLocal:e,isRecursive:u(t),location:n});if(t.kind===`Identifier`&&v(1).kind===`Operator`&&zs.has(v(1).text)&&v(2).kind===`Identifier`&&w(`==`,3)){let e=O(),t=T().text,n=O();return D(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&Bs.has(v(1).text)&&w(`==`,2);if(a||o){let e=a?t.text:v(1).text;r.index+=a?1:2;let n=a?O():t.text;return D(`==`),i(e,[{name:n,arity:0}])}let s=O();if(E(`[`)){let t=se(()=>de());return D(`]`),D(`==`),{kind:`Function`,name:s,bounds:t,body:N(),isLocal:e,isRecursive:u(s),location:n}}let c=r.index,l=we();return D(`==`),w(`INSTANCE`)?{...De(s,l,e,n),definitionRange:h(c)}:i(s,l)},De=(e,t,n,i)=>{let a=r.index;return D(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:O(),substitutions:E(`WITH`)?k(()=>{let e=T().text;return D(`<-`),{name:e,expression:fe()}}):[],isLocal:n,location:i,instanceRange:h(a)}},Oe=()=>{let e=d(v());if(w(`_`)&&v(1).kind===`Operator`)return T(),{name:T().text,arity:E(`_`)?2:1,location:e};if(v().kind===`Operator`&&w(`_`,1)){let t=T().text;return T(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=O();if(!E(`(`))return{name:t,arity:0,location:e};let n=k(()=>D(`_`));return D(`)`),{name:t,arity:n.length,location:e}},F=()=>k(Oe),ke=()=>{let e=F();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ae=e=>{let t={value:0,offset:e};do{let e=v(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&rc.has(e.text)&&t.value++,e.kind===`Operator`&&ic.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},je=()=>{let e=v(),t=v(1);return e.kind===`Identifier`?w(`(`,1)||w(`[`,1)?w(`==`,Ae(1)):t.kind===`Operator`&&Bs.has(t.text)?w(`==`,2):t.kind===`Operator`&&zs.has(t.text)?v(2).kind===`Identifier`&&w(`==`,3):w(`==`,1):w(`-.`)&&t.kind===`Identifier`&&w(`==`,2)},Me=[],I=()=>Me[Me.length-1]??-1,Ne=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),Pe=e=>{let t=e.text.slice(e.text.indexOf(`>`)+1),n={value:t.length};for(;t[n.value-1]===`.`;)n.value--;return t.slice(0,n.value)},Fe=e=>!e.text.endsWith(`.`)&&!$s.has(Pe(e)),L=e=>{let t=Pe(e);if($s.has(t))return;let n=Ne(e);if(n>=0)return`<${n}>${t}`;let r=I(),i=Me[Me.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Ie=e=>{if(e.kind===`Keyword`)return Xs.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Me.length===0;if(e.text[1]===`+`||Me.length===0)return!0;let t=I();return t>=0&&Ne(e)>t},Le=e=>{let t=Ne(e),n=Me.length-1,r=Me[n-1]??-1,i=Me[n]<0;return i&&(Me[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Me[n]===t},Re=e=>!a.has(e)&&l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),ze=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!ac.has(e.name)&&!Re(e.name):!1,Be=()=>{let e=v();return e.kind===`Step`?Fe(e):e.kind===`Keyword`?ec.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!je()},Ve=()=>{let e=r.index;s.index=e;let t=v();return t.kind===`Operator`&&!Hs.has(t.text)&&Gs(t.text)?(r.index++,g({kind:`OperatorReference`,operator:t.text,location:d(t)},e)):E(`MODULE`)?g({kind:`ModuleFact`,name:O(),location:d(t)},e):N()},He=e=>o[o.length-1]?.add(e),Ue=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},We=e=>o.some(t=>t.has(e))||l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Ge=()=>{let e=r.index,t=v(),n=k(()=>{let e=v();if((e.kind!==`Identifier`||te(e))&&e.kind!==`Operator`)throw C(`Expected a definition name but found ${y(e)}`,e);return r.index++,e.text},`!`),i=d(t);return g(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ke=()=>{if(t)return k(Ge);let e=k(Ve),n=e.find(e=>e.kind===`Identifier`&&We(e.name));if(n)throw S(`DEF clause entry should describe a defined operator`,n.location);return e},qe=()=>({facts:Be()?k(Ve):[],defs:E(`DEF`)||E(`DEFS`)?Ke():[]}),Je=()=>{let e=r.index,n=T(),i=n.text===`USE`&&E(`ONLY`),a=h(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...qe(),keyword:a,location:d(n)},s=o.kind===`Hide`&&!t?o.facts.find(e=>!ze(e)):void 0;if(s)throw S(`The only expression allowed as a fact in a HIDE is the name of a theorem, assumption, or step`,s.location);return g(o,e)},Ye=()=>{let e=r.index,t=d(v()),n=E(`NEW`),i=v().kind===`Keyword`?tc.get(v().text):void 0;if(!n&&i===void 0)throw C(`Expected a declaration but found ${y(v())}`);if(i!==void 0&&T(),i===`Variable`){let n=O();return He(n),g({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Oe();He(a.name);let o=(i??`Constant`)===`Constant`&&w(`\\in`);if(o&&a.arity>0)throw S(`declared symbol with arguments before \\in`);return o&&T(),g({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?N():void 0,location:t},e)},Xe=()=>{let e=r.index,t=d(D(`ASSUME`)),n=k(()=>w(`ASSUME`)?Ue(Xe):v().kind===`Keyword`&&nc.has(v().text)?Ye():N());return D(`PROVE`),g({kind:`AssumeProve`,assumptions:n,conclusion:N(),location:t},e)},Ze=e=>{let t={value:0};for(;v(t.value).kind===`Identifier`&&w(`,`,t.value+1);)t.value+=2;return v(t.value).kind===`Identifier`&&w(e,t.value+1)},Qe=(e,t)=>{e.forEach(He),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(He))},$e=()=>{let e=v();if(w(`USE`)||w(`HIDE`))return Je();if(w(`INSTANCE`))return g(De(void 0,[],!1,d(e)),r.index);if(w(`DEFINE`)||je()){let t=r.index;E(`DEFINE`);let n=[P(!1)];for(;je();)n.push(P(!1));let i={kind:`Define`,definitions:n,location:d(e)};return g(i,t)}if(E(`HAVE`))return{kind:`Have`,expression:N()};if(E(`TAKE`)){let e=ce(),t=e?[]:k(O),n=e?de():[];return Qe(t,n),{kind:`Take`,names:t,bounds:n}}if(E(`WITNESS`))return{kind:`Witness`,expressions:k(()=>N())};if(E(`PICK`)){let e=Ze(`:`),t=e?k(O):[],n=e?[]:de();return Qe(t,n),D(`:`),{kind:`Pick`,names:t,bounds:n,body:N()}}return E(`CASE`)?{kind:`Case`,expression:N()}:{kind:`Assert`,isSuffices:E(`SUFFICES`),statement:w(`ASSUME`)?Xe():N()}},et=e=>{let t=v();if(t.kind!==`Step`)throw C(`Expected a step number but found ${y(t)}`,t);if(!Le(t))throw S(`${e?`QED step`:`step`}'s number has bad level`,t);if(Ne(t)<0&&L(t)!==void 0)throw S(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:L(t),token:t.text,location:d(t)}},tt=()=>{let e=r.index,t=et(w(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=E(`QED`)?{kind:`Qed`}:$e(),a=h(e),s=Ie(v());if(s&&!Zs.has(i.kind))throw S(`Proof of a step that does not take a proof`);let c=s?rt():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(He),g({...t,body:i,head:a,proof:c},e)},nt=()=>{let e=d(v());if(w(`BY`)||w(`PROOF`)&&w(`BY`,1)){E(`PROOF`),T();let t=h(r.index-1);return{kind:`By`,isOnly:E(`ONLY`),...qe(),keyword:t,location:e}}let t=v(+!!w(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){E(`PROOF`),T();let n=h(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}E(`PROOF`);let n=[tt()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(tt());return{kind:`Steps`,level:I(),steps:n,location:e}},rt=()=>{let e=r.index;Me.push(-1);let t=Ue(nt);return Me.pop(),g(t,e)},it=e=>{let t=r.index,n=T(),i=v().kind===`Identifier`&&w(`==`,1)?O():void 0;i!==void 0&&(a.add(i),T());let o=Ue(()=>({statement:w(`ASSUME`)?Xe():N(),proof:Ie(v())?rt():void 0})),s=o.statement,c=g({name:i,statement:s,proof:o.proof,location:d(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(g({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:d(n)},t))},at=()=>{let e=r.index;return g(ot(),e)},ot=()=>{let e=T(),t=d(e),n=e.text===`AXIOM`;if(v().kind===`Identifier`&&w(`==`,1)){let e=O();return a.add(e),T(),{name:e,expression:N(),isAxiom:n,location:t}}return{name:void 0,expression:N(),isAxiom:n,location:t}},st=()=>{let e=d(D(`----`));D(`MODULE`);let t=O();D(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(l.push(n),i.push(/* @__PURE__ */ new Set),E(`EXTENDS`)&&k(()=>{let e=r.index;n.extends.push(O()),n.extendsRanges.push(h(e))});;){let a=r.index;ee.index=a;let o=v();if(o.kind===`ModuleEnd`||o.kind===`End`)return o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),l.pop(),i.pop(),n;if(o.kind===`Separator`){if(w(`MODULE`,1)){let e=st();n.modules.push(e),n.units.push({kind:`Module`,module:e}),D(`====`);continue}T()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{T();let e=F();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{T();let e=k(()=>{let e=r.index,t=d(v());return g({name:O(),arity:0,location:t},e)});n.variables.push(...e),n.units.push({kind:`Variables`,declarations:e});continue}case`ASSUME`:case`ASSUMPTION`:case`AXIOM`:{let e=at();n.assumptions.push(e),n.units.push({kind:`Assumption`,assumption:e}),e.name!==void 0&&n.definitions.push({kind:`Operator`,name:e.name,params:[],body:e.expression,isLocal:!1,isRecursive:!1,location:e.location});continue}case`USE`:case`HIDE`:{let e=Je();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:T(),n.units.push({kind:`Recursive`,declarations:ke()});continue;case`INSTANCE`:ct(n,g(De(void 0,[],!1,d(o)),a));continue;case`LOCAL`:if(T(),w(`INSTANCE`)){ct(n,g(De(void 0,[],!0,d(o)),a));continue}ct(n,P(!0));continue}o.kind===`Keyword`&&Ys.has(o.text)?it(n):ct(n,P(!1))}}},ct=(e,t)=>{t.kind===`Instance`?(e.instances.push(t),e.units.push({kind:`Instance`,instance:t})):(e.definitions.push(t),e.units.push({kind:`Definition`,definition:t}))};return st()},lc=e=>cc(e,!1),uc=e=>cc(e,!0),dc=25214903917n,fc=(1n<<48n)-1n,pc=2147483647,mc=e=>{let t={value:(BigInt.asUintN(64,e)^dc)&fc},n=e=>(t.value=t.value*dc+11n&fc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^dc)&fc},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=pc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},hc=10454148508367108822n,gc=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:hc);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),_c=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e>>32n))),vc=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e))),yc=Number(BigInt.asIntN(32,hc>>32n)),bc=Number(BigInt.asIntN(32,hc));let xc=yc,Sc=bc;const Cc=e=>{let t=(e^Sc)&255;Sc=(Sc>>>8|xc<<24)^vc[t],xc=xc>>>8^_c[t]},wc=e=>{for(let t=0;t<32;t+=8)Cc(e>>>t)},Tc=e=>{if(typeof e==`boolean`)Cc(0),Cc(e?116:102);else if(typeof e==`number`)Cc(1),wc(e);else if(typeof e==`string`){Cc(3),wc(e.length);for(let t=0;t<e.length;t++)Cc(e.charCodeAt(t))}else if(M(e))Cc(21),wc(De(e.name)+1);else if(j(e)){let t=H(e);Cc(9),wc(t.domain.length);for(let e=0;e<t.domain.length;e++)Tc(t.domain[e]),Tc(t.range[e])}else{let t=B(e).elements;Cc(5),wc(t.length);for(let e of t)Tc(e)}},Ec=e=>{let t={high:xc,low:Sc};xc=yc,Sc=bc;for(let t of e)Tc(t);let n=BigInt(xc>>>0)<<32n|BigInt(Sc>>>0);return xc=t.high,Sc=t.low,n},Dc=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||M(e))return 5;if(typeof e==`string`)return 5+e.length;if(j(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+Dc(n)+Dc(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+Dc(t),5)},Oc=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){xc=n<32?0:1<<n-32,Sc=n<32?1<<n:0;for(let t=0;t<e;t++)Cc(0);let r=n>>3,i=1<<(n&7);for(let e=i;e<2*i;e++){let n=(r*256+e)*2,a=(r*256+e-i)*2;t[n]=t[a]^xc,t[n+1]=t[a+1]^Sc}}return t},kc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=[],r=e=>{let r=t.get(e);if(r!==void 0)return r;let i=Dc(e);return xc=0,Sc=0,Tc(e),t.set(e,n.length),n.push(i,xc,Sc),n.length-3},i=t=>{let n=e.get(t);if(n)return n;let r=Oc(t);return e.set(t,r),r};return e=>{let t={high:xc,low:Sc},a={high:yc,low:bc};for(let t of e){let e=r(t),o=i(n[e]),s={high:n[e+1],low:n[e+2]};for(let e=0;e<8;e++){let t=e<4?a.low:a.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=o[n],s.low^=o[n+1]}a.high=s.high,a.low=s.low}return xc=t.high,Sc=t.low,BigInt(a.high>>>0)<<32n|BigInt(a.low>>>0)}},Ac=[],jc=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Mc=()=>{for(let e=1277011;Ac.length<1341;e++)jc(e)&&Ac.push(e);return Ac},Nc=e=>{let t=Mc(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Pc=e=>{let t=[],n={value:e};for(let e=2;e*e<=n.value;e++)for(;n.value%e===0;)t.push(e),n.value/=e;return n.value>1&&t.push(n.value),t},Fc=e=>{for(let t=Math.max(e,9);;t++){let e=Pc(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Ic=(e,t,n)=>{if(t<=0)return[];let r=Fc(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Nc(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Lc=(1n<<63n)-1n-24n,Rc=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Lc*BigInt(n)+i)%t;return r<0n?r+t:r})},zc=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Bc=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Tt(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>L(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>Dt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Vc=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ic(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=Bc(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(pc)?Rc(e,t,n):Ic(e,Number(t),n)).map(e=>r.create(zc(r.lists,e)))}let i=B(t).elements;return Ic(e,i.length,n).map(e=>i[Number(e)])},Hc=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new u(`RandomElement of the empty set`);return n},Uc=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Tt(e.domain)];return L(n,n.map(()=>Uc(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Dt(e.names.map((n,r)=>[n,Uc(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Uc(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.floor(t.nextDouble()*n);if(r>=n)throw new u(`RandomElement of the empty set`);return e.low+r}return Hc(B(e).elements,t)},Wc=(e,t=0n)=>{let n=mc(t),r={random:mc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Dt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Ec,getRandom:()=>{let e=i.isStartup?void 0:a.getCurrentState();return e===void 0?n:(e!==r.state&&(r.random.setSeed(a.getFingerprint(e)^BigInt.asUintN(64,t)),r.state=e),r.random)},evaluateAtStartup:e=>{let t=i.isStartup;i.isStartup=!0;try{return e()}finally{i.isStartup=t}},pause:()=>{},seed:t,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,isStopped:!1,checkDeadlock:e,startedAt:Date.now()};return a},Gc=e=>_t([...e.possibleCounts].map(([e,t])=>[e,t])),Kc=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Gc(e)]]),qc=(e,t,n)=>new d(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Jc=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Yc=e=>j(e)?H(e):void 0,Xc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw qc(n,`a function with a finite domain`,r);return i},Zc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw Jc(t===0?`first`:`second`,n,`bag`,r);return i},Qc=(e,t)=>{if(!A(e)||!z(e))throw t();return B(e).elements},$c=e=>e.range.every(e=>typeof e==`number`&&e>0),el=(e,t)=>{let n=e.domain.findIndex(e=>Ie(e,t));return n===-1?void 0:e.range[n]},tl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,nl=tl(`BagDiff`,`tlc2.value.impl.Value`,2),rl=tl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),il=tl(`BagUnion`,`tlc2.value.impl.Value`,1),al=tl(`BagOfAll`,`tlc2.value.impl.Value`,2),ol=tl(`BagCup`,`tlc2.value.impl.Value`,2),sl=tl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),cl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${$n(e)}`;throw tr(t,`class ${n} cannot be cast to class tlc2.value.impl.IntValue (${n} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`)},ll=(e,t,n)=>{let r=cl(e,n)+cl(t,n);if(Jn(r))throw Yn(`${e}+${t}`);return r},ul=(e,t,n,r)=>{let i=el(n,e.domain[t]),a=cl(e.range[t],r);return i===void 0?a:a-cl(i,r)|0},dl=(e,t)=>_t(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>Ie(e[0],r));a?a[1]=ll(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),fl=L([],[]),pl=[Wn(`EmptyBag`,fl),K(`IsABag`,1,e=>{let t=Yc(G(e,0,`IsABag`));return t!==void 0&&$c(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Xc(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw qc(`BagCardinality`,`a bag`,t);return ll(e,n,sl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=el(Xc(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Jc(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=el(Xc(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Jc(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Zc(e,t,`(+)`);if(!$c(n))throw Jc(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return dl(t,ol)}),K(`\\ominus`,2,e=>{let t=Zc(e,0,`(-)`),n=Zc(e,1,`(-)`);return _t(t.domain.flatMap((e,r)=>{let i=ul(t,r,n,nl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Qc(t,()=>qc(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??fl;let r=n.map(e=>{let n=Yc(e);if(!n)throw new d(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return dl(r,il)}),K(`\\sqsubseteq`,2,e=>{let t=Xc(e,0,`\\sqsubseteq`),n=Xc(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>ul(t,r,n,rl)<=0)}),Gn(`BagOfAll`,2,e=>{let t=Un(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new d(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Yc(n);if(!r)throw Jc(`second`,`BagOfAll`,`function with a finite domain`,n);return dl(r.domain.map((e,n)=>L([t.call([e])],[r.range[n]])),al)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!j(t))throw new u(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=dt(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new u(`The ${e?`first`:`second`} argument of >= should be an integer, but instead it is:\n${U(e?r[0]:i)}`)}let a=n.range.filter(e=>typeof e==`number`);if(a.some(e=>e<1))throw new u(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return dt(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>L(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>nn(Xc(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Qc(t,()=>qc(`BagToSet`,`a function with a finite domain`,t));return L([...n],n.map(()=>1))})],ml=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,hl=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,gl=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,_l=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,vl=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,yl=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,bl=e=>{if(!j(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},xl=(e,t)=>tr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${$n(t)}`),Sl=(e,t)=>tr(e,`Cannot cast tlc2.value.impl.${$n(t)} to tlc2.value.impl.StringValue`),Cl=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),wl=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw xl(t,e);return`[${B(e).elements.map(e=>El(e,t)).join(`,`)}]`},Tl=(e,t)=>{let n=H(e),r=Gt(n);return r?`[${r.map(e=>El(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${Cl(typeof e==`string`?e:U(e))}:${El(n.range[r],t)}`).join(`,`)}}`},El=(e,t)=>typeof e==`string`?Cl(e):typeof e==`object`?e.kind===`ModelValue`?Cl(e.name):A(e)?wl(e,t):Tl(e,t):String(e),Dl=e=>{if(A(e))return wl(e,ml);if(!j(e)||bl(e))throw xl(ml,e);return Tl(e,ml)},Ol=e=>{if(!j(e))throw xl(hl,e);return Tl(e,hl)},kl=e=>{let[,t,n=`0`,r=``,i=`0`]=/^(-?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(e)??[],a=BigInt(n+r),o=Number(i)-r.length,s=o>=0?a*10n**BigInt(o):a/10n**BigInt(-o);return Number(BigInt.asIntN(32,t===`-`?-s:s))},Al=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return P(e);if(Array.isArray(e))return R(e.map(e=>Al(e,t)));if(typeof e==`object`&&e)return Dt(Object.entries(e).map(([e,n])=>[P(e),Al(n,t)]));throw tr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},jl=(e,t)=>{if(e.trim()===``)return Al(null,t);try{return Al(JSON.parse(e,(e,t,n)=>typeof t==`number`?kl(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?tr(t,e.message):e}},Ml=(e,t)=>{if(typeof e!=`string`)throw Sl(t,e);return e},Nl=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw tr(n,`${t} (No such file or directory)`);return r},Pl=e=>[Kn(`ToJson`,1,e=>P(El(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Kn(`ToJsonArray`,1,e=>P(Dl(G(e,0,`ToJsonArray`)))),Kn(`ToJsonObject`,1,e=>P(Ol(G(e,0,`ToJsonObject`)))),Kn(`JsonSerialize`,2,t=>{let n=Ml(G(t,0,`JsonSerialize`),gl),r=G(t,1,`JsonSerialize`);if(!Gt(r)&&!bl(r))throw new d(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,El(r,gl)),!0}),Kn(`ndJsonSerialize`,2,t=>{let n=Ml(G(t,0,`ndJsonSerialize`),_l),r=G(t,1,`ndJsonSerialize`),i=Gt(r);if(!i)throw new d(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${El(e,_l)}\n`).join(``)),!0}),Kn(`JsonDeserialize`,1,t=>{let n=Ml(G(t,0,`JsonDeserialize`),vl);return jl(Nl(e,n,vl),vl)}),Kn(`ndJsonDeserialize`,1,t=>{let n=Ml(G(t,0,`ndJsonDeserialize`),yl);return R(Nl(e,n,yl).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>jl(e,yl)))})],Fl=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Il=(e,t,n)=>{if(typeof e!=`number`||e<0)throw Fl(t,n,`nonnegative integer`,U(e));return e},Ll=(e,t,n,r)=>{if(!A(e)||!z(e))throw Fl(t,n,r,U(e));return B(e).elements},Rl=(e,t,n,r)=>dt(Array.from({length:t},()=>dt(e.filter(()=>r.nextDouble()<n)))),zl=(e,t)=>{let n=`RandomSetOfSubsets`,r=Il(G(e,0,n),`first`,n),i=Il(G(e,1,n),`second`,n),a=Ll(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw Fl(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw Fl(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Rl(a,r,a.length===0?0:i/a.length,t.getRandom())},Bl=e=>[Kn(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw Fl(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new u(`Attempted to apply the operator overridden by the Java method\npublic static tlc2.value.impl.Value tlc2.module.Randomization.RandomSubset(tlc2.value.impl.Value,tlc2.value.impl.Value),\nbut it produced the following error:\n${n}`);let r=G(t,1,`RandomSubset`);if(!A(r)||!V(r)&&!z(r))throw Fl(`second`,`RandomSubset`,`a finite set`,U(r));return dt(Vc(n,r,e.getRandom()))}),Kn(`RandomSetOfSubsets`,3,t=>zl(t,e)),Kn(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(zl(t,e)).elements.length)))],Vl=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Hl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Vl})`,Ul=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Vl}) throws java.io.IOException`,Wl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Vl})`,Gl=()=>Dt([[`action`,dt([])],[`state`,dt([])]]),Kl=()=>Dt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ql=e=>Dt([[`name`,e??`UnnamedAction`],[`location`,Kl()]]),Jl=(e,t)=>{let n=e.map((e,t)=>R([t+1,Dt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ql(e[r+1].action),t])),i=t?[R([n[n.length-1],ql(t.action),n[t.start]])]:[];return Dt([[`action`,dt([...r,...i])],[`state`,dt(n)]])},Yl=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Kc(e).get(t)},Xl=(e,t,n,r)=>{if(typeof n==`number`&&n>=0)e.registers.set(n,r);else if(n===`exit`)r===!0&&(e.isStopped=!0);else if(n===`pause`){if(r!==!0)return;t(`Press enter to resume model checking.`),e.pause()}else if(typeof n==`string`&&n.startsWith(`s:`))e.namedRegisters.set(n,r);else if(typeof n==`string`&&n.startsWith(`-D`))e.properties.set(n.slice(2),U(r));else throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(n)}`)},Zl=e=>e.every(e=>e!==void 0),Ql=(e,t)=>Dt(t.variables.map((t,n)=>[t,e[n]])),$l=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(e.kind===`Prime`||e.kind===`Unchanged`)return!0;if(r!==void 0&&!W(e)){if(t.variableIndex.has(r))return!0;let e=qa(r,t);if(e&&!n.has(e)&&(n.add(e),$l(e.body,t,n)))return!0}return jn(e).some(e=>$l(e,t,n))},eu=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new WeakMap,i=e=>{let t=r.get(e)??/* @__PURE__ */ new Map;return r.set(e,t),t};return[K(`AssertEq`,2,t=>{let n=G(t,0,`AssertEq`),r=G(t,1,`AssertEq`),i=Ie(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),cr(`AssertError`,2,e=>{let t=Un(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw tr(Hl,`In computing AssertError, a non-string expression (line ${t.location.line}, col ${t.location.column}) was used as the err of an AssertError(err, exp).`);let n=lr(e,0,`AssertError`)();try{lr(e,1,`AssertError`)()}catch(e){if(e instanceof u)return e.message===n;throw e}return!1}),Kn(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Yl(t,n)??G(e,1,`TLCGetOrDefault`)}),{...Gn(`TLCGetAndSet`,4,n=>{let r=G(n,0,`TLCGetAndSet`),i=Yl(t,r)??G(n,3,`TLCGetAndSet`),a=Un(n,1,`TLCGetAndSet`);return Xl(t,e,r,a.call([i,G(n,2,`TLCGetAndSet`)])),i}),isStateLevel:!0},Kn(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Zl(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw tr(Ul,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return R(t.getBehavior(r).map(e=>Ql(e,n.environment)))}),Kn(`CounterExample`,0,()=>t.counterExample??Gl()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!j(t)||!Ie(nn(t),dt([`action`,`state`])))throw new u(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(en(t,`state`)).elements.map(e=>Gt(e)??[]);return R(n.sort((e,t)=>Number(e[0])-Number(t[0])).map(e=>e[1]))}),K(`TLCModelValue`,1,e=>{let t=G(e,0,`TLCModelValue`);if(typeof t!=`string`)throw new d(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Pe(t)}),cr(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),cr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Zl(r))throw tr(Wl,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Ka(lr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new m(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),cr(`TLCCache`,2,(e,t)=>{let r=Un(e,0,`TLCCache`),a=xn(lr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=$l(o,t.environment,/* @__PURE__ */ new Set)&&t.state?i(t.state):n,c=s.get(o)??/* @__PURE__ */ new Map;s.set(o,c);let l=c.get(a);if(l!==void 0)return l;let u=r.call([]);return c.set(a,u),u}),K(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Ec([G(e,0,`TLCFP`)])))),Kn(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?qa(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new d(`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${U(n)}`);if(r.kind===`Operator`&&r.params.length>0)throw new d(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return X({kind:`Identifier`,name:n,location:r.location},t)})]},tu=(e,t)=>[Kn(`_Track`,2,e=>{let n=String(G(e,1,`_Track`)),r=t.possibleCounts.get(n)??0;return t.possibleCounts.set(n,G(e,0,`_Track`)===!0?r+1:r),!0}),Kn(`_Counts`,0,()=>Gc(t)),Kn(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(Gc(t),!0)),!1)}),Kn(`_PrintCounts`,0,()=>(e(U(Gc(t),!0)),!0))],nu=e=>String(e).padStart(2,`0`),ru=e=>`${e.getUTCFullYear()}.${nu(e.getUTCMonth()+1)}.${nu(e.getUTCDate())}.${nu(e.getUTCHours())}${nu(e.getUTCMinutes())}${nu(e.getUTCSeconds())}`,iu=e=>_t([...e].map(([e,t])=>[e,R([t])])),au=(e,t,n)=>{let r=Math.floor((Date.now()-e.startedAt)/1e3);switch(t){case`level`:return n===void 0?0:e.getLevel(n);case`diameter`:return e.diameter;case`generated`:return e.generatedStates;case`distinct`:return e.distinctStates;case`queue`:return e.queueSize;case`duration`:return r;case`stats`:return Dt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Dt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Dt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,P(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,P(ru(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ql(void 0);case`all`:return iu(e.registers);case`all:named`:return iu(Kc(e))}if(t.startsWith(`s:`)){let n=Kc(e).get(t);if(n===void 0)throw new d(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return P(e.properties.get(t.slice(2))??t);throw new d(`TLCGet(${t}) was undefined.`)},ou=e=>e.length===0?[[]]:e.flatMap((t,n)=>ou([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),su=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(su),e.kind===`Function`&&e.range.forEach(su))},cu=(t,n)=>[K(`Print`,2,e=>(t(`${de(U(G(e,0,`Print`),!0,!0))} ${de(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(de(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new d(`The first argument of Assert evaluated to FALSE; the second argument was:\n${de(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>_t([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=Hn(e,0,`@@`),n=Hn(e,1,`@@`);return vt([...ge(t),...ge(n)])}),K(`ToString`,1,e=>P(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return su(t),t}),K(`Permutations`,1,e=>{let t=Bn(e,0,`Permutations`);return dt(ou(t).map(e=>_t(t.map((t,n)=>[t,e[n]]))))}),Gn(`SortSeq`,2,e=>{let t=Un(e,1,`SortSeq`);return R(Vn(e,0,`SortSeq`).reduce((e,n)=>{let r=e.findIndex(e=>t.call([n,e])===!0);return r===-1?[...e,n]:[...e.slice(0,r),n,...e.slice(r)]},[]))}),Kn(`TLCGet`,1,(e,t)=>{let r=G(e,0,`TLCGet`);if(typeof r==`number`&&r>=0){let e=n.registers.get(r);if(e===void 0)throw new d(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new d(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return au(n,r,t?.state)}),Kn(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`);return Xl(n,t,r,G(e,1,`TLCSet`)),!0}),Wn(`Any`,je),K(`RandomElement`,1,e=>Uc(Rn(e,0,`RandomElement`),n.getRandom()))],lu=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices`.split(`,`),uu=[[`\\lnot`,`~`,`\\neg`,`¬`],[`[]`,`□`],[`<>`,`◇`],[`\\land`,`/\\`,`∧`],[`\\lor`,`\\/`,`∨`],[`\\equiv`,`<=>`,`≡`,`⇔`],[`/=`,`#`,`≠`],[`\\leq`,`<=`,`=<`,`≤`],[`\\geq`,`>=`,`≥`],[`\\times`,`\\X`,`×`],[`\\intersect`,`\\cap`,`∩`],[`\\union`,`\\cup`,`∪`],[`\\o`,`\\circ`,`∘`],[`\\oplus`,`(+)`,`⊕`],[`\\ominus`,`(-)`,`⊖`],[`\\odot`,`(.)`,`⊙`],[`\\oslash`,`(/)`,`⊘`],[`\\otimes`,`(\\X)`,`⊗`],[`\\approx`,`≈`],[`:=`,`≔`],[`\\asymp`,`≍`],[`\\bigcirc`,`◯`],[`::=`,`⩴`],[`\\bullet`,`●`],[`\\cdot`,`⋅`],[`\\cong`,`≅`],[`\\div`,`÷`],[`\\doteq`,`≐`],[`..`,`‥`],[`...`,`…`],[`!!`,`‼`],[`\\gg`,`≫`],[`=>`,`⇒`],[`\\in`,`∈`],[`=|`,`⫤`],[`~>`,`↝`],[`\\ll`,`≪`],[`-|`,`⊣`],[`\\notin`,`∉`],[`-+->`,`⇸`],[`\\prec`,`≺`],[`\\preceq`,`⪯`],[`\\propto`,`∝`],[`??`,`⁇`],[`|=`,`⊨`],[`|-`,`⊢`],[`\\sim`,`∼`],[`\\simeq`,`≃`],[`\\sqcap`,`⊓`],[`\\sqcup`,`⊔`],[`\\sqsubset`,`⊏`],[`\\sqsubseteq`,`⊑`],[`\\sqsupset`,`⊐`],[`\\sqsupseteq`,`⊒`],[`\\star`,`⋆`],[`\\subset`,`⊂`],[`\\subseteq`,`⊆`],[`\\succ`,`≻`],[`\\succeq`,`⪰`],[`\\supset`,`⊃`],[`\\supseteq`,`⊇`],[`\\uplus`,`⊎`],[`||`,`‖`],[`\\wr`,`≀`],[`^+`,`⁺`]],du=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices,***I do not exist***,--TLA+ BUILTINS--,Formal_0,Formal_1,Formal_2,[,^,/,*,-,-.,+,^+,^*,^#,<,\\leq,>,\\geq,...,..,|,||,&&,&,$$,$,??,%%,%,##,++,--,**,//,^^,@@,!!,|-,|=,-|,=|,<:,:>,:=,::=,\\oplus,\\ominus,\\odot,\\oslash,\\otimes,\\uplus,\\sqcap,\\sqcup,\\div,\\wr,\\star,\\o,\\bigcirc,\\bullet,\\prec,\\succ,\\preceq,\\succeq,\\sim,\\simeq,\\ll,\\gg,\\asymp,\\subset,\\supset,\\supseteq,\\approx,\\cong,\\sqsubset,\\sqsubseteq,\\sqsupset,\\sqsupseteq,\\doteq,\\propto,~,¬,□,◇,/\\,∧,\\/,∨,<=>,≡,⇔,#,≠,<=,=<,≤,>=,≥,\\X,×,\\cap,∩,\\cup,∪,\\circ,∘,(+),⊕,(-),⊖,(.),⊙,(/),⊘,(\\X),⊗,≈,≔,≍,◯,⩴,●,⋅,≅,÷,≐,‥,…,‼,≫,⇒,∈,⫤,↝,≪,⊣,∉,⇸,≺,⪯,∝,⁇,⊨,⊢,∼,≃,⊓,⊔,⊏,⊑,⊐,⊒,⋆,⊂,⊆,≻,⪰,⊃,⊇,⊎,‖,≀,⁺,@`.split(`,`),fu=/* @__PURE__ */ `exit.pause.config.spec.coverage.action.install.id.behavior.all.mode.deadlock.seed.fingerprint.worker.traces.depth.aril.sched.revision.timestamp.date.count.tag.calver.impliedinits.impliedactions.invariants.impliedtemporals.temporals.actions.inits.variables.actionconstraints.constraints.stats.duration.generated.diameter.distinct.initial.queue.retries.distinctvalues.levelmean.levelvariance.bfs`.split(`.`),pu=/* @__PURE__ */ `Not a node.N_ActDecl.N_ActionExpr.N_AssumeDecl.N_AssumeProve.N_Assumption.N_BeginModule.N_Body.N_BoundedQuant.N_Case.N_CaseArm.N_CaseStatement.N_ChooseStatement.N_ConjItem.N_ConjList.N_ConsDecl.N_DisjItem.N_DisjList.N_EndModule.N_Except.N_ExceptComponent.N_ExceptSpec.N_Times.N_Extends.N_FairnessExpr.N_FcnAppl.N_FcnConst.N_FieldSet.N_FieldVal.N_FunctionDefinition.N_FunctionParam.N_GeneralId.N_GenInfixOp.N_GenNonExpPrefixOp.N_GenPostfixOp.N_GenPrefixOp.N_IdentDecl.N_Real.N_IdentifierTuple.N_IdentLHS.N_IdPrefix.N_IdPrefixElement.N_IfThenElse.N_InfixDecl.N_InfixExpr.N_InfixLHS.N_InfixOp.N_InnerProof.N_Instance.N_NonLocalInstance.N_Integer.N_LeafProof.N_LetDefinitions.N_LetIn.N_MaybeBound.N_Module.N_ModuleDefinition.N_NonExpPrefixOp.N_Number.N_NumberedAssumeProve.N_OpApplication.N_OpArgs.N_OperatorDefinition.N_OtherArm.N_ParamDecl.N_ParamDeclaration.N_ParenExpr.N_PostfixDecl.N_PostfixExpr.N_PostfixLHS.N_PostfixOp.N_PrefixDecl.N_PrefixExpr.N_PrefixLHS.N_PrefixOp.N_Proof.N_ProofLet.N_ProofName.N_ProofStatement.N_ProofStep.N_QEDStep.N_QuantBound.N_RcdConstructor.N_RecordComponent.N_SetEnumerate.N_SetOfAll.N_SetOfFcns.N_SetOfRcds.N_String.N_SubsetOf.N_Substitution.N_TempDecl.N_Theorem.N_Tuple.N_UnBoundedOrBoundedChoose.N_UnboundedQuant.N_VariableDeclaration.Token =.Token \\in.N_NewSymb.N_Lambda.N_Recursive.N_Label.N_StructOp.N_NumerableStep.N_TerminalProof.N_UseOrHide.N_NonExprBody.N_DefStep.N_HaveStep.N_TakeStep.N_WitnessStep.N_PickStep.N_CaseStep.N_AssertStep`.split(`.`),mu=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
|
|
93
|
+
`)},cc=(e,t)=>{let n=oe(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},l=[],u=e=>i[i.length-1].has(e),d=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),f=[],p=[],m=[],h=e=>{let t=r.index-1,i=e===t?m[e]:void 0;if(i)return i;let a=n[t];f[e]??=d(n[e]),p[t]??={line:a.line,column:a.endColumn};let o={module:l[l.length-1].name,start:f[e],end:p[t]};return e===t&&(m[e]=o),o},g=(e,t)=>(e.location.range=h(t),e),_=(e=0)=>n[Math.min(r.index+e,n.length-1)],v=(e=0)=>{let t=_(e),n=r.offsideColumns[r.offsideColumns.length-1];return n===void 0||n===-1||t.kind===`End`?t:t.column<=n?{...t,kind:`End`,text:``}:t},y=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),ee={index:0},b=e=>{let t=n.slice(ee.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},te=e=>t&&(e.kind===`Keyword`||ac.has(e.text)),re=e=>{let t=n.findLast(t=>t.kind!==`End`&&(t.line<e.line||t.line===e.line&&t.column<e.column));return t?{line:t.line,column:t.endColumn+1}:e},x=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Qs.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):te(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,S=(e,t=_(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new c(`${e} at line ${t.line}, column ${t.column}`,void 0,ie(e,t,a,r))},ie=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...b(re(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${x(a)}`,...re(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},C=(e,t=_())=>S(e,t,t),ae=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!te(e),w=(e,t=0)=>{let n=v(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},T=()=>{let e=v();if(e.kind===`End`)throw S(`Unexpected end of expression`);return r.index++,e},E=e=>w(e)?(r.index++,!0):!1,D=e=>{if(!w(e))throw C(`Expected ${JSON.stringify(e)} but found ${y(v())}`);return T()},O=()=>{let e=v();if(e.kind!==`Identifier`)throw C(`Expected an identifier but found ${y(e)}`);if(te(e))throw C(`Unexpected keyword ${e.text}`);return r.index++,e.text},se=e=>{r.offsideColumns.push(-1);let t=e();return r.offsideColumns.pop(),t},k=(e,t=`,`)=>{let n=[e()];for(;E(t);)n.push(e());return n},ce=()=>{if(w(`<<`)){let e={value:1};for(;v(e.value).kind===`Identifier`||w(`,`,e.value);)e.value++;return w(`>>`,e.value)&&w(`\\in`,e.value+1)}let e={value:0};for(;v(e.value).kind===`Identifier`;){if(w(`\\in`,e.value+1))return!0;if(!w(`,`,e.value+1))return!1;e.value+=2}return!1},le=()=>{if(w(`::`))return!0;if(!w(`(`))return!1;let e={value:1};for(;v(e.value).kind===`Identifier`&&w(`,`,e.value+1);)e.value+=2;return v(e.value).kind===`Identifier`&&w(`)`,e.value+1)&&w(`::`,e.value+2)},ue=()=>{if(!E(`<<`))return{kind:`Name`,name:O()};let e=k(O);return D(`>>`),{kind:`Tuple`,names:e}},de=()=>k(()=>{let e=k(ue);D(`\\in`);let t=N();return e.map(e=>({pattern:e,set:t}))}).flat(),A=()=>{let e=v();if(e.kind===`Identifier`){let t=r.index,n=[T().text];for(;w(`!`)&&v(1).kind===`Identifier`;)T(),n.push(O());return g({kind:`Identifier`,name:n.join(`!`),location:d(e)},t)}if(w(`<<`)||w(`(`))return Se();throw C(`Expected a subscript but found ${y(e)}`)},j=e=>{let t=v(1),n=v(2);return t.kind===`Identifier`&&n.text===`==`?!0:t.line===e.line?!1:t.text===`-.`||t.kind===`Identifier`&&(n.text===`(`||n.text===`[`||n.kind===`Operator`&&w(`==`,Bs.has(n.text)?3:4))},M=e=>{if(!Hs.has(e.text))return!0;let t=v(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||w(`,`,1)||w(`)`,1)||t.kind===`Keyword`&&Js.has(t.text)||j(e)},fe=()=>{let e=v(),n=e.kind===`Operator`&&(zs.has(e.text)||Vs.has(e.text))&&M(e);if(t&&e.kind!==`String`&&(Vs.has(e.text)||Ws.has(e.text)&&e.text!==`'`&&!Bs.has(e.text)||Us.has(e.text)&&v(-1).text===`(`&&v(-1).line===e.line&&v(-1).endColumn+1===e.column&&v(1).text===`)`&&v(1).line===e.line&&v(1).column===e.endColumn+1)&&M(e))throw S(`incomplete expression`,e);if(n)return r.index++,g({kind:`OperatorReference`,operator:e.text,location:d(e)},r.index-1);if(e.kind!==`String`&&Ws.has(e.text)&&M(e)){r.index++;let t=d(e);if(Bs.has(e.text))return{kind:`OperatorReference`,operator:e.text,location:t};let n={kind:`Identifier`,name:`argument`,location:t};return{kind:`Lambda`,params:[n.name],body:Ks(e.text,n,t),location:t}}if(w(`LAMBDA`)){let t=r.index;T();let n=k(O);D(`:`);let i=N();return g({kind:`Lambda`,params:n,body:i,location:d(e)},t)}return N()},pe=()=>se(()=>{D(`(`);let e=k(fe);return D(`)`),e}),me=()=>{let e=T();r.offsideColumns.push(e.column);let t=[N()];for(;_().text===e.text&&_().column===e.column;)r.index++,t.push(N());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:d(e)}},he=e=>se(()=>{let t=d(e);if(v().kind===`Identifier`&&(w(`|->`,1)||w(`:`,1))){let e=w(`|->`,1)?`Record`:`RecordSet`,n=k(()=>{let t=O();return D(e===`Record`?`|->`:`:`),{name:t,value:N()}});return D(`]`),{kind:e,fields:n,location:t}}if(ce()){let e=de();D(`|->`);let n=N();return D(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=N();if(E(`->`)){let e=N();return D(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(E(`EXCEPT`)){let e=k(()=>{D(`!`);let e=[];for(;w(`.`)||w(`[`);)if(E(`.`)){if(!ae(v()))throw C(`Expected a field name but found ${y(v())}`);e.push({kind:`Field`,name:T().text})}else D(`[`),e.push({kind:`Index`,args:k(()=>N())}),D(`]`);return D(`=`),{path:e,value:N()}});return D(`]`),{kind:`Except`,function:n,updates:e,location:t}}return D(`]_`),{kind:`BoxAction`,action:n,subscript:A(),location:t}}),ge=e=>se(()=>{let t=d(e);if(E(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(ce()&&(v(1).text===`\\in`||w(`<<`))){let e=r.index,n=ue();D(`\\in`);let i=N();if(E(`:`)){let e=N();return D(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=N();if(E(`:`)){let e=de();return D(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;E(`,`);)i.push(N());return D(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),_e=e=>{let t=d(e),n=se(()=>w(`>>`)||w(`>>_`)?[]:k(()=>N()));if(E(`>>_`)){if(n.length!==1)throw S(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:A(),location:t}}return D(`>>`),{kind:`Tuple`,elements:n,location:t}},ve=e=>{let t=d(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&ce()){let e=de();return D(`:`),{kind:n,bounds:e,body:N(),location:t}}let i=k(O);return D(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:N(),isTemporal:r,location:t}},ye=e=>{let t=[];do{if(E(`OTHER`))return D(`->`),{kind:`Case`,arms:t,other:N(),location:d(e)};let n=N();D(`->`),t.push({condition:n,body:N()})}while(E(`[]`));return{kind:`Case`,arms:t,other:void 0,location:d(e)}},be=()=>{let e=v(1);return w(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||qs.has(e.text)||e.kind===`Operator`&&(zs.has(e.text)||Bs.has(e.text)||Vs.has(e.text)))},xe=()=>{let e=T();if(e.kind===`Number`)return{kind:`Operand`,operand:ne(e.text)};switch(e.text){case`<<`:case`>>`:return{kind:`Operand`,operand:e.text};case`:`:return{kind:`Colon`};case`@`:return{kind:`At`};case`(`:return r.index--,{kind:`Bound`,args:pe()}}return{kind:`Name`,name:e.text,args:w(`(`)?pe():[]}},Se=()=>{let e=r.index===s.index,n=T(),a=d(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=k(O);return D(`:`),{kind:`Lambda`,params:e,body:N(),location:a}}if(n.kind===`Number`){if(t&&/^\\[BOH]/.test(n.text))throw S(`incomplete expression`,n);return{kind:`Number`,value:ne(n.text),text:n.text,location:a}}if(n.kind===`Decimal`)return{kind:`Decimal`,text:n.text,location:a};if(n.kind===`String`)return{kind:`String`,value:n.text,location:a};let o=n.kind===`Step`&&Fe(n);if(o&&I()<0&&Me.length<=1)throw S(`Step number used outside proof`,n);if(o&&n.text[1]===`+`)throw S(`<+> step number used in an expression`,n);if(n.kind===`Identifier`||o){let r=o?L(n)??n.text:n.text;if(le()){let e=E(`(`)?k(O):[];return e.length>0&&D(`)`),D(`::`),{kind:`Label`,name:r,params:e,body:N(),location:a}}let i=w(`(`),s=i?pe():[];if(!be())return i?{kind:`Apply`,operator:r,args:s,location:a}:{kind:`Identifier`,name:r,location:a};let c=l.flatMap(e=>e.instances).find(e=>e.name===r);if(c&&!e&&!t&&c.params.length!==s.length)throw S(`The operator ${r} requires ${c.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;be();)T(),u.push(xe());let d=u.flatMap(e=>e.kind===`Name`?[e.name]:[]);if(d.length<u.length)return{kind:`Subexpression`,selectors:u,location:a};let f=d.join(`!`),p=u.flatMap(e=>`args`in e?e.args:[]);if(p.length===0)return{kind:`Identifier`,name:f,location:a};let m=u.map(e=>`args`in e?e.args.length:0);return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,location:a}:{kind:`Apply`,operator:f,args:p,location:a}}if(n.kind===`Operator`&&Gs(n.text)&&w(`(`))return{kind:`Apply`,operator:n.text,args:pe(),location:a};switch(n.text){case`(`:{let e=se(()=>N());return D(`)`),e}case`[`:return he(n);case`{`:return ge(n);case`<<`:return _e(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return ve(n);case`IF`:{let e=N();D(`THEN`);let t=N();return D(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:N(),location:a}}case`CASE`:return ye(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!E(`IN`);){if(t&&w(`RECURSIVE`))throw S(`Unexpected keyword RECURSIVE`,b(_()));if(E(`RECURSIVE`)){ke();continue}let r=P(!1);r.kind===`Instance`?n.push(r):e.push(r)}i.pop();let r=N();return n.length===0?{kind:`Let`,definitions:e,body:r,location:a}:{kind:`Let`,definitions:e,instances:n,body:r,location:a}}case`CHOOSE`:{let e=ue(),t=E(`\\in`)?N():void 0;return D(`:`),{kind:`Choose`,pattern:e,set:t,body:N(),location:a}}case`WF_`:case`SF_`:{let e=A(),t=se(()=>{D(`(`);let e=N();return D(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw C(`Unexpected ${y(n)}`,n)},Ce=()=>{let e=v(),t=d(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return me();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return T(),{kind:`Apply`,operator:`~`,args:[N(5)],location:t};case`-`:return T(),{kind:`Apply`,operator:`-.`,args:[N(13)],location:t};case`[]`:return T(),{kind:`Always`,expression:N(16),location:t};case`<>`:return T(),{kind:`Eventually`,expression:N(16),location:t};case`ENABLED`:return T(),{kind:`Enabled`,expression:N(16),location:t};case`UNCHANGED`:return T(),{kind:`Unchanged`,expression:N(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return T(),{kind:`Apply`,operator:e.text,args:[N(9)],location:t}}return Se()},N=(e=0)=>{let t=r.index,n=Ce(),i={left:n.location.range?n:g(n,t),previous:void 0};for(;;){let n=v();if(n.kind!==`Operator`)break;let r=d(n);if(n.text===`'`&&e<=15){T(),i.left=g({kind:`Prime`,expression:i.left,location:r},t);continue}if(Bs.has(n.text)&&e<=15){T(),i.left=g({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){T();let e=se(()=>k(()=>N()));se(()=>D(`]`)),i.left=g({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&ae(v(1))){T();let e=T().text;i.left=g({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=zs.get(n.text);if(!a||a.low<e)break;let o=i.previous;if(o){let e=!(o.low>a.high||o.high<a.low),t=o.text===n.text&&a.isAssociative;if(e&&!t&&(o.text!==`\\X`||n.text!==`\\X`))throw S(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(T(),a.low>12&&w(`-`))throw S(`Precedence conflict between ${n.text} and -`,v());let s=N(a.high+1),c=i.left;if(n.text===`/\\`||n.text===`\\/`){let e=n.text===`/\\`?`And`:`Or`;i.left=c.kind===e&&o?.text===n.text?{...c,operands:[...c.operands,s]}:{kind:e,operands:[c,s],location:r}}else i.left=n.text===`\\X`?c.kind===`Product`&&o?.text===`\\X`?{...c,factors:[...c.factors,s]}:{kind:`Product`,factors:[c,s],location:r}:{kind:`Apply`,operator:n.text,args:[c,s],location:r};i.left=g(i.left,t),i.previous={...a,text:n.text}}return i.left},we=()=>{if(!E(`(`))return[];let e=F();return D(`)`),e},Te=()=>{let e=d(v()),t=N(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:l[l.length-1].name,start:e,end:a}}},P=e=>{let t=r.index;return g(Ee(e),t)},Ee=e=>{let t=v(),n=d(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...Te(),isLocal:e,isRecursive:u(t),location:n});if(t.kind===`Identifier`&&v(1).kind===`Operator`&&zs.has(v(1).text)&&v(2).kind===`Identifier`&&w(`==`,3)){let e=O(),t=T().text,n=O();return D(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&Bs.has(v(1).text)&&w(`==`,2);if(a||o){let e=a?t.text:v(1).text;r.index+=a?1:2;let n=a?O():t.text;return D(`==`),i(e,[{name:n,arity:0}])}let s=O();if(E(`[`)){let t=se(()=>de());return D(`]`),D(`==`),{kind:`Function`,name:s,bounds:t,body:N(),isLocal:e,isRecursive:u(s),location:n}}let c=r.index,l=we();return D(`==`),w(`INSTANCE`)?{...De(s,l,e,n),definitionRange:h(c)}:i(s,l)},De=(e,t,n,i)=>{let a=r.index;return D(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:O(),substitutions:E(`WITH`)?k(()=>{let e=T().text;return D(`<-`),{name:e,expression:fe()}}):[],isLocal:n,location:i,instanceRange:h(a)}},Oe=()=>{let e=d(v());if(w(`_`)&&v(1).kind===`Operator`)return T(),{name:T().text,arity:E(`_`)?2:1,location:e};if(v().kind===`Operator`&&w(`_`,1)){let t=T().text;return T(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=O();if(!E(`(`))return{name:t,arity:0,location:e};let n=k(()=>D(`_`));return D(`)`),{name:t,arity:n.length,location:e}},F=()=>k(Oe),ke=()=>{let e=F();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ae=e=>{let t={value:0,offset:e};do{let e=v(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&rc.has(e.text)&&t.value++,e.kind===`Operator`&&ic.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},je=()=>{let e=v(),t=v(1);return e.kind===`Identifier`?w(`(`,1)||w(`[`,1)?w(`==`,Ae(1)):t.kind===`Operator`&&Bs.has(t.text)?w(`==`,2):t.kind===`Operator`&&zs.has(t.text)?v(2).kind===`Identifier`&&w(`==`,3):w(`==`,1):w(`-.`)&&t.kind===`Identifier`&&w(`==`,2)},Me=[],I=()=>Me[Me.length-1]??-1,Ne=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),Pe=e=>{let t=e.text.slice(e.text.indexOf(`>`)+1),n={value:t.length};for(;t[n.value-1]===`.`;)n.value--;return t.slice(0,n.value)},Fe=e=>!e.text.endsWith(`.`)&&!$s.has(Pe(e)),L=e=>{let t=Pe(e);if($s.has(t))return;let n=Ne(e);if(n>=0)return`<${n}>${t}`;let r=I(),i=Me[Me.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Ie=e=>{if(e.kind===`Keyword`)return Xs.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Me.length===0;if(e.text[1]===`+`||Me.length===0)return!0;let t=I();return t>=0&&Ne(e)>t},Le=e=>{let t=Ne(e),n=Me.length-1,r=Me[n-1]??-1,i=Me[n]<0;return i&&(Me[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Me[n]===t},Re=e=>!a.has(e)&&l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),ze=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!ac.has(e.name)&&!Re(e.name):!1,Be=()=>{let e=v();return e.kind===`Step`?Fe(e):e.kind===`Keyword`?ec.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!je()},Ve=()=>{let e=r.index;s.index=e;let t=v();return t.kind===`Operator`&&!Hs.has(t.text)&&Gs(t.text)?(r.index++,g({kind:`OperatorReference`,operator:t.text,location:d(t)},e)):E(`MODULE`)?g({kind:`ModuleFact`,name:O(),location:d(t)},e):N()},He=e=>o[o.length-1]?.add(e),Ue=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},We=e=>o.some(t=>t.has(e))||l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Ge=()=>{let e=r.index,t=v(),n=k(()=>{let e=v();if((e.kind!==`Identifier`||te(e))&&e.kind!==`Operator`)throw C(`Expected a definition name but found ${y(e)}`,e);return r.index++,e.text},`!`),i=d(t);return g(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ke=()=>{if(t)return k(Ge);let e=k(Ve),n=e.find(e=>e.kind===`Identifier`&&We(e.name));if(n)throw S(`DEF clause entry should describe a defined operator`,n.location);return e},qe=()=>({facts:Be()?k(Ve):[],defs:E(`DEF`)||E(`DEFS`)?Ke():[]}),Je=()=>{let e=r.index,n=T(),i=n.text===`USE`&&E(`ONLY`),a=h(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...qe(),keyword:a,location:d(n)},s=o.kind===`Hide`&&!t?o.facts.find(e=>!ze(e)):void 0;if(s)throw S(`The only expression allowed as a fact in a HIDE is the name of a theorem, assumption, or step`,s.location);return g(o,e)},Ye=()=>{let e=r.index,t=d(v()),n=E(`NEW`),i=v().kind===`Keyword`?tc.get(v().text):void 0;if(!n&&i===void 0)throw C(`Expected a declaration but found ${y(v())}`);if(i!==void 0&&T(),i===`Variable`){let n=O();return He(n),g({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Oe();He(a.name);let o=(i??`Constant`)===`Constant`&&w(`\\in`);if(o&&a.arity>0)throw S(`declared symbol with arguments before \\in`);return o&&T(),g({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?N():void 0,location:t},e)},Xe=()=>{let e=r.index,t=d(D(`ASSUME`)),n=k(()=>w(`ASSUME`)?Ue(Xe):v().kind===`Keyword`&&nc.has(v().text)?Ye():N());return D(`PROVE`),g({kind:`AssumeProve`,assumptions:n,conclusion:N(),location:t},e)},Ze=e=>{let t={value:0};for(;v(t.value).kind===`Identifier`&&w(`,`,t.value+1);)t.value+=2;return v(t.value).kind===`Identifier`&&w(e,t.value+1)},Qe=(e,t)=>{e.forEach(He),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(He))},$e=()=>{let e=v();if(w(`USE`)||w(`HIDE`))return Je();if(w(`INSTANCE`))return g(De(void 0,[],!1,d(e)),r.index);if(w(`DEFINE`)||je()){let t=r.index;E(`DEFINE`);let n=[P(!1)];for(;je();)n.push(P(!1));let i={kind:`Define`,definitions:n,location:d(e)};return g(i,t)}if(E(`HAVE`))return{kind:`Have`,expression:N()};if(E(`TAKE`)){let e=ce(),t=e?[]:k(O),n=e?de():[];return Qe(t,n),{kind:`Take`,names:t,bounds:n}}if(E(`WITNESS`))return{kind:`Witness`,expressions:k(()=>N())};if(E(`PICK`)){let e=Ze(`:`),t=e?k(O):[],n=e?[]:de();return Qe(t,n),D(`:`),{kind:`Pick`,names:t,bounds:n,body:N()}}return E(`CASE`)?{kind:`Case`,expression:N()}:{kind:`Assert`,isSuffices:E(`SUFFICES`),statement:w(`ASSUME`)?Xe():N()}},et=e=>{let t=v();if(t.kind!==`Step`)throw C(`Expected a step number but found ${y(t)}`,t);if(!Le(t))throw S(`${e?`QED step`:`step`}'s number has bad level`,t);if(Ne(t)<0&&L(t)!==void 0)throw S(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:L(t),token:t.text,location:d(t)}},tt=()=>{let e=r.index,t=et(w(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=E(`QED`)?{kind:`Qed`}:$e(),a=h(e),s=Ie(v());if(s&&!Zs.has(i.kind))throw S(`Proof of a step that does not take a proof`);let c=s?rt():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(He),g({...t,body:i,head:a,proof:c},e)},nt=()=>{let e=d(v());if(w(`BY`)||w(`PROOF`)&&w(`BY`,1)){E(`PROOF`),T();let t=h(r.index-1);return{kind:`By`,isOnly:E(`ONLY`),...qe(),keyword:t,location:e}}let t=v(+!!w(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){E(`PROOF`),T();let n=h(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}E(`PROOF`);let n=[tt()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(tt());return{kind:`Steps`,level:I(),steps:n,location:e}},rt=()=>{let e=r.index;Me.push(-1);let t=Ue(nt);return Me.pop(),g(t,e)},it=e=>{let t=r.index,n=T(),i=v().kind===`Identifier`&&w(`==`,1)?O():void 0;i!==void 0&&(a.add(i),T());let o=Ue(()=>({statement:w(`ASSUME`)?Xe():N(),proof:Ie(v())?rt():void 0})),s=o.statement,c=g({name:i,statement:s,proof:o.proof,location:d(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(g({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:d(n)},t))},at=()=>{let e=r.index;return g(ot(),e)},ot=()=>{let e=T(),t=d(e),n=e.text===`AXIOM`;if(v().kind===`Identifier`&&w(`==`,1)){let e=O();return a.add(e),T(),{name:e,expression:N(),isAxiom:n,location:t}}return{name:void 0,expression:N(),isAxiom:n,location:t}},st=()=>{let e=d(D(`----`));D(`MODULE`);let t=O();D(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(l.push(n),i.push(/* @__PURE__ */ new Set),E(`EXTENDS`)&&k(()=>{let e=r.index;n.extends.push(O()),n.extendsRanges.push(h(e))});;){let a=r.index;ee.index=a;let o=v();if(o.kind===`ModuleEnd`||o.kind===`End`)return o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),l.pop(),i.pop(),n;if(o.kind===`Separator`){if(w(`MODULE`,1)){let e=st();n.modules.push(e),n.units.push({kind:`Module`,module:e}),D(`====`);continue}T()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{T();let e=F();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{T();let e=k(()=>{let e=r.index,t=d(v());return g({name:O(),arity:0,location:t},e)});n.variables.push(...e),n.units.push({kind:`Variables`,declarations:e});continue}case`ASSUME`:case`ASSUMPTION`:case`AXIOM`:{let e=at();n.assumptions.push(e),n.units.push({kind:`Assumption`,assumption:e}),e.name!==void 0&&n.definitions.push({kind:`Operator`,name:e.name,params:[],body:e.expression,isLocal:!1,isRecursive:!1,location:e.location});continue}case`USE`:case`HIDE`:{let e=Je();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:T(),n.units.push({kind:`Recursive`,declarations:ke()});continue;case`INSTANCE`:ct(n,g(De(void 0,[],!1,d(o)),a));continue;case`LOCAL`:if(T(),w(`INSTANCE`)){ct(n,g(De(void 0,[],!0,d(o)),a));continue}ct(n,P(!0));continue}o.kind===`Keyword`&&Ys.has(o.text)?it(n):ct(n,P(!1))}}},ct=(e,t)=>{t.kind===`Instance`?(e.instances.push(t),e.units.push({kind:`Instance`,instance:t})):(e.definitions.push(t),e.units.push({kind:`Definition`,definition:t}))};return st()},lc=e=>cc(e,!1),uc=e=>cc(e,!0),dc=25214903917n,fc=(1n<<48n)-1n,pc=2147483647,mc=e=>{let t={value:(BigInt.asUintN(64,e)^dc)&fc},n=e=>(t.value=t.value*dc+11n&fc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^dc)&fc},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=pc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},hc=10454148508367108822n,gc=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:hc);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),_c=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e>>32n))),vc=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e))),yc=Number(BigInt.asIntN(32,hc>>32n)),bc=Number(BigInt.asIntN(32,hc));let xc=yc,Sc=bc;const Cc=e=>{let t=(e^Sc)&255;Sc=(Sc>>>8|xc<<24)^vc[t],xc=xc>>>8^_c[t]},wc=e=>{for(let t=0;t<32;t+=8)Cc(e>>>t)},Tc=e=>{if(typeof e==`boolean`)Cc(0),Cc(e?116:102);else if(typeof e==`number`)Cc(1),wc(e);else if(typeof e==`string`){Cc(3),wc(e.length);for(let t=0;t<e.length;t++)Cc(e.charCodeAt(t))}else if(M(e))Cc(21),wc(De(e.name)+1);else if(j(e)){let t=H(e);Cc(9),wc(t.domain.length);for(let e=0;e<t.domain.length;e++)Tc(t.domain[e]),Tc(t.range[e])}else{let t=B(e).elements;Cc(5),wc(t.length);for(let e of t)Tc(e)}},Ec=e=>{let t={high:xc,low:Sc};xc=yc,Sc=bc;for(let t of e)Tc(t);let n=BigInt(xc>>>0)<<32n|BigInt(Sc>>>0);return xc=t.high,Sc=t.low,n},Dc=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||M(e))return 5;if(typeof e==`string`)return 5+e.length;if(j(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+Dc(n)+Dc(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+Dc(t),5)},Oc=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){xc=n<32?0:1<<n-32,Sc=n<32?1<<n:0;for(let t=0;t<e;t++)Cc(0);let r=n>>3,i=1<<(n&7);for(let e=i;e<2*i;e++){let n=(r*256+e)*2,a=(r*256+e-i)*2;t[n]=t[a]^xc,t[n+1]=t[a+1]^Sc}}return t},kc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=[],r=e=>{let r=t.get(e);if(r!==void 0)return r;let i=Dc(e);return xc=0,Sc=0,Tc(e),t.set(e,n.length),n.push(i,xc,Sc),n.length-3},i=t=>{let n=e.get(t);if(n)return n;let r=Oc(t);return e.set(t,r),r};return e=>{let t={high:xc,low:Sc},a={high:yc,low:bc};for(let t of e){let e=r(t),o=i(n[e]),s={high:n[e+1],low:n[e+2]};for(let e=0;e<8;e++){let t=e<4?a.low:a.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=o[n],s.low^=o[n+1]}a.high=s.high,a.low=s.low}return xc=t.high,Sc=t.low,BigInt(a.high>>>0)<<32n|BigInt(a.low>>>0)}},Ac=[],jc=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Mc=()=>{for(let e=1277011;Ac.length<1341;e++)jc(e)&&Ac.push(e);return Ac},Nc=e=>{let t=Mc(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Pc=e=>{let t=[],n={value:e};for(let e=2;e*e<=n.value;e++)for(;n.value%e===0;)t.push(e),n.value/=e;return n.value>1&&t.push(n.value),t},Fc=e=>{for(let t=Math.max(e,9);;t++){let e=Pc(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Ic=(e,t,n)=>{if(t<=0)return[];let r=Fc(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Nc(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Lc=(1n<<63n)-1n-24n,Rc=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Lc*BigInt(n)+i)%t;return r<0n?r+t:r})},zc=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Bc=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Tt(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>L(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>Dt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Vc=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ic(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=Bc(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(pc)?Rc(e,t,n):Ic(e,Number(t),n)).map(e=>r.create(zc(r.lists,e)))}let i=B(t).elements;return Ic(e,i.length,n).map(e=>i[Number(e)])},Hc=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new u(`RandomElement of the empty set`);return n},Uc=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Tt(e.domain)];return L(n,n.map(()=>Uc(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Dt(e.names.map((n,r)=>[n,Uc(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Uc(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.floor(t.nextDouble()*n);if(r>=n)throw new u(`RandomElement of the empty set`);return e.low+r}return Hc(B(e).elements,t)},Wc=(e,t=0n)=>{let n=mc(t),r={random:mc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Dt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Ec,getRandom:()=>{let e=i.isStartup?void 0:a.getCurrentState();return e===void 0?n:(e!==r.state&&(r.random.setSeed(a.getFingerprint(e)^BigInt.asUintN(64,t)),r.state=e),r.random)},evaluateAtStartup:e=>{let t=i.isStartup;i.isStartup=!0;try{return e()}finally{i.isStartup=t}},pause:()=>{},seed:t,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,isStopped:!1,checkDeadlock:e,startedAt:Date.now()};return a},Gc=e=>_t([...e.possibleCounts].map(([e,t])=>[e,t])),Kc=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Gc(e)]]),qc=(e,t,n)=>new d(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Jc=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Yc=e=>j(e)?H(e):void 0,Xc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw qc(n,`a function with a finite domain`,r);return i},Zc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw Jc(t===0?`first`:`second`,n,`bag`,r);return i},Qc=(e,t)=>{if(!A(e)||!z(e))throw t();return B(e).elements},$c=e=>e.range.every(e=>typeof e==`number`&&e>0),el=(e,t)=>{let n=e.domain.findIndex(e=>Ie(e,t));return n===-1?void 0:e.range[n]},tl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,nl=tl(`BagDiff`,`tlc2.value.impl.Value`,2),rl=tl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),il=tl(`BagUnion`,`tlc2.value.impl.Value`,1),al=tl(`BagOfAll`,`tlc2.value.impl.Value`,2),ol=tl(`BagCup`,`tlc2.value.impl.Value`,2),sl=tl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),cl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${$n(e)}`;throw tr(t,`class ${n} cannot be cast to class tlc2.value.impl.IntValue (${n} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`)},ll=(e,t,n)=>{let r=cl(e,n)+cl(t,n);if(Jn(r))throw Yn(`${e}+${t}`);return r},ul=(e,t,n,r)=>{let i=el(n,e.domain[t]),a=cl(e.range[t],r);return i===void 0?a:a-cl(i,r)|0},dl=(e,t)=>_t(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>Ie(e[0],r));a?a[1]=ll(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),fl=L([],[]),pl=[Wn(`EmptyBag`,fl),K(`IsABag`,1,e=>{let t=Yc(G(e,0,`IsABag`));return t!==void 0&&$c(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Xc(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw qc(`BagCardinality`,`a bag`,t);return ll(e,n,sl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=el(Xc(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Jc(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=el(Xc(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Jc(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Zc(e,t,`(+)`);if(!$c(n))throw Jc(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return dl(t,ol)}),K(`\\ominus`,2,e=>{let t=Zc(e,0,`(-)`),n=Zc(e,1,`(-)`);return _t(t.domain.flatMap((e,r)=>{let i=ul(t,r,n,nl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Qc(t,()=>qc(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??fl;let r=n.map(e=>{let n=Yc(e);if(!n)throw new d(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return dl(r,il)}),K(`\\sqsubseteq`,2,e=>{let t=Xc(e,0,`\\sqsubseteq`),n=Xc(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>ul(t,r,n,rl)<=0)}),Gn(`BagOfAll`,2,e=>{let t=Un(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new d(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Yc(n);if(!r)throw Jc(`second`,`BagOfAll`,`function with a finite domain`,n);return dl(r.domain.map((e,n)=>L([t.call([e])],[r.range[n]])),al)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!j(t))throw new u(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=dt(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new u(`The ${e?`first`:`second`} argument of >= should be an integer, but instead it is:\n${U(e?r[0]:i)}`)}let a=n.range.filter(e=>typeof e==`number`);if(a.some(e=>e<1))throw new u(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return dt(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>L(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>nn(Xc(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Qc(t,()=>qc(`BagToSet`,`a function with a finite domain`,t));return L([...n],n.map(()=>1))})],ml=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,hl=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,gl=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,_l=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,vl=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,yl=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,bl=e=>{if(!j(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},xl=(e,t)=>tr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${$n(t)}`),Sl=(e,t)=>tr(e,`Cannot cast tlc2.value.impl.${$n(t)} to tlc2.value.impl.StringValue`),Cl=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),wl=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw xl(t,e);return`[${B(e).elements.map(e=>El(e,t)).join(`,`)}]`},Tl=(e,t)=>{let n=H(e),r=Gt(n);return r?`[${r.map(e=>El(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${Cl(typeof e==`string`?e:U(e))}:${El(n.range[r],t)}`).join(`,`)}}`},El=(e,t)=>typeof e==`string`?Cl(e):typeof e==`object`?e.kind===`ModelValue`?Cl(e.name):A(e)?wl(e,t):Tl(e,t):String(e),Dl=e=>{if(A(e))return wl(e,ml);if(!j(e)||bl(e))throw xl(ml,e);return Tl(e,ml)},Ol=e=>{if(!j(e))throw xl(hl,e);return Tl(e,hl)},kl=e=>{let[,t,n=`0`,r=``,i=`0`]=/^(-?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(e)??[],a=BigInt(n+r),o=Number(i)-r.length,s=o>=0?a*10n**BigInt(o):a/10n**BigInt(-o);return Number(BigInt.asIntN(32,t===`-`?-s:s))},Al=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return P(e);if(Array.isArray(e))return R(e.map(e=>Al(e,t)));if(typeof e==`object`&&e)return Dt(Object.entries(e).map(([e,n])=>[P(e),Al(n,t)]));throw tr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},jl=(e,t)=>{if(e.trim()===``)return Al(null,t);try{return Al(JSON.parse(e,(e,t,n)=>typeof t==`number`?kl(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?tr(t,e.message):e}},Ml=(e,t)=>{if(typeof e!=`string`)throw Sl(t,e);return e},Nl=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw tr(n,`${t} (No such file or directory)`);return r},Pl=e=>[Kn(`ToJson`,1,e=>P(El(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Kn(`ToJsonArray`,1,e=>P(Dl(G(e,0,`ToJsonArray`)))),Kn(`ToJsonObject`,1,e=>P(Ol(G(e,0,`ToJsonObject`)))),Kn(`JsonSerialize`,2,t=>{let n=Ml(G(t,0,`JsonSerialize`),gl),r=G(t,1,`JsonSerialize`);if(!Gt(r)&&!bl(r))throw new d(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,El(r,gl)),!0}),Kn(`ndJsonSerialize`,2,t=>{let n=Ml(G(t,0,`ndJsonSerialize`),_l),r=G(t,1,`ndJsonSerialize`),i=Gt(r);if(!i)throw new d(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${El(e,_l)}\n`).join(``)),!0}),Kn(`JsonDeserialize`,1,t=>{let n=Ml(G(t,0,`JsonDeserialize`),vl);return jl(Nl(e,n,vl),vl)}),Kn(`ndJsonDeserialize`,1,t=>{let n=Ml(G(t,0,`ndJsonDeserialize`),yl);return R(Nl(e,n,yl).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>jl(e,yl)))})],Fl=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Il=(e,t,n)=>{if(typeof e!=`number`||e<0)throw Fl(t,n,`nonnegative integer`,U(e));return e},Ll=(e,t,n,r)=>{if(!A(e)||!z(e))throw Fl(t,n,r,U(e));return B(e).elements},Rl=(e,t,n,r)=>dt(Array.from({length:t},()=>dt(e.filter(()=>r.nextDouble()<n)))),zl=(e,t)=>{let n=`RandomSetOfSubsets`,r=Il(G(e,0,n),`first`,n),i=Il(G(e,1,n),`second`,n),a=Ll(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw Fl(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw Fl(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Rl(a,r,a.length===0?0:i/a.length,t.getRandom())},Bl=e=>[Kn(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw Fl(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new u(`Attempted to apply the operator overridden by the Java method\npublic static tlc2.value.impl.Value tlc2.module.Randomization.RandomSubset(tlc2.value.impl.Value,tlc2.value.impl.Value),\nbut it produced the following error:\n${n}`);let r=G(t,1,`RandomSubset`);if(!A(r)||!V(r)&&!z(r))throw Fl(`second`,`RandomSubset`,`a finite set`,U(r));return dt(Vc(n,r,e.getRandom()))}),Kn(`RandomSetOfSubsets`,3,t=>zl(t,e)),Kn(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(zl(t,e)).elements.length)))],Vl=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Hl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Vl})`,Ul=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Vl}) throws java.io.IOException`,Wl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Vl})`,Gl=()=>Dt([[`action`,dt([])],[`state`,dt([])]]),Kl=()=>Dt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ql=e=>Dt([[`name`,e??`UnnamedAction`],[`location`,Kl()]]),Jl=(e,t)=>{let n=e.map((e,t)=>R([t+1,Dt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ql(e[r+1].action),t])),i=t?[R([n[n.length-1],ql(t.action),n[t.start]])]:[];return Dt([[`action`,dt([...r,...i])],[`state`,dt(n)]])},Yl=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Kc(e).get(t)},Xl=(e,t,n)=>{if(typeof t==`number`&&t>=0)e.registers.set(t,n);else if(typeof t==`string`&&t.startsWith(`s:`))e.namedRegisters.set(t,n);else throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(t)}`)},Zl=e=>e.every(e=>e!==void 0),Ql=(e,t)=>Dt(t.variables.map((t,n)=>[t,e[n]])),$l=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(e.kind===`Prime`||e.kind===`Unchanged`)return!0;if(r!==void 0&&!W(e)){if(t.variableIndex.has(r))return!0;let e=qa(r,t);if(e&&!n.has(e)&&(n.add(e),$l(e.body,t,n)))return!0}return jn(e).some(e=>$l(e,t,n))},eu=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new WeakMap,i=e=>{let t=r.get(e)??/* @__PURE__ */ new Map;return r.set(e,t),t};return[K(`AssertEq`,2,t=>{let n=G(t,0,`AssertEq`),r=G(t,1,`AssertEq`),i=Ie(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),cr(`AssertError`,2,e=>{let t=Un(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw tr(Hl,`In computing AssertError, a non-string expression (line ${t.location.line}, col ${t.location.column}) was used as the err of an AssertError(err, exp).`);let n=lr(e,0,`AssertError`)();try{lr(e,1,`AssertError`)()}catch(e){if(e instanceof u)return e.message===n;throw e}return!1}),Kn(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Yl(t,n)??G(e,1,`TLCGetOrDefault`)}),{...Gn(`TLCGetAndSet`,4,e=>{let n=G(e,0,`TLCGetAndSet`),r=Yl(t,n)??G(e,3,`TLCGetAndSet`),i=Un(e,1,`TLCGetAndSet`);return Xl(t,n,i.call([r,G(e,2,`TLCGetAndSet`)])),r}),isStateLevel:!0},Kn(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Zl(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw tr(Ul,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return R(t.getBehavior(r).map(e=>Ql(e,n.environment)))}),Kn(`CounterExample`,0,()=>t.counterExample??Gl()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!j(t)||!Ie(nn(t),dt([`action`,`state`])))throw new u(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(en(t,`state`)).elements.map(e=>Gt(e)??[]);return R(n.sort((e,t)=>Number(e[0])-Number(t[0])).map(e=>e[1]))}),K(`TLCModelValue`,1,e=>{let t=G(e,0,`TLCModelValue`);if(typeof t!=`string`)throw new d(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Pe(t)}),cr(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),cr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Zl(r))throw tr(Wl,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Ka(lr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new m(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),cr(`TLCCache`,2,(e,t)=>{let r=Un(e,0,`TLCCache`),a=xn(lr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=$l(o,t.environment,/* @__PURE__ */ new Set)&&t.state?i(t.state):n,c=s.get(o)??/* @__PURE__ */ new Map;s.set(o,c);let l=c.get(a);if(l!==void 0)return l;let u=r.call([]);return c.set(a,u),u}),K(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Ec([G(e,0,`TLCFP`)])))),Kn(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?qa(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new d(`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${U(n)}`);if(r.kind===`Operator`&&r.params.length>0)throw new d(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return X({kind:`Identifier`,name:n,location:r.location},t)})]},tu=(e,t)=>[Kn(`_Track`,2,e=>{let n=String(G(e,1,`_Track`)),r=t.possibleCounts.get(n)??0;return t.possibleCounts.set(n,G(e,0,`_Track`)===!0?r+1:r),!0}),Kn(`_Counts`,0,()=>Gc(t)),Kn(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(Gc(t),!0)),!1)}),Kn(`_PrintCounts`,0,()=>(e(U(Gc(t),!0)),!0))],nu=e=>String(e).padStart(2,`0`),ru=e=>`${e.getUTCFullYear()}.${nu(e.getUTCMonth()+1)}.${nu(e.getUTCDate())}.${nu(e.getUTCHours())}${nu(e.getUTCMinutes())}${nu(e.getUTCSeconds())}`,iu=e=>_t([...e].map(([e,t])=>[e,R([t])])),au=(e,t,n)=>{let r=Math.floor((Date.now()-e.startedAt)/1e3);switch(t){case`level`:return n===void 0?0:e.getLevel(n);case`diameter`:return e.diameter;case`generated`:return e.generatedStates;case`distinct`:return e.distinctStates;case`queue`:return e.queueSize;case`duration`:return r;case`stats`:return Dt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Dt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Dt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,P(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,P(ru(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ql(void 0);case`all`:return iu(e.registers);case`all:named`:return iu(Kc(e))}if(t.startsWith(`s:`)){let n=Kc(e).get(t);if(n===void 0)throw new d(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return P(e.properties.get(t.slice(2))??t);throw new d(`TLCGet(${t}) was undefined.`)},ou=e=>e.length===0?[[]]:e.flatMap((t,n)=>ou([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),su=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(su),e.kind===`Function`&&e.range.forEach(su))},cu=(t,n)=>[K(`Print`,2,e=>(t(`${de(U(G(e,0,`Print`),!0,!0))} ${de(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(de(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new d(`The first argument of Assert evaluated to FALSE; the second argument was:\n${de(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>_t([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=Hn(e,0,`@@`),n=Hn(e,1,`@@`);return vt([...ge(t),...ge(n)])}),K(`ToString`,1,e=>P(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return su(t),t}),K(`Permutations`,1,e=>{let t=Bn(e,0,`Permutations`);return dt(ou(t).map(e=>_t(t.map((t,n)=>[t,e[n]]))))}),Gn(`SortSeq`,2,e=>{let t=Un(e,1,`SortSeq`);return R(Vn(e,0,`SortSeq`).reduce((e,n)=>{let r=e.findIndex(e=>t.call([n,e])===!0);return r===-1?[...e,n]:[...e.slice(0,r),n,...e.slice(r)]},[]))}),Kn(`TLCGet`,1,(e,t)=>{let r=G(e,0,`TLCGet`);if(typeof r==`number`&&r>=0){let e=n.registers.get(r);if(e===void 0)throw new d(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new d(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return au(n,r,t?.state)}),Kn(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`),i=G(e,1,`TLCSet`);if(typeof r==`number`&&r>=0)return n.registers.set(r,i),!0;if(r===`exit`)return i===!0&&(n.isStopped=!0),!0;if(r===`pause`)return i===!0&&(t(`Press enter to resume model checking.`),n.pause()),!0;if(typeof r==`string`&&r.startsWith(`s:`))return n.namedRegisters.set(r,i),!0;if(typeof r==`string`&&r.startsWith(`-D`))return n.properties.set(r.slice(2),U(i)),!0;throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(r)}`)}),Wn(`Any`,je),K(`RandomElement`,1,e=>Uc(Rn(e,0,`RandomElement`),n.getRandom()))],lu=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices`.split(`,`),uu=[[`\\lnot`,`~`,`\\neg`,`¬`],[`[]`,`□`],[`<>`,`◇`],[`\\land`,`/\\`,`∧`],[`\\lor`,`\\/`,`∨`],[`\\equiv`,`<=>`,`≡`,`⇔`],[`/=`,`#`,`≠`],[`\\leq`,`<=`,`=<`,`≤`],[`\\geq`,`>=`,`≥`],[`\\times`,`\\X`,`×`],[`\\intersect`,`\\cap`,`∩`],[`\\union`,`\\cup`,`∪`],[`\\o`,`\\circ`,`∘`],[`\\oplus`,`(+)`,`⊕`],[`\\ominus`,`(-)`,`⊖`],[`\\odot`,`(.)`,`⊙`],[`\\oslash`,`(/)`,`⊘`],[`\\otimes`,`(\\X)`,`⊗`],[`\\approx`,`≈`],[`:=`,`≔`],[`\\asymp`,`≍`],[`\\bigcirc`,`◯`],[`::=`,`⩴`],[`\\bullet`,`●`],[`\\cdot`,`⋅`],[`\\cong`,`≅`],[`\\div`,`÷`],[`\\doteq`,`≐`],[`..`,`‥`],[`...`,`…`],[`!!`,`‼`],[`\\gg`,`≫`],[`=>`,`⇒`],[`\\in`,`∈`],[`=|`,`⫤`],[`~>`,`↝`],[`\\ll`,`≪`],[`-|`,`⊣`],[`\\notin`,`∉`],[`-+->`,`⇸`],[`\\prec`,`≺`],[`\\preceq`,`⪯`],[`\\propto`,`∝`],[`??`,`⁇`],[`|=`,`⊨`],[`|-`,`⊢`],[`\\sim`,`∼`],[`\\simeq`,`≃`],[`\\sqcap`,`⊓`],[`\\sqcup`,`⊔`],[`\\sqsubset`,`⊏`],[`\\sqsubseteq`,`⊑`],[`\\sqsupset`,`⊐`],[`\\sqsupseteq`,`⊒`],[`\\star`,`⋆`],[`\\subset`,`⊂`],[`\\subseteq`,`⊆`],[`\\succ`,`≻`],[`\\succeq`,`⪰`],[`\\supset`,`⊃`],[`\\supseteq`,`⊇`],[`\\uplus`,`⊎`],[`||`,`‖`],[`\\wr`,`≀`],[`^+`,`⁺`]],du=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices,***I do not exist***,--TLA+ BUILTINS--,Formal_0,Formal_1,Formal_2,[,^,/,*,-,-.,+,^+,^*,^#,<,\\leq,>,\\geq,...,..,|,||,&&,&,$$,$,??,%%,%,##,++,--,**,//,^^,@@,!!,|-,|=,-|,=|,<:,:>,:=,::=,\\oplus,\\ominus,\\odot,\\oslash,\\otimes,\\uplus,\\sqcap,\\sqcup,\\div,\\wr,\\star,\\o,\\bigcirc,\\bullet,\\prec,\\succ,\\preceq,\\succeq,\\sim,\\simeq,\\ll,\\gg,\\asymp,\\subset,\\supset,\\supseteq,\\approx,\\cong,\\sqsubset,\\sqsubseteq,\\sqsupset,\\sqsupseteq,\\doteq,\\propto,~,¬,□,◇,/\\,∧,\\/,∨,<=>,≡,⇔,#,≠,<=,=<,≤,>=,≥,\\X,×,\\cap,∩,\\cup,∪,\\circ,∘,(+),⊕,(-),⊖,(.),⊙,(/),⊘,(\\X),⊗,≈,≔,≍,◯,⩴,●,⋅,≅,÷,≐,‥,…,‼,≫,⇒,∈,⫤,↝,≪,⊣,∉,⇸,≺,⪯,∝,⁇,⊨,⊢,∼,≃,⊓,⊔,⊏,⊑,⊐,⊒,⋆,⊂,⊆,≻,⪰,⊃,⊇,⊎,‖,≀,⁺,@`.split(`,`),fu=/* @__PURE__ */ `exit.pause.config.spec.coverage.action.install.id.behavior.all.mode.deadlock.seed.fingerprint.worker.traces.depth.aril.sched.revision.timestamp.date.count.tag.calver.impliedinits.impliedactions.invariants.impliedtemporals.temporals.actions.inits.variables.actionconstraints.constraints.stats.duration.generated.diameter.distinct.initial.queue.retries.distinctvalues.levelmean.levelvariance.bfs`.split(`.`),pu=/* @__PURE__ */ `Not a node.N_ActDecl.N_ActionExpr.N_AssumeDecl.N_AssumeProve.N_Assumption.N_BeginModule.N_Body.N_BoundedQuant.N_Case.N_CaseArm.N_CaseStatement.N_ChooseStatement.N_ConjItem.N_ConjList.N_ConsDecl.N_DisjItem.N_DisjList.N_EndModule.N_Except.N_ExceptComponent.N_ExceptSpec.N_Times.N_Extends.N_FairnessExpr.N_FcnAppl.N_FcnConst.N_FieldSet.N_FieldVal.N_FunctionDefinition.N_FunctionParam.N_GeneralId.N_GenInfixOp.N_GenNonExpPrefixOp.N_GenPostfixOp.N_GenPrefixOp.N_IdentDecl.N_Real.N_IdentifierTuple.N_IdentLHS.N_IdPrefix.N_IdPrefixElement.N_IfThenElse.N_InfixDecl.N_InfixExpr.N_InfixLHS.N_InfixOp.N_InnerProof.N_Instance.N_NonLocalInstance.N_Integer.N_LeafProof.N_LetDefinitions.N_LetIn.N_MaybeBound.N_Module.N_ModuleDefinition.N_NonExpPrefixOp.N_Number.N_NumberedAssumeProve.N_OpApplication.N_OpArgs.N_OperatorDefinition.N_OtherArm.N_ParamDecl.N_ParamDeclaration.N_ParenExpr.N_PostfixDecl.N_PostfixExpr.N_PostfixLHS.N_PostfixOp.N_PrefixDecl.N_PrefixExpr.N_PrefixLHS.N_PrefixOp.N_Proof.N_ProofLet.N_ProofName.N_ProofStatement.N_ProofStep.N_QEDStep.N_QuantBound.N_RcdConstructor.N_RecordComponent.N_SetEnumerate.N_SetOfAll.N_SetOfFcns.N_SetOfRcds.N_String.N_SubsetOf.N_Substitution.N_TempDecl.N_Theorem.N_Tuple.N_UnBoundedOrBoundedChoose.N_UnboundedQuant.N_VariableDeclaration.Token =.Token \\in.N_NewSymb.N_Lambda.N_Recursive.N_Label.N_StructOp.N_NumerableStep.N_TerminalProof.N_UseOrHide.N_NonExprBody.N_DefStep.N_HaveStep.N_TakeStep.N_WitnessStep.N_PickStep.N_CaseStep.N_AssertStep`.split(`.`),mu=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
|
|
94
94
|
Nat == { }
|
|
95
95
|
a+b == {a, b}
|
|
96
96
|
a-b == CHOOSE n : b + n = a
|
package/dist/transfer.js
CHANGED
|
@@ -90,7 +90,7 @@ _TEPosition ==
|
|
|
90
90
|
ELSE IF TLCGet("level") = 0 THEN 1 ELSE TLCGet("level")
|
|
91
91
|
|
|
92
92
|
=============================================================================`]]),js=`tlc2/value/impl/`,Ms=e=>{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n={offset:0},r=e=>{let t=n.offset;return n.offset+=e,t};return{readUint8:()=>t.getUint8(r(1)),readUint16:()=>t.getUint16(r(2)),readUint32:()=>t.getUint32(r(4)),readInt32:()=>t.getInt32(r(4)),readBytes:t=>e.subarray(r(t),n.offset)}},Ns=e=>[...e.slice(1,e.indexOf(`)`)).matchAll(/\[*(?:L[^;]*;|[BCDFIJSZ])/g)].length,Ps=e=>{let t=Ms(e);if(t.readUint32()!==3405691582)throw new c(`A module override is not a class file`);t.readUint16(),t.readUint16();let n=[],r=t.readUint16(),i=new TextDecoder;for(let e=1;e<r;e++){let r=t.readUint8(),a={tag:r,text:``,value:0,first:0,second:0};n[e]=a,r===1?a.text=i.decode(t.readBytes(t.readUint16())):r===3?a.value=t.readInt32():r===4?t.readUint32():r===5||r===6?(t.readBytes(8),e++):r===7||r===8||r===16||r===19||r===20?a.first=t.readUint16():r===15?(t.readUint8(),a.first=t.readUint16()):(a.first=t.readUint16(),a.second=t.readUint16())}t.readUint16(),t.readUint16(),t.readUint16(),t.readBytes(t.readUint16()*2);for(let e=t.readUint16();e>0;e--){t.readBytes(6);for(let e=t.readUint16();e>0;e--)t.readUint16(),t.readBytes(t.readUint32())}let a=[];for(let e=t.readUint16();e>0;e--){let e=t.readUint16(),r=n[t.readUint16()].text,i=n[t.readUint16()].text,o={name:r,arity:Ns(i),code:void 0};for(let e=t.readUint16();e>0;e--){let e=n[t.readUint16()].text,r=t.readBytes(t.readUint32());if(e===`Code`){let e=new DataView(r.buffer,r.byteOffset+4,4).getUint32(0);o.code=r.subarray(8,8+e)}}e&1&&e&8&&a.push(o)}return{pool:n,methods:a}},Fs=(e,t)=>e[e[t].first].text,Is=(e,t)=>{let n=e[t],r=e[n.second];return{className:Fs(e,n.first),name:e[r.first].text}},Ls=(e,t,n,r)=>{let i=()=>new m(`The Java override ${n}.${e.name} computes its value, which tla-ts cannot run`),a=e.code;if(!a)throw i();let o=[],s=()=>{let e=o.pop();if(e===void 0)throw i();return e},c=e=>{let n=t[e];if(n.tag===3)return n.value;if(n.tag===8)return t[n.first].text;throw i()};for(let e=0;e<a.length;){let n=a[e],l=()=>a[e+1]<<8|a[e+2];if(n>=2&&n<=8)o.push(n-3),e+=1;else if(n===16)o.push(a[e+1]<<24>>24),e+=2;else if(n===17)o.push(l()<<16>>16),e+=3;else if(n===18)o.push(c(a[e+1])),e+=2;else if(n===19)o.push(c(l())),e+=3;else if(n===89){let t=s();o.push(t,t),e+=1}else if(n===178){let n=Is(t,l());if(n.className!==`${js}BoolValue`||n.name!==`ValTrue`&&n.name!==`ValFalse`)throw i();o.push({kind:`Identifier`,name:n.name===`ValTrue`?`TRUE`:`FALSE`,location:r}),e+=3}else if(n===184){let n=Is(t,l()),a=s();if(n.className!==`${js}IntValue`||n.name!==`gen`||typeof a!=`number`)throw i();o.push({kind:`Number`,value:a,location:r}),e+=3}else if(n===187)o.push({className:Fs(t,l()),value:void 0}),e+=3;else if(n===183){let n=Is(t,l()),a=s(),o=s();if(!(n.className===`${js}StringValue`&&n.name===`<init>`&&typeof a==`string`&&typeof o==`object`&&`className`in o))throw i();o.value={kind:`String`,value:a,location:r},e+=3}else if(n===176){let e=s();if(typeof e!=`object`)throw i();if(`className`in e){if(!e.value)throw i();return e.value}return e}else throw i()}throw i()},Rs=(e,t)=>{if(!t)return e;let n=Ps(t),r=e.definitions.map(t=>{if(t.kind!==`Operator`)return t;let r=n.methods.find(e=>e.name===t.name&&e.arity===t.params.length);return r?{...t,body:Ls(r,n.pool,e.name,t.location)}:t});return{...e,definitions:r}},Z=(e,t,n)=>({low:e,high:t,isAssociative:n}),zs=new Map([[`=>`,Z(1,1,!1)],[`<=>`,Z(2,2,!1)],[`~>`,Z(2,2,!1)],[`-+->`,Z(2,2,!1)],[`/\\`,Z(3,3,!0)],[`\\/`,Z(3,3,!0)],...(/* @__PURE__ */ `=.#.<.>.<=.>=.\\in.\\notin.\\subseteq.\\subset.\\supseteq.\\supset.\\sqsubseteq.\\sqsupseteq.\\sqsubset.\\sqsupset.\\prec.\\preceq.\\succ.\\succeq.\\sim.\\simeq.\\approx.\\cong.\\asymp.\\doteq.\\propto.\\ll.\\gg.|-.-|.|=.=|.:=.::=`.split(`.`)).map(e=>[e,Z(5,5,!1)]),[`\\cdot`,Z(5,14,!0)],[`@@`,Z(6,6,!0)],[`:>`,Z(7,7,!1)],[`<:`,Z(7,7,!1)],[`\\cup`,Z(8,8,!0)],[`\\cap`,Z(8,8,!0)],[`\\`,Z(8,8,!1)],[`..`,Z(9,9,!1)],[`...`,Z(9,9,!1)],[`##`,Z(9,13,!0)],[`$`,Z(9,13,!0)],[`$$`,Z(9,13,!0)],[`??`,Z(9,13,!0)],[`!!`,Z(9,13,!1)],[`\\sqcap`,Z(9,13,!0)],[`\\sqcup`,Z(9,13,!0)],[`\\uplus`,Z(9,13,!0)],[`\\wr`,Z(9,14,!1)],[`+`,Z(10,10,!0)],[`++`,Z(10,10,!0)],[`(+)`,Z(10,10,!0)],[`\\oplus`,Z(10,10,!0)],[`%`,Z(10,11,!1)],[`%%`,Z(10,11,!0)],[`|`,Z(10,11,!0)],[`||`,Z(10,11,!0)],[`\\X`,Z(10,13,!1)],[`-`,Z(11,11,!0)],[`--`,Z(11,11,!0)],[`(-)`,Z(11,11,!0)],[`\\ominus`,Z(11,11,!0)],[`*`,Z(13,13,!0)],[`**`,Z(13,13,!0)],[`/`,Z(13,13,!1)],[`//`,Z(13,13,!1)],[`\\div`,Z(13,13,!1)],[`\\o`,Z(13,13,!0)],[`(.)`,Z(13,13,!0)],[`\\odot`,Z(13,13,!0)],[`(/)`,Z(13,13,!1)],[`\\oslash`,Z(13,13,!1)],[`(\\X)`,Z(13,13,!0)],[`\\otimes`,Z(13,13,!0)],[`&`,Z(13,13,!0)],[`&&`,Z(13,13,!0)],[`\\star`,Z(13,13,!0)],[`\\bullet`,Z(13,13,!0)],[`\\bigcirc`,Z(13,13,!0)],[`^`,Z(14,14,!1)],[`^^`,Z(14,14,!1)]]),Bs=/* @__PURE__ */ new Set([`^+`,`^*`,`^#`]),Vs=/* @__PURE__ */ new Set([`-`,`~`,`-.`]),Hs=/* @__PURE__ */ new Set([`-`,`~`,`/\\`,`\\/`,`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`]),Us=/* @__PURE__ */ new Set([`+`,`-`,`/`,`\\X`]),Ws=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`,`'`,...Bs]),Gs=e=>zs.has(e)||Bs.has(e)||e===`-.`,Ks=(e,t,n)=>{switch(e){case`ENABLED`:return{kind:`Enabled`,expression:t,location:n};case`UNCHANGED`:return{kind:`Unchanged`,expression:t,location:n};case`[]`:return{kind:`Always`,expression:t,location:n};case`<>`:return{kind:`Eventually`,expression:t,location:n};case`'`:return{kind:`Prime`,expression:t,location:n};default:return{kind:`Apply`,operator:e,args:[t],location:n}}},qs=/* @__PURE__ */ new Set([`<<`,`>>`,`:`,`@`,`(`]),Js=/* @__PURE__ */ new Set([`ASSUME`,`ASSUMPTION`,`AXIOM`,`CONSTANT`,`CONSTANTS`,`COROLLARY`,`INSTANCE`,`LEMMA`,`LOCAL`,`PROPOSITION`,`RECURSIVE`,`THEOREM`,`VARIABLE`,`VARIABLES`]),Ys=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Xs=/* @__PURE__ */ new Set([`BY`,`PROOF`,`OBVIOUS`,`OMITTED`]),Zs=/* @__PURE__ */ new Set([`Qed`,`Pick`,`Case`,`Assert`]),Qs=/* @__PURE__ */ new Set(/* @__PURE__ */ `, . _ ( ) [ ] { } << >> ]_ >>_ == ! @ : :: ; -> <- |-> \\A \\AA \\E \\EE \\forall \\exists WF_ SF_ (*{ }*)`.split(` `)),$s=/* @__PURE__ */ new Set([``,`*`,`-`]),ec=/* @__PURE__ */ new Set([`CASE`,`CHOOSE`,`DOMAIN`,`ENABLED`,`IF`,`LAMBDA`,`LET`,`SF_`,`SUBSET`,`UNCHANGED`,`UNION`,`WF_`]),tc=/* @__PURE__ */ new Map([[`CONSTANT`,`Constant`],[`CONSTANTS`,`Constant`],[`VARIABLE`,`Variable`],[`VARIABLES`,`Variable`],[`STATE`,`State`],[`ACTION`,`Action`],[`ACTIONS`,`Action`],[`TEMPORAL`,`Temporal`],[`TEMPORALS`,`Temporal`]]),nc=/* @__PURE__ */ new Set([`NEW`,...tc.keys()]),rc=/* @__PURE__ */ new Set([`(`,`[`,`{`,`<<`]),ic=/* @__PURE__ */ new Set([`)`,`]`,`}`,`>>`,`]_`,`>>_`]),ac=/* @__PURE__ */ new Set([`TRUE`,`FALSE`,`BOOLEAN`,`STRING`]),oc=e=>RegExp(`^-{4,}\\s*MODULE\\s+${e}\\s*-{3,}$`),sc=(e,t)=>{let n=e.split(/\r?\n/),r=n.findIndex(e=>oc(t).test(e));if(r===-1)return;let i=n.findIndex((e,t)=>t>r&&e.startsWith(`====`));return n.slice(r,i===-1?void 0:i+1).join(`
|
|
93
|
-
`)},cc=(e,t)=>{let n=oe(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},l=[],u=e=>i[i.length-1].has(e),d=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),f=[],p=[],m=[],h=e=>{let t=r.index-1,i=e===t?m[e]:void 0;if(i)return i;let a=n[t];f[e]??=d(n[e]),p[t]??={line:a.line,column:a.endColumn};let o={module:l[l.length-1].name,start:f[e],end:p[t]};return e===t&&(m[e]=o),o},g=(e,t)=>(e.location.range=h(t),e),_=(e=0)=>n[Math.min(r.index+e,n.length-1)],v=(e=0)=>{let t=_(e),n=r.offsideColumns[r.offsideColumns.length-1];return n===void 0||n===-1||t.kind===`End`?t:t.column<=n?{...t,kind:`End`,text:``}:t},y=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),ee={index:0},b=e=>{let t=n.slice(ee.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},te=e=>t&&(e.kind===`Keyword`||ac.has(e.text)),re=e=>{let t=n.findLast(t=>t.kind!==`End`&&(t.line<e.line||t.line===e.line&&t.column<e.column));return t?{line:t.line,column:t.endColumn+1}:e},x=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Qs.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):te(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,S=(e,t=_(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new c(`${e} at line ${t.line}, column ${t.column}`,void 0,ie(e,t,a,r))},ie=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...b(re(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${x(a)}`,...re(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},C=(e,t=_())=>S(e,t,t),ae=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!te(e),w=(e,t=0)=>{let n=v(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},T=()=>{let e=v();if(e.kind===`End`)throw S(`Unexpected end of expression`);return r.index++,e},E=e=>w(e)?(r.index++,!0):!1,D=e=>{if(!w(e))throw C(`Expected ${JSON.stringify(e)} but found ${y(v())}`);return T()},O=()=>{let e=v();if(e.kind!==`Identifier`)throw C(`Expected an identifier but found ${y(e)}`);if(te(e))throw C(`Unexpected keyword ${e.text}`);return r.index++,e.text},se=e=>{r.offsideColumns.push(-1);let t=e();return r.offsideColumns.pop(),t},k=(e,t=`,`)=>{let n=[e()];for(;E(t);)n.push(e());return n},ce=()=>{if(w(`<<`)){let e={value:1};for(;v(e.value).kind===`Identifier`||w(`,`,e.value);)e.value++;return w(`>>`,e.value)&&w(`\\in`,e.value+1)}let e={value:0};for(;v(e.value).kind===`Identifier`;){if(w(`\\in`,e.value+1))return!0;if(!w(`,`,e.value+1))return!1;e.value+=2}return!1},le=()=>{if(w(`::`))return!0;if(!w(`(`))return!1;let e={value:1};for(;v(e.value).kind===`Identifier`&&w(`,`,e.value+1);)e.value+=2;return v(e.value).kind===`Identifier`&&w(`)`,e.value+1)&&w(`::`,e.value+2)},ue=()=>{if(!E(`<<`))return{kind:`Name`,name:O()};let e=k(O);return D(`>>`),{kind:`Tuple`,names:e}},de=()=>k(()=>{let e=k(ue);D(`\\in`);let t=N();return e.map(e=>({pattern:e,set:t}))}).flat(),A=()=>{let e=v();if(e.kind===`Identifier`){let t=r.index,n=[T().text];for(;w(`!`)&&v(1).kind===`Identifier`;)T(),n.push(O());return g({kind:`Identifier`,name:n.join(`!`),location:d(e)},t)}if(w(`<<`)||w(`(`))return Se();throw C(`Expected a subscript but found ${y(e)}`)},j=e=>{let t=v(1),n=v(2);return t.kind===`Identifier`&&n.text===`==`?!0:t.line===e.line?!1:t.text===`-.`||t.kind===`Identifier`&&(n.text===`(`||n.text===`[`||n.kind===`Operator`&&w(`==`,Bs.has(n.text)?3:4))},M=e=>{if(!Hs.has(e.text))return!0;let t=v(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||w(`,`,1)||w(`)`,1)||t.kind===`Keyword`&&Js.has(t.text)||j(e)},fe=()=>{let e=v(),n=e.kind===`Operator`&&(zs.has(e.text)||Vs.has(e.text))&&M(e);if(t&&e.kind!==`String`&&(Vs.has(e.text)||Ws.has(e.text)&&e.text!==`'`&&!Bs.has(e.text)||Us.has(e.text)&&v(-1).text===`(`&&v(-1).line===e.line&&v(-1).endColumn+1===e.column&&v(1).text===`)`&&v(1).line===e.line&&v(1).column===e.endColumn+1)&&M(e))throw S(`incomplete expression`,e);if(n)return r.index++,g({kind:`OperatorReference`,operator:e.text,location:d(e)},r.index-1);if(e.kind!==`String`&&Ws.has(e.text)&&M(e)){r.index++;let t=d(e);if(Bs.has(e.text))return{kind:`OperatorReference`,operator:e.text,location:t};let n={kind:`Identifier`,name:`argument`,location:t};return{kind:`Lambda`,params:[n.name],body:Ks(e.text,n,t),location:t}}if(w(`LAMBDA`)){let t=r.index;T();let n=k(O);D(`:`);let i=N();return g({kind:`Lambda`,params:n,body:i,location:d(e)},t)}return N()},pe=()=>se(()=>{D(`(`);let e=k(fe);return D(`)`),e}),me=()=>{let e=T();r.offsideColumns.push(e.column);let t=[N()];for(;_().text===e.text&&_().column===e.column;)r.index++,t.push(N());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:d(e)}},he=e=>se(()=>{let t=d(e);if(v().kind===`Identifier`&&(w(`|->`,1)||w(`:`,1))){let e=w(`|->`,1)?`Record`:`RecordSet`,n=k(()=>{let t=O();return D(e===`Record`?`|->`:`:`),{name:t,value:N()}});return D(`]`),{kind:e,fields:n,location:t}}if(ce()){let e=de();D(`|->`);let n=N();return D(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=N();if(E(`->`)){let e=N();return D(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(E(`EXCEPT`)){let e=k(()=>{D(`!`);let e=[];for(;w(`.`)||w(`[`);)if(E(`.`)){if(!ae(v()))throw C(`Expected a field name but found ${y(v())}`);e.push({kind:`Field`,name:T().text})}else D(`[`),e.push({kind:`Index`,args:k(()=>N())}),D(`]`);return D(`=`),{path:e,value:N()}});return D(`]`),{kind:`Except`,function:n,updates:e,location:t}}return D(`]_`),{kind:`BoxAction`,action:n,subscript:A(),location:t}}),ge=e=>se(()=>{let t=d(e);if(E(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(ce()&&(v(1).text===`\\in`||w(`<<`))){let e=r.index,n=ue();D(`\\in`);let i=N();if(E(`:`)){let e=N();return D(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=N();if(E(`:`)){let e=de();return D(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;E(`,`);)i.push(N());return D(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),_e=e=>{let t=d(e),n=se(()=>w(`>>`)||w(`>>_`)?[]:k(()=>N()));if(E(`>>_`)){if(n.length!==1)throw S(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:A(),location:t}}return D(`>>`),{kind:`Tuple`,elements:n,location:t}},ve=e=>{let t=d(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&ce()){let e=de();return D(`:`),{kind:n,bounds:e,body:N(),location:t}}let i=k(O);return D(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:N(),isTemporal:r,location:t}},ye=e=>{let t=[];do{if(E(`OTHER`))return D(`->`),{kind:`Case`,arms:t,other:N(),location:d(e)};let n=N();D(`->`),t.push({condition:n,body:N()})}while(E(`[]`));return{kind:`Case`,arms:t,other:void 0,location:d(e)}},be=()=>{let e=v(1);return w(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||qs.has(e.text)||e.kind===`Operator`&&(zs.has(e.text)||Bs.has(e.text)||Vs.has(e.text)))},xe=()=>{let e=T();if(e.kind===`Number`)return{kind:`Operand`,operand:ne(e.text)};switch(e.text){case`<<`:case`>>`:return{kind:`Operand`,operand:e.text};case`:`:return{kind:`Colon`};case`@`:return{kind:`At`};case`(`:return r.index--,{kind:`Bound`,args:pe()}}return{kind:`Name`,name:e.text,args:w(`(`)?pe():[]}},Se=()=>{let e=r.index===s.index,n=T(),a=d(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=k(O);return D(`:`),{kind:`Lambda`,params:e,body:N(),location:a}}if(n.kind===`Number`){if(t&&/^\\[BOH]/.test(n.text))throw S(`incomplete expression`,n);return{kind:`Number`,value:ne(n.text),text:n.text,location:a}}if(n.kind===`Decimal`)return{kind:`Decimal`,text:n.text,location:a};if(n.kind===`String`)return{kind:`String`,value:n.text,location:a};let o=n.kind===`Step`&&Fe(n);if(o&&I()<0&&Me.length<=1)throw S(`Step number used outside proof`,n);if(o&&n.text[1]===`+`)throw S(`<+> step number used in an expression`,n);if(n.kind===`Identifier`||o){let r=o?L(n)??n.text:n.text;if(le()){let e=E(`(`)?k(O):[];return e.length>0&&D(`)`),D(`::`),{kind:`Label`,name:r,params:e,body:N(),location:a}}let i=w(`(`),s=i?pe():[];if(!be())return i?{kind:`Apply`,operator:r,args:s,location:a}:{kind:`Identifier`,name:r,location:a};let c=l.flatMap(e=>e.instances).find(e=>e.name===r);if(c&&!e&&!t&&c.params.length!==s.length)throw S(`The operator ${r} requires ${c.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;be();)T(),u.push(xe());let d=u.flatMap(e=>e.kind===`Name`?[e.name]:[]);if(d.length<u.length)return{kind:`Subexpression`,selectors:u,location:a};let f=d.join(`!`),p=u.flatMap(e=>`args`in e?e.args:[]);if(p.length===0)return{kind:`Identifier`,name:f,location:a};let m=u.map(e=>`args`in e?e.args.length:0);return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,location:a}:{kind:`Apply`,operator:f,args:p,location:a}}if(n.kind===`Operator`&&Gs(n.text)&&w(`(`))return{kind:`Apply`,operator:n.text,args:pe(),location:a};switch(n.text){case`(`:{let e=se(()=>N());return D(`)`),e}case`[`:return he(n);case`{`:return ge(n);case`<<`:return _e(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return ve(n);case`IF`:{let e=N();D(`THEN`);let t=N();return D(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:N(),location:a}}case`CASE`:return ye(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!E(`IN`);){if(t&&w(`RECURSIVE`))throw S(`Unexpected keyword RECURSIVE`,b(_()));if(E(`RECURSIVE`)){ke();continue}let r=P(!1);r.kind===`Instance`?n.push(r):e.push(r)}i.pop();let r=N();return n.length===0?{kind:`Let`,definitions:e,body:r,location:a}:{kind:`Let`,definitions:e,instances:n,body:r,location:a}}case`CHOOSE`:{let e=ue(),t=E(`\\in`)?N():void 0;return D(`:`),{kind:`Choose`,pattern:e,set:t,body:N(),location:a}}case`WF_`:case`SF_`:{let e=A(),t=se(()=>{D(`(`);let e=N();return D(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw C(`Unexpected ${y(n)}`,n)},Ce=()=>{let e=v(),t=d(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return me();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return T(),{kind:`Apply`,operator:`~`,args:[N(5)],location:t};case`-`:return T(),{kind:`Apply`,operator:`-.`,args:[N(13)],location:t};case`[]`:return T(),{kind:`Always`,expression:N(16),location:t};case`<>`:return T(),{kind:`Eventually`,expression:N(16),location:t};case`ENABLED`:return T(),{kind:`Enabled`,expression:N(16),location:t};case`UNCHANGED`:return T(),{kind:`Unchanged`,expression:N(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return T(),{kind:`Apply`,operator:e.text,args:[N(9)],location:t}}return Se()},N=(e=0)=>{let t=r.index,n=Ce(),i={left:n.location.range?n:g(n,t),previous:void 0};for(;;){let n=v();if(n.kind!==`Operator`)break;let r=d(n);if(n.text===`'`&&e<=15){T(),i.left=g({kind:`Prime`,expression:i.left,location:r},t);continue}if(Bs.has(n.text)&&e<=15){T(),i.left=g({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){T();let e=se(()=>k(()=>N()));se(()=>D(`]`)),i.left=g({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&ae(v(1))){T();let e=T().text;i.left=g({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=zs.get(n.text);if(!a||a.low<e)break;let o=i.previous;if(o){let e=!(o.low>a.high||o.high<a.low),t=o.text===n.text&&a.isAssociative;if(e&&!t&&(o.text!==`\\X`||n.text!==`\\X`))throw S(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(T(),a.low>12&&w(`-`))throw S(`Precedence conflict between ${n.text} and -`,v());let s=N(a.high+1),c=i.left;if(n.text===`/\\`||n.text===`\\/`){let e=n.text===`/\\`?`And`:`Or`;i.left=c.kind===e&&o?.text===n.text?{...c,operands:[...c.operands,s]}:{kind:e,operands:[c,s],location:r}}else i.left=n.text===`\\X`?c.kind===`Product`&&o?.text===`\\X`?{...c,factors:[...c.factors,s]}:{kind:`Product`,factors:[c,s],location:r}:{kind:`Apply`,operator:n.text,args:[c,s],location:r};i.left=g(i.left,t),i.previous={...a,text:n.text}}return i.left},we=()=>{if(!E(`(`))return[];let e=F();return D(`)`),e},Te=()=>{let e=d(v()),t=N(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:l[l.length-1].name,start:e,end:a}}},P=e=>{let t=r.index;return g(Ee(e),t)},Ee=e=>{let t=v(),n=d(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...Te(),isLocal:e,isRecursive:u(t),location:n});if(t.kind===`Identifier`&&v(1).kind===`Operator`&&zs.has(v(1).text)&&v(2).kind===`Identifier`&&w(`==`,3)){let e=O(),t=T().text,n=O();return D(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&Bs.has(v(1).text)&&w(`==`,2);if(a||o){let e=a?t.text:v(1).text;r.index+=a?1:2;let n=a?O():t.text;return D(`==`),i(e,[{name:n,arity:0}])}let s=O();if(E(`[`)){let t=se(()=>de());return D(`]`),D(`==`),{kind:`Function`,name:s,bounds:t,body:N(),isLocal:e,isRecursive:u(s),location:n}}let c=r.index,l=we();return D(`==`),w(`INSTANCE`)?{...De(s,l,e,n),definitionRange:h(c)}:i(s,l)},De=(e,t,n,i)=>{let a=r.index;return D(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:O(),substitutions:E(`WITH`)?k(()=>{let e=T().text;return D(`<-`),{name:e,expression:fe()}}):[],isLocal:n,location:i,instanceRange:h(a)}},Oe=()=>{let e=d(v());if(w(`_`)&&v(1).kind===`Operator`)return T(),{name:T().text,arity:E(`_`)?2:1,location:e};if(v().kind===`Operator`&&w(`_`,1)){let t=T().text;return T(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=O();if(!E(`(`))return{name:t,arity:0,location:e};let n=k(()=>D(`_`));return D(`)`),{name:t,arity:n.length,location:e}},F=()=>k(Oe),ke=()=>{let e=F();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ae=e=>{let t={value:0,offset:e};do{let e=v(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&rc.has(e.text)&&t.value++,e.kind===`Operator`&&ic.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},je=()=>{let e=v(),t=v(1);return e.kind===`Identifier`?w(`(`,1)||w(`[`,1)?w(`==`,Ae(1)):t.kind===`Operator`&&Bs.has(t.text)?w(`==`,2):t.kind===`Operator`&&zs.has(t.text)?v(2).kind===`Identifier`&&w(`==`,3):w(`==`,1):w(`-.`)&&t.kind===`Identifier`&&w(`==`,2)},Me=[],I=()=>Me[Me.length-1]??-1,Ne=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),Pe=e=>{let t=e.text.slice(e.text.indexOf(`>`)+1),n={value:t.length};for(;t[n.value-1]===`.`;)n.value--;return t.slice(0,n.value)},Fe=e=>!e.text.endsWith(`.`)&&!$s.has(Pe(e)),L=e=>{let t=Pe(e);if($s.has(t))return;let n=Ne(e);if(n>=0)return`<${n}>${t}`;let r=I(),i=Me[Me.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Ie=e=>{if(e.kind===`Keyword`)return Xs.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Me.length===0;if(e.text[1]===`+`||Me.length===0)return!0;let t=I();return t>=0&&Ne(e)>t},Le=e=>{let t=Ne(e),n=Me.length-1,r=Me[n-1]??-1,i=Me[n]<0;return i&&(Me[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Me[n]===t},Re=e=>!a.has(e)&&l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),ze=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!ac.has(e.name)&&!Re(e.name):!1,Be=()=>{let e=v();return e.kind===`Step`?Fe(e):e.kind===`Keyword`?ec.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!je()},Ve=()=>{let e=r.index;s.index=e;let t=v();return t.kind===`Operator`&&!Hs.has(t.text)&&Gs(t.text)?(r.index++,g({kind:`OperatorReference`,operator:t.text,location:d(t)},e)):E(`MODULE`)?g({kind:`ModuleFact`,name:O(),location:d(t)},e):N()},He=e=>o[o.length-1]?.add(e),Ue=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},We=e=>o.some(t=>t.has(e))||l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Ge=()=>{let e=r.index,t=v(),n=k(()=>{let e=v();if((e.kind!==`Identifier`||te(e))&&e.kind!==`Operator`)throw C(`Expected a definition name but found ${y(e)}`,e);return r.index++,e.text},`!`),i=d(t);return g(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ke=()=>{if(t)return k(Ge);let e=k(Ve),n=e.find(e=>e.kind===`Identifier`&&We(e.name));if(n)throw S(`DEF clause entry should describe a defined operator`,n.location);return e},qe=()=>({facts:Be()?k(Ve):[],defs:E(`DEF`)||E(`DEFS`)?Ke():[]}),Je=()=>{let e=r.index,n=T(),i=n.text===`USE`&&E(`ONLY`),a=h(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...qe(),keyword:a,location:d(n)},s=o.kind===`Hide`&&!t?o.facts.find(e=>!ze(e)):void 0;if(s)throw S(`The only expression allowed as a fact in a HIDE is the name of a theorem, assumption, or step`,s.location);return g(o,e)},Ye=()=>{let e=r.index,t=d(v()),n=E(`NEW`),i=v().kind===`Keyword`?tc.get(v().text):void 0;if(!n&&i===void 0)throw C(`Expected a declaration but found ${y(v())}`);if(i!==void 0&&T(),i===`Variable`){let n=O();return He(n),g({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Oe();He(a.name);let o=(i??`Constant`)===`Constant`&&w(`\\in`);if(o&&a.arity>0)throw S(`declared symbol with arguments before \\in`);return o&&T(),g({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?N():void 0,location:t},e)},Xe=()=>{let e=r.index,t=d(D(`ASSUME`)),n=k(()=>w(`ASSUME`)?Ue(Xe):v().kind===`Keyword`&&nc.has(v().text)?Ye():N());return D(`PROVE`),g({kind:`AssumeProve`,assumptions:n,conclusion:N(),location:t},e)},Ze=e=>{let t={value:0};for(;v(t.value).kind===`Identifier`&&w(`,`,t.value+1);)t.value+=2;return v(t.value).kind===`Identifier`&&w(e,t.value+1)},Qe=(e,t)=>{e.forEach(He),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(He))},$e=()=>{let e=v();if(w(`USE`)||w(`HIDE`))return Je();if(w(`INSTANCE`))return g(De(void 0,[],!1,d(e)),r.index);if(w(`DEFINE`)||je()){let t=r.index;E(`DEFINE`);let n=[P(!1)];for(;je();)n.push(P(!1));let i={kind:`Define`,definitions:n,location:d(e)};return g(i,t)}if(E(`HAVE`))return{kind:`Have`,expression:N()};if(E(`TAKE`)){let e=ce(),t=e?[]:k(O),n=e?de():[];return Qe(t,n),{kind:`Take`,names:t,bounds:n}}if(E(`WITNESS`))return{kind:`Witness`,expressions:k(()=>N())};if(E(`PICK`)){let e=Ze(`:`),t=e?k(O):[],n=e?[]:de();return Qe(t,n),D(`:`),{kind:`Pick`,names:t,bounds:n,body:N()}}return E(`CASE`)?{kind:`Case`,expression:N()}:{kind:`Assert`,isSuffices:E(`SUFFICES`),statement:w(`ASSUME`)?Xe():N()}},et=e=>{let t=v();if(t.kind!==`Step`)throw C(`Expected a step number but found ${y(t)}`,t);if(!Le(t))throw S(`${e?`QED step`:`step`}'s number has bad level`,t);if(Ne(t)<0&&L(t)!==void 0)throw S(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:L(t),token:t.text,location:d(t)}},tt=()=>{let e=r.index,t=et(w(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=E(`QED`)?{kind:`Qed`}:$e(),a=h(e),s=Ie(v());if(s&&!Zs.has(i.kind))throw S(`Proof of a step that does not take a proof`);let c=s?rt():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(He),g({...t,body:i,head:a,proof:c},e)},nt=()=>{let e=d(v());if(w(`BY`)||w(`PROOF`)&&w(`BY`,1)){E(`PROOF`),T();let t=h(r.index-1);return{kind:`By`,isOnly:E(`ONLY`),...qe(),keyword:t,location:e}}let t=v(+!!w(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){E(`PROOF`),T();let n=h(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}E(`PROOF`);let n=[tt()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(tt());return{kind:`Steps`,level:I(),steps:n,location:e}},rt=()=>{let e=r.index;Me.push(-1);let t=Ue(nt);return Me.pop(),g(t,e)},it=e=>{let t=r.index,n=T(),i=v().kind===`Identifier`&&w(`==`,1)?O():void 0;i!==void 0&&(a.add(i),T());let o=Ue(()=>({statement:w(`ASSUME`)?Xe():N(),proof:Ie(v())?rt():void 0})),s=o.statement,c=g({name:i,statement:s,proof:o.proof,location:d(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(g({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:d(n)},t))},at=()=>{let e=r.index;return g(ot(),e)},ot=()=>{let e=T(),t=d(e),n=e.text===`AXIOM`;if(v().kind===`Identifier`&&w(`==`,1)){let e=O();return a.add(e),T(),{name:e,expression:N(),isAxiom:n,location:t}}return{name:void 0,expression:N(),isAxiom:n,location:t}},st=()=>{let e=d(D(`----`));D(`MODULE`);let t=O();D(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(l.push(n),i.push(/* @__PURE__ */ new Set),E(`EXTENDS`)&&k(()=>{let e=r.index;n.extends.push(O()),n.extendsRanges.push(h(e))});;){let a=r.index;ee.index=a;let o=v();if(o.kind===`ModuleEnd`||o.kind===`End`)return o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),l.pop(),i.pop(),n;if(o.kind===`Separator`){if(w(`MODULE`,1)){let e=st();n.modules.push(e),n.units.push({kind:`Module`,module:e}),D(`====`);continue}T()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{T();let e=F();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{T();let e=k(()=>{let e=r.index,t=d(v());return g({name:O(),arity:0,location:t},e)});n.variables.push(...e),n.units.push({kind:`Variables`,declarations:e});continue}case`ASSUME`:case`ASSUMPTION`:case`AXIOM`:{let e=at();n.assumptions.push(e),n.units.push({kind:`Assumption`,assumption:e}),e.name!==void 0&&n.definitions.push({kind:`Operator`,name:e.name,params:[],body:e.expression,isLocal:!1,isRecursive:!1,location:e.location});continue}case`USE`:case`HIDE`:{let e=Je();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:T(),n.units.push({kind:`Recursive`,declarations:ke()});continue;case`INSTANCE`:ct(n,g(De(void 0,[],!1,d(o)),a));continue;case`LOCAL`:if(T(),w(`INSTANCE`)){ct(n,g(De(void 0,[],!0,d(o)),a));continue}ct(n,P(!0));continue}o.kind===`Keyword`&&Ys.has(o.text)?it(n):ct(n,P(!1))}}},ct=(e,t)=>{t.kind===`Instance`?(e.instances.push(t),e.units.push({kind:`Instance`,instance:t})):(e.definitions.push(t),e.units.push({kind:`Definition`,definition:t}))};return st()},lc=e=>cc(e,!1),uc=e=>cc(e,!0),dc=25214903917n,fc=(1n<<48n)-1n,pc=2147483647,mc=e=>{let t={value:(BigInt.asUintN(64,e)^dc)&fc},n=e=>(t.value=t.value*dc+11n&fc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^dc)&fc},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=pc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},hc=10454148508367108822n,gc=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:hc);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),_c=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e>>32n))),vc=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e))),yc=Number(BigInt.asIntN(32,hc>>32n)),bc=Number(BigInt.asIntN(32,hc));let xc=yc,Sc=bc;const Cc=e=>{let t=(e^Sc)&255;Sc=(Sc>>>8|xc<<24)^vc[t],xc=xc>>>8^_c[t]},wc=e=>{for(let t=0;t<32;t+=8)Cc(e>>>t)},Tc=e=>{if(typeof e==`boolean`)Cc(0),Cc(e?116:102);else if(typeof e==`number`)Cc(1),wc(e);else if(typeof e==`string`){Cc(3),wc(e.length);for(let t=0;t<e.length;t++)Cc(e.charCodeAt(t))}else if(M(e))Cc(21),wc(De(e.name)+1);else if(j(e)){let t=H(e);Cc(9),wc(t.domain.length);for(let e=0;e<t.domain.length;e++)Tc(t.domain[e]),Tc(t.range[e])}else{let t=B(e).elements;Cc(5),wc(t.length);for(let e of t)Tc(e)}},Ec=e=>{let t={high:xc,low:Sc};xc=yc,Sc=bc;for(let t of e)Tc(t);let n=BigInt(xc>>>0)<<32n|BigInt(Sc>>>0);return xc=t.high,Sc=t.low,n},Dc=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||M(e))return 5;if(typeof e==`string`)return 5+e.length;if(j(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+Dc(n)+Dc(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+Dc(t),5)},Oc=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){xc=n<32?0:1<<n-32,Sc=n<32?1<<n:0;for(let t=0;t<e;t++)Cc(0);let r=n>>3,i=1<<(n&7);for(let e=i;e<2*i;e++){let n=(r*256+e)*2,a=(r*256+e-i)*2;t[n]=t[a]^xc,t[n+1]=t[a+1]^Sc}}return t},kc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=[],r=e=>{let r=t.get(e);if(r!==void 0)return r;let i=Dc(e);return xc=0,Sc=0,Tc(e),t.set(e,n.length),n.push(i,xc,Sc),n.length-3},i=t=>{let n=e.get(t);if(n)return n;let r=Oc(t);return e.set(t,r),r};return e=>{let t={high:xc,low:Sc},a={high:yc,low:bc};for(let t of e){let e=r(t),o=i(n[e]),s={high:n[e+1],low:n[e+2]};for(let e=0;e<8;e++){let t=e<4?a.low:a.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=o[n],s.low^=o[n+1]}a.high=s.high,a.low=s.low}return xc=t.high,Sc=t.low,BigInt(a.high>>>0)<<32n|BigInt(a.low>>>0)}},Ac=[],jc=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Mc=()=>{for(let e=1277011;Ac.length<1341;e++)jc(e)&&Ac.push(e);return Ac},Nc=e=>{let t=Mc(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Pc=e=>{let t=[],n={value:e};for(let e=2;e*e<=n.value;e++)for(;n.value%e===0;)t.push(e),n.value/=e;return n.value>1&&t.push(n.value),t},Fc=e=>{for(let t=Math.max(e,9);;t++){let e=Pc(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Ic=(e,t,n)=>{if(t<=0)return[];let r=Fc(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Nc(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Lc=(1n<<63n)-1n-24n,Rc=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Lc*BigInt(n)+i)%t;return r<0n?r+t:r})},zc=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Bc=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Tt(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>L(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>Dt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Vc=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ic(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=Bc(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(pc)?Rc(e,t,n):Ic(e,Number(t),n)).map(e=>r.create(zc(r.lists,e)))}let i=B(t).elements;return Ic(e,i.length,n).map(e=>i[Number(e)])},Hc=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new u(`RandomElement of the empty set`);return n},Uc=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Tt(e.domain)];return L(n,n.map(()=>Uc(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Dt(e.names.map((n,r)=>[n,Uc(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Uc(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.floor(t.nextDouble()*n);if(r>=n)throw new u(`RandomElement of the empty set`);return e.low+r}return Hc(B(e).elements,t)},Wc=(e,t=0n)=>{let n=mc(t),r={random:mc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Dt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Ec,getRandom:()=>{let e=i.isStartup?void 0:a.getCurrentState();return e===void 0?n:(e!==r.state&&(r.random.setSeed(a.getFingerprint(e)^BigInt.asUintN(64,t)),r.state=e),r.random)},evaluateAtStartup:e=>{let t=i.isStartup;i.isStartup=!0;try{return e()}finally{i.isStartup=t}},pause:()=>{},seed:t,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,isStopped:!1,checkDeadlock:e,startedAt:Date.now()};return a},Gc=e=>_t([...e.possibleCounts].map(([e,t])=>[e,t])),Kc=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Gc(e)]]),qc=(e,t,n)=>new d(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Jc=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Yc=e=>j(e)?H(e):void 0,Xc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw qc(n,`a function with a finite domain`,r);return i},Zc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw Jc(t===0?`first`:`second`,n,`bag`,r);return i},Qc=(e,t)=>{if(!A(e)||!z(e))throw t();return B(e).elements},$c=e=>e.range.every(e=>typeof e==`number`&&e>0),el=(e,t)=>{let n=e.domain.findIndex(e=>Ie(e,t));return n===-1?void 0:e.range[n]},tl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,nl=tl(`BagDiff`,`tlc2.value.impl.Value`,2),rl=tl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),il=tl(`BagUnion`,`tlc2.value.impl.Value`,1),al=tl(`BagOfAll`,`tlc2.value.impl.Value`,2),ol=tl(`BagCup`,`tlc2.value.impl.Value`,2),sl=tl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),cl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${$n(e)}`;throw tr(t,`class ${n} cannot be cast to class tlc2.value.impl.IntValue (${n} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`)},ll=(e,t,n)=>{let r=cl(e,n)+cl(t,n);if(Jn(r))throw Yn(`${e}+${t}`);return r},ul=(e,t,n,r)=>{let i=el(n,e.domain[t]),a=cl(e.range[t],r);return i===void 0?a:a-cl(i,r)|0},dl=(e,t)=>_t(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>Ie(e[0],r));a?a[1]=ll(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),fl=L([],[]),pl=[Wn(`EmptyBag`,fl),K(`IsABag`,1,e=>{let t=Yc(G(e,0,`IsABag`));return t!==void 0&&$c(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Xc(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw qc(`BagCardinality`,`a bag`,t);return ll(e,n,sl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=el(Xc(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Jc(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=el(Xc(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Jc(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Zc(e,t,`(+)`);if(!$c(n))throw Jc(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return dl(t,ol)}),K(`\\ominus`,2,e=>{let t=Zc(e,0,`(-)`),n=Zc(e,1,`(-)`);return _t(t.domain.flatMap((e,r)=>{let i=ul(t,r,n,nl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Qc(t,()=>qc(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??fl;let r=n.map(e=>{let n=Yc(e);if(!n)throw new d(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return dl(r,il)}),K(`\\sqsubseteq`,2,e=>{let t=Xc(e,0,`\\sqsubseteq`),n=Xc(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>ul(t,r,n,rl)<=0)}),Gn(`BagOfAll`,2,e=>{let t=Un(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new d(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Yc(n);if(!r)throw Jc(`second`,`BagOfAll`,`function with a finite domain`,n);return dl(r.domain.map((e,n)=>L([t.call([e])],[r.range[n]])),al)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!j(t))throw new u(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=dt(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new u(`The ${e?`first`:`second`} argument of >= should be an integer, but instead it is:\n${U(e?r[0]:i)}`)}let a=n.range.filter(e=>typeof e==`number`);if(a.some(e=>e<1))throw new u(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return dt(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>L(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>nn(Xc(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Qc(t,()=>qc(`BagToSet`,`a function with a finite domain`,t));return L([...n],n.map(()=>1))})],ml=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,hl=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,gl=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,_l=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,vl=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,yl=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,bl=e=>{if(!j(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},xl=(e,t)=>tr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${$n(t)}`),Sl=(e,t)=>tr(e,`Cannot cast tlc2.value.impl.${$n(t)} to tlc2.value.impl.StringValue`),Cl=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),wl=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw xl(t,e);return`[${B(e).elements.map(e=>El(e,t)).join(`,`)}]`},Tl=(e,t)=>{let n=H(e),r=Gt(n);return r?`[${r.map(e=>El(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${Cl(typeof e==`string`?e:U(e))}:${El(n.range[r],t)}`).join(`,`)}}`},El=(e,t)=>typeof e==`string`?Cl(e):typeof e==`object`?e.kind===`ModelValue`?Cl(e.name):A(e)?wl(e,t):Tl(e,t):String(e),Dl=e=>{if(A(e))return wl(e,ml);if(!j(e)||bl(e))throw xl(ml,e);return Tl(e,ml)},Ol=e=>{if(!j(e))throw xl(hl,e);return Tl(e,hl)},kl=e=>{let[,t,n=`0`,r=``,i=`0`]=/^(-?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(e)??[],a=BigInt(n+r),o=Number(i)-r.length,s=o>=0?a*10n**BigInt(o):a/10n**BigInt(-o);return Number(BigInt.asIntN(32,t===`-`?-s:s))},Al=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return P(e);if(Array.isArray(e))return R(e.map(e=>Al(e,t)));if(typeof e==`object`&&e)return Dt(Object.entries(e).map(([e,n])=>[P(e),Al(n,t)]));throw tr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},jl=(e,t)=>{if(e.trim()===``)return Al(null,t);try{return Al(JSON.parse(e,(e,t,n)=>typeof t==`number`?kl(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?tr(t,e.message):e}},Ml=(e,t)=>{if(typeof e!=`string`)throw Sl(t,e);return e},Nl=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw tr(n,`${t} (No such file or directory)`);return r},Pl=e=>[Kn(`ToJson`,1,e=>P(El(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Kn(`ToJsonArray`,1,e=>P(Dl(G(e,0,`ToJsonArray`)))),Kn(`ToJsonObject`,1,e=>P(Ol(G(e,0,`ToJsonObject`)))),Kn(`JsonSerialize`,2,t=>{let n=Ml(G(t,0,`JsonSerialize`),gl),r=G(t,1,`JsonSerialize`);if(!Gt(r)&&!bl(r))throw new d(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,El(r,gl)),!0}),Kn(`ndJsonSerialize`,2,t=>{let n=Ml(G(t,0,`ndJsonSerialize`),_l),r=G(t,1,`ndJsonSerialize`),i=Gt(r);if(!i)throw new d(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${El(e,_l)}\n`).join(``)),!0}),Kn(`JsonDeserialize`,1,t=>{let n=Ml(G(t,0,`JsonDeserialize`),vl);return jl(Nl(e,n,vl),vl)}),Kn(`ndJsonDeserialize`,1,t=>{let n=Ml(G(t,0,`ndJsonDeserialize`),yl);return R(Nl(e,n,yl).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>jl(e,yl)))})],Fl=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Il=(e,t,n)=>{if(typeof e!=`number`||e<0)throw Fl(t,n,`nonnegative integer`,U(e));return e},Ll=(e,t,n,r)=>{if(!A(e)||!z(e))throw Fl(t,n,r,U(e));return B(e).elements},Rl=(e,t,n,r)=>dt(Array.from({length:t},()=>dt(e.filter(()=>r.nextDouble()<n)))),zl=(e,t)=>{let n=`RandomSetOfSubsets`,r=Il(G(e,0,n),`first`,n),i=Il(G(e,1,n),`second`,n),a=Ll(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw Fl(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw Fl(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Rl(a,r,a.length===0?0:i/a.length,t.getRandom())},Bl=e=>[Kn(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw Fl(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new u(`Attempted to apply the operator overridden by the Java method\npublic static tlc2.value.impl.Value tlc2.module.Randomization.RandomSubset(tlc2.value.impl.Value,tlc2.value.impl.Value),\nbut it produced the following error:\n${n}`);let r=G(t,1,`RandomSubset`);if(!A(r)||!V(r)&&!z(r))throw Fl(`second`,`RandomSubset`,`a finite set`,U(r));return dt(Vc(n,r,e.getRandom()))}),Kn(`RandomSetOfSubsets`,3,t=>zl(t,e)),Kn(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(zl(t,e)).elements.length)))],Vl=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Hl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Vl})`,Ul=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Vl}) throws java.io.IOException`,Wl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Vl})`,Gl=()=>Dt([[`action`,dt([])],[`state`,dt([])]]),Kl=()=>Dt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ql=e=>Dt([[`name`,e??`UnnamedAction`],[`location`,Kl()]]),Jl=(e,t)=>{let n=e.map((e,t)=>R([t+1,Dt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ql(e[r+1].action),t])),i=t?[R([n[n.length-1],ql(t.action),n[t.start]])]:[];return Dt([[`action`,dt([...r,...i])],[`state`,dt(n)]])},Yl=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Kc(e).get(t)},Xl=(e,t,n,r)=>{if(typeof n==`number`&&n>=0)e.registers.set(n,r);else if(n===`exit`)r===!0&&(e.isStopped=!0);else if(n===`pause`){if(r!==!0)return;t(`Press enter to resume model checking.`),e.pause()}else if(typeof n==`string`&&n.startsWith(`s:`))e.namedRegisters.set(n,r);else if(typeof n==`string`&&n.startsWith(`-D`))e.properties.set(n.slice(2),U(r));else throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(n)}`)},Zl=e=>e.every(e=>e!==void 0),Ql=(e,t)=>Dt(t.variables.map((t,n)=>[t,e[n]])),$l=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(e.kind===`Prime`||e.kind===`Unchanged`)return!0;if(r!==void 0&&!W(e)){if(t.variableIndex.has(r))return!0;let e=qa(r,t);if(e&&!n.has(e)&&(n.add(e),$l(e.body,t,n)))return!0}return jn(e).some(e=>$l(e,t,n))},eu=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new WeakMap,i=e=>{let t=r.get(e)??/* @__PURE__ */ new Map;return r.set(e,t),t};return[K(`AssertEq`,2,t=>{let n=G(t,0,`AssertEq`),r=G(t,1,`AssertEq`),i=Ie(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),cr(`AssertError`,2,e=>{let t=Un(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw tr(Hl,`In computing AssertError, a non-string expression (line ${t.location.line}, col ${t.location.column}) was used as the err of an AssertError(err, exp).`);let n=lr(e,0,`AssertError`)();try{lr(e,1,`AssertError`)()}catch(e){if(e instanceof u)return e.message===n;throw e}return!1}),Kn(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Yl(t,n)??G(e,1,`TLCGetOrDefault`)}),{...Gn(`TLCGetAndSet`,4,n=>{let r=G(n,0,`TLCGetAndSet`),i=Yl(t,r)??G(n,3,`TLCGetAndSet`),a=Un(n,1,`TLCGetAndSet`);return Xl(t,e,r,a.call([i,G(n,2,`TLCGetAndSet`)])),i}),isStateLevel:!0},Kn(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Zl(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw tr(Ul,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return R(t.getBehavior(r).map(e=>Ql(e,n.environment)))}),Kn(`CounterExample`,0,()=>t.counterExample??Gl()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!j(t)||!Ie(nn(t),dt([`action`,`state`])))throw new u(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(en(t,`state`)).elements.map(e=>Gt(e)??[]);return R(n.sort((e,t)=>Number(e[0])-Number(t[0])).map(e=>e[1]))}),K(`TLCModelValue`,1,e=>{let t=G(e,0,`TLCModelValue`);if(typeof t!=`string`)throw new d(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Pe(t)}),cr(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),cr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Zl(r))throw tr(Wl,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Ka(lr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new m(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),cr(`TLCCache`,2,(e,t)=>{let r=Un(e,0,`TLCCache`),a=xn(lr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=$l(o,t.environment,/* @__PURE__ */ new Set)&&t.state?i(t.state):n,c=s.get(o)??/* @__PURE__ */ new Map;s.set(o,c);let l=c.get(a);if(l!==void 0)return l;let u=r.call([]);return c.set(a,u),u}),K(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Ec([G(e,0,`TLCFP`)])))),Kn(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?qa(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new d(`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${U(n)}`);if(r.kind===`Operator`&&r.params.length>0)throw new d(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return X({kind:`Identifier`,name:n,location:r.location},t)})]},tu=(e,t)=>[Kn(`_Track`,2,e=>{let n=String(G(e,1,`_Track`)),r=t.possibleCounts.get(n)??0;return t.possibleCounts.set(n,G(e,0,`_Track`)===!0?r+1:r),!0}),Kn(`_Counts`,0,()=>Gc(t)),Kn(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(Gc(t),!0)),!1)}),Kn(`_PrintCounts`,0,()=>(e(U(Gc(t),!0)),!0))],nu=e=>String(e).padStart(2,`0`),ru=e=>`${e.getUTCFullYear()}.${nu(e.getUTCMonth()+1)}.${nu(e.getUTCDate())}.${nu(e.getUTCHours())}${nu(e.getUTCMinutes())}${nu(e.getUTCSeconds())}`,iu=e=>_t([...e].map(([e,t])=>[e,R([t])])),au=(e,t,n)=>{let r=Math.floor((Date.now()-e.startedAt)/1e3);switch(t){case`level`:return n===void 0?0:e.getLevel(n);case`diameter`:return e.diameter;case`generated`:return e.generatedStates;case`distinct`:return e.distinctStates;case`queue`:return e.queueSize;case`duration`:return r;case`stats`:return Dt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Dt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Dt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,P(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,P(ru(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ql(void 0);case`all`:return iu(e.registers);case`all:named`:return iu(Kc(e))}if(t.startsWith(`s:`)){let n=Kc(e).get(t);if(n===void 0)throw new d(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return P(e.properties.get(t.slice(2))??t);throw new d(`TLCGet(${t}) was undefined.`)},ou=e=>e.length===0?[[]]:e.flatMap((t,n)=>ou([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),su=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(su),e.kind===`Function`&&e.range.forEach(su))},cu=(t,n)=>[K(`Print`,2,e=>(t(`${de(U(G(e,0,`Print`),!0,!0))} ${de(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(de(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new d(`The first argument of Assert evaluated to FALSE; the second argument was:\n${de(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>_t([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=Hn(e,0,`@@`),n=Hn(e,1,`@@`);return vt([...ge(t),...ge(n)])}),K(`ToString`,1,e=>P(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return su(t),t}),K(`Permutations`,1,e=>{let t=Bn(e,0,`Permutations`);return dt(ou(t).map(e=>_t(t.map((t,n)=>[t,e[n]]))))}),Gn(`SortSeq`,2,e=>{let t=Un(e,1,`SortSeq`);return R(Vn(e,0,`SortSeq`).reduce((e,n)=>{let r=e.findIndex(e=>t.call([n,e])===!0);return r===-1?[...e,n]:[...e.slice(0,r),n,...e.slice(r)]},[]))}),Kn(`TLCGet`,1,(e,t)=>{let r=G(e,0,`TLCGet`);if(typeof r==`number`&&r>=0){let e=n.registers.get(r);if(e===void 0)throw new d(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new d(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return au(n,r,t?.state)}),Kn(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`);return Xl(n,t,r,G(e,1,`TLCSet`)),!0}),Wn(`Any`,je),K(`RandomElement`,1,e=>Uc(Rn(e,0,`RandomElement`),n.getRandom()))],lu=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices`.split(`,`),uu=[[`\\lnot`,`~`,`\\neg`,`¬`],[`[]`,`□`],[`<>`,`◇`],[`\\land`,`/\\`,`∧`],[`\\lor`,`\\/`,`∨`],[`\\equiv`,`<=>`,`≡`,`⇔`],[`/=`,`#`,`≠`],[`\\leq`,`<=`,`=<`,`≤`],[`\\geq`,`>=`,`≥`],[`\\times`,`\\X`,`×`],[`\\intersect`,`\\cap`,`∩`],[`\\union`,`\\cup`,`∪`],[`\\o`,`\\circ`,`∘`],[`\\oplus`,`(+)`,`⊕`],[`\\ominus`,`(-)`,`⊖`],[`\\odot`,`(.)`,`⊙`],[`\\oslash`,`(/)`,`⊘`],[`\\otimes`,`(\\X)`,`⊗`],[`\\approx`,`≈`],[`:=`,`≔`],[`\\asymp`,`≍`],[`\\bigcirc`,`◯`],[`::=`,`⩴`],[`\\bullet`,`●`],[`\\cdot`,`⋅`],[`\\cong`,`≅`],[`\\div`,`÷`],[`\\doteq`,`≐`],[`..`,`‥`],[`...`,`…`],[`!!`,`‼`],[`\\gg`,`≫`],[`=>`,`⇒`],[`\\in`,`∈`],[`=|`,`⫤`],[`~>`,`↝`],[`\\ll`,`≪`],[`-|`,`⊣`],[`\\notin`,`∉`],[`-+->`,`⇸`],[`\\prec`,`≺`],[`\\preceq`,`⪯`],[`\\propto`,`∝`],[`??`,`⁇`],[`|=`,`⊨`],[`|-`,`⊢`],[`\\sim`,`∼`],[`\\simeq`,`≃`],[`\\sqcap`,`⊓`],[`\\sqcup`,`⊔`],[`\\sqsubset`,`⊏`],[`\\sqsubseteq`,`⊑`],[`\\sqsupset`,`⊐`],[`\\sqsupseteq`,`⊒`],[`\\star`,`⋆`],[`\\subset`,`⊂`],[`\\subseteq`,`⊆`],[`\\succ`,`≻`],[`\\succeq`,`⪰`],[`\\supset`,`⊃`],[`\\supseteq`,`⊇`],[`\\uplus`,`⊎`],[`||`,`‖`],[`\\wr`,`≀`],[`^+`,`⁺`]],du=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices,***I do not exist***,--TLA+ BUILTINS--,Formal_0,Formal_1,Formal_2,[,^,/,*,-,-.,+,^+,^*,^#,<,\\leq,>,\\geq,...,..,|,||,&&,&,$$,$,??,%%,%,##,++,--,**,//,^^,@@,!!,|-,|=,-|,=|,<:,:>,:=,::=,\\oplus,\\ominus,\\odot,\\oslash,\\otimes,\\uplus,\\sqcap,\\sqcup,\\div,\\wr,\\star,\\o,\\bigcirc,\\bullet,\\prec,\\succ,\\preceq,\\succeq,\\sim,\\simeq,\\ll,\\gg,\\asymp,\\subset,\\supset,\\supseteq,\\approx,\\cong,\\sqsubset,\\sqsubseteq,\\sqsupset,\\sqsupseteq,\\doteq,\\propto,~,¬,□,◇,/\\,∧,\\/,∨,<=>,≡,⇔,#,≠,<=,=<,≤,>=,≥,\\X,×,\\cap,∩,\\cup,∪,\\circ,∘,(+),⊕,(-),⊖,(.),⊙,(/),⊘,(\\X),⊗,≈,≔,≍,◯,⩴,●,⋅,≅,÷,≐,‥,…,‼,≫,⇒,∈,⫤,↝,≪,⊣,∉,⇸,≺,⪯,∝,⁇,⊨,⊢,∼,≃,⊓,⊔,⊏,⊑,⊐,⊒,⋆,⊂,⊆,≻,⪰,⊃,⊇,⊎,‖,≀,⁺,@`.split(`,`),fu=/* @__PURE__ */ `exit.pause.config.spec.coverage.action.install.id.behavior.all.mode.deadlock.seed.fingerprint.worker.traces.depth.aril.sched.revision.timestamp.date.count.tag.calver.impliedinits.impliedactions.invariants.impliedtemporals.temporals.actions.inits.variables.actionconstraints.constraints.stats.duration.generated.diameter.distinct.initial.queue.retries.distinctvalues.levelmean.levelvariance.bfs`.split(`.`),pu=/* @__PURE__ */ `Not a node.N_ActDecl.N_ActionExpr.N_AssumeDecl.N_AssumeProve.N_Assumption.N_BeginModule.N_Body.N_BoundedQuant.N_Case.N_CaseArm.N_CaseStatement.N_ChooseStatement.N_ConjItem.N_ConjList.N_ConsDecl.N_DisjItem.N_DisjList.N_EndModule.N_Except.N_ExceptComponent.N_ExceptSpec.N_Times.N_Extends.N_FairnessExpr.N_FcnAppl.N_FcnConst.N_FieldSet.N_FieldVal.N_FunctionDefinition.N_FunctionParam.N_GeneralId.N_GenInfixOp.N_GenNonExpPrefixOp.N_GenPostfixOp.N_GenPrefixOp.N_IdentDecl.N_Real.N_IdentifierTuple.N_IdentLHS.N_IdPrefix.N_IdPrefixElement.N_IfThenElse.N_InfixDecl.N_InfixExpr.N_InfixLHS.N_InfixOp.N_InnerProof.N_Instance.N_NonLocalInstance.N_Integer.N_LeafProof.N_LetDefinitions.N_LetIn.N_MaybeBound.N_Module.N_ModuleDefinition.N_NonExpPrefixOp.N_Number.N_NumberedAssumeProve.N_OpApplication.N_OpArgs.N_OperatorDefinition.N_OtherArm.N_ParamDecl.N_ParamDeclaration.N_ParenExpr.N_PostfixDecl.N_PostfixExpr.N_PostfixLHS.N_PostfixOp.N_PrefixDecl.N_PrefixExpr.N_PrefixLHS.N_PrefixOp.N_Proof.N_ProofLet.N_ProofName.N_ProofStatement.N_ProofStep.N_QEDStep.N_QuantBound.N_RcdConstructor.N_RecordComponent.N_SetEnumerate.N_SetOfAll.N_SetOfFcns.N_SetOfRcds.N_String.N_SubsetOf.N_Substitution.N_TempDecl.N_Theorem.N_Tuple.N_UnBoundedOrBoundedChoose.N_UnboundedQuant.N_VariableDeclaration.Token =.Token \\in.N_NewSymb.N_Lambda.N_Recursive.N_Label.N_StructOp.N_NumerableStep.N_TerminalProof.N_UseOrHide.N_NonExprBody.N_DefStep.N_HaveStep.N_TakeStep.N_WitnessStep.N_PickStep.N_CaseStep.N_AssertStep`.split(`.`),mu=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
|
|
93
|
+
`)},cc=(e,t)=>{let n=oe(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},l=[],u=e=>i[i.length-1].has(e),d=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),f=[],p=[],m=[],h=e=>{let t=r.index-1,i=e===t?m[e]:void 0;if(i)return i;let a=n[t];f[e]??=d(n[e]),p[t]??={line:a.line,column:a.endColumn};let o={module:l[l.length-1].name,start:f[e],end:p[t]};return e===t&&(m[e]=o),o},g=(e,t)=>(e.location.range=h(t),e),_=(e=0)=>n[Math.min(r.index+e,n.length-1)],v=(e=0)=>{let t=_(e),n=r.offsideColumns[r.offsideColumns.length-1];return n===void 0||n===-1||t.kind===`End`?t:t.column<=n?{...t,kind:`End`,text:``}:t},y=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),ee={index:0},b=e=>{let t=n.slice(ee.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},te=e=>t&&(e.kind===`Keyword`||ac.has(e.text)),re=e=>{let t=n.findLast(t=>t.kind!==`End`&&(t.line<e.line||t.line===e.line&&t.column<e.column));return t?{line:t.line,column:t.endColumn+1}:e},x=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Qs.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):te(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,S=(e,t=_(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new c(`${e} at line ${t.line}, column ${t.column}`,void 0,ie(e,t,a,r))},ie=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...b(re(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${x(a)}`,...re(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},C=(e,t=_())=>S(e,t,t),ae=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!te(e),w=(e,t=0)=>{let n=v(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},T=()=>{let e=v();if(e.kind===`End`)throw S(`Unexpected end of expression`);return r.index++,e},E=e=>w(e)?(r.index++,!0):!1,D=e=>{if(!w(e))throw C(`Expected ${JSON.stringify(e)} but found ${y(v())}`);return T()},O=()=>{let e=v();if(e.kind!==`Identifier`)throw C(`Expected an identifier but found ${y(e)}`);if(te(e))throw C(`Unexpected keyword ${e.text}`);return r.index++,e.text},se=e=>{r.offsideColumns.push(-1);let t=e();return r.offsideColumns.pop(),t},k=(e,t=`,`)=>{let n=[e()];for(;E(t);)n.push(e());return n},ce=()=>{if(w(`<<`)){let e={value:1};for(;v(e.value).kind===`Identifier`||w(`,`,e.value);)e.value++;return w(`>>`,e.value)&&w(`\\in`,e.value+1)}let e={value:0};for(;v(e.value).kind===`Identifier`;){if(w(`\\in`,e.value+1))return!0;if(!w(`,`,e.value+1))return!1;e.value+=2}return!1},le=()=>{if(w(`::`))return!0;if(!w(`(`))return!1;let e={value:1};for(;v(e.value).kind===`Identifier`&&w(`,`,e.value+1);)e.value+=2;return v(e.value).kind===`Identifier`&&w(`)`,e.value+1)&&w(`::`,e.value+2)},ue=()=>{if(!E(`<<`))return{kind:`Name`,name:O()};let e=k(O);return D(`>>`),{kind:`Tuple`,names:e}},de=()=>k(()=>{let e=k(ue);D(`\\in`);let t=N();return e.map(e=>({pattern:e,set:t}))}).flat(),A=()=>{let e=v();if(e.kind===`Identifier`){let t=r.index,n=[T().text];for(;w(`!`)&&v(1).kind===`Identifier`;)T(),n.push(O());return g({kind:`Identifier`,name:n.join(`!`),location:d(e)},t)}if(w(`<<`)||w(`(`))return Se();throw C(`Expected a subscript but found ${y(e)}`)},j=e=>{let t=v(1),n=v(2);return t.kind===`Identifier`&&n.text===`==`?!0:t.line===e.line?!1:t.text===`-.`||t.kind===`Identifier`&&(n.text===`(`||n.text===`[`||n.kind===`Operator`&&w(`==`,Bs.has(n.text)?3:4))},M=e=>{if(!Hs.has(e.text))return!0;let t=v(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||w(`,`,1)||w(`)`,1)||t.kind===`Keyword`&&Js.has(t.text)||j(e)},fe=()=>{let e=v(),n=e.kind===`Operator`&&(zs.has(e.text)||Vs.has(e.text))&&M(e);if(t&&e.kind!==`String`&&(Vs.has(e.text)||Ws.has(e.text)&&e.text!==`'`&&!Bs.has(e.text)||Us.has(e.text)&&v(-1).text===`(`&&v(-1).line===e.line&&v(-1).endColumn+1===e.column&&v(1).text===`)`&&v(1).line===e.line&&v(1).column===e.endColumn+1)&&M(e))throw S(`incomplete expression`,e);if(n)return r.index++,g({kind:`OperatorReference`,operator:e.text,location:d(e)},r.index-1);if(e.kind!==`String`&&Ws.has(e.text)&&M(e)){r.index++;let t=d(e);if(Bs.has(e.text))return{kind:`OperatorReference`,operator:e.text,location:t};let n={kind:`Identifier`,name:`argument`,location:t};return{kind:`Lambda`,params:[n.name],body:Ks(e.text,n,t),location:t}}if(w(`LAMBDA`)){let t=r.index;T();let n=k(O);D(`:`);let i=N();return g({kind:`Lambda`,params:n,body:i,location:d(e)},t)}return N()},pe=()=>se(()=>{D(`(`);let e=k(fe);return D(`)`),e}),me=()=>{let e=T();r.offsideColumns.push(e.column);let t=[N()];for(;_().text===e.text&&_().column===e.column;)r.index++,t.push(N());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:d(e)}},he=e=>se(()=>{let t=d(e);if(v().kind===`Identifier`&&(w(`|->`,1)||w(`:`,1))){let e=w(`|->`,1)?`Record`:`RecordSet`,n=k(()=>{let t=O();return D(e===`Record`?`|->`:`:`),{name:t,value:N()}});return D(`]`),{kind:e,fields:n,location:t}}if(ce()){let e=de();D(`|->`);let n=N();return D(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=N();if(E(`->`)){let e=N();return D(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(E(`EXCEPT`)){let e=k(()=>{D(`!`);let e=[];for(;w(`.`)||w(`[`);)if(E(`.`)){if(!ae(v()))throw C(`Expected a field name but found ${y(v())}`);e.push({kind:`Field`,name:T().text})}else D(`[`),e.push({kind:`Index`,args:k(()=>N())}),D(`]`);return D(`=`),{path:e,value:N()}});return D(`]`),{kind:`Except`,function:n,updates:e,location:t}}return D(`]_`),{kind:`BoxAction`,action:n,subscript:A(),location:t}}),ge=e=>se(()=>{let t=d(e);if(E(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(ce()&&(v(1).text===`\\in`||w(`<<`))){let e=r.index,n=ue();D(`\\in`);let i=N();if(E(`:`)){let e=N();return D(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=N();if(E(`:`)){let e=de();return D(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;E(`,`);)i.push(N());return D(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),_e=e=>{let t=d(e),n=se(()=>w(`>>`)||w(`>>_`)?[]:k(()=>N()));if(E(`>>_`)){if(n.length!==1)throw S(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:A(),location:t}}return D(`>>`),{kind:`Tuple`,elements:n,location:t}},ve=e=>{let t=d(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&ce()){let e=de();return D(`:`),{kind:n,bounds:e,body:N(),location:t}}let i=k(O);return D(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:N(),isTemporal:r,location:t}},ye=e=>{let t=[];do{if(E(`OTHER`))return D(`->`),{kind:`Case`,arms:t,other:N(),location:d(e)};let n=N();D(`->`),t.push({condition:n,body:N()})}while(E(`[]`));return{kind:`Case`,arms:t,other:void 0,location:d(e)}},be=()=>{let e=v(1);return w(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||qs.has(e.text)||e.kind===`Operator`&&(zs.has(e.text)||Bs.has(e.text)||Vs.has(e.text)))},xe=()=>{let e=T();if(e.kind===`Number`)return{kind:`Operand`,operand:ne(e.text)};switch(e.text){case`<<`:case`>>`:return{kind:`Operand`,operand:e.text};case`:`:return{kind:`Colon`};case`@`:return{kind:`At`};case`(`:return r.index--,{kind:`Bound`,args:pe()}}return{kind:`Name`,name:e.text,args:w(`(`)?pe():[]}},Se=()=>{let e=r.index===s.index,n=T(),a=d(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=k(O);return D(`:`),{kind:`Lambda`,params:e,body:N(),location:a}}if(n.kind===`Number`){if(t&&/^\\[BOH]/.test(n.text))throw S(`incomplete expression`,n);return{kind:`Number`,value:ne(n.text),text:n.text,location:a}}if(n.kind===`Decimal`)return{kind:`Decimal`,text:n.text,location:a};if(n.kind===`String`)return{kind:`String`,value:n.text,location:a};let o=n.kind===`Step`&&Fe(n);if(o&&I()<0&&Me.length<=1)throw S(`Step number used outside proof`,n);if(o&&n.text[1]===`+`)throw S(`<+> step number used in an expression`,n);if(n.kind===`Identifier`||o){let r=o?L(n)??n.text:n.text;if(le()){let e=E(`(`)?k(O):[];return e.length>0&&D(`)`),D(`::`),{kind:`Label`,name:r,params:e,body:N(),location:a}}let i=w(`(`),s=i?pe():[];if(!be())return i?{kind:`Apply`,operator:r,args:s,location:a}:{kind:`Identifier`,name:r,location:a};let c=l.flatMap(e=>e.instances).find(e=>e.name===r);if(c&&!e&&!t&&c.params.length!==s.length)throw S(`The operator ${r} requires ${c.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;be();)T(),u.push(xe());let d=u.flatMap(e=>e.kind===`Name`?[e.name]:[]);if(d.length<u.length)return{kind:`Subexpression`,selectors:u,location:a};let f=d.join(`!`),p=u.flatMap(e=>`args`in e?e.args:[]);if(p.length===0)return{kind:`Identifier`,name:f,location:a};let m=u.map(e=>`args`in e?e.args.length:0);return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,location:a}:{kind:`Apply`,operator:f,args:p,location:a}}if(n.kind===`Operator`&&Gs(n.text)&&w(`(`))return{kind:`Apply`,operator:n.text,args:pe(),location:a};switch(n.text){case`(`:{let e=se(()=>N());return D(`)`),e}case`[`:return he(n);case`{`:return ge(n);case`<<`:return _e(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return ve(n);case`IF`:{let e=N();D(`THEN`);let t=N();return D(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:N(),location:a}}case`CASE`:return ye(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!E(`IN`);){if(t&&w(`RECURSIVE`))throw S(`Unexpected keyword RECURSIVE`,b(_()));if(E(`RECURSIVE`)){ke();continue}let r=P(!1);r.kind===`Instance`?n.push(r):e.push(r)}i.pop();let r=N();return n.length===0?{kind:`Let`,definitions:e,body:r,location:a}:{kind:`Let`,definitions:e,instances:n,body:r,location:a}}case`CHOOSE`:{let e=ue(),t=E(`\\in`)?N():void 0;return D(`:`),{kind:`Choose`,pattern:e,set:t,body:N(),location:a}}case`WF_`:case`SF_`:{let e=A(),t=se(()=>{D(`(`);let e=N();return D(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw C(`Unexpected ${y(n)}`,n)},Ce=()=>{let e=v(),t=d(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return me();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return T(),{kind:`Apply`,operator:`~`,args:[N(5)],location:t};case`-`:return T(),{kind:`Apply`,operator:`-.`,args:[N(13)],location:t};case`[]`:return T(),{kind:`Always`,expression:N(16),location:t};case`<>`:return T(),{kind:`Eventually`,expression:N(16),location:t};case`ENABLED`:return T(),{kind:`Enabled`,expression:N(16),location:t};case`UNCHANGED`:return T(),{kind:`Unchanged`,expression:N(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return T(),{kind:`Apply`,operator:e.text,args:[N(9)],location:t}}return Se()},N=(e=0)=>{let t=r.index,n=Ce(),i={left:n.location.range?n:g(n,t),previous:void 0};for(;;){let n=v();if(n.kind!==`Operator`)break;let r=d(n);if(n.text===`'`&&e<=15){T(),i.left=g({kind:`Prime`,expression:i.left,location:r},t);continue}if(Bs.has(n.text)&&e<=15){T(),i.left=g({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){T();let e=se(()=>k(()=>N()));se(()=>D(`]`)),i.left=g({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&ae(v(1))){T();let e=T().text;i.left=g({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=zs.get(n.text);if(!a||a.low<e)break;let o=i.previous;if(o){let e=!(o.low>a.high||o.high<a.low),t=o.text===n.text&&a.isAssociative;if(e&&!t&&(o.text!==`\\X`||n.text!==`\\X`))throw S(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(T(),a.low>12&&w(`-`))throw S(`Precedence conflict between ${n.text} and -`,v());let s=N(a.high+1),c=i.left;if(n.text===`/\\`||n.text===`\\/`){let e=n.text===`/\\`?`And`:`Or`;i.left=c.kind===e&&o?.text===n.text?{...c,operands:[...c.operands,s]}:{kind:e,operands:[c,s],location:r}}else i.left=n.text===`\\X`?c.kind===`Product`&&o?.text===`\\X`?{...c,factors:[...c.factors,s]}:{kind:`Product`,factors:[c,s],location:r}:{kind:`Apply`,operator:n.text,args:[c,s],location:r};i.left=g(i.left,t),i.previous={...a,text:n.text}}return i.left},we=()=>{if(!E(`(`))return[];let e=F();return D(`)`),e},Te=()=>{let e=d(v()),t=N(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:l[l.length-1].name,start:e,end:a}}},P=e=>{let t=r.index;return g(Ee(e),t)},Ee=e=>{let t=v(),n=d(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...Te(),isLocal:e,isRecursive:u(t),location:n});if(t.kind===`Identifier`&&v(1).kind===`Operator`&&zs.has(v(1).text)&&v(2).kind===`Identifier`&&w(`==`,3)){let e=O(),t=T().text,n=O();return D(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&Bs.has(v(1).text)&&w(`==`,2);if(a||o){let e=a?t.text:v(1).text;r.index+=a?1:2;let n=a?O():t.text;return D(`==`),i(e,[{name:n,arity:0}])}let s=O();if(E(`[`)){let t=se(()=>de());return D(`]`),D(`==`),{kind:`Function`,name:s,bounds:t,body:N(),isLocal:e,isRecursive:u(s),location:n}}let c=r.index,l=we();return D(`==`),w(`INSTANCE`)?{...De(s,l,e,n),definitionRange:h(c)}:i(s,l)},De=(e,t,n,i)=>{let a=r.index;return D(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:O(),substitutions:E(`WITH`)?k(()=>{let e=T().text;return D(`<-`),{name:e,expression:fe()}}):[],isLocal:n,location:i,instanceRange:h(a)}},Oe=()=>{let e=d(v());if(w(`_`)&&v(1).kind===`Operator`)return T(),{name:T().text,arity:E(`_`)?2:1,location:e};if(v().kind===`Operator`&&w(`_`,1)){let t=T().text;return T(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=O();if(!E(`(`))return{name:t,arity:0,location:e};let n=k(()=>D(`_`));return D(`)`),{name:t,arity:n.length,location:e}},F=()=>k(Oe),ke=()=>{let e=F();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ae=e=>{let t={value:0,offset:e};do{let e=v(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&rc.has(e.text)&&t.value++,e.kind===`Operator`&&ic.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},je=()=>{let e=v(),t=v(1);return e.kind===`Identifier`?w(`(`,1)||w(`[`,1)?w(`==`,Ae(1)):t.kind===`Operator`&&Bs.has(t.text)?w(`==`,2):t.kind===`Operator`&&zs.has(t.text)?v(2).kind===`Identifier`&&w(`==`,3):w(`==`,1):w(`-.`)&&t.kind===`Identifier`&&w(`==`,2)},Me=[],I=()=>Me[Me.length-1]??-1,Ne=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),Pe=e=>{let t=e.text.slice(e.text.indexOf(`>`)+1),n={value:t.length};for(;t[n.value-1]===`.`;)n.value--;return t.slice(0,n.value)},Fe=e=>!e.text.endsWith(`.`)&&!$s.has(Pe(e)),L=e=>{let t=Pe(e);if($s.has(t))return;let n=Ne(e);if(n>=0)return`<${n}>${t}`;let r=I(),i=Me[Me.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Ie=e=>{if(e.kind===`Keyword`)return Xs.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Me.length===0;if(e.text[1]===`+`||Me.length===0)return!0;let t=I();return t>=0&&Ne(e)>t},Le=e=>{let t=Ne(e),n=Me.length-1,r=Me[n-1]??-1,i=Me[n]<0;return i&&(Me[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Me[n]===t},Re=e=>!a.has(e)&&l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),ze=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!ac.has(e.name)&&!Re(e.name):!1,Be=()=>{let e=v();return e.kind===`Step`?Fe(e):e.kind===`Keyword`?ec.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!je()},Ve=()=>{let e=r.index;s.index=e;let t=v();return t.kind===`Operator`&&!Hs.has(t.text)&&Gs(t.text)?(r.index++,g({kind:`OperatorReference`,operator:t.text,location:d(t)},e)):E(`MODULE`)?g({kind:`ModuleFact`,name:O(),location:d(t)},e):N()},He=e=>o[o.length-1]?.add(e),Ue=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},We=e=>o.some(t=>t.has(e))||l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Ge=()=>{let e=r.index,t=v(),n=k(()=>{let e=v();if((e.kind!==`Identifier`||te(e))&&e.kind!==`Operator`)throw C(`Expected a definition name but found ${y(e)}`,e);return r.index++,e.text},`!`),i=d(t);return g(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ke=()=>{if(t)return k(Ge);let e=k(Ve),n=e.find(e=>e.kind===`Identifier`&&We(e.name));if(n)throw S(`DEF clause entry should describe a defined operator`,n.location);return e},qe=()=>({facts:Be()?k(Ve):[],defs:E(`DEF`)||E(`DEFS`)?Ke():[]}),Je=()=>{let e=r.index,n=T(),i=n.text===`USE`&&E(`ONLY`),a=h(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...qe(),keyword:a,location:d(n)},s=o.kind===`Hide`&&!t?o.facts.find(e=>!ze(e)):void 0;if(s)throw S(`The only expression allowed as a fact in a HIDE is the name of a theorem, assumption, or step`,s.location);return g(o,e)},Ye=()=>{let e=r.index,t=d(v()),n=E(`NEW`),i=v().kind===`Keyword`?tc.get(v().text):void 0;if(!n&&i===void 0)throw C(`Expected a declaration but found ${y(v())}`);if(i!==void 0&&T(),i===`Variable`){let n=O();return He(n),g({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Oe();He(a.name);let o=(i??`Constant`)===`Constant`&&w(`\\in`);if(o&&a.arity>0)throw S(`declared symbol with arguments before \\in`);return o&&T(),g({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?N():void 0,location:t},e)},Xe=()=>{let e=r.index,t=d(D(`ASSUME`)),n=k(()=>w(`ASSUME`)?Ue(Xe):v().kind===`Keyword`&&nc.has(v().text)?Ye():N());return D(`PROVE`),g({kind:`AssumeProve`,assumptions:n,conclusion:N(),location:t},e)},Ze=e=>{let t={value:0};for(;v(t.value).kind===`Identifier`&&w(`,`,t.value+1);)t.value+=2;return v(t.value).kind===`Identifier`&&w(e,t.value+1)},Qe=(e,t)=>{e.forEach(He),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(He))},$e=()=>{let e=v();if(w(`USE`)||w(`HIDE`))return Je();if(w(`INSTANCE`))return g(De(void 0,[],!1,d(e)),r.index);if(w(`DEFINE`)||je()){let t=r.index;E(`DEFINE`);let n=[P(!1)];for(;je();)n.push(P(!1));let i={kind:`Define`,definitions:n,location:d(e)};return g(i,t)}if(E(`HAVE`))return{kind:`Have`,expression:N()};if(E(`TAKE`)){let e=ce(),t=e?[]:k(O),n=e?de():[];return Qe(t,n),{kind:`Take`,names:t,bounds:n}}if(E(`WITNESS`))return{kind:`Witness`,expressions:k(()=>N())};if(E(`PICK`)){let e=Ze(`:`),t=e?k(O):[],n=e?[]:de();return Qe(t,n),D(`:`),{kind:`Pick`,names:t,bounds:n,body:N()}}return E(`CASE`)?{kind:`Case`,expression:N()}:{kind:`Assert`,isSuffices:E(`SUFFICES`),statement:w(`ASSUME`)?Xe():N()}},et=e=>{let t=v();if(t.kind!==`Step`)throw C(`Expected a step number but found ${y(t)}`,t);if(!Le(t))throw S(`${e?`QED step`:`step`}'s number has bad level`,t);if(Ne(t)<0&&L(t)!==void 0)throw S(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:L(t),token:t.text,location:d(t)}},tt=()=>{let e=r.index,t=et(w(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=E(`QED`)?{kind:`Qed`}:$e(),a=h(e),s=Ie(v());if(s&&!Zs.has(i.kind))throw S(`Proof of a step that does not take a proof`);let c=s?rt():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(He),g({...t,body:i,head:a,proof:c},e)},nt=()=>{let e=d(v());if(w(`BY`)||w(`PROOF`)&&w(`BY`,1)){E(`PROOF`),T();let t=h(r.index-1);return{kind:`By`,isOnly:E(`ONLY`),...qe(),keyword:t,location:e}}let t=v(+!!w(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){E(`PROOF`),T();let n=h(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}E(`PROOF`);let n=[tt()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(tt());return{kind:`Steps`,level:I(),steps:n,location:e}},rt=()=>{let e=r.index;Me.push(-1);let t=Ue(nt);return Me.pop(),g(t,e)},it=e=>{let t=r.index,n=T(),i=v().kind===`Identifier`&&w(`==`,1)?O():void 0;i!==void 0&&(a.add(i),T());let o=Ue(()=>({statement:w(`ASSUME`)?Xe():N(),proof:Ie(v())?rt():void 0})),s=o.statement,c=g({name:i,statement:s,proof:o.proof,location:d(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(g({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:d(n)},t))},at=()=>{let e=r.index;return g(ot(),e)},ot=()=>{let e=T(),t=d(e),n=e.text===`AXIOM`;if(v().kind===`Identifier`&&w(`==`,1)){let e=O();return a.add(e),T(),{name:e,expression:N(),isAxiom:n,location:t}}return{name:void 0,expression:N(),isAxiom:n,location:t}},st=()=>{let e=d(D(`----`));D(`MODULE`);let t=O();D(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(l.push(n),i.push(/* @__PURE__ */ new Set),E(`EXTENDS`)&&k(()=>{let e=r.index;n.extends.push(O()),n.extendsRanges.push(h(e))});;){let a=r.index;ee.index=a;let o=v();if(o.kind===`ModuleEnd`||o.kind===`End`)return o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),l.pop(),i.pop(),n;if(o.kind===`Separator`){if(w(`MODULE`,1)){let e=st();n.modules.push(e),n.units.push({kind:`Module`,module:e}),D(`====`);continue}T()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{T();let e=F();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{T();let e=k(()=>{let e=r.index,t=d(v());return g({name:O(),arity:0,location:t},e)});n.variables.push(...e),n.units.push({kind:`Variables`,declarations:e});continue}case`ASSUME`:case`ASSUMPTION`:case`AXIOM`:{let e=at();n.assumptions.push(e),n.units.push({kind:`Assumption`,assumption:e}),e.name!==void 0&&n.definitions.push({kind:`Operator`,name:e.name,params:[],body:e.expression,isLocal:!1,isRecursive:!1,location:e.location});continue}case`USE`:case`HIDE`:{let e=Je();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:T(),n.units.push({kind:`Recursive`,declarations:ke()});continue;case`INSTANCE`:ct(n,g(De(void 0,[],!1,d(o)),a));continue;case`LOCAL`:if(T(),w(`INSTANCE`)){ct(n,g(De(void 0,[],!0,d(o)),a));continue}ct(n,P(!0));continue}o.kind===`Keyword`&&Ys.has(o.text)?it(n):ct(n,P(!1))}}},ct=(e,t)=>{t.kind===`Instance`?(e.instances.push(t),e.units.push({kind:`Instance`,instance:t})):(e.definitions.push(t),e.units.push({kind:`Definition`,definition:t}))};return st()},lc=e=>cc(e,!1),uc=e=>cc(e,!0),dc=25214903917n,fc=(1n<<48n)-1n,pc=2147483647,mc=e=>{let t={value:(BigInt.asUintN(64,e)^dc)&fc},n=e=>(t.value=t.value*dc+11n&fc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^dc)&fc},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=pc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},hc=10454148508367108822n,gc=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:hc);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),_c=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e>>32n))),vc=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e))),yc=Number(BigInt.asIntN(32,hc>>32n)),bc=Number(BigInt.asIntN(32,hc));let xc=yc,Sc=bc;const Cc=e=>{let t=(e^Sc)&255;Sc=(Sc>>>8|xc<<24)^vc[t],xc=xc>>>8^_c[t]},wc=e=>{for(let t=0;t<32;t+=8)Cc(e>>>t)},Tc=e=>{if(typeof e==`boolean`)Cc(0),Cc(e?116:102);else if(typeof e==`number`)Cc(1),wc(e);else if(typeof e==`string`){Cc(3),wc(e.length);for(let t=0;t<e.length;t++)Cc(e.charCodeAt(t))}else if(M(e))Cc(21),wc(De(e.name)+1);else if(j(e)){let t=H(e);Cc(9),wc(t.domain.length);for(let e=0;e<t.domain.length;e++)Tc(t.domain[e]),Tc(t.range[e])}else{let t=B(e).elements;Cc(5),wc(t.length);for(let e of t)Tc(e)}},Ec=e=>{let t={high:xc,low:Sc};xc=yc,Sc=bc;for(let t of e)Tc(t);let n=BigInt(xc>>>0)<<32n|BigInt(Sc>>>0);return xc=t.high,Sc=t.low,n},Dc=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||M(e))return 5;if(typeof e==`string`)return 5+e.length;if(j(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+Dc(n)+Dc(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+Dc(t),5)},Oc=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){xc=n<32?0:1<<n-32,Sc=n<32?1<<n:0;for(let t=0;t<e;t++)Cc(0);let r=n>>3,i=1<<(n&7);for(let e=i;e<2*i;e++){let n=(r*256+e)*2,a=(r*256+e-i)*2;t[n]=t[a]^xc,t[n+1]=t[a+1]^Sc}}return t},kc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=[],r=e=>{let r=t.get(e);if(r!==void 0)return r;let i=Dc(e);return xc=0,Sc=0,Tc(e),t.set(e,n.length),n.push(i,xc,Sc),n.length-3},i=t=>{let n=e.get(t);if(n)return n;let r=Oc(t);return e.set(t,r),r};return e=>{let t={high:xc,low:Sc},a={high:yc,low:bc};for(let t of e){let e=r(t),o=i(n[e]),s={high:n[e+1],low:n[e+2]};for(let e=0;e<8;e++){let t=e<4?a.low:a.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=o[n],s.low^=o[n+1]}a.high=s.high,a.low=s.low}return xc=t.high,Sc=t.low,BigInt(a.high>>>0)<<32n|BigInt(a.low>>>0)}},Ac=[],jc=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Mc=()=>{for(let e=1277011;Ac.length<1341;e++)jc(e)&&Ac.push(e);return Ac},Nc=e=>{let t=Mc(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Pc=e=>{let t=[],n={value:e};for(let e=2;e*e<=n.value;e++)for(;n.value%e===0;)t.push(e),n.value/=e;return n.value>1&&t.push(n.value),t},Fc=e=>{for(let t=Math.max(e,9);;t++){let e=Pc(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Ic=(e,t,n)=>{if(t<=0)return[];let r=Fc(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Nc(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Lc=(1n<<63n)-1n-24n,Rc=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Lc*BigInt(n)+i)%t;return r<0n?r+t:r})},zc=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Bc=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Tt(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>L(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>Dt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Vc=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ic(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=Bc(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(pc)?Rc(e,t,n):Ic(e,Number(t),n)).map(e=>r.create(zc(r.lists,e)))}let i=B(t).elements;return Ic(e,i.length,n).map(e=>i[Number(e)])},Hc=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new u(`RandomElement of the empty set`);return n},Uc=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Tt(e.domain)];return L(n,n.map(()=>Uc(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Dt(e.names.map((n,r)=>[n,Uc(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Uc(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.floor(t.nextDouble()*n);if(r>=n)throw new u(`RandomElement of the empty set`);return e.low+r}return Hc(B(e).elements,t)},Wc=(e,t=0n)=>{let n=mc(t),r={random:mc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Dt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Ec,getRandom:()=>{let e=i.isStartup?void 0:a.getCurrentState();return e===void 0?n:(e!==r.state&&(r.random.setSeed(a.getFingerprint(e)^BigInt.asUintN(64,t)),r.state=e),r.random)},evaluateAtStartup:e=>{let t=i.isStartup;i.isStartup=!0;try{return e()}finally{i.isStartup=t}},pause:()=>{},seed:t,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,isStopped:!1,checkDeadlock:e,startedAt:Date.now()};return a},Gc=e=>_t([...e.possibleCounts].map(([e,t])=>[e,t])),Kc=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Gc(e)]]),qc=(e,t,n)=>new d(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Jc=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Yc=e=>j(e)?H(e):void 0,Xc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw qc(n,`a function with a finite domain`,r);return i},Zc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw Jc(t===0?`first`:`second`,n,`bag`,r);return i},Qc=(e,t)=>{if(!A(e)||!z(e))throw t();return B(e).elements},$c=e=>e.range.every(e=>typeof e==`number`&&e>0),el=(e,t)=>{let n=e.domain.findIndex(e=>Ie(e,t));return n===-1?void 0:e.range[n]},tl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,nl=tl(`BagDiff`,`tlc2.value.impl.Value`,2),rl=tl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),il=tl(`BagUnion`,`tlc2.value.impl.Value`,1),al=tl(`BagOfAll`,`tlc2.value.impl.Value`,2),ol=tl(`BagCup`,`tlc2.value.impl.Value`,2),sl=tl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),cl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${$n(e)}`;throw tr(t,`class ${n} cannot be cast to class tlc2.value.impl.IntValue (${n} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`)},ll=(e,t,n)=>{let r=cl(e,n)+cl(t,n);if(Jn(r))throw Yn(`${e}+${t}`);return r},ul=(e,t,n,r)=>{let i=el(n,e.domain[t]),a=cl(e.range[t],r);return i===void 0?a:a-cl(i,r)|0},dl=(e,t)=>_t(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>Ie(e[0],r));a?a[1]=ll(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),fl=L([],[]),pl=[Wn(`EmptyBag`,fl),K(`IsABag`,1,e=>{let t=Yc(G(e,0,`IsABag`));return t!==void 0&&$c(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Xc(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw qc(`BagCardinality`,`a bag`,t);return ll(e,n,sl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=el(Xc(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Jc(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=el(Xc(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Jc(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Zc(e,t,`(+)`);if(!$c(n))throw Jc(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return dl(t,ol)}),K(`\\ominus`,2,e=>{let t=Zc(e,0,`(-)`),n=Zc(e,1,`(-)`);return _t(t.domain.flatMap((e,r)=>{let i=ul(t,r,n,nl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Qc(t,()=>qc(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??fl;let r=n.map(e=>{let n=Yc(e);if(!n)throw new d(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return dl(r,il)}),K(`\\sqsubseteq`,2,e=>{let t=Xc(e,0,`\\sqsubseteq`),n=Xc(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>ul(t,r,n,rl)<=0)}),Gn(`BagOfAll`,2,e=>{let t=Un(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new d(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Yc(n);if(!r)throw Jc(`second`,`BagOfAll`,`function with a finite domain`,n);return dl(r.domain.map((e,n)=>L([t.call([e])],[r.range[n]])),al)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!j(t))throw new u(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=dt(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new u(`The ${e?`first`:`second`} argument of >= should be an integer, but instead it is:\n${U(e?r[0]:i)}`)}let a=n.range.filter(e=>typeof e==`number`);if(a.some(e=>e<1))throw new u(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return dt(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>L(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>nn(Xc(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Qc(t,()=>qc(`BagToSet`,`a function with a finite domain`,t));return L([...n],n.map(()=>1))})],ml=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,hl=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,gl=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,_l=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,vl=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,yl=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,bl=e=>{if(!j(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},xl=(e,t)=>tr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${$n(t)}`),Sl=(e,t)=>tr(e,`Cannot cast tlc2.value.impl.${$n(t)} to tlc2.value.impl.StringValue`),Cl=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),wl=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw xl(t,e);return`[${B(e).elements.map(e=>El(e,t)).join(`,`)}]`},Tl=(e,t)=>{let n=H(e),r=Gt(n);return r?`[${r.map(e=>El(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${Cl(typeof e==`string`?e:U(e))}:${El(n.range[r],t)}`).join(`,`)}}`},El=(e,t)=>typeof e==`string`?Cl(e):typeof e==`object`?e.kind===`ModelValue`?Cl(e.name):A(e)?wl(e,t):Tl(e,t):String(e),Dl=e=>{if(A(e))return wl(e,ml);if(!j(e)||bl(e))throw xl(ml,e);return Tl(e,ml)},Ol=e=>{if(!j(e))throw xl(hl,e);return Tl(e,hl)},kl=e=>{let[,t,n=`0`,r=``,i=`0`]=/^(-?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(e)??[],a=BigInt(n+r),o=Number(i)-r.length,s=o>=0?a*10n**BigInt(o):a/10n**BigInt(-o);return Number(BigInt.asIntN(32,t===`-`?-s:s))},Al=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return P(e);if(Array.isArray(e))return R(e.map(e=>Al(e,t)));if(typeof e==`object`&&e)return Dt(Object.entries(e).map(([e,n])=>[P(e),Al(n,t)]));throw tr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},jl=(e,t)=>{if(e.trim()===``)return Al(null,t);try{return Al(JSON.parse(e,(e,t,n)=>typeof t==`number`?kl(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?tr(t,e.message):e}},Ml=(e,t)=>{if(typeof e!=`string`)throw Sl(t,e);return e},Nl=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw tr(n,`${t} (No such file or directory)`);return r},Pl=e=>[Kn(`ToJson`,1,e=>P(El(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Kn(`ToJsonArray`,1,e=>P(Dl(G(e,0,`ToJsonArray`)))),Kn(`ToJsonObject`,1,e=>P(Ol(G(e,0,`ToJsonObject`)))),Kn(`JsonSerialize`,2,t=>{let n=Ml(G(t,0,`JsonSerialize`),gl),r=G(t,1,`JsonSerialize`);if(!Gt(r)&&!bl(r))throw new d(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,El(r,gl)),!0}),Kn(`ndJsonSerialize`,2,t=>{let n=Ml(G(t,0,`ndJsonSerialize`),_l),r=G(t,1,`ndJsonSerialize`),i=Gt(r);if(!i)throw new d(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${El(e,_l)}\n`).join(``)),!0}),Kn(`JsonDeserialize`,1,t=>{let n=Ml(G(t,0,`JsonDeserialize`),vl);return jl(Nl(e,n,vl),vl)}),Kn(`ndJsonDeserialize`,1,t=>{let n=Ml(G(t,0,`ndJsonDeserialize`),yl);return R(Nl(e,n,yl).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>jl(e,yl)))})],Fl=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Il=(e,t,n)=>{if(typeof e!=`number`||e<0)throw Fl(t,n,`nonnegative integer`,U(e));return e},Ll=(e,t,n,r)=>{if(!A(e)||!z(e))throw Fl(t,n,r,U(e));return B(e).elements},Rl=(e,t,n,r)=>dt(Array.from({length:t},()=>dt(e.filter(()=>r.nextDouble()<n)))),zl=(e,t)=>{let n=`RandomSetOfSubsets`,r=Il(G(e,0,n),`first`,n),i=Il(G(e,1,n),`second`,n),a=Ll(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw Fl(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw Fl(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Rl(a,r,a.length===0?0:i/a.length,t.getRandom())},Bl=e=>[Kn(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw Fl(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new u(`Attempted to apply the operator overridden by the Java method\npublic static tlc2.value.impl.Value tlc2.module.Randomization.RandomSubset(tlc2.value.impl.Value,tlc2.value.impl.Value),\nbut it produced the following error:\n${n}`);let r=G(t,1,`RandomSubset`);if(!A(r)||!V(r)&&!z(r))throw Fl(`second`,`RandomSubset`,`a finite set`,U(r));return dt(Vc(n,r,e.getRandom()))}),Kn(`RandomSetOfSubsets`,3,t=>zl(t,e)),Kn(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(zl(t,e)).elements.length)))],Vl=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Hl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Vl})`,Ul=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Vl}) throws java.io.IOException`,Wl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Vl})`,Gl=()=>Dt([[`action`,dt([])],[`state`,dt([])]]),Kl=()=>Dt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ql=e=>Dt([[`name`,e??`UnnamedAction`],[`location`,Kl()]]),Jl=(e,t)=>{let n=e.map((e,t)=>R([t+1,Dt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ql(e[r+1].action),t])),i=t?[R([n[n.length-1],ql(t.action),n[t.start]])]:[];return Dt([[`action`,dt([...r,...i])],[`state`,dt(n)]])},Yl=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Kc(e).get(t)},Xl=(e,t,n)=>{if(typeof t==`number`&&t>=0)e.registers.set(t,n);else if(typeof t==`string`&&t.startsWith(`s:`))e.namedRegisters.set(t,n);else throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(t)}`)},Zl=e=>e.every(e=>e!==void 0),Ql=(e,t)=>Dt(t.variables.map((t,n)=>[t,e[n]])),$l=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(e.kind===`Prime`||e.kind===`Unchanged`)return!0;if(r!==void 0&&!W(e)){if(t.variableIndex.has(r))return!0;let e=qa(r,t);if(e&&!n.has(e)&&(n.add(e),$l(e.body,t,n)))return!0}return jn(e).some(e=>$l(e,t,n))},eu=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new WeakMap,i=e=>{let t=r.get(e)??/* @__PURE__ */ new Map;return r.set(e,t),t};return[K(`AssertEq`,2,t=>{let n=G(t,0,`AssertEq`),r=G(t,1,`AssertEq`),i=Ie(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),cr(`AssertError`,2,e=>{let t=Un(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw tr(Hl,`In computing AssertError, a non-string expression (line ${t.location.line}, col ${t.location.column}) was used as the err of an AssertError(err, exp).`);let n=lr(e,0,`AssertError`)();try{lr(e,1,`AssertError`)()}catch(e){if(e instanceof u)return e.message===n;throw e}return!1}),Kn(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Yl(t,n)??G(e,1,`TLCGetOrDefault`)}),{...Gn(`TLCGetAndSet`,4,e=>{let n=G(e,0,`TLCGetAndSet`),r=Yl(t,n)??G(e,3,`TLCGetAndSet`),i=Un(e,1,`TLCGetAndSet`);return Xl(t,n,i.call([r,G(e,2,`TLCGetAndSet`)])),r}),isStateLevel:!0},Kn(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Zl(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw tr(Ul,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return R(t.getBehavior(r).map(e=>Ql(e,n.environment)))}),Kn(`CounterExample`,0,()=>t.counterExample??Gl()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!j(t)||!Ie(nn(t),dt([`action`,`state`])))throw new u(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(en(t,`state`)).elements.map(e=>Gt(e)??[]);return R(n.sort((e,t)=>Number(e[0])-Number(t[0])).map(e=>e[1]))}),K(`TLCModelValue`,1,e=>{let t=G(e,0,`TLCModelValue`);if(typeof t!=`string`)throw new d(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Pe(t)}),cr(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),cr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Zl(r))throw tr(Wl,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Ka(lr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new m(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),cr(`TLCCache`,2,(e,t)=>{let r=Un(e,0,`TLCCache`),a=xn(lr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=$l(o,t.environment,/* @__PURE__ */ new Set)&&t.state?i(t.state):n,c=s.get(o)??/* @__PURE__ */ new Map;s.set(o,c);let l=c.get(a);if(l!==void 0)return l;let u=r.call([]);return c.set(a,u),u}),K(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Ec([G(e,0,`TLCFP`)])))),Kn(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?qa(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new d(`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${U(n)}`);if(r.kind===`Operator`&&r.params.length>0)throw new d(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return X({kind:`Identifier`,name:n,location:r.location},t)})]},tu=(e,t)=>[Kn(`_Track`,2,e=>{let n=String(G(e,1,`_Track`)),r=t.possibleCounts.get(n)??0;return t.possibleCounts.set(n,G(e,0,`_Track`)===!0?r+1:r),!0}),Kn(`_Counts`,0,()=>Gc(t)),Kn(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(Gc(t),!0)),!1)}),Kn(`_PrintCounts`,0,()=>(e(U(Gc(t),!0)),!0))],nu=e=>String(e).padStart(2,`0`),ru=e=>`${e.getUTCFullYear()}.${nu(e.getUTCMonth()+1)}.${nu(e.getUTCDate())}.${nu(e.getUTCHours())}${nu(e.getUTCMinutes())}${nu(e.getUTCSeconds())}`,iu=e=>_t([...e].map(([e,t])=>[e,R([t])])),au=(e,t,n)=>{let r=Math.floor((Date.now()-e.startedAt)/1e3);switch(t){case`level`:return n===void 0?0:e.getLevel(n);case`diameter`:return e.diameter;case`generated`:return e.generatedStates;case`distinct`:return e.distinctStates;case`queue`:return e.queueSize;case`duration`:return r;case`stats`:return Dt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Dt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Dt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,P(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,P(ru(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ql(void 0);case`all`:return iu(e.registers);case`all:named`:return iu(Kc(e))}if(t.startsWith(`s:`)){let n=Kc(e).get(t);if(n===void 0)throw new d(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return P(e.properties.get(t.slice(2))??t);throw new d(`TLCGet(${t}) was undefined.`)},ou=e=>e.length===0?[[]]:e.flatMap((t,n)=>ou([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),su=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(su),e.kind===`Function`&&e.range.forEach(su))},cu=(t,n)=>[K(`Print`,2,e=>(t(`${de(U(G(e,0,`Print`),!0,!0))} ${de(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(de(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new d(`The first argument of Assert evaluated to FALSE; the second argument was:\n${de(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>_t([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=Hn(e,0,`@@`),n=Hn(e,1,`@@`);return vt([...ge(t),...ge(n)])}),K(`ToString`,1,e=>P(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return su(t),t}),K(`Permutations`,1,e=>{let t=Bn(e,0,`Permutations`);return dt(ou(t).map(e=>_t(t.map((t,n)=>[t,e[n]]))))}),Gn(`SortSeq`,2,e=>{let t=Un(e,1,`SortSeq`);return R(Vn(e,0,`SortSeq`).reduce((e,n)=>{let r=e.findIndex(e=>t.call([n,e])===!0);return r===-1?[...e,n]:[...e.slice(0,r),n,...e.slice(r)]},[]))}),Kn(`TLCGet`,1,(e,t)=>{let r=G(e,0,`TLCGet`);if(typeof r==`number`&&r>=0){let e=n.registers.get(r);if(e===void 0)throw new d(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new d(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return au(n,r,t?.state)}),Kn(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`),i=G(e,1,`TLCSet`);if(typeof r==`number`&&r>=0)return n.registers.set(r,i),!0;if(r===`exit`)return i===!0&&(n.isStopped=!0),!0;if(r===`pause`)return i===!0&&(t(`Press enter to resume model checking.`),n.pause()),!0;if(typeof r==`string`&&r.startsWith(`s:`))return n.namedRegisters.set(r,i),!0;if(typeof r==`string`&&r.startsWith(`-D`))return n.properties.set(r.slice(2),U(i)),!0;throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(r)}`)}),Wn(`Any`,je),K(`RandomElement`,1,e=>Uc(Rn(e,0,`RandomElement`),n.getRandom()))],lu=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices`.split(`,`),uu=[[`\\lnot`,`~`,`\\neg`,`¬`],[`[]`,`□`],[`<>`,`◇`],[`\\land`,`/\\`,`∧`],[`\\lor`,`\\/`,`∨`],[`\\equiv`,`<=>`,`≡`,`⇔`],[`/=`,`#`,`≠`],[`\\leq`,`<=`,`=<`,`≤`],[`\\geq`,`>=`,`≥`],[`\\times`,`\\X`,`×`],[`\\intersect`,`\\cap`,`∩`],[`\\union`,`\\cup`,`∪`],[`\\o`,`\\circ`,`∘`],[`\\oplus`,`(+)`,`⊕`],[`\\ominus`,`(-)`,`⊖`],[`\\odot`,`(.)`,`⊙`],[`\\oslash`,`(/)`,`⊘`],[`\\otimes`,`(\\X)`,`⊗`],[`\\approx`,`≈`],[`:=`,`≔`],[`\\asymp`,`≍`],[`\\bigcirc`,`◯`],[`::=`,`⩴`],[`\\bullet`,`●`],[`\\cdot`,`⋅`],[`\\cong`,`≅`],[`\\div`,`÷`],[`\\doteq`,`≐`],[`..`,`‥`],[`...`,`…`],[`!!`,`‼`],[`\\gg`,`≫`],[`=>`,`⇒`],[`\\in`,`∈`],[`=|`,`⫤`],[`~>`,`↝`],[`\\ll`,`≪`],[`-|`,`⊣`],[`\\notin`,`∉`],[`-+->`,`⇸`],[`\\prec`,`≺`],[`\\preceq`,`⪯`],[`\\propto`,`∝`],[`??`,`⁇`],[`|=`,`⊨`],[`|-`,`⊢`],[`\\sim`,`∼`],[`\\simeq`,`≃`],[`\\sqcap`,`⊓`],[`\\sqcup`,`⊔`],[`\\sqsubset`,`⊏`],[`\\sqsubseteq`,`⊑`],[`\\sqsupset`,`⊐`],[`\\sqsupseteq`,`⊒`],[`\\star`,`⋆`],[`\\subset`,`⊂`],[`\\subseteq`,`⊆`],[`\\succ`,`≻`],[`\\succeq`,`⪰`],[`\\supset`,`⊃`],[`\\supseteq`,`⊇`],[`\\uplus`,`⊎`],[`||`,`‖`],[`\\wr`,`≀`],[`^+`,`⁺`]],du=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices,***I do not exist***,--TLA+ BUILTINS--,Formal_0,Formal_1,Formal_2,[,^,/,*,-,-.,+,^+,^*,^#,<,\\leq,>,\\geq,...,..,|,||,&&,&,$$,$,??,%%,%,##,++,--,**,//,^^,@@,!!,|-,|=,-|,=|,<:,:>,:=,::=,\\oplus,\\ominus,\\odot,\\oslash,\\otimes,\\uplus,\\sqcap,\\sqcup,\\div,\\wr,\\star,\\o,\\bigcirc,\\bullet,\\prec,\\succ,\\preceq,\\succeq,\\sim,\\simeq,\\ll,\\gg,\\asymp,\\subset,\\supset,\\supseteq,\\approx,\\cong,\\sqsubset,\\sqsubseteq,\\sqsupset,\\sqsupseteq,\\doteq,\\propto,~,¬,□,◇,/\\,∧,\\/,∨,<=>,≡,⇔,#,≠,<=,=<,≤,>=,≥,\\X,×,\\cap,∩,\\cup,∪,\\circ,∘,(+),⊕,(-),⊖,(.),⊙,(/),⊘,(\\X),⊗,≈,≔,≍,◯,⩴,●,⋅,≅,÷,≐,‥,…,‼,≫,⇒,∈,⫤,↝,≪,⊣,∉,⇸,≺,⪯,∝,⁇,⊨,⊢,∼,≃,⊓,⊔,⊏,⊑,⊐,⊒,⋆,⊂,⊆,≻,⪰,⊃,⊇,⊎,‖,≀,⁺,@`.split(`,`),fu=/* @__PURE__ */ `exit.pause.config.spec.coverage.action.install.id.behavior.all.mode.deadlock.seed.fingerprint.worker.traces.depth.aril.sched.revision.timestamp.date.count.tag.calver.impliedinits.impliedactions.invariants.impliedtemporals.temporals.actions.inits.variables.actionconstraints.constraints.stats.duration.generated.diameter.distinct.initial.queue.retries.distinctvalues.levelmean.levelvariance.bfs`.split(`.`),pu=/* @__PURE__ */ `Not a node.N_ActDecl.N_ActionExpr.N_AssumeDecl.N_AssumeProve.N_Assumption.N_BeginModule.N_Body.N_BoundedQuant.N_Case.N_CaseArm.N_CaseStatement.N_ChooseStatement.N_ConjItem.N_ConjList.N_ConsDecl.N_DisjItem.N_DisjList.N_EndModule.N_Except.N_ExceptComponent.N_ExceptSpec.N_Times.N_Extends.N_FairnessExpr.N_FcnAppl.N_FcnConst.N_FieldSet.N_FieldVal.N_FunctionDefinition.N_FunctionParam.N_GeneralId.N_GenInfixOp.N_GenNonExpPrefixOp.N_GenPostfixOp.N_GenPrefixOp.N_IdentDecl.N_Real.N_IdentifierTuple.N_IdentLHS.N_IdPrefix.N_IdPrefixElement.N_IfThenElse.N_InfixDecl.N_InfixExpr.N_InfixLHS.N_InfixOp.N_InnerProof.N_Instance.N_NonLocalInstance.N_Integer.N_LeafProof.N_LetDefinitions.N_LetIn.N_MaybeBound.N_Module.N_ModuleDefinition.N_NonExpPrefixOp.N_Number.N_NumberedAssumeProve.N_OpApplication.N_OpArgs.N_OperatorDefinition.N_OtherArm.N_ParamDecl.N_ParamDeclaration.N_ParenExpr.N_PostfixDecl.N_PostfixExpr.N_PostfixLHS.N_PostfixOp.N_PrefixDecl.N_PrefixExpr.N_PrefixLHS.N_PrefixOp.N_Proof.N_ProofLet.N_ProofName.N_ProofStatement.N_ProofStep.N_QEDStep.N_QuantBound.N_RcdConstructor.N_RecordComponent.N_SetEnumerate.N_SetOfAll.N_SetOfFcns.N_SetOfRcds.N_String.N_SubsetOf.N_Substitution.N_TempDecl.N_Theorem.N_Tuple.N_UnBoundedOrBoundedChoose.N_UnboundedQuant.N_VariableDeclaration.Token =.Token \\in.N_NewSymb.N_Lambda.N_Recursive.N_Label.N_StructOp.N_NumerableStep.N_TerminalProof.N_UseOrHide.N_NonExprBody.N_DefStep.N_HaveStep.N_TakeStep.N_WitnessStep.N_PickStep.N_CaseStep.N_AssertStep`.split(`.`),mu=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
|
|
94
94
|
Nat == { }
|
|
95
95
|
a+b == {a, b}
|
|
96
96
|
a-b == CHOOSE n : b + n = a
|
package/package.json
CHANGED
package/src/tlc-ext.ts
CHANGED
|
@@ -103,35 +103,15 @@ const getRegister = (runtime: CheckerRuntime, key: Value) => {
|
|
|
103
103
|
return undefined;
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
export const setTlcValue = (
|
|
108
|
-
runtime: CheckerRuntime,
|
|
109
|
-
print: (text: string) => void,
|
|
110
|
-
key: Value,
|
|
111
|
-
value: Value,
|
|
112
|
-
) => {
|
|
106
|
+
const setRegister = (runtime: CheckerRuntime, key: Value, value: Value) => {
|
|
113
107
|
if (typeof key === "number" && key >= 0) {
|
|
114
108
|
runtime.registers.set(key, value);
|
|
115
109
|
return;
|
|
116
110
|
}
|
|
117
|
-
if (key === "exit") {
|
|
118
|
-
if (value === true) runtime.isStopped = true;
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (key === "pause") {
|
|
122
|
-
if (value !== true) return;
|
|
123
|
-
print("Press enter to resume model checking.");
|
|
124
|
-
runtime.pause();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
111
|
if (typeof key === "string" && key.startsWith(NAMED_REGISTER_PREFIX)) {
|
|
128
112
|
runtime.namedRegisters.set(key, value);
|
|
129
113
|
return;
|
|
130
114
|
}
|
|
131
|
-
if (typeof key === "string" && key.startsWith("-D")) {
|
|
132
|
-
runtime.properties.set(key.slice(2), formatValue(value));
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
115
|
throw new TlaModuleError(
|
|
136
116
|
`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
137
117
|
);
|
|
@@ -215,12 +195,7 @@ export const createTlcExtOperators = (
|
|
|
215
195
|
const key = getValue(args, 0, "TLCGetAndSet");
|
|
216
196
|
const previous = getRegister(runtime, key) ?? getValue(args, 3, "TLCGetAndSet");
|
|
217
197
|
const update = getOperator(args, 1, "TLCGetAndSet");
|
|
218
|
-
|
|
219
|
-
runtime,
|
|
220
|
-
print,
|
|
221
|
-
key,
|
|
222
|
-
update.call([previous, getValue(args, 2, "TLCGetAndSet")]),
|
|
223
|
-
);
|
|
198
|
+
setRegister(runtime, key, update.call([previous, getValue(args, 2, "TLCGetAndSet")]));
|
|
224
199
|
return previous;
|
|
225
200
|
}),
|
|
226
201
|
isStateLevel: true,
|
package/src/tlc-module.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
getValue,
|
|
16
16
|
} from "./builtins";
|
|
17
17
|
import { getNamedRegisters, NAMED_REGISTER_PREFIX, type CheckerRuntime } from "./runtime";
|
|
18
|
-
import { createActionRecord
|
|
18
|
+
import { createActionRecord } from "./tlc-ext";
|
|
19
19
|
import { getRandomElement } from "./tlc-random";
|
|
20
20
|
import {
|
|
21
21
|
ANY_SET,
|
|
@@ -203,8 +203,33 @@ export const createTlcOperators = (
|
|
|
203
203
|
}),
|
|
204
204
|
defineStateOperator("TLCSet", 2, (args) => {
|
|
205
205
|
const key = getValue(args, 0, "TLCSet");
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
const value = getValue(args, 1, "TLCSet");
|
|
207
|
+
if (typeof key === "number" && key >= 0) {
|
|
208
|
+
runtime.registers.set(key, value);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
if (key === "exit") {
|
|
212
|
+
if (value === true) runtime.isStopped = true;
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (key === "pause") {
|
|
216
|
+
if (value === true) {
|
|
217
|
+
print("Press enter to resume model checking.");
|
|
218
|
+
runtime.pause();
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
if (typeof key === "string" && key.startsWith(NAMED_REGISTER_PREFIX)) {
|
|
223
|
+
runtime.namedRegisters.set(key, value);
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
if (typeof key === "string" && key.startsWith("-D")) {
|
|
227
|
+
runtime.properties.set(key.slice(2), formatValue(value));
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
throw new TlaModuleError(
|
|
231
|
+
`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${formatValue(key)}`,
|
|
232
|
+
);
|
|
208
233
|
}),
|
|
209
234
|
defineConstant("Any", ANY_SET),
|
|
210
235
|
defineOperator("RandomElement", 1, (args) =>
|