tla-ts 0.0.3-dev.ab42bab → 0.0.3-dev.ab9c809
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/index.cjs +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/parallel-worker.cjs +1 -1
- package/dist/parallel-worker.js +2 -2
- package/dist/parallel.cjs +1 -1
- package/dist/parallel.js +2 -2
- package/dist/run-cli.cjs +14 -14
- package/dist/run-cli.js +17 -17
- package/dist/transfer.cjs +23 -16
- package/dist/transfer.js +23 -16
- package/package.json +1 -1
- package/src/ast.ts +3 -1
- package/src/builtins.ts +9 -3
- package/src/check.ts +100 -39
- package/src/environment.ts +43 -22
- package/src/errors.ts +25 -3
- package/src/evaluate.ts +95 -6
- package/src/fingerprints.ts +2 -1
- package/src/levels.ts +124 -16
- package/src/parser.ts +41 -9
- package/src/resolve.ts +7 -5
- package/src/run-cli.ts +31 -11
- package/src/sany-lexer.ts +615 -0
- package/src/sany-parse-error.ts +3143 -0
- package/src/standard-modules.ts +52 -38
- package/src/substitution-levels.ts +38 -17
- package/src/successors.ts +39 -6
- package/src/value-sources.ts +29 -0
- package/src/values.ts +119 -41
package/dist/transfer.js
CHANGED
|
@@ -13,22 +13,22 @@ The exception was a java.lang.RuntimeException
|
|
|
13
13
|
: `,u=`This was a Java StackOverflowError. It was probably the result
|
|
14
14
|
of an incorrect recursive function definition that caused TLC to enter
|
|
15
15
|
an infinite loop when trying to compute the function or its application
|
|
16
|
-
to an element in its putative domain.`,d=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var f=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},p=class extends f{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}};const m=(e,t=!1)=>new p(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
16
|
+
to an element in its putative domain.`,d=e=>e instanceof RangeError&&e.message===`Maximum call stack size exceeded`;var f=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},p=class extends f{failure;sany;constructor(e,t,n,r){super(e,t),this.name=`TlaSyntaxError`,this.failure=n,this.sany=r}};const m=(e,t=!1,n)=>new p(e.map(e=>`${e.location}\n\n${e.message}`).join(`
|
|
17
17
|
|
|
18
|
-
`),void 0,void 0,{errors:e,isFatal:t})
|
|
18
|
+
`),void 0,void 0,{errors:e,isFatal:t,parseError:n});var h=class extends f{constructor(e){super(e),this.name=`TlaParseError`}};const g=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,_=(e,t)=>m([{location:g(t),message:e}]);var v=class extends f{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},y=class extends f{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}},b=class extends y{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},ee=class extends y{variable;constructor(e,t){super(e),this.name=`TlaEvaluationError`,this.variable=t}},x=class extends y{state;action;missing;constructor(e,t,n){super(`Successor state is not completely specified by the next-state action. The following variable${n.length>1?`s are`:` is`} not defined: ${n.join(`, `)}.\n`),this.name=`TlaEvaluationError`,this.state=e,this.action=t,this.missing=n}},S=class extends y{state;constructor(e){super(`current state is not a legal state`),this.name=`TlaEvaluationError`,this.state=e}},C=class extends f{failure;exception;constructor(e,t={}){super(e),this.name=`TlaProofError`,this.failure=t.exception===void 0?t.failure??e:void 0,this.exception=t.exception??`Failure(${JSON.stringify(this.failure)})`}},w=class extends C{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},T=class extends f{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}};const te=t=>r(t)??(t instanceof p?e.specParseError:t instanceof v?e.configParseError:t instanceof y?e.specEvaluationFailure:e.error),ne=/* @__PURE__ */ new Set(/* @__PURE__ */ `ACTION.ACTIONS.ASSUME.ASSUMPTION.AXIOM.BY.CASE.CHOOSE.CONSTANT.CONSTANTS.COROLLARY.DEF.DEFINE.DEFS.DOMAIN.ELSE.ENABLED.EXCEPT.EXTENDS.HAVE.HIDE.IF.IN.INSTANCE.LAMBDA.LEMMA.LET.LOCAL.MODULE.NEW.OBVIOUS.OMITTED.ONLY.OTHER.PICK.PROOF.PROPOSITION.PROVE.QED.RECURSIVE.STATE.SUBSET.SUFFICES.TAKE.TEMPORAL.TEMPORALS.THEN.THEOREM.UNCHANGED.UNION.USE.VARIABLE.VARIABLES.WITH.WITNESS`.split(`.`)),E=/* @__PURE__ */ new Map([[`in`,`\\in`],[`notin`,`\\notin`],[`subseteq`,`\\subseteq`],[`subset`,`\\subset`],[`supseteq`,`\\supseteq`],[`supset`,`\\supset`],[`cup`,`\\cup`],[`union`,`\\cup`],[`cap`,`\\cap`],[`intersect`,`\\cap`],[`X`,`\\X`],[`times`,`\\X`],[`o`,`\\o`],[`circ`,`\\o`],[`div`,`\\div`],[`land`,`/\\`],[`lor`,`\\/`],[`lnot`,`~`],[`neg`,`~`],[`equiv`,`<=>`],[`leq`,`<=`],[`geq`,`>=`],[`A`,`\\A`],[`forall`,`\\A`],[`E`,`\\E`],[`exists`,`\\E`],[`AA`,`\\AA`],[`EE`,`\\EE`],[`cdot`,`\\cdot`],[`sqsubseteq`,`\\sqsubseteq`],[`sqsupseteq`,`\\sqsupseteq`],[`sqsubset`,`\\sqsubset`],[`sqsupset`,`\\sqsupset`],[`sqcap`,`\\sqcap`],[`sqcup`,`\\sqcup`],[`oplus`,`\\oplus`],[`ominus`,`\\ominus`],[`otimes`,`\\otimes`],[`oslash`,`\\oslash`],[`odot`,`\\odot`],[`uplus`,`\\uplus`],[`prec`,`\\prec`],[`preceq`,`\\preceq`],[`succ`,`\\succ`],[`succeq`,`\\succeq`],[`sim`,`\\sim`],[`simeq`,`\\simeq`],[`approx`,`\\approx`],[`cong`,`\\cong`],[`asymp`,`\\asymp`],[`doteq`,`\\doteq`],[`propto`,`\\propto`],[`wr`,`\\wr`],[`star`,`\\star`],[`bullet`,`\\bullet`],[`bigcirc`,`\\bigcirc`],[`ll`,`\\ll`],[`gg`,`\\gg`]]),D=/* @__PURE__ */ new Map([[`/=`,`#`],[`=<`,`<=`],[`(+)`,`\\oplus`],[`(-)`,`\\ominus`],[`(.)`,`\\odot`],[`(/)`,`\\oslash`],[`(\\X)`,`\\otimes`]]),O=/* @__PURE__ */ `-+-> (\\X) <=> |-> ... ::= >>_ (+) (-) (.) (/) == => =< =| << <= <> <- >> >= /\\ \\/ /= [] ]_ |- |= || -> -| ~> .. :: := :> <: @@ ++ -- -. ** // ^^ ^+ ^* ^# %% ## && $$ ?? !! = < > / [ ] ( ) { } | - ~ . : @ , ' ! # % + * ^ & $ ?`.split(` `),k=/* @__PURE__ */ new Map([[`∧`,`/\\`],[`∨`,`\\/`],[`¬`,`~`],[`⇒`,`=>`],[`⟹`,`=>`],[`≡`,`<=>`],[`⇔`,`<=>`],[`∈`,`\\in`],[`∉`,`\\notin`],[`⊆`,`\\subseteq`],[`⊂`,`\\subset`],[`⊇`,`\\supseteq`],[`⊃`,`\\supset`],[`∪`,`\\cup`],[`∩`,`\\cap`],[`×`,`\\X`],[`∀`,`\\A`],[`∃`,`\\E`],[`≠`,`#`],[`≤`,`<=`],[`≥`,`>=`],[`↦`,`|->`],[`→`,`->`],[`⟨`,`<<`],[`⟩`,`>>`],[`□`,`[]`],[`◇`,`<>`],[`≜`,`==`],[`′`,`'`],[`∘`,`\\o`],[`⋅`,`\\cdot`]]),A=/^\\([bB][01]+|[oO][0-7]+|[hH][0-9a-fA-F]+)/,j=/* @__PURE__ */ new Map([[`b`,2],[`o`,8],[`h`,16]]),re=e=>e.startsWith(`\\`)?parseInt(e.slice(2),j.get(e[1].toLowerCase())):Number(e),M=/-{4,}[ \t]*MODULE\b/,ie=e=>/[A-Za-z0-9_]/.test(e),ae=(e,t)=>{let n=e[t];if(n===`\\`&&/[A-Za-z]/.test(e[t+1]??``)){let n=/^[A-Za-z]+/.exec(e.slice(t+1))?.[0]??``,r={value:n.length};for(;r.value>0&&!E.has(n.slice(0,r.value));)r.value--;let i=E.get(n.slice(0,r.value));return{text:i??`\\`,length:i===void 0?1:r.value+1}}let r=k.get(n);if(r)return{text:r,length:n.length};let i=O.find(n=>e.startsWith(n,t));return i?{text:D.get(i)??i,length:i.length}:n===`\\`?{text:`\\`,length:1}:void 0},oe=e=>e!==void 0&&e>=`0`&&e<=`9`,se=(e,t,n)=>{let r={value:t};for(;r.value<e.length&&n(e[r.value]);)r.value++;return r.value},ce=(e,t)=>{if(e[t]!==`<`)return 0;let n=e[t+1]===`+`||e[t+1]===`*`?t+2:se(e,t+1,oe);if(n===t+1||e[n]!==`>`)return 0;let r=se(e,n+1,ie),i=r===n+1&&(e[r]===`*`||e[r]===`-`);return se(e,i?r+1:r,e=>e===`.`)-t},le=(e,t)=>t===` `?e+8-e%8:e+1,ue=e=>{let t=M.exec(e);if(!t)throw new p(`Expected a module header such as ---- MODULE Name ----`);let n=[],r=/* @__PURE__ */ new Map,i=e.slice(0,t.index).split(`
|
|
19
19
|
`),a={index:t.index,line:i.length,lineStart:t.index-i[i.length-1].length,moduleDepth:0},o={lineStart:-1,position:0,width:0},s=()=>{for((o.lineStart!==a.lineStart||o.position>a.index)&&(o.lineStart=a.lineStart,o.position=a.lineStart,o.width=0);o.position<a.index;o.position++)o.width=le(o.width,e[o.position]);return le(o.width,e[a.index])},c=(e,t,r)=>{let i=s();n.push({kind:e,text:t,line:a.line,column:i,endColumn:i+r-1}),a.index+=r},l=t=>{for(let n=0;n<t;n++)e[a.index]===`
|
|
20
20
|
`&&(a.line++,a.lineStart=a.index+1),a.index++},u=t=>new p(`${t} at line ${a.line}, column ${s()}`,void 0,{reason:t,line:a.line,column:s(),isEnd:a.index>=e.length});for(;a.index<e.length;){let t=e[a.index];if(t===`
|
|
21
21
|
`||t===` `||t===` `||t===`\r`){l(1);continue}if(e.startsWith(`\\*`,a.index)){let t=e.indexOf(`
|
|
22
|
-
`,a.index);l((t===-1?e.length:t)-a.index);continue}if(e.startsWith(`(*`,a.index)){let t={value:0};do{if(a.index>=e.length)throw u(`Unterminated comment`);e.startsWith(`(*`,a.index)?(t.value++,l(2)):e.startsWith(`*)`,a.index)?(t.value--,l(2)):l(1)}while(t.value>0);continue}if(e.startsWith(`----`,a.index)){let t=
|
|
22
|
+
`,a.index);l((t===-1?e.length:t)-a.index);continue}if(e.startsWith(`(*`,a.index)){let t={value:0};do{if(a.index>=e.length)throw u(`Unterminated comment`);e.startsWith(`(*`,a.index)?(t.value++,l(2)):e.startsWith(`*)`,a.index)?(t.value--,l(2)):l(1)}while(t.value>0);continue}if(e.startsWith(`----`,a.index)){let t=se(e,a.index,e=>e===`-`)-a.index;e.slice(a.index+t).trimStart().startsWith(`MODULE`)&&a.moduleDepth++,c(`Separator`,`----`,t);continue}if(e.startsWith(`====`,a.index)){if(c(`ModuleEnd`,`====`,se(e,a.index,e=>e===`=`)-a.index),a.moduleDepth--,a.moduleDepth<=0)break;continue}if(t===`"`){let t=a.line,r=s(),i=[];for(l(1);e[a.index]!==`"`;){if(a.index>=e.length||e[a.index]===`
|
|
23
23
|
`)throw u(`Unterminated string`);if(e[a.index]===`\\`){let t=e[a.index+1];i.push({n:`
|
|
24
|
-
`,t:` `,r:`\r`,f:`\f`}[t]??t),l(2)}else i.push(e[a.index]),l(1)}l(1),n.push({kind:`String`,text:i.join(``),line:t,column:r,endColumn:s()-1});continue}let i=
|
|
24
|
+
`,t:` `,r:`\r`,f:`\f`}[t]??t),l(2)}else i.push(e[a.index]),l(1)}l(1),n.push({kind:`String`,text:i.join(``),line:t,column:r,endColumn:s()-1});continue}let i=A.exec(e.slice(a.index,a.index+64));if(i){c(`Number`,i[0],i[0].length);continue}if(ie(t)){let t=e.slice(a.index,se(e,a.index,ie));if(/^\d+$/.test(t)){let n=/^\d+(\.\d+)?/.exec(e.slice(a.index))?.[0]??t;c(n.includes(`.`)?`Decimal`:`Number`,n,n.length);continue}if(t.startsWith(`WF_`)||t.startsWith(`SF_`)){c(`Keyword`,t.slice(0,3),3);continue}let n=r.get(t)??t;r.set(n,n),c(ne.has(t)?`Keyword`:`Identifier`,n,t.length);continue}let o=ce(e,a.index);if(o>0){c(`Step`,e.slice(a.index,a.index+o),o);continue}let d=ae(e,a.index);if(d)c(`Operator`,d.text,d.length);else throw u(`Unexpected character ${JSON.stringify(t)}`)}let d=s();return n.push({kind:`End`,text:``,line:a.line,column:d,endColumn:d}),n},de=/* @__PURE__ */ new Set([`CONSTANT`,`CONSTANTS`,`INIT`,`NEXT`,`SPECIFICATION`,`INVARIANT`,`INVARIANTS`,`PROPERTY`,`PROPERTIES`,`CONSTRAINT`,`CONSTRAINTS`,`ACTION_CONSTRAINT`,`ACTION_CONSTRAINTS`,`SYMMETRY`,`VIEW`,`CHECK_DEADLOCK`,`ALIAS`,`POSTCONDITION`,`POSTCONDITIONS`,`_POSSIBLE`,`_PERIODIC`,`_RL_REWARD`]),fe=[`<-`,`<<`,`>>`,`=`,`{`,`}`,`,`,`[`,`]`,`(`,`)`],N={INIT:`init`,NEXT:`next`,SPECIFICATION:`specification`,VIEW:`view`,SYMMETRY:`symmetry`,ALIAS:`alias`,_PERIODIC:`periodic`,_RL_REWARD:`rlReward`},pe={INVARIANT:`invariants`,INVARIANTS:`invariants`,PROPERTY:`properties`,PROPERTIES:`properties`,CONSTRAINT:`constraints`,CONSTRAINTS:`constraints`,ACTION_CONSTRAINT:`actionConstraints`,ACTION_CONSTRAINTS:`actionConstraints`,POSTCONDITION:`postconditions`,POSTCONDITIONS:`postconditions`,_POSSIBLE:`possible`},me=e=>Object.hasOwn(N,e),he=e=>Object.hasOwn(pe,e),ge=e=>[...e].map(e=>{let t={"\b":`\\b`," ":`\\t`,"\n":`\\n`,"\f":`\\f`,"\r":`\\r`}[e];if(t)return t;if(e===`"`||e===`'`||e===`\\`)return`\\${e}`;let n=e.codePointAt(0)??0;return n<32||n>126?`\\u${n.toString(16).padStart(4,`0`)}`:e}).join(``),_e=(e,t,n,r=``)=>new v(`TLC found an error in the configuration file:\nLexical error at line ${e}, column ${t}. Encountered: ${n===void 0?`<EOF> `:`"${ge(n)}" (${n.codePointAt(0)}), `}after : "${ge(r)}"`),ve=(e,t)=>new v(`TLC found an error in the configuration file at line ${e}\n${t}`),ye=e=>{let t=`${e}\n`,n=[],r={index:0,line:1,lineStart:0},i=e=>{let n=t.slice(r.index,r.index+e),i=n.lastIndexOf(`
|
|
25
25
|
`);i!==-1&&(r.line+=n.split(`
|
|
26
26
|
`).length-1,r.lineStart=r.index+i+1),r.index+=e},a=e=>_e(r.line+1,0,void 0,e);for(;r.index<t.length;){let e=t.slice(r.index),o=/^\s+/.exec(e)?.[0];if(o){i(o.length);continue}if(e.startsWith(`\\*`)){r.index+=e.indexOf(`
|
|
27
27
|
`);continue}if(e.startsWith(`(*`)){let t=e.indexOf(`*)`);if(t===-1)throw r.line+=e.split(`
|
|
28
28
|
`).length-2,a(``);i(t+2);continue}let s=/^\d+(?![A-Za-z_])/.exec(e)?.[0];if(s){n.push({kind:`Number`,text:s,line:r.line}),r.index+=s.length;continue}let c=/^[A-Za-z0-9_!]+/.exec(e)?.[0];if(c){n.push({kind:`Word`,text:c,line:r.line}),r.index+=c.length;continue}if(e.startsWith(`"`)){let t=/^"((?:[^"\\\n]|\\.)*)"/.exec(e);if(!t){let t=e.indexOf(`
|
|
29
29
|
`);throw t===e.length-1?a(e):_e(r.line,r.index+t-r.lineStart+1,`
|
|
30
|
-
`,e.slice(0,t))}n.push({kind:`String`,text:t[1],line:r.line}),r.index+=t[0].length;continue}let l=fe.find(t=>e.startsWith(t));if(l){n.push({kind:`Symbol`,text:l,line:r.line}),r.index+=l.length;continue}let u=k(t,r.index);if(!u)throw _e(r.line,r.index-r.lineStart+1,e[0]);n.push({kind:`Word`,text:u.text,line:r.line}),r.index+=u.length}return n.push({kind:`End`,text:``,line:r.line-1}),n},be=e=>{let t=ye(e),n={index:0},r={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},i={isSet:!1},a=()=>t[Math.min(n.index++,t.length-1)],o=e=>e.kind===`Word`&&de.has(e.text),s=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t=a();if(t.text!==`}`)for(;e.push(s(t)),t=a(),t.text===`,`;)t=a();if(t.text!==`}`)throw ve(t.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw ve(e.line,`It was expecting a value, but did not find it.`)},c=e=>{let t=a();if(t.kind===`End`)throw ve(t.line,`Expected an identifier after ${e}[.`);let n=a();if(n.text!==`]`)throw ve(n.line,`It was expecting ], but did not find it.`);return t.text},l=e=>{for(;;){let t=a();if(t.kind===`End`||o(t))return t;let n={text:t.text},i=a();for(;i.text===`!`;)n.text=`${n.text}!${a().text}`,i=a();if(i.text===`<-`){if(i=a(),i.text===`[`){let e=c(`<-`),t=a();if(t.kind===`End`)throw ve(t.line,`Expected an identifier after <-[mod].`);r.substitutions.push({name:n.text,target:t.text,module:e});continue}if(i.kind===`End`)throw ve(i.line,`Expected an identifier after <-.`);r.substitutions.push({name:n.text,target:i.text});continue}let l=[];if(i.text===`(`){for(;l.push(s(a())),i=a(),i.text===`,`;);if(i.text!==`)`)throw ve(e,``);i=a()}if(i.text!==`=`)throw ve(i.line,`It was expecting = or <-, but did not find it.`);i=a();let u=i.text===`[`?c(`=`):void 0,d=s(u===void 0?i:a());r.constants.push({name:n.text,value:d,...l.length>0&&{args:l},...u&&{module:u}})}},u=a();for(;u.kind!==`End`;){let e=u.text,t=u.line;if(me(e)){let n=a();if(n.kind===`End`)throw ve(t,`The keyword ${e} was not followed by an identifier.`);let i=j[e];if(r[i]!==void 0)throw ve(t,`The keyword ${e} appeared twice.`);r[i]=n.text,u=a()}else if(he(e)){let t=r[pe[e]];for(u=a();u.kind!==`End`&&!o(u);)t.push(u.text),u=a()}else if(e===`CONSTANT`||e===`CONSTANTS`)u=l(t);else if(e===`CHECK_DEADLOCK`){let e=a();if(e.kind===`End`)throw ve(t,`The keyword CHECK_DEADLOCK was not followed by an identifier.`);if(e.text!==`TRUE`&&e.text!==`FALSE`)throw ve(e.line,`It was expecting TRUE or FALSE, but did not find it.`);if(i.isSet)throw ve(t,`The keyword CHECK_DEADLOCK appeared twice.`);i.isSet=!0,r.checkDeadlock=e.text===`TRUE`,u=a()}else throw ve(t,`It was expecting a keyword, but did not find it.`)}if(r.specification!==void 0&&(r.init!==void 0||r.next!==void 0))throw new _(`The configuration file cannot specify both INIT/NEXT and SPECIFICATION fields.`);return r},xe={Set:{open:`{ `,close:` }`,pad:` `,separator:`,`,divider:``,dividerPad:``},Sequence:{open:`<< `,close:` >>`,pad:` `,separator:`,`,divider:``,dividerPad:``},Subset:{open:`SUBSET `,close:` `,pad:` `,separator:`,`,divider:``,dividerPad:``},Function:{open:`( `,close:` )`,pad:` `,separator:` @@`,divider:` :>`,dividerPad:` `},Record:{open:`[ `,close:` ]`,pad:` `,separator:`,`,divider:` |->`,dividerPad:` `}},Se=e=>{if(e===void 0)return!1;let t=e.charCodeAt(0);return t>=9&&t<=13||t>=28&&t<=32||t===5760||t>=8192&&t<=8202&&t!==8199||t===8232||t===8233||t===8287||t===12288},Ce=e=>e!==void 0&&/^\p{Nd}$/u.test(e),we=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),Te=e=>{let t=t=>{let n=A(e,t,Se);return e[n]===void 0?void 0:n},n=(n,r,i,a,o,s)=>{let c={kind:n,first:r,last:r,children:[]},l={index:t(i)};for(;l.index!==void 0&&e[l.index]!==a;){let n=o(l.index);if(!n)return;c.children.push(n);let r=t(n.last+1);if(r===void 0)return;let i=e.startsWith(s,r)?r+s.length:r;l.index=t(i)}if(l.index!==void 0)return c.last=l.index,c},r=(n,r)=>{let i=o(n);if(!i)return;let a=t(i.last+1);if(a===void 0||!e.startsWith(r,a))return;let s=t(a+r.length),c=s===void 0?void 0:o(s);if(c)return{kind:`Pair`,first:n,last:c.last,children:[i,c]}},i=t=>{let n=A(e,t,Ce);if(e.startsWith(`..`,n)&&Ce(e[n+2]))return{kind:`Constant`,first:t,last:A(e,n+2,Ce)-1,children:[]}},a=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=Ce(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:A(e,t+1,Ce)-1,children:[]};if(we(n))return{kind:`Constant`,first:t,last:A(e,t,we)-1,children:[]}},o=i=>{let s=t(i);if(s!==void 0)switch(e[s]){case`{`:return n(`Set`,s,s+1,`}`,o,`,`);case`<`:{let t=n(`Sequence`,s,s+2,`>`,o,`,`);return!t||t.last+1>=e.length?void 0:{...t,last:t.last+1}}case`[`:return n(`Record`,s,s+1,`]`,e=>r(e,`|->`),`,`);case`(`:return n(`Function`,s,s+1,`)`,e=>r(e,`:>`),`@@`);default:{if(!e.startsWith(`SUBSET`,s))return a(s);let n=t(s+6),r=n===void 0?void 0:o(n);return r?{kind:`Subset`,first:s,last:r.last,children:[r]}:void 0}}};return o(0)},Ee=e=>{let t=e.length===0?void 0:Te(e);if(!t||t.last<e.length-1)return e;let n=t=>e.slice(t.first,t.last+1),r=e=>e.last-e.first+1,i=(e,t,i,s)=>{if(r(e)<=t-i||e.kind===`Constant`)return n(e);if(e.kind===`Pair`)return;let c=xe[e.kind],l=t-Math.max(c.open.length,c.pad.length),u=i+c.close.length,d=s+c.pad,f=e.kind===`Function`||e.kind===`Record`?o(e.children,l,u,d,c):a(e.children,l,u,d,c.separator);return f===void 0?void 0:c.open+f+c.close},a=(e,t,n,r,a)=>{let o=e.map((o,s)=>{let c=s===e.length-1,l=i(o,t,c?n:a.length,r);return l===void 0||c?l:`${l}${a}\n${r}`});return o.includes(void 0)?void 0:o.join(``)},o=(e,t,a,o,s)=>{let c=e.map((c,l)=>{let u=l===e.length-1,d=c.children[0],f=c.children[1],p=u?``:`${s.separator}\n${o}`,m=r(d)+s.divider.length+1+r(f);if(u?m<=t-a:m+s.separator.length<=t)return`${n(d)}${s.divider} ${n(f)}${p}`;let h=r(d)+s.divider.length<=t?n(d):i(d,t,a+s.divider.length,o),g=i(f,t-s.dividerPad.length,u?a:s.separator.length,o+s.dividerPad);return h===void 0||g===void 0?void 0:`${h}${s.divider}\n${o}${s.dividerPad}${g}${p}`});return c.includes(void 0)?void 0:c.join(``)};return i(t,80,0,``)??e},M=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,N=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),P=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),F=e=>typeof e==`object`&&e.kind===`ModelValue`,De=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:M(e)?`set`:`function`,Oe=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new y(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},ke={isUsed:!1},Ae=(e,t)=>(ke.isUsed=!0,e.writtenKeys=t,e),je=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[fn(e.domain,t)]]),Me=(e,t,n)=>Ae($e(e,t),n),Ne=e=>{if(!(typeof e!=`object`||e.kind!==`Function`&&e.kind!==`Set`)&&e.hash===0&&e.fingerprint===0){if(e.kind===`Set`)return e.elements.forEach(Ne);e.writtenKeys=void 0,e.range.forEach(Ne)}},Pe=e=>e.every(e=>typeof e==`string`),Fe=(e,t)=>e.length>0&&t.length>0&&Pe(e)!==Pe(t),Ie=(e,t)=>{ke.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return Fe(n,r)?yt(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=Ye(n[e],r[e]);if(t!==0)return t}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=Ye(i[e],a[e]);if(t!==0)return t}return 0},Le=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return n.length-r.length;if(n===r)return 0;for(let e=0;e<n.length;e++){let t=Ye(n[e],r[e]);if(t!==0)return t}return 0},I=e=>F(e)?e.type:void 0,Re=(e,t,n)=>{let r=I(e),i=I(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(F(e)&&F(t)){if(r===void 0||i===void 0||r===i)return;throw new v(`Attempted to ${a} the differently-typed model values ${U(e)} and ${U(t)}`)}throw r===void 0?new v(`Attempted to ${a} the typed model value ${U(t)} and the non-model value\n${U(e)}`):new v(`Attempted to ${a}${n?``:` the`} typed model value ${U(e)} and non-model value\n${U(t)}`)},ze={ranks:Object.create(null),size:0},Be=e=>{ze.ranks=Object.create(null),ze.size=0,Xe.clear();for(let t of e)Ve(t)},Ve=e=>(ze.ranks[e]===void 0&&(ze.ranks[e]=ze.size++),e),He=()=>ze.size,Ue=e=>ze.ranks[Ve(e)],We=(e,t)=>{if(e===t)return 0;let n=ze.ranks,r=n[e],i=n[t];return r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},L=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),Ge=(e,t)=>(L(e)||L(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),Ke=(e,t,n)=>{if(!L(e))throw new v(`Attempted to ${n} the set ${U(z(e)?B(e):e,!0)} with the value:\n${U(t,!0)}`);if(!L(t))throw new v(`Attempted to compare overridden value ${U(e,!0)} with non-overridden value:\n${U(t,!0)}`);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new v(`Attempted to compare ${U(e,!0)} with the value\n${U(t,!0)}`)},qe={kind:`InfiniteSet`,name:`Any`},Je=e=>{throw new v(`Attempted to compare ANY with the value\n${U(e)}`)},Ye=(e,t)=>{if(e===t)return ke.isUsed&&Ne(e),e===qe?Je(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return Ie(e,t);if(n===`Set`&&r===`Set`)return Le(e,t);if(n===`Interval`&&r===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.max(0,t.high-t.low+1);return n!==r||n===0?n-r:e.low-t.low}if(n===`ModelValue`&&r===`ModelValue`)return e.type!==void 0&&t.type!==void 0&&Re(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Re(e,t,!1),n===`ModelValue`?-1:1;if(e===qe||t===qe)return Je(e===qe?t:e);if(M(e)&&M(t)&&Ge(e,t))return Ke(e,t,`compare`);let i=M(e);if(i!==M(t))throw new v(`Attempted to compare ${De(e)} ${U(e)} with ${De(t)} ${U(t)}`);return i?Le(B(e),an(t)):Ie(H(e),H(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return We(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Re(e,t,!1),F(e))return-1;if(F(t))return 1;throw new v(`Attempted to compare ${De(e)} ${U(e)} with ${De(t)} ${U(t)}`)},Xe=/* @__PURE__ */ new Map,Ze=e=>{let t=Xe.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Ue(e)};return Xe.set(e,n),n},Qe=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0}),$e=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0}),et=(e,t)=>{if(e===t)return ke.isUsed&&Ne(e),e!==qe||Je(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Re(e,t,!0),Ye(e,t)===0);if((e.kind===`Set`||e.kind===`Function`)&&(t.kind===`Set`||t.kind===`Function`)&&e.hash!==0&&t.hash!==0&&e.hash!==t.hash)return!1;if(e.kind===`Function`&&t.kind===`Function`)return Ie(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Le(e,t)===0;if(F(e)||F(t))return Re(e,t,!0),F(e)&&F(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return et(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=V(e.domain),r=V(t.domain);if(n||r)return n===r;let i=V(e.range),a=V(t.range);return i||a?i===a:et(e.domain,t.domain)&&et(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){if(V(e))return V(t);if(V(t))return!1;let n=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),r=n(t);return e.names.length===t.names.length&&n(e).every((e,t)=>e[0]===r[t][0]&&et(e[1],r[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`)return V(e)?V(t):!V(t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>et(e,t.factors[n]));let n=M(e)&&M(t)&&!(z(e)&&z(t));if(n&&Ge(e,t))return Ke(e,t,`check equality of`)===0;if(n){if(!L(e)){let n=B(e);if(!L(t))return Le(n,B(t))===0}return Jn(e)===Jn(t)}return Ye(e,t)===0},tt=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>nt(e,t[n])),nt=(e,t)=>e===t?!0:typeof e!=`object`||typeof t!=`object`?!1:e.kind===`Set`&&t.kind===`Set`?(e.hash===0||t.hash===0||e.hash===t.hash)&&tt(e.elements,t.elements):e.kind===`Function`&&t.kind===`Function`?(e.hash===0||t.hash===0||e.hash===t.hash)&&tt(e.domain,t.domain)&&tt(e.range,t.range):Jn(e)===Jn(t),rt=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},it=e=>{if(!P(e))return;let t=H(e);return{domain:t.domain,range:t.range,low:rt(t.domain)}},at=e=>{if(!P(e))return;let t=H(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},ot=(e,t)=>{if(I(e)!==void 0)throw new v(`Attempted to compare the typed model value ${U(e)} and the non-model value\n${U(t)}`);return 1},st=(e,t)=>{if(I(e)!==void 0)throw new v(`Attempted to check equality of the typed model value ${U(e)} and the non-model value\n${U(t)}`);return!1},ct=(e,t)=>{let n=I(e);if(n===void 0)return F(t)?e.rank-t.rank:-1;if(!F(t))throw new v(`Attempted to compare the typed model value ${U(e)} and non-model value\n${U(t)}`);let r=I(t);if(r!==void 0&&r!==n)throw new v(`Attempted to compare the differently-typed model values ${U(e)} and ${U(t)}`);return e.rank-t.rank},lt=(e,t)=>{let n=I(e);if(n===void 0)return F(t)&&e.name===t.name;if(!F(t))throw new v(`Attempted to check equality of typed model value ${U(e)} and non-model value\n${U(t)}`);let r=I(t);if(r!==void 0&&r!==n)throw new v(`Attempted to check equality of the differently-typed model values ${U(e)} and ${U(t)}`);return e.name===t.name},ut={number:{name:`integer`,other:`non-integer`,equality:`check equality of`},string:{name:`string`,other:`non-string`,equality:`check equality of`},boolean:{name:`boolean`,other:`non-boolean`,equality:`compare equality of`}},dt=(e,t,n)=>{let r=ut[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${U(e)} with ${r.other}:\n${U(t)}`},ft=(e,t,n)=>{let r=it(n);if(!r){if(F(n))return ot(n,t);throw new v(`Attempted to compare the function ${U(t)} with the value:\n${U(n)}`)}if(e.range.length!==r.range.length)return e.range.length-r.range.length;let i=()=>pt(e.range,r.range);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&r.low!==void 0)return e.low===r.low?i():e.low-r.low;let a=e.low??r.low;if(a===void 0)return pt(e.domain,r.domain)||i();let o=e.low===void 0?e.domain:r.domain;for(let t=0;t<o.length;t++){let n=o[t];if(typeof n!=`number`)throw new v(`Attempted to compare integer with non-integer${e.low===void 0?``:`:`}\n${U(n)}.`);let r=e.low===void 0?n-(a+t):a+t-n;if(r!==0)return r}return i()},pt=(e,t)=>{for(let n=0;n<e.length;n++){let r=yt(e[n],t[n]);if(r!==0)return r}return 0},mt=(e,t)=>{let n=H(e);if(e.kind===`Function`&&pn(n)!==void 0){let r=P(t)?pn(t):void 0;return r?n.range.length-r.length||pt(n.range,r):ft({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=at(t);if(!r){if(F(t))return ot(t,e);throw new v(`Attempted to compare record:\n${U(e)}\nwith non-record\n${U(t)}`)}return n.domain.length-r.domain.length||pt(n.domain,r.domain)||pt(n.range,r.range)}return ft({...n,low:rt(n.domain)},e,t)},ht=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),gt=(e,t)=>L(e)||L(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),_t=(e,t)=>{let n=ht(t)?t:B(t);return{elements:B(e).elements,otherElements:B(n).elements}},vt=(e,t)=>{if(gt(e,t))return Ye(e,t);if(!ht(e))return vt(B(e),t);if(!M(t)){if(F(t))return ot(t,e);throw new v(`Attempted to compare the set ${U(e)} with the value:\n${U(t)}`)}let n=_t(e,t);return n.elements.length-n.otherElements.length||pt(n.elements,n.otherElements)},yt=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return Ye(e,t);if(F(t))return ot(t,e);throw new v(dt(e,t,!1))}return e.kind===`ModelValue`?ct(e,t):P(e)?mt(e,t):vt(e,t)},bt=(e,t)=>e.every((e,n)=>wt(e,t[n])),xt=(e,t,n)=>{let r=it(n);if(!r){if(F(n))return st(n,t);throw new v(`Attempted to check equality of the function ${U(t)} with the value:\n${U(n)}`)}if(e.range.length!==r.range.length)return!1;if(e.low!==void 0&&r.low!==void 0)return(e.range.length===0||e.low===r.low)&&bt(e.range,r.range);let i=e.low??r.low;return i===void 0?bt(e.domain,r.domain)&&bt(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new v(`Attempted to compare an integer with non-integer:\n${U(e)}.`);return e===i+t})&&bt(e.range,r.range)},St=(e,t)=>{let n=H(e);if(e.kind===`Function`&&pn(n)!==void 0){let r=P(t)?pn(t):void 0;return r?n.range.length===r.length&&bt(n.range,r):xt({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=at(t);if(!r){if(F(t))return st(t,e);throw new v(`Attempted to check equality of record:\n${U(e)}\nwith non-record\n${U(t)}`)}return n.domain.length===r.domain.length&&bt(n.domain,r.domain)&&bt(n.range,r.range)}return xt({...n,low:rt(n.domain)},e,t)},Ct=(e,t)=>{if(gt(e,t))return et(e,t);if(!ht(e))return Ct(B(e),t);if(!M(t)){if(F(t))return st(t,e);throw new v(`Attempted to check equality of the set ${U(e)} with the value:\n${U(t)}`)}let n=_t(e,t);return n.elements.length===n.otherElements.length&&bt(n.elements,n.otherElements)},wt=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(F(t))return st(t,e);throw new v(dt(e,t,!0))}return e.kind===`ModelValue`?lt(e,t):P(e)?St(e,t):Ct(e,t)},Tt=e=>{let t=[];for(let n of e){let e={low:0,high:t.length,comparison:1};for(;e.low<e.high;){let r=e.low+(e.high-e.low>>1);if(e.comparison=yt(n,t[r]),e.comparison===0)break;e.comparison<0?e.high=r:e.low=r+1}e.comparison!==0&&t.splice(e.low,0,n)}return t},Et=(e,t)=>t.some(t=>wt(t,e)),Dt=(e,t)=>{try{return et(e,t)}catch(n){if(!(n instanceof v))throw n;return wt(e,t)}},Ot=e=>{for(let t=1;t<e.length;t++)if(Ye(e[t],e[t-1])<=0)return!1;return!0},kt=e=>{if(e.length<2||Ot(e))return Qe(e);let t=[...e].sort(Ye),n=[t[0]];for(let e=1;e<t.length;e++)Ye(n[n.length-1],t[e])!==0&&n.push(t[e]);return Qe(n)},At=e=>{try{return kt(e)}catch(t){if(!(t instanceof v))throw t;return{kind:`MixedSet`,elements:e}}},jt=Qe([]),Mt=(e,t)=>{if(e.elements.length===0||t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&Ye(r[a],t)<0;)a++;a<r.length&&Ye(r[a],t)===0||i.push(t)}return i.length===n.length?e:Qe(i)},Nt=(e,t)=>{let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&Ye(r[a],t)<0;)a++;a<r.length&&Ye(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Qe(i)},Pt=(e,t)=>{if(e.elements.length===0)return t;if(t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=[],o=0,s=0;for(;o<n.length&&s<r.length;){let e=Ye(n[o],r[s]);e<0?i.push(n[o++]):e>0?(a.push(r[s]),i.push(r[s++])):(i.push(n[o++]),s++)}for(;o<n.length;)i.push(n[o++]);for(;s<r.length;)a.push(r[s]),i.push(r[s++]);if(a.length===0)return e;let c=Qe(i);if(e.hash!==0){let t=e.hash;for(let e=0;e<a.length;e++)t=t+In(a[e])|0;c.hash=t}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+Un(a[e])|0;c.fingerprint=t}return c},Ft=e=>{let t=e.length<2?e:[...e].sort((e,t)=>Ye(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&Ye(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return $e(n,r)},It=e=>{let t=Ft(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:Ae(t,e.map(e=>e[0]))},Lt=[],Rt=[],zt=/* @__PURE__ */ new WeakMap,Bt=e=>{let t=Lt[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Lt[e]=n,n},Vt=e=>{if(ln(e),e.low===1&&e.high>=1)return Bt(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Ht=e=>e.length>0&&(e===Lt[e.length]||zt.has(e)),Ut=e=>{let t=B(e).elements;return Ht(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Wt=e=>{let t=Rt[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return Rt[e]=n,n},R=e=>$e(Bt(e.length),e),Gt=e=>Ft(e),Kt=e=>M(e)&&!L(e),qt=(e,t=!1)=>`UNION(${U(e.base,t)})`,Jt=(e,t=e=>B(e).elements)=>{if(!Kt(e.base))throw new v(`Attempted to enumerate the nonenumerable set:\n${qt(e)}`);return t(e.base)},Yt=(e,t,n)=>{if(Kt(e))return e;throw new v(t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${U(e)}\nwhen enumerating:\n${qt(n)}`)},z=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`InfiniteSet`:case`SequenceSet`:return!1;case`Subset`:case`FilteredSet`:return z(e.base);case`FunctionSet`:return z(e.domain)&&z(e.range)||Xt(e.domain)===!0||Xt(e)===!0;case`RecordSet`:return e.sets.every(z)||Xt(e)===!0;case`ProductSet`:return e.factors.every(z)||Xt(e)===!0;case`Union`:return z(e.base)&&on(e.base).every(z);case`SetOperation`:return e.operator===`\\cup`?z(e.left)&&z(e.right):e.operator===`\\cap`?z(e.left)||z(e.right):z(e.left);default:return!1}},Xt=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:return e.name===`Any`&&void 0;case`Subset`:case`SequenceSet`:return!1;case`FunctionSet`:{let t=Xt(e.domain);return t===void 0?void 0:!t&&Xt(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Xt(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return z(e)?B(e).elements.length===0:void 0;default:return}},Zt=e=>{let t=e.reduce((e,t)=>e*t.length,1),n=[],r=e.map(()=>0);for(let i=0;i<t;i++){n.push(e.map((e,t)=>e[r[t]]));for(let t=e.length-1;t>=0&&(r[t]++,!(r[t]<e[t].length));t--)r[t]=0}return n},Qt=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]<t-e.length+n){e[n]++;for(let t=n+1;t<e.length;t++)e[t]=e[t-1]+1;return!0}return!1},$t=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Qe(r.map(t=>e[t])));while(Qt(r,e.length))}return t},en=e=>{if(typeof e!=`object`)throw new v(`Expected a set but found ${U(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return Tt(e.elements);case`Interval`:{let t=Vt(e);return t!==Lt[t.length]&&zt.set(t,e),t}case`Subset`:{L(e.base)&&ln(e.base);let t=B(e.base).elements;if(t.length>30)throw new v(cn(e));return $t(t)}case`FunctionSet`:{if(V(e))return[];if(L(e.domain))throw new v(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${U(e.domain)}\ncannot be enumerated.`);let t=Ut(e.domain);if(t.length>0&&L(e.range))throw new v(`Attempted to enumerate a set of the form [D -> R],but the range R:\n${U(e.range)}\ncannot be enumerated.`);let n=t.length===0?[]:B(e.range).elements;return Zt(t.map(()=>n)).map(e=>$e(t,e))}case`RecordSet`:{if(V(e))return[];let t=e.sets.map((t,n)=>{if(L(t))throw new v(`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[n]}' field:\n${U(t)}`);return B(t).elements});return Zt(t).map(t=>Gt(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(V(e))return[];let t=e.factors.map((e,t)=>{if(L(e))throw new v(`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${U(e)}`);return B(e).elements});return Zt(t).map(R)}case`FilteredSet`:if(L(e.base))throw new v(`Attempted to enumerate { x \\in S : p(x) } when S:\n${U(e.base)}\nis not enumerable`);return B(e.base).elements.filter(e.test);case`Union`:{let t=Jt(e).flatMap((t,n)=>B(Yt(t,n,e)).elements);return B(At(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(L(e.left)||L(e.right)))throw new v(`Attempted to enumerate S \\cup T when S:\n${U(e.left)}\nand T:\n${U(e.right)}\nare not both enumerable`);if(e.operator===`\\cap`&&L(e.left)&&L(e.right))throw new v(`Attempted to enumerate S \\cap T when neither S:\n${U(e.left)}\nnor T:\n${U(e.right)}\nis enumerable`);if(e.operator===`\\`&&L(e.left))throw new v(`Attempted to enumerate S \\ T when S:\n${U(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return Pt(B(e.left),B(e.right)).elements;let t=e.operator===`\\`||z(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return B(n).elements.filter(t=>gn(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new v(`Attempted to enumerate the non-enumerable set ${U(e)}`);default:throw new v(`Expected a set but found ${U(e)}`)}},tn=/* @__PURE__ */ new WeakMap,nn=/* @__PURE__ */ new WeakMap,B=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Qe(en(e));let t=typeof e==`object`?tn.get(e):void 0;if(t)return t;let n=(typeof e==`object`?nn.get(e):void 0)??rn(e);return typeof e==`object`&&tn.set(e,n),n},rn=e=>{let t=en(e);return typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Qe(t):kt(t)},an=e=>{if(typeof e!=`object`||e.kind!==`Union`&&e.kind!==`SetOperation`&&e.kind!==`FilteredSet`||tn.has(e))return B(e);let t=nn.get(e);if(t)return t;let n=rn(e);return nn.set(e,n),n},on=e=>{if(typeof e!=`object`||tn.has(e))return B(e).elements;if(e.kind===`Union`)return Jt(e,on).flatMap((t,n)=>on(Yt(t,n,e)));if(e.kind===`FilteredSet`&&!L(e.base))return on(e.base).filter(e.test);if(e.kind!==`SetOperation`)return B(e).elements;if(e.operator===`\\cup`)return L(e.left)||L(e.right)?B(e).elements:[...on(e.left),...on(e.right)];let t=e.operator===`\\`||z(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return L(n)?B(e).elements:on(n).filter(t=>gn(t,r)===(e.operator===`\\cap`))},V=e=>{if(typeof e!=`object`||!M(e))throw new v(`Shouldn't call isEmpty() on value ${U(e)}`);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:if(e.name===`Any`)throw new v(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1;case`ProductSet`:return e.factors.some(V);case`RecordSet`:return e.sets.some(V);case`FunctionSet`:return!V(e.domain)&&V(e.range);case`Union`:return Jt(e).every((t,n)=>V(Yt(t,n,e)));default:return B(e).elements.length===0}},sn=(e,t)=>e.reduce((e,n)=>{let r=e*ln(n);if(r>2147483647)throw new v(t());return r},1),cn=e=>`Overflow when computing the number of elements in:\n${U(e)}`,ln=e=>{if(typeof e!=`object`)return B(e).elements.length;switch(e.kind){case`Interval`:{let t=Math.max(0,e.high-e.low+1);if(t>2147483647)throw new v(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new v(`Attempted to compute the number of elements in the overridden value ${U(e)}.`);case`Subset`:{let t=ln(e.base);if(t>=31)throw new v(cn(e));return 2**t}case`FunctionSet`:{if(V(e.domain))return 1;if(V(e.range))return 0;let t=ln(e.range);if(t===1)return 1;let n=ln(e.domain),r={value:1};for(let i=0;i<n;i++)if(r.value*=t,r.value>2147483647)throw new v(cn(e));return r.value}case`RecordSet`:return V(e)?0:sn(e.sets,()=>cn(e));case`ProductSet`:return V(e)?0:sn(e.factors,()=>`Overflow when computing the number of elements in ${U(e)}`);default:return B(e).elements.length}},un=e=>`Attempted to check if the set ${U(e)}is finite.`,dn=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new v(`Attempted to check if the ${De(e)} ${U(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new v(`Attempted to check if the function:\n${U(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return dn(e.base)&&V(e.base);case`Subset`:return dn(e.base);case`FunctionSet`:{let t=dn(e.domain);if(t&&V(e.domain))return!0;let n=dn(e.range);return n&&V(e.range)?!0:n&&(t||ln(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n={isAllFinite:!0};for(let e of t)if(!dn(e))n.isAllFinite=!1;else if(V(e))return!0;return n.isAllFinite}case`Union`:if(!Kt(e.base))throw new v(`Attempted to check if the nonenumerable set:\n${qt(e)}\nis a finite set.`);return B(e.base).elements.every(dn);case`SetOperation`:if(e.operator===`\\cup`)return dn(e.left)&&dn(e.right);if(e.operator===`\\cap`){if(!dn(e.left)&&!dn(e.right))throw new v(un(e));return!0}if(dn(e.left))return!0;if(!dn(e.right))throw new v(un(e));return!1;case`FilteredSet`:if(!dn(e.base))throw new v(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${U(e.base)}\nis finite.`);return!0}},fn=(e,t)=>{let n={low:0,high:e.length-1};for(;n.low<=n.high;){let r=n.low+n.high>>1,i=Ye(e[r],t);if(i===0)return r;i<0?n.low=r+1:n.high=r-1}return-1},pn=e=>{if(typeof e!=`object`||!P(e))return;let t=H(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},mn=(e,t)=>`Attempted to check if the value ${U(e)} is an element of ${U(t)}`,hn=(e,t)=>{let n=`Attempted to check if the value:\n${U(e)}\nis an element of the`;if(!P(t))return`${n} ${De(t)} ${U(t)}`;let r=t.kind===`Function`||z(t.domain)?H(t).domain:[];return r.length>0&&r.every(e=>typeof e==`string`)?`Attempted to check if element:\n${U(e)}\nis in the record:\n${U(t)}`:r.every((e,t)=>e===t+1)?`Attempted to check set membership in a tuple value.`:`${n} function ${U(t)}`},gn=(e,t)=>{if(!M(t))throw new v(hn(e,t));switch(t.kind){case`Set`:try{return fn(t.elements,e)!==-1}catch(n){if(!(n instanceof v))throw n;return Et(e,t.elements)}case`MixedSet`:return Et(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!F(e))throw new v(`Attempted to check if the value:\n${U(e)}\nis in the integer interval ${U(t)}`);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(F(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new v(`Attempted to check if the value:\n${U(e)}\nis an element of ${t.name}.`);return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:if(!M(e))throw new v(mn(e,t));return B(e).elements.every(e=>gn(e,t.base));case`FunctionSet`:{if(!P(e)){if(F(e))return!1;throw new v(`Attempted to check if \n${U(e)}\nwhich is not a TLC function value, is in the set of functions:\n${Ee(U(t))}`)}let n=H(e),r=rt(n.domain);return(r===void 0?Dt(t.domain,Qe(n.domain)):Dt({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>gn(e,t.range))}case`RecordSet`:{let n=P(e)?H(e):void 0;if(!n||!Pe(n.domain)){if(F(e))return!1;throw new v(`Attempted to check if non-record\n${U(e)}\nis in the set of records:\n${U(t)}`)}return n.domain.length===t.names.length&&t.names.every((e,r)=>{let i=fn(n.domain,e);return i!==-1&&gn(n.range[i],t.sets[r])})}case`ProductSet`:{let n=P(e)?pn(e):void 0;if(n===void 0){if(P(e)&&H(e).domain.every(e=>typeof e==`number`)||F(e))return!1;throw new v(`Attempted to check if non-tuple\n${U(e)}\nis in the set of tuples:\n${U(t)}`)}return n.length===t.factors.length&&n.every((e,n)=>gn(e,t.factors[n]))}case`FilteredSet`:return gn(e,t.base)&&t.test(e);case`Union`:if(!Kt(t.base))throw new v(`Attempted to check if:\n ${U(e)}\nis an element of the non-enumerable set:\n ${qt(t)}`);return B(t.base).elements.some(t=>gn(e,t));case`SetOperation`:return t.operator===`\\cup`?gn(e,t.left)||gn(e,t.right):gn(e,t.left)&&gn(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=pn(e);if(n===void 0){if(F(e))return!1;throw new v(mn(e,t))}return n.every(e=>gn(e,t.base))}default:throw new v(hn(e,t))}},_n=(e,t,n)=>e===t?!0:typeof e!=`object`||typeof t!=`object`||typeof n!=`object`||e.kind!==`Function`||t.kind!==`Function`||n.kind!==`FunctionSet`||e.domain!==t.domain?gn(e,n):e.range.every((e,r)=>_n(e,t.range[r],n.range)),H=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){z(e.domain)||ln(e.domain);let t=Ut(e.domain);return $e(t,t.map(t=>e.apply(t)))}throw new v(`Expected a function but found ${U(e)}`)},vn=/* @__PURE__ */ new WeakSet,yn=e=>(vn.add(e),e),bn=e=>{let t=e.domain;return t.length===0?vn.has(e)?`FcnRcdValue`:`TupleValue`:t===Lt[t.length]?`TupleValue`:zt.has(t)?`IntervalFcnRcdValue`:t.every(e=>typeof e==`string`)?`RecordValue`:`FcnRcdValue`},xn=(e,t)=>`Attempted to apply function:\n${Ee(U(e))}\nto argument ${Ee(U(t))}, which is not in the domain of the function.`,Sn=e=>`Attempted to apply function with integer domain to the non-integer argument ${Ee(U(e))}`,Cn=(e,t)=>{if(vn.has(e)||e.kind===`LazyFunction`)return`In applying the function\n${Ee(U(e))},\nthe first argument is:\n${Ee(U(t))}\nwhich is not in its domain.\n`;let n=bn(e);return n===`TupleValue`?typeof t==`number`?`Attempted to access index ${t} of tuple\n${Ee(U(e))}\nwhich is out of bounds.`:`Attempted to access tuple at a non integral index: ${Ee(U(t))}`:n===`RecordValue`?typeof t==`string`?`Attempted to access nonexistent field '${t}' of record\n${Ee(U(e))}`:`Attempted to access record by a non-string argument: ${Ee(U(t))}`:n===`IntervalFcnRcdValue`&&typeof t!=`number`?Sn(t):xn(e,t)},wn=(e,t)=>bn(e)===`FcnRcdValue`?xn(e,t):Sn(t),Tn=e=>bn(e)===`RecordValue`,En=(e,t)=>{let n=e[0];return typeof n==`number`?typeof t!=`number`&&(e===Lt[e.length]||zt.has(e)):typeof n==`string`&&typeof t!=`string`},Dn=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}if(e.length<=8){for(let n=0;n<e.length;n++)if(e[n]===t)return n}return fn(e,t)},On=(e,t,n,r)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!gn(t,e.domain))throw new v(vn.has(e)?Cn(e,t):`Attempted to apply a function to ${U(t)}, which is not in its domain`);return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new v(r?.(e)??`Attempted to apply ${U(e)}, which is not a function`);let i=En(e.domain,t)?-1:Dn(e.domain,t);if(i===-1)throw new v(n?.(e)??Cn(e,t));return e.range[i]},kn=e=>Ht(e)?zt.get(e)??Wt(e.length):void 0,An=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=H(e).domain;return kn(t)??Qe(t)},jn=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!z(e.domain))){if(!gn(t,e.domain))return e;let r=n(e.apply(t));return{kind:`LazyFunction`,domain:e.domain,apply:n=>Dt(t,n)?r:e.apply(n),source:e.source}}let i=H(e),a=Dn(i.domain,t);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=$e(i.domain,o);if(l.writtenKeys=i.writtenKeys,i.hash!==0){let e=i.domain[a];l.hash=s===c?i.hash:i.hash-Ln(e,s)+Ln(e,c)|0}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-Wn(e,s)+Wn(e,c)|0}return l},Mn=/* @__PURE__ */ new WeakMap,Nn=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Pn=(e,t)=>Math.imul(e^t,16777619),Fn=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Nn(t)},In=e=>Nn(zn(e)+2654435769|0),Ln=(e,t)=>Nn(Math.imul(zn(e),668265261)+zn(t)|0),Rn=e=>{if(e.kind===`ModelValue`)return Nn(Pn(Fn(e.name),109));if(M(e)){if(!z(e))return Fn(Jn(e));let t=B(e).elements,n=1940243425;for(let e=0;e<t.length;e++)n=n+In(t[e])|0;return n}let t=H(e),n=1725019383;for(let e=0;e<t.domain.length;e++)n=n+Ln(t.domain[e],t.range[e])|0;return n},zn=e=>{if(typeof e==`number`)return Nn(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Fn(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=Rn(e)),e.hash;let t=Mn.get(e);if(t!==void 0)return t;let n=Rn(e);return Mn.set(e,n),n},Bn=/* @__PURE__ */ new WeakMap,Vn=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},Hn=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return Vn(t)},Un=e=>Vn(Kn(e)+2135587861|0),Wn=(e,t)=>Vn(Math.imul(Kn(e),374761393)+Kn(t)|0),Gn=e=>{if(e.kind===`ModelValue`)return Vn(Hn(e.name)^60);if(M(e)){if(!z(e))return Hn(Jn(e));let t=B(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+Un(t[e])|0;return n}let t=H(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+Wn(t.domain[e],t.range[e])|0;return n},Kn=e=>{if(typeof e==`number`)return Vn(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return Hn(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=Gn(e)),e.fingerprint;let t=Bn.get(e);if(t!==void 0)return t;let n=Gn(e);return Bn.set(e,n),n},qn=/* @__PURE__ */ new WeakMap,Jn=e=>{if(typeof e==`boolean`)return e?`T`:`F`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return JSON.stringify(e);let t=qn.get(e);if(t!==void 0)return t;let n=Yn(e);return qn.set(e,n),n},Yn=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${Jn(e.base)}>`;if(e.kind===`FilteredSet`&&!z(e))throw new v(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(M(e))return z(e)?`{${B(e).elements.map(Jn).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let t=H(e);return`(${t.domain.map((e,n)=>`${Jn(e)}:${Jn(t.range[n])}`).join(`,`)})`},Xn=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,Zn=e=>e.reduce((e,t)=>e===0?0:e*ln(t),1),Qn=e=>{if(e.kind===`Subset`)return ln(e.base)<=6?B(e):void 0;if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return B(e);if(e.kind===`FunctionSet`&&z(e.domain)&&ln(e.domain)===0)return Qe([$e([],[])]);let t=e.kind===`FunctionSet`?ln(e.range)**ln(e.domain):Zn(e.kind===`RecordSet`?e.sets:e.factors);return t===0?jt:t<=1999?B(e):void 0},$n=(e,t)=>{if(t)return Qn(e);if(z(e))try{return Qn(e)}catch(e){if(e instanceof v)return;throw e}},er=(e,t)=>{let n=e=>U(e,t);switch(e.kind){case`Subset`:return typeof e.base==`object`&&e.base.kind===`Interval`?`SUBSET (${n(e.base)})`:`SUBSET ${n(e.base)}`;case`FunctionSet`:return`[${n(e.domain)} -> ${n(e.range)}]`;case`RecordSet`:return`[${e.names.map((t,r)=>`${t}: ${n(e.sets[r])}`).join(`, `)}]`;case`ProductSet`:return`(${e.factors.map(n).join(` \\X `)})`;case`SetOperation`:return`${n(e.left)} ${e.operator} ${n(e.right)}`;case`FilteredSet`:return`{x \\in ${n(e.base)} : ...}`;case`Union`:return qt(e,t)}},tr=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),U=(e,t=!1,n=!1)=>{let r=e=>U(e,t,n);if(typeof e==`boolean`)return e?`TRUE`:`FALSE`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return Xn(e);switch(e.kind){case`ModelValue`:return e.name;case`Set`:return`{${e.elements.map(r).join(`, `)}}`;case`MixedSet`:return r(B(e));case`Interval`:return e.low<=e.high?`${e.low}..${e.high}`:`{}`;case`InfiniteSet`:return e.name===`Any`?`ANY`:e.name;case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let n=$n(e,t);return n?r(n):er(e,t)}case`SequenceSet`:return`Seq(${r(e.base)})`;case`Function`:case`LazyFunction`:{if(e.kind===`LazyFunction`&&!z(e.domain)){let t=e.source;return t?`[${t.parameters.map(e=>`${e.name} \\in ${U(e.domain)}`).join(`, `)} |-> <expression ${t.body}>]`:`<function>`}let i=H(e),a=r=>U(r,t,n&&e.kind===`Function`);return i.domain.every((e,t)=>e===t+1)?`<<${i.range.map(a).join(`, `)}>>`:i.domain.every(e=>typeof e==`string`&&tr(e))?`[${(n||i.hash!==0||i.fingerprint!==0?i.domain.map((e,t)=>[e,i.range[t]]):je(i)).map(e=>`${String(e[0])} |-> ${a(e[1])}`).join(`, `)}]`:`(${i.domain.map((e,t)=>`${r(e)} :> ${a(i.range[t])}`).join(` @@ `)})`}}},nr=e=>{let t=Object.entries(e);return t.map(([e,n])=>`${t.length===1?``:`/\\ `}${e} = ${Ee(U(n))}\n`).join(``)},rr=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},ir=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=zn(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||nt(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||nt(i[e],n))return i[e]}return n.kind===`Set`?rr(n.elements,t):(rr(n.domain,t),rr(n.range,t)),i===void 0?e.set(r,n):Array.isArray(i)?i.push(n):e.set(r,[i,n]),n};return e=>{for(let n=0;n<e.length;n++)e[n]=t(e[n]);return e}},ar=e=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return[];case`Apply`:return e.args;case`Lambda`:return[e.body];case`And`:case`Or`:return e.operands;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`If`:return[e.condition,e.consequent,e.alternative];case`Case`:return[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]];case`Let`:return[...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),e.body];case`Forall`:case`Exists`:return[...e.bounds.map(e=>e.set),e.body];case`UnboundedQuantifier`:return[e.body];case`Choose`:return[...e.set?[e.set]:[],e.body];case`SetEnumeration`:case`Tuple`:return e.elements;case`SetFilter`:return[e.bound.set,e.predicate];case`SetMap`:return[e.expression,...e.bounds.map(e=>e.set)];case`FunctionConstruction`:return[...e.bounds.map(e=>e.set),e.body];case`FunctionSet`:return[e.domain,e.range];case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`Except`:return[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])];case`FunctionApplication`:return[e.function,...e.args];case`FieldAccess`:return[e.record];case`Product`:return e.factors;case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`Label`:return[e.body];case`Subexpression`:return e.selectors.flatMap(e=>`args`in e?e.args:[])}},W=e=>(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`,or=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),sr=(e,t)=>or.has(e)?new v(t):new y(t),cr=e=>typeof e==`object`&&e.kind===`Operator`,G=(e,t,n)=>{let r=e[t];if(r===void 0||cr(r))throw sr(n,`${n} expects a value as argument ${t+1}`);return r},lr=(e,t,n)=>{let r=G(e,t,n);if(typeof r!=`number`)throw sr(n,`${n} expects an integer but received ${U(r)}`);return r},ur=(e,t,n)=>{let r=G(e,t,n);if(typeof r!=`boolean`)throw sr(n,`${n} expects a boolean but received ${U(r)}`);return r},dr=(e,t,n)=>{let r=G(e,t,n);if(!M(r))throw sr(n,`${n} expects a set but received ${U(r)}`);return r},fr=(e,t,n)=>{let r=dr(e,t,n);if(!z(r))throw sr(n,`${n} cannot enumerate the non-enumerable set ${U(r)}`);return r},pr=(e,t,n)=>B(fr(e,t,n)),mr=(e,t,n)=>pr(e,t,n).elements,hr=(e,t,n)=>{let r=G(e,t,n),i=pn(r);if(!i)throw sr(n,`${n} expects a sequence but received ${U(r)}`);return i},gr=(e,t,n)=>{let r=G(e,t,n);if(!P(r))throw sr(n,`${n} expects a function but received ${U(r)}`);return H(r)},_r=(e,t,n)=>{let r=e[t];if(r===void 0||!cr(r))throw sr(n,`${n} expects an operator as argument ${t+1}`);return r},vr=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),K=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:t===1?e=>n([e]):void 0,evaluateBinary:t===2?(e,t)=>n([e,t]):void 0}),yr=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),br=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),xr=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(G(n,0,e),G(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Sr=e=>e>2147483647||e<-2147483648,Cr=e=>new y(`Overflow when computing ${e}`),wr={ModelValue:`ModelValue`,Set:`SetEnumValue`,Interval:`IntervalValue`,InfiniteSet:`UserValue`,SequenceSet:`UserValue`,Subset:`SubsetValue`,FunctionSet:`SetOfFcnsValue`,RecordSet:`SetOfRcdsValue`,ProductSet:`SetOfTuplesValue`,FilteredSet:`SetPredValue`,LazyFunction:`FcnLambdaValue`,Union:`UnionValue`,MixedSet:`SetEnumValue`},Tr={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},Er={BoolValue:`a Boolean value`,IntValue:`an integer`,StringValue:`a string`,RecordValue:`a record`,SetEnumValue:`a set of the form {e1, ... ,eN}`,SetPredValue:`a set of the form {x \\in S : expr}`,TupleValue:`a tuple`,FcnLambdaValue:`a function of the form [x \\in S |-> expr]`,FcnRcdValue:`a function of the form (d1 :> e1 @@ ... @@ dN :> eN)`,SetOfFcnsValue:`a set of the form [S -> T]`,SetOfRcdsValue:`a set of the form [d1 : S1, ... , dN : SN]`,SetOfTuplesValue:`a cartesian product`,SubsetValue:`a set of the form SUBSET S`,SetDiffValue:`a set of the form S \\ T`,SetCapValue:`a set of the form S \\cap T`,SetCupValue:`a set of the form S \\cup T`,ModelValue:`a model value`,UserValue:`a special set constant`,IntervalValue:`a set of the form i..j`,UnionValue:`a set of the form UNION S`},Dr=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Tr[e.operator];if(e.kind!==`Function`)return wr[e.kind];let t=e.domain;return t.every((e,t)=>e===t+1)?`TupleValue`:t.every(e=>typeof e==`string`)?`RecordValue`:`FcnRcdValue`},Or=e=>Er[Dr(e)],kr=(e,t)=>new v(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),Ar=(e,t)=>{let n=n=>(...r)=>{try{return n(...r)}catch(n){throw n instanceof v&&(e.isLazy===!0||!(n instanceof y))?kr(t,n.message):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},jr=(e,t)=>{if(typeof e!=`number`)throw kr(t,`Cannot cast tlc2.value.impl.${Dr(e)} to tlc2.value.impl.IntValue`);return e},Mr=(e,t,n)=>`public static tlc2.value.impl.${t} tlc2.module.Integers.${e}(${Array.from({length:n},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,Nr=(e,t,n)=>{let r=Mr(t,`IntValue`,2);return xr(e,(t,i)=>{let a=jr(t,r),o=jr(i,r),s=n(a,o);if(Sr(s))throw Cr(`${a}${e}${o}`);return s})},Pr=(e,t,n)=>{if(typeof e!=`number`)throw new y(`The ${t} argument of ${n} should be an integer, but instead it is:\n${U(e)}`);return e},Fr=(e,t)=>xr(e,(n,r)=>t(Pr(n,`first`,e),Pr(r,`second`,e))),Ir=(e,t,n)=>({...br(e,t,n),isLazy:!0}),Lr=(e,t,n)=>{let r=_r(e,t,n);return()=>r.call([])},Rr=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),zr=()=>({bool:Ao,condition:(e,t)=>{if(typeof e!=`boolean`)throw _o(t,e);return e},conjunct:(e,t,n)=>{if(typeof e!=`boolean`)throw vo(t,n,e);return e},apply:On,tuple:R,set:At,record:$e,writtenRecord:Me,equal:et,enumerate:Fo,unassigned:(e,t)=>{throw sc(e,t)},primeOutsideAction:e=>{throw cc(e)},prime:e=>({environment:e.environment,scope:e.scope,state:e.next,next:void 0}),extend:(e,t,n)=>({environment:e.environment,scope:t.reduce((e,t,r)=>Do(e,t,n[r]),e.scope),state:e.state,next:e.next})}),Br={value:void 0},Vr=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),Hr=e=>`local${e.counter++}`,Ur=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),ar(e).forEach(e=>Ur(e,t)),t),Wr=(e,t,n)=>{let r=Vr(e,Y(t,e.environment)),i=Ur(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=Vr(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},Gr=(e,t,n)=>{let r=t.kind===`Forall`,i=JSON.stringify(r?`the body of \\A`:`the body of \\E`),a=`quantifier${e.counter++}`,o=[...n.locals.values()],s={context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:new Map(n.locals)},c=t.bounds.map(()=>Hr(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${qr(e,t.set,s)}, ${Vr(e,t.set)});`),u=t.bounds.map(t=>{let n=Hr(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${qr(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=Hr(e);return`for (let ${i} = 0; ${i} < ${c[r]}.length; ${i}++) { const ${n} = ${c[r]}[${i}]; ${t} }`},d),p=o.map(e=>`, ${e}`).join(``);return e.helpers.push(`function ${a}(context, state, next${p}) { let primed; ${l.join(` `)} ${f} return ${r}; }`),`${a}(${n.context}, ${n.state}, ${n.isPrimed?`undefined`:n.next}${p})`},Kr=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${qr(e,r[0],n)}, "the left side of =>") ? bool(${qr(e,r[1],n)}, "the right side of =>") : true)`;if(W(t))return Wr(e,t,n);let i=Yo(t.operator,e.environment);if(i?.kind!==`Builtin`)return Wr(e,t,n);if(i.name===`DOMAIN`)return`${Vr(e,So(t))}(${qr(e,r[0],n)})`;if(i.name===`TLCEval`)return Wr(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${Vr(e,Co(t,i))}(${qr(e,r[0],n)}, ${qr(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&Vs(r[0],a))return`${Vr(e,i.evaluateUnary)}(${qr(e,r[0],n)})`;let o=r.length===2&&Vs(r[0],a)&&Vs(r[1],a);return i.evaluateBinary&&o?`${Vr(e,i.evaluateBinary)}(${qr(e,r[0],n)}, ${qr(e,r[1],n)})`:Wr(e,t,n)},qr=(e,t,n)=>{let r=(t,r=n)=>qr(e,t,r);if(As(t)&&Ts(t,e.environment))return Wr(e,t,n);switch(t.kind){case`Number`:return ps(t.value)?String(t.value):Wr(e,t,n);case`String`:return JSON.stringify(t.value);case`Identifier`:{let r=n.locals.get(t.name);if(r)return r;if(W(t))return Wr(e,t,n);let i=as(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=Vr(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?Vr(e,i.value):Wr(e,t,n)}case`Apply`:return Kr(e,t,n);case`And`:{let n=Vr(e,t);return`(${t.operands.map((e,t)=>`conjunct(${r(e)}, ${n}, ${t})`).join(` && `)})`}case`Or`:return`(${t.operands.map(e=>`bool(${r(e)}, "a disjunct")`).join(` || `)})`;case`If`:return`(condition(${r(t.condition)}, ${Vr(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{tc(t.function);let n=r(t.function),i=Vr(e,bo(t));return t.args.length===1?`apply(${n}, ${r(t.args[0])}, undefined, ${i})`:`apply(${n}, tuple([${t.args.map(e=>r(e)).join(`, `)}]), undefined, ${i})`}case`FieldAccess`:return`apply(${r(t.record)}, ${JSON.stringify(t.field)}, ${Vr(e,yo(t))}, ${Vr(e,xo(t))})`;case`Record`:{let i=ac(t.fields);if(oc(i))return Wr(e,t,n);let a=Vr(e,i.map(e=>e.name)),o=`[${i.map(e=>r(e.value)).join(`, `)}]`,s=t.fields.map(e=>e.name);return s.every((e,t)=>e===i[t].name)?`record(${a}, ${o})`:`writtenRecord(${a}, ${o}, ${Vr(e,s)})`}case`Tuple`:return`tuple([${t.elements.map(e=>r(e)).join(`, `)}])`;case`SetEnumeration`:return`set([${t.elements.map(e=>r(e)).join(`, `)}])`;case`Prime`:{let i=Vr(e,t);if(n.isPrimed)return`primeOutsideAction(${i})`;let a={context:`(primed ??= prime(${n.context}))`,state:n.next,next:`undefined`,isPrimed:!0,locals:n.locals};return`(${n.next} === undefined ? primeOutsideAction(${i}) : ${r(t.expression,a)})`}case`Unchanged`:return`equal(${r({kind:`Prime`,expression:t.expression,location:t.location})}, ${r(t.expression)})`;case`Forall`:case`Exists`:return t.bounds.every(e=>e.pattern.kind===`Name`)?Gr(e,t,n):Wr(e,t,n);default:return Wr(e,t,n)}},Jr=(e,t)=>{if(!Rr.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=qr(n,e,{context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:/* @__PURE__ */ new Map}),i=n.references.map((e,t)=>`reference${t}`),a=`${n.helpers.join(`
|
|
31
|
-
`)}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${r}; };`;Br.value??=zr();let o=Br.value,s=Object.keys(o);return Function(...s,...i,a)(...Object.values(o),...n.references)},Yr={kind:`Local`},Xr=/* @__PURE__ */ new WeakMap,Zr=e=>{let t=e.lastIndexOf(`@`);return t>0&&t<e.length-1},Qr=new Map([`~>`,`-+->`,`\\cdot`].map(e=>[e,{key:e,arity:2}])),$r=(e,t)=>e.line<t.line||e.line===t.line&&e.column<t.column,ei=e=>e.kind===`Operator`?e.params.length:0,ti=e=>e.name.includes(`!`),ni=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n},ri=(e,t,n=0)=>t.reduce((e,t)=>({name:t,arity:n,parent:e}),e),ii=(e,t)=>t.reduce((e,t)=>({name:t.name,arity:t.arity,parent:e}),e),ai=e=>e.kind===`Name`?[e.name]:e.names,oi=e=>e.flatMap(e=>ai(e.pattern)),si=(e,t)=>{let n=t.definitions.get(e);return n!==void 0&&(n===t.self?n.kind===`Function`||n.isRecursive:n.isRecursive||$r(n.location,t.location))?n:void 0},ci=(e,t)=>{let n=si(e,t);return n?{key:t.getKey(n),arity:ei(n)}:t.imported.get(e)},li=(e,t)=>({module:e.range?.module??``,start:e,end:{line:e.line,column:e.column+t.length-1}}),ui=e=>{if(e.kind===`Apply`){if(e.args.length===2)return`infix`;if(e.args.length===1)return $r(e.location,e.args[0].location)?`prefix`:`postfix`}},di=e=>e[0].toLowerCase()===e[0].toUpperCase()&&e[0]!==`_`&&(e[0]<`0`||e[0]>`9`),fi=e=>e.startsWith(`<`)&&(e[1]>=`0`&&e[1]<=`9`||e[1]===`*`),pi=(e,t,n,r)=>{let i=e.location,a=Xr.get(e);if(a!==void 0)return a;if(Zr(t))return e.kind===`Apply`?e.args.length:0;if(fi(t))return 0;let o=ni(n,t);if(o&&e.kind!==`OperatorReference`&&(e.resolution=Yr),o)return o.arity;let s=ci(t,r);if(s)return e.kind===`Identifier`?e.name=s.key:e.operator=s.key,Xr.set(e,s.arity),s.arity;let c=t.includes(`!`)?t.slice(0,t.indexOf(`!`)):``;if(c!==``&&(ni(n,c)!==void 0||ci(c,r)!==void 0||r.facts.has(c)))return e.kind===`Apply`?e.args.length:0;let l=li(i,t===`-.`?`-`:t);if(!di(t))throw g(`Unknown operator: \`${t}'.`,l);let u={location:h(l),message:`Could not find declaration or definition of symbol '${t}'.`},d=ui(e);throw m(d&&i.range?[u,{location:h(i.range),message:`Couldn't resolve ${d} operator symbol \`${t}'.`}]:[u])},mi=(e,t,n)=>(e.forEach(e=>q(e.set,t,n)),e.reduce((e,t)=>ri(e,ai(t.pattern)),t)),hi=(e,t)=>e.kind===`Identifier`&&e.name===t&&W(e)||ar(e).some(e=>hi(e,t)),gi=(e,t)=>{e.kind===`FunctionConstruction`&&hi(e.body,t)&&(e.isRecursive=!0),ar(e).forEach(e=>gi(e,t))},_i=(e,t,n)=>{let r=ri(t,e.kind===`Function`?[e.name]:[]);e.kind===`Function`?(q(e.body,mi(e.bounds,r,n),n),gi(e.body,e.name)):q(e.body,ii(r,e.params),n)},vi=(e,t,n)=>{let r=e.filter(e=>e.isRecursive).reduce((e,t)=>({name:t.name,arity:ei(t),parent:e}),t);return e.reduce((e,t)=>(ti(t)||_i(t,e,n),{name:t.name,arity:ei(t),parent:e}),r)},yi=(e,t,n,r,i)=>{let a=e.kind===`Operator`?e.params[t]:void 0,o=n.location;if(a?.arity===0&&r>0)throw new p(`Operator used in argument number ${t+1} has incorrect number of arguments at line ${o.line}, column ${o.column}`);let s=i?.kind===`Operator`&&i.params.some(e=>e.arity>0);if(a!==void 0&&a.arity>0&&(r!==a.arity||s))throw new p(`Argument number ${t+1} to operator '${e.name}' should be a ${a.arity}-parameter operator at line ${o.line}, column ${o.column}`)},bi=e=>e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:void 0,xi=(e,t,n)=>{let r=e.operator,i=ni(t,r)?void 0:si(r,n),a=pi(e,r,t,n);if(a!==e.args.length)throw g(`The operator ${r} requires ${a} arguments.`,e.argumentsRange??li(e.location,r));e.args.forEach((e,r)=>{let a=bi(e),o=a===void 0||ni(t,a)?void 0:si(a,n),s=Si(e,t,n);i&&yi(i,r,e,s,o)})},Si=(e,t,n)=>e.kind===`Identifier`?pi(e,e.name,t,n):e.kind===`OperatorReference`?pi(e,e.operator,t,n):(q(e,t,n),e.kind===`Lambda`?e.params.length:0),q=(e,t,n)=>{let r=e=>e.forEach(e=>q(e,t,n));switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return;case`Identifier`:{let r=e.name,i=pi(e,r,t,n);if(i>0)throw g(`The operator ${r} requires ${i} arguments.`,li(e.location,r));return}case`OperatorReference`:pi(e,e.operator,t,n);return;case`Apply`:xi(e,t,n);return;case`Lambda`:q(e.body,ri(t,e.params),n);return;case`And`:case`Or`:r(e.operands);return;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:q(e.expression,t,n);return;case`If`:r([e.condition,e.consequent,e.alternative]);return;case`Case`:r(e.arms.flatMap(e=>[e.condition,e.body])),e.other&&q(e.other,t,n);return;case`Let`:q(e.body,vi(e.definitions,t,n),n);return;case`Forall`:case`Exists`:case`FunctionConstruction`:q(e.body,mi(e.bounds,t,n),n);return;case`UnboundedQuantifier`:q(e.body,ri(t,e.names),n);return;case`Choose`:e.set&&q(e.set,t,n),q(e.body,ri(t,ai(e.pattern)),n);return;case`SetEnumeration`:case`Tuple`:r(e.elements);return;case`SetFilter`:q(e.predicate,mi([e.bound],t,n),n);return;case`SetMap`:q(e.expression,mi(e.bounds,t,n),n);return;case`FunctionSet`:r([e.domain,e.range]);return;case`Record`:case`RecordSet`:{let t=e.fields.filter((t,n)=>e.fields.slice(0,n).some(e=>e.name===t.name));if(t.length>0)throw m(t.map(e=>({location:h(e.location.range??li(e.location,e.name)),message:`Non-unique fields in constructor.`})));r(e.fields.map(e=>e.value));return}case`Except`:r([e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])]);return;case`FunctionApplication`:r([e.function,...e.args]);return;case`FieldAccess`:q(e.record,t,n);return;case`Product`:r(e.factors);return;case`BoxAction`:case`AngleAction`:r([e.action,e.subscript]);return;case`WeakFairness`:case`StrongFairness`:r([e.subscript,e.action]);return;case`Label`:q(e.body,t,n);return;case`Subexpression`:e.selectors.flatMap(e=>`args`in e?e.args:[]).forEach(e=>Si(e,t,n))}},Ci=(e,t,n)=>(e.set&&q(e.set,t,n),{name:e.name,arity:e.arity,parent:t}),wi=(e,t,n)=>{let r=e.assumptions.reduce((e,t)=>t.kind===`NewSymbol`?Ci(t,e,n):(t.kind===`AssumeProve`?wi(t,e,n):q(t,e,n),e),t);return q(e.conclusion,r,n),r},Ti=(e,t,n)=>e.kind===`AssumeProve`?wi(e,t,n):(q(e,t,n),t),Ei=(e,t,n)=>{e?.kind===`Steps`&&e.steps.reduce((e,t)=>Di(t,e,n),t)},Di=(e,t,n)=>{let r=e.body;switch(r.kind){case`Assert`:{let i=Ti(r.statement,t,n);return Ei(e.proof,i,n),r.isSuffices?i:t}case`Define`:return vi(r.definitions.flatMap(e=>e.kind===`Instance`?[]:[e]),t,n);case`Have`:case`Case`:return q(r.expression,t,n),Ei(e.proof,t,n),t;case`Witness`:return r.expressions.forEach(e=>q(e,t,n)),t;case`Take`:return ri(mi(r.bounds,t,n),r.names);case`Pick`:{let i=ri(mi(r.bounds,t,n),r.names);return q(r.body,i,n),Ei(e.proof,t,n),i}default:return Ei(e.proof,t,n),t}},Oi=(e,t)=>{let n=e.name!==void 0&&e.statement.kind!==`AssumeProve`?void 0:Ti(e.statement,void 0,t);Ei(e.proof,n,t)},ki=(e,t)=>new p(`Multiply-defined symbol '${e}' at line ${t.line}, column ${t.column}`),Ai=(e,t,n,r)=>t.reduce((e,t)=>{if(ni(e,t)||n(t))throw ki(t,r);return{name:t,arity:0,parent:e}},e),ji=(e,t,n,r)=>(e.forEach(e=>Ni(e.set,t,n)),e.reduce((e,t)=>Ai(e,ai(t.pattern),n,r),t)),Mi=(e,t,n)=>{if(e.kind===`Function`){let r=ri(t,[e.name]),i=ji(e.bounds,r,n,e.location);Ni(e.body,i,n);return}let r=Ai(t,e.params.map(e=>e.name),n,e.location);Ni(e.body,r,n)},Ni=(e,t,n)=>{let r=e.location;switch(e.kind){case`Lambda`:Ni(e.body,Ai(t,e.params,n,r),n);return;case`Let`:{let i=e.definitions.filter(e=>e.isRecursive).map(e=>e.name),a=e.definitions.reduce((e,t)=>{if(ni(e,t.name)||n(t.name))throw ki(t.name,t.location);return Mi(t,ri(e,i),n),ri(e,[t.name])},t);Ni(e.body,Ai(a,(e.instances??[]).flatMap(e=>e.name===void 0?[]:[e.name]),n,r),n);return}case`Forall`:case`Exists`:case`FunctionConstruction`:Ni(e.body,ji(e.bounds,t,n,r),n);return;case`SetFilter`:Ni(e.predicate,ji([e.bound],t,n,r),n);return;case`SetMap`:Ni(e.expression,ji(e.bounds,t,n,r),n);return;case`UnboundedQuantifier`:Ni(e.body,Ai(t,e.names,n,r),n);return;case`Choose`:e.set&&Ni(e.set,t,n),Ni(e.body,Ai(t,ai(e.pattern),n,r),n);return;default:ar(e).forEach(e=>Ni(e,t,n))}},Pi=e=>[...e.definitions.map(e=>({name:e.name,kind:`Definition`,location:e.location,isRecursive:e.isRecursive})),...e.instances.flatMap(e=>e.name===void 0?[]:[{name:e.name,kind:`Definition`,location:e.location,isRecursive:!1}]),...e.constants.map(e=>({name:e.name,kind:`Constant`,location:e.location,isRecursive:!1})),...e.variables.map(e=>({name:e.name,kind:`Variable`,location:e.location,isRecursive:!1}))],Fi=(e,t)=>{let n=/* @__PURE__ */ new Map;Pi(e).sort((e,t)=>$r(e.location,t.location)?-1:1).forEach(e=>n.set(e.name,[...n.get(e.name)??[],e]));let r=(e,n)=>{if(!t.imported.has(e)&&!Qr.has(e))return!1;let r=t.importedAt.get(e);return r===void 0||$r(r,n)};n.forEach(e=>e.forEach((n,i)=>{let a=e.slice(0,i).some(e=>e.kind===`Definition`||n.kind===`Definition`||e.kind!==n.kind),o=t.imported.get(n.name)?.declaration===n.kind;if(a||!o&&r(n.name,n.location))throw ki(n.name,n.location)}));let i=e=>t=>(n.get(t)??[]).some(t=>t.isRecursive||$r(t.location,e))||r(t,e);e.definitions.forEach(e=>Mi(e,void 0,i(e.location))),e.assumptions.forEach(e=>Ni(e.expression,void 0,i(e.location))),e.instances.forEach(e=>{let t=i(e.location),n=Ai(void 0,e.params.map(e=>e.name),t,e.location);e.substitutions.forEach(e=>Ni(e.expression,n,t))})},Ii=(e,t)=>{let n=new Map([...Qr,...t]);return e.constants.forEach(e=>n.set(e.name,{key:e.name,arity:e.arity})),e.variables.forEach(e=>n.set(e.name,{key:e.name,arity:0})),n},Li=(e,t,n,r)=>{let i=ii(void 0,e.params),a={imported:Ii(n,r.imported),definitions:r.definitions,getKey:r.getKey,location:e.location,self:void 0,facts:/* @__PURE__ */ new Set},o=new Map(e.substitutions.map(e=>[e.name,e.expression])),s=`in the instance of ${e.module} at line ${e.location.line}, column ${e.location.column}`;return o.forEach((e,n)=>{if(t.every(e=>e.name!==n))throw new p(`Identifier '${n}' is not a legal target of a substitution ${s}`)}),new Map(t.map(t=>{let n=t.name;if(!o.has(n)&&!ni(i,n)&&!ci(n,a))throw new p(`Substitution missing for symbol ${n} ${s}`);let r=o.get(n)??{kind:`Identifier`,name:n,location:e.location};if(t.arity===0||r.kind!==`Identifier`)return q(r,i,a),[n,r];if(pi(r,r.name,i,a)!==t.arity)throw new p(`An operator must be substituted for symbol '${n}', and it must have arity ${t.arity} ${s}`);return[n,r]}))},Ri=e=>{let t=[];if(e.toSorted((e,t)=>$r(e.location,t.location)?-1:1).forEach(e=>{try{e.check()}catch(e){if(!(e instanceof p)||!e.sany)throw e;e.sany.errors.filter(e=>t.every(t=>t.location!==e.location||t.message!==e.message)).forEach(e=>t.push(e))}}),t.length>0)throw m(t)},zi=(e,t)=>{let n=Ii(e,t.imported),r=new Set([...e.theorems,...e.assumptions].flatMap(e=>e.name??[])),i=(e,i)=>({imported:n,definitions:t.definitions,getKey:t.getKey,location:e,self:i,facts:r});Ri([...e.definitions.map(e=>({location:e.location,check:()=>_i(e,void 0,i(e.location,e))})),...e.assumptions.map(e=>({location:e.location,check:()=>q(e.expression,void 0,i(e.location,void 0))})),...e.theorems.map(e=>({location:e.location,check:()=>Oi(e,i(e.location,void 0))}))])},Bi=/* @__PURE__ */ new WeakSet,Vi=/* @__PURE__ */ new WeakSet,Hi=(e,t,n=/* @__PURE__ */ new Set)=>{let r=Ji(e,(e,r)=>Hi(e,t,r.length===0?n:/* @__PURE__ */ new Set([...n,...r])));return r.kind===`Identifier`&&W(r)&&!n.has(r.name)?{...r,name:t.get(r.name)??r.name}:r.kind===`Apply`&&W(r)&&!n.has(r.operator)?{...r,operator:t.get(r.operator)??r.operator}:r},Ui=(e,t)=>e.map(e=>({pattern:e.pattern,set:t(e.set)})),Wi=/* @__PURE__ */ new WeakMap,Gi=e=>Wi.get(e)??e.name,Ki=(e,t)=>(Gi(t)!==e.name&&Wi.set(e,Gi(t)),e),qi=(e,t)=>Ki(e.kind===`Function`?{...e,bounds:Ui(e.bounds,e=>t(e,[])),body:t(e.body,oi(e.bounds))}:{...e,body:t(e.body,e.params.map(e=>e.name))},e),Ji=(e,t)=>{let n=e=>t(e,[]);switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return e;case`Apply`:return{...e,args:e.args.map(n)};case`Lambda`:return{...e,body:t(e.body,e.params)};case`And`:case`Or`:return{...e,operands:e.operands.map(n)};case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return{...e,expression:n(e.expression)};case`If`:return{...e,condition:n(e.condition),consequent:n(e.consequent),alternative:n(e.alternative)};case`Case`:return{...e,arms:e.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:e.other?n(e.other):void 0};case`Let`:{let n=e.definitions.map(e=>e.name);return{...e,definitions:e.definitions.map(e=>qi(e,(e,r)=>t(e,[...n,...r]))),body:t(e.body,n)}}case`Forall`:case`Exists`:case`FunctionConstruction`:return{...e,bounds:Ui(e.bounds,n),body:t(e.body,oi(e.bounds))};case`UnboundedQuantifier`:return{...e,body:t(e.body,e.names)};case`Choose`:return{...e,set:e.set?n(e.set):void 0,body:t(e.body,ai(e.pattern))};case`SetEnumeration`:case`Tuple`:return{...e,elements:e.elements.map(n)};case`SetFilter`:return{...e,bound:{pattern:e.bound.pattern,set:n(e.bound.set)},predicate:t(e.predicate,ai(e.bound.pattern))};case`SetMap`:return{...e,bounds:Ui(e.bounds,n),expression:t(e.expression,oi(e.bounds))};case`FunctionSet`:return{...e,domain:n(e.domain),range:n(e.range)};case`Record`:case`RecordSet`:return{...e,fields:e.fields.map(e=>({...e,value:n(e.value)}))};case`Except`:return{...e,function:n(e.function),updates:e.updates.map(e=>({path:e.path.map(e=>e.kind===`Index`?{kind:`Index`,args:e.args.map(n)}:e),value:n(e.value)}))};case`FunctionApplication`:return{...e,function:n(e.function),args:e.args.map(n)};case`FieldAccess`:return{...e,record:n(e.record)};case`Product`:return{...e,factors:e.factors.map(n)};case`BoxAction`:case`AngleAction`:return{...e,action:n(e.action),subscript:n(e.subscript)};case`WeakFairness`:case`StrongFairness`:return{...e,subscript:n(e.subscript),action:n(e.action)};case`Label`:return{...e,body:n(e.body)};case`Subexpression`:return{...e,selectors:e.selectors.map(e=>`args`in e?{...e,args:e.args.map(n)}:e)}}},Yi=`LAMBDA`,Xi=(e,t=/* @__PURE__ */ new Set)=>{let n=e.kind===`Identifier`?e.name:e.kind===`Apply`||e.kind===`OperatorReference`?e.operator:void 0,r=n===void 0||t.has(n)?[]:[n];return Ji(e,(e,n)=>(r.push(...Xi(e,n.length===0?t:/* @__PURE__ */ new Set([...t,...n]))),e)),r},Zi=e=>{let t=/* @__PURE__ */ new Map;return n=>{if(!e.substitutedNames.has(n))return n;let r=t.get(n)??e.instantiation.createName(n);return t.set(n,r),r}},Qi=(e,t,n)=>new Map([...e,...t.map(e=>[e,n(e)])]),$i=(e,t)=>e.kind===`Name`?{kind:`Name`,name:t(e.name)}:{kind:`Tuple`,names:e.names.map(t)},ea=(e,t)=>e.map(e=>({pattern:$i(e.pattern,t),set:e.set})),ta=(e,t)=>e.kind===`Function`?{...e,bounds:ea(e.bounds,t)}:{...e,params:e.params.map(e=>({name:t(e.name),arity:e.arity}))},na=(e,t,n)=>{let r=e=>t.get(e)??e;switch(e.kind){case`Identifier`:return{...e,name:r(e.name)};case`Apply`:case`OperatorReference`:return{...e,operator:r(e.operator)};case`Label`:return{...e,params:e.params.map(r)};case`Lambda`:return{...e,params:e.params.map(n)};case`Let`:return{...e,definitions:e.definitions.map(e=>Ki({...ta(e,n),name:n(e.name)},e))};case`Forall`:case`Exists`:case`FunctionConstruction`:case`SetMap`:return{...e,bounds:ea(e.bounds,n)};case`UnboundedQuantifier`:return{...e,names:e.names.map(n)};case`Choose`:return{...e,pattern:$i(e.pattern,n)};case`SetFilter`:return{...e,bound:{pattern:$i(e.bound.pattern,n),set:e.bound.set}};default:return e}},ra=e=>`${e}@ENABLED`,ia=(e,t)=>e.modes.get(t)??e,aa=(e,t,n)=>e.kind===`Identifier`&&!n.has(e.name)&&!W(e)&&t.instantiation.variables.has(e.name),oa=(e,t,n)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>oa(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`)return;if(aa(e,t,n))return[e.name];let r=W(e)?void 0:t.instantiation.getDefinition(e.name);return r?.kind===`Operator`&&r.params.length===0?oa(r.body,t,/* @__PURE__ */ new Map):void 0},sa=(e,t,n)=>{if(t.mode===`Normal`)return;if(t.mode===`Primed`)return aa(e,t,n)&&e.kind===`Identifier`?{kind:`Identifier`,name:ra(e.name),location:e.location}:void 0;if(e.kind===`Prime`)return{...e,expression:fa(e.expression,ia(t,`Primed`),n)};if(e.kind===`AngleAction`){let r=e.location;return{kind:`And`,operands:[fa(e.action,t,n),{kind:`Apply`,operator:`#`,args:[{kind:`Prime`,expression:fa(e.subscript,ia(t,`Primed`),n),location:r},fa(e.subscript,t,n)],location:r}],location:r}}if(e.kind!==`Unchanged`)return;let r=oa(e.expression,t,n);if(r!==void 0)return{kind:`And`,operands:r.map(r=>({kind:`Apply`,operator:`=`,args:[{kind:`Prime`,expression:{kind:`Identifier`,name:ra(r),location:e.location},location:e.location},fa({kind:`Identifier`,name:r,location:e.location},t,n)],location:e.location})),location:e.location}},ca=(e,t)=>({kind:`Identifier`,name:e,location:t,resolution:{kind:`Local`}}),la=(e,t)=>e.map(e=>ca(e.name,t)),ua=(e,t,n,r)=>{let i=Array.from({length:n},(e,t)=>`argument${t}`);return{kind:`Lambda`,params:i,body:{kind:`Apply`,operator:e,args:[...la(t,r),...i.map(e=>ca(e,r))],location:r},location:r}},da=(e,t)=>e.instantiation.isParameterized(t)?ma(e,t):void 0,fa=(e,t,n)=>{let r=e=>fa(e,t,n),i=t.instantiation,a=i.params,o=t=>!n.has(t)&&!W(e);if(e.kind===`Enabled`&&t.mode===`Normal`)return{...e,expression:fa(e.expression,ia(t,`Enabled`),n)};if((e.kind===`WeakFairness`||e.kind===`StrongFairness`)&&t.mode===`Normal`)return{...e,subscript:r(e.subscript),action:r(e.action),enabled:fa(e.enabled??{kind:`AngleAction`,action:e.action,subscript:e.subscript,location:e.location},ia(t,`Enabled`),n)};let s=sa(e,t,n);if(s)return s;if(e.kind===`Identifier`&&o(e.name)){let n=i.substitutions.get(e.name);if(n)return Bi.add(n),n;let r=da(t,e.name);if(r===void 0)return e;if(a.length===0)return{...e,name:r};let o=i.getDefinition(e.name);return o&&ei(o)>0?ua(r,a,ei(o),e.location):{kind:`Apply`,operator:r,args:la(a,e.location),location:e.location}}if(e.kind===`Apply`&&o(e.operator)){let n=e.args.map(r),o=i.substitutions.get(e.operator),s=i.substitutions.size>0||a.length>0||Vi.has(e),c=e=>(s&&Vi.add(e),e);if(o?.kind===`Identifier`||o?.kind===`OperatorReference`){let t=o.kind===`Identifier`?o.name:o.operator;return c({...e,operator:t,args:n,resolution:o.kind===`Identifier`?o.resolution:void 0})}if(o?.kind===`Apply`)return c({...e,operator:o.operator,args:[...o.args,...n],resolution:o.resolution});if(o?.kind===`Lambda`)return{kind:`Let`,definitions:[{kind:`Operator`,name:Yi,params:o.params.map(e=>({name:e,arity:0})),body:o.body,isLocal:!0,isRecursive:!1,location:o.location}],body:{...e,operator:Yi,args:n,resolution:{kind:`Local`}},location:e.location};if(o)throw new p(`The operator ${e.operator} can only be substituted by an operator at line ${e.location.line}, column ${e.location.column}`);let l=da(t,e.operator);return l===void 0?c({...e,args:n}):{...e,operator:l,args:[...la(a,e.location),...n]}}if(e.kind===`OperatorReference`&&o(e.operator)){let n=da(t,e.operator);if(n===void 0)return e;let r=i.getDefinition(e.operator);return a.length>0&&r?ua(n,a,ei(r),e.location):{...e,operator:n}}let c=Zi(t),l=Ji(e,(e,i)=>i.length===0?r(e):fa(e,t,Qi(n,i,c)));return na(l,n,c)},pa=(e,t,n)=>t.length===0?e:e.kind===`Operator`?{...e,params:[...t,...e.params]}:{kind:`Operator`,name:e.name,params:t,body:{kind:`Let`,definitions:[e],body:ca(e.name,n),location:n},isLocal:e.isLocal,isRecursive:!1,location:e.location},ma=(e,t)=>{let n=e.copies.get(t);if(n!==void 0)return n;let r=e.instantiation,i=r.getDefinition(t);return i?r.addDefinition(t,i.name,n=>{e.copies.set(t,n);let a=Zi(e),o=ta(qi(i,(t,n)=>fa(t,e,Qi(/* @__PURE__ */ new Map,n,a))),a);return pa(o,r.params,i.location)}):t},ha=e=>{let t=/* @__PURE__ */ new Map,n=new Set([...e.substitutions.values()].flatMap(e=>Xi(e))),r=r=>{let i={instantiation:e,substitutedNames:n,copies:/* @__PURE__ */ new Map,mode:r,modes:t};return t.set(r,i),i},i=r(`Normal`);return r(`Enabled`),r(`Primed`),{getKey:e=>da(i,e)??e,getQualifiedKey:t=>{let n=da(i,t);if(n!==void 0)return n;let r=e.getDefinition(t);return r?e.addDefinition(t,r.name,()=>pa(r,e.params,r.location)):t}}},ga=e=>e.kind===`Let`&&e.instances!==void 0||ar(e).some(ga),_a=(e,t,n)=>{let r=e.kind===`Let`?[...n,...e.definitions]:n,i=Ji(e,e=>_a(e,t,r));return i.kind!==`Let`||!i.instances?i:{kind:`Let`,definitions:i.instances.reduce((e,n)=>{let i=e.findIndex(e=>$r(n.location,e.location)),a=i===-1?e.length:i;return[...e.slice(0,a),...t(n,r),...e.slice(a)]},i.definitions),body:i.body,location:i.location}},va=e=>e.name===void 0&&e.statement.kind!==`AssumeProve`?e.statement:void 0,ya=(e,t)=>e.definitions.some(e=>ga(e.body))||e.assumptions.some(e=>ga(e.expression))||e.theorems.some(e=>{let t=va(e);return t!==void 0&&ga(t)})?{...e,definitions:e.definitions.map(e=>qi(e,e=>_a(e,t,[]))),assumptions:e.assumptions.map(e=>({...e,expression:_a(e.expression,t,[])})),theorems:e.theorems.map(e=>{let n=va(e);return n===void 0?e:{...e,statement:_a(n,t,[])}})}:e,ba=/* @__PURE__ */ new WeakMap,xa=/* @__PURE__ */ new WeakMap,J=(e,t,n)=>e.isInit?{environment:e.environment,scope:t,state:n,next:void 0}:{environment:e.environment,scope:t,state:e.current,next:n},Sa=(e,t,n)=>{let r=e.slice();return r[t]=n,r},Ca=(e,t,n)=>{if(typeof t==`boolean`)return t;throw new v(`In computing ${n?`initial`:`next`} states, TLC expected a boolean expression,\nbut instead found ${U(t)}.\n${go(e)}`)},wa=(t,r,i=X(t,r))=>{if(r.next!==void 0&&t.kind===`Number`)throw n(new v(`The next state relation is not a boolean expression.\n${t.text??t.value}`),e.error);return Ca(t,i,r.next===void 0)},Ta=e=>e===`=`||e===`\\in`||e===`\\subseteq`,Ea=/* @__PURE__ */ new WeakMap,Da=(e,t)=>{if(!e.trace)return t?ba:xa;let n=Ea.get(e)??[/* @__PURE__ */ new WeakMap,/* @__PURE__ */ new WeakMap];return Ea.set(e,n),n[+!t]},Oa=(e,t,n)=>{let r=Da(t,n),i=r.get(e);if(i)return i;let a=io(e,t,n),o=t.trace,s=o?(t,n,r,i,s,c)=>{let l=o.length;o.push(e),a(t,n,r,i,s,c),o.length=l}:a;return r.set(e,s),s},ka=(e,t)=>{if(t.constants.has(e))return;let n=jo(e,t);return n?.kind===`Operator`&&n.params.length===0?n:void 0},Aa=(e,t,n,r=/* @__PURE__ */ new Set)=>{if(e.kind===`Prime`&&n)return Aa(e.expression,t,!1,r);if(e.kind!==`Identifier`||W(e))return;let i=t.variableIndex.get(e.name);if(i!==void 0)return n?void 0:i;let a=ka(e.name,t);if(a&&!r.has(a))return r.add(a),Aa(a.body,t,n,r)},ja=(e,t,n)=>Aa(e,t,!n),Ma=(e,t,n,r,i)=>{if(e.kind===`Prime`&&i)return Ma(e.expression,t,n,r,!1);if(e.kind===`Let`){let a=ds(e.definitions,J(r,t,n));return Ma(e.body,a,n,r,i)}if(e.kind!==`Identifier`)return;let a=Eo(t,e.name);if(a?.kind===`Thunk`)return Ma(a.expression,a.scope,n,r,i);if(a)return;let o=r.environment.variableIndex.get(e.name);if(o!==void 0)return i?void 0:o;let s=ka(e.name,r.environment);if(s)return Ma(s.body,void 0,n,r,i)},Na=(e,t)=>e.kind===`Let`||e.kind===`Identifier`&&(t||W(e))||!t&&e.kind===`Prime`,Pa=(e,t,n=/* @__PURE__ */ new Set)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>Pa(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`||n.has(e.name))return;let r=t.variableIndex.get(e.name);if(r!==void 0)return[r];let i=ka(e.name,t);if(i)return n.add(e.name),Pa(i.body,t,n)},Fa=(e,t)=>{if(e.kind===`Tuple`)return[e,...e.elements.flatMap(e=>Fa(e,t))];let n=e.kind===`Identifier`&&!t.variableIndex.has(e.name)?ka(e.name,t):void 0;return n?[e,...Fa(n.body,t)]:[e]},Ia=/* @__PURE__ */ new Set([`Label`,`And`,`Or`,`Exists`,`Forall`,`If`,`Case`,`Let`,`Unchanged`,`BoxAction`,`AngleAction`,`FunctionApplication`]),La=(e,t,n)=>Ia.has(e.kind)?!1:e.kind===`Identifier`?t.variableIndex.has(e.name)||t.constants.has(e.name):e.kind===`Apply`?e.operator===`=>`||Ta(e.operator)&&(Na(e.args[0],n)||ja(e.args[0],t,n)!==void 0)||W(e)?!1:t.definitions.get(t.substitutions.get(e.operator)??e.operator)===void 0&&t.builtins.has(e.operator):!0,Ra=/* @__PURE__ */ new Set,za=(e,t)=>{if(W(e))return e.kind===`Identifier`?t.has(e.name)?[]:[e.name]:void 0;let n=[],r={isReadOnly:!0};return Ji(e,(e,i)=>{let a=r.isReadOnly?za(e,i.length===0?t:/* @__PURE__ */ new Set([...t,...i])):[];return a?n.push(...a):r.isReadOnly=!1,e}),r.isReadOnly?n:void 0},Ba=(e,t,n)=>{if(e.kind===`Or`||e.kind===`Exists`)return!0;let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,i=r===void 0||W(e)?void 0:jo(r,t);return i&&!n.has(i)&&(n.add(i),Ba(i.body,t,n))?!0:ar(e).some(e=>Ba(e,t,n))},Va=(e,t,n)=>{if(e.kind===`Apply`&&e.operator===`=`){let r=ja(e.args[0],t,n);if(r!==void 0)return{kind:`Assign`,expression:e,index:r,value:e.args[1]}}if(!n&&e.kind===`Unchanged`){let n=Pa(e.expression,t);if(n)return{kind:`Unchanged`,expression:e,indices:n}}return La(e,t,n)?{kind:`Guard`,expression:e}:{kind:`Branch`,expression:e,runner:Oa(e,t,n)}},Ha=(e,t)=>{if(e.bounds.length<2||e.body.kind!==`And`)return;let n=e.bounds.flatMap(e=>e.pattern.kind===`Name`?[e.pattern.name]:[]);if(n.length!==e.bounds.length)return;let r=new Set(n.slice(0,-1)),i=e.body.operands,a=i.findIndex(e=>{if(pc(e,t)===void 0||Ba(e,t,/* @__PURE__ */ new Set))return!0;let n=za(e,Ra);return!n||n.some(e=>r.has(e))}),o=a===-1?i.length:a;if(o!==0)return{names:n,guards:i.slice(0,o),rest:i.slice(o)}},Ua=(e,t,n)=>{let r=e.map(e=>Va(e,t,n)),i=r.map(()=>void 0),a=t.trace,o=(e,n,s,c,l,u)=>{let d=c,f;for(let c=e;c<r.length;c++){if(c>0&&n.isInit&&co(d)){f??=J(n,s,d);for(let e=c;e<r.length;e++)if(!Wa(r[e].expression,f))return;u(d,l);return}let e=r[c];if(a&&(a.push(e.expression),e.expression.kind===`Unchanged`&&a.push(...Fa(e.expression.expression,t))),e.kind===`Guard`){f??=J(n,s,d);let r=i[c]??=Is(e.expression,t);if(!wa(e.expression,f,r(f)))return;continue}if(e.kind===`Assign`){f??=J(n,s,d);let r=(i[c]??=Is(e.value,t))(f),a=d[e.index];if(a===void 0)d=Sa(d,e.index,r),f=void 0;else if(!et(a,r))return;continue}if(e.kind===`Unchanged`){let t=n.current;if(!t)return;for(let n of e.indices){let e=d[n];if(e===void 0)d=Sa(d,n,t[n]),f=void 0;else if(!et(e,t[n]))return}continue}let p=c+1;e.runner(n,s,d,l,!0,(e,t)=>o(p,n,s,e,t,u));return}u(d,l)};return(e,t,n,r,i,a)=>o(0,e,t,n,r,a)},Wa=(e,t)=>Ca(e,X(e,t),!0),Ga=e=>(t,n,r,i,a,o)=>{wa(e,J(t,n,r))&&o(r,i)},Ka=(e,t)=>{let n=e.args[1];return(r,i,a,o,s,c)=>{let l=t(r,i,a),u=J(r,i,a);if(a[l]!==void 0){wa(e,u)&&c(a,o);return}let d=X(n,u),f=e.operator===`\\subseteq`?{kind:`Subset`,base:d}:d;if(!z(f))throw new v(`In computing ${r.isInit?`initial`:`next`} states, the right side of \\IN is not enumerable.\n${go(e)}`);let p=on(f);for(let e=0;e<p.length&&!r.isStopped;e++)c(Sa(a,l,p[e]),o)}},qa=/* @__PURE__ */ new WeakMap,Ja=e=>{let t=qa.get(e);if(t)return t;let n=e.kind===`Tuple`?{kind:`And`,operands:e.elements.map(Ja),location:e.location}:{kind:`Unchanged`,expression:e,location:e.location};return qa.set(e,n),n},Ya=(e,t)=>{let n=e.args[0],r=Ga(e),i=(e,r,i)=>Ma(n,r,i,e,!t)??-1,a=Ka(e,i);return(t,n,o,s,c,l)=>{let u=i(t,n,o);if(u===-1||o[u]!==void 0){r(t,n,o,s,c,l);return}if(e.operator!==`=`){a(t,n,o,s,c,l);return}let d=X(e.args[1],J(t,n,o));l(Sa(o,u,d),s)}},Xa=(e,t,n,r)=>{if(e.kind===`FunctionConstruction`)return{bounds:e.bounds,body:e.body,scope:t};if(e.kind!==`Identifier`)return;let i=Eo(t,e.name);if(i?.kind===`Thunk`)return Xa(i.expression,i.scope,n,r);let a=i?void 0:jo(e.name,r.environment);if(a?.kind!==`Function`)return;let o=X(e,J(r,void 0,n));return{bounds:a.bounds,body:a.body,scope:Do(void 0,a.name,o)}},Za=(e,t,n)=>{let r=Ga(e);return(i,a,o,s,c,l)=>{let u=Xa(e.function,a,o,i);if(!u){r(i,a,o,s,c,l);return}let d=J(i,a,o),f=e.args.map(e=>X(e,d)),p=f.length===1?f[0]:R(f),m=Lo(u.bounds,J(i,u.scope,o));if(!gn(p,m))throw new v(`Attempted to apply a function to ${U(p)}, which is not in its domain at ${ho(e)}`);Oa(u.body,t,n)(i,Ro(u.bounds,u.scope,p),o,s,c,l)}},Qa=(e,t)=>{if(Pa(e,t))return Ua([Ja(e)],t,!1);if(e.kind===`Tuple`)return Oa(Ja(e),t,!1);let n=Ja(e);return(r,i,a,o,s,c)=>{let l=e.kind===`Identifier`?Eo(i,e.name):void 0;l?.kind===`Thunk`?Oa(Ja(l.expression),t,!1)(r,l.scope,a,o,s,c):wa(n,J(r,i,a))&&c(a,o)}},$a=(e,t,n)=>{let r=e.operator,i=Ga(e),a=W(e)?void 0:Yo(r,t);if(a?.kind===`Builtin`)return i;if(a?.kind===`Closure`){let i=Ws(a,e.args,t),o={body:void 0};return(e,s,c,l,u,d)=>{o.body??=Oa(a.body,t,n),o.body(e,i(J(e,s,c)),c,u?l:r,u,d)}}return(a,o,s,c,l,u)=>{let d=J(a,o,s),f=Zo(e,d);f?.kind===`Closure`?Oa(f.body,t,n)(a,ls(f,e.args,d),s,l?c:r,l,u):i(a,o,s,c,l,u)}},eo=(e,t,n)=>{let r=Ga(e),i=W(e)?void 0:ka(e.name,t),a={body:void 0};return(o,s,c,l,u,d)=>{let f=Eo(s,e.name);f?.kind===`Thunk`?Oa(f.expression,t,n)(o,f.scope,c,l,u,d):f||!i?r(o,s,c,l,u,d):(a.body??=Oa(i.body,t,n),a.body(o,void 0,c,u?l:i.name,u,d))}},to=(e,t,n)=>{if(n.has(e))return;if(n.add(e),e.kind===`And`){let n=e.operands[0];if(n.kind!==`Apply`||n.operator!==`=`||W(n))return;let r=n.args[0],i=n.args[1];if(r.kind!==`FunctionApplication`||i.kind!==`String`)return;let a=r.args.length===1?r.args[0]:void 0;if(a?.kind!==`Identifier`||!W(a))return;let o=Aa(r.function,t,!1);return o===void 0?void 0:{variable:o,argument:a.name,labels:/* @__PURE__ */ new Set([i.value])}}if(e.kind===`Or`){let r=e.operands.map(e=>to(e,t,n)),i=r[0],a=r.every(e=>e!==void 0&&e.variable===i?.variable&&e.argument===i.argument);if(!i||!a)return;let o=new Set(r.flatMap(e=>[...e?.labels??[]]));return{variable:i.variable,argument:i.argument,labels:o}}if(e.kind!==`Apply`||W(e))return;let r=Yo(e.operator,t);if(r?.kind!==`Closure`||r.scope!==void 0)return;let i=to(r.body,t,n),a=r.params.findIndex(e=>e.arity===0&&e.name===i?.argument),o=e.args[a];if(i&&o?.kind===`Identifier`&&W(o))return{variable:i.variable,argument:o.name,labels:i.labels}},no=(e,t,n)=>{let r=Eo(t,n.argument),i=e.current?.[n.variable];if(r?.kind!==`Value`||typeof i!=`object`||i.kind!==`Function`)return;let a=i.domain.indexOf(r.value),o=a===-1?void 0:i.range[a];return typeof o==`string`?o:void 0},ro=(e,t,n)=>{let r=e.map(e=>Oa(e,t,n)),i=n?[]:e.map(e=>to(e,t,/* @__PURE__ */ new Set)),a=i.find(e=>e!==void 0),o=i.map(e=>e?.variable===a?.variable&&e?.argument===a?.argument?e?.labels:void 0);return(e,t,n,i,s,c)=>{let l=a&&no(e,t,a);for(let a=0;a<r.length&&!e.isStopped;a++)(l===void 0||o[a]?.has(l)!==!1)&&r[a](e,t,n,i,s,c)}},io=(e,t,n)=>{let r=e=>Oa(e,t,n);switch(e.kind){case`And`:return Ua(e.operands,t,n);case`Or`:return ro(e.operands,t,n);case`Exists`:{let i=r(e.body),a=e.bounds[0];if(e.bounds.length===1&&a.pattern.kind===`Name`){let e=a.pattern.name;return(t,n,r,o,s,c)=>{let l=Fo(X(a.set,J(t,n,r)),a.set);for(let a=0;a<l.length&&!t.isStopped;a++)i(t,Do(n,e,l[a]),r,o,s,c)}}let o=n||t.trace?void 0:Ha(e,t);if(o){let r=Ua(o.rest,t,n);return(t,n,i,a,s,c)=>{let l=J(t,n,i),u=e.bounds.map(e=>Fo(X(e.set,l),e.set));if(u.some(e=>e.length===0))return;let d=(e,n)=>{if(e<0)r(t,n,i,a,s,c);else for(let r of u[e]){if(t.isStopped)return;let a=Do(n,o.names[e],r);if(e===u.length-1){let e=J(t,a,i);if(!o.guards.every(t=>wa(t,e)))continue}d(e-1,a)}};d(u.length-1,n)}}return(t,n,r,a,o,s)=>{Io(e.bounds,J(t,n,r),e=>(i(t,e,r,a,o,s),t.isStopped))}}case`Forall`:{let i=r(e.body),a=!n&&pc(e,t)!==void 0&&!Ba(e.body,t,/* @__PURE__ */ new Set)?za(e,Ra):void 0;return(t,n,r,o,s,c)=>{let l=[];Io(e.bounds,J(t,n,r),e=>(l.push(e),!1));let u=[...l.slice(0,1),...l.slice(1).reverse()];if(a?.every(e=>Eo(n,e)?.kind===`Value`)){u.every(n=>wa(e.body,J(t,n,r)))&&c(r,o);return}let d=(n,r,a)=>{n===u.length?c(r,a):n>0&&t.isInit&&co(r)?u.slice(n).every(n=>Wa(e.body,J(t,n,r)))&&c(r,a):i(t,u[n],r,a,!0,(e,t)=>d(n+1,e,t))};d(0,r,o)}}case`If`:{let t=r(e.consequent),n=r(e.alternative);return(r,i,a,o,s,c)=>{let l=X(e.condition,J(r,i,a));(Ao(l,`an IF condition`)?t:n)(r,i,a,o,s,c)}}case`Case`:{let t=e.arms.map(e=>({condition:e.condition,body:r(e.body)})),n=e.other?r(e.other):void 0;return(r,i,a,o,s,c)=>{let l=J(r,i,a),u=t.find(e=>Ao(X(e.condition,l),`a CASE guard`))?.body??n;if(!u)throw new v(`In computing ${r.isInit?`initial`:`next`} states, TLC encountered a CASE with no conditions true.\n${go(e)}`);u(r,i,a,o,s,c)}}case`Let`:{let n=r(e.body),i=xs(e.definitions,t);return(t,r,a,o,s,c)=>n(t,ds(e.definitions,J(t,r,a),i),a,o,s,c)}case`Unchanged`:return n?()=>{throw new v(`UNCHANGED appears in an initial predicate at ${ho(e)}`)}:Qa(e.expression,t);case`AngleAction`:{let t=r(e.action),n=Ja(e.subscript);return(e,r,i,a,o,s)=>t(e,r,i,a,o,(t,i)=>{wa(n,J(e,r,t))||s(t,i)})}case`BoxAction`:return r({kind:`Or`,operands:[e.action,Ja(e.subscript)],location:e.location});case`Label`:return r(e.body);case`Identifier`:return eo(e,t,n);case`FunctionApplication`:return Za(e,t,n);case`Apply`:{let i=e.args;if(Ta(e.operator)){let r=ja(i[0],t,n);if(r!==void 0)return e.operator===`=`?Ua([e],t,n):Ka(e,()=>r);if(Na(i[0],n))return Ya(e,n)}if(e.operator===`=>`){let e=r(i[1]);return(t,n,r,a,o,s)=>{let c=X(i[0],J(t,n,r));(typeof c==`boolean`?c:Ao(c,`the left side of => at ${ho(i[0])}`))?e(t,n,r,a,o,s):s(r,a)}}return $a(e,t,n)}default:return Ga(e)}},ao=/* @__PURE__ */ new WeakMap,oo=e=>{let t=ao.get(e);if(t)return t;let n=e.variables.map(()=>void 0);return ao.set(e,n),n},so=(e,t)=>t.variables.filter((t,n)=>e[n]===void 0),co=e=>{for(let t=0;t<e.length;t++)if(e[t]===void 0)return!1;return!0},lo=(e,t)=>{let n=t.state;if(!n||!co(n))throw new v(`ENABLED needs a complete state at ${ho(e)}`);let r=t.environment,i={environment:r,isInit:!1,current:n,isStopped:!1};return Oa(e,r,!1)(i,t.scope,oo(r),void 0,!1,()=>{i.isStopped=!0}),i.isStopped},uo=(t,r,i,a)=>{let o={environment:r,isInit:!0,current:void 0,isStopped:!1};Oa(t,r,!0)(o,a,oo(r),void 0,!1,t=>{if(!o.isStopped){if(!co(t))throw n(new x(t),e.error);o.isStopped=i(t)}})},fo=(e,t,n)=>{let r=[];return uo(e,t,e=>(r.push(e),!1),n),r},po=(e,t,n,r,i)=>{let a={environment:n,isInit:!1,current:t,isStopped:!1},o={successors:0};return Oa(e,n,!1)(a,i,oo(n),void 0,!1,(e,t)=>{if(!a.isStopped){if(!co(e))throw new b(e,t,so(e,n).sort());o.successors++,a.isStopped=r({state:e,action:t})}}),o.successors},mo=(e,t,n,r)=>{let i=[];return po(e,t,n,e=>(i.push(e),!1),r),i},ho=e=>`line ${e.location.line}, column ${e.location.column}`,go=e=>{let t=e.location.range;return t?h(t):ho(e)},_o=(e,t)=>new v(`A non-boolean expression (${Or(t)}) was used as the condition of an IF.\n${go(e)}`),vo=(e,t,n)=>{let r=e.location.range;if(r?.start.line===e.location.line&&r.start.column===e.location.column||!r){let r=e.operands[t],i=r.kind===`Number`?String(r.value):go(r);return new v(`A non-boolean expression (${Or(n)}) was used as a formula in a conjunction.\n${i}`)}let i=e.operands[Math.max(t,1)].location.range?.end??r.end;return new v(`Attempted to evaluate an expression of form P /\\ Q when ${t===0?`P`:`Q`} was\n${Or(n)}.\n${go({...e,location:{...e.location,range:{...r,end:i}}})}`)},yo=e=>t=>Tn(t)?`Attempted to select nonexistent field "${e.field}" from the record\n${U(t)}\n${go(e)}`:wn(t,e.field),bo=e=>t=>`A non-function (${Or(t)}) was applied as a function.\n${go(e)}`,xo=e=>t=>`Attempted to select field "${e.field}" from a non-record value ${U(t)}\n${go(e)}`,So=e=>t=>{if(!P(t))throw new v(`Attempted to apply the operator DOMAIN to a non-function\n(${Or(t)})\n${go(e)}`);return An(t)},Co=(e,t)=>(n,r)=>{if(!M(n)||L(n))throw new v(`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${go(e)}`);return t.evaluate([n,r])},wo=t=>n(new v(`TLC can't handle real numbers: ${t.text} at ${ho(t)}`),e.configParseError),To=t=>n(new v(`TLC can't handle a number this big: ${t.text??t.value} at ${ho(t)}`),e.error),Eo=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n.binding},Do=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n},parent:e}),Oo=(e,t,n)=>{if(t.kind===`Name`)return Do(e,t.name,n);let r=pn(n);if(!r||r.length!==t.names.length)throw new v(`Cannot bind <<${t.names.join(`, `)}>> to ${U(n)}, which is not a tuple of that length`);return t.names.reduce((e,t,n)=>Do(e,t,r[n]),e)},ko=(e,t)=>({environment:e.environment,scope:t,state:e.state,next:e.next}),Ao=(e,t)=>{if(typeof e!=`boolean`)throw new v(`Expected ${t} to be a boolean but found ${U(e)}`);return e},jo=(e,t)=>t.definitions.get(t.substitutions.get(e)??e),Mo=(e,t)=>{if(e.kind===`Prime`||e.kind===`Unchanged`||e.kind===`Enabled`)return!0;let n=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(n!==void 0){if(t.variableIndex.has(n)||t.builtins.get(n)?.isStateLevel)return!0;let e=jo(n,t);if(e&&!t.constants.has(n)&&!No(e,t))return!0}return ar(e).some(e=>Mo(e,t))},No=(e,t)=>{let n=t.constantLevels.get(e);if(n!==void 0)return n;t.constantLevels.set(e,!0);let r=!Mo(e.body,t)&&(e.kind===`Operator`||!e.bounds.some(e=>Mo(e.set,t)));return t.constantLevels.set(e,r),r},Po=(e,t)=>{let n=`universally (\\A) or existentially (\\E) quantify over ${t}, because this would require checking an\ninfinite number of cases.`;if(typeof e==`object`&&e.kind===`SequenceSet`)return`In TLA+, Seq(S) represents the set of all finite sequences whose elements come from the set S. Even when S\nis a finite set, the number of possible sequences in Seq(S) is unbounded because sequences can have any\nfinite length (e.g., length 0, 1, 2, and so on). As a result, TLC cannot evaluate expressions that\n${n} Note that for a finite set of sequences s, TLC handles s \\subseteq Seq(S).\nSee https://explain.tlapl.us/seq-unenumerable for additional details.`;if(typeof e==`object`&&e.kind===`InfiniteSet`&&e.name!==`STRING`&&e.name!==`Any`)return`The set ${e.name} contains infinitely many elements. As a result, TLC cannot evaluate expressions that\n${n} Note that TLC handles set membership like T \\subseteq ${e.name} for any finite set T.`},Fo=(e,t)=>{if(!M(e)||L(e)){let n=U(e),r=Po(e,n);throw new v(r===void 0?`TLC encountered a non-enumerable quantifier bound\n${n}.\n${go(t)}`:`TLC encountered the non-enumerable quantifier bound\n${n}\n${go(t)}\n${r}`)}return typeof e==`object`&&e.kind===`Interval`?Vt(e):B(e).elements},Io=(e,t,n)=>{let r=e.map(e=>Fo(X(e.set,t),e.set)),i=(t,a)=>t<0?n(a):r[t].some(n=>i(t-1,Oo(a,e[t].pattern,n)));return i(e.length-1,t.scope)},Lo=(e,t)=>{let n=e.map(e=>X(e.set,t));return n.length===1?n[0]:{kind:`ProductSet`,factors:n}},Ro=(e,t,n)=>{if(e.length===1)return Oo(t,e[0].pattern,n);let r=pn(n)??[];return e.reduce((e,t,n)=>Oo(e,t.pattern,r[n]),t)},zo=/* @__PURE__ */ new WeakMap,Bo=(e,t)=>{let n=zo.get(t);if(n)return n;let r=t.location.range;if(!r)return;let i={parameters:e.flatMap((t,n)=>n>0&&e[n-1].set===t.set?[]:[{index:n,name:t.pattern.kind===`Name`?t.pattern.name:`<<${t.pattern.names.join(`, `)}>>`}]),body:h(r)};return zo.set(t,i),i},Vo=(e,t,n)=>{let r=Bo(e,t);if(!r)return;let i=e.length>1&&typeof n==`object`&&n.kind===`ProductSet`?n.factors:[n];return{parameters:r.parameters.map(e=>({name:e.name,domain:i[e.index]})),body:r.body}},Ho=(e,t,n)=>{let r=/* @__PURE__ */ new Map,i={kind:`LazyFunction`,domain:e,source:n,apply:e=>{let n=zn(e),a=r.get(n);if(a!==void 0){for(let t=0;t<a.length;t+=2)if(nt(a[t],e))return a[t+1]}let o=t(e,i),s=r.get(n);return s===void 0?r.set(n,[e,o]):s.push(e,o),o}};return i},Uo=(e,t)=>{let n=Lo(e.bounds,t),r=Ho(n,(n,r)=>X(e.body,ko(t,Ro(e.bounds,Do(void 0,e.name,r),n))),Vo(e.bounds,e.body,n));return e.bounds.length===1?yn(r):r},Wo=(e,t)=>e.kind===`Function`?Uo(e,t):X(e.body,t),Go=(e,t)=>{let n=No(e,t.environment),r=n?t.environment.definitionValues.get(e):void 0;if(r!==void 0)return r;if(e.kind===`Operator`&&e.params.length>0)throw new v(`Operator ${e.name} requires ${e.params.length} arguments`);let i=ko(t,void 0);if(!n)return Wo(e,i);let a=t.environment.runtime.evaluateAtStartup(()=>Wo(e,i));return t.environment.definitionValues.set(e,a),a},Ko=(e,t)=>{let n=e.state===t.state&&e.next===t.next;if(n&&e.cache!==void 0)return e.cache;let r=X(e.expression,ko(t,e.scope));return n&&(e.cache=r),r},qo=/* @__PURE__ */ new WeakMap,Jo=e=>{let t=qo.get(e);if(t)return t;let n={kind:`Closure`,name:e.name,params:e.params,body:e.body,scope:void 0};return qo.set(e,n),n},Yo=(e,t)=>{let n=t.substitutions.get(e);if(n!==void 0)return Yo(n,t);let r=t.definitions.get(e);return r?.kind===`Operator`?Jo(r):t.builtins.get(e)},Xo=/* @__PURE__ */ new WeakMap,Zo=(e,t)=>{if(W(e))return Qo(e.operator,t);let n=Xo.get(e),r=n===void 0?Yo(e.operator,t.environment)??null:n;return n===void 0&&Xo.set(e,r),r??Qo(e.operator,t)},Qo=(e,t)=>{let n=Eo(t.scope,e);if(n?.kind===`Operator`)return n.operator;if(!n)return Yo(e,t.environment)},$o=e=>e.kind===`Closure`?e.params.length:e.arity,es=(e,t)=>{if(e.kind===`Lambda`)return{kind:`Closure`,name:`LAMBDA`,params:e.params.map(e=>({name:e,arity:0})),body:e.body,scope:t.scope};let n=e.kind===`OperatorReference`?e.operator:e.kind===`Identifier`?e.name:void 0,r=n===void 0?void 0:Qo(n,t);if(!r)throw new v(`Expected an operator argument at ${ho(e)}`);return r},ts=(e,t,n)=>{if(e.kind===`Builtin`)return e.evaluate(t,n);if(e.kind===`Operator`)return e.call(t);let r=e.params.reduce((e,n,r)=>Do(e,n.name,t[r]),e.scope);return X(e.body,ko(n,r))},ns=(e,t)=>e.kind===`Operator`?e:{kind:`Operator`,name:e.name,arity:$o(e),call:n=>ts(e,n,t),literalBody:e.kind===`Closure`&&(e.body.kind===`Number`||e.body.kind===`String`)?e.body.value:void 0},rs=(e,t)=>{if(e.kind===`Lambda`||e.kind===`OperatorReference`)return!0;if(e.kind!==`Identifier`)return!1;let n=Qo(e.name,t);return n!==void 0&&$o(n)>0},is=(e,t)=>({kind:`Thunk`,expression:e,scope:t.scope,state:t.state,next:t.next,cache:void 0}),as=(e,t)=>{let n=t.variableIndex.get(e);if(n!==void 0)return{kind:`Variable`,index:n};let r=t.constants.get(e);if(r!==void 0)return{kind:`Value`,value:r};let i=t.substitutions.get(e);if(i!==void 0)return as(i,t);let a=t.definitions.get(e);if(a)return{kind:`Definition`,definition:a};let o=t.builtins.get(e);if(o&&o.arity===0&&!o.isStateLevel)return{kind:`Value`,value:o.evaluate([])}},os=(e,t)=>{if(e.kind===`String`||e.kind===`Number`&&ps(e.value)){let t={kind:`Value`,value:e.value};return()=>t}if(e.kind===`Identifier`){let n=W(e)?void 0:as(e.name,t);if(n?.kind===`Value`){let e={kind:`Value`,value:n.value};return()=>e}if(n===void 0)return t=>{let n=Eo(t.scope,e.name);return n?.kind===`Value`||n?.kind===`Thunk`?n:is(e,t)}}return t=>is(e,t)},ss=/* @__PURE__ */ new WeakMap,cs=(e,t)=>{let n=ss.get(e);if(n)return n;let r=os(e,t);return ss.set(e,r),r},ls=(e,t,n)=>{if(t.length!==e.params.length)throw new v(`Operator ${e.name} expects ${e.params.length} arguments but received ${t.length}`);let r=e.scope;for(let i=0;i<t.length;i++){let a=e.params[i],o=a.arity>0?{kind:`Operator`,operator:es(t[i],n)}:cs(t[i],n.environment)(n);r={name:a.name,binding:o,parent:r}}return r},us=(e,t,n)=>e.kind===`Closure`?X(e.body,ko(n,ls(e,t,n))):e.kind===`Operator`?e.call(t.map(e=>X(e,n))):e.isLazy?e.evaluate(Hs(t,n),n):e.evaluate(t.map(e=>rs(e,n)?ns(es(e,n),n):X(e,n)),n),ds=(e,t,n)=>e.reduce((e,r)=>{let i={name:r.name,binding:{kind:`Value`,value:!1},parent:e};return r.kind===`Function`?(i.binding={kind:`Thunk`,expression:{kind:`FunctionConstruction`,bounds:r.bounds,body:r.body,location:r.location,isRecursive:!0},scope:i,state:t.state,next:t.next,cache:void 0},i):r.params.length>0||n?.has(r)?(i.binding={kind:`Operator`,operator:{kind:`Closure`,name:r.name,params:r.params,body:r.body,scope:i}},i):(i.binding={kind:`Thunk`,expression:r.body,scope:i,state:t.state,next:t.next,cache:void 0},i)},t.scope),fs=(e,t,n)=>{let r=Eo(n.scope,e);if(r?.kind===`Value`)return r.value;if(r?.kind===`Thunk`)return Ko(r,n);if(r?.kind===`Operator`){if($o(r.operator)===0)return ts(r.operator,[],n);throw new v(`Operator ${e} is used without arguments`)}let i=as(e,n.environment);if(i?.kind===`Variable`){let r=n.state?.[i.index];if(r===void 0)throw sc(e,t);return r}if(i?.kind===`Value`)return i.value;if(i?.kind===`Definition`)return Go(i.definition,n);let a=n.environment.builtins.get(e);if(a?.arity===0)return a.evaluate([],n);throw new v(`Unknown identifier ${e} at ${ho(t)}`)},ps=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,ms=/* @__PURE__ */ new Set([`Print`,`PrintT`,`Assert`,`JavaTime`,`RandomElement`,`TLCGet`,`TLCSet`]),hs=(e,t)=>ms.has(e)||t.builtins.get(e)?.isStateLevel===!0,gs={builtins:ms,definitions:/* @__PURE__ */ new WeakMap},_s={builtins:new Set([...ms].filter(e=>e!==`Assert`)),definitions:/* @__PURE__ */ new WeakMap},vs=(e,t)=>e.kind===`Operator`&&e.params.length===0&&No(e,t),ys=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`||e.kind===`OperatorReference`?e.operator:void 0;if(r!==void 0&&!W(e)){let e=jo(r,t),i=n.builtins.has(r)||t.builtins.get(r)?.isStateLevel===!0;if(!e&&i||e&&!vs(e,t)&&bs(e,t,n))return!0}return ar(e).some(e=>ys(e,t,n))},bs=(e,t,n=gs)=>{let r=n.definitions.get(e);if(r!==void 0)return r;n.definitions.set(e,!1);let i=ys(e.body,t,n)||e.kind===`Function`&&e.bounds.some(e=>ys(e.set,t,n));return n.definitions.set(e,i),i},xs=(e,t)=>new Set(e.filter(e=>bs(e,t))),Ss=e=>[...e.definitions.values()].some(t=>bs(t,e)),Cs=e=>[...e.definitions.values()].some(t=>bs(t,e,_s)),ws=/* @__PURE__ */ new WeakMap,Ts=(e,t)=>{let n=ws.get(e);if(n!==void 0)return n;let r=ks(e,t,Ds);return ws.set(e,r),r},Es=/* @__PURE__ */ new Set([`Number`,`String`,`Identifier`,`Apply`,`And`,`Or`,`If`,`Case`,`SetEnumeration`,`Tuple`,`FunctionSet`,`Record`,`RecordSet`,`FunctionApplication`,`FieldAccess`,`Product`,`SetFilter`,`SetMap`,`Forall`,`Exists`,`Choose`,`FunctionConstruction`,`Let`]),Ds=/* @__PURE__ */ new Set,Os=(e,t,n)=>n.size===0?Ts(e,t):ks(e,t,n),ks=(e,t,n)=>{if(!Es.has(e.kind))return!1;if(e.kind===`Identifier`&&W(e))return n.has(e.name);if(W(e))return!1;if(e.kind===`Identifier`){let n=as(e.name,t);return n?.kind===`Value`||n?.kind===`Definition`&&vs(n.definition,t)}if(e.kind===`Apply`){if(hs(e.operator,t)||e.operator===`~>`)return!1;let r=Yo(e.operator,t);if(r?.kind!==`Builtin`&&r?.kind!==`Closure`)return!1;if(r.kind===`Closure`){let n=jo(e.operator,t);if(!n||!No(n,t)||bs(n,t))return!1}return!(r.kind===`Closure`?r.params:[]).some(e=>e.arity>0)&&e.args.every(e=>e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&Os(e,t,n))}let r={value:!0};return Ji(e,(e,i)=>(r.value&&=Os(e,t,i.length===0?n:/* @__PURE__ */ new Set([...n,...i])),e)),r.value},As=e=>e.kind!==`Number`&&e.kind!==`String`&&e.kind!==`Identifier`,js=e=>{let t={value:void 0};return n=>{if(t.value!==void 0)return t.value;let r=e(n);return t.value=r,r}},Ms=(e,t)=>{if(e.kind===`Identifier`&&W(e))return!t.has(e.name);if(W(e))return!0;let n={value:!1};return Ji(e,(e,r)=>(n.value||=Ms(e,r.length===0?t:/* @__PURE__ */ new Set([...t,...r])),e)),n.value},Ns=(e,t)=>Bi.has(e)&&As(e)&&pc(e,t)!==void 0&&!Ms(e,Ds),Ps=/* @__PURE__ */ new WeakMap,Y=(e,t)=>{let n=t.evaluators.get(e);if(n)return n;let r=uc(e,t),i=As(e)&&Ts(e,t)?js(r):Ns(e,t)?zs(r):r,a=t.trace,o=a?n=>{let r=a.length;a.push(e);let o=i(n);a.length=r;let s=typeof o==`object`&&o.kind===`FilteredSet`?Ps.get(o):void 0;return s?s(t):o}:i;return t.evaluators.set(e,o),o},Fs=/* @__PURE__ */ new WeakMap,Is=(e,t)=>{if(t.trace)return Y(e,t);let n=Fs.get(e);if(n)return n;let r=(As(e)&&Ts(e,t)?void 0:Jr(e,t))??Y(e,t);return Fs.set(e,r),r},X=(e,t)=>Is(e,t.environment)(t),Ls=(e,t)=>{let n=e.name,r=W(e)?void 0:as(n,t);if(r?.kind===`Variable`){let t=r.index;return r=>{let i=r.state?.[t];if(i===void 0)throw sc(n,e);return i}}if(r?.kind===`Value`){let e=r.value;return()=>e}if(r?.kind===`Definition`&&r.definition.kind===`Operator`){let e=r.definition;if(e.params.length===0&&No(e,t))return t=>Go(e,t);if(e.params.length===0){let n={body:void 0},r=r=>(n.body??=Is(e.body,t),n.body(ko(r,void 0)));return Rs(e,t)?zs(r):r}return t=>Go(e,t)}if(r?.kind===`Definition`){let e=r.definition,n=t=>Go(e,t);return No(e,t)||!Rs(e,t)?n:zs(n)}return t=>fs(n,e,t)},Rs=(e,t)=>pc(e.body,t)!==void 0&&(e.kind===`Operator`||e.bounds.every(e=>pc(e.set,t)!==void 0)),zs=e=>{let t={recent:void 0,recentValue:void 0,previous:void 0,previousValue:void 0};return n=>{let r=n.state;if(r!==void 0&&t.recent===r&&t.recentValue!==void 0)return t.recentValue;if(r!==void 0&&t.previous===r&&t.previousValue!==void 0)return t.previousValue;let i=e(n);return t.previous=t.recent,t.previousValue=t.recentValue,t.recent=r,t.recentValue=i,i}},Bs=(e,t)=>{let n=Yo(e,t);return n!==void 0&&$o(n)>0},Vs=(e,t)=>e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&!(e.kind===`Identifier`&&!W(e)&&Bs(e.name,t)),Hs=(e,t)=>e.map(e=>({kind:`Operator`,name:`argument`,arity:0,call:()=>X(e,t),expression:e})),Us=(e,t,n)=>{if(e.isLazy)return n=>e.evaluate(Hs(t,n),n);let r=e.evaluateUnary;if(r&&t.length===1&&Vs(t[0],n)){let e=Y(t[0],n);return t=>r(e(t))}let i=e.evaluateBinary,a=t.length===2&&Vs(t[0],n)&&Vs(t[1],n);if(i&&a){let e=Y(t[0],n),r=Y(t[1],n);return t=>i(e(t),r(t))}return n=>e.evaluate(t.map(e=>rs(e,n)?ns(es(e,n),n):X(e,n)),n)},Ws=(e,t,n)=>{if(t.length!==e.params.length)return()=>{throw new v(`Operator ${e.name} expects ${e.params.length} arguments but received ${t.length}`)};let r=e.params,i=t.map((e,t)=>r[t].arity>0?void 0:cs(e,n));return n=>{let a=e.scope;for(let e=0;e<t.length;e++){let o=i[e],s=o?o(n):{kind:`Operator`,operator:es(t[e],n)};a={name:r[e].name,binding:s,parent:a}}return a}},Gs=/* @__PURE__ */ new WeakMap,Ks=e=>{let t=Gs.get(e);if(t)return t;let n={calls:/* @__PURE__ */ new Map,size:0};return Gs.set(e,n),n},qs=(e,t)=>{let n=[];for(let r=e;n.length<t;r=r?.parent){if(r?.binding.kind!==`Value`)return;n.push(r.binding.value)}return n},Js=(e,t)=>e.every((e,n)=>nt(e,t[n])),Ys=(e,t)=>{let n=jo(e.operator,t);return n?.kind===`Operator`&&n.params.length>0&&n.params.every(e=>e.arity===0)&&No(n,t)&&!bs(n,t)},Xs=(e,t,n,r)=>{let i=Ws(e,t,n),a={body:void 0},o=(t,r)=>(a.body??=Is(e.body,n),a.body({environment:n,scope:t,state:r.state,next:r.next}));if(!r)return e=>o(i(e),e);let s=Ks(e);return e=>{let n=i(e),r=qs(n,t.length);if(!r)return o(n,e);let a=r.length;for(let e of r)a=Pn(a,zn(e));let c=s.calls.get(a),l=c?.find(e=>Js(e.args,r));if(l)return l.value;let u=o(n,e);return s.size<65536&&(s.size++,c?c.push({args:r,value:u}):s.calls.set(a,[{args:r,value:u}])),u}},Zs=(e,t)=>{let n=e.args;if(e.operator===`=>`){let e=Y(n[0],t),r=Y(n[1],t);return t=>!Ao(e(t),`the left side of =>`)||Ao(r(t),`the right side of =>`)}if(e.operator===`~>`)return()=>{throw new v(`TLC cannot evaluate a temporal formula such as ~> in a state`)};let r=W(e)?void 0:Yo(e.operator,t);if(r?.kind===`Closure`)return Xs(r,n,t,Ys(e,t));if(r?.kind===`Builtin`&&r.name===`DOMAIN`){let r=Y(n[0],t),i=So(e);return e=>i(r(e))}if(r?.kind===`Builtin`&&r.name===`TLCEval`&&n.length===1){let i=Y(n[0],t);return Vi.has(e)||Mo(n[0],t)?i:e=>e.scope===void 0?r.evaluate([i(e)]):i(e)}if(r?.kind===`Builtin`&&r.name===`\\subseteq`&&n.length===2){let i=Y(n[0],t),a=Y(n[1],t),o=Co(e,r);return e=>o(i(e),a(e))}return r?.kind===`Builtin`?Us(r,n,t):r=>{let i=Qo(e.operator,r);if(i)return us(i,n,r);throw t.definitions.get(e.operator)?.kind===`Function`?new v(`${e.operator} is a function; apply it with brackets`):e.operator===`\\cdot`?new v(`The current version of TLC does not support action composition. An incomplete implementation can be enabled via the tlc2.tool.impl.Tool.cdot=true java property.`):new v(`Unknown operator ${e.operator} at ${ho(e)}`)}},Qs=(e,t)=>{let n=e.kind===`Forall`,r=n?`the body of \\A`:`the body of \\E`,i=Y(e.body,t),a=e.bounds[0];if(e.bounds.length===1&&a.pattern.kind===`Name`){let e=a.pattern.name,o=Y(a.set,t);return t=>{let s=Fo(o(t),a.set);for(let a=0;a<s.length;a++){let o=Ao(i(ko(t,Do(t.scope,e,s[a]))),r);if(o!==n)return o}return n}}let o=e.bounds;if(o.every(e=>e.pattern.kind===`Name`)){let e=o.map(e=>e.pattern.kind===`Name`?e.pattern.name:``),a=o.map(e=>Y(e.set,t));return t=>{let s=a.map((e,n)=>Fo(e(t),o[n].set)),c=(a,o)=>{if(a<0)return Ao(i(ko(t,o)),r)!==n;let l=s[a];for(let t=0;t<l.length;t++)if(c(a-1,Do(o,e[a],l[t])))return!0;return!1};return c(o.length-1,t.scope)?!n:n}}return e=>Io(o,e,t=>Ao(i(ko(e,t)),r)!==n)?!n:n},$s=(e,t)=>{if(e.kind===`Tuple`)return R(e.names.map(e=>{let n=Eo(t,e);return n?.kind===`Value`&&n.value}));let n=Eo(t,e.name);return n?.kind===`Value`?n.value:void 0},ec=/* @__PURE__ */ new WeakSet,tc=e=>{(e.kind===`FunctionConstruction`||e.kind===`Except`)&&ec.add(e)},nc=(e,t)=>{let n=ec.has(e),r=Y(e.body,t),i=e.bounds,a=i[0],o=i.length===1&&a.pattern.kind===`Name`,s=Y(a.set,t);return t=>{let c=o?s(t):Lo(i,t),l=typeof c==`object`&&c.kind===`ProductSet`&&i.length>1?c.factors:[c];if(e.isRecursive||n||!l.every(N)){let n=Ho(c,e=>r(ko(t,Ro(i,t.scope,e))),Vo(i,e.body,c));return i.length===1?yn(n):n}if(o&&a.pattern.kind===`Name`){let e=a.pattern.name,n=Ut(c);return yn($e(n,n.map(n=>r(ko(t,Do(t.scope,e,n))))))}let u=[];return Io(i,t,e=>{let n=i.length===1?$s(a.pattern,e)??!1:R(i.map(t=>$s(t.pattern,e)??!1));return u.push([n,r(ko(t,e))]),!1}),Ft(u)}},rc=(e,t)=>{let n=ec.has(e);n&&tc(e.function);let r=Y(e.function,t),i=e.updates.map(e=>({path:e.path.map(e=>e.kind===`Field`?{kind:`Field`,name:e.name,args:[]}:{kind:`Index`,name:``,args:e.args.map(e=>Y(e,t))}),value:Y(e.value,t)})),a=(e,t)=>e.kind===`Field`?e.name:e.args.length===1?e.args[0](t):R(e.args.map(e=>e(t))),o=(e,t,r,i,s)=>r===t.length?s(ko(i,Do(i.scope,`@`,e))):jn(e,a(t[r],i),e=>o(e,t,r+1,i,s),n&&r===0);return e=>{let t=r(e);for(let n of i)t=o(t,n.path,0,e,n.value);return t}},ic=(e,t)=>{if(e.kind===`SetFilter`){let n=Y(e.predicate,t),r=Y(e.bound.set,t),i=e.bound.pattern;return t=>{let a=r(t),o=e=>n=>Ao(e(ko(t,Oo(t.scope,i,n))),`a set filter predicate`),s=o(n);if(!N(a)){if(M(a)){let t={kind:`FilteredSet`,base:a,test:s};return Ps.set(t,n=>({...t,test:o(Y(e.predicate,n))})),t}throw new v(`TLC encountered a non-enumerable quantifier bound ${U(a)} at ${ho(e.bound.set)}`)}return Qe(B(a).elements.filter(s))}}if(e.kind===`SetMap`){let n=Y(e.expression,t);return t=>{let r=[];return Io(e.bounds,t,e=>(r.push(n(ko(t,e))),!1)),At(r)}}let n=e.set;if(!n)return()=>{throw new v(`TLC cannot evaluate an unbounded CHOOSE at ${ho(e)}`)};let r=Y(e.body,t),i={pattern:e.pattern,set:n};return t=>{let n={value:void 0};if(Io([i],t,i=>Ao(r(ko(t,i)),`the body of CHOOSE`)?(n.value=$s(e.pattern,i),!0):!1),n.value===void 0)throw new v(`Attempted to compute the value of an expression of form\nCHOOSE x \\in S: P, but no element of S satisfied P.\n${go(e)}`);return n.value}},ac=e=>[...e].sort((e,t)=>Ye(e.name,t.name)),oc=e=>e.some((t,n)=>n>0&&e[n-1].name===t.name),sc=(t,n)=>a(new v(`In evaluation, the identifier ${t} is either undefined or not an operator.\n${go(n)}`),e.configParseError),cc=e=>new v(`A primed expression appears outside an action at ${ho(e)}`),lc=(e,t)=>{let n=ac(e),r=oc(n),i=n.map(e=>Y(e.value,t));if(r)return e=>Ft(n.map((t,n)=>[t.name,i[n](e)]));let a=n.map(e=>e.name),o=e.map(e=>e.name);return o.some((e,t)=>e!==a[t])?e=>Me(a,i.map(t=>t(e)),o):e=>$e(a,i.map(t=>t(e)))},uc=(e,t)=>{let n=e=>Y(e,t);switch(e.kind){case`Number`:{let t=e.value;return ps(t)?()=>t:()=>{throw To(e)}}case`Decimal`:return()=>{throw wo(e)};case`String`:{let t=e.value;return()=>t}case`Identifier`:return Ls(e,t);case`Apply`:return Zs(e,t);case`OperatorReference`:case`Lambda`:return()=>{throw new v(`An operator cannot be used as a value at ${ho(e)}`)};case`And`:{let t=e.operands.map(n);return n=>{for(let r=0;r<t.length;r++){let i=t[r](n);if(typeof i!=`boolean`)throw vo(e,r,i);if(!i)return!1}return!0}}case`Or`:{let t=e.operands.map(n);return e=>{for(let n=0;n<t.length;n++)if(Ao(t[n](e),`a disjunct`))return!0;return!1}}case`Prime`:{let t=n(e.expression);return n=>{if(!n.next)throw cc(e);return t({environment:n.environment,scope:n.scope,state:n.next,next:void 0})}}case`Unchanged`:{let t=n({kind:`Prime`,expression:e.expression,location:e.location}),r=n(e.expression);return e=>et(t(e),r(e))}case`If`:{let t=n(e.condition),r=n(e.consequent),i=n(e.alternative);return n=>{let a=t(n);if(typeof a!=`boolean`)throw _o(e,a);return a?r(n):i(n)}}case`Case`:{let t=e.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),r=e.other?n(e.other):void 0;return n=>{for(let e of t)if(Ao(e.condition(n),`a CASE guard`))return e.body(n);if(r)return r(n);throw new v(`Attempted to evaluate a CASE with no conditions true.\n${go(e)}`)}}case`Let`:{let t=n(e.body);return n=>t(ko(n,ds(e.definitions,n)))}case`Forall`:case`Exists`:return Qs(e,t);case`UnboundedQuantifier`:return()=>{throw new v(`TLC cannot evaluate an unbounded quantifier at ${ho(e)}`)};case`Choose`:case`SetFilter`:case`SetMap`:return ic(e,t);case`SetEnumeration`:{let t=e.elements.map(n);return e=>At(t.map(t=>t(e)))}case`Tuple`:{let t=e.elements.map(n);return e=>R(t.map(t=>t(e)))}case`FunctionConstruction`:return nc(e,t);case`FunctionSet`:{let t=n(e.domain),r=n(e.range);return e=>({kind:`FunctionSet`,domain:t(e),range:r(e)})}case`Record`:return lc(e.fields,t);case`RecordSet`:{let t=ac(e.fields),r=t.map(e=>e.name),i=t.map(e=>n(e.value));return e=>({kind:`RecordSet`,names:r,sets:i.map(t=>t(e))})}case`Except`:return rc(e,t);case`ExceptAt`:return t=>{let n=Eo(t.scope,`@`);if(n?.kind!==`Value`)throw new v(`@ appears outside an EXCEPT at ${ho(e)}`);return n.value};case`FunctionApplication`:{tc(e.function);let t=n(e.function),r=e.args.map(n),i=bo(e);if(r.length===1){let e=r[0];return n=>On(t(n),e(n),void 0,i)}return e=>On(t(e),R(r.map(t=>t(e))),void 0,i)}case`FieldAccess`:{let t=n(e.record),r=e.field,i=yo(e),a=xo(e);return e=>On(t(e),r,i,a)}case`Product`:{let t=e.factors.map(n);return e=>({kind:`ProductSet`,factors:t.map(t=>t(e))})}case`BoxAction`:case`AngleAction`:{let t=n(e.action),r=n({kind:`Unchanged`,expression:e.subscript,location:e.location}),i=e.kind===`BoxAction`;return e=>i?Ao(t(e),`an action`)||r(e):Ao(t(e),`an action`)&&!r(e)}case`Enabled`:{let t=e.expression;return e=>lo(t,e)}case`Label`:return n(e.body);case`Subexpression`:return()=>{throw new v(`The subexpression reference at ${ho(e)} does not name a subexpression`)};case`Always`:case`Eventually`:case`WeakFairness`:case`StrongFairness`:return()=>{throw new v(`TLC cannot evaluate a temporal formula in a state at ${ho(e)}`)}}},dc=/* @__PURE__ */ new Set([`Prime`,`Unchanged`,`Enabled`,`Always`,`Eventually`,`BoxAction`,`AngleAction`,`WeakFairness`,`StrongFairness`]),fc=e=>{if(e.kind===`Identifier`)return e.name;if(e.kind===`Apply`||e.kind===`OperatorReference`)return e.operator},pc=(e,t)=>{let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=e=>{if(dc.has(e.kind))return!1;let a=fc(e),o=(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`;if(a!==void 0&&!o&&!t.constants.has(a)){let e=t.substitutions.get(a)??a,o=t.definitions.get(e);if(!o&&hs(e,t))return!1;let s=t.variableIndex.get(a);if(s!==void 0&&n.add(s),o&&!r.has(o)&&(r.add(o),!i(o.body)||o.kind!==`Operator`&&!o.bounds.every(e=>i(e.set))))return!1}return ar(e).every(i)};return i(e)?[...n]:void 0},mc=/* @__PURE__ */ new Map([[`Reals`,`-------------------------------- MODULE Reals -------------------------------
|
|
30
|
+
`,e.slice(0,t))}n.push({kind:`String`,text:t[1],line:r.line}),r.index+=t[0].length;continue}let l=fe.find(t=>e.startsWith(t));if(l){n.push({kind:`Symbol`,text:l,line:r.line}),r.index+=l.length;continue}let u=ae(t,r.index);if(!u)throw _e(r.line,r.index-r.lineStart+1,e[0]);n.push({kind:`Word`,text:u.text,line:r.line}),r.index+=u.length}return n.push({kind:`End`,text:``,line:r.line-1}),n},be=e=>{let t=ye(e),n={index:0},r={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},i={isSet:!1},a=()=>t[Math.min(n.index++,t.length-1)],o=e=>e.kind===`Word`&&de.has(e.text),s=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t=a();if(t.text!==`}`)for(;e.push(s(t)),t=a(),t.text===`,`;)t=a();if(t.text!==`}`)throw ve(t.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw ve(e.line,`It was expecting a value, but did not find it.`)},c=e=>{let t=a();if(t.kind===`End`)throw ve(t.line,`Expected an identifier after ${e}[.`);let n=a();if(n.text!==`]`)throw ve(n.line,`It was expecting ], but did not find it.`);return t.text},l=e=>{for(;;){let t=a();if(t.kind===`End`||o(t))return t;let n={text:t.text},i=a();for(;i.text===`!`;)n.text=`${n.text}!${a().text}`,i=a();if(i.text===`<-`){if(i=a(),i.text===`[`){let e=c(`<-`),t=a();if(t.kind===`End`)throw ve(t.line,`Expected an identifier after <-[mod].`);r.substitutions.push({name:n.text,target:t.text,module:e});continue}if(i.kind===`End`)throw ve(i.line,`Expected an identifier after <-.`);r.substitutions.push({name:n.text,target:i.text});continue}let l=[];if(i.text===`(`){for(;l.push(s(a())),i=a(),i.text===`,`;);if(i.text!==`)`)throw ve(e,``);i=a()}if(i.text!==`=`)throw ve(i.line,`It was expecting = or <-, but did not find it.`);i=a();let u=i.text===`[`?c(`=`):void 0,d=s(u===void 0?i:a());r.constants.push({name:n.text,value:d,...l.length>0&&{args:l},...u&&{module:u}})}},u=a();for(;u.kind!==`End`;){let e=u.text,t=u.line;if(me(e)){let n=a();if(n.kind===`End`)throw ve(t,`The keyword ${e} was not followed by an identifier.`);let i=N[e];if(r[i]!==void 0)throw ve(t,`The keyword ${e} appeared twice.`);r[i]=n.text,u=a()}else if(he(e)){let t=r[pe[e]];for(u=a();u.kind!==`End`&&!o(u);)t.push(u.text),u=a()}else if(e===`CONSTANT`||e===`CONSTANTS`)u=l(t);else if(e===`CHECK_DEADLOCK`){let e=a();if(e.kind===`End`)throw ve(t,`The keyword CHECK_DEADLOCK was not followed by an identifier.`);if(e.text!==`TRUE`&&e.text!==`FALSE`)throw ve(e.line,`It was expecting TRUE or FALSE, but did not find it.`);if(i.isSet)throw ve(t,`The keyword CHECK_DEADLOCK appeared twice.`);i.isSet=!0,r.checkDeadlock=e.text===`TRUE`,u=a()}else throw ve(t,`It was expecting a keyword, but did not find it.`)}if(r.specification!==void 0&&(r.init!==void 0||r.next!==void 0))throw new v(`The configuration file cannot specify both INIT/NEXT and SPECIFICATION fields.`);return r},xe={Set:{open:`{ `,close:` }`,pad:` `,separator:`,`,divider:``,dividerPad:``},Sequence:{open:`<< `,close:` >>`,pad:` `,separator:`,`,divider:``,dividerPad:``},Subset:{open:`SUBSET `,close:` `,pad:` `,separator:`,`,divider:``,dividerPad:``},Function:{open:`( `,close:` )`,pad:` `,separator:` @@`,divider:` :>`,dividerPad:` `},Record:{open:`[ `,close:` ]`,pad:` `,separator:`,`,divider:` |->`,dividerPad:` `}},Se=e=>{if(e===void 0)return!1;let t=e.charCodeAt(0);return t>=9&&t<=13||t>=28&&t<=32||t===5760||t>=8192&&t<=8202&&t!==8199||t===8232||t===8233||t===8287||t===12288},Ce=e=>e!==void 0&&/^\p{Nd}$/u.test(e),we=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),Te=e=>{let t=t=>{let n=se(e,t,Se);return e[n]===void 0?void 0:n},n=(n,r,i,a,o,s)=>{let c={kind:n,first:r,last:r,children:[]},l={index:t(i)};for(;l.index!==void 0&&e[l.index]!==a;){let n=o(l.index);if(!n)return;c.children.push(n);let r=t(n.last+1);if(r===void 0)return;let i=e.startsWith(s,r)?r+s.length:r;l.index=t(i)}if(l.index!==void 0)return c.last=l.index,c},r=(n,r)=>{let i=o(n);if(!i)return;let a=t(i.last+1);if(a===void 0||!e.startsWith(r,a))return;let s=t(a+r.length),c=s===void 0?void 0:o(s);if(c)return{kind:`Pair`,first:n,last:c.last,children:[i,c]}},i=t=>{let n=se(e,t,Ce);if(e.startsWith(`..`,n)&&Ce(e[n+2]))return{kind:`Constant`,first:t,last:se(e,n+2,Ce)-1,children:[]}},a=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=Ce(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:se(e,t+1,Ce)-1,children:[]};if(we(n))return{kind:`Constant`,first:t,last:se(e,t,we)-1,children:[]}},o=i=>{let s=t(i);if(s!==void 0)switch(e[s]){case`{`:return n(`Set`,s,s+1,`}`,o,`,`);case`<`:{let t=n(`Sequence`,s,s+2,`>`,o,`,`);return!t||t.last+1>=e.length?void 0:{...t,last:t.last+1}}case`[`:return n(`Record`,s,s+1,`]`,e=>r(e,`|->`),`,`);case`(`:return n(`Function`,s,s+1,`)`,e=>r(e,`:>`),`@@`);default:{if(!e.startsWith(`SUBSET`,s))return a(s);let n=t(s+6),r=n===void 0?void 0:o(n);return r?{kind:`Subset`,first:s,last:r.last,children:[r]}:void 0}}};return o(0)},Ee=e=>{let t=e.length===0?void 0:Te(e);if(!t||t.last<e.length-1)return e;let n=t=>e.slice(t.first,t.last+1),r=e=>e.last-e.first+1,i=(e,t,i,s)=>{if(r(e)<=t-i||e.kind===`Constant`)return n(e);if(e.kind===`Pair`)return;let c=xe[e.kind],l=t-Math.max(c.open.length,c.pad.length),u=i+c.close.length,d=s+c.pad,f=e.kind===`Function`||e.kind===`Record`?o(e.children,l,u,d,c):a(e.children,l,u,d,c.separator);return f===void 0?void 0:c.open+f+c.close},a=(e,t,n,r,a)=>{let o=e.map((o,s)=>{let c=s===e.length-1,l=i(o,t,c?n:a.length,r);return l===void 0||c?l:`${l}${a}\n${r}`});return o.includes(void 0)?void 0:o.join(``)},o=(e,t,a,o,s)=>{let c=e.map((c,l)=>{let u=l===e.length-1,d=c.children[0],f=c.children[1],p=u?``:`${s.separator}\n${o}`,m=r(d)+s.divider.length+1+r(f);if(u?m<=t-a:m+s.separator.length<=t)return`${n(d)}${s.divider} ${n(f)}${p}`;let h=r(d)+s.divider.length<=t?n(d):i(d,t,a+s.divider.length,o),g=i(f,t-s.dividerPad.length,u?a:s.separator.length,o+s.dividerPad);return h===void 0||g===void 0?void 0:`${h}${s.divider}\n${o}${s.dividerPad}${g}${p}`});return c.includes(void 0)?void 0:c.join(``)};return i(t,80,0,``)??e},P={current:void 0},De=/* @__PURE__ */ new WeakMap,Oe=e=>e instanceof y?De.get(e):void 0,ke=(e,t)=>{let n=P.current;if(!n||typeof e!=`object`)return t();try{return t()}catch(t){let r=n.get(e);throw r&&t instanceof y&&De.set(t,[r,...De.get(t)??[]]),t}},Ae=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,je=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),Me=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),F=e=>typeof e==`object`&&e.kind===`ModelValue`,Ne=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:Ae(e)?`set`:`function`,Pe=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new b(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},I={isUsed:!1},Fe=(e,t)=>(I.isUsed=!0,e.writtenKeys=t,e),Ie=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[pn(e.domain,t)]]),L=(e,t,n)=>Fe(Qe(e,t),n),R=e=>{if(!(typeof e!=`object`||e.kind!==`Function`&&e.kind!==`Set`)&&e.hash===0&&e.fingerprint===0){if(e.kind===`Set`)return e.elements.forEach(R);e.writtenKeys=void 0,e.range.forEach(R)}},Le=e=>e.every(e=>typeof e==`string`),z=(e,t)=>e.length>0&&t.length>0&&Le(e)!==Le(t),B=(e,t)=>{I.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return z(n,r)?gt(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=Je(n[e],r[e]);if(t!==0)return t}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=Je(i[e],a[e]);if(t!==0)return t}return 0},Re=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return n.length-r.length;if(n===r)return 0;for(let e=0;e<n.length;e++){let t=Je(n[e],r[e]);if(t!==0)return t}return 0},V=e=>F(e)?e.type:void 0,H=(e,t,n)=>{let r=V(e),i=V(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(F(e)&&F(t)){if(r===void 0||i===void 0||r===i)return;throw new y(`Attempted to ${a} the differently-typed model values ${Y(e)} and ${Y(t)}`)}throw r===void 0?new y(`Attempted to ${a} the typed model value ${Y(t)} and the non-model value\n${Y(e)}`):new y(`Attempted to ${a}${n?``:` the`} typed model value ${Y(e)} and non-model value\n${Y(t)}`)},U={ranks:Object.create(null),size:0},W=e=>{U.ranks=Object.create(null),U.size=0,Ye.clear();for(let t of e)ze(t)},ze=e=>(U.ranks[e]===void 0&&(U.ranks[e]=U.size++),e),Be=()=>U.size,Ve=e=>U.ranks[ze(e)],He=(e,t)=>{if(e===t)return 0;let n=U.ranks,r=n[e],i=n[t];return r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},Ue=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),We=(e,t)=>(Ue(e)||Ue(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),Ge=(e,t,n)=>{if(!Ue(e))throw new y(`Attempted to ${n} the set ${Y(Jt(e)?q(e):e,!0)} with the value:\n${Y(t,!0)}`);if(!Ue(t))throw new y(`Attempted to compare overridden value ${Y(e,!0)} with non-overridden value:\n${Y(t,!0)}`);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new y(`Attempted to compare ${Y(e,!0)} with the value\n${Y(t,!0)}`)},Ke={kind:`InfiniteSet`,name:`Any`},qe=e=>{throw new y(`Attempted to compare ANY with the value\n${Y(e)}`)},Je=(e,t)=>{if(e===t)return I.isUsed&&R(e),e===Ke?qe(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return B(e,t);if(n===`Set`&&r===`Set`)return Re(e,t);if(n===`Interval`&&r===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.max(0,t.high-t.low+1);return n!==r||n===0?n-r:e.low-t.low}if(n===`ModelValue`&&r===`ModelValue`)return e.type!==void 0&&t.type!==void 0&&H(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return H(e,t,!1),n===`ModelValue`?-1:1;if(e===Ke||t===Ke)return qe(e===Ke?t:e);if(Ae(e)&&Ae(t)&&We(e,t))return Ge(e,t,`compare`);let i=Ae(e);if(i!==Ae(t))throw new y(`Attempted to compare ${Ne(e)} ${Y(e)} with ${Ne(t)} ${Y(t)}`);return i?Re(q(e),an(t)):B(bn(e),bn(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return He(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(H(e,t,!1),F(e))return-1;if(F(t))return 1;throw new y(`Attempted to compare ${Ne(e)} ${Y(e)} with ${Ne(t)} ${Y(t)}`)},Ye=/* @__PURE__ */ new Map,Xe=e=>{let t=Ye.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Ve(e)};return Ye.set(e,n),n},Ze=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0}),Qe=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0}),$e=(e,t)=>{if(e===t)return I.isUsed&&R(e),e!==Ke||qe(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&H(e,t,!0),Je(e,t)===0);if((e.kind===`Set`||e.kind===`Function`)&&(t.kind===`Set`||t.kind===`Function`)&&e.hash!==0&&t.hash!==0&&e.hash!==t.hash)return!1;if(e.kind===`Function`&&t.kind===`Function`)return B(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Re(e,t)===0;if(F(e)||F(t))return H(e,t,!0),F(e)&&F(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return $e(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=sn(e.domain),r=sn(t.domain);if(n||r)return n===r;let i=sn(e.range),a=sn(t.range);return i||a?i===a:$e(e.domain,t.domain)&&$e(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){if(sn(e))return sn(t);if(sn(t))return!1;let n=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),r=n(t);return e.names.length===t.names.length&&n(e).every((e,t)=>e[0]===r[t][0]&&$e(e[1],r[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`)return sn(e)?sn(t):!sn(t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>$e(e,t.factors[n]));let n=Ae(e)&&Ae(t)&&!(Jt(e)&&Jt(t));if(n&&We(e,t))return Ge(e,t,`check equality of`)===0;if(n){if(!Ue(e)){let n=q(e);if(!Ue(t))return Re(n,q(t))===0}return $n(e)===$n(t)}return Je(e,t)===0},et=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>tt(e,t[n])),tt=(e,t)=>e===t?!0:typeof e!=`object`||typeof t!=`object`?!1:e.kind===`Set`&&t.kind===`Set`?(e.hash===0||t.hash===0||e.hash===t.hash)&&et(e.elements,t.elements):e.kind===`Function`&&t.kind===`Function`?(e.hash===0||t.hash===0||e.hash===t.hash)&&et(e.domain,t.domain)&&et(e.range,t.range):$n(e)===$n(t),nt=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},rt=e=>{if(!Me(e))return;let t=bn(e);return{domain:t.domain,range:t.range,low:nt(t.domain)}},G=e=>{if(!Me(e))return;let t=bn(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},K=(e,t)=>{if(V(e)!==void 0)throw new y(`Attempted to compare the typed model value ${Y(e)} and the non-model value\n${Y(t)}`);return 1},it=(e,t)=>{if(V(e)!==void 0)throw new y(`Attempted to check equality of the typed model value ${Y(e)} and the non-model value\n${Y(t)}`);return!1},at=(e,t)=>{let n=V(e);if(n===void 0)return F(t)?e.rank-t.rank:-1;if(!F(t))throw new y(`Attempted to compare the typed model value ${Y(e)} and non-model value\n${Y(t)}`);let r=V(t);if(r!==void 0&&r!==n)throw new y(`Attempted to compare the differently-typed model values ${Y(e)} and ${Y(t)}`);return e.rank-t.rank},ot=(e,t)=>{let n=V(e);if(n===void 0)return F(t)&&e.name===t.name;if(!F(t))throw new y(`Attempted to check equality of typed model value ${Y(e)} and non-model value\n${Y(t)}`);let r=V(t);if(r!==void 0&&r!==n)throw new y(`Attempted to check equality of the differently-typed model values ${Y(e)} and ${Y(t)}`);return e.name===t.name},st={number:{name:`integer`,other:`non-integer`,equality:`check equality of`},string:{name:`string`,other:`non-string`,equality:`check equality of`},boolean:{name:`boolean`,other:`non-boolean`,equality:`compare equality of`}},ct=(e,t,n)=>{let r=st[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${Y(e)} with ${r.other}:\n${Y(t)}`},lt=(e,t,n)=>{let r=rt(n);if(!r){if(F(n))return K(n,t);throw new y(`Attempted to compare the function ${Y(t)} with the value:\n${Y(n)}`)}if(e.range.length!==r.range.length)return e.range.length-r.range.length;let i=()=>ut(e.range,r.range);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&r.low!==void 0)return e.low===r.low?i():e.low-r.low;let a=e.low??r.low;if(a===void 0)return ut(e.domain,r.domain)||i();let o=e.low===void 0?e.domain:r.domain;for(let t=0;t<o.length;t++){let n=o[t];if(typeof n!=`number`)throw new y(`Attempted to compare integer with non-integer${e.low===void 0?``:`:`}\n${Y(n)}.`);let r=e.low===void 0?n-(a+t):a+t-n;if(r!==0)return r}return i()},ut=(e,t)=>{for(let n=0;n<e.length;n++){let r=gt(e[n],t[n]);if(r!==0)return r}return 0},dt=(e,t)=>{let n=bn(e);if(e.kind===`Function`&&mn(n)!==void 0){let r=Me(t)?mn(t):void 0;return r?n.range.length-r.length||ut(n.range,r):lt({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=G(t);if(!r){if(F(t))return K(t,e);throw new y(`Attempted to compare record:\n${Y(e)}\nwith non-record\n${Y(t)}`)}return n.domain.length-r.domain.length||ut(n.domain,r.domain)||ut(n.range,r.range)}return lt({...n,low:nt(n.domain)},e,t)},ft=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),pt=(e,t)=>Ue(e)||Ue(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),mt=(e,t)=>{let n=ft(t)?t:q(t);return{elements:q(e).elements,otherElements:q(n).elements}},ht=(e,t)=>{if(pt(e,t))return Je(e,t);if(!ft(e))return ht(q(e),t);if(!Ae(t)){if(F(t))return K(t,e);throw new y(`Attempted to compare the set ${Y(e)} with the value:\n${Y(t)}`)}let n=mt(e,t);return n.elements.length-n.otherElements.length||ut(n.elements,n.otherElements)},gt=(e,t)=>ke(e,()=>{if(typeof e!=`object`){if(typeof t==typeof e)return Je(e,t);if(F(t))return K(t,e);throw new y(ct(e,t,!1))}return e.kind===`ModelValue`?at(e,t):Me(e)?dt(e,t):ht(e,t)}),_t=(e,t)=>e.every((e,n)=>xt(e,t[n])),vt=(e,t,n)=>{let r=rt(n);if(!r){if(F(n))return it(n,t);throw new y(`Attempted to check equality of the function ${Y(t)} with the value:\n${Y(n)}`)}if(e.range.length!==r.range.length)return!1;if(e.low!==void 0&&r.low!==void 0)return(e.range.length===0||e.low===r.low)&&_t(e.range,r.range);let i=e.low??r.low;return i===void 0?_t(e.domain,r.domain)&&_t(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new y(`Attempted to compare an integer with non-integer:\n${Y(e)}.`);return e===i+t})&&_t(e.range,r.range)},yt=(e,t)=>{let n=bn(e);if(e.kind===`Function`&&mn(n)!==void 0){let r=Me(t)?mn(t):void 0;return r?n.range.length===r.length&&_t(n.range,r):vt({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=G(t);if(!r){if(F(t))return it(t,e);throw new y(`Attempted to check equality of record:\n${Y(e)}\nwith non-record\n${Y(t)}`)}return n.domain.length===r.domain.length&&_t(n.domain,r.domain)&&_t(n.range,r.range)}return vt({...n,low:nt(n.domain)},e,t)},bt=(e,t)=>{if(pt(e,t))return $e(e,t);if(!ft(e))return bt(q(e),t);if(!Ae(t)){if(F(t))return it(t,e);throw new y(`Attempted to check equality of the set ${Y(e)} with the value:\n${Y(t)}`)}let n=mt(e,t);return n.elements.length===n.otherElements.length&&_t(n.elements,n.otherElements)},xt=(e,t)=>ke(e,()=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(F(t))return it(t,e);throw new y(ct(e,t,!0))}return e.kind===`ModelValue`?ot(e,t):Me(e)?yt(e,t):bt(e,t)}),St=e=>{let t=[];for(let n of e){let e={low:0,high:t.length,comparison:1};for(;e.low<e.high;){let r=e.low+(e.high-e.low>>1);if(e.comparison=gt(n,t[r]),e.comparison===0)break;e.comparison<0?e.high=r:e.low=r+1}e.comparison!==0&&t.splice(e.low,0,n)}return t},Ct=(e,t)=>t.some(t=>xt(t,e)),wt=(e,t)=>{try{return $e(e,t)}catch(n){if(!(n instanceof y))throw n;return xt(e,t)}},Tt=e=>{for(let t=1;t<e.length;t++)if(Je(e[t],e[t-1])<=0)return!1;return!0},Et=e=>{if(e.length<2||Tt(e))return Ze(e);let t=[...e].sort(Je),n=[t[0]];for(let e=1;e<t.length;e++)Je(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ze(n)},Dt=e=>{try{return Et(e)}catch(t){if(!(t instanceof y))throw t;return{kind:`MixedSet`,elements:e}}},Ot=Ze([]),kt=(e,t)=>{if(e.elements.length===0||t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&Je(r[a],t)<0;)a++;a<r.length&&Je(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ze(i)},At=(e,t)=>{let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&Je(r[a],t)<0;)a++;a<r.length&&Je(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ze(i)},jt=(e,t)=>{if(e.elements.length===0)return t;if(t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=[],o=0,s=0;for(;o<n.length&&s<r.length;){let e=Je(n[o],r[s]);e<0?i.push(n[o++]):e>0?(a.push(r[s]),i.push(r[s++])):(i.push(n[o++]),s++)}for(;o<n.length;)i.push(n[o++]);for(;s<r.length;)a.push(r[s]),i.push(r[s++]);if(a.length===0)return e;let c=Ze(i);if(e.hash!==0){let t=e.hash;for(let e=0;e<a.length;e++)t=t+Rn(a[e])|0;c.hash=t}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+Jn(a[e])|0;c.fingerprint=t}return c},Mt=e=>{let t=e.length<2?e:[...e].sort((e,t)=>Je(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&Je(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Qe(n,r)},Nt=e=>{let t=Mt(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:Fe(t,e.map(e=>e[0]))},Pt=[],Ft=[],It=/* @__PURE__ */ new WeakMap,Lt=e=>{let t=Pt[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Pt[e]=n,n},Rt=e=>{if(un(e),e.low===1&&e.high>=1)return Lt(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},zt=e=>e.length>0&&(e===Pt[e.length]||It.has(e)),Bt=e=>{let t=q(e).elements;return zt(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Vt=e=>{let t=Ft[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return Ft[e]=n,n},Ht=e=>Qe(Lt(e.length),e),Ut=e=>Mt(e),Wt=e=>Ae(e)&&!Ue(e),Gt=(e,t=!1)=>`UNION(${Y(e.base,t)})`,Kt=(e,t=e=>q(e).elements)=>{if(!Wt(e.base))throw new y(`Attempted to enumerate the nonenumerable set:\n${Gt(e)}`);return t(e.base)},qt=(e,t,n)=>{if(Wt(e))return e;throw new y(t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${Y(e)}\nwhen enumerating:\n${Gt(n)}`)},Jt=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`InfiniteSet`:case`SequenceSet`:return!1;case`Subset`:case`FilteredSet`:return Jt(e.base);case`FunctionSet`:return Jt(e.domain)&&Jt(e.range)||Yt(e.domain)===!0||Yt(e)===!0;case`RecordSet`:return e.sets.every(Jt)||Yt(e)===!0;case`ProductSet`:return e.factors.every(Jt)||Yt(e)===!0;case`Union`:return Jt(e.base)&&on(e.base).every(Jt);case`SetOperation`:return e.operator===`\\cup`?Jt(e.left)&&Jt(e.right):e.operator===`\\cap`?Jt(e.left)||Jt(e.right):Jt(e.left);default:return!1}},Yt=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:return e.name===`Any`&&void 0;case`Subset`:case`SequenceSet`:return!1;case`FunctionSet`:{let t=Yt(e.domain);return t===void 0?void 0:!t&&Yt(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Yt(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return Jt(e)?q(e).elements.length===0:void 0;default:return}},Xt=e=>{let t=e.reduce((e,t)=>e*t.length,1),n=[],r=e.map(()=>0);for(let i=0;i<t;i++){n.push(e.map((e,t)=>e[r[t]]));for(let t=e.length-1;t>=0&&(r[t]++,!(r[t]<e[t].length));t--)r[t]=0}return n},Zt=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]<t-e.length+n){e[n]++;for(let t=n+1;t<e.length;t++)e[t]=e[t-1]+1;return!0}return!1},Qt=e=>{if(typeof e!=`object`||e.kind!==`Subset`||Ue(e.base))return;let t=q(e.base).elements;if(t.length<=30)return;let n={index:-1,indices:[0]},r=e=>{for(e<=n.index&&(n.index=-1);n.index<e;)n.index===-1?n.indices=[]:Zt(n.indices,t.length)||(n.indices=Array.from({length:n.indices.length+1},(e,t)=>t)),n.index++;return Ze(n.indices.map(e=>t[e]))},i=2**t.length,a=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<i;return new Proxy([],{get:(e,t,n)=>t===`length`?i:a(t)?r(Number(t)):Reflect.get(e,t,n),has:(e,t)=>a(t)||Reflect.has(e,t)})},$t=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Ze(r.map(t=>e[t])));while(Zt(r,e.length))}return t},en=e=>{if(typeof e!=`object`)throw new y(`Expected a set but found ${Y(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return St(e.elements);case`Interval`:{let t=Rt(e);return t!==Pt[t.length]&&It.set(t,e),t}case`Subset`:{Ue(e.base)&&un(e.base);let t=q(e.base).elements;if(t.length>30)throw new y(ln(e));return $t(t)}case`FunctionSet`:{if(sn(e))return[];if(Ue(e.domain))throw new y(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${Y(e.domain)}\ncannot be enumerated.`);let t=Bt(e.domain);if(t.length>0&&Ue(e.range))throw new y(`Attempted to enumerate a set of the form [D -> R],but the range R:\n${Y(e.range)}\ncannot be enumerated.`);let n=t.length===0?[]:q(e.range).elements;return Xt(t.map(()=>n)).map(e=>Qe(t,e))}case`RecordSet`:{if(sn(e))return[];let t=e.sets.map((t,n)=>{if(Ue(t))throw new y(`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[n]}' field:\n${Y(t)}`);return q(t).elements});return Xt(t).map(t=>Ut(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(sn(e))return[];let t=e.factors.map((e,t)=>{if(Ue(e))throw new y(`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${Y(e)}`);return q(e).elements});return Xt(t).map(Ht)}case`FilteredSet`:if(Ue(e.base))throw new y(`Attempted to enumerate { x \\in S : p(x) } when S:\n${Y(e.base)}\nis not enumerable`);return q(e.base).elements.filter(e.test);case`Union`:{let t=Kt(e).flatMap((t,n)=>q(qt(t,n,e)).elements);return q(Dt(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(!Wt(e.left)||!Wt(e.right)))throw new y(`Attempted to enumerate S \\cup T when S:\n${Y(e.left)}\nand T:\n${Y(e.right)}\nare not both enumerable`);if(e.operator===`\\cap`&&!Wt(e.left)&&!Wt(e.right))throw new y(`Attempted to enumerate S \\cap T when neither S:\n${Y(e.left)}\nnor T:\n${Y(e.right)}\nis enumerable`);if(e.operator===`\\`&&!Wt(e.left))throw new y(`Attempted to enumerate S \\ T when S:\n${Y(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return jt(q(e.left),q(e.right)).elements;let t=e.operator===`\\`||Jt(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return q(n).elements.filter(t=>vn(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to enumerate the non-enumerable set ${Y(e)}`);default:throw new y(`Expected a set but found ${Y(e)}`)}},tn=/* @__PURE__ */ new WeakMap,nn=/* @__PURE__ */ new WeakMap,q=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ze(en(e));let t=typeof e==`object`?tn.get(e):void 0;if(t)return t;let n=(typeof e==`object`?nn.get(e):void 0)??(P.current?ke(e,()=>rn(e)):rn(e));return typeof e==`object`&&tn.set(e,n),n},rn=e=>{let t=en(e);return typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Ze(t):Et(t)},an=e=>{if(typeof e!=`object`||e.kind!==`Union`&&e.kind!==`SetOperation`&&e.kind!==`FilteredSet`||tn.has(e))return q(e);let t=nn.get(e);if(t)return t;let n=rn(e);return nn.set(e,n),n},on=e=>{if(typeof e!=`object`||tn.has(e))return q(e).elements;if(e.kind===`Union`)return Kt(e,on).flatMap((t,n)=>on(qt(t,n,e)));if(e.kind===`FilteredSet`&&!Ue(e.base))return on(e.base).filter(e.test);if(e.kind!==`SetOperation`)return q(e).elements;if(e.operator===`\\cup`)return!Wt(e.left)||!Wt(e.right)?q(e).elements:[...on(e.left),...on(e.right)];let t=e.operator===`\\`||Jt(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return Wt(n)?on(n).filter(t=>vn(t,r)===(e.operator===`\\cap`)):q(e).elements},sn=e=>{if(typeof e!=`object`||!Ae(e))throw new y(`Shouldn't call isEmpty() on value ${Y(e)}`);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:if(e.name===`Any`)throw new y(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1;case`ProductSet`:return e.factors.some(sn);case`RecordSet`:return e.sets.some(sn);case`FunctionSet`:return!sn(e.domain)&&sn(e.range);case`Union`:return Kt(e).every((t,n)=>sn(qt(t,n,e)));default:return q(e).elements.length===0}},cn=(e,t)=>e.reduce((e,n)=>{let r=e*un(n);if(r>2147483647)throw new y(t());return r},1),ln=e=>`Overflow when computing the number of elements in:\n${Y(e)}`,un=e=>{if(typeof e!=`object`)return q(e).elements.length;switch(e.kind){case`Interval`:{let t=Math.max(0,e.high-e.low+1);if(t>2147483647)throw new y(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to compute the number of elements in the overridden value ${Y(e)}.`);case`Subset`:{let t=un(e.base);if(t>=31)throw new y(ln(e));return 2**t}case`FunctionSet`:{if(sn(e.domain))return 1;if(sn(e.range))return 0;let t=un(e.range);if(t===1)return 1;let n=un(e.domain),r={value:1};for(let i=0;i<n;i++)if(r.value*=t,r.value>2147483647)throw new y(ln(e));return r.value}case`RecordSet`:return sn(e)?0:cn(e.sets,()=>ln(e));case`ProductSet`:return sn(e)?0:cn(e.factors,()=>`Overflow when computing the number of elements in ${Y(e)}`);default:return q(e).elements.length}},dn=e=>`Attempted to check if the set ${Y(e)}is finite.`,fn=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new y(`Attempted to check if the ${Ne(e)} ${Y(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new y(`Attempted to check if the function:\n${Y(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return fn(e.base)&&sn(e.base);case`Subset`:return fn(e.base);case`FunctionSet`:{let t=fn(e.domain);if(t&&sn(e.domain))return!0;let n=fn(e.range);return n&&sn(e.range)?!0:n&&(t||un(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n={isAllFinite:!0};for(let e of t)if(!fn(e))n.isAllFinite=!1;else if(sn(e))return!0;return n.isAllFinite}case`Union`:if(!Wt(e.base))throw new y(`Attempted to check if the nonenumerable set:\n${Gt(e)}\nis a finite set.`);return q(e.base).elements.every(fn);case`SetOperation`:if(e.operator===`\\cup`)return fn(e.left)&&fn(e.right);if(e.operator===`\\cap`){if(!fn(e.left)&&!fn(e.right))throw new y(dn(e));return!0}if(fn(e.left))return!0;if(!fn(e.right))throw new y(dn(e));return!1;case`FilteredSet`:if(!fn(e.base))throw new y(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${Y(e.base)}\nis finite.`);return!0}},pn=(e,t)=>{let n={low:0,high:e.length-1};for(;n.low<=n.high;){let r=n.low+n.high>>1,i=Je(e[r],t);if(i===0)return r;i<0?n.low=r+1:n.high=r-1}return-1},mn=e=>{if(typeof e!=`object`||!Me(e))return;let t=bn(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},hn=(e,t)=>`Attempted to check if the value ${Y(e)} is an element of ${Y(t)}`,gn=(e,t)=>{let n=`Attempted to check if the value:\n${Y(e)}\nis an element of the`;if(!Me(t))return`${n} ${Ne(t)} ${Y(t)}`;let r=t.kind===`Function`||Jt(t.domain)?bn(t).domain:[];return r.length>0&&r.every(e=>typeof e==`string`)?`Attempted to check if element:\n${Y(e)}\nis in the record:\n${Y(t)}`:r.every((e,t)=>e===t+1)?`Attempted to check set membership in a tuple value.`:`${n} function ${Y(t)}`},_n=(e,t)=>P.current?ke(t,()=>vn(e,t)):vn(e,t),vn=(e,t)=>{if(!Ae(t))throw new y(gn(e,t));switch(t.kind){case`Set`:try{return pn(t.elements,e)!==-1}catch(n){if(!(n instanceof y))throw n;return ke(t,()=>Ct(e,t.elements))}case`MixedSet`:return ke(t,()=>Ct(e,t.elements));case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!F(e))throw new y(`Attempted to check if the value:\n${Y(e)}\nis in the integer interval ${Y(t)}`);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(F(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new y(`Attempted to check if the value:\n${Y(e)}\nis an element of ${t.name}.`);return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:if(!Wt(e))throw new y(`Attempted to check if the non-enumerable value\n${Ee(Y(e))}\nis element of\n${Ee(Y(t))}`);return q(e).elements.every(e=>_n(e,t.base));case`FunctionSet`:{if(!Me(e)){if(F(e))return!1;throw new y(`Attempted to check if \n${Y(e)}\nwhich is not a TLC function value, is in the set of functions:\n${Ee(Y(t))}`)}let n=bn(e),r=nt(n.domain);return(r===void 0?wt(t.domain,Ze(n.domain)):wt({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>_n(e,t.range))}case`RecordSet`:{let n=Me(e)?bn(e):void 0;if(!n||!Le(n.domain)){if(F(e))return!1;throw new y(`Attempted to check if non-record\n${Y(e)}\nis in the set of records:\n${Y(t)}`)}return n.domain.length===t.names.length&&t.names.every((e,r)=>{let i=pn(n.domain,e);return i!==-1&&_n(n.range[i],t.sets[r])})}case`ProductSet`:{let n=Me(e)?mn(e):void 0;if(n===void 0){if(Me(e)&&bn(e).domain.every(e=>typeof e==`number`)||F(e))return!1;throw new y(`Attempted to check if non-tuple\n${Y(e)}\nis in the set of tuples:\n${Y(t)}`)}return n.length===t.factors.length&&n.every((e,n)=>_n(e,t.factors[n]))}case`FilteredSet`:return _n(e,t.base)&&t.test(e);case`Union`:if(!Wt(t.base))throw new y(`Attempted to check if:\n ${Y(e)}\nis an element of the non-enumerable set:\n ${Gt(t)}`);return q(t.base).elements.some(t=>_n(e,t));case`SetOperation`:return t.operator===`\\cup`?_n(e,t.left)||_n(e,t.right):_n(e,t.left)&&_n(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=mn(e);if(n===void 0){if(F(e))return!1;throw new y(hn(e,t))}return n.every(e=>vn(e,t.base))}default:throw new y(gn(e,t))}},yn=(e,t,n)=>e===t?!0:typeof e!=`object`||typeof t!=`object`||typeof n!=`object`||e.kind!==`Function`||t.kind!==`Function`||n.kind!==`FunctionSet`||e.domain!==t.domain?vn(e,n):e.range.every((e,r)=>yn(e,t.range[r],n.range)),bn=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){Jt(e.domain)||un(e.domain);let t=Bt(e.domain);return Qe(t,t.map(t=>e.apply(t)))}throw new y(`Expected a function but found ${Y(e)}`)},xn=/* @__PURE__ */ new WeakSet,Sn=e=>(xn.add(e),e),Cn=e=>{let t=e.domain;return t.length===0?xn.has(e)?`FcnRcdValue`:`TupleValue`:t===Pt[t.length]?`TupleValue`:It.has(t)?`IntervalFcnRcdValue`:t.every(e=>typeof e==`string`)?`RecordValue`:`FcnRcdValue`},wn=(e,t)=>`Attempted to apply function:\n${Ee(Y(e))}\nto argument ${Ee(Y(t))}, which is not in the domain of the function.`,J=e=>`Attempted to apply function with integer domain to the non-integer argument ${Ee(Y(e))}`,Tn=(e,t)=>{if(xn.has(e)||e.kind===`LazyFunction`)return`In applying the function\n${Ee(Y(e))},\nthe first argument is:\n${Ee(Y(t))}\nwhich is not in its domain.\n`;let n=Cn(e);return n===`TupleValue`?typeof t==`number`?`Attempted to access index ${t} of tuple\n${Ee(Y(e))}\nwhich is out of bounds.`:`Attempted to access tuple at a non integral index: ${Ee(Y(t))}`:n===`RecordValue`?typeof t==`string`?`Attempted to access nonexistent field '${t}' of record\n${Ee(Y(e))}`:`Attempted to access record by a non-string argument: ${Ee(Y(t))}`:n===`IntervalFcnRcdValue`&&typeof t!=`number`?J(t):wn(e,t)},En=(e,t)=>Cn(e)===`FcnRcdValue`?wn(e,t):J(t),Dn=e=>Cn(e)===`RecordValue`,On=(e,t)=>{let n=e[0];return typeof n==`number`?typeof t!=`number`&&(e===Pt[e.length]||It.has(e)):typeof n==`string`&&typeof t!=`string`},kn=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}if(e.length<=8){for(let n=0;n<e.length;n++)if(e[n]===t)return n}return pn(e,t)},An=(e,t,n,r)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!vn(t,e.domain))throw new y(xn.has(e)?Tn(e,t):`Attempted to apply a function to ${Y(t)}, which is not in its domain`);return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new y(r?.(e)??`Attempted to apply ${Y(e)}, which is not a function`);let i=On(e.domain,t)?-1:kn(e.domain,t);if(i===-1)throw new y(n?.(e)??Tn(e,t));return e.range[i]},jn=e=>zt(e)?It.get(e)??Vt(e.length):void 0,Mn=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=bn(e).domain;return jn(t)??Ze(t)},Nn=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!Jt(e.domain))){if(!vn(t,e.domain))return e;let r=n(e.apply(t));return{kind:`LazyFunction`,domain:e.domain,apply:n=>wt(t,n)?r:e.apply(n),source:e.source}}let i=bn(e),a=kn(i.domain,t);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=Qe(i.domain,o);if(l.writtenKeys=i.writtenKeys,i.hash!==0){let e=i.domain[a];l.hash=s===c?i.hash:i.hash-zn(e,s)+zn(e,c)|0}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-Yn(e,s)+Yn(e,c)|0}return l},Pn=/* @__PURE__ */ new WeakMap,Fn=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},In=(e,t)=>Math.imul(e^t,16777619),Ln=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Fn(t)},Rn=e=>Fn(Hn(e)+2654435769|0),zn=(e,t)=>Fn(Math.imul(Hn(e),668265261)+Hn(t)|0),Bn={isHashed:!1},Vn=e=>{if(e.kind===`ModelValue`)return Fn(In(Ln(e.name),109));if(Ae(e)){if(!Jt(e))return Bn.isHashed=!0,Ln($n(e));let t=q(e).elements,n=1940243425;for(let e=0;e<t.length;e++)n=n+Rn(t[e])|0;return n}let t=bn(e),n=1725019383;for(let e=0;e<t.domain.length;e++)n=n+zn(t.domain[e],t.range[e])|0;return n},Hn=e=>{if(typeof e==`number`)return Fn(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Ln(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=Vn(e)),e.hash;let t=Pn.get(e);if(t!==void 0)return t;let n=Vn(e);return Pn.set(e,n),n},Un=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return;if(Ue(e))throw new y(`TLC has found a state in which the value of a variable contains ${Y(e)}`);if(Ae(e))return q(e).elements.forEach(Un);let t=bn(e);t.domain.forEach(Un),t.range.forEach(Un)},Wn=e=>{Bn.isHashed&&e.forEach(Un)},Gn=/* @__PURE__ */ new WeakMap,Kn=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},qn=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return Kn(t)},Jn=e=>Kn(Zn(e)+2135587861|0),Yn=(e,t)=>Kn(Math.imul(Zn(e),374761393)+Zn(t)|0),Xn=e=>{if(e.kind===`ModelValue`)return Kn(qn(e.name)^60);if(Ae(e)){if(!Jt(e))return Bn.isHashed=!0,qn($n(e));let t=q(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+Jn(t[e])|0;return n}let t=bn(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+Yn(t.domain[e],t.range[e])|0;return n},Zn=e=>{if(typeof e==`number`)return Kn(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return qn(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=Xn(e)),e.fingerprint;let t=Gn.get(e);if(t!==void 0)return t;let n=Xn(e);return Gn.set(e,n),n},Qn=/* @__PURE__ */ new WeakMap,$n=e=>{if(typeof e==`boolean`)return e?`T`:`F`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return JSON.stringify(e);let t=Qn.get(e);if(t!==void 0)return t;let n=er(e);return Qn.set(e,n),n},er=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${$n(e.base)}>`;if(e.kind===`FilteredSet`&&!Jt(e))throw new y(`Attempted to compare the non-enumerable set ${Y(e)} with another value`);if(Ae(e))return Jt(e)?`{${q(e).elements.map($n).join(`,`)}}`:`<${e.kind} ${Y(e)}>`;let t=bn(e);return`(${t.domain.map((e,n)=>`${$n(e)}:${$n(t.range[n])}`).join(`,`)})`},tr=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,nr=e=>e.reduce((e,t)=>e===0?0:e*un(t),1),rr=e=>{if(e.kind===`Subset`)return un(e.base)<=6?q(e):void 0;if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return q(e);if(e.kind===`FunctionSet`&&Jt(e.domain)&&un(e.domain)===0)return Ze([Qe([],[])]);let t=e.kind===`FunctionSet`?un(e.range)**un(e.domain):nr(e.kind===`RecordSet`?e.sets:e.factors);return t===0?Ot:t<=1999?q(e):void 0},ir=(e,t)=>{if(t)return rr(e);if(Jt(e))try{return rr(e)}catch(e){if(e instanceof y)return;throw e}},ar=(e,t)=>{let n=e=>Y(e,t);switch(e.kind){case`Subset`:return typeof e.base==`object`&&e.base.kind===`Interval`?`SUBSET (${n(e.base)})`:`SUBSET ${n(e.base)}`;case`FunctionSet`:return`[${n(e.domain)} -> ${n(e.range)}]`;case`RecordSet`:return`[${e.names.map((t,r)=>`${t}: ${n(e.sets[r])}`).join(`, `)}]`;case`ProductSet`:return`(${e.factors.map(n).join(` \\X `)})`;case`SetOperation`:return`${n(e.left)} ${e.operator} ${n(e.right)}`;case`FilteredSet`:return`{x \\in ${n(e.base)} : ...}`;case`Union`:return Gt(e,t)}},or=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),Y=(e,t=!1,n=!1)=>{let r=e=>Y(e,t,n);if(typeof e==`boolean`)return e?`TRUE`:`FALSE`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return tr(e);switch(e.kind){case`ModelValue`:return e.name;case`Set`:return`{${e.elements.map(r).join(`, `)}}`;case`MixedSet`:return r(q(e));case`Interval`:return e.low<=e.high?`${e.low}..${e.high}`:`{}`;case`InfiniteSet`:return e.name===`Any`?`ANY`:e.name;case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let n=ir(e,t);return n?r(n):ar(e,t)}case`SequenceSet`:return`Seq(${r(e.base)})`;case`Function`:case`LazyFunction`:{if(e.kind===`LazyFunction`&&!Jt(e.domain)){let t=e.source;return t?`[${t.parameters.map(e=>`${e.name} \\in ${Y(e.domain)}`).join(`, `)} |-> <expression ${t.body}>]`:`<function>`}let i=bn(e),a=r=>Y(r,t,n&&e.kind===`Function`);return i.domain.every((e,t)=>e===t+1)?`<<${i.range.map(a).join(`, `)}>>`:i.domain.every(e=>typeof e==`string`&&or(e))?`[${(n||i.hash!==0||i.fingerprint!==0?i.domain.map((e,t)=>[e,i.range[t]]):Ie(i)).map(e=>`${String(e[0])} |-> ${a(e[1])}`).join(`, `)}]`:`(${i.domain.map((e,t)=>`${r(e)} :> ${a(i.range[t])}`).join(` @@ `)})`}}},sr=e=>{let t=Object.entries(e);return t.map(([e,n])=>`${t.length===1?``:`/\\ `}${e} = ${Ee(Y(n))}\n`).join(``)},cr=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},lr=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=Hn(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||tt(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||tt(i[e],n))return i[e]}return n.kind===`Set`?cr(n.elements,t):(cr(n.domain,t),cr(n.range,t)),i===void 0?e.set(r,n):Array.isArray(i)?i.push(n):e.set(r,[i,n]),n};return e=>{for(let n=0;n<e.length;n++)e[n]=t(e[n]);return e}},ur=e=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return[];case`Apply`:return e.args;case`Lambda`:return[e.body];case`And`:case`Or`:return e.operands;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`If`:return[e.condition,e.consequent,e.alternative];case`Case`:return[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]];case`Let`:return[...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),e.body];case`Forall`:case`Exists`:return[...e.bounds.map(e=>e.set),e.body];case`UnboundedQuantifier`:return[e.body];case`Choose`:return[...e.set?[e.set]:[],e.body];case`SetEnumeration`:case`Tuple`:return e.elements;case`SetFilter`:return[e.bound.set,e.predicate];case`SetMap`:return[e.expression,...e.bounds.map(e=>e.set)];case`FunctionConstruction`:return[...e.bounds.map(e=>e.set),e.body];case`FunctionSet`:return[e.domain,e.range];case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`Except`:return[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])];case`FunctionApplication`:return[e.function,...e.args];case`FieldAccess`:return[e.record];case`Product`:return e.factors;case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`Label`:return[e.body];case`Subexpression`:return e.selectors.flatMap(e=>`args`in e?e.args:[])}},X=e=>(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`,dr=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),fr=(e,t)=>dr.has(e)?new y(t):new b(t),pr=e=>typeof e==`object`&&e.kind===`Operator`,Z=(e,t,n)=>{let r=e[t];if(r===void 0||pr(r))throw fr(n,`${n} expects a value as argument ${t+1}`);return r},mr=(e,t,n)=>{let r=Z(e,t,n);if(typeof r!=`number`)throw fr(n,`${n} expects an integer but received ${Y(r)}`);return r},hr=(e,t,n)=>{let r=Z(e,t,n);if(typeof r!=`boolean`)throw fr(n,`${n} expects a boolean but received ${Y(r)}`);return r},gr=(e,t,n)=>{let r=Z(e,t,n);if(!Ae(r))throw fr(n,`${n} expects a set but received ${Y(r)}`);return r},_r=(e,t,n)=>{let r=gr(e,t,n);if(!Jt(r))throw fr(n,`${n} cannot enumerate the non-enumerable set ${Y(r)}`);return r},vr=(e,t,n)=>q(_r(e,t,n)),yr=(e,t,n)=>vr(e,t,n).elements,br=(e,t,n)=>{let r=Z(e,t,n),i=mn(r);if(!i)throw fr(n,`${n} expects a sequence but received ${Y(r)}`);return i},xr=(e,t,n)=>{let r=Z(e,t,n);if(!Me(r))throw fr(n,`${n} expects a function but received ${Y(r)}`);return bn(r)},Sr=(e,t,n)=>{let r=e[t];if(r===void 0||!pr(r))throw fr(n,`${n} expects an operator as argument ${t+1}`);return r},Cr=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),Q=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:t===1?e=>n([e]):void 0,evaluateBinary:t===2?(e,t)=>n([e,t]):void 0}),wr=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Tr=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),Er=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(Z(n,0,e),Z(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Dr=e=>e>2147483647||e<-2147483648,Or=e=>new b(`Overflow when computing ${e}`),kr={ModelValue:`ModelValue`,Set:`SetEnumValue`,Interval:`IntervalValue`,InfiniteSet:`UserValue`,SequenceSet:`UserValue`,Subset:`SubsetValue`,FunctionSet:`SetOfFcnsValue`,RecordSet:`SetOfRcdsValue`,ProductSet:`SetOfTuplesValue`,FilteredSet:`SetPredValue`,LazyFunction:`FcnLambdaValue`,Union:`UnionValue`,MixedSet:`SetEnumValue`},Ar={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},jr={BoolValue:`a Boolean value`,IntValue:`an integer`,StringValue:`a string`,RecordValue:`a record`,SetEnumValue:`a set of the form {e1, ... ,eN}`,SetPredValue:`a set of the form {x \\in S : expr}`,TupleValue:`a tuple`,FcnLambdaValue:`a function of the form [x \\in S |-> expr]`,FcnRcdValue:`a function of the form (d1 :> e1 @@ ... @@ dN :> eN)`,SetOfFcnsValue:`a set of the form [S -> T]`,SetOfRcdsValue:`a set of the form [d1 : S1, ... , dN : SN]`,SetOfTuplesValue:`a cartesian product`,SubsetValue:`a set of the form SUBSET S`,SetDiffValue:`a set of the form S \\ T`,SetCapValue:`a set of the form S \\cap T`,SetCupValue:`a set of the form S \\cup T`,ModelValue:`a model value`,UserValue:`a special set constant`,IntervalValue:`a set of the form i..j`,UnionValue:`a set of the form UNION S`},Mr=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Ar[e.operator];if(e.kind!==`Function`)return kr[e.kind];let t=e.domain;return t.every((e,t)=>e===t+1)?`TupleValue`:t.every(e=>typeof e==`string`)?`RecordValue`:`FcnRcdValue`},Nr=e=>jr[Mr(e)],Pr=(e,t)=>new y(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),Fr=(e,t)=>{let n=n=>(...r)=>{try{return n(...r)}catch(n){throw n instanceof y&&(e.isLazy===!0||!(n instanceof b))?Pr(t,n.message):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},Ir=(e,t)=>{if(typeof e!=`number`)throw Pr(t,`Cannot cast tlc2.value.impl.${Mr(e)} to tlc2.value.impl.IntValue`);return e},Lr=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,Rr=(e,t,n,r)=>{let i=Lr(e,n,`IntValue`,2);return Er(t,(e,n)=>{let a=Ir(e,i),o=Ir(n,i),s=r(a,o);if(Dr(s))throw Or(`${a}${t}${o}`);return s})},zr=(e,t,n)=>{if(typeof e!=`number`)throw new b(`The ${t} argument of ${n} should be an integer, but instead it is:\n${Y(e)}`);return e},Br=(e,t)=>Er(e,(n,r)=>t(zr(n,`first`,e),zr(r,`second`,e))),Vr=(e,t,n)=>({...Tr(e,t,n),isLazy:!0}),Hr=(e,t,n)=>{let r=Sr(e,t,n);return()=>r.call([])},Ur=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),Wr=()=>({bool:Lo,condition:(e,t)=>{if(typeof e!=`boolean`)throw wo(t,e);return e},conjunct:(e,t,n)=>{if(typeof e!=`boolean`)throw To(t,n,e);return e},apply:An,tuple:Ht,set:Dt,record:Qe,writtenRecord:L,equal:$e,enumerate:Ho,unassigned:(e,t)=>{throw Sc(e,t)},primeOutsideAction:e=>{throw Cc(e)},prime:e=>({environment:e.environment,scope:e.scope,state:e.next,next:void 0}),extend:(e,t,n)=>({environment:e.environment,scope:t.reduce((e,t,r)=>Po(e,t,n[r]),e.scope),state:e.state,next:e.next})}),Gr={value:void 0},Kr=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),qr=e=>`local${e.counter++}`,Jr=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),ur(e).forEach(e=>Jr(e,t)),t),Yr=(e,t,n)=>{let r=Kr(e,Ks(t,e.environment)),i=Jr(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=Kr(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},Xr=(e,t,n)=>{let r=t.kind===`Forall`,i=JSON.stringify(r?`the body of \\A`:`the body of \\E`),a=`quantifier${e.counter++}`,o=[...n.locals.values()],s={context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:new Map(n.locals)},c=t.bounds.map(()=>qr(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${Qr(e,t.set,s)}, ${Kr(e,t.set)});`),u=t.bounds.map(t=>{let n=qr(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${Qr(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=qr(e);return`for (let ${i} = 0; ${i} < ${c[r]}.length; ${i}++) { const ${n} = ${c[r]}[${i}]; ${t} }`},d),p=o.map(e=>`, ${e}`).join(``);return e.helpers.push(`function ${a}(context, state, next${p}) { let primed; ${l.join(` `)} ${f} return ${r}; }`),`${a}(${n.context}, ${n.state}, ${n.isPrimed?`undefined`:n.next}${p})`},Zr=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${Qr(e,r[0],n)}, "the left side of =>") ? bool(${Qr(e,r[1],n)}, "the right side of =>") : true)`;if(X(t))return Yr(e,t,n);let i=ns(t.operator,e.environment);if(i?.kind!==`Builtin`)return Yr(e,t,n);if(i.name===`DOMAIN`)return`${Kr(e,ko(t))}(${Qr(e,r[0],n)})`;if(i.name===`TLCEval`)return Yr(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${Kr(e,Ao(t,i))}(${Qr(e,r[0],n)}, ${Qr(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&ec(r[0],a))return`${Kr(e,i.evaluateUnary)}(${Qr(e,r[0],n)})`;let o=r.length===2&&ec(r[0],a)&&ec(r[1],a);return i.evaluateBinary&&o?`${Kr(e,i.evaluateBinary)}(${Qr(e,r[0],n)}, ${Qr(e,r[1],n)})`:Yr(e,t,n)},Qr=(e,t,n)=>{let r=(t,r=n)=>Qr(e,t,r);if(Ls(t)&&Ms(t,e.environment))return Yr(e,t,n);switch(t.kind){case`Number`:return bs(t.value)?String(t.value):Yr(e,t,n);case`String`:return JSON.stringify(t.value);case`Identifier`:{let r=n.locals.get(t.name);if(r)return r;if(X(t))return Yr(e,t,n);let i=fs(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=Kr(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?Kr(e,i.value):Yr(e,t,n)}case`Apply`:return Zr(e,t,n);case`And`:{let n=Kr(e,t);return`(${t.operands.map((e,t)=>`conjunct(${r(e)}, ${n}, ${t})`).join(` && `)})`}case`Or`:return`(${t.operands.map(e=>`bool(${r(e)}, "a disjunct")`).join(` || `)})`;case`If`:return`(condition(${r(t.condition)}, ${Kr(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{gc(t.function);let n=r(t.function),i=Kr(e,Do(t));return t.args.length===1?`apply(${n}, ${r(t.args[0])}, undefined, ${i})`:`apply(${n}, tuple([${t.args.map(e=>r(e)).join(`, `)}]), undefined, ${i})`}case`FieldAccess`:return`apply(${r(t.record)}, ${JSON.stringify(t.field)}, ${Kr(e,Eo(t))}, ${Kr(e,Oo(t))})`;case`Record`:{let i=bc(t.fields);if(xc(i))return Yr(e,t,n);let a=Kr(e,i.map(e=>e.name)),o=`[${i.map(e=>r(e.value)).join(`, `)}]`,s=t.fields.map(e=>e.name);return s.every((e,t)=>e===i[t].name)?`record(${a}, ${o})`:`writtenRecord(${a}, ${o}, ${Kr(e,s)})`}case`Tuple`:return`tuple([${t.elements.map(e=>r(e)).join(`, `)}])`;case`SetEnumeration`:return`set([${t.elements.map(e=>r(e)).join(`, `)}])`;case`Prime`:{let i=Kr(e,t);if(n.isPrimed)return`primeOutsideAction(${i})`;let a={context:`(primed ??= prime(${n.context}))`,state:n.next,next:`undefined`,isPrimed:!0,locals:n.locals};return`(${n.next} === undefined ? primeOutsideAction(${i}) : ${r(t.expression,a)})`}case`Unchanged`:return`equal(${r({kind:`Prime`,expression:t.expression,location:t.location})}, ${r(t.expression)})`;case`Forall`:case`Exists`:return t.bounds.every(e=>e.pattern.kind===`Name`)?Xr(e,t,n):Yr(e,t,n);default:return Yr(e,t,n)}},$r=(e,t)=>{if(!Ur.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=Qr(n,e,{context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:/* @__PURE__ */ new Map}),i=n.references.map((e,t)=>`reference${t}`),a=`${n.helpers.join(`
|
|
31
|
+
`)}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${r}; };`;Gr.value??=Wr();let o=Gr.value,s=Object.keys(o);return Function(...s,...i,a)(...Object.values(o),...n.references)},ei={kind:`Local`},ti=/* @__PURE__ */ new WeakMap,ni=e=>{let t=e.lastIndexOf(`@`);return t>0&&t<e.length-1},ri=new Map([`~>`,`-+->`,`\\cdot`].map(e=>[e,{key:e,arity:2}])),ii=(e,t)=>e.line<t.line||e.line===t.line&&e.column<t.column,ai=e=>e.kind===`Operator`?e.params.length:0,oi=e=>e.name.includes(`!`),si=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n},ci=(e,t,n=0)=>t.reduce((e,t)=>({name:t,arity:n,parent:e}),e),li=(e,t)=>t.reduce((e,t)=>({name:t.name,arity:t.arity,parent:e}),e),ui=e=>e.kind===`Name`?[e.name]:e.names,di=e=>e.flatMap(e=>ui(e.pattern)),fi=(e,t)=>{let n=t.definitions.get(e);return n!==void 0&&(n===t.self?n.kind===`Function`||n.isRecursive:n.isRecursive||ii(n.location,t.location))?n:void 0},pi=(e,t)=>{let n=fi(e,t);return n?{key:t.getKey(n),arity:ai(n)}:t.imported.get(e)},mi=(e,t)=>({module:e.range?.module??``,start:e,end:{line:e.line,column:e.column+t.length-1}}),hi=e=>{if(e.kind===`Apply`){if(e.args.length===2)return`infix`;if(e.args.length===1)return ii(e.location,e.args[0].location)?`prefix`:`postfix`}},gi=e=>e[0].toLowerCase()===e[0].toUpperCase()&&e[0]!==`_`&&(e[0]<`0`||e[0]>`9`),_i=e=>e.startsWith(`<`)&&(e[1]>=`0`&&e[1]<=`9`||e[1]===`*`),vi=(e,t,n,r)=>{let i=e.location,a=ti.get(e);if(a!==void 0)return a;if(ni(t))return e.kind===`Apply`?e.args.length:0;if(_i(t))return 0;let o=si(n,t);if(o&&e.kind!==`OperatorReference`&&(e.resolution=ei),o)return o.arity;let s=pi(t,r);if(s)return e.kind===`Identifier`?e.name=s.key:e.operator=s.key,ti.set(e,s.arity),s.arity;let c=t.includes(`!`)?t.slice(0,t.indexOf(`!`)):``;if(c!==``&&(si(n,c)!==void 0||pi(c,r)!==void 0||r.facts.has(c)))return e.kind===`Apply`?e.args.length:0;let l=mi(i,t===`-.`?`-`:t);if(!gi(t))throw _(`Unknown operator: \`${t}'.`,l);let u={location:g(l),message:`Could not find declaration or definition of symbol '${t}'.`},d=hi(e);throw m(d&&i.range?[u,{location:g(i.range),message:`Couldn't resolve ${d} operator symbol \`${t}'.`}]:[u])},yi=(e,t,n)=>(e.forEach(e=>Oi(e.set,t,n)),e.reduce((e,t)=>ci(e,ui(t.pattern)),t)),bi=(e,t)=>e.kind===`Identifier`&&e.name===t&&X(e)||ur(e).some(e=>bi(e,t)),xi=(e,t)=>{e.kind===`FunctionConstruction`&&bi(e.body,t)&&(e.isRecursive=!0),ur(e).forEach(e=>xi(e,t))},Si=(e,t,n)=>{let r=ci(t,e.kind===`Function`?[e.name]:[]);e.kind===`Function`?(Oi(e.body,yi(e.bounds,r,n),n),xi(e.body,e.name)):Oi(e.body,li(r,e.params),n)},Ci=(e,t,n)=>{let r=e.filter(e=>e.isRecursive).reduce((e,t)=>({name:t.name,arity:ai(t),parent:e}),t);return e.reduce((e,t)=>(oi(t)||Si(t,e,n),{name:t.name,arity:ai(t),parent:e}),r)},wi=(e,t,n,r,i)=>{let a=e.kind===`Operator`?e.params[t]:void 0,o=n.location;if(a?.arity===0&&r>0)throw new p(`Operator used in argument number ${t+1} has incorrect number of arguments at line ${o.line}, column ${o.column}`);let s=i?.kind===`Operator`&&i.params.some(e=>e.arity>0);if(a!==void 0&&a.arity>0&&(r!==a.arity||s))throw new p(`Argument number ${t+1} to operator '${e.name}' should be a ${a.arity}-parameter operator at line ${o.line}, column ${o.column}`)},Ti=e=>e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:void 0,Ei=(e,t,n)=>{let r=e.operator,i=si(t,r)?void 0:fi(r,n),a=vi(e,r,t,n);if(a!==e.args.length)throw _(`The operator ${r} requires ${a} arguments.`,e.argumentsRange??mi(e.location,r));e.args.forEach((e,r)=>{let a=Ti(e),o=a===void 0||si(t,a)?void 0:fi(a,n),s=Di(e,t,n);i&&wi(i,r,e,s,o)})},Di=(e,t,n)=>e.kind===`Identifier`?vi(e,e.name,t,n):e.kind===`OperatorReference`?vi(e,e.operator,t,n):(Oi(e,t,n),e.kind===`Lambda`?e.params.length:0),Oi=(e,t,n)=>{let r=e=>e.forEach(e=>Oi(e,t,n));switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return;case`Identifier`:{let r=e.name,i=vi(e,r,t,n);if(i>0)throw _(`The operator ${r} requires ${i} arguments.`,mi(e.location,r));return}case`OperatorReference`:vi(e,e.operator,t,n);return;case`Apply`:Ei(e,t,n);return;case`Lambda`:Oi(e.body,ci(t,e.params),n);return;case`And`:case`Or`:r(e.operands);return;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:Oi(e.expression,t,n);return;case`If`:r([e.condition,e.consequent,e.alternative]);return;case`Case`:r(e.arms.flatMap(e=>[e.condition,e.body])),e.other&&Oi(e.other,t,n);return;case`Let`:Oi(e.body,Ci(e.definitions,t,n),n);return;case`Forall`:case`Exists`:case`FunctionConstruction`:Oi(e.body,yi(e.bounds,t,n),n);return;case`UnboundedQuantifier`:Oi(e.body,ci(t,e.names),n);return;case`Choose`:e.set&&Oi(e.set,t,n),Oi(e.body,ci(t,ui(e.pattern)),n);return;case`SetEnumeration`:case`Tuple`:r(e.elements);return;case`SetFilter`:Oi(e.predicate,yi([e.bound],t,n),n);return;case`SetMap`:Oi(e.expression,yi(e.bounds,t,n),n);return;case`FunctionSet`:r([e.domain,e.range]);return;case`Record`:case`RecordSet`:{let t=e.fields.filter((t,n)=>e.fields.slice(0,n).some(e=>e.name===t.name));if(t.length>0)throw m(t.map(e=>({location:g(e.location.range??mi(e.location,e.name)),message:`Non-unique fields in constructor.`})));r(e.fields.map(e=>e.value));return}case`Except`:r([e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])]);return;case`FunctionApplication`:r([e.function,...e.args]);return;case`FieldAccess`:Oi(e.record,t,n);return;case`Product`:r(e.factors);return;case`BoxAction`:case`AngleAction`:r([e.action,e.subscript]);return;case`WeakFairness`:case`StrongFairness`:r([e.subscript,e.action]);return;case`Label`:Oi(e.body,t,n);return;case`Subexpression`:e.selectors.flatMap(e=>`args`in e?e.args:[]).forEach(e=>Di(e,t,n))}},ki=(e,t,n)=>(e.set&&Oi(e.set,t,n),{name:e.name,arity:e.arity,parent:t}),Ai=(e,t,n)=>{let r=e.assumptions.reduce((e,t)=>t.kind===`NewSymbol`?ki(t,e,n):(t.kind===`AssumeProve`?Ai(t,e,n):Oi(t,e,n),e),t);return Oi(e.conclusion,r,n),r},ji=(e,t,n)=>e.kind===`AssumeProve`?Ai(e,t,n):(Oi(e,t,n),t),Mi=(e,t,n)=>{e?.kind===`Steps`&&e.steps.reduce((e,t)=>Ni(t,e,n),t)},Ni=(e,t,n)=>{let r=e.body;switch(r.kind){case`Assert`:{let i=ji(r.statement,t,n);return Mi(e.proof,i,n),r.isSuffices?i:t}case`Define`:return Ci(r.definitions.flatMap(e=>e.kind===`Instance`?[]:[e]),t,n);case`Have`:case`Case`:return Oi(r.expression,t,n),Mi(e.proof,t,n),t;case`Witness`:return r.expressions.forEach(e=>Oi(e,t,n)),t;case`Take`:return ci(yi(r.bounds,t,n),r.names);case`Pick`:{let i=ci(yi(r.bounds,t,n),r.names);return Oi(r.body,i,n),Mi(e.proof,t,n),i}default:return Mi(e.proof,t,n),t}},Pi=(e,t)=>{let n=e.name!==void 0&&e.statement.kind!==`AssumeProve`?void 0:ji(e.statement,void 0,t);Mi(e.proof,n,t)},Fi=(e,t)=>new p(`Multiply-defined symbol '${e}' at line ${t.line}, column ${t.column}`),Ii=(e,t,n,r)=>t.reduce((e,t)=>{if(si(e,t)||n(t))throw Fi(t,r);return{name:t,arity:0,parent:e}},e),Li=(e,t,n,r)=>(e.forEach(e=>zi(e.set,t,n)),e.reduce((e,t)=>Ii(e,ui(t.pattern),n,r),t)),Ri=(e,t,n)=>{if(e.kind===`Function`){let r=ci(t,[e.name]),i=Li(e.bounds,r,n,e.location);zi(e.body,i,n);return}let r=Ii(t,e.params.map(e=>e.name),n,e.location);zi(e.body,r,n)},zi=(e,t,n)=>{let r=e.location;switch(e.kind){case`Lambda`:zi(e.body,Ii(t,e.params,n,r),n);return;case`Let`:{let i=e.definitions.filter(e=>e.isRecursive).map(e=>e.name),a=e.definitions.reduce((e,t)=>{if(si(e,t.name)||n(t.name))throw Fi(t.name,t.location);return Ri(t,ci(e,i),n),ci(e,[t.name])},t);zi(e.body,Ii(a,(e.instances??[]).flatMap(e=>e.name===void 0?[]:[e.name]),n,r),n);return}case`Forall`:case`Exists`:case`FunctionConstruction`:zi(e.body,Li(e.bounds,t,n,r),n);return;case`SetFilter`:zi(e.predicate,Li([e.bound],t,n,r),n);return;case`SetMap`:zi(e.expression,Li(e.bounds,t,n,r),n);return;case`UnboundedQuantifier`:zi(e.body,Ii(t,e.names,n,r),n);return;case`Choose`:e.set&&zi(e.set,t,n),zi(e.body,Ii(t,ui(e.pattern),n,r),n);return;default:ur(e).forEach(e=>zi(e,t,n))}},Bi=e=>[...e.definitions.map(e=>({name:e.name,kind:`Definition`,location:e.location,isRecursive:e.isRecursive})),...e.instances.flatMap(e=>e.name===void 0?[]:[{name:e.name,kind:`Definition`,location:e.location,isRecursive:!1}]),...e.constants.map(e=>({name:e.name,kind:`Constant`,location:e.location,isRecursive:!1})),...e.variables.map(e=>({name:e.name,kind:`Variable`,location:e.location,isRecursive:!1}))],Vi=(e,t)=>{let n=/* @__PURE__ */ new Map;Bi(e).sort((e,t)=>ii(e.location,t.location)?-1:1).forEach(e=>n.set(e.name,[...n.get(e.name)??[],e]));let r=(e,n)=>{if(!t.imported.has(e)&&!ri.has(e))return!1;let r=t.importedAt.get(e);return r===void 0||ii(r,n)};n.forEach(e=>e.forEach((n,i)=>{let a=e.slice(0,i).some(e=>e.kind===`Definition`||n.kind===`Definition`||e.kind!==n.kind),o=t.imported.get(n.name)?.declaration===n.kind;if(a||!o&&r(n.name,n.location))throw Fi(n.name,n.location)}));let i=e=>t=>(n.get(t)??[]).some(t=>t.isRecursive||ii(t.location,e))||r(t,e);e.definitions.forEach(e=>Ri(e,void 0,i(e.location))),e.assumptions.forEach(e=>zi(e.expression,void 0,i(e.location))),e.instances.forEach(e=>{let t=i(e.location),n=Ii(void 0,e.params.map(e=>e.name),t,e.location);e.substitutions.forEach(e=>zi(e.expression,n,t))})},Hi=(e,t)=>{let n=new Map([...ri,...t]);return e.constants.forEach(e=>n.set(e.name,{key:e.name,arity:e.arity})),e.variables.forEach(e=>n.set(e.name,{key:e.name,arity:0})),n},Ui=(e,t,n,r)=>{let i=li(void 0,e.params),a={imported:Hi(n,r.imported),definitions:r.definitions,getKey:r.getKey,location:e.location,self:void 0,facts:/* @__PURE__ */ new Set},o=new Map(e.substitutions.map(e=>[e.name,e.expression])),s=`in the instance of ${e.module} at line ${e.location.line}, column ${e.location.column}`;return o.forEach((e,n)=>{if(t.every(e=>e.name!==n))throw new p(`Identifier '${n}' is not a legal target of a substitution ${s}`)}),new Map(t.map(t=>{let n=t.name;if(!o.has(n)&&!si(i,n)&&!pi(n,a))throw new p(`Substitution missing for symbol ${n} ${s}`);let r=o.get(n)??{kind:`Identifier`,name:n,location:e.location};if(t.arity===0||r.kind!==`Identifier`)return Oi(r,i,a),[n,r];if(vi(r,r.name,i,a)!==t.arity)throw new p(`An operator must be substituted for symbol '${n}', and it must have arity ${t.arity} ${s}`);return[n,r]}))},Wi=e=>{let t=[];if(e.toSorted((e,t)=>ii(e.location,t.location)?-1:1).forEach(e=>{try{e.check()}catch(e){if(!(e instanceof p)||!e.sany)throw e;e.sany.errors.forEach(e=>{t.every(t=>t.location!==e.location||t.message!==e.message)&&t.push(e)})}}),t.length>0)throw m(t)},Gi=(e,t)=>{let n=Hi(e,t.imported),r=new Set([...e.theorems,...e.assumptions].flatMap(e=>e.name??[])),i=(e,i)=>({imported:n,definitions:t.definitions,getKey:t.getKey,location:e,self:i,facts:r});Wi([...e.definitions.map(e=>({location:e.location,check:()=>Si(e,void 0,i(e.location,e))})),...e.assumptions.map(e=>({location:e.location,check:()=>Oi(e.expression,void 0,i(e.location,void 0))})),...e.theorems.map(e=>({location:e.location,check:()=>Pi(e,i(e.location,void 0))}))])},Ki=/* @__PURE__ */ new WeakSet,qi=/* @__PURE__ */ new WeakSet,Ji=(e,t,n=/* @__PURE__ */ new Set)=>{let r=ea(e,(e,r)=>Ji(e,t,r.length===0?n:/* @__PURE__ */ new Set([...n,...r])));return r.kind===`Identifier`&&X(r)&&!n.has(r.name)?{...r,name:t.get(r.name)??r.name}:r.kind===`Apply`&&X(r)&&!n.has(r.operator)?{...r,operator:t.get(r.operator)??r.operator}:r},Yi=(e,t)=>e.map(e=>({pattern:e.pattern,set:t(e.set)})),Xi=/* @__PURE__ */ new WeakMap,Zi=e=>Xi.get(e)??e.name,Qi=(e,t)=>(Zi(t)!==e.name&&Xi.set(e,Zi(t)),e),$i=(e,t)=>Qi(e.kind===`Function`?{...e,bounds:Yi(e.bounds,e=>t(e,[])),body:t(e.body,di(e.bounds))}:{...e,body:t(e.body,e.params.map(e=>e.name))},e),ea=(e,t)=>{let n=e=>t(e,[]);switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return e;case`Apply`:return{...e,args:e.args.map(n)};case`Lambda`:return{...e,body:t(e.body,e.params)};case`And`:case`Or`:return{...e,operands:e.operands.map(n)};case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return{...e,expression:n(e.expression)};case`If`:return{...e,condition:n(e.condition),consequent:n(e.consequent),alternative:n(e.alternative)};case`Case`:return{...e,arms:e.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:e.other?n(e.other):void 0};case`Let`:{let n=e.definitions.map(e=>e.name);return{...e,definitions:e.definitions.map(e=>$i(e,(e,r)=>t(e,[...n,...r]))),body:t(e.body,n)}}case`Forall`:case`Exists`:case`FunctionConstruction`:return{...e,bounds:Yi(e.bounds,n),body:t(e.body,di(e.bounds))};case`UnboundedQuantifier`:return{...e,body:t(e.body,e.names)};case`Choose`:return{...e,set:e.set?n(e.set):void 0,body:t(e.body,ui(e.pattern))};case`SetEnumeration`:case`Tuple`:return{...e,elements:e.elements.map(n)};case`SetFilter`:return{...e,bound:{pattern:e.bound.pattern,set:n(e.bound.set)},predicate:t(e.predicate,ui(e.bound.pattern))};case`SetMap`:return{...e,bounds:Yi(e.bounds,n),expression:t(e.expression,di(e.bounds))};case`FunctionSet`:return{...e,domain:n(e.domain),range:n(e.range)};case`Record`:case`RecordSet`:return{...e,fields:e.fields.map(e=>({...e,value:n(e.value)}))};case`Except`:return{...e,function:n(e.function),updates:e.updates.map(e=>({path:e.path.map(e=>e.kind===`Index`?{kind:`Index`,args:e.args.map(n)}:e),value:n(e.value)}))};case`FunctionApplication`:return{...e,function:n(e.function),args:e.args.map(n)};case`FieldAccess`:return{...e,record:n(e.record)};case`Product`:return{...e,factors:e.factors.map(n)};case`BoxAction`:case`AngleAction`:return{...e,action:n(e.action),subscript:n(e.subscript)};case`WeakFairness`:case`StrongFairness`:return{...e,subscript:n(e.subscript),action:n(e.action)};case`Label`:return{...e,body:n(e.body)};case`Subexpression`:return{...e,selectors:e.selectors.map(e=>`args`in e?{...e,args:e.args.map(n)}:e)}}},ta=`LAMBDA`,na=(e,t=/* @__PURE__ */ new Set)=>{let n=e.kind===`Identifier`?e.name:e.kind===`Apply`||e.kind===`OperatorReference`?e.operator:void 0,r=n===void 0||t.has(n)?[]:[n];return ea(e,(e,n)=>(r.push(...na(e,n.length===0?t:/* @__PURE__ */ new Set([...t,...n]))),e)),r},ra=e=>{let t=/* @__PURE__ */ new Map;return n=>{if(!e.substitutedNames.has(n))return n;let r=t.get(n)??e.instantiation.createName(n);return t.set(n,r),r}},ia=(e,t,n)=>new Map([...e,...t.map(e=>[e,n(e)])]),aa=(e,t)=>e.kind===`Name`?{kind:`Name`,name:t(e.name)}:{kind:`Tuple`,names:e.names.map(t)},oa=(e,t)=>e.map(e=>({pattern:aa(e.pattern,t),set:e.set})),sa=(e,t)=>e.kind===`Function`?{...e,bounds:oa(e.bounds,t)}:{...e,params:e.params.map(e=>({name:t(e.name),arity:e.arity}))},ca=(e,t,n)=>{let r=e=>t.get(e)??e;switch(e.kind){case`Identifier`:return{...e,name:r(e.name)};case`Apply`:case`OperatorReference`:return{...e,operator:r(e.operator)};case`Label`:return{...e,params:e.params.map(r)};case`Lambda`:return{...e,params:e.params.map(n)};case`Let`:return{...e,definitions:e.definitions.map(e=>Qi({...sa(e,n),name:n(e.name)},e))};case`Forall`:case`Exists`:case`FunctionConstruction`:case`SetMap`:return{...e,bounds:oa(e.bounds,n)};case`UnboundedQuantifier`:return{...e,names:e.names.map(n)};case`Choose`:return{...e,pattern:aa(e.pattern,n)};case`SetFilter`:return{...e,bound:{pattern:aa(e.bound.pattern,n),set:e.bound.set}};default:return e}},la=e=>`${e}@ENABLED`,ua=(e,t)=>e.modes.get(t)??e,da=(e,t,n)=>e.kind===`Identifier`&&!n.has(e.name)&&!X(e)&&t.instantiation.variables.has(e.name),fa=(e,t,n)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>fa(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`)return;if(da(e,t,n))return[e.name];let r=X(e)?void 0:t.instantiation.getDefinition(e.name);return r?.kind===`Operator`&&r.params.length===0?fa(r.body,t,/* @__PURE__ */ new Map):void 0},pa=(e,t,n)=>{if(t.mode===`Normal`)return;if(t.mode===`Primed`)return da(e,t,n)&&e.kind===`Identifier`?{kind:`Identifier`,name:la(e.name),location:e.location}:void 0;if(e.kind===`Prime`)return{...e,expression:va(e.expression,ua(t,`Primed`),n)};if(e.kind===`AngleAction`){let r=e.location;return{kind:`And`,operands:[va(e.action,t,n),{kind:`Apply`,operator:`#`,args:[{kind:`Prime`,expression:va(e.subscript,ua(t,`Primed`),n),location:r},va(e.subscript,t,n)],location:r}],location:r}}if(e.kind!==`Unchanged`)return;let r=fa(e.expression,t,n);if(r!==void 0)return{kind:`And`,operands:r.map(r=>({kind:`Apply`,operator:`=`,args:[{kind:`Prime`,expression:{kind:`Identifier`,name:la(r),location:e.location},location:e.location},va({kind:`Identifier`,name:r,location:e.location},t,n)],location:e.location})),location:e.location}},ma=(e,t)=>({kind:`Identifier`,name:e,location:t,resolution:{kind:`Local`}}),ha=(e,t)=>e.map(e=>ma(e.name,t)),ga=(e,t,n,r)=>{let i=Array.from({length:n},(e,t)=>`argument${t}`);return{kind:`Lambda`,params:i,body:{kind:`Apply`,operator:e,args:[...ha(t,r),...i.map(e=>ma(e,r))],location:r},location:r}},_a=(e,t)=>e.instantiation.isParameterized(t)?ba(e,t):void 0,va=(e,t,n)=>{let r=e=>va(e,t,n),i=t.instantiation,a=i.params,o=t=>!n.has(t)&&!X(e);if(e.kind===`Enabled`&&t.mode===`Normal`)return{...e,expression:va(e.expression,ua(t,`Enabled`),n)};if((e.kind===`WeakFairness`||e.kind===`StrongFairness`)&&t.mode===`Normal`)return{...e,subscript:r(e.subscript),action:r(e.action),enabled:va(e.enabled??{kind:`AngleAction`,action:e.action,subscript:e.subscript,location:e.location},ua(t,`Enabled`),n)};let s=pa(e,t,n);if(s)return s;if(e.kind===`Identifier`&&o(e.name)){let n=i.substitutions.get(e.name);if(n)return Ki.add(n),n;let r=_a(t,e.name);if(r===void 0)return e;if(a.length===0)return{...e,name:r};let o=i.getDefinition(e.name);return o&&ai(o)>0?ga(r,a,ai(o),e.location):{kind:`Apply`,operator:r,args:ha(a,e.location),location:e.location}}if(e.kind===`Apply`&&o(e.operator)){let n=e.args.map(r),o=i.substitutions.get(e.operator),s=i.substitutions.size>0||a.length>0||qi.has(e),c=e=>(s&&qi.add(e),e);if(o?.kind===`Identifier`||o?.kind===`OperatorReference`){let t=o.kind===`Identifier`?o.name:o.operator;return c({...e,operator:t,args:n,resolution:o.kind===`Identifier`?o.resolution:void 0})}if(o?.kind===`Apply`)return c({...e,operator:o.operator,args:[...o.args,...n],resolution:o.resolution});if(o?.kind===`Lambda`)return{kind:`Let`,definitions:[{kind:`Operator`,name:ta,params:o.params.map(e=>({name:e,arity:0})),body:o.body,isLocal:!0,isRecursive:!1,location:o.location}],body:{...e,operator:ta,args:n,resolution:{kind:`Local`}},location:e.location};if(o)throw new p(`The operator ${e.operator} can only be substituted by an operator at line ${e.location.line}, column ${e.location.column}`);let l=_a(t,e.operator);return l===void 0?c({...e,args:n}):{...e,operator:l,args:[...ha(a,e.location),...n]}}if(e.kind===`OperatorReference`&&o(e.operator)){let n=_a(t,e.operator);if(n===void 0)return e;let r=i.getDefinition(e.operator);return a.length>0&&r?ga(n,a,ai(r),e.location):{...e,operator:n}}let c=ra(t),l=ea(e,(e,i)=>i.length===0?r(e):va(e,t,ia(n,i,c)));return ca(l,n,c)},ya=(e,t,n)=>t.length===0?e:e.kind===`Operator`?{...e,params:[...t,...e.params]}:{kind:`Operator`,name:e.name,params:t,body:{kind:`Let`,definitions:[e],body:ma(e.name,n),location:n},isLocal:e.isLocal,isRecursive:!1,location:e.location},ba=(e,t)=>{let n=e.copies.get(t);if(n!==void 0)return n;let r=e.instantiation,i=r.getDefinition(t);return i?r.addDefinition(t,i.name,n=>{e.copies.set(t,n);let a=ra(e),o=sa($i(i,(t,n)=>va(t,e,ia(/* @__PURE__ */ new Map,n,a))),a);return ya(o,r.params,i.location)}):t},xa=e=>{let t=/* @__PURE__ */ new Map,n=new Set([...e.substitutions.values()].flatMap(e=>na(e))),r=r=>{let i={instantiation:e,substitutedNames:n,copies:/* @__PURE__ */ new Map,mode:r,modes:t};return t.set(r,i),i},i=r(`Normal`);return r(`Enabled`),r(`Primed`),{getKey:e=>_a(i,e)??e,getQualifiedKey:t=>{let n=_a(i,t);if(n!==void 0)return n;let r=e.getDefinition(t);return r?e.addDefinition(t,r.name,()=>ya(r,e.params,r.location)):t}}},Sa=e=>e.kind===`Let`&&e.instances!==void 0||ur(e).some(Sa),Ca=(e,t,n)=>{let r=e.kind===`Let`?[...n,...e.definitions]:n,i=ea(e,e=>Ca(e,t,r));return i.kind!==`Let`||!i.instances?i:{kind:`Let`,definitions:i.instances.reduce((e,n)=>{let i=e.findIndex(e=>ii(n.location,e.location)),a=i===-1?e.length:i;return[...e.slice(0,a),...t(n,r),...e.slice(a)]},i.definitions),body:i.body,location:i.location}},wa=e=>e.name===void 0&&e.statement.kind!==`AssumeProve`?e.statement:void 0,Ta=(e,t)=>e.definitions.some(e=>Sa(e.body))||e.assumptions.some(e=>Sa(e.expression))||e.theorems.some(e=>{let t=wa(e);return t!==void 0&&Sa(t)})?{...e,definitions:e.definitions.map(e=>$i(e,e=>Ca(e,t,[]))),assumptions:e.assumptions.map(e=>({...e,expression:Ca(e.expression,t,[])})),theorems:e.theorems.map(e=>{let n=wa(e);return n===void 0?e:{...e,statement:Ca(n,t,[])}})}:e,Ea=/* @__PURE__ */ new WeakMap,Da=/* @__PURE__ */ new WeakMap,Oa=(e,t,n)=>e.isInit?{environment:e.environment,scope:t,state:n,next:void 0}:{environment:e.environment,scope:t,state:e.current,next:n},ka=(e,t,n)=>{let r=e.slice();return r[t]=n,r},Aa=(e,t,n)=>{if(typeof t==`boolean`)return t;throw new y(`In computing ${n?`initial`:`next`} states, TLC expected a boolean expression,\nbut instead found ${Y(t)}.\n${Co(e)}`)},ja=(t,r,i=Ys(t,r))=>{if(r.next!==void 0&&t.kind===`Number`)throw n(new y(`The next state relation is not a boolean expression.\n${t.text??t.value}`),e.error);return Aa(t,i,r.next===void 0)},Ma=e=>e===`=`||e===`\\in`||e===`\\subseteq`,Na=/* @__PURE__ */ new WeakMap,Pa=(e,t)=>{if(!e.trace)return t?Ea:Da;let n=Na.get(e)??[/* @__PURE__ */ new WeakMap,/* @__PURE__ */ new WeakMap];return Na.set(e,n),n[+!t]},Fa=(e,t,n)=>{let r=Pa(t,n),i=r.get(e);if(i)return i;let a=fo(e,t,n),o=t.trace,s=o?(t,n,r,i,s,c)=>{let l=o.length;o.push(e),a(t,n,r,i,s,c),o.length=l}:a;return r.set(e,s),s},Ia=(e,t)=>{if(t.constants.has(e))return;let n=Ro(e,t);return n?.kind===`Operator`&&n.params.length===0?n:void 0},La=(e,t,n,r=/* @__PURE__ */ new Set)=>{if(e.kind===`Prime`&&n)return La(e.expression,t,!1,r);if(e.kind!==`Identifier`||X(e))return;let i=t.variableIndex.get(e.name);if(i!==void 0)return n?void 0:i;let a=Ia(e.name,t);if(a&&!r.has(a))return r.add(a),La(a.body,t,n,r)},Ra=(e,t,n)=>La(e,t,!n),za=(e,t,n,r,i)=>{if(e.kind===`Prime`&&i)return za(e.expression,t,n,r,!1);if(e.kind===`Let`){let a=vs(e.definitions,Oa(r,t,n));return za(e.body,a,n,r,i)}if(e.kind!==`Identifier`)return;let a=No(t,e.name);if(a?.kind===`Thunk`)return za(a.expression,a.scope,n,r,i);if(a)return;let o=r.environment.variableIndex.get(e.name);if(o!==void 0)return i?void 0:o;let s=Ia(e.name,r.environment);if(s)return za(s.body,void 0,n,r,i)},Ba=(e,t)=>e.kind===`Let`||e.kind===`Identifier`&&(t||X(e))||!t&&e.kind===`Prime`,Va=(e,t,n=/* @__PURE__ */ new Set)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>Va(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`||n.has(e.name))return;let r=t.variableIndex.get(e.name);if(r!==void 0)return[r];let i=Ia(e.name,t);if(i)return n.add(e.name),Va(i.body,t,n)},Ha=(e,t)=>{if(e.kind===`Tuple`)return[e,...e.elements.flatMap(e=>Ha(e,t))];let n=e.kind===`Identifier`&&!t.variableIndex.has(e.name)?Ia(e.name,t):void 0;return n?[e,...Ha(n.body,t)]:[e]},Ua=/* @__PURE__ */ new Set([`Label`,`And`,`Or`,`Exists`,`Forall`,`If`,`Case`,`Let`,`Unchanged`,`BoxAction`,`AngleAction`,`FunctionApplication`]),Wa=(e,t,n)=>Ua.has(e.kind)?!1:e.kind===`Identifier`?t.variableIndex.has(e.name)||t.constants.has(e.name):e.kind===`Apply`?e.operator===`=>`||Ma(e.operator)&&(Ba(e.args[0],n)||Ra(e.args[0],t,n)!==void 0)||X(e)?!1:t.definitions.get(t.substitutions.get(e.operator)??e.operator)===void 0&&t.builtins.has(e.operator):!0,Ga=/* @__PURE__ */ new Set,Ka=(e,t)=>{if(X(e))return e.kind===`Identifier`?t.has(e.name)?[]:[e.name]:void 0;let n=[],r={isReadOnly:!0};return ea(e,(e,i)=>{let a=r.isReadOnly?Ka(e,i.length===0?t:/* @__PURE__ */ new Set([...t,...i])):[];return a?n.push(...a):r.isReadOnly=!1,e}),r.isReadOnly?n:void 0},qa=(e,t,n)=>{if(e.kind===`Or`||e.kind===`Exists`)return!0;let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,i=r===void 0||X(e)?void 0:Ro(r,t);return i&&!n.has(i)&&(n.add(i),qa(i.body,t,n))?!0:ur(e).some(e=>qa(e,t,n))},Ja=(e,t,n)=>{if(e.kind===`Apply`&&e.operator===`=`){let r=Ra(e.args[0],t,n);if(r!==void 0)return{kind:`Assign`,expression:e,index:r,value:e.args[1]}}if(!n&&e.kind===`Unchanged`){let n=Va(e.expression,t);if(n)return{kind:`Unchanged`,expression:e,indices:n}}return Wa(e,t,n)?{kind:`Guard`,expression:e}:{kind:`Branch`,expression:e,runner:Fa(e,t,n)}},Ya=(e,t)=>{if(e.bounds.length<2||e.body.kind!==`And`)return;let n=e.bounds.flatMap(e=>e.pattern.kind===`Name`?[e.pattern.name]:[]);if(n.length!==e.bounds.length)return;let r=new Set(n.slice(0,-1)),i=e.body.operands,a=i.findIndex(e=>{if(Oc(e,t)===void 0||qa(e,t,/* @__PURE__ */ new Set))return!0;let n=Ka(e,Ga);return!n||n.some(e=>r.has(e))}),o=a===-1?i.length:a;if(o!==0)return{names:n,guards:i.slice(0,o),rest:i.slice(o)}},Xa=(e,t,n)=>{let r=e.map(e=>Ja(e,t,n)),i=r.map(()=>void 0),a=t.trace,o=(e,n,s,c,l,u)=>{let d=c,f;for(let c=e;c<r.length;c++){if(c>0&&n.isInit&&go(d)){f??=Oa(n,s,d);for(let e=c;e<r.length;e++)if(!Za(r[e].expression,f))return;u(d,l);return}let e=r[c];if(a&&(a.push(e.expression),e.expression.kind===`Unchanged`&&a.push(...Ha(e.expression.expression,t))),e.kind===`Guard`){f??=Oa(n,s,d);let r=i[c]??=Js(e.expression,t);if(!ja(e.expression,f,r(f)))return;continue}if(e.kind===`Assign`){f??=Oa(n,s,d);let r=(i[c]??=Js(e.value,t))(f),a=d[e.index];if(a===void 0)d=ka(d,e.index,r),f=void 0;else if(!$e(a,r))return;continue}if(e.kind===`Unchanged`){let t=n.current;if(!t)return;for(let n of e.indices){let e=d[n];if(e===void 0)d=ka(d,n,t[n]),f=void 0;else if(!$e(e,t[n]))return}continue}let p=c+1;e.runner(n,s,d,l,!0,(e,t)=>o(p,n,s,e,t,u));return}u(d,l)};return(e,t,n,r,i,a)=>o(0,e,t,n,r,a)},Za=(e,t)=>Aa(e,Ys(e,t),!0),Qa=e=>(t,n,r,i,a,o)=>{ja(e,Oa(t,n,r))&&o(r,i)},$a=(e,t)=>{let n=e.args[1];return(r,i,a,o,s,c)=>{let l=t(r,i,a),u=Oa(r,i,a);if(a[l]!==void 0){ja(e,u)&&c(a,o);return}let d=Ys(n,u),f=e.operator===`\\subseteq`?{kind:`Subset`,base:d}:d;if(!Jt(f))throw new y(`In computing ${r.isInit?`initial`:`next`} states, the right side of \\IN is not enumerable.\n${Co(e)}`);let p=on(f);for(let e=0;e<p.length&&!r.isStopped;e++)c(ka(a,l,p[e]),o)}},eo=/* @__PURE__ */ new WeakMap,to=e=>{let t=eo.get(e);if(t)return t;let n=e.kind===`Tuple`?{kind:`And`,operands:e.elements.map(to),location:e.location}:{kind:`Unchanged`,expression:e,location:e.location};return eo.set(e,n),n},no=(e,t)=>{let n=e.args[0],r=Qa(e),i=(e,r,i)=>za(n,r,i,e,!t)??-1,a=$a(e,i);return(t,n,o,s,c,l)=>{let u=i(t,n,o);if(u===-1||o[u]!==void 0){r(t,n,o,s,c,l);return}if(e.operator!==`=`){a(t,n,o,s,c,l);return}let d=Ys(e.args[1],Oa(t,n,o));l(ka(o,u,d),s)}},ro=(e,t,n,r)=>{if(e.kind===`FunctionConstruction`)return{bounds:e.bounds,body:e.body,scope:t};if(e.kind!==`Identifier`)return;let i=No(t,e.name);if(i?.kind===`Thunk`)return ro(i.expression,i.scope,n,r);let a=i?void 0:Ro(e.name,r.environment);if(a?.kind!==`Function`)return;let o=Ys(e,Oa(r,void 0,n));return{bounds:a.bounds,body:a.body,scope:Po(void 0,a.name,o)}},io=(e,t,n)=>{let r=Qa(e);return(i,a,o,s,c,l)=>{let u=ro(e.function,a,o,i);if(!u){r(i,a,o,s,c,l);return}let d=Oa(i,a,o),f=e.args.map(e=>Ys(e,d)),p=f.length===1?f[0]:Ht(f),m=Wo(u.bounds,Oa(i,u.scope,o));if(!vn(p,m))throw new y(`Attempted to apply a function to ${Y(p)}, which is not in its domain at ${So(e)}`);Fa(u.body,t,n)(i,Go(u.bounds,u.scope,p),o,s,c,l)}},ao=(e,t)=>{if(Va(e,t))return Xa([to(e)],t,!1);if(e.kind===`Tuple`)return Fa(to(e),t,!1);let n=to(e);return(r,i,a,o,s,c)=>{let l=e.kind===`Identifier`?No(i,e.name):void 0;l?.kind===`Thunk`?Fa(to(l.expression),t,!1)(r,l.scope,a,o,s,c):ja(n,Oa(r,i,a))&&c(a,o)}},oo=(e,t,n)=>{let r=e.operator,i=Qa(e),a=X(e)?void 0:ns(r,t);if(a?.kind===`Builtin`)return i;if(a?.kind===`Closure`){let i=ac(a,e.args,t),o={body:void 0};return(e,s,c,l,u,d)=>{o.body??=Fa(a.body,t,n),o.body(e,i(Oa(e,s,c)),c,u?l:r,u,d)}}return(a,o,s,c,l,u)=>{let d=Oa(a,o,s),f=is(e,d);f?.kind===`Closure`?Fa(f.body,t,n)(a,gs(f,e.args,d),s,l?c:r,l,u):i(a,o,s,c,l,u)}},so=(e,t,n)=>{let r=Qa(e),i=X(e)?void 0:Ia(e.name,t),a={body:void 0};return(o,s,c,l,u,d)=>{let f=No(s,e.name);f?.kind===`Thunk`?Fa(f.expression,t,n)(o,f.scope,c,l,u,d):f||!i?r(o,s,c,l,u,d):(a.body??=Fa(i.body,t,n),a.body(o,void 0,c,u?l:i.name,u,d))}},co=(e,t,n)=>{if(n.has(e))return;if(n.add(e),e.kind===`And`){let n=e.operands[0];if(n.kind!==`Apply`||n.operator!==`=`||X(n))return;let r=n.args[0],i=n.args[1];if(r.kind!==`FunctionApplication`||i.kind!==`String`)return;let a=r.args.length===1?r.args[0]:void 0;if(a?.kind!==`Identifier`||!X(a))return;let o=La(r.function,t,!1);return o===void 0?void 0:{variable:o,argument:a.name,labels:/* @__PURE__ */ new Set([i.value])}}if(e.kind===`Or`){let r=e.operands.map(e=>co(e,t,n)),i=r[0],a=r.every(e=>e!==void 0&&e.variable===i?.variable&&e.argument===i.argument);if(!i||!a)return;let o=new Set(r.flatMap(e=>[...e?.labels??[]]));return{variable:i.variable,argument:i.argument,labels:o}}if(e.kind!==`Apply`||X(e))return;let r=ns(e.operator,t);if(r?.kind!==`Closure`||r.scope!==void 0)return;let i=co(r.body,t,n),a=r.params.findIndex(e=>e.arity===0&&e.name===i?.argument),o=e.args[a];if(i&&o?.kind===`Identifier`&&X(o))return{variable:i.variable,argument:o.name,labels:i.labels}},lo=(e,t,n)=>{let r=No(t,n.argument),i=e.current?.[n.variable];if(r?.kind!==`Value`||typeof i!=`object`||i.kind!==`Function`)return;let a=i.domain.indexOf(r.value),o=a===-1?void 0:i.range[a];return typeof o==`string`?o:void 0},uo=(e,t,n)=>{let r=e.map(e=>Fa(e,t,n)),i=n?[]:e.map(e=>co(e,t,/* @__PURE__ */ new Set)),a=i.find(e=>e!==void 0),o=i.map(e=>e?.variable===a?.variable&&e?.argument===a?.argument?e?.labels:void 0);return(e,t,n,i,s,c)=>{let l=a&&lo(e,t,a);for(let a=0;a<r.length&&!e.isStopped;a++)(l===void 0||o[a]?.has(l)!==!1)&&r[a](e,t,n,i,s,c)}},fo=(e,t,n)=>{let r=e=>Fa(e,t,n);switch(e.kind){case`And`:return Xa(e.operands,t,n);case`Or`:return uo(e.operands,t,n);case`Exists`:{let i=r(e.body),a=e.bounds[0];if(e.bounds.length===1&&a.pattern.kind===`Name`){let e=a.pattern.name;return(t,n,r,o,s,c)=>{let l=Ho(Ys(a.set,Oa(t,n,r)),a.set);for(let a=0;a<l.length&&!t.isStopped;a++)i(t,Po(n,e,l[a]),r,o,s,c)}}let o=n||t.trace?void 0:Ya(e,t);if(o){let r=Xa(o.rest,t,n);return(t,n,i,a,s,c)=>{let l=Oa(t,n,i),u=e.bounds.map(e=>Ho(Ys(e.set,l),e.set));if(u.some(e=>e.length===0))return;let d=(e,n)=>{if(e<0)r(t,n,i,a,s,c);else for(let r of u[e]){if(t.isStopped)return;let a=Po(n,o.names[e],r);if(e===u.length-1){let e=Oa(t,a,i);if(!o.guards.every(t=>ja(t,e)))continue}d(e-1,a)}};d(u.length-1,n)}}return(t,n,r,a,o,s)=>{Uo(e.bounds,Oa(t,n,r),e=>(i(t,e,r,a,o,s),t.isStopped))}}case`Forall`:{let i=r(e.body),a=!n&&Oc(e,t)!==void 0&&!qa(e.body,t,/* @__PURE__ */ new Set)?Ka(e,Ga):void 0;return(t,n,r,o,s,c)=>{let l=[];Uo(e.bounds,Oa(t,n,r),e=>(l.push(e),!1));let u=[...l.slice(0,1),...l.slice(1).reverse()];if(a?.every(e=>No(n,e)?.kind===`Value`)){u.every(n=>ja(e.body,Oa(t,n,r)))&&c(r,o);return}let d=(n,r,a)=>{n===u.length?c(r,a):n>0&&t.isInit&&go(r)?u.slice(n).every(n=>Za(e.body,Oa(t,n,r)))&&c(r,a):i(t,u[n],r,a,!0,(e,t)=>d(n+1,e,t))};d(0,r,o)}}case`If`:{let t=r(e.consequent),n=r(e.alternative);return(r,i,a,o,s,c)=>{let l=Ys(e.condition,Oa(r,i,a));(Lo(l,`an IF condition`)?t:n)(r,i,a,o,s,c)}}case`Case`:{let t=e.arms.map(e=>({condition:e.condition,body:r(e.body)})),n=e.other?r(e.other):void 0;return(r,i,a,o,s,c)=>{let l=Oa(r,i,a),u=t.find(e=>Lo(Ys(e.condition,l),`a CASE guard`))?.body??n;if(!u)throw new y(`In computing ${r.isInit?`initial`:`next`} states, TLC encountered a CASE with no conditions true.\n${Co(e)}`);u(r,i,a,o,s,c)}}case`Let`:{let n=r(e.body),i=Os(e.definitions,t);return(t,r,a,o,s,c)=>n(t,vs(e.definitions,Oa(t,r,a),i),a,o,s,c)}case`Unchanged`:return n?()=>{throw new y(`UNCHANGED appears in an initial predicate at ${So(e)}`)}:ao(e.expression,t);case`AngleAction`:{let t=r(e.action),n=to(e.subscript);return(e,r,i,a,o,s)=>t(e,r,i,a,o,(t,i)=>{try{ja(n,Oa(e,r,t))||s(t,i)}catch(t){throw!e.isEnabled||!(t instanceof ee)?t:new y(`The action formula A appearing in a WF_v(A) or SF_v(A) operator does not specify the primed value of the variable ${t.variable} occurring in the state formula v.\n`)}})}case`BoxAction`:return r({kind:`Or`,operands:[e.action,to(e.subscript)],location:e.location});case`Label`:return r(e.body);case`Identifier`:return so(e,t,n);case`FunctionApplication`:return io(e,t,n);case`Apply`:{let i=e.args;if(Ma(e.operator)){let r=Ra(i[0],t,n);if(r!==void 0)return e.operator===`=`?Xa([e],t,n):$a(e,()=>r);if(Ba(i[0],n))return no(e,n)}if(e.operator===`=>`){let e=r(i[1]);return(t,n,r,a,o,s)=>{let c=Ys(i[0],Oa(t,n,r));(typeof c==`boolean`?c:Lo(c,`the left side of => at ${So(i[0])}`))?e(t,n,r,a,o,s):s(r,a)}}return oo(e,t,n)}default:return Qa(e)}},po=/* @__PURE__ */ new WeakMap,mo=e=>{let t=po.get(e);if(t)return t;let n=e.variables.map(()=>void 0);return po.set(e,n),n},ho=(e,t)=>t.variables.filter((t,n)=>e[n]===void 0),go=e=>{for(let t=0;t<e.length;t++)if(e[t]===void 0)return!1;return!0},_o=(e,t)=>{let n=t.state;if(!n||!go(n))throw new y(`ENABLED needs a complete state at ${So(e)}`);let r=t.environment,i={environment:r,isInit:!1,isEnabled:!0,current:n,isStopped:!1};return Fa(e,r,!1)(i,t.scope,mo(r),void 0,!1,()=>{i.isStopped=!0}),i.isStopped},vo=(t,r,i,a)=>{let o={environment:r,isInit:!0,isEnabled:!1,current:void 0,isStopped:!1};Fa(t,r,!0)(o,a,mo(r),void 0,!1,t=>{if(!o.isStopped){if(!go(t))throw n(new S(t),e.error);o.isStopped=i(t)}})},yo=(e,t,n)=>{let r=[];return vo(e,t,e=>(r.push(e),!1),n),r},bo=(e,t,n,r,i)=>{let a={environment:n,isInit:!1,isEnabled:!1,current:t,isStopped:!1},o={successors:0};return Fa(e,n,!1)(a,i,mo(n),void 0,!1,(e,t)=>{if(!a.isStopped){if(!go(e))throw new x(e,t,ho(e,n).sort());o.successors++,a.isStopped=r({state:e,action:t})}}),o.successors},xo=(e,t,n,r)=>{let i=[];return bo(e,t,n,e=>(i.push(e),!1),r),i},So=e=>`line ${e.location.line}, column ${e.location.column}`,Co=e=>{let t=e.location.range;return t?g(t):So(e)},wo=(e,t)=>new y(`A non-boolean expression (${Nr(t)}) was used as the condition of an IF.\n${Co(e)}`),To=(e,t,n)=>{let r=e.location.range;if(r?.start.line===e.location.line&&r.start.column===e.location.column||!r){let r=e.operands[t],i=r.kind===`Number`?String(r.value):Co(r);return new y(`A non-boolean expression (${Nr(n)}) was used as a formula in a conjunction.\n${i}`)}let i=e.operands[Math.max(t,1)].location.range?.end??r.end;return new y(`Attempted to evaluate an expression of form P /\\ Q when ${t===0?`P`:`Q`} was\n${Nr(n)}.\n${Co({...e,location:{...e.location,range:{...r,end:i}}})}`)},Eo=e=>t=>Dn(t)?`Attempted to select nonexistent field "${e.field}" from the record\n${Y(t)}\n${Co(e)}`:En(t,e.field),Do=e=>t=>`A non-function (${Nr(t)}) was applied as a function.\n${Co(e)}`,Oo=e=>t=>`Attempted to select field "${e.field}" from a non-record value ${Y(t)}\n${Co(e)}`,ko=e=>t=>{if(!Me(t))throw new y(`Attempted to apply the operator DOMAIN to a non-function\n(${Nr(t)})\n${Co(e)}`);return Mn(t)},Ao=(e,t)=>(n,r)=>{if(!Ae(n)||Ue(n))throw new y(`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${Co(e)}`);return t.evaluate([n,r])},jo=t=>n(new y(`TLC can't handle real numbers: ${t.text} at ${So(t)}`),e.configParseError),Mo=t=>n(new y(`TLC can't handle a number this big: ${t.text??t.value} at ${So(t)}`),e.error),No=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n.binding},Po=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n},parent:e}),Fo=(e,t,n)=>{if(t.kind===`Name`)return Po(e,t.name,n);let r=mn(n);if(!r||r.length!==t.names.length)throw new y(`Cannot bind <<${t.names.join(`, `)}>> to ${Y(n)}, which is not a tuple of that length`);return t.names.reduce((e,t,n)=>Po(e,t,r[n]),e)},Io=(e,t)=>({environment:e.environment,scope:t,state:e.state,next:e.next}),Lo=(e,t)=>{if(typeof e!=`boolean`)throw new y(`Expected ${t} to be a boolean but found ${Y(e)}`);return e},Ro=(e,t)=>t.definitions.get(t.substitutions.get(e)??e),zo=(e,t)=>{if(e.kind===`Prime`||e.kind===`Unchanged`||e.kind===`Enabled`)return!0;let n=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(n!==void 0){if(t.variableIndex.has(n)||t.builtins.get(n)?.isStateLevel)return!0;let e=Ro(n,t);if(e&&!t.constants.has(n)&&!Bo(e,t))return!0}return ur(e).some(e=>zo(e,t))},Bo=(e,t)=>{let n=t.constantLevels.get(e);if(n!==void 0)return n;t.constantLevels.set(e,!0);let r=!zo(e.body,t)&&(e.kind===`Operator`||!e.bounds.some(e=>zo(e.set,t)));return t.constantLevels.set(e,r),r},Vo=(e,t)=>{let n=`universally (\\A) or existentially (\\E) quantify over ${t}, because this would require checking an\ninfinite number of cases.`;if(typeof e==`object`&&e.kind===`SequenceSet`)return`In TLA+, Seq(S) represents the set of all finite sequences whose elements come from the set S. Even when S\nis a finite set, the number of possible sequences in Seq(S) is unbounded because sequences can have any\nfinite length (e.g., length 0, 1, 2, and so on). As a result, TLC cannot evaluate expressions that\n${n} Note that for a finite set of sequences s, TLC handles s \\subseteq Seq(S).\nSee https://explain.tlapl.us/seq-unenumerable for additional details.`;if(typeof e==`object`&&e.kind===`InfiniteSet`&&e.name!==`STRING`&&e.name!==`Any`)return`The set ${e.name} contains infinitely many elements. As a result, TLC cannot evaluate expressions that\n${n} Note that TLC handles set membership like T \\subseteq ${e.name} for any finite set T.`},Ho=(e,t)=>{if(!Ae(e)||Ue(e)){let n=Y(e),r=Vo(e,n);throw new y(r===void 0?`TLC encountered a non-enumerable quantifier bound\n${n}.\n${Co(t)}`:`TLC encountered the non-enumerable quantifier bound\n${n}\n${Co(t)}\n${r}`)}return typeof e==`object`&&e.kind===`Interval`?Rt(e):Qt(e)??q(e).elements},Uo=(e,t,n)=>{let r=e.map(e=>Ho(Ys(e.set,t),e.set)),i=(t,a)=>t<0?n(a):r[t].some(n=>i(t-1,Fo(a,e[t].pattern,n)));return i(e.length-1,t.scope)},Wo=(e,t)=>{let n=e.map(e=>Ys(e.set,t));return n.length===1?n[0]:{kind:`ProductSet`,factors:n}},Go=(e,t,n)=>{if(e.length===1)return Fo(t,e[0].pattern,n);let r=mn(n)??[];return e.reduce((e,t,n)=>Fo(e,t.pattern,r[n]),t)},Ko=/* @__PURE__ */ new WeakMap,qo=(e,t)=>{let n=Ko.get(t);if(n)return n;let r=t.location.range;if(!r)return;let i={parameters:e.flatMap((t,n)=>n>0&&e[n-1].set===t.set?[]:[{index:n,name:t.pattern.kind===`Name`?t.pattern.name:`<<${t.pattern.names.join(`, `)}>>`}]),body:g(r)};return Ko.set(t,i),i},Jo=(e,t,n)=>{let r=qo(e,t);if(!r)return;let i=e.length>1&&typeof n==`object`&&n.kind===`ProductSet`?n.factors:[n];return{parameters:r.parameters.map(e=>({name:e.name,domain:i[e.index]})),body:r.body}},Yo=(e,t,n)=>{let r=/* @__PURE__ */ new Map,i={kind:`LazyFunction`,domain:e,source:n,apply:e=>{let n=Hn(e),a=r.get(n);if(a!==void 0){for(let t=0;t<a.length;t+=2)if(tt(a[t],e))return a[t+1]}let o=t(e,i),s=r.get(n);return s===void 0?r.set(n,[e,o]):s.push(e,o),o}};return i},Xo=(e,t)=>{let n=Wo(e.bounds,t),r=Yo(n,(n,r)=>Ys(e.body,Io(t,Go(e.bounds,Po(void 0,e.name,r),n))),Jo(e.bounds,e.body,n));return e.bounds.length===1?Sn(r):r},Zo=(e,t)=>e.kind===`Function`?Xo(e,t):Ys(e.body,t),Qo=(e,t)=>{let n=Bo(e,t.environment),r=n?t.environment.definitionValues.get(e):void 0;if(r!==void 0)return r;if(e.kind===`Operator`&&e.params.length>0)throw new y(`Operator ${e.name} requires ${e.params.length} arguments`);let i=Io(t,void 0);if(!n)return Zo(e,i);let a=t.environment.runtime.evaluateAtStartup(()=>Zo(e,i));return t.environment.definitionValues.set(e,a),a},$o=(e,t)=>{let n=e.state===t.state&&e.next===t.next;if(n&&e.cache!==void 0)return e.cache;let r=Ys(e.expression,Io(t,e.scope));return n&&(e.cache=r),r},es=/* @__PURE__ */ new WeakMap,ts=e=>{let t=es.get(e);if(t)return t;let n={kind:`Closure`,name:e.name,params:e.params,body:e.body,scope:void 0};return es.set(e,n),n},ns=(e,t)=>{let n=t.substitutions.get(e);if(n!==void 0)return ns(n,t);let r=t.definitions.get(e);return r?.kind===`Operator`?ts(r):t.builtins.get(e)},rs=/* @__PURE__ */ new WeakMap,is=(e,t)=>{if(X(e))return as(e.operator,t);let n=rs.get(e),r=n===void 0?ns(e.operator,t.environment)??null:n;return n===void 0&&rs.set(e,r),r??as(e.operator,t)},as=(e,t)=>{let n=No(t.scope,e);if(n?.kind===`Operator`)return n.operator;if(!n)return ns(e,t.environment)},os=e=>e.kind===`Closure`?e.params.length:e.arity,ss=(e,t)=>{if(e.kind===`Lambda`)return{kind:`Closure`,name:`LAMBDA`,params:e.params.map(e=>({name:e,arity:0})),body:e.body,scope:t.scope};let n=e.kind===`OperatorReference`?e.operator:e.kind===`Identifier`?e.name:void 0,r=n===void 0?void 0:as(n,t);if(!r)throw new y(`Expected an operator argument at ${So(e)}`);return r},cs=(e,t,n)=>{if(e.kind===`Builtin`)return e.evaluate(t,n);if(e.kind===`Operator`)return e.call(t);let r=e.params.reduce((e,n,r)=>Po(e,n.name,t[r]),e.scope);return Ys(e.body,Io(n,r))},ls=(e,t)=>e.kind===`Operator`?e:{kind:`Operator`,name:e.name,arity:os(e),call:n=>cs(e,n,t),literalBody:e.kind===`Closure`&&(e.body.kind===`Number`||e.body.kind===`String`)?e.body.value:void 0},us=(e,t)=>{if(e.kind===`Lambda`||e.kind===`OperatorReference`)return!0;if(e.kind!==`Identifier`)return!1;let n=as(e.name,t);return n!==void 0&&os(n)>0},ds=(e,t)=>({kind:`Thunk`,expression:e,scope:t.scope,state:t.state,next:t.next,cache:void 0}),fs=(e,t)=>{let n=t.variableIndex.get(e);if(n!==void 0)return{kind:`Variable`,index:n};let r=t.constants.get(e);if(r!==void 0)return{kind:`Value`,value:r};let i=t.substitutions.get(e);if(i!==void 0)return fs(i,t);let a=t.definitions.get(e);if(a)return{kind:`Definition`,definition:a};let o=t.builtins.get(e);if(o&&o.arity===0&&!o.isStateLevel)return{kind:`Value`,value:o.evaluate([])}},ps=(e,t)=>{if(e.kind===`String`||e.kind===`Number`&&bs(e.value)){let t={kind:`Value`,value:e.value};return()=>t}if(e.kind===`Identifier`){let n=X(e)?void 0:fs(e.name,t);if(n?.kind===`Value`){let e={kind:`Value`,value:n.value};return()=>e}if(n===void 0)return t=>{let n=No(t.scope,e.name);return n?.kind===`Value`||n?.kind===`Thunk`?n:ds(e,t)}}return t=>ds(e,t)},ms=/* @__PURE__ */ new WeakMap,hs=(e,t)=>{let n=ms.get(e);if(n)return n;let r=ps(e,t);return ms.set(e,r),r},gs=(e,t,n)=>{if(t.length!==e.params.length)throw new y(`Operator ${e.name} expects ${e.params.length} arguments but received ${t.length}`);let r=e.scope;for(let i=0;i<t.length;i++){let a=e.params[i],o=a.arity>0?{kind:`Operator`,operator:ss(t[i],n)}:hs(t[i],n.environment)(n);r={name:a.name,binding:o,parent:r}}return r},_s=(e,t,n)=>e.kind===`Closure`?Ys(e.body,Io(n,gs(e,t,n))):e.kind===`Operator`?e.call(t.map(e=>Ys(e,n))):e.isLazy?e.evaluate(tc(t,n),n):e.evaluate(t.map(e=>us(e,n)?ls(ss(e,n),n):Ys(e,n)),n),vs=(e,t,n)=>e.reduce((e,r)=>{let i={name:r.name,binding:{kind:`Value`,value:!1},parent:e};return r.kind===`Function`?(i.binding={kind:`Thunk`,expression:{kind:`FunctionConstruction`,bounds:r.bounds,body:r.body,location:r.location,isRecursive:!0},scope:i,state:t.state,next:t.next,cache:void 0},i):r.params.length>0||n?.has(r)?(i.binding={kind:`Operator`,operator:{kind:`Closure`,name:r.name,params:r.params,body:r.body,scope:i}},i):(i.binding={kind:`Thunk`,expression:r.body,scope:i,state:t.state,next:t.next,cache:void 0},i)},t.scope),ys=(e,t,n)=>{let r=No(n.scope,e);if(r?.kind===`Value`)return r.value;if(r?.kind===`Thunk`)return $o(r,n);if(r?.kind===`Operator`){if(os(r.operator)===0)return cs(r.operator,[],n);throw new y(`Operator ${e} is used without arguments`)}let i=fs(e,n.environment);if(i?.kind===`Variable`){let r=n.state?.[i.index];if(r===void 0)throw Sc(e,t);return r}if(i?.kind===`Value`)return i.value;if(i?.kind===`Definition`)return Qo(i.definition,n);let a=n.environment.builtins.get(e);if(a?.arity===0)return a.evaluate([],n);throw new y(`Unknown identifier ${e} at ${So(t)}`)},bs=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,xs=/* @__PURE__ */ new Set([`Print`,`PrintT`,`Assert`,`JavaTime`,`RandomElement`,`TLCGet`,`TLCSet`]),Ss=(e,t)=>xs.has(e)||t.builtins.get(e)?.isStateLevel===!0,Cs={builtins:xs,definitions:/* @__PURE__ */ new WeakMap},ws={builtins:new Set([...xs].filter(e=>e!==`Assert`)),definitions:/* @__PURE__ */ new WeakMap},Ts=(e,t)=>e.kind===`Operator`&&e.params.length===0&&Bo(e,t),Es=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`||e.kind===`OperatorReference`?e.operator:void 0;if(r!==void 0&&!X(e)){let e=Ro(r,t),i=n.builtins.has(r)||t.builtins.get(r)?.isStateLevel===!0;if(!e&&i||e&&!Ts(e,t)&&Ds(e,t,n))return!0}return ur(e).some(e=>Es(e,t,n))},Ds=(e,t,n=Cs)=>{let r=n.definitions.get(e);if(r!==void 0)return r;n.definitions.set(e,!1);let i=Es(e.body,t,n)||e.kind===`Function`&&e.bounds.some(e=>Es(e.set,t,n));return n.definitions.set(e,i),i},Os=(e,t)=>new Set(e.filter(e=>Ds(e,t))),ks=e=>[...e.definitions.values()].some(t=>Ds(t,e)),As=e=>[...e.definitions.values()].some(t=>Ds(t,e,ws)),js=/* @__PURE__ */ new WeakMap,Ms=(e,t)=>{let n=js.get(e);if(n!==void 0)return n;let r=Is(e,t,Ps);return js.set(e,r),r},Ns=/* @__PURE__ */ new Set([`Number`,`String`,`Identifier`,`Apply`,`And`,`Or`,`If`,`Case`,`SetEnumeration`,`Tuple`,`FunctionSet`,`Record`,`RecordSet`,`FunctionApplication`,`FieldAccess`,`Product`,`SetFilter`,`SetMap`,`Forall`,`Exists`,`Choose`,`FunctionConstruction`,`Let`]),Ps=/* @__PURE__ */ new Set,Fs=(e,t,n)=>n.size===0?Ms(e,t):Is(e,t,n),Is=(e,t,n)=>{if(!Ns.has(e.kind))return!1;if(e.kind===`Identifier`&&X(e))return n.has(e.name);if(X(e))return!1;if(e.kind===`Identifier`){let n=fs(e.name,t);return n?.kind===`Value`||n?.kind===`Definition`&&Ts(n.definition,t)}if(e.kind===`Apply`){if(Ss(e.operator,t)||e.operator===`~>`)return!1;let r=ns(e.operator,t);if(r?.kind!==`Builtin`&&r?.kind!==`Closure`)return!1;if(r.kind===`Closure`){let n=Ro(e.operator,t);if(!n||!Bo(n,t)||Ds(n,t))return!1}return!(r.kind===`Closure`?r.params:[]).some(e=>e.arity>0)&&e.args.every(e=>e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&Fs(e,t,n))}let r={value:!0};return ea(e,(e,i)=>(r.value&&=Fs(e,t,i.length===0?n:/* @__PURE__ */ new Set([...n,...i])),e)),r.value},Ls=e=>e.kind!==`Number`&&e.kind!==`String`&&e.kind!==`Identifier`,Rs=e=>{let t={value:void 0};return n=>{if(t.value!==void 0)return t.value;let r=e(n);return t.value=r,r}},zs=(e,t)=>{if(e.kind===`Identifier`&&X(e))return!t.has(e.name);if(X(e))return!0;let n={value:!1};return ea(e,(e,r)=>(n.value||=zs(e,r.length===0?t:/* @__PURE__ */ new Set([...t,...r])),e)),n.value},Bs=(e,t)=>Ki.has(e)&&Ls(e)&&Oc(e,t)!==void 0&&!zs(e,Ps),Vs=/* @__PURE__ */ new WeakMap,Hs=/* @__PURE__ */ new Set([`SetEnumeration`,`SetMap`,`SetFilter`,`Tuple`,`Record`,`RecordSet`,`FunctionSet`,`Product`]),Us=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`\\cup`,`\\cap`,`\\`]),Ws=(e,t)=>Hs.has(e.kind)||e.kind===`Apply`&&Us.has(e.operator)&&!X(e)&&ns(e.operator,t)?.kind===`Builtin`,Gs=(e,t,n,r)=>{try{return e(t)}catch(e){throw n.length===r+1&&n.push(...Oe(e)??[]),e}},Ks=(e,t)=>{let n=t.evaluators.get(e);if(n)return n;let r=Tc(e,t),i=Ls(e)&&Ms(e,t)?Rs(r):Bs(e,t)?Qs(r):r,a=t.trace,o=a!==void 0&&Ws(e,t),s=a?n=>{let r=a.length;a.push(e);let s=Gs(i,n,a,r);a.length=r,o&&typeof s==`object`&&s.kind!==`FilteredSet`&&P.current?.set(s,e);let c=typeof s==`object`&&s.kind===`FilteredSet`?Vs.get(s):void 0;return c?c(t):s}:i;return t.evaluators.set(e,s),s},qs=/* @__PURE__ */ new WeakMap,Js=(e,t)=>{if(t.trace)return Ks(e,t);let n=qs.get(e);if(n)return n;let r=(Ls(e)&&Ms(e,t)?void 0:$r(e,t))??Ks(e,t);return qs.set(e,r),r},Ys=(e,t)=>Js(e,t.environment)(t),Xs=(e,t)=>{let n=e.name,r=X(e)?void 0:fs(n,t);if(r?.kind===`Variable`){let t=r.index;return r=>{let i=r.state?.[t];if(i===void 0)throw Sc(n,e);return i}}if(r?.kind===`Value`){let e=r.value;return()=>e}if(r?.kind===`Definition`&&r.definition.kind===`Operator`){let e=r.definition;if(e.params.length===0&&Bo(e,t))return t=>Qo(e,t);if(e.params.length===0){let n={body:void 0},r=r=>(n.body??=Js(e.body,t),n.body(Io(r,void 0)));return Zs(e,t)?Qs(r):r}return t=>Qo(e,t)}if(r?.kind===`Definition`){let e=r.definition,n=t=>Qo(e,t);return Bo(e,t)||!Zs(e,t)?n:Qs(n)}return t=>ys(n,e,t)},Zs=(e,t)=>Oc(e.body,t)!==void 0&&(e.kind===`Operator`||e.bounds.every(e=>Oc(e.set,t)!==void 0)),Qs=e=>{let t={recent:void 0,recentValue:void 0,previous:void 0,previousValue:void 0};return n=>{let r=n.state;if(r!==void 0&&t.recent===r&&t.recentValue!==void 0)return t.recentValue;if(r!==void 0&&t.previous===r&&t.previousValue!==void 0)return t.previousValue;let i=e(n);return t.previous=t.recent,t.previousValue=t.recentValue,t.recent=r,t.recentValue=i,i}},$s=(e,t)=>{let n=ns(e,t);return n!==void 0&&os(n)>0},ec=(e,t)=>e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&!(e.kind===`Identifier`&&!X(e)&&$s(e.name,t)),tc=(e,t)=>e.map(e=>({kind:`Operator`,name:`argument`,arity:0,call:()=>Ys(e,t),expression:e})),nc=/* @__PURE__ */ new Set([`=`,`#`,`\\in`,`\\notin`,`\\cup`,`\\cap`,`\\`]),rc=(e,t,n)=>e===`\\in`||e===`\\notin`||(e===`\\cup`||e===`\\cap`)&&!je(t)?n:t,ic=(e,t,n)=>{if(n.trace&&nc.has(e.name)&&t.length===2){let r=Ks(t[0],n),i=Ks(t[1],n);return t=>{let n=r(t),a=i(t);return ke(rc(e.name,n,a),()=>e.evaluate([n,a],t))}}if(e.isLazy)return n=>e.evaluate(tc(t,n),n);let r=e.evaluateUnary;if(r&&t.length===1&&ec(t[0],n)){let e=Ks(t[0],n);return t=>r(e(t))}let i=e.evaluateBinary,a=t.length===2&&ec(t[0],n)&&ec(t[1],n);if(i&&a){let e=Ks(t[0],n),r=Ks(t[1],n);return t=>i(e(t),r(t))}return n=>e.evaluate(t.map(e=>us(e,n)?ls(ss(e,n),n):Ys(e,n)),n)},ac=(e,t,n)=>{if(t.length!==e.params.length)return()=>{throw new y(`Operator ${e.name} expects ${e.params.length} arguments but received ${t.length}`)};let r=e.params,i=t.map((e,t)=>r[t].arity>0?void 0:hs(e,n));return n=>{let a=e.scope;for(let e=0;e<t.length;e++){let o=i[e],s=o?o(n):{kind:`Operator`,operator:ss(t[e],n)};a={name:r[e].name,binding:s,parent:a}}return a}},oc=/* @__PURE__ */ new WeakMap,sc=e=>{let t=oc.get(e);if(t)return t;let n={calls:/* @__PURE__ */ new Map,size:0};return oc.set(e,n),n},cc=(e,t)=>{let n=[];for(let r=e;n.length<t;r=r?.parent){if(r?.binding.kind!==`Value`)return;n.push(r.binding.value)}return n},lc=(e,t)=>e.every((e,n)=>tt(e,t[n])),uc=(e,t)=>{let n=Ro(e.operator,t);return n?.kind===`Operator`&&n.params.length>0&&n.params.every(e=>e.arity===0)&&Bo(n,t)&&!Ds(n,t)},dc=(e,t,n,r)=>{let i=ac(e,t,n),a={body:void 0},o=(t,r)=>(a.body??=Js(e.body,n),a.body({environment:n,scope:t,state:r.state,next:r.next}));if(!r)return e=>o(i(e),e);let s=sc(e);return e=>{let n=i(e),r=cc(n,t.length);if(!r)return o(n,e);let a=r.length;for(let e of r)a=In(a,Hn(e));let c=s.calls.get(a),l=c?.find(e=>lc(e.args,r));if(l)return l.value;let u=o(n,e);return s.size<65536&&(s.size++,c?c.push({args:r,value:u}):s.calls.set(a,[{args:r,value:u}])),u}},fc=(e,t)=>{let n=e.args;if(e.operator===`=>`){let e=Ks(n[0],t),r=Ks(n[1],t);return t=>!Lo(e(t),`the left side of =>`)||Lo(r(t),`the right side of =>`)}if(e.operator===`~>`)return()=>{throw new y(`TLC cannot evaluate a temporal formula such as ~> in a state`)};let r=X(e)?void 0:ns(e.operator,t);if(r?.kind===`Closure`)return dc(r,n,t,uc(e,t));if(r?.kind===`Builtin`&&r.name===`DOMAIN`){let r=Ks(n[0],t),i=ko(e);return t.trace?e=>{let t=i(r(e));return typeof t==`object`&&t.kind===`Interval`?{...t}:t}:e=>i(r(e))}if(r?.kind===`Builtin`&&r.name===`TLCEval`&&n.length===1){let i=Ks(n[0],t);return qi.has(e)||zo(n[0],t)?i:e=>e.scope===void 0?r.evaluate([i(e)]):i(e)}if(r?.kind===`Builtin`&&r.name===`\\subseteq`&&n.length===2){let i=Ks(n[0],t),a=Ks(n[1],t),o=Ao(e,r);return t.trace?e=>{let t=i(e),n=a(e);return ke(t,()=>o(t,n))}:e=>o(i(e),a(e))}return r?.kind===`Builtin`?ic(r,n,t):r=>{let i=as(e.operator,r);if(i)return _s(i,n,r);throw t.definitions.get(e.operator)?.kind===`Function`?new y(`${e.operator} is a function; apply it with brackets`):e.operator===`\\cdot`?new y(`The current version of TLC does not support action composition. An incomplete implementation can be enabled via the tlc2.tool.impl.Tool.cdot=true java property.`):new y(`Unknown operator ${e.operator} at ${So(e)}`)}},pc=(e,t)=>{let n=e.kind===`Forall`,r=n?`the body of \\A`:`the body of \\E`,i=Ks(e.body,t),a=e.bounds[0];if(e.bounds.length===1&&a.pattern.kind===`Name`){let e=a.pattern.name,o=Ks(a.set,t);return t=>{let s=Ho(o(t),a.set);for(let a=0;a<s.length;a++){let o=Lo(i(Io(t,Po(t.scope,e,s[a]))),r);if(o!==n)return o}return n}}let o=e.bounds;if(o.every(e=>e.pattern.kind===`Name`)){let e=o.map(e=>e.pattern.kind===`Name`?e.pattern.name:``),a=o.map(e=>Ks(e.set,t));return t=>{let s=a.map((e,n)=>Ho(e(t),o[n].set)),c=(a,o)=>{if(a<0)return Lo(i(Io(t,o)),r)!==n;let l=s[a];for(let t=0;t<l.length;t++)if(c(a-1,Po(o,e[a],l[t])))return!0;return!1};return c(o.length-1,t.scope)?!n:n}}return e=>Uo(o,e,t=>Lo(i(Io(e,t)),r)!==n)?!n:n},mc=(e,t)=>{if(e.kind===`Tuple`)return Ht(e.names.map(e=>{let n=No(t,e);return n?.kind===`Value`&&n.value}));let n=No(t,e.name);return n?.kind===`Value`?n.value:void 0},hc=/* @__PURE__ */ new WeakSet,gc=e=>{(e.kind===`FunctionConstruction`||e.kind===`Except`)&&hc.add(e)},_c=(e,t)=>{let n=hc.has(e),r=Ks(e.body,t),i=e.bounds,a=i[0],o=i.length===1&&a.pattern.kind===`Name`,s=Ks(a.set,t);return t=>{let c=o?s(t):Wo(i,t),l=typeof c==`object`&&c.kind===`ProductSet`&&i.length>1?c.factors:[c];if(e.isRecursive||n||!l.every(je)){let n=Yo(c,e=>r(Io(t,Go(i,t.scope,e))),Jo(i,e.body,c));return i.length===1?Sn(n):n}if(o&&a.pattern.kind===`Name`){let e=a.pattern.name,n=Bt(c);return Sn(Qe(n,n.map(n=>r(Io(t,Po(t.scope,e,n))))))}let u=[];return Uo(i,t,e=>{let n=i.length===1?mc(a.pattern,e)??!1:Ht(i.map(t=>mc(t.pattern,e)??!1));return u.push([n,r(Io(t,e))]),!1}),Mt(u)}},vc=(e,t)=>{let n=hc.has(e);n&&gc(e.function);let r=Ks(e.function,t),i=e.updates.map(e=>({path:e.path.map(e=>e.kind===`Field`?{kind:`Field`,name:e.name,args:[]}:{kind:`Index`,name:``,args:e.args.map(e=>Ks(e,t))}),value:Ks(e.value,t)})),a=(e,t)=>e.kind===`Field`?e.name:e.args.length===1?e.args[0](t):Ht(e.args.map(e=>e(t))),o=(e,t,r,i,s)=>r===t.length?s(Io(i,Po(i.scope,`@`,e))):Nn(e,a(t[r],i),e=>o(e,t,r+1,i,s),n&&r===0);return e=>{let t=r(e);for(let n of i)t=o(t,n.path,0,e,n.value);return t}},yc=(e,t)=>{if(e.kind===`SetFilter`){let n=Ks(e.predicate,t),r=Ks(e.bound.set,t),i=e.bound.pattern;return t=>{let a=r(t),o=e=>n=>Lo(e(Io(t,Fo(t.scope,i,n))),`a set filter predicate`),s=o(n);if(!je(a)){if(Ae(a)){let t={kind:`FilteredSet`,base:a,test:s};return Vs.set(t,n=>({...t,test:o(Ks(e.predicate,n))})),t}throw new y(`TLC encountered a non-enumerable quantifier bound ${Y(a)} at ${So(e.bound.set)}`)}return Ze(q(a).elements.filter(s))}}if(e.kind===`SetMap`){let n=Ks(e.expression,t);return t=>{let r=[];return Uo(e.bounds,t,e=>(r.push(n(Io(t,e))),!1)),Dt(r)}}let n=e.set;if(!n)return()=>{throw new y(`TLC cannot evaluate an unbounded CHOOSE at ${So(e)}`)};let r=Ks(e.body,t),i={pattern:e.pattern,set:n};return t=>{let n={value:void 0};if(Uo([i],t,i=>Lo(r(Io(t,i)),`the body of CHOOSE`)?(n.value=mc(e.pattern,i),!0):!1),n.value===void 0)throw new y(`Attempted to compute the value of an expression of form\nCHOOSE x \\in S: P, but no element of S satisfied P.\n${Co(e)}`);return n.value}},bc=e=>[...e].sort((e,t)=>Je(e.name,t.name)),xc=e=>e.some((t,n)=>n>0&&e[n-1].name===t.name),Sc=(t,n)=>a(new ee(`In evaluation, the identifier ${t} is either undefined or not an operator.\n${Co(n)}`,t),e.configParseError),Cc=e=>new y(`A primed expression appears outside an action at ${So(e)}`),wc=(e,t)=>{let n=bc(e),r=xc(n),i=n.map(e=>Ks(e.value,t));if(r)return e=>Mt(n.map((t,n)=>[t.name,i[n](e)]));let a=n.map(e=>e.name),o=e.map(e=>e.name);return o.some((e,t)=>e!==a[t])?e=>L(a,i.map(t=>t(e)),o):e=>Qe(a,i.map(t=>t(e)))},Tc=(e,t)=>{let n=e=>Ks(e,t);switch(e.kind){case`Number`:{let t=e.value;return bs(t)?()=>t:()=>{throw Mo(e)}}case`Decimal`:return()=>{throw jo(e)};case`String`:{let t=e.value;return()=>t}case`Identifier`:return Xs(e,t);case`Apply`:return fc(e,t);case`OperatorReference`:case`Lambda`:return()=>{throw new y(`An operator cannot be used as a value at ${So(e)}`)};case`And`:{let t=e.operands.map(n);return n=>{for(let r=0;r<t.length;r++){let i=t[r](n);if(typeof i!=`boolean`)throw To(e,r,i);if(!i)return!1}return!0}}case`Or`:{let t=e.operands.map(n);return e=>{for(let n=0;n<t.length;n++)if(Lo(t[n](e),`a disjunct`))return!0;return!1}}case`Prime`:{let t=n(e.expression);return n=>{if(!n.next)throw Cc(e);return t({environment:n.environment,scope:n.scope,state:n.next,next:void 0})}}case`Unchanged`:{let t=n({kind:`Prime`,expression:e.expression,location:e.location}),r=n(e.expression);return e=>$e(t(e),r(e))}case`If`:{let t=n(e.condition),r=n(e.consequent),i=n(e.alternative);return n=>{let a=t(n);if(typeof a!=`boolean`)throw wo(e,a);return a?r(n):i(n)}}case`Case`:{let t=e.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),r=e.other?n(e.other):void 0;return n=>{for(let e of t)if(Lo(e.condition(n),`a CASE guard`))return e.body(n);if(r)return r(n);throw new y(`Attempted to evaluate a CASE with no conditions true.\n${Co(e)}`)}}case`Let`:{let t=n(e.body);return n=>t(Io(n,vs(e.definitions,n)))}case`Forall`:case`Exists`:return pc(e,t);case`UnboundedQuantifier`:return()=>{throw new y(`TLC cannot evaluate an unbounded quantifier at ${So(e)}`)};case`Choose`:case`SetFilter`:case`SetMap`:return yc(e,t);case`SetEnumeration`:{let t=e.elements.map(n);return e=>Dt(t.map(t=>t(e)))}case`Tuple`:{let t=e.elements.map(n);return e=>Ht(t.map(t=>t(e)))}case`FunctionConstruction`:return _c(e,t);case`FunctionSet`:{let t=n(e.domain),r=n(e.range);return e=>({kind:`FunctionSet`,domain:t(e),range:r(e)})}case`Record`:return wc(e.fields,t);case`RecordSet`:{let t=bc(e.fields),r=t.map(e=>e.name),i=t.map(e=>n(e.value));return e=>({kind:`RecordSet`,names:r,sets:i.map(t=>t(e))})}case`Except`:return vc(e,t);case`ExceptAt`:return t=>{let n=No(t.scope,`@`);if(n?.kind!==`Value`)throw new y(`@ appears outside an EXCEPT at ${So(e)}`);return n.value};case`FunctionApplication`:{gc(e.function);let r=n(e.function),i=e.args.map(n),a=Do(e);if(i.length===1&&t.trace){let e=i[0];return t=>{let n=r(t),i=e(t),o=()=>An(n,i,void 0,a);return Me(n)?ke(n,o):o()}}if(i.length===1){let e=i[0];return t=>An(r(t),e(t),void 0,a)}return e=>An(r(e),Ht(i.map(t=>t(e))),void 0,a)}case`FieldAccess`:{let t=n(e.record),r=e.field,i=Eo(e),a=Oo(e);return e=>An(t(e),r,i,a)}case`Product`:{let t=e.factors.map(n);return e=>({kind:`ProductSet`,factors:t.map(t=>t(e))})}case`BoxAction`:case`AngleAction`:{let t=n(e.action),r=n({kind:`Unchanged`,expression:e.subscript,location:e.location}),i=e.kind===`BoxAction`;return e=>i?Lo(t(e),`an action`)||r(e):Lo(t(e),`an action`)&&!r(e)}case`Enabled`:{let t=e.expression;return e=>_o(t,e)}case`Label`:return n(e.body);case`Subexpression`:return()=>{throw new y(`The subexpression reference at ${So(e)} does not name a subexpression`)};case`Always`:case`Eventually`:case`WeakFairness`:case`StrongFairness`:return()=>{throw new y(`TLC cannot evaluate a temporal formula in a state at ${So(e)}`)}}},Ec=/* @__PURE__ */ new Set([`Prime`,`Unchanged`,`Enabled`,`Always`,`Eventually`,`BoxAction`,`AngleAction`,`WeakFairness`,`StrongFairness`]),Dc=e=>{if(e.kind===`Identifier`)return e.name;if(e.kind===`Apply`||e.kind===`OperatorReference`)return e.operator},Oc=(e,t)=>{let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=e=>{if(Ec.has(e.kind))return!1;let a=Dc(e),o=(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`;if(a!==void 0&&!o&&!t.constants.has(a)){let e=t.substitutions.get(a)??a,o=t.definitions.get(e);if(!o&&Ss(e,t))return!1;let s=t.variableIndex.get(a);if(s!==void 0&&n.add(s),o&&!r.has(o)&&(r.add(o),!i(o.body)||o.kind!==`Operator`&&!o.bounds.every(e=>i(e.set))))return!1}return ur(e).every(i)};return i(e)?[...n]:void 0},kc=/* @__PURE__ */ new Map([[`Reals`,`-------------------------------- MODULE Reals -------------------------------
|
|
32
32
|
(***************************************************************************)
|
|
33
33
|
(* This module provides dummy definitions of the operators that are *)
|
|
34
34
|
(* defined by the real Reals module. It is expected that any tool that *)
|
|
@@ -97,9 +97,17 @@ _TEPosition ==
|
|
|
97
97
|
THEN _TETraceLength
|
|
98
98
|
ELSE IF TLCGet("level") = 0 THEN 1 ELSE TLCGet("level")
|
|
99
99
|
|
|
100
|
-
=============================================================================`]]),
|
|
101
|
-
`)},Kc=(e,t)=>{let n=ue(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},c=[],l=e=>i[i.length-1].has(e),u=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),d=[],f=[],g=[],_=e=>{let t=r.index-1,i=e===t?g[e]:void 0;if(i)return i;let a=n[t];d[e]??=u(n[e]),f[t]??={line:a.line,column:a.endColumn};let o={module:c[c.length-1].name,start:d[e],end:f[t]};return e===t&&(g[e]=o),o},v=(e,t)=>(e.location.range=_(t),e),y=(e=0)=>n[Math.min(r.index+e,n.length-1)],b=(e=0)=>{let t=y(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},x=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),ee={index:0},te=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},ne=e=>t&&(e.kind===`Keyword`||Uc.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},ie=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Ic.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):ne(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,S=(e,t=y(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new p(`${e} at line ${t.line}, column ${t.column}`,void 0,ae(e,t,a,r))},ae=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...te(re(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${ie(a)}`,...re(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},C=(e,t=y())=>S(e,t,t),oe=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!ne(e),w=(e,t=0)=>{let n=b(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},T=()=>{let e=b();if(e.kind===`End`)throw S(`Unexpected end of expression`);return r.index++,e},D=e=>w(e)?(r.index++,!0):!1,O=e=>{if(!w(e))throw C(`Expected ${JSON.stringify(e)} but found ${x(b())}`);return T()},k=()=>{let e=b();if(e.kind!==`Identifier`)throw C(`Expected an identifier but found ${x(e)}`);if(ne(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},A=(e,t=`,`)=>{let n=[e()];for(;D(t);)n.push(e());return n},ce=()=>{if(w(`<<`)){let e={value:1};for(;b(e.value).kind===`Identifier`||w(`,`,e.value);)e.value++;return w(`>>`,e.value)&&w(`\\in`,e.value+1)}let e={value:0};for(;b(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(;b(e.value).kind===`Identifier`&&w(`,`,e.value+1);)e.value+=2;return b(e.value).kind===`Identifier`&&w(`)`,e.value+1)&&w(`::`,e.value+2)},de=()=>{if(!D(`<<`))return{kind:`Name`,name:k()};let e=A(k);return O(`>>`),{kind:`Tuple`,names:e}},fe=()=>A(()=>{let e=A(de);O(`\\in`);let t=N();return e.map(e=>({pattern:e,set:t}))}).flat(),j=()=>{let e=b();if(e.kind===`Identifier`){let t=r.index,n=[T().text];for(;w(`!`)&&b(1).kind===`Identifier`;)T(),n.push(k());return v({kind:`Identifier`,name:n.join(`!`),location:u(e)},t)}if(w(`<<`)||w(`(`))return Ee();throw C(`Expected a subscript but found ${x(e)}`)},pe=e=>{let t=b(1),n=b(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(`==`,wc.has(n.text)?3:4))},me=e=>{if(!Ec.has(e.text))return!0;let t=b(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||w(`,`,1)||w(`)`,1)||t.kind===`Keyword`&&Mc.has(t.text)||pe(e)},he=()=>{let e=b(),n=e.kind===`Operator`&&(Cc.has(e.text)||Tc.has(e.text))&&me(e);if(t&&e.kind!==`String`&&(Tc.has(e.text)||Oc.has(e.text)&&e.text!==`'`&&!wc.has(e.text)||Dc.has(e.text)&&b(-1).text===`(`&&b(-1).line===e.line&&b(-1).endColumn+1===e.column&&b(1).text===`)`&&b(1).line===e.line&&b(1).column===e.endColumn+1)&&me(e))throw S(`incomplete expression`,e);if(n)return r.index++,v({kind:`OperatorReference`,operator:e.text,location:u(e)},r.index-1);if(e.kind!==`String`&&Oc.has(e.text)&&me(e)){r.index++;let t=u(e);if(wc.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:Ac(e.text,n,t),location:t}}if(w(`LAMBDA`)){let t=r.index;T();let n=A(k);O(`:`);let i=N();return v({kind:`Lambda`,params:n,body:i,location:u(e)},t)}return N()},ge={range:void 0},_e=()=>se(()=>{let e=r.index;O(`(`);let t=A(he);return O(`)`),ge.range=_(e),t}),ve=()=>{let e=T();r.offsideColumns.push(e.column);let t=[N()];for(;y().text===e.text&&y().column===e.column;)r.index++,t.push(N());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:u(e)}},ye=e=>se(()=>{let t=u(e);if(b().kind===`Identifier`&&(w(`|->`,1)||w(`:`,1))){let e=w(`|->`,1)?`Record`:`RecordSet`,n=A(()=>{let t=r.index,n=u(b()),i=k();return n.range=_(t),O(e===`Record`?`|->`:`:`),{name:i,value:N(),location:n}});return O(`]`),{kind:e,fields:n,location:t}}if(ce()){let e=fe();O(`|->`);let n=N();return O(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=N();if(D(`->`)){let e=N();return O(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(D(`EXCEPT`)){let e=A(()=>{O(`!`);let e=[];for(;w(`.`)||w(`[`);)if(D(`.`)){if(!oe(b()))throw C(`Expected a field name but found ${x(b())}`);e.push({kind:`Field`,name:T().text})}else O(`[`),e.push({kind:`Index`,args:A(()=>N())}),O(`]`);return O(`=`),{path:e,value:N()}});return O(`]`),{kind:`Except`,function:n,updates:e,location:t}}return O(`]_`),{kind:`BoxAction`,action:n,subscript:j(),location:t}}),be=e=>se(()=>{let t=u(e);if(D(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(ce()&&(b(1).text===`\\in`||w(`<<`))){let e=r.index,n=de();O(`\\in`);let i=N();if(D(`:`)){let e=N();return O(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=N();if(D(`:`)){let e=fe();return O(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;D(`,`);)i.push(N());return O(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),xe=e=>{let t=u(e),n=se(()=>w(`>>`)||w(`>>_`)?[]:A(()=>N()));if(D(`>>_`)){if(n.length!==1)throw S(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:j(),location:t}}return O(`>>`),{kind:`Tuple`,elements:n,location:t}},Se=e=>{let t=u(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&ce()){let e=fe();return O(`:`),{kind:n,bounds:e,body:N(),location:t}}let i=A(k);return O(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:N(),isTemporal:r,location:t}},Ce=e=>{let t=[];do{if(D(`OTHER`))return O(`->`),{kind:`Case`,arms:t,other:N(),location:u(e)};let n=N();O(`->`),t.push({condition:n,body:N()})}while(D(`[]`));return{kind:`Case`,arms:t,other:void 0,location:u(e)}},we=()=>{let e=b(1);return w(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||jc.has(e.text)||e.kind===`Operator`&&(Cc.has(e.text)||wc.has(e.text)||Tc.has(e.text)))},Te=()=>{let e=T();if(e.kind===`Number`)return{kind:`Operand`,operand:E(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:_e()}}return{kind:`Name`,name:e.text,args:w(`(`)?_e():[]}},Ee=()=>{let e=r.index===s.index,n=T(),a=u(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=A(k);return O(`:`),{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:E(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`&&Re(n);if(o&&Ie()<0&&Fe.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?ze(n)??n.text:n.text;if(le()){let e=D(`(`)?A(k):[];return e.length>0&&O(`)`),O(`::`),{kind:`Label`,name:r,params:e,body:N(),location:a}}let i=w(`(`),s=i?_e():[];if(!we())return i?{kind:`Apply`,operator:r,args:s,argumentsRange:ge.range,location:a}:{kind:`Identifier`,name:r,location:a};let l=c.flatMap(e=>e.instances).find(e=>e.name===r);if(l&&!e&&!t&&l.params.length!==s.length)throw S(`The operator ${r} requires ${l.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;we();)T(),u.push(Te());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),h=ge.range;return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,argumentsRange:h,location:a}:{kind:`Apply`,operator:f,args:p,argumentsRange:h,location:a}}if(n.kind===`Operator`&&kc(n.text)&&w(`(`))return{kind:`Apply`,operator:n.text,args:_e(),location:a};switch(n.text){case`(`:{let e=se(()=>N());return O(`)`),e}case`[`:return ye(n);case`{`:return be(n);case`<<`:return xe(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return Se(n);case`IF`:{let e=N();O(`THEN`);let t=N();return O(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:N(),location:a}}case`CASE`:return Ce(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!D(`IN`);){if(t&&w(`RECURSIVE`))throw S(`Unexpected keyword RECURSIVE`,te(y()));if(D(`RECURSIVE`)){Me();continue}let r=De(!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=de(),t=D(`\\in`)?N():void 0;return O(`:`),{kind:`Choose`,pattern:e,set:t,body:N(),location:a}}case`WF_`:case`SF_`:{let e=j(),t=se(()=>{O(`(`);let e=N();return O(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw C(`Unexpected ${x(n)}`,n)},M=()=>{let e=b(),t=u(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return ve();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 Ee()},N=(e=0)=>{let t=r.index,n=M(),i={left:n.location.range?n:v(n,t),previous:void 0};for(;;){let n=b();if(n.kind!==`Operator`)break;let r=u(n);if(n.text===`'`&&e<=15){T(),i.left=v({kind:`Prime`,expression:i.left,location:r},t);continue}if(wc.has(n.text)&&e<=15){T(),i.left=v({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){T();let e=se(()=>A(()=>N()));se(()=>O(`]`)),i.left=v({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&oe(b(1))){T();let e=T().text;i.left=v({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=Cc.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 -`,b());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=v(i.left,t),i.previous={...a,text:n.text}}return i.left},P=()=>{if(!D(`(`))return[];let e=je();return O(`)`),e},F=()=>{let e=u(b()),t=N(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:c[c.length-1].name,start:e,end:a}}},De=e=>{let t=r.index;return v(Oe(e),t)},Oe=e=>{let t=b(),n=u(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...F(),isLocal:e,isRecursive:l(t),location:n});if(t.kind===`Identifier`&&b(1).kind===`Operator`&&Cc.has(b(1).text)&&b(2).kind===`Identifier`&&w(`==`,3)){let e=k(),t=T().text,n=k();return O(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&wc.has(b(1).text)&&w(`==`,2);if(a||o){let e=a?t.text:b(1).text;r.index+=a?1:2;let n=a?k():t.text;return O(`==`),i(e,[{name:n,arity:0}])}let s=k();if(D(`[`)){let t=se(()=>fe());return O(`]`),O(`==`),{kind:`Function`,name:s,bounds:t,body:N(),isLocal:e,isRecursive:l(s),location:n}}let c=r.index,d=P();return O(`==`),w(`INSTANCE`)?{...ke(s,d,e,n),definitionRange:_(c)}:i(s,d)},ke=(e,t,n,i)=>{let a=r.index;return O(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:k(),substitutions:D(`WITH`)?A(()=>{let e=T().text;return O(`<-`),{name:e,expression:he()}}):[],isLocal:n,location:i,instanceRange:_(a)}},Ae=()=>{let e=u(b());if(w(`_`)&&b(1).kind===`Operator`)return T(),{name:T().text,arity:D(`_`)?2:1,location:e};if(b().kind===`Operator`&&w(`_`,1)){let t=T().text;return T(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=k();if(!D(`(`))return{name:t,arity:0,location:e};let n=A(()=>O(`_`));return O(`)`),{name:t,arity:n.length,location:e}},je=()=>A(Ae),Me=()=>{let e=je();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ne=e=>{let t={value:0,offset:e};do{let e=b(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&Vc.has(e.text)&&t.value++,e.kind===`Operator`&&Hc.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},Pe=()=>{let e=b(),t=b(1);return e.kind===`Identifier`?w(`(`,1)||w(`[`,1)?w(`==`,Ne(1)):t.kind===`Operator`&&wc.has(t.text)?w(`==`,2):t.kind===`Operator`&&Cc.has(t.text)?b(2).kind===`Identifier`&&w(`==`,3):w(`==`,1):w(`-.`)&&t.kind===`Identifier`&&w(`==`,2)},Fe=[],Ie=()=>Fe[Fe.length-1]??-1,Le=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),I=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)},Re=e=>!e.text.endsWith(`.`)&&!Lc.has(I(e)),ze=e=>{let t=I(e);if(Lc.has(t))return;let n=Le(e);if(n>=0)return`<${n}>${t}`;let r=Ie(),i=Fe[Fe.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Be=e=>{if(e.kind===`Keyword`)return Pc.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Fe.length===0;if(e.text[1]===`+`||Fe.length===0)return!0;let t=Ie();return t>=0&&Le(e)>t},Ve=e=>{let t=Le(e),n=Fe.length-1,r=Fe[n-1]??-1,i=Fe[n]<0;return i&&(Fe[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Fe[n]===t},He=e=>!a.has(e)&&c.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),Ue=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!Uc.has(e.name)&&!He(e.name):!1,We=()=>{let e=b();return e.kind===`Step`?Re(e):e.kind===`Keyword`?Rc.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!Pe()},L=()=>{let e=r.index;s.index=e;let t=b();return t.kind===`Operator`&&!Ec.has(t.text)&&kc(t.text)?(r.index++,v({kind:`OperatorReference`,operator:t.text,location:u(t)},e)):D(`MODULE`)?v({kind:`ModuleFact`,name:k(),location:u(t)},e):N()},Ge=e=>o[o.length-1]?.add(e),Ke=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},qe=e=>o.some(t=>t.has(e))||c.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Je=()=>{let e=r.index,t=b(),n=A(()=>{let e=b();if((e.kind!==`Identifier`||ne(e))&&e.kind!==`Operator`)throw C(`Expected a definition name but found ${x(e)}`,e);return r.index++,e.text},`!`),i=u(t);return v(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ye=()=>{if(t)return A(Je);let e=A(L),n=e.find(e=>e.kind===`Identifier`&&qe(e.name));if(n)throw S(`DEF clause entry should describe a defined operator`,n.location);return e},Xe=()=>({facts:We()?A(L):[],defs:D(`DEF`)||D(`DEFS`)?Ye():[]}),Ze=()=>{let e=r.index,n=T(),i=n.text===`USE`&&D(`ONLY`),a=_(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...Xe(),keyword:a,location:u(n)},s=o.kind===`Hide`&&!t?o.facts.filter(e=>!Ue(e)):[];if(s.length>0)throw m(s.map(t=>({location:h(t.location.range??_(e)),message:`The only expression allowed as a fact in a HIDE is
|
|
102
|
-
the name of a theorem, assumption, or step.`})));return v(o,e)},Qe=()=>{let e=r.index,t=u(b()),n=D(`NEW`),i=b().kind===`Keyword`?zc.get(b().text):void 0;if(!n&&i===void 0)throw C(`Expected a declaration but found ${x(b())}`);if(i!==void 0&&T(),i===`Variable`){let n=k();return Ge(n),v({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Ae();Ge(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(),v({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?N():void 0,location:t},e)},$e=()=>{let e=r.index,t=u(O(`ASSUME`)),n=A(()=>w(`ASSUME`)?Ke($e):b().kind===`Keyword`&&Bc.has(b().text)?Qe():N());return O(`PROVE`),v({kind:`AssumeProve`,assumptions:n,conclusion:N(),location:t},e)},et=e=>{let t={value:0};for(;b(t.value).kind===`Identifier`&&w(`,`,t.value+1);)t.value+=2;return b(t.value).kind===`Identifier`&&w(e,t.value+1)},tt=(e,t)=>{e.forEach(Ge),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(Ge))},nt=()=>{let e=b();if(w(`USE`)||w(`HIDE`))return Ze();if(w(`INSTANCE`))return v(ke(void 0,[],!1,u(e)),r.index);if(w(`DEFINE`)||Pe()){let t=r.index;D(`DEFINE`);let n=[De(!1)];for(;Pe();)n.push(De(!1));let i={kind:`Define`,definitions:n,location:u(e)};return v(i,t)}if(D(`HAVE`))return{kind:`Have`,expression:N()};if(D(`TAKE`)){let e=ce(),t=e?[]:A(k),n=e?fe():[];return tt(t,n),{kind:`Take`,names:t,bounds:n}}if(D(`WITNESS`))return{kind:`Witness`,expressions:A(()=>N())};if(D(`PICK`)){let e=et(`:`),t=e?A(k):[],n=e?[]:fe();return tt(t,n),O(`:`),{kind:`Pick`,names:t,bounds:n,body:N()}}return D(`CASE`)?{kind:`Case`,expression:N()}:{kind:`Assert`,isSuffices:D(`SUFFICES`),statement:w(`ASSUME`)?$e():N()}},rt=e=>{let t=b();if(t.kind!==`Step`)throw C(`Expected a step number but found ${x(t)}`,t);if(!Ve(t))throw S(`${e?`QED step`:`step`}'s number has bad level`,t);if(Le(t)<0&&ze(t)!==void 0)throw S(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:ze(t),token:t.text,location:u(t)}},it=()=>{let e=r.index,t=rt(w(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=D(`QED`)?{kind:`Qed`}:nt(),a=_(e),s=Be(b());if(s&&!Fc.has(i.kind))throw S(`Proof of a step that does not take a proof`);let c=s?ot():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(Ge),v({...t,body:i,head:a,proof:c},e)},at=()=>{let e=u(b());if(w(`BY`)||w(`PROOF`)&&w(`BY`,1)){D(`PROOF`),T();let t=_(r.index-1);return{kind:`By`,isOnly:D(`ONLY`),...Xe(),keyword:t,location:e}}let t=b(+!!w(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){D(`PROOF`),T();let n=_(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}D(`PROOF`);let n=[it()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(it());return{kind:`Steps`,level:Ie(),steps:n,location:e}},ot=()=>{let e=r.index;Fe.push(-1);let t=Ke(at);return Fe.pop(),v(t,e)},st=e=>{let t=r.index,n=T(),i=b().kind===`Identifier`&&w(`==`,1)?k():void 0;i!==void 0&&(a.add(i),T());let o=Ke(()=>({statement:w(`ASSUME`)?$e():N(),proof:Be(b())?ot():void 0})),s=o.statement,c=v({name:i,statement:s,proof:o.proof,location:u(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(v({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:u(n)},t))},ct=()=>{let e=r.index;return v(lt(),e)},lt=()=>{let e=T(),t=u(e),n=e.text===`AXIOM`;if(b().kind===`Identifier`&&w(`==`,1)){let e=k();return a.add(e),T(),{name:e,expression:N(),isAxiom:n,location:t}}return{name:void 0,expression:N(),isAxiom:n,location:t}},ut=()=>{let e=u(O(`----`));O(`MODULE`);let t=k();O(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(c.push(n),i.push(/* @__PURE__ */ new Set),D(`EXTENDS`)&&A(()=>{let e=r.index;n.extends.push(k()),n.extendsRanges.push(_(e))});;){let a=r.index;ee.index=a;let o=b();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}}),c.pop(),i.pop(),n;if(o.kind===`Separator`){if(w(`MODULE`,1)){let e=ut();n.modules.push(e),n.units.push({kind:`Module`,module:e}),O(`====`);continue}T()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{T();let e=je();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{T();let e=A(()=>{let e=r.index,t=u(b());return v({name:k(),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=ct();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=Ze();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:T(),n.units.push({kind:`Recursive`,declarations:Me()});continue;case`INSTANCE`:dt(n,v(ke(void 0,[],!1,u(o)),a));continue;case`LOCAL`:if(T(),w(`INSTANCE`)){dt(n,v(ke(void 0,[],!0,u(o)),a));continue}dt(n,De(!0));continue}o.kind===`Keyword`&&Nc.has(o.text)?st(n):dt(n,De(!1))}}},dt=(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 ut()},qc=e=>Kc(e,!1),Jc=e=>Kc(e,!0),Yc=25214903917n,Xc=(1n<<48n)-1n,Zc=2147483647,Qc=e=>{let t={value:(BigInt.asUintN(64,e)^Yc)&Xc},n=e=>(t.value=t.value*Yc+11n&Xc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^Yc)&Xc},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<=Zc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},$c=10454148508367108822n,el=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:$c);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),tl=Int32Array.from(el,e=>Number(BigInt.asIntN(32,e>>32n))),nl=Int32Array.from(el,e=>Number(BigInt.asIntN(32,e))),rl=Number(BigInt.asIntN(32,$c>>32n)),il=Number(BigInt.asIntN(32,$c));let al=rl,ol=il;const sl=e=>{let t=(e^ol)&255;ol=(ol>>>8|al<<24)^nl[t],al=al>>>8^tl[t]},cl=e=>{for(let t=0;t<32;t+=8)sl(e>>>t)},ll=e=>{if(typeof e==`boolean`)sl(0),sl(e?116:102);else if(typeof e==`number`)sl(1),cl(e);else if(typeof e==`string`){sl(3),cl(e.length);for(let t=0;t<e.length;t++)sl(e.charCodeAt(t))}else if(F(e))sl(21),cl(Ue(e.name)+1);else if(P(e)){let t=H(e);sl(9),cl(t.domain.length);for(let e=0;e<t.domain.length;e++)ll(t.domain[e]),ll(t.range[e])}else{let t=B(e).elements;sl(5),cl(t.length);for(let e of t)ll(e)}},ul=e=>{let t={high:al,low:ol};al=rl,ol=il;for(let t of e)ll(t);let n=BigInt(al>>>0)<<32n|BigInt(ol>>>0);return al=t.high,ol=t.low,n},dl=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||F(e))return 5;if(typeof e==`string`)return 5+e.length;if(P(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+dl(n)+dl(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+dl(t),5)},fl=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){al=n<32?0:1<<n-32,ol=n<32?1<<n:0;for(let t=0;t<e;t++)sl(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]^al,t[n+1]=t[a+1]^ol}}return t},pl=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=[],a=e=>{let t=r.get(e);if(t!==void 0)return t;let n=dl(e);return al=0,ol=0,ll(e),r.set(e,i.length),i.push(n,al,ol),i.length-3},o=e=>{let t=n.get(e);if(t)return t;let r=fl(e);return n.set(e,r),r};return(n,r)=>{let s={high:al,low:ol},c={high:rl,low:il};for(let t of e){let e=a(n[t]),r=o(i[e]),s={high:i[e+1],low:i[e+2]};for(let e=0;e<8;e++){let t=e<4?c.low:c.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=r[n],s.low^=r[n+1]}c.high=s.high,c.low=s.low}al=s.high,ol=s.low,t[2*r]=c.low,t[2*r+1]=c.high}},ml=[],hl=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},gl=()=>{for(let e=1277011;ml.length<1341;e++)hl(e)&&ml.push(e);return ml},_l=e=>{let t=gl(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},vl=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},yl=e=>{for(let t=Math.max(e,9);;t++){let e=vl(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)}}},bl=(e,t,n)=>{if(t<=0)return[];let r=yl(t),i={index:BigInt(n.nextInt(t))},a=BigInt(_l(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},xl=(1n<<63n)-1n-24n,Sl=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(xl*BigInt(n)+i)%t;return r<0n?r+t:r})},Cl=(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,wl=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Ut(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>$e(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>Gt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Tl=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return bl(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=wl(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(Zc)?Sl(e,t,n):bl(e,Number(t),n)).map(e=>r.create(Cl(r.lists,e)))}let i=B(t).elements;return bl(e,i.length,n).map(e=>i[Number(e)])},El=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new v(`RandomElement of the empty set`);return n},Dl=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Ut(e.domain)];return $e(n,n.map(()=>Dl(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Gt(e.names.map((n,r)=>[n,Dl(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Dl(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 v(`RandomElement of the empty set`);return e.low+r}return El(B(e).elements,t)},Ol=(e,t=0n)=>{let n=Qc(t),r={random:Qc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Gt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:ul,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,isStarted:!1,checkDeadlock:e,startedAt:Date.now()};return a},kl=e=>Ft([...e.possibleCounts].map(([e,t])=>[e,t])),Al=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,kl(e)]]),jl=(e,t,n)=>new y(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Ml=(e,t,n,r)=>new y(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Nl=e=>P(e)?H(e):void 0,Pl=(e,t,n)=>{let r=G(e,t,n),i=Nl(r);if(!i)throw jl(n,`a function with a finite domain`,r);return i},Fl=(e,t,n)=>{let r=G(e,t,n),i=Nl(r);if(!i)throw Ml(t===0?`first`:`second`,n,`bag`,r);return i},Il=(e,t)=>{if(!M(e)||!z(e))throw t();return B(e).elements},Ll=e=>e.range.every(e=>typeof e==`number`&&e>0),Rl=(e,t)=>{let n=e.domain.findIndex(e=>et(e,t));return n===-1?void 0:e.range[n]},zl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,Bl=zl(`BagDiff`,`tlc2.value.impl.Value`,2),Vl=zl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),Hl=zl(`BagUnion`,`tlc2.value.impl.Value`,1),Ul=zl(`BagOfAll`,`tlc2.value.impl.Value`,2),Wl=zl(`BagCup`,`tlc2.value.impl.Value`,2),Gl=zl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),Kl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${Dr(e)}`;throw kr(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')`)},ql=(e,t,n)=>{let r=Kl(e,n)+Kl(t,n);if(Sr(r))throw Cr(`${e}+${t}`);return r},Jl=(e,t,n,r)=>{let i=Rl(n,e.domain[t]),a=Kl(e.range[t],r);return i===void 0?a:a-Kl(i,r)|0},Yl=(e,t)=>Ft(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>et(e[0],r));a?a[1]=ql(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),Xl=$e([],[]),Zl=[vr(`EmptyBag`,Xl),K(`IsABag`,1,e=>{let t=Nl(G(e,0,`IsABag`));return t!==void 0&&Ll(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Pl(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw jl(`BagCardinality`,`a bag`,t);return ql(e,n,Gl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=Rl(Pl(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Ml(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=Rl(Pl(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Ml(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Fl(e,t,`(+)`);if(!Ll(n))throw Ml(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return Yl(t,Wl)}),K(`\\ominus`,2,e=>{let t=Fl(e,0,`(-)`),n=Fl(e,1,`(-)`);return Ft(t.domain.flatMap((e,r)=>{let i=Jl(t,r,n,Bl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Il(t,()=>jl(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??Xl;let r=n.map(e=>{let n=Nl(e);if(!n)throw new y(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return Yl(r,Hl)}),K(`\\sqsubseteq`,2,e=>{let t=Pl(e,0,`\\sqsubseteq`),n=Pl(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>Jl(t,r,n,Vl)<=0)}),yr(`BagOfAll`,2,e=>{let t=_r(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new y(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Nl(n);if(!r)throw Ml(`second`,`BagOfAll`,`function with a finite domain`,n);return Yl(r.domain.map((e,n)=>$e([t.call([e])],[r.range[n]])),Ul)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!P(t))throw new v(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=kt(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new v(`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 v(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return kt(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>$e(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>An(Pl(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Il(t,()=>jl(`BagToSet`,`a function with a finite domain`,t));return $e([...n],n.map(()=>1))})],Ql=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,$l=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,eu=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,tu=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,nu=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,ru=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,iu=e=>{if(!P(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},au=(e,t)=>kr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${Dr(t)}`),ou=(e,t)=>kr(e,`Cannot cast tlc2.value.impl.${Dr(t)} to tlc2.value.impl.StringValue`),su=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),cu=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw au(t,e);return`[${B(e).elements.map(e=>uu(e,t)).join(`,`)}]`},lu=(e,t)=>{let n=H(e),r=pn(n);return r?`[${r.map(e=>uu(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${su(typeof e==`string`?e:U(e))}:${uu(n.range[r],t)}`).join(`,`)}}`},uu=(e,t)=>typeof e==`string`?su(e):typeof e==`object`?e.kind===`ModelValue`?su(e.name):M(e)?cu(e,t):lu(e,t):String(e),du=e=>{if(M(e))return cu(e,Ql);if(!P(e)||iu(e))throw au(Ql,e);return lu(e,Ql)},fu=e=>{if(!P(e))throw au($l,e);return lu(e,$l)},pu=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))},mu=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return Ve(e);if(Array.isArray(e))return R(e.map(e=>mu(e,t)));if(typeof e==`object`&&e)return Gt(Object.entries(e).map(([e,n])=>[Ve(e),mu(n,t)]));throw kr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},hu=(e,t)=>{if(e.trim()===``)return mu(null,t);try{return mu(JSON.parse(e,(e,t,n)=>typeof t==`number`?pu(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?kr(t,e.message):e}},gu=(e,t)=>{if(typeof e!=`string`)throw ou(t,e);return e},_u=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw kr(n,`${t} (No such file or directory)`);return r},vu=e=>[br(`ToJson`,1,e=>Ve(uu(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),br(`ToJsonArray`,1,e=>Ve(du(G(e,0,`ToJsonArray`)))),br(`ToJsonObject`,1,e=>Ve(fu(G(e,0,`ToJsonObject`)))),br(`JsonSerialize`,2,t=>{let n=gu(G(t,0,`JsonSerialize`),eu),r=G(t,1,`JsonSerialize`);if(!pn(r)&&!iu(r))throw new y(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,uu(r,eu)),!0}),br(`ndJsonSerialize`,2,t=>{let n=gu(G(t,0,`ndJsonSerialize`),tu),r=G(t,1,`ndJsonSerialize`),i=pn(r);if(!i)throw new y(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${uu(e,tu)}\n`).join(``)),!0}),br(`JsonDeserialize`,1,t=>{let n=gu(G(t,0,`JsonDeserialize`),nu);return hu(_u(e,n,nu),nu)}),br(`ndJsonDeserialize`,1,t=>{let n=gu(G(t,0,`ndJsonDeserialize`),ru);return R(_u(e,n,ru).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>hu(e,ru)))})],yu=(e,t,n,r)=>new y(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),bu=(e,t,n)=>{if(typeof e!=`number`||e<0)throw yu(t,n,`nonnegative integer`,U(e));return e},xu=(e,t,n,r)=>{if(!M(e)||!z(e))throw yu(t,n,r,U(e));return B(e).elements},Su=(e,t,n,r)=>kt(Array.from({length:t},()=>kt(e.filter(()=>r.nextDouble()<n)))),Cu=(e,t)=>{let n=`RandomSetOfSubsets`,r=bu(G(e,0,n),`first`,n),i=bu(G(e,1,n),`second`,n),a=xu(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw yu(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw yu(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Su(a,r,a.length===0?0:i/a.length,t.getRandom())},wu=e=>[br(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw yu(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new v(`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(!M(r)||!V(r)&&!z(r))throw yu(`second`,`RandomSubset`,`a finite set`,U(r));return kt(Tl(n,r,e.getRandom()))}),br(`RandomSetOfSubsets`,3,t=>Cu(t,e)),br(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(Cu(t,e)).elements.length)))],Tu=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Eu=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Tu})`,Du=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Tu}) throws java.io.IOException`,Ou=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Tu})`,ku=()=>Gt([[`action`,kt([])],[`state`,kt([])]]),Au=()=>Gt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ju=e=>Gt([[`name`,e??`UnnamedAction`],[`location`,Au()]]),Mu=(e,t)=>{let n=e.map((e,t)=>R([t+1,Gt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ju(e[r+1].action),t])),i=t?[R([n[n.length-1],ju(t.action),n[t.start]])]:[];return Gt([[`action`,kt([...r,...i])],[`state`,kt(n)]])},Nu=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Al(e).get(t)},Pu=(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 y(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(n)}`)},Fu=e=>e.every(e=>e!==void 0),Iu=(e,t)=>Gt(t.variables.map((t,n)=>[t,e[n]])),Lu=(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=jo(r,t);if(e&&!n.has(e)&&(n.add(e),Lu(e.body,t,n)))return!0}return ar(e).some(e=>Lu(e,t,n))},Ru=(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=et(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),Ir(`AssertError`,2,e=>{let t=_r(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw kr(Eu,`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 v)return e.message===n;throw e}return!1}),br(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Nu(t,n)??G(e,1,`TLCGetOrDefault`)}),{...yr(`TLCGetAndSet`,4,n=>{let r=G(n,0,`TLCGetAndSet`),i=Nu(t,r)??G(n,3,`TLCGetAndSet`),a=_r(n,1,`TLCGetAndSet`);return Pu(t,e,r,a.call([i,G(n,2,`TLCGetAndSet`)])),i}),isStateLevel:!0},br(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Fu(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw kr(Du,`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=>Iu(e,n.environment)))}),br(`CounterExample`,0,()=>t.counterExample??ku()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!P(t)||!et(An(t),kt([`action`,`state`])))throw new v(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(On(t,`state`)).elements.map(e=>pn(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 y(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Ze(t)}),Ir(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),Ir(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Fu(r))throw kr(Ou,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Ao(Lr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new ne(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),Ir(`TLCCache`,2,(e,t)=>{let r=_r(e,0,`TLCCache`),a=Jn(Lr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=Lu(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,ul([G(e,0,`TLCFP`)])))),br(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?jo(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new y(`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 y(`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)})]},zu=(e,t)=>[br(`_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}),br(`_Counts`,0,()=>kl(t)),br(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(kl(t),!0)),!1)}),br(`_PrintCounts`,0,()=>(e(U(kl(t),!0)),!0))],Bu=e=>String(e).padStart(2,`0`),Vu=e=>`${e.getUTCFullYear()}.${Bu(e.getUTCMonth()+1)}.${Bu(e.getUTCDate())}.${Bu(e.getUTCHours())}${Bu(e.getUTCMinutes())}${Bu(e.getUTCSeconds())}`,Hu=e=>Ft([...e].map(([e,t])=>[e,R([t])])),Uu=/* @__PURE__ */ new Set([`diameter`,`generated`,`distinct`,`queue`,`stats`,`config`]),Wu=(e,t,n)=>{if(!e.isStarted&&Uu.has(t))throw new v(`TLCGet(${t}) was undefined.`);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 Gt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Gt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Gt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,Ve(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,Ve(Vu(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ju(void 0);case`all`:return Hu(e.registers);case`all:named`:return Hu(Al(e))}if(t.startsWith(`s:`)){let n=Al(e).get(t);if(n===void 0)throw new v(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return Ve(e.properties.get(t.slice(2))??t);throw new v(`TLCGet(${t}) was undefined.`)},Gu=e=>e.length===0?[[]]:e.flatMap((t,n)=>Gu([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),Ku=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(Ku),e.kind===`Function`&&e.range.forEach(Ku))},qu=(t,n)=>[K(`Print`,2,e=>(t(`${Ee(U(G(e,0,`Print`),!0,!0))} ${Ee(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(Ee(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new y(`The first argument of Assert evaluated to FALSE; the second argument was:\n${Ee(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>Ft([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=gr(e,0,`@@`),n=gr(e,1,`@@`);return It([...je(t),...je(n)])}),K(`ToString`,1,e=>Ve(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return Ku(t),t}),K(`Permutations`,1,e=>{let t=mr(e,0,`Permutations`);return kt(Gu(t).map(e=>Ft(t.map((t,n)=>[t,e[n]]))))}),yr(`SortSeq`,2,e=>{let t=_r(e,1,`SortSeq`);return R(hr(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)]},[]))}),br(`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 v(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new v(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return Wu(n,r,t?.state)}),br(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`);return Pu(n,t,r,G(e,1,`TLCSet`)),!0}),vr(`Any`,qe),K(`RandomElement`,1,e=>Dl(fr(e,0,`RandomElement`),n.getRandom()))],Ju=/* @__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(`,`),Yu=[[`\\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`,`≀`],[`^+`,`⁺`]],Xu=/* @__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(`,`),Zu=/* @__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(`.`),Qu=/* @__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(`.`),$u=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
|
|
100
|
+
=============================================================================`]]),Ac=`tlc2/value/impl/`,jc=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)}},Mc=e=>[...e.slice(1,e.indexOf(`)`)).matchAll(/\[*(?:L[^;]*;|[BCDFIJSZ])/g)].length,Nc=e=>{let t=jc(e);if(t.readUint32()!==3405691582)throw new p(`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:Mc(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}},Pc=(e,t)=>e[e[t].first].text,Fc=(e,t)=>{let n=e[t],r=e[n.second];return{className:Pc(e,n.first),name:e[r.first].text}},Ic=(e,t,n,r)=>{let i=()=>new T(`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=Fc(t,l());if(n.className!==`${Ac}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=Fc(t,l()),a=s();if(n.className!==`${Ac}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:Pc(t,l()),value:void 0}),e+=3;else if(n===183){let n=Fc(t,l()),a=s(),o=s();if(!(n.className===`${Ac}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()},Lc=(e,t)=>{if(!t)return e;let n=Nc(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:Ic(r,n.pool,e.name,t.location)}:t});return{...e,definitions:r}},$=(e,t,n)=>({low:e,high:t,isAssociative:n}),Rc=new Map([[`=>`,$(1,1,!1)],[`<=>`,$(2,2,!1)],[`~>`,$(2,2,!1)],[`-+->`,$(2,2,!1)],[`/\\`,$(3,3,!0)],[`\\/`,$(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,$(5,5,!1)]),[`\\cdot`,$(5,14,!0)],[`@@`,$(6,6,!0)],[`:>`,$(7,7,!1)],[`<:`,$(7,7,!1)],[`\\cup`,$(8,8,!0)],[`\\cap`,$(8,8,!0)],[`\\`,$(8,8,!1)],[`..`,$(9,9,!1)],[`...`,$(9,9,!1)],[`##`,$(9,13,!0)],[`$`,$(9,13,!0)],[`$$`,$(9,13,!0)],[`??`,$(9,13,!0)],[`!!`,$(9,13,!1)],[`\\sqcap`,$(9,13,!0)],[`\\sqcup`,$(9,13,!0)],[`\\uplus`,$(9,13,!0)],[`\\wr`,$(9,14,!1)],[`+`,$(10,10,!0)],[`++`,$(10,10,!0)],[`(+)`,$(10,10,!0)],[`\\oplus`,$(10,10,!0)],[`%`,$(10,11,!1)],[`%%`,$(10,11,!0)],[`|`,$(10,11,!0)],[`||`,$(10,11,!0)],[`\\X`,$(10,13,!1)],[`-`,$(11,11,!0)],[`--`,$(11,11,!0)],[`(-)`,$(11,11,!0)],[`\\ominus`,$(11,11,!0)],[`*`,$(13,13,!0)],[`**`,$(13,13,!0)],[`/`,$(13,13,!1)],[`//`,$(13,13,!1)],[`\\div`,$(13,13,!1)],[`\\o`,$(13,13,!0)],[`(.)`,$(13,13,!0)],[`\\odot`,$(13,13,!0)],[`(/)`,$(13,13,!1)],[`\\oslash`,$(13,13,!1)],[`(\\X)`,$(13,13,!0)],[`\\otimes`,$(13,13,!0)],[`&`,$(13,13,!0)],[`&&`,$(13,13,!0)],[`\\star`,$(13,13,!0)],[`\\bullet`,$(13,13,!0)],[`\\bigcirc`,$(13,13,!0)],[`^`,$(14,14,!1)],[`^^`,$(14,14,!1)]]),zc=/* @__PURE__ */ new Set([`^+`,`^*`,`^#`]),Bc=/* @__PURE__ */ new Set([`-`,`~`,`-.`]),Vc=/* @__PURE__ */ new Set([`-`,`~`,`/\\`,`\\/`,`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`]),Hc=/* @__PURE__ */ new Set([`+`,`-`,`/`,`\\X`]),Uc=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`,`'`,...zc]),Wc=e=>Rc.has(e)||zc.has(e)||e===`-.`,Gc=(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}}},Kc=/* @__PURE__ */ new Set([`<<`,`>>`,`:`,`@`,`(`]),qc=/* @__PURE__ */ new Set([`ASSUME`,`ASSUMPTION`,`AXIOM`,`CONSTANT`,`CONSTANTS`,`COROLLARY`,`INSTANCE`,`LEMMA`,`LOCAL`,`PROPOSITION`,`RECURSIVE`,`THEOREM`,`VARIABLE`,`VARIABLES`]),Jc=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Yc=/* @__PURE__ */ new Set([`BY`,`PROOF`,`OBVIOUS`,`OMITTED`]),Xc=/* @__PURE__ */ new Set([`Qed`,`Pick`,`Case`,`Assert`]),Zc=/* @__PURE__ */ new Set(/* @__PURE__ */ `, . _ ( ) [ ] { } << >> ]_ >>_ == ! @ : :: ; -> <- |-> \\A \\AA \\E \\EE \\forall \\exists WF_ SF_ (*{ }*)`.split(` `)),Qc=/* @__PURE__ */ new Set([``,`*`,`-`]),$c=/* @__PURE__ */ new Set([`CASE`,`CHOOSE`,`DOMAIN`,`ENABLED`,`IF`,`LAMBDA`,`LET`,`SF_`,`SUBSET`,`UNCHANGED`,`UNION`,`WF_`]),el=/* @__PURE__ */ new Map([[`CONSTANT`,`Constant`],[`CONSTANTS`,`Constant`],[`VARIABLE`,`Variable`],[`VARIABLES`,`Variable`],[`STATE`,`State`],[`ACTION`,`Action`],[`ACTIONS`,`Action`],[`TEMPORAL`,`Temporal`],[`TEMPORALS`,`Temporal`]]),tl=/* @__PURE__ */ new Set([`NEW`,...el.keys()]),nl=/* @__PURE__ */ new Set([`(`,`[`,`{`,`<<`]),rl=/* @__PURE__ */ new Set([`)`,`]`,`}`,`>>`,`]_`,`>>_`]),il=/* @__PURE__ */ new Set([`TRUE`,`FALSE`,`BOOLEAN`,`STRING`]),al=e=>RegExp(`^-{4,}\\s*MODULE\\s+${e}\\s*-{3,}$`),ol=(e,t)=>{let n=e.split(/\r?\n/),r=n.findIndex(e=>al(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(`
|
|
101
|
+
`)},sl=(e,t)=>{let n=ue(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},c=[],l=e=>i[i.length-1].has(e),u=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),d=[],f=[],h=[],_=e=>{let t=r.index-1,i=e===t?h[e]:void 0;if(i)return i;let a=n[t];d[e]??=u(n[e]),f[t]??={line:a.line,column:a.endColumn};let o={module:c[c.length-1].name,start:d[e],end:f[t]};return e===t&&(h[e]=o),o},v=(e,t)=>(e.location.range=_(t),e),y=(e=0)=>n[Math.min(r.index+e,n.length-1)],b=(e=0)=>{let t=y(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},ee=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),x={index:0},S=e=>{let t=n.slice(x.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},C=e=>t&&(e.kind===`Keyword`||il.has(e.text)),w=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},T=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Zc.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):C(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,te=(e,t=y(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new p(`${e} at line ${t.line}, column ${t.column}`,void 0,ne(e,t,a,r))},ne=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...S(w(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${T(a)}`,...w(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},E=(e,t=y())=>te(e,t,t),D=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!C(e),O=(e,t=0)=>{let n=b(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},k=()=>{let e=b();if(e.kind===`End`)throw te(`Unexpected end of expression`);return r.index++,e},A=e=>O(e)?(r.index++,!0):!1,j=e=>{if(!O(e))throw E(`Expected ${JSON.stringify(e)} but found ${ee(b())}`);return k()},M=()=>{let e=b();if(e.kind!==`Identifier`)throw E(`Expected an identifier but found ${ee(e)}`);if(C(e))throw E(`Unexpected keyword ${e.text}`);return r.index++,e.text},ie=e=>{r.offsideColumns.push(-1);let t=e();return r.offsideColumns.pop(),t},ae=(e,t=`,`)=>{let n=[e()];for(;A(t);)n.push(e());return n},oe=()=>{if(O(`<<`)){let e={value:1};for(;b(e.value).kind===`Identifier`||O(`,`,e.value);)e.value++;return O(`>>`,e.value)&&O(`\\in`,e.value+1)}let e={value:0};for(;b(e.value).kind===`Identifier`;){if(O(`\\in`,e.value+1))return!0;if(!O(`,`,e.value+1))return!1;e.value+=2}return!1},se=()=>{if(O(`::`))return!0;if(!O(`(`))return!1;let e={value:1};for(;b(e.value).kind===`Identifier`&&O(`,`,e.value+1);)e.value+=2;return b(e.value).kind===`Identifier`&&O(`)`,e.value+1)&&O(`::`,e.value+2)},ce=()=>{if(!A(`<<`))return{kind:`Name`,name:M()};let e=ae(M);return j(`>>`),{kind:`Tuple`,names:e}},le=()=>ae(()=>{let e=ae(ce);j(`\\in`);let t=P();return e.map(e=>({pattern:e,set:t}))}).flat(),de=()=>{let e=b();if(e.kind===`Identifier`){let t=r.index,n=[k().text];for(;O(`!`)&&b(1).kind===`Identifier`;)k(),n.push(M());return v({kind:`Identifier`,name:n.join(`!`),location:u(e)},t)}if(O(`<<`)||O(`(`))return Te();throw E(`Expected a subscript but found ${ee(e)}`)},fe=e=>{let t=b(1),n=b(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`&&O(`==`,zc.has(n.text)?3:4))},N=e=>{if(!Vc.has(e.text))return!0;let t=b(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||O(`,`,1)||O(`)`,1)||t.kind===`Keyword`&&qc.has(t.text)||fe(e)},pe=()=>{let e=b(),n=e.kind===`Operator`&&(Rc.has(e.text)||Bc.has(e.text))&&N(e);if(t&&e.kind!==`String`&&(Bc.has(e.text)||Uc.has(e.text)&&e.text!==`'`&&!zc.has(e.text)||Hc.has(e.text)&&b(-1).text===`(`&&b(-1).line===e.line&&b(-1).endColumn+1===e.column&&b(1).text===`)`&&b(1).line===e.line&&b(1).column===e.endColumn+1)&&N(e))throw te(`incomplete expression`,e);if(n)return r.index++,v({kind:`OperatorReference`,operator:e.text,location:u(e)},r.index-1);if(e.kind!==`String`&&Uc.has(e.text)&&N(e)){r.index++;let t=u(e);if(zc.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:Gc(e.text,n,t),location:t}}if(O(`LAMBDA`)){let t=r.index;k();let n=ae(M);j(`:`);let i=P();return v({kind:`Lambda`,params:n,body:i,location:u(e)},t)}let i=P();return i.kind===`Identifier`&&me.delete(i),i},me=/* @__PURE__ */ new Map,he={range:void 0},ge=()=>ie(()=>{let e=r.index;j(`(`);let t=ae(pe);return j(`)`),he.range=_(e),t}),_e=()=>{let e=k();r.offsideColumns.push(e.column);let t=[P()];for(;y().text===e.text&&y().column===e.column;)r.index++,t.push(P());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:u(e)}},ve=e=>ie(()=>{let t=u(e);if(b().kind===`Identifier`&&(O(`|->`,1)||O(`:`,1))){let e=O(`|->`,1)?`Record`:`RecordSet`,n=ae(()=>{let t=r.index,n=u(b()),i=M();return n.range=_(t),j(e===`Record`?`|->`:`:`),{name:i,value:P(),location:n}});return j(`]`),{kind:e,fields:n,location:t}}if(oe()){let e=le();j(`|->`);let n=P();return j(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=P();if(A(`->`)){let e=P();return j(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(A(`EXCEPT`)){let e=ae(()=>{j(`!`);let e=[];for(;O(`.`)||O(`[`);)if(A(`.`)){if(!D(b()))throw E(`Expected a field name but found ${ee(b())}`);e.push({kind:`Field`,name:k().text})}else j(`[`),e.push({kind:`Index`,args:ae(()=>P())}),j(`]`);return j(`=`),{path:e,value:P()}});return j(`]`),{kind:`Except`,function:n,updates:e,location:t}}return j(`]_`),{kind:`BoxAction`,action:n,subscript:de(),location:t}}),ye=e=>ie(()=>{let t=u(e);if(A(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(oe()&&(b(1).text===`\\in`||O(`<<`))){let e=r.index,n=ce();j(`\\in`);let i=P();if(A(`:`)){let e=P();return j(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=P();if(A(`:`)){let e=le();return j(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;A(`,`);)i.push(P());return j(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),be=e=>{let t=u(e),n=ie(()=>O(`>>`)||O(`>>_`)?[]:ae(()=>P()));if(A(`>>_`)){if(n.length!==1)throw te(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:de(),location:t}}return j(`>>`),{kind:`Tuple`,elements:n,location:t}},xe=e=>{let t=u(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&oe()){let e=le();return j(`:`),{kind:n,bounds:e,body:P(),location:t}}let i=ae(M);return j(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:P(),isTemporal:r,location:t}},Se=e=>{let t=[];do{if(A(`OTHER`))return j(`->`),{kind:`Case`,arms:t,other:P(),location:u(e)};let n=P();j(`->`),t.push({condition:n,body:P()})}while(A(`[]`));return{kind:`Case`,arms:t,other:void 0,location:u(e)}},Ce=()=>{let e=b(1);return O(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||Kc.has(e.text)||e.kind===`Operator`&&(Rc.has(e.text)||zc.has(e.text)||Bc.has(e.text)))},we=()=>{let e=k();if(e.kind===`Number`)return{kind:`Operand`,operand:re(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:ge()}}return{kind:`Name`,name:e.text,args:O(`(`)?ge():[]}},Te=()=>{let e=r.index,n=e===s.index,a=k(),o=u(a);if(t&&a.kind===`Keyword`&&a.text===`LAMBDA`){let e=ae(M);return j(`:`),{kind:`Lambda`,params:e,body:P(),location:o}}if(a.kind===`Number`){if(t&&/^\\[BOH]/.test(a.text))throw te(`incomplete expression`,a);return{kind:`Number`,value:re(a.text),text:a.text,location:o}}if(a.kind===`Decimal`)return{kind:`Decimal`,text:a.text,location:o};if(a.kind===`String`)return{kind:`String`,value:a.text,location:o};let l=a.kind===`Step`&&Le(a);if(l&&Ie()<0&&Fe.length<=1)throw te(`Step number used outside proof`,a);if(l&&a.text[1]===`+`)throw te(`<+> step number used in an expression`,a);if(a.kind===`Identifier`||l){let r=l?z(a)??a.text:a.text;if(se()){let e=A(`(`)?ae(M):[];return e.length>0&&j(`)`),j(`::`),{kind:`Label`,name:r,params:e,body:P(),location:o}}let i=O(`(`),s=i?ge():[];if(!Ce())return i?{kind:`Apply`,operator:r,args:s,argumentsRange:he.range,location:o}:{kind:`Identifier`,name:r,location:o};let u=c.flatMap(e=>e.instances).find(e=>e.name===r),d=u!==void 0&&!n&&!t&&u.params.length!==s.length;if(d&&s.length>0)throw te(`The operator ${r} requires ${u.params.length} arguments`,a);let f=[{kind:`Name`,name:r,args:s}];for(;Ce();)k(),f.push(we());let p=f.flatMap(e=>e.kind===`Name`?[e.name]:[]),m=p.join(`!`),h=f.flatMap(e=>`args`in e?e.args:[]),v=f.map(e=>`args`in e?e.args.length:0),y=he.range,b=p.length<f.length?{kind:`Subexpression`,selectors:f,location:o}:h.length===0?{kind:`Identifier`,name:m,location:o}:v.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:m,args:h,argumentCounts:v,argumentsRange:y,location:o}:{kind:`Apply`,operator:m,args:h,argumentsRange:y,location:o};return d&&me.set(b,{location:g(_(e)),message:`The operator ${r} requires ${u.params.length} arguments.`}),b}if(a.kind===`Operator`&&Wc(a.text)&&O(`(`))return{kind:`Apply`,operator:a.text,args:ge(),location:o};switch(a.text){case`(`:{let e=ie(()=>P());return j(`)`),e}case`[`:return ve(a);case`{`:return ye(a);case`<<`:return be(a);case`@`:return{kind:`ExceptAt`,location:o};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return xe(a);case`IF`:{let e=P();j(`THEN`);let t=P();return j(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:P(),location:o}}case`CASE`:return Se(a);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!A(`IN`);){if(t&&O(`RECURSIVE`))throw te(`Unexpected keyword RECURSIVE`,S(y()));if(A(`RECURSIVE`)){Ne();continue}let r=ke(!1);r.kind===`Instance`?n.push(r):e.push(r)}i.pop();let r=P();return n.length===0?{kind:`Let`,definitions:e,body:r,location:o}:{kind:`Let`,definitions:e,instances:n,body:r,location:o}}case`CHOOSE`:{let e=ce(),t=A(`\\in`)?P():void 0;return j(`:`),{kind:`Choose`,pattern:e,set:t,body:P(),location:o}}case`WF_`:case`SF_`:{let e=de(),t=ie(()=>{j(`(`);let e=P();return j(`)`),e});return{kind:a.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:o}}}throw E(`Unexpected ${ee(a)}`,a)},Ee=()=>{let e=b(),t=u(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return _e();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return k(),{kind:`Apply`,operator:`~`,args:[P(5)],location:t};case`-`:return k(),{kind:`Apply`,operator:`-.`,args:[P(13)],location:t};case`[]`:return k(),{kind:`Always`,expression:P(16),location:t};case`<>`:return k(),{kind:`Eventually`,expression:P(16),location:t};case`ENABLED`:return k(),{kind:`Enabled`,expression:P(16),location:t};case`UNCHANGED`:return k(),{kind:`Unchanged`,expression:P(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return k(),{kind:`Apply`,operator:e.text,args:[P(9)],location:t}}return Te()},P=(e=0)=>{let t=r.index,n=Ee(),i={left:n.location.range?n:v(n,t),previous:void 0};for(;;){let n=b();if(n.kind!==`Operator`)break;let r=u(n);if(n.text===`'`&&e<=15){k(),i.left=v({kind:`Prime`,expression:i.left,location:r},t);continue}if(zc.has(n.text)&&e<=15){k(),i.left=v({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){k();let e=ie(()=>ae(()=>P()));ie(()=>j(`]`)),i.left=v({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&D(b(1))){k();let e=k().text;i.left=v({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=Rc.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 te(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(k(),a.low>12&&O(`-`))throw te(`Precedence conflict between ${n.text} and -`,b());let s=P(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=v(i.left,t),i.previous={...a,text:n.text}}return i.left},De=()=>{if(!A(`(`))return[];let e=F();return j(`)`),e},Oe=()=>{let e=u(b()),t=P(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:c[c.length-1].name,start:e,end:a}}},ke=e=>{let t=r.index;return v(Ae(e),t)},Ae=e=>{let t=b(),n=u(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...Oe(),isLocal:e,isRecursive:l(t),location:n});if(t.kind===`Identifier`&&b(1).kind===`Operator`&&Rc.has(b(1).text)&&b(2).kind===`Identifier`&&O(`==`,3)){let e=M(),t=k().text,n=M();return j(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&zc.has(b(1).text)&&O(`==`,2);if(a||o){let e=a?t.text:b(1).text;r.index+=a?1:2;let n=a?M():t.text;return j(`==`),i(e,[{name:n,arity:0}])}let s=M();if(A(`[`)){let t=ie(()=>le());return j(`]`),j(`==`),{kind:`Function`,name:s,bounds:t,body:P(),isLocal:e,isRecursive:l(s),location:n}}let c=r.index,d=De();return j(`==`),O(`INSTANCE`)?{...je(s,d,e,n),definitionRange:_(c)}:i(s,d)},je=(e,t,n,i)=>{let a=r.index;return j(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:M(),substitutions:A(`WITH`)?ae(()=>{let e=k().text;return j(`<-`),{name:e,expression:pe()}}):[],isLocal:n,location:i,instanceRange:_(a)}},Me=()=>{let e=u(b());if(O(`_`)&&b(1).kind===`Operator`)return k(),{name:k().text,arity:A(`_`)?2:1,location:e};if(b().kind===`Operator`&&O(`_`,1)){let t=k().text;return k(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=M();if(!A(`(`))return{name:t,arity:0,location:e};let n=ae(()=>j(`_`));return j(`)`),{name:t,arity:n.length,location:e}},F=()=>ae(Me),Ne=()=>{let e=F();return e.forEach(e=>i[i.length-1].add(e.name)),e},Pe=e=>{let t={value:0,offset:e};do{let e=b(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&nl.has(e.text)&&t.value++,e.kind===`Operator`&&rl.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},I=()=>{let e=b(),t=b(1);return e.kind===`Identifier`?O(`(`,1)||O(`[`,1)?O(`==`,Pe(1)):t.kind===`Operator`&&zc.has(t.text)?O(`==`,2):t.kind===`Operator`&&Rc.has(t.text)?b(2).kind===`Identifier`&&O(`==`,3):O(`==`,1):O(`-.`)&&t.kind===`Identifier`&&O(`==`,2)},Fe=[],Ie=()=>Fe[Fe.length-1]??-1,L=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),R=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)},Le=e=>!e.text.endsWith(`.`)&&!Qc.has(R(e)),z=e=>{let t=R(e);if(Qc.has(t))return;let n=L(e);if(n>=0)return`<${n}>${t}`;let r=Ie(),i=Fe[Fe.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},B=e=>{if(e.kind===`Keyword`)return Yc.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Fe.length===0;if(e.text[1]===`+`||Fe.length===0)return!0;let t=Ie();return t>=0&&L(e)>t},Re=e=>{let t=L(e),n=Fe.length-1,r=Fe[n-1]??-1,i=Fe[n]<0;return i&&(Fe[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Fe[n]===t},V=e=>!a.has(e)&&c.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),H=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!il.has(e.name)&&!V(e.name):!1,U=()=>{let e=b();return e.kind===`Step`?Le(e):e.kind===`Keyword`?$c.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!I()},W=()=>{let e=r.index;s.index=e;let t=b();return t.kind===`Operator`&&!Vc.has(t.text)&&Wc(t.text)?(r.index++,v({kind:`OperatorReference`,operator:t.text,location:u(t)},e)):A(`MODULE`)?v({kind:`ModuleFact`,name:M(),location:u(t)},e):P()},ze=e=>o[o.length-1]?.add(e),Be=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},Ve=e=>o.some(t=>t.has(e))||c.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),He=()=>{let e=r.index,t=b(),n=ae(()=>{let e=b();if((e.kind!==`Identifier`||C(e))&&e.kind!==`Operator`)throw E(`Expected a definition name but found ${ee(e)}`,e);return r.index++,e.text},`!`),i=u(t);return v(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ue=()=>{if(t)return ae(He);let e=ae(W),n=e.find(e=>e.kind===`Identifier`&&Ve(e.name));if(n)throw te(`DEF clause entry should describe a defined operator`,n.location);return e},We=()=>({facts:U()?ae(W):[],defs:A(`DEF`)||A(`DEFS`)?Ue():[]}),Ge=()=>{let e=r.index,n=k(),i=n.text===`USE`&&A(`ONLY`),a=_(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...We(),keyword:a,location:u(n)},s=o.kind===`Hide`&&!t?o.facts.filter(e=>!H(e)):[];if(s.length>0)throw m(s.map(t=>({location:g(t.location.range??_(e)),message:`The only expression allowed as a fact in a HIDE is
|
|
102
|
+
the name of a theorem, assumption, or step.`})));return v(o,e)},Ke=()=>{let e=r.index,t=u(b()),n=A(`NEW`),i=b().kind===`Keyword`?el.get(b().text):void 0;if(!n&&i===void 0)throw E(`Expected a declaration but found ${ee(b())}`);if(i!==void 0&&k(),i===`Variable`){let n=M();return ze(n),v({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Me();ze(a.name);let o=(i??`Constant`)===`Constant`&&O(`\\in`);if(o&&a.arity>0)throw te(`declared symbol with arguments before \\in`);return o&&k(),v({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?P():void 0,location:t},e)},qe=()=>{let e=r.index,t=u(j(`ASSUME`)),n=ae(()=>O(`ASSUME`)?Be(qe):b().kind===`Keyword`&&tl.has(b().text)?Ke():P());return j(`PROVE`),v({kind:`AssumeProve`,assumptions:n,conclusion:P(),location:t},e)},Je=e=>{let t={value:0};for(;b(t.value).kind===`Identifier`&&O(`,`,t.value+1);)t.value+=2;return b(t.value).kind===`Identifier`&&O(e,t.value+1)},Ye=(e,t)=>{e.forEach(ze),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(ze))},Xe=()=>{let e=b();if(O(`USE`)||O(`HIDE`))return Ge();if(O(`INSTANCE`))return v(je(void 0,[],!1,u(e)),r.index);if(O(`DEFINE`)||I()){let t=r.index;A(`DEFINE`);let n=[ke(!1)];for(;I();)n.push(ke(!1));let i={kind:`Define`,definitions:n,location:u(e)};return v(i,t)}if(A(`HAVE`))return{kind:`Have`,expression:P()};if(A(`TAKE`)){let e=oe(),t=e?[]:ae(M),n=e?le():[];return Ye(t,n),{kind:`Take`,names:t,bounds:n}}if(A(`WITNESS`))return{kind:`Witness`,expressions:ae(()=>P())};if(A(`PICK`)){let e=Je(`:`),t=e?ae(M):[],n=e?[]:le();return Ye(t,n),j(`:`),{kind:`Pick`,names:t,bounds:n,body:P()}}return A(`CASE`)?{kind:`Case`,expression:P()}:{kind:`Assert`,isSuffices:A(`SUFFICES`),statement:O(`ASSUME`)?qe():P()}},Ze=e=>{let t=b();if(t.kind!==`Step`)throw E(`Expected a step number but found ${ee(t)}`,t);if(!Re(t))throw te(`${e?`QED step`:`step`}'s number has bad level`,t);if(L(t)<0&&z(t)!==void 0)throw te(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:z(t),token:t.text,location:u(t)}},Qe=()=>{let e=r.index,t=Ze(O(`QED`,1)),n=r.index,i=/* @__PURE__ */ new Set;o.push(i);let a=A(`QED`)?{kind:`Qed`}:Xe(),s=_(e),c=_(n),l=B(b());if(l&&!Xc.has(a.kind))throw te(`Proof of a step that does not take a proof`);let u=l?et():void 0;return o.pop(),(a.kind!==`Assert`||a.isSuffices)&&i.forEach(ze),v({...t,body:a,head:s,statement:c,proof:u},e)},$e=()=>{let e=u(b());if(O(`BY`)||O(`PROOF`)&&O(`BY`,1)){A(`PROOF`),k();let t=_(r.index-1);return{kind:`By`,isOnly:A(`ONLY`),...We(),keyword:t,location:e}}let t=b(+!!O(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){A(`PROOF`),k();let n=_(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}A(`PROOF`);let n=[Qe()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(Qe());return{kind:`Steps`,level:Ie(),steps:n,location:e}},et=()=>{let e=r.index;Fe.push(-1);let t=Be($e);return Fe.pop(),v(t,e)},tt=e=>{let t=r.index,n=k(),i=b().kind===`Identifier`&&O(`==`,1)?M():void 0;i!==void 0&&(a.add(i),k());let o=Be(()=>({statement:O(`ASSUME`)?qe():P(),proof:B(b())?et():void 0})),s=o.statement,c=v({name:i,statement:s,proof:o.proof,location:u(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(v({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:u(n)},t))},nt=()=>{let e=r.index;return v(rt(),e)},rt=()=>{let e=k(),t=u(e),n=e.text===`AXIOM`;if(b().kind===`Identifier`&&O(`==`,1)){let e=M();return a.add(e),k(),{name:e,expression:P(),isAxiom:n,location:t}}return{name:void 0,expression:P(),isAxiom:n,location:t}},G=()=>{let e=u(j(`----`));j(`MODULE`);let t=M();j(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(c.push(n),i.push(/* @__PURE__ */ new Set),A(`EXTENDS`)&&ae(()=>{let e=r.index;n.extends.push(M()),n.extendsRanges.push(_(e))});;){let a=r.index;x.index=a;let o=b();if(o.kind===`ModuleEnd`||o.kind===`End`){if(o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),me.size>0)throw m([...me.values()]);return c.pop(),i.pop(),n}if(o.kind===`Separator`){if(O(`MODULE`,1)){let e=G();n.modules.push(e),n.units.push({kind:`Module`,module:e}),j(`====`);continue}k()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{k();let e=F();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{k();let e=ae(()=>{let e=r.index,t=u(b());return v({name:M(),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=nt();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=Ge();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:k(),n.units.push({kind:`Recursive`,declarations:Ne()});continue;case`INSTANCE`:K(n,v(je(void 0,[],!1,u(o)),a));continue;case`LOCAL`:if(k(),O(`INSTANCE`)){K(n,v(je(void 0,[],!0,u(o)),a));continue}K(n,ke(!0));continue}o.kind===`Keyword`&&Jc.has(o.text)?tt(n):K(n,ke(!1))}}},K=(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 G()},cl=e=>sl(e,!1),ll=e=>sl(e,!0),ul=25214903917n,dl=(1n<<48n)-1n,fl=2147483647,pl=e=>{let t={value:(BigInt.asUintN(64,e)^ul)&dl},n=e=>(t.value=t.value*ul+11n&dl,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^ul)&dl},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<=fl)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},ml=10454148508367108822n,hl=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:ml);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),gl=Int32Array.from(hl,e=>Number(BigInt.asIntN(32,e>>32n))),_l=Int32Array.from(hl,e=>Number(BigInt.asIntN(32,e))),vl=Number(BigInt.asIntN(32,ml>>32n)),yl=Number(BigInt.asIntN(32,ml));let bl=vl,xl=yl;const Sl=e=>{let t=(e^xl)&255;xl=(xl>>>8|bl<<24)^_l[t],bl=bl>>>8^gl[t]},Cl=e=>{for(let t=0;t<32;t+=8)Sl(e>>>t)},wl=e=>{if(typeof e==`boolean`)Sl(0),Sl(e?116:102);else if(typeof e==`number`)Sl(1),Cl(e);else if(typeof e==`string`){Sl(3),Cl(e.length);for(let t=0;t<e.length;t++)Sl(e.charCodeAt(t))}else if(F(e))Sl(21),Cl(Ve(e.name)+1);else if(Me(e)){let t=bn(e);Sl(9),Cl(t.domain.length);for(let e=0;e<t.domain.length;e++)wl(t.domain[e]),wl(t.range[e])}else{let t=q(e).elements;Sl(5),Cl(t.length);for(let e of t)wl(e)}},Tl=e=>{let t={high:bl,low:xl};bl=vl,xl=yl;for(let t of e)wl(t);let n=BigInt(bl>>>0)<<32n|BigInt(xl>>>0);return bl=t.high,xl=t.low,n},El=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||F(e))return 5;if(typeof e==`string`)return 5+e.length;if(Me(e)){let t=bn(e);return t.domain.reduce((e,n,r)=>e+El(n)+El(t.range[r]),5)}return q(e).elements.reduce((e,t)=>e+El(t),5)},Dl=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){bl=n<32?0:1<<n-32,xl=n<32?1<<n:0;for(let t=0;t<e;t++)Sl(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]^bl,t[n+1]=t[a+1]^xl}}return t},Ol=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=[],a=e=>{let t=r.get(e);if(t!==void 0)return t;let n=El(e);return bl=0,xl=0,wl(e),r.set(e,i.length),i.push(n,bl,xl),i.length-3},o=e=>{let t=n.get(e);if(t)return t;let r=Dl(e);return n.set(e,r),r};return(n,r)=>{let s={high:bl,low:xl},c={high:vl,low:yl};for(let t of e){let e=a(n[t]),r=o(i[e]),s={high:i[e+1],low:i[e+2]};for(let e=0;e<8;e++){let t=e<4?c.low:c.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=r[n],s.low^=r[n+1]}c.high=s.high,c.low=s.low}bl=s.high,xl=s.low,t[2*r]=c.low,t[2*r+1]=c.high}},kl=[],Al=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},jl=()=>{for(let e=1277011;kl.length<1341;e++)Al(e)&&kl.push(e);return kl},Ml=e=>{let t=jl(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Nl=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},Pl=e=>{for(let t=Math.max(e,9);;t++){let e=Nl(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)}}},Fl=(e,t,n)=>{if(t<=0)return[];let r=Pl(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Ml(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Il=(1n<<63n)-1n-24n,Ll=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Il*BigInt(n)+i)%t;return r<0n?r+t:r})},Rl=(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,zl=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Bt(e.domain),n=q(e.range).elements;return{lists:t.map(()=>n),create:e=>Qe(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>q(e).elements),create:t=>Ut(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>q(e).elements),create:Ht}}},Bl=(e,t,n)=>{if(sn(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Fl(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=zl(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(fl)?Ll(e,t,n):Fl(e,Number(t),n)).map(e=>r.create(Rl(r.lists,e)))}let i=q(t).elements;return Fl(e,i.length,n).map(e=>i[Number(e)])},Vl=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new y(`RandomElement of the empty set`);return n},Hl=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Bt(e.domain)];return Qe(n,n.map(()=>Hl(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Ut(e.names.map((n,r)=>[n,Hl(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return Ht(e.factors.map(e=>Hl(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 y(`RandomElement of the empty set`);return e.low+r}return Vl(q(e).elements,t)},Ul=(e,t=0n)=>{let n=pl(t),r={random:pl(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Ut([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Tl,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,isStarted:!1,checkDeadlock:e,startedAt:Date.now()};return a},Wl=e=>Mt([...e.possibleCounts].map(([e,t])=>[e,t])),Gl=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Wl(e)]]),Kl=[[38,[`ACTION`,`ACTIONS`]],[39,[`ASSUME`]],[40,[`[]ASSUME`]],[41,[`ASSUMPTION`,`AXIOM`]],[42,[`CASE`]],[43,[`CHOOSE`]],[44,[`CONSTANT`,`CONSTANTS`]],[45,[`ELSE`]],[46,[`EXCEPT`]],[47,[`\\E`,`\\exists`,`∃`]],[48,[`EXTENDS`]],[49,[`\\A`,`\\forall`,`∀`]],[50,[`IF`]],[51,[`INSTANCE`]],[52,[`LET`]],[53,[`IN`]],[54,[`LOCAL`]],[55,[`MODULE`]],[56,[`NEW`]],[57,[`OTHER`]],[58,[`PROPOSITION`,`LEMMA`,`COROLLARY`]],[59,[`SF_`]],[60,[`\\EE`]],[61,[`\\AA`]],[62,[`THEN`]],[63,[`BY`]],[64,[`ONLY`]],[65,[`DEFINE`]],[66,[`DEF`,`DEFS`]],[67,[`THEOREM`]],[68,[`USE`]],[69,[`HIDE`]],[70,[`HAVE`]],[71,[`OBVIOUS`]],[72,[`OMITTED`]],[73,[`LAMBDA`]],[74,[`TAKE`]],[75,[`PROOF`]],[76,[`PROVE`]],[77,[`[]PROVE`]],[78,[`QED`]],[79,[`RECURSIVE`]],[80,[`STATE`]],[81,[`TEMPORAL`,`TEMPORALS`]],[82,[`PICK`]],[83,[`WITNESS`]],[84,[`SUFFICES`]],[85,[`VARIABLE`,`VARIABLES`]],[86,[`WF_`]],[87,[`WITH`]],[88,[`,`]],[89,[`:`]],[90,[`::`,`∷`]],[91,[`.`]],[92,[`_`]],[93,[`==`,`≜`]],[94,[`(`]],[95,[`)`]],[96,[`-|-`]],[97,[`[`]],[98,[`]_`]],[99,[`]`]],[100,[`{`]],[101,[`}`]],[102,[`<<`,`⟨`]],[103,[`>>_`,`⟩_`]],[104,[`>>`,`⟩`]],[105,[`!`]],[106,[`->`,`→`]],[107,[`<-`,`←`]],[108,[`|->`,`↦`]],[113,[`'`]],[114,[`^+`,`⁺`]],[115,[`^*`]],[116,[`^#`]],[117,[`-.`]],[118,[`\\lnot`,`¬`]],[119,[`\\neg`]],[120,[`~`]],[121,[`[]`,`□`]],[122,[`<>`,`◇`]],[123,[`ENABLED`]],[124,[`UNCHANGED`]],[125,[`SUBSET`]],[126,[`UNION`]],[127,[`DOMAIN`]],...[`//`,`/\\`,`/=`,`/`,`\\/`,`\\approx`,`\\asymp`,`\\bigcirc`,`\\bullet`,`\\cap`,`\\cdot`,`\\circ`,`\\cong`,`\\cup`,`\\div`,`\\doteq`,`\\equiv`,`\\geq`,`\\gg`,`\\in`,`\\intersect`,`\\union`,`\\land`,`\\leq`,`\\ll`,`\\lor`,`\\o`,`\\odot`,`\\ominus`,`\\oplus`,`\\oslash`,`\\otimes`,`\\prec`,`\\preceq`,`\\propto`,`\\sim`,`\\simeq`,`\\sqcap`,`\\sqcup`,`\\sqsubset`,`\\sqsupset`,`\\sqsubseteq`,`\\sqsupseteq`,`\\star`,`\\subset`,`\\subseteq`,`\\succ`,`\\succeq`,`\\supset`,`\\supseteq`,`\\uplus`,`\\wr`,`\\`,`~>`,`=>`,`=<`,`=|`,`=`,`##`,`#`,`^^`,`^`,`--`,`-|`,`-+->`,`-`,`**`,`*`,`++`,`+`,`<=>`,`<:`,`<=`,`<`,`>=`,`>`,`...`,`..`,`||`,`|`,`|-`,`|=`,`&&`,`&`,`$$`,`$`,`??`,`%%`,`%`,`@@`,`!!`,`:>`,`:=`,`::=`,`(+)`,`(-)`,`(.)`,`(/)`,`(\\X)`,`\\notin`,...`≈≔≍◯⩴●∩⋅∘≅∪÷≐‥…≡‼≥≫⇔⇒⫤↝≤≪⊣≠∉⊙⊖⊕⊘⊗⇸≺⪯∝⁇⊨⊢∼≃⊓⊔⊏⊑⊐⊒⋆⊂⊆≻⪰⊃⊇×⊎‖≀`,`\\times`,`\\X`].map((e,t)=>[128+t,[e]]),[129,[`∧`]],[132,[`∨`]],[147,[`∈`]]],ql=(()=>{let e=/* @__PURE__ */ new Map;for(let t of Kl)for(let n of t[1])e.set(n[0],[...e.get(n[0])??[],[t[0],n]]);return e})(),Jl=/-{4,} *MODULE/y,Yl=[/[0-9][A-Za-z0-9]*\.\/\\/y,/[WS][a-zA-EG-Z0-9][A-Za-z0-9]*\.\/\\/y,/[a-zA-RT-VX-Z][A-Za-z0-9]*\.\/\\/y],Xl=[/[0-9][A-Za-z0-9]*\.\\\//y,/[WS][a-zA-EG-Z0-9][A-Za-z0-9]*\.\\\//y,/[a-zA-RT-VX-Z][A-Za-z0-9]*\.\\\//y],Zl=[/_[A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*/y,/[0-9][A-Za-z0-9_]*[A-Za-z][A-Za-z0-9_]*/y,/[WS](?:[a-zA-EG-Z_0-9][A-Za-z0-9_]*)?/y,/[WS]F(?:[A-Za-z0-9][A-Za-z0-9_]*)?/y,/[a-zA-RT-VX-Z][A-Za-z0-9_]*/y,/[@ℕℤℝ]/y],Ql=[[35,[Jl]],[36,[/-{4,}/y]],[37,[/={4,}/y]],[109,[/[0-9]+|\\[oO][0-7]+|\\[bB][01]+|\\[hH][0-9a-fA-F]+/y]],[110,[/"(?:[^"\n\r\\]|\\[ntrf\\"])*"/y]],[111,Yl],[112,Xl],[289,Zl],[290,[/<[0-9]+>[A-Za-z0-9_]+/y]],[291,[/<[+*]>[A-Za-z0-9]+/y]],[292,[/<(?:[0-9]+|\+|\*)>[A-Za-z0-9_]+\.+/y]],[293,[/<(?:[0-9]+|\+|\*)>/y]],[294,[/<(?:[0-9]+|\+|\*)>(?:\*\.*|-\.*|\.+)/y]]],$l=[[20,[/[0-9]+/y]],[21,[Jl]],[111,Yl],[112,Xl],[289,Zl]],eu=(e,t,n)=>Math.max(0,...e.map(e=>(e.lastIndex=n,e.exec(t)?.[0].length??0))),tu=(e,t,n,r)=>{let i=n.map(([n,r])=>[n,eu(r,e,t)]);if(r)for(let[n,r]of ql.get(e[t])??[])e.startsWith(r,t)&&i.push([n,r.length]);return i.reduce((e,t)=>t[1]>e[1]||t[1]===e[1]&&t[1]>0&&t[0]<e[0]?t:e,[0,0])},nu=(e,t)=>{if(e[t]===`?`)return 1;if(e[t]!==`"`)return 0;let n=/"(?:[^"\n\r\\]|\\[ntrf\\"])*\\?/y;return n.lastIndex=t,n.exec(e)?.[0].length??0},ru=/* @__PURE__ */ new Map([[`\b`,`\\b`],[` `,`\\t`],[`
|
|
103
|
+
`,`\\n`],[`\f`,`\\f`],[`\r`,`\\r`],[`"`,`\\"`],[`'`,`\\'`],[`\\`,`\\\\`],[`\0`,``]]),iu=e=>e.split(``).map(e=>{let t=e.charCodeAt(0);return ru.get(e)??(t<32||t>126?`\\u${t.toString(16).padStart(4,`0`)}`:e)}).join(``),au=e=>{let t=[],n=[],r={line:1,column:0,isAfterCarriageReturn:!1,isAfterLineFeed:!1};for(let i of e.split(``))r.column++,r.isAfterLineFeed?(r.isAfterLineFeed=!1,r.line++,r.column=1):r.isAfterCarriageReturn&&(r.isAfterCarriageReturn=!1,i===`
|
|
104
|
+
`?r.isAfterLineFeed=!0:(r.line++,r.column=1)),i===`\r`&&(r.isAfterCarriageReturn=!0),i===`
|
|
105
|
+
`&&(r.isAfterLineFeed=!0),i===` `&&(r.column=r.column-1+(8-(r.column-1)%8)),t.push(r.line),n.push(r.column);let i={state:0,index:0,commentDepth:0},a=(r,i,a)=>({kind:r,image:e.slice(i,a),beginLine:t[i],beginColumn:n[i],endLine:t[a-1],endColumn:n[a-1],next:void 0}),o=(r,i,a)=>{if(a!==void 0&&a+1<e.length)throw new h(`Lexical error at line ${t[a]}, column ${n[a]}. Encountered: "${iu(e[a])}" (${e.charCodeAt(a)}), after : "${iu(i)}"`);let o=e.length-1,s=e[o]===`
|
|
106
|
+
`||e[o]===`\r`,c=`Lexical error at line ${s?t[o]+1:t[o]}, column ${s?0:n[o]+1}. Encountered: <EOF> after : "${iu(i)}"`;throw new h(t[r]===t[o]?c:`Lexical {error: EOF reached, possibly open comment starting around line ${t[r]}`)},s=t=>{for(;;){if(i.index>=e.length)return o(t,``,void 0);let n=e.startsWith(`(*.`,i.index)?3:e.startsWith(`(*`,i.index)?2:0;if(i.state===5){let t=e.startsWith(`\r
|
|
107
|
+
`,i.index)?2:+(e[i.index]===`
|
|
108
|
+
`||e[i.index]===`\r`);if(t>0){i.index+=t,i.state=2;return}}else if(n>0){i.index+=n,i.commentDepth++,i.state=4;return}else if(e.startsWith(`*)`,i.index)){i.index+=2,i.state===3?i.state=2:(i.commentDepth--,i.commentDepth===0&&(i.state=3));return}i.index++}};return{getNextToken:()=>{for(;;){if(i.index>=e.length){let r=e.length-1;return{kind:0,image:``,beginLine:t[r]??0,beginColumn:n[r]??0,endLine:t[r]??0,endColumn:n[r]??0,next:void 0}}let r=i.index;if(i.state===0){let t=e.startsWith(`--->`,i.index)?4:0;Jl.lastIndex=i.index;let n=Jl.exec(e)?.[0].length??0;if(n>0&&n>=t)return i.index+=n,i.state=2,a(3,r,i.index);if(t>0)return i.index+=t,i.state=1,a(2,r,i.index);i.index++;continue}if(i.state===1){let[t,n]=tu(e,i.index,$l,!1);if(n===0){i.index++;continue}return i.index+=n,t===21&&(i.state=2),a(t,r,i.index)}if(i.state!==2){s(r);continue}if(`
|
|
109
|
+
\r`.includes(e[i.index])){i.index++;continue}if(e.startsWith(`(*`,i.index)||e.startsWith(`\\*`,i.index)){i.state=e[i.index]===`(`?3:5,i.index+=e.startsWith(`(*.`,i.index)?3:2,s(r);continue}let[c,l]=tu(e,i.index,Ql,!0);if(l===0){let t=nu(e,i.index),n=i.index+t;return n<e.length?o(r,n+1<e.length||t===0?e.slice(r,n):e.slice(r,n+1),n):o(r,t<=1?``:e.slice(r),void 0)}return i.index+=l,a(c,r,i.index)}}}},ou=2147483647,su=-2147483648,cu=(e,t)=>Array.from({length:t-e+1},(t,n)=>e+n),lu=cu(118,127),uu=cu(117,127),du=cu(128,288),fu=cu(113,116),pu=cu(290,294),mu=[42,43,47,49,50,52,60,61],hu=new Set(cu(113,291)),gu=/* @__PURE__ */ new Set([59,86,94,97,100,102]),_u=/* @__PURE__ */ new Set([38,44,56,80,81,85]),vu=/* @__PURE__ */ new Set([92,...uu]),yu=/* @__PURE__ */ new Set([`Tuple`,`ParenExpr`,`SetEnumerate`,`SubsetOf`,`SetOfAll`,`SetOfFcns`,`RcdConstructor`,`SetOfRcds`,`Except`,`FcnConst`,`ActionExpr`]),bu=[[`[`,160,160,`left`,`postfix`],[`.`,170,170,`left`,`infix`],[`'`,150,150,`none`,`postfix`],[`^`,140,140,`none`,`infix`],[`/`,130,130,`none`,`infix`],[`*`,130,130,`left`,`infix`],[`-`,110,110,`left`,`infix`],[`-.`,120,120,`none`,`prefix`],[`+`,100,100,`left`,`infix`],[`=`,50,50,`none`,`infix`],[`\\lnot`,40,40,`left`,`prefix`],[`\\land`,30,30,`left`,`infix`],[`\\lor`,30,30,`left`,`infix`],[`~>`,20,20,`none`,`infix`],[`=>`,10,10,`none`,`infix`],[`[]`,40,150,`none`,`prefix`],[`<>`,40,150,`none`,`prefix`],[`ENABLED`,40,150,`none`,`prefix`],[`UNCHANGED`,40,150,`none`,`prefix`],[`SUBSET`,100,130,`none`,`prefix`],[`UNION`,100,130,`none`,`prefix`],[`DOMAIN`,100,130,`none`,`prefix`],[`^+`,150,150,`none`,`postfix`],[`^*`,150,150,`none`,`postfix`],[`^#`,150,150,`none`,`postfix`],[`\\cdot`,50,140,`left`,`infix`],[`\\equiv`,20,20,`none`,`infix`],[`-+->`,20,20,`none`,`infix`],[`/=`,50,50,`none`,`infix`],[`\\subseteq`,50,50,`none`,`infix`],[`\\in`,50,50,`none`,`infix`],[`\\notin`,50,50,`none`,`infix`],[`<`,50,50,`none`,`infix`],[`\\leq`,50,50,`none`,`infix`],[`>`,50,50,`none`,`infix`],[`\\geq`,50,50,`none`,`infix`],[`\\times`,100,130,`left`,`nfix`],[`\\`,80,80,`none`,`infix`],[`\\intersect`,80,80,`left`,`infix`],[`\\union`,80,80,`left`,`infix`],[`...`,90,90,`none`,`infix`],[`..`,90,90,`none`,`infix`],[`|`,100,110,`left`,`infix`],[`||`,100,110,`left`,`infix`],[`&&`,130,130,`left`,`infix`],[`&`,130,130,`left`,`infix`],[`$$`,90,130,`left`,`infix`],[`$`,90,130,`left`,`infix`],[`??`,90,130,`left`,`infix`],[`%%`,100,110,`left`,`infix`],[`%`,100,110,`none`,`infix`],[`##`,90,130,`left`,`infix`],[`++`,100,100,`left`,`infix`],[`--`,110,110,`left`,`infix`],[`**`,130,130,`left`,`infix`],[`//`,130,130,`none`,`infix`],[`^^`,140,140,`none`,`infix`],[`@@`,60,60,`left`,`infix`],[`!!`,90,130,`none`,`infix`],[`|-`,50,50,`none`,`infix`],[`|=`,50,50,`none`,`infix`],[`-|`,50,50,`none`,`infix`],[`=|`,50,50,`none`,`infix`],[`<:`,70,70,`none`,`infix`],[`:>`,70,70,`none`,`infix`],[`:=`,50,50,`none`,`infix`],[`::=`,50,50,`none`,`infix`],[`\\oplus`,100,100,`left`,`infix`],[`\\ominus`,110,110,`left`,`infix`],[`\\odot`,130,130,`left`,`infix`],[`\\oslash`,130,130,`none`,`infix`],[`\\otimes`,130,130,`left`,`infix`],[`\\uplus`,90,130,`left`,`infix`],[`\\sqcap`,90,130,`left`,`infix`],[`\\sqcup`,90,130,`left`,`infix`],[`\\div`,130,130,`none`,`infix`],[`\\wr`,90,140,`none`,`infix`],[`\\star`,130,130,`left`,`infix`],[`\\o`,130,130,`left`,`infix`],[`\\bigcirc`,130,130,`left`,`infix`],[`\\bullet`,130,130,`left`,`infix`],[`\\prec`,50,50,`none`,`infix`],[`\\succ`,50,50,`none`,`infix`],[`\\preceq`,50,50,`none`,`infix`],[`\\succeq`,50,50,`none`,`infix`],[`\\sim`,50,50,`none`,`infix`],[`\\simeq`,50,50,`none`,`infix`],[`\\ll`,50,50,`none`,`infix`],[`\\gg`,50,50,`none`,`infix`],[`\\asymp`,50,50,`none`,`infix`],[`\\subset`,50,50,`none`,`infix`],[`\\supset`,50,50,`none`,`infix`],[`\\supseteq`,50,50,`none`,`infix`],[`\\approx`,50,50,`none`,`infix`],[`\\cong`,50,50,`none`,`infix`],[`\\sqsubset`,50,50,`none`,`infix`],[`\\sqsubseteq`,50,50,`none`,`infix`],[`\\sqsupset`,50,50,`none`,`infix`],[`\\sqsupseteq`,50,50,`none`,`infix`],[`\\doteq`,50,50,`none`,`infix`],[`\\propto`,50,50,`none`,`infix`]].map(e=>({name:e[0],low:e[1],high:e[2],associativity:e[3],fix:e[4]})),xu=[[`\\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`,`≀`],[`^+`,`⁺`]],Su=(()=>{let e=new Map(bu.map(e=>[e.name,e]));for(let t of xu){let n=e.get(t[0]);if(n)for(let r of t.slice(1))e.set(r,n)}return e})(),Cu=Su.get(`[`),wu={name:`$$_void`,low:0,high:0,associativity:`none`,fix:`infix`},Tu=e=>e.fix===`prefix`?e:Su.get(`${e.name}.`),Eu=e=>e.fix===`infix`||e.fix===`nfix`,Du=(e,t)=>e.low>t.high,Ou=(e,t)=>e.high<t.low,ku=e=>e!==void 0&&e.kind>=113&&e.kind<=288,Au=e=>e!==void 0&&e.kind>=128&&e.kind<=288,ju=(e,t)=>{let n=e[t];if(n.kind===95||n.kind===99){let n={index:t,depth:1};for(;n.index>0;){n.index--;let t=e[n.index].kind,r=t===94||t===97;if(r&&n.depth===1)break;r&&n.depth--,(t===95||t===99)&&n.depth++}return n.index>0&&e[n.index-1].kind===289?n.index-1:n.index}if(n.kind===289){let n=e[t-1];return!ku(n)||n.kind>=113&&n.kind<=116||Au(n)&&e[t-2]?.kind!==289||e[t-2]?.kind===107?t:Au(n)?t-2:t-1}return ku(n)?t-1:t},Mu=e=>e.kind>=38&&e.kind<=46||e.kind===48||e.kind>=50&&e.kind<=59||e.kind===80||e.kind>=62&&e.kind<=87||e.kind===92||e.kind>=123&&e.kind<=127,Nu=e=>e.image[1]===`*`?-1:e.image[1]===`+`?-2:Number.parseInt(e.image.slice(1,e.image.indexOf(`>`))),Pu=e=>{let t=au(e),n=[],r={kind:0,image:``,beginLine:0,beginColumn:0,endLine:0,endColumn:0,next:void 0},i={token:r,nextKind:-1,generation:0,expectedGeneration:-1,moduleName:void 0,expecting:``,lastOperator:void 0,fairnessHook:void 0,proofDepth:-1,operatorStack:void 0},a={scanPosition:r,lastPosition:r,remaining:0,isSucceeded:!1,isLookingAhead:!1,isRescanning:!1,endPosition:0,longestExpected:0},o=[],s=[],c=[],l=[],u=[],d=e=>e.next??=t.getNextToken(),f=e=>Array.from({length:e}).reduce(e=>d(e),a.isLookingAhead?a.scanPosition:i.token),p=()=>i.nextKind===-1?i.nextKind=d(i.token).kind:i.nextKind,m=()=>(i.expectedGeneration=i.generation,!1),g=e=>p()===e||m(),_=e=>`line ${e.location[0]}, col ${e.location[1]} to line ${e.location[2]}, col ${e.location[3]} of module ${i.moduleName??`null`}`,v=e=>new h(`***Parse Error***\n${i.expecting===``?``:`Was expecting "${i.expecting}"\n`}${e}\n\nResidual stack trace follows:\n${s.slice(-5).reverse().map(e=>`${e.name} starting at line ${e.token.beginLine}, column ${e.token.beginColumn}.\n`).join(``)}`),y=e=>{e>=100||(e===a.endPosition+1?a.endPosition++:a.endPosition!==0&&(a.longestExpected=Math.max(a.longestExpected,a.endPosition),e!==0&&(a.endPosition=e)))},b=(e,t)=>e===void 0||t>=100?void 0:e===a.scanPosition?t:b(e.next,t+1),ee=e=>{a.scanPosition===a.lastPosition&&(a.remaining--,a.lastPosition=d(a.scanPosition)),a.scanPosition=d(a.scanPosition);let t=a.isRescanning?b(i.token,0):void 0;return t!==void 0&&y(t),e.has(a.scanPosition.kind)?(a.remaining===0&&a.scanPosition===a.lastPosition&&(a.isSucceeded=!0),!0):!1},x=e=>{if(typeof e!=`number`)return e;let t=/* @__PURE__ */ new Set([e]);return()=>ee(t)},S=(...e)=>{let t=new Set(e);return()=>ee(t)},C=(...e)=>{let t=e.map(x);return()=>{for(let e of t){if(!e())return!1;if(a.isSucceeded)return!0}return!0}},w=(...e)=>{let t=e.map(x);return()=>{let e=a.scanPosition;for(let n of t)if(a.scanPosition=e,n())return!0;return!1}},T=e=>{let t=x(e);return()=>{let e=a.scanPosition;return t()||(a.scanPosition=e),!0}},te=e=>{let t=x(e);return()=>{for(;;){let e=a.scanPosition;if(!t())return a.scanPosition=e,!0;if(a.isSucceeded)return!0}}},ne=(e,t)=>{let n=x(t);return()=>{a.isLookingAhead=!0;let t=e();return a.isLookingAhead=!1,t&&n()}},E=e=>l.length===0||l[l.length-1].column<e,D=()=>E(f(1).beginColumn),O=()=>{let e=f(1),t=l.at(-1);return t!==void 0&&(e.kind===129||e.kind===132)&&t.column===e.beginColumn&&t.isConjunction===(e.kind===129)},k=()=>f(1).kind===39||f(1).kind===40,A=()=>k()||f(2).kind===90&&(f(3).kind===39||f(3).kind===40),j=()=>{let e=i.operatorStack?.at(-1)?.operator;return i.operatorStack===void 0||i.operatorStack.length===0||e!==void 0&&e.fix!==`postfix`},re=()=>{let e=d(a.isLookingAhead?a.scanPosition:i.token);if(e.kind===102){let t={token:e,depth:1};for(;t.depth!==0;)if(t.token=d(t.token),t.token.kind===102&&t.depth++,t.token.kind===104&&t.depth--,t.token.kind===0)return!1;return d(t.token).kind===147}if(e.kind!==289)return!1;let t={token:d(e)};for(;t.token.kind===88;){let e=d(t.token);if(e.kind!==289)return!1;t.token=d(e)}return t.token.kind===147},M=()=>je(),ie=()=>we(),ae=C(102,T(C(289,te(C(88,289)))),104),oe=w(ae,289),se=C(91,109),ce=C(109,T(se)),le=C(94,M),ue=w(ne(re,oe),M,M,M),de=C(100,T(ue),101),fe=C(97,w(ne(re,oe),289,ne(()=>f(2).kind===108&&Mu(f(1)),289),289,M)),N=C(102,T(M),S(104,103)),pe=C(S(132,129),M),me=C(T(54),96,S(289,...uu)),he=w(me,79),ge=C(289,T(94)),_e=S(92,...uu),ve=C(94,w(ne(D,S(...uu,...du,...fu)),ne(D,73),M)),ye=C(56,44),be=C(ge,T(147)),xe=C(w(ye,56,44),w(be,_e)),Se=C(T(56),85,289),Ce=C(T(56),S(80,38,81),w(ge,_e)),we=C(T(C(289,90,ie)),S(39,40),w(ne(A,ie),w(xe,Se,Ce),M),te(88),S(76,77)),Te=C(T(96),289,93),Ee=C(289,93),P=x(75),De=C(T(84),w(M,ne(k,ie))),Oe=w(ne(D,110),ne(D,ce),C(S(289,290,291,...du,...fu,...uu),T(ve),te(105))),ke=w(ne(D,S(...fu)),ne(D,91),ne(D,fe)),Ae=w(ne(D,S(...du)),ne(D,90)),je=C(te(S(...lu,...du)),w(ne(D,w(C(S(47,49),w(289,oe)),C(S(60,61),289),C(50,M),C(42,M),C(52,he,te(he)),C(43,w(289,ae)))),ne(D,C(w(ne(j,w(pe,pe)),w(le,de,fe,N,C(S(86,59),w(289,le,de,fe,N))),Oe),te(ke),T(Ae))))),Me={moduleUnit:[w(36,85,44,me,79,C(T(54),51,289),C(S(41,39),T(Te),M),C(S(67,58),T(Ee),w(ne(k,ie),M)),S(35,3,21),ne(()=>f(1).kind===68&&f(2).kind!==64||f(1).kind===69,w(C(T(75),63),68,69))),1],unitDefinition:[me,2],unitInstance:[C(T(54),51,289),2],unitAssumption:[C(S(41,39),T(Te),M),2],unitTheorem:[C(S(67,58),T(Ee),w(ne(k,ie),M)),2],constantArguments:[C(94,92),2],definitionBody:[M,1],functionDefinition:[C(289,97),ou],postfixDefinition:[C(289,S(...fu)),ou],infixDefinition:[C(289,S(...du)),ou],identifierDefinition:[C(289,S(94,93)),ou],nextSubstitution:[C(88,S(289,...uu,...du,...fu),107),3],assumptionName:[Te,2],assumeExpression:[M,1],nextAssumeExpression:[M,1],newConstant:[ye,2],constantDeclaration:[be,2],constantSymbol:[xe,2],variableSymbol:[Se,2],levelSymbol:[Ce,2],theoremName:[Ee,2],theoremAssumeProve:[ne(k,ie),3],theoremExpression:[M,1],proofKeyword:[P,2],terminalProof:[C(T(75),S(71,72)),2],stepProof:[C(T(P),te(S(...pu)),S(...pu)),1],usedExpression:[M,1],nextUsedExpression:[M,1],usedFacts:[w(55,M),1],definedExpression:[M,1],nextDefinedExpression:[M,1],assertStep:[De,1],nextDefinition:[me,2],takeBounds:[w(C(289,te(C(88,289)),147),102),ou],pickIdentifiers:[C(289,te(C(88,289)),89),ou],assertedExpression:[M,1],decimalPart:[se,2],operatorArgument:[C(S(...uu,...du,...fu),S(88,95,96,54,51,67,39,37,36,35,41,44,85,79)),2],lambdaArgument:[x(73),ou],expressionArgument:[M,1],unboundQuantifier:[C(289,te(C(88,289)),89),ou],setEnumeration:[C(oe,88),ou],setOfAll:[C(oe,89),ou],setExpression:[M,1],setContents:[ue,1],recordFields:[C(289,108),ou],recordSets:[C(289,89),ou],bracketExpression:[M,1],tupleContents:[M,1],identifierArguments:[ve,2],fairnessArguments:[C(94,M),2],disjunctionList:[x(132),ou],conjunctionList:[x(129),ou],leadingOperator:[S(...lu,193),ou],openExpression:[S(...mu),ou],junctionList:[S(129,132),ou],primitiveExpression:[Oe,1],expressionSuffix:[ke,1],postfixSuffix:[S(...fu),ou],recordSuffix:[x(91),ou],applicationSuffix:[x(97),ou],nextLeadingOperator:[S(...lu,193),ou],nextOpenExpression:[S(...mu),ou],infixContinuation:[S(...du),ou],labelContinuation:[x(90),ou],expressionContinuation:[Ae,1],negativeOperator:[x(117),ou],primitiveArguments:[ve,2],stringLiteral:[x(110),ou],numberLiteral:[x(109),ou],bangIdentifier:[x(289),ou],bangArguments:[ve,2],bangOperand:[w(ne(()=>f(1).image!==`@`,289),S(...uu),S(...du),S(...fu)),1],structureOperator:[w(102,104,89,ce,ne(()=>f(1).image===`@`,289)),1]},F=Object.keys(Me),Ne=F.map(()=>[{generation:0,first:void 0,amount:0}]),Pe=(e,t,n)=>(a.remaining=n,a.scanPosition=t,a.lastPosition=t,a.isSucceeded=!1,e()),I=e=>{let t=Me[e][1],n=Pe(Me[e][0],i.token,t),r=Ne[F.indexOf(e)],o=r.find(e=>e.generation<=i.generation)??r[r.push({generation:0,first:void 0,amount:0})-1];return o.generation=i.generation+t-a.remaining,o.first=i.token,o.amount=t,n},Fe=(e,t)=>t===0?[]:e.kind===0?[`<EOF>`]:[e.image,...Fe(d(e),t-1)],Ie=(e=-1)=>{a.longestExpected=+(e>=0||i.expectedGeneration===i.generation),a.endPosition=0,a.isRescanning=!0,Object.values(Me).forEach((e,t)=>{for(let n of Ne[t])if(!(n.generation<=i.generation||n.first===void 0)&&(Pe(e[0],n.first,n.amount),a.isSucceeded))break}),a.isRescanning=!1,y(0);let t=d(i.token);return v(`Encountered "${Fe(t,a.longestExpected).join(` `)}" at line ${t.beginLine}, column ${t.beginColumn} and token "${iu(i.token.image)}" `)},L=()=>(d(i.token),i.nextKind=-1,Ie()),R=e=>{let t=i.token;if(i.token=d(i.token),i.nextKind=-1,i.token.kind===e)return i.generation++,i.token;throw i.token=t,Ie(e)},Le=e=>{if(e.includes(p()))return R(p());throw m(),L()},z=(e,t=e.kind)=>({kind:t,image:e.image,location:[e.beginLine,e.beginColumn,e.endLine,e.endColumn],heirs:[]}),B=(e,...t)=>{let n=t.flatMap(e=>e??[]),r=[ou,ou,su,su];for(let e of n)(e.location[0]<r[0]||e.location[0]===r[0]&&e.location[1]<r[1])&&(r[0]=e.location[0],r[1]=e.location[1]),(e.location[2]>r[2]||e.location[2]===r[2]&&e.location[3]>r[3])&&(r[2]=e.location[2],r[3]=e.location[3]);return{kind:e,image:e,location:r,heirs:n}},Re=()=>B(`IdPrefix`),V=e=>c.push(e),H=()=>{let e=c.lastIndexOf(void 0)+1;if(e!==c.length)return c.splice(e).filter(e=>e!==void 0)},U=e=>{c.push(void 0),s.push({name:e,token:f(1)}),i.expecting=``},W=()=>{s.pop(),c.pop(),i.expecting=``},ze=(e,t)=>{U(e);let n=t();return W(),n},Be=(e,t)=>ze(e,()=>{let e=t();return B(e,H())}),Ve=e=>{Mu(e)&&(e.kind=289)},He=()=>{let e=[i.token,d(i.token)];for(;;){let t=e[e.length-1],n=d(t);if([0,67,58,41,37].includes(n.kind)||t.kind===67||t.kind===58)return;if(t.kind===93)break;e.push(n)}let t=ju(e,e.length-2);if(t<=0||e[t-1].kind===96)return;let n=e[t];e[t-1].next={kind:96,image:`Beginning of definition`,beginLine:n.beginLine,beginColumn:n.beginColumn,endLine:n.endLine,endColumn:n.endColumn,next:n}},Ue=(e,t)=>i.operatorStack?.push({node:e,operator:t}),We=()=>i.operatorStack??[],Ge=e=>We()[e].node??B(`Missing`),Ke=e=>{let t=We(),n=t.length-1;if(n<3)return;let r=Ge(n-2),i=Ge(n-3),a=Ge(n-1);t.splice(n-2,2);let o=e.fix===`nfix`&&i.kind===`Times`?B(`Times`,i.heirs,[r,a]):B(e.fix===`nfix`?`Times`:`InfixExpr`,[i,r,a]);t[n-3]={node:o,operator:void 0}},qe=()=>{let e=We(),t=e.length-1;if(t<2)return;let n=B(`PrefixExpr`,[Ge(t-2),Ge(t-1)]);e.splice(t-1,1),e[t-2]={node:n,operator:void 0}},Je=()=>{let e=We(),t=e.length-1;if(t<2)return;let n=Ge(t-1),r=e[t-1].operator===Cu?B(`FcnAppl`,[Ge(t-2)],n.heirs):B(`PostfixExpr`,[Ge(t-2),n]);e.splice(t-1,1),e[t-2]={node:r,operator:void 0}},Ye=()=>{let e=We();for(;;){let t=e.length-1,n=e[t],r=n.operator;if(r===void 0)return;let i=_(n.node??B(`Missing`));if(r.fix===`postfix`){if(t===0)throw v(`\n Encountered postfix op ${r.name} in block ${i} on empty stack`);let n=e[t-1];if(n.operator!==void 0){if(Eu(n.operator)||n.operator.fix===`prefix`)throw v(`\n Encountered postfix op ${r.name} in block ${i} following prefix or infix op ${n.operator.name}.`);Je()}else{if(t<=1)return;let n=e[t-2].operator;if(n===void 0)throw v(`Expression at location ${_(Ge(t-2))} and expression at location ${_(Ge(t-1))} follow each other without any intervening operator.`);if(Du(n,r))Eu(n)?Ke(n):qe();else if(Ou(n,r))return;else throw v(`Precedence conflict between ops ${n.name} in block ${i} and ${r.name}.`)}}else if(r.fix===`prefix`){if(t===0)return;let n=e[t-1];if(n.operator===void 0)throw v(`\n Encountered prefix op ${r.name} in block ${i} following an expression.`);if(n.operator.fix===`postfix`)throw v(`\n Encountered prefix op ${r.name} in block ${i} following postfix op ${n.operator.name}.`);return}else if(t===0){if(Tu(r)===void 0)throw v(`\n Encountered infix op ${r.name} in block ${i} on empty stack.`);return}else{let n=e[t-1];if(n.operator!==void 0){let e=n.operator;if(Eu(e)||e.fix===`prefix`){let n=Tu(r),i=_(Ge(t-1));if(n===void 0)throw v(r===wu?`\n Missing expression in block ${i} following prefix or infix op ${e.name}.`:`\n Encountered infix op ${r.name} in block ${i} following prefix or infix op ${e.name}.`);if(Du(e,n)||e===n&&e.associativity===`left`)throw v(`\n Precedence conflict between ops ${e.name} in block ${i} and ${n.name}.`)}else Je()}else{if(t<=1)return;let n=e[t-2];if(n.operator===void 0)throw v(`Expression at location ${_(Ge(t-2))} and expression at location ${_(Ge(t-1))} follow each other without any intervening operator.`);let i=Tu(n.operator),a=i!==void 0&&(t===2||e[t-3].operator!==void 0)?i:n.operator,o=_(Ge(t-2));if(Du(a,r)||a===r&&a.associativity===`left`){if(Eu(a))Ke(a);else if(a.fix===`prefix`)qe();else if(Ge(t-2).location[0]<Ge(t-1).location[0]&&r.name===`=`)throw v(`\n *** Hint *** You may have mistyped ==\n Illegal combination of operators ${a.name} in block ${o} and ${r.name}.`);else if(r===wu)throw v(`\n Error following expression at ${o}, missing operator or separator.`);else throw v(`\n Illegal combination of operators ${a.name} in block ${o} and ${r.name}.`)}else if(Ou(a,r)||a===r&&a.associativity===`right`)return;else throw v(`\n Precedence conflict between ops ${a.name} in block ${o} and ${r.name}.`)}}if(t===e.length-1)return}},Xe=()=>{Ue(void 0,wu),Ye();let e=We();if(e.length===2)return e[0].node;n.push(`Couldn't properly parse expression${e.slice(0,Math.max(e.length-1,1)).map((e,t)=>`-- incomplete expression at ${_(Ge(t))}.\n`).join(``)}`)},Ze=(e,t)=>{let n=We(),r=n.at(-1);if(r===void 0)throw v(`\n \`\`.'' has no left hand side at ${_(e)}.`);if(r.operator!==void 0){if(r.operator.fix!==`postfix`||n[n.length-2].operator!==void 0)throw v(`\n \`\`.'' follows operator ${_(r.node??B(`Missing`))}.`);n.push({node:void 0,operator:void 0}),Je(),n.pop()}let i=n.length-1;n[i]={node:B(`RecordComponent`,[Ge(i),e,t]),operator:void 0}},Qe=e=>{i.fairnessHook=e},$e=e=>e===void 0?!1:e.kind===`GeneralId`?e.heirs[0].heirs.length===0:e.kind===`OpApplication`&&e.heirs[1].heirs.filter((e,t)=>t%2==1).every(e=>e.kind===`GeneralId`&&e.heirs[0].heirs.length===0),et=(e,t)=>{for(let n of e.heirs)if(n.kind!==`ConjList`&&n.kind!==`DisjList`){if(!E(n.location[1]))throw v(`Item at ${_(n)} is not properly indented inside conjunction or disjunction list item at ${_(t)}`);et(n,t)}},tt=()=>i.proofDepth<0?i.proofDepth:o[i.proofDepth],nt=e=>e.image.length<2?!1:e.image[1]===`*`?i.proofDepth<0:e.image[1]===`+`?!0:[290,293,294,292].includes(e.kind)?i.proofDepth<0||o[i.proofDepth]>=0&&Nu(e)>o[i.proofDepth]:[63,75,71,72].includes(e.kind),rt=e=>{let t=Nu(e),n=i.proofDepth>0?o[i.proofDepth-1]:-1;return t===-1?(o[i.proofDepth]<0&&(o[i.proofDepth]=n+1),!0):o[i.proofDepth]>=0?t!==-2&&o[i.proofDepth]===t:(o[i.proofDepth]=t===-2?n+1:t,t===-2||t>n)},G=()=>z(R(289)),K=e=>V(z(R(e))),it=(e,t)=>{let n=Le(e);return i.lastOperator=Su.get(n.image),z(n,t)},at=()=>{U(`Infix Op`);let e=Le(du);return i.lastOperator=Su.get(e.image),W(),z(e,`InfixOp`)},ot=()=>{let e=Le(fu);return i.lastOperator=Su.get(e.image),z(e,`PostfixOp`)},st=()=>it(uu,`NonExpPrefixOp`),ct=()=>{U(`Module definition`),i.expecting=`---- MODULE`;let e=lt();i.expecting=`EXTENDS clause or module body`;let t=ut();i.expecting=`Module body`;let n=ft();i.expecting=`==== or more Module body`;let r=B(`EndModule`,[z(R(37))]);return W(),B(`Module`,[e,t,n,r])},lt=()=>{U(`Begin module`),i.expecting=`---- MODULE (beginning of module)`;let e=z(Le([35,3,21]));i.expecting=`Identifier`,Ve(f(1));let t=G();i.moduleName??=t.image,i.expecting=`----`;let n=z(R(36));return W(),B(`BeginModule`,[e,t,n])},ut=()=>{if(U(`Extends`),g(48))for(K(48),i.expecting=`Identifier`,Ve(f(1)),V(G()),i.expecting=`comma or module body`;g(88);)K(88),i.expecting=`Identifier`,Ve(f(1)),V(G());let e=H();return W(),B(`Extends`,e)},dt=()=>{let e=p();if(e===36)return z(R(36));if(e===85)return pt();if(e===44)return mt();if(m(),I(`unitDefinition`))return yt();if(p()===79)return ht();if(m(),I(`unitInstance`))return Tt();if(I(`unitAssumption`))return Ot();if(I(`unitTheorem`))return Mt();if([35,3,21].includes(p())){let e=ct();return He(),e}if(m(),f(1).kind===68&&f(2).kind!==64||f(1).kind===69)return Ft();throw L()},ft=()=>{for(U(`Module body`),i.expecting=`LOCAL, INSTANCE, PROOF, ASSUMPTION, THEOREM, RECURSIVE, declaration, or definition`;I(`moduleUnit`);)V(dt());let e=H();return W(),B(`Body`,e)},pt=()=>{U(`variable declaration`);let e=z(R(85));for(i.expecting=`Identifier`,V(G()),i.expecting=`comma or module body`;g(88);)K(88),i.expecting=`Identifier`,V(G());let t=H();return W(),B(`VariableDeclaration`,e,t)},mt=()=>{U(`Parameter declaration`),i.expecting=`CONSTANT`,U(`Parameter declaration item`);let e=B(`ConsDecl`,[z(R(44))]);for(W(),V(e),i.expecting=`Identifier, operator or _`,V(_t()),i.expecting=`,`;g(88);)K(88),i.expecting=`Identifier, operator or _`,V(_t());let t=H();return W(),B(`ParamDeclaration`,t)},ht=()=>{for(U(`Recursive`),i.expecting=`RECURSIVE`,K(79),i.expecting=`Identifier, operator or _`,V(_t()),i.expecting=`,`;g(88);)K(88),i.expecting=`Identifier, operator or _`,V(_t()),i.expecting="`,' or `)'";let e=H();return W(),B(`Recursive`,e)},gt=()=>{for(K(94),i.expecting=`_`,K(92),i.expecting=`comma or )`;g(88);)K(88),i.expecting=`_`,K(92),i.expecting=`comma or )`;K(95)},_t=()=>Be(`Constant declaration items`,()=>{i.expecting=`Identifier, _ or prefix op`;let e=p();if(e===289)return V(G()),i.expecting=`(, comma, or Module Body`,I(`constantArguments`)&>(),`IdentDecl`;if(uu.includes(e)){let e=st();return i.expecting=`_`,V(e),K(92),`PrefixDecl`}if(e!==92)throw m(),L();let t=z(R(92));i.expecting=`prefix or postfix operator`;let n=p();if(du.includes(n)){let e=at();return i.expecting=`_`,V(t),V(e),K(92),`InfixDecl`}if(fu.includes(n)){let e=ot();return V(t),V(e),`PostfixDecl`}throw m(),L()}),vt=e=>{let t=z(R(93));He(),V(t),i.expecting=e},yt=()=>Be(`Definition`,()=>{if(i.expecting=`LOCAL, Identifier or Operator Symbol`,g(54)&&K(54),R(96),i.expecting=`LOCAL, Identifier or Operator Symbol`,I(`functionDefinition`)){for(V(G()),i.expecting=`[`,K(97),i.expecting=`Identifier`,V(tn()),i.expecting=`COMMA or ]`;g(88);)K(88),i.expecting=`Identifier`,V(tn());let e=z(R(99));return i.expecting=`==`,V(e),vt(`Expression`),V(J()),`FunctionDefinition`}if(I(`postfixDefinition`)){U(`Postfix LHS`);let e=G(),t=z(Le(fu));return W(),V(B(`PostfixLHS`,[e,t])),i.expecting=`==`,vt(`Expression`),V(J()),`OperatorDefinition`}if(I(`infixDefinition`)){U(`Infix LHS`);let e=G(),t=z(Le(du)),n=G();return W(),V(B(`InfixLHS`,[e,t,n])),i.expecting=`==`,vt(`Expression`),V(J()),`OperatorDefinition`}if(I(`identifierDefinition`)){if(V(St()),i.expecting=`==`,vt(`Expression or Instance`),I(`definitionBody`))return V(J()),`OperatorDefinition`;if(p()===51)return V(Et()),`ModuleDefinition`;throw m(),L()}if(!uu.includes(p()))throw m(),L();U(`Prefix LHS`);let e=z(Le(uu));i.expecting=`Identifier`;let t=G();return W(),V(B(`PrefixLHS`,[e,t])),i.expecting=`==`,vt(`Expression`),V(J()),`OperatorDefinition`}),bt=()=>{if(U(`Identifier tuple`),K(102),i.expecting=`Identifier or >>`,g(289))for(V(G()),i.expecting=`COMMA or >>`;g(88);)K(88),i.expecting=`COMMA or >>`,V(G()),i.expecting=`COMMA or >>`;K(104);let e=H();return W(),B(`IdentifierTuple`,e)},xt=()=>{let e=p();if(e===289)return Ct();if(vu.has(e))return wt();throw m(),L()},St=()=>{if(U(`Identifier LHS`),V(G()),i.expecting=`( or ==`,g(94)){for(K(94),i.expecting=`Identifier Declaration, prefix op, _ or )`,V(xt()),i.expecting=`COMMA or )`;g(88);)K(88),i.expecting=`Identifier Declaration, prefix op or _`,V(xt()),i.expecting=`COMMA or )`;K(95)}let e=H();return W(),B(`IdentLHS`,e)},Ct=()=>{if(U(`Identifier Declation`),V(G()),i.expecting=`( or ...`,g(94)){for(K(94),i.expecting=`_`,K(92),i.expecting=`COMMA or )`;g(88);)K(88),i.expecting=`_`,K(92),i.expecting=`COMMA or )`;K(95)}let e=H();return W(),B(`IdentDecl`,e)},wt=()=>Be(`Op. Symbol Declaration`,()=>{let e=p();if(uu.includes(e))return V(st()),i.expecting=`_`,K(92),`PrefixDecl`;if(e!==92)throw m(),L();K(92),i.expecting=`infix or postfix operator`;let t=p();if(du.includes(t))return V(at()),i.expecting=`_`,K(92),`InfixDecl`;if(fu.includes(t))return V(ot()),`PostfixDecl`;throw m(),L()}),Tt=()=>{U(`Instance`),i.expecting=`LOCAL or instance`;let e=g(54)?z(R(54)):void 0;V(Et()),i.expecting=`COMMA or Module Body`;let t=H();return W(),B(`Instance`,e,t)},Et=()=>{if(U(`NonLocalInstance`),K(51),i.expecting=`Module identifier`,Ve(f(1)),V(G()),i.expecting=`WITH or another definition.`,g(87))for(K(87),i.expecting=``,V(Dt()),i.expecting=``;I(`nextSubstitution`);)K(88),i.expecting=``,V(Dt()),i.expecting=``;let e=H();return W(),B(`NonLocalInstance`,e)},Dt=()=>{U(`Substitution`);let e=p(),t=e===289?G():uu.includes(e)?st():du.includes(e)?at():fu.includes(e)?ot():void 0;if(t===void 0)throw m(),L();i.expecting=`<-`;let n=z(R(107));i.expecting=`Expression or Op. Symbol`;let r=Zt();return W(),B(`Substitution`,[t,n,r])},Ot=()=>{U(`Assumption`),i.expecting=`ASSUM...`,V(z(Le([41,39]))),I(`assumptionName`)&&(g(96)&&R(96),V(G()),i.expecting=`==`,K(93)),He(),i.expecting=`Expression`,V(J());let e=H();return W(),B(`Assumption`,e)},kt=e=>{if(A())return At();if(_u.has(p()))return jt();if(m(),I(e))return J();throw L()},At=()=>{if(U(`Assume-Prove`),g(289)){V(B(`GeneralId`,[Re(),G()])),K(90),V(At());let e=H();return W(),B(`Label`,e)}for(V(z(Le([39,40]))),i.expecting=`Expression, Declaration, or AssumeProve`,V(kt(`assumeExpression`)),i.expecting="PROVE or `,'";g(88);)K(88),i.expecting=`Expression, Declaration, or AssumeProve`,V(kt(`nextAssumeExpression`)),i.expecting="PROVE or `,'";V(z(Le([76,77]))),i.expecting=`Expression`,V(J());let e=H();return W(),B(`AssumeProve`,e)},jt=()=>{if(U(`NEW symbol declaration`),i.expecting=`NEW, CONSTANT, VARIABLE, STATE, ACTION, or TEMPORAL`,I(`constantSymbol`)){if(I(`newConstant`)?(K(56),K(44)):V(z(Le([56,44]))),i.expecting=`Constant declaration`,I(`constantDeclaration`)){let e=Ct();if(V(e),g(147)){let t=R(147);if(e.heirs.length>1)throw v(`declared symbol with arguments before \\in at ${_(e)}`);V(z(t)),i.expecting=`Expression`,V(J())}}else if(vu.has(p()))V(wt());else throw m(),L()}else if(I(`variableSymbol`))g(56)&&K(56),K(85),i.expecting=`Identifier`,V(B(`IdentDecl`,[G()]));else if(I(`levelSymbol`))g(56)&&K(56),V(z(Le([80,38,81]))),i.expecting=`Declaration`,V(xt());else throw L();let e=H();return W(),B(`NewSymb`,e)},Mt=()=>{if(U(`Theorem`),i.expecting=`THEOREM, PROPOSITION`,V(z(Le([67,58]))),i.expecting=`Identifier, Assume-Prove or Expression`,I(`theoremName`)&&(V(G()),i.expecting=`==`,K(93)),He(),I(`theoremAssumeProve`)){if(!k())throw L();V(At())}else if(I(`theoremExpression`))V(J());else throw L();nt(f(1))&&V(Nt());let e=H();return W(),B(`Theorem`,e)},Nt=()=>{if(i.proofDepth++,i.proofDepth>=100)throw v(`Proofs nested more than 100deep.`);o[i.proofDepth]=-1;let e=ze(`Proof`,()=>{if(f(1).kind===63||f(2).kind===63)return Ft();if(I(`terminalProof`)){let e=g(75)?z(R(75)):void 0;return B(`TerminalProof`,e,[z(Le([71,72]))])}if(!I(`stepProof`))throw L();for(I(`proofKeyword`)&&K(75);f(2).kind!==78;)V(zt()),i.expecting=`a proof step`;return V(Lt()),B(`Proof`,H())});if(i.proofDepth<0)throw v(`Parser bug: an extra QED step found.`);return i.proofDepth--,e},Pt=e=>{if(p()===55)K(55),i.expecting=`identifier`,V(G());else{if(m(),!I(e))throw L();V(J())}},Ft=()=>{U(`UseOrHideOrBy`);let e=p(),t=e===63||e===75?`TerminalProof`:`UseOrHide`;if(t===`TerminalProof`)g(75)&&K(75),K(63),g(64)&&K(64);else if(e===68)K(68),g(64)&&K(64);else if(e===69)K(69);else throw m(),L();if(i.expecting="an expression, `MODULE' or `DEF'",I(`usedFacts`))for(Pt(`usedExpression`);g(88);)K(88),i.expecting=`MODULE or expression`,Pt(`nextUsedExpression`),i.expecting=t===`TerminalProof`?`comma, DEF, or [.]`:`comma, DEF, or proof step`;if(g(66))for(K(66),i.expecting=`MODULE or expression`,Pt(`definedExpression`);g(88);)K(88),i.expecting=`MODULE or expression`,Pt(`nextDefinedExpression`),i.expecting=t===`TerminalProof`?`comma or [.]`:`comma or proof step`;let n=H();return W(),B(t,n)},It=e=>{i.expecting=`Step number`;let t=z(Le(pu));if(!rt(i.token))throw v(`${_(t)}: ${e}`);V(t)},Lt=()=>{U(`QED step`),It(`QED step's number has bad level.`),i.expecting=`QED`,V(B(`QEDStep`,[z(R(78))])),nt(f(1))&&V(Nt());let e=H();return W(),B(`ProofStep`,e)},Rt=()=>{let e=f(1).kind;if(e===68||e===69)return[Ft(),!1];if(e===51)return[Et(),!1];if(e===96||e===65)return[Bt(),!1];let t=p();if(t===70)return[Vt(`HaveStep`,70),!1];if(t===74)return[Ut(),!1];if(t===83)return[Wt(),!1];if(t===82)return[Gt(),!0];if(t===42)return[Vt(`CaseStep`,42),!0];if(m(),I(`assertStep`))return[Kt(),!0];throw L()},zt=()=>{U(`Step`),It(`step's number has bad level.`),i.expecting=`proof step`;let e=Rt();if(V(e[0]),nt(f(1))){if(!e[1])throw v(`${_(e[0])}: proof of step that does not take a proof.`);V(Nt())}let t=H();return W(),B(`ProofStep`,t)},Bt=()=>{U(`DefStep`),g(65)&&K(65);do V(yt());while(I(`nextDefinition`));let e=H();return W(),B(`DefStep`,e)},Vt=(e,t)=>{U(e),K(t),i.expecting=`expression`,V(J());let n=H();return W(),B(e,n)},Ht=(e,t,n,r)=>{for(V(e()),i.expecting=t;g(88);)K(88),i.expecting=n,V(e()),i.expecting=r},Ut=()=>{if(U(`TakeStep`),K(74),i.expecting=`identifier`,I(`takeBounds`))Ht(tn,`comma or step`,`identifier or tuple of identifiers`,`comma or proof step`);else if(g(289))Ht(G,`comma or proof step`,`identifier`,`comma or proof step`);else throw L();let e=H();return W(),B(`TakeStep`,e)},Wt=()=>{for(U(`WitnessStep`),K(83),i.expecting=`expression`,V(J());g(88);)K(88),i.expecting=`expression`,V(J()),i.expecting=`comma or colon`;let e=H();return W(),B(`WitnessStep`,e)},Gt=()=>{if(U(`PickStep`),K(82),i.expecting=`identifier`,I(`pickIdentifiers`))Ht(G,`comma, or colon`,`identifier`,`comma or colon`);else if(p()===102||p()===289)Ht(tn,`comma or colon`,`identifier or tuple of identifiers`,`comma or colon`);else throw m(),L();K(89),i.expecting=`expression`,V(J());let e=H();return W(),B(`PickStep`,e)},Kt=()=>{if(U(`AssertStep`),g(84)&&(K(84),i.expecting=`expression or ASSUME/PROVE`),I(`assertedExpression`))V(J());else if(k())V(At());else throw L();let e=H();return W(),B(`AssertStep`,e)},qt=()=>{let e=p();if(e===94)return Qt();if(e===100)return nn();if(e===97)return on();if(e===102)return ln();if(e===59||e===86)return fn();throw m(),L()},Jt=()=>{let e=p();if(e===47||e===49)return $t();if(e===60||e===61)return en();if(e===50)return pn();if(e===42)return gn();if(e===52)return _n();if(e===43)return xn();throw m(),L()},Yt=()=>{let e=z(R(109));if(!I(`decimalPart`))return B(`Number`,[e]);let t=z(R(91));return B(`Real`,[e,t,z(R(109))])},Xt=()=>{for(U(`Optional Arguments`),K(94),V(Zt());g(88);)K(88),V(Zt());K(95);let e=H();return W(),B(`OpArgs`,e)},Zt=()=>{if(I(`operatorArgument`)&&D()){let e=p();if(uu.includes(e))return B(`GenNonExpPrefixOp`,[Re(),st()]);if(du.includes(e)){let e=at();if(e.image===`\\X`||e.image===`\\times`)throw v(`${_(e)}: \\X may not be used as an infix operator.`);return B(`GenInfixOp`,[Re(),e])}if(fu.includes(e))return B(`GenPostfixOp`,[Re(),ot()]);throw m(),L()}if(I(`lambdaArgument`)&&D())return Sn();if(I(`expressionArgument`))return J();throw L()},Qt=()=>B(`ParenExpr`,[z(R(94)),J(),z(R(95))]),$t=()=>{U(`Quantified form`),V(z(Le([47,49])));let e=I(`unboundQuantifier`);if(e)for(V(G());g(88);)K(88),V(G());else if(p()===102||p()===289)for(V(tn());g(88);)K(88),V(tn());else throw m(),L();K(89),V(J());let t=H();return W(),B(e?`UnboundQuant`:`BoundQuant`,t)},en=()=>{for(U(`Bound Quantified Expression`),V(z(Le([60,61]))),V(G());g(88);)K(88),V(G());K(89),V(J());let e=H();return W(),B(`UnboundQuant`,e)},tn=()=>{U(`Quant Bound`);let e=p();if(e===102)V(bt());else if(e===289)for(V(G());g(88);)K(88),V(G()),i.expecting=`, or \\in`;else throw m(),L();K(147),V(J());let t=H();return W(),B(`QuantBound`,t)},nn=()=>Be(`Some { } form`,()=>{K(100);let e=I(`setContents`)?q():`SetEnumerate`;return K(101),e}),q=()=>{if(re()){let e=p(),t=e===102?bt():e===289?G():void 0;if(t===void 0)throw m(),L();i.expecting=`\\in`;let n=z(R(147)),r=J();if(i.expecting=`':', ',' or '}'`,p()===89){let e=z(R(89));return V(t),V(n),V(r),V(e),V(J()),`SubsetOf`}if(V(B(`InfixExpr`,[B(`GeneralId`,[Re(),t]),B(`GenInfixOp`,[Re(),n]),r])),p()!==88)return m(),`SetEnumerate`;do K(88),V(J());while(g(88));return`SetEnumerate`}if(I(`setEnumeration`)){for(V(J());g(88);)K(88),V(J());return`SetEnumerate`}if(I(`setOfAll`)){for(V(J()),K(89),V(tn());g(88);)K(88),V(tn());return`SetOfAll`}if(!I(`setExpression`))throw L();let e=J();V(e);let t=p();if(t===89){let t=R(89);if(e.heirs.length>1&&e.kind===`InfixExpr`&&e.heirs[1].heirs[1].image===`\\in`)throw v(`Form {a \\in b : c \\in d }, at line ${t.beginLine}, is not allowed`);for(V(z(t)),V(tn());g(88);)K(88),V(tn());return`SetOfAll`}if(t!==88)return m(),`SetEnumerate`;do K(88),V(J());while(g(88));return`SetEnumerate`},rn=e=>{for(V(e());g(88);)K(88),V(e());K(99)},an=(e,t,n)=>()=>{U(e);let r=G(),i=z(R(n)),a=J();return W(),B(t,[r,i,a])},on=()=>Be(`Some [] Form`,()=>{if(K(97),re()){for(V(tn());g(88);)K(88),V(tn());return K(108),V(J()),K(99),`FcnConst`}if(I(`recordFields`))return rn(an(`Field Value`,`FieldVal`,108)),`RcdConstructor`;if(f(2).kind===108&&Mu(f(1)))return f(1).kind=289,rn(an(`Field Value`,`FieldVal`,108)),`RcdConstructor`;if(I(`recordSets`))return rn(an(`Field Set`,`FieldSet`,89)),`SetOfRcds`;if(!I(`bracketExpression`))throw L();V(J());let e=p();if(e===88||e===99){for(;g(88);)K(88),V(J());return K(99),i.lastOperator=Cu,`FcnAppl`}if(e===106)return K(106),V(J()),K(99),`SetOfFcns`;if(e===46){for(K(46),V(sn());g(88);)K(88),V(sn());return K(99),`Except`}if(e===98)return K(98),V(dn()),`ActionExpr`;throw m(),L()}),sn=()=>{U(`Except Spec`),K(105);do V(cn()),i.expecting=`= or ,`;while(p()===91||p()===97||m());K(185),V(J());let e=H();return W(),B(`ExceptSpec`,e)},cn=()=>{U(`Except Component`);let e=p();if(e===91){K(91),Ve(f(1));let e=G();e.image===`@`&&n.push(`@ used in !.@`),V(e)}else if(e===97){for(K(97),V(J());g(88);)K(88),V(J());K(99)}else throw m(),L();let t=H();return W(),B(`ExceptComponent`,t)},ln=()=>Be(`Some << -- >> or >>_ Form`,()=>{if(K(102),I(`tupleContents`))for(V(J());g(88);)K(88),V(J());let e=p();if(e===104)return K(104),`Tuple`;if(e===103)return K(103),V(dn()),`ActionExpr`;throw m(),L()}),un=()=>{let e=G(),t=I(`identifierArguments`)?Xt():void 0;if(g(105)){let n=z(R(105));return V(B(`IdPrefixElement`,[e],t,[n])),un()}return Qe(t),B(`GeneralId`,[B(`IdPrefix`,H()),e])},dn=()=>{U(`restricted form of expression`);let e=p(),t=e===289?un():e===94?Qt():e===100?nn():e===97?on():e===102?ln():void 0;if(t===void 0)throw m(),L();return W(),t},fn=()=>{Qe(void 0),U(`Fairness Expression`);let e=z(Le([86,59])),t=dn(),r=`${e.location[0]}`;if(I(`fairnessArguments`)){let a=z(R(94)),o=J(),s=z(R(95));return W(),t.kind===`GeneralId`&&i.fairnessHook!==void 0?B(`FairnessExpr`,[e,B(`OpApplication`,[t,i.fairnessHook]),a,o,s]):yu.has(String(t.kind))?B(`FairnessExpr`,[e,t,a,o,s]):(n.push(`Error in fairness expression at ${r}: ${e.location[1]}: could not link arguments\n`),t)}if(W(),i.fairnessHook===void 0)throw v(`Ill-structured fairness expression at line ${r}, column ${e.location[1]}`);let a=i.fairnessHook.heirs;return a.length===3?B(`FairnessExpr`,[e,t,...a]):(n.push(`Error in fairness expression at ${r}: ${e.location[1]}\n`),t)},pn=()=>{U(`IF THEN ELSE`);let e=[z(R(50)),J(),z(R(62)),J(),z(R(45)),J()];return W(),B(`IfThenElse`,e)},mn=()=>{let e=f(1);return e.kind===121&&E(e.beginColumn)},hn=(e,t,n)=>{U(e);let r=[n(),z(R(106)),J()];return W(),B(t,r)},gn=()=>{for(U(`CASE Expression`),K(42),V(hn(`Case Arm`,`CaseArm`,J));mn()&&f(2).kind!==57;)K(121),V(hn(`Case Arm`,`CaseArm`,J));mn()&&(K(121),V(hn(`Case Other Arm`,`OtherArm`,()=>z(R(57)))));let e=H();return W(),B(`Case`,e)},_n=()=>{U(`Case Other Arm`);let e=[z(R(52)),vn(),z(R(53)),J()];return W(),B(`LetIn`,e)},vn=()=>{U(`Let Definitions`);do{let e=p();if(e===54||e===96)V(yt());else if(e===79)V(ht());else throw m(),L()}while([54,79,96].includes(p())||m());let e=H();return W(),B(`LetDefinitions`,e)},yn=e=>{U(`Junction Item`);let t=z(Le([132,129])),n=J();W();let r=B(e,[t,n]);return et(n,r),r},bn=()=>{let e=f(1);return l.push({isConjunction:e.kind===129,column:e.beginColumn}),Be(`AND-OR Junction`,()=>{let e=I(`disjunctionList`)?`DisjList`:I(`conjunctionList`)?`ConjList`:void 0;if(e===void 0)throw L();let t=e===`DisjList`?`DisjItem`:`ConjItem`;for(V(yn(t));O();)V(yn(t));return l.pop(),e})},xn=()=>{U(`(Un)Bounded Choose`);let e=z(R(43)),t=p(),n=t===289?G():t===102?bt():void 0;if(n===void 0)throw m(),L();U(`Domain binding`),g(147)&&(K(147),i.expecting=`Expression`,V(J()));let r=B(`MaybeBound`,H());W();let a=[e,n,r,z(R(89)),J()];return W(),B(`UnboundOrBoundChoose`,a)},Sn=()=>{U(`Lambda`),K(73),i.expecting=`Identifier`,Ht(G,"`,' or `:'",`Identifier`,"`,' or `:'"),K(89),i.expecting=`Expression`,V(J());let e=H();return W(),B(`Lambda`,e)},Cn=(e,t)=>{Ue(B(e,[Re(),t]),i.lastOperator),We().length!==1&&Ye()},wn=()=>{let e=p();if(lu.includes(e))return Cn(`GenPrefixOp`,it(lu,`PrefixOp`));if(du.includes(e))return Cn(`GenInfixOp`,at());throw m(),L()},J=()=>{for(U(`Expression`),i.operatorStack=[],u.push(i.operatorStack);I(`leadingOperator`)&&D();)wn();if(I(`openExpression`)&&D())Ue(Jt());else if(D())Tn();else throw L();W();let e=Xe();if(e===void 0)throw v(` Couldn't reduce expression stack.`);return u.pop(),i.operatorStack=u.at(-1),e},Tn=()=>{if(U(`ExtendableExpr`),I(`junctionList`)&&j())Ue(bn());else if(gu.has(p()))Ue(qt());else{if(m(),!I(`primitiveExpression`))throw L();Ue(On())}for(;I(`expressionSuffix`);)if(I(`postfixSuffix`)&&D())Cn(`GenPostfixOp`,ot());else if(I(`recordSuffix`)&&D()){let e=z(R(91));if(Ve(f(1)),!D())throw L();Ze(e,G())}else if(I(`applicationSuffix`)&&D()){i.expecting=`function argument`;let e=on();[`GenPrefixOp`,`GenNonExpPrefixOp`,`GenInfixOp`,`GenPostfixOp`,`FcnAppl`].includes(String(e.kind))?(Ue(e,i.lastOperator),We().length!==1&&Ye()):Ue(e)}else throw L();if(I(`expressionContinuation`)){if(I(`infixContinuation`)&&D()){for(Cn(`GenInfixOp`,at());I(`nextLeadingOperator`)&&D();)wn();if(I(`nextOpenExpression`)&&D())Ue(Jt());else if(D())Tn();else throw L()}else if(I(`labelContinuation`)&&D()){let e=z(R(90)),t=We().at(-1)?.node;if(!$e(t))throw v(`\`::' at ${_(e)} does not follow a label.`);We().pop();let n=J(),r=We().at(-1)?.operator;if((n.kind===`InfixExpr`||n.kind===`PostfixExpr`)&&We().length>0&&r!==void 0&&i.lastOperator!==void 0&&!Ou(r,i.lastOperator))throw v(`Removing label at ${_(t??B(`Missing`))} would change expression parsing.`);Ue(B(`Label`,[t??B(`Missing`),e,n]))}else throw L()}W()},En=()=>{let e=Le([290,291]),t=z(e);if(tt()<0&&i.proofDepth<=0)throw v(`${_(t)}: Step number used outside proof.`);if(e.image[1]===`+`)throw v(`${_(t)}: <+> step number used in an expression.`);return t},Dn=()=>{let e=p();if(e===289)return G();if(e===290||e===291)return En();if(du.includes(e))return at();if(fu.includes(e))return ot();if(m(),!I(`negativeOperator`))throw L();return st()},On=()=>ze(`Primitive expression`,()=>{if(I(`stringLiteral`)&&D())return ze(`String`,()=>z(R(110),`String`));if(I(`numberLiteral`)&&D())return Yt();if(!hu.has(p()))throw m(),L();let e=Dn(),t=I(`primitiveArguments`)?Xt():void 0;for(;g(105);)V(kn());let n=H();if(n===void 0){let n=B(`GeneralId`,[B(`IdPrefix`,[]),e]);return t?B(`OpApplication`,[n,t]):n}let r=[B(`IdPrefixElement`,[e],t,[n[0].heirs[0]]),...n.slice(0,-1).map((e,t)=>B(`IdPrefixElement`,e.heirs.slice(1),[n[t+1].heirs[0]]))],i=n[n.length-1].heirs,a=B(`GeneralId`,[B(`IdPrefix`,r),i[1]]);return i.length===2?a:B(`OpApplication`,[a,i[2]])}),kn=()=>{if(U(`Bang Extension`),K(105),I(`bangOperand`)){if(I(`bangIdentifier`)&&f(1).image!==`@`)V(G());else{let e=p();if(uu.includes(e))V(st());else if(du.includes(e))V(at());else if(fu.includes(e))V(ot());else throw m(),L()}I(`bangArguments`)&&V(Xt())}else if(p()===94)V(Xt());else{if(m(),!I(`structureOperator`))throw L();V(An())}let e=B(`IdPrefixElement`,H());return W(),e},An=()=>{let e=ze(`StructOp`,()=>{i.expecting="`<<' , `>>' , `:' , `@' , or number";let e=p();if(e===102||e===104||e===89)return z(R(e),`StructOp`);if(e===109)return Yt();if(m(),f(1).image!==`@`)throw L();return z(R(289),`StructOp`)});if(e.kind===`Real`)throw v(`Illegal structural term at ${_(e)}`);return e.kind===`Number`?B(`StructOp`,[e]):e},jn=()=>{if(He(),g(2))for(R(2);;){let e=p();if(e!==20&&e!==289){m();break}R(e)}ct()};try{jn()}catch(e){if(!(e instanceof h))throw e;n.push(e.message)}return n.length===0?void 0:n.join(`
|
|
110
|
+
`)},Fu=(e,t)=>{try{return cl(e)}catch(n){if(!(n instanceof p))throw n;let r=Pu(e);throw r===void 0?n:m([{location:`In module ${t}`,message:`Could not parse module ${t} from file ${t}.tla`}],!0,r)}},Iu=(e,t,n)=>new b(`Applying ${e} to the following value,\nwhich is not ${t}:\n${Y(n)}`),Lu=(e,t,n,r)=>new b(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${Y(r)}`),Ru=e=>Me(e)?bn(e):void 0,zu=(e,t,n)=>{let r=Z(e,t,n),i=Ru(r);if(!i)throw Iu(n,`a function with a finite domain`,r);return i},Bu=(e,t,n)=>{let r=Z(e,t,n),i=Ru(r);if(!i)throw Lu(t===0?`first`:`second`,n,`bag`,r);return i},Vu=(e,t)=>{if(!Ae(e)||!Jt(e))throw t();return q(e).elements},Hu=e=>e.range.every(e=>typeof e==`number`&&e>0),Uu=(e,t)=>{let n=e.domain.findIndex(e=>$e(e,t));return n===-1?void 0:e.range[n]},Wu=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,Gu=Wu(`BagDiff`,`tlc2.value.impl.Value`,2),Ku=Wu(`SqSubseteq`,`tlc2.value.IBoolValue`,2),qu=Wu(`BagUnion`,`tlc2.value.impl.Value`,1),Ju=Wu(`BagOfAll`,`tlc2.value.impl.Value`,2),Yu=Wu(`BagCup`,`tlc2.value.impl.Value`,2),Xu=Wu(`BagCardinality`,`tlc2.value.impl.IntValue`,1),Zu=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${Mr(e)}`;throw Pr(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')`)},Qu=(e,t,n)=>{let r=Zu(e,n)+Zu(t,n);if(Dr(r))throw Or(`${e}+${t}`);return r},$u=(e,t,n,r)=>{let i=Uu(n,e.domain[t]),a=Zu(e.range[t],r);return i===void 0?a:a-Zu(i,r)|0},ed=(e,t)=>Mt(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>$e(e[0],r));a?a[1]=Qu(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),td=Qe([],[]),nd=[Cr(`EmptyBag`,td),Q(`IsABag`,1,e=>{let t=Ru(Z(e,0,`IsABag`));return t!==void 0&&Hu(t)}),Q(`BagCardinality`,1,e=>{let t=Z(e,0,`BagCardinality`);return zu(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw Iu(`BagCardinality`,`a bag`,t);return Qu(e,n,Xu)},0)}),Q(`BagIn`,2,e=>{let t=Z(e,1,`BagIn`),n=Uu(zu(e,1,`BagIn`),Z(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Lu(`second`,`BagIn`,`bag`,t);return n>0}),Q(`CopiesIn`,2,e=>{let t=Z(e,1,`CopiesIn`),n=Uu(zu(e,1,`CopiesIn`),Z(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Lu(`second`,`CopiesIn`,`bag`,t);return n}),Q(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Bu(e,t,`(+)`);if(!Hu(n))throw Lu(t===0?`first`:`second`,`(+)`,`bag`,Z(e,t,`(+)`));return n});return ed(t,Yu)}),Q(`\\ominus`,2,e=>{let t=Bu(e,0,`(-)`),n=Bu(e,1,`(-)`);return Mt(t.domain.flatMap((e,r)=>{let i=$u(t,r,n,Gu);return i>0?[[e,i]]:[]}))}),Q(`BagUnion`,1,e=>{let t=Z(e,0,`BagUnion`),n=Vu(t,()=>Iu(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??td;let r=n.map(e=>{let n=Ru(e);if(!n)throw new b(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${Y(t)}`);return n});return ed(r,qu)}),Q(`\\sqsubseteq`,2,e=>{let t=zu(e,0,`\\sqsubseteq`),n=zu(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>$u(t,r,n,Ku)<=0)}),wr(`BagOfAll`,2,e=>{let t=Sr(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new b(`The first argument of BagOfAll should be an operator, but instead it is:\n${Y(t.literalBody)}`);let n=Z(e,1,`BagOfAll`),r=Ru(n);if(!r)throw Lu(`second`,`BagOfAll`,`function with a finite domain`,n);return ed(r.domain.map((e,n)=>Qe([t.call([e])],[r.range[n]])),Ju)}),Q(`SubBag`,1,e=>{let t=Z(e,0,`SubBag`);if(!Me(t))throw new y(`DOMAIN expects a function but received ${Y(t)}`);let n=bn(t),r=Et(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new y(`The ${e?`first`:`second`} argument of >= should be an integer, but instead it is:\n${Y(e?r[0]:i)}`)}let a=n.range.filter(e=>typeof e==`number`);if(a.some(e=>e<1))throw new y(`Attempted to apply a function to ${Y(n)}, which is not in its domain`);return Et(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>Qe(e.map(e=>e[0]),e.map(e=>e[1]))))}),Q(`BagToSet`,1,e=>Mn(zu(e,0,`BagToSet`))),Q(`SetToBag`,1,e=>{let t=Z(e,0,`SetToBag`),n=Vu(t,()=>Iu(`BagToSet`,`a function with a finite domain`,t));return Qe([...n],n.map(()=>1))})],rd=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,id=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,ad=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,od=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,sd=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,cd=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,ld=e=>{if(!Me(e))return!1;let t=bn(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},ud=(e,t)=>Pr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${Mr(t)}`),dd=(e,t)=>Pr(e,`Cannot cast tlc2.value.impl.${Mr(t)} to tlc2.value.impl.StringValue`),fd=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),pd=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw ud(t,e);return`[${q(e).elements.map(e=>hd(e,t)).join(`,`)}]`},md=(e,t)=>{let n=bn(e),r=mn(n);return r?`[${r.map(e=>hd(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${fd(typeof e==`string`?e:Y(e))}:${hd(n.range[r],t)}`).join(`,`)}}`},hd=(e,t)=>typeof e==`string`?fd(e):typeof e==`object`?e.kind===`ModelValue`?fd(e.name):Ae(e)?pd(e,t):md(e,t):String(e),gd=e=>{if(Ae(e))return pd(e,rd);if(!Me(e)||ld(e))throw ud(rd,e);return md(e,rd)},_d=e=>{if(!Me(e))throw ud(id,e);return md(e,id)},vd=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))},yd=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return ze(e);if(Array.isArray(e))return Ht(e.map(e=>yd(e,t)));if(typeof e==`object`&&e)return Ut(Object.entries(e).map(([e,n])=>[ze(e),yd(n,t)]));throw Pr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},bd=(e,t)=>{if(e.trim()===``)return yd(null,t);try{return yd(JSON.parse(e,(e,t,n)=>typeof t==`number`?vd(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?Pr(t,e.message):e}},xd=(e,t)=>{if(typeof e!=`string`)throw dd(t,e);return e},Sd=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw Pr(n,`${t} (No such file or directory)`);return r},Cd=e=>[Tr(`ToJson`,1,e=>ze(hd(Z(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Tr(`ToJsonArray`,1,e=>ze(gd(Z(e,0,`ToJsonArray`)))),Tr(`ToJsonObject`,1,e=>ze(_d(Z(e,0,`ToJsonObject`)))),Tr(`JsonSerialize`,2,t=>{let n=xd(Z(t,0,`JsonSerialize`),ad),r=Z(t,1,`JsonSerialize`);if(!mn(r)&&!ld(r))throw new b(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${Y(r)}`);return e.writeFile?.(n,hd(r,ad)),!0}),Tr(`ndJsonSerialize`,2,t=>{let n=xd(Z(t,0,`ndJsonSerialize`),od),r=Z(t,1,`ndJsonSerialize`),i=mn(r);if(!i)throw new b(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${Y(r)}`);return e.writeFile?.(n,i.map(e=>`${hd(e,od)}\n`).join(``)),!0}),Tr(`JsonDeserialize`,1,t=>{let n=xd(Z(t,0,`JsonDeserialize`),sd);return bd(Sd(e,n,sd),sd)}),Tr(`ndJsonDeserialize`,1,t=>{let n=xd(Z(t,0,`ndJsonDeserialize`),cd);return Ht(Sd(e,n,cd).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>bd(e,cd)))})],wd=(e,t,n,r)=>new b(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Td=(e,t,n)=>{if(typeof e!=`number`||e<0)throw wd(t,n,`nonnegative integer`,Y(e));return e},Ed=(e,t,n,r)=>{if(!Ae(e)||!Jt(e))throw wd(t,n,r,Y(e));return q(e).elements},Dd=(e,t,n,r)=>Et(Array.from({length:t},()=>Et(e.filter(()=>r.nextDouble()<n)))),Od=(e,t)=>{let n=`RandomSetOfSubsets`,r=Td(Z(e,0,n),`first`,n),i=Td(Z(e,1,n),`second`,n),a=Ed(Z(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw wd(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw wd(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Dd(a,r,a.length===0?0:i/a.length,t.getRandom())},kd=e=>[Tr(`RandomSubset`,2,t=>{let n=Z(t,0,`RandomSubset`);if(typeof n!=`number`)throw wd(`first`,`RandomSubset`,`nonnegative integer`,Y(n));if(n<0)throw new y(`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=Z(t,1,`RandomSubset`);if(!Ae(r)||!sn(r)&&!Jt(r))throw wd(`second`,`RandomSubset`,`a finite set`,Y(r));return Et(Bl(n,r,e.getRandom()))}),Tr(`RandomSetOfSubsets`,3,t=>Od(t,e)),Tr(`TestRandomSetOfSubsets`,3,t=>Ht(Array.from({length:5},()=>q(Od(t,e)).elements.length)))],Ad=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,jd=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Ad})`,Md=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Ad}) throws java.io.IOException`,Nd=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Ad})`,Pd=()=>Ut([[`action`,Et([])],[`state`,Et([])]]),Fd=()=>Ut([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),Id=e=>Ut([[`name`,e??`UnnamedAction`],[`location`,Fd()]]),Ld=(e,t)=>{let n=e.map((e,t)=>Ht([t+1,Ut(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>Ht([n[r],Id(e[r+1].action),t])),i=t?[Ht([n[n.length-1],Id(t.action),n[t.start]])]:[];return Ut([[`action`,Et([...r,...i])],[`state`,Et(n)]])},Rd=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Gl(e).get(t)},zd=(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),Y(r));else throw new b(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${Y(n)}`)},Bd=e=>e.every(e=>e!==void 0),Vd=(e,t)=>Ut(t.variables.map((t,n)=>[t,e[n]])),Hd=(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&&!X(e)){if(t.variableIndex.has(r))return!0;let e=Ro(r,t);if(e&&!n.has(e)&&(n.add(e),Hd(e.body,t,n)))return!0}return ur(e).some(e=>Hd(e,t,n))},Ud=(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[Q(`AssertEq`,2,t=>{let n=Z(t,0,`AssertEq`),r=Z(t,1,`AssertEq`),i=$e(n,r);return i||(e(Y(`Assertion failed`,!0)),e(Y(n,!0)),e(Y(r,!0))),i}),Vr(`AssertError`,2,e=>{let t=Sr(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw Pr(jd,`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=Hr(e,0,`AssertError`)();try{Hr(e,1,`AssertError`)()}catch(e){if(e instanceof y)return e.message===n;throw e}return!1}),Tr(`TLCGetOrDefault`,2,e=>{let n=Z(e,0,`TLCGetOrDefault`);return Rd(t,n)??Z(e,1,`TLCGetOrDefault`)}),{...wr(`TLCGetAndSet`,4,n=>{let r=Z(n,0,`TLCGetAndSet`),i=Rd(t,r)??Z(n,3,`TLCGetAndSet`),a=Sr(n,1,`TLCGetAndSet`);return zd(t,e,r,a.call([i,Z(n,2,`TLCGetAndSet`)])),i}),isStateLevel:!0},Tr(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Bd(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw Pr(Md,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return Ht(t.getBehavior(r).map(e=>Vd(e,n.environment)))}),Tr(`CounterExample`,0,()=>t.counterExample??Pd()),Q(`ToTrace`,1,e=>{let t=Z(e,0,`ToTrace`);if(!Me(t)||!$e(Mn(t),Et([`action`,`state`])))throw new y(`The argument of ToTrace should be a CounterExample, but instead it is:\n${Y(t)}`);let n=q(An(t,`state`)).elements.map(e=>mn(e)??[]);return Ht(n.sort((e,t)=>Number(e[0])-Number(t[0])).map(e=>e[1]))}),Q(`TLCModelValue`,1,e=>{let t=Z(e,0,`TLCModelValue`);if(typeof t!=`string`)throw new b(`The argument of ModelValue should be a string, but instead it is:\n${Y(t)}`);return Xe(t)}),Vr(`TLCDefer`,1,()=>!0),Q(`TLCNoOp`,1,e=>Z(e,0,`TLCNoOp`)),Vr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Bd(r))throw Pr(Nd,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Lo(Hr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new T(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),Vr(`TLCCache`,2,(e,t)=>{let r=Sr(e,0,`TLCCache`),a=$n(Hr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=Hd(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}),Q(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Tl([Z(e,0,`TLCFP`)])))),Tr(`TLCEvalDefinition`,1,(e,t)=>{let n=Z(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?Ro(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new b(`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${Y(n)}`);if(r.kind===`Operator`&&r.params.length>0)throw new b(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return Ys({kind:`Identifier`,name:n,location:r.location},t)})]},Wd=(e,t)=>[Tr(`_Track`,2,e=>{let n=String(Z(e,1,`_Track`)),r=t.possibleCounts.get(n)??0;return t.possibleCounts.set(n,Z(e,0,`_Track`)===!0?r+1:r),!0}),Tr(`_Counts`,0,()=>Wl(t)),Tr(`_CheckName`,1,n=>{let r=String(Z(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(Y(Wl(t),!0)),!1)}),Tr(`_PrintCounts`,0,()=>(e(Y(Wl(t),!0)),!0))],Gd=e=>String(e).padStart(2,`0`),Kd=e=>`${e.getUTCFullYear()}.${Gd(e.getUTCMonth()+1)}.${Gd(e.getUTCDate())}.${Gd(e.getUTCHours())}${Gd(e.getUTCMinutes())}${Gd(e.getUTCSeconds())}`,qd=e=>Mt([...e].map(([e,t])=>[e,Ht([t])])),Jd=/* @__PURE__ */ new Set([`diameter`,`generated`,`distinct`,`queue`,`stats`,`config`]),Yd=(e,t,n)=>{if(!e.isStarted&&Jd.has(t))throw new y(`TLCGet(${t}) was undefined.`);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 Ut([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Ut([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Ut([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,ze(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,ze(Kd(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return Id(void 0);case`all`:return qd(e.registers);case`all:named`:return qd(Gl(e))}if(t.startsWith(`s:`)){let n=Gl(e).get(t);if(n===void 0)throw new y(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return ze(e.properties.get(t.slice(2))??t);throw new y(`TLCGet(${t}) was undefined.`)},Xd=e=>e.length===0?[[]]:e.flatMap((t,n)=>Xd([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),Zd=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&q(e).elements.forEach(Zd),e.kind===`Function`&&e.range.forEach(Zd))},Qd=(t,n)=>[Q(`Print`,2,e=>(t(`${Ee(Y(Z(e,0,`Print`),!0,!0))} ${Ee(Y(Z(e,1,`Print`),!0,!0))}`),Z(e,1,`Print`))),Q(`PrintT`,1,e=>(t(Ee(Y(Z(e,0,`PrintT`),!0,!0))),!0)),Q(`Assert`,2,t=>{if(Z(t,0,`Assert`)!==!0)throw new b(`The first argument of Assert evaluated to FALSE; the second argument was:\n${Ee(Y(Z(t,1,`Assert`)))}`,e.assertViolation);return!0}),Q(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),Q(`:>`,2,e=>Mt([[Z(e,0,`:>`),Z(e,1,`:>`)]])),Q(`@@`,2,e=>{let t=xr(e,0,`@@`),n=xr(e,1,`@@`);return Nt([...Ie(t),...Ie(n)])}),Q(`ToString`,1,e=>ze(Y(Z(e,0,`ToString`),!0))),Q(`TLCEval`,1,e=>{let t=Z(e,0,`TLCEval`);return Zd(t),t}),Q(`Permutations`,1,e=>{let t=yr(e,0,`Permutations`);return Et(Xd(t).map(e=>Mt(t.map((t,n)=>[t,e[n]]))))}),wr(`SortSeq`,2,e=>{let t=Sr(e,1,`SortSeq`);return Ht(br(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)]},[]))}),Tr(`TLCGet`,1,(e,t)=>{let r=Z(e,0,`TLCGet`);if(typeof r==`number`&&r>=0){let e=n.registers.get(r);if(e===void 0)throw new y(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new y(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${Y(r)}`);return Yd(n,r,t?.state)}),Tr(`TLCSet`,2,e=>{let r=Z(e,0,`TLCSet`);return zd(n,t,r,Z(e,1,`TLCSet`)),!0}),Cr(`Any`,Ke),Q(`RandomElement`,1,e=>Hl(_r(e,0,`RandomElement`),n.getRandom()))],$d=/* @__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(`,`),ef=[[`\\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`,`≀`],[`^+`,`⁺`]],tf=/* @__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(`,`),nf=/* @__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(`.`),rf=/* @__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(`.`),af=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
|
|
103
111
|
Nat == { }
|
|
104
112
|
a+b == {a, b}
|
|
105
113
|
a-b == CHOOSE n : b + n = a
|
|
@@ -415,16 +423,15 @@ _CheckName(name) ==
|
|
|
415
423
|
=> (PrintT(counts) /\\ FALSE)
|
|
416
424
|
_PrintCounts == PrintT(_Counts)
|
|
417
425
|
=============================================================================
|
|
418
|
-
`]]),ed=/* @__PURE__ */ new Map([[`FiniteSets`,/* @__PURE__ */ new Map([[`IsFiniteSet`,`public static tlc2.value.IBoolValue tlc2.module.FiniteSets.IsFiniteSet(tlc2.value.impl.Value)`],[`Cardinality`,`public static tlc2.value.impl.IntValue tlc2.module.FiniteSets.Cardinality(tlc2.value.impl.Value)`]])],[`Sequences`,/* @__PURE__ */ new Map([[`Seq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Seq(tlc2.value.impl.Value)`],[`Len`,`public static tlc2.value.impl.IntValue tlc2.module.Sequences.Len(tlc2.value.impl.Value)`],[`Head`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Head(tlc2.value.impl.Value)`],[`Tail`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Tail(tlc2.value.impl.Value)`],[`Append`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Append(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`\\o`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Concat(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SubSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SubSeq(tlc2.value.impl.Value,tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SelectSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SelectSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`]])],[`TLC`,/* @__PURE__ */ new Map([[`Print`,`public static tlc2.value.impl.Value tlc2.module.TLC.Print(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`PrintT`,`public static tlc2.value.impl.Value tlc2.module.TLC.PrintT(tlc2.value.impl.Value)`],[`ToString`,`public static tlc2.value.impl.Value tlc2.module.TLC.ToString(tlc2.value.impl.Value)`],[`Assert`,`public static tlc2.value.impl.Value tlc2.module.TLC.Assert(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`:>`,`public static tlc2.value.impl.Value tlc2.module.TLC.MakeFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`@@`,`public static tlc2.value.impl.Value tlc2.module.TLC.CombineFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SortSeq`,`public static tlc2.value.impl.Value tlc2.module.TLC.SortSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`Permutations`,`public static tlc2.value.impl.Value tlc2.module.TLC.Permutations(tlc2.value.impl.Value)`],[`RandomElement`,`public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)`],[`TLCGet`,`public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`],[`TLCEval`,`public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`]])]]),td=(e,t)=>e.every(e=>gn(e,t)),nd=kt([!1,!0]),rd=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return Pt(rd(e,t,r),rd(e,r,n))},id=[`\\cup`,`\\cap`,`\\`],ad=e=>typeof e==`object`&&e.kind===`MixedSet`,od=e=>e.kind===`Interval`?B(e).elements:e.elements,sd=(e,t,n)=>{let r=od(t);if(e!==`\\cup`){let t=e===`\\cap`;return At(r.filter(e=>gn(e,n)===t))}if(r.length===0)return n;if(!N(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!gn(e,t));return At([...r,...i])},cd=[vr(`TRUE`,!0),vr(`FALSE`,!1),vr(`BOOLEAN`,nd),vr(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),xr(`=`,Dt),xr(`#`,(e,t)=>!Dt(e,t)),K(`~`,1,e=>!ur(e,0,`~`)),K(`<=>`,2,e=>ur(e,0,`<=>`)===ur(e,1,`<=>`)),K(`/\\`,2,e=>ur(e,0,`/\\`)&&ur(e,1,`/\\`)),K(`\\/`,2,e=>ur(e,0,`\\/`)||ur(e,1,`\\/`)),K(`=>`,2,e=>!ur(e,0,`=>`)||ur(e,1,`=>`)),K(`\\in`,2,e=>gn(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!gn(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=dr(e,0,`\\subseteq`),n=dr(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?td(B(t.base).elements,n.base):td(B(t).elements,n)}),...id.map(e=>K(e,2,t=>{let n=dr(t,0,e),r=dr(t,1,e);return N(n)&&N(r)&&!ad(n)&&!ad(r)?e===`\\cup`&&V(n)?r:(e===`\\cup`?Pt:e===`\\cap`?Nt:Mt)(B(n),B(r)):N(n)?sd(e,n,r):e!==`\\`&&N(r)?sd(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:dr(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=dr(e,0,`UNION`),n=ht(t)?t.elements.filter(ht):[];if(!ht(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(ad(t)||n.some(ad)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{gn(t,e)||e.elements.push(t)})),At(e.elements)}return n.length===0?jt:rd(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!P(t))throw new v(`DOMAIN expects a function but received ${U(t)}`);return An(t)})],ld=Mr(`DotDot`,`IntervalValue`,2),ud=Mr(`Neg`,`IntValue`,1),dd=[vr(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),Nr(`+`,`Plus`,(e,t)=>e+t),Nr(`-`,`Minus`,(e,t)=>e-t),Nr(`*`,`Times`,(e,t)=>e*t),Nr(`^`,`Expt`,(e,t)=>{if(t<0)throw new y(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new y(`0^0 is undefined.`);return e**t}),Nr(`\\div`,`Divide`,(e,t)=>{if(t===0)throw new y(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Sr(n))throw Cr(`${e} \\div ${t}`);return n}),Nr(`%`,`Mod`,(e,t)=>{if(t<=0)throw new y(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),Fr(`<`,(e,t)=>e<t),Fr(`>`,(e,t)=>e>t),Fr(`<=`,(e,t)=>e<=t),Fr(`>=`,(e,t)=>e>=t),K(`..`,2,e=>({kind:`Interval`,low:jr(G(e,0,`..`),ld),high:jr(G(e,1,`..`),ld)}))],fd=[vr(`Int`,{kind:`InfiniteSet`,name:`Int`}),K(`-.`,1,e=>{let t=jr(G(e,0,`-`),ud);if(Sr(-t))throw Cr(`-${t}`);return-t})],pd=(e,t,n)=>{let r=G(e,t,n),i=pn(r);if(!i)throw new y(`${n}\n${U(r)}`);return i},md=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:pd(e,t,n)},hd=(e,t,n)=>typeof e==`string`?Ve(e.slice(t,n)):R(e.slice(t,n)),gd=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,_d=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,vd=(e,t)=>{let n=ed.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?Ar(e,t):e}):t},yd=vd(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>md(e,0,gd(``,`Len`)).length),K(`\\o`,2,e=>{let t=md(e,0,_d(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=pd(e,1,_d(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new y(`${_d(`t \\o s`,`string`)}\n${U(n)}`);return Ve(t+n)}),K(`Append`,2,e=>R([...pd(e,0,_d(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=pd(e,0,gd(``,`Head`));if(t.length===0)throw new y(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=md(e,0,gd(``,`Tail`));if(t.length===0)throw new y(`Attempted to apply Tail to the empty sequence.`);return hd(t,1)}),K(`SubSeq`,3,e=>{let t=md(e,0,gd(`first `,`SubSeq`)),n=lr(e,1,`SubSeq`),r=lr(e,2,`SubSeq`);if(n>r)return hd(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new y(`The ${i.position} argument of SubSeq must be in the domain of its first argument:\n${U(G(e,0,`SubSeq`))}\n, but instead it is\n${i.value}`);return hd(t,n-1,r)}),yr(`SelectSeq`,2,e=>{let t=_r(e,1,`SelectSeq`);return R(pd(e,0,gd(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new y(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),bd=vd(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(M(t))return dn(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new v(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${De(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!M(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new y(`Attempted to compute cardinality of the value\n${U(t)}`);return ln(t)})]),xd=/* @__PURE__ */ new Map([[`Integers`,[`Naturals`]],[`Sequences`,[`Naturals`]],[`FiniteSets`,[`Naturals`,`Sequences`]],[`TLC`,[`Naturals`,`Sequences`,`FiniteSets`]],[`Randomization`,[`Naturals`,`FiniteSets`,`Sequences`]],[`_Possible`,[`TLC`,`TLCExt`,`Naturals`,`Sequences`,`FiniteSets`,`Integers`]],[`Json`,[`Sequences`,`FiniteSets`,`TLC`,`Naturals`]],[`Bags`,[`Naturals`]],[`TLCExt`,[`TLC`,`Integers`,`Naturals`,`Sequences`,`FiniteSets`]]]),Sd=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:dd};case`Integers`:return{extends:[`Naturals`],operators:fd};case`Sequences`:return{extends:[],operators:yd};case`FiniteSets`:return{extends:[],operators:bd};case`TLC`:return{extends:[],operators:vd(`TLC`,qu(t,n))};case`Randomization`:return{extends:[],operators:wu(n)};case`_Possible`:return{extends:[],operators:zu(t,n)};case`Json`:return{extends:[],operators:vu(r)};case`Bags`:return{extends:[],operators:Zl};case`TLCExt`:return{extends:[],operators:Ru(t,n)};default:return}},Cd=`$subexpression`,wd=(e,t)=>new p(`${e} at line ${t.line}, column ${t.column}`),Td=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Ed=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Dd=e=>{switch(e.kind){case`Apply`:return e.args;case`And`:case`Or`:return e.operands;case`If`:return[e.condition,e.consequent,e.alternative];case`Tuple`:case`SetEnumeration`:return e.elements;case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`FunctionApplication`:return[e.function,e.args.length===1?e.args[0]:{kind:`Tuple`,elements:e.args,location:e.location}];case`FieldAccess`:return[e.record,{kind:`String`,value:e.field,location:e.location}];case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`FunctionSet`:return[e.domain,e.range];case`Product`:return e.factors;case`Except`:return[e.function];default:return}},Od=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:oi(e.bounds),body:e.body,sets:Td(e.bounds)};case`SetMap`:return{names:oi(e.bounds),body:e.expression,sets:Td(e.bounds)};case`SetFilter`:return{names:ai(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:ai(e.pattern),body:e.body,sets:e.set?[e.set]:[]};case`UnboundedQuantifier`:case`Lambda`:return{names:e.kind===`Lambda`?e.params:e.names,body:e.body,sets:[]};default:return}},kd=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return kd(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of ar(e)){let e=kd(r,t,n);if(e)return e}},Ad=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,jd=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Md=(e,t)=>{let n=e.location,r=jd(t,e.lets,n);if(e.params.length===0)return r;if(e.args.length===0){if(e.params.some(e=>e.arity>0))throw wd(`Selected an operator with operator parameters as an argument`,n);return{kind:`Lambda`,params:e.params.map(e=>e.name),body:r,location:n}}if(e.args.length!==e.params.length)throw wd(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:Cd,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:Cd,args:e.args,location:n,resolution:Yr},location:n}},Nd=(e,t)=>{let n=t.location,r=e.kind===`Operator`?e.params.map((e,n)=>({name:`${e.name}$${t.params.length+n}`,arity:e.arity})):[],i=r.map(e=>({kind:`Identifier`,name:e.name,location:n,resolution:Yr})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:Yr}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:Yr};return Md({...t,params:[...t.params,...r]},a)},Pd=(e,t,n,r)=>{let i={params:[],args:[],lets:[],location:n},a={index:0,current:void 0},o=i=>{let o=[],s=[];for(;a.index<e.length;){let c=e[a.index];if(c.kind!==`Name`)throw wd(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>Gi(e)===l):t(l);if(u)return{definition:u,args:Ad(s,ei(u),r)};a.index++}throw wd(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=ei(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw wd(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw wd(`Cannot select a subexpression of ${s.name}`,n);i.params.push(...s.params),i.args.push(...r.args),a.current=s.body,a.index++},c=()=>{for(;a.index<e.length;){let t=e[a.index];if(t.kind!==`Name`)return;let o=a.current&&kd(a.current,t.name,[]);if(!o)throw wd(`Cannot find label ${t.name}`,n);i.lets.push(...o.lets),i.params.push(...o.label.params.map(e=>({name:e,arity:0}))),i.args.push(...Ad(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw wd(`Subexpression selection failed`,n);if(t.kind===`Colon`)return;if(o.kind===`Label`){a.current=o.body,l(t);return}if(o.kind===`Let`){if(t.kind!==`Operand`||Ed(t.operand,1)!==0)throw wd(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Od(o);if(s&&(t.kind===`Bound`||t.kind===`At`)){i.params.push(...s.names.map(e=>({name:e,arity:0}))),t.kind===`Bound`&&i.args.push(...Ad(t.args,s.names.length,r)),a.current=s.body;return}if(o.kind===`Case`&&t.kind===`Operand`){let r=[...o.arms,...o.other?[{condition:void 0,body:o.other}]:[]],i=r[Ed(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw wd(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Ed(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw wd(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw wd(`Unexpected subexpression selector`,n);let c=s?s.sets:Dd(o),u=c?.[Ed(t.operand,c.length)];if(!u)throw wd(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Nd(u.definition,{...i,args:u.args});for(c();a.index<e.length;){let t=e[a.index];if(t.kind===`Name`){for(;a.current?.kind===`Label`;)a.current=a.current.body;if(a.current?.kind!==`Let`)throw wd(`A name selector here must be from a LET clause`,n);i.lets.push(a.current.definitions);let e=s(a.current.definitions);if(e)return Nd(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw wd(`Subexpression selection failed`,n);return Md(i,a.current)},Fd=(e,t)=>{if(!e.includes(`!`)||t(e))return;let n=e.split(`!`),r=n.findIndex((e,r)=>t(n.slice(0,r+1).join(`!`)));if(r!==-1)return[{kind:`Name`,name:n.slice(0,r+1).join(`!`),args:[]},...n.slice(r+1).map(e=>({kind:`Name`,name:e,args:[]}))]},Id=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||ar(e).some(Id),Ld=(e,t)=>{if(!Id(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return Ji(e,e=>Ld(e,n))}let n=Ji(e,e=>Ld(e,t));if(n.kind===`Subexpression`)return Pd(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Fd(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Pd(i,t,n.location,a);if(a.length>0)throw wd(`Too many arguments for ${r}`,n.location);return o},Rd=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},zd=(e,t)=>{let n=Rd(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:Ld(e.expression,n)}))}},Bd=(e,t)=>{let n=Rd([...t,...e.definitions]);return e.definitions.some(e=>Id(e.body))||e.assumptions.some(e=>Id(e.expression))?{...e,definitions:e.definitions.map(e=>qi(e,e=>Ld(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:Ld(e.expression,n)}))}:e},Vd=new Map([[`Nat`,0,[],[],[]],[`+`,0,[0,0],[2,2],[1,1]],[`-`,0,[0,0],[2,2],[1,1]],[`*`,0,[0,0],[3,3],[0,0]],[`^`,0,[0,0],[2,2],[1,1]],[`<`,0,[0,0],[2,2],[1,1]],[`>`,0,[0,0],[2,2],[1,1]],[`<=`,0,[0,0],[2,2],[1,1]],[`>=`,0,[0,0],[2,2],[1,1]],[`%`,0,[0,0],[2,2],[1,1]],[`\\div`,0,[0,0],[2,2],[1,1]],[`..`,0,[0,0],[2,2],[1,1]],[`Int`,0,[],[],[]],[`-.`,0,[0],[2],[1]],[`Seq`,0,[0],[2],[1]],[`Len`,0,[0],[2],[1]],[`\\o`,0,[0,0],[2,2],[1,1]],[`Append`,0,[0,0],[2,2],[1,1]],[`Head`,0,[0],[2],[1]],[`Tail`,0,[0],[2],[1]],[`SubSeq`,0,[0,0,0],[2,2,2],[1,1,1]],[`SelectSeq`,0,[0,1],[2,2],[1,1],[],[`1,0,0`]],[`IsFiniteSet`,0,[0],[2],[1]],[`Cardinality`,0,[0],[2],[1]],[`IsABag`,0,[0],[2],[1]],[`BagToSet`,0,[0],[2],[1]],[`SetToBag`,0,[0],[3],[1]],[`BagIn`,0,[0,0],[2,2],[1,1]],[`EmptyBag`,0,[],[],[]],[`\\oplus`,0,[0,0],[2,2],[1,1]],[`\\ominus`,0,[0,0],[2,2],[1,1]],[`BagUnion`,0,[0],[2],[1]],[`\\sqsubseteq`,0,[0,0],[2,2],[1,1]],[`SubBag`,0,[0],[2],[1]],[`BagOfAll`,0,[1,0],[2,2],[1,1]],[`BagCardinality`,0,[0],[2],[1]],[`CopiesIn`,0,[0,0],[2,2],[1,1]],[`Print`,0,[0,0],[3,3],[0,1]],[`PrintT`,0,[0],[3],[0]],[`Assert`,0,[0,0],[2,3],[1,0]],[`JavaTime`,0,[],[],[]],[`TLCGet`,0,[0],[3],[0]],[`TLCSet`,0,[0,0],[3,3],[0,0]],[`:>`,0,[0,0],[2,3],[1,1]],[`@@`,0,[0,0],[2,2],[1,1]],[`Permutations`,0,[0],[2],[1]],[`SortSeq`,0,[0,2],[2,2],[1,1],[],[`1,0,0`,`1,0,1`]],[`RandomElement`,0,[0],[3],[1]],[`Any`,0,[],[],[]],[`ToString`,0,[0],[2],[1]],[`TLCEval`,0,[0],[3],[1]],[`AssertEq`,0,[0,0],[2,2],[1,1]],[`AssertError`,0,[0,0],[2,3],[1,0]],[`TLCGetOrDefault`,0,[0,0],[3,3],[0,0]],[`TLCGetAndSet`,0,[0,2,0,0],[3,3,3,3],[0,0,0,0],[],[`1,2,1`]],[`Trace`,0,[],[],[]],[`CounterExample`,0,[],[],[]],[`ToTrace`,0,[0],[3],[0]],[`TLCModelValue`,0,[0],[2],[1]],[`TLCDefer`,0,[0],[3],[0]],[`TLCNoOp`,0,[0],[3],[1]],[`PickSuccessor`,0,[0],[3],[1]],[`TLCCache`,0,[0,0],[3,3],[1,0]],[`TLCFP`,0,[0],[3],[0]],[`TLCEvalDefinition`,0,[0],[3],[0]],[`ToJson`,0,[0],[2],[1]],[`ToJsonArray`,0,[0],[2],[1]],[`ToJsonObject`,0,[0],[2],[1]],[`JsonSerialize`,0,[0,0],[3,3],[0,0]],[`JsonDeserialize`,0,[0],[3],[0]],[`ndJsonSerialize`,0,[0,0],[3,3],[0,0]],[`ndJsonDeserialize`,0,[0],[3],[0]],[`RandomSubset`,0,[0,0],[2,2],[1,1]],[`RandomSetOfSubsets`,0,[0,0,0],[2,3,2],[1,0,1]],[`TestRandomSetOfSubsets`,0,[0,0,0],[2,3,2],[1,0,1]]].map(e=>[e[0],{name:e[0],level:e[1],params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set,formals:e[2].map((e,t)=>({name:`$${t}`,arity:e})),maxLevels:e[3],weights:e[4],minMaxLevels:e[5]??[],conditions:new Set(e[6]),nonLeibniz:/* @__PURE__ */ new Set}])),Hd=(e,t)=>`${e}${t}`,Ud=(e,t,n)=>`${e}${t}${n}`,Wd=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},Gd=(e,t,n)=>`${e},${t},${n}`,Kd=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),qd=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),Jd=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),Yd=(e,t,n,r)=>({...Kd(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),Xd=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,Zd=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,Qd=new Map([[`=`,0,[2,2],[1,1]],[`#`,0,[2,2],[1,1]],[`\\in`,0,[2,2],[1,1]],[`\\notin`,0,[2,2],[1,1]],[`\\subseteq`,0,[2,2],[1,1]],[`\\cup`,0,[2,2],[1,1]],[`\\cap`,0,[2,2],[1,1]],[`\\`,0,[2,2],[1,1]],[`=>`,0,[3,3],[1,1]],[`<=>`,0,[3,3],[1,1]],[`/\\`,0,[3,3],[1,1]],[`\\/`,0,[3,3],[1,1]],[`~`,0,[3],[1]],[`SUBSET`,0,[2],[1]],[`UNION`,0,[2],[1]],[`DOMAIN`,0,[2],[1]],[`~>`,3,[3,3],[0,0]],[`-+->`,3,[3,3],[0,0]],[`\\cdot`,2,[2,2],[0,0]],[`TRUE`,0,[],[]],[`FALSE`,0,[],[]],[`BOOLEAN`,0,[],[]],[`STRING`,0,[],[]]].map(([e,t,n,r])=>[e,{...Yd(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),$d=Yd(`$Set`,0,[2],[1]),ef=Yd(`$Junction`,0,[3],[1]),tf=Yd(`$Choose`,0,[2],[1]),nf=Yd(`$Function`,0,[3],[1]),rf=Yd(`$FcnApply`,0,[2,2],[1,1]),af=Yd(`$RcdSelect`,0,[2,0],[1,1]),of=Yd(`'`,2,[1],[0]),sf=Yd(`ENABLED`,1,[2],[0]),cf=Yd(`[]`,3,[3],[0]),lf=Yd(`$SquareAct`,2,[2,1],[0,0]),uf=Yd(`$WF`,3,[1,2],[0,0]),df=Yd(`$TemporalExists`,3,[3],[0]),ff=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),pf=e=>e.map(e=>({name:e,arity:0})),mf=(e,t)=>t.location.range?g(`${e}.`,t.location.range):new p(`${e} at line ${t.location.line}, column ${t.location.column}`),hf=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),gf=e=>e.kind!==`Let`&&e.kind!==`Label`,_f=e=>{let t=/* @__PURE__ */ new Map,n=(t,n)=>{let r=n.get(t);if(r?.kind===`Formal`)return{kind:`Declared`,name:t,level:0,arity:r.arity};if(r?.kind===`Let`)return{kind:`Defined`,levels:v(r.definition,r.scope)};if(e.constants.has(t))return{kind:`Declared`,name:t,level:0,arity:0};if(e.variables.has(t))return{kind:`Declared`,name:t,level:1,arity:0};let i=e.getDefinition(t);if(i)return{kind:`Defined`,levels:v(i,/* @__PURE__ */ new Map)};let a=Qd.get(t)??Vd.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=Kd(Math.max(t,...n.map(e=>e.data.level)));return r.params.add(e),n.forEach((t,n)=>{t.data.params.forEach(t=>{r.params.add(t),r.argParams.add(Ud(e,n,t))}),t.data.constraints.forEach((e,t)=>qd(r.constraints,t,e)),Jd(r.argConstraints,Hd(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>Jd(r.argConstraints,t,e)),t.data.argParams.forEach(e=>r.argParams.add(e))}),r},i=(e,t,n=[],r=[])=>{let i=e=>r.includes(e);if(t.forEach((t,n)=>{if(!(t.operator||t.declared)&&t.data.level>Xd(e,n))throw new p(`Level error in applying operator ${e.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator`)}),n.some(e=>e.level>2))throw new p(`Level error in applying operator ${e.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`);let a=n=>{let r=e.formals.findIndex(e=>e.name===n);return r===-1?void 0:t[r]},o=(t,n,r)=>e.conditions.has(Gd(t,n,r)),s=Kd(Math.max(e.level,...t.filter((t,n)=>Zd(e,n)===1).map(e=>e.data.level),...n.map(e=>e.level)));return e.params.forEach(e=>s.params.add(e)),t.forEach((t,n)=>{Zd(e,n)===1&&t.data.params.forEach(e=>s.params.add(e))}),n.forEach(e=>e.params.forEach(e=>s.params.add(e))),r.forEach(e=>s.params.delete(e)),e.constraints.forEach((e,t)=>qd(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||qd(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>qd(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||qd(s.constraints,t,Xd(e,n))})),t.forEach((e,n)=>{let r=e.operator;r&&t.forEach((e,t)=>r.formals.forEach((i,a)=>{o(n,t,a)&&e.data.params.forEach(e=>qd(s.constraints,e,Xd(r,a)))}))}),e.argParams.forEach(e=>{let t=Wd(e),n=a(t.operator)?.operator;n&&qd(s.constraints,t.param,Xd(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>Jd(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>Jd(s.argConstraints,Hd(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&Jd(s.argConstraints,Hd(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=Wd(e),n=a(t.operator);n&&Jd(s.argConstraints,Hd(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(Wd(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=Wd(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(Ud(n.declared.name,t.index,t.param));else{let n=a(t.param);if(!n){s.argParams.add(e);return}n.data.params.forEach(e=>s.argParams.add(Ud(t.operator,t.index,e)))}}),t.forEach((e,n)=>{let r=e.declared;r&&t.forEach((e,t)=>Array.from({length:r.arity},(i,a)=>{o(n,t,a)&&e.data.params.forEach(e=>s.argParams.add(Ud(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=_(`LAMBDA`,pf(e.params),e.body,t);return{data:n,operator:n}}let r=e.kind===`OperatorReference`?e.operator:e.kind===`Identifier`?e.name:void 0;if(r!==void 0){let i=n(r,t);if(i.kind===`Defined`&&(i.levels.formals.length>0||e.kind===`OperatorReference`))return{data:i.levels,operator:i.levels};if(i.kind===`Declared`&&i.arity>0){let e=Kd();return e.params.add(r),{data:e,declared:{name:r,arity:i.arity}}}}return{data:m(e,t)}},o=(e,t)=>e.map(e=>a(e,t)),s=(e,t,n,r=[],a=[])=>{let s=ff(n,pf(a));return i(e,o(t,s),r.map(e=>m(e,n)),a)},c=(e,t)=>e.kind===`Declared`?r(e.name,e.level,t):i(e.levels,t),l=(e,t)=>{let n=e.map(e=>e.data.level);if(n.includes(2)&&n.includes(3))throw mf(`Formula has both temporal formula and action as arguments`,t)},u=(e,t)=>{if((e.operator===`~>`||e.operator===`-+->`)&&t.some(e=>e.data.level===2))throw mf(`Action used where only temporal formula or state predicate allowed`,e);hf.has(e.operator)&&l(t,e)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&gf(n)&&n.kind!==r)throw mf(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e)},f=(e,t)=>{let n=new Map(t);e.definitions.forEach(e=>n.set(e.name,{kind:`Let`,definition:e,scope:n}));let r=m(e.body,n),i={level:r.level,params:new Set(r.params),constraints:new Map(r.constraints),argConstraints:new Map(r.argConstraints),argParams:new Set(r.argParams)};return e.definitions.forEach(e=>{let t=v(e,n);t.constraints.forEach((e,t)=>qd(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>Jd(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{try{return h(e,t)}catch(t){throw!(t instanceof p)||t.sany?t:mf(t.message,e)}},h=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return Kd();case`Identifier`:return c(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return u(e,r),c(n(e.operator,t),r)}case`OperatorReference`:case`Lambda`:return a(e,t).data;case`And`:case`Or`:{let n=o(e.operands,t);return l(n,e),i(ef,n)}case`Prime`:case`Unchanged`:return s(of,[e.expression],t);case`Enabled`:return s(sf,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(cf,[n])}case`If`:return s(ef,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(ef,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return f(e,t);case`Forall`:case`Exists`:{let n=s(ef,[e.body],t,e.bounds.map(e=>e.set),oi(e.bounds)),r=n.level===3?e.bounds.find(e=>m(e.set,t).level===2):void 0;if(r)throw mf(`Action-level bound of quantified temporal formula`,r.set);return n}case`UnboundedQuantifier`:return s(e.isTemporal?df:ef,[e.body],t,[],e.names);case`Choose`:return s(tf,[e.body],t,e.set?[e.set]:[],ai(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s($d,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s($d,[e.predicate],t,[e.bound.set],ai(e.bound.pattern));case`SetMap`:return s($d,[e.expression],t,e.bounds.map(e=>e.set),oi(e.bounds));case`FunctionConstruction`:return s(nf,[e.body],t,e.bounds.map(e=>e.set),oi(e.bounds));case`Record`:return s(nf,e.fields.map(e=>e.value),t);case`RecordSet`:return s($d,e.fields.map(e=>e.value),t);case`Except`:return s($d,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(rf,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s($d,e.args,t)}]);case`FieldAccess`:return i(af,[a(e.record,t),{data:Kd()}]);case`BoxAction`:case`AngleAction`:return s(lf,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(uf,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return Kd()}},g=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>g(e,a,n,i),o=(e,o)=>{let s=n(e,t);s.kind===`Declared`?(r&&i.add(e),o.forEach(e=>a(e))):o.forEach((e,t)=>a(e,r||s.levels.nonLeibniz.has(t)))};switch(e.kind){case`Identifier`:return o(e.name,[]),i;case`Apply`:return o(e.operator,e.args),i;case`Lambda`:case`Let`:return i;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:case`BoxAction`:case`AngleAction`:case`WeakFairness`:case`StrongFairness`:return ar(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,ff(t,pf(e.names))),i;default:return Ji(e,(e,n)=>(a(e,r,ff(t,pf(n))),e)),i}},_=(e,t,n,r)=>{let i=ff(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=g(n,i),c={...Kd(a.level),name:e,formals:t,nonLeibniz:new Set(t.flatMap((e,t)=>s.has(e.name)?[t]:[])),maxLevels:t.map(e=>Math.min(3,a.constraints.get(e.name)??3)),weights:t.map(e=>+!!a.params.has(e.name)),minMaxLevels:t.map(e=>Array.from({length:e.arity},(t,n)=>a.argConstraints.get(Hd(e.name,n))??0)),conditions:new Set(t.flatMap((e,n)=>t.flatMap((t,r)=>Array.from({length:e.arity},(e,t)=>t).filter(n=>a.argParams.has(Ud(e.name,n,t.name))).map(e=>Gd(n,r,e)))))};return a.params.forEach(e=>{o(e)||c.params.add(e)}),a.constraints.forEach((e,t)=>{o(t)||c.constraints.set(t,e)}),a.argConstraints.forEach((e,t)=>{o(Wd(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=Wd(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},v=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...Kd(),name:e.name,formals:i,maxLevels:i.map(()=>3),weights:i.map(()=>0),minMaxLevels:i.map(()=>[]),conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set});let a=e.kind===`Function`?{kind:`FunctionConstruction`,bounds:e.bounds,body:e.body,location:e.location}:e.body,o=_(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:v,toOperand:a}},vf=(e,t,n)=>{let r=new Map(t);e.assumptions.forEach(e=>{e.kind===`NewSymbol`?(e.set&&n.analyze(e.set,r),r.set(e.name,{kind:`Formal`,arity:e.arity})):e.kind===`AssumeProve`?vf(e,r,n):n.analyze(e,r)}),n.analyze(e.conclusion,r)},yf=(e,t)=>{let n=_f(t);Ri([...e.definitions.filter(e=>!e.name.includes(`!`)).map(e=>({location:e.location,check:()=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)})),...e.assumptions.map(e=>({location:e.location,check:()=>n.analyze(e.expression,/* @__PURE__ */ new Map)})),...e.theorems.map(e=>({location:e.location,check:()=>e.statement.kind===`AssumeProve`?vf(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map)}))])},bf=(e,t)=>e.maxLevels[t]??3,xf=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=_f({constants:new Set(i.constants.map(e=>e.name)),variables:new Set(i.variables),getDefinition:i.getDefinition});return n.set(e,a),a},i=/* @__PURE__ */ new Map,a=e=>{let n=i.get(e);if(n)return n;let a=t(e),o=r(e),s=a.definitions.map(e=>o.analyzeDefinition(e,/* @__PURE__ */ new Map)),c={isConstant:a.variables.length===0&&s.every(e=>e.level===0),constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set};c.isConstant||a.constants.forEach(e=>qd(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>qd(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>Jd(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=Wd(e);t(n.operator,n.param)&&c.argParams.add(e)})};return s.forEach(e=>l(e,(t,n)=>e.formals.every(e=>e.name!==t&&e.name!==n))),a.assumptions.forEach(e=>l(o.analyze(e,/* @__PURE__ */ new Map),()=>!0)),i.set(e,c),c},o=/* @__PURE__ */ new Set;if(e.forEach(e=>{let n=`at line ${e.location.line}, column ${e.location.column}`,i=e=>o.add(`${e} ${n}`),s=t(e.module),c=a(e.module),l=r(e.instancer),u=/* @__PURE__ */ new Map;e.lets.forEach(e=>u.set(e.name,{kind:`Let`,definition:e,scope:u}));let d=[...s.constants.map(e=>({...e,maximumLevel:0})),...s.variables.map(e=>({name:e,arity:0,maximumLevel:1}))].flatMap(t=>{let n=e.substitutions.get(t.name);if(!n)return[];if(t.arity===0){let e=l.analyze(n,u);return[{...t,level:e.level,operator:void 0,isLeibniz:!0}]}let r=l.toOperand(n,u);return[{...t,level:r.data.level,operator:r.operator,isLeibniz:r.operator===void 0||r.operator.nonLeibniz.size===0}]}),f=(t,n)=>`Level error in instantiating module '${e.module}': the level of the expression or operator substituted for '${t}' must be at most ${n}`;d.forEach(t=>{!c.isConstant&&t.level>t.maximumLevel&&i(f(t.name,t.maximumLevel)),t.isLeibniz||i(`Error in instantiating module '${e.module}': a non-Leibniz operator substituted for '${t.name}'`)}),d.forEach(t=>{let n=c.constraints.get(t.name);n!==void 0&&t.level>n&&i(f(t.name,n));let r=t.operator;r&&Array.from({length:t.arity},(n,a)=>{let o=c.argConstraints.get(Hd(t.name,a));o!==void 0&&bf(r,a)<o&&i(`Level error in instantiating module '${e.module}': the level of the argument ${a+1} of the operator ${r.name} must be at least ${o}`)})}),c.argParams.forEach(t=>{let n=Wd(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=bf(r,n.index);a.level>o&&i(`Level error when instantiating module '${e.module}': the level of the argument ${n.index} of the operator ${n.operator}' must be at most ${o}`)})}),o.size>0)throw new p([...o].join(`
|
|
419
|
-
`))},Sf=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],Cf=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),wf=new Map(Yu.flatMap(e=>e.map(t=>[t,e[0]]))),Tf=e=>wf.get(e)??e,Ef=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Df=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Ef(e.name)&2147483647)%t,i=()=>{let t=e.buckets.length*2+1,n=Array.from({length:t},()=>[]);for(let i=e.buckets.length-1;i>=0;i--)for(let a of e.buckets[i])n[r(a,t)].unshift(a);e.buckets=n,e.threshold=Math.floor(t*.75)};return{put:a=>{t.has(a.key)||(n.length>=e.threshold&&i(),e.buckets[r(a,e.buckets.length)].unshift(a),t.add(a.key),n.push(a))},inserted:n,enumerate:()=>e.buckets.toReversed().flat()}},Of=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),kf=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Tf(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Tf(n.text),end:t+2};if(r?.text!==`(`)return{name:n.text,end:t+1};let i=e.findIndex((e,n)=>n>t&&e.text===`)`);return{name:n.text,end:i+1}},Af=(e,t)=>{let n=[];for(let r=t;;){let t=kf(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},jf=e=>({line:e.line,column:e.column}),Mf=(e,t,n)=>{let r=/* @__PURE__ */ new Set,i=(a,o)=>{let s={key:o,unit:t,extends:[],instances:[],inner:[],allExtends:r};for(let t=a+1;t<e.length;t++){let a=e[t];if(a.kind===`ModuleEnd`)return{references:s,end:t};if(a.kind===`Separator`&&e[t+1]?.text===`MODULE`){let r=e[t+2].text,a=i(t,`${o}/${r}`);n.set(r,a.references),s.inner.push(a.references),t=a.end}else if(a.text===`EXTENDS`){let n=Af(e,t+1);s.extends.push(...n),n.forEach(e=>r.add(e))}else a.text===`INSTANCE`&&e[t+1]?.kind===`Identifier`&&s.instances.push(e[t+1].text)}return{references:s,end:e.length}};return i(0,t??``).references},Nf=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Pf={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Ff=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Nf(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Nf(e[n+1],e[n+2])?n+=Nf(e[n+2],e[n+3])?3:2:(r.text!==`MODULE`||e[n-1]?.kind!==`Separator`)&&t.push(r.kind===`String`?`"${r.text.replace(/[\\"\n\t\r\f]/g,e=>Pf[e])}"`:r.text)}return t},If=e=>{let t=/* @__PURE__ */ new Map,n=[];return e.forEach((r,i)=>{r.kind===`Separator`&&e[i+1]?.text===`MODULE`&&n.push({name:e[i+2].text,start:i});let a=r.kind===`ModuleEnd`?n.pop():void 0;a&&!t.has(a.name)&&t.set(a.name,{start:a.start,end:i+1})}),t},Lf=(e,t)=>e.find(e=>e.name===t)??e.map(e=>Lf(e.modules,t)).find(Boolean),Rf=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=i=>{let a=n.get(i??``);if(a)return a;let o=i===void 0?e:$u.get(i)??t?.(i)??Gc(e,i),s=o===void 0?[]:ue(o),c=If(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=qc(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>Lf(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},zf=(e,t,n)=>{let r=Rf(e,t),i=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],a=(e,n)=>{let i=Af(t,e+1);r.push({location:jf(t[e]),apply:e=>i.forEach(t=>e.put(Of(t,n,!1)))})},s=new Set(n.definitions.filter(e=>e.isRecursive).map(e=>e.name)),c={value:0};t.slice(e.start,e.end).forEach((n,o)=>{let l=e.start+o,u=t[l];if(u.kind===`Separator`&&t[l+1]?.text===`MODULE`){if(c.value++,c.value===2){let e=t[l+2].text;r.push({location:jf(u),apply:t=>t.put(Of(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&a(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&a(l,`variable`),u.text===`RECURSIVE`&&Af(t,l+1).every(e=>s.has(e))&&a(l,`definition`),Cf.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(jf(u)),r.push({location:jf(u),apply:e=>e.put(Of(t[l+1].text,`theorem`,!1))})))}),n.assumptions.forEach(e=>{i.push(e.location);let t=e.name;t!==void 0&&r.push({location:e.location,apply:e=>e.put(Of(t,`theorem`,!1))})});let l=e=>i.some(t=>t.line===e.line&&t.column===e.column);return n.definitions.forEach(e=>{if(l(e.location))return;let t=Tf(e.name);r.push({location:e.location,apply:n=>n.put(Of(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=o(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),a=n.filter(e=>e.kind===`theorem`);[...i,...a].forEach(n=>{n.isLocal||t.put(Of(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Of(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>$r(e.location,t.location)?-1:+!!$r(t.location,e.location))},a=/* @__PURE__ */ new Map,o=e=>{let t=a.get(e??``);if(t)return t;let n=Df();a.set(e??``,n),Ju.toReversed().forEach(e=>n.put(Of(e,`builtin`,!1)));let s=r(e);return s.getModule().extends.forEach(e=>o(e).inserted.forEach(e=>{e.isLocal||n.put(e)})),i(s).forEach(e=>e.apply(n)),n};return o(void 0).enumerate().filter(e=>e.kind===n).map(e=>e.name).reverse()},Bf=(e,t,n)=>{let r=Rf(e,n),i=/* @__PURE__ */ new Set,a=e=>{i.add(e)},o=e=>{e.kind===`ModelValue`&&a(e.name),e.kind===`String`&&a(e.value),e.kind===`Set`&&e.elements.forEach(o)};t.constants.forEach(e=>{e.args?.forEach(o),o(e.value)}),Xu.forEach(a);let s=e=>{let t=r(e);return t.tokens.slice(t.start,t.end)},c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u=e=>{let t=l.get(e);if(t)return t;let n=Mf(s(e),e,c);return l.set(e,n),n},d=e=>c.get(e)??u(e),f=/* @__PURE__ */ new Set,p=(e,t)=>c.has(t)||f.has(`${e.key}>${t}`),m=(e,t,n)=>{let r=[...e.extends.map(d),...e.instances.filter(t=>p(e,t)).map(d),...e.inner];for(let e of r){let r=n(e,t);if(r)return r}},h=e=>{let t=(n,r)=>{if(r.has(n.key))return;r.add(n.key);let i=e(n).find(e=>!p(n,e));return i===void 0?m(n,r,t):[n,i]};return t},g=h(e=>e.extends),_=h(e=>e.instances),v=/* @__PURE__ */ new Set([void 0]),y=/* @__PURE__ */ new Map;Ff(s(void 0)).forEach((e,t)=>{t===3&&Qu.forEach(a),a(e)});let b=u(void 0);for(;;){let e=g(b,/* @__PURE__ */ new Set)??_(b,/* @__PURE__ */ new Set);if(!e)break;let[t,n]=e;f.add(`${t.key}>${n}`),y.set(t.unit,[...y.get(t.unit)??[],n]),!v.has(n)&&(v.add(n),Ff(s(n)).forEach(a))}Sf.forEach(a);let x=/* @__PURE__ */ new Set,ee=e=>{if(x.has(e))return;x.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(ee),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return ee(void 0),Zu.forEach(a),[...i]},Vf=t=>{switch(t.kind){case`Number`:try{return Oe(t.value)}catch(t){throw n(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return Ze(t.name);case`Set`:return kt(t.elements.map(Vf))}},Hf=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],Uf=e=>new p(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),Wf=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:Yr},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),Gf=(e,t,n)=>{let r=`{ ${n.map(e=>`<${[...e[0],e[1]].map(e=>U(e)).join(`, `)}>`).join(`, `)}}`;return{kind:`Builtin`,name:e,arity:t,evaluate:e=>{let t=n.find(t=>{if(t[0].length!==e.length)throw new v(`Attempted to apply the operator ${r}\nwith wrong number of arguments.`);return t[0].every((t,n)=>{let r=e[n];return(typeof r!=`object`||r.kind!==`Operator`)&&et(t,r)})});if(t)return t[1];throw new v(`Attempted to apply operator:\n${r}\nto arguments (${e.map(e=>typeof e==`object`&&e.kind===`Operator`?e.name:U(e)).join(`, `)}), which is undefined.`)},evaluateUnary:void 0,evaluateBinary:void 0}},Kf=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||ar(e).some(e=>Kf(e,t)),qf=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(ra(e),n.get(e)??n.size)),n},Jf=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),Yf=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw wo(e);if(e.kind===`Number`&&!ps(e.value))throw To(e);Yf(e.kind===`Let`?[...ar(e),...Jf(e.instances??[])]:ar(e))}),Xf=(e,t)=>{let n=qc(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=new Map(cd.map(e=>[e.name,e])),s=/* @__PURE__ */ new Map,c=Ol(e.checkDeadlock,t.seed),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=[],f=/* @__PURE__ */ new Map,h=[],g=[],b=(e,t)=>h.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),x={value:0},ee=e=>`${e}#${x.value++}`,te=[],ne=/* @__PURE__ */ new Map,re=e=>{let n=s.get(e);if(n)return n;let r=Sd(e,t.print,c,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>re(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{o.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),s.set(e,i),i},ie=e=>{let t=re(e);return t&&b(e,xd.get(e)??[]),t},S=e=>(Yf([...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),...e.assumptions.map(e=>e.expression),...e.theorems.flatMap(e=>e.statement.kind===`AssumeProve`?[]:[e.statement]),...Jf(e.instances)]),e.modules.forEach(S),e);S(n);let ae=(e,n)=>{let r=t.loadModule?.(e)??mc.get(e)??Gc(t.source,e);if(r===void 0)throw m([{location:`In module ${n}`,message:`Cannot find source file for module ${e} imported in module ${n}.`}],!0);let i=qc(r);if(i.name!==e)throw m([{location:`Unknown location`,message:`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`}],!0);return S(i)},C=e=>{let t=g.indexOf(e.name);if(t!==-1)throw new p(`Circular dependency among .tla files; dependency cycle is: ${[...g.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];g.push(e.name),h.push(n);let i=A(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});h.pop(),g.pop();let a=r.find(e=>n.has(e.name));if(a)throw Uf(a);return{linked:i,closure:n}},oe=(e,t)=>{let n=l.get(e);if(n)return b(e,f.get(e)??[]),n;let r=C(ae(e,t));return l.set(e,r.linked),f.set(e,r.closure),b(e,r.closure),r.linked},w=(e,t,n,o,s)=>{let c=s?void 0:ie(e.module);if(c)return e.name===void 0?c:new Map([...c].map(([t,n])=>[`${e.name}!${t}`,n]));let l=s??oe(e.module,t.name),u=Hf(l),d=`#${x.value++}`,f=new Map(e.params.map(e=>[e.name,`${e.name}${d}`])),p=Li(zd(e,t),u,t,n);te.push({module:e.module,instancer:t.name,lets:[],substitutions:p,location:e.location});let m=ha({params:e.params.map(e=>({...e,name:`${e.name}${d}`})),substitutions:new Map([...p].map(([e,t])=>[e,Hi(t,f)])),variables:new Set(l.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(n,s,c)=>{let l=ee(`${s}@${t.name}`);return r.set(l,c(l)),i.set(l,!o),a.set(l,{source:n,prefix:e.params.length}),l},createName:ee}),h=new Set(u.map(e=>e.name)),g=/* @__PURE__ */ new Map;return l.exported.forEach((t,n)=>{if(h.has(n))return;if(e.name===void 0){let r=m.getKey(t.key);u.length>0&&ne.set(r,{name:n,location:e.location}),g.set(n,{key:r,arity:t.arity});return}let r=m.getQualifiedKey(t.key);u.length>0&&ne.set(r,{name:`${e.name}!${n}`,location:e.location}),g.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),g},T=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:Yr})),E=(e,t,n,r,i)=>({kind:`Operator`,name:e,params:n,body:r.length===0?{kind:`Identifier`,name:t,location:i}:{kind:`Apply`,operator:t,args:T(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),D=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),O=(e,t,n)=>{if(t.arity===0)return{params:[],body:e};if(e.kind===`Lambda`)return{params:e.params.map(e=>({name:e,arity:0})),body:e.body};let r=D(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:T(r,n),location:n}}},k=(e,t,n,a)=>{let o=e.location,s=a?void 0:ie(e.module);if(s)return e.name===void 0?[]:[...s].map(([t,n])=>{let r=D(n.arity);return E(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??oe(e.module,n),l=`#${x.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=Hf(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};te.push({module:e.module,instancer:n,lets:t,substitutions:new Map(d.map(e=>[e.name,f(e)])),location:o});let p=new Set(e.params.map(e=>e.name)),m=e=>Kf(f(e),p),h=d.map(t=>{let n=O(f(t),t,o);return{kind:`Operator`,name:`${t.name}${l}`,params:[...m(t)?e.params:[],...n.params],body:n.body,isLocal:!0,isRecursive:!1,location:o}}),g=[],_=ha({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:T(e.params,o),location:o,resolution:Yr}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:Yr}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n,r)=>{let i=`${n}@${e.module}${l}.${g.length}`,a=r(i);return g.push(a.kind===`Operator`?{...a,name:i}:Wf(a,i)),i},createName:ee}),v=new Set(d.map(e=>e.name)),y=[...c.exported].filter(([e])=>!v.has(e)).map(([t,n])=>{let r=_.getKey(n.key),i=D(n.arity),a=[...e.params,...i];return E(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...y]},se=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),A=(e,a)=>{let o=Sc(e,t.loadClass?.(e.name)),s=new Map([...cd.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,f=[],p=[...o.constants],m=o.variables.map(e=>e.name),h=o.variables.map(e=>e.location),g=(e,t)=>e.forEach((e,n)=>{s.set(n,e),t&&c.set(n,e)});o.extends.forEach(e=>{let t=a.modules.get(e),n=t?void 0:ie(e);if(n){g(n,!0);return}let r=t??oe(e,o.name);p.push(...r.constants.filter(e=>p.every(t=>t.name!==e.name))),r.variables.forEach((e,t)=>{m.includes(e)||(m.push(e),h.push(r.variableLocations[t]))}),g(r.exported,!0),r.modules.forEach((e,t)=>l.set(t,e)),f.push(r)}),o.constants.forEach(e=>c.set(e.name,{key:e.name,arity:e.arity,declaration:`Constant`})),o.variables.forEach(e=>c.set(e.name,{key:e.name,arity:0,declaration:`Variable`}));let _=p.length===0&&m.length===0,v=e=>o===n?e.name:`${e.name}@${a.id}`,y=/* @__PURE__ */ new Map,b=e=>({imported:s,importedAt:y,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:v}),x=()=>new Map([...a.modules,...l]),ee=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>$r(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>$r(t.location,e)).map(e=>[e.name,{key:v(e),arity:ei(e)}])]),te=e=>{let t=x();if(t.has(e.name))throw Uf(e);a.nested.push(e);let n=A(e,{id:`${a.id}/${e.name}`,symbols:ee(e.location),modules:t,nested:a.nested});l.set(e.name,n),u.has(e.name)||u.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=w(e,o,b(o),_,x().get(e.module));t.forEach((t,n)=>{s.has(n)||y.set(n,e.location)}),g(t,!e.isLocal)}})),...o.modules.map(e=>({location:e.location,link:()=>te(e)}))].sort((e,t)=>$r(e.location,t.location)?-1:1).forEach(e=>e.link()),Fi(o,b(o));let ne=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&$r(e.location,t.location)},re=e=>{let t=o.modules.find(t=>t.name===e.module);return t?ne(t)?l.get(t.name):void 0:x().get(e.module)},S=Bd(ya(o,(e,t)=>k(e,t,o.name,re(e))),se(s));zi(S,b(S)),S.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:ei(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),yf(S,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e)});let ae={module:S,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:l,extended:f};return d.push(ae),ae},ce=C(n).linked,le=e=>ce.visible.get(e)?.key??e;ce.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let ue=[],de=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>de(e,t)),ue.push(...e.module.assumptions))};de(ce,/* @__PURE__ */ new Set);let fe=ce.constants.map(e=>e.name),j=ce.variables,pe=e=>e.module===void 0?[e.name,le(e.name)]:e.module===n.name||fe.includes(e.name)?[]:[(l.get(e.module)??u.get(e.module))?.visible.get(e.name)?.key??e.name],me=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:ce.constants.find(t=>t.name===e)?.arity??0},he=/* @__PURE__ */ new Map,ge=/* @__PURE__ */ new Set,_e=(e,t)=>{o.set(e,t),r.delete(e),he.delete(e),ge.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=Vf(e.value);pe(e).forEach(e=>{let n=me(e);n===0?he.set(e,t):_e(e,{kind:`Builtin`,name:e,arity:n,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0,isLazy:!0})})});let ve=/* @__PURE__ */ new Map;e.constants.forEach(e=>{if(e.args===void 0)return;let t=`${e.module??``}!${e.name}`,n=ve.get(t)??{name:e.name,module:e.module,rows:[]};if(n.rows.length>0&&n.rows[0][0].length!==e.args.length)throw new _(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(Vf),Vf(e.value)]),ve.set(t,n)}),ve.forEach(e=>pe(e).forEach(t=>_e(t,Gf(e.name,me(t)||e.rows[0][0].length,e.rows))));let ye=new Map(e.substitutions.flatMap(e=>pe(e).map(t=>[t,le(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!fe.includes(n)&&!ce.visible.has(n))throw new _(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new _(`In the configuration file, the identifier ${i} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`);let a=le(i),s=r.get(a);if(!(s!==void 0||o.has(a)||he.has(a)||fe.includes(i)||j.includes(i)))throw new _(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(ce.constants.find(e=>e.name===n)?.arity??ce.visible.get(n)?.arity))throw new _(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)});let be=new Set([...e.constants,...e.substitutions].filter(e=>e.module!==void 0).flatMap(pe)),xe=(e,t)=>{if(be.has(e))return{key:e,prefix:t};let n=a.get(e);return n&&xe(n.source,t+n.prefix)};a.forEach((e,t)=>{let n=xe(e.source,e.prefix),i=r.get(t);if(!n||!i)return;let a=i.kind===`Operator`?i.params:[],o=E(t,n.key,a,a.slice(n.prefix),i.location);r.set(t,o),ce.visible.forEach((e,n)=>{e.key===t&&n!==t&&r.set(n,o)})});let Se=fe.filter(e=>!he.has(e)&&!ye.has(e)&&!ge.has(e));if(Se.length>0)throw new _(`The constant parameter ${zf(t.source,t.loadModule,`constant`).find(e=>Se.includes(e))??Se[0]} is not assigned a value by the configuration file.`);let Ce={runtime:c,definitions:r,builtins:o,constants:he,substitutions:ye,variables:j,variableIndex:qf(j,d.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};xf(te,e=>{let t=l.get(e)??u.get(e)??ce;return{constants:t.constants,variables:t.variables,definitions:[...new Set([...t.visible.values()].flatMap(e=>r.get(e.key)??[]))],assumptions:t.module.assumptions.map(e=>e.expression),getDefinition:e=>r.get(t.visible.get(e)?.key??e)}});let we=_f({constants:new Set(he.keys()),variables:/* @__PURE__ */ new Set([...j,...[`TLCGet`,`Trace`,`CounterExample`].filter(e=>o.has(e))]),getDefinition:e=>jo(e,Ce)}),Te=e=>{try{X(e,{environment:Ce,scope:void 0,state:void 0,next:void 0});return}catch(e){if(e instanceof v)return e;throw e}};return ye.forEach((e,t)=>{let n=r.get(e),i=fe.includes(t)&&n?.kind===`Operator`&&n.params.length===0&&we.analyzeDefinition(n,/* @__PURE__ */ new Map).level>0?Te(n.body):void 0;if(i)throw new _(`The configuration file substitutes constant ${t} with non-constant ${e}${i instanceof y?``:` - specifically: ${i.message}`}`)}),c.isStarted=!0,{environment:Ce,assumptions:ue,variableLocations:ce.variableLocations,instanceActions:ne}},Zf={kind:`Boolean`,value:!0},Qf={kind:`Boolean`,value:!1},$f=e=>e?Zf:Qf,ep=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,tp=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),np=(e,t,n)=>({kind:e,operands:[t,n]}),rp=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?rp(e,t.operands).operands:[t])}),ip=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return ip(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,ip(t)),0)}},ap=e=>{switch(e.kind){case`Action`:return!0;case`Boolean`:case`State`:case`Enabled`:return!1;case`Not`:case`Always`:case`Eventually`:case`Next`:return ap(e.body);case`And`:case`Or`:return e.operands.some(ap)}},op=/* @__PURE__ */ new WeakMap,sp={count:0},cp=e=>{let t=op.get(e);if(t!==void 0)return t;let n=(()=>{switch(e.kind){case`Boolean`:return String(e.value);case`State`:case`Enabled`:case`Action`:return`#${sp.count++}`;case`And`:case`Or`:return`${e.kind}(${e.operands.map(cp).join(`,`)})`;default:return`${e.kind}(${cp(e.body)})`}})();return op.set(e,n),n},lp=(e,t)=>e===t||cp(e)===cp(t),up=(e,t)=>{let n=cp(t);return e.some(e=>e===t||cp(e)===n)},dp=e=>e===`And`?`Or`:`And`,fp=(e,t)=>{switch(e.kind){case`Boolean`:return t?$f(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return fp(e.body,!t);case`And`:case`Or`:return rp(t?dp(e.kind):e.kind,e.operands.map(e=>fp(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,fp(e.body,t))}}},pp=e=>{switch(e.kind){case`Boolean`:return $f(!e.value);case`Not`:return e.body;case`And`:case`Or`:return rp(dp(e.kind),e.operands.map(pp));case`Always`:return Q(`Eventually`,pp(e.body));case`Eventually`:return Q(`Always`,pp(e.body));default:return Q(`Not`,e)}},mp=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=mp(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return $f(t)}return n.length===0?$f(!t):n.length===1?n[0]:rp(e.kind,n)}case`Not`:{let t=mp(e.body);return t.kind===`Boolean`?$f(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=mp(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},hp=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,gp=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=gp(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new v(`TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form.`);t.push(e)}}if(n.value===1)return{kind:`And`,operands:t};let r=Array.from({length:n.value},()=>[]),i={groups:1,repeat:n.value};for(let e of t){if(e.kind!==`Or`){r.forEach(t=>t.push(e));continue}i.repeat/=e.operands.length;let t={value:0};for(let n=0;n<i.groups;n++)for(let n of e.operands)for(let e=0;e<i.repeat;e++)r[t.value++].push(n);i.groups*=e.operands.length}return{kind:`Or`,operands:r.map(e=>rp(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=gp(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=hp(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:rp(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return rp(`Or`,n)}case`Not`:return ep(e.body)?e:gp(pp(e.body));default:return e}},_p=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?_p(e.operands[0]):rp(e.kind,e.operands.map(_p));case`Not`:return e.body.kind===`Not`?_p(e.body.body):Q(`Not`,_p(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,_p(e.body));default:return e}},vp=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return vp(e.operands[0]);let t=Math.floor(e.operands.length/2);return np(e.kind,vp(rp(e.kind,e.operands.slice(0,t))),vp(rp(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,vp(e.body));default:return e}},yp=(e,t)=>{e.kind===`Eventually`&&!up(t,e)&&t.push(e),`body`in e&&yp(e.body,t),`operands`in e&&e.operands.forEach(e=>yp(e,t))},bp=e=>{let t=e.filter(tp),n=e.flatMap(e=>e.kind===`Not`&&tp(e.body)?[e.body]:[]);return!t.some(e=>up(n,e))},xp=e=>{let t=[...e],n=[];for(;t.length>0;){let e=t.pop();if(!e)break;switch(e.kind){case`Not`:t.push(e.body);break;case`Next`:n.push(e),t.push(e.body);break;case`Always`:case`Eventually`:n.push(e,Q(`Next`,e)),t.push(e.body);break;case`And`:case`Or`:t.push(...e.operands),n.push(e);break;case`Action`:throw new v(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},Sp=(e,t,n)=>{if(e.kind===t&&`body`in e)return{first:e.body,second:Q(`Next`,e)};if(e.kind===n&&`operands`in e)return{first:e.operands[0],second:e.operands[1]}},Cp=(e,t,n)=>e.flatMap(e=>{let r=Sp(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),wp=e=>[...new Set(e.map(cp))].sort().join(`|`),Tp=(e,t)=>{let n=new Set(t.map(wp));return[...e.filter(e=>!n.has(wp(e))),...t]},Ep=e=>{let t=xp(e),n=Cp(t,`Always`,`And`),r=Cp(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=Sp(t,`Eventually`,`Or`);if(n&&!(up(e,n.first)||up(e,n.second)))return Tp(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(up(e,t.first)||up(e,t.second))&&!up(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!bp(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=Sp(t[e],`Always`,`And`);n&&(up(t,n.first)||t.push(n.first),up(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)up(t,e.first)&&up(t,e.second)&&!up(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!bp(t)?[]:i(t)};return a(e)},Dp=e=>({particle:e,successors:[],statePredicates:e.filter(e=>ip(e)<=1)}),Op=e=>{let t=Ep([e]).map(Dp),n=t.length,r=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let n=wp(e.particle);r.has(n)||r.set(n,t)});for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let i of Ep(n)){let n=wp(i),a=r.get(n);a===void 0&&(r.set(n,t.length),t.push(Dp(i))),t[e].successors.push(a??t.length-1)}}return{nodes:t,initialCount:n}},kp=(e,t)=>!up(e,t)||up(e,t.body),Ap=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&ip(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=hp(e);if(n){let e=ip(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(ap(e))throw new v(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},jp=(e,t)=>{let n=e.findIndex(e=>lp(e,t));return n===-1?(e.push(t),e.length-1):n},Mp=e=>{let t=gp(mp(fp(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=_p(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])Ap(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:rp(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:lp(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&vp(e.formula),n=[];t&&yp(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>jp(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>jp(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>jp(i,e))}));return{tableau:t&&Op(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Np=/* @__PURE__ */ new Set([`~>`,`-+->`]),Pp=/* @__PURE__ */ new WeakMap,Fp=/* @__PURE__ */ new WeakSet,Ip=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),Lp=(t,r)=>{try{return X(t,r)}catch(t){if(!(t instanceof v)||t instanceof y)throw t;let r=o(t);throw r===void 0?n(new v(`${l}${t.message}`,t),e.error):n(t,r)}},Rp=e=>new v(`TLC cannot handle the temporal formula at ${ho(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Eo(t,e);if(!r)return;if(r.kind===`Value`)return 0;if(r.kind===`Thunk`)return $(r.expression,r.scope,n);let i=r.operator;return i.kind===`Closure`?$(i.body,i.scope,n):0},a=e=>{if(n.variableIndex.has(e))return 1;if(n.constants.has(e))return 0;let t=jo(e,n);if(t)return zp(t,n);let r=n.builtins.get(n.substitutions.get(e)??e);return r?+!!r.isStateLevel:void 0},o=(e,t)=>r.has(e)?0:W(t)?i(e)??a(e)??0:a(e)??i(e)??0,s=e=>{let i={value:0};return Ji(e,(e,a)=>(i.value=Math.max(i.value,$(e,t,n,a.length===0?r:/* @__PURE__ */ new Set([...r,...a]))),e)),i.value};switch(e.kind){case`Prime`:case`Unchanged`:case`BoxAction`:case`AngleAction`:return 2;case`Enabled`:return 1;case`Always`:case`Eventually`:case`WeakFairness`:case`StrongFairness`:return 3;case`UnboundedQuantifier`:return e.isTemporal?3:s(e);case`Identifier`:return o(e.name,e);case`OperatorReference`:return o(e.operator,e);case`Apply`:return Np.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},zp=(e,t)=>{let n=Pp.get(e);if(n!==void 0)return n;Pp.set(e,0);let r=e.kind===`Function`?e.bounds:[],i=Math.max($(e.body,void 0,t),...r.map(e=>$(e.set,void 0,t)));return Pp.set(e,i),i},Bp=`Temporal formula is a tautology (its negation is unsatisfiable).`,Vp=(t,r,i,a,o=``,s=/* @__PURE__ */ new Set)=>{let c=(e,t,n=o,r=s)=>Vp(e,t,i,a,n,r);if(t.kind===`And`)return t.operands.flatMap(e=>c(e,r,go(e)));if(t.kind===`Label`)return c(t.body,r);if(t.kind===`Let`)return c(t.body,Hp(t,r,i));if(t.kind===`Identifier`){let o=W(t)?Eo(r,t.name):void 0;if(o?.kind===`Thunk`)return c(o.expression,o.scope);let l=i.constants.has(t.name)?void 0:jo(t.name,i);if(!o&&l?.kind===`Operator`&&l.params.length===0&&zp(l,i)>0){if(s.has(l))throw n(new v(u),e.error);let r=c(l.body,void 0,t.name,/* @__PURE__ */ new Set([...s,l]));return!a&&zp(l,i)<2?[{expression:l.body,scope:void 0,name:t.name}]:r}}let l=Ip(i,r);if(t.kind===`Apply`&&(e=>a||$(e,r,i)===3)(t)){let e=Zo(t,l),n=W(t)?void 0:jo(t.operator,i);if(e?.kind===`Closure`&&e.params.length===t.args.length&&!n?.isRecursive)return c(e.body,ls(e,t.args,l),t.operator)}if(a&&t.kind===`Forall`&&t.bounds.every(e=>$(e.set,r,i)===0)){let r=[],i={count:0};if(Io(t.bounds,l,e=>(i.count++,r.push(...c(t.body,e,go(t.body))),!1)),i.count===0)throw n(new v(Bp),e.livenessEvaluationFailure);return r}return[{expression:t,scope:r,name:o}]},Hp=(e,t,n)=>{let r=ds(e.definitions,Ip(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&Fp.add(e.binding);return r},Up=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),Wp=(t,r,i)=>{let a=(e,t,n)=>{let r=n===0?$(e,t,i):n;if(r===0){let n=Lp(e,Ip(i,t));if(typeof n!=`boolean`)throw new v(`TLC expected a boolean in the temporal formula at ${ho(e)}`);return $f(n)}return r===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},o={depth:0},s=(t,r,i,s)=>{if(o.depth>=100)throw n(new v(u),e.error);o.depth++;let c=f(t,r);o.depth--;let l=ip(c);return l>2?c:a(i,s,l)},c=(e,t)=>{let n=e.kind===`Identifier`?e.name:e.operator,r=Ip(i,t),a=W(e)||jo(n,i)===void 0?Eo(t,n):void 0;if(a?.kind===`Thunk`&&Fp.has(a))return s(a.expression,a.scope,e,t);let o=a?.kind===`Operator`?a.operator:a?void 0:W(e)?Qo(n,r):Yo(n,i);if(o?.kind!==`Closure`)throw Rp(e);let c=e.kind===`Apply`?e.args:[];return s(o.body,ls(o,c,r),e,t)},l=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,i)===0))throw Rp(e);let n=[];Io(e.bounds,Ip(i,t),t=>(n.push(f(e.body,t)),!1));let r=e.kind===`Forall`;if(n.length===0)return $f(r);let o=rp(r?`And`:`Or`,n),s=ip(o);return s>2?o:a(e,t,s)},d=(e,t)=>{switch(e.kind){case`Label`:f(e.body,t);return;case`Let`:f(e.body,Hp(e,t,i));return;case`And`:case`Or`:for(let n of e.operands)f(n,t);return;case`Apply`:if(e.operator===`=>`||e.operator===`~`&&!W(e))for(let n of e.args)f(n,t);return;case`If`:{let n=f(e.condition,t),r=n.kind===`Boolean`?[n.value?e.consequent:e.alternative]:[e.consequent,e.alternative];for(let e of r)f(e,t)}}},f=(e,t)=>{let n=$(e,t,i);if(n<=2)return d(e,t),a(e,t,n);switch(e.kind){case`Label`:return f(e.body,t);case`Let`:return f(e.body,Hp(e,t,i));case`Identifier`:return c(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,np(`Or`,Q(`Not`,f(n[0],t)),Q(`Eventually`,f(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,f(n[0],t)):e.operator===`=>`?np(`Or`,Q(`Not`,f(n[0],t)),f(n[1],t)):c(e,t)}case`And`:case`Or`:return rp(e.kind,e.operands.map(e=>f(e,t)));case`Forall`:case`Exists`:return l(e,t);case`If`:{if($(e.condition,t,i)===0){let n=Lp(e.condition,Ip(i,t));if(typeof n==`boolean`)return f(n?e.consequent:e.alternative,t)}let n=f(e.condition,t);return np(`Or`,np(`And`,n,f(e.consequent,t)),np(`And`,Q(`Not`,n),f(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,f(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=Up(e.action,e.subscript),r={kind:`Enabled`,step:e.enabled??n,scope:t},i=Q(`Not`,r),a={kind:`Action`,expression:e.action,unchanged:{kind:`Unchanged`,expression:e.subscript,location:n.location},scope:t,enabled:r};return e.kind===`WeakFairness`?Q(`Always`,Q(`Eventually`,np(`Or`,i,a))):np(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw Rp(e)}};return f(t,r)},Gp=(e,t,n,r,i)=>{let a=e=>Gp(e,t,n,r,i);switch(e.kind){case`Boolean`:return e.value;case`State`:case`Enabled`:{let n=i.get(e);if(n!==void 0)return n;let a={environment:r,scope:e.scope,state:t,next:void 0},o=e.kind===`State`?Ao(X(e.expression,a),`a temporal property predicate`):lo(e.step,a);return i.set(e,o),o}case`Action`:{if(e.enabled&&i.get(e.enabled)===!1)return!1;let a={environment:r,scope:e.scope,state:t,next:n};return e.unchanged&&Ao(X(e.unchanged,a),`a subscript`)?!1:Ao(X(e.expression,a),`an action predicate`)}case`Not`:return!a(e.body);case`And`:return e.operands.every(a);case`Or`:return e.operands.some(a);case`Next`:return Gp(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new v(`TLC cannot evaluate a temporal formula in a single step`)}},Kp=(e,t,n,r,i)=>{let a=e=>e+1<t.length?e+1:n,o=e=>t.map((e,t)=>t).filter(t=>t>=Math.min(e,n)),s=(e,a=r)=>Kp(e,t,n,a,i);switch(e.kind){case`Not`:return!s(e.body);case`And`:return e.operands.every(e=>s(e));case`Or`:return e.operands.some(e=>s(e));case`Next`:return s(e.body,a(r));case`Always`:return o(r).every(t=>s(e.body,t));case`Eventually`:return o(r).some(t=>s(e.body,t));default:return Gp(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},qp=(e,t)=>e.every((e,n)=>nt(e,t[n])),Jp=e=>e.filter((t,n)=>n===0||e[n-1]!==t),Yp=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.pending.push(void 0),e.offsets.push(-1),e.edgeOffsets.push(-1),e.nodeStates.length-1),Xp=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},Zp=(e,t)=>(e.offsets[t]??-1)!==-1,Qp=(e,t)=>e.pending[t]??=[],$p=(e,t)=>{let n=e.edgeOffsets[t];return e.edges.ids.subarray(n+1,n+1+e.edges.ids[n])},em=(e,t,n)=>e.results.bytes[e.offsets[t]+n]===1,tm=2**53-1,nm=(t,r,i,a)=>{if(t.length===0)return;let o=r.map(e=>Wp(e.expression,e.scope,i)),s=t.map(e=>Q(`Not`,Wp(e.expression,e.scope,i))),c=s.length===1?s[0]:rp(`Or`,s),l=o.length===0?c:rp(`And`,[...o,c]),u=Mp(l);if(u.length===0)throw n(new v(Bp),e.livenessEvaluationFailure);let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=cp(e),n=d.get(t)??d.size;return d.set(t,n),n}),nodeStates:[],nodeTableaux:[],pending:[],offsets:[],results:{bytes:/* @__PURE__ */ new Uint8Array(1024),length:0},edgeOffsets:[],edges:{ids:/* @__PURE__ */ new Int32Array(1024),length:0},initial:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!Cs(i),h={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},g=e=>{let t=h.states.get(e)??/* @__PURE__ */ new Map;return h.states.set(e,t),t},_=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},y=(e,t)=>Gp(e,t,void 0,i,m?g(t):/* @__PURE__ */ new Map),b=(e,t,n)=>_(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!y(e,n))),x=(e,t,n,r)=>_(t,()=>{let t=e.solution.actionChecks;if(!m)return Uint8Array.from(t,e=>+!!Gp(e,n,r,i,/* @__PURE__ */ new Map));let a=g(n),o=h.actions.get(n)??/* @__PURE__ */ new Map;h.actions.set(n,o);let s=o.get(r)??new Int8Array(d.size).fill(-1);return o.set(r,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!Gp(t[o],n,r,i,a)),s[e]))}),ee=(e,t,n,r)=>_(n,()=>e.nodes[t].statePredicates.every(e=>y(e,r))),te=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},ne=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),re=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=Xp(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},ie=(e,t,n)=>{let r=Yp(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),Xp(i,e[t]-1,e[t+1]))}return i.slots.set([t+1,n,r],Xp(i,t,n)),r},S=(e,t,n)=>t.nodes.flatMap((t,r)=>re(e,n,r)??[]).sort((e,t)=>e-t),ae=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=e.results,o=a.length;if(a.length+=r.length+n.length*i,a.length>a.bytes.length){let e=new Uint8Array(Math.max(2*a.bytes.length,a.length));e.set(a.bytes),a.bytes=e}a.bytes.set(r,o),n.forEach((e,t)=>a.bytes.set(e,o+r.length+t*i)),e.offsets[t]=o;let s=e.pending[t]??[],c=e.edges,l=c.length;if(c.length+=s.length+1,c.length>c.ids.length){let e=new Int32Array(Math.max(2*c.ids.length,c.length));e.set(c.ids),c.ids=e}c.ids[l]=s.length,c.ids.set(s,l+1),e.edgeOffsets[t]=l,e.pending[t]=void 0},C=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t.index)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&qp(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},oe=(e,t,n,r,i)=>{let o=b(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=Qp(e,i),u=s.successors.length>0?x(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ee(t,a,r,n))continue;if(te(t,a)&&e.errorNode===void 0&&ne(e)){e.errorNode=i;return}let o=re(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??ie(e,r,a);l.push(s),c.push(u),o===void 0&&oe(e,t,n,r,s)}for(let i of a.getSuccessors(n)){let a=x(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ee(t,n,r,i.state))continue;let s=re(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??ie(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&oe(e,t,i.state,i.index,u)}}l.length>0&&ae(e,i,c,o)},w=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ee(t,r,a,e.state)));e.isDone[a]=!0;for(let s of S(e,t,a)){let a=Qp(e,s),c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=re(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??ie(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&oe(e,t,n.state,n.index,d)}}),ae(e,s,c,i)}if(e.errorNode!==void 0)return Jp(E(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},T=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)Yp(e,e.nodeStates.length,-1);let a=Qp(e,i),o=[];t.forEach((t,r)=>{Zp(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),ae(e,i,o,r)},E=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)Zp(e,t)&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of $p(e,a))if(!(i===a&&e.solution.tableau)){if(i===t){let e=[t];for(let t=a;t!==-1;t=n.get(t)??-1)e.push(t);return e}Zp(e,i)&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new v(`Couldn't re-create liveness trace (path) starting at: ${t}`)},D=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=n.stateChecks.length,a=(t,n,a)=>e.results.bytes[e.offsets[t]+i+n*r+a]===1,o=(e,n)=>t.eventuallyAlways.every(t=>a(e,n,t)),s=new Float64Array(e.nodeStates.length).fill(-1),c=e.initial.filter(t=>Zp(e,t)),l=[],u=t=>{let n=$p(e,t).indexOf(t);return n!==-1&&o(t,n)},d=(t,r)=>n.tableau!==void 0&&kp(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let i=l.pop()??r;if(i===r&&!u(i)){s[i]=tm;return}let c=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=i;;t=l.pop()??r){c.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),s[t]=tm,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...c].some(n=>em(e,n,t))),h=t.infinitelyOftenActions.every(t=>[...c].some(n=>$p(e,n).some((e,r)=>c.has(e)&&o(n,r)&&a(n,r,t)))),g=n.promises.every(e=>[...c].some(t=>d(t,e)));if(m&&h&&g)return p(r,c,f)},p=(r,i,s)=>{let c=Jp(E(e,r).reverse().map(t=>e.nodeStates[t])),l=[],u=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),p=t.infinitelyOftenActions.map(()=>!1),h=n.promises.map(()=>!1),g={count:f.length+p.length+h.length},_={node:r},y=e=>i.has(e),b=e=>{l.push(_.node),_.node=e};for(;g.count>0;){let r=g.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&em(e,_.node,t)&&(f[n]=!0,g.count--)}),n.promises.forEach((e,t)=>{!h[t]&&d(_.node,e)&&(h[t]=!0,g.count--)}),!(g.count<=0);){let n={last:-1,unvisited:-1},i=g.count;if($p(e,_.node).some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!o(_.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!p[t]&&a(_.node,c,e)&&(p[t]=!0,g.count--)})}return g.count<i?(b(r),u.clear(),!0):(y(r)&&!u.has(r)&&(n.unvisited=r),!1)}))break;if(g.count<r){b(n.last),u.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);_.node=t,n.unvisited=$p(e,t).find(e=>y(e)&&!u.has(e))??-1}b(n.unvisited),u.add(n.unvisited)}}let x=m(r,_.node,s,o);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];x[x.length-1]!==n&&x.push(n)}let ee=c[c.length-1];return x[x.length-1]===ee&&x.pop(),{prefix:c.slice(0,-1),cycle:[ee,...x.reverse()]}},m=(t,n,r,i)=>{if(n===t)return[];let a=e.nodeStates[n],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set([a]),c=[];for(let n=a,l=-1,u=0;;u++){for(let u of r.get(n)??[])for(let[d,f]of $p(e,u).entries()){if(f===u||!i(u,d))continue;if(f===t){let e=[];for(let t=n,r=l;t!==a;)e.push(t),t=r,r=o.get(t)??-1;return e.push(a),e}let p=e.nodeStates[f];r.has(p)&&!s.has(p)&&(s.add(p),c.push([p,n]))}o.set(n,l);let d=c[u];if(d===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<c.length;t++){let n=[c[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),a=n.pop()??0;if(i===-42){if(s[a]===t){let e=f(a);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(s[a]!==-1){n.push(Math.min(t,s[a]));continue}s[a]=r.link,n.push(t,a,-42),l.push(a);let u={value:r.link++};$p(e,a).forEach((t,r)=>{Zp(e,t)&&(o(a,r)?s[t]===-1?n.push(t,-1):u.value=Math.min(u.value,s[t]):s[t]===-1&&c.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{h.states.clear(),h.actions.clear();for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ee(r,i,void 0,t)&&n.initial.push(re(n,e,i)??ie(n,e,i))}},addState:(e,t,n)=>{h.states.clear(),h.actions.clear();let r=C(e,t,n);for(let n of f){let i=r.map(r=>x(n,e,t,r.state)),a=b(n,e,t),o=n.solution.tableau,s=o?w(n,o,r,i,a,e):T(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=D(e,t);if(n)return n}},getViolatedProperties:(e,n)=>[...new Set(t.filter((t,r)=>!Kp(s[r].body,e,n,0,i)).map(e=>e.name))]}},rm=`UnnamedAction`,im={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},am=e=>{let t=e.range??im;return Gt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},om=e=>{let t=[[`name`,e.name],[`location`,am(e.location)]];return e.parameters.length===0?Gt(t):Gt([...t,[`context`,Gt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},sm=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),cm=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),lm=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,um=e=>e.kind===`Apply`?e.args:[],dm=(e,t,n)=>{let r=lm(e);if(r===void 0)return;if(W(e)){let e=Eo(t,r);return e?.kind===`Operator`&&e.operator.kind===`Closure`?e.operator:void 0}if(n.constants.has(r)||n.variableIndex.has(r))return;let i=Yo(r,n);return i?.kind===`Closure`?i:void 0},fm=(e,t)=>{try{return X(e,cm(t,void 0)),!0}catch(e){if(e instanceof f)return!1;throw e}},pm=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&No(e,t)&&fm(e.body,t),mm=(e,t)=>{let n=jo(e.name,t);return n?.body===e.body&&pm(n,t)},hm=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Eo(t,e.name);return n?.kind===`Thunk`?n:void 0},gm=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Eo(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),_m=(e,t)=>{try{return e()}catch(e){if(e instanceof f)return t();throw e}},vm=(e,t,n,r,i)=>{let a=um(t),o=()=>[{name:e.name,location:t.location,parameters:[],expression:t,scope:n}];return!r||a.length===0?[{...e,parameters:[],expression:t,scope:n}]:a.some(e=>$(e,n,i)!==0)?o():_m(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,cm(i,n))]),expression:t,scope:n}],o)},ym=(e,t,n,r,i)=>{let a=()=>({name:n?.name??rm,location:e.location,parameters:gm(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return ym(e.body,ds(e.definitions,cm(r,t)),n,r,i);case`Label`:return ym(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>ym(e,t,n,r,i));case`Exists`:return _m(()=>{let o=[];return Io(e.bounds,cm(r,t),t=>(o.push(...ym(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get(lm(e)??``),s=dm(e,t,r);if(o)return vm(o,e,t,s,r);if(!s)return[a()];let c=um(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return mm(s,r)||c.some(e=>$(e,t,r)!==0)?l():_m(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,cm(r,t))},parent:e}),s.scope);return ym(s.body,e,s,r,i)},l)},bm=(e,t,n,r,i)=>{let a=(e,t)=>bm(e,t,n,r,i);if(e.kind===`Let`){a(e.body,ds(e.definitions,cm(n,t)));return}let o=hm(e,t);if(o){a(o.expression,o.scope);return}let s=dm(e,t,n);if(s&&mm(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(sm(s.name,s.body));return}a(s.body,s.scope);return}if(s&&e.kind===`Apply`&&s.params.length===e.args.length){a(s.body,ls(s,e.args,cm(n,t)));return}if(e.kind===`And`){e.operands.forEach(e=>a(e,t));return}if(e.kind===`Always`){if(e.expression.kind===`BoxAction`){i.push({expression:e.expression.action,scope:t});return}r.temporals.push(sm(rm,e));return}let c=$(e,t,n);c<=1?r.inits.push(sm(rm,e)):c===3&&r.temporals.push(sm(rm,e))},xm=(e,t,n,r,i)=>{let a=(t,n)=>xm(e,t,n,r,i);if(t.kind===`Let`){a(t.body,ds(t.definitions,cm(r,n)));return}let o=hm(t,n);if(o){a(o.expression,o.scope);return}let s=dm(t,n,r);if(s&&mm(s,r))return;if(s&&s.params.length===um(t).length){a(s.body,t.kind===`Apply`?ls(s,t.args,cm(r,n)):s.scope);return}if(t.kind===`Forall`&&_m(()=>(Io(t.bounds,cm(r,n),e=>(a(t.body,e),!1)),!0),()=>!1))return;if(t.kind===`And`){t.operands.forEach(e=>a(e,n));return}if(t.kind===`Always`){let a=t.expression;a.kind===`BoxAction`?i.impliedActions.push(sm(e,a)):$(a,n,r)<2?i.invariants.push(sm(e,a)):i.impliedTemporals.push(sm(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(sm(e,t)):c===3&&i.impliedTemporals.push(sm(e,t))},Sm=(e,t)=>{let n=jo(e,t);return n?.kind===`Operator`&&!pm(n,t)?n:void 0},Cm=e=>Gt([[`name`,e.name],[`location`,am(e.location)]]),wm=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:Sm(e.specification,t);a&&(bm(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...ym(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:Yo(e.init,t);o?.kind===`Closure`&&r.inits.push(sm(e.init??``,o.body));let s=e.next===void 0?void 0:Yo(e.next,t);return s?.kind===`Closure`&&r.actions.push(...ym(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=Sm(e,t);n&&r.invariants.push(sm(e,n.body))}),e.properties.forEach(e=>{let n=Sm(e,t);n&&xm(e,n.body,void 0,t,r)}),r},Tm=(e,t,n)=>wm(e,t,n).actions,Em=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>U(e[1])).join(`,`)})`,Dm=e=>`${e.name===rm?`Action`:e.name}${Em(e)} ${h(e.location.range??im)}`,Om=e=>`${e.name}${Em(e)}`,km=(e,t,n,r)=>{let i=wm(e,t,r),a=e=>kt(e.map(om)),o=e=>kt(e.flatMap(e=>{let n=Sm(e,t);return n?[Cm(n)]:[]}));return Gt([[`inits`,a(i.inits)],[`actions`,a(i.actions)],[`temporals`,a(i.temporals)],[`invariants`,a(i.invariants)],[`impliedinits`,a(i.impliedInits)],[`impliedactions`,a(i.impliedActions)],[`impliedtemporals`,a(i.impliedTemporals)],[`variables`,kt(t.variables.map((e,t)=>Gt([[`name`,e],[`location`,am(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},Am=`paired12`,jm=(e,t=16)=>e<=t*.75?t:jm(e,t*2),Mm=(e,t)=>{let n=jm(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Nm=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Pm=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Fm=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Im=e=>Fm(e).replaceAll(`
|
|
420
|
-
`,`\\n`),Lm=(e,t)=>{let n=[],r=e=>n.push(`State ${n.length+1}:\n${e.getText()}\n`);return{writeInitialState:r,writeSuccessor:(e,t,n)=>{n||r(t)},close:()=>t?.(e.path,n.join(``))}},Rm=(e,t)=>{let n=[`strict digraph DiskGraph {
|
|
426
|
+
`]]),of=/* @__PURE__ */ new Map([[`FiniteSets`,/* @__PURE__ */ new Map([[`IsFiniteSet`,`public static tlc2.value.IBoolValue tlc2.module.FiniteSets.IsFiniteSet(tlc2.value.impl.Value)`],[`Cardinality`,`public static tlc2.value.impl.IntValue tlc2.module.FiniteSets.Cardinality(tlc2.value.impl.Value)`]])],[`Sequences`,/* @__PURE__ */ new Map([[`Seq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Seq(tlc2.value.impl.Value)`],[`Len`,`public static tlc2.value.impl.IntValue tlc2.module.Sequences.Len(tlc2.value.impl.Value)`],[`Head`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Head(tlc2.value.impl.Value)`],[`Tail`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Tail(tlc2.value.impl.Value)`],[`Append`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Append(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`\\o`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Concat(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SubSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SubSeq(tlc2.value.impl.Value,tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SelectSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SelectSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`]])],[`TLC`,/* @__PURE__ */ new Map([[`Print`,`public static tlc2.value.impl.Value tlc2.module.TLC.Print(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`PrintT`,`public static tlc2.value.impl.Value tlc2.module.TLC.PrintT(tlc2.value.impl.Value)`],[`ToString`,`public static tlc2.value.impl.Value tlc2.module.TLC.ToString(tlc2.value.impl.Value)`],[`Assert`,`public static tlc2.value.impl.Value tlc2.module.TLC.Assert(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`:>`,`public static tlc2.value.impl.Value tlc2.module.TLC.MakeFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`@@`,`public static tlc2.value.impl.Value tlc2.module.TLC.CombineFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SortSeq`,`public static tlc2.value.impl.Value tlc2.module.TLC.SortSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`Permutations`,`public static tlc2.value.impl.Value tlc2.module.TLC.Permutations(tlc2.value.impl.Value)`],[`RandomElement`,`public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)`],[`TLCGet`,`public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`],[`TLCEval`,`public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`]])]]),sf=(e,t)=>e.every(e=>vn(e,t)),cf=Et([!1,!0]),lf=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return jt(lf(e,t,r),lf(e,r,n))},uf=[`\\cup`,`\\cap`,`\\`],df=e=>typeof e==`object`&&e.kind===`MixedSet`,ff=e=>e.kind===`Interval`?q(e).elements:e.elements,pf=(e,t,n)=>{let r=ff(t);if(e!==`\\cup`){let t=e===`\\cap`;return Dt(r.filter(e=>vn(e,n)===t))}if(r.length===0)return n;if(!je(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=q(n).elements.filter(e=>!vn(e,t));return Dt([...r,...i])},mf=[Cr(`TRUE`,!0),Cr(`FALSE`,!1),Cr(`BOOLEAN`,cf),Cr(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),Er(`=`,wt),Er(`#`,(e,t)=>!wt(e,t)),Q(`~`,1,e=>!hr(e,0,`~`)),Q(`<=>`,2,e=>hr(e,0,`<=>`)===hr(e,1,`<=>`)),Q(`/\\`,2,e=>hr(e,0,`/\\`)&&hr(e,1,`/\\`)),Q(`\\/`,2,e=>hr(e,0,`\\/`)||hr(e,1,`\\/`)),Q(`=>`,2,e=>!hr(e,0,`=>`)||hr(e,1,`=>`)),Q(`\\in`,2,e=>vn(Z(e,0,`\\in`),Z(e,1,`\\in`))),Q(`\\notin`,2,e=>!vn(Z(e,0,`\\notin`),Z(e,1,`\\notin`))),Q(`\\subseteq`,2,e=>{let t=gr(e,0,`\\subseteq`),n=Z(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&Jt(t.base)?sf(q(t.base).elements,n.base):sf(q(t).elements,n)}),...uf.map(e=>Q(e,2,t=>{let n=Z(t,0,e),r=Z(t,1,e);if(je(n)&&je(r)&&!df(n)&&!df(r)){if(e===`\\cup`&&sn(n))return r;let t=e===`\\cup`?jt:e===`\\cap`?At:kt;try{return t(q(n),q(r))}catch(e){if(!(e instanceof y))throw e}}return je(n)?pf(e,n,r):e!==`\\`&&je(r)?pf(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),Q(`SUBSET`,1,e=>({kind:`Subset`,base:gr(e,0,`SUBSET`)})),Q(`UNION`,1,e=>{let t=gr(e,0,`UNION`),n=ft(t)?t.elements.filter(ft):[];if(!ft(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(df(t)||n.some(df)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{vn(t,e)||e.elements.push(t)})),Dt(e.elements)}return n.length===0?Ot:lf(n.map(q),0,n.length)}),Q(`DOMAIN`,1,e=>{let t=Z(e,0,`DOMAIN`);if(!Me(t))throw new y(`DOMAIN expects a function but received ${Y(t)}`);return Mn(t)})],hf=Lr(`Integers`,`Neg`,`IntValue`,1),gf=e=>{let t=Lr(e,`DotDot`,`IntervalValue`,2);return[Rr(e,`+`,`Plus`,(e,t)=>e+t),Rr(e,`-`,`Minus`,(e,t)=>e-t),Rr(e,`*`,`Times`,(e,t)=>e*t),Rr(e,`^`,`Expt`,(e,t)=>{if(t<0)throw new b(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new b(`0^0 is undefined.`);return e**t}),Rr(e,`\\div`,`Divide`,(e,t)=>{if(t===0)throw new b(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Dr(n))throw Or(`${e} \\div ${t}`);return n}),Rr(e,`%`,`Mod`,(e,t)=>{if(t<=0)throw new b(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),Q(`..`,2,e=>({kind:`Interval`,low:Ir(Z(e,0,`..`),t),high:Ir(Z(e,1,`..`),t)}))]},_f=[Cr(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),...gf(`Naturals`),Br(`<`,(e,t)=>e<t),Br(`>`,(e,t)=>e>t),Br(`<=`,(e,t)=>e<=t),Br(`>=`,(e,t)=>e>=t)],vf=[Cr(`Int`,{kind:`InfiniteSet`,name:`Int`}),...gf(`Integers`),Q(`-.`,1,e=>{let t=Ir(Z(e,0,`-`),hf);if(Dr(-t))throw Or(`-${t}`);return-t})],yf=(e,t,n)=>{let r=Z(e,t,n),i=mn(r);if(!i)throw new b(`${n}\n${Y(r)}`);return i},bf=(e,t,n)=>{let r=Z(e,t,n);return typeof r==`string`?r:yf(e,t,n)},xf=(e,t,n)=>typeof e==`string`?ze(e.slice(t,n)):Ht(e.slice(t,n)),Sf=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Cf=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,wf=(e,t)=>{let n=of.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?Fr(e,t):e}):t},Tf=wf(`Sequences`,[Q(`Seq`,1,e=>({kind:`SequenceSet`,base:Z(e,0,`Seq`)})),Q(`Len`,1,e=>bf(e,0,Sf(``,`Len`)).length),Q(`\\o`,2,e=>{let t=bf(e,0,Cf(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=yf(e,1,Cf(`t \\o s`,`sequence`));return Ht([...t,...n])}let n=Z(e,1,`\\o`);if(typeof n!=`string`)throw new b(`${Cf(`t \\o s`,`string`)}\n${Y(n)}`);return ze(t+n)}),Q(`Append`,2,e=>Ht([...yf(e,0,Cf(`Append(s, v)`,`sequence`)),Z(e,1,`Append`)])),Q(`Head`,1,e=>{let t=yf(e,0,Sf(``,`Head`));if(t.length===0)throw new b(`Attempted to apply Head to the empty sequence.`);return t[0]}),Q(`Tail`,1,e=>{let t=bf(e,0,Sf(``,`Tail`));if(t.length===0)throw new b(`Attempted to apply Tail to the empty sequence.`);return xf(t,1)}),Q(`SubSeq`,3,e=>{let t=bf(e,0,Sf(`first `,`SubSeq`)),n=mr(e,1,`SubSeq`),r=mr(e,2,`SubSeq`);if(n>r)return xf(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new b(`The ${i.position} argument of SubSeq must be in the domain of its first argument:\n${Y(Z(e,0,`SubSeq`))}\n, but instead it is\n${i.value}`);return xf(t,n-1,r)}),wr(`SelectSeq`,2,e=>{let t=Sr(e,1,`SelectSeq`);return Ht(yf(e,0,Sf(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new b(`The second argument of SelectSeq should be a operator, but instead it is:\n${Y(n)}`);return n}))})]),Ef=wf(`FiniteSets`,[Q(`IsFiniteSet`,1,e=>{let t=Z(e,0,`IsFiniteSet`);if(Ae(t))return fn(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new y(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${Y(t)}\nis a finite set.`:`Attempted to check if the ${Ne(t)} ${Y(t)} is a finite set.`)}),Q(`Cardinality`,1,e=>{let t=Z(e,0,`Cardinality`);if(!Ae(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new b(`Attempted to compute cardinality of the value\n${Y(t)}`);return un(t)})]),Df=/* @__PURE__ */ new Map([[`Integers`,[`Naturals`]],[`Sequences`,[`Naturals`]],[`FiniteSets`,[`Naturals`,`Sequences`]],[`TLC`,[`Naturals`,`Sequences`,`FiniteSets`]],[`Randomization`,[`Naturals`,`FiniteSets`,`Sequences`]],[`_Possible`,[`TLC`,`TLCExt`,`Naturals`,`Sequences`,`FiniteSets`,`Integers`]],[`Json`,[`Sequences`,`FiniteSets`,`TLC`,`Naturals`]],[`Bags`,[`Naturals`]],[`TLCExt`,[`TLC`,`Integers`,`Naturals`,`Sequences`,`FiniteSets`]]]),Of=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:_f};case`Integers`:return{extends:[`Naturals`],operators:vf};case`Sequences`:return{extends:[],operators:Tf};case`FiniteSets`:return{extends:[],operators:Ef};case`TLC`:return{extends:[],operators:wf(`TLC`,Qd(t,n))};case`Randomization`:return{extends:[],operators:kd(n)};case`_Possible`:return{extends:[],operators:Wd(t,n)};case`Json`:return{extends:[],operators:Cd(r)};case`Bags`:return{extends:[],operators:nd};case`TLCExt`:return{extends:[],operators:Ud(t,n)};default:return}},kf=`$subexpression`,Af=(e,t)=>new p(`${e} at line ${t.line}, column ${t.column}`),jf=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Mf=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Nf=e=>{switch(e.kind){case`Apply`:return e.args;case`And`:case`Or`:return e.operands;case`If`:return[e.condition,e.consequent,e.alternative];case`Tuple`:case`SetEnumeration`:return e.elements;case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`FunctionApplication`:return[e.function,e.args.length===1?e.args[0]:{kind:`Tuple`,elements:e.args,location:e.location}];case`FieldAccess`:return[e.record,{kind:`String`,value:e.field,location:e.location}];case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`FunctionSet`:return[e.domain,e.range];case`Product`:return e.factors;case`Except`:return[e.function];default:return}},Pf=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:di(e.bounds),body:e.body,sets:jf(e.bounds)};case`SetMap`:return{names:di(e.bounds),body:e.expression,sets:jf(e.bounds)};case`SetFilter`:return{names:ui(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:ui(e.pattern),body:e.body,sets:e.set?[e.set]:[]};case`UnboundedQuantifier`:case`Lambda`:return{names:e.kind===`Lambda`?e.params:e.names,body:e.body,sets:[]};default:return}},Ff=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Ff(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of ur(e)){let e=Ff(r,t,n);if(e)return e}},If=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,Lf=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Rf=(e,t)=>{let n=e.location,r=Lf(t,e.lets,n);if(e.params.length===0)return r;if(e.args.length===0){if(e.params.some(e=>e.arity>0))throw Af(`Selected an operator with operator parameters as an argument`,n);return{kind:`Lambda`,params:e.params.map(e=>e.name),body:r,location:n}}if(e.args.length!==e.params.length)throw Af(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:kf,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:kf,args:e.args,location:n,resolution:ei},location:n}},zf=(e,t)=>{let n=t.location,r=e.kind===`Operator`?e.params.map((e,n)=>({name:`${e.name}$${t.params.length+n}`,arity:e.arity})):[],i=r.map(e=>({kind:`Identifier`,name:e.name,location:n,resolution:ei})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:ei}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:ei};return Rf({...t,params:[...t.params,...r]},a)},Bf=(e,t,n,r)=>{let i={params:[],args:[],lets:[],location:n},a={index:0,current:void 0},o=i=>{let o=[],s=[];for(;a.index<e.length;){let c=e[a.index];if(c.kind!==`Name`)throw Af(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>Zi(e)===l):t(l);if(u)return{definition:u,args:If(s,ai(u),r)};a.index++}throw Af(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=ai(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Af(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Af(`Cannot select a subexpression of ${s.name}`,n);i.params.push(...s.params),i.args.push(...r.args),a.current=s.body,a.index++},c=()=>{for(;a.index<e.length;){let t=e[a.index];if(t.kind!==`Name`)return;let o=a.current&&Ff(a.current,t.name,[]);if(!o)throw Af(`Cannot find label ${t.name}`,n);i.lets.push(...o.lets),i.params.push(...o.label.params.map(e=>({name:e,arity:0}))),i.args.push(...If(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Af(`Subexpression selection failed`,n);if(t.kind===`Colon`)return;if(o.kind===`Label`){a.current=o.body,l(t);return}if(o.kind===`Let`){if(t.kind!==`Operand`||Mf(t.operand,1)!==0)throw Af(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Pf(o);if(s&&(t.kind===`Bound`||t.kind===`At`)){i.params.push(...s.names.map(e=>({name:e,arity:0}))),t.kind===`Bound`&&i.args.push(...If(t.args,s.names.length,r)),a.current=s.body;return}if(o.kind===`Case`&&t.kind===`Operand`){let r=[...o.arms,...o.other?[{condition:void 0,body:o.other}]:[]],i=r[Mf(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Af(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Mf(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Af(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Af(`Unexpected subexpression selector`,n);let c=s?s.sets:Nf(o),u=c?.[Mf(t.operand,c.length)];if(!u)throw Af(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return zf(u.definition,{...i,args:u.args});for(c();a.index<e.length;){let t=e[a.index];if(t.kind===`Name`){for(;a.current?.kind===`Label`;)a.current=a.current.body;if(a.current?.kind!==`Let`)throw Af(`A name selector here must be from a LET clause`,n);i.lets.push(a.current.definitions);let e=s(a.current.definitions);if(e)return zf(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Af(`Subexpression selection failed`,n);return Rf(i,a.current)},Vf=(e,t)=>{if(!e.includes(`!`)||t(e))return;let n=e.split(`!`),r=n.findIndex((e,r)=>t(n.slice(0,r+1).join(`!`)));if(r!==-1)return[{kind:`Name`,name:n.slice(0,r+1).join(`!`),args:[]},...n.slice(r+1).map(e=>({kind:`Name`,name:e,args:[]}))]},Hf=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||ur(e).some(Hf),Uf=(e,t)=>{if(!Hf(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return ea(e,e=>Uf(e,n))}let n=ea(e,e=>Uf(e,t));if(n.kind===`Subexpression`)return Bf(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Vf(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Bf(i,t,n.location,a);if(a.length>0)throw Af(`Too many arguments for ${r}`,n.location);return o},Wf=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},Gf=(e,t)=>{let n=Wf(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:Uf(e.expression,n)}))}},Kf=(e,t)=>{let n=Wf([...t,...e.definitions]);return e.definitions.some(e=>Hf(e.body))||e.assumptions.some(e=>Hf(e.expression))?{...e,definitions:e.definitions.map(e=>$i(e,e=>Uf(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:Uf(e.expression,n)}))}:e},qf=new Map([[`Nat`,0,[],[],[]],[`+`,0,[0,0],[2,2],[1,1]],[`-`,0,[0,0],[2,2],[1,1]],[`*`,0,[0,0],[3,3],[0,0]],[`^`,0,[0,0],[2,2],[1,1]],[`<`,0,[0,0],[2,2],[1,1]],[`>`,0,[0,0],[2,2],[1,1]],[`<=`,0,[0,0],[2,2],[1,1]],[`>=`,0,[0,0],[2,2],[1,1]],[`%`,0,[0,0],[2,2],[1,1]],[`\\div`,0,[0,0],[2,2],[1,1]],[`..`,0,[0,0],[2,2],[1,1]],[`Int`,0,[],[],[]],[`-.`,0,[0],[2],[1]],[`Seq`,0,[0],[2],[1]],[`Len`,0,[0],[2],[1]],[`\\o`,0,[0,0],[2,2],[1,1]],[`Append`,0,[0,0],[2,2],[1,1]],[`Head`,0,[0],[2],[1]],[`Tail`,0,[0],[2],[1]],[`SubSeq`,0,[0,0,0],[2,2,2],[1,1,1]],[`SelectSeq`,0,[0,1],[2,2],[1,1],[],[`1,0,0`]],[`IsFiniteSet`,0,[0],[2],[1]],[`Cardinality`,0,[0],[2],[1]],[`IsABag`,0,[0],[2],[1]],[`BagToSet`,0,[0],[2],[1]],[`SetToBag`,0,[0],[3],[1]],[`BagIn`,0,[0,0],[2,2],[1,1]],[`EmptyBag`,0,[],[],[]],[`\\oplus`,0,[0,0],[2,2],[1,1]],[`\\ominus`,0,[0,0],[2,2],[1,1]],[`BagUnion`,0,[0],[2],[1]],[`\\sqsubseteq`,0,[0,0],[2,2],[1,1]],[`SubBag`,0,[0],[2],[1]],[`BagOfAll`,0,[1,0],[2,2],[1,1]],[`BagCardinality`,0,[0],[2],[1]],[`CopiesIn`,0,[0,0],[2,2],[1,1]],[`Print`,0,[0,0],[3,3],[0,1]],[`PrintT`,0,[0],[3],[0]],[`Assert`,0,[0,0],[2,3],[1,0]],[`JavaTime`,0,[],[],[]],[`TLCGet`,0,[0],[3],[0]],[`TLCSet`,0,[0,0],[3,3],[0,0]],[`:>`,0,[0,0],[2,3],[1,1]],[`@@`,0,[0,0],[2,2],[1,1]],[`Permutations`,0,[0],[2],[1]],[`SortSeq`,0,[0,2],[2,2],[1,1],[],[`1,0,0`,`1,0,1`]],[`RandomElement`,0,[0],[3],[1]],[`Any`,0,[],[],[]],[`ToString`,0,[0],[2],[1]],[`TLCEval`,0,[0],[3],[1]],[`AssertEq`,0,[0,0],[2,2],[1,1]],[`AssertError`,0,[0,0],[2,3],[1,0]],[`TLCGetOrDefault`,0,[0,0],[3,3],[0,0]],[`TLCGetAndSet`,0,[0,2,0,0],[3,3,3,3],[0,0,0,0],[],[`1,2,1`]],[`Trace`,0,[],[],[]],[`CounterExample`,0,[],[],[]],[`ToTrace`,0,[0],[3],[0]],[`TLCModelValue`,0,[0],[2],[1]],[`TLCDefer`,0,[0],[3],[0]],[`TLCNoOp`,0,[0],[3],[1]],[`PickSuccessor`,0,[0],[3],[1]],[`TLCCache`,0,[0,0],[3,3],[1,0]],[`TLCFP`,0,[0],[3],[0]],[`TLCEvalDefinition`,0,[0],[3],[0]],[`ToJson`,0,[0],[2],[1]],[`ToJsonArray`,0,[0],[2],[1]],[`ToJsonObject`,0,[0],[2],[1]],[`JsonSerialize`,0,[0,0],[3,3],[0,0]],[`JsonDeserialize`,0,[0],[3],[0]],[`ndJsonSerialize`,0,[0,0],[3,3],[0,0]],[`ndJsonDeserialize`,0,[0],[3],[0]],[`RandomSubset`,0,[0,0],[2,2],[1,1]],[`RandomSetOfSubsets`,0,[0,0,0],[2,3,2],[1,0,1]],[`TestRandomSetOfSubsets`,0,[0,0,0],[2,3,2],[1,0,1]]].map(e=>[e[0],{name:e[0],level:e[1],params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set,formals:e[2].map((e,t)=>({name:`$${t}`,arity:e})),maxLevels:e[3],weights:e[4],minMaxLevels:e[5]??[],conditions:new Set(e[6]),nonLeibniz:/* @__PURE__ */ new Set}])),Jf=(e,t)=>`${e}${t}`,Yf=(e,t,n)=>`${e}${t}${n}`,Xf=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},Zf=(e,t,n)=>`${e},${t},${n}`,Qf=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),$f=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),ep=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),tp=(e,t,n,r)=>({...Qf(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),np=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,rp=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,ip=new Map([[`=`,0,[2,2],[1,1]],[`#`,0,[2,2],[1,1]],[`\\in`,0,[2,2],[1,1]],[`\\notin`,0,[2,2],[1,1]],[`\\subseteq`,0,[2,2],[1,1]],[`\\cup`,0,[2,2],[1,1]],[`\\cap`,0,[2,2],[1,1]],[`\\`,0,[2,2],[1,1]],[`=>`,0,[3,3],[1,1]],[`<=>`,0,[3,3],[1,1]],[`/\\`,0,[3,3],[1,1]],[`\\/`,0,[3,3],[1,1]],[`~`,0,[3],[1]],[`SUBSET`,0,[2],[1]],[`UNION`,0,[2],[1]],[`DOMAIN`,0,[2],[1]],[`~>`,3,[3,3],[0,0]],[`-+->`,3,[3,3],[0,0]],[`\\cdot`,2,[2,2],[0,0]],[`TRUE`,0,[],[]],[`FALSE`,0,[],[]],[`BOOLEAN`,0,[],[]],[`STRING`,0,[],[]]].map(([e,t,n,r])=>[e,{...tp(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),ap=tp(`$Set`,0,[2],[1]),op=tp(`$Junction`,0,[3],[1]),sp=tp(`$Choose`,0,[2],[1]),cp=tp(`$Function`,0,[3],[1]),lp=tp(`$FcnApply`,0,[2,2],[1,1]),up=tp(`$RcdSelect`,0,[2,0],[1,1]),dp=tp(`'`,2,[1],[0]),fp=tp(`ENABLED`,1,[2],[0]),pp=tp(`[]`,3,[3],[0]),mp=tp(`$SquareAct`,2,[2,1],[0,0]),hp=tp(`$WF`,3,[1,2],[0,0]),gp=tp(`$TemporalExists`,3,[3],[0]),_p=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),vp=e=>e.map(e=>({name:e,arity:0})),yp=(e,t)=>t.location.range?_(`${e}.`,t.location.range):new p(`${e} at line ${t.location.line}, column ${t.location.column}`),bp=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),xp=e=>e.kind!==`Let`&&e.kind!==`Label`,Sp=e=>{let t=/* @__PURE__ */ new Map,n=(t,n)=>{let r=n.get(t);if(r?.kind===`Formal`)return{kind:`Declared`,name:t,level:0,arity:r.arity};if(r?.kind===`Let`)return{kind:`Defined`,levels:v(r.definition,r.scope)};if(e.constants.has(t))return{kind:`Declared`,name:t,level:0,arity:0};if(e.variables.has(t))return{kind:`Declared`,name:t,level:1,arity:0};let i=e.getDefinition(t);if(i){let n=v(i,/* @__PURE__ */ new Map),r=e.getQualifiedName?.(t);return{kind:`Defined`,levels:r?{...n,name:r}:n}}let a=ip.get(t)??qf.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=Qf(Math.max(t,...n.map(e=>e.data.level)));return r.params.add(e),n.forEach((t,n)=>{t.data.params.forEach(t=>{r.params.add(t),r.argParams.add(Yf(e,n,t))}),t.data.constraints.forEach((e,t)=>$f(r.constraints,t,e)),ep(r.argConstraints,Jf(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>ep(r.argConstraints,t,e)),t.data.argParams.forEach(e=>r.argParams.add(e))}),r},i=(e,t,n=[],r=[])=>{let i=e=>r.includes(e);if(t.forEach((t,n)=>{if(!(t.operator||t.declared)&&t.data.level>np(e,n))throw new p(`Level error in applying operator ${e.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator`)}),n.some(e=>e.level>2))throw new p(`Level error in applying operator ${e.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`);let a=n=>{let r=e.formals.findIndex(e=>e.name===n);return r===-1?void 0:t[r]},o=(t,n,r)=>e.conditions.has(Zf(t,n,r)),s=Qf(Math.max(e.level,...t.filter((t,n)=>rp(e,n)===1).map(e=>e.data.level),...n.map(e=>e.level)));return e.params.forEach(e=>s.params.add(e)),t.forEach((t,n)=>{rp(e,n)===1&&t.data.params.forEach(e=>s.params.add(e))}),n.forEach(e=>e.params.forEach(e=>s.params.add(e))),r.forEach(e=>s.params.delete(e)),e.constraints.forEach((e,t)=>$f(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||$f(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>$f(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||$f(s.constraints,t,np(e,n))})),t.forEach((e,n)=>{let r=e.operator;r&&t.forEach((e,t)=>r.formals.forEach((i,a)=>{o(n,t,a)&&e.data.params.forEach(e=>$f(s.constraints,e,np(r,a)))}))}),e.argParams.forEach(e=>{let t=Xf(e),n=a(t.operator)?.operator;n&&$f(s.constraints,t.param,np(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>ep(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>ep(s.argConstraints,Jf(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&ep(s.argConstraints,Jf(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=Xf(e),n=a(t.operator);n&&ep(s.argConstraints,Jf(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(Xf(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=Xf(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(Yf(n.declared.name,t.index,t.param));else{let n=a(t.param);if(!n){s.argParams.add(e);return}n.data.params.forEach(e=>s.argParams.add(Yf(t.operator,t.index,e)))}}),t.forEach((e,n)=>{let r=e.declared;r&&t.forEach((e,t)=>Array.from({length:r.arity},(i,a)=>{o(n,t,a)&&e.data.params.forEach(e=>s.argParams.add(Yf(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=_(`LAMBDA`,vp(e.params),e.body,t);return{data:n,operator:n}}let r=e.kind===`OperatorReference`?e.operator:e.kind===`Identifier`?e.name:void 0;if(r!==void 0){let i=n(r,t);if(i.kind===`Defined`&&(i.levels.formals.length>0||e.kind===`OperatorReference`))return{data:i.levels,operator:i.levels};if(i.kind===`Declared`&&i.arity>0){let e=Qf();return e.params.add(r),{data:e,declared:{name:r,arity:i.arity}}}}return{data:m(e,t)}},o=(e,t)=>e.map(e=>a(e,t)),s=(e,t,n,r=[],a=[])=>{let s=_p(n,vp(a));return i(e,o(t,s),r.map(e=>m(e,n)),a)},c=(e,t)=>e.kind===`Declared`?r(e.name,e.level,t):i(e.levels,t),l=(e,t)=>{let n=e.map(e=>e.data.level);if(n.includes(2)&&n.includes(3))throw yp(`Formula has both temporal formula and action as arguments`,t)},u=(e,t)=>{if((e.operator===`~>`||e.operator===`-+->`)&&t.some(e=>e.data.level===2))throw yp(`Action used where only temporal formula or state predicate allowed`,e);bp.has(e.operator)&&l(t,e)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&xp(n)&&n.kind!==r)throw yp(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e)},f=(e,t)=>{let n=new Map(t);e.definitions.forEach(e=>n.set(e.name,{kind:`Let`,definition:e,scope:n}));let r=m(e.body,n),i={level:r.level,params:new Set(r.params),constraints:new Map(r.constraints),argConstraints:new Map(r.argConstraints),argParams:new Set(r.argParams)};return e.definitions.forEach(e=>{let t=v(e,n);t.constraints.forEach((e,t)=>$f(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>ep(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{try{return h(e,t)}catch(t){throw!(t instanceof p)||t.sany?t:yp(t.message,e)}},h=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return Qf();case`Identifier`:return c(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return u(e,r),c(n(e.operator,t),r)}case`OperatorReference`:case`Lambda`:return a(e,t).data;case`And`:case`Or`:{let n=o(e.operands,t);return l(n,e),i(op,n)}case`Prime`:case`Unchanged`:return s(dp,[e.expression],t);case`Enabled`:return s(fp,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(pp,[n])}case`If`:return s(op,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(op,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return f(e,t);case`Forall`:case`Exists`:{let n=s(op,[e.body],t,e.bounds.map(e=>e.set),di(e.bounds)),r=n.level===3?e.bounds.find(e=>m(e.set,t).level===2):void 0;if(r)throw yp(`Action-level bound of quantified temporal formula`,r.set);return n}case`UnboundedQuantifier`:return s(e.isTemporal?gp:op,[e.body],t,[],e.names);case`Choose`:return s(sp,[e.body],t,e.set?[e.set]:[],ui(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(ap,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(ap,[e.predicate],t,[e.bound.set],ui(e.bound.pattern));case`SetMap`:return s(ap,[e.expression],t,e.bounds.map(e=>e.set),di(e.bounds));case`FunctionConstruction`:return s(cp,[e.body],t,e.bounds.map(e=>e.set),di(e.bounds));case`Record`:return s(cp,e.fields.map(e=>e.value),t);case`RecordSet`:return s(ap,e.fields.map(e=>e.value),t);case`Except`:return s(ap,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(lp,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(ap,e.args,t)}]);case`FieldAccess`:return i(up,[a(e.record,t),{data:Qf()}]);case`BoxAction`:case`AngleAction`:return s(mp,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(hp,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return Qf()}},g=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>g(e,a,n,i),o=(e,o)=>{let s=n(e,t);s.kind===`Declared`?(r&&i.add(e),o.forEach(e=>a(e))):o.forEach((e,t)=>a(e,r||s.levels.nonLeibniz.has(t)))};switch(e.kind){case`Identifier`:return o(e.name,[]),i;case`Apply`:return o(e.operator,e.args),i;case`Lambda`:case`Let`:return i;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:case`BoxAction`:case`AngleAction`:case`WeakFairness`:case`StrongFairness`:return ur(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,_p(t,vp(e.names))),i;default:return ea(e,(e,n)=>(a(e,r,_p(t,vp(n))),e)),i}},_=(e,t,n,r)=>{let i=_p(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=g(n,i),c={...Qf(a.level),name:e,formals:t,nonLeibniz:new Set(t.flatMap((e,t)=>s.has(e.name)?[t]:[])),maxLevels:t.map(e=>Math.min(3,a.constraints.get(e.name)??3)),weights:t.map(e=>+!!a.params.has(e.name)),minMaxLevels:t.map(e=>Array.from({length:e.arity},(t,n)=>a.argConstraints.get(Jf(e.name,n))??0)),conditions:new Set(t.flatMap((e,n)=>t.flatMap((t,r)=>Array.from({length:e.arity},(e,t)=>t).filter(n=>a.argParams.has(Yf(e.name,n,t.name))).map(e=>Zf(n,r,e)))))};return a.params.forEach(e=>{o(e)||c.params.add(e)}),a.constraints.forEach((e,t)=>{o(t)||c.constraints.set(t,e)}),a.argConstraints.forEach((e,t)=>{o(Xf(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=Xf(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},v=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...Qf(),name:e.name,formals:i,maxLevels:i.map(()=>3),weights:i.map(()=>0),minMaxLevels:i.map(()=>[]),conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set});let a=e.kind===`Function`?{kind:`FunctionConstruction`,bounds:e.bounds,body:e.body,location:e.location}:e.body,o=_(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:v,toOperand:a}},Cp=(e,t,n)=>{let r=new Map(t),i=e.assumptions.flatMap(e=>{if(e.kind===`NewSymbol`){let t=e.set&&n.analyze(e.set,r);return r.set(e.name,{kind:`Formal`,arity:e.arity}),t?[t]:[]}return[e.kind===`AssumeProve`?Cp(e,r,n):n.analyze(e,r)]});i.push(n.analyze(e.conclusion,r));let a=Qf(Math.max(...i.map(e=>e.level)));return i.forEach(e=>{e.params.forEach(e=>a.params.add(e)),e.constraints.forEach((e,t)=>$f(a.constraints,t,e)),e.argConstraints.forEach((e,t)=>ep(a.argConstraints,t,e)),e.argParams.forEach(e=>a.argParams.add(e))}),a},wp=(e,t,n)=>{let r=Sp(t),i=e=>Math.max(0,...e.map(e=>r.analyze(e,/* @__PURE__ */ new Map).level)),a=e=>{let t=e.body;return t.kind===`Have`||t.kind===`Case`?i([t.expression]):t.kind===`Witness`?i(t.expressions):t.kind===`Take`?i(t.bounds.map(e=>e.set)):t.kind===`Pick`?i([t.body,...t.bounds.map(e=>e.set)]):t.kind===`Assert`?t.statement.kind===`AssumeProve`?Cp(t.statement,/* @__PURE__ */ new Map,r).level:i([t.statement]):0},o=e=>e?.kind===`Steps`?e.steps.flatMap(e=>{let t=g(e.statement),n=()=>a(e)===0;return e.body.kind===`Have`||e.body.kind===`Take`||e.body.kind===`Witness`?n()?[]:[{location:t,message:`Non-constant TAKE, WITNESS, or HAVE for temporal goal.`}]:e.body.kind===`Case`?[...n()?[]:[{location:t,message:`Non-constant CASE for temporal goal.`}],...o(e.proof)]:e.body.kind===`Qed`?o(e.proof):[]}):[],s=e=>e?.kind===`Steps`?e.steps.flatMap(e=>{let t=e.body,n=()=>a(e)===3,r=t.kind===`Pick`&&t.bounds.length>0&&n()?t.bounds.filter(e=>i([e.set])!==0).flatMap(e=>e.set.location.range?[{location:g(e.set.location.range),message:`Non-constant bound of temporal PICK.`}]:[]):[];return[...s(e.proof),...r,...e.proof?.kind===`Steps`&&n()?o(e.proof):[]]}):[];Wi([...e.definitions.filter(e=>!e.name.includes(`!`)).map(e=>({location:e.location,check:()=>r.analyzeDefinition(e,/* @__PURE__ */ new Map)})),...e.assumptions.map(e=>({location:e.location,check:()=>r.analyze(e.expression,/* @__PURE__ */ new Map)})),...e.theorems.map(e=>({location:e.location,check:()=>{let t=e.statement.kind===`AssumeProve`?Cp(e.statement,/* @__PURE__ */ new Map,r):r.analyze(e.statement,/* @__PURE__ */ new Map),n=[...s(e.proof),...t.level===3?o(e.proof):[]];if(n.length>0)throw m(n)}})),...n])},Tp=(e,t)=>e.maxLevels[t]??3,Ep=e=>{let t=/* @__PURE__ */ new Map,n=n=>{let r=t.get(n);if(r)return r;let i=e(n),a=Sp({constants:new Set(i.constants.map(e=>e.name)),variables:new Set(i.variables),getDefinition:i.getDefinition});return t.set(n,a),a},r=/* @__PURE__ */ new Map,i=t=>{let i=r.get(t);if(i)return i;let a=e(t),o=n(t),s=a.definitions.map(e=>o.analyzeDefinition(e,/* @__PURE__ */ new Map)),c={isConstant:a.variables.length===0&&s.every(e=>e.level===0),constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set};c.isConstant||a.constants.forEach(e=>$f(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>$f(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>ep(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=Xf(e);t(n.operator,n.param)&&c.argParams.add(e)})};s.forEach(e=>l(e,(t,n)=>e.formals.every(e=>e.name!==t&&e.name!==n)));let u=e=>{l(e,()=>!0),a.constants.forEach(t=>{e.params.has(t.name)&&$f(c.constraints,t.name,2)})};return a.assumptions.forEach(e=>u(o.analyze(e,/* @__PURE__ */ new Map))),a.theorems.forEach(e=>e.statement.kind===`AssumeProve`?u(Cp(e.statement,/* @__PURE__ */ new Map,o)):l(o.analyze(e.statement,/* @__PURE__ */ new Map),()=>!0)),r.set(t,c),c};return t=>{let r=/* @__PURE__ */ new Map,a=g(t.location.range??{module:t.instancer,start:t.location,end:t.location}),o=e=>r.set(`${a}\n${e}`,{location:a,message:e}),s=e(t.module),c=i(t.module),l=n(t.instancer),u=/* @__PURE__ */ new Map;t.lets.forEach(e=>u.set(e.name,{kind:`Let`,definition:e,scope:u}));let d=[...s.constants.map(e=>({...e,maximumLevel:0})),...s.variables.map(e=>({name:e,arity:0,maximumLevel:1}))].flatMap(e=>{let n=t.substitutions.get(e.name);if(!n)return[];if(e.arity===0){let t=l.analyze(n,u);return[{...e,level:t.level,operator:void 0,isLeibniz:!0}]}let r=l.toOperand(n,u);return[{...e,level:r.data.level,operator:r.operator,isLeibniz:r.operator===void 0||r.operator.nonLeibniz.size===0}]}),f=(e,n)=>`Level error in instantiating module '${t.module}':\nThe level of the expression or operator substituted for '${e}' \nmust be at most ${n}.`;if(d.forEach(e=>{!c.isConstant&&e.level>e.maximumLevel&&o(f(e.name,e.maximumLevel)),e.isLeibniz||o(`Error in instantiating module '${t.module}':\n A non-Leibniz operator substituted for '${e.name}'.`)}),d.forEach(e=>{let n=c.constraints.get(e.name);n!==void 0&&e.level>n&&o(f(e.name,n));let r=e.operator;r&&Array.from({length:e.arity},(n,i)=>{let a=c.argConstraints.get(Jf(e.name,i));a!==void 0&&Tp(r,i)<a&&o(`Level error in instantiating module '${t.module}':\nThe level of the argument ${i+1} of the operator ${r.name} \nmust be at least ${a}.`)})}),c.argParams.forEach(e=>{let n=Xf(e),r=d.find(e=>e.name===n.operator)?.operator,i=d.find(e=>e.name===n.param);if(!r||!i)return;let a=Tp(r,n.index);i.level>a&&o(`Level error when instantiating module '${t.module}':\nThe level of the argument ${n.index} of the operator ${n.operator}' \nmust be at most ${a}.`)}),r.size>0)throw m([...r.values()])}},Dp=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],Op=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),kp=new Map(ef.flatMap(e=>e.map(t=>[t,e[0]]))),Ap=e=>kp.get(e)??e,jp=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Mp=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(jp(e.name)&2147483647)%t,i=()=>{let t=e.buckets.length*2+1,n=Array.from({length:t},()=>[]);for(let i=e.buckets.length-1;i>=0;i--)for(let a of e.buckets[i])n[r(a,t)].unshift(a);e.buckets=n,e.threshold=Math.floor(t*.75)};return{put:a=>{t.has(a.key)||(n.length>=e.threshold&&i(),e.buckets[r(a,e.buckets.length)].unshift(a),t.add(a.key),n.push(a))},inserted:n,enumerate:()=>e.buckets.toReversed().flat()}},Np=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Pp=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Ap(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Ap(n.text),end:t+2};if(r?.text!==`(`)return{name:n.text,end:t+1};let i=e.findIndex((e,n)=>n>t&&e.text===`)`);return{name:n.text,end:i+1}},Fp=(e,t)=>{let n=[];for(let r=t;;){let t=Pp(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},Ip=e=>({line:e.line,column:e.column}),Lp=(e,t,n)=>{let r=/* @__PURE__ */ new Set,i=(a,o)=>{let s={key:o,unit:t,extends:[],instances:[],inner:[],allExtends:r};for(let t=a+1;t<e.length;t++){let a=e[t];if(a.kind===`ModuleEnd`)return{references:s,end:t};if(a.kind===`Separator`&&e[t+1]?.text===`MODULE`){let r=e[t+2].text,a=i(t,`${o}/${r}`);n.set(r,a.references),s.inner.push(a.references),t=a.end}else if(a.text===`EXTENDS`){let n=Fp(e,t+1);s.extends.push(...n),n.forEach(e=>r.add(e))}else a.text===`INSTANCE`&&e[t+1]?.kind===`Identifier`&&s.instances.push(e[t+1].text)}return{references:s,end:e.length}};return i(0,t??``).references},Rp=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,zp={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Bp=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Rp(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Rp(e[n+1],e[n+2])?n+=Rp(e[n+2],e[n+3])?3:2:(r.text!==`MODULE`||e[n-1]?.kind!==`Separator`)&&t.push(r.kind===`String`?`"${r.text.replace(/[\\"\n\t\r\f]/g,e=>zp[e])}"`:r.text)}return t},Vp=e=>{let t=/* @__PURE__ */ new Map,n=[];return e.forEach((r,i)=>{r.kind===`Separator`&&e[i+1]?.text===`MODULE`&&n.push({name:e[i+2].text,start:i});let a=r.kind===`ModuleEnd`?n.pop():void 0;a&&!t.has(a.name)&&t.set(a.name,{start:a.start,end:i+1})}),t},Hp=(e,t)=>e.find(e=>e.name===t)??e.map(e=>Hp(e.modules,t)).find(Boolean),Up=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new Map,i=i=>{let a=n.get(i??``);if(a)return a;let o=i===void 0?e:af.get(i)??t?.(i)??ol(e,i),s=o===void 0?[]:ue(o),c=Vp(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=cl(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>Hp(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},Wp=(e,t,n)=>{let r=Up(e,t),i=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],a=(e,n)=>{let i=Fp(t,e+1);r.push({location:Ip(t[e]),apply:e=>i.forEach(t=>e.put(Np(t,n,!1)))})},s=new Set(n.definitions.filter(e=>e.isRecursive).map(e=>e.name)),c={value:0};t.slice(e.start,e.end).forEach((n,o)=>{let l=e.start+o,u=t[l];if(u.kind===`Separator`&&t[l+1]?.text===`MODULE`){if(c.value++,c.value===2){let e=t[l+2].text;r.push({location:Ip(u),apply:t=>t.put(Np(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&a(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&a(l,`variable`),u.text===`RECURSIVE`&&Fp(t,l+1).every(e=>s.has(e))&&a(l,`definition`),Op.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(Ip(u)),r.push({location:Ip(u),apply:e=>e.put(Np(t[l+1].text,`theorem`,!1))})))}),n.assumptions.forEach(e=>{i.push(e.location);let t=e.name;t!==void 0&&r.push({location:e.location,apply:e=>e.put(Np(t,`theorem`,!1))})});let l=e=>i.some(t=>t.line===e.line&&t.column===e.column);return n.definitions.forEach(e=>{if(l(e.location))return;let t=Ap(e.name);r.push({location:e.location,apply:n=>n.put(Np(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=o(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),a=n.filter(e=>e.kind===`theorem`);[...i,...a].forEach(n=>{n.isLocal||t.put(Np(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Np(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>ii(e.location,t.location)?-1:+!!ii(t.location,e.location))},a=/* @__PURE__ */ new Map,o=e=>{let t=a.get(e??``);if(t)return t;let n=Mp();a.set(e??``,n),$d.toReversed().forEach(e=>n.put(Np(e,`builtin`,!1)));let s=r(e);return s.getModule().extends.forEach(e=>o(e).inserted.forEach(e=>{e.isLocal||n.put(e)})),i(s).forEach(e=>e.apply(n)),n};return o(void 0).enumerate().filter(e=>e.kind===n).map(e=>e.name).reverse()},Gp=(e,t,n)=>{let r=Up(e,n),i=/* @__PURE__ */ new Set,a=e=>{i.add(e)},o=e=>{e.kind===`ModelValue`&&a(e.name),e.kind===`String`&&a(e.value),e.kind===`Set`&&e.elements.forEach(o)};t.constants.forEach(e=>{e.args?.forEach(o),o(e.value)}),tf.forEach(a);let s=e=>{let t=r(e);return t.tokens.slice(t.start,t.end)},c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u=e=>{let t=l.get(e);if(t)return t;let n=Lp(s(e),e,c);return l.set(e,n),n},d=e=>c.get(e)??u(e),f=/* @__PURE__ */ new Set,p=(e,t)=>c.has(t)||f.has(`${e.key}>${t}`),m=(e,t,n)=>{let r=[...e.extends.map(d),...e.instances.filter(t=>p(e,t)).map(d),...e.inner];for(let e of r){let r=n(e,t);if(r)return r}},h=e=>{let t=(n,r)=>{if(r.has(n.key))return;r.add(n.key);let i=e(n).find(e=>!p(n,e));return i===void 0?m(n,r,t):[n,i]};return t},g=h(e=>e.extends),_=h(e=>e.instances),v=/* @__PURE__ */ new Set([void 0]),y=/* @__PURE__ */ new Map;Bp(s(void 0)).forEach((e,t)=>{t===3&&rf.forEach(a),a(e)});let b=u(void 0);for(;;){let e=g(b,/* @__PURE__ */ new Set)??_(b,/* @__PURE__ */ new Set);if(!e)break;let[t,n]=e;f.add(`${t.key}>${n}`),y.set(t.unit,[...y.get(t.unit)??[],n]),!v.has(n)&&(v.add(n),Bp(s(n)).forEach(a))}Dp.forEach(a);let ee=/* @__PURE__ */ new Set,x=e=>{if(ee.has(e))return;ee.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(x),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return x(void 0),nf.forEach(a),[...i]},Kp=t=>{switch(t.kind){case`Number`:try{return Pe(t.value)}catch(t){throw n(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return Xe(t.name);case`Set`:return Et(t.elements.map(Kp))}},qp=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],Jp=e=>new p(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),Yp=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:ei},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),Xp=(e,t,n)=>{let r=`{ ${n.map(e=>`<${[...e[0],e[1]].map(e=>Y(e)).join(`, `)}>`).join(`, `)}}`;return{kind:`Builtin`,name:e,arity:t,evaluate:e=>{let t=n.find(t=>{if(t[0].length!==e.length)throw new y(`Attempted to apply the operator ${r}\nwith wrong number of arguments.`);return t[0].every((t,n)=>{let r=e[n];return(typeof r!=`object`||r.kind!==`Operator`)&&$e(t,r)})});if(t)return t[1];throw new y(`Attempted to apply operator:\n${r}\nto arguments (${e.map(e=>typeof e==`object`&&e.kind===`Operator`?e.name:Y(e)).join(`, `)}), which is undefined.`)},evaluateUnary:void 0,evaluateBinary:void 0}},Zp=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||ur(e).some(e=>Zp(e,t)),Qp=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(la(e),n.get(e)??n.size)),n},$p=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),em=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw jo(e);if(e.kind===`Number`&&!bs(e.value))throw Mo(e);em(e.kind===`Let`?[...ur(e),...$p(e.instances??[])]:ur(e))}),tm=(e,t)=>{let n=cl(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=new Map(mf.map(e=>[e.name,e])),s=/* @__PURE__ */ new Map,c=Ul(e.checkDeadlock,t.seed),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,f=[],h=/* @__PURE__ */ new Map,g=[],_=[],ee=(e,t)=>g.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),x={value:0},S=e=>`${e}#${x.value++}`,C=[],w=Ep(e=>{let t=d.get(e)??A(e,e);return{constants:t.constants,variables:t.variables,definitions:[...new Set([...t.visible.values()].flatMap(e=>r.get(e.key)??[]))],assumptions:t.module.assumptions.map(e=>e.expression),theorems:t.module.theorems,getDefinition:e=>r.get(t.visible.get(e)?.key??e)}}),T=/* @__PURE__ */ new Map,te=/* @__PURE__ */ new Map,ne=e=>{let n=s.get(e);if(n)return n;let r=Of(e,t.print,c,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>ne(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{o.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),s.set(e,i),i},E=e=>{let t=ne(e),n=Df.get(e)??[];return t&&ee(e,n),t&&n.includes(`Integers`)&&ne(`Integers`),t},D=e=>(em([...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),...e.assumptions.map(e=>e.expression),...e.theorems.flatMap(e=>e.statement.kind===`AssumeProve`?[]:[e.statement]),...$p(e.instances)]),e.modules.forEach(D),e);D(n);let O=(e,n)=>{let r=t.loadModule?.(e)??kc.get(e)??ol(t.source,e);if(r===void 0)throw m([{location:`In module ${n}`,message:`Cannot find source file for module ${e} imported in module ${n}.`}],!0);let i=Fu(r,e);if(i.name!==e)throw m([{location:`Unknown location`,message:`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`}],!0);return D(i)},k=e=>{let t=_.indexOf(e.name);if(t!==-1)throw new p(`Circular dependency among .tla files; dependency cycle is: ${[..._.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];_.push(e.name),g.push(n);let i=ce(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});g.pop(),_.pop();let a=r.find(e=>n.has(e.name));if(a)throw Jp(a);return{linked:i,closure:n}},A=(e,t)=>{let n=l.get(e);if(n)return ee(e,h.get(e)??[]),n;let r=k(O(e,t));return l.set(e,r.linked),h.set(e,r.closure),ee(e,r.closure),r.linked},j=(e,t,n,o,s)=>{let c=s?void 0:E(e.module);if(c)return e.name===void 0?c:new Map([...c].map(([t,n])=>[`${e.name}!${t}`,n]));let l=s??A(e.module,t.name),u=qp(l),d=`#${x.value++}`,f=new Map(e.params.map(e=>[e.name,`${e.name}${d}`])),p=Ui(Gf(e,t),u,t,n);C.push({module:e.module,instancer:t.name,lets:[],substitutions:p,location:e.location});let m=xa({params:e.params.map(e=>({...e,name:`${e.name}${d}`})),substitutions:new Map([...p].map(([e,t])=>[e,Ji(t,f)])),variables:new Set(l.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(n,s,c)=>{let l=S(`${s}@${t.name}`);return r.set(l,c(l)),i.set(l,!o),a.set(l,{source:n,prefix:e.params.length}),l},createName:S}),h=new Set(u.map(e=>e.name)),g=/* @__PURE__ */ new Map;return l.exported.forEach((t,n)=>{if(h.has(n))return;if(e.name===void 0){let r=m.getKey(t.key);u.length>0&&T.set(r,{name:n,location:e.location}),g.set(n,{key:r,arity:t.arity});return}let r=m.getQualifiedKey(t.key);u.length>0&&T.set(r,{name:`${e.name}!${n}`,location:e.location}),te.set(r,`${e.name}!${n}`),g.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),g},re=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:ei})),M=(e,t,n,r,i)=>({kind:`Operator`,name:e,params:n,body:r.length===0?{kind:`Identifier`,name:t,location:i}:{kind:`Apply`,operator:t,args:re(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),ie=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),ae=(e,t,n)=>{if(t.arity===0)return{params:[],body:e};if(e.kind===`Lambda`)return{params:e.params.map(e=>({name:e,arity:0})),body:e.body};let r=ie(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:re(r,n),location:n}}},oe=(e,t,n,a)=>{let o=e.location,s=a?void 0:E(e.module);if(s)return e.name===void 0?[]:[...s].map(([t,n])=>{let r=ie(n.arity);return M(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??A(e.module,n),l=`#${x.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=qp(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};C.push({module:e.module,instancer:n,lets:t,substitutions:new Map(d.map(e=>[e.name,f(e)])),location:o});let p=new Set(e.params.map(e=>e.name)),m=e=>Zp(f(e),p),h=d.map(t=>{let n=ae(f(t),t,o);return{kind:`Operator`,name:`${t.name}${l}`,params:[...m(t)?e.params:[],...n.params],body:n.body,isLocal:!0,isRecursive:!1,location:o}}),g=[],_=xa({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:re(e.params,o),location:o,resolution:ei}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:ei}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n,r)=>{let i=`${n}@${e.module}${l}.${g.length}`,a=r(i);return g.push(a.kind===`Operator`?{...a,name:i}:Yp(a,i)),i},createName:S}),v=new Set(d.map(e=>e.name)),y=[...c.exported].filter(([e])=>!v.has(e)).map(([t,n])=>{let r=_.getKey(n.key),i=ie(n.arity),a=[...e.params,...i];return M(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...y]},se=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),ce=(e,a)=>{let o=Lc(e,t.loadClass?.(e.name)),s=C.length,c=new Map([...mf.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),l=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Map,m=[],h=[...o.constants],g=o.variables.map(e=>e.name),_=o.variables.map(e=>e.location),v=(e,t)=>e.forEach((e,n)=>{c.set(n,e),t&&l.set(n,e)});o.extends.forEach(e=>{let t=a.modules.get(e),n=t?void 0:E(e);if(n){v(n,!0);return}let r=t??A(e,o.name);h.push(...r.constants.filter(e=>h.every(t=>t.name!==e.name))),r.variables.forEach((e,t)=>{g.includes(e)||(g.push(e),_.push(r.variableLocations[t]))}),v(r.exported,!0),r.modules.forEach((e,t)=>p.set(t,e)),m.push(r)}),o.constants.forEach(e=>l.set(e.name,{key:e.name,arity:e.arity,declaration:`Constant`})),o.variables.forEach(e=>l.set(e.name,{key:e.name,arity:0,declaration:`Variable`}));let y=h.length===0&&g.length===0,b=e=>o===n?e.name:`${e.name}@${a.id}`,ee=/* @__PURE__ */ new Map,x=e=>({imported:c,importedAt:ee,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:b}),S=()=>new Map([...a.modules,...p]),T=e=>new Map([...c,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>ii(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>ii(t.location,e)).map(e=>[e.name,{key:b(e),arity:ai(e)}])]),ne=e=>{let t=S();if(t.has(e.name))throw Jp(e);a.nested.push(e);let n=ce(e,{id:`${a.id}/${e.name}`,symbols:T(e.location),modules:t,nested:a.nested});p.set(e.name,n),u.has(e.name)||u.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=j(e,o,x(o),y,S().get(e.module));t.forEach((t,n)=>{c.has(n)||ee.set(n,e.location)}),v(t,!e.isLocal)}})),...o.modules.map(e=>({location:e.location,link:()=>ne(e)}))].sort((e,t)=>ii(e.location,t.location)?-1:1).forEach(e=>e.link()),Vi(o,x(o));let D=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&ii(e.location,t.location)},O=e=>{let t=o.modules.find(t=>t.name===e.module);return t?D(t)?p.get(t.name):void 0:S().get(e.module)},k=Kf(Ta(o,(e,t)=>oe(e,t,o.name,O(e))),se(c));Gi(k,x(k)),k.definitions.forEach(e=>{let t=b(e);r.set(t,e),i.set(t,!y);let n={key:t,arity:ai(e)};c.set(e.name,n),e.isLocal||l.set(e.name,n)});let re={module:k,constants:h,variables:g,variableLocations:_,visible:c,exported:l,modules:p,extended:m};return d.has(o.name)||d.set(o.name,re),wp(k,{constants:new Set(h.map(e=>e.name)),variables:new Set(g),getDefinition:e=>r.get(c.get(e)?.key??e),getQualifiedName:e=>te.get(c.get(e)?.key??e)},C.splice(s).map(e=>({location:e.location,check:()=>w(e)}))),f.push(re),re},le=k(n).linked,ue=e=>le.visible.get(e)?.key??e;le.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let de=[],fe=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>fe(e,t)),de.push(...e.module.assumptions))};fe(le,/* @__PURE__ */ new Set);let N=le.constants.map(e=>e.name),pe=le.variables,me=e=>e.module===void 0?[e.name,ue(e.name)]:e.module===n.name||N.includes(e.name)?[]:[(l.get(e.module)??u.get(e.module))?.visible.get(e.name)?.key??e.name],he=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:le.constants.find(t=>t.name===e)?.arity??0},ge=/* @__PURE__ */ new Map,_e=/* @__PURE__ */ new Set,ve=(e,t)=>{o.set(e,t),r.delete(e),ge.delete(e),_e.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=Kp(e.value);me(e).forEach(e=>{let n=he(e);n===0?ge.set(e,t):ve(e,{kind:`Builtin`,name:e,arity:n,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0,isLazy:!0})})});let ye=/* @__PURE__ */ new Map;e.constants.forEach(e=>{if(e.args===void 0)return;let t=`${e.module??``}!${e.name}`,n=ye.get(t)??{name:e.name,module:e.module,rows:[]};if(n.rows.length>0&&n.rows[0][0].length!==e.args.length)throw new v(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(Kp),Kp(e.value)]),ye.set(t,n)}),ye.forEach(e=>me(e).forEach(t=>ve(t,Xp(e.name,he(t)||e.rows[0][0].length,e.rows))));let be=new Map(e.substitutions.flatMap(e=>me(e).map(t=>[t,ue(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!N.includes(n)&&!le.visible.has(n))throw new v(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new v(`In the configuration file, the identifier ${i} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`);let a=ue(i),s=r.get(a);if(!(s!==void 0||o.has(a)||ge.has(a)||N.includes(i)||pe.includes(i)))throw new v(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(le.constants.find(e=>e.name===n)?.arity??le.visible.get(n)?.arity))throw new v(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)});let xe=new Set([...e.constants,...e.substitutions].filter(e=>e.module!==void 0).flatMap(me)),Se=(e,t)=>{if(xe.has(e))return{key:e,prefix:t};let n=a.get(e);return n&&Se(n.source,t+n.prefix)};a.forEach((e,t)=>{let n=Se(e.source,e.prefix),i=r.get(t);if(!n||!i)return;let a=i.kind===`Operator`?i.params:[],o=M(t,n.key,a,a.slice(n.prefix),i.location);r.set(t,o),le.visible.forEach((e,n)=>{e.key===t&&n!==t&&r.set(n,o)})});let Ce=N.filter(e=>!ge.has(e)&&!be.has(e)&&!_e.has(e));if(Ce.length>0)throw new v(`The constant parameter ${Wp(t.source,t.loadModule,`constant`).find(e=>Ce.includes(e))??Ce[0]} is not assigned a value by the configuration file.`);let we={runtime:c,definitions:r,builtins:o,constants:ge,substitutions:be,variables:pe,variableIndex:Qp(pe,f.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap},Te=Sp({constants:new Set(ge.keys()),variables:/* @__PURE__ */ new Set([...pe,...[`TLCGet`,`Trace`,`CounterExample`].filter(e=>o.has(e))]),getDefinition:e=>Ro(e,we)}),Ee=e=>{try{Ys(e,{environment:we,scope:void 0,state:void 0,next:void 0});return}catch(e){if(e instanceof y)return e;throw e}};return be.forEach((e,t)=>{let n=r.get(e),i=N.includes(t)&&n?.kind===`Operator`&&n.params.length===0&&Te.analyzeDefinition(n,/* @__PURE__ */ new Map).level>0?Ee(n.body):void 0;if(i)throw new v(`The configuration file substitutes constant ${t} with non-constant ${e}${i instanceof b?``:` - specifically: ${i.message}`}`)}),c.isStarted=!0,{environment:we,assumptions:de,variableLocations:le.variableLocations,instanceActions:T}},nm={kind:`Boolean`,value:!0},rm={kind:`Boolean`,value:!1},im=e=>e?nm:rm,am=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,om=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,sm=(e,t)=>({kind:e,body:t}),cm=(e,t,n)=>({kind:e,operands:[t,n]}),lm=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?lm(e,t.operands).operands:[t])}),um=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return um(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,um(t)),0)}},dm=e=>{switch(e.kind){case`Action`:return!0;case`Boolean`:case`State`:case`Enabled`:return!1;case`Not`:case`Always`:case`Eventually`:case`Next`:return dm(e.body);case`And`:case`Or`:return e.operands.some(dm)}},fm=/* @__PURE__ */ new WeakMap,pm={count:0},mm=e=>{let t=fm.get(e);if(t!==void 0)return t;let n=(()=>{switch(e.kind){case`Boolean`:return String(e.value);case`State`:case`Enabled`:case`Action`:return`#${pm.count++}`;case`And`:case`Or`:return`${e.kind}(${e.operands.map(mm).join(`,`)})`;default:return`${e.kind}(${mm(e.body)})`}})();return fm.set(e,n),n},hm=(e,t)=>e===t||mm(e)===mm(t),gm=(e,t)=>{let n=mm(t);return e.some(e=>e===t||mm(e)===n)},_m=e=>e===`And`?`Or`:`And`,vm=(e,t)=>{switch(e.kind){case`Boolean`:return t?im(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?sm(`Not`,e):e;case`Not`:return vm(e.body,!t);case`And`:case`Or`:return lm(t?_m(e.kind):e.kind,e.operands.map(e=>vm(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return sm(n,vm(e.body,t))}}},ym=e=>{switch(e.kind){case`Boolean`:return im(!e.value);case`Not`:return e.body;case`And`:case`Or`:return lm(_m(e.kind),e.operands.map(ym));case`Always`:return sm(`Eventually`,ym(e.body));case`Eventually`:return sm(`Always`,ym(e.body));default:return sm(`Not`,e)}},bm=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=bm(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return im(t)}return n.length===0?im(!t):n.length===1?n[0]:lm(e.kind,n)}case`Not`:{let t=bm(e.body);return t.kind===`Boolean`?im(!t.value):sm(`Not`,t)}case`Always`:case`Eventually`:{let t=bm(e.body);return sm(e.kind,t.kind===e.kind?t.body:t)}default:return e}},xm=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,Sm=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=Sm(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new y(`TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form.`);t.push(e)}}if(n.value===1)return{kind:`And`,operands:t};let r=Array.from({length:n.value},()=>[]),i={groups:1,repeat:n.value};for(let e of t){if(e.kind!==`Or`){r.forEach(t=>t.push(e));continue}i.repeat/=e.operands.length;let t={value:0};for(let n=0;n<i.groups;n++)for(let n of e.operands)for(let e=0;e<i.repeat;e++)r[t.value++].push(n);i.groups*=e.operands.length}return{kind:`Or`,operands:r.map(e=>lm(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=Sm(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=xm(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:lm(`Or`,t);n.push(sm(`Always`,sm(`Eventually`,e)))}return lm(`Or`,n)}case`Not`:return am(e.body)?e:Sm(ym(e.body));default:return e}},Cm=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?Cm(e.operands[0]):lm(e.kind,e.operands.map(Cm));case`Not`:return e.body.kind===`Not`?Cm(e.body.body):sm(`Not`,Cm(e.body));case`Always`:case`Eventually`:case`Next`:return sm(e.kind,Cm(e.body));default:return e}},wm=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return wm(e.operands[0]);let t=Math.floor(e.operands.length/2);return cm(e.kind,wm(lm(e.kind,e.operands.slice(0,t))),wm(lm(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return sm(e.kind,wm(e.body));default:return e}},Tm=(e,t)=>{e.kind===`Eventually`&&!gm(t,e)&&t.push(e),`body`in e&&Tm(e.body,t),`operands`in e&&e.operands.forEach(e=>Tm(e,t))},Em=e=>{let t=e.filter(om),n=e.flatMap(e=>e.kind===`Not`&&om(e.body)?[e.body]:[]);return!t.some(e=>gm(n,e))},Dm=e=>{let t=[...e],n=[];for(;t.length>0;){let e=t.pop();if(!e)break;switch(e.kind){case`Not`:t.push(e.body);break;case`Next`:n.push(e),t.push(e.body);break;case`Always`:case`Eventually`:n.push(e,sm(`Next`,e)),t.push(e.body);break;case`And`:case`Or`:t.push(...e.operands),n.push(e);break;case`Action`:throw new y(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},Om=(e,t,n)=>{if(e.kind===t&&`body`in e)return{first:e.body,second:sm(`Next`,e)};if(e.kind===n&&`operands`in e)return{first:e.operands[0],second:e.operands[1]}},km=(e,t,n)=>e.flatMap(e=>{let r=Om(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),Am=e=>[...new Set(e.map(mm))].sort().join(`|`),jm=(e,t)=>{let n=new Set(t.map(Am));return[...e.filter(e=>!n.has(Am(e))),...t]},Mm=e=>{let t=Dm(e),n=km(t,`Always`,`And`),r=km(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=Om(t,`Eventually`,`Or`);if(n&&!(gm(e,n.first)||gm(e,n.second)))return jm(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(gm(e,t.first)||gm(e,t.second))&&!gm(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!Em(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=Om(t[e],`Always`,`And`);n&&(gm(t,n.first)||t.push(n.first),gm(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)gm(t,e.first)&&gm(t,e.second)&&!gm(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!Em(t)?[]:i(t)};return a(e)},Nm=e=>({particle:e,successors:[],statePredicates:e.filter(e=>um(e)<=1)}),Pm=e=>{let t=Mm([e]).map(Nm),n=t.length,r=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let n=Am(e.particle);r.has(n)||r.set(n,t)});for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let i of Mm(n)){let n=Am(i),a=r.get(n);a===void 0&&(r.set(n,t.length),t.push(Nm(i))),t[e].successors.push(a??t.length-1)}}return{nodes:t,initialCount:n}},Fm=(e,t)=>!gm(e,t)||gm(e,t.body),Im=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&um(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=xm(e);if(n){let e=um(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(dm(e))throw new y(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},Lm=(e,t)=>{let n=e.findIndex(e=>hm(e,t));return n===-1?(e.push(t),e.length-1):n},Rm=e=>{let t=Sm(bm(vm(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=Cm(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])Im(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:lm(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:hm(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&wm(e.formula),n=[];t&&Tm(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>Lm(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>Lm(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>Lm(i,e))}));return{tableau:t&&Pm(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},zm=/* @__PURE__ */ new Set([`~>`,`-+->`]),Bm=/* @__PURE__ */ new WeakMap,Vm=/* @__PURE__ */ new WeakSet,Hm=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),Um=(t,r)=>{try{return Ys(t,r)}catch(t){if(!(t instanceof y)||t instanceof b)throw t;let r=o(t);throw r===void 0?n(new y(`${l}${t.message}`,t),e.error):n(t,r)}},Wm=e=>new y(`TLC cannot handle the temporal formula at ${So(e)}`),Gm=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=No(t,e);if(!r)return;if(r.kind===`Value`)return 0;if(r.kind===`Thunk`)return Gm(r.expression,r.scope,n);let i=r.operator;return i.kind===`Closure`?Gm(i.body,i.scope,n):0},a=e=>{if(n.variableIndex.has(e))return 1;if(n.constants.has(e))return 0;let t=Ro(e,n);if(t)return Km(t,n);let r=n.builtins.get(n.substitutions.get(e)??e);return r?+!!r.isStateLevel:void 0},o=(e,t)=>r.has(e)?0:X(t)?i(e)??a(e)??0:a(e)??i(e)??0,s=e=>{let i={value:0};return ea(e,(e,a)=>(i.value=Math.max(i.value,Gm(e,t,n,a.length===0?r:/* @__PURE__ */ new Set([...r,...a]))),e)),i.value};switch(e.kind){case`Prime`:case`Unchanged`:case`BoxAction`:case`AngleAction`:return 2;case`Enabled`:return 1;case`Always`:case`Eventually`:case`WeakFairness`:case`StrongFairness`:return 3;case`UnboundedQuantifier`:return e.isTemporal?3:s(e);case`Identifier`:return o(e.name,e);case`OperatorReference`:return o(e.operator,e);case`Apply`:return zm.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},Km=(e,t)=>{let n=Bm.get(e);if(n!==void 0)return n;Bm.set(e,0);let r=e.kind===`Function`?e.bounds:[],i=Math.max(Gm(e.body,void 0,t),...r.map(e=>Gm(e.set,void 0,t)));return Bm.set(e,i),i},qm=`Temporal formula is a tautology (its negation is unsatisfiable).`,Jm=(t,r,i,a,o=``,s=/* @__PURE__ */ new Set)=>{let c=(e,t,n=o,r=s)=>Jm(e,t,i,a,n,r);if(t.kind===`And`)return t.operands.flatMap(e=>c(e,r,Co(e)));if(t.kind===`Label`)return c(t.body,r);if(t.kind===`Let`)return c(t.body,Ym(t,r,i));if(t.kind===`Identifier`){let o=X(t)?No(r,t.name):void 0;if(o?.kind===`Thunk`)return c(o.expression,o.scope);let l=i.constants.has(t.name)?void 0:Ro(t.name,i);if(!o&&l?.kind===`Operator`&&l.params.length===0&&Km(l,i)>0){if(s.has(l))throw n(new y(u),e.error);let r=c(l.body,void 0,t.name,/* @__PURE__ */ new Set([...s,l]));return!a&&Km(l,i)<2?[{expression:l.body,scope:void 0,name:t.name}]:r}}let l=Hm(i,r);if(t.kind===`Apply`&&(e=>a||Gm(e,r,i)===3)(t)){let e=is(t,l),n=X(t)?void 0:Ro(t.operator,i);if(e?.kind===`Closure`&&e.params.length===t.args.length&&!n?.isRecursive)return c(e.body,gs(e,t.args,l),t.operator)}if(a&&t.kind===`Forall`&&t.bounds.every(e=>Gm(e.set,r,i)===0)){let r=[],i={count:0};if(Uo(t.bounds,l,e=>(i.count++,r.push(...c(t.body,e,Co(t.body))),!1)),i.count===0)throw n(new y(qm),e.livenessEvaluationFailure);return r}return[{expression:t,scope:r,name:o}]},Ym=(e,t,n)=>{let r=vs(e.definitions,Hm(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&Vm.add(e.binding);return r},Xm=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),Zm=(t,r,i)=>{let a=(e,t,n)=>{let r=n===0?Gm(e,t,i):n;if(r===0){let n=Um(e,Hm(i,t));if(typeof n!=`boolean`)throw new y(`TLC expected a boolean in the temporal formula at ${So(e)}`);return im(n)}return r===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},o={depth:0},s=(t,r,i,s)=>{if(o.depth>=100)throw n(new y(u),e.error);o.depth++;let c=f(t,r);o.depth--;let l=um(c);return l>2?c:a(i,s,l)},c=(e,t)=>{let n=e.kind===`Identifier`?e.name:e.operator,r=Hm(i,t),a=X(e)||Ro(n,i)===void 0?No(t,n):void 0;if(a?.kind===`Thunk`&&Vm.has(a))return s(a.expression,a.scope,e,t);let o=a?.kind===`Operator`?a.operator:a?void 0:X(e)?as(n,r):ns(n,i);if(o?.kind!==`Closure`)throw Wm(e);let c=e.kind===`Apply`?e.args:[];return s(o.body,gs(o,c,r),e,t)},l=(e,t)=>{if(!e.bounds.every(e=>Gm(e.set,t,i)===0))throw Wm(e);let n=[];Uo(e.bounds,Hm(i,t),t=>(n.push(f(e.body,t)),!1));let r=e.kind===`Forall`;if(n.length===0)return im(r);let o=lm(r?`And`:`Or`,n),s=um(o);return s>2?o:a(e,t,s)},d=(e,t)=>{switch(e.kind){case`Label`:f(e.body,t);return;case`Let`:f(e.body,Ym(e,t,i));return;case`And`:case`Or`:for(let n of e.operands)f(n,t);return;case`Apply`:if(e.operator===`=>`||e.operator===`~`&&!X(e))for(let n of e.args)f(n,t);return;case`If`:{let n=f(e.condition,t),r=n.kind===`Boolean`?[n.value?e.consequent:e.alternative]:[e.consequent,e.alternative];for(let e of r)f(e,t)}}},f=(e,t)=>{let n=Gm(e,t,i);if(n<=2)return d(e,t),a(e,t,n);switch(e.kind){case`Label`:return f(e.body,t);case`Let`:return f(e.body,Ym(e,t,i));case`Identifier`:return c(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?sm(`Always`,cm(`Or`,sm(`Not`,f(n[0],t)),sm(`Eventually`,f(n[1],t)))):e.operator===`~`&&!X(e)?sm(`Not`,f(n[0],t)):e.operator===`=>`?cm(`Or`,sm(`Not`,f(n[0],t)),f(n[1],t)):c(e,t)}case`And`:case`Or`:return lm(e.kind,e.operands.map(e=>f(e,t)));case`Forall`:case`Exists`:return l(e,t);case`If`:{if(Gm(e.condition,t,i)===0){let n=Um(e.condition,Hm(i,t));if(typeof n==`boolean`)return f(n?e.consequent:e.alternative,t)}let n=f(e.condition,t);return cm(`Or`,cm(`And`,n,f(e.consequent,t)),cm(`And`,sm(`Not`,n),f(e.alternative,t)))}case`Always`:case`Eventually`:return sm(e.kind,f(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=Xm(e.action,e.subscript),r={kind:`Enabled`,step:e.enabled??n,scope:t},i=sm(`Not`,r),a={kind:`Action`,expression:e.action,unchanged:{kind:`Unchanged`,expression:e.subscript,location:n.location},scope:t,enabled:r};return e.kind===`WeakFairness`?sm(`Always`,sm(`Eventually`,cm(`Or`,i,a))):cm(`Or`,sm(`Eventually`,sm(`Always`,i)),sm(`Always`,sm(`Eventually`,a)))}default:throw Wm(e)}};return f(t,r)},Qm=(e,t,n,r,i)=>{let a=e=>Qm(e,t,n,r,i);switch(e.kind){case`Boolean`:return e.value;case`State`:case`Enabled`:{let n=i.get(e);if(n!==void 0)return n;let a={environment:r,scope:e.scope,state:t,next:void 0},o=e.kind===`State`?Lo(Ys(e.expression,a),`a temporal property predicate`):_o(e.step,a);return i.set(e,o),o}case`Action`:{if(e.enabled&&i.get(e.enabled)===!1)return!1;let a={environment:r,scope:e.scope,state:t,next:n};return e.unchanged&&Lo(Ys(e.unchanged,a),`a subscript`)?!1:Lo(Ys(e.expression,a),`an action predicate`)}case`Not`:return!a(e.body);case`And`:return e.operands.every(a);case`Or`:return e.operands.some(a);case`Next`:return Qm(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new y(`TLC cannot evaluate a temporal formula in a single step`)}},$m=(e,t,n,r,i)=>{let a=e=>e+1<t.length?e+1:n,o=e=>t.map((e,t)=>t).filter(t=>t>=Math.min(e,n)),s=(e,a=r)=>$m(e,t,n,a,i);switch(e.kind){case`Not`:return!s(e.body);case`And`:return e.operands.every(e=>s(e));case`Or`:return e.operands.some(e=>s(e));case`Next`:return s(e.body,a(r));case`Always`:return o(r).every(t=>s(e.body,t));case`Eventually`:return o(r).some(t=>s(e.body,t));default:return Qm(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},eh=(e,t)=>e.every((e,n)=>tt(e,t[n])),th=e=>e.filter((t,n)=>n===0||e[n-1]!==t),nh=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.pending.push(void 0),e.offsets.push(-1),e.edgeOffsets.push(-1),e.nodeStates.length-1),rh=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},ih=(e,t)=>(e.offsets[t]??-1)!==-1,ah=(e,t)=>e.pending[t]??=[],oh=(e,t)=>{let n=e.edgeOffsets[t];return e.edges.ids.subarray(n+1,n+1+e.edges.ids[n])},sh=(e,t,n)=>e.results.bytes[e.offsets[t]+n]===1,ch=2**53-1,lh=(t,r,i,a)=>{if(t.length===0)return;let o=r.map(e=>Zm(e.expression,e.scope,i)),s=t.map(e=>sm(`Not`,Zm(e.expression,e.scope,i))),c=s.length===1?s[0]:lm(`Or`,s),l=o.length===0?c:lm(`And`,[...o,c]),u=Rm(l);if(u.length===0)throw n(new y(qm),e.livenessEvaluationFailure);let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=mm(e),n=d.get(t)??d.size;return d.set(t,n),n}),nodeStates:[],nodeTableaux:[],pending:[],offsets:[],results:{bytes:/* @__PURE__ */ new Uint8Array(1024),length:0},edgeOffsets:[],edges:{ids:/* @__PURE__ */ new Int32Array(1024),length:0},initial:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!As(i),h={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},g=e=>{let t=h.states.get(e)??/* @__PURE__ */ new Map;return h.states.set(e,t),t},_=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},v=(e,t)=>Qm(e,t,void 0,i,m?g(t):/* @__PURE__ */ new Map),b=(e,t,n)=>_(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!v(e,n))),ee=(e,t,n,r)=>_(t,()=>{let t=e.solution.actionChecks;if(!m)return Uint8Array.from(t,e=>+!!Qm(e,n,r,i,/* @__PURE__ */ new Map));let a=g(n),o=h.actions.get(n)??/* @__PURE__ */ new Map;h.actions.set(n,o);let s=o.get(r)??new Int8Array(d.size).fill(-1);return o.set(r,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!Qm(t[o],n,r,i,a)),s[e]))}),x=(e,t,n,r)=>_(n,()=>e.nodes[t].statePredicates.every(e=>v(e,r))),S=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},C=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),w=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=rh(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},T=(e,t,n)=>{let r=nh(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),rh(i,e[t]-1,e[t+1]))}return i.slots.set([t+1,n,r],rh(i,t,n)),r},te=(e,t,n)=>t.nodes.flatMap((t,r)=>w(e,n,r)??[]).sort((e,t)=>e-t),ne=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=e.results,o=a.length;if(a.length+=r.length+n.length*i,a.length>a.bytes.length){let e=new Uint8Array(Math.max(2*a.bytes.length,a.length));e.set(a.bytes),a.bytes=e}a.bytes.set(r,o),n.forEach((e,t)=>a.bytes.set(e,o+r.length+t*i)),e.offsets[t]=o;let s=e.pending[t]??[],c=e.edges,l=c.length;if(c.length+=s.length+1,c.length>c.ids.length){let e=new Int32Array(Math.max(2*c.ids.length,c.length));e.set(c.ids),c.ids=e}c.ids[l]=s.length,c.ids.set(s,l+1),e.edgeOffsets[t]=l,e.pending[t]=void 0},E=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t.index)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&eh(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},D=(e,t,n,r,i)=>{let o=b(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=ah(e,i),u=s.successors.length>0?ee(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!x(t,a,r,n))continue;if(S(t,a)&&e.errorNode===void 0&&C(e)){e.errorNode=i;return}let o=w(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??T(e,r,a);l.push(s),c.push(u),o===void 0&&D(e,t,n,r,s)}for(let i of a.getSuccessors(n)){let a=ee(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!x(t,n,r,i.state))continue;let s=w(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??T(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&D(e,t,i.state,i.index,u)}}l.length>0&&ne(e,i,c,o)},O=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>x(t,r,a,e.state)));e.isDone[a]=!0;for(let s of te(e,t,a)){let a=ah(e,s),c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=w(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??T(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&D(e,t,n.state,n.index,d)}}),ne(e,s,c,i)}if(e.errorNode!==void 0)return th(A(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},k=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)nh(e,e.nodeStates.length,-1);let a=ah(e,i),o=[];t.forEach((t,r)=>{ih(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),ne(e,i,o,r)},A=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)ih(e,t)&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of oh(e,a))if(!(i===a&&e.solution.tableau)){if(i===t){let e=[t];for(let t=a;t!==-1;t=n.get(t)??-1)e.push(t);return e}ih(e,i)&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new y(`Couldn't re-create liveness trace (path) starting at: ${t}`)},j=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=n.stateChecks.length,a=(t,n,a)=>e.results.bytes[e.offsets[t]+i+n*r+a]===1,o=(e,n)=>t.eventuallyAlways.every(t=>a(e,n,t)),s=new Float64Array(e.nodeStates.length).fill(-1),c=e.initial.filter(t=>ih(e,t)),l=[],u=t=>{let n=oh(e,t).indexOf(t);return n!==-1&&o(t,n)},d=(t,r)=>n.tableau!==void 0&&Fm(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let i=l.pop()??r;if(i===r&&!u(i)){s[i]=ch;return}let c=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=i;;t=l.pop()??r){c.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),s[t]=ch,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...c].some(n=>sh(e,n,t))),h=t.infinitelyOftenActions.every(t=>[...c].some(n=>oh(e,n).some((e,r)=>c.has(e)&&o(n,r)&&a(n,r,t)))),g=n.promises.every(e=>[...c].some(t=>d(t,e)));if(m&&h&&g)return p(r,c,f)},p=(r,i,s)=>{let c=th(A(e,r).reverse().map(t=>e.nodeStates[t])),l=[],u=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),p=t.infinitelyOftenActions.map(()=>!1),h=n.promises.map(()=>!1),g={count:f.length+p.length+h.length},_={node:r},v=e=>i.has(e),b=e=>{l.push(_.node),_.node=e};for(;g.count>0;){let r=g.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&sh(e,_.node,t)&&(f[n]=!0,g.count--)}),n.promises.forEach((e,t)=>{!h[t]&&d(_.node,e)&&(h[t]=!0,g.count--)}),!(g.count<=0);){let n={last:-1,unvisited:-1},i=g.count;if(oh(e,_.node).some((r,c)=>{if(s.has(e.nodeStates[r])){if(!v(r)||!o(_.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!p[t]&&a(_.node,c,e)&&(p[t]=!0,g.count--)})}return g.count<i?(b(r),u.clear(),!0):(v(r)&&!u.has(r)&&(n.unvisited=r),!1)}))break;if(g.count<r){b(n.last),u.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new y(`TLC failed to build the counterexample of a liveness property`);_.node=t,n.unvisited=oh(e,t).find(e=>v(e)&&!u.has(e))??-1}b(n.unvisited),u.add(n.unvisited)}}let ee=m(r,_.node,s,o);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];ee[ee.length-1]!==n&&ee.push(n)}let x=c[c.length-1];return ee[ee.length-1]===x&&ee.pop(),{prefix:c.slice(0,-1),cycle:[x,...ee.reverse()]}},m=(t,n,r,i)=>{if(n===t)return[];let a=e.nodeStates[n],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set([a]),c=[];for(let n=a,l=-1,u=0;;u++){for(let u of r.get(n)??[])for(let[d,f]of oh(e,u).entries()){if(f===u||!i(u,d))continue;if(f===t){let e=[];for(let t=n,r=l;t!==a;)e.push(t),t=r,r=o.get(t)??-1;return e.push(a),e}let p=e.nodeStates[f];r.has(p)&&!s.has(p)&&(s.add(p),c.push([p,n]))}o.set(n,l);let d=c[u];if(d===void 0)throw new y(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<c.length;t++){let n=[c[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),a=n.pop()??0;if(i===-42){if(s[a]===t){let e=f(a);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(s[a]!==-1){n.push(Math.min(t,s[a]));continue}s[a]=r.link,n.push(t,a,-42),l.push(a);let u={value:r.link++};oh(e,a).forEach((t,r)=>{ih(e,t)&&(o(a,r)?s[t]===-1?n.push(t,-1):u.value=Math.min(u.value,s[t]):s[t]===-1&&c.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{h.states.clear(),h.actions.clear();for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)x(r,i,void 0,t)&&n.initial.push(w(n,e,i)??T(n,e,i))}},addState:(e,t,n)=>{h.states.clear(),h.actions.clear();let r=E(e,t,n);for(let n of f){let i=r.map(r=>ee(n,e,t,r.state)),a=b(n,e,t),o=n.solution.tableau,s=o?O(n,o,r,i,a,e):k(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=j(e,t);if(n)return n}},getViolatedProperties:(e,n)=>[...new Set(t.filter((t,r)=>!$m(s[r].body,e,n,0,i)).map(e=>e.name))]}},uh=`UnnamedAction`,dh={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},fh=e=>{let t=e.range??dh;return Ut([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},ph=e=>{let t=[[`name`,e.name],[`location`,fh(e.location)]];return e.parameters.length===0?Ut(t):Ut([...t,[`context`,Ut(e.parameters)],[`parameters`,Ht(e.parameters.map(e=>e[0]))]])},mh=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),hh=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),gh=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,_h=e=>e.kind===`Apply`?e.args:[],vh=(e,t,n)=>{let r=gh(e);if(r===void 0)return;if(X(e)){let e=No(t,r);return e?.kind===`Operator`&&e.operator.kind===`Closure`?e.operator:void 0}if(n.constants.has(r)||n.variableIndex.has(r))return;let i=ns(r,n);return i?.kind===`Closure`?i:void 0},yh=(e,t)=>{try{return Ys(e,hh(t,void 0)),!0}catch(e){if(e instanceof f)return!1;throw e}},bh=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&Bo(e,t)&&yh(e.body,t),xh=(e,t)=>{let n=Ro(e.name,t);return n?.body===e.body&&bh(n,t)},Sh=(e,t)=>{if(e.kind!==`Identifier`||!X(e))return;let n=No(t,e.name);return n?.kind===`Thunk`?n:void 0},Ch=(e,t)=>(e?.params??[]).flatMap(e=>{let n=No(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),wh=(e,t)=>{try{return e()}catch(e){if(e instanceof f)return t();throw e}},Th=(e,t,n,r,i)=>{let a=_h(t),o=()=>[{name:e.name,location:t.location,parameters:[],expression:t,scope:n}];return!r||a.length===0?[{...e,parameters:[],expression:t,scope:n}]:a.some(e=>Gm(e,n,i)!==0)?o():wh(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),Ys(e,hh(i,n))]),expression:t,scope:n}],o)},Eh=(e,t,n,r,i)=>{let a=()=>({name:n?.name??uh,location:e.location,parameters:Ch(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return Eh(e.body,vs(e.definitions,hh(r,t)),n,r,i);case`Label`:return Eh(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>Eh(e,t,n,r,i));case`Exists`:return wh(()=>{let o=[];return Uo(e.bounds,hh(r,t),t=>(o.push(...Eh(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=X(e)?void 0:i.get(gh(e)??``),s=vh(e,t,r);if(o)return Th(o,e,t,s,r);if(!s)return[a()];let c=_h(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return xh(s,r)||c.some(e=>Gm(e,t,r)!==0)?l():wh(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:Ys(n,hh(r,t))},parent:e}),s.scope);return Eh(s.body,e,s,r,i)},l)},Dh=(e,t,n,r,i)=>{let a=(e,t)=>Dh(e,t,n,r,i);if(e.kind===`Let`){a(e.body,vs(e.definitions,hh(n,t)));return}let o=Sh(e,t);if(o){a(o.expression,o.scope);return}let s=vh(e,t,n);if(s&&xh(s,n))return;if(s&&s.params.length===0){if(Gm(s.body,s.scope,n)===1){r.inits.push(mh(s.name,s.body));return}a(s.body,s.scope);return}if(s&&e.kind===`Apply`&&s.params.length===e.args.length){a(s.body,gs(s,e.args,hh(n,t)));return}if(e.kind===`And`){e.operands.forEach(e=>a(e,t));return}if(e.kind===`Always`){if(e.expression.kind===`BoxAction`){i.push({expression:e.expression.action,scope:t});return}r.temporals.push(mh(uh,e));return}let c=Gm(e,t,n);c<=1?r.inits.push(mh(uh,e)):c===3&&r.temporals.push(mh(uh,e))},Oh=(e,t,n,r,i)=>{let a=(t,n)=>Oh(e,t,n,r,i);if(t.kind===`Let`){a(t.body,vs(t.definitions,hh(r,n)));return}let o=Sh(t,n);if(o){a(o.expression,o.scope);return}let s=vh(t,n,r);if(s&&xh(s,r))return;if(s&&s.params.length===_h(t).length){a(s.body,t.kind===`Apply`?gs(s,t.args,hh(r,n)):s.scope);return}if(t.kind===`Forall`&&wh(()=>(Uo(t.bounds,hh(r,n),e=>(a(t.body,e),!1)),!0),()=>!1))return;if(t.kind===`And`){t.operands.forEach(e=>a(e,n));return}if(t.kind===`Always`){let a=t.expression;a.kind===`BoxAction`?i.impliedActions.push(mh(e,a)):Gm(a,n,r)<2?i.invariants.push(mh(e,a)):i.impliedTemporals.push(mh(e,t));return}let c=Gm(t,n,r);c<=1?i.impliedInits.push(mh(e,t)):c===3&&i.impliedTemporals.push(mh(e,t))},kh=(e,t)=>{let n=Ro(e,t);return n?.kind===`Operator`&&!bh(n,t)?n:void 0},Ah=e=>Ut([[`name`,e.name],[`location`,fh(e.location)]]),jh=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:kh(e.specification,t);a&&(Dh(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...Eh(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:ns(e.init,t);o?.kind===`Closure`&&r.inits.push(mh(e.init??``,o.body));let s=e.next===void 0?void 0:ns(e.next,t);return s?.kind===`Closure`&&r.actions.push(...Eh(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=kh(e,t);n&&r.invariants.push(mh(e,n.body))}),e.properties.forEach(e=>{let n=kh(e,t);n&&Oh(e,n.body,void 0,t,r)}),r},Mh=(e,t,n)=>jh(e,t,n).actions,Nh=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>Y(e[1])).join(`,`)})`,Ph=e=>`${e.name===uh?`Action`:e.name}${Nh(e)} ${g(e.location.range??dh)}`,Fh=e=>`${e.name}${Nh(e)}`,Ih=(e,t,n,r)=>{let i=jh(e,t,r),a=e=>Et(e.map(ph)),o=e=>Et(e.flatMap(e=>{let n=kh(e,t);return n?[Ah(n)]:[]}));return Ut([[`inits`,a(i.inits)],[`actions`,a(i.actions)],[`temporals`,a(i.temporals)],[`invariants`,a(i.invariants)],[`impliedinits`,a(i.impliedInits)],[`impliedactions`,a(i.impliedActions)],[`impliedtemporals`,a(i.impliedTemporals)],[`variables`,Et(t.variables.map((e,t)=>Ut([[`name`,e],[`location`,fh(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},Lh=`paired12`,Rh=(e,t=16)=>e<=t*.75?t:Rh(e,t*2),zh=(e,t)=>{let n=Rh(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Bh=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Vh=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Hh=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Uh=e=>Hh(e).replaceAll(`
|
|
427
|
+
`,`\\n`),Wh=(e,t)=>{let n=[],r=e=>n.push(`State ${n.length+1}:\n${e.getText()}\n`);return{writeInitialState:r,writeSuccessor:(e,t,n)=>{n||r(t)},close:()=>t?.(e.path,n.join(``))}},Gh=(e,t)=>{let n=[`strict digraph DiskGraph {
|
|
421
428
|
`,`node [shape=box,style=rounded]
|
|
422
|
-
`,e.colorize?`edge [colorscheme="${
|
|
429
|
+
`,e.colorize?`edge [colorscheme="${Lh}"]\n`:``,`nodesep=0.35;
|
|
423
430
|
`,`subgraph cluster_graph {
|
|
424
431
|
`,`color="white";
|
|
425
432
|
`],r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=e=>{let t=r.get(e.level)??/* @__PURE__ */ new Set;r.set(e.level,t.add(e.fingerprint))},o=e=>{if(!e)return 1;let t=i.get(e.name)??i.size+2;return i.set(e.name,t),t},s=()=>[`subgraph cluster_legend {graph[style=bold];label = "Next State Actions" style="solid"
|
|
426
|
-
`,`node [ labeljust="l",colorscheme="${
|
|
427
|
-
`,e.colorize&&i.size>1?s():``,`}`].join(``),l=()=>{e.snapshot&&t?.(e.path.replaceAll(`.dot`,`_snapshot.dot`),n.join(``)+c())};return{writeInitialState:e=>{n.push(`${e.fingerprint} [label="${
|
|
433
|
+
`,`node [ labeljust="l",colorscheme="${Lh}",style=filled,shape=record ]\n`,...zh([...i.keys()],Vh).map(e=>`${e.replaceAll(`!`,`:`)} [label="${e}",fillcolor=${i.get(e)}]\n`),`}`].join(``),c=()=>[...zh([...r],e=>e[0]).map(e=>`{rank = same; ${zh([...e[1]],Bh).map(e=>`${e};`).join(``)}}\n`),`}
|
|
434
|
+
`,e.colorize&&i.size>1?s():``,`}`].join(``),l=()=>{e.snapshot&&t?.(e.path.replaceAll(`.dot`,`_snapshot.dot`),n.join(``)+c())};return{writeInitialState:e=>{n.push(`${e.fingerprint} [label="${Uh(e.getLabel())}",style = filled]\n`),a(e),l()},writeSuccessor:(t,r,i,s)=>{let c=e.colorize?String(o(s)):`black`,u=e.actionLabels&&s?Hh(s.signature):``;n.push(`${t.fingerprint} -> ${r.fingerprint} [label="${u}",color="${c}",fontcolor="${c}"];\n`),i||n.push(`${r.fingerprint} [label="${Uh(r.getLabel())}",tooltip="${Uh(r.getText())}"];\n`),a(t),l()},close:()=>t?.(e.path,n.join(``)+c())}},Kh=(e,t)=>e.dot?Gh(e,t):Wh(e,t),qh=e=>[...e].map(([e,t])=>`${e}>${t.name}`).sort().join(`,`),Jh=(e,t)=>{let n=/* @__PURE__ */ new Map;return(/* @__PURE__ */ new Set([...e.keys(),...t.keys()])).forEach(r=>{let i=e.get(r),a=i?t.get(i.name)??i:t.get(r);a&&a.name!==r&&n.set(r,a)}),n},Yh=t=>n(new y(`${l}${t}`),e.error),Xh=e=>{if(!Me(e))throw Yh(`The symmetry values must be function records.`);let t=bn(e),n=/* @__PURE__ */ new Map;return t.domain.forEach((e,r)=>{let i=t.range[r];if(!F(e)||!F(i))throw new v(`Symmetry function must have model values as domain and range`);e.name!==i.name&&n.set(e.name,i)}),n},Zh=(e,t)=>{let n=t.definitions.get(e);if(n===void 0&&!t.constants.has(e))throw new v(`The symmetry function ${e} specified in the configuration file\nis not defined in the specification.`);if(n?.kind!==`Operator`||n.params.length>0)throw Yh(`The symmetry function ${e} must specify a set of permutations.`);let r=Ys(n.body,{environment:t,scope:void 0,state:void 0,next:void 0});if(!Ae(r)||!Jt(r))throw Yh(`The symmetry operator must specify a set of functions.`);let i=q(r).elements.map(Xh);if(n.body.kind===`Apply`&&n.body.args.length>=i.length)return[];let a=/* @__PURE__ */ new Map;i.forEach(e=>{e.size>0&&a.set(qh(e),e)});let o=[...a.values()],s={start:0};for(;s.start<a.size;){let e=[...a.values()],t=e.length;o.forEach(n=>e.slice(s.start,t).forEach(e=>{let t=Jh(n,e),r=qh(t);t.size>0&&!a.has(r)&&a.set(r,t)})),s.start=t}let c=Math.max(256,Math.floor(4194304/a.size));return[...a.values()].map(e=>({images:e,cache:/* @__PURE__ */ new WeakMap,cacheSize:0,cacheLimit:c}))},Qh=(e,t)=>{for(let n=0;n<e.length;n++){let r=e[n],i=tg(r,t);if(i===r)continue;let a=e.slice(0,n);a.push(i);for(let r=n+1;r<e.length;r++)a.push(tg(e[r],t));return a}},$h=(e,t)=>{let n=[],r=[];for(let i of e){let e=tg(i,t);e===i?n.push(i):r.push(e)}if(r.length===0)return;r.sort(Je);let i=[],a=0,o=0;for(;a<n.length&&o<r.length;)i.push(Je(n[a],r[o])<0?n[a++]:r[o++]);for(;a<n.length;)i.push(n[a++]);for(;o<r.length;)i.push(r[o++]);return i},eg=e=>e.kind===`Set`?e.elements.length:e.kind===`Function`?e.domain.length:0,tg=(e,t)=>{if(typeof e!=`object`)return e;if(e.kind===`ModelValue`)return t.images.get(e.name)??e;let n=eg(e);if(n===0||n>64)return ng(e,t);let r=t.cache.get(e);if(r!==void 0)return r;let i=ng(e,t),a=i!==e&&tt(i,e)?e:i;return t.cacheSize>=t.cacheLimit&&(t.cache=/* @__PURE__ */ new WeakMap,t.cacheSize=0),t.cache.set(e,a),t.cacheSize++,a},ng=(e,t)=>{let n=e.kind;if(n===`Set`){let n=$h(e.elements,t);return n?Ze(n):e}if(n===`Function`||n===`LazyFunction`&&Jt(e.domain)){let n=bn(e),r=Qh(n.domain,t),i=Qh(n.range,t)??n.range;if(r){let e=Mt(r.map((e,t)=>[e,i[t]]));return e.domain.every((e,t)=>e===n.domain[t])?Qe(n.domain,e.range):e}return i===n.range?n:Qe(n.domain,i)}if(n===`Interval`||!Ae(e)||!Jt(e))return e;let r=q(e),i=Qh(r.elements,t);return i?Et(i):r},rg=(e,t,n)=>{for(let r=t.length;r<e.length;r++)t.push(tg(e[r],n));return t},ig=(e,t,n,r)=>{let i=[];for(let a=0;a<e.length;a++){let o=r?r[a]:a,s=tg(e[o],n),c=Je(s,t[o]);if(c>0)return;if(r||i.push(s),c<0)return r?e.map(e=>tg(e,n)):rg(e,i,n)}},ag=(e,t,n)=>t.reduce((t,r)=>ig(e,t,r,n)??t,e),og=(e,t)=>e*((t-e)/2**64),sg=e=>e.includes(`.`)?e:`${e}.0`,cg=e=>{let t=Math.abs(e);if(t>=.001&&t<1e7)return sg(String(e));let[n,r]=e.toExponential().split(`e`);return`${sg(n)}E${r.replace(`+`,``)}`},lg=e=>e!==void 0&&e>=`0`&&e<=`9`,ug=e=>{if(e===0)return`0.0`;let t=cg(e),n={next:0,digits:0,result:``};for(;t[n.next]===`0`;)n.next++;for(;lg(t[n.next]);)n.result+=t[n.next++],n.digits++;if(n.next===t.length)return n.result;if(t[n.next]!==`.`)return t;if(n.next++,n.digits>=2)for(;lg(t[n.next]);)n.next++;else{if(n.result+=`.`,n.digits===0)for(;t[n.next]===`0`;)n.result+=t[n.next++];for(;lg(t[n.next])&&n.digits<2;)n.result+=t[n.next++],n.digits++;for(lg(t[n.next])&&Number(t[n.next])>=5&&(n.result=dg(n.result));lg(t[n.next]);)n.next++}return n.next>=t.length?n.result:t[n.next]===`E`?`${n.result}${t.slice(n.next)}`:t},dg=e=>{let t=e.length-1;if(t<0)return`1`;let n=e[t],r=e.slice(0,t);return n===`.`?`${dg(r)}.`:n===`9`?`${dg(r)}0`:`${r}${Number(n)+1}`},fg=e=>{let t={value:0};for(;10n**BigInt(t.value+1)<e*10n;)t.value++;let n=10n**BigInt(t.value+1),r=n/e,i=n%e*2n>=e;return Number(`${r+(i?1n:0n)}e-${t.value+1}`)},pg=(e,t,n)=>{if(og(e,t)<1e-10)return;let r=n().sort(),i=new Int32Array(r.buffer),a={narrow:1/0,wide:9223372036854775807n};for(let e=1;e<r.length;e++){let t=i[2*e+1],n=i[2*e-1];if(t<0!=n<0)continue;let o=t-n;if(o<=1048576){let t=o*4294967296+(i[2*e]>>>0)-(i[2*e-2]>>>0);a.narrow=Math.min(a.narrow,t)}else{let t=r[e]-r[e-1];t<a.wide&&(a.wide=t)}}if(a.narrow===1/0)return a.wide;let o=BigInt(a.narrow);return o<a.wide?o:a.wide},mg=e=>{let t=e.reduce((e,t)=>e+t,0);if(t===0)return;let n=e.flatMap((e,t)=>e>0?[t]:[]),r=e.reduce((e,t,n)=>e+t*n,0),i=Math.floor(t*.95),a={count:0},o=n.find(t=>(a.count+=e[t],a.count>i));return`The average outdegree of the complete state graph is ${Math.round(r/t)} (minimum is ${n[0]}, the maximum ${n[n.length-1]} and the 95th percentile is ${o}).`},hg={line:0,column:0},gg=`Failed to recover the initial state from its fingerprint.`,_g=`Failed to recover the next state from its fingerprint.`,vg=e=>({kind:`Identifier`,name:e,location:hg}),yg=/* @__PURE__ */ new Set([`name`,`property`]),bg=(e,t,n)=>{let r=Ro(t,n);if(!r)throw new v(`The ${e} ${t} specified in the configuration file\nis not defined in the specification.`);if(r.kind===`Operator`&&r.params.length>0)throw new v(yg.has(e)?`TLC requires ${t} not to take any argument.`:`TLC requires ${e} not to take any argument, but one was given: ${t}`);return r},xg=(e,t,n)=>{let r=bg(e,t,n);if(Bo(r,n))throw new v(`The ${e} ${t} cannot be a constant.`);return r},Sg=(e,t,n)=>{if(Bo(t,n)&&t.body.kind!==`Number`&&t.body.kind!==`String`)try{return Ys(vg(e),Vg(n,void 0,void 0))}catch(e){if(e instanceof y||d(e))return;throw e}},Cg=(e,t,n)=>{let r=bg(e,t,n),i=Sg(t,r,n);if(i!==void 0&&i!==!0)throw new v(`The ${e} of ${t} is equal to ${Y(i)}`);return i===void 0?r:void 0},wg=(t,r)=>{let i=Sp({constants:new Set(r.constants.keys()),variables:new Set(r.variables),getDefinition:e=>Ro(e,r)});return t.flatMap(t=>{let a=Cg(`invariant`,t,r);if(!a)return[];let o=i.analyzeDefinition(a,/* @__PURE__ */ new Map);if(o.level>=2){let r=o.params.size===0?``:`
|
|
428
435
|
Note that a bug can cause TLC to incorrectly report this error.
|
|
429
436
|
If you believe your TLA+ or PlusCal specification to be correct,
|
|
430
|
-
please check if this bug described in LevelNode.java starting at line 590ff affects you.`;throw n(new _(`The invariant ${t} is not a state predicate (one with no primes or temporal operators).${r}`),e.safetyEvaluationFailure)}return[{name:t,expression:dh(t),scope:void 0}]})},vh=(e,t)=>{if(!P(e))return;let n=H(e);if(!n.domain.every(e=>typeof e==`string`))return;let r=n.domain.map((e,t)=>[String(e),n.range[t]]);return Object.fromEntries(r.sort((e,n)=>t.indexOf(e[0])-t.indexOf(n[0])))},yh=(e,t)=>{if(e.kind===`And`)return e.operands.flatMap(e=>yh(e,t));if(e.kind===`Identifier`&&!t.constants.has(e.name)){let n=jo(e.name,t);if(n?.kind===`Operator`&&n.params.length===0)return yh(n.body,t)}return[e]},bh=(e,t,n)=>{let r=e.expression;if(r.kind!==`Identifier`||$(r,e.scope,t)>0)return!1;let i=X(r,Ph(t,void 0,void 0,e.scope));if(i===!1)throw new _(`The spec is trivially false because ${r.name} is false.`);if(i!==!0)throw new _(`The operator ${r.name}, which equals ${U(i)},\ncannot be used as a ${n}`);return!0},xh=(t,r)=>{if(t.specification===void 0){let e=(e,t)=>{if(e===void 0)return;let n=ph(t,e,r).body,i=dh(e);if(n.kind!==`Number`&&n.kind!==`String`&&$(i,void 0,r)===0)throw new _(`The ${t} ${e} cannot be a constant.`);return i};return{init:e(t.init,`initial predicate`),next:e(t.next,`next state action`),scope:void 0,temporals:[]}}let i=[],a=[],o=[],s=ph(`name`,t.specification,r),c=hh(t.specification,s,r);if(c!==void 0)throw new _(`The value of ${t.specification} is equal to ${U(c)}`);if(Vp(s.body,void 0,r,!1).forEach(s=>{let c=s.expression;if(bh(s,r,`spec`))return;if(c.kind===`UnboundedQuantifier`&&c.isTemporal)throw n(new _(`TLC does not support temporal existential, nor universal, quantification over state variables.`),e.error);if(c.kind===`Always`&&c.expression.kind===`BoxAction`){a.push({expression:c.expression.action,scope:s.scope});return}if(c.kind===`Always`&&$(c.expression,s.scope,r)<2)throw n(new _(`TLC cannot handle the temporal formula ${go(c.expression)}`),e.error);let l=$(c,s.scope,r);if(l===3)o.push(s);else{if(l===2)throw new _(`TLC cannot handle the action-level conjunct of the specification ${t.specification}`);i.push(s)}}),a.length>1)throw new _(`The specification ${t.specification} must contain at most one [][Next]_vars`);let l=[...i,...a],u=e=>`$specification${e}`,d=l.reduce((e,t,n)=>t.scope===void 0?e:{name:u(n),binding:{kind:`Thunk`,expression:t.expression,scope:t.scope,state:void 0,next:void 0,cache:void 0},parent:e},void 0),f=(e,t)=>e.scope===void 0?e.expression:{kind:`Identifier`,name:u(t),location:e.expression.location,resolution:{kind:`Local`}};return{init:i.length===0?void 0:{kind:`And`,operands:i.map(f),location:ch},next:a.length===0?void 0:f(a[0],i.length),scope:d,temporals:o}},Sh=(e,t)=>{let n={initialPredicates:[],invariants:[],actionProperties:[],liveness:[]};return e.properties.forEach(e=>{let r=gh(`property`,e,t);r&&Vp(r.body,void 0,t,!0,e).forEach(r=>{let i=r.expression;if(bh(r,t,`property`))return;if(i.kind===`Always`&&i.expression.kind===`BoxAction`){n.actionProperties.push({name:r.name,box:i.expression,action:i.expression.action,subscript:i.expression.subscript,scope:r.scope});return}if(i.kind===`Always`&&$(i.expression,r.scope,t)<=1){let e=i.expression;n.invariants.push({name:e.kind===`Identifier`?e.name:r.name,expression:e,scope:r.scope});return}let a=$(i,r.scope,t);if(a<2)n.initialPredicates.push({name:r.name,expression:i,scope:r.scope});else{if(a===2)throw new _(`The property ${e} is an action-level formula`);n.liveness.push({name:e,expression:i,scope:r.scope})}})}),n},Ch=(e,t,n)=>t.flatMap(t=>gh(e,t,n)?[{name:t,expression:dh(t),scope:void 0}]:[]),wh=(e,t)=>{let n=jo(e,t);return n?.kind===`Operator`?n.bodyRange:void 0},Th=(e,t)=>e.map((n,r)=>{if(e.indexOf(n)!==r)throw new _(`_POSSIBLE lists ${n} more than once`);mh(`possible`,n,t);let i=dh(n);if($(i,void 0,t)===3)throw new _(`The possible of ${n} is equal to a temporal formula; only state- and action-level predicates are supported`);return{name:n,expression:i,scope:void 0}}),Eh=(e,t,n)=>{if(e.kind!==`Apply`||e.operator!==`\\in`||t?.length!==1)return;let r=e.args[0];if(!(r.kind!==`Identifier`||W(r)))return n.variableIndex.get(r.name)===t[0]?{variable:t[0],set:e.args[1]}:void 0},Dh=(e,t)=>e.flatMap(e=>yh(e.expression,t).map(n=>{let r=e.scope===void 0?pc(n,t):void 0;return{name:e.name,expression:n,scope:e.scope,variables:r,membership:Eh(n,r,t)}})),Oh=(e,t,n)=>{let r=e.variables;if(!n||!r)return!1;for(let e=0;e<r.length;e++)if(t[r[e]]!==n[r[e]])return!1;return!0},kh=/[\u0100-\uffff]/,Ah=/* @__PURE__ */ new Set([`JsonDeserialize`,`ndJsonDeserialize`]),jh=e=>e.kind===`String`?kh.test(e.value):e.kind===`Set`&&e.elements.some(jh),Mh=e=>e.kind===`String`&&kh.test(e.value)||e.kind===`Apply`&&Ah.has(e.operator)||ar(e).some(Mh),Nh=(e,t)=>e.constants.some(e=>jh(e.value)||(e.args??[]).some(jh))||[...t.definitions.values()].some(e=>Mh(e.body)||e.kind===`Function`&&e.bounds.some(e=>Mh(e.set))),Ph=(e,t,n,r)=>({environment:e,scope:r,state:t,next:n}),Fh=(e,t,n)=>Ao(X(e,t),n),Ih=(e,t,n=Lh)=>{let r=X(e,t);if(typeof r!=`boolean`)throw new v(n(e,t.environment));return r},Lh=(e,t)=>{let n=e.kind===`Identifier`?jo(e.name,t):void 0,r=n?.kind===`Operator`?n.body:e,i=n?.kind===`Operator`?n.bodyRange:void 0;return`TLC expected a boolean value, but did not find one. ${r.kind===`Number`?r.text??String(r.value):i?h(i):go(r)}`},Rh=()=>{},zh=(e,t,n)=>e.forEach(e=>{let r=t.possibleCounts.get(e.name)??0,i=Fh(e.expression,n,`_POSSIBLE ${e.name}`);t.possibleCounts.set(e.name,i?r+1:r)}),Bh=(e,t,n)=>{try{return Fh(e,Ph(t,void 0,void 0),n)?void 0:{message:void 0}}catch(e){if(e instanceof v)return{message:e.message};throw e}},Vh=(e,t)=>{for(let n of e.filter(e=>!e.isAxiom)){let e=Bh(n.expression,t,`an assumption`);if(e)return{name:go(n.expression),trace:[],message:e.message}}},Hh=(t,r,i)=>{let a=_h(t.invariants,r),o=xh(t,r),s=Sh(t,r),c=Dh([...a,...s.invariants],r),l=c.length>0||s.actionProperties.length>0||s.liveness.length>0;if(o.init===void 0&&(l||s.initialPredicates.length>0||r.variables.length>0))throw new _(`The configuration file did not specify the initial state predicate.`);if(o.next===void 0&&l)throw new _(`The configuration file did not specify the next state predicate.`);let u=Dh(Ch(`constraint`,t.constraints,r),r),d=Ch(`action constraint`,t.actionConstraints,r);t.rlReward!==void 0&&ph(`rlreward`,t.rlReward,r),t.periodic!==void 0&&ph(`periodic`,t.periodic,r);let f=Th(t.possible,r);if(r.variables.length===0)return;let p=t.symmetry===void 0?[]:Wm(t.symmetry,r);t.view!==void 0&&ph(`view function`,t.view,r);let m=t.view===void 0?void 0:{name:t.view,expression:dh(t.view),scope:void 0},g=s.actionProperties.map(e=>{let t={kind:`Unchanged`,expression:e.subscript,location:ch};return{...e,unchanged:t}}),v=e=>$(e.expression,void 0,r)>=2,y=f.filter(e=>!v(e)),b=f.filter(v),x=r.runtime,ee={indices:void 0},te=()=>{if(ee.indices)return ee.indices;let e=i(),t=t=>{let n=e.indexOf(r.variables[t]);return n===-1?r.variables.length:n};return ee.indices=r.variables.map((e,t)=>t).sort((e,n)=>t(e)-t(n)),ee.indices},ne=p.length>0?te():void 0,re=(e,t)=>X(e,Ph(r,t,void 0)),ie=e=>{let t=te(),n=p.length===0?e:Qm(e,p,t);return ul(m===void 0?t.map(e=>n[e]):[re(m.expression,n)])},S=Nh(t,r);x.getFingerprint=ie;let ae=()=>{let e=f.find(e=>!x.possibleCounts.get(e.name));if(!e)return;let t=wh(e.name,r),n=t?` at ${h(t)}`:``;return{name:e.name,message:`The _POSSIBLE predicate ${e.name}${n} was never witnessed.\nOthers may be unwitnessed too; only witnessed predicates appear with a\nnon-zero count in the record printed above.\nSee https://explain.tlapl.us/possible-conditions for additional details.`,counts:Ee(U(kl(x),!0))}};return{properties:s,spec:o,isSymmetric:p.length>0,getTlcOrder:te,getStoredFingerprints:(e,t)=>{if(m!==void 0||S)return BigInt64Array.from(e,ie);let n=new BigInt64Array(t.length),r=pl(te(),new Int32Array(n.buffer));return t.forEach(r),n},getFingerprintState:e=>{if(S)return[String(ie(e))];let t=p.length===0?e:Qm(e,p,ne);return m===void 0?t:[re(m.expression,t)]},findViolatedInvariant:(t,i)=>c.find(a=>{if(Oh(a,t,i))return!1;try{let e=Ph(r,t,void 0,a.scope),n=a.membership;return i&&n?!_n(t[n.variable],i[n.variable],X(n.set,e)):!Ih(a.expression,e)}catch(t){throw i?Kh(n(t,e.safetyEvaluationFailure),`Evaluating invariant ${a.name} failed.`):t}}),satisfiesConstraints:(e,t)=>u.every(n=>{try{return Oh(n,e,t)||Ih(n.expression,Ph(r,e,void 0))}catch(e){throw t?Wh(e):e}}),findFailedInitialPredicate:e=>s.initialPredicates.find(t=>!Ih(t.expression,Ph(r,e,void 0,t.scope))),findViolatedActionProperty:(e,t)=>g.find(n=>{try{return!Ih(n.action,Ph(r,e,t,n.scope),()=>`Attempted to evaluate an expression of form [A]_e, but A was not a boolean.\n${go(n.box)}`)&&!Fh(n.unchanged,Ph(r,e,t,n.scope),`a subscript`)}catch(e){throw Kh(Uh(e),`Evaluating action property ${n.name} failed.`)}}),satisfiesActionConstraints:(e,t)=>d.every(n=>{try{return Ih(n.expression,Ph(r,e,t))}catch(e){throw Wh(e)}}),trackStatePossible:y.length===0?Rh:e=>zh(y,x,Ph(r,e,void 0)),trackActionPossible:b.length===0?Rh:(e,t)=>zh(b,x,Ph(r,e,t)),findUnwitnessedPossible:ae,findPostconditionViolation:()=>{let e=ae();if(e)return e;for(let e of t.postconditions){let t=Bh(dh(e),r,`a postcondition`);if(t)return{name:e,message:t.message??`Postcondition ${e} is false.`}}}}},Uh=e=>e instanceof y?n(e,e.exitCode):e,Wh=e=>e instanceof v&&!(e instanceof y)&&!(e instanceof b)?n(new v(`${l}${e.message}`,e),re(e)):Uh(e),Gh=(e,t)=>{try{e();return}catch(e){return e instanceof v?t.flatMap(e=>{let t=e.location.range;return t?[`Line ${t.start.line}, column ${t.start.column} to line ${t.end.line}, column ${t.end.column} in ${t.module}`]:[]}).filter((e,t,n)=>t===0||n[t-1]!==e):[]}},Kh=(e,t)=>e instanceof v?n(new v(`${t}\n${e.message}`,e),re(e)):e,qh=t=>{let r=t.dump&&zm(t.dump,t.writeFile);try{return Jh(t,r)}catch(t){throw d(t)?n(new v(u),e.error):t}finally{r?.close()}},Jh=(t,r)=>{let i=typeof t.config==`string`?be(t.config):t.config,a=t.onPrint??console.log,o={isMuted:!1,replayed:void 0},s=e=>{o.replayed?o.replayed.push(e):o.isMuted||a(e)},l=e=>{o.isMuted=!0;let t=e();return o.isMuted=!1,t};Be(Bf(t.source,i,t.loadModule));let f=Xf(i,{source:t.source,loadModule:t.loadModule,loadClass:t.loadClass,print:s,files:{readFile:t.readFile,writeFile:t.writeFile},seed:t.seed}),p=f.environment,m=p.runtime;m.pause=t.onPause??(()=>{}),m.getSpecification=()=>km(i,p,f.variableLocations,f.instanceActions);let h={depth:0},g=(e,t,n)=>({status:e,violation:t&&{...t,loopStart:t.loopStart},failure:n,generatedStates:m.generatedStates,distinctStates:m.distinctStates,queuedStates:m.queueSize,depth:m.generatedStates===0?0:Math.max(h.depth,1),outDegrees:void 0,fingerprintDistance:void 0}),ee=Array.from({length:32},()=>0),te={newStates:0},ne=()=>Math.min(te.newStates,31),ie=()=>ee.map((e,t)=>t===ne()?e+1:e),S=()=>({...g(`success`),outDegrees:[...ee],fingerprintDistance:oh(m.distinctStates,m.generatedStates,()=>C?C.getStoredFingerprints(j,pe):BigInt64Array.from(j,m.getFingerprint))}),ae=()=>zf(t.source,t.loadModule,`variable`),C=Hh(i,p,ae),oe=Vh(f.assumptions,p);if(oe)return g(`assumption-violation`,oe);if(!C)return S();let w=i.postconditions.length>0||i.possible.length>0,T=(e,t,n)=>{if(w){let e=t.loopStart;m.counterExample=Mu(t.trace,e===void 0||!n?void 0:{start:e,action:n()})}let r=C.findUnwitnessedPossible();return r||C.findPostconditionViolation(),g(e,r?{...t,unwitnessed:r}:t)},E=C.spec,D=C.getFingerprintState,O={value:void 0},k=(e,t)=>{if(!e.failure)return e;let n=[],r={...p,evaluators:/* @__PURE__ */ new WeakMap,trace:n},a=Hh(i,r,ae);if(!a)return e;let s=[];o.replayed=s;let c=Gh(()=>t(a,r),n);return o.replayed=void 0,{...e,failure:{...e.failure,replay:{output:s,callStack:c}}}},se=e=>k(e,(e,t)=>{E.init!==void 0&&uo(E.init,t,t=>(e.satisfiesConstraints(t),e.findViolatedInvariant(t)!==void 0||e.findFailedInitialPredicate(t)!==void 0),E.scope)}),A=e=>{let t=me[e];t===-1?Te():(A(t),Ce(t,j[t],j[e]))},ce=(e,t)=>k(e,(e,n)=>{A(t);let r=j[t];O.value??=Tm(i,p,f.instanceActions),O.value.find(t=>mo(t.expression,r,n,t.scope).some(t=>!(e.satisfiesConstraints(t.state)&&e.satisfiesActionConstraints(r,t.state))&&e.findViolatedInvariant(t.state)!==void 0||e.findViolatedActionProperty(r,t.state)!==void 0))}),le=i.view!==void 0||i.symmetry!==void 0,ue=[],de=c(()=>nm(C.properties.liveness,E.temporals,p,{getFingerprint:e=>ue[e]??=Number(BigInt.asIntN(32,m.getFingerprint(j[e]))),getSuccessors:e=>{let t=[];return E.next===void 0||po(E.next,e,p,n=>{if(ve(n.state),!(C.satisfiesConstraints(n.state,e)&&C.satisfiesActionConstraints(e,n.state)))return!1;let r=D(n.state),i=Ne(Ae(r),r);return t.push({index:i,state:n.state}),!1},E.scope),t}})),fe=C.isSymmetric||de!==void 0,j=[],pe=[],me=[],he=[],ge=[],_e={slots:new Int32Array(1<<17),size:0,shift:16},ve=ir(),ye=e=>Object.fromEntries(C.getTlcOrder().map(t=>[p.variables[t],e[t]])),xe=(e,t,n,r)=>(m.getLevel=()=>n+1,m.getBehavior=()=>t.slice(0,n+1).map(e=>e.state),Se(e,t[n].state,(t[n+1]??t[r??n]).state)),Se=(e,t,n)=>{try{let r=mh(`alias`,e,p).body,i=X(dh(e),Ph(p,t,n)),a=r.kind===`Record`?r.fields.map(e=>e.name):[];return vh(i,a)??ye(t)}catch(e){if(!(e instanceof _||e instanceof v))throw e;return{...ye(t),_ALIASEvalError:e.message}}},Ce=(e,t,n)=>{O.value??=Tm(i,p,f.instanceActions);let r={...I};Object.assign(I,{index:e,isExpanding:!0,candidate:void 0});let a=D(n),o=O.value.find(e=>mo(e.expression,t,p,e.scope).some(e=>je(D(e.state),a)));return Object.assign(I,r),o&&Dm(o)},we=(e,t,n)=>{let r=i.alias,a=l(()=>(e.length>1&&Ss(p)&&Te(),e.map((n,r)=>r===0||n.action===`Stuttering`?void 0:Ce(t[r-1],e[r-1].state,n.state))));return e.map((t,i)=>({action:t.action,label:a[i],state:r===void 0?ye(t.state):xe(r,e,i,n)}))},Te=()=>E.init===void 0?[]:fo(E.init,p,E.scope),Ee=e=>E.next===void 0?[]:mo(E.next,e,p,E.scope),M=(e,t)=>je(D(e),pe[t]),N=(e,t)=>Ee(e).find(e=>M(e.state,t)),P=(e,t)=>{let n=le||Ss(p)?Te().find(t=>M(t,e[0])):j[e[0]];if(!n)throw new v(lh);let r=[{state:n,action:void 0}];for(let n=1;n<e.length;n++){let i=r[n-1].state;if(e[n-1]===e[n]){r.push({state:i,action:`Stuttering`});continue}let a=N(i,e[n]);if(!a)throw new v(t);r.push(a)}return r},F=(e,t)=>{let n=[];for(let t=e;t!==-1;t=me[t])n.unshift(t);let r=le&&n.length>1?P(n,lh):n.map(e=>({state:j[e],action:he[e]}));if(!t)return we(r,n);let i=le?Ee(j[e]).find(e=>je(e.state,t.state))?.action:t.action;return we([...r,{state:t.state,action:i}],n)},De=e=>me[e]===-1?[{action:void 0,label:void 0,state:ye(j[e])}]:F(e),Oe=(t,r,i,a)=>{if(d(t))return I.isExpanding?Oe(n(new v(u),e.error),De(I.index)):Oe(new v(u),r,i);if(!(t instanceof v))throw t;return{...g(`error`,void 0,{message:t.message,trace:r,initialState:i&&!(t instanceof y)?ye(i):void 0,exitCode:re(t)}),outDegrees:a}},ke=(e,t)=>{let n=P(e,uh),r=n[n.length-1].state;if(le&&t!==void 0&&t!==e.length-1&&N(r,e[t])===void 0)throw new v(uh);return n},Ae=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Pn(t,zn(e[n]));return t&1073741823},je=(e,t)=>{for(let n=0;n<t.length;n++)if(!nt(e[n],t[n]))return!1;return!0},Me=e=>Math.imul(e,2654435761)>>>_e.shift<<1,Ne=(e,t)=>{let n=_e.slots.length-1;for(let r=Me(e);;r=r+2&n){let n=_e.slots[r+1];if(n===0)return-1;if(_e.slots[r]===e&&je(pe[n-1],t))return n-1}},Pe=(e,t)=>{let n=_e.slots.length-1,r=Me(e);for(;_e.slots[r+1]!==0;)r=r+2&n;_e.slots[r]=e,_e.slots[r+1]=t},Fe=(e,t)=>{if(_e.size++,_e.size*4>_e.slots.length){let e=_e.slots;_e.slots=new Int32Array(e.length*2),_e.shift--;for(let t=0;t<e.length;t+=2)e[t+1]!==0&&Pe(e[t],e[t+1])}Pe(e,t+1)},Ie=e=>{m.distinctStates=j.length+1,h.depth=Math.max(h.depth,e),m.diameter=Math.max(m.diameter,e)},Le=(e,t,n,r)=>{let i=n===-1?1:ge[n]+1;j.push(e),pe.push(t),me.push(n),he.push(r),ge.push(i)},I={index:-1,isExpanding:!1,candidate:void 0,candidateLevel:0,isFingerprinting:!1,livenessSource:-1},Re=e=>e===-1?[]:[...Re(me[e]),j[e]];m.isSeen=e=>{let t=D(e);return Ne(Ae(t),t)!==-1},m.getBehavior=e=>{let t=e===I.candidate?-1:j.indexOf(e);return t===-1?[...Re(I.index),e]:Re(t)},m.getCurrentState=()=>I.index===-1?void 0:j[I.index],m.setLivenessSource=e=>{I.livenessSource=e??-1},m.getLevel=e=>{let t=I.livenessSource;return t===-1?e===I.candidate?I.candidateLevel:I.index===-1?0:e===j[I.index]?ge[I.index]:I.isExpanding?ge[I.index]+1:0:e===j[t]?ge[t]:ge[t]+1};let ze=(e,t)=>({fingerprint:BigInt.asIntN(64,m.getFingerprint(e)),level:t,getLabel:()=>nr(i.alias===void 0?ye(e):Se(i.alias,e,void 0)),getText:()=>nr(ye(e))}),Ve=e=>{ve(e),m.generatedStates++,m.initialStates++,I.candidate=e,I.candidateLevel=1;let t=D(e),n=Ae(t),i=C.satisfiesConstraints(e);if(i&&C.trackStatePossible(e),i&&Ne(n,t)!==-1)return;i&&(Ie(1),m.queueSize++,de?.addInitialState(j.length,e),r?.writeInitialState(ze(e,1)));let a=C.findViolatedInvariant(e);if(a)return T(`invariant-violation`,{name:a.name,trace:we([{action:void 0,state:e}],[])});let o=C.findFailedInitialPredicate(e);if(o)return T(`liveness-violation`,{name:o.name,trace:we([{action:void 0,state:e}],[])});i&&(Fe(n,j.length),Le(e,t,-1,void 0))},He=(e,t,n,i,a)=>{let o=j[e];m.generatedStates++,I.candidate=t.state,I.candidateLevel=ge[e]+1,fe&&ve(t.state),I.isFingerprinting=!0;let s=D(t.state),c=Ae(s);I.isFingerprinting=!1;let l=Ne(c,s),u=C.satisfiesConstraints(t.state,o);u&&C.trackStatePossible(t.state);let d=u&&C.satisfiesActionConstraints(o,t.state);d&&C.trackActionPossible(o,t.state);let f=d?l:-1;if(i&&d&&r?.writeSuccessor(i,ze(t.state,ge[e]+1),f!==-1,a&&{name:a.name,signature:Om(a)}),f!==-1&&de){let e=j[f],r=e.every((e,n)=>e===t.state[n]);n.push({index:f,state:r?e:t.state})}let p=d&&f===-1;if(p&&(Ie(ge[e]+1),te.newStates++),f===-1)try{let n=C.findViolatedInvariant(t.state,o);if(n)return T(`invariant-violation`,{name:n.name,trace:F(e,t)})}catch(n){return Oe(n,F(e,t),void 0,ie())}let h=C.findViolatedActionProperty(o,t.state);if(h)return T(`liveness-violation`,{name:h.name,trace:F(e,t)});p&&(fe||ve(t.state),Fe(c,j.length),de&&n.push({index:j.length,state:t.state}),Le(t.state,s,e,t.action),m.queueSize++)},Ue={result:void 0};if(E.init!==void 0)try{uo(E.init,p,e=>{try{Ue.result=Ve(e)}catch(t){Ue.result=Oe(t,[],e)}return Ue.result!==void 0},E.scope)}catch(e){if(!(e instanceof x))return se(Oe(e,[]));let t=Oe(e,[],e.state.map(e=>e??Ze(`null`)));return{...t,failure:t.failure&&{...t.failure,isWithoutStatistics:!0}}}if(Ue.result)return se(Ue.result);let We=E.next;if(We===void 0){if(j.length>0)throw new v(`No next state actions defined to generate successor states from.`);return S()}let L=!!(t.dump?.dot&&(t.dump.actionLabels||t.dump.colorize)),Ge=(e,t)=>{if(!L)return po(We,e,p,e=>t(e,void 0),E.scope);O.value??=Tm(i,p,f.instanceActions);let n={isStopped:!1};return O.value.reduce((r,i)=>n.isStopped?r:r+po(i.expression,e,p,e=>(n.isStopped=t(e,i),n.isStopped),i.scope),0)},Ke=e=>{let t=j[e],n=[],a=r&&ze(t,ge[e]),o=Ge(t,(t,r)=>{try{Ue.result=He(e,t,n,a,r)}catch(n){if(I.isFingerprinting)throw n;let r=Oe(n,F(e,t));Ue.result=d(n)?r:ce(r,e)}return Ue.result!==void 0});if(I.isExpanding=!1,Ue.result)return Ue.result;if(o===0&&i.checkDeadlock)return T(`deadlock`,{name:`deadlock`,trace:De(e)});try{let r=de?.addState(e,t,n);if(!de||!r)return;let i=ke(r),a=de.getViolatedProperties(i.map(e=>e.state),i.length-1);return T(`property-violation`,{name:a[0],properties:a,trace:we(i,r)})}catch(t){return Oe(t,De(e),void 0,ie())}},qe=(e,t)=>{O.value??=Tm(i,p,f.instanceActions);let n=O.value,r=n.length===1?n[0]:n.find(t=>t.name===e.action),a=`variable${e.missing.length>1?`s are`:` is`} not defined: ${e.missing.join(`, `)}.\n`;return m.generatedStates++,Oe(n.length===1?e:new v(`Successor state is not completely specified by action ${e.action} of the next-state relation. The following ${a}`),[...De(t),{action:e.action,label:r&&Dm(r),state:ye(e.state.map(e=>e??Ze(`null`)))}])},Je=(e,t)=>{let n=[...t.prefix,...t.cycle],r=t.prefix.length,i=ke(n,r),a=we(i,n,r),o=e.getViolatedProperties(i.map(e=>e.state),r),s=n[r],c=n[n.length-1],u=i[i.length-1].state,d=s===c?void 0:l(()=>Ce(c,u,j[s]));return T(`liveness-violation`,{name:o[0],properties:o,trace:a,loopStart:r,loopLabel:d},()=>s===c?a[a.length-1].action:N(u,s)?.action)},Ye=de!==void 0&&t.livenessCheck!==`final`,Xe=performance.now(),Qe={at:Xe+3e3,size:1,time:0},$e=e=>{let t=performance.now();if(Qe.at=t+6e4,!((e-Qe.size)/Qe.size>.1)||Qe.time>(t-Xe)*.2)return;Qe.size=e;let n=de?.findViolation();return Qe.time+=performance.now()-t,n};for(let e=0;e<j.length&&!m.isStopped;e++){I.index=e,I.candidate=void 0,m.queueSize=j.length-e-1,I.isExpanding=!0;try{Ue.result=Ke(e)}catch(t){let n=t instanceof b?qe(t,e):Oe(Wh(t),De(e));Ue.result=t instanceof b||d(t)?n:ce(n,e)}if(Ue.result)return Ue.result;if(ee[ne()]++,te.newStates=0,Ye&&performance.now()>=Qe.at){let t=$e(e+1);if(de&&t)return Je(de,t)}}I.index=-1,I.candidate=void 0;let et=de?.findViolation();if(de&&et)return Je(de,et);let tt=C.findPostconditionViolation();return tt?g(`postcondition-violation`,{...tt,trace:[]}):S()},Yh=e=>{let t=Math.imul(e^e>>>16,2146121005),n=Math.imul(t^t>>>15,2221713035);return n^n>>>16},Xh=(e,t)=>{let n=2166136261,r=1779033703;for(let t=0;t<e.length;t++)n=Math.imul(n^zn(e[t]),16777619),r=Math.imul(r^Kn(e[t]),1540483477);t[0]=Yh(n)||1,t[1]=Yh(r)},Zh=()=>{let e={slots:/* @__PURE__ */ new Int32Array(8192),used:0},t=(e,t,n)=>{let r=e.length/2-1;for(let i=t&r;;i=i+1&r){let r=e[i*2];if(r===0||r===t&&e[i*2+1]===n)return i}},n=()=>{let n=e.slots,r=new Int32Array(n.length*2);for(let e=0;e<n.length;e+=2){if(n[e]===0)continue;let i=t(r,n[e],n[e+1]);r[i*2]=n[e],r[i*2+1]=n[e+1]}e.slots=r};return{insert:(r,i)=>{e.used*4>=e.slots.length&&n();let a=t(e.slots,r,i);return e.slots[a*2]!==r&&(e.slots[a*2]=r,e.slots[a*2+1]=i,e.used++,!0)}}},Qh=(e,t)=>{let n=e.length-1;for(let r=Number(t>>32n)&n;;r=r+1&n){let n=Atomics.load(e,r);if(n===t)return!1;if(n!==0n)continue;let i=Atomics.compareExchange(e,r,0n,t);if(i===0n)return!0;if(i===t)return!1}},$h=()=>({slots:new BigInt64Array(new SharedArrayBuffer(8192)),used:new Int32Array(new SharedArrayBuffer(4))}),eg=(e,t,n)=>{let r=BigInt.asIntN(64,BigInt(t)<<32n|BigInt(n>>>0));return Qh(e.slots,r)?(Atomics.add(e.used,0,1),!0):!1},tg=e=>Atomics.load(e.used,0)*2>=e.slots.length,ng=e=>{let t=new BigInt64Array(new SharedArrayBuffer(e.slots.byteLength*2));for(let n of e.slots)n!==0n&&Qh(t,n);return{slots:t,used:e.used}},rg=()=>{let e={words:/* @__PURE__ */ new Int32Array(1024),length:0,count:0},t=[],n=/* @__PURE__ */ new Map,r=t=>{if(e.length===e.words.length){let t=new Int32Array(e.words.length*2);t.set(e.words),e.words=t}e.words[e.length++]=t},i=e=>{let i=n.get(e);if(i!==void 0)return r(i);n.set(e,t.length),r(t.length),t.push(e)},a=e=>{if(typeof e==`boolean`)return r(+!!e),!0;if(typeof e==`number`)return(e|0)===e&&(r(2),r(e),!0);if(typeof e==`string`)return r(3),i(e),!0;if(e.kind===`ModelValue`)return r(4),i(e.name),!0;if(e.kind===`Set`)return r(5),r(e.elements.length),e.elements.every(a);if(e.kind===`Function`){let t=kn(e.domain);return t?(r(7),r(t.low),r(e.range.length),e.range.every(a)):(r(6),r(e.domain.length),e.domain.every(a)&&e.range.every(a))}return!1};return{encode:t=>{let n=e.length;return t.every(a)?(e.count++,!0):(e.length=n,!1)},finish:()=>({words:e.words.slice(0,e.length),strings:t,count:e.count})}},ig=e=>t=>{let n=t.words,r={index:0},i=e=>Array.from({length:e},()=>a()),a=()=>{let e=n[r.index++];if(e===0)return!1;if(e===1)return!0;if(e===2)return n[r.index++];if(e===3)return t.strings[n[r.index++]];if(e===4)return Ze(t.strings[n[r.index++]]);if(e===7){let e=n[r.index++],t=n[r.index++],a=Ut({kind:`Interval`,low:e,high:e+t-1});return $e(a,i(t))}let a=n[r.index++];if(e===5)return Qe(i(a));let o=i(a);return $e(o,i(a))};return Array.from({length:t.count},()=>Array.from({length:e},()=>a()))};export{be as A,re as B,fo as C,U as D,nr as E,ee as F,p as I,ne as L,_ as M,f as N,He as O,v as P,te as R,Ss as S,ir as T,e as V,Xf as _,ng as a,qc as b,Xh as c,Vh as d,rh as f,sh as g,$m as h,$h as i,ue as j,Be as k,qh as l,oh as m,rg as n,eg as o,ah as p,Zh as r,tg as s,ig as t,Hh as u,zf as v,mo as w,Jc as x,Bf as y,m as z};
|
|
437
|
+
please check if this bug described in LevelNode.java starting at line 590ff affects you.`;throw n(new v(`The invariant ${t} is not a state predicate (one with no primes or temporal operators).${r}`),e.safetyEvaluationFailure)}return[{name:t,expression:vg(t),scope:void 0}]})},Tg=(e,t)=>{if(!Me(e))return;let n=bn(e);if(!n.domain.every(e=>typeof e==`string`))return;let r=n.domain.map((e,t)=>[String(e),n.range[t]]);return Object.fromEntries(r.sort((e,n)=>t.indexOf(e[0])-t.indexOf(n[0])))},Eg=(e,t)=>{if(e.kind===`And`)return e.operands.flatMap(e=>Eg(e,t));if(e.kind===`Identifier`&&!t.constants.has(e.name)){let n=Ro(e.name,t);if(n?.kind===`Operator`&&n.params.length===0)return Eg(n.body,t)}return[e]},Dg=(e,t,n)=>{let r=e.expression;if(r.kind!==`Identifier`||Gm(r,e.scope,t)>0)return!1;let i=Ys(r,Vg(t,void 0,void 0,e.scope));if(i===!1)throw new v(`The spec is trivially false because ${r.name} is false.`);if(i!==!0)throw new v(`The operator ${r.name}, which equals ${Y(i)},\ncannot be used as a ${n}`);return!0},Og=(t,r)=>{if(t.specification===void 0){let e=(e,t)=>{if(e===void 0)return;let n=bg(t,e,r).body,i=vg(e);if(n.kind!==`Number`&&n.kind!==`String`&&Gm(i,void 0,r)===0)throw new v(`The ${t} ${e} cannot be a constant.`);return i};return{init:e(t.init,`initial predicate`),next:e(t.next,`next state action`),scope:void 0,temporals:[]}}let i=[],a=[],o=[],s=bg(`name`,t.specification,r),c=Sg(t.specification,s,r);if(c!==void 0)throw new v(`The value of ${t.specification} is equal to ${Y(c)}`);if(Jm(s.body,void 0,r,!1).forEach(s=>{let c=s.expression;if(Dg(s,r,`spec`))return;if(c.kind===`UnboundedQuantifier`&&c.isTemporal)throw n(new v(`TLC does not support temporal existential, nor universal, quantification over state variables.`),e.error);if(c.kind===`Always`&&c.expression.kind===`BoxAction`){a.push({expression:c.expression.action,scope:s.scope});return}if(c.kind===`Always`&&Gm(c.expression,s.scope,r)<2)throw n(new v(`TLC cannot handle the temporal formula ${Co(c.expression)}`),e.error);let l=Gm(c,s.scope,r);if(l===3)o.push(s);else{if(l===2)throw new v(`TLC cannot handle the action-level conjunct of the specification ${t.specification}`);i.push(s)}}),a.length>1)throw new v(`The specification ${t.specification} must contain at most one [][Next]_vars`);let l=[...i,...a],u=e=>`$specification${e}`,d=l.reduce((e,t,n)=>t.scope===void 0?e:{name:u(n),binding:{kind:`Thunk`,expression:t.expression,scope:t.scope,state:void 0,next:void 0,cache:void 0},parent:e},void 0),f=(e,t)=>e.scope===void 0?e.expression:{kind:`Identifier`,name:u(t),location:e.expression.location,resolution:{kind:`Local`}};return{init:i.length===0?void 0:{kind:`And`,operands:i.map(f),location:hg},next:a.length===0?void 0:f(a[0],i.length),scope:d,temporals:o}},kg=(e,t)=>{let n={initialPredicates:[],invariants:[],actionProperties:[],liveness:[]};return e.properties.forEach(e=>{let r=Cg(`property`,e,t);r&&Jm(r.body,void 0,t,!0,e).forEach(r=>{let i=r.expression;if(Dg(r,t,`property`))return;if(i.kind===`Always`&&i.expression.kind===`BoxAction`){n.actionProperties.push({name:r.name,box:i.expression,action:i.expression.action,subscript:i.expression.subscript,scope:r.scope});return}if(i.kind===`Always`&&Gm(i.expression,r.scope,t)<=1){let e=i.expression;n.invariants.push({name:e.kind===`Identifier`?e.name:r.name,expression:e,scope:r.scope});return}let a=Gm(i,r.scope,t);if(a<2)n.initialPredicates.push({name:r.name,expression:i,scope:r.scope});else{if(a===2)throw new v(`The property ${e} is an action-level formula`);n.liveness.push({name:e,expression:i,scope:r.scope})}})}),n},Ag=(e,t,n)=>t.flatMap(t=>Cg(e,t,n)?[{name:t,expression:vg(t),scope:void 0}]:[]),jg=(e,t)=>{let n=Ro(e,t);return n?.kind===`Operator`?n.bodyRange:void 0},Mg=(e,t)=>e.map((n,r)=>{if(e.indexOf(n)!==r)throw new v(`_POSSIBLE lists ${n} more than once`);xg(`possible`,n,t);let i=vg(n);if(Gm(i,void 0,t)===3)throw new v(`The possible of ${n} is equal to a temporal formula; only state- and action-level predicates are supported`);return{name:n,expression:i,scope:void 0}}),Ng=(e,t,n)=>{if(e.kind!==`Apply`||e.operator!==`\\in`||t?.length!==1)return;let r=e.args[0];if(!(r.kind!==`Identifier`||X(r)))return n.variableIndex.get(r.name)===t[0]?{variable:t[0],set:e.args[1]}:void 0},Pg=(e,t)=>e.flatMap(e=>Eg(e.expression,t).map(n=>{let r=e.scope===void 0?Oc(n,t):void 0;return{name:e.name,expression:n,scope:e.scope,variables:r,membership:Ng(n,r,t)}})),Fg=(e,t,n)=>{let r=e.variables;if(!n||!r)return!1;for(let e=0;e<r.length;e++)if(t[r[e]]!==n[r[e]])return!1;return!0},Ig=/[\u0100-\uffff]/,Lg=/* @__PURE__ */ new Set([`JsonDeserialize`,`ndJsonDeserialize`]),Rg=e=>e.kind===`String`?Ig.test(e.value):e.kind===`Set`&&e.elements.some(Rg),zg=e=>e.kind===`String`&&Ig.test(e.value)||e.kind===`Apply`&&Lg.has(e.operator)||ur(e).some(zg),Bg=(e,t)=>e.constants.some(e=>Rg(e.value)||(e.args??[]).some(Rg))||[...t.definitions.values()].some(e=>zg(e.body)||e.kind===`Function`&&e.bounds.some(e=>zg(e.set))),Vg=(e,t,n,r)=>({environment:e,scope:r,state:t,next:n}),Hg=(e,t,n)=>Lo(Ys(e,t),n),Ug=(e,t,n=Wg)=>{let r=Ys(e,t);if(typeof r!=`boolean`)throw new y(n(e,t.environment));return r},Wg=(e,t)=>{let n=e.kind===`Identifier`?Ro(e.name,t):void 0,r=n?.kind===`Operator`?n.body:e,i=n?.kind===`Operator`?n.bodyRange:void 0;return`TLC expected a boolean value, but did not find one. ${r.kind===`Number`?r.text??String(r.value):i?g(i):Co(r)}`},Gg=()=>{},Kg=(e,t,n)=>e.forEach(e=>{let r=t.possibleCounts.get(e.name)??0,i=Hg(e.expression,n,`_POSSIBLE ${e.name}`);t.possibleCounts.set(e.name,i?r+1:r)}),qg=(e,t,n)=>{try{return Hg(e,Vg(t,void 0,void 0),n)?void 0:{message:void 0}}catch(e){if(e instanceof y)return{message:e.message};throw e}},Jg=(e,t)=>{for(let n of e.filter(e=>!e.isAxiom)){let e=qg(n.expression,t,`an assumption`);if(e)return{name:Co(n.expression),trace:[],message:e.message}}},Yg=(t,r,i)=>{let a=wg(t.invariants,r),o=Og(t,r),s=kg(t,r),c=Pg([...a,...s.invariants],r),l=c.length>0||s.actionProperties.length>0||s.liveness.length>0;if(o.init===void 0&&(l||s.initialPredicates.length>0||r.variables.length>0))throw new v(`The configuration file did not specify the initial state predicate.`);if(o.next===void 0&&l)throw new v(`The configuration file did not specify the next state predicate.`);let u=Pg(Ag(`constraint`,t.constraints,r),r),d=Ag(`action constraint`,t.actionConstraints,r);t.rlReward!==void 0&&bg(`rlreward`,t.rlReward,r),t.periodic!==void 0&&bg(`periodic`,t.periodic,r);let f=Mg(t.possible,r);if(r.variables.length===0)return;let p=t.symmetry===void 0?[]:Zh(t.symmetry,r);t.view!==void 0&&bg(`view function`,t.view,r);let m=t.view===void 0?void 0:{name:t.view,expression:vg(t.view),scope:void 0},h=s.actionProperties.map(e=>{let t={kind:`Unchanged`,expression:e.subscript,location:hg};return{...e,unchanged:t}}),_=e=>Gm(e.expression,void 0,r)>=2,y=f.filter(e=>!_(e)),b=f.filter(_),ee=r.runtime,x={indices:void 0},S=()=>{if(x.indices)return x.indices;let e=i(),t=t=>{let n=e.indexOf(r.variables[t]);return n===-1?r.variables.length:n};return x.indices=r.variables.map((e,t)=>t).sort((e,n)=>t(e)-t(n)),x.indices},C=p.length>0?S():void 0,w=(e,t)=>Ys(e,Vg(r,t,void 0)),T=e=>{let t=S(),n=p.length===0?e:ag(e,p,t);return Tl(m===void 0?t.map(e=>n[e]):[w(m.expression,n)])},te=Bg(t,r);ee.getFingerprint=T;let ne=()=>{let e=f.find(e=>!ee.possibleCounts.get(e.name));if(!e)return;let t=jg(e.name,r),n=t?` at ${g(t)}`:``;return{name:e.name,message:`The _POSSIBLE predicate ${e.name}${n} was never witnessed.\nOthers may be unwitnessed too; only witnessed predicates appear with a\nnon-zero count in the record printed above.\nSee https://explain.tlapl.us/possible-conditions for additional details.`,counts:Ee(Y(Wl(ee),!0))}};return{properties:s,spec:o,isSymmetric:p.length>0,getTlcOrder:S,getStoredFingerprints:(e,t)=>{if(m!==void 0||te)return BigInt64Array.from(e,T);let n=new BigInt64Array(t.length),r=Ol(S(),new Int32Array(n.buffer));return t.forEach(r),n},getFingerprintState:e=>{if(te)return[String(T(e))];let t=p.length===0?e:ag(e,p,C);return m===void 0?t:[w(m.expression,t)]},findViolatedInvariant:(t,i)=>c.find(a=>{if(Fg(a,t,i))return!1;try{let e=Vg(r,t,void 0,a.scope),n=a.membership;return i&&n?!yn(t[n.variable],i[n.variable],Ys(n.set,e)):!Ug(a.expression,e)}catch(t){throw i?t_(n(t,e.safetyEvaluationFailure),`Evaluating invariant ${a.name} failed.`):t}}),satisfiesConstraints:(e,t)=>u.every(n=>{try{return Fg(n,e,t)||Ug(n.expression,Vg(r,e,void 0))}catch(e){throw t?Zg(e):e}}),findFailedInitialPredicate:e=>s.initialPredicates.find(t=>!Ug(t.expression,Vg(r,e,void 0,t.scope))),findViolatedActionProperty:(e,t)=>h.find(n=>{try{return!Ug(n.action,Vg(r,e,t,n.scope),()=>`Attempted to evaluate an expression of form [A]_e, but A was not a boolean.\n${Co(n.box)}`)&&!Hg(n.unchanged,Vg(r,e,t,n.scope),`a subscript`)}catch(e){throw t_(Xg(e),`Evaluating action property ${n.name} failed.`)}}),satisfiesActionConstraints:(e,t)=>d.every(n=>{try{return Ug(n.expression,Vg(r,e,t))}catch(e){throw Zg(e)}}),trackStatePossible:y.length===0?Gg:e=>Kg(y,ee,Vg(r,e,void 0)),trackActionPossible:b.length===0?Gg:(e,t)=>Kg(b,ee,Vg(r,e,t)),findUnwitnessedPossible:ne,findPostconditionViolation:()=>{let e=ne();if(e)return e;for(let e of t.postconditions){let t=qg(vg(e),r,`a postcondition`);if(t)return{name:e,message:t.message??`Postcondition ${e} is false.`}}}}},Xg=e=>e instanceof b?n(e,e.exitCode):e,Zg=e=>e instanceof y&&!(e instanceof b)&&!(e instanceof x)?n(new y(`${l}${e.message}`,e),te(e)):Xg(e),Qg=(e,t,n)=>t>0&&n[t-1]===e,$g=e=>e.flatMap(e=>e.location.range?[g(e.location.range)]:[]).filter((e,t,n)=>!Qg(e,t,n)).map((e,t)=>`${t}) ${e}`).reverse(),e_=(e,t)=>{try{return e(),{callStack:void 0}}catch(e){if(!(e instanceof y))return{callStack:[]};let n=t.flatMap(e=>{let t=e.location.range;return t?[`Line ${t.start.line}, column ${t.start.column} to line ${t.end.line}, column ${t.end.column} in ${t.module}`]:[]}).filter((e,t,n)=>!Qg(e,t,n)),r=Oe(e);return{callStack:n,fingerprint:r&&{sources:$g(r),reason:e.message}}}},t_=(e,t)=>e instanceof y?n(new y(`${t}\n${e.message}`,e),te(e)):e,n_=t=>{let r=t.dump&&Kh(t.dump,t.writeFile);try{return r_(t,r)}catch(t){throw d(t)?n(new y(u),e.error):t}finally{r?.close()}},r_=(t,r)=>{let i=typeof t.config==`string`?be(t.config):t.config,a=t.onPrint??console.log,o={isMuted:!1,replayed:void 0},s=e=>{o.replayed?o.replayed.push(e):o.isMuted||a(e)},l=e=>{o.isMuted=!0;let t=e();return o.isMuted=!1,t};W(Gp(t.source,i,t.loadModule));let f=tm(i,{source:t.source,loadModule:t.loadModule,loadClass:t.loadClass,print:s,files:{readFile:t.readFile,writeFile:t.writeFile},seed:t.seed}),p=f.environment,m=p.runtime;m.pause=t.onPause??(()=>{}),m.getSpecification=()=>Ih(i,p,f.variableLocations,f.instanceActions);let h={depth:0},g=(e,t,n)=>({status:e,violation:t&&{...t,loopStart:t.loopStart},failure:n,generatedStates:m.generatedStates,distinctStates:m.distinctStates,queuedStates:m.queueSize,depth:m.generatedStates===0?0:Math.max(h.depth,1),outDegrees:void 0,fingerprintDistance:void 0}),_=Array.from({length:32},()=>0),ee={newStates:0},C=()=>Math.min(ee.newStates,31),w=()=>_.map((e,t)=>t===C()?e+1:e),T=()=>({...g(`success`),outDegrees:[..._],fingerprintDistance:pg(m.distinctStates,m.generatedStates,()=>E?E.getStoredFingerprints(N,pe):BigInt64Array.from(N,m.getFingerprint))}),ne=()=>Wp(t.source,t.loadModule,`variable`),E=Yg(i,p,ne),D=Jg(f.assumptions,p);if(D)return g(`assumption-violation`,D);if(!E)return T();let O=i.postconditions.length>0||i.possible.length>0,k=(e,t,n)=>{if(O){let e=t.loopStart;m.counterExample=Ld(t.trace,e===void 0||!n?void 0:{start:e,action:n()})}let r=E.findUnwitnessedPossible();return r||E.findPostconditionViolation(),g(e,r?{...t,unwitnessed:r}:t)},A=E.spec,j=E.getFingerprintState,re={value:void 0},M=(e,t,n=!1)=>{if(!e.failure)return e;let r=[],a={...p,evaluators:/* @__PURE__ */ new WeakMap,trace:r},s=Yg(i,a,ne);if(!s)return e;let c=[];o.replayed=c,P.current=/* @__PURE__ */ new WeakMap;let l=e_(()=>t(s,a),r);return P.current=void 0,o.replayed=void 0,{...e,failure:{...e.failure,replay:{output:c,...l,isBeforeError:n}}}},ie=(e,t)=>{try{Pe(j(e))}catch(e){throw t.trace&&Oe(e)&&(t.trace.length=0),e}},ae=e=>M(e,(e,t)=>{A.init!==void 0&&vo(A.init,t,n=>(e.satisfiesConstraints(n)&&ie(n,t),e.findViolatedInvariant(n)!==void 0||e.findFailedInitialPredicate(n)!==void 0),A.scope)}),oe=e=>{let t=me[e];t===-1?Te():(oe(t),Ce(t,N[t],N[e]))},se=(e,t)=>M(e,(e,n)=>{oe(t);let r=N[t];re.value??=Mh(i,p,f.instanceActions),re.value.find(t=>xo(t.expression,r,n,t.scope).some(t=>{let i=e.satisfiesConstraints(t.state)&&e.satisfiesActionConstraints(r,t.state);return i&&ie(t.state,n),!i&&e.findViolatedInvariant(t.state)!==void 0||e.findViolatedActionProperty(r,t.state)!==void 0}))}),ce=i.view!==void 0||i.symmetry!==void 0,le=[],ue={getFingerprint:e=>le[e]??=Number(BigInt.asIntN(32,m.getFingerprint(N[e]))),getSuccessors:e=>{let t=[];return A.next===void 0||bo(A.next,e,p,n=>{if(ve(n.state),!(E.satisfiesConstraints(n.state,e)&&E.satisfiesActionConstraints(e,n.state)))return!1;let r=j(n.state),i=Ie(Pe(r),r);return t.push({index:i,state:n.state}),!1},A.scope),t}},de=c(()=>lh(E.properties.liveness,A.temporals,p,ue)),fe=E.isSymmetric||de!==void 0,N=[],pe=[],me=[],he=[],ge=[],_e={slots:new Int32Array(1<<17),size:0,shift:16},ve=lr(),ye=e=>Object.fromEntries(E.getTlcOrder().map(t=>[p.variables[t],e[t]])),xe=(e,t,n,r)=>(m.getLevel=()=>n+1,m.getBehavior=()=>t.slice(0,n+1).map(e=>e.state),Se(e,t[n].state,(t[n+1]??t[r??n]).state)),Se=(e,t,n)=>{try{let r=xg(`alias`,e,p).body,i=Ys(vg(e),Vg(p,t,n)),a=r.kind===`Record`?r.fields.map(e=>e.name):[];return Tg(i,a)??ye(t)}catch(e){if(!(e instanceof v||e instanceof y))throw e;return{...ye(t),_ALIASEvalError:e.message}}},Ce=(e,t,n)=>{re.value??=Mh(i,p,f.instanceActions);let r={...B};Object.assign(B,{index:e,isExpanding:!0,candidate:void 0});let a=j(n),o=re.value.find(e=>xo(e.expression,t,p,e.scope).some(e=>I(j(e.state),a)));return Object.assign(B,r),o&&Ph(o)},we=(e,t,n)=>{let r=i.alias,a=l(()=>(e.length>1&&ks(p)&&Te(),e.map((n,r)=>r===0||n.action===`Stuttering`?void 0:Ce(t[r-1],e[r-1].state,n.state))));return e.map((t,i)=>({action:t.action,label:a[i],state:r===void 0?ye(t.state):xe(r,e,i,n)}))},Te=()=>A.init===void 0?[]:yo(A.init,p,A.scope),Ee=e=>A.next===void 0?[]:xo(A.next,e,p,A.scope),De=(e,t)=>I(j(e),pe[t]),ke=(e,t)=>Ee(e).find(e=>De(e.state,t)),Ae=(e,t)=>{let n=ce||ks(p)?Te().find(t=>De(t,e[0])):N[e[0]];if(!n)throw new y(gg);let r=[{state:n,action:void 0}];for(let n=1;n<e.length;n++){let i=r[n-1].state;if(e[n-1]===e[n]){r.push({state:i,action:`Stuttering`});continue}let a=ke(i,e[n]);if(!a)throw new y(t);r.push(a)}return r},je=(e,t)=>{let n=[];for(let t=e;t!==-1;t=me[t])n.unshift(t);let r=ce&&n.length>1?Ae(n,gg):n.map(e=>({state:N[e],action:he[e]}));if(!t)return we(r,n);let i=ce?Ee(N[e]).find(e=>I(e.state,t.state))?.action:t.action;return we([...r,{state:t.state,action:i}],n)},Me=e=>me[e]===-1?[{action:void 0,label:void 0,state:ye(N[e])}]:je(e),F=(t,r,i,a)=>{if(d(t))return B.isExpanding?F(n(new y(u),e.error),Me(B.index)):F(new y(u),r,i);if(!(t instanceof y))throw t;return{...g(`error`,void 0,{message:t.message,trace:r,initialState:i&&!(t instanceof b)?ye(i):void 0,exitCode:te(t)}),outDegrees:a}},Ne=(e,t)=>{let n=Ae(e,_g),r=n[n.length-1].state;if(ce&&t!==void 0&&t!==e.length-1&&ke(r,e[t])===void 0)throw new y(_g);return n},Pe=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=In(t,Hn(e[n]));return Wn(e),t&1073741823},I=(e,t)=>{for(let n=0;n<t.length;n++)if(!tt(e[n],t[n]))return!1;return!0},Fe=e=>Math.imul(e,2654435761)>>>_e.shift<<1,Ie=(e,t)=>{let n=_e.slots.length-1;for(let r=Fe(e);;r=r+2&n){let n=_e.slots[r+1];if(n===0)return-1;if(_e.slots[r]===e&&I(pe[n-1],t))return n-1}},L=(e,t)=>{let n=_e.slots.length-1,r=Fe(e);for(;_e.slots[r+1]!==0;)r=r+2&n;_e.slots[r]=e,_e.slots[r+1]=t},R=(e,t)=>{if(_e.size++,_e.size*4>_e.slots.length){let e=_e.slots;_e.slots=new Int32Array(e.length*2),_e.shift--;for(let t=0;t<e.length;t+=2)e[t+1]!==0&&L(e[t],e[t+1])}L(e,t+1)},Le=e=>{m.distinctStates=N.length+1,h.depth=Math.max(h.depth,e),m.diameter=Math.max(m.diameter,e)},z=(e,t,n,r)=>{let i=n===-1?1:ge[n]+1;N.push(e),pe.push(t),me.push(n),he.push(r),ge.push(i)},B={index:-1,isExpanding:!1,candidate:void 0,candidateLevel:0,isFingerprinting:!1,livenessSource:-1},Re=e=>e===-1?[]:[...Re(me[e]),N[e]];m.isSeen=e=>{let t=j(e);return Ie(Pe(t),t)!==-1},m.getBehavior=e=>{let t=e===B.candidate?-1:N.indexOf(e);return t===-1?[...Re(B.index),e]:Re(t)},m.getCurrentState=()=>B.index===-1?void 0:N[B.index],m.setLivenessSource=e=>{B.livenessSource=e??-1},m.getLevel=e=>{let t=B.livenessSource;return t===-1?e===B.candidate?B.candidateLevel:B.index===-1?0:e===N[B.index]?ge[B.index]:B.isExpanding?ge[B.index]+1:0:e===N[t]?ge[t]:ge[t]+1};let V=(e,t)=>({fingerprint:BigInt.asIntN(64,m.getFingerprint(e)),level:t,getLabel:()=>sr(i.alias===void 0?ye(e):Se(i.alias,e,void 0)),getText:()=>sr(ye(e))}),H=e=>{ve(e),m.generatedStates++,m.initialStates++,B.candidate=e,B.candidateLevel=1;let t=j(e),n=Pe(t),i=E.satisfiesConstraints(e);if(i&&E.trackStatePossible(e),i&&Ie(n,t)!==-1)return;i&&(Le(1),m.queueSize++,de?.addInitialState(N.length,e),r?.writeInitialState(V(e,1)));let a=E.findViolatedInvariant(e);if(a)return k(`invariant-violation`,{name:a.name,trace:we([{action:void 0,state:e}],[])});let o=E.findFailedInitialPredicate(e);if(o)return k(`liveness-violation`,{name:o.name,trace:we([{action:void 0,state:e}],[])});i&&(R(n,N.length),z(e,t,-1,void 0))},U=(e,t,n,i,a)=>{let o=N[e];m.generatedStates++,B.candidate=t.state,B.candidateLevel=ge[e]+1,fe&&ve(t.state),B.isFingerprinting=!0;let s=j(t.state),c=Pe(s);B.isFingerprinting=!1;let l=Ie(c,s),u=E.satisfiesConstraints(t.state,o);u&&E.trackStatePossible(t.state);let d=u&&E.satisfiesActionConstraints(o,t.state);d&&E.trackActionPossible(o,t.state);let f=d?l:-1;if(i&&d&&r?.writeSuccessor(i,V(t.state,ge[e]+1),f!==-1,a&&{name:a.name,signature:Fh(a)}),f!==-1&&de){let e=N[f],r=e.every((e,n)=>e===t.state[n]);n.push({index:f,state:r?e:t.state})}let p=d&&f===-1;if(p&&(Le(ge[e]+1),ee.newStates++),f===-1)try{let n=E.findViolatedInvariant(t.state,o);if(n)return k(`invariant-violation`,{name:n.name,trace:je(e,t)})}catch(n){return F(n,je(e,t),void 0,w())}let h=E.findViolatedActionProperty(o,t.state);if(h)return k(`liveness-violation`,{name:h.name,trace:je(e,t)});p&&(fe||ve(t.state),R(c,N.length),de&&n.push({index:N.length,state:t.state}),z(t.state,s,e,t.action),m.queueSize++)},ze={result:void 0};if(A.init!==void 0)try{vo(A.init,p,e=>{try{ze.result=H(e)}catch(t){ze.result=F(t,[],e)}return ze.result!==void 0},A.scope)}catch(e){if(!(e instanceof S))return ae(F(e,[]));let t=F(e,[],e.state.map(e=>e??Xe(`null`)));return{...t,failure:t.failure&&{...t.failure,isWithoutStatistics:!0}}}if(ze.result)return ae(ze.result);let Be=A.next;if(Be===void 0){if(N.length>0)throw new y(`No next state actions defined to generate successor states from.`);return T()}let Ve=!!(t.dump?.dot&&(t.dump.actionLabels||t.dump.colorize)),He=(e,t)=>{if(!Ve)return bo(Be,e,p,e=>t(e,void 0),A.scope);re.value??=Mh(i,p,f.instanceActions);let n={isStopped:!1};return re.value.reduce((r,i)=>n.isStopped?r:r+bo(i.expression,e,p,e=>(n.isStopped=t(e,i),n.isStopped),i.scope),0)},Ue=e=>{let t=N[e],n=[],a=r&&V(t,ge[e]),o=He(t,(t,r)=>{try{ze.result=U(e,t,n,a,r)}catch(n){if(B.isFingerprinting)throw n;let r=F(n,je(e,t));ze.result=d(n)?r:se(r,e)}return ze.result!==void 0});if(B.isExpanding=!1,ze.result)return ze.result;if(o===0&&i.checkDeadlock)return k(`deadlock`,{name:`deadlock`,trace:Me(e)});try{let r=de?.addState(e,t,n);if(!de||!r)return;let i=Ne(r),a=de.getViolatedProperties(i.map(e=>e.state),i.length-1);return k(`property-violation`,{name:a[0],properties:a,trace:we(i,r)})}catch(r){return M(F(Zg(r),Me(e),void 0,w()),(r,i)=>lh(E.properties.liveness,A.temporals,i,ue)?.addState(e,t,n),!0)}},We=(e,t)=>{re.value??=Mh(i,p,f.instanceActions);let n=re.value,r=n.length===1?n[0]:n.find(t=>t.name===e.action),a=`variable${e.missing.length>1?`s are`:` is`} not defined: ${e.missing.join(`, `)}.\n`;return m.generatedStates++,F(n.length===1?e:new y(`Successor state is not completely specified by action ${e.action} of the next-state relation. The following ${a}`),[...Me(t),{action:e.action,label:r&&Ph(r),state:ye(e.state.map(e=>e??Xe(`null`)))}])},Ge=(e,t)=>{let n=[...t.prefix,...t.cycle],r=t.prefix.length,i=Ne(n,r),a=we(i,n,r),o=e.getViolatedProperties(i.map(e=>e.state),r),s=n[r],c=n[n.length-1],u=i[i.length-1].state,d=s===c?void 0:l(()=>Ce(c,u,N[s]));return k(`liveness-violation`,{name:o[0],properties:o,trace:a,loopStart:r,loopLabel:d},()=>s===c?a[a.length-1].action:ke(u,s)?.action)},Ke=de!==void 0&&t.livenessCheck!==`final`,qe=performance.now(),Je={at:qe+3e3,size:1,time:0},Ye=e=>{let t=performance.now();if(Je.at=t+6e4,!((e-Je.size)/Je.size>.1)||Je.time>(t-qe)*.2)return;Je.size=e;let n=de?.findViolation();return Je.time+=performance.now()-t,n};for(let e=0;e<N.length&&!m.isStopped;e++){B.index=e,B.candidate=void 0,m.queueSize=N.length-e-1,B.isExpanding=!0;try{ze.result=Ue(e)}catch(t){let n=t instanceof x?We(t,e):F(Zg(t),Me(e));ze.result=t instanceof x||d(t)?n:se(n,e)}if(ze.result)return ze.result;if(_[C()]++,ee.newStates=0,Ke&&performance.now()>=Je.at){let t=Ye(e+1);if(de&&t)return Ge(de,t)}}B.index=-1,B.candidate=void 0;let Ze=de?.findViolation();if(de&&Ze)return Ge(de,Ze);let Qe=E.findPostconditionViolation();return Qe?g(`postcondition-violation`,{...Qe,trace:[]}):T()},i_=e=>{let t=Math.imul(e^e>>>16,2146121005),n=Math.imul(t^t>>>15,2221713035);return n^n>>>16},a_=(e,t)=>{let n=2166136261,r=1779033703;for(let t=0;t<e.length;t++)n=Math.imul(n^Hn(e[t]),16777619),r=Math.imul(r^Zn(e[t]),1540483477);Wn(e),t[0]=i_(n)||1,t[1]=i_(r)},o_=()=>{let e={slots:/* @__PURE__ */ new Int32Array(8192),used:0},t=(e,t,n)=>{let r=e.length/2-1;for(let i=t&r;;i=i+1&r){let r=e[i*2];if(r===0||r===t&&e[i*2+1]===n)return i}},n=()=>{let n=e.slots,r=new Int32Array(n.length*2);for(let e=0;e<n.length;e+=2){if(n[e]===0)continue;let i=t(r,n[e],n[e+1]);r[i*2]=n[e],r[i*2+1]=n[e+1]}e.slots=r};return{insert:(r,i)=>{e.used*4>=e.slots.length&&n();let a=t(e.slots,r,i);return e.slots[a*2]!==r&&(e.slots[a*2]=r,e.slots[a*2+1]=i,e.used++,!0)}}},s_=(e,t)=>{let n=e.length-1;for(let r=Number(t>>32n)&n;;r=r+1&n){let n=Atomics.load(e,r);if(n===t)return!1;if(n!==0n)continue;let i=Atomics.compareExchange(e,r,0n,t);if(i===0n)return!0;if(i===t)return!1}},c_=()=>({slots:new BigInt64Array(new SharedArrayBuffer(8192)),used:new Int32Array(new SharedArrayBuffer(4))}),l_=(e,t,n)=>{let r=BigInt.asIntN(64,BigInt(t)<<32n|BigInt(n>>>0));return s_(e.slots,r)?(Atomics.add(e.used,0,1),!0):!1},u_=e=>Atomics.load(e.used,0)*2>=e.slots.length,d_=e=>{let t=new BigInt64Array(new SharedArrayBuffer(e.slots.byteLength*2));for(let n of e.slots)n!==0n&&s_(t,n);return{slots:t,used:e.used}},f_=()=>{let e={words:/* @__PURE__ */ new Int32Array(1024),length:0,count:0},t=[],n=/* @__PURE__ */ new Map,r=t=>{if(e.length===e.words.length){let t=new Int32Array(e.words.length*2);t.set(e.words),e.words=t}e.words[e.length++]=t},i=e=>{let i=n.get(e);if(i!==void 0)return r(i);n.set(e,t.length),r(t.length),t.push(e)},a=e=>{if(typeof e==`boolean`)return r(+!!e),!0;if(typeof e==`number`)return(e|0)===e&&(r(2),r(e),!0);if(typeof e==`string`)return r(3),i(e),!0;if(e.kind===`ModelValue`)return r(4),i(e.name),!0;if(e.kind===`Set`)return r(5),r(e.elements.length),e.elements.every(a);if(e.kind===`Function`){let t=jn(e.domain);return t?(r(7),r(t.low),r(e.range.length),e.range.every(a)):(r(6),r(e.domain.length),e.domain.every(a)&&e.range.every(a))}return!1};return{encode:t=>{let n=e.length;return t.every(a)?(e.count++,!0):(e.length=n,!1)},finish:()=>({words:e.words.slice(0,e.length),strings:t,count:e.count})}},p_=e=>t=>{let n=t.words,r={index:0},i=e=>Array.from({length:e},()=>a()),a=()=>{let e=n[r.index++];if(e===0)return!1;if(e===1)return!0;if(e===2)return n[r.index++];if(e===3)return t.strings[n[r.index++]];if(e===4)return Xe(t.strings[n[r.index++]]);if(e===7){let e=n[r.index++],t=n[r.index++],a=Bt({kind:`Interval`,low:e,high:e+t-1});return Qe(a,i(t))}let a=n[r.index++];if(e===5)return Ze(i(a));let o=i(a);return Qe(o,i(a))};return Array.from({length:t.count},()=>Array.from({length:e},()=>a()))};export{W as A,m as B,ks as C,sr as D,lr as E,y as F,e as H,C as I,p as L,ue as M,v as N,Y as O,f as P,T as R,ll as S,xo as T,te as V,tm as _,d_ as a,Fu as b,a_ as c,Jg as d,ug as f,mg as g,og as h,c_ as i,be as j,Be as k,n_ as l,pg as m,f_ as n,l_ as o,fg as p,o_ as r,u_ as s,p_ as t,Yg as u,Wp as v,yo as w,cl as x,Gp as y,w as z};
|