tla-ts 0.0.3-dev.252cf06 → 0.0.3-dev.366c320

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/transfer.cjs CHANGED
@@ -6,21 +6,21 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=/* @__PURE__ */ new WeakMap,n=/* @__PURE__ */ new WeakMap,r={isNextState:!1},i=e=>{r.isNextState=e},a=(e,n)=>(e instanceof Error&&!t.has(e)&&t.set(e,n),e),o=(e,t)=>{r.isNextState&&n.set(e,t)},s=e=>t.get(e)??n.get(e),c=t=>{try{return t()}catch(t){throw a(t,e.error)}},l=e=>{let t=c(e);return t&&{addInitialState:(e,n)=>c(()=>t.addInitialState(e,n)),addState:(e,n,r)=>c(()=>t.addState(e,n,r)),findViolation:()=>c(()=>t.findViolation()),getViolatedProperties:(e,n)=>c(()=>t.getViolatedProperties(e,n))}},u=`TLC threw an unexpected exception.
9
+ const e={success:0,assumptionViolation:10,deadlock:11,safetyViolation:12,livenessViolation:13,assertViolation:14,specEvaluationFailure:75,safetyEvaluationFailure:76,livenessEvaluationFailure:77,specParseError:150,configParseError:151,error:255},t=/* @__PURE__ */ new WeakMap,n=(e,n)=>(e instanceof Error&&!t.has(e)&&t.set(e,n),e),r=e=>t.get(e),i=t=>{try{return t()}catch(t){throw n(t,e.error)}},a=e=>{let t=i(e);return t&&{addInitialState:(e,n)=>i(()=>t.addInitialState(e,n)),addState:(e,n,r)=>i(()=>t.addState(e,n,r)),findViolation:()=>i(()=>t.findViolation()),getViolatedProperties:(e,n)=>i(()=>t.getViolatedProperties(e,n))}},o=`TLC threw an unexpected exception.
10
10
  This was probably caused by an error in the spec or model.
11
11
  See the User Output or TLC Console for clues to what happened.
12
12
  The exception was a java.lang.RuntimeException
13
- : `;var d=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},f=class extends d{failure;constructor(e,t,n){super(e,t),this.name=`TlaSyntaxError`,this.failure=n}},p=class extends d{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},m=class extends d{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}},h=class extends m{constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,o(this,n)}},g=class extends d{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)})`}},_=class extends g{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},v=class extends d{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}};const y=t=>s(t)??(t instanceof f?e.specParseError:t instanceof p?e.configParseError:t instanceof m?e.specEvaluationFailure:e.error),b=/* @__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(`.`)),x=/* @__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`]]),S=/* @__PURE__ */ new Map([[`/=`,`#`],[`=<`,`<=`],[`(+)`,`\\oplus`],[`(-)`,`\\ominus`],[`(.)`,`\\odot`],[`(/)`,`\\oslash`],[`(\\X)`,`\\otimes`]]),ee=/* @__PURE__ */ `-+-> (\\X) <=> |-> ... ::= >>_ (+) (-) (.) (/) == => =< =| << <= <> <- >> >= /\\ \\/ /= [] ]_ |- |= || -> -| ~> .. :: := :> <: @@ ++ -- -. ** // ^^ ^+ ^* ^# %% ## && $$ ?? !! = < > / [ ] ( ) { } | - ~ . : @ , ' ! # % + * ^ & $ ?`.split(` `),te=/* @__PURE__ */ new Map([[`∧`,`/\\`],[`∨`,`\\/`],[`¬`,`~`],[`⇒`,`=>`],[`⟹`,`=>`],[`≡`,`<=>`],[`⇔`,`<=>`],[`∈`,`\\in`],[`∉`,`\\notin`],[`⊆`,`\\subseteq`],[`⊂`,`\\subset`],[`⊇`,`\\supseteq`],[`⊃`,`\\supset`],[`∪`,`\\cup`],[`∩`,`\\cap`],[`×`,`\\X`],[`∀`,`\\A`],[`∃`,`\\E`],[`≠`,`#`],[`≤`,`<=`],[`≥`,`>=`],[`↦`,`|->`],[`→`,`->`],[`⟨`,`<<`],[`⟩`,`>>`],[`□`,`[]`],[`◇`,`<>`],[`≜`,`==`],[`′`,`'`],[`∘`,`\\o`],[`⋅`,`\\cdot`]]),C=/^\\([bB][01]+|[oO][0-7]+|[hH][0-9a-fA-F]+)/,w=/* @__PURE__ */ new Map([[`b`,2],[`o`,8],[`h`,16]]),ne=e=>e.startsWith(`\\`)?parseInt(e.slice(2),w.get(e[1].toLowerCase())):Number(e),re=/-{4,}[ \t]*MODULE\b/,ie=e=>/[A-Za-z0-9_]/.test(e),T=(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&&!x.has(n.slice(0,r.value));)r.value--;let i=x.get(n.slice(0,r.value));return{text:i??`\\`,length:i===void 0?1:r.value+1}}let r=te.get(n);if(r)return{text:r,length:n.length};let i=ee.find(n=>e.startsWith(n,t));return i?{text:S.get(i)??i,length:i.length}:n===`\\`?{text:`\\`,length:1}:void 0},E=e=>e!==void 0&&e>=`0`&&e<=`9`,D=(e,t,n)=>{let r={value:t};for(;r.value<e.length&&n(e[r.value]);)r.value++;return r.value},O=(e,t)=>{if(e[t]!==`<`)return 0;let n=e[t+1]===`+`||e[t+1]===`*`?t+2:D(e,t+1,E);if(n===t+1||e[n]!==`>`)return 0;let r=D(e,n+1,ie),i=r===n+1&&(e[r]===`*`||e[r]===`-`);return D(e,i?r+1:r,e=>e===`.`)-t},k=(e,t)=>t===` `?e+8-e%8:e+1,ae=e=>{let t=re.exec(e);if(!t)throw new f(`Expected a module header such as ---- MODULE Name ----`);let n=[],r=/* @__PURE__ */ new Map,i=e.slice(0,t.index).split(`
14
- `),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=k(o.width,e[o.position]);return k(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]===`
15
- `&&(a.line++,a.lineStart=a.index+1),a.index++},u=t=>new f(`${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===`
16
- `||t===` `||t===` `||t===`\r`){l(1);continue}if(e.startsWith(`\\*`,a.index)){let t=e.indexOf(`
17
- `,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=D(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`,`====`,D(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]===`
18
- `)throw u(`Unterminated string`);if(e[a.index]===`\\`){let t=e[a.index+1];i.push({n:`
19
- `,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=C.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,D(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(b.has(t)?`Keyword`:`Identifier`,n,t.length);continue}let o=O(e,a.index);if(o>0){c(`Step`,e.slice(a.index,a.index+o),o);continue}let d=T(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},oe=/* @__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`]),A=[`<-`,`<<`,`>>`,`=`,`{`,`}`,`,`,`[`,`]`,`(`,`)`],se=e=>{let t=[],n={index:0,line:1};for(;n.index<e.length;){let r=e.slice(n.index),i=/^\s+/.exec(r)?.[0];if(i){n.line+=i.split(`
13
+ : `;var s=class extends Error{constructor(e,t){super(e,{cause:t}),this.name=`TlaError`}},c=class extends s{failure;constructor(e,t,n){super(e,t),this.name=`TlaSyntaxError`,this.failure=n}},l=class extends s{constructor(e,t){super(e,t),this.name=`TlaConfigError`}},u=class extends s{constructor(e,t){super(e,t),this.name=`TlaEvaluationError`}},d=class extends u{exitCode;constructor(t,n=e.error){super(t),this.name=`TlaEvaluationError`,this.exitCode=n}},f=class extends s{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)})`}},p=class extends f{constructor(e=`Assert_failure`){super(`Oops, this seems to be a bug in TLAPM.`,{exception:e}),this.name=`TlaProofError`}},m=class extends s{constructor(e,t){super(e,t),this.name=`TlaUnsupportedError`}};const h=t=>r(t)??(t instanceof c?e.specParseError:t instanceof l?e.configParseError:t instanceof u?e.specEvaluationFailure:e.error),g=/* @__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(`.`)),_=/* @__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`]]),v=/* @__PURE__ */ new Map([[`/=`,`#`],[`=<`,`<=`],[`(+)`,`\\oplus`],[`(-)`,`\\ominus`],[`(.)`,`\\odot`],[`(/)`,`\\oslash`],[`(\\X)`,`\\otimes`]]),y=/* @__PURE__ */ `-+-> (\\X) <=> |-> ... ::= >>_ (+) (-) (.) (/) == => =< =| << <= <> <- >> >= /\\ \\/ /= [] ]_ |- |= || -> -| ~> .. :: := :> <: @@ ++ -- -. ** // ^^ ^+ ^* ^# %% ## && $$ ?? !! = < > / [ ] ( ) { } | - ~ . : @ , ' ! # % + * ^ & $ ?`.split(` `),ee=/* @__PURE__ */ new Map([[`∧`,`/\\`],[`∨`,`\\/`],[`¬`,`~`],[`⇒`,`=>`],[`⟹`,`=>`],[`≡`,`<=>`],[`⇔`,`<=>`],[`∈`,`\\in`],[`∉`,`\\notin`],[`⊆`,`\\subseteq`],[`⊂`,`\\subset`],[`⊇`,`\\supseteq`],[`⊃`,`\\supset`],[`∪`,`\\cup`],[`∩`,`\\cap`],[`×`,`\\X`],[`∀`,`\\A`],[`∃`,`\\E`],[`≠`,`#`],[`≤`,`<=`],[`≥`,`>=`],[`↦`,`|->`],[`→`,`->`],[`⟨`,`<<`],[`⟩`,`>>`],[`□`,`[]`],[`◇`,`<>`],[`≜`,`==`],[`′`,`'`],[`∘`,`\\o`],[`⋅`,`\\cdot`]]),b=/^\\([bB][01]+|[oO][0-7]+|[hH][0-9a-fA-F]+)/,te=/* @__PURE__ */ new Map([[`b`,2],[`o`,8],[`h`,16]]),ne=e=>e.startsWith(`\\`)?parseInt(e.slice(2),te.get(e[1].toLowerCase())):Number(e),re=/-{4,}[ \t]*MODULE\b/,x=e=>/[A-Za-z0-9_]/.test(e),S=(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&&!_.has(n.slice(0,r.value));)r.value--;let i=_.get(n.slice(0,r.value));return{text:i??`\\`,length:i===void 0?1:r.value+1}}let r=ee.get(n);if(r)return{text:r,length:n.length};let i=y.find(n=>e.startsWith(n,t));return i?{text:v.get(i)??i,length:i.length}:n===`\\`?{text:`\\`,length:1}:void 0},ie=e=>e!==void 0&&e>=`0`&&e<=`9`,C=(e,t,n)=>{let r={value:t};for(;r.value<e.length&&n(e[r.value]);)r.value++;return r.value},ae=(e,t)=>{if(e[t]!==`<`)return 0;let n=e[t+1]===`+`||e[t+1]===`*`?t+2:C(e,t+1,ie);if(n===t+1||e[n]!==`>`)return 0;let r=C(e,n+1,x),i=r===n+1&&(e[r]===`*`||e[r]===`-`);return C(e,i?r+1:r,e=>e===`.`)-t},w=(e,t)=>t===` `?e+8-e%8:e+1,oe=e=>{let t=re.exec(e);if(!t)throw new c(`Expected a module header such as ---- MODULE Name ----`);let n=[],r=/* @__PURE__ */ new Map,i=e.slice(0,t.index).split(`
14
+ `),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=w(o.width,e[o.position]);return w(o.width,e[a.index])},l=(e,t,r)=>{let i=s();n.push({kind:e,text:t,line:a.line,column:i,endColumn:i+r-1}),a.index+=r},u=t=>{for(let n=0;n<t;n++)e[a.index]===`
15
+ `&&(a.line++,a.lineStart=a.index+1),a.index++},d=t=>new c(`${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===`
16
+ `||t===` `||t===` `||t===`\r`){u(1);continue}if(e.startsWith(`\\*`,a.index)){let t=e.indexOf(`
17
+ `,a.index);u((t===-1?e.length:t)-a.index);continue}if(e.startsWith(`(*`,a.index)){let t={value:0};do{if(a.index>=e.length)throw d(`Unterminated comment`);e.startsWith(`(*`,a.index)?(t.value++,u(2)):e.startsWith(`*)`,a.index)?(t.value--,u(2)):u(1)}while(t.value>0);continue}if(e.startsWith(`----`,a.index)){let t=C(e,a.index,e=>e===`-`)-a.index;e.slice(a.index+t).trimStart().startsWith(`MODULE`)&&a.moduleDepth++,l(`Separator`,`----`,t);continue}if(e.startsWith(`====`,a.index)){if(l(`ModuleEnd`,`====`,C(e,a.index,e=>e===`=`)-a.index),a.moduleDepth--,a.moduleDepth<=0)break;continue}if(t===`"`){let t=a.line,r=s(),i=[];for(u(1);e[a.index]!==`"`;){if(a.index>=e.length||e[a.index]===`
18
+ `)throw d(`Unterminated string`);if(e[a.index]===`\\`){let t=e[a.index+1];i.push({n:`
19
+ `,t:` `,r:`\r`,f:`\f`}[t]??t),u(2)}else i.push(e[a.index]),u(1)}u(1),n.push({kind:`String`,text:i.join(``),line:t,column:r,endColumn:s()-1});continue}let i=b.exec(e.slice(a.index,a.index+64));if(i){l(`Number`,i[0],i[0].length);continue}if(x(t)){let t=e.slice(a.index,C(e,a.index,x));if(/^\d+$/.test(t)){let n=/^\d+(\.\d+)?/.exec(e.slice(a.index))?.[0]??t;l(n.includes(`.`)?`Decimal`:`Number`,n,n.length);continue}if(t.startsWith(`WF_`)||t.startsWith(`SF_`)){l(`Keyword`,t.slice(0,3),3);continue}let n=r.get(t)??t;r.set(n,n),l(g.has(t)?`Keyword`:`Identifier`,n,t.length);continue}let o=ae(e,a.index);if(o>0){l(`Step`,e.slice(a.index,a.index+o),o);continue}let c=S(e,a.index);if(c)l(`Operator`,c.text,c.length);else throw d(`Unexpected character ${JSON.stringify(t)}`)}let f=s();return n.push({kind:`End`,text:``,line:a.line,column:f,endColumn:f}),n},T=/* @__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`]),E=[`<-`,`<<`,`>>`,`=`,`{`,`}`,`,`,`[`,`]`,`(`,`)`],D=e=>{let t=[],n={index:0,line:1};for(;n.index<e.length;){let r=e.slice(n.index),i=/^\s+/.exec(r)?.[0];if(i){n.line+=i.split(`
20
20
  `).length-1,n.index+=i.length;continue}if(r.startsWith(`\\*`)){let e=r.indexOf(`
21
- `);n.index+=e===-1?r.length:e;continue}if(r.startsWith(`(*`)){let e=r.indexOf(`*)`);if(e===-1)throw new p(`Unterminated comment at line ${n.line}`);n.line+=r.slice(0,e).split(`
22
- `).length-1,n.index+=e+2;continue}let a=/^\d+(?![A-Za-z_])/.exec(r)?.[0];if(a){t.push({kind:`Number`,text:a,line:n.line}),n.index+=a.length;continue}let o=/^[A-Za-z0-9_!]+/.exec(r)?.[0];if(o){t.push({kind:`Word`,text:o,line:n.line}),n.index+=o.length;continue}let s=/^"((?:[^"\\]|\\.)*)"/.exec(r);if(s){t.push({kind:`String`,text:s[1],line:n.line}),n.index+=s[0].length;continue}let c=A.find(e=>r.startsWith(e));if(c){t.push({kind:`Symbol`,text:c,line:n.line}),n.index+=c.length;continue}let l=T(e,n.index);if(!l)throw new p(`Unexpected character ${JSON.stringify(r[0])} at line ${n.line}`);t.push({kind:`Word`,text:l.text,line:n.line}),n.index+=l.length}return t.push({kind:`End`,text:``,line:n.line}),t},ce=e=>{let t=se(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[n.index],o=()=>t[n.index++],s=e=>e.kind===`Word`&&oe.has(e.text),c=e=>{let t=o();if(t.text!==e)throw new p(`Expected ${JSON.stringify(e)} but found ${JSON.stringify(t.text)} at line ${t.line}`)},l=()=>{let e=o();if(e.kind!==`Word`||s(e))throw new p(`Expected a name but found ${JSON.stringify(e.text)} at line ${e.line}`);return e.text},u=()=>a().kind===`Word`&&!s(a()),d=()=>{let e=[];for(;u();)e.push(o().text);return e},f=(e,t)=>{if(r[e]!==void 0)throw new p(`The keyword ${t} appears twice`);r[e]=l()},m=()=>{let e=o();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=[];for(a().text!==`}`&&e.push(m());a().text===`,`;)o(),e.push(m());return c(`}`),{kind:`Set`,elements:e}}if(e.kind===`Word`&&!s(e))return{kind:`ModelValue`,name:e.text};throw new p(`Expected a value but found ${JSON.stringify(e.text)} at line ${e.line}`)},h=()=>{if(a().text!==`[`)return;o();let e=l();return c(`]`),e},g=()=>{for(;u();){let e=o().text;if(a().text===`(`){o();let t=[];for(;a().text!==`)`;)t.push(m()),a().text!==`)`&&c(`,`);o(),c(`=`);let n=h();r.constants.push({name:e,value:m(),args:t,...n&&{module:n}});continue}if(a().text===`<-`){o();let t=h();r.substitutions.push({name:e,target:l(),...t&&{module:t}});continue}c(`=`);let t=h();r.constants.push({name:e,value:m(),...t&&{module:t}})}};for(;a().kind!==`End`;){let e=o();switch(e.text){case`CONSTANT`:case`CONSTANTS`:g();break;case`INIT`:f(`init`,e.text);break;case`NEXT`:f(`next`,e.text);break;case`SPECIFICATION`:f(`specification`,e.text);break;case`SYMMETRY`:f(`symmetry`,e.text);break;case`VIEW`:f(`view`,e.text);break;case`INVARIANT`:case`INVARIANTS`:r.invariants.push(...d());break;case`PROPERTY`:case`PROPERTIES`:r.properties.push(...d());break;case`CONSTRAINT`:case`CONSTRAINTS`:r.constraints.push(...d());break;case`ACTION_CONSTRAINT`:case`ACTION_CONSTRAINTS`:r.actionConstraints.push(...d());break;case`ALIAS`:f(`alias`,e.text);break;case`POSTCONDITION`:case`POSTCONDITIONS`:r.postconditions.push(...d());break;case`_POSSIBLE`:r.possible.push(...d());break;case`_PERIODIC`:f(`periodic`,e.text);break;case`_RL_REWARD`:f(`rlReward`,e.text);break;case`CHECK_DEADLOCK`:{if(i.isSet)throw new p(`The keyword CHECK_DEADLOCK appears twice`);i.isSet=!0;let e=o().text;if(e!==`TRUE`&&e!==`FALSE`)throw new p(`CHECK_DEADLOCK expects TRUE or FALSE but found ${JSON.stringify(e)}`);r.checkDeadlock=e===`TRUE`;break}default:throw new p(`Unexpected ${JSON.stringify(e.text)} at line ${e.line}`)}}if(r.specification!==void 0&&(r.init!==void 0||r.next!==void 0))throw new p(`SPECIFICATION cannot be combined with INIT or NEXT`);return r},le={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:` `}},ue=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},de=e=>e!==void 0&&/^\p{Nd}$/u.test(e),fe=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),pe=e=>{let t=t=>{let n=D(e,t,ue);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=D(e,t,de);if(e.startsWith(`..`,n)&&de(e[n+2]))return{kind:`Constant`,first:t,last:D(e,n+2,de)-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=de(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:D(e,t+1,de)-1,children:[]};if(fe(n))return{kind:`Constant`,first:t,last:D(e,t,fe)-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)},me=e=>{let t=e.length===0?void 0:pe(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=le[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},j=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,M=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),N=e=>typeof e==`object`&&e.kind===`ModelValue`,he=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:j(e)?`set`:`function`,ge=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new h(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},_e={isUsed:!1},ve=(e,t)=>(_e.isUsed=!0,e.writtenKeys=t,e),ye=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[Jt(e.domain,t)]]),be=(e,t,n)=>ve(ze(e,t),n),xe=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(xe);e.writtenKeys=void 0,e.range.forEach(xe)}},Se=e=>e.every(e=>typeof e==`string`),P=(e,t)=>e.length>0&&t.length>0&&Se(e)!==Se(t),Ce=(e,t)=>{_e.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return P(n,r)?at(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=L(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=L(i[e],a[e]);if(t!==0)return t}return 0},we=(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=L(n[e],r[e]);if(t!==0)return t}return 0},F=e=>N(e)?e.type:void 0,Te=(e,t,n)=>{let r=F(e),i=F(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(N(e)&&N(t)){if(r===void 0||i===void 0||r===i)return;throw new m(`Attempted to ${a} the differently-typed model values ${U(e)} and ${U(t)}`)}throw r===void 0?new m(`Attempted to ${a} the typed model value ${U(t)} and the non-model value\n${U(e)}`):new m(`Attempted to ${a}${n?``:` the`} typed model value ${U(e)} and non-model value\n${U(t)}`)},Ee={ranks:Object.create(null),size:0},De=e=>{Ee.ranks=Object.create(null),Ee.size=0,Ie.clear();for(let t of e)Oe(t)},Oe=e=>(Ee.ranks[e]===void 0&&(Ee.ranks[e]=Ee.size++),e),ke=()=>Ee.size,Ae=e=>Ee.ranks[Oe(e)],je=(e,t)=>{if(e===t)return 0;let n=Ee.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},I=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),Me=(e,t)=>(I(e)||I(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),Ne=(e,t,n)=>{if(!I(e))throw new m(`Attempted to ${n} the set ${U(z(e)?B(e):e,!0)} with the value:\n${U(t,!0)}`);if(!I(t))throw new m(`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 m(`Attempted to compare ${U(e,!0)} with the value\n${U(t,!0)}`)},Pe={kind:`InfiniteSet`,name:`Any`},Fe=e=>{throw new m(`Attempted to compare ANY with the value\n${U(e)}`)},L=(e,t)=>{if(e===t)return _e.isUsed&&xe(e),e===Pe?Fe(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return Ce(e,t);if(n===`Set`&&r===`Set`)return we(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&&Te(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Te(e,t,!1),n===`ModelValue`?-1:1;if(e===Pe||t===Pe)return Fe(e===Pe?t:e);if(j(e)&&j(t)&&Me(e,t))return Ne(e,t,`compare`);let i=j(e);if(i!==j(t))throw new m(`Attempted to compare ${he(e)} ${U(e)} with ${he(t)} ${U(t)}`);return i?we(B(e),B(t)):Ce(H(e),H(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return je(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Te(e,t,!1),N(e))return-1;if(N(t))return 1;throw new m(`Attempted to compare ${he(e)} ${U(e)} with ${he(t)} ${U(t)}`)},Ie=/* @__PURE__ */ new Map,Le=e=>{let t=Ie.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Ae(e)};return Ie.set(e,n),n},Re=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0}),ze=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0}),Be=(e,t)=>{if(e===t)return _e.isUsed&&xe(e),e!==Pe||Fe(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Te(e,t,!0),L(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 Ce(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return we(e,t)===0;if(N(e)||N(t))return Te(e,t,!0),N(e)&&N(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return Be(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:Be(e.domain,t.domain)&&Be(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]&&Be(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)=>Be(e,t.factors[n]));let n=j(e)&&j(t)&&!(z(e)&&z(t));if(n&&Me(e,t))return Ne(e,t,`check equality of`)===0;if(n){if(!I(e)){let n=B(e);if(!I(t))return we(n,B(t))===0}return Tn(e)===Tn(t)}return L(e,t)===0},Ve=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>He(e,t[n])),He=(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)&&Ve(e.elements,t.elements):e.kind===`Function`&&t.kind===`Function`?(e.hash===0||t.hash===0||e.hash===t.hash)&&Ve(e.domain,t.domain)&&Ve(e.range,t.range):Tn(e)===Tn(t),Ue=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},We=e=>{if(!M(e))return;let t=H(e);return{domain:t.domain,range:t.range,low:Ue(t.domain)}},Ge=e=>{if(!M(e))return;let t=H(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},Ke=(e,t)=>{if(F(e)!==void 0)throw new m(`Attempted to compare the typed model value ${U(e)} and the non-model value\n${U(t)}`);return 1},qe=(e,t)=>{if(F(e)!==void 0)throw new m(`Attempted to check equality of the typed model value ${U(e)} and the non-model value\n${U(t)}`);return!1},Je=(e,t)=>{let n=F(e);if(n===void 0)return N(t)?e.rank-t.rank:-1;if(!N(t))throw new m(`Attempted to compare the typed model value ${U(e)} and non-model value\n${U(t)}`);let r=F(t);if(r!==void 0&&r!==n)throw new m(`Attempted to compare the differently-typed model values ${U(e)} and ${U(t)}`);return e.rank-t.rank},Ye=(e,t)=>{let n=F(e);if(n===void 0)return N(t)&&e.name===t.name;if(!N(t))throw new m(`Attempted to check equality of typed model value ${U(e)} and non-model value\n${U(t)}`);let r=F(t);if(r!==void 0&&r!==n)throw new m(`Attempted to check equality of the differently-typed model values ${U(e)} and ${U(t)}`);return e.name===t.name},Xe={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`}},Ze=(e,t,n)=>{let r=Xe[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)}`},Qe=(e,t,n)=>{let r=We(n);if(!r){if(N(n))return Ke(n,t);throw new m(`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=()=>$e(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 $e(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 m(`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()},$e=(e,t)=>{for(let n=0;n<e.length;n++){let r=at(e[n],t[n]);if(r!==0)return r}return 0},et=(e,t)=>{let n=H(e);if(e.kind===`Function`&&Yt(n)!==void 0){let r=M(t)?Yt(t):void 0;return r?n.range.length-r.length||$e(n.range,r):Qe({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=Ge(t);if(!r){if(N(t))return Ke(t,e);throw new m(`Attempted to compare record:\n${U(e)}\nwith non-record\n${U(t)}`)}return n.domain.length-r.domain.length||$e(n.domain,r.domain)||$e(n.range,r.range)}return Qe({...n,low:Ue(n.domain)},e,t)},tt=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),nt=(e,t)=>I(e)||I(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),rt=(e,t)=>{let n=tt(t)?t:B(t);return{elements:B(e).elements,otherElements:B(n).elements}},it=(e,t)=>{if(nt(e,t))return L(e,t);if(!tt(e))return it(B(e),t);if(!j(t)){if(N(t))return Ke(t,e);throw new m(`Attempted to compare the set ${U(e)} with the value:\n${U(t)}`)}let n=rt(e,t);return n.elements.length-n.otherElements.length||$e(n.elements,n.otherElements)},at=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return L(e,t);if(N(t))return Ke(t,e);throw new m(Ze(e,t,!1))}return e.kind===`ModelValue`?Je(e,t):M(e)?et(e,t):it(e,t)},ot=(e,t)=>e.every((e,n)=>ut(e,t[n])),st=(e,t,n)=>{let r=We(n);if(!r){if(N(n))return qe(n,t);throw new m(`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)&&ot(e.range,r.range);let i=e.low??r.low;return i===void 0?ot(e.domain,r.domain)&&ot(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new m(`Attempted to compare an integer with non-integer:\n${U(e)}.`);return e===i+t})&&ot(e.range,r.range)},ct=(e,t)=>{let n=H(e);if(e.kind===`Function`&&Yt(n)!==void 0){let r=M(t)?Yt(t):void 0;return r?n.range.length===r.length&&ot(n.range,r):st({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=Ge(t);if(!r){if(N(t))return qe(t,e);throw new m(`Attempted to check equality of record:\n${U(e)}\nwith non-record\n${U(t)}`)}return n.domain.length===r.domain.length&&ot(n.domain,r.domain)&&ot(n.range,r.range)}return st({...n,low:Ue(n.domain)},e,t)},lt=(e,t)=>{if(nt(e,t))return Be(e,t);if(!tt(e))return lt(B(e),t);if(!j(t)){if(N(t))return qe(t,e);throw new m(`Attempted to check equality of the set ${U(e)} with the value:\n${U(t)}`)}let n=rt(e,t);return n.elements.length===n.otherElements.length&&ot(n.elements,n.otherElements)},ut=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(N(t))return qe(t,e);throw new m(Ze(e,t,!0))}return e.kind===`ModelValue`?Ye(e,t):M(e)?ct(e,t):lt(e,t)},dt=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=at(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},ft=(e,t)=>t.some(t=>ut(t,e)),pt=(e,t)=>{try{return Be(e,t)}catch(n){if(!(n instanceof m))throw n;return ut(e,t)}},mt=e=>{for(let t=1;t<e.length;t++)if(L(e[t-1],e[t])>=0)return!1;return!0},ht=e=>{if(e.length<2||mt(e))return Re(e);let t=[...e].sort(L),n=[t[0]];for(let e=1;e<t.length;e++)L(n[n.length-1],t[e])!==0&&n.push(t[e]);return Re(n)},gt=e=>{try{return ht(e)}catch(t){if(!(t instanceof m))throw t;return{kind:`MixedSet`,elements:e}}},_t=Re([]),vt=(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&&L(r[a],t)<0;)a++;a<r.length&&L(r[a],t)===0||i.push(t)}return i.length===n.length?e:Re(i)},yt=(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&&L(r[a],t)<0;)a++;a<r.length&&L(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Re(i)},bt=(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=L(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=Re(i);if(e.hash!==0){let t=e.hash;for(let e=0;e<a.length;e++)t=t+pn(a[e])|0;c.hash=t}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+bn(a[e])|0;c.fingerprint=t}return c},xt=e=>{let t=e.length<2?e:[...e].sort((e,t)=>L(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&L(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return ze(n,r)},St=e=>{let t=xt(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:ve(t,e.map(e=>e[0]))},Ct=[],wt=[],Tt=/* @__PURE__ */ new WeakMap,Et=e=>{let t=Ct[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Ct[e]=n,n},Dt=e=>{if(Gt(e),e.low===1&&e.high>=1)return Et(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Ot=e=>e.length>0&&(e===Ct[e.length]||Tt.has(e)),kt=e=>{let t=B(e).elements;return Ot(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},At=e=>{let t=wt[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return wt[e]=n,n},R=e=>ze(Et(e.length),e),jt=e=>xt(e),Mt=e=>j(e)&&!I(e),Nt=(e,t=!1)=>`UNION(${U(e.base,t)})`,Pt=e=>{if(!Mt(e.base))throw new m(`Attempted to enumerate the nonenumerable set:\n${Nt(e)}`);return B(e.base).elements},Ft=(e,t,n)=>{if(Mt(e))return e;throw new m(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${Nt(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)||It(e.domain)===!0||It(e)===!0;case`RecordSet`:return e.sets.every(z)||It(e)===!0;case`ProductSet`:return e.factors.every(z)||It(e)===!0;case`Union`:return z(e.base)&&B(e.base).elements.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}},It=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=It(e.domain);return t===void 0?void 0:!t&&It(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=It(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}},Lt=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},Rt=(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},zt=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Re(r.map(t=>e[t])));while(Rt(r,e.length))}return t},Bt=e=>{if(typeof e!=`object`)throw new m(`Expected a set but found ${U(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return dt(e.elements);case`Interval`:{let t=Dt(e);return t!==Ct[t.length]&&Tt.set(t,e),t}case`Subset`:{I(e.base)&&Gt(e.base);let t=B(e.base).elements;if(t.length>30)throw new m(`SUBSET of a set with ${t.length} elements is too large to enumerate`);return zt(t)}case`FunctionSet`:{if(V(e))return[];if(I(e.domain))throw new m(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${U(e.domain)}\ncannot be enumerated.`);let t=kt(e.domain);if(t.length>0&&I(e.range))throw new m(`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 Lt(t.map(()=>n)).map(e=>ze(t,e))}case`RecordSet`:{if(V(e))return[];let t=e.sets.map((t,n)=>{if(I(t))throw new m(`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 Lt(t).map(t=>jt(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(V(e))return[];let t=e.factors.map((e,t)=>{if(I(e))throw new m(`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 Lt(t).map(R)}case`FilteredSet`:if(I(e.base))throw new m(`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=Pt(e).flatMap((t,n)=>B(Ft(t,n,e)).elements);return B(gt(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(I(e.left)||I(e.right)))throw new m(`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`&&I(e.left)&&I(e.right))throw new m(`Attempted to enumerate S \\cap T when neither S:\n${U(e.left)}\nnor T:\n${U(e.right)}\nis enumerable`);if(e.operator===`\\`&&I(e.left))throw new m(`Attempted to enumerate S \\ T when S:\n${U(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return bt(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=>Qt(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new m(`Attempted to enumerate the non-enumerable set ${U(e)}`);default:throw new m(`Expected a set but found ${U(e)}`)}},Vt=/* @__PURE__ */ new WeakMap,B=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Re(Bt(e));let t=typeof e==`object`?Vt.get(e):void 0;if(t)return t;let n=Bt(e),r=typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Re(n):ht(n);return typeof e==`object`&&Vt.set(e,r),r},Ht=e=>{if(typeof e!=`object`||Vt.has(e))return B(e).elements;if(e.kind===`Union`)return Pt(e).flatMap((t,n)=>Ht(Ft(t,n,e)));if(e.kind===`FilteredSet`&&!I(e.base))return Ht(e.base).filter(e.test);if(e.kind!==`SetOperation`)return B(e).elements;if(e.operator===`\\cup`)return I(e.left)||I(e.right)?B(e).elements:[...Ht(e.left),...Ht(e.right)];let t=e.operator===`\\`||z(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return I(n)?B(e).elements:Ht(n).filter(t=>Qt(t,r)===(e.operator===`\\cap`))},V=e=>{if(typeof e!=`object`||!j(e))throw new m(`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 m(`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 Pt(e).every((t,n)=>V(Ft(t,n,e)));default:return B(e).elements.length===0}},Ut=(e,t)=>e.reduce((e,n)=>{let r=e*Gt(n);if(r>2147483647)throw new m(t());return r},1),Wt=e=>`Overflow when computing the number of elements in:\n${U(e)}`,Gt=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 m(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new m(`Attempted to compute the number of elements in the overridden value ${U(e)}.`);case`Subset`:{let t=Gt(e.base);if(t>=31)throw new m(Wt(e));return 2**t}case`FunctionSet`:{if(V(e.domain))return 1;if(V(e.range))return 0;let t=Gt(e.range);if(t===1)return 1;let n=Gt(e.domain),r={value:1};for(let i=0;i<n;i++)if(r.value*=t,r.value>2147483647)throw new m(Wt(e));return r.value}case`RecordSet`:return V(e)?0:Ut(e.sets,()=>Wt(e));case`ProductSet`:return V(e)?0:Ut(e.factors,()=>`Overflow when computing the number of elements in ${U(e)}`);default:return B(e).elements.length}},Kt=e=>`Attempted to check if the set ${U(e)}is finite.`,qt=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new m(`Attempted to check if the ${he(e)} ${U(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new m(`Attempted to check if the function:\n${U(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return qt(e.base)&&V(e.base);case`Subset`:return qt(e.base);case`FunctionSet`:{let t=qt(e.domain);if(t&&V(e.domain))return!0;let n=qt(e.range);return n&&V(e.range)?!0:n&&(t||Gt(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(!qt(e))n.isAllFinite=!1;else if(V(e))return!0;return n.isAllFinite}case`Union`:if(!Mt(e.base))throw new m(`Attempted to check if the nonenumerable set:\n${Nt(e)}\nis a finite set.`);return B(e.base).elements.every(qt);case`SetOperation`:if(e.operator===`\\cup`)return qt(e.left)&&qt(e.right);if(e.operator===`\\cap`){if(!qt(e.left)&&!qt(e.right))throw new m(Kt(e));return!0}if(qt(e.left))return!0;if(!qt(e.right))throw new m(Kt(e));return!1;case`FilteredSet`:if(!qt(e.base))throw new m(`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}},Jt=(e,t)=>{let n={low:0,high:e.length-1};for(;n.low<=n.high;){let r=n.low+n.high>>1,i=L(e[r],t);if(i===0)return r;i<0?n.low=r+1:n.high=r-1}return-1},Yt=e=>{if(typeof e!=`object`||!M(e))return;let t=H(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},Xt=(e,t)=>`Attempted to check if the value ${U(e)} is an element of ${U(t)}`,Zt=(e,t)=>{let n=`Attempted to check if the value:\n${U(e)}\nis an element of the`;if(!M(t))return`${n} ${he(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)}`},Qt=(e,t)=>{if(!j(t))throw new m(Zt(e,t));switch(t.kind){case`Set`:try{return Jt(t.elements,e)!==-1}catch(n){if(!(n instanceof m))throw n;return ft(e,t.elements)}case`MixedSet`:return ft(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!N(e))throw new m(`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(N(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new m(`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(!j(e))throw new m(Xt(e,t));return B(e).elements.every(e=>Qt(e,t.base));case`FunctionSet`:{if(!M(e)){if(N(e))return!1;throw new m(Xt(e,t))}let n=H(e),r=Ue(n.domain);return(r===void 0?pt(t.domain,Re(n.domain)):pt({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>Qt(e,t.range))}case`RecordSet`:{let n=M(e)?H(e):void 0;if(!n||!Se(n.domain)){if(N(e))return!1;throw new m(`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=Jt(n.domain,e);return i!==-1&&Qt(n.range[i],t.sets[r])})}case`ProductSet`:{let n=M(e)?Yt(e):void 0;if(n===void 0){if(M(e)&&H(e).domain.every(e=>typeof e==`number`)||N(e))return!1;throw new m(`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)=>Qt(e,t.factors[n]))}case`FilteredSet`:return Qt(e,t.base)&&t.test(e);case`Union`:if(!Mt(t.base))throw new m(`Attempted to check if:\n ${U(e)}\nis an element of the non-enumerable set:\n ${Nt(t)}`);return B(t.base).elements.some(t=>Qt(e,t));case`SetOperation`:return t.operator===`\\cup`?Qt(e,t.left)||Qt(e,t.right):Qt(e,t.left)&&Qt(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Yt(e);if(n===void 0){if(N(e))return!1;throw new m(Xt(e,t))}return n.every(e=>Qt(e,t.base))}default:throw new m(Zt(e,t))}},$t=(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?Qt(e,n):e.range.every((e,r)=>$t(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)||Gt(e.domain);let t=kt(e.domain);return ze(t,t.map(t=>e.apply(t)))}throw new m(`Expected a function but found ${U(e)}`)},en=/* @__PURE__ */ new WeakSet,tn=e=>(en.add(e),e),nn=(e,t)=>typeof e==`object`&&en.has(e)?`In applying the function\n${me(U(e))},\nthe first argument is:\n${me(U(t))}\nwhich is not in its domain.\n`:`Attempted to apply function ${U(e)} to ${U(t)}, which is not in its domain`,rn=(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 Jt(e,t)},an=(e,t,n)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!Qt(t,e.domain))throw new m(en.has(e)?nn(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 m(`Attempted to apply ${U(e)}, which is not a function`);let r=rn(e.domain,t);if(r===-1)throw new m(n?.(e)??nn(e,t));return e.range[r]},on=e=>Ot(e)?Tt.get(e)??At(e.length):void 0,sn=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=H(e).domain;return on(t)??Re(t)},cn=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!z(e.domain))){if(!Qt(t,e.domain))return e;let r=n(e.apply(t));return{kind:`LazyFunction`,domain:e.domain,apply:n=>pt(t,n)?r:e.apply(n),source:e.source}}let i=H(e),a=rn(i.domain,t);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=ze(i.domain,o);if(l.writtenKeys=i.writtenKeys,i.hash!==0){let e=i.domain[a];l.hash=s===c?i.hash:i.hash-mn(e,s)+mn(e,c)|0}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-xn(e,s)+xn(e,c)|0}return l},ln=/* @__PURE__ */ new WeakMap,un=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},dn=(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 un(t)},pn=e=>un(gn(e)+2654435769|0),mn=(e,t)=>un(Math.imul(gn(e),668265261)+gn(t)|0),hn=e=>{if(e.kind===`ModelValue`)return un(dn(fn(e.name),109));if(j(e)){if(!z(e))return fn(Tn(e));let t=B(e).elements,n=1940243425;for(let e=0;e<t.length;e++)n=n+pn(t[e])|0;return n}let t=H(e),n=1725019383;for(let e=0;e<t.domain.length;e++)n=n+mn(t.domain[e],t.range[e])|0;return n},gn=e=>{if(typeof e==`number`)return un(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=hn(e)),e.hash;let t=ln.get(e);if(t!==void 0)return t;let n=hn(e);return ln.set(e,n),n},_n=/* @__PURE__ */ new WeakMap,vn=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},yn=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return vn(t)},bn=e=>vn(Cn(e)+2135587861|0),xn=(e,t)=>vn(Math.imul(Cn(e),374761393)+Cn(t)|0),Sn=e=>{if(e.kind===`ModelValue`)return vn(yn(e.name)^60);if(j(e)){if(!z(e))return yn(Tn(e));let t=B(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+bn(t[e])|0;return n}let t=H(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+xn(t.domain[e],t.range[e])|0;return n},Cn=e=>{if(typeof e==`number`)return vn(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return yn(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=Sn(e)),e.fingerprint;let t=_n.get(e);if(t!==void 0)return t;let n=Sn(e);return _n.set(e,n),n},wn=/* @__PURE__ */ new WeakMap,Tn=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=wn.get(e);if(t!==void 0)return t;let n=En(e);return wn.set(e,n),n},En=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${Tn(e.base)}>`;if(e.kind===`FilteredSet`&&!z(e))throw new m(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(j(e))return z(e)?`{${B(e).elements.map(Tn).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let t=H(e);return`(${t.domain.map((e,n)=>`${Tn(e)}:${Tn(t.range[n])}`).join(`,`)})`},Dn=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,On=e=>e.reduce((e,t)=>e===0?0:e*Gt(t),1),kn=e=>{if(e.kind===`Subset`)return Gt(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)&&Gt(e.domain)===0)return Re([ze([],[])]);let t=e.kind===`FunctionSet`?Gt(e.range)**Gt(e.domain):On(e.kind===`RecordSet`?e.sets:e.factors);return t===0?_t:t<=1999?B(e):void 0},An=(e,t)=>{if(t)return kn(e);if(z(e))try{return kn(e)}catch(e){if(e instanceof m)return;throw e}},jn=(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 Nt(e,t)}},Mn=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 Dn(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=An(e,t);return n?r(n):jn(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 t=H(e);return t.domain.every((e,t)=>e===t+1)?`<<${t.range.map(r).join(`, `)}>>`:t.domain.every(e=>typeof e==`string`&&Mn(e))?`[${(n||t.hash!==0||t.fingerprint!==0?t.domain.map((e,n)=>[e,t.range[n]]):ye(t)).map(e=>`${String(e[0])} |-> ${r(e[1])}`).join(`, `)}]`:`(${t.domain.map((e,n)=>`${r(e)} :> ${r(t.range[n])}`).join(` @@ `)})`}}},Nn=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},Pn=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=gn(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||He(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||He(i[e],n))return i[e]}return n.kind===`Set`?Nn(n.elements,t):(Nn(n.domain,t),Nn(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}},Fn=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`,In=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),Ln=(e,t)=>In.has(e)?new m(t):new h(t),Rn=e=>typeof e==`object`&&e.kind===`Operator`,G=(e,t,n)=>{let r=e[t];if(r===void 0||Rn(r))throw Ln(n,`${n} expects a value as argument ${t+1}`);return r},zn=(e,t,n)=>{let r=G(e,t,n);if(typeof r!=`number`)throw Ln(n,`${n} expects an integer but received ${U(r)}`);return r},Bn=(e,t,n)=>{let r=G(e,t,n);if(typeof r!=`boolean`)throw Ln(n,`${n} expects a boolean but received ${U(r)}`);return r},Vn=(e,t,n)=>{let r=G(e,t,n);if(!j(r))throw Ln(n,`${n} expects a set but received ${U(r)}`);return r},Hn=(e,t,n)=>{let r=Vn(e,t,n);if(!z(r))throw Ln(n,`${n} cannot enumerate the non-enumerable set ${U(r)}`);return r},Un=(e,t,n)=>B(Hn(e,t,n)),Wn=(e,t,n)=>Un(e,t,n).elements,Gn=(e,t,n)=>{let r=G(e,t,n),i=Yt(r);if(!i)throw Ln(n,`${n} expects a sequence but received ${U(r)}`);return i},Kn=(e,t,n)=>{let r=G(e,t,n);if(!M(r))throw Ln(n,`${n} expects a function but received ${U(r)}`);return H(r)},qn=(e,t,n)=>{let r=e[t];if(r===void 0||!Rn(r))throw Ln(n,`${n} expects an operator as argument ${t+1}`);return r},Jn=(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}),Yn=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Xn=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),Zn=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(G(n,0,e),G(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Qn=e=>e>2147483647||e<-2147483648,$n=e=>new h(`Overflow when computing ${e}`),er={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`},nr={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`},rr=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 er[e.kind];let t=e.domain;return t.every((e,t)=>e===t+1)?`TupleValue`:t.every(e=>typeof e==`string`)?`RecordValue`:`FcnRcdValue`},ir=e=>nr[rr(e)],ar=(e,t)=>new m(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),or=(e,t)=>{let n=n=>(...r)=>{try{return n(...r)}catch(n){throw n instanceof m&&(e.isLazy===!0||!(n instanceof h))?ar(t,n.message):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},sr=(e,t)=>{if(typeof e!=`number`)throw ar(t,`Cannot cast tlc2.value.impl.${rr(e)} to tlc2.value.impl.IntValue`);return e},cr=(e,t,n)=>`public static tlc2.value.impl.${t} tlc2.module.Integers.${e}(${Array.from({length:n},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,lr=(e,t,n)=>{let r=cr(t,`IntValue`,2);return Zn(e,(t,i)=>{let a=sr(t,r),o=sr(i,r),s=n(a,o);if(Qn(s))throw $n(`${a}${e}${o}`);return s})},ur=(e,t,n)=>{if(typeof e!=`number`)throw new h(`The ${t} argument of ${n} should be an integer, but instead it is:\n${U(e)}`);return e},dr=(e,t)=>Zn(e,(n,r)=>t(ur(n,`first`,e),ur(r,`second`,e))),fr=(e,t,n)=>({...Xn(e,t,n),isLazy:!0}),pr=(e,t,n)=>{let r=qn(e,t,n);return()=>r.call([])},mr=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),hr=()=>({bool:Xa,condition:(e,t)=>{if(typeof e!=`boolean`)throw za(t,e);return e},conjunct:(e,t,n)=>{if(typeof e!=`boolean`)throw Ba(t,n,e);return e},apply:an,tuple:R,set:gt,record:ze,writtenRecord:be,equal:Be,enumerate:to,unassigned:(e,t)=>{throw new m(`The variable ${e} is not assigned at ${J(t)}`)},primeOutsideAction:e=>{throw new m(`A primed expression appears outside an action at ${J(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)=>qa(e,t,n[r]),e.scope),state:e.state,next:e.next})}),gr={value:void 0},_r=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),vr=e=>`local${e.counter++}`,yr=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),Fn(e).forEach(e=>yr(e,t)),t),br=(e,t,n)=>{let r=_r(e,Y(t,e.environment)),i=yr(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=_r(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(()=>vr(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${Cr(e,t.set,s)}, ${_r(e,t.set)});`),u=t.bounds.map(t=>{let n=vr(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${Cr(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=vr(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})`},Sr=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${Cr(e,r[0],n)}, "the left side of =>") ? bool(${Cr(e,r[1],n)}, "the right side of =>") : true)`;if(W(t))return br(e,t,n);let i=go(t.operator,e.environment);if(i?.kind!==`Builtin`)return br(e,t,n);if(i.name===`DOMAIN`)return`${_r(e,Ha(t))}(${Cr(e,r[0],n)})`;if(i.name===`TLCEval`)return br(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${_r(e,Ua(t,i))}(${Cr(e,r[0],n)}, ${Cr(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&ss(r[0],a))return`${_r(e,i.evaluateUnary)}(${Cr(e,r[0],n)})`;let o=r.length===2&&ss(r[0],a)&&ss(r[1],a);return i.evaluateBinary&&o?`${_r(e,i.evaluateBinary)}(${Cr(e,r[0],n)}, ${Cr(e,r[1],n)})`:br(e,t,n)},Cr=(e,t,n)=>{let r=(t,r=n)=>Cr(e,t,r);if(Zo(t)&&Ko(t,e.environment))return br(e,t,n);switch(t.kind){case`Number`:return Po(t.value)?String(t.value):br(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 br(e,t,n);let i=Eo(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=_r(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?_r(e,i.value):br(e,t,n)}case`Apply`:return Sr(e,t,n);case`And`:{let n=_r(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)}, ${_r(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{xs(t.function);let e=r(t.function);return t.args.length===1?`apply(${e}, ${r(t.args[0])})`:`apply(${e}, tuple([${t.args.map(e=>r(e)).join(`, `)}]))`}case`FieldAccess`:return`apply(${r(t.record)}, ${JSON.stringify(t.field)}, ${_r(e,Va(t))})`;case`Record`:{let i=[...t.fields].sort((e,t)=>L(e.name,t.name));if(i.some((e,t)=>t>0&&i[t-1].name===e.name))return br(e,t,n);let a=_r(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}, ${_r(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=_r(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):br(e,t,n);default:return br(e,t,n)}},wr=(e,t)=>{if(!mr.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=Cr(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(`
23
- `)}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${r}; };`;gr.value??=hr();let o=gr.value,s=Object.keys(o);return Function(...s,...i,a)(...Object.values(o),...n.references)},Tr={kind:`Local`},Er=/* @__PURE__ */ new WeakMap,Dr=e=>{let t=e.lastIndexOf(`@`);return t>0&&t<e.length-1},Or=new Map([`~>`,`-+->`,`\\cdot`].map(e=>[e,{key:e,arity:2}])),kr=(e,t)=>e.line<t.line||e.line===t.line&&e.column<t.column,Ar=e=>e.kind===`Operator`?e.params.length:0,jr=e=>e.name.includes(`!`),Mr=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n},Nr=(e,t,n=0)=>t.reduce((e,t)=>({name:t,arity:n,parent:e}),e),Pr=(e,t)=>t.reduce((e,t)=>({name:t.name,arity:t.arity,parent:e}),e),Fr=e=>e.kind===`Name`?[e.name]:e.names,Ir=e=>e.flatMap(e=>Fr(e.pattern)),Lr=(e,t)=>{let n=t.definitions.get(e);return n!==void 0&&(n===t.self?n.kind===`Function`||n.isRecursive:n.isRecursive||kr(n.location,t.location))?n:void 0},Rr=(e,t)=>{let n=Lr(e,t);return n?{key:t.getKey(n),arity:Ar(n)}:t.imported.get(e)},zr=e=>e[0].toLowerCase()===e[0].toUpperCase()&&e[0]!==`_`&&(e[0]<`0`||e[0]>`9`),Br=e=>e.startsWith(`<`)&&(e[1]>=`0`&&e[1]<=`9`||e[1]===`*`),Vr=(e,t,n,r)=>{let i=e.location,a=Er.get(e);if(a!==void 0)return a;if(Dr(t))return e.kind===`Apply`?e.args.length:0;if(Br(t))return 0;let o=Mr(n,t);if(o&&e.kind!==`OperatorReference`&&(e.resolution=Tr),o)return o.arity;let s=Rr(t,r);if(s)return e.kind===`Identifier`?e.name=s.key:e.operator=s.key,Er.set(e,s.arity),s.arity;let c=t.slice(0,t.indexOf(`!`));if(c!==``&&(Mr(n,c)!==void 0||Rr(c,r)!==void 0||r.facts.has(c)))return e.kind===`Apply`?e.args.length:0;let l=`at line ${i.line}, column ${i.column}`;throw new f(zr(t)?`Could not find declaration or definition of symbol '${t}' ${l}`:`Unknown operator: \`${t}' ${l}`)},Hr=(e,t,n)=>(e.forEach(e=>q(e.set,t,n)),e.reduce((e,t)=>Nr(e,Fr(t.pattern)),t)),Ur=(e,t)=>e.kind===`Identifier`&&e.name===t&&W(e)||Fn(e).some(e=>Ur(e,t)),Wr=(e,t)=>{e.kind===`FunctionConstruction`&&Ur(e.body,t)&&(e.isRecursive=!0),Fn(e).forEach(e=>Wr(e,t))},Gr=(e,t,n)=>{let r=Nr(t,e.kind===`Function`?[e.name]:[]);e.kind===`Function`?(q(e.body,Hr(e.bounds,r,n),n),Wr(e.body,e.name)):q(e.body,Pr(r,e.params),n)},Kr=(e,t,n)=>{let r=e.filter(e=>e.isRecursive).reduce((e,t)=>({name:t.name,arity:Ar(t),parent:e}),t);return e.reduce((e,t)=>(jr(t)||Gr(t,e,n),{name:t.name,arity:Ar(t),parent:e}),r)},qr=(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 f(`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 f(`Argument number ${t+1} to operator '${e.name}' should be a ${a.arity}-parameter operator at line ${o.line}, column ${o.column}`)},Jr=e=>e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:void 0,Yr=(e,t,n)=>{let r=Mr(t,e.operator)?void 0:Lr(e.operator,n),i=Vr(e,e.operator,t,n);if(i!==e.args.length)throw new f(`The operator ${e.operator} requires ${i} arguments at line ${e.location.line}, column ${e.location.column}`);e.args.forEach((e,i)=>{let a=Jr(e),o=a===void 0||Mr(t,a)?void 0:Lr(a,n),s=Xr(e,t,n);r&&qr(r,i,e,s,o)})},Xr=(e,t,n)=>e.kind===`Identifier`?Vr(e,e.name,t,n):e.kind===`OperatorReference`?Vr(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=Vr(e,e.name,t,n);if(r>0)throw new f(`The operator ${e.name} requires ${r} arguments at line ${e.location.line}, column ${e.location.column}`);return}case`OperatorReference`:Vr(e,e.operator,t,n);return;case`Apply`:Yr(e,t,n);return;case`Lambda`:q(e.body,Nr(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,Kr(e.definitions,t,n),n);return;case`Forall`:case`Exists`:case`FunctionConstruction`:q(e.body,Hr(e.bounds,t,n),n);return;case`UnboundedQuantifier`:q(e.body,Nr(t,e.names),n);return;case`Choose`:e.set&&q(e.set,t,n),q(e.body,Nr(t,Fr(e.pattern)),n);return;case`SetEnumeration`:case`Tuple`:r(e.elements);return;case`SetFilter`:q(e.predicate,Hr([e.bound],t,n),n);return;case`SetMap`:q(e.expression,Hr(e.bounds,t,n),n);return;case`FunctionSet`:r([e.domain,e.range]);return;case`Record`:case`RecordSet`:if(new Set(e.fields.map(e=>e.name)).size<e.fields.length)throw new f(`Non-unique fields in constructor at line ${e.location.line}, column ${e.location.column}`);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=>Xr(e,t,n))}},Zr=(e,t,n)=>(e.set&&q(e.set,t,n),{name:e.name,arity:e.arity,parent:t}),Qr=(e,t,n)=>{let r=e.assumptions.reduce((e,t)=>t.kind===`NewSymbol`?Zr(t,e,n):(t.kind===`AssumeProve`?Qr(t,e,n):q(t,e,n),e),t);return q(e.conclusion,r,n),r},$r=(e,t,n)=>e.kind===`AssumeProve`?Qr(e,t,n):(q(e,t,n),t),ei=(e,t,n)=>{e?.kind===`Steps`&&e.steps.reduce((e,t)=>ti(t,e,n),t)},ti=(e,t,n)=>{let r=e.body;switch(r.kind){case`Assert`:{let i=$r(r.statement,t,n);return ei(e.proof,i,n),r.isSuffices?i:t}case`Define`:return Kr(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 Nr(Hr(r.bounds,t,n),r.names);case`Pick`:{let i=Nr(Hr(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}},ni=(e,t)=>{let n=e.name!==void 0&&e.statement.kind!==`AssumeProve`?void 0:$r(e.statement,void 0,t);ei(e.proof,n,t)},ri=(e,t)=>new f(`Multiply-defined symbol '${e}' at line ${t.line}, column ${t.column}`),ii=(e,t,n,r)=>t.reduce((e,t)=>{if(Mr(e,t)||n(t))throw ri(t,r);return{name:t,arity:0,parent:e}},e),ai=(e,t,n,r)=>(e.forEach(e=>si(e.set,t,n)),e.reduce((e,t)=>ii(e,Fr(t.pattern),n,r),t)),oi=(e,t,n)=>{if(e.kind===`Function`){let r=Nr(t,[e.name]),i=ai(e.bounds,r,n,e.location);si(e.body,i,n);return}let r=ii(t,e.params.map(e=>e.name),n,e.location);si(e.body,r,n)},si=(e,t,n)=>{let r=e.location;switch(e.kind){case`Lambda`:si(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(Mr(e,t.name)||n(t.name))throw ri(t.name,t.location);return oi(t,Nr(e,i),n),Nr(e,[t.name])},t);si(e.body,ii(a,(e.instances??[]).flatMap(e=>e.name===void 0?[]:[e.name]),n,r),n);return}case`Forall`:case`Exists`:case`FunctionConstruction`:si(e.body,ai(e.bounds,t,n,r),n);return;case`SetFilter`:si(e.predicate,ai([e.bound],t,n,r),n);return;case`SetMap`:si(e.expression,ai(e.bounds,t,n,r),n);return;case`UnboundedQuantifier`:si(e.body,ii(t,e.names,n,r),n);return;case`Choose`:e.set&&si(e.set,t,n),si(e.body,ii(t,Fr(e.pattern),n,r),n);return;default:Fn(e).forEach(e=>si(e,t,n))}},ci=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}))],li=(e,t)=>{let n=/* @__PURE__ */ new Map;ci(e).sort((e,t)=>kr(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)&&!Or.has(e))return!1;let r=t.importedAt.get(e);return r===void 0||kr(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 ri(n.name,n.location)}));let i=e=>t=>(n.get(t)??[]).some(t=>t.isRecursive||kr(t.location,e))||r(t,e);e.definitions.forEach(e=>oi(e,void 0,i(e.location))),e.assumptions.forEach(e=>si(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=>si(e.expression,n,t))})},ui=(e,t)=>{let n=new Map([...Or,...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},di=(e,t,n,r)=>{let i=Pr(void 0,e.params),a={imported:ui(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 f(`Identifier '${n}' is not a legal target of a substitution ${s}`)}),new Map(t.map(t=>{let n=t.name;if(!o.has(n)&&!Mr(i,n)&&!Rr(n,a))throw new f(`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(Vr(r,r.name,i,a)!==t.arity)throw new f(`An operator must be substituted for symbol '${n}', and it must have arity ${t.arity} ${s}`);return[n,r]}))},fi=(e,t)=>{let n=ui(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});e.definitions.forEach(e=>Gr(e,void 0,i(e.location,e))),e.assumptions.forEach(e=>q(e.expression,void 0,i(e.location,void 0))),e.theorems.forEach(e=>ni(e,i(e.location,void 0)))},pi=/* @__PURE__ */ new WeakSet,mi=/* @__PURE__ */ new WeakSet,hi=(e,t,n=/* @__PURE__ */ new Set)=>{let r=xi(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},gi=(e,t)=>e.map(e=>({pattern:e.pattern,set:t(e.set)})),_i=/* @__PURE__ */ new WeakMap,vi=e=>_i.get(e)??e.name,yi=(e,t)=>(vi(t)!==e.name&&_i.set(e,vi(t)),e),bi=(e,t)=>yi(e.kind===`Function`?{...e,bounds:gi(e.bounds,e=>t(e,[])),body:t(e.body,Ir(e.bounds))}:{...e,body:t(e.body,e.params.map(e=>e.name))},e),xi=(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=>bi(e,(e,r)=>t(e,[...n,...r]))),body:t(e.body,n)}}case`Forall`:case`Exists`:case`FunctionConstruction`:return{...e,bounds:gi(e.bounds,n),body:t(e.body,Ir(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,Fr(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,Fr(e.bound.pattern))};case`SetMap`:return{...e,bounds:gi(e.bounds,n),expression:t(e.expression,Ir(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=>({name:e.name,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)}}},Si=`LAMBDA`,Ci=(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 xi(e,(e,n)=>(r.push(...Ci(e,n.length===0?t:/* @__PURE__ */ new Set([...t,...n]))),e)),r},wi=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}},Ti=(e,t,n)=>new Map([...e,...t.map(e=>[e,n(e)])]),Ei=(e,t)=>e.kind===`Name`?{kind:`Name`,name:t(e.name)}:{kind:`Tuple`,names:e.names.map(t)},Di=(e,t)=>e.map(e=>({pattern:Ei(e.pattern,t),set:e.set})),Oi=(e,t)=>e.kind===`Function`?{...e,bounds:Di(e.bounds,t)}:{...e,params:e.params.map(e=>({name:t(e.name),arity:e.arity}))},ki=(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=>yi({...Oi(e,n),name:n(e.name)},e))};case`Forall`:case`Exists`:case`FunctionConstruction`:case`SetMap`:return{...e,bounds:Di(e.bounds,n)};case`UnboundedQuantifier`:return{...e,names:e.names.map(n)};case`Choose`:return{...e,pattern:Ei(e.pattern,n)};case`SetFilter`:return{...e,bound:{pattern:Ei(e.bound.pattern,n),set:e.bound.set}};default:return e}},Ai=e=>`${e}@ENABLED`,ji=(e,t)=>e.modes.get(t)??e,Mi=(e,t,n)=>e.kind===`Identifier`&&!n.has(e.name)&&!W(e)&&t.instantiation.variables.has(e.name),Ni=(e,t,n)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>Ni(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`)return;if(Mi(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?Ni(r.body,t,/* @__PURE__ */ new Map):void 0},Pi=(e,t,n)=>{if(t.mode===`Normal`)return;if(t.mode===`Primed`)return Mi(e,t,n)&&e.kind===`Identifier`?{kind:`Identifier`,name:Ai(e.name),location:e.location}:void 0;if(e.kind===`Prime`)return{...e,expression:zi(e.expression,ji(t,`Primed`),n)};if(e.kind===`AngleAction`){let r=e.location;return{kind:`And`,operands:[zi(e.action,t,n),{kind:`Apply`,operator:`#`,args:[{kind:`Prime`,expression:zi(e.subscript,ji(t,`Primed`),n),location:r},zi(e.subscript,t,n)],location:r}],location:r}}if(e.kind!==`Unchanged`)return;let r=Ni(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:Ai(r),location:e.location},location:e.location},zi({kind:`Identifier`,name:r,location:e.location},t,n)],location:e.location})),location:e.location}},Fi=(e,t)=>({kind:`Identifier`,name:e,location:t,resolution:{kind:`Local`}}),Ii=(e,t)=>e.map(e=>Fi(e.name,t)),Li=(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:[...Ii(t,r),...i.map(e=>Fi(e,r))],location:r},location:r}},Ri=(e,t)=>e.instantiation.isParameterized(t)?Vi(e,t):void 0,zi=(e,t,n)=>{let r=e=>zi(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:zi(e.expression,ji(t,`Enabled`),n)};if((e.kind===`WeakFairness`||e.kind===`StrongFairness`)&&t.mode===`Normal`)return{...e,subscript:r(e.subscript),action:r(e.action),enabled:zi(e.enabled??{kind:`AngleAction`,action:e.action,subscript:e.subscript,location:e.location},ji(t,`Enabled`),n)};let s=Pi(e,t,n);if(s)return s;if(e.kind===`Identifier`&&o(e.name)){let n=i.substitutions.get(e.name);if(n)return pi.add(n),n;let r=Ri(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&&Ar(o)>0?Li(r,a,Ar(o),e.location):{kind:`Apply`,operator:r,args:Ii(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||mi.has(e),c=e=>(s&&mi.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:Si,params:o.params.map(e=>({name:e,arity:0})),body:o.body,isLocal:!0,isRecursive:!1,location:o.location}],body:{...e,operator:Si,args:n,resolution:{kind:`Local`}},location:e.location};if(o)throw new f(`The operator ${e.operator} can only be substituted by an operator at line ${e.location.line}, column ${e.location.column}`);let l=Ri(t,e.operator);return l===void 0?c({...e,args:n}):{...e,operator:l,args:[...Ii(a,e.location),...n]}}if(e.kind===`OperatorReference`&&o(e.operator)){let n=Ri(t,e.operator);if(n===void 0)return e;let r=i.getDefinition(e.operator);return a.length>0&&r?Li(n,a,Ar(r),e.location):{...e,operator:n}}let c=wi(t),l=xi(e,(e,i)=>i.length===0?r(e):zi(e,t,Ti(n,i,c)));return ki(l,n,c)},Bi=(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:Fi(e.name,n),location:n},isLocal:e.isLocal,isRecursive:!1,location:e.location},Vi=(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(i.name,n=>{e.copies.set(t,n);let a=wi(e),o=Oi(bi(i,(t,n)=>zi(t,e,Ti(/* @__PURE__ */ new Map,n,a))),a);return Bi(o,r.params,i.location)}):t},Hi=e=>{let t=/* @__PURE__ */ new Map,n=new Set([...e.substitutions.values()].flatMap(e=>Ci(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=>Ri(i,e)??e,getQualifiedKey:t=>{let n=Ri(i,t);if(n!==void 0)return n;let r=e.getDefinition(t);return r?e.addDefinition(r.name,()=>Bi(r,e.params,r.location)):t}}},Ui=e=>e.kind===`Let`&&e.instances!==void 0||Fn(e).some(Ui),Wi=(e,t,n)=>{let r=e.kind===`Let`?[...n,...e.definitions]:n,i=xi(e,e=>Wi(e,t,r));return i.kind!==`Let`||!i.instances?i:{kind:`Let`,definitions:i.instances.reduce((e,n)=>{let i=e.findIndex(e=>kr(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}},Gi=e=>e.name===void 0&&e.statement.kind!==`AssumeProve`?e.statement:void 0,Ki=(e,t)=>e.definitions.some(e=>Ui(e.body))||e.assumptions.some(e=>Ui(e.expression))||e.theorems.some(e=>{let t=Gi(e);return t!==void 0&&Ui(t)})?{...e,definitions:e.definitions.map(e=>bi(e,e=>Wi(e,t,[]))),assumptions:e.assumptions.map(e=>({...e,expression:Wi(e.expression,t,[])})),theorems:e.theorems.map(e=>{let n=Gi(e);return n===void 0?e:{...e,statement:Wi(n,t,[])}})}:e,qi=/* @__PURE__ */ new WeakMap,Ji=/* @__PURE__ */ new WeakMap,Yi=(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},Xi=(e,t,n)=>{let r=e.slice();return r[t]=n,r},Zi=(t,n)=>{let r=X(t,n);if(typeof r==`boolean`)return r;try{return Xa(r,`the action at ${J(t)}`)}catch(t){throw n.next===void 0?t:a(t,e.error)}},Qi=e=>e===`=`||e===`\\in`||e===`\\subseteq`,$i=(e,t,n)=>{let r=n?qi:Ji,i=r.get(e);if(i)return i;let a=Da(e,t,n);return r.set(e,a),a},ea=(e,t)=>{if(t.constants.has(e))return;let n=Za(e,t);return n?.kind===`Operator`&&n.params.length===0?n:void 0},ta=(e,t,n,r=/* @__PURE__ */ new Set)=>{if(e.kind===`Prime`&&n)return ta(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=ea(e.name,t);if(a&&!r.has(a))return r.add(a),ta(a.body,t,n,r)},na=(e,t,n)=>ta(e,t,!n),ra=(e,t,n,r,i)=>{if(e.kind===`Prime`&&i)return ra(e.expression,t,n,r,!1);if(e.kind===`Let`){let a=Mo(e.definitions,Yi(r,t,n));return ra(e.body,a,n,r,i)}if(e.kind!==`Identifier`)return;let a=Ka(t,e.name);if(a?.kind===`Thunk`)return ra(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=ea(e.name,r.environment);if(s)return ra(s.body,void 0,n,r,i)},ia=(e,t)=>e.kind===`Let`||e.kind===`Identifier`&&(t||W(e))||!t&&e.kind===`Prime`,aa=(e,t,n=/* @__PURE__ */ new Set)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>aa(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=ea(e.name,t);if(i)return n.add(e.name),aa(i.body,t,n)},oa=/* @__PURE__ */ new Set([`Label`,`And`,`Or`,`Exists`,`Forall`,`If`,`Case`,`Let`,`Unchanged`,`BoxAction`,`AngleAction`,`FunctionApplication`]),sa=(e,t,n)=>oa.has(e.kind)?!1:e.kind===`Identifier`?t.variableIndex.has(e.name)||t.constants.has(e.name):e.kind===`Apply`?e.operator===`=>`||Qi(e.operator)&&(ia(e.args[0],n)||na(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,ca=/* @__PURE__ */ new Set,la=(e,t)=>{if(W(e))return e.kind===`Identifier`?t.has(e.name)?[]:[e.name]:void 0;let n=[],r={isReadOnly:!0};return xi(e,(e,i)=>{let a=r.isReadOnly?la(e,i.length===0?t:/* @__PURE__ */ new Set([...t,...i])):[];return a?n.push(...a):r.isReadOnly=!1,e}),r.isReadOnly?n:void 0},ua=(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:Za(r,t);return i&&!n.has(i)&&(n.add(i),ua(i.body,t,n))?!0:Fn(e).some(e=>ua(e,t,n))},da=(e,t,n)=>{if(e.kind===`Apply`&&e.operator===`=`){let r=na(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=aa(e.expression,t);if(n)return{kind:`Unchanged`,expression:e,indices:n}}return sa(e,t,n)?{kind:`Guard`,expression:e}:{kind:`Branch`,expression:e,runner:$i(e,t,n)}},fa=(e,t,n)=>{let r=e.map(e=>da(e,t,n)),i=(e,t,n,a,o,s)=>{let c=a,l;for(let a=e;a<r.length;a++){if(a>0&&t.isInit&&ja(c)){l??=Yi(t,n,c);for(let e=a;e<r.length;e++)if(!pa(r[e].expression,l))return;s(c,o);return}let e=r[a];if(e.kind===`Guard`){if(l??=Yi(t,n,c),!Zi(e.expression,l))return;continue}if(e.kind===`Assign`){l??=Yi(t,n,c);let r=X(e.value,l),i=c[e.index];if(i===void 0)c=Xi(c,e.index,r),l=void 0;else if(!Be(i,r))return;continue}if(e.kind===`Unchanged`){let n=t.current;if(!n)return;for(let t of e.indices){let e=c[t];if(e===void 0)c=Xi(c,t,n[t]),l=void 0;else if(!Be(e,n[t]))return}continue}let u=a+1;e.runner(t,n,c,o,!0,(e,r)=>i(u,t,n,e,r,s));return}s(c,o)};return(e,t,n,r,a,o)=>i(0,e,t,n,r,o)},pa=(e,t)=>Xa(X(e,t),`the initial predicate at ${J(e)}`),ma=e=>(t,n,r,i,a,o)=>{Zi(e,Yi(t,n,r))&&o(r,i)},ha=(e,t)=>{let n=e.args[1];return(r,i,a,o,s,c)=>{let l=t(r,i,a),u=Yi(r,i,a);if(a[l]!==void 0){Zi(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 m(`In computing next states, the right side of \\in is not enumerable: ${U(f)} at ${J(e)}`);let p=Ht(f);for(let e=0;e<p.length&&!r.isStopped;e++)c(Xi(a,l,p[e]),o)}},ga=/* @__PURE__ */ new WeakMap,_a=e=>{let t=ga.get(e);if(t)return t;let n=e.kind===`Tuple`?{kind:`And`,operands:e.elements.map(_a),location:e.location}:{kind:`Unchanged`,expression:e,location:e.location};return ga.set(e,n),n},va=(e,t)=>{let n=e.args[0],r=ma(e),i=(e,r,i)=>ra(n,r,i,e,!t)??-1,a=ha(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],Yi(t,n,o));l(Xi(o,u,d),s)}},ya=(e,t,n,r)=>{if(e.kind===`FunctionConstruction`)return{bounds:e.bounds,body:e.body,scope:t};if(e.kind!==`Identifier`)return;let i=Ka(t,e.name);if(i?.kind===`Thunk`)return ya(i.expression,i.scope,n,r);let a=i?void 0:Za(e.name,r.environment);if(a?.kind!==`Function`)return;let o=X(e,Yi(r,void 0,n));return{bounds:a.bounds,body:a.body,scope:qa(void 0,a.name,o)}},ba=(e,t,n)=>{let r=ma(e);return(i,a,o,s,c,l)=>{let u=ya(e.function,a,o,i);if(!u){r(i,a,o,s,c,l);return}let d=Yi(i,a,o),f=e.args.map(e=>X(e,d)),p=f.length===1?f[0]:R(f),h=ro(u.bounds,Yi(i,u.scope,o));if(!Qt(p,h))throw new m(`Attempted to apply a function to ${U(p)}, which is not in its domain at ${J(e)}`);$i(u.body,t,n)(i,io(u.bounds,u.scope,p),o,s,c,l)}},xa=(e,t)=>{if(aa(e,t))return fa([_a(e)],t,!1);if(e.kind===`Tuple`)return $i(_a(e),t,!1);let n=_a(e);return(r,i,a,o,s,c)=>{let l=e.kind===`Identifier`?Ka(i,e.name):void 0;l?.kind===`Thunk`?$i(_a(l.expression),t,!1)(r,l.scope,a,o,s,c):Zi(n,Yi(r,i,a))&&c(a,o)}},Sa=(e,t,n)=>{let r=e.operator,i=ma(e),a=W(e)?void 0:go(r,t);if(a?.kind===`Builtin`)return i;if(a?.kind===`Closure`){let i=us(a,e.args,t),o={body:void 0};return(e,s,c,l,u,d)=>{o.body??=$i(a.body,t,n),o.body(e,i(Yi(e,s,c)),c,u?l:r,u,d)}}return(a,o,s,c,l,u)=>{let d=Yi(a,o,s),f=vo(e,d);f?.kind===`Closure`?$i(f.body,t,n)(a,Ao(f,e.args,d),s,l?c:r,l,u):i(a,o,s,c,l,u)}},Ca=(e,t,n)=>{let r=ma(e),i=W(e)?void 0:ea(e.name,t),a={body:void 0};return(o,s,c,l,u,d)=>{let f=Ka(s,e.name);f?.kind===`Thunk`?$i(f.expression,t,n)(o,f.scope,c,l,u,d):f||!i?r(o,s,c,l,u,d):(a.body??=$i(i.body,t,n),a.body(o,void 0,c,u?l:i.name,u,d))}},wa=(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=ta(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=>wa(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=go(e.operator,t);if(r?.kind!==`Closure`||r.scope!==void 0)return;let i=wa(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}},Ta=(e,t,n)=>{let r=Ka(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},Ea=(e,t,n)=>{let r=e.map(e=>$i(e,t,n)),i=n?[]:e.map(e=>wa(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&&Ta(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)}},Da=(e,t,n)=>{let r=e=>$i(e,t,n);switch(e.kind){case`And`:return fa(e.operands,t,n);case`Or`:return Ea(e.operands,t,n);case`Exists`:{let t=r(e.body),n=e.bounds[0];if(e.bounds.length===1&&n.pattern.kind===`Name`){let e=n.pattern.name;return(r,i,a,o,s,c)=>{let l=to(X(n.set,Yi(r,i,a)),n.set);for(let n=0;n<l.length&&!r.isStopped;n++)t(r,qa(i,e,l[n]),a,o,s,c)}}return(n,r,i,a,o,s)=>{no(e.bounds,Yi(n,r,i),e=>(t(n,e,i,a,o,s),n.isStopped))}}case`Forall`:{let i=r(e.body),a=!n&&ks(e,t)!==void 0&&!ua(e.body,t,/* @__PURE__ */ new Set)?la(e,ca):void 0;return(t,n,r,o,s,c)=>{let l=[];no(e.bounds,Yi(t,n,r),e=>(l.push(e),!1));let u=[...l.slice(0,1),...l.slice(1).reverse()];if(a?.every(e=>Ka(n,e)?.kind===`Value`)){u.every(n=>Zi(e.body,Yi(t,n,r)))&&c(r,o);return}let d=(n,r,a)=>{n===u.length?c(r,a):n>0&&t.isInit&&ja(r)?u.slice(n).every(n=>pa(e.body,Yi(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,Yi(r,i,a));(Xa(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=Yi(r,i,a),d=t.find(e=>Xa(X(e.condition,l),`a CASE guard`))?.body??n;if(!d)throw new m(`${u}In computing next states, TLC encountered a CASE with no conditions true.\n${Ra(e)}`);d(r,i,a,o,s,c)}}case`Let`:{let n=r(e.body),i=Ho(e.definitions,t);return(t,r,a,o,s,c)=>n(t,Mo(e.definitions,Yi(t,r,a),i),a,o,s,c)}case`Unchanged`:return n?()=>{throw new m(`UNCHANGED appears in an initial predicate at ${J(e)}`)}:xa(e.expression,t);case`AngleAction`:{let t=r(e.action),n=_a(e.subscript);return(e,r,i,a,o,s)=>t(e,r,i,a,o,(t,i)=>{Zi(n,Yi(e,r,t))||s(t,i)})}case`BoxAction`:return r({kind:`Or`,operands:[e.action,_a(e.subscript)],location:e.location});case`Label`:return r(e.body);case`Identifier`:return Ca(e,t,n);case`FunctionApplication`:return ba(e,t,n);case`Apply`:{let i=e.args;if(Qi(e.operator)){let r=na(i[0],t,n);if(r!==void 0)return e.operator===`=`?fa([e],t,n):ha(e,()=>r);if(ia(i[0],n))return va(e,n)}if(e.operator===`=>`){let e=r(i[1]);return(t,n,r,a,o,s)=>{let c=X(i[0],Yi(t,n,r));(typeof c==`boolean`?c:Xa(c,`the left side of => at ${J(i[0])}`))?e(t,n,r,a,o,s):s(r,a)}}return Sa(e,t,n)}default:return ma(e)}},Oa=/* @__PURE__ */ new WeakMap,ka=e=>{let t=Oa.get(e);if(t)return t;let n=e.variables.map(()=>void 0);return Oa.set(e,n),n},Aa=(e,t)=>t.variables.filter((t,n)=>e[n]===void 0),ja=e=>{for(let t=0;t<e.length;t++)if(e[t]===void 0)return!1;return!0},Ma=(e,t)=>{let n=t.state;if(!n||!ja(n))throw new m(`ENABLED needs a complete state at ${J(e)}`);let r=t.environment,i={environment:r,isInit:!1,current:n,isStopped:!1};return $i(e,r,!1)(i,t.scope,ka(r),void 0,!1,()=>{i.isStopped=!0}),i.isStopped},Na=(t,n,r,i)=>{let o={environment:n,isInit:!0,current:void 0,isStopped:!1};$i(t,n,!0)(o,i,ka(n),void 0,!1,t=>{if(!o.isStopped){if(!ja(t))throw a(new m(`The initial predicate does not assign ${Aa(t,n).join(`, `)}`),e.error);o.isStopped=r(t)}})},Pa=(e,t,n)=>{let r=[];return Na(e,t,e=>(r.push(e),!1),n),r},Fa=(e,t,n,r,i)=>{let a={environment:n,isInit:!1,current:t,isStopped:!1},o={successors:0};return $i(e,n,!1)(a,i,ka(n),void 0,!1,(e,t)=>{if(!a.isStopped){if(!ja(e))throw new m(`Successor state is not completely specified by action ${t??`Next`}. The following variables are not assigned: ${Aa(e,n).join(`, `)}`);o.successors++,a.isStopped=r({state:e,action:t})}}),o.successors},Ia=(e,t,n,r)=>{let i=[];return Fa(e,t,n,e=>(i.push(e),!1),r),i},J=e=>`line ${e.location.line}, column ${e.location.column}`,La=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,Ra=e=>{let t=e.location.range;return t?La(t):J(e)},za=(e,t)=>new m(`A non-boolean expression (${ir(t)}) was used as the condition of an IF.\n${Ra(e)}`),Ba=(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):Ra(r);return new m(`A non-boolean expression (${ir(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 m(`Attempted to evaluate an expression of form P /\\ Q when ${t===0?`P`:`Q`} was\n${ir(n)}.\n${Ra({...e,location:{...e.location,range:{...r,end:i}}})}`)},Va=e=>t=>`Attempted to select nonexistent field "${e.field}" from the record\n${U(t)}\n${Ra(e)}`,Ha=e=>t=>{if(!M(t))throw new m(`Attempted to apply the operator DOMAIN to a non-function\n(${ir(t)})\n${Ra(e)}`);return sn(t)},Ua=(e,t)=>(n,r)=>{if(!j(n)||I(n))throw new m(`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${Ra(e)}`);return t.evaluate([n,r])},Wa=t=>a(new m(`TLC can't handle real numbers: ${t.text} at ${J(t)}`),e.configParseError),Ga=t=>a(new m(`TLC can't handle a number this big: ${t.text??t.value} at ${J(t)}`),e.error),Ka=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n.binding},qa=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n},parent:e}),Ja=(e,t,n)=>{if(t.kind===`Name`)return qa(e,t.name,n);let r=Yt(n);if(!r||r.length!==t.names.length)throw new m(`Cannot bind <<${t.names.join(`, `)}>> to ${U(n)}, which is not a tuple of that length`);return t.names.reduce((e,t,n)=>qa(e,t,r[n]),e)},Ya=(e,t)=>({environment:e.environment,scope:t,state:e.state,next:e.next}),Xa=(e,t)=>{if(typeof e!=`boolean`)throw new m(`Expected ${t} to be a boolean but found ${U(e)}`);return e},Za=(e,t)=>t.definitions.get(t.substitutions.get(e)??e),Qa=(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=Za(n,t);if(e&&!t.constants.has(n)&&!$a(e,t))return!0}return Fn(e).some(e=>Qa(e,t))},$a=(e,t)=>{let n=t.constantLevels.get(e);if(n!==void 0)return n;t.constantLevels.set(e,!0);let r=!Qa(e.body,t)&&(e.kind===`Operator`||!e.bounds.some(e=>Qa(e.set,t)));return t.constantLevels.set(e,r),r},eo=(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.`},to=(e,t)=>{if(!j(e)||I(e)){let n=U(e),r=eo(e,n);throw new m(r===void 0?`TLC encountered a non-enumerable quantifier bound\n${n}.\n${Ra(t)}`:`TLC encountered the non-enumerable quantifier bound\n${n}\n${Ra(t)}\n${r}`)}return typeof e==`object`&&e.kind===`Interval`?Dt(e):B(e).elements},no=(e,t,n)=>{let r=e.map(e=>to(X(e.set,t),e.set)),i=(t,a)=>t<0?n(a):r[t].some(n=>i(t-1,Ja(a,e[t].pattern,n)));return i(e.length-1,t.scope)},ro=(e,t)=>{let n=e.map(e=>X(e.set,t));return n.length===1?n[0]:{kind:`ProductSet`,factors:n}},io=(e,t,n)=>{if(e.length===1)return Ja(t,e[0].pattern,n);let r=Yt(n)??[];return e.reduce((e,t,n)=>Ja(e,t.pattern,r[n]),t)},ao=/* @__PURE__ */ new WeakMap,oo=(e,t)=>{let n=ao.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:La(r)};return ao.set(t,i),i},so=(e,t,n)=>{let r=oo(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}},co=(e,t,n)=>{let r=/* @__PURE__ */ new Map,i={kind:`LazyFunction`,domain:e,source:n,apply:e=>{let n=gn(e),a=r.get(n);if(a!==void 0){for(let t=0;t<a.length;t+=2)if(He(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},lo=(e,t)=>{let n=ro(e.bounds,t),r=co(n,(n,r)=>X(e.body,Ya(t,io(e.bounds,qa(void 0,e.name,r),n))),so(e.bounds,e.body,n));return e.bounds.length===1?tn(r):r},uo=(e,t)=>e.kind===`Function`?lo(e,t):X(e.body,t),fo=(e,t)=>{let n=$a(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 m(`Operator ${e.name} requires ${e.params.length} arguments`);let i=Ya(t,void 0);if(!n)return uo(e,i);let a=t.environment.runtime.evaluateAtStartup(()=>uo(e,i));return t.environment.definitionValues.set(e,a),a},po=(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,Ya(t,e.scope));return n&&(e.cache=r),r},mo=/* @__PURE__ */ new WeakMap,ho=e=>{let t=mo.get(e);if(t)return t;let n={kind:`Closure`,name:e.name,params:e.params,body:e.body,scope:void 0};return mo.set(e,n),n},go=(e,t)=>{let n=t.substitutions.get(e);if(n!==void 0)return go(n,t);let r=t.definitions.get(e);return r?.kind===`Operator`?ho(r):t.builtins.get(e)},_o=/* @__PURE__ */ new WeakMap,vo=(e,t)=>{if(W(e))return yo(e.operator,t);let n=_o.get(e),r=n===void 0?go(e.operator,t.environment)??null:n;return n===void 0&&_o.set(e,r),r??yo(e.operator,t)},yo=(e,t)=>{let n=Ka(t.scope,e);if(n?.kind===`Operator`)return n.operator;if(!n)return go(e,t.environment)},bo=e=>e.kind===`Closure`?e.params.length:e.arity,xo=(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:yo(n,t);if(!r)throw new m(`Expected an operator argument at ${J(e)}`);return r},So=(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)=>qa(e,n.name,t[r]),e.scope);return X(e.body,Ya(n,r))},Co=(e,t)=>e.kind===`Operator`?e:{kind:`Operator`,name:e.name,arity:bo(e),call:n=>So(e,n,t),literalBody:e.kind===`Closure`&&(e.body.kind===`Number`||e.body.kind===`String`)?e.body.value:void 0},wo=(e,t)=>{if(e.kind===`Lambda`||e.kind===`OperatorReference`)return!0;if(e.kind!==`Identifier`)return!1;let n=yo(e.name,t);return n!==void 0&&bo(n)>0},To=(e,t)=>({kind:`Thunk`,expression:e,scope:t.scope,state:t.state,next:t.next,cache:void 0}),Eo=(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 Eo(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([])}},Do=(e,t)=>{if(e.kind===`String`||e.kind===`Number`&&Po(e.value)){let t={kind:`Value`,value:e.value};return()=>t}if(e.kind===`Identifier`){let n=W(e)?void 0:Eo(e.name,t);if(n?.kind===`Value`){let e={kind:`Value`,value:n.value};return()=>e}if(n===void 0)return t=>{let n=Ka(t.scope,e.name);return n?.kind===`Value`||n?.kind===`Thunk`?n:To(e,t)}}return t=>To(e,t)},Oo=/* @__PURE__ */ new WeakMap,ko=(e,t)=>{let n=Oo.get(e);if(n)return n;let r=Do(e,t);return Oo.set(e,r),r},Ao=(e,t,n)=>{if(t.length!==e.params.length)throw new m(`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:xo(t[i],n)}:ko(t[i],n.environment)(n);r={name:a.name,binding:o,parent:r}}return r},jo=(e,t,n)=>e.kind===`Closure`?X(e.body,Ya(n,Ao(e,t,n))):e.kind===`Operator`?e.call(t.map(e=>X(e,n))):e.isLazy?e.evaluate(cs(t,n),n):e.evaluate(t.map(e=>wo(e,n)?Co(xo(e,n),n):X(e,n)),n),Mo=(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),No=(e,t,n)=>{let r=Ka(n.scope,e);if(r?.kind===`Value`)return r.value;if(r?.kind===`Thunk`)return po(r,n);if(r?.kind===`Operator`){if(bo(r.operator)===0)return So(r.operator,[],n);throw new m(`Operator ${e} is used without arguments`)}let i=Eo(e,n.environment);if(i?.kind===`Variable`){let r=n.state?.[i.index];if(r===void 0)throw new m(`The variable ${e} is not assigned at ${J(t)}`);return r}if(i?.kind===`Value`)return i.value;if(i?.kind===`Definition`)return fo(i.definition,n);let a=n.environment.builtins.get(e);if(a?.arity===0)return a.evaluate([],n);throw new m(`Unknown identifier ${e} at ${J(t)}`)},Po=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,Fo=/* @__PURE__ */ new Set([`Print`,`PrintT`,`Assert`,`JavaTime`,`RandomElement`,`TLCGet`,`TLCSet`]),Io=(e,t)=>Fo.has(e)||t.builtins.get(e)?.isStateLevel===!0,Lo={builtins:Fo,definitions:/* @__PURE__ */ new WeakMap},Ro={builtins:new Set([...Fo].filter(e=>e!==`Assert`)),definitions:/* @__PURE__ */ new WeakMap},zo=(e,t)=>e.kind===`Operator`&&e.params.length===0&&$a(e,t),Bo=(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=Za(r,t),i=n.builtins.has(r)||t.builtins.get(r)?.isStateLevel===!0;if(!e&&i||e&&!zo(e,t)&&Vo(e,t,n))return!0}return Fn(e).some(e=>Bo(e,t,n))},Vo=(e,t,n=Lo)=>{let r=n.definitions.get(e);if(r!==void 0)return r;n.definitions.set(e,!1);let i=Bo(e.body,t,n)||e.kind===`Function`&&e.bounds.some(e=>Bo(e.set,t,n));return n.definitions.set(e,i),i},Ho=(e,t)=>new Set(e.filter(e=>Vo(e,t))),Uo=e=>[...e.definitions.values()].some(t=>Vo(t,e)),Wo=e=>[...e.definitions.values()].some(t=>Vo(t,e,Ro)),Go=/* @__PURE__ */ new WeakMap,Ko=(e,t)=>{let n=Go.get(e);if(n!==void 0)return n;let r=Xo(e,t,Jo);return Go.set(e,r),r},qo=/* @__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`]),Jo=/* @__PURE__ */ new Set,Yo=(e,t,n)=>n.size===0?Ko(e,t):Xo(e,t,n),Xo=(e,t,n)=>{if(!qo.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=Eo(e.name,t);return n?.kind===`Value`||n?.kind===`Definition`&&zo(n.definition,t)}if(e.kind===`Apply`){if(Io(e.operator,t)||e.operator===`~>`)return!1;let r=go(e.operator,t);if(r?.kind!==`Builtin`&&r?.kind!==`Closure`)return!1;if(r.kind===`Closure`){let n=Za(e.operator,t);if(!n||!$a(n,t)||Vo(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`&&Yo(e,t,n))}let r={value:!0};return xi(e,(e,i)=>(r.value&&=Yo(e,t,i.length===0?n:/* @__PURE__ */ new Set([...n,...i])),e)),r.value},Zo=e=>e.kind!==`Number`&&e.kind!==`String`&&e.kind!==`Identifier`,Qo=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}},$o=(e,t)=>{if(e.kind===`Identifier`&&W(e))return!t.has(e.name);if(W(e))return!0;let n={value:!1};return xi(e,(e,r)=>(n.value||=$o(e,r.length===0?t:/* @__PURE__ */ new Set([...t,...r])),e)),n.value},es=(e,t)=>pi.has(e)&&Zo(e)&&ks(e,t)!==void 0&&!$o(e,Jo),Y=(e,t)=>{let n=t.evaluators.get(e);if(n)return n;let r=Es(e,t),i=Zo(e)&&Ko(e,t)?Qo(r):es(e,t)?as(r):r;return t.evaluators.set(e,i),i},ts=/* @__PURE__ */ new WeakMap,ns=(e,t)=>{let n=ts.get(e);if(n)return n;let r=(Zo(e)&&Ko(e,t)?void 0:wr(e,t))??Y(e,t);return ts.set(e,r),r},X=(e,t)=>ns(e,t.environment)(t),rs=(e,t)=>{let n=e.name,r=W(e)?void 0:Eo(n,t);if(r?.kind===`Variable`){let t=r.index;return r=>{let i=r.state?.[t];if(i===void 0)throw new m(`The variable ${n} is not assigned at ${J(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&&$a(e,t))return t=>fo(e,t);if(e.params.length===0){let n={body:void 0},r=r=>(n.body??=ns(e.body,t),n.body(Ya(r,void 0)));return is(e,t)?as(r):r}return t=>fo(e,t)}if(r?.kind===`Definition`){let e=r.definition,n=t=>fo(e,t);return $a(e,t)||!is(e,t)?n:as(n)}return t=>No(n,e,t)},is=(e,t)=>ks(e.body,t)!==void 0&&(e.kind===`Operator`||e.bounds.every(e=>ks(e.set,t)!==void 0)),as=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}},os=(e,t)=>{let n=go(e,t);return n!==void 0&&bo(n)>0},ss=(e,t)=>e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&!(e.kind===`Identifier`&&!W(e)&&os(e.name,t)),cs=(e,t)=>e.map(e=>({kind:`Operator`,name:`argument`,arity:0,call:()=>X(e,t),expression:e})),ls=(e,t,n)=>{if(e.isLazy)return n=>e.evaluate(cs(t,n),n);let r=e.evaluateUnary;if(r&&t.length===1&&ss(t[0],n)){let e=Y(t[0],n);return t=>r(e(t))}let i=e.evaluateBinary,a=t.length===2&&ss(t[0],n)&&ss(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=>wo(e,n)?Co(xo(e,n),n):X(e,n)),n)},us=(e,t,n)=>{if(t.length!==e.params.length)return()=>{throw new m(`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:ko(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:xo(t[e],n)};a={name:r[e].name,binding:s,parent:a}}return a}},ds=/* @__PURE__ */ new WeakMap,fs=e=>{let t=ds.get(e);if(t)return t;let n={calls:/* @__PURE__ */ new Map,size:0};return ds.set(e,n),n},ps=(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},ms=(e,t)=>e.every((e,n)=>He(e,t[n])),hs=(e,t)=>{let n=Za(e.operator,t);return n?.kind===`Operator`&&n.params.length>0&&n.params.every(e=>e.arity===0)&&$a(n,t)&&!Vo(n,t)},gs=(e,t,n,r)=>{let i=us(e,t,n),a={body:void 0},o=(t,r)=>(a.body??=ns(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=fs(e);return e=>{let n=i(e),r=ps(n,t.length);if(!r)return o(n,e);let a=r.length;for(let e of r)a=dn(a,gn(e));let c=s.calls.get(a),l=c?.find(e=>ms(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}},_s=(e,t)=>{let n=e.args;if(e.operator===`=>`){let e=Y(n[0],t),r=Y(n[1],t);return t=>!Xa(e(t),`the left side of =>`)||Xa(r(t),`the right side of =>`)}if(e.operator===`~>`)return()=>{throw new m(`TLC cannot evaluate a temporal formula such as ~> in a state`)};let r=W(e)?void 0:go(e.operator,t);if(r?.kind===`Closure`)return gs(r,n,t,hs(e,t));if(r?.kind===`Builtin`&&r.name===`DOMAIN`){let r=Y(n[0],t),i=Ha(e);return e=>i(r(e))}if(r?.kind===`Builtin`&&r.name===`TLCEval`&&n.length===1){let i=Y(n[0],t);return mi.has(e)||Qa(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=Ua(e,r);return e=>o(i(e),a(e))}return r?.kind===`Builtin`?ls(r,n,t):r=>{let i=yo(e.operator,r);if(i)return jo(i,n,r);throw t.definitions.get(e.operator)?.kind===`Function`?new m(`${e.operator} is a function; apply it with brackets`):new m(`Unknown operator ${e.operator} at ${J(e)}`)}},vs=(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=to(o(t),a.set);for(let a=0;a<s.length;a++){let o=Xa(i(Ya(t,qa(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)=>to(e(t),o[n].set)),c=(a,o)=>{if(a<0)return Xa(i(Ya(t,o)),r)!==n;let l=s[a];for(let t=0;t<l.length;t++)if(c(a-1,qa(o,e[a],l[t])))return!0;return!1};return c(o.length-1,t.scope)?!n:n}}return e=>no(o,e,t=>Xa(i(Ya(e,t)),r)!==n)?!n:n},ys=(e,t)=>{if(e.kind===`Tuple`)return R(e.names.map(e=>{let n=Ka(t,e);return n?.kind===`Value`&&n.value}));let n=Ka(t,e.name);return n?.kind===`Value`?n.value:void 0},bs=/* @__PURE__ */ new WeakSet,xs=e=>{(e.kind===`FunctionConstruction`||e.kind===`Except`)&&bs.add(e)},Ss=(e,t)=>{let n=bs.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):ro(i,t);if(e.isRecursive||n||!z(c)){let n=co(c,e=>r(Ya(t,io(i,t.scope,e))),so(i,e.body,c));return i.length===1?tn(n):n}if(o&&a.pattern.kind===`Name`){let e=a.pattern.name,n=kt(c);return tn(ze(n,n.map(n=>r(Ya(t,qa(t.scope,e,n))))))}let l=[];return no(i,t,e=>{let n=i.length===1?ys(a.pattern,e)??!1:R(i.map(t=>ys(t.pattern,e)??!1));return l.push([n,r(Ya(t,e))]),!1}),xt(l)}},Cs=(e,t)=>{let n=bs.has(e);n&&xs(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(Ya(i,qa(i.scope,`@`,e))):cn(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}},ws=(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=>Xa(n(Ya(t,Ja(t.scope,i,e))),`a set filter predicate`);if(typeof a!=`object`||a.kind!==`Set`&&a.kind!==`MixedSet`&&a.kind!==`Interval`){if(j(a))return{kind:`FilteredSet`,base:a,test:o};throw new m(`TLC encountered a non-enumerable quantifier bound ${U(a)} at ${J(e.bound.set)}`)}return Re(B(a).elements.filter(o))}}if(e.kind===`SetMap`){let n=Y(e.expression,t);return t=>{let r=[];return no(e.bounds,t,e=>(r.push(n(Ya(t,e))),!1)),gt(r)}}let n=e.set;if(!n)return()=>{throw new m(`TLC cannot evaluate an unbounded CHOOSE at ${J(e)}`)};let r=Y(e.body,t),i={pattern:e.pattern,set:n};return t=>{let n={value:void 0};if(no([i],t,i=>Xa(r(Ya(t,i)),`the body of CHOOSE`)?(n.value=ys(e.pattern,i),!0):!1),n.value===void 0)throw new m(`Attempted to compute the value of an expression of form\nCHOOSE x \\in S: P, but no element of S satisfied P.\n${Ra(e)}`);return n.value}},Ts=(e,t)=>{let n=[...e].sort((e,t)=>L(e.name,t.name)),r=n.some((e,t)=>t>0&&n[t-1].name===e.name),i=n.map(e=>Y(e.value,t));if(r)return e=>xt(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=>be(a,i.map(t=>t(e)),o):e=>ze(a,i.map(t=>t(e)))},Es=(e,t)=>{let n=e=>Y(e,t);switch(e.kind){case`Number`:{let t=e.value;return Po(t)?()=>t:()=>{throw Ga(e)}}case`Decimal`:return()=>{throw Wa(e)};case`String`:{let t=e.value;return()=>t}case`Identifier`:return rs(e,t);case`Apply`:return _s(e,t);case`OperatorReference`:case`Lambda`:return()=>{throw new m(`An operator cannot be used as a value at ${J(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 Ba(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(Xa(t[n](e),`a disjunct`))return!0;return!1}}case`Prime`:{let t=n(e.expression);return n=>{if(!n.next)throw new m(`A primed expression appears outside an action at ${J(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=>Be(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 za(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(Xa(e.condition(n),`a CASE guard`))return e.body(n);if(r)return r(n);throw new m(`Attempted to evaluate a CASE with no conditions true.\n${Ra(e)}`)}}case`Let`:{let t=n(e.body);return n=>t(Ya(n,Mo(e.definitions,n)))}case`Forall`:case`Exists`:return vs(e,t);case`UnboundedQuantifier`:return()=>{throw new m(`TLC cannot evaluate an unbounded quantifier at ${J(e)}`)};case`Choose`:case`SetFilter`:case`SetMap`:return ws(e,t);case`SetEnumeration`:{let t=e.elements.map(n);return e=>gt(t.map(t=>t(e)))}case`Tuple`:{let t=e.elements.map(n);return e=>R(t.map(t=>t(e)))}case`FunctionConstruction`:return Ss(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 Ts(e.fields,t);case`RecordSet`:{let t=[...e.fields].sort((e,t)=>L(e.name,t.name)),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 Cs(e,t);case`ExceptAt`:return t=>{let n=Ka(t.scope,`@`);if(n?.kind!==`Value`)throw new m(`@ appears outside an EXCEPT at ${J(e)}`);return n.value};case`FunctionApplication`:{xs(e.function);let t=n(e.function),r=e.args.map(n);if(r.length===1){let e=r[0];return n=>an(t(n),e(n))}return e=>an(t(e),R(r.map(t=>t(e))))}case`FieldAccess`:{let t=n(e.record),r=e.field,i=Va(e);return e=>an(t(e),r,i)}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?Xa(t(e),`an action`)||r(e):Xa(t(e),`an action`)&&!r(e)}case`Enabled`:{let t=e.expression;return e=>Ma(t,e)}case`Label`:return n(e.body);case`Subexpression`:return()=>{throw new m(`The subexpression reference at ${J(e)} does not name a subexpression`)};case`Always`:case`Eventually`:case`WeakFairness`:case`StrongFairness`:return()=>{throw new m(`TLC cannot evaluate a temporal formula in a state at ${J(e)}`)}}},Ds=/* @__PURE__ */ new Set([`Prime`,`Unchanged`,`Enabled`,`Always`,`Eventually`,`BoxAction`,`AngleAction`,`WeakFairness`,`StrongFairness`]),Os=e=>{if(e.kind===`Identifier`)return e.name;if(e.kind===`Apply`||e.kind===`OperatorReference`)return e.operator},ks=(e,t)=>{let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=e=>{if(Ds.has(e.kind))return!1;let a=Os(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&&Io(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 Fn(e).every(i)};return i(e)?[...n]:void 0},As=/* @__PURE__ */ new Map([[`Reals`,`-------------------------------- MODULE Reals -------------------------------
21
+ `);n.index+=e===-1?r.length:e;continue}if(r.startsWith(`(*`)){let e=r.indexOf(`*)`);if(e===-1)throw new l(`Unterminated comment at line ${n.line}`);n.line+=r.slice(0,e).split(`
22
+ `).length-1,n.index+=e+2;continue}let a=/^\d+(?![A-Za-z_])/.exec(r)?.[0];if(a){t.push({kind:`Number`,text:a,line:n.line}),n.index+=a.length;continue}let o=/^[A-Za-z0-9_!]+/.exec(r)?.[0];if(o){t.push({kind:`Word`,text:o,line:n.line}),n.index+=o.length;continue}let s=/^"((?:[^"\\]|\\.)*)"/.exec(r);if(s){t.push({kind:`String`,text:s[1],line:n.line}),n.index+=s[0].length;continue}let c=E.find(e=>r.startsWith(e));if(c){t.push({kind:`Symbol`,text:c,line:n.line}),n.index+=c.length;continue}let u=S(e,n.index);if(!u)throw new l(`Unexpected character ${JSON.stringify(r[0])} at line ${n.line}`);t.push({kind:`Word`,text:u.text,line:n.line}),n.index+=u.length}return t.push({kind:`End`,text:``,line:n.line}),t},O=e=>{let t=D(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[n.index],o=()=>t[n.index++],s=e=>e.kind===`Word`&&T.has(e.text),c=e=>{let t=o();if(t.text!==e)throw new l(`Expected ${JSON.stringify(e)} but found ${JSON.stringify(t.text)} at line ${t.line}`)},u=()=>{let e=o();if(e.kind!==`Word`||s(e))throw new l(`Expected a name but found ${JSON.stringify(e.text)} at line ${e.line}`);return e.text},d=()=>a().kind===`Word`&&!s(a()),f=()=>{let e=[];for(;d();)e.push(o().text);return e},p=(e,t)=>{if(r[e]!==void 0)throw new l(`The keyword ${t} appears twice`);r[e]=u()},m=()=>{let e=o();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=[];for(a().text!==`}`&&e.push(m());a().text===`,`;)o(),e.push(m());return c(`}`),{kind:`Set`,elements:e}}if(e.kind===`Word`&&!s(e))return{kind:`ModelValue`,name:e.text};throw new l(`Expected a value but found ${JSON.stringify(e.text)} at line ${e.line}`)},h=()=>{if(a().text!==`[`)return;o();let e=u();return c(`]`),e},g=()=>{for(;d();){let e=o().text;if(a().text===`(`){o();let t=[];for(;a().text!==`)`;)t.push(m()),a().text!==`)`&&c(`,`);o(),c(`=`);let n=h();r.constants.push({name:e,value:m(),args:t,...n&&{module:n}});continue}if(a().text===`<-`){o();let t=h();r.substitutions.push({name:e,target:u(),...t&&{module:t}});continue}c(`=`);let t=h();r.constants.push({name:e,value:m(),...t&&{module:t}})}};for(;a().kind!==`End`;){let e=o();switch(e.text){case`CONSTANT`:case`CONSTANTS`:g();break;case`INIT`:p(`init`,e.text);break;case`NEXT`:p(`next`,e.text);break;case`SPECIFICATION`:p(`specification`,e.text);break;case`SYMMETRY`:p(`symmetry`,e.text);break;case`VIEW`:p(`view`,e.text);break;case`INVARIANT`:case`INVARIANTS`:r.invariants.push(...f());break;case`PROPERTY`:case`PROPERTIES`:r.properties.push(...f());break;case`CONSTRAINT`:case`CONSTRAINTS`:r.constraints.push(...f());break;case`ACTION_CONSTRAINT`:case`ACTION_CONSTRAINTS`:r.actionConstraints.push(...f());break;case`ALIAS`:p(`alias`,e.text);break;case`POSTCONDITION`:case`POSTCONDITIONS`:r.postconditions.push(...f());break;case`_POSSIBLE`:r.possible.push(...f());break;case`_PERIODIC`:p(`periodic`,e.text);break;case`_RL_REWARD`:p(`rlReward`,e.text);break;case`CHECK_DEADLOCK`:{if(i.isSet)throw new l(`The keyword CHECK_DEADLOCK appears twice`);i.isSet=!0;let e=o().text;if(e!==`TRUE`&&e!==`FALSE`)throw new l(`CHECK_DEADLOCK expects TRUE or FALSE but found ${JSON.stringify(e)}`);r.checkDeadlock=e===`TRUE`;break}default:throw new l(`Unexpected ${JSON.stringify(e.text)} at line ${e.line}`)}}if(r.specification!==void 0&&(r.init!==void 0||r.next!==void 0))throw new l(`SPECIFICATION cannot be combined with INIT or NEXT`);return r},se={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:` `}},k=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),le=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),ue=e=>{let t=t=>{let n=C(e,t,k);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=C(e,t,ce);if(e.startsWith(`..`,n)&&ce(e[n+2]))return{kind:`Constant`,first:t,last:C(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:C(e,t+1,ce)-1,children:[]};if(le(n))return{kind:`Constant`,first:t,last:C(e,t,le)-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)},de=e=>{let t=e.length===0?void 0:ue(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=se[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},A=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,j=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),M=e=>typeof e==`object`&&e.kind===`ModelValue`,fe=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:A(e)?`set`:`function`,pe=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new d(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},me={isUsed:!1},he=(e,t)=>(me.isUsed=!0,e.writtenKeys=t,e),ge=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[Wt(e.domain,t)]]),_e=(e,t,n)=>he(L(e,t),n),ve=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(ve);e.writtenKeys=void 0,e.range.forEach(ve)}},ye=e=>e.every(e=>typeof e==`string`),be=(e,t)=>e.length>0&&t.length>0&&ye(e)!==ye(t),xe=(e,t)=>{me.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return be(n,r)?tt(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=I(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=I(i[e],a[e]);if(t!==0)return t}return 0},Se=(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=I(n[e],r[e]);if(t!==0)return t}return 0},Ce=e=>M(e)?e.type:void 0,N=(e,t,n)=>{let r=Ce(e),i=Ce(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(M(e)&&M(t)){if(r===void 0||i===void 0||r===i)return;throw new u(`Attempted to ${a} the differently-typed model values ${U(e)} and ${U(t)}`)}throw r===void 0?new u(`Attempted to ${a} the typed model value ${U(t)} and the non-model value\n${U(e)}`):new u(`Attempted to ${a}${n?``:` the`} typed model value ${U(e)} and non-model value\n${U(t)}`)},we={ranks:Object.create(null),size:0},Te=e=>{we.ranks=Object.create(null),we.size=0,Ne.clear();for(let t of e)P(t)},P=e=>(we.ranks[e]===void 0&&(we.ranks[e]=we.size++),e),Ee=()=>we.size,De=e=>we.ranks[P(e)],Oe=(e,t)=>{if(e===t)return 0;let n=we.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},F=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),ke=(e,t)=>(F(e)||F(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),Ae=(e,t,n)=>{if(!F(e))throw new u(`Attempted to ${n} the set ${U(z(e)?B(e):e,!0)} with the value:\n${U(t,!0)}`);if(!F(t))throw new u(`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 u(`Attempted to compare ${U(e,!0)} with the value\n${U(t,!0)}`)},je={kind:`InfiniteSet`,name:`Any`},Me=e=>{throw new u(`Attempted to compare ANY with the value\n${U(e)}`)},I=(e,t)=>{if(e===t)return me.isUsed&&ve(e),e===je?Me(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return xe(e,t);if(n===`Set`&&r===`Set`)return Se(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&&N(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return N(e,t,!1),n===`ModelValue`?-1:1;if(e===je||t===je)return Me(e===je?t:e);if(A(e)&&A(t)&&ke(e,t))return Ae(e,t,`compare`);let i=A(e);if(i!==A(t))throw new u(`Attempted to compare ${fe(e)} ${U(e)} with ${fe(t)} ${U(t)}`);return i?Se(B(e),B(t)):xe(H(e),H(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Oe(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(N(e,t,!1),M(e))return-1;if(M(t))return 1;throw new u(`Attempted to compare ${fe(e)} ${U(e)} with ${fe(t)} ${U(t)}`)},Ne=/* @__PURE__ */ new Map,Pe=e=>{let t=Ne.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:De(e)};return Ne.set(e,n),n},Fe=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0}),L=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0}),Ie=(e,t)=>{if(e===t)return me.isUsed&&ve(e),e!==je||Me(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&N(e,t,!0),I(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 xe(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Se(e,t)===0;if(M(e)||M(t))return N(e,t,!0),M(e)&&M(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return Ie(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:Ie(e.domain,t.domain)&&Ie(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]&&Ie(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)=>Ie(e,t.factors[n]));let n=A(e)&&A(t)&&!(z(e)&&z(t));if(n&&ke(e,t))return Ae(e,t,`check equality of`)===0;if(n){if(!F(e)){let n=B(e);if(!F(t))return Se(n,B(t))===0}return xn(e)===xn(t)}return I(e,t)===0},Le=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>Re(e,t[n])),Re=(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)&&Le(e.elements,t.elements):e.kind===`Function`&&t.kind===`Function`?(e.hash===0||t.hash===0||e.hash===t.hash)&&Le(e.domain,t.domain)&&Le(e.range,t.range):xn(e)===xn(t),ze=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},Be=e=>{if(!j(e))return;let t=H(e);return{domain:t.domain,range:t.range,low:ze(t.domain)}},Ve=e=>{if(!j(e))return;let t=H(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},He=(e,t)=>{if(Ce(e)!==void 0)throw new u(`Attempted to compare the typed model value ${U(e)} and the non-model value\n${U(t)}`);return 1},Ue=(e,t)=>{if(Ce(e)!==void 0)throw new u(`Attempted to check equality of the typed model value ${U(e)} and the non-model value\n${U(t)}`);return!1},We=(e,t)=>{let n=Ce(e);if(n===void 0)return M(t)?e.rank-t.rank:-1;if(!M(t))throw new u(`Attempted to compare the typed model value ${U(e)} and non-model value\n${U(t)}`);let r=Ce(t);if(r!==void 0&&r!==n)throw new u(`Attempted to compare the differently-typed model values ${U(e)} and ${U(t)}`);return e.rank-t.rank},Ge=(e,t)=>{let n=Ce(e);if(n===void 0)return M(t)&&e.name===t.name;if(!M(t))throw new u(`Attempted to check equality of typed model value ${U(e)} and non-model value\n${U(t)}`);let r=Ce(t);if(r!==void 0&&r!==n)throw new u(`Attempted to check equality of the differently-typed model values ${U(e)} and ${U(t)}`);return e.name===t.name},Ke={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`}},qe=(e,t,n)=>{let r=Ke[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)}`},Je=(e,t,n)=>{let r=Be(n);if(!r){if(M(n))return He(n,t);throw new u(`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=()=>Ye(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 Ye(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 u(`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()},Ye=(e,t)=>{for(let n=0;n<e.length;n++){let r=tt(e[n],t[n]);if(r!==0)return r}return 0},Xe=(e,t)=>{let n=H(e);if(e.kind===`Function`&&Gt(n)!==void 0){let r=j(t)?Gt(t):void 0;return r?n.range.length-r.length||Ye(n.range,r):Je({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=Ve(t);if(!r){if(M(t))return He(t,e);throw new u(`Attempted to compare record:\n${U(e)}\nwith non-record\n${U(t)}`)}return n.domain.length-r.domain.length||Ye(n.domain,r.domain)||Ye(n.range,r.range)}return Je({...n,low:ze(n.domain)},e,t)},Ze=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),Qe=(e,t)=>F(e)||F(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),$e=(e,t)=>{let n=Ze(t)?t:B(t);return{elements:B(e).elements,otherElements:B(n).elements}},et=(e,t)=>{if(Qe(e,t))return I(e,t);if(!Ze(e))return et(B(e),t);if(!A(t)){if(M(t))return He(t,e);throw new u(`Attempted to compare the set ${U(e)} with the value:\n${U(t)}`)}let n=$e(e,t);return n.elements.length-n.otherElements.length||Ye(n.elements,n.otherElements)},tt=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return I(e,t);if(M(t))return He(t,e);throw new u(qe(e,t,!1))}return e.kind===`ModelValue`?We(e,t):j(e)?Xe(e,t):et(e,t)},nt=(e,t)=>e.every((e,n)=>ot(e,t[n])),rt=(e,t,n)=>{let r=Be(n);if(!r){if(M(n))return Ue(n,t);throw new u(`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)&&nt(e.range,r.range);let i=e.low??r.low;return i===void 0?nt(e.domain,r.domain)&&nt(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new u(`Attempted to compare an integer with non-integer:\n${U(e)}.`);return e===i+t})&&nt(e.range,r.range)},it=(e,t)=>{let n=H(e);if(e.kind===`Function`&&Gt(n)!==void 0){let r=j(t)?Gt(t):void 0;return r?n.range.length===r.length&&nt(n.range,r):rt({...n,low:1},e,t)}if(e.kind===`Function`&&n.domain.every(e=>typeof e==`string`)){let r=Ve(t);if(!r){if(M(t))return Ue(t,e);throw new u(`Attempted to check equality of record:\n${U(e)}\nwith non-record\n${U(t)}`)}return n.domain.length===r.domain.length&&nt(n.domain,r.domain)&&nt(n.range,r.range)}return rt({...n,low:ze(n.domain)},e,t)},at=(e,t)=>{if(Qe(e,t))return Ie(e,t);if(!Ze(e))return at(B(e),t);if(!A(t)){if(M(t))return Ue(t,e);throw new u(`Attempted to check equality of the set ${U(e)} with the value:\n${U(t)}`)}let n=$e(e,t);return n.elements.length===n.otherElements.length&&nt(n.elements,n.otherElements)},ot=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(M(t))return Ue(t,e);throw new u(qe(e,t,!0))}return e.kind===`ModelValue`?Ge(e,t):j(e)?it(e,t):at(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=tt(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=>ot(t,e)),lt=(e,t)=>{try{return Ie(e,t)}catch(n){if(!(n instanceof u))throw n;return ot(e,t)}},ut=e=>{for(let t=1;t<e.length;t++)if(I(e[t-1],e[t])>=0)return!1;return!0},dt=e=>{if(e.length<2||ut(e))return Fe(e);let t=[...e].sort(I),n=[t[0]];for(let e=1;e<t.length;e++)I(n[n.length-1],t[e])!==0&&n.push(t[e]);return Fe(n)},ft=e=>{try{return dt(e)}catch(t){if(!(t instanceof u))throw t;return{kind:`MixedSet`,elements:e}}},pt=Fe([]),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&&I(r[a],t)<0;)a++;a<r.length&&I(r[a],t)===0||i.push(t)}return i.length===n.length?e:Fe(i)},ht=(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&&I(r[a],t)<0;)a++;a<r.length&&I(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Fe(i)},gt=(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=I(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=Fe(i);if(e.hash!==0){let t=e.hash;for(let e=0;e<a.length;e++)t=t+ln(a[e])|0;c.hash=t}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+gn(a[e])|0;c.fingerprint=t}return c},_t=e=>{let t=e.length<2?e:[...e].sort((e,t)=>I(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&I(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return L(n,r)},vt=e=>{let t=_t(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:he(t,e.map(e=>e[0]))},yt=[],bt=[],xt=/* @__PURE__ */ new WeakMap,St=e=>{let t=yt[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return yt[e]=n,n},Ct=e=>{if(Vt(e),e.low===1&&e.high>=1)return St(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},wt=e=>e.length>0&&(e===yt[e.length]||xt.has(e)),Tt=e=>{let t=B(e).elements;return wt(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Et=e=>{let t=bt[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return bt[e]=n,n},R=e=>L(St(e.length),e),Dt=e=>_t(e),Ot=e=>A(e)&&!F(e),kt=(e,t=!1)=>`UNION(${U(e.base,t)})`,At=e=>{if(!Ot(e.base))throw new u(`Attempted to enumerate the nonenumerable set:\n${kt(e)}`);return B(e.base).elements},jt=(e,t,n)=>{if(Ot(e))return e;throw new u(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${kt(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)||Mt(e.domain)===!0||Mt(e)===!0;case`RecordSet`:return e.sets.every(z)||Mt(e)===!0;case`ProductSet`:return e.factors.every(z)||Mt(e)===!0;case`Union`:return z(e.base)&&B(e.base).elements.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}},Mt=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=Mt(e.domain);return t===void 0?void 0:!t&&Mt(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Mt(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}},Nt=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},Pt=(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},Ft=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Fe(r.map(t=>e[t])));while(Pt(r,e.length))}return t},It=e=>{if(typeof e!=`object`)throw new u(`Expected a set but found ${U(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return st(e.elements);case`Interval`:{let t=Ct(e);return t!==yt[t.length]&&xt.set(t,e),t}case`Subset`:{F(e.base)&&Vt(e.base);let t=B(e.base).elements;if(t.length>30)throw new u(`SUBSET of a set with ${t.length} elements is too large to enumerate`);return Ft(t)}case`FunctionSet`:{if(V(e))return[];if(F(e.domain))throw new u(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${U(e.domain)}\ncannot be enumerated.`);let t=Tt(e.domain);if(t.length>0&&F(e.range))throw new u(`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 Nt(t.map(()=>n)).map(e=>L(t,e))}case`RecordSet`:{if(V(e))return[];let t=e.sets.map((t,n)=>{if(F(t))throw new u(`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 Nt(t).map(t=>Dt(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(V(e))return[];let t=e.factors.map((e,t)=>{if(F(e))throw new u(`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 Nt(t).map(R)}case`FilteredSet`:if(F(e.base))throw new u(`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=At(e).flatMap((t,n)=>B(jt(t,n,e)).elements);return B(ft(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(F(e.left)||F(e.right)))throw new u(`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`&&F(e.left)&&F(e.right))throw new u(`Attempted to enumerate S \\cap T when neither S:\n${U(e.left)}\nnor T:\n${U(e.right)}\nis enumerable`);if(e.operator===`\\`&&F(e.left))throw new u(`Attempted to enumerate S \\ T when S:\n${U(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return gt(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=>Jt(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new u(`Attempted to enumerate the non-enumerable set ${U(e)}`);default:throw new u(`Expected a set but found ${U(e)}`)}},Lt=/* @__PURE__ */ new WeakMap,B=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Fe(It(e));let t=typeof e==`object`?Lt.get(e):void 0;if(t)return t;let n=It(e),r=typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Fe(n):dt(n);return typeof e==`object`&&Lt.set(e,r),r},Rt=e=>{if(typeof e!=`object`||Lt.has(e))return B(e).elements;if(e.kind===`Union`)return At(e).flatMap((t,n)=>Rt(jt(t,n,e)));if(e.kind===`FilteredSet`&&!F(e.base))return Rt(e.base).filter(e.test);if(e.kind!==`SetOperation`)return B(e).elements;if(e.operator===`\\cup`)return F(e.left)||F(e.right)?B(e).elements:[...Rt(e.left),...Rt(e.right)];let t=e.operator===`\\`||z(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return F(n)?B(e).elements:Rt(n).filter(t=>Jt(t,r)===(e.operator===`\\cap`))},V=e=>{if(typeof e!=`object`||!A(e))throw new u(`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 u(`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 At(e).every((t,n)=>V(jt(t,n,e)));default:return B(e).elements.length===0}},zt=(e,t)=>e.reduce((e,n)=>{let r=e*Vt(n);if(r>2147483647)throw new u(t());return r},1),Bt=e=>`Overflow when computing the number of elements in:\n${U(e)}`,Vt=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 u(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new u(`Attempted to compute the number of elements in the overridden value ${U(e)}.`);case`Subset`:{let t=Vt(e.base);if(t>=31)throw new u(Bt(e));return 2**t}case`FunctionSet`:{if(V(e.domain))return 1;if(V(e.range))return 0;let t=Vt(e.range);if(t===1)return 1;let n=Vt(e.domain),r={value:1};for(let i=0;i<n;i++)if(r.value*=t,r.value>2147483647)throw new u(Bt(e));return r.value}case`RecordSet`:return V(e)?0:zt(e.sets,()=>Bt(e));case`ProductSet`:return V(e)?0:zt(e.factors,()=>`Overflow when computing the number of elements in ${U(e)}`);default:return B(e).elements.length}},Ht=e=>`Attempted to check if the set ${U(e)}is finite.`,Ut=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new u(`Attempted to check if the ${fe(e)} ${U(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new u(`Attempted to check if the function:\n${U(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return Ut(e.base)&&V(e.base);case`Subset`:return Ut(e.base);case`FunctionSet`:{let t=Ut(e.domain);if(t&&V(e.domain))return!0;let n=Ut(e.range);return n&&V(e.range)?!0:n&&(t||Vt(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(!Ut(e))n.isAllFinite=!1;else if(V(e))return!0;return n.isAllFinite}case`Union`:if(!Ot(e.base))throw new u(`Attempted to check if the nonenumerable set:\n${kt(e)}\nis a finite set.`);return B(e.base).elements.every(Ut);case`SetOperation`:if(e.operator===`\\cup`)return Ut(e.left)&&Ut(e.right);if(e.operator===`\\cap`){if(!Ut(e.left)&&!Ut(e.right))throw new u(Ht(e));return!0}if(Ut(e.left))return!0;if(!Ut(e.right))throw new u(Ht(e));return!1;case`FilteredSet`:if(!Ut(e.base))throw new u(`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}},Wt=(e,t)=>{let n={low:0,high:e.length-1};for(;n.low<=n.high;){let r=n.low+n.high>>1,i=I(e[r],t);if(i===0)return r;i<0?n.low=r+1:n.high=r-1}return-1},Gt=e=>{if(typeof e!=`object`||!j(e))return;let t=H(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},Kt=(e,t)=>`Attempted to check if the value ${U(e)} is an element of ${U(t)}`,qt=(e,t)=>{let n=`Attempted to check if the value:\n${U(e)}\nis an element of the`;if(!j(t))return`${n} ${fe(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)}`},Jt=(e,t)=>{if(!A(t))throw new u(qt(e,t));switch(t.kind){case`Set`:try{return Wt(t.elements,e)!==-1}catch(n){if(!(n instanceof u))throw n;return ct(e,t.elements)}case`MixedSet`:return ct(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!M(e))throw new u(`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(M(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new u(`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(!A(e))throw new u(Kt(e,t));return B(e).elements.every(e=>Jt(e,t.base));case`FunctionSet`:{if(!j(e)){if(M(e))return!1;throw new u(Kt(e,t))}let n=H(e),r=ze(n.domain);return(r===void 0?lt(t.domain,Fe(n.domain)):lt({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>Jt(e,t.range))}case`RecordSet`:{let n=j(e)?H(e):void 0;if(!n||!ye(n.domain)){if(M(e))return!1;throw new u(`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=Wt(n.domain,e);return i!==-1&&Jt(n.range[i],t.sets[r])})}case`ProductSet`:{let n=j(e)?Gt(e):void 0;if(n===void 0){if(j(e)&&H(e).domain.every(e=>typeof e==`number`)||M(e))return!1;throw new u(`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)=>Jt(e,t.factors[n]))}case`FilteredSet`:return Jt(e,t.base)&&t.test(e);case`Union`:if(!Ot(t.base))throw new u(`Attempted to check if:\n ${U(e)}\nis an element of the non-enumerable set:\n ${kt(t)}`);return B(t.base).elements.some(t=>Jt(e,t));case`SetOperation`:return t.operator===`\\cup`?Jt(e,t.left)||Jt(e,t.right):Jt(e,t.left)&&Jt(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Gt(e);if(n===void 0){if(M(e))return!1;throw new u(Kt(e,t))}return n.every(e=>Jt(e,t.base))}default:throw new u(qt(e,t))}},Yt=(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?Jt(e,n):e.range.every((e,r)=>Yt(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)||Vt(e.domain);let t=Tt(e.domain);return L(t,t.map(t=>e.apply(t)))}throw new u(`Expected a function but found ${U(e)}`)},Xt=/* @__PURE__ */ new WeakSet,Zt=e=>(Xt.add(e),e),Qt=(e,t)=>typeof e==`object`&&Xt.has(e)?`In applying the function\n${de(U(e))},\nthe first argument is:\n${de(U(t))}\nwhich is not in its domain.\n`:`Attempted to apply function ${U(e)} to ${U(t)}, which is not in its domain`,$t=(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 Wt(e,t)},en=(e,t,n)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!Jt(t,e.domain))throw new u(Xt.has(e)?Qt(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 u(`Attempted to apply ${U(e)}, which is not a function`);let r=$t(e.domain,t);if(r===-1)throw new u(n?.(e)??Qt(e,t));return e.range[r]},tn=e=>wt(e)?xt.get(e)??Et(e.length):void 0,nn=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=H(e).domain;return tn(t)??Fe(t)},rn=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!z(e.domain))){if(!Jt(t,e.domain))return e;let r=n(e.apply(t));return{kind:`LazyFunction`,domain:e.domain,apply:n=>lt(t,n)?r:e.apply(n),source:e.source}}let i=H(e),a=$t(i.domain,t);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=L(i.domain,o);if(l.writtenKeys=i.writtenKeys,i.hash!==0){let e=i.domain[a];l.hash=s===c?i.hash:i.hash-un(e,s)+un(e,c)|0}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-_n(e,s)+_n(e,c)|0}return l},an=/* @__PURE__ */ new WeakMap,on=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},sn=(e,t)=>Math.imul(e^t,16777619),cn=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return on(t)},ln=e=>on(fn(e)+2654435769|0),un=(e,t)=>on(Math.imul(fn(e),668265261)+fn(t)|0),dn=e=>{if(e.kind===`ModelValue`)return on(sn(cn(e.name),109));if(A(e)){if(!z(e))return cn(xn(e));let t=B(e).elements,n=1940243425;for(let e=0;e<t.length;e++)n=n+ln(t[e])|0;return n}let t=H(e),n=1725019383;for(let e=0;e<t.domain.length;e++)n=n+un(t.domain[e],t.range[e])|0;return n},fn=e=>{if(typeof e==`number`)return on(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return cn(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=dn(e)),e.hash;let t=an.get(e);if(t!==void 0)return t;let n=dn(e);return an.set(e,n),n},pn=/* @__PURE__ */ new WeakMap,mn=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 mn(t)},gn=e=>mn(yn(e)+2135587861|0),_n=(e,t)=>mn(Math.imul(yn(e),374761393)+yn(t)|0),vn=e=>{if(e.kind===`ModelValue`)return mn(hn(e.name)^60);if(A(e)){if(!z(e))return hn(xn(e));let t=B(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+gn(t[e])|0;return n}let t=H(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+_n(t.domain[e],t.range[e])|0;return n},yn=e=>{if(typeof e==`number`)return mn(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=vn(e)),e.fingerprint;let t=pn.get(e);if(t!==void 0)return t;let n=vn(e);return pn.set(e,n),n},bn=/* @__PURE__ */ new WeakMap,xn=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=bn.get(e);if(t!==void 0)return t;let n=Sn(e);return bn.set(e,n),n},Sn=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${xn(e.base)}>`;if(e.kind===`FilteredSet`&&!z(e))throw new u(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(A(e))return z(e)?`{${B(e).elements.map(xn).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let t=H(e);return`(${t.domain.map((e,n)=>`${xn(e)}:${xn(t.range[n])}`).join(`,`)})`},Cn=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,wn=e=>e.reduce((e,t)=>e===0?0:e*Vt(t),1),Tn=e=>{if(e.kind===`Subset`)return Vt(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)&&Vt(e.domain)===0)return Fe([L([],[])]);let t=e.kind===`FunctionSet`?Vt(e.range)**Vt(e.domain):wn(e.kind===`RecordSet`?e.sets:e.factors);return t===0?pt:t<=1999?B(e):void 0},En=(e,t)=>{if(t)return Tn(e);if(z(e))try{return Tn(e)}catch(e){if(e instanceof u)return;throw e}},Dn=(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 kt(e,t)}},On=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 Cn(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=En(e,t);return n?r(n):Dn(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 t=H(e);return t.domain.every((e,t)=>e===t+1)?`<<${t.range.map(r).join(`, `)}>>`:t.domain.every(e=>typeof e==`string`&&On(e))?`[${(n||t.hash!==0||t.fingerprint!==0?t.domain.map((e,n)=>[e,t.range[n]]):ge(t)).map(e=>`${String(e[0])} |-> ${r(e[1])}`).join(`, `)}]`:`(${t.domain.map((e,n)=>`${r(e)} :> ${r(t.range[n])}`).join(` @@ `)})`}}},kn=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},An=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=fn(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||Re(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||Re(i[e],n))return i[e]}return n.kind===`Set`?kn(n.elements,t):(kn(n.domain,t),kn(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}},jn=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`,Mn=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),Nn=(e,t)=>Mn.has(e)?new u(t):new d(t),Pn=e=>typeof e==`object`&&e.kind===`Operator`,G=(e,t,n)=>{let r=e[t];if(r===void 0||Pn(r))throw Nn(n,`${n} expects a value as argument ${t+1}`);return r},Fn=(e,t,n)=>{let r=G(e,t,n);if(typeof r!=`number`)throw Nn(n,`${n} expects an integer but received ${U(r)}`);return r},In=(e,t,n)=>{let r=G(e,t,n);if(typeof r!=`boolean`)throw Nn(n,`${n} expects a boolean but received ${U(r)}`);return r},Ln=(e,t,n)=>{let r=G(e,t,n);if(!A(r))throw Nn(n,`${n} expects a set but received ${U(r)}`);return r},Rn=(e,t,n)=>{let r=Ln(e,t,n);if(!z(r))throw Nn(n,`${n} cannot enumerate the non-enumerable set ${U(r)}`);return r},zn=(e,t,n)=>B(Rn(e,t,n)),Bn=(e,t,n)=>zn(e,t,n).elements,Vn=(e,t,n)=>{let r=G(e,t,n),i=Gt(r);if(!i)throw Nn(n,`${n} expects a sequence but received ${U(r)}`);return i},Hn=(e,t,n)=>{let r=G(e,t,n);if(!j(r))throw Nn(n,`${n} expects a function but received ${U(r)}`);return H(r)},Un=(e,t,n)=>{let r=e[t];if(r===void 0||!Pn(r))throw Nn(n,`${n} expects an operator as argument ${t+1}`);return r},Wn=(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}),Gn=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Kn=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),qn=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(G(n,0,e),G(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Jn=e=>e>2147483647||e<-2147483648,Yn=e=>new d(`Overflow when computing ${e}`),Xn={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`},Zn={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},Qn={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`},$n=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Zn[e.operator];if(e.kind!==`Function`)return Xn[e.kind];let t=e.domain;return t.every((e,t)=>e===t+1)?`TupleValue`:t.every(e=>typeof e==`string`)?`RecordValue`:`FcnRcdValue`},er=e=>Qn[$n(e)],tr=(e,t)=>new u(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),nr=(e,t)=>{let n=n=>(...r)=>{try{return n(...r)}catch(n){throw n instanceof u&&(e.isLazy===!0||!(n instanceof d))?tr(t,n.message):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},rr=(e,t)=>{if(typeof e!=`number`)throw tr(t,`Cannot cast tlc2.value.impl.${$n(e)} to tlc2.value.impl.IntValue`);return e},ir=(e,t,n)=>`public static tlc2.value.impl.${t} tlc2.module.Integers.${e}(${Array.from({length:n},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,ar=(e,t,n)=>{let r=ir(t,`IntValue`,2);return qn(e,(t,i)=>{let a=rr(t,r),o=rr(i,r),s=n(a,o);if(Jn(s))throw Yn(`${a}${e}${o}`);return s})},or=(e,t,n)=>{if(typeof e!=`number`)throw new d(`The ${t} argument of ${n} should be an integer, but instead it is:\n${U(e)}`);return e},sr=(e,t)=>qn(e,(n,r)=>t(or(n,`first`,e),or(r,`second`,e))),cr=(e,t,n)=>({...Kn(e,t,n),isLazy:!0}),lr=(e,t,n)=>{let r=Un(e,t,n);return()=>r.call([])},ur=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),dr=()=>({bool:Ka,condition:(e,t)=>{if(typeof e!=`boolean`)throw Fa(t,e);return e},conjunct:(e,t,n)=>{if(typeof e!=`boolean`)throw Ia(t,n,e);return e},apply:en,tuple:R,set:ft,record:L,writtenRecord:_e,equal:Ie,enumerate:Za,unassigned:(e,t)=>{throw Cs(e,t)},primeOutsideAction:e=>{throw ws(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)=>Ua(e,t,n[r]),e.scope),state:e.state,next:e.next})}),fr={value:void 0},pr=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),mr=e=>`local${e.counter++}`,hr=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),jn(e).forEach(e=>hr(e,t)),t),gr=(e,t,n)=>{let r=pr(e,Y(t,e.environment)),i=hr(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=pr(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},_r=(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(()=>mr(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${yr(e,t.set,s)}, ${pr(e,t.set)});`),u=t.bounds.map(t=>{let n=mr(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${yr(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=mr(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})`},vr=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${yr(e,r[0],n)}, "the left side of =>") ? bool(${yr(e,r[1],n)}, "the right side of =>") : true)`;if(W(t))return gr(e,t,n);let i=fo(t.operator,e.environment);if(i?.kind!==`Builtin`)return gr(e,t,n);if(i.name===`DOMAIN`)return`${pr(e,Ra(t))}(${yr(e,r[0],n)})`;if(i.name===`TLCEval`)return gr(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${pr(e,za(t,i))}(${yr(e,r[0],n)}, ${yr(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&rs(r[0],a))return`${pr(e,i.evaluateUnary)}(${yr(e,r[0],n)})`;let o=r.length===2&&rs(r[0],a)&&rs(r[1],a);return i.evaluateBinary&&o?`${pr(e,i.evaluateBinary)}(${yr(e,r[0],n)}, ${yr(e,r[1],n)})`:gr(e,t,n)},yr=(e,t,n)=>{let r=(t,r=n)=>yr(e,t,r);if(qo(t)&&Ho(t,e.environment))return gr(e,t,n);switch(t.kind){case`Number`:return Ao(t.value)?String(t.value):gr(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 gr(e,t,n);let i=So(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=pr(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?pr(e,i.value):gr(e,t,n)}case`Apply`:return vr(e,t,n);case`And`:{let n=pr(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)}, ${pr(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{_s(t.function);let e=r(t.function);return t.args.length===1?`apply(${e}, ${r(t.args[0])})`:`apply(${e}, tuple([${t.args.map(e=>r(e)).join(`, `)}]))`}case`FieldAccess`:return`apply(${r(t.record)}, ${JSON.stringify(t.field)}, ${pr(e,La(t))})`;case`Record`:{let i=xs(t.fields);if(Ss(i))return gr(e,t,n);let a=pr(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}, ${pr(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=pr(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`)?_r(e,t,n):gr(e,t,n);default:return gr(e,t,n)}},br=(e,t)=>{if(!ur.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=yr(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(`
23
+ `)}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${r}; };`;fr.value??=dr();let o=fr.value,s=Object.keys(o);return Function(...s,...i,a)(...Object.values(o),...n.references)},xr={kind:`Local`},Sr=/* @__PURE__ */ new WeakMap,Cr=e=>{let t=e.lastIndexOf(`@`);return t>0&&t<e.length-1},wr=new Map([`~>`,`-+->`,`\\cdot`].map(e=>[e,{key:e,arity:2}])),Tr=(e,t)=>e.line<t.line||e.line===t.line&&e.column<t.column,Er=e=>e.kind===`Operator`?e.params.length:0,Dr=e=>e.name.includes(`!`),Or=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n},kr=(e,t,n=0)=>t.reduce((e,t)=>({name:t,arity:n,parent:e}),e),Ar=(e,t)=>t.reduce((e,t)=>({name:t.name,arity:t.arity,parent:e}),e),jr=e=>e.kind===`Name`?[e.name]:e.names,Mr=e=>e.flatMap(e=>jr(e.pattern)),Nr=(e,t)=>{let n=t.definitions.get(e);return n!==void 0&&(n===t.self?n.kind===`Function`||n.isRecursive:n.isRecursive||Tr(n.location,t.location))?n:void 0},Pr=(e,t)=>{let n=Nr(e,t);return n?{key:t.getKey(n),arity:Er(n)}:t.imported.get(e)},Fr=e=>e[0].toLowerCase()===e[0].toUpperCase()&&e[0]!==`_`&&(e[0]<`0`||e[0]>`9`),Ir=e=>e.startsWith(`<`)&&(e[1]>=`0`&&e[1]<=`9`||e[1]===`*`),Lr=(e,t,n,r)=>{let i=e.location,a=Sr.get(e);if(a!==void 0)return a;if(Cr(t))return e.kind===`Apply`?e.args.length:0;if(Ir(t))return 0;let o=Or(n,t);if(o&&e.kind!==`OperatorReference`&&(e.resolution=xr),o)return o.arity;let s=Pr(t,r);if(s)return e.kind===`Identifier`?e.name=s.key:e.operator=s.key,Sr.set(e,s.arity),s.arity;let l=t.slice(0,t.indexOf(`!`));if(l!==``&&(Or(n,l)!==void 0||Pr(l,r)!==void 0||r.facts.has(l)))return e.kind===`Apply`?e.args.length:0;let u=`at line ${i.line}, column ${i.column}`;throw new c(Fr(t)?`Could not find declaration or definition of symbol '${t}' ${u}`:`Unknown operator: \`${t}' ${u}`)},Rr=(e,t,n)=>(e.forEach(e=>q(e.set,t,n)),e.reduce((e,t)=>kr(e,jr(t.pattern)),t)),zr=(e,t)=>e.kind===`Identifier`&&e.name===t&&W(e)||jn(e).some(e=>zr(e,t)),Br=(e,t)=>{e.kind===`FunctionConstruction`&&zr(e.body,t)&&(e.isRecursive=!0),jn(e).forEach(e=>Br(e,t))},Vr=(e,t,n)=>{let r=kr(t,e.kind===`Function`?[e.name]:[]);e.kind===`Function`?(q(e.body,Rr(e.bounds,r,n),n),Br(e.body,e.name)):q(e.body,Ar(r,e.params),n)},Hr=(e,t,n)=>{let r=e.filter(e=>e.isRecursive).reduce((e,t)=>({name:t.name,arity:Er(t),parent:e}),t);return e.reduce((e,t)=>(Dr(t)||Vr(t,e,n),{name:t.name,arity:Er(t),parent:e}),r)},Ur=(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 c(`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 c(`Argument number ${t+1} to operator '${e.name}' should be a ${a.arity}-parameter operator at line ${o.line}, column ${o.column}`)},Wr=e=>e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:void 0,Gr=(e,t,n)=>{let r=Or(t,e.operator)?void 0:Nr(e.operator,n),i=Lr(e,e.operator,t,n);if(i!==e.args.length)throw new c(`The operator ${e.operator} requires ${i} arguments at line ${e.location.line}, column ${e.location.column}`);e.args.forEach((e,i)=>{let a=Wr(e),o=a===void 0||Or(t,a)?void 0:Nr(a,n),s=Kr(e,t,n);r&&Ur(r,i,e,s,o)})},Kr=(e,t,n)=>e.kind===`Identifier`?Lr(e,e.name,t,n):e.kind===`OperatorReference`?Lr(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=Lr(e,e.name,t,n);if(r>0)throw new c(`The operator ${e.name} requires ${r} arguments at line ${e.location.line}, column ${e.location.column}`);return}case`OperatorReference`:Lr(e,e.operator,t,n);return;case`Apply`:Gr(e,t,n);return;case`Lambda`:q(e.body,kr(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,Hr(e.definitions,t,n),n);return;case`Forall`:case`Exists`:case`FunctionConstruction`:q(e.body,Rr(e.bounds,t,n),n);return;case`UnboundedQuantifier`:q(e.body,kr(t,e.names),n);return;case`Choose`:e.set&&q(e.set,t,n),q(e.body,kr(t,jr(e.pattern)),n);return;case`SetEnumeration`:case`Tuple`:r(e.elements);return;case`SetFilter`:q(e.predicate,Rr([e.bound],t,n),n);return;case`SetMap`:q(e.expression,Rr(e.bounds,t,n),n);return;case`FunctionSet`:r([e.domain,e.range]);return;case`Record`:case`RecordSet`:if(new Set(e.fields.map(e=>e.name)).size<e.fields.length)throw new c(`Non-unique fields in constructor at line ${e.location.line}, column ${e.location.column}`);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=>Kr(e,t,n))}},qr=(e,t,n)=>(e.set&&q(e.set,t,n),{name:e.name,arity:e.arity,parent:t}),Jr=(e,t,n)=>{let r=e.assumptions.reduce((e,t)=>t.kind===`NewSymbol`?qr(t,e,n):(t.kind===`AssumeProve`?Jr(t,e,n):q(t,e,n),e),t);return q(e.conclusion,r,n),r},Yr=(e,t,n)=>e.kind===`AssumeProve`?Jr(e,t,n):(q(e,t,n),t),Xr=(e,t,n)=>{e?.kind===`Steps`&&e.steps.reduce((e,t)=>Zr(t,e,n),t)},Zr=(e,t,n)=>{let r=e.body;switch(r.kind){case`Assert`:{let i=Yr(r.statement,t,n);return Xr(e.proof,i,n),r.isSuffices?i:t}case`Define`:return Hr(r.definitions.flatMap(e=>e.kind===`Instance`?[]:[e]),t,n);case`Have`:case`Case`:return q(r.expression,t,n),Xr(e.proof,t,n),t;case`Witness`:return r.expressions.forEach(e=>q(e,t,n)),t;case`Take`:return kr(Rr(r.bounds,t,n),r.names);case`Pick`:{let i=kr(Rr(r.bounds,t,n),r.names);return q(r.body,i,n),Xr(e.proof,t,n),i}default:return Xr(e.proof,t,n),t}},Qr=(e,t)=>{let n=e.name!==void 0&&e.statement.kind!==`AssumeProve`?void 0:Yr(e.statement,void 0,t);Xr(e.proof,n,t)},$r=(e,t)=>new c(`Multiply-defined symbol '${e}' at line ${t.line}, column ${t.column}`),ei=(e,t,n,r)=>t.reduce((e,t)=>{if(Or(e,t)||n(t))throw $r(t,r);return{name:t,arity:0,parent:e}},e),ti=(e,t,n,r)=>(e.forEach(e=>ri(e.set,t,n)),e.reduce((e,t)=>ei(e,jr(t.pattern),n,r),t)),ni=(e,t,n)=>{if(e.kind===`Function`){let r=kr(t,[e.name]),i=ti(e.bounds,r,n,e.location);ri(e.body,i,n);return}let r=ei(t,e.params.map(e=>e.name),n,e.location);ri(e.body,r,n)},ri=(e,t,n)=>{let r=e.location;switch(e.kind){case`Lambda`:ri(e.body,ei(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(Or(e,t.name)||n(t.name))throw $r(t.name,t.location);return ni(t,kr(e,i),n),kr(e,[t.name])},t);ri(e.body,ei(a,(e.instances??[]).flatMap(e=>e.name===void 0?[]:[e.name]),n,r),n);return}case`Forall`:case`Exists`:case`FunctionConstruction`:ri(e.body,ti(e.bounds,t,n,r),n);return;case`SetFilter`:ri(e.predicate,ti([e.bound],t,n,r),n);return;case`SetMap`:ri(e.expression,ti(e.bounds,t,n,r),n);return;case`UnboundedQuantifier`:ri(e.body,ei(t,e.names,n,r),n);return;case`Choose`:e.set&&ri(e.set,t,n),ri(e.body,ei(t,jr(e.pattern),n,r),n);return;default:jn(e).forEach(e=>ri(e,t,n))}},ii=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}))],ai=(e,t)=>{let n=/* @__PURE__ */ new Map;ii(e).sort((e,t)=>Tr(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)&&!wr.has(e))return!1;let r=t.importedAt.get(e);return r===void 0||Tr(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 $r(n.name,n.location)}));let i=e=>t=>(n.get(t)??[]).some(t=>t.isRecursive||Tr(t.location,e))||r(t,e);e.definitions.forEach(e=>ni(e,void 0,i(e.location))),e.assumptions.forEach(e=>ri(e.expression,void 0,i(e.location))),e.instances.forEach(e=>{let t=i(e.location),n=ei(void 0,e.params.map(e=>e.name),t,e.location);e.substitutions.forEach(e=>ri(e.expression,n,t))})},oi=(e,t)=>{let n=new Map([...wr,...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},si=(e,t,n,r)=>{let i=Ar(void 0,e.params),a={imported:oi(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 c(`Identifier '${n}' is not a legal target of a substitution ${s}`)}),new Map(t.map(t=>{let n=t.name;if(!o.has(n)&&!Or(i,n)&&!Pr(n,a))throw new c(`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(Lr(r,r.name,i,a)!==t.arity)throw new c(`An operator must be substituted for symbol '${n}', and it must have arity ${t.arity} ${s}`);return[n,r]}))},ci=(e,t)=>{let n=oi(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});e.definitions.forEach(e=>Vr(e,void 0,i(e.location,e))),e.assumptions.forEach(e=>q(e.expression,void 0,i(e.location,void 0))),e.theorems.forEach(e=>Qr(e,i(e.location,void 0)))},li=/* @__PURE__ */ new WeakSet,ui=/* @__PURE__ */ new WeakSet,di=(e,t,n=/* @__PURE__ */ new Set)=>{let r=_i(e,(e,r)=>di(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},fi=(e,t)=>e.map(e=>({pattern:e.pattern,set:t(e.set)})),pi=/* @__PURE__ */ new WeakMap,mi=e=>pi.get(e)??e.name,hi=(e,t)=>(mi(t)!==e.name&&pi.set(e,mi(t)),e),gi=(e,t)=>hi(e.kind===`Function`?{...e,bounds:fi(e.bounds,e=>t(e,[])),body:t(e.body,Mr(e.bounds))}:{...e,body:t(e.body,e.params.map(e=>e.name))},e),_i=(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=>gi(e,(e,r)=>t(e,[...n,...r]))),body:t(e.body,n)}}case`Forall`:case`Exists`:case`FunctionConstruction`:return{...e,bounds:fi(e.bounds,n),body:t(e.body,Mr(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,jr(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,jr(e.bound.pattern))};case`SetMap`:return{...e,bounds:fi(e.bounds,n),expression:t(e.expression,Mr(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=>({name:e.name,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)}}},vi=`LAMBDA`,yi=(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 _i(e,(e,n)=>(r.push(...yi(e,n.length===0?t:/* @__PURE__ */ new Set([...t,...n]))),e)),r},bi=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}},xi=(e,t,n)=>new Map([...e,...t.map(e=>[e,n(e)])]),Si=(e,t)=>e.kind===`Name`?{kind:`Name`,name:t(e.name)}:{kind:`Tuple`,names:e.names.map(t)},Ci=(e,t)=>e.map(e=>({pattern:Si(e.pattern,t),set:e.set})),wi=(e,t)=>e.kind===`Function`?{...e,bounds:Ci(e.bounds,t)}:{...e,params:e.params.map(e=>({name:t(e.name),arity:e.arity}))},Ti=(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=>hi({...wi(e,n),name:n(e.name)},e))};case`Forall`:case`Exists`:case`FunctionConstruction`:case`SetMap`:return{...e,bounds:Ci(e.bounds,n)};case`UnboundedQuantifier`:return{...e,names:e.names.map(n)};case`Choose`:return{...e,pattern:Si(e.pattern,n)};case`SetFilter`:return{...e,bound:{pattern:Si(e.bound.pattern,n),set:e.bound.set}};default:return e}},Ei=e=>`${e}@ENABLED`,Di=(e,t)=>e.modes.get(t)??e,Oi=(e,t,n)=>e.kind===`Identifier`&&!n.has(e.name)&&!W(e)&&t.instantiation.variables.has(e.name),ki=(e,t,n)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>ki(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`)return;if(Oi(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?ki(r.body,t,/* @__PURE__ */ new Map):void 0},Ai=(e,t,n)=>{if(t.mode===`Normal`)return;if(t.mode===`Primed`)return Oi(e,t,n)&&e.kind===`Identifier`?{kind:`Identifier`,name:Ei(e.name),location:e.location}:void 0;if(e.kind===`Prime`)return{...e,expression:Fi(e.expression,Di(t,`Primed`),n)};if(e.kind===`AngleAction`){let r=e.location;return{kind:`And`,operands:[Fi(e.action,t,n),{kind:`Apply`,operator:`#`,args:[{kind:`Prime`,expression:Fi(e.subscript,Di(t,`Primed`),n),location:r},Fi(e.subscript,t,n)],location:r}],location:r}}if(e.kind!==`Unchanged`)return;let r=ki(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:Ei(r),location:e.location},location:e.location},Fi({kind:`Identifier`,name:r,location:e.location},t,n)],location:e.location})),location:e.location}},ji=(e,t)=>({kind:`Identifier`,name:e,location:t,resolution:{kind:`Local`}}),Mi=(e,t)=>e.map(e=>ji(e.name,t)),Ni=(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:[...Mi(t,r),...i.map(e=>ji(e,r))],location:r},location:r}},Pi=(e,t)=>e.instantiation.isParameterized(t)?Li(e,t):void 0,Fi=(e,t,n)=>{let r=e=>Fi(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:Fi(e.expression,Di(t,`Enabled`),n)};if((e.kind===`WeakFairness`||e.kind===`StrongFairness`)&&t.mode===`Normal`)return{...e,subscript:r(e.subscript),action:r(e.action),enabled:Fi(e.enabled??{kind:`AngleAction`,action:e.action,subscript:e.subscript,location:e.location},Di(t,`Enabled`),n)};let s=Ai(e,t,n);if(s)return s;if(e.kind===`Identifier`&&o(e.name)){let n=i.substitutions.get(e.name);if(n)return li.add(n),n;let r=Pi(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&&Er(o)>0?Ni(r,a,Er(o),e.location):{kind:`Apply`,operator:r,args:Mi(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||ui.has(e),l=e=>(s&&ui.add(e),e);if(o?.kind===`Identifier`||o?.kind===`OperatorReference`){let t=o.kind===`Identifier`?o.name:o.operator;return l({...e,operator:t,args:n,resolution:o.kind===`Identifier`?o.resolution:void 0})}if(o?.kind===`Apply`)return l({...e,operator:o.operator,args:[...o.args,...n],resolution:o.resolution});if(o?.kind===`Lambda`)return{kind:`Let`,definitions:[{kind:`Operator`,name:vi,params:o.params.map(e=>({name:e,arity:0})),body:o.body,isLocal:!0,isRecursive:!1,location:o.location}],body:{...e,operator:vi,args:n,resolution:{kind:`Local`}},location:e.location};if(o)throw new c(`The operator ${e.operator} can only be substituted by an operator at line ${e.location.line}, column ${e.location.column}`);let u=Pi(t,e.operator);return u===void 0?l({...e,args:n}):{...e,operator:u,args:[...Mi(a,e.location),...n]}}if(e.kind===`OperatorReference`&&o(e.operator)){let n=Pi(t,e.operator);if(n===void 0)return e;let r=i.getDefinition(e.operator);return a.length>0&&r?Ni(n,a,Er(r),e.location):{...e,operator:n}}let l=bi(t),u=_i(e,(e,i)=>i.length===0?r(e):Fi(e,t,xi(n,i,l)));return Ti(u,n,l)},Ii=(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:ji(e.name,n),location:n},isLocal:e.isLocal,isRecursive:!1,location:e.location},Li=(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(i.name,n=>{e.copies.set(t,n);let a=bi(e),o=wi(gi(i,(t,n)=>Fi(t,e,xi(/* @__PURE__ */ new Map,n,a))),a);return Ii(o,r.params,i.location)}):t},Ri=e=>{let t=/* @__PURE__ */ new Map,n=new Set([...e.substitutions.values()].flatMap(e=>yi(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=>Pi(i,e)??e,getQualifiedKey:t=>{let n=Pi(i,t);if(n!==void 0)return n;let r=e.getDefinition(t);return r?e.addDefinition(r.name,()=>Ii(r,e.params,r.location)):t}}},zi=e=>e.kind===`Let`&&e.instances!==void 0||jn(e).some(zi),Bi=(e,t,n)=>{let r=e.kind===`Let`?[...n,...e.definitions]:n,i=_i(e,e=>Bi(e,t,r));return i.kind!==`Let`||!i.instances?i:{kind:`Let`,definitions:i.instances.reduce((e,n)=>{let i=e.findIndex(e=>Tr(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}},Vi=e=>e.name===void 0&&e.statement.kind!==`AssumeProve`?e.statement:void 0,Hi=(e,t)=>e.definitions.some(e=>zi(e.body))||e.assumptions.some(e=>zi(e.expression))||e.theorems.some(e=>{let t=Vi(e);return t!==void 0&&zi(t)})?{...e,definitions:e.definitions.map(e=>gi(e,e=>Bi(e,t,[]))),assumptions:e.assumptions.map(e=>({...e,expression:Bi(e.expression,t,[])})),theorems:e.theorems.map(e=>{let n=Vi(e);return n===void 0?e:{...e,statement:Bi(n,t,[])}})}:e,Ui=/* @__PURE__ */ new WeakMap,Wi=/* @__PURE__ */ new WeakMap,Gi=(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},Ki=(e,t,n)=>{let r=e.slice();return r[t]=n,r},qi=(t,r)=>{let i=X(t,r);if(typeof i==`boolean`)return i;try{return Ka(i,`the action at ${J(t)}`)}catch(t){throw r.next===void 0?t:n(t,e.error)}},Ji=e=>e===`=`||e===`\\in`||e===`\\subseteq`,Yi=(e,t,n)=>{let r=n?Ui:Wi,i=r.get(e);if(i)return i;let a=Ca(e,t,n);return r.set(e,a),a},Xi=(e,t)=>{if(t.constants.has(e))return;let n=qa(e,t);return n?.kind===`Operator`&&n.params.length===0?n:void 0},Zi=(e,t,n,r=/* @__PURE__ */ new Set)=>{if(e.kind===`Prime`&&n)return Zi(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=Xi(e.name,t);if(a&&!r.has(a))return r.add(a),Zi(a.body,t,n,r)},Qi=(e,t,n)=>Zi(e,t,!n),$i=(e,t,n,r,i)=>{if(e.kind===`Prime`&&i)return $i(e.expression,t,n,r,!1);if(e.kind===`Let`){let a=Oo(e.definitions,Gi(r,t,n));return $i(e.body,a,n,r,i)}if(e.kind!==`Identifier`)return;let a=Ha(t,e.name);if(a?.kind===`Thunk`)return $i(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=Xi(e.name,r.environment);if(s)return $i(s.body,void 0,n,r,i)},ea=(e,t)=>e.kind===`Let`||e.kind===`Identifier`&&(t||W(e))||!t&&e.kind===`Prime`,ta=(e,t,n=/* @__PURE__ */ new Set)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>ta(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=Xi(e.name,t);if(i)return n.add(e.name),ta(i.body,t,n)},na=/* @__PURE__ */ new Set([`Label`,`And`,`Or`,`Exists`,`Forall`,`If`,`Case`,`Let`,`Unchanged`,`BoxAction`,`AngleAction`,`FunctionApplication`]),ra=(e,t,n)=>na.has(e.kind)?!1:e.kind===`Identifier`?t.variableIndex.has(e.name)||t.constants.has(e.name):e.kind===`Apply`?e.operator===`=>`||Ji(e.operator)&&(ea(e.args[0],n)||Qi(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,ia=/* @__PURE__ */ new Set,aa=(e,t)=>{if(W(e))return e.kind===`Identifier`?t.has(e.name)?[]:[e.name]:void 0;let n=[],r={isReadOnly:!0};return _i(e,(e,i)=>{let a=r.isReadOnly?aa(e,i.length===0?t:/* @__PURE__ */ new Set([...t,...i])):[];return a?n.push(...a):r.isReadOnly=!1,e}),r.isReadOnly?n:void 0},oa=(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:qa(r,t);return i&&!n.has(i)&&(n.add(i),oa(i.body,t,n))?!0:jn(e).some(e=>oa(e,t,n))},sa=(e,t,n)=>{if(e.kind===`Apply`&&e.operator===`=`){let r=Qi(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=ta(e.expression,t);if(n)return{kind:`Unchanged`,expression:e,indices:n}}return ra(e,t,n)?{kind:`Guard`,expression:e}:{kind:`Branch`,expression:e,runner:Yi(e,t,n)}},ca=(e,t,n)=>{let r=e.map(e=>sa(e,t,n)),i=(e,t,n,a,o,s)=>{let c=a,l;for(let a=e;a<r.length;a++){if(a>0&&t.isInit&&Da(c)){l??=Gi(t,n,c);for(let e=a;e<r.length;e++)if(!la(r[e].expression,l))return;s(c,o);return}let e=r[a];if(e.kind===`Guard`){if(l??=Gi(t,n,c),!qi(e.expression,l))return;continue}if(e.kind===`Assign`){l??=Gi(t,n,c);let r=X(e.value,l),i=c[e.index];if(i===void 0)c=Ki(c,e.index,r),l=void 0;else if(!Ie(i,r))return;continue}if(e.kind===`Unchanged`){let n=t.current;if(!n)return;for(let t of e.indices){let e=c[t];if(e===void 0)c=Ki(c,t,n[t]),l=void 0;else if(!Ie(e,n[t]))return}continue}let u=a+1;e.runner(t,n,c,o,!0,(e,r)=>i(u,t,n,e,r,s));return}s(c,o)};return(e,t,n,r,a,o)=>i(0,e,t,n,r,o)},la=(e,t)=>Ka(X(e,t),`the initial predicate at ${J(e)}`),ua=e=>(t,n,r,i,a,o)=>{qi(e,Gi(t,n,r))&&o(r,i)},da=(e,t)=>{let n=e.args[1];return(r,i,a,o,s,c)=>{let l=t(r,i,a),d=Gi(r,i,a);if(a[l]!==void 0){qi(e,d)&&c(a,o);return}let f=X(n,d),p=e.operator===`\\subseteq`?{kind:`Subset`,base:f}:f;if(!z(p))throw new u(`In computing next states, the right side of \\in is not enumerable: ${U(p)} at ${J(e)}`);let m=Rt(p);for(let e=0;e<m.length&&!r.isStopped;e++)c(Ki(a,l,m[e]),o)}},fa=/* @__PURE__ */ new WeakMap,pa=e=>{let t=fa.get(e);if(t)return t;let n=e.kind===`Tuple`?{kind:`And`,operands:e.elements.map(pa),location:e.location}:{kind:`Unchanged`,expression:e,location:e.location};return fa.set(e,n),n},ma=(e,t)=>{let n=e.args[0],r=ua(e),i=(e,r,i)=>$i(n,r,i,e,!t)??-1,a=da(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],Gi(t,n,o));l(Ki(o,u,d),s)}},ha=(e,t,n,r)=>{if(e.kind===`FunctionConstruction`)return{bounds:e.bounds,body:e.body,scope:t};if(e.kind!==`Identifier`)return;let i=Ha(t,e.name);if(i?.kind===`Thunk`)return ha(i.expression,i.scope,n,r);let a=i?void 0:qa(e.name,r.environment);if(a?.kind!==`Function`)return;let o=X(e,Gi(r,void 0,n));return{bounds:a.bounds,body:a.body,scope:Ua(void 0,a.name,o)}},ga=(e,t,n)=>{let r=ua(e);return(i,a,o,s,c,l)=>{let d=ha(e.function,a,o,i);if(!d){r(i,a,o,s,c,l);return}let f=Gi(i,a,o),p=e.args.map(e=>X(e,f)),m=p.length===1?p[0]:R(p),h=$a(d.bounds,Gi(i,d.scope,o));if(!Jt(m,h))throw new u(`Attempted to apply a function to ${U(m)}, which is not in its domain at ${J(e)}`);Yi(d.body,t,n)(i,eo(d.bounds,d.scope,m),o,s,c,l)}},_a=(e,t)=>{if(ta(e,t))return ca([pa(e)],t,!1);if(e.kind===`Tuple`)return Yi(pa(e),t,!1);let n=pa(e);return(r,i,a,o,s,c)=>{let l=e.kind===`Identifier`?Ha(i,e.name):void 0;l?.kind===`Thunk`?Yi(pa(l.expression),t,!1)(r,l.scope,a,o,s,c):qi(n,Gi(r,i,a))&&c(a,o)}},va=(e,t,n)=>{let r=e.operator,i=ua(e),a=W(e)?void 0:fo(r,t);if(a?.kind===`Builtin`)return i;if(a?.kind===`Closure`){let i=os(a,e.args,t),o={body:void 0};return(e,s,c,l,u,d)=>{o.body??=Yi(a.body,t,n),o.body(e,i(Gi(e,s,c)),c,u?l:r,u,d)}}return(a,o,s,c,l,u)=>{let d=Gi(a,o,s),f=mo(e,d);f?.kind===`Closure`?Yi(f.body,t,n)(a,Eo(f,e.args,d),s,l?c:r,l,u):i(a,o,s,c,l,u)}},ya=(e,t,n)=>{let r=ua(e),i=W(e)?void 0:Xi(e.name,t),a={body:void 0};return(o,s,c,l,u,d)=>{let f=Ha(s,e.name);f?.kind===`Thunk`?Yi(f.expression,t,n)(o,f.scope,c,l,u,d):f||!i?r(o,s,c,l,u,d):(a.body??=Yi(i.body,t,n),a.body(o,void 0,c,u?l:i.name,u,d))}},ba=(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=Zi(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=>ba(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=fo(e.operator,t);if(r?.kind!==`Closure`||r.scope!==void 0)return;let i=ba(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}},xa=(e,t,n)=>{let r=Ha(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},Sa=(e,t,n)=>{let r=e.map(e=>Yi(e,t,n)),i=n?[]:e.map(e=>ba(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&&xa(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)}},Ca=(e,t,n)=>{let r=e=>Yi(e,t,n);switch(e.kind){case`And`:return ca(e.operands,t,n);case`Or`:return Sa(e.operands,t,n);case`Exists`:{let t=r(e.body),n=e.bounds[0];if(e.bounds.length===1&&n.pattern.kind===`Name`){let e=n.pattern.name;return(r,i,a,o,s,c)=>{let l=Za(X(n.set,Gi(r,i,a)),n.set);for(let n=0;n<l.length&&!r.isStopped;n++)t(r,Ua(i,e,l[n]),a,o,s,c)}}return(n,r,i,a,o,s)=>{Qa(e.bounds,Gi(n,r,i),e=>(t(n,e,i,a,o,s),n.isStopped))}}case`Forall`:{let i=r(e.body),a=!n&&ks(e,t)!==void 0&&!oa(e.body,t,/* @__PURE__ */ new Set)?aa(e,ia):void 0;return(t,n,r,o,s,c)=>{let l=[];Qa(e.bounds,Gi(t,n,r),e=>(l.push(e),!1));let u=[...l.slice(0,1),...l.slice(1).reverse()];if(a?.every(e=>Ha(n,e)?.kind===`Value`)){u.every(n=>qi(e.body,Gi(t,n,r)))&&c(r,o);return}let d=(n,r,a)=>{n===u.length?c(r,a):n>0&&t.isInit&&Da(r)?u.slice(n).every(n=>la(e.body,Gi(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,Gi(r,i,a));(Ka(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,s,c,l)=>{let d=Gi(r,i,a),f=t.find(e=>Ka(X(e.condition,d),`a CASE guard`))?.body??n;if(!f)throw new u(`${o}In computing next states, TLC encountered a CASE with no conditions true.\n${Pa(e)}`);f(r,i,a,s,c,l)}}case`Let`:{let n=r(e.body),i=Ro(e.definitions,t);return(t,r,a,o,s,c)=>n(t,Oo(e.definitions,Gi(t,r,a),i),a,o,s,c)}case`Unchanged`:return n?()=>{throw new u(`UNCHANGED appears in an initial predicate at ${J(e)}`)}:_a(e.expression,t);case`AngleAction`:{let t=r(e.action),n=pa(e.subscript);return(e,r,i,a,o,s)=>t(e,r,i,a,o,(t,i)=>{qi(n,Gi(e,r,t))||s(t,i)})}case`BoxAction`:return r({kind:`Or`,operands:[e.action,pa(e.subscript)],location:e.location});case`Label`:return r(e.body);case`Identifier`:return ya(e,t,n);case`FunctionApplication`:return ga(e,t,n);case`Apply`:{let i=e.args;if(Ji(e.operator)){let r=Qi(i[0],t,n);if(r!==void 0)return e.operator===`=`?ca([e],t,n):da(e,()=>r);if(ea(i[0],n))return ma(e,n)}if(e.operator===`=>`){let e=r(i[1]);return(t,n,r,a,o,s)=>{let c=X(i[0],Gi(t,n,r));(typeof c==`boolean`?c:Ka(c,`the left side of => at ${J(i[0])}`))?e(t,n,r,a,o,s):s(r,a)}}return va(e,t,n)}default:return ua(e)}},wa=/* @__PURE__ */ new WeakMap,Ta=e=>{let t=wa.get(e);if(t)return t;let n=e.variables.map(()=>void 0);return wa.set(e,n),n},Ea=(e,t)=>t.variables.filter((t,n)=>e[n]===void 0),Da=e=>{for(let t=0;t<e.length;t++)if(e[t]===void 0)return!1;return!0},Oa=(e,t)=>{let n=t.state;if(!n||!Da(n))throw new u(`ENABLED needs a complete state at ${J(e)}`);let r=t.environment,i={environment:r,isInit:!1,current:n,isStopped:!1};return Yi(e,r,!1)(i,t.scope,Ta(r),void 0,!1,()=>{i.isStopped=!0}),i.isStopped},ka=(t,r,i,a)=>{let o={environment:r,isInit:!0,current:void 0,isStopped:!1};Yi(t,r,!0)(o,a,Ta(r),void 0,!1,t=>{if(!o.isStopped){if(!Da(t))throw n(new u(`The initial predicate does not assign ${Ea(t,r).join(`, `)}`),e.error);o.isStopped=i(t)}})},Aa=(e,t,n)=>{let r=[];return ka(e,t,e=>(r.push(e),!1),n),r},ja=(e,t,n,r,i)=>{let a={environment:n,isInit:!1,current:t,isStopped:!1},o={successors:0};return Yi(e,n,!1)(a,i,Ta(n),void 0,!1,(e,t)=>{if(!a.isStopped){if(!Da(e))throw new u(`Successor state is not completely specified by action ${t??`Next`}. The following variables are not assigned: ${Ea(e,n).join(`, `)}`);o.successors++,a.isStopped=r({state:e,action:t})}}),o.successors},Ma=(e,t,n,r)=>{let i=[];return ja(e,t,n,e=>(i.push(e),!1),r),i},J=e=>`line ${e.location.line}, column ${e.location.column}`,Na=e=>`line ${e.start.line}, col ${e.start.column} to line ${e.end.line}, col ${e.end.column} of module ${e.module}`,Pa=e=>{let t=e.location.range;return t?Na(t):J(e)},Fa=(e,t)=>new u(`A non-boolean expression (${er(t)}) was used as the condition of an IF.\n${Pa(e)}`),Ia=(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):Pa(r);return new u(`A non-boolean expression (${er(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 u(`Attempted to evaluate an expression of form P /\\ Q when ${t===0?`P`:`Q`} was\n${er(n)}.\n${Pa({...e,location:{...e.location,range:{...r,end:i}}})}`)},La=e=>t=>`Attempted to select nonexistent field "${e.field}" from the record\n${U(t)}\n${Pa(e)}`,Ra=e=>t=>{if(!j(t))throw new u(`Attempted to apply the operator DOMAIN to a non-function\n(${er(t)})\n${Pa(e)}`);return nn(t)},za=(e,t)=>(n,r)=>{if(!A(n)||F(n))throw new u(`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${Pa(e)}`);return t.evaluate([n,r])},Ba=t=>n(new u(`TLC can't handle real numbers: ${t.text} at ${J(t)}`),e.configParseError),Va=t=>n(new u(`TLC can't handle a number this big: ${t.text??t.value} at ${J(t)}`),e.error),Ha=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n.binding},Ua=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n},parent:e}),Wa=(e,t,n)=>{if(t.kind===`Name`)return Ua(e,t.name,n);let r=Gt(n);if(!r||r.length!==t.names.length)throw new u(`Cannot bind <<${t.names.join(`, `)}>> to ${U(n)}, which is not a tuple of that length`);return t.names.reduce((e,t,n)=>Ua(e,t,r[n]),e)},Ga=(e,t)=>({environment:e.environment,scope:t,state:e.state,next:e.next}),Ka=(e,t)=>{if(typeof e!=`boolean`)throw new u(`Expected ${t} to be a boolean but found ${U(e)}`);return e},qa=(e,t)=>t.definitions.get(t.substitutions.get(e)??e),Ja=(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=qa(n,t);if(e&&!t.constants.has(n)&&!Ya(e,t))return!0}return jn(e).some(e=>Ja(e,t))},Ya=(e,t)=>{let n=t.constantLevels.get(e);if(n!==void 0)return n;t.constantLevels.set(e,!0);let r=!Ja(e.body,t)&&(e.kind===`Operator`||!e.bounds.some(e=>Ja(e.set,t)));return t.constantLevels.set(e,r),r},Xa=(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.`},Za=(e,t)=>{if(!A(e)||F(e)){let n=U(e),r=Xa(e,n);throw new u(r===void 0?`TLC encountered a non-enumerable quantifier bound\n${n}.\n${Pa(t)}`:`TLC encountered the non-enumerable quantifier bound\n${n}\n${Pa(t)}\n${r}`)}return typeof e==`object`&&e.kind===`Interval`?Ct(e):B(e).elements},Qa=(e,t,n)=>{let r=e.map(e=>Za(X(e.set,t),e.set)),i=(t,a)=>t<0?n(a):r[t].some(n=>i(t-1,Wa(a,e[t].pattern,n)));return i(e.length-1,t.scope)},$a=(e,t)=>{let n=e.map(e=>X(e.set,t));return n.length===1?n[0]:{kind:`ProductSet`,factors:n}},eo=(e,t,n)=>{if(e.length===1)return Wa(t,e[0].pattern,n);let r=Gt(n)??[];return e.reduce((e,t,n)=>Wa(e,t.pattern,r[n]),t)},to=/* @__PURE__ */ new WeakMap,no=(e,t)=>{let n=to.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:Na(r)};return to.set(t,i),i},ro=(e,t,n)=>{let r=no(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}},io=(e,t,n)=>{let r=/* @__PURE__ */ new Map,i={kind:`LazyFunction`,domain:e,source:n,apply:e=>{let n=fn(e),a=r.get(n);if(a!==void 0){for(let t=0;t<a.length;t+=2)if(Re(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},ao=(e,t)=>{let n=$a(e.bounds,t),r=io(n,(n,r)=>X(e.body,Ga(t,eo(e.bounds,Ua(void 0,e.name,r),n))),ro(e.bounds,e.body,n));return e.bounds.length===1?Zt(r):r},oo=(e,t)=>e.kind===`Function`?ao(e,t):X(e.body,t),so=(e,t)=>{let n=Ya(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 u(`Operator ${e.name} requires ${e.params.length} arguments`);let i=Ga(t,void 0);if(!n)return oo(e,i);let a=t.environment.runtime.evaluateAtStartup(()=>oo(e,i));return t.environment.definitionValues.set(e,a),a},co=(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,Ga(t,e.scope));return n&&(e.cache=r),r},lo=/* @__PURE__ */ new WeakMap,uo=e=>{let t=lo.get(e);if(t)return t;let n={kind:`Closure`,name:e.name,params:e.params,body:e.body,scope:void 0};return lo.set(e,n),n},fo=(e,t)=>{let n=t.substitutions.get(e);if(n!==void 0)return fo(n,t);let r=t.definitions.get(e);return r?.kind===`Operator`?uo(r):t.builtins.get(e)},po=/* @__PURE__ */ new WeakMap,mo=(e,t)=>{if(W(e))return ho(e.operator,t);let n=po.get(e),r=n===void 0?fo(e.operator,t.environment)??null:n;return n===void 0&&po.set(e,r),r??ho(e.operator,t)},ho=(e,t)=>{let n=Ha(t.scope,e);if(n?.kind===`Operator`)return n.operator;if(!n)return fo(e,t.environment)},go=e=>e.kind===`Closure`?e.params.length:e.arity,_o=(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:ho(n,t);if(!r)throw new u(`Expected an operator argument at ${J(e)}`);return r},vo=(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)=>Ua(e,n.name,t[r]),e.scope);return X(e.body,Ga(n,r))},yo=(e,t)=>e.kind===`Operator`?e:{kind:`Operator`,name:e.name,arity:go(e),call:n=>vo(e,n,t),literalBody:e.kind===`Closure`&&(e.body.kind===`Number`||e.body.kind===`String`)?e.body.value:void 0},bo=(e,t)=>{if(e.kind===`Lambda`||e.kind===`OperatorReference`)return!0;if(e.kind!==`Identifier`)return!1;let n=ho(e.name,t);return n!==void 0&&go(n)>0},xo=(e,t)=>({kind:`Thunk`,expression:e,scope:t.scope,state:t.state,next:t.next,cache:void 0}),So=(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 So(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([])}},Co=(e,t)=>{if(e.kind===`String`||e.kind===`Number`&&Ao(e.value)){let t={kind:`Value`,value:e.value};return()=>t}if(e.kind===`Identifier`){let n=W(e)?void 0:So(e.name,t);if(n?.kind===`Value`){let e={kind:`Value`,value:n.value};return()=>e}if(n===void 0)return t=>{let n=Ha(t.scope,e.name);return n?.kind===`Value`||n?.kind===`Thunk`?n:xo(e,t)}}return t=>xo(e,t)},wo=/* @__PURE__ */ new WeakMap,To=(e,t)=>{let n=wo.get(e);if(n)return n;let r=Co(e,t);return wo.set(e,r),r},Eo=(e,t,n)=>{if(t.length!==e.params.length)throw new u(`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:_o(t[i],n)}:To(t[i],n.environment)(n);r={name:a.name,binding:o,parent:r}}return r},Do=(e,t,n)=>e.kind===`Closure`?X(e.body,Ga(n,Eo(e,t,n))):e.kind===`Operator`?e.call(t.map(e=>X(e,n))):e.isLazy?e.evaluate(is(t,n),n):e.evaluate(t.map(e=>bo(e,n)?yo(_o(e,n),n):X(e,n)),n),Oo=(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),ko=(e,t,n)=>{let r=Ha(n.scope,e);if(r?.kind===`Value`)return r.value;if(r?.kind===`Thunk`)return co(r,n);if(r?.kind===`Operator`){if(go(r.operator)===0)return vo(r.operator,[],n);throw new u(`Operator ${e} is used without arguments`)}let i=So(e,n.environment);if(i?.kind===`Variable`){let r=n.state?.[i.index];if(r===void 0)throw Cs(e,t);return r}if(i?.kind===`Value`)return i.value;if(i?.kind===`Definition`)return so(i.definition,n);let a=n.environment.builtins.get(e);if(a?.arity===0)return a.evaluate([],n);throw new u(`Unknown identifier ${e} at ${J(t)}`)},Ao=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,jo=/* @__PURE__ */ new Set([`Print`,`PrintT`,`Assert`,`JavaTime`,`RandomElement`,`TLCGet`,`TLCSet`]),Mo=(e,t)=>jo.has(e)||t.builtins.get(e)?.isStateLevel===!0,No={builtins:jo,definitions:/* @__PURE__ */ new WeakMap},Po={builtins:new Set([...jo].filter(e=>e!==`Assert`)),definitions:/* @__PURE__ */ new WeakMap},Fo=(e,t)=>e.kind===`Operator`&&e.params.length===0&&Ya(e,t),Io=(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=qa(r,t),i=n.builtins.has(r)||t.builtins.get(r)?.isStateLevel===!0;if(!e&&i||e&&!Fo(e,t)&&Lo(e,t,n))return!0}return jn(e).some(e=>Io(e,t,n))},Lo=(e,t,n=No)=>{let r=n.definitions.get(e);if(r!==void 0)return r;n.definitions.set(e,!1);let i=Io(e.body,t,n)||e.kind===`Function`&&e.bounds.some(e=>Io(e.set,t,n));return n.definitions.set(e,i),i},Ro=(e,t)=>new Set(e.filter(e=>Lo(e,t))),zo=e=>[...e.definitions.values()].some(t=>Lo(t,e)),Bo=e=>[...e.definitions.values()].some(t=>Lo(t,e,Po)),Vo=/* @__PURE__ */ new WeakMap,Ho=(e,t)=>{let n=Vo.get(e);if(n!==void 0)return n;let r=Ko(e,t,Wo);return Vo.set(e,r),r},Uo=/* @__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`]),Wo=/* @__PURE__ */ new Set,Go=(e,t,n)=>n.size===0?Ho(e,t):Ko(e,t,n),Ko=(e,t,n)=>{if(!Uo.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=So(e.name,t);return n?.kind===`Value`||n?.kind===`Definition`&&Fo(n.definition,t)}if(e.kind===`Apply`){if(Mo(e.operator,t)||e.operator===`~>`)return!1;let r=fo(e.operator,t);if(r?.kind!==`Builtin`&&r?.kind!==`Closure`)return!1;if(r.kind===`Closure`){let n=qa(e.operator,t);if(!n||!Ya(n,t)||Lo(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`&&Go(e,t,n))}let r={value:!0};return _i(e,(e,i)=>(r.value&&=Go(e,t,i.length===0?n:/* @__PURE__ */ new Set([...n,...i])),e)),r.value},qo=e=>e.kind!==`Number`&&e.kind!==`String`&&e.kind!==`Identifier`,Jo=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}},Yo=(e,t)=>{if(e.kind===`Identifier`&&W(e))return!t.has(e.name);if(W(e))return!0;let n={value:!1};return _i(e,(e,r)=>(n.value||=Yo(e,r.length===0?t:/* @__PURE__ */ new Set([...t,...r])),e)),n.value},Xo=(e,t)=>li.has(e)&&qo(e)&&ks(e,t)!==void 0&&!Yo(e,Wo),Y=(e,t)=>{let n=t.evaluators.get(e);if(n)return n;let r=Es(e,t),i=qo(e)&&Ho(e,t)?Jo(r):Xo(e,t)?ts(r):r;return t.evaluators.set(e,i),i},Zo=/* @__PURE__ */ new WeakMap,Qo=(e,t)=>{let n=Zo.get(e);if(n)return n;let r=(qo(e)&&Ho(e,t)?void 0:br(e,t))??Y(e,t);return Zo.set(e,r),r},X=(e,t)=>Qo(e,t.environment)(t),$o=(e,t)=>{let n=e.name,r=W(e)?void 0:So(n,t);if(r?.kind===`Variable`){let t=r.index;return r=>{let i=r.state?.[t];if(i===void 0)throw Cs(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&&Ya(e,t))return t=>so(e,t);if(e.params.length===0){let n={body:void 0},r=r=>(n.body??=Qo(e.body,t),n.body(Ga(r,void 0)));return es(e,t)?ts(r):r}return t=>so(e,t)}if(r?.kind===`Definition`){let e=r.definition,n=t=>so(e,t);return Ya(e,t)||!es(e,t)?n:ts(n)}return t=>ko(n,e,t)},es=(e,t)=>ks(e.body,t)!==void 0&&(e.kind===`Operator`||e.bounds.every(e=>ks(e.set,t)!==void 0)),ts=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}},ns=(e,t)=>{let n=fo(e,t);return n!==void 0&&go(n)>0},rs=(e,t)=>e.kind!==`Lambda`&&e.kind!==`OperatorReference`&&!(e.kind===`Identifier`&&!W(e)&&ns(e.name,t)),is=(e,t)=>e.map(e=>({kind:`Operator`,name:`argument`,arity:0,call:()=>X(e,t),expression:e})),as=(e,t,n)=>{if(e.isLazy)return n=>e.evaluate(is(t,n),n);let r=e.evaluateUnary;if(r&&t.length===1&&rs(t[0],n)){let e=Y(t[0],n);return t=>r(e(t))}let i=e.evaluateBinary,a=t.length===2&&rs(t[0],n)&&rs(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=>bo(e,n)?yo(_o(e,n),n):X(e,n)),n)},os=(e,t,n)=>{if(t.length!==e.params.length)return()=>{throw new u(`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:To(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:_o(t[e],n)};a={name:r[e].name,binding:s,parent:a}}return a}},ss=/* @__PURE__ */ new WeakMap,cs=e=>{let t=ss.get(e);if(t)return t;let n={calls:/* @__PURE__ */ new Map,size:0};return ss.set(e,n),n},ls=(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},us=(e,t)=>e.every((e,n)=>Re(e,t[n])),ds=(e,t)=>{let n=qa(e.operator,t);return n?.kind===`Operator`&&n.params.length>0&&n.params.every(e=>e.arity===0)&&Ya(n,t)&&!Lo(n,t)},fs=(e,t,n,r)=>{let i=os(e,t,n),a={body:void 0},o=(t,r)=>(a.body??=Qo(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=cs(e);return e=>{let n=i(e),r=ls(n,t.length);if(!r)return o(n,e);let a=r.length;for(let e of r)a=sn(a,fn(e));let c=s.calls.get(a),l=c?.find(e=>us(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}},ps=(e,t)=>{let n=e.args;if(e.operator===`=>`){let e=Y(n[0],t),r=Y(n[1],t);return t=>!Ka(e(t),`the left side of =>`)||Ka(r(t),`the right side of =>`)}if(e.operator===`~>`)return()=>{throw new u(`TLC cannot evaluate a temporal formula such as ~> in a state`)};let r=W(e)?void 0:fo(e.operator,t);if(r?.kind===`Closure`)return fs(r,n,t,ds(e,t));if(r?.kind===`Builtin`&&r.name===`DOMAIN`){let r=Y(n[0],t),i=Ra(e);return e=>i(r(e))}if(r?.kind===`Builtin`&&r.name===`TLCEval`&&n.length===1){let i=Y(n[0],t);return ui.has(e)||Ja(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=za(e,r);return e=>o(i(e),a(e))}return r?.kind===`Builtin`?as(r,n,t):r=>{let i=ho(e.operator,r);if(i)return Do(i,n,r);throw t.definitions.get(e.operator)?.kind===`Function`?new u(`${e.operator} is a function; apply it with brackets`):new u(`Unknown operator ${e.operator} at ${J(e)}`)}},ms=(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=Za(o(t),a.set);for(let a=0;a<s.length;a++){let o=Ka(i(Ga(t,Ua(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)=>Za(e(t),o[n].set)),c=(a,o)=>{if(a<0)return Ka(i(Ga(t,o)),r)!==n;let l=s[a];for(let t=0;t<l.length;t++)if(c(a-1,Ua(o,e[a],l[t])))return!0;return!1};return c(o.length-1,t.scope)?!n:n}}return e=>Qa(o,e,t=>Ka(i(Ga(e,t)),r)!==n)?!n:n},hs=(e,t)=>{if(e.kind===`Tuple`)return R(e.names.map(e=>{let n=Ha(t,e);return n?.kind===`Value`&&n.value}));let n=Ha(t,e.name);return n?.kind===`Value`?n.value:void 0},gs=/* @__PURE__ */ new WeakSet,_s=e=>{(e.kind===`FunctionConstruction`||e.kind===`Except`)&&gs.add(e)},vs=(e,t)=>{let n=gs.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):$a(i,t);if(e.isRecursive||n||!z(c)){let n=io(c,e=>r(Ga(t,eo(i,t.scope,e))),ro(i,e.body,c));return i.length===1?Zt(n):n}if(o&&a.pattern.kind===`Name`){let e=a.pattern.name,n=Tt(c);return Zt(L(n,n.map(n=>r(Ga(t,Ua(t.scope,e,n))))))}let l=[];return Qa(i,t,e=>{let n=i.length===1?hs(a.pattern,e)??!1:R(i.map(t=>hs(t.pattern,e)??!1));return l.push([n,r(Ga(t,e))]),!1}),_t(l)}},ys=(e,t)=>{let n=gs.has(e);n&&_s(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(Ga(i,Ua(i.scope,`@`,e))):rn(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}},bs=(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=>Ka(n(Ga(t,Wa(t.scope,i,e))),`a set filter predicate`);if(typeof a!=`object`||a.kind!==`Set`&&a.kind!==`MixedSet`&&a.kind!==`Interval`){if(A(a))return{kind:`FilteredSet`,base:a,test:o};throw new u(`TLC encountered a non-enumerable quantifier bound ${U(a)} at ${J(e.bound.set)}`)}return Fe(B(a).elements.filter(o))}}if(e.kind===`SetMap`){let n=Y(e.expression,t);return t=>{let r=[];return Qa(e.bounds,t,e=>(r.push(n(Ga(t,e))),!1)),ft(r)}}let n=e.set;if(!n)return()=>{throw new u(`TLC cannot evaluate an unbounded CHOOSE at ${J(e)}`)};let r=Y(e.body,t),i={pattern:e.pattern,set:n};return t=>{let n={value:void 0};if(Qa([i],t,i=>Ka(r(Ga(t,i)),`the body of CHOOSE`)?(n.value=hs(e.pattern,i),!0):!1),n.value===void 0)throw new u(`Attempted to compute the value of an expression of form\nCHOOSE x \\in S: P, but no element of S satisfied P.\n${Pa(e)}`);return n.value}},xs=e=>[...e].sort((e,t)=>I(e.name,t.name)),Ss=e=>e.some((t,n)=>n>0&&e[n-1].name===t.name),Cs=(e,t)=>new u(`The variable ${e} is not assigned at ${J(t)}`),ws=e=>new u(`A primed expression appears outside an action at ${J(e)}`),Ts=(e,t)=>{let n=xs(e),r=Ss(n),i=n.map(e=>Y(e.value,t));if(r)return e=>_t(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=>_e(a,i.map(t=>t(e)),o):e=>L(a,i.map(t=>t(e)))},Es=(e,t)=>{let n=e=>Y(e,t);switch(e.kind){case`Number`:{let t=e.value;return Ao(t)?()=>t:()=>{throw Va(e)}}case`Decimal`:return()=>{throw Ba(e)};case`String`:{let t=e.value;return()=>t}case`Identifier`:return $o(e,t);case`Apply`:return ps(e,t);case`OperatorReference`:case`Lambda`:return()=>{throw new u(`An operator cannot be used as a value at ${J(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 Ia(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(Ka(t[n](e),`a disjunct`))return!0;return!1}}case`Prime`:{let t=n(e.expression);return n=>{if(!n.next)throw ws(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=>Ie(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 Fa(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(Ka(e.condition(n),`a CASE guard`))return e.body(n);if(r)return r(n);throw new u(`Attempted to evaluate a CASE with no conditions true.\n${Pa(e)}`)}}case`Let`:{let t=n(e.body);return n=>t(Ga(n,Oo(e.definitions,n)))}case`Forall`:case`Exists`:return ms(e,t);case`UnboundedQuantifier`:return()=>{throw new u(`TLC cannot evaluate an unbounded quantifier at ${J(e)}`)};case`Choose`:case`SetFilter`:case`SetMap`:return bs(e,t);case`SetEnumeration`:{let t=e.elements.map(n);return e=>ft(t.map(t=>t(e)))}case`Tuple`:{let t=e.elements.map(n);return e=>R(t.map(t=>t(e)))}case`FunctionConstruction`:return vs(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 Ts(e.fields,t);case`RecordSet`:{let t=xs(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 ys(e,t);case`ExceptAt`:return t=>{let n=Ha(t.scope,`@`);if(n?.kind!==`Value`)throw new u(`@ appears outside an EXCEPT at ${J(e)}`);return n.value};case`FunctionApplication`:{_s(e.function);let t=n(e.function),r=e.args.map(n);if(r.length===1){let e=r[0];return n=>en(t(n),e(n))}return e=>en(t(e),R(r.map(t=>t(e))))}case`FieldAccess`:{let t=n(e.record),r=e.field,i=La(e);return e=>en(t(e),r,i)}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?Ka(t(e),`an action`)||r(e):Ka(t(e),`an action`)&&!r(e)}case`Enabled`:{let t=e.expression;return e=>Oa(t,e)}case`Label`:return n(e.body);case`Subexpression`:return()=>{throw new u(`The subexpression reference at ${J(e)} does not name a subexpression`)};case`Always`:case`Eventually`:case`WeakFairness`:case`StrongFairness`:return()=>{throw new u(`TLC cannot evaluate a temporal formula in a state at ${J(e)}`)}}},Ds=/* @__PURE__ */ new Set([`Prime`,`Unchanged`,`Enabled`,`Always`,`Eventually`,`BoxAction`,`AngleAction`,`WeakFairness`,`StrongFairness`]),Os=e=>{if(e.kind===`Identifier`)return e.name;if(e.kind===`Apply`||e.kind===`OperatorReference`)return e.operator},ks=(e,t)=>{let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Set,i=e=>{if(Ds.has(e.kind))return!1;let a=Os(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&&Mo(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 jn(e).every(i)};return i(e)?[...n]:void 0},As=/* @__PURE__ */ new Map([[`Reals`,`-------------------------------- MODULE Reals -------------------------------
24
24
  (***************************************************************************)
25
25
  (* This module provides dummy definitions of the operators that are *)
26
26
  (* defined by the real Reals module. It is expected that any tool that *)
@@ -89,8 +89,8 @@ _TEPosition ==
89
89
  THEN _TETraceLength
90
90
  ELSE IF TLCGet("level") = 0 THEN 1 ELSE TLCGet("level")
91
91
 
92
- =============================================================================`]]),js=`tlc2/value/impl/`,Ms=e=>{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n={offset:0},r=e=>{let t=n.offset;return n.offset+=e,t};return{readUint8:()=>t.getUint8(r(1)),readUint16:()=>t.getUint16(r(2)),readUint32:()=>t.getUint32(r(4)),readInt32:()=>t.getInt32(r(4)),readBytes:t=>e.subarray(r(t),n.offset)}},Ns=e=>[...e.slice(1,e.indexOf(`)`)).matchAll(/\[*(?:L[^;]*;|[BCDFIJSZ])/g)].length,Ps=e=>{let t=Ms(e);if(t.readUint32()!==3405691582)throw new f(`A module override is not a class file`);t.readUint16(),t.readUint16();let n=[],r=t.readUint16(),i=new TextDecoder;for(let e=1;e<r;e++){let r=t.readUint8(),a={tag:r,text:``,value:0,first:0,second:0};n[e]=a,r===1?a.text=i.decode(t.readBytes(t.readUint16())):r===3?a.value=t.readInt32():r===4?t.readUint32():r===5||r===6?(t.readBytes(8),e++):r===7||r===8||r===16||r===19||r===20?a.first=t.readUint16():r===15?(t.readUint8(),a.first=t.readUint16()):(a.first=t.readUint16(),a.second=t.readUint16())}t.readUint16(),t.readUint16(),t.readUint16(),t.readBytes(t.readUint16()*2);for(let e=t.readUint16();e>0;e--){t.readBytes(6);for(let e=t.readUint16();e>0;e--)t.readUint16(),t.readBytes(t.readUint32())}let a=[];for(let e=t.readUint16();e>0;e--){let e=t.readUint16(),r=n[t.readUint16()].text,i=n[t.readUint16()].text,o={name:r,arity:Ns(i),code:void 0};for(let e=t.readUint16();e>0;e--){let e=n[t.readUint16()].text,r=t.readBytes(t.readUint32());if(e===`Code`){let e=new DataView(r.buffer,r.byteOffset+4,4).getUint32(0);o.code=r.subarray(8,8+e)}}e&1&&e&8&&a.push(o)}return{pool:n,methods:a}},Fs=(e,t)=>e[e[t].first].text,Is=(e,t)=>{let n=e[t],r=e[n.second];return{className:Fs(e,n.first),name:e[r.first].text}},Ls=(e,t,n,r)=>{let i=()=>new v(`The Java override ${n}.${e.name} computes its value, which tla-ts cannot run`),a=e.code;if(!a)throw i();let o=[],s=()=>{let e=o.pop();if(e===void 0)throw i();return e},c=e=>{let n=t[e];if(n.tag===3)return n.value;if(n.tag===8)return t[n.first].text;throw i()};for(let e=0;e<a.length;){let n=a[e],l=()=>a[e+1]<<8|a[e+2];if(n>=2&&n<=8)o.push(n-3),e+=1;else if(n===16)o.push(a[e+1]<<24>>24),e+=2;else if(n===17)o.push(l()<<16>>16),e+=3;else if(n===18)o.push(c(a[e+1])),e+=2;else if(n===19)o.push(c(l())),e+=3;else if(n===89){let t=s();o.push(t,t),e+=1}else if(n===178){let n=Is(t,l());if(n.className!==`${js}BoolValue`||n.name!==`ValTrue`&&n.name!==`ValFalse`)throw i();o.push({kind:`Identifier`,name:n.name===`ValTrue`?`TRUE`:`FALSE`,location:r}),e+=3}else if(n===184){let n=Is(t,l()),a=s();if(n.className!==`${js}IntValue`||n.name!==`gen`||typeof a!=`number`)throw i();o.push({kind:`Number`,value:a,location:r}),e+=3}else if(n===187)o.push({className:Fs(t,l()),value:void 0}),e+=3;else if(n===183){let n=Is(t,l()),a=s(),o=s();if(!(n.className===`${js}StringValue`&&n.name===`<init>`&&typeof a==`string`&&typeof o==`object`&&`className`in o))throw i();o.value={kind:`String`,value:a,location:r},e+=3}else if(n===176){let e=s();if(typeof e!=`object`)throw i();if(`className`in e){if(!e.value)throw i();return e.value}return e}else throw i()}throw i()},Rs=(e,t)=>{if(!t)return e;let n=Ps(t),r=e.definitions.map(t=>{if(t.kind!==`Operator`)return t;let r=n.methods.find(e=>e.name===t.name&&e.arity===t.params.length);return r?{...t,body:Ls(r,n.pool,e.name,t.location)}:t});return{...e,definitions:r}},Z=(e,t,n)=>({low:e,high:t,isAssociative:n}),zs=new Map([[`=>`,Z(1,1,!1)],[`<=>`,Z(2,2,!1)],[`~>`,Z(2,2,!1)],[`-+->`,Z(2,2,!1)],[`/\\`,Z(3,3,!0)],[`\\/`,Z(3,3,!0)],...(/* @__PURE__ */ `=.#.<.>.<=.>=.\\in.\\notin.\\subseteq.\\subset.\\supseteq.\\supset.\\sqsubseteq.\\sqsupseteq.\\sqsubset.\\sqsupset.\\prec.\\preceq.\\succ.\\succeq.\\sim.\\simeq.\\approx.\\cong.\\asymp.\\doteq.\\propto.\\ll.\\gg.|-.-|.|=.=|.:=.::=`.split(`.`)).map(e=>[e,Z(5,5,!1)]),[`\\cdot`,Z(5,14,!0)],[`@@`,Z(6,6,!0)],[`:>`,Z(7,7,!1)],[`<:`,Z(7,7,!1)],[`\\cup`,Z(8,8,!0)],[`\\cap`,Z(8,8,!0)],[`\\`,Z(8,8,!1)],[`..`,Z(9,9,!1)],[`...`,Z(9,9,!1)],[`##`,Z(9,13,!0)],[`$`,Z(9,13,!0)],[`$$`,Z(9,13,!0)],[`??`,Z(9,13,!0)],[`!!`,Z(9,13,!1)],[`\\sqcap`,Z(9,13,!0)],[`\\sqcup`,Z(9,13,!0)],[`\\uplus`,Z(9,13,!0)],[`\\wr`,Z(9,14,!1)],[`+`,Z(10,10,!0)],[`++`,Z(10,10,!0)],[`(+)`,Z(10,10,!0)],[`\\oplus`,Z(10,10,!0)],[`%`,Z(10,11,!1)],[`%%`,Z(10,11,!0)],[`|`,Z(10,11,!0)],[`||`,Z(10,11,!0)],[`\\X`,Z(10,13,!1)],[`-`,Z(11,11,!0)],[`--`,Z(11,11,!0)],[`(-)`,Z(11,11,!0)],[`\\ominus`,Z(11,11,!0)],[`*`,Z(13,13,!0)],[`**`,Z(13,13,!0)],[`/`,Z(13,13,!1)],[`//`,Z(13,13,!1)],[`\\div`,Z(13,13,!1)],[`\\o`,Z(13,13,!0)],[`(.)`,Z(13,13,!0)],[`\\odot`,Z(13,13,!0)],[`(/)`,Z(13,13,!1)],[`\\oslash`,Z(13,13,!1)],[`(\\X)`,Z(13,13,!0)],[`\\otimes`,Z(13,13,!0)],[`&`,Z(13,13,!0)],[`&&`,Z(13,13,!0)],[`\\star`,Z(13,13,!0)],[`\\bullet`,Z(13,13,!0)],[`\\bigcirc`,Z(13,13,!0)],[`^`,Z(14,14,!1)],[`^^`,Z(14,14,!1)]]),Bs=/* @__PURE__ */ new Set([`^+`,`^*`,`^#`]),Vs=/* @__PURE__ */ new Set([`-`,`~`,`-.`]),Hs=/* @__PURE__ */ new Set([`-`,`~`,`/\\`,`\\/`,`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`]),Us=/* @__PURE__ */ new Set([`+`,`-`,`/`,`\\X`]),Ws=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`,`'`,...Bs]),Gs=e=>zs.has(e)||Bs.has(e)||e===`-.`,Ks=(e,t,n)=>{switch(e){case`ENABLED`:return{kind:`Enabled`,expression:t,location:n};case`UNCHANGED`:return{kind:`Unchanged`,expression:t,location:n};case`[]`:return{kind:`Always`,expression:t,location:n};case`<>`:return{kind:`Eventually`,expression:t,location:n};case`'`:return{kind:`Prime`,expression:t,location:n};default:return{kind:`Apply`,operator:e,args:[t],location:n}}},qs=/* @__PURE__ */ new Set([`<<`,`>>`,`:`,`@`,`(`]),Js=/* @__PURE__ */ new Set([`ASSUME`,`ASSUMPTION`,`AXIOM`,`CONSTANT`,`CONSTANTS`,`COROLLARY`,`INSTANCE`,`LEMMA`,`LOCAL`,`PROPOSITION`,`RECURSIVE`,`THEOREM`,`VARIABLE`,`VARIABLES`]),Ys=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Xs=/* @__PURE__ */ new Set([`BY`,`PROOF`,`OBVIOUS`,`OMITTED`]),Zs=/* @__PURE__ */ new Set([`Qed`,`Pick`,`Case`,`Assert`]),Qs=/* @__PURE__ */ new Set(/* @__PURE__ */ `, . _ ( ) [ ] { } << >> ]_ >>_ == ! @ : :: ; -> <- |-> \\A \\AA \\E \\EE \\forall \\exists WF_ SF_ (*{ }*)`.split(` `)),$s=/* @__PURE__ */ new Set([``,`*`,`-`]),ec=/* @__PURE__ */ new Set([`CASE`,`CHOOSE`,`DOMAIN`,`ENABLED`,`IF`,`LAMBDA`,`LET`,`SF_`,`SUBSET`,`UNCHANGED`,`UNION`,`WF_`]),tc=/* @__PURE__ */ new Map([[`CONSTANT`,`Constant`],[`CONSTANTS`,`Constant`],[`VARIABLE`,`Variable`],[`VARIABLES`,`Variable`],[`STATE`,`State`],[`ACTION`,`Action`],[`ACTIONS`,`Action`],[`TEMPORAL`,`Temporal`],[`TEMPORALS`,`Temporal`]]),nc=/* @__PURE__ */ new Set([`NEW`,...tc.keys()]),rc=/* @__PURE__ */ new Set([`(`,`[`,`{`,`<<`]),ic=/* @__PURE__ */ new Set([`)`,`]`,`}`,`>>`,`]_`,`>>_`]),ac=/* @__PURE__ */ new Set([`TRUE`,`FALSE`,`BOOLEAN`,`STRING`]),oc=e=>RegExp(`^-{4,}\\s*MODULE\\s+${e}\\s*-{3,}$`),sc=(e,t)=>{let n=e.split(/\r?\n/),r=n.findIndex(e=>oc(t).test(e));if(r===-1)return;let i=n.findIndex((e,t)=>t>r&&e.startsWith(`====`));return n.slice(r,i===-1?void 0:i+1).join(`
93
- `)},cc=(e,t)=>{let n=ae(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=[],p=[],m=[],h=e=>{let t=r.index-1,i=e===t?m[e]:void 0;if(i)return i;let a=n[t];d[e]??=u(n[e]),p[t]??={line:a.line,column:a.endColumn};let o={module:c[c.length-1].name,start:d[e],end:p[t]};return e===t&&(m[e]=o),o},g=(e,t)=>(e.location.range=h(t),e),_=(e=0)=>n[Math.min(r.index+e,n.length-1)],v=(e=0)=>{let t=_(e),n=r.offsideColumns[r.offsideColumns.length-1];return n===void 0||n===-1||t.kind===`End`?t:t.column<=n?{...t,kind:`End`,text:``}:t},y=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),b={index:0},x=e=>{let t=n.slice(b.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},S=e=>t&&(e.kind===`Keyword`||ac.has(e.text)),ee=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},te=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Qs.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):S(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,C=(e,t=_(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new f(`${e} at line ${t.line}, column ${t.column}`,void 0,w(e,t,a,r))},w=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...x(ee(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${te(a)}`,...ee(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},re=(e,t=_())=>C(e,t,t),ie=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!S(e),T=(e,t=0)=>{let n=v(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},E=()=>{let e=v();if(e.kind===`End`)throw C(`Unexpected end of expression`);return r.index++,e},D=e=>T(e)?(r.index++,!0):!1,O=e=>{if(!T(e))throw re(`Expected ${JSON.stringify(e)} but found ${y(v())}`);return E()},k=()=>{let e=v();if(e.kind!==`Identifier`)throw re(`Expected an identifier but found ${y(e)}`);if(S(e))throw re(`Unexpected keyword ${e.text}`);return r.index++,e.text},oe=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},se=()=>{if(T(`<<`)){let e={value:1};for(;v(e.value).kind===`Identifier`||T(`,`,e.value);)e.value++;return T(`>>`,e.value)&&T(`\\in`,e.value+1)}let e={value:0};for(;v(e.value).kind===`Identifier`;){if(T(`\\in`,e.value+1))return!0;if(!T(`,`,e.value+1))return!1;e.value+=2}return!1},ce=()=>{if(T(`::`))return!0;if(!T(`(`))return!1;let e={value:1};for(;v(e.value).kind===`Identifier`&&T(`,`,e.value+1);)e.value+=2;return v(e.value).kind===`Identifier`&&T(`)`,e.value+1)&&T(`::`,e.value+2)},le=()=>{if(!D(`<<`))return{kind:`Name`,name:k()};let e=A(k);return O(`>>`),{kind:`Tuple`,names:e}},ue=()=>A(()=>{let e=A(le);O(`\\in`);let t=P();return e.map(e=>({pattern:e,set:t}))}).flat(),de=()=>{let e=v();if(e.kind===`Identifier`){let t=r.index,n=[E().text];for(;T(`!`)&&v(1).kind===`Identifier`;)E(),n.push(k());return g({kind:`Identifier`,name:n.join(`!`),location:u(e)},t)}if(T(`<<`)||T(`(`))return xe();throw re(`Expected a subscript but found ${y(e)}`)},fe=e=>{let t=v(1),n=v(2);return t.kind===`Identifier`&&n.text===`==`?!0:t.line===e.line?!1:t.text===`-.`||t.kind===`Identifier`&&(n.text===`(`||n.text===`[`||n.kind===`Operator`&&T(`==`,Bs.has(n.text)?3:4))},pe=e=>{if(!Hs.has(e.text))return!0;let t=v(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||T(`,`,1)||T(`)`,1)||t.kind===`Keyword`&&Js.has(t.text)||fe(e)},me=()=>{let e=v(),n=e.kind===`Operator`&&(zs.has(e.text)||Vs.has(e.text))&&pe(e);if(t&&e.kind!==`String`&&(Vs.has(e.text)||Ws.has(e.text)&&e.text!==`'`&&!Bs.has(e.text)||Us.has(e.text)&&v(-1).text===`(`&&v(-1).line===e.line&&v(-1).endColumn+1===e.column&&v(1).text===`)`&&v(1).line===e.line&&v(1).column===e.endColumn+1)&&pe(e))throw C(`incomplete expression`,e);if(n)return r.index++,g({kind:`OperatorReference`,operator:e.text,location:u(e)},r.index-1);if(e.kind!==`String`&&Ws.has(e.text)&&pe(e)){r.index++;let t=u(e);if(Bs.has(e.text))return{kind:`OperatorReference`,operator:e.text,location:t};let n={kind:`Identifier`,name:`argument`,location:t};return{kind:`Lambda`,params:[n.name],body:Ks(e.text,n,t),location:t}}if(T(`LAMBDA`)){let t=r.index;E();let n=A(k);O(`:`);let i=P();return g({kind:`Lambda`,params:n,body:i,location:u(e)},t)}return P()},j=()=>oe(()=>{O(`(`);let e=A(me);return O(`)`),e}),M=()=>{let e=E();r.offsideColumns.push(e.column);let t=[P()];for(;_().text===e.text&&_().column===e.column;)r.index++,t.push(P());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:u(e)}},N=e=>oe(()=>{let t=u(e);if(v().kind===`Identifier`&&(T(`|->`,1)||T(`:`,1))){let e=T(`|->`,1)?`Record`:`RecordSet`,n=A(()=>{let t=k();return O(e===`Record`?`|->`:`:`),{name:t,value:P()}});return O(`]`),{kind:e,fields:n,location:t}}if(se()){let e=ue();O(`|->`);let n=P();return O(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=P();if(D(`->`)){let e=P();return O(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(D(`EXCEPT`)){let e=A(()=>{O(`!`);let e=[];for(;T(`.`)||T(`[`);)if(D(`.`)){if(!ie(v()))throw re(`Expected a field name but found ${y(v())}`);e.push({kind:`Field`,name:E().text})}else O(`[`),e.push({kind:`Index`,args:A(()=>P())}),O(`]`);return O(`=`),{path:e,value:P()}});return O(`]`),{kind:`Except`,function:n,updates:e,location:t}}return O(`]_`),{kind:`BoxAction`,action:n,subscript:de(),location:t}}),he=e=>oe(()=>{let t=u(e);if(D(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(se()&&(v(1).text===`\\in`||T(`<<`))){let e=r.index,n=le();O(`\\in`);let i=P();if(D(`:`)){let e=P();return O(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=P();if(D(`:`)){let e=ue();return O(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;D(`,`);)i.push(P());return O(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),ge=e=>{let t=u(e),n=oe(()=>T(`>>`)||T(`>>_`)?[]:A(()=>P()));if(D(`>>_`)){if(n.length!==1)throw C(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:de(),location:t}}return O(`>>`),{kind:`Tuple`,elements:n,location:t}},_e=e=>{let t=u(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&se()){let e=ue();return O(`:`),{kind:n,bounds:e,body:P(),location:t}}let i=A(k);return O(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:P(),isTemporal:r,location:t}},ve=e=>{let t=[];do{if(D(`OTHER`))return O(`->`),{kind:`Case`,arms:t,other:P(),location:u(e)};let n=P();O(`->`),t.push({condition:n,body:P()})}while(D(`[]`));return{kind:`Case`,arms:t,other:void 0,location:u(e)}},ye=()=>{let e=v(1);return T(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||qs.has(e.text)||e.kind===`Operator`&&(zs.has(e.text)||Bs.has(e.text)||Vs.has(e.text)))},be=()=>{let e=E();if(e.kind===`Number`)return{kind:`Operand`,operand:ne(e.text)};switch(e.text){case`<<`:case`>>`:return{kind:`Operand`,operand:e.text};case`:`:return{kind:`Colon`};case`@`:return{kind:`At`};case`(`:return r.index--,{kind:`Bound`,args:j()}}return{kind:`Name`,name:e.text,args:T(`(`)?j():[]}},xe=()=>{let e=r.index===s.index,n=E(),a=u(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=A(k);return O(`:`),{kind:`Lambda`,params:e,body:P(),location:a}}if(n.kind===`Number`){if(t&&/^\\[BOH]/.test(n.text))throw C(`incomplete expression`,n);return{kind:`Number`,value:ne(n.text),text:n.text,location:a}}if(n.kind===`Decimal`)return{kind:`Decimal`,text:n.text,location:a};if(n.kind===`String`)return{kind:`String`,value:n.text,location:a};let o=n.kind===`Step`&&Fe(n);if(o&&Me()<0&&I.length<=1)throw C(`Step number used outside proof`,n);if(o&&n.text[1]===`+`)throw C(`<+> step number used in an expression`,n);if(n.kind===`Identifier`||o){let r=o?L(n)??n.text:n.text;if(ce()){let e=D(`(`)?A(k):[];return e.length>0&&O(`)`),O(`::`),{kind:`Label`,name:r,params:e,body:P(),location:a}}let i=T(`(`),s=i?j():[];if(!ye())return i?{kind:`Apply`,operator:r,args:s,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 C(`The operator ${r} requires ${l.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;ye();)E(),u.push(be());let d=u.flatMap(e=>e.kind===`Name`?[e.name]:[]);if(d.length<u.length)return{kind:`Subexpression`,selectors:u,location:a};let f=d.join(`!`),p=u.flatMap(e=>`args`in e?e.args:[]);if(p.length===0)return{kind:`Identifier`,name:f,location:a};let m=u.map(e=>`args`in e?e.args.length:0);return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,location:a}:{kind:`Apply`,operator:f,args:p,location:a}}if(n.kind===`Operator`&&Gs(n.text)&&T(`(`))return{kind:`Apply`,operator:n.text,args:j(),location:a};switch(n.text){case`(`:{let e=oe(()=>P());return O(`)`),e}case`[`:return N(n);case`{`:return he(n);case`<<`:return ge(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return _e(n);case`IF`:{let e=P();O(`THEN`);let t=P();return O(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:P(),location:a}}case`CASE`:return ve(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!D(`IN`);){if(t&&T(`RECURSIVE`))throw C(`Unexpected keyword RECURSIVE`,x(_()));if(D(`RECURSIVE`)){ke();continue}let r=F(!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:a}:{kind:`Let`,definitions:e,instances:n,body:r,location:a}}case`CHOOSE`:{let e=le(),t=D(`\\in`)?P():void 0;return O(`:`),{kind:`Choose`,pattern:e,set:t,body:P(),location:a}}case`WF_`:case`SF_`:{let e=de(),t=oe(()=>{O(`(`);let e=P();return O(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw re(`Unexpected ${y(n)}`,n)},Se=()=>{let e=v(),t=u(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return M();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return E(),{kind:`Apply`,operator:`~`,args:[P(5)],location:t};case`-`:return E(),{kind:`Apply`,operator:`-.`,args:[P(13)],location:t};case`[]`:return E(),{kind:`Always`,expression:P(16),location:t};case`<>`:return E(),{kind:`Eventually`,expression:P(16),location:t};case`ENABLED`:return E(),{kind:`Enabled`,expression:P(16),location:t};case`UNCHANGED`:return E(),{kind:`Unchanged`,expression:P(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return E(),{kind:`Apply`,operator:e.text,args:[P(9)],location:t}}return xe()},P=(e=0)=>{let t=r.index,n=Se(),i={left:n.location.range?n:g(n,t),previous:void 0};for(;;){let n=v();if(n.kind!==`Operator`)break;let r=u(n);if(n.text===`'`&&e<=15){E(),i.left=g({kind:`Prime`,expression:i.left,location:r},t);continue}if(Bs.has(n.text)&&e<=15){E(),i.left=g({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){E();let e=oe(()=>A(()=>P()));oe(()=>O(`]`)),i.left=g({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&ie(v(1))){E();let e=E().text;i.left=g({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=zs.get(n.text);if(!a||a.low<e)break;let o=i.previous;if(o){let e=!(o.low>a.high||o.high<a.low),t=o.text===n.text&&a.isAssociative;if(e&&!t&&(o.text!==`\\X`||n.text!==`\\X`))throw C(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(E(),a.low>12&&T(`-`))throw C(`Precedence conflict between ${n.text} and -`,v());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=g(i.left,t),i.previous={...a,text:n.text}}return i.left},Ce=()=>{if(!D(`(`))return[];let e=Oe();return O(`)`),e},we=()=>{let e=u(v()),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}}},F=e=>{let t=r.index;return g(Te(e),t)},Te=e=>{let t=v(),n=u(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...we(),isLocal:e,isRecursive:l(t),location:n});if(t.kind===`Identifier`&&v(1).kind===`Operator`&&zs.has(v(1).text)&&v(2).kind===`Identifier`&&T(`==`,3)){let e=k(),t=E().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`&&Bs.has(v(1).text)&&T(`==`,2);if(a||o){let e=a?t.text:v(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=oe(()=>ue());return O(`]`),O(`==`),{kind:`Function`,name:s,bounds:t,body:P(),isLocal:e,isRecursive:l(s),location:n}}let c=r.index,d=Ce();return O(`==`),T(`INSTANCE`)?{...Ee(s,d,e,n),definitionRange:h(c)}:i(s,d)},Ee=(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=E().text;return O(`<-`),{name:e,expression:me()}}):[],isLocal:n,location:i,instanceRange:h(a)}},De=()=>{let e=u(v());if(T(`_`)&&v(1).kind===`Operator`)return E(),{name:E().text,arity:D(`_`)?2:1,location:e};if(v().kind===`Operator`&&T(`_`,1)){let t=E().text;return E(),{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}},Oe=()=>A(De),ke=()=>{let e=Oe();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ae=e=>{let t={value:0,offset:e};do{let e=v(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&rc.has(e.text)&&t.value++,e.kind===`Operator`&&ic.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},je=()=>{let e=v(),t=v(1);return e.kind===`Identifier`?T(`(`,1)||T(`[`,1)?T(`==`,Ae(1)):t.kind===`Operator`&&Bs.has(t.text)?T(`==`,2):t.kind===`Operator`&&zs.has(t.text)?v(2).kind===`Identifier`&&T(`==`,3):T(`==`,1):T(`-.`)&&t.kind===`Identifier`&&T(`==`,2)},I=[],Me=()=>I[I.length-1]??-1,Ne=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),Pe=e=>{let t=e.text.slice(e.text.indexOf(`>`)+1),n={value:t.length};for(;t[n.value-1]===`.`;)n.value--;return t.slice(0,n.value)},Fe=e=>!e.text.endsWith(`.`)&&!$s.has(Pe(e)),L=e=>{let t=Pe(e);if($s.has(t))return;let n=Ne(e);if(n>=0)return`<${n}>${t}`;let r=Me(),i=I[I.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Ie=e=>{if(e.kind===`Keyword`)return Xs.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return I.length===0;if(e.text[1]===`+`||I.length===0)return!0;let t=Me();return t>=0&&Ne(e)>t},Le=e=>{let t=Ne(e),n=I.length-1,r=I[n-1]??-1,i=I[n]<0;return i&&(I[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:I[n]===t},Re=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)),ze=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!ac.has(e.name)&&!Re(e.name):!1,Be=()=>{let e=v();return e.kind===`Step`?Fe(e):e.kind===`Keyword`?ec.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!je()},Ve=()=>{let e=r.index;s.index=e;let t=v();return t.kind===`Operator`&&!Hs.has(t.text)&&Gs(t.text)?(r.index++,g({kind:`OperatorReference`,operator:t.text,location:u(t)},e)):D(`MODULE`)?g({kind:`ModuleFact`,name:k(),location:u(t)},e):P()},He=e=>o[o.length-1]?.add(e),Ue=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},We=e=>o.some(t=>t.has(e))||c.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Ge=()=>{let e=r.index,t=v(),n=A(()=>{let e=v();if((e.kind!==`Identifier`||S(e))&&e.kind!==`Operator`)throw re(`Expected a definition name but found ${y(e)}`,e);return r.index++,e.text},`!`),i=u(t);return g(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ke=()=>{if(t)return A(Ge);let e=A(Ve),n=e.find(e=>e.kind===`Identifier`&&We(e.name));if(n)throw C(`DEF clause entry should describe a defined operator`,n.location);return e},qe=()=>({facts:Be()?A(Ve):[],defs:D(`DEF`)||D(`DEFS`)?Ke():[]}),Je=()=>{let e=r.index,n=E(),i=n.text===`USE`&&D(`ONLY`),a=h(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...qe(),keyword:a,location:u(n)},s=o.kind===`Hide`&&!t?o.facts.find(e=>!ze(e)):void 0;if(s)throw C(`The only expression allowed as a fact in a HIDE is the name of a theorem, assumption, or step`,s.location);return g(o,e)},Ye=()=>{let e=r.index,t=u(v()),n=D(`NEW`),i=v().kind===`Keyword`?tc.get(v().text):void 0;if(!n&&i===void 0)throw re(`Expected a declaration but found ${y(v())}`);if(i!==void 0&&E(),i===`Variable`){let n=k();return He(n),g({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=De();He(a.name);let o=(i??`Constant`)===`Constant`&&T(`\\in`);if(o&&a.arity>0)throw C(`declared symbol with arguments before \\in`);return o&&E(),g({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?P():void 0,location:t},e)},Xe=()=>{let e=r.index,t=u(O(`ASSUME`)),n=A(()=>T(`ASSUME`)?Ue(Xe):v().kind===`Keyword`&&nc.has(v().text)?Ye():P());return O(`PROVE`),g({kind:`AssumeProve`,assumptions:n,conclusion:P(),location:t},e)},Ze=e=>{let t={value:0};for(;v(t.value).kind===`Identifier`&&T(`,`,t.value+1);)t.value+=2;return v(t.value).kind===`Identifier`&&T(e,t.value+1)},Qe=(e,t)=>{e.forEach(He),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(He))},$e=()=>{let e=v();if(T(`USE`)||T(`HIDE`))return Je();if(T(`INSTANCE`))return g(Ee(void 0,[],!1,u(e)),r.index);if(T(`DEFINE`)||je()){let t=r.index;D(`DEFINE`);let n=[F(!1)];for(;je();)n.push(F(!1));let i={kind:`Define`,definitions:n,location:u(e)};return g(i,t)}if(D(`HAVE`))return{kind:`Have`,expression:P()};if(D(`TAKE`)){let e=se(),t=e?[]:A(k),n=e?ue():[];return Qe(t,n),{kind:`Take`,names:t,bounds:n}}if(D(`WITNESS`))return{kind:`Witness`,expressions:A(()=>P())};if(D(`PICK`)){let e=Ze(`:`),t=e?A(k):[],n=e?[]:ue();return Qe(t,n),O(`:`),{kind:`Pick`,names:t,bounds:n,body:P()}}return D(`CASE`)?{kind:`Case`,expression:P()}:{kind:`Assert`,isSuffices:D(`SUFFICES`),statement:T(`ASSUME`)?Xe():P()}},et=e=>{let t=v();if(t.kind!==`Step`)throw re(`Expected a step number but found ${y(t)}`,t);if(!Le(t))throw C(`${e?`QED step`:`step`}'s number has bad level`,t);if(Ne(t)<0&&L(t)!==void 0)throw C(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:L(t),token:t.text,location:u(t)}},tt=()=>{let e=r.index,t=et(T(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=D(`QED`)?{kind:`Qed`}:$e(),a=h(e),s=Ie(v());if(s&&!Zs.has(i.kind))throw C(`Proof of a step that does not take a proof`);let c=s?rt():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(He),g({...t,body:i,head:a,proof:c},e)},nt=()=>{let e=u(v());if(T(`BY`)||T(`PROOF`)&&T(`BY`,1)){D(`PROOF`),E();let t=h(r.index-1);return{kind:`By`,isOnly:D(`ONLY`),...qe(),keyword:t,location:e}}let t=v(+!!T(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){D(`PROOF`),E();let n=h(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}D(`PROOF`);let n=[tt()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(tt());return{kind:`Steps`,level:Me(),steps:n,location:e}},rt=()=>{let e=r.index;I.push(-1);let t=Ue(nt);return I.pop(),g(t,e)},it=e=>{let t=r.index,n=E(),i=v().kind===`Identifier`&&T(`==`,1)?k():void 0;i!==void 0&&(a.add(i),E());let o=Ue(()=>({statement:T(`ASSUME`)?Xe():P(),proof:Ie(v())?rt():void 0})),s=o.statement,c=g({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(g({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:u(n)},t))},at=()=>{let e=r.index;return g(ot(),e)},ot=()=>{let e=E(),t=u(e),n=e.text===`AXIOM`;if(v().kind===`Identifier`&&T(`==`,1)){let e=k();return a.add(e),E(),{name:e,expression:P(),isAxiom:n,location:t}}return{name:void 0,expression:P(),isAxiom:n,location:t}},st=()=>{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(h(e))});;){let a=r.index;b.index=a;let o=v();if(o.kind===`ModuleEnd`||o.kind===`End`)return o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),c.pop(),i.pop(),n;if(o.kind===`Separator`){if(T(`MODULE`,1)){let e=st();n.modules.push(e),n.units.push({kind:`Module`,module:e}),O(`====`);continue}E()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{E();let e=Oe();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{E();let e=A(()=>{let e=r.index,t=u(v());return g({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=at();n.assumptions.push(e),n.units.push({kind:`Assumption`,assumption:e}),e.name!==void 0&&n.definitions.push({kind:`Operator`,name:e.name,params:[],body:e.expression,isLocal:!1,isRecursive:!1,location:e.location});continue}case`USE`:case`HIDE`:{let e=Je();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:E(),n.units.push({kind:`Recursive`,declarations:ke()});continue;case`INSTANCE`:ct(n,g(Ee(void 0,[],!1,u(o)),a));continue;case`LOCAL`:if(E(),T(`INSTANCE`)){ct(n,g(Ee(void 0,[],!0,u(o)),a));continue}ct(n,F(!0));continue}o.kind===`Keyword`&&Ys.has(o.text)?it(n):ct(n,F(!1))}}},ct=(e,t)=>{t.kind===`Instance`?(e.instances.push(t),e.units.push({kind:`Instance`,instance:t})):(e.definitions.push(t),e.units.push({kind:`Definition`,definition:t}))};return st()},lc=e=>cc(e,!1),uc=e=>cc(e,!0),dc=25214903917n,fc=(1n<<48n)-1n,pc=2147483647,mc=e=>{let t={value:(BigInt.asUintN(64,e)^dc)&fc},n=e=>(t.value=t.value*dc+11n&fc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^dc)&fc},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=pc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},hc=10454148508367108822n,gc=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:hc);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),_c=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e>>32n))),vc=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e))),yc=Number(BigInt.asIntN(32,hc>>32n)),bc=Number(BigInt.asIntN(32,hc));let xc=yc,Sc=bc;const Cc=e=>{let t=(e^Sc)&255;Sc=(Sc>>>8|xc<<24)^vc[t],xc=xc>>>8^_c[t]},wc=e=>{for(let t=0;t<32;t+=8)Cc(e>>>t)},Tc=e=>{if(typeof e==`boolean`)Cc(0),Cc(e?116:102);else if(typeof e==`number`)Cc(1),wc(e);else if(typeof e==`string`){Cc(3),wc(e.length);for(let t=0;t<e.length;t++)Cc(e.charCodeAt(t))}else if(N(e))Cc(21),wc(Ae(e.name)+1);else if(M(e)){let t=H(e);Cc(9),wc(t.domain.length);for(let e=0;e<t.domain.length;e++)Tc(t.domain[e]),Tc(t.range[e])}else{let t=B(e).elements;Cc(5),wc(t.length);for(let e of t)Tc(e)}},Ec=e=>{let t={high:xc,low:Sc};xc=yc,Sc=bc;for(let t of e)Tc(t);let n=BigInt(xc>>>0)<<32n|BigInt(Sc>>>0);return xc=t.high,Sc=t.low,n},Dc=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||N(e))return 5;if(typeof e==`string`)return 5+e.length;if(M(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+Dc(n)+Dc(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+Dc(t),5)},Oc=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){xc=n<32?0:1<<n-32,Sc=n<32?1<<n:0;for(let t=0;t<e;t++)Cc(0);let r=n>>3,i=1<<(n&7);for(let e=i;e<2*i;e++){let n=(r*256+e)*2,a=(r*256+e-i)*2;t[n]=t[a]^xc,t[n+1]=t[a+1]^Sc}}return t},kc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=[],r=e=>{let r=t.get(e);if(r!==void 0)return r;let i=Dc(e);return xc=0,Sc=0,Tc(e),t.set(e,n.length),n.push(i,xc,Sc),n.length-3},i=t=>{let n=e.get(t);if(n)return n;let r=Oc(t);return e.set(t,r),r};return e=>{let t={high:xc,low:Sc},a={high:yc,low:bc};for(let t of e){let e=r(t),o=i(n[e]),s={high:n[e+1],low:n[e+2]};for(let e=0;e<8;e++){let t=e<4?a.low:a.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=o[n],s.low^=o[n+1]}a.high=s.high,a.low=s.low}return xc=t.high,Sc=t.low,BigInt(a.high>>>0)<<32n|BigInt(a.low>>>0)}},Ac=[],jc=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Mc=()=>{for(let e=1277011;Ac.length<1341;e++)jc(e)&&Ac.push(e);return Ac},Nc=e=>{let t=Mc(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Pc=e=>{let t=[],n={value:e};for(let e=2;e*e<=n.value;e++)for(;n.value%e===0;)t.push(e),n.value/=e;return n.value>1&&t.push(n.value),t},Fc=e=>{for(let t=Math.max(e,9);;t++){let e=Pc(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Ic=(e,t,n)=>{if(t<=0)return[];let r=Fc(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Nc(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Lc=(1n<<63n)-1n-24n,Rc=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Lc*BigInt(n)+i)%t;return r<0n?r+t:r})},zc=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Bc=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=kt(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>ze(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>jt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Vc=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ic(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=Bc(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(pc)?Rc(e,t,n):Ic(e,Number(t),n)).map(e=>r.create(zc(r.lists,e)))}let i=B(t).elements;return Ic(e,i.length,n).map(e=>i[Number(e)])},Hc=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new m(`RandomElement of the empty set`);return n},Uc=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...kt(e.domain)];return ze(n,n.map(()=>Uc(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return jt(e.names.map((n,r)=>[n,Uc(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Uc(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.floor(t.nextDouble()*n);if(r>=n)throw new m(`RandomElement of the empty set`);return e.low+r}return Hc(B(e).elements,t)},Wc=(e,t=0n)=>{let n=mc(t),r={random:mc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>jt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Ec,getRandom:()=>{let e=i.isStartup?void 0:a.getCurrentState();return e===void 0?n:(e!==r.state&&(r.random.setSeed(a.getFingerprint(e)^BigInt.asUintN(64,t)),r.state=e),r.random)},evaluateAtStartup:e=>{let t=i.isStartup;i.isStartup=!0;try{return e()}finally{i.isStartup=t}},pause:()=>{},seed:t,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,isStopped:!1,checkDeadlock:e,startedAt:Date.now()};return a},Gc=e=>xt([...e.possibleCounts].map(([e,t])=>[e,t])),Kc=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Gc(e)]]),qc=(e,t,n)=>new h(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Jc=(e,t,n,r)=>new h(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Yc=e=>M(e)?H(e):void 0,Xc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw qc(n,`a function with a finite domain`,r);return i},Zc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw Jc(t===0?`first`:`second`,n,`bag`,r);return i},Qc=(e,t)=>{if(!j(e)||!z(e))throw t();return B(e).elements},$c=e=>e.range.every(e=>typeof e==`number`&&e>0),el=(e,t)=>{let n=e.domain.findIndex(e=>Be(e,t));return n===-1?void 0:e.range[n]},tl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,nl=tl(`BagDiff`,`tlc2.value.impl.Value`,2),rl=tl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),il=tl(`BagUnion`,`tlc2.value.impl.Value`,1),al=tl(`BagOfAll`,`tlc2.value.impl.Value`,2),ol=tl(`BagCup`,`tlc2.value.impl.Value`,2),sl=tl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),cl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${rr(e)}`;throw ar(t,`class ${n} cannot be cast to class tlc2.value.impl.IntValue (${n} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`)},ll=(e,t,n)=>{let r=cl(e,n)+cl(t,n);if(Qn(r))throw $n(`${e}+${t}`);return r},ul=(e,t,n,r)=>{let i=el(n,e.domain[t]),a=cl(e.range[t],r);return i===void 0?a:a-cl(i,r)|0},dl=(e,t)=>xt(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>Be(e[0],r));a?a[1]=ll(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),fl=ze([],[]),pl=[Jn(`EmptyBag`,fl),K(`IsABag`,1,e=>{let t=Yc(G(e,0,`IsABag`));return t!==void 0&&$c(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Xc(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw qc(`BagCardinality`,`a bag`,t);return ll(e,n,sl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=el(Xc(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Jc(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=el(Xc(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Jc(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Zc(e,t,`(+)`);if(!$c(n))throw Jc(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return dl(t,ol)}),K(`\\ominus`,2,e=>{let t=Zc(e,0,`(-)`),n=Zc(e,1,`(-)`);return xt(t.domain.flatMap((e,r)=>{let i=ul(t,r,n,nl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Qc(t,()=>qc(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??fl;let r=n.map(e=>{let n=Yc(e);if(!n)throw new h(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return dl(r,il)}),K(`\\sqsubseteq`,2,e=>{let t=Xc(e,0,`\\sqsubseteq`),n=Xc(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>ul(t,r,n,rl)<=0)}),Yn(`BagOfAll`,2,e=>{let t=qn(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new h(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Yc(n);if(!r)throw Jc(`second`,`BagOfAll`,`function with a finite domain`,n);return dl(r.domain.map((e,n)=>ze([t.call([e])],[r.range[n]])),al)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!M(t))throw new m(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=ht(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new m(`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 m(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return ht(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>ze(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>sn(Xc(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Qc(t,()=>qc(`BagToSet`,`a function with a finite domain`,t));return ze([...n],n.map(()=>1))})],ml=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,hl=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,gl=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,_l=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,vl=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,yl=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,bl=e=>{if(!M(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},xl=(e,t)=>ar(e,`Cannot convert value: unsupported value type tlc2.value.impl.${rr(t)}`),Sl=(e,t)=>ar(e,`Cannot cast tlc2.value.impl.${rr(t)} to tlc2.value.impl.StringValue`),Cl=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),wl=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw xl(t,e);return`[${B(e).elements.map(e=>El(e,t)).join(`,`)}]`},Tl=(e,t)=>{let n=H(e),r=Yt(n);return r?`[${r.map(e=>El(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${Cl(typeof e==`string`?e:U(e))}:${El(n.range[r],t)}`).join(`,`)}}`},El=(e,t)=>typeof e==`string`?Cl(e):typeof e==`object`?e.kind===`ModelValue`?Cl(e.name):j(e)?wl(e,t):Tl(e,t):String(e),Dl=e=>{if(j(e))return wl(e,ml);if(!M(e)||bl(e))throw xl(ml,e);return Tl(e,ml)},Ol=e=>{if(!M(e))throw xl(hl,e);return Tl(e,hl)},kl=e=>{let[,t,n=`0`,r=``,i=`0`]=/^(-?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(e)??[],a=BigInt(n+r),o=Number(i)-r.length,s=o>=0?a*10n**BigInt(o):a/10n**BigInt(-o);return Number(BigInt.asIntN(32,t===`-`?-s:s))},Al=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return Oe(e);if(Array.isArray(e))return R(e.map(e=>Al(e,t)));if(typeof e==`object`&&e)return jt(Object.entries(e).map(([e,n])=>[Oe(e),Al(n,t)]));throw ar(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},jl=(e,t)=>{if(e.trim()===``)return Al(null,t);try{return Al(JSON.parse(e,(e,t,n)=>typeof t==`number`?kl(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?ar(t,e.message):e}},Ml=(e,t)=>{if(typeof e!=`string`)throw Sl(t,e);return e},Nl=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw ar(n,`${t} (No such file or directory)`);return r},Pl=e=>[Xn(`ToJson`,1,e=>Oe(El(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Xn(`ToJsonArray`,1,e=>Oe(Dl(G(e,0,`ToJsonArray`)))),Xn(`ToJsonObject`,1,e=>Oe(Ol(G(e,0,`ToJsonObject`)))),Xn(`JsonSerialize`,2,t=>{let n=Ml(G(t,0,`JsonSerialize`),gl),r=G(t,1,`JsonSerialize`);if(!Yt(r)&&!bl(r))throw new h(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,El(r,gl)),!0}),Xn(`ndJsonSerialize`,2,t=>{let n=Ml(G(t,0,`ndJsonSerialize`),_l),r=G(t,1,`ndJsonSerialize`),i=Yt(r);if(!i)throw new h(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${El(e,_l)}\n`).join(``)),!0}),Xn(`JsonDeserialize`,1,t=>{let n=Ml(G(t,0,`JsonDeserialize`),vl);return jl(Nl(e,n,vl),vl)}),Xn(`ndJsonDeserialize`,1,t=>{let n=Ml(G(t,0,`ndJsonDeserialize`),yl);return R(Nl(e,n,yl).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>jl(e,yl)))})],Fl=(e,t,n,r)=>new h(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Il=(e,t,n)=>{if(typeof e!=`number`||e<0)throw Fl(t,n,`nonnegative integer`,U(e));return e},Ll=(e,t,n,r)=>{if(!j(e)||!z(e))throw Fl(t,n,r,U(e));return B(e).elements},Rl=(e,t,n,r)=>ht(Array.from({length:t},()=>ht(e.filter(()=>r.nextDouble()<n)))),zl=(e,t)=>{let n=`RandomSetOfSubsets`,r=Il(G(e,0,n),`first`,n),i=Il(G(e,1,n),`second`,n),a=Ll(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw Fl(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw Fl(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Rl(a,r,a.length===0?0:i/a.length,t.getRandom())},Bl=e=>[Xn(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw Fl(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new m(`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(!j(r)||!V(r)&&!z(r))throw Fl(`second`,`RandomSubset`,`a finite set`,U(r));return ht(Vc(n,r,e.getRandom()))}),Xn(`RandomSetOfSubsets`,3,t=>zl(t,e)),Xn(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(zl(t,e)).elements.length)))],Vl=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Hl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Vl})`,Ul=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Vl}) throws java.io.IOException`,Wl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Vl})`,Gl=()=>jt([[`action`,ht([])],[`state`,ht([])]]),Kl=()=>jt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ql=e=>jt([[`name`,e??`UnnamedAction`],[`location`,Kl()]]),Jl=(e,t)=>{let n=e.map((e,t)=>R([t+1,jt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ql(e[r+1].action),t])),i=t?[R([n[n.length-1],ql(t.action),n[t.start]])]:[];return jt([[`action`,ht([...r,...i])],[`state`,ht(n)]])},Yl=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Kc(e).get(t)},Xl=(e,t,n)=>{if(typeof t==`number`&&t>=0)e.registers.set(t,n);else if(typeof t==`string`&&t.startsWith(`s:`))e.namedRegisters.set(t,n);else throw new h(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(t)}`)},Zl=e=>e.every(e=>e!==void 0),Ql=(e,t)=>jt(t.variables.map((t,n)=>[t,e[n]])),$l=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(e.kind===`Prime`||e.kind===`Unchanged`)return!0;if(r!==void 0&&!W(e)){if(t.variableIndex.has(r))return!0;let e=Za(r,t);if(e&&!n.has(e)&&(n.add(e),$l(e.body,t,n)))return!0}return Fn(e).some(e=>$l(e,t,n))},eu=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new WeakMap,i=e=>{let t=r.get(e)??/* @__PURE__ */ new Map;return r.set(e,t),t};return[K(`AssertEq`,2,t=>{let n=G(t,0,`AssertEq`),r=G(t,1,`AssertEq`),i=Be(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),fr(`AssertError`,2,e=>{let t=qn(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw ar(Hl,`In computing AssertError, a non-string expression (line ${t.location.line}, col ${t.location.column}) was used as the err of an AssertError(err, exp).`);let n=pr(e,0,`AssertError`)();try{pr(e,1,`AssertError`)()}catch(e){if(e instanceof m)return e.message===n;throw e}return!1}),Xn(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Yl(t,n)??G(e,1,`TLCGetOrDefault`)}),{...Yn(`TLCGetAndSet`,4,e=>{let n=G(e,0,`TLCGetAndSet`),r=Yl(t,n)??G(e,3,`TLCGetAndSet`),i=qn(e,1,`TLCGetAndSet`);return Xl(t,n,i.call([r,G(e,2,`TLCGetAndSet`)])),r}),isStateLevel:!0},Xn(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Zl(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw ar(Ul,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return R(t.getBehavior(r).map(e=>Ql(e,n.environment)))}),Xn(`CounterExample`,0,()=>t.counterExample??Gl()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!M(t)||!Be(sn(t),ht([`action`,`state`])))throw new m(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(an(t,`state`)).elements.map(e=>Yt(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 h(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Le(t)}),fr(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),fr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Zl(r))throw ar(Wl,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Xa(pr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new v(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),fr(`TLCCache`,2,(e,t)=>{let r=qn(e,0,`TLCCache`),a=Tn(pr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=$l(o,t.environment,/* @__PURE__ */ new Set)&&t.state?i(t.state):n,c=s.get(o)??/* @__PURE__ */ new Map;s.set(o,c);let l=c.get(a);if(l!==void 0)return l;let u=r.call([]);return c.set(a,u),u}),K(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Ec([G(e,0,`TLCFP`)])))),Xn(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?Za(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new h(`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 h(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return X({kind:`Identifier`,name:n,location:r.location},t)})]},tu=(e,t)=>[Xn(`_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}),Xn(`_Counts`,0,()=>Gc(t)),Xn(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(Gc(t),!0)),!1)}),Xn(`_PrintCounts`,0,()=>(e(U(Gc(t),!0)),!0))],nu=e=>String(e).padStart(2,`0`),ru=e=>`${e.getUTCFullYear()}.${nu(e.getUTCMonth()+1)}.${nu(e.getUTCDate())}.${nu(e.getUTCHours())}${nu(e.getUTCMinutes())}${nu(e.getUTCSeconds())}`,iu=e=>xt([...e].map(([e,t])=>[e,R([t])])),au=(e,t,n)=>{let r=Math.floor((Date.now()-e.startedAt)/1e3);switch(t){case`level`:return n===void 0?0:e.getLevel(n);case`diameter`:return e.diameter;case`generated`:return e.generatedStates;case`distinct`:return e.distinctStates;case`queue`:return e.queueSize;case`duration`:return r;case`stats`:return jt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return jt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return jt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,Oe(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,Oe(ru(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ql(void 0);case`all`:return iu(e.registers);case`all:named`:return iu(Kc(e))}if(t.startsWith(`s:`)){let n=Kc(e).get(t);if(n===void 0)throw new h(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return Oe(e.properties.get(t.slice(2))??t);throw new h(`TLCGet(${t}) was undefined.`)},ou=e=>e.length===0?[[]]:e.flatMap((t,n)=>ou([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),su=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(su),e.kind===`Function`&&e.range.forEach(su))},cu=(t,n)=>[K(`Print`,2,e=>(t(`${me(U(G(e,0,`Print`),!0,!0))} ${me(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(me(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new h(`The first argument of Assert evaluated to FALSE; the second argument was:\n${me(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>xt([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=Kn(e,0,`@@`),n=Kn(e,1,`@@`);return St([...ye(t),...ye(n)])}),K(`ToString`,1,e=>Oe(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return su(t),t}),K(`Permutations`,1,e=>{let t=Wn(e,0,`Permutations`);return ht(ou(t).map(e=>xt(t.map((t,n)=>[t,e[n]]))))}),Yn(`SortSeq`,2,e=>{let t=qn(e,1,`SortSeq`);return R(Gn(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)]},[]))}),Xn(`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 h(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new h(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return au(n,r,t?.state)}),Xn(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`),i=G(e,1,`TLCSet`);if(typeof r==`number`&&r>=0)return n.registers.set(r,i),!0;if(r===`exit`)return i===!0&&(n.isStopped=!0),!0;if(r===`pause`)return i===!0&&(t(`Press enter to resume model checking.`),n.pause()),!0;if(typeof r==`string`&&r.startsWith(`s:`))return n.namedRegisters.set(r,i),!0;if(typeof r==`string`&&r.startsWith(`-D`))return n.properties.set(r.slice(2),U(i)),!0;throw new h(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(r)}`)}),Jn(`Any`,Pe),K(`RandomElement`,1,e=>Uc(Hn(e,0,`RandomElement`),n.getRandom()))],lu=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices`.split(`,`),uu=[[`\\lnot`,`~`,`\\neg`,`¬`],[`[]`,`□`],[`<>`,`◇`],[`\\land`,`/\\`,`∧`],[`\\lor`,`\\/`,`∨`],[`\\equiv`,`<=>`,`≡`,`⇔`],[`/=`,`#`,`≠`],[`\\leq`,`<=`,`=<`,`≤`],[`\\geq`,`>=`,`≥`],[`\\times`,`\\X`,`×`],[`\\intersect`,`\\cap`,`∩`],[`\\union`,`\\cup`,`∪`],[`\\o`,`\\circ`,`∘`],[`\\oplus`,`(+)`,`⊕`],[`\\ominus`,`(-)`,`⊖`],[`\\odot`,`(.)`,`⊙`],[`\\oslash`,`(/)`,`⊘`],[`\\otimes`,`(\\X)`,`⊗`],[`\\approx`,`≈`],[`:=`,`≔`],[`\\asymp`,`≍`],[`\\bigcirc`,`◯`],[`::=`,`⩴`],[`\\bullet`,`●`],[`\\cdot`,`⋅`],[`\\cong`,`≅`],[`\\div`,`÷`],[`\\doteq`,`≐`],[`..`,`‥`],[`...`,`…`],[`!!`,`‼`],[`\\gg`,`≫`],[`=>`,`⇒`],[`\\in`,`∈`],[`=|`,`⫤`],[`~>`,`↝`],[`\\ll`,`≪`],[`-|`,`⊣`],[`\\notin`,`∉`],[`-+->`,`⇸`],[`\\prec`,`≺`],[`\\preceq`,`⪯`],[`\\propto`,`∝`],[`??`,`⁇`],[`|=`,`⊨`],[`|-`,`⊢`],[`\\sim`,`∼`],[`\\simeq`,`≃`],[`\\sqcap`,`⊓`],[`\\sqcup`,`⊔`],[`\\sqsubset`,`⊏`],[`\\sqsubseteq`,`⊑`],[`\\sqsupset`,`⊐`],[`\\sqsupseteq`,`⊒`],[`\\star`,`⋆`],[`\\subset`,`⊂`],[`\\subseteq`,`⊆`],[`\\succ`,`≻`],[`\\succeq`,`⪰`],[`\\supset`,`⊃`],[`\\supseteq`,`⊇`],[`\\uplus`,`⊎`],[`||`,`‖`],[`\\wr`,`≀`],[`^+`,`⁺`]],du=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices,***I do not exist***,--TLA+ BUILTINS--,Formal_0,Formal_1,Formal_2,[,^,/,*,-,-.,+,^+,^*,^#,<,\\leq,>,\\geq,...,..,|,||,&&,&,$$,$,??,%%,%,##,++,--,**,//,^^,@@,!!,|-,|=,-|,=|,<:,:>,:=,::=,\\oplus,\\ominus,\\odot,\\oslash,\\otimes,\\uplus,\\sqcap,\\sqcup,\\div,\\wr,\\star,\\o,\\bigcirc,\\bullet,\\prec,\\succ,\\preceq,\\succeq,\\sim,\\simeq,\\ll,\\gg,\\asymp,\\subset,\\supset,\\supseteq,\\approx,\\cong,\\sqsubset,\\sqsubseteq,\\sqsupset,\\sqsupseteq,\\doteq,\\propto,~,¬,□,◇,/\\,∧,\\/,∨,<=>,≡,⇔,#,≠,<=,=<,≤,>=,≥,\\X,×,\\cap,∩,\\cup,∪,\\circ,∘,(+),⊕,(-),⊖,(.),⊙,(/),⊘,(\\X),⊗,≈,≔,≍,◯,⩴,●,⋅,≅,÷,≐,‥,…,‼,≫,⇒,∈,⫤,↝,≪,⊣,∉,⇸,≺,⪯,∝,⁇,⊨,⊢,∼,≃,⊓,⊔,⊏,⊑,⊐,⊒,⋆,⊂,⊆,≻,⪰,⊃,⊇,⊎,‖,≀,⁺,@`.split(`,`),fu=/* @__PURE__ */ `exit.pause.config.spec.coverage.action.install.id.behavior.all.mode.deadlock.seed.fingerprint.worker.traces.depth.aril.sched.revision.timestamp.date.count.tag.calver.impliedinits.impliedactions.invariants.impliedtemporals.temporals.actions.inits.variables.actionconstraints.constraints.stats.duration.generated.diameter.distinct.initial.queue.retries.distinctvalues.levelmean.levelvariance.bfs`.split(`.`),pu=/* @__PURE__ */ `Not a node.N_ActDecl.N_ActionExpr.N_AssumeDecl.N_AssumeProve.N_Assumption.N_BeginModule.N_Body.N_BoundedQuant.N_Case.N_CaseArm.N_CaseStatement.N_ChooseStatement.N_ConjItem.N_ConjList.N_ConsDecl.N_DisjItem.N_DisjList.N_EndModule.N_Except.N_ExceptComponent.N_ExceptSpec.N_Times.N_Extends.N_FairnessExpr.N_FcnAppl.N_FcnConst.N_FieldSet.N_FieldVal.N_FunctionDefinition.N_FunctionParam.N_GeneralId.N_GenInfixOp.N_GenNonExpPrefixOp.N_GenPostfixOp.N_GenPrefixOp.N_IdentDecl.N_Real.N_IdentifierTuple.N_IdentLHS.N_IdPrefix.N_IdPrefixElement.N_IfThenElse.N_InfixDecl.N_InfixExpr.N_InfixLHS.N_InfixOp.N_InnerProof.N_Instance.N_NonLocalInstance.N_Integer.N_LeafProof.N_LetDefinitions.N_LetIn.N_MaybeBound.N_Module.N_ModuleDefinition.N_NonExpPrefixOp.N_Number.N_NumberedAssumeProve.N_OpApplication.N_OpArgs.N_OperatorDefinition.N_OtherArm.N_ParamDecl.N_ParamDeclaration.N_ParenExpr.N_PostfixDecl.N_PostfixExpr.N_PostfixLHS.N_PostfixOp.N_PrefixDecl.N_PrefixExpr.N_PrefixLHS.N_PrefixOp.N_Proof.N_ProofLet.N_ProofName.N_ProofStatement.N_ProofStep.N_QEDStep.N_QuantBound.N_RcdConstructor.N_RecordComponent.N_SetEnumerate.N_SetOfAll.N_SetOfFcns.N_SetOfRcds.N_String.N_SubsetOf.N_Substitution.N_TempDecl.N_Theorem.N_Tuple.N_UnBoundedOrBoundedChoose.N_UnboundedQuant.N_VariableDeclaration.Token =.Token \\in.N_NewSymb.N_Lambda.N_Recursive.N_Label.N_StructOp.N_NumerableStep.N_TerminalProof.N_UseOrHide.N_NonExprBody.N_DefStep.N_HaveStep.N_TakeStep.N_WitnessStep.N_PickStep.N_CaseStep.N_AssertStep`.split(`.`),mu=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
92
+ =============================================================================`]]),js=`tlc2/value/impl/`,Ms=e=>{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n={offset:0},r=e=>{let t=n.offset;return n.offset+=e,t};return{readUint8:()=>t.getUint8(r(1)),readUint16:()=>t.getUint16(r(2)),readUint32:()=>t.getUint32(r(4)),readInt32:()=>t.getInt32(r(4)),readBytes:t=>e.subarray(r(t),n.offset)}},Ns=e=>[...e.slice(1,e.indexOf(`)`)).matchAll(/\[*(?:L[^;]*;|[BCDFIJSZ])/g)].length,Ps=e=>{let t=Ms(e);if(t.readUint32()!==3405691582)throw new c(`A module override is not a class file`);t.readUint16(),t.readUint16();let n=[],r=t.readUint16(),i=new TextDecoder;for(let e=1;e<r;e++){let r=t.readUint8(),a={tag:r,text:``,value:0,first:0,second:0};n[e]=a,r===1?a.text=i.decode(t.readBytes(t.readUint16())):r===3?a.value=t.readInt32():r===4?t.readUint32():r===5||r===6?(t.readBytes(8),e++):r===7||r===8||r===16||r===19||r===20?a.first=t.readUint16():r===15?(t.readUint8(),a.first=t.readUint16()):(a.first=t.readUint16(),a.second=t.readUint16())}t.readUint16(),t.readUint16(),t.readUint16(),t.readBytes(t.readUint16()*2);for(let e=t.readUint16();e>0;e--){t.readBytes(6);for(let e=t.readUint16();e>0;e--)t.readUint16(),t.readBytes(t.readUint32())}let a=[];for(let e=t.readUint16();e>0;e--){let e=t.readUint16(),r=n[t.readUint16()].text,i=n[t.readUint16()].text,o={name:r,arity:Ns(i),code:void 0};for(let e=t.readUint16();e>0;e--){let e=n[t.readUint16()].text,r=t.readBytes(t.readUint32());if(e===`Code`){let e=new DataView(r.buffer,r.byteOffset+4,4).getUint32(0);o.code=r.subarray(8,8+e)}}e&1&&e&8&&a.push(o)}return{pool:n,methods:a}},Fs=(e,t)=>e[e[t].first].text,Is=(e,t)=>{let n=e[t],r=e[n.second];return{className:Fs(e,n.first),name:e[r.first].text}},Ls=(e,t,n,r)=>{let i=()=>new m(`The Java override ${n}.${e.name} computes its value, which tla-ts cannot run`),a=e.code;if(!a)throw i();let o=[],s=()=>{let e=o.pop();if(e===void 0)throw i();return e},c=e=>{let n=t[e];if(n.tag===3)return n.value;if(n.tag===8)return t[n.first].text;throw i()};for(let e=0;e<a.length;){let n=a[e],l=()=>a[e+1]<<8|a[e+2];if(n>=2&&n<=8)o.push(n-3),e+=1;else if(n===16)o.push(a[e+1]<<24>>24),e+=2;else if(n===17)o.push(l()<<16>>16),e+=3;else if(n===18)o.push(c(a[e+1])),e+=2;else if(n===19)o.push(c(l())),e+=3;else if(n===89){let t=s();o.push(t,t),e+=1}else if(n===178){let n=Is(t,l());if(n.className!==`${js}BoolValue`||n.name!==`ValTrue`&&n.name!==`ValFalse`)throw i();o.push({kind:`Identifier`,name:n.name===`ValTrue`?`TRUE`:`FALSE`,location:r}),e+=3}else if(n===184){let n=Is(t,l()),a=s();if(n.className!==`${js}IntValue`||n.name!==`gen`||typeof a!=`number`)throw i();o.push({kind:`Number`,value:a,location:r}),e+=3}else if(n===187)o.push({className:Fs(t,l()),value:void 0}),e+=3;else if(n===183){let n=Is(t,l()),a=s(),o=s();if(!(n.className===`${js}StringValue`&&n.name===`<init>`&&typeof a==`string`&&typeof o==`object`&&`className`in o))throw i();o.value={kind:`String`,value:a,location:r},e+=3}else if(n===176){let e=s();if(typeof e!=`object`)throw i();if(`className`in e){if(!e.value)throw i();return e.value}return e}else throw i()}throw i()},Rs=(e,t)=>{if(!t)return e;let n=Ps(t),r=e.definitions.map(t=>{if(t.kind!==`Operator`)return t;let r=n.methods.find(e=>e.name===t.name&&e.arity===t.params.length);return r?{...t,body:Ls(r,n.pool,e.name,t.location)}:t});return{...e,definitions:r}},Z=(e,t,n)=>({low:e,high:t,isAssociative:n}),zs=new Map([[`=>`,Z(1,1,!1)],[`<=>`,Z(2,2,!1)],[`~>`,Z(2,2,!1)],[`-+->`,Z(2,2,!1)],[`/\\`,Z(3,3,!0)],[`\\/`,Z(3,3,!0)],...(/* @__PURE__ */ `=.#.<.>.<=.>=.\\in.\\notin.\\subseteq.\\subset.\\supseteq.\\supset.\\sqsubseteq.\\sqsupseteq.\\sqsubset.\\sqsupset.\\prec.\\preceq.\\succ.\\succeq.\\sim.\\simeq.\\approx.\\cong.\\asymp.\\doteq.\\propto.\\ll.\\gg.|-.-|.|=.=|.:=.::=`.split(`.`)).map(e=>[e,Z(5,5,!1)]),[`\\cdot`,Z(5,14,!0)],[`@@`,Z(6,6,!0)],[`:>`,Z(7,7,!1)],[`<:`,Z(7,7,!1)],[`\\cup`,Z(8,8,!0)],[`\\cap`,Z(8,8,!0)],[`\\`,Z(8,8,!1)],[`..`,Z(9,9,!1)],[`...`,Z(9,9,!1)],[`##`,Z(9,13,!0)],[`$`,Z(9,13,!0)],[`$$`,Z(9,13,!0)],[`??`,Z(9,13,!0)],[`!!`,Z(9,13,!1)],[`\\sqcap`,Z(9,13,!0)],[`\\sqcup`,Z(9,13,!0)],[`\\uplus`,Z(9,13,!0)],[`\\wr`,Z(9,14,!1)],[`+`,Z(10,10,!0)],[`++`,Z(10,10,!0)],[`(+)`,Z(10,10,!0)],[`\\oplus`,Z(10,10,!0)],[`%`,Z(10,11,!1)],[`%%`,Z(10,11,!0)],[`|`,Z(10,11,!0)],[`||`,Z(10,11,!0)],[`\\X`,Z(10,13,!1)],[`-`,Z(11,11,!0)],[`--`,Z(11,11,!0)],[`(-)`,Z(11,11,!0)],[`\\ominus`,Z(11,11,!0)],[`*`,Z(13,13,!0)],[`**`,Z(13,13,!0)],[`/`,Z(13,13,!1)],[`//`,Z(13,13,!1)],[`\\div`,Z(13,13,!1)],[`\\o`,Z(13,13,!0)],[`(.)`,Z(13,13,!0)],[`\\odot`,Z(13,13,!0)],[`(/)`,Z(13,13,!1)],[`\\oslash`,Z(13,13,!1)],[`(\\X)`,Z(13,13,!0)],[`\\otimes`,Z(13,13,!0)],[`&`,Z(13,13,!0)],[`&&`,Z(13,13,!0)],[`\\star`,Z(13,13,!0)],[`\\bullet`,Z(13,13,!0)],[`\\bigcirc`,Z(13,13,!0)],[`^`,Z(14,14,!1)],[`^^`,Z(14,14,!1)]]),Bs=/* @__PURE__ */ new Set([`^+`,`^*`,`^#`]),Vs=/* @__PURE__ */ new Set([`-`,`~`,`-.`]),Hs=/* @__PURE__ */ new Set([`-`,`~`,`/\\`,`\\/`,`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`]),Us=/* @__PURE__ */ new Set([`+`,`-`,`/`,`\\X`]),Ws=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`ENABLED`,`UNCHANGED`,`[]`,`<>`,`'`,...Bs]),Gs=e=>zs.has(e)||Bs.has(e)||e===`-.`,Ks=(e,t,n)=>{switch(e){case`ENABLED`:return{kind:`Enabled`,expression:t,location:n};case`UNCHANGED`:return{kind:`Unchanged`,expression:t,location:n};case`[]`:return{kind:`Always`,expression:t,location:n};case`<>`:return{kind:`Eventually`,expression:t,location:n};case`'`:return{kind:`Prime`,expression:t,location:n};default:return{kind:`Apply`,operator:e,args:[t],location:n}}},qs=/* @__PURE__ */ new Set([`<<`,`>>`,`:`,`@`,`(`]),Js=/* @__PURE__ */ new Set([`ASSUME`,`ASSUMPTION`,`AXIOM`,`CONSTANT`,`CONSTANTS`,`COROLLARY`,`INSTANCE`,`LEMMA`,`LOCAL`,`PROPOSITION`,`RECURSIVE`,`THEOREM`,`VARIABLE`,`VARIABLES`]),Ys=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Xs=/* @__PURE__ */ new Set([`BY`,`PROOF`,`OBVIOUS`,`OMITTED`]),Zs=/* @__PURE__ */ new Set([`Qed`,`Pick`,`Case`,`Assert`]),Qs=/* @__PURE__ */ new Set(/* @__PURE__ */ `, . _ ( ) [ ] { } << >> ]_ >>_ == ! @ : :: ; -> <- |-> \\A \\AA \\E \\EE \\forall \\exists WF_ SF_ (*{ }*)`.split(` `)),$s=/* @__PURE__ */ new Set([``,`*`,`-`]),ec=/* @__PURE__ */ new Set([`CASE`,`CHOOSE`,`DOMAIN`,`ENABLED`,`IF`,`LAMBDA`,`LET`,`SF_`,`SUBSET`,`UNCHANGED`,`UNION`,`WF_`]),tc=/* @__PURE__ */ new Map([[`CONSTANT`,`Constant`],[`CONSTANTS`,`Constant`],[`VARIABLE`,`Variable`],[`VARIABLES`,`Variable`],[`STATE`,`State`],[`ACTION`,`Action`],[`ACTIONS`,`Action`],[`TEMPORAL`,`Temporal`],[`TEMPORALS`,`Temporal`]]),nc=/* @__PURE__ */ new Set([`NEW`,...tc.keys()]),rc=/* @__PURE__ */ new Set([`(`,`[`,`{`,`<<`]),ic=/* @__PURE__ */ new Set([`)`,`]`,`}`,`>>`,`]_`,`>>_`]),ac=/* @__PURE__ */ new Set([`TRUE`,`FALSE`,`BOOLEAN`,`STRING`]),oc=e=>RegExp(`^-{4,}\\s*MODULE\\s+${e}\\s*-{3,}$`),sc=(e,t)=>{let n=e.split(/\r?\n/),r=n.findIndex(e=>oc(t).test(e));if(r===-1)return;let i=n.findIndex((e,t)=>t>r&&e.startsWith(`====`));return n.slice(r,i===-1?void 0:i+1).join(`
93
+ `)},cc=(e,t)=>{let n=oe(e),r={index:0,offsideColumns:[]},i=[],a=/* @__PURE__ */ new Set,o=[],s={index:-1},l=[],u=e=>i[i.length-1].has(e),d=e=>({line:e.line,column:t&&e.kind===`String`?e.endColumn:e.column,range:void 0}),f=[],p=[],m=[],h=e=>{let t=r.index-1,i=e===t?m[e]:void 0;if(i)return i;let a=n[t];f[e]??=d(n[e]),p[t]??={line:a.line,column:a.endColumn};let o={module:l[l.length-1].name,start:f[e],end:p[t]};return e===t&&(m[e]=o),o},g=(e,t)=>(e.location.range=h(t),e),_=(e=0)=>n[Math.min(r.index+e,n.length-1)],v=(e=0)=>{let t=_(e),n=r.offsideColumns[r.offsideColumns.length-1];return n===void 0||n===-1||t.kind===`End`?t:t.column<=n?{...t,kind:`End`,text:``}:t},y=e=>e.kind===`End`?`end of input`:JSON.stringify(e.text),ee={index:0},b=e=>{let t=n.slice(ee.index,r.index).find(e=>e.text===`==`&&e.kind!==`String`);return t?{line:t.line,column:t.endColumn+1}:e},te=e=>t&&(e.kind===`Keyword`||ac.has(e.text)),re=e=>{let t=n.findLast(t=>t.kind!==`End`&&(t.line<e.line||t.line===e.line&&t.column<e.column));return t?{line:t.line,column:t.endColumn+1}:e},x=e=>/^-{4,}$/.test(e.text)?`----`:/^={4,}$/.test(e.text)?`====`:Qs.has(e.text)||e.kind===`Number`||e.kind===`Decimal`?e.text:e.kind===`String`?JSON.stringify(e.text):te(e)?`keyword ${e.text}`:e.kind===`Identifier`?`identifier ${e.text}`:`operator ${e.text}`,S=(e,t=_(),r)=>{let i=n[n.length-1],a=t.line===i.line&&t.column===i.column;return new c(`${e} at line ${t.line}, column ${t.column}`,void 0,ie(e,t,a,r))},ie=(e,r,i,a)=>{if(t&&i){let e=n[n.length-1];return{reason:`Unexpected EOF`,...b(re(e)),isEnd:i}}return t&&a?{reason:`Unexpected ${x(a)}`,...re(a),isEnd:i}:{reason:e,line:r.line,column:r.column,isEnd:i}},C=(e,t=_())=>S(e,t,t),ae=e=>(e.kind===`Identifier`||e.kind===`Keyword`)&&!te(e),w=(e,t=0)=>{let n=v(t);return n.text===e&&n.kind!==`String`&&n.kind!==`End`},T=()=>{let e=v();if(e.kind===`End`)throw S(`Unexpected end of expression`);return r.index++,e},E=e=>w(e)?(r.index++,!0):!1,D=e=>{if(!w(e))throw C(`Expected ${JSON.stringify(e)} but found ${y(v())}`);return T()},O=()=>{let e=v();if(e.kind!==`Identifier`)throw C(`Expected an identifier but found ${y(e)}`);if(te(e))throw C(`Unexpected keyword ${e.text}`);return r.index++,e.text},se=e=>{r.offsideColumns.push(-1);let t=e();return r.offsideColumns.pop(),t},k=(e,t=`,`)=>{let n=[e()];for(;E(t);)n.push(e());return n},ce=()=>{if(w(`<<`)){let e={value:1};for(;v(e.value).kind===`Identifier`||w(`,`,e.value);)e.value++;return w(`>>`,e.value)&&w(`\\in`,e.value+1)}let e={value:0};for(;v(e.value).kind===`Identifier`;){if(w(`\\in`,e.value+1))return!0;if(!w(`,`,e.value+1))return!1;e.value+=2}return!1},le=()=>{if(w(`::`))return!0;if(!w(`(`))return!1;let e={value:1};for(;v(e.value).kind===`Identifier`&&w(`,`,e.value+1);)e.value+=2;return v(e.value).kind===`Identifier`&&w(`)`,e.value+1)&&w(`::`,e.value+2)},ue=()=>{if(!E(`<<`))return{kind:`Name`,name:O()};let e=k(O);return D(`>>`),{kind:`Tuple`,names:e}},de=()=>k(()=>{let e=k(ue);D(`\\in`);let t=N();return e.map(e=>({pattern:e,set:t}))}).flat(),A=()=>{let e=v();if(e.kind===`Identifier`){let t=r.index,n=[T().text];for(;w(`!`)&&v(1).kind===`Identifier`;)T(),n.push(O());return g({kind:`Identifier`,name:n.join(`!`),location:d(e)},t)}if(w(`<<`)||w(`(`))return Se();throw C(`Expected a subscript but found ${y(e)}`)},j=e=>{let t=v(1),n=v(2);return t.kind===`Identifier`&&n.text===`==`?!0:t.line===e.line?!1:t.text===`-.`||t.kind===`Identifier`&&(n.text===`(`||n.text===`[`||n.kind===`Operator`&&w(`==`,Bs.has(n.text)?3:4))},M=e=>{if(!Hs.has(e.text))return!0;let t=v(1);return t.kind===`End`||t.kind===`ModuleEnd`||t.kind===`Separator`||w(`,`,1)||w(`)`,1)||t.kind===`Keyword`&&Js.has(t.text)||j(e)},fe=()=>{let e=v(),n=e.kind===`Operator`&&(zs.has(e.text)||Vs.has(e.text))&&M(e);if(t&&e.kind!==`String`&&(Vs.has(e.text)||Ws.has(e.text)&&e.text!==`'`&&!Bs.has(e.text)||Us.has(e.text)&&v(-1).text===`(`&&v(-1).line===e.line&&v(-1).endColumn+1===e.column&&v(1).text===`)`&&v(1).line===e.line&&v(1).column===e.endColumn+1)&&M(e))throw S(`incomplete expression`,e);if(n)return r.index++,g({kind:`OperatorReference`,operator:e.text,location:d(e)},r.index-1);if(e.kind!==`String`&&Ws.has(e.text)&&M(e)){r.index++;let t=d(e);if(Bs.has(e.text))return{kind:`OperatorReference`,operator:e.text,location:t};let n={kind:`Identifier`,name:`argument`,location:t};return{kind:`Lambda`,params:[n.name],body:Ks(e.text,n,t),location:t}}if(w(`LAMBDA`)){let t=r.index;T();let n=k(O);D(`:`);let i=N();return g({kind:`Lambda`,params:n,body:i,location:d(e)},t)}return N()},pe=()=>se(()=>{D(`(`);let e=k(fe);return D(`)`),e}),me=()=>{let e=T();r.offsideColumns.push(e.column);let t=[N()];for(;_().text===e.text&&_().column===e.column;)r.index++,t.push(N());return r.offsideColumns.pop(),{kind:e.text===`/\\`?`And`:`Or`,operands:t,isBulleted:!0,location:d(e)}},he=e=>se(()=>{let t=d(e);if(v().kind===`Identifier`&&(w(`|->`,1)||w(`:`,1))){let e=w(`|->`,1)?`Record`:`RecordSet`,n=k(()=>{let t=O();return D(e===`Record`?`|->`:`:`),{name:t,value:N()}});return D(`]`),{kind:e,fields:n,location:t}}if(ce()){let e=de();D(`|->`);let n=N();return D(`]`),{kind:`FunctionConstruction`,bounds:e,body:n,location:t}}let n=N();if(E(`->`)){let e=N();return D(`]`),{kind:`FunctionSet`,domain:n,range:e,location:t}}if(E(`EXCEPT`)){let e=k(()=>{D(`!`);let e=[];for(;w(`.`)||w(`[`);)if(E(`.`)){if(!ae(v()))throw C(`Expected a field name but found ${y(v())}`);e.push({kind:`Field`,name:T().text})}else D(`[`),e.push({kind:`Index`,args:k(()=>N())}),D(`]`);return D(`=`),{path:e,value:N()}});return D(`]`),{kind:`Except`,function:n,updates:e,location:t}}return D(`]_`),{kind:`BoxAction`,action:n,subscript:A(),location:t}}),ge=e=>se(()=>{let t=d(e);if(E(`}`))return{kind:`SetEnumeration`,elements:[],location:t};if(ce()&&(v(1).text===`\\in`||w(`<<`))){let e=r.index,n=ue();D(`\\in`);let i=N();if(E(`:`)){let e=N();return D(`}`),{kind:`SetFilter`,bound:{pattern:n,set:i},predicate:e,location:t}}r.index=e}let n=N();if(E(`:`)){let e=de();return D(`}`),{kind:`SetMap`,expression:n,bounds:e,location:t}}let i=[n];for(;E(`,`);)i.push(N());return D(`}`),{kind:`SetEnumeration`,elements:i,location:t}}),_e=e=>{let t=d(e),n=se(()=>w(`>>`)||w(`>>_`)?[]:k(()=>N()));if(E(`>>_`)){if(n.length!==1)throw S(`Expected a single action inside <<A>>_v`,e);return{kind:`AngleAction`,action:n[0],subscript:A(),location:t}}return D(`>>`),{kind:`Tuple`,elements:n,location:t}},ve=e=>{let t=d(e),n=e.text===`\\A`?`Forall`:`Exists`,r=e.text===`\\AA`||e.text===`\\EE`;if(!r&&ce()){let e=de();return D(`:`),{kind:n,bounds:e,body:N(),location:t}}let i=k(O);return D(`:`),{kind:`UnboundedQuantifier`,quantifier:e.text===`\\A`||e.text===`\\AA`?`Forall`:`Exists`,names:i,body:N(),isTemporal:r,location:t}},ye=e=>{let t=[];do{if(E(`OTHER`))return D(`->`),{kind:`Case`,arms:t,other:N(),location:d(e)};let n=N();D(`->`),t.push({condition:n,body:N()})}while(E(`[]`));return{kind:`Case`,arms:t,other:void 0,location:d(e)}},be=()=>{let e=v(1);return w(`!`)&&(e.kind===`Identifier`||e.kind===`Number`||qs.has(e.text)||e.kind===`Operator`&&(zs.has(e.text)||Bs.has(e.text)||Vs.has(e.text)))},xe=()=>{let e=T();if(e.kind===`Number`)return{kind:`Operand`,operand:ne(e.text)};switch(e.text){case`<<`:case`>>`:return{kind:`Operand`,operand:e.text};case`:`:return{kind:`Colon`};case`@`:return{kind:`At`};case`(`:return r.index--,{kind:`Bound`,args:pe()}}return{kind:`Name`,name:e.text,args:w(`(`)?pe():[]}},Se=()=>{let e=r.index===s.index,n=T(),a=d(n);if(t&&n.kind===`Keyword`&&n.text===`LAMBDA`){let e=k(O);return D(`:`),{kind:`Lambda`,params:e,body:N(),location:a}}if(n.kind===`Number`){if(t&&/^\\[BOH]/.test(n.text))throw S(`incomplete expression`,n);return{kind:`Number`,value:ne(n.text),text:n.text,location:a}}if(n.kind===`Decimal`)return{kind:`Decimal`,text:n.text,location:a};if(n.kind===`String`)return{kind:`String`,value:n.text,location:a};let o=n.kind===`Step`&&Fe(n);if(o&&I()<0&&Me.length<=1)throw S(`Step number used outside proof`,n);if(o&&n.text[1]===`+`)throw S(`<+> step number used in an expression`,n);if(n.kind===`Identifier`||o){let r=o?L(n)??n.text:n.text;if(le()){let e=E(`(`)?k(O):[];return e.length>0&&D(`)`),D(`::`),{kind:`Label`,name:r,params:e,body:N(),location:a}}let i=w(`(`),s=i?pe():[];if(!be())return i?{kind:`Apply`,operator:r,args:s,location:a}:{kind:`Identifier`,name:r,location:a};let c=l.flatMap(e=>e.instances).find(e=>e.name===r);if(c&&!e&&!t&&c.params.length!==s.length)throw S(`The operator ${r} requires ${c.params.length} arguments`,n);let u=[{kind:`Name`,name:r,args:s}];for(;be();)T(),u.push(xe());let d=u.flatMap(e=>e.kind===`Name`?[e.name]:[]);if(d.length<u.length)return{kind:`Subexpression`,selectors:u,location:a};let f=d.join(`!`),p=u.flatMap(e=>`args`in e?e.args:[]);if(p.length===0)return{kind:`Identifier`,name:f,location:a};let m=u.map(e=>`args`in e?e.args.length:0);return m.slice(0,-1).some(e=>e>0)?{kind:`Apply`,operator:f,args:p,argumentCounts:m,location:a}:{kind:`Apply`,operator:f,args:p,location:a}}if(n.kind===`Operator`&&Gs(n.text)&&w(`(`))return{kind:`Apply`,operator:n.text,args:pe(),location:a};switch(n.text){case`(`:{let e=se(()=>N());return D(`)`),e}case`[`:return he(n);case`{`:return ge(n);case`<<`:return _e(n);case`@`:return{kind:`ExceptAt`,location:a};case`\\A`:case`\\E`:case`\\AA`:case`\\EE`:return ve(n);case`IF`:{let e=N();D(`THEN`);let t=N();return D(`ELSE`),{kind:`If`,condition:e,consequent:t,alternative:N(),location:a}}case`CASE`:return ye(n);case`LET`:{let e=[],n=[];for(i.push(/* @__PURE__ */ new Set);!E(`IN`);){if(t&&w(`RECURSIVE`))throw S(`Unexpected keyword RECURSIVE`,b(_()));if(E(`RECURSIVE`)){ke();continue}let r=P(!1);r.kind===`Instance`?n.push(r):e.push(r)}i.pop();let r=N();return n.length===0?{kind:`Let`,definitions:e,body:r,location:a}:{kind:`Let`,definitions:e,instances:n,body:r,location:a}}case`CHOOSE`:{let e=ue(),t=E(`\\in`)?N():void 0;return D(`:`),{kind:`Choose`,pattern:e,set:t,body:N(),location:a}}case`WF_`:case`SF_`:{let e=A(),t=se(()=>{D(`(`);let e=N();return D(`)`),e});return{kind:n.text===`WF_`?`WeakFairness`:`StrongFairness`,subscript:e,action:t,location:a}}}throw C(`Unexpected ${y(n)}`,n)},Ce=()=>{let e=v(),t=d(e);if(e.kind===`Operator`&&(e.text===`/\\`||e.text===`\\/`))return me();if(e.kind===`Operator`||e.kind===`Keyword`)switch(e.text){case`~`:return T(),{kind:`Apply`,operator:`~`,args:[N(5)],location:t};case`-`:return T(),{kind:`Apply`,operator:`-.`,args:[N(13)],location:t};case`[]`:return T(),{kind:`Always`,expression:N(16),location:t};case`<>`:return T(),{kind:`Eventually`,expression:N(16),location:t};case`ENABLED`:return T(),{kind:`Enabled`,expression:N(16),location:t};case`UNCHANGED`:return T(),{kind:`Unchanged`,expression:N(16),location:t};case`SUBSET`:case`UNION`:case`DOMAIN`:return T(),{kind:`Apply`,operator:e.text,args:[N(9)],location:t}}return Se()},N=(e=0)=>{let t=r.index,n=Ce(),i={left:n.location.range?n:g(n,t),previous:void 0};for(;;){let n=v();if(n.kind!==`Operator`)break;let r=d(n);if(n.text===`'`&&e<=15){T(),i.left=g({kind:`Prime`,expression:i.left,location:r},t);continue}if(Bs.has(n.text)&&e<=15){T(),i.left=g({kind:`Apply`,operator:n.text,args:[i.left],location:r},t);continue}if(n.text===`[`){T();let e=se(()=>k(()=>N()));se(()=>D(`]`)),i.left=g({kind:`FunctionApplication`,function:i.left,args:e,location:r},t);continue}if(n.text===`.`&&ae(v(1))){T();let e=T().text;i.left=g({kind:`FieldAccess`,record:i.left,field:e,location:r},t);continue}let a=zs.get(n.text);if(!a||a.low<e)break;let o=i.previous;if(o){let e=!(o.low>a.high||o.high<a.low),t=o.text===n.text&&a.isAssociative;if(e&&!t&&(o.text!==`\\X`||n.text!==`\\X`))throw S(`Precedence conflict between ${o.text} and ${n.text}`,n)}if(T(),a.low>12&&w(`-`))throw S(`Precedence conflict between ${n.text} and -`,v());let s=N(a.high+1),c=i.left;if(n.text===`/\\`||n.text===`\\/`){let e=n.text===`/\\`?`And`:`Or`;i.left=c.kind===e&&o?.text===n.text?{...c,operands:[...c.operands,s]}:{kind:e,operands:[c,s],location:r}}else i.left=n.text===`\\X`?c.kind===`Product`&&o?.text===`\\X`?{...c,factors:[...c.factors,s]}:{kind:`Product`,factors:[c,s],location:r}:{kind:`Apply`,operator:n.text,args:[c,s],location:r};i.left=g(i.left,t),i.previous={...a,text:n.text}}return i.left},we=()=>{if(!E(`(`))return[];let e=F();return D(`)`),e},Te=()=>{let e=d(v()),t=N(),i=n[r.index-1],a={line:i.line,column:i.endColumn};return{body:t,bodyRange:{module:l[l.length-1].name,start:e,end:a}}},P=e=>{let t=r.index;return g(Ee(e),t)},Ee=e=>{let t=v(),n=d(t),i=(t,r)=>({kind:`Operator`,name:t,params:r,...Te(),isLocal:e,isRecursive:u(t),location:n});if(t.kind===`Identifier`&&v(1).kind===`Operator`&&zs.has(v(1).text)&&v(2).kind===`Identifier`&&w(`==`,3)){let e=O(),t=T().text,n=O();return D(`==`),i(t,[{name:e,arity:0},{name:n,arity:0}])}let a=t.kind===`Operator`&&t.text===`-.`,o=t.kind===`Identifier`&&Bs.has(v(1).text)&&w(`==`,2);if(a||o){let e=a?t.text:v(1).text;r.index+=a?1:2;let n=a?O():t.text;return D(`==`),i(e,[{name:n,arity:0}])}let s=O();if(E(`[`)){let t=se(()=>de());return D(`]`),D(`==`),{kind:`Function`,name:s,bounds:t,body:N(),isLocal:e,isRecursive:u(s),location:n}}let c=r.index,l=we();return D(`==`),w(`INSTANCE`)?{...De(s,l,e,n),definitionRange:h(c)}:i(s,l)},De=(e,t,n,i)=>{let a=r.index;return D(`INSTANCE`),{kind:`Instance`,name:e,params:t,module:O(),substitutions:E(`WITH`)?k(()=>{let e=T().text;return D(`<-`),{name:e,expression:fe()}}):[],isLocal:n,location:i,instanceRange:h(a)}},Oe=()=>{let e=d(v());if(w(`_`)&&v(1).kind===`Operator`)return T(),{name:T().text,arity:E(`_`)?2:1,location:e};if(v().kind===`Operator`&&w(`_`,1)){let t=T().text;return T(),{name:t===`-`?`-.`:t,arity:1,location:e}}let t=O();if(!E(`(`))return{name:t,arity:0,location:e};let n=k(()=>D(`_`));return D(`)`),{name:t,arity:n.length,location:e}},F=()=>k(Oe),ke=()=>{let e=F();return e.forEach(e=>i[i.length-1].add(e.name)),e},Ae=e=>{let t={value:0,offset:e};do{let e=v(t.offset);if(e.kind===`End`)return t.offset;e.kind===`Operator`&&rc.has(e.text)&&t.value++,e.kind===`Operator`&&ic.has(e.text)&&t.value--,t.offset++}while(t.value>0);return t.offset},je=()=>{let e=v(),t=v(1);return e.kind===`Identifier`?w(`(`,1)||w(`[`,1)?w(`==`,Ae(1)):t.kind===`Operator`&&Bs.has(t.text)?w(`==`,2):t.kind===`Operator`&&zs.has(t.text)?v(2).kind===`Identifier`&&w(`==`,3):w(`==`,1):w(`-.`)&&t.kind===`Identifier`&&w(`==`,2)},Me=[],I=()=>Me[Me.length-1]??-1,Ne=e=>e.text[1]===`*`?-1:e.text[1]===`+`?-2:Number(e.text.slice(1,e.text.indexOf(`>`))),Pe=e=>{let t=e.text.slice(e.text.indexOf(`>`)+1),n={value:t.length};for(;t[n.value-1]===`.`;)n.value--;return t.slice(0,n.value)},Fe=e=>!e.text.endsWith(`.`)&&!$s.has(Pe(e)),L=e=>{let t=Pe(e);if($s.has(t))return;let n=Ne(e);if(n>=0)return`<${n}>${t}`;let r=I(),i=Me[Me.length-2];return`<${r<0&&i!==void 0?i:r}>${t}`},Ie=e=>{if(e.kind===`Keyword`)return Xs.has(e.text);if(e.kind!==`Step`)return!1;if(e.text[1]===`*`)return Me.length===0;if(e.text[1]===`+`||Me.length===0)return!0;let t=I();return t>=0&&Ne(e)>t},Le=e=>{let t=Ne(e),n=Me.length-1,r=Me[n-1]??-1,i=Me[n]<0;return i&&(Me[n]=t<0?r+1:t),t===-1?!0:t===-2?i:i?t>r:Me[n]===t},Re=e=>!a.has(e)&&l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)||t.definitions.some(t=>t.name===e)),ze=e=>e.kind===`ModuleFact`||e.kind===`Subexpression`?!0:e.kind===`Apply`?e.operator.includes(`!`):e.kind===`Identifier`?e.name.startsWith(`<`)||e.name.includes(`!`)?!0:!ac.has(e.name)&&!Re(e.name):!1,Be=()=>{let e=v();return e.kind===`Step`?Fe(e):e.kind===`Keyword`?ec.has(e.text):e.kind===`End`||e.kind===`ModuleEnd`||e.kind===`Separator`?!1:!je()},Ve=()=>{let e=r.index;s.index=e;let t=v();return t.kind===`Operator`&&!Hs.has(t.text)&&Gs(t.text)?(r.index++,g({kind:`OperatorReference`,operator:t.text,location:d(t)},e)):E(`MODULE`)?g({kind:`ModuleFact`,name:O(),location:d(t)},e):N()},He=e=>o[o.length-1]?.add(e),Ue=e=>{o.push(/* @__PURE__ */ new Set);let t=e();return o.pop(),t},We=e=>o.some(t=>t.has(e))||l.some(t=>t.constants.some(t=>t.name===e)||t.variables.some(t=>t.name===e)),Ge=()=>{let e=r.index,t=v(),n=k(()=>{let e=v();if((e.kind!==`Identifier`||te(e))&&e.kind!==`Operator`)throw C(`Expected a definition name but found ${y(e)}`,e);return r.index++,e.text},`!`),i=d(t);return g(n.length===1&&t.kind===`Operator`?{kind:`OperatorReference`,operator:t.text,location:i}:{kind:`Identifier`,name:n.join(`!`),location:i},e)},Ke=()=>{if(t)return k(Ge);let e=k(Ve),n=e.find(e=>e.kind===`Identifier`&&We(e.name));if(n)throw S(`DEF clause entry should describe a defined operator`,n.location);return e},qe=()=>({facts:Be()?k(Ve):[],defs:E(`DEF`)||E(`DEFS`)?Ke():[]}),Je=()=>{let e=r.index,n=T(),i=n.text===`USE`&&E(`ONLY`),a=h(e),o={kind:n.text===`USE`?`Use`:`Hide`,isOnly:i,...qe(),keyword:a,location:d(n)},s=o.kind===`Hide`&&!t?o.facts.find(e=>!ze(e)):void 0;if(s)throw S(`The only expression allowed as a fact in a HIDE is the name of a theorem, assumption, or step`,s.location);return g(o,e)},Ye=()=>{let e=r.index,t=d(v()),n=E(`NEW`),i=v().kind===`Keyword`?tc.get(v().text):void 0;if(!n&&i===void 0)throw C(`Expected a declaration but found ${y(v())}`);if(i!==void 0&&T(),i===`Variable`){let n=O();return He(n),g({kind:`NewSymbol`,name:n,arity:0,level:i,set:void 0,location:t},e)}let a=Oe();He(a.name);let o=(i??`Constant`)===`Constant`&&w(`\\in`);if(o&&a.arity>0)throw S(`declared symbol with arguments before \\in`);return o&&T(),g({kind:`NewSymbol`,name:a.name,arity:a.arity,level:i??`Constant`,set:o?N():void 0,location:t},e)},Xe=()=>{let e=r.index,t=d(D(`ASSUME`)),n=k(()=>w(`ASSUME`)?Ue(Xe):v().kind===`Keyword`&&nc.has(v().text)?Ye():N());return D(`PROVE`),g({kind:`AssumeProve`,assumptions:n,conclusion:N(),location:t},e)},Ze=e=>{let t={value:0};for(;v(t.value).kind===`Identifier`&&w(`,`,t.value+1);)t.value+=2;return v(t.value).kind===`Identifier`&&w(e,t.value+1)},Qe=(e,t)=>{e.forEach(He),t.forEach(e=>(e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names).forEach(He))},$e=()=>{let e=v();if(w(`USE`)||w(`HIDE`))return Je();if(w(`INSTANCE`))return g(De(void 0,[],!1,d(e)),r.index);if(w(`DEFINE`)||je()){let t=r.index;E(`DEFINE`);let n=[P(!1)];for(;je();)n.push(P(!1));let i={kind:`Define`,definitions:n,location:d(e)};return g(i,t)}if(E(`HAVE`))return{kind:`Have`,expression:N()};if(E(`TAKE`)){let e=ce(),t=e?[]:k(O),n=e?de():[];return Qe(t,n),{kind:`Take`,names:t,bounds:n}}if(E(`WITNESS`))return{kind:`Witness`,expressions:k(()=>N())};if(E(`PICK`)){let e=Ze(`:`),t=e?k(O):[],n=e?[]:de();return Qe(t,n),D(`:`),{kind:`Pick`,names:t,bounds:n,body:N()}}return E(`CASE`)?{kind:`Case`,expression:N()}:{kind:`Assert`,isSuffices:E(`SUFFICES`),statement:w(`ASSUME`)?Xe():N()}},et=e=>{let t=v();if(t.kind!==`Step`)throw C(`Expected a step number but found ${y(t)}`,t);if(!Le(t))throw S(`${e?`QED step`:`step`}'s number has bad level`,t);if(Ne(t)<0&&L(t)!==void 0)throw S(`<*> and <+> cannot be used for a named step`,t);return r.index++,{name:L(t),token:t.text,location:d(t)}},tt=()=>{let e=r.index,t=et(w(`QED`,1)),n=/* @__PURE__ */ new Set;o.push(n);let i=E(`QED`)?{kind:`Qed`}:$e(),a=h(e),s=Ie(v());if(s&&!Zs.has(i.kind))throw S(`Proof of a step that does not take a proof`);let c=s?rt():void 0;return o.pop(),(i.kind!==`Assert`||i.isSuffices)&&n.forEach(He),g({...t,body:i,head:a,proof:c},e)},nt=()=>{let e=d(v());if(w(`BY`)||w(`PROOF`)&&w(`BY`,1)){E(`PROOF`),T();let t=h(r.index-1);return{kind:`By`,isOnly:E(`ONLY`),...qe(),keyword:t,location:e}}let t=v(+!!w(`PROOF`));if(t.kind===`Keyword`&&(t.text===`OBVIOUS`||t.text===`OMITTED`)){E(`PROOF`),T();let n=h(r.index-1);return{kind:t.text===`OBVIOUS`?`Obvious`:`Omitted`,keyword:n,location:e}}E(`PROOF`);let n=[tt()];for(;n[n.length-1].body.kind!==`Qed`;)n.push(tt());return{kind:`Steps`,level:I(),steps:n,location:e}},rt=()=>{let e=r.index;Me.push(-1);let t=Ue(nt);return Me.pop(),g(t,e)},it=e=>{let t=r.index,n=T(),i=v().kind===`Identifier`&&w(`==`,1)?O():void 0;i!==void 0&&(a.add(i),T());let o=Ue(()=>({statement:w(`ASSUME`)?Xe():N(),proof:Ie(v())?rt():void 0})),s=o.statement,c=g({name:i,statement:s,proof:o.proof,location:d(n)},t);e.theorems.push(c),e.units.push({kind:`Theorem`,theorem:c}),i!==void 0&&s.kind!==`AssumeProve`&&e.definitions.push(g({kind:`Operator`,name:i,params:[],body:s,isLocal:!1,isRecursive:!1,location:d(n)},t))},at=()=>{let e=r.index;return g(ot(),e)},ot=()=>{let e=T(),t=d(e),n=e.text===`AXIOM`;if(v().kind===`Identifier`&&w(`==`,1)){let e=O();return a.add(e),T(),{name:e,expression:N(),isAxiom:n,location:t}}return{name:void 0,expression:N(),isAxiom:n,location:t}},st=()=>{let e=d(D(`----`));D(`MODULE`);let t=O();D(`----`);let n={name:t,modules:[],extends:[],extendsRanges:[],constants:[],variables:[],definitions:[],instances:[],assumptions:[],location:e,theorems:[],uses:[],units:[]};for(l.push(n),i.push(/* @__PURE__ */ new Set),E(`EXTENDS`)&&k(()=>{let e=r.index;n.extends.push(O()),n.extendsRanges.push(h(e))});;){let a=r.index;ee.index=a;let o=v();if(o.kind===`ModuleEnd`||o.kind===`End`)return o.kind===`ModuleEnd`&&(e.range={module:t,start:{line:e.line,column:e.column},end:{line:o.line,column:o.endColumn}}),l.pop(),i.pop(),n;if(o.kind===`Separator`){if(w(`MODULE`,1)){let e=st();n.modules.push(e),n.units.push({kind:`Module`,module:e}),D(`====`);continue}T()}else{switch(o.text){case`CONSTANT`:case`CONSTANTS`:{T();let e=F();n.constants.push(...e),n.units.push({kind:`Constants`,declarations:e});continue}case`VARIABLE`:case`VARIABLES`:{T();let e=k(()=>{let e=r.index,t=d(v());return g({name:O(),arity:0,location:t},e)});n.variables.push(...e),n.units.push({kind:`Variables`,declarations:e});continue}case`ASSUME`:case`ASSUMPTION`:case`AXIOM`:{let e=at();n.assumptions.push(e),n.units.push({kind:`Assumption`,assumption:e}),e.name!==void 0&&n.definitions.push({kind:`Operator`,name:e.name,params:[],body:e.expression,isLocal:!1,isRecursive:!1,location:e.location});continue}case`USE`:case`HIDE`:{let e=Je();n.uses.push(e),n.units.push({kind:`Use`,use:e});continue}case`RECURSIVE`:T(),n.units.push({kind:`Recursive`,declarations:ke()});continue;case`INSTANCE`:ct(n,g(De(void 0,[],!1,d(o)),a));continue;case`LOCAL`:if(T(),w(`INSTANCE`)){ct(n,g(De(void 0,[],!0,d(o)),a));continue}ct(n,P(!0));continue}o.kind===`Keyword`&&Ys.has(o.text)?it(n):ct(n,P(!1))}}},ct=(e,t)=>{t.kind===`Instance`?(e.instances.push(t),e.units.push({kind:`Instance`,instance:t})):(e.definitions.push(t),e.units.push({kind:`Definition`,definition:t}))};return st()},lc=e=>cc(e,!1),uc=e=>cc(e,!0),dc=25214903917n,fc=(1n<<48n)-1n,pc=2147483647,mc=e=>{let t={value:(BigInt.asUintN(64,e)^dc)&fc},n=e=>(t.value=t.value*dc+11n&fc,Number(BigInt.asIntN(32,t.value>>BigInt(48-e))));return{setSeed:e=>{t.value=(BigInt.asUintN(64,e)^dc)&fc},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=pc)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},hc=10454148508367108822n,gc=(()=>{let e=[];for(let t=1n<<63n;e.length<72;)e.push(t),t=t>>1n^((t&1n)==0n?0n:hc);return Array.from({length:256},(t,n)=>e.slice(64,72).reverse().reduce((e,t,r)=>n>>r&1?e^t:e,0n))})(),_c=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e>>32n))),vc=Int32Array.from(gc,e=>Number(BigInt.asIntN(32,e))),yc=Number(BigInt.asIntN(32,hc>>32n)),bc=Number(BigInt.asIntN(32,hc));let xc=yc,Sc=bc;const Cc=e=>{let t=(e^Sc)&255;Sc=(Sc>>>8|xc<<24)^vc[t],xc=xc>>>8^_c[t]},wc=e=>{for(let t=0;t<32;t+=8)Cc(e>>>t)},Tc=e=>{if(typeof e==`boolean`)Cc(0),Cc(e?116:102);else if(typeof e==`number`)Cc(1),wc(e);else if(typeof e==`string`){Cc(3),wc(e.length);for(let t=0;t<e.length;t++)Cc(e.charCodeAt(t))}else if(M(e))Cc(21),wc(De(e.name)+1);else if(j(e)){let t=H(e);Cc(9),wc(t.domain.length);for(let e=0;e<t.domain.length;e++)Tc(t.domain[e]),Tc(t.range[e])}else{let t=B(e).elements;Cc(5),wc(t.length);for(let e of t)Tc(e)}},Ec=e=>{let t={high:xc,low:Sc};xc=yc,Sc=bc;for(let t of e)Tc(t);let n=BigInt(xc>>>0)<<32n|BigInt(Sc>>>0);return xc=t.high,Sc=t.low,n},Dc=e=>{if(typeof e==`boolean`)return 2;if(typeof e==`number`||M(e))return 5;if(typeof e==`string`)return 5+e.length;if(j(e)){let t=H(e);return t.domain.reduce((e,n,r)=>e+Dc(n)+Dc(t.range[r]),5)}return B(e).elements.reduce((e,t)=>e+Dc(t),5)},Oc=e=>{let t=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<64;n++){xc=n<32?0:1<<n-32,Sc=n<32?1<<n:0;for(let t=0;t<e;t++)Cc(0);let r=n>>3,i=1<<(n&7);for(let e=i;e<2*i;e++){let n=(r*256+e)*2,a=(r*256+e-i)*2;t[n]=t[a]^xc,t[n+1]=t[a+1]^Sc}}return t},kc=()=>{let e=/* @__PURE__ */ new Map,t=/* @__PURE__ */ new Map,n=[],r=e=>{let r=t.get(e);if(r!==void 0)return r;let i=Dc(e);return xc=0,Sc=0,Tc(e),t.set(e,n.length),n.push(i,xc,Sc),n.length-3},i=t=>{let n=e.get(t);if(n)return n;let r=Oc(t);return e.set(t,r),r};return e=>{let t={high:xc,low:Sc},a={high:yc,low:bc};for(let t of e){let e=r(t),o=i(n[e]),s={high:n[e+1],low:n[e+2]};for(let e=0;e<8;e++){let t=e<4?a.low:a.high,n=(e*256+(t>>>(e&3)*8&255))*2;s.high^=o[n],s.low^=o[n+1]}a.high=s.high,a.low=s.low}return xc=t.high,Sc=t.low,BigInt(a.high>>>0)<<32n|BigInt(a.low>>>0)}},Ac=[],jc=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Mc=()=>{for(let e=1277011;Ac.length<1341;e++)jc(e)&&Ac.push(e);return Ac},Nc=e=>{let t=Mc(),n={index:t.length};for(;n.index===t.length;)n.index=Math.floor(e.nextDouble()*t.length);return t[n.index]},Pc=e=>{let t=[],n={value:e};for(let e=2;e*e<=n.value;e++)for(;n.value%e===0;)t.push(e),n.value/=e;return n.value>1&&t.push(n.value),t},Fc=e=>{for(let t=Math.max(e,9);;t++){let e=Pc(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Ic=(e,t,n)=>{if(t<=0)return[];let r=Fc(t),i={index:BigInt(n.nextInt(t))},a=BigInt(Nc(n));return Array.from({length:e},()=>{do i.index=(r.multiplier*i.index+a)%r.modulus;while(i.index>=t);return i.index})},Lc=(1n<<63n)-1n-24n,Rc=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Lc*BigInt(n)+i)%t;return r<0n?r+t:r})},zc=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Bc=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){let t=Tt(e.domain),n=B(e.range).elements;return{lists:t.map(()=>n),create:e=>L(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>B(e).elements),create:t=>Dt(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>B(e).elements),create:R}}},Vc=(e,t,n)=>{if(V(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ic(e,Math.max(0,t.high-t.low+1),n).map(e=>t.low+Number(e));let r=Bc(t);if(r){let t=r.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(pc)?Rc(e,t,n):Ic(e,Number(t),n)).map(e=>r.create(zc(r.lists,e)))}let i=B(t).elements;return Ic(e,i.length,n).map(e=>i[Number(e)])},Hc=(e,t)=>{let n=e[Math.floor(t.nextDouble()*e.length)];if(n===void 0)throw new u(`RandomElement of the empty set`);return n},Uc=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...Tt(e.domain)];return L(n,n.map(()=>Uc(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Dt(e.names.map((n,r)=>[n,Uc(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return R(e.factors.map(e=>Uc(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.floor(t.nextDouble()*n);if(r>=n)throw new u(`RandomElement of the empty set`);return e.low+r}return Hc(B(e).elements,t)},Wc=(e,t=0n)=>{let n=mc(t),r={random:mc(t),state:void 0},i={isStartup:!1},a={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Dt([]),counterExample:void 0,isSeen:()=>!1,setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Ec,getRandom:()=>{let e=i.isStartup?void 0:a.getCurrentState();return e===void 0?n:(e!==r.state&&(r.random.setSeed(a.getFingerprint(e)^BigInt.asUintN(64,t)),r.state=e),r.random)},evaluateAtStartup:e=>{let t=i.isStartup;i.isStartup=!0;try{return e()}finally{i.isStartup=t}},pause:()=>{},seed:t,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,isStopped:!1,checkDeadlock:e,startedAt:Date.now()};return a},Gc=e=>_t([...e.possibleCounts].map(([e,t])=>[e,t])),Kc=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Gc(e)]]),qc=(e,t,n)=>new d(`Applying ${e} to the following value,\nwhich is not ${t}:\n${U(n)}`),Jc=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${U(r)}`),Yc=e=>j(e)?H(e):void 0,Xc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw qc(n,`a function with a finite domain`,r);return i},Zc=(e,t,n)=>{let r=G(e,t,n),i=Yc(r);if(!i)throw Jc(t===0?`first`:`second`,n,`bag`,r);return i},Qc=(e,t)=>{if(!A(e)||!z(e))throw t();return B(e).elements},$c=e=>e.range.every(e=>typeof e==`number`&&e>0),el=(e,t)=>{let n=e.domain.findIndex(e=>Ie(e,t));return n===-1?void 0:e.range[n]},tl=(e,t,n)=>`public static ${t} tlc2.module.Bags.${e}(${Array.from({length:n},()=>`tlc2.value.impl.Value`).join(`,`)})`,nl=tl(`BagDiff`,`tlc2.value.impl.Value`,2),rl=tl(`SqSubseteq`,`tlc2.value.IBoolValue`,2),il=tl(`BagUnion`,`tlc2.value.impl.Value`,1),al=tl(`BagOfAll`,`tlc2.value.impl.Value`,2),ol=tl(`BagCup`,`tlc2.value.impl.Value`,2),sl=tl(`BagCardinality`,`tlc2.value.impl.IntValue`,1),cl=(e,t)=>{if(typeof e==`number`)return e;let n=`tlc2.value.impl.${$n(e)}`;throw tr(t,`class ${n} cannot be cast to class tlc2.value.impl.IntValue (${n} and tlc2.value.impl.IntValue are in unnamed module of loader 'app')`)},ll=(e,t,n)=>{let r=cl(e,n)+cl(t,n);if(Jn(r))throw Yn(`${e}+${t}`);return r},ul=(e,t,n,r)=>{let i=el(n,e.domain[t]),a=cl(e.range[t],r);return i===void 0?a:a-cl(i,r)|0},dl=(e,t)=>_t(e.reduce((e,n)=>(n.domain.forEach((r,i)=>{let a=e.find(e=>Ie(e[0],r));a?a[1]=ll(a[1],n.range[i],t):e.push([r,n.range[i]])}),e),[])),fl=L([],[]),pl=[Wn(`EmptyBag`,fl),K(`IsABag`,1,e=>{let t=Yc(G(e,0,`IsABag`));return t!==void 0&&$c(t)}),K(`BagCardinality`,1,e=>{let t=G(e,0,`BagCardinality`);return Xc(e,0,`BagCardinality`).range.reduce((e,n)=>{if(typeof n!=`number`||n<=0)throw qc(`BagCardinality`,`a bag`,t);return ll(e,n,sl)},0)}),K(`BagIn`,2,e=>{let t=G(e,1,`BagIn`),n=el(Xc(e,1,`BagIn`),G(e,0,`BagIn`));if(n===void 0)return!1;if(typeof n!=`number`)throw Jc(`second`,`BagIn`,`bag`,t);return n>0}),K(`CopiesIn`,2,e=>{let t=G(e,1,`CopiesIn`),n=el(Xc(e,1,`CopiesIn`),G(e,0,`CopiesIn`));if(n===void 0)return 0;if(typeof n!=`number`)throw Jc(`second`,`CopiesIn`,`bag`,t);return n}),K(`\\oplus`,2,e=>{let t=[0,1].map(t=>{let n=Zc(e,t,`(+)`);if(!$c(n))throw Jc(t===0?`first`:`second`,`(+)`,`bag`,G(e,t,`(+)`));return n});return dl(t,ol)}),K(`\\ominus`,2,e=>{let t=Zc(e,0,`(-)`),n=Zc(e,1,`(-)`);return _t(t.domain.flatMap((e,r)=>{let i=ul(t,r,n,nl);return i>0?[[e,i]]:[]}))}),K(`BagUnion`,1,e=>{let t=G(e,0,`BagUnion`),n=Qc(t,()=>qc(`BagUnion`,`a finite enumerable set`,t));if(n.length<2)return n[0]??fl;let r=n.map(e=>{let n=Yc(e);if(!n)throw new d(`Attempted to apply BagUnion to the following set, whose\nelement is not a bag:\n${U(t)}`);return n});return dl(r,il)}),K(`\\sqsubseteq`,2,e=>{let t=Xc(e,0,`\\sqsubseteq`),n=Xc(e,1,`\\sqsubseteq`);return t.domain.every((e,r)=>ul(t,r,n,rl)<=0)}),Gn(`BagOfAll`,2,e=>{let t=Un(e,0,`BagOfAll`);if(t.literalBody!==void 0)throw new d(`The first argument of BagOfAll should be an operator, but instead it is:\n${U(t.literalBody)}`);let n=G(e,1,`BagOfAll`),r=Yc(n);if(!r)throw Jc(`second`,`BagOfAll`,`function with a finite domain`,n);return dl(r.domain.map((e,n)=>L([t.call([e])],[r.range[n]])),al)}),K(`SubBag`,1,e=>{let t=G(e,0,`SubBag`);if(!j(t))throw new u(`DOMAIN expects a function but received ${U(t)}`);let n=H(t),r=dt(n.range).elements,i=r.find(e=>typeof e!=`number`);if(i!==void 0){let e=typeof r[0]!=`number`;throw new u(`The ${e?`first`:`second`} argument of >= should be an integer, but instead it is:\n${U(e?r[0]:i)}`)}let a=n.range.filter(e=>typeof e==`number`);if(a.some(e=>e<1))throw new u(`Attempted to apply a function to ${U(n)}, which is not in its domain`);return dt(n.domain.reduce((e,t,n)=>e.flatMap(e=>[e,...Array.from({length:a[n]},(n,r)=>[...e,[t,r+1]])]),[[]]).map(e=>L(e.map(e=>e[0]),e.map(e=>e[1]))))}),K(`BagToSet`,1,e=>nn(Xc(e,0,`BagToSet`))),K(`SetToBag`,1,e=>{let t=G(e,0,`SetToBag`),n=Qc(t,()=>qc(`BagToSet`,`a function with a finite domain`,t));return L([...n],n.map(()=>1))})],ml=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonArray(tlc2.value.IValue) throws java.io.IOException`,hl=`public static tlc2.value.impl.StringValue tlc2.module.Json.toJsonObject(tlc2.value.IValue) throws java.io.IOException`,gl=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.serialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,_l=`public static synchronized tlc2.value.impl.BoolValue tlc2.module.Json.ndSerialize(tlc2.value.impl.StringValue,tlc2.value.impl.Value) throws java.io.IOException`,vl=`public static tlc2.value.IValue tlc2.module.Json.deserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,yl=`public static tlc2.value.IValue tlc2.module.Json.ndDeserialize(tlc2.value.impl.StringValue) throws java.io.IOException`,bl=e=>{if(!j(e))return!1;let t=H(e).domain;return t.length>0&&t.every(e=>typeof e==`string`)},xl=(e,t)=>tr(e,`Cannot convert value: unsupported value type tlc2.value.impl.${$n(t)}`),Sl=(e,t)=>tr(e,`Cannot cast tlc2.value.impl.${$n(t)} to tlc2.value.impl.StringValue`),Cl=e=>JSON.stringify(e).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`),wl=(e,t)=>{if(typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`))throw xl(t,e);return`[${B(e).elements.map(e=>El(e,t)).join(`,`)}]`},Tl=(e,t)=>{let n=H(e),r=Gt(n);return r?`[${r.map(e=>El(e,t)).join(`,`)}]`:`{${n.domain.map((e,r)=>`${Cl(typeof e==`string`?e:U(e))}:${El(n.range[r],t)}`).join(`,`)}}`},El=(e,t)=>typeof e==`string`?Cl(e):typeof e==`object`?e.kind===`ModelValue`?Cl(e.name):A(e)?wl(e,t):Tl(e,t):String(e),Dl=e=>{if(A(e))return wl(e,ml);if(!j(e)||bl(e))throw xl(ml,e);return Tl(e,ml)},Ol=e=>{if(!j(e))throw xl(hl,e);return Tl(e,hl)},kl=e=>{let[,t,n=`0`,r=``,i=`0`]=/^(-?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(e)??[],a=BigInt(n+r),o=Number(i)-r.length,s=o>=0?a*10n**BigInt(o):a/10n**BigInt(-o);return Number(BigInt.asIntN(32,t===`-`?-s:s))},Al=(e,t)=>{if(typeof e==`boolean`||typeof e==`number`)return e;if(typeof e==`string`)return P(e);if(Array.isArray(e))return R(e.map(e=>Al(e,t)));if(typeof e==`object`&&e)return Dt(Object.entries(e).map(([e,n])=>[P(e),Al(n,t)]));throw tr(t,`Cannot convert value: unsupported JSON value ${String(e)}`)},jl=(e,t)=>{if(e.trim()===``)return Al(null,t);try{return Al(JSON.parse(e,(e,t,n)=>typeof t==`number`?kl(n?.source??String(t)):t),t)}catch(e){throw e instanceof SyntaxError?tr(t,e.message):e}},Ml=(e,t)=>{if(typeof e!=`string`)throw Sl(t,e);return e},Nl=(e,t,n)=>{let r=e.readFile?.(t);if(r===void 0)throw tr(n,`${t} (No such file or directory)`);return r},Pl=e=>[Kn(`ToJson`,1,e=>P(El(G(e,0,`ToJson`),`public static tlc2.value.impl.StringValue tlc2.module.Json.toJson(tlc2.value.IValue) throws java.io.IOException`))),Kn(`ToJsonArray`,1,e=>P(Dl(G(e,0,`ToJsonArray`)))),Kn(`ToJsonObject`,1,e=>P(Ol(G(e,0,`ToJsonObject`)))),Kn(`JsonSerialize`,2,t=>{let n=Ml(G(t,0,`JsonSerialize`),gl),r=G(t,1,`JsonSerialize`);if(!Gt(r)&&!bl(r))throw new d(`The second argument of JsonSerialize should be a sequence or record, but instead it is:\n${U(r)}`);return e.writeFile?.(n,El(r,gl)),!0}),Kn(`ndJsonSerialize`,2,t=>{let n=Ml(G(t,0,`ndJsonSerialize`),_l),r=G(t,1,`ndJsonSerialize`),i=Gt(r);if(!i)throw new d(`The second argument of ndJsonSerialize should be a sequence, but instead it is:\n${U(r)}`);return e.writeFile?.(n,i.map(e=>`${El(e,_l)}\n`).join(``)),!0}),Kn(`JsonDeserialize`,1,t=>{let n=Ml(G(t,0,`JsonDeserialize`),vl);return jl(Nl(e,n,vl),vl)}),Kn(`ndJsonDeserialize`,1,t=>{let n=Ml(G(t,0,`ndJsonDeserialize`),yl);return R(Nl(e,n,yl).split(/\r\n|\r|\n/).map(e=>e.trim()).filter(e=>e!==``).map(e=>jl(e,yl)))})],Fl=(e,t,n,r)=>new d(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${r}`),Il=(e,t,n)=>{if(typeof e!=`number`||e<0)throw Fl(t,n,`nonnegative integer`,U(e));return e},Ll=(e,t,n,r)=>{if(!A(e)||!z(e))throw Fl(t,n,r,U(e));return B(e).elements},Rl=(e,t,n,r)=>dt(Array.from({length:t},()=>dt(e.filter(()=>r.nextDouble()<n)))),zl=(e,t)=>{let n=`RandomSetOfSubsets`,r=Il(G(e,0,n),`first`,n),i=Il(G(e,1,n),`second`,n),a=Ll(G(e,2,n),`third`,n,`finite set`);if(a.length<31&&r>2**a.length)throw Fl(`first`,n,`nonnegative integer that is smaller than the subset's size of 2^${a.length}`,String(r));if(a.length<i)throw Fl(`second`,n,`nonnegative integer in range 0..Cardinality(S)`,String(i));return Rl(a,r,a.length===0?0:i/a.length,t.getRandom())},Bl=e=>[Kn(`RandomSubset`,2,t=>{let n=G(t,0,`RandomSubset`);if(typeof n!=`number`)throw Fl(`first`,`RandomSubset`,`nonnegative integer`,U(n));if(n<0)throw new u(`Attempted to apply the operator overridden by the Java method\npublic static tlc2.value.impl.Value tlc2.module.Randomization.RandomSubset(tlc2.value.impl.Value,tlc2.value.impl.Value),\nbut it produced the following error:\n${n}`);let r=G(t,1,`RandomSubset`);if(!A(r)||!V(r)&&!z(r))throw Fl(`second`,`RandomSubset`,`a finite set`,U(r));return dt(Vc(n,r,e.getRandom()))}),Kn(`RandomSetOfSubsets`,3,t=>zl(t,e)),Kn(`TestRandomSetOfSubsets`,3,t=>R(Array.from({length:5},()=>B(zl(t,e)).elements.length)))],Vl=`tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel`,Hl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.assertError(${Vl})`,Ul=`public static tlc2.value.impl.TupleValue tlc2.module.TLCExt.getTrace(${Vl}) throws java.io.IOException`,Wl=`public static synchronized tlc2.value.impl.Value tlc2.module.TLCExt.pickSuccessor(${Vl})`,Gl=()=>Dt([[`action`,dt([])],[`state`,dt([])]]),Kl=()=>Dt([[`beginLine`,0],[`beginColumn`,0],[`endLine`,0],[`endColumn`,0],[`module`,`--TLA+ BUILTINS--`]]),ql=e=>Dt([[`name`,e??`UnnamedAction`],[`location`,Kl()]]),Jl=(e,t)=>{let n=e.map((e,t)=>R([t+1,Dt(Object.entries(e.state))])),r=n.slice(1).map((t,r)=>R([n[r],ql(e[r+1].action),t])),i=t?[R([n[n.length-1],ql(t.action),n[t.start]])]:[];return Dt([[`action`,dt([...r,...i])],[`state`,dt(n)]])},Yl=(e,t)=>{if(typeof t==`number`)return e.registers.get(t);if(typeof t==`string`&&t.startsWith(`s:`))return Kc(e).get(t)},Xl=(e,t,n,r)=>{if(typeof n==`number`&&n>=0)e.registers.set(n,r);else if(n===`exit`)r===!0&&(e.isStopped=!0);else if(n===`pause`){if(r!==!0)return;t(`Press enter to resume model checking.`),e.pause()}else if(typeof n==`string`&&n.startsWith(`s:`))e.namedRegisters.set(n,r);else if(typeof n==`string`&&n.startsWith(`-D`))e.properties.set(n.slice(2),U(r));else throw new d(`The first argument of TLCSet should be a nonnegative integer, but instead it is:\n${U(n)}`)},Zl=e=>e.every(e=>e!==void 0),Ql=(e,t)=>Dt(t.variables.map((t,n)=>[t,e[n]])),$l=(e,t,n)=>{let r=e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0;if(e.kind===`Prime`||e.kind===`Unchanged`)return!0;if(r!==void 0&&!W(e)){if(t.variableIndex.has(r))return!0;let e=qa(r,t);if(e&&!n.has(e)&&(n.add(e),$l(e.body,t,n)))return!0}return jn(e).some(e=>$l(e,t,n))},eu=(e,t)=>{let n=/* @__PURE__ */ new Map,r=/* @__PURE__ */ new WeakMap,i=e=>{let t=r.get(e)??/* @__PURE__ */ new Map;return r.set(e,t),t};return[K(`AssertEq`,2,t=>{let n=G(t,0,`AssertEq`),r=G(t,1,`AssertEq`),i=Ie(n,r);return i||(e(U(`Assertion failed`,!0)),e(U(n,!0)),e(U(r,!0))),i}),cr(`AssertError`,2,e=>{let t=Un(e,0,`AssertError`).expression;if(t&&t.kind!==`String`)throw tr(Hl,`In computing AssertError, a non-string expression (line ${t.location.line}, col ${t.location.column}) was used as the err of an AssertError(err, exp).`);let n=lr(e,0,`AssertError`)();try{lr(e,1,`AssertError`)()}catch(e){if(e instanceof u)return e.message===n;throw e}return!1}),Kn(`TLCGetOrDefault`,2,e=>{let n=G(e,0,`TLCGetOrDefault`);return Yl(t,n)??G(e,1,`TLCGetOrDefault`)}),{...Gn(`TLCGetAndSet`,4,n=>{let r=G(n,0,`TLCGetAndSet`),i=Yl(t,r)??G(n,3,`TLCGetAndSet`),a=Un(n,1,`TLCGetAndSet`);return Xl(t,e,r,a.call([i,G(n,2,`TLCGetAndSet`)])),i}),isStateLevel:!0},Kn(`Trace`,0,(e,n)=>{let r=n?.state;if(!n||!r||!Zl(r)){let e=(n?.environment.variables??[]).filter((e,t)=>r?.[t]===void 0);throw tr(Ul,`In evaluating TLCExt!Trace, the state is not completely specified yet (variable${e.length>1?`s`:``} ${e.join(`, `)} undefined).`)}return R(t.getBehavior(r).map(e=>Ql(e,n.environment)))}),Kn(`CounterExample`,0,()=>t.counterExample??Gl()),K(`ToTrace`,1,e=>{let t=G(e,0,`ToTrace`);if(!j(t)||!Ie(nn(t),dt([`action`,`state`])))throw new u(`The argument of ToTrace should be a CounterExample, but instead it is:\n${U(t)}`);let n=B(en(t,`state`)).elements.map(e=>Gt(e)??[]);return R(n.sort((e,t)=>Number(e[0])-Number(t[0])).map(e=>e[1]))}),K(`TLCModelValue`,1,e=>{let t=G(e,0,`TLCModelValue`);if(typeof t!=`string`)throw new d(`The argument of ModelValue should be a string, but instead it is:\n${U(t)}`);return Pe(t)}),cr(`TLCDefer`,1,()=>!0),K(`TLCNoOp`,1,e=>G(e,0,`TLCNoOp`)),cr(`PickSuccessor`,1,(e,n)=>{let r=n?.next;if(!r||!Zl(r))throw tr(Wl,`Cannot invoke "tlc2.value.IValue.fingerPrint(long)" because "minVals[i]" is null`);if(t.isSeen(r)||Ka(lr(e,0,`PickSuccessor`)(),`the condition of PickSuccessor`))return!0;throw new m(`PickSuccessor needs interactive input to extend the behavior with a new state`)}),cr(`TLCCache`,2,(e,t)=>{let r=Un(e,0,`TLCCache`),a=xn(lr(e,1,`TLCCache`)()),o=r.expression;if(!o||!t)return r.call([]);let s=$l(o,t.environment,/* @__PURE__ */ new Set)&&t.state?i(t.state):n,c=s.get(o)??/* @__PURE__ */ new Map;s.set(o,c);let l=c.get(a);if(l!==void 0)return l;let u=r.call([]);return c.set(a,u),u}),K(`TLCFP`,1,e=>Number(BigInt.asIntN(32,Ec([G(e,0,`TLCFP`)])))),Kn(`TLCEvalDefinition`,1,(e,t)=>{let n=G(e,0,`TLCEvalDefinition`),r=typeof n==`string`&&t?qa(n,t.environment):void 0;if(!r||typeof n!=`string`||!t)throw new d(`The argument of TLCEvalDefinition should be a name of a definition reachable from the root module, but instead it is:\n${U(n)}`);if(r.kind===`Operator`&&r.params.length>0)throw new d(`The argument of TLCEvalDefinition should be a zero-arity definition, but instead it is:\n${n}`);return X({kind:`Identifier`,name:n,location:r.location},t)})]},tu=(e,t)=>[Kn(`_Track`,2,e=>{let n=String(G(e,1,`_Track`)),r=t.possibleCounts.get(n)??0;return t.possibleCounts.set(n,G(e,0,`_Track`)===!0?r+1:r),!0}),Kn(`_Counts`,0,()=>Gc(t)),Kn(`_CheckName`,1,n=>{let r=String(G(n,0,`_CheckName`));return t.possibleCounts.get(r)?!0:(e(U(Gc(t),!0)),!1)}),Kn(`_PrintCounts`,0,()=>(e(U(Gc(t),!0)),!0))],nu=e=>String(e).padStart(2,`0`),ru=e=>`${e.getUTCFullYear()}.${nu(e.getUTCMonth()+1)}.${nu(e.getUTCDate())}.${nu(e.getUTCHours())}${nu(e.getUTCMinutes())}${nu(e.getUTCSeconds())}`,iu=e=>_t([...e].map(([e,t])=>[e,R([t])])),au=(e,t,n)=>{let r=Math.floor((Date.now()-e.startedAt)/1e3);switch(t){case`level`:return n===void 0?0:e.getLevel(n);case`diameter`:return e.diameter;case`generated`:return e.generatedStates;case`distinct`:return e.distinctStates;case`queue`:return e.queueSize;case`duration`:return r;case`stats`:return Dt([[`queue`,e.queueSize],[`distinct`,e.distinctStates],[`initial`,e.initialStates],[`generated`,e.generatedStates],[`diameter`,e.diameter],[`duration`,r],[`worker`,0]]);case`config`:return Dt([[`mode`,`bfs`],[`deadlock`,e.checkDeadlock],[`worker`,1],[`seed`,String(e.seed)],[`fingerprint`,`0`],[`install`,`unknown`]]);case`revision`:{let t=/* @__PURE__ */ new Date;return Dt([[`count`,0],[`timestamp`,Math.floor(t.getTime()/1e3)],[`date`,P(`${t.toISOString().slice(0,19)}.${t.getUTCMilliseconds()}Z`)],[`tag`,`development`],[`calver`,P(ru(new Date(e.startedAt)))]])}case`spec`:return e.getSpecification();case`action`:return ql(void 0);case`all`:return iu(e.registers);case`all:named`:return iu(Kc(e))}if(t.startsWith(`s:`)){let n=Kc(e).get(t);if(n===void 0)throw new d(`TLCGet(${t}) was undefined.`);return n}if(t.startsWith(`-D`))return P(e.properties.get(t.slice(2))??t);throw new d(`TLCGet(${t}) was undefined.`)},ou=e=>e.length===0?[[]]:e.flatMap((t,n)=>ou([...e.slice(0,n),...e.slice(n+1)]).map(e=>[t,...e])),su=e=>{typeof e==`object`&&((e.kind===`Set`||e.kind===`MixedSet`)&&B(e).elements.forEach(su),e.kind===`Function`&&e.range.forEach(su))},cu=(t,n)=>[K(`Print`,2,e=>(t(`${de(U(G(e,0,`Print`),!0,!0))} ${de(U(G(e,1,`Print`),!0,!0))}`),G(e,1,`Print`))),K(`PrintT`,1,e=>(t(de(U(G(e,0,`PrintT`),!0,!0))),!0)),K(`Assert`,2,t=>{if(G(t,0,`Assert`)!==!0)throw new d(`The first argument of Assert evaluated to FALSE; the second argument was:\n${de(U(G(t,1,`Assert`)))}`,e.assertViolation);return!0}),K(`JavaTime`,0,()=>Math.floor(Date.now()/1e3)&2147483647),K(`:>`,2,e=>_t([[G(e,0,`:>`),G(e,1,`:>`)]])),K(`@@`,2,e=>{let t=Hn(e,0,`@@`),n=Hn(e,1,`@@`);return vt([...ge(t),...ge(n)])}),K(`ToString`,1,e=>P(U(G(e,0,`ToString`),!0))),K(`TLCEval`,1,e=>{let t=G(e,0,`TLCEval`);return su(t),t}),K(`Permutations`,1,e=>{let t=Bn(e,0,`Permutations`);return dt(ou(t).map(e=>_t(t.map((t,n)=>[t,e[n]]))))}),Gn(`SortSeq`,2,e=>{let t=Un(e,1,`SortSeq`);return R(Vn(e,0,`SortSeq`).reduce((e,n)=>{let r=e.findIndex(e=>t.call([n,e])===!0);return r===-1?[...e,n]:[...e.slice(0,r),n,...e.slice(r)]},[]))}),Kn(`TLCGet`,1,(e,t)=>{let r=G(e,0,`TLCGet`);if(typeof r==`number`&&r>=0){let e=n.registers.get(r);if(e===void 0)throw new d(`TLCGet(${r}) was undefined.`);return e}if(typeof r!=`string`)throw new d(`The argument of TLCGet should be a nonnegative integer, but instead it is:\n${U(r)}`);return au(n,r,t?.state)}),Kn(`TLCSet`,2,e=>{let r=G(e,0,`TLCSet`);return Xl(n,t,r,G(e,1,`TLCSet`)),!0}),Wn(`Any`,je),K(`RandomElement`,1,e=>Uc(Rn(e,0,`RandomElement`),n.getRandom()))],lu=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices`.split(`,`),uu=[[`\\lnot`,`~`,`\\neg`,`¬`],[`[]`,`□`],[`<>`,`◇`],[`\\land`,`/\\`,`∧`],[`\\lor`,`\\/`,`∨`],[`\\equiv`,`<=>`,`≡`,`⇔`],[`/=`,`#`,`≠`],[`\\leq`,`<=`,`=<`,`≤`],[`\\geq`,`>=`,`≥`],[`\\times`,`\\X`,`×`],[`\\intersect`,`\\cap`,`∩`],[`\\union`,`\\cup`,`∪`],[`\\o`,`\\circ`,`∘`],[`\\oplus`,`(+)`,`⊕`],[`\\ominus`,`(-)`,`⊖`],[`\\odot`,`(.)`,`⊙`],[`\\oslash`,`(/)`,`⊘`],[`\\otimes`,`(\\X)`,`⊗`],[`\\approx`,`≈`],[`:=`,`≔`],[`\\asymp`,`≍`],[`\\bigcirc`,`◯`],[`::=`,`⩴`],[`\\bullet`,`●`],[`\\cdot`,`⋅`],[`\\cong`,`≅`],[`\\div`,`÷`],[`\\doteq`,`≐`],[`..`,`‥`],[`...`,`…`],[`!!`,`‼`],[`\\gg`,`≫`],[`=>`,`⇒`],[`\\in`,`∈`],[`=|`,`⫤`],[`~>`,`↝`],[`\\ll`,`≪`],[`-|`,`⊣`],[`\\notin`,`∉`],[`-+->`,`⇸`],[`\\prec`,`≺`],[`\\preceq`,`⪯`],[`\\propto`,`∝`],[`??`,`⁇`],[`|=`,`⊨`],[`|-`,`⊢`],[`\\sim`,`∼`],[`\\simeq`,`≃`],[`\\sqcap`,`⊓`],[`\\sqcup`,`⊔`],[`\\sqsubset`,`⊏`],[`\\sqsubseteq`,`⊑`],[`\\sqsupset`,`⊐`],[`\\sqsupseteq`,`⊒`],[`\\star`,`⋆`],[`\\subset`,`⊂`],[`\\subseteq`,`⊆`],[`\\succ`,`≻`],[`\\succeq`,`⪰`],[`\\supset`,`⊃`],[`\\supseteq`,`⊇`],[`\\uplus`,`⊎`],[`||`,`‖`],[`\\wr`,`≀`],[`^+`,`⁺`]],du=/* @__PURE__ */ `STRING,FALSE,TRUE,BOOLEAN,=,/=,.,',\\lnot,\\neg,\\land,\\lor,\\equiv,=>,SUBSET,UNION,DOMAIN,\\subseteq,\\in,\\notin,\\,\\intersect,\\union,\\times,~>,[],<>,ENABLED,UNCHANGED,\\cdot,-+->,$AngleAct,$BoundedChoose,$BoundedExists,$BoundedForall,$CartesianProd,$Case,$ConjList,$DisjList,$Except,$FcnApply,$FcnConstructor,$IfThenElse,$NonRecursiveFcnSpec,$Pair,$RcdConstructor,$RcdSelect,$RecursiveFcnSpec,$Seq,$SetEnumerate,$SetOfAll,$SetOfFcns,$SetOfRcds,$SF,$SquareAct,$SubsetOf,$TemporalExists,$TemporalForall,$TemporalWhile,$Tuple,$UnboundedChoose,$UnboundedExists,$UnboundedForall,$WF,$Nop,$Qed,$Pfcase,$Have,$Take,$Pick,$Witness,$Suffices,***I do not exist***,--TLA+ BUILTINS--,Formal_0,Formal_1,Formal_2,[,^,/,*,-,-.,+,^+,^*,^#,<,\\leq,>,\\geq,...,..,|,||,&&,&,$$,$,??,%%,%,##,++,--,**,//,^^,@@,!!,|-,|=,-|,=|,<:,:>,:=,::=,\\oplus,\\ominus,\\odot,\\oslash,\\otimes,\\uplus,\\sqcap,\\sqcup,\\div,\\wr,\\star,\\o,\\bigcirc,\\bullet,\\prec,\\succ,\\preceq,\\succeq,\\sim,\\simeq,\\ll,\\gg,\\asymp,\\subset,\\supset,\\supseteq,\\approx,\\cong,\\sqsubset,\\sqsubseteq,\\sqsupset,\\sqsupseteq,\\doteq,\\propto,~,¬,□,◇,/\\,∧,\\/,∨,<=>,≡,⇔,#,≠,<=,=<,≤,>=,≥,\\X,×,\\cap,∩,\\cup,∪,\\circ,∘,(+),⊕,(-),⊖,(.),⊙,(/),⊘,(\\X),⊗,≈,≔,≍,◯,⩴,●,⋅,≅,÷,≐,‥,…,‼,≫,⇒,∈,⫤,↝,≪,⊣,∉,⇸,≺,⪯,∝,⁇,⊨,⊢,∼,≃,⊓,⊔,⊏,⊑,⊐,⊒,⋆,⊂,⊆,≻,⪰,⊃,⊇,⊎,‖,≀,⁺,@`.split(`,`),fu=/* @__PURE__ */ `exit.pause.config.spec.coverage.action.install.id.behavior.all.mode.deadlock.seed.fingerprint.worker.traces.depth.aril.sched.revision.timestamp.date.count.tag.calver.impliedinits.impliedactions.invariants.impliedtemporals.temporals.actions.inits.variables.actionconstraints.constraints.stats.duration.generated.diameter.distinct.initial.queue.retries.distinctvalues.levelmean.levelvariance.bfs`.split(`.`),pu=/* @__PURE__ */ `Not a node.N_ActDecl.N_ActionExpr.N_AssumeDecl.N_AssumeProve.N_Assumption.N_BeginModule.N_Body.N_BoundedQuant.N_Case.N_CaseArm.N_CaseStatement.N_ChooseStatement.N_ConjItem.N_ConjList.N_ConsDecl.N_DisjItem.N_DisjList.N_EndModule.N_Except.N_ExceptComponent.N_ExceptSpec.N_Times.N_Extends.N_FairnessExpr.N_FcnAppl.N_FcnConst.N_FieldSet.N_FieldVal.N_FunctionDefinition.N_FunctionParam.N_GeneralId.N_GenInfixOp.N_GenNonExpPrefixOp.N_GenPostfixOp.N_GenPrefixOp.N_IdentDecl.N_Real.N_IdentifierTuple.N_IdentLHS.N_IdPrefix.N_IdPrefixElement.N_IfThenElse.N_InfixDecl.N_InfixExpr.N_InfixLHS.N_InfixOp.N_InnerProof.N_Instance.N_NonLocalInstance.N_Integer.N_LeafProof.N_LetDefinitions.N_LetIn.N_MaybeBound.N_Module.N_ModuleDefinition.N_NonExpPrefixOp.N_Number.N_NumberedAssumeProve.N_OpApplication.N_OpArgs.N_OperatorDefinition.N_OtherArm.N_ParamDecl.N_ParamDeclaration.N_ParenExpr.N_PostfixDecl.N_PostfixExpr.N_PostfixLHS.N_PostfixOp.N_PrefixDecl.N_PrefixExpr.N_PrefixLHS.N_PrefixOp.N_Proof.N_ProofLet.N_ProofName.N_ProofStatement.N_ProofStep.N_QEDStep.N_QuantBound.N_RcdConstructor.N_RecordComponent.N_SetEnumerate.N_SetOfAll.N_SetOfFcns.N_SetOfRcds.N_String.N_SubsetOf.N_Substitution.N_TempDecl.N_Theorem.N_Tuple.N_UnBoundedOrBoundedChoose.N_UnboundedQuant.N_VariableDeclaration.Token =.Token \\in.N_NewSymb.N_Lambda.N_Recursive.N_Label.N_StructOp.N_NumerableStep.N_TerminalProof.N_UseOrHide.N_NonExprBody.N_DefStep.N_HaveStep.N_TakeStep.N_WitnessStep.N_PickStep.N_CaseStep.N_AssertStep`.split(`.`),mu=/* @__PURE__ */ new Map([[`Naturals`,`-------------------------------- MODULE Naturals ----------------------------
94
94
  Nat == { }
95
95
  a+b == {a, b}
96
96
  a-b == CHOOSE n : b + n = a
@@ -406,8 +406,8 @@ _CheckName(name) ==
406
406
  => (PrintT(counts) /\\ FALSE)
407
407
  _PrintCounts == PrintT(_Counts)
408
408
  =============================================================================
409
- `]]),hu=/* @__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)`],[`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)`]])]]),gu=(e,t)=>e.every(e=>Qt(e,t)),_u=ht([!1,!0]),vu=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return bt(vu(e,t,r),vu(e,r,n))},yu=[`\\cup`,`\\cap`,`\\`],bu=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),xu=e=>typeof e==`object`&&e.kind===`MixedSet`,Su=e=>e.kind===`Interval`?B(e).elements:e.elements,Cu=(e,t,n)=>{let r=Su(t);if(e!==`\\cup`){let t=e===`\\cap`;return gt(r.filter(e=>Qt(e,n)===t))}if(r.length===0)return n;if(!bu(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!Qt(e,t));return gt([...r,...i])},wu=[Jn(`TRUE`,!0),Jn(`FALSE`,!1),Jn(`BOOLEAN`,_u),Jn(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),Zn(`=`,pt),Zn(`#`,(e,t)=>!pt(e,t)),K(`~`,1,e=>!Bn(e,0,`~`)),K(`<=>`,2,e=>Bn(e,0,`<=>`)===Bn(e,1,`<=>`)),K(`/\\`,2,e=>Bn(e,0,`/\\`)&&Bn(e,1,`/\\`)),K(`\\/`,2,e=>Bn(e,0,`\\/`)||Bn(e,1,`\\/`)),K(`=>`,2,e=>!Bn(e,0,`=>`)||Bn(e,1,`=>`)),K(`\\in`,2,e=>Qt(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!Qt(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=Vn(e,0,`\\subseteq`),n=Vn(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?gu(B(t.base).elements,n.base):gu(B(t).elements,n)}),...yu.map(e=>K(e,2,t=>{let n=Vn(t,0,e),r=Vn(t,1,e);return bu(n)&&bu(r)&&!xu(n)&&!xu(r)?e===`\\cup`&&V(n)?r:(e===`\\cup`?bt:e===`\\cap`?yt:vt)(B(n),B(r)):bu(n)?Cu(e,n,r):e!==`\\`&&bu(r)?Cu(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:Vn(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=Vn(e,0,`UNION`),n=tt(t)?t.elements.filter(tt):[];if(!tt(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(xu(t)||n.some(xu)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{Qt(t,e)||e.elements.push(t)})),gt(e.elements)}return n.length===0?_t:vu(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!M(t))throw new m(`DOMAIN expects a function but received ${U(t)}`);return sn(t)})],Tu=cr(`DotDot`,`IntervalValue`,2),Eu=cr(`Neg`,`IntValue`,1),Du=[Jn(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),lr(`+`,`Plus`,(e,t)=>e+t),lr(`-`,`Minus`,(e,t)=>e-t),lr(`*`,`Times`,(e,t)=>e*t),lr(`^`,`Expt`,(e,t)=>{if(t<0)throw new h(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new h(`0^0 is undefined.`);return e**t}),lr(`\\div`,`Divide`,(e,t)=>{if(t===0)throw new h(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Qn(n))throw $n(`${e} \\div ${t}`);return n}),lr(`%`,`Mod`,(e,t)=>{if(t<=0)throw new h(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),dr(`<`,(e,t)=>e<t),dr(`>`,(e,t)=>e>t),dr(`<=`,(e,t)=>e<=t),dr(`>=`,(e,t)=>e>=t),K(`..`,2,e=>({kind:`Interval`,low:sr(G(e,0,`..`),Tu),high:sr(G(e,1,`..`),Tu)}))],Ou=[Jn(`Int`,{kind:`InfiniteSet`,name:`Int`}),K(`-.`,1,e=>{let t=sr(G(e,0,`-`),Eu);if(Qn(-t))throw $n(`-${t}`);return-t})],ku=(e,t,n)=>{let r=G(e,t,n),i=Yt(r);if(!i)throw new h(`${n}\n${U(r)}`);return i},Au=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:ku(e,t,n)},ju=(e,t,n)=>typeof e==`string`?Oe(e.slice(t,n)):R(e.slice(t,n)),Mu=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Nu=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,Pu=(e,t)=>{let n=hu.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?or(e,t):e}):t},Fu=Pu(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>Au(e,0,Mu(``,`Len`)).length),K(`\\o`,2,e=>{let t=Au(e,0,Nu(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=ku(e,1,Nu(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new h(`${Nu(`t \\o s`,`string`)}\n${U(n)}`);return Oe(t+n)}),K(`Append`,2,e=>R([...ku(e,0,Nu(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=ku(e,0,Mu(``,`Head`));if(t.length===0)throw new h(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=Au(e,0,Mu(``,`Tail`));if(t.length===0)throw new h(`Attempted to apply Tail to the empty sequence.`);return ju(t,1)}),K(`SubSeq`,3,e=>{let t=Au(e,0,Mu(`first `,`SubSeq`)),n=zn(e,1,`SubSeq`),r=zn(e,2,`SubSeq`);if(n>r)return ju(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new h(`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 ju(t,n-1,r)}),Yn(`SelectSeq`,2,e=>{let t=qn(e,1,`SelectSeq`);return R(ku(e,0,Mu(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new h(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),Iu=Pu(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(j(t))return qt(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new m(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${he(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!j(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new h(`Attempted to compute cardinality of the value\n${U(t)}`);return Gt(t)})]),Lu=/* @__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`]]]),Ru=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:Du};case`Integers`:return{extends:[`Naturals`],operators:Ou};case`Sequences`:return{extends:[],operators:Fu};case`FiniteSets`:return{extends:[],operators:Iu};case`TLC`:return{extends:[],operators:Pu(`TLC`,cu(t,n))};case`Randomization`:return{extends:[],operators:Bl(n)};case`_Possible`:return{extends:[],operators:tu(t,n)};case`Json`:return{extends:[],operators:Pl(r)};case`Bags`:return{extends:[],operators:pl};case`TLCExt`:return{extends:[],operators:eu(t,n)};default:return}},zu=`$subexpression`,Bu=(e,t)=>new f(`${e} at line ${t.line}, column ${t.column}`),Vu=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Hu=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Uu=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}},Wu=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:Ir(e.bounds),body:e.body,sets:Vu(e.bounds)};case`SetMap`:return{names:Ir(e.bounds),body:e.expression,sets:Vu(e.bounds)};case`SetFilter`:return{names:Fr(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:Fr(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}},Gu=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Gu(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of Fn(e)){let e=Gu(r,t,n);if(e)return e}},Ku=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,qu=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Ju=(e,t)=>{let n=e.location,r=qu(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 Bu(`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 Bu(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:zu,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:zu,args:e.args,location:n,resolution:Tr},location:n}},Yu=(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:Tr})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:Tr}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:Tr};return Ju({...t,params:[...t.params,...r]},a)},Xu=(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 Bu(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>vi(e)===l):t(l);if(u)return{definition:u,args:Ku(s,Ar(u),r)};a.index++}throw Bu(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=Ar(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Bu(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Bu(`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&&Gu(a.current,t.name,[]);if(!o)throw Bu(`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(...Ku(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Bu(`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`||Hu(t.operand,1)!==0)throw Bu(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Wu(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(...Ku(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[Hu(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Bu(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Hu(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Bu(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Bu(`Unexpected subexpression selector`,n);let c=s?s.sets:Uu(o),u=c?.[Hu(t.operand,c.length)];if(!u)throw Bu(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Yu(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 Bu(`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 Yu(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Bu(`Subexpression selection failed`,n);return Ju(i,a.current)},Zu=(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:[]}))]},Qu=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||Fn(e).some(Qu),$u=(e,t)=>{if(!Qu(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return xi(e,e=>$u(e,n))}let n=xi(e,e=>$u(e,t));if(n.kind===`Subexpression`)return Xu(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Zu(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Xu(i,t,n.location,a);if(a.length>0)throw Bu(`Too many arguments for ${r}`,n.location);return o},ed=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},td=(e,t)=>{let n=ed(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:$u(e.expression,n)}))}},nd=(e,t)=>{let n=ed([...t,...e.definitions]);return e.definitions.some(e=>Qu(e.body))||e.assumptions.some(e=>Qu(e.expression))?{...e,definitions:e.definitions.map(e=>bi(e,e=>$u(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:$u(e.expression,n)}))}:e},rd=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}])),id=(e,t)=>`${e}${t}`,ad=(e,t,n)=>`${e}${t}${n}`,od=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},sd=(e,t,n)=>`${e},${t},${n}`,cd=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),ld=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),ud=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),dd=(e,t,n,r)=>({...cd(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),fd=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,pd=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,md=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,{...dd(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),hd=dd(`$Set`,0,[2],[1]),gd=dd(`$Junction`,0,[3],[1]),_d=dd(`$Choose`,0,[2],[1]),vd=dd(`$Function`,0,[3],[1]),yd=dd(`$FcnApply`,0,[2,2],[1,1]),bd=dd(`$RcdSelect`,0,[2,0],[1,1]),xd=dd(`'`,2,[1],[0]),Sd=dd(`ENABLED`,1,[2],[0]),Cd=dd(`[]`,3,[3],[0]),wd=dd(`$SquareAct`,2,[2,1],[0,0]),Td=dd(`$WF`,3,[1,2],[0,0]),Ed=dd(`$TemporalExists`,3,[3],[0]),Dd=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),Od=e=>e.map(e=>({name:e,arity:0})),kd=(e,t)=>new f(`${e} at line ${t.line}, column ${t.column}`),Ad=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),jd=e=>e.kind!==`Let`&&e.kind!==`Label`,Md=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:_(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:_(i,/* @__PURE__ */ new Map)};let a=md.get(t)??rd.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=cd(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(ad(e,n,t))}),t.data.constraints.forEach((e,t)=>ld(r.constraints,t,e)),ud(r.argConstraints,id(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>ud(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>fd(e,n))throw new f(`Level error in applying operator ${e.name}: The level of argument ${n+1} exceeds the maximum level allowed by the operator.`)}),n.some(e=>e.level>2))throw new f(`Level error in applying operator ${e.name}: The 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(sd(t,n,r)),s=cd(Math.max(e.level,...t.filter((t,n)=>pd(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)=>{pd(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)=>ld(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||ld(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>ld(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||ld(s.constraints,t,fd(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=>ld(s.constraints,e,fd(r,a)))}))}),e.argParams.forEach(e=>{let t=od(e),n=a(t.operator)?.operator;n&&ld(s.constraints,t.param,fd(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>ud(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>ud(s.argConstraints,id(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&ud(s.argConstraints,id(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=od(e),n=a(t.operator);n&&ud(s.argConstraints,id(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(od(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=od(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(ad(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(ad(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(ad(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=g(`LAMBDA`,Od(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=cd();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=Dd(n,Od(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 kd(`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 kd(`Action used where only temporal formula or state predicate allowed`,e.location);Ad.has(e.operator)&&l(t,e.location)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&jd(n)&&n.kind!==r)throw kd(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e.location)},p=(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=_(e,n);t.constraints.forEach((e,t)=>ld(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>ud(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return cd();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.location),i(gd,n)}case`Prime`:case`Unchanged`:return s(xd,[e.expression],t);case`Enabled`:return s(Sd,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(Cd,[n])}case`If`:return s(gd,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(gd,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return p(e,t);case`Forall`:case`Exists`:{let n=s(gd,[e.body],t,e.bounds.map(e=>e.set),Ir(e.bounds));if(n.level===3&&e.bounds.some(e=>m(e.set,t).level===2))throw kd(`Action-level bound of quantified temporal formula`,e.location);return n}case`UnboundedQuantifier`:return s(e.isTemporal?Ed:gd,[e.body],t,[],e.names);case`Choose`:return s(_d,[e.body],t,e.set?[e.set]:[],Fr(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(hd,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(hd,[e.predicate],t,[e.bound.set],Fr(e.bound.pattern));case`SetMap`:return s(hd,[e.expression],t,e.bounds.map(e=>e.set),Ir(e.bounds));case`FunctionConstruction`:return s(vd,[e.body],t,e.bounds.map(e=>e.set),Ir(e.bounds));case`Record`:return s(vd,e.fields.map(e=>e.value),t);case`RecordSet`:return s(hd,e.fields.map(e=>e.value),t);case`Except`:return s(hd,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(yd,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(hd,e.args,t)}]);case`FieldAccess`:return i(bd,[a(e.record,t),{data:cd()}]);case`BoxAction`:case`AngleAction`:return s(wd,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(Td,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return cd()}},h=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>h(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 Fn(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,Dd(t,Od(e.names))),i;default:return xi(e,(e,n)=>(a(e,r,Dd(t,Od(n))),e)),i}},g=(e,t,n,r)=>{let i=Dd(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=h(n,i),c={...cd(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(id(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(ad(e.name,n,t.name))).map(e=>sd(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(od(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=od(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},_=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...cd(),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=g(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:_,toOperand:a}},Nd=(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`?Nd(e,r,n):n.analyze(e,r)}),n.analyze(e.conclusion,r)},Pd=(e,t)=>{let n=Md(t);e.definitions.filter(e=>!e.name.includes(`!`)).forEach(e=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)),e.assumptions.forEach(e=>n.analyze(e.expression,/* @__PURE__ */ new Map)),e.theorems.forEach(e=>e.statement.kind===`AssumeProve`?Nd(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map))},Fd=(e,t)=>e.maxLevels[t]??3,Id=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=Md({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=>ld(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>ld(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>ud(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=od(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(id(t.name,a));o!==void 0&&Fd(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=od(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=Fd(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 f([...o].join(`
410
- `))},Ld=t=>{switch(t.kind){case`Number`:try{return ge(t.value)}catch(t){throw a(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return Le(t.name);case`Set`:return ht(t.elements.map(Ld))}},Rd=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],zd=e=>new f(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),Bd=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:Tr},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),Vd=(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 m(`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`)&&Be(t,r)})});if(t)return t[1];throw new m(`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}},Hd=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||Fn(e).some(e=>Hd(e,t)),Ud=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(Ai(e),n.get(e)??n.size)),n},Wd=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),Gd=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw Wa(e);if(e.kind===`Number`&&!Po(e.value))throw Ga(e);Gd(e.kind===`Let`?[...Fn(e),...Wd(e.instances??[])]:Fn(e))}),Kd=(e,t)=>{let n=lc(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=new Map(wu.map(e=>[e.name,e])),o=/* @__PURE__ */ new Map,s=Wc(e.checkDeadlock,t.seed),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u=[],d=/* @__PURE__ */ new Map,m=[],h=[],g=(e,t)=>m.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),_={value:0},v=e=>`${e}#${_.value++}`,y=[],b=/* @__PURE__ */ new Map,x=e=>{let n=o.get(e);if(n)return n;let r=Ru(e,t.print,s,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>x(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{a.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),o.set(e,i),i},S=e=>{let t=x(e);return t&&g(e,Lu.get(e)??[]),t},ee=e=>(Gd([...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]),...Wd(e.instances)]),e.modules.forEach(ee),e);ee(n);let te=(e,n)=>{let r=t.loadModule?.(e)??As.get(e)??sc(t.source,e);if(r===void 0)throw new f(`Cannot find source file for module ${e} imported in module ${n}.`);let i=lc(r);if(i.name!==e)throw new f(`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`);return ee(i)},C=e=>{let t=h.indexOf(e.name);if(t!==-1)throw new f(`Circular dependency among .tla files; dependency cycle is: ${[...h.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];h.push(e.name),m.push(n);let i=k(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});m.pop(),h.pop();let a=r.find(e=>n.has(e.name));if(a)throw zd(a);return{linked:i,closure:n}},w=(e,t)=>{let n=c.get(e);if(n)return g(e,d.get(e)??[]),n;let r=C(te(e,t));return c.set(e,r.linked),d.set(e,r.closure),g(e,r.closure),r.linked},ne=(e,t,n,a,o)=>{let s=o?void 0:S(e.module);if(s)return e.name===void 0?s:new Map([...s].map(([t,n])=>[`${e.name}!${t}`,n]));let c=o??w(e.module,t.name),l=Rd(c),u=`#${_.value++}`,d=new Map(e.params.map(e=>[e.name,`${e.name}${u}`])),f=di(td(e,t),l,t,n);y.push({module:e.module,instancer:t.name,lets:[],substitutions:f,location:e.location});let p=Hi({params:e.params.map(e=>({...e,name:`${e.name}${u}`})),substitutions:new Map([...f].map(([e,t])=>[e,hi(t,d)])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(e,n)=>{let o=v(`${e}@${t.name}`);return r.set(o,n(o)),i.set(o,!a),o},createName:v}),m=new Set(l.map(e=>e.name)),h=/* @__PURE__ */ new Map;return c.exported.forEach((t,n)=>{if(m.has(n))return;if(e.name===void 0){let r=p.getKey(t.key);l.length>0&&b.set(r,{name:n,location:e.location}),h.set(n,{key:r,arity:t.arity});return}let r=p.getQualifiedKey(t.key);l.length>0&&b.set(r,{name:`${e.name}!${n}`,location:e.location}),h.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),h},re=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:Tr})),ie=(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}),T=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),E=(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=T(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}}},D=(e,t,n,a)=>{let o=e.location,s=a?void 0:S(e.module);if(s)return e.name===void 0?[]:[...s].map(([t,n])=>{let r=T(n.arity);return ie(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??w(e.module,n),l=`#${_.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=Rd(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};y.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=>Hd(f(e),p),h=d.map(t=>{let n=E(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=[],b=Hi({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:Tr}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:Tr}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n)=>{let r=`${t}@${e.module}${l}.${g.length}`,i=n(r);return g.push(i.kind===`Operator`?{...i,name:r}:Bd(i,r)),r},createName:v}),x=new Set(d.map(e=>e.name)),ee=[...c.exported].filter(([e])=>!x.has(e)).map(([t,n])=>{let r=b.getKey(n.key),i=T(n.arity),a=[...e.params,...i];return ie(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...ee]},O=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),k=(e,a)=>{let o=Rs(e,t.loadClass?.(e.name)),s=new Map([...wu.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,d=/* @__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:S(e);if(n){g(n,!0);return}let r=t??w(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)=>d.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,...d]),ee=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>kr(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>kr(t.location,e)).map(e=>[e.name,{key:v(e),arity:Ar(e)}])]),te=e=>{let t=x();if(t.has(e.name))throw zd(e);a.nested.push(e);let n=k(e,{id:`${a.id}/${e.name}`,symbols:ee(e.location),modules:t,nested:a.nested});d.set(e.name,n),l.has(e.name)||l.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=ne(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)=>kr(e.location,t.location)?-1:1).forEach(e=>e.link()),li(o,b(o));let C=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&kr(e.location,t.location)},re=e=>{let t=o.modules.find(t=>t.name===e.module);return t?C(t)?d.get(t.name):void 0:x().get(e.module)},ie=nd(Ki(o,(e,t)=>D(e,t,o.name,re(e))),O(s));fi(ie,b(ie)),ie.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:Ar(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),Pd(ie,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e)});let T={module:ie,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:d,extended:f};return u.push(T),T},ae=C(n).linked,oe=e=>ae.visible.get(e)?.key??e;ae.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let A=[],se=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>se(e,t)),A.push(...e.module.assumptions))};se(ae,/* @__PURE__ */ new Set);let ce=ae.constants.map(e=>e.name),le=ae.variables,ue=e=>e.module===void 0?[e.name,oe(e.name)]:e.module===n.name||ce.includes(e.name)?[]:[(c.get(e.module)??l.get(e.module))?.visible.get(e.name)?.key??e.name],de=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:ae.constants.find(t=>t.name===e)?.arity??0},fe=/* @__PURE__ */ new Map,pe=/* @__PURE__ */ new Set,me=(e,t)=>{a.set(e,t),r.delete(e),fe.delete(e),pe.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=Ld(e.value);ue(e).forEach(e=>{let n=de(e);n===0?fe.set(e,t):me(e,{kind:`Builtin`,name:e,arity:n,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0,isLazy:!0})})});let j=/* @__PURE__ */ new Map;e.constants.forEach(e=>{if(e.args===void 0)return;let t=`${e.module??``}!${e.name}`,n=j.get(t)??{name:e.name,module:e.module,rows:[]};if(n.rows.length>0&&n.rows[0][0].length!==e.args.length)throw new p(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(Ld),Ld(e.value)]),j.set(t,n)}),j.forEach(e=>ue(e).forEach(t=>me(t,Vd(e.name,de(t)||e.rows[0][0].length,e.rows))));let M=new Map(e.substitutions.flatMap(e=>ue(e).map(t=>[t,oe(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!ce.includes(n)&&!ae.visible.has(n))throw new p(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new p(`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 o=oe(i),s=r.get(o);if(!(s!==void 0||a.has(o)||fe.has(o)||ce.includes(i)||le.includes(i)))throw new p(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(ae.constants.find(e=>e.name===n)?.arity??ae.visible.get(n)?.arity))throw new p(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)}),ce.forEach(e=>{if(!fe.has(e)&&!M.has(e)&&!pe.has(e))throw new p(`The constant ${e} is not assigned a value by the configuration`)});let N={runtime:s,definitions:r,builtins:a,constants:fe,substitutions:M,variables:le,variableIndex:Ud(le,u.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};return Id(y,e=>{let t=c.get(e)??l.get(e)??ae;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)}}),M.forEach((e,t)=>{let n=r.get(e);if(ce.includes(t)&&n&&!$a(n,N))throw new p(`The configuration file substitutes constant ${t} with non-constant ${e}`)}),{environment:N,assumptions:A,variableLocations:ae.variableLocations,instanceActions:b}},qd={kind:`Boolean`,value:!0},Jd={kind:`Boolean`,value:!1},Yd=e=>e?qd:Jd,Xd=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,Zd=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),Qd=(e,t,n)=>({kind:e,operands:[t,n]}),$d=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?$d(e,t.operands).operands:[t])}),ef=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return ef(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,ef(t)),0)}},tf=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 tf(e.body);case`And`:case`Or`:return e.operands.some(tf)}},nf=(e,t)=>e.kind===t.kind?e.kind===`Boolean`&&t.kind===`Boolean`?e.value===t.value:Xd(e)?e===t:`body`in e&&`body`in t?nf(e.body,t.body):`operands`in e&&`operands`in t&&e.operands.length===t.operands.length&&e.operands.every((e,n)=>nf(e,t.operands[n])):!1,rf=(e,t)=>e.some(e=>nf(e,t)),af=e=>e===`And`?`Or`:`And`,of=(e,t)=>{switch(e.kind){case`Boolean`:return t?Yd(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return of(e.body,!t);case`And`:case`Or`:return $d(t?af(e.kind):e.kind,e.operands.map(e=>of(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,of(e.body,t))}}},sf=e=>{switch(e.kind){case`Boolean`:return Yd(!e.value);case`Not`:return e.body;case`And`:case`Or`:return $d(af(e.kind),e.operands.map(sf));case`Always`:return Q(`Eventually`,sf(e.body));case`Eventually`:return Q(`Always`,sf(e.body));default:return Q(`Not`,e)}},cf=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=cf(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return Yd(t)}return n.length===0?Yd(!t):n.length===1?n[0]:$d(e.kind,n)}case`Not`:{let t=cf(e.body);return t.kind===`Boolean`?Yd(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=cf(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},lf=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,uf=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=uf(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new m(`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=>$d(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=uf(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=lf(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:$d(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return $d(`Or`,n)}case`Not`:return Xd(e.body)?e:uf(sf(e.body));default:return e}},df=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?df(e.operands[0]):$d(e.kind,e.operands.map(df));case`Not`:return e.body.kind===`Not`?df(e.body.body):Q(`Not`,df(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,df(e.body));default:return e}},ff=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return ff(e.operands[0]);let t=Math.floor(e.operands.length/2);return Qd(e.kind,ff($d(e.kind,e.operands.slice(0,t))),ff($d(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,ff(e.body));default:return e}},pf=(e,t)=>{e.kind===`Eventually`&&!rf(t,e)&&t.push(e),`body`in e&&pf(e.body,t),`operands`in e&&e.operands.forEach(e=>pf(e,t))},mf=e=>{let t=e.filter(Zd),n=e.flatMap(e=>e.kind===`Not`&&Zd(e.body)?[e.body]:[]);return!t.some(e=>rf(n,e))},hf=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 m(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},gf=(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]}},_f=(e,t,n)=>e.flatMap(e=>{let r=gf(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),vf=(e,t)=>e.every(e=>rf(t,e))&&t.every(t=>rf(e,t)),yf=(e,t)=>[...e.filter(e=>!t.some(t=>vf(e,t))),...t],bf=e=>{let t=hf(e),n=_f(t,`Always`,`And`),r=_f(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=gf(t,`Eventually`,`Or`);if(n&&!(rf(e,n.first)||rf(e,n.second)))return yf(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(rf(e,t.first)||rf(e,t.second))&&!rf(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!mf(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=gf(t[e],`Always`,`And`);n&&(rf(t,n.first)||t.push(n.first),rf(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)rf(t,e.first)&&rf(t,e.second)&&!rf(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!mf(t)?[]:i(t)};return a(e)},xf=e=>({particle:e,successors:[],statePredicates:e.filter(e=>ef(e)<=1)}),Sf=e=>{let t=bf([e]).map(xf),n=t.length;for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let r of bf(n)){let n=t.findIndex(e=>vf(e.particle,r));n===-1&&t.push(xf(r)),t[e].successors.push(n===-1?t.length-1:n)}}return{nodes:t,initialCount:n}},Cf=(e,t)=>!rf(e,t)||rf(e,t.body),wf=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&ef(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=lf(e);if(n){let e=ef(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(tf(e))throw new m(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},Tf=(e,t)=>{let n=e.findIndex(e=>nf(e,t));return n===-1?(e.push(t),e.length-1):n},Ef=e=>{let t=uf(cf(of(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=df(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])wf(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:$d(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:nf(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&ff(e.formula),n=[];t&&pf(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>Tf(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>Tf(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>Tf(i,e))}));return{tableau:t&&Sf(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Df=/* @__PURE__ */ new Set([`~>`,`-+->`]),Of=/* @__PURE__ */ new WeakMap,kf=/* @__PURE__ */ new WeakSet,Af=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),jf=e=>new m(`TLC cannot handle the temporal formula at ${J(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Ka(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=Za(e,n);if(t)return Mf(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 xi(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 Df.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},Mf=(e,t)=>{let n=Of.get(e);if(n!==void 0)return n;Of.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 Of.set(e,i),i},Nf=(e,t,n,r,i=/* @__PURE__ */ new Set)=>{let a=(e,t,a=i)=>Nf(e,t,n,r,a);if(e.kind===`And`)return e.operands.flatMap(e=>a(e,t));if(e.kind===`Label`)return a(e.body,t);if(e.kind===`Let`)return a(e.body,Pf(e,t,n));if(e.kind===`Identifier`){let r=W(e)?Ka(t,e.name):void 0;if(r?.kind===`Thunk`)return a(r.expression,r.scope);let o=n.constants.has(e.name)?void 0:Za(e.name,n);if(!r&&o?.kind===`Operator`&&o.params.length===0&&Mf(o,n)>0){if(i.has(o))throw new p(`The definition of ${e.name} refers to itself`);return a(o.body,void 0,/* @__PURE__ */ new Set([...i,o]))}}let o=Af(n,t);if(e.kind===`Apply`&&$(e,t,n)===3){let t=vo(e,o),r=W(e)?void 0:Za(e.operator,n);if(t?.kind===`Closure`&&!r?.isRecursive)return a(t.body,Ao(t,e.args,o))}if(r&&e.kind===`Forall`&&$(e.body,t,n)===3&&e.bounds.every(e=>$(e.set,t,n)===0)){let t=[];return no(e.bounds,o,n=>(t.push(...a(e.body,n)),!1)),t}return[{expression:e,scope:t}]},Pf=(e,t,n)=>{let r=Mo(e.definitions,Af(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&kf.add(e.binding);return r},Ff=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),If=(e,t,n)=>{let r=(e,t,r)=>{let i=r===0?$(e,t,n):r;if(i===0){let r=X(e,Af(n,t));if(typeof r!=`boolean`)throw new m(`TLC expected a boolean in the temporal formula at ${J(e)}`);return Yd(r)}return i===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},i={depth:0},a=(e,t,n,a)=>{if(i.depth>=100)throw new m(`TLC overflowed the stack while expanding the temporal formula at ${J(n)}`);i.depth++;let o=c(e,t);i.depth--;let s=ef(o);return s>2?o:r(n,a,s)},o=(e,t)=>{let r=e.kind===`Identifier`?e.name:e.operator,i=Af(n,t),o=W(e)||Za(r,n)===void 0?Ka(t,r):void 0;if(o?.kind===`Thunk`&&kf.has(o))return a(o.expression,o.scope,e,t);let s=o?.kind===`Operator`?o.operator:o?void 0:W(e)?yo(r,i):go(r,n);if(s?.kind!==`Closure`)throw jf(e);let c=e.kind===`Apply`?e.args:[];return a(s.body,Ao(s,c,i),e,t)},s=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,n)===0))throw jf(e);let i=[];no(e.bounds,Af(n,t),t=>(i.push(c(e.body,t)),!1));let a=e.kind===`Forall`;if(i.length===0)return Yd(a);let o=$d(a?`And`:`Or`,i),s=ef(o);return s>2?o:r(e,t,s)},c=(e,t)=>{let i=$(e,t,n);if(i<=2)return r(e,t,i);switch(e.kind){case`Label`:return c(e.body,t);case`Let`:return c(e.body,Pf(e,t,n));case`Identifier`:return o(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,Qd(`Or`,Q(`Not`,c(n[0],t)),Q(`Eventually`,c(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,c(n[0],t)):e.operator===`=>`?Qd(`Or`,Q(`Not`,c(n[0],t)),c(n[1],t)):o(e,t)}case`And`:case`Or`:return $d(e.kind,e.operands.map(e=>c(e,t)));case`Forall`:case`Exists`:return s(e,t);case`If`:{if($(e.condition,t,n)===0){let r=X(e.condition,Af(n,t));if(typeof r==`boolean`)return c(r?e.consequent:e.alternative,t)}let r=c(e.condition,t);return Qd(`Or`,Qd(`And`,r,c(e.consequent,t)),Qd(`And`,Q(`Not`,r),c(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,c(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=Ff(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`,Qd(`Or`,i,a))):Qd(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw jf(e)}};return c(e,t)},Lf=(e,t,n,r,i)=>{let a=e=>Lf(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`?Xa(X(e.expression,a),`a temporal property predicate`):Ma(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&&Xa(X(e.unchanged,a),`a subscript`)?!1:Xa(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 Lf(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new m(`TLC cannot evaluate a temporal formula in a single step`)}},Rf=(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)=>Rf(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 Lf(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},zf=/* @__PURE__ */ new WeakMap,Bf={value:0},Vf=e=>{let t=zf.get(e);if(t!==void 0)return t;let n=e.kind===`Boolean`?String(e.value):`body`in e?`${e.kind}(${Vf(e.body)})`:`operands`in e?`${e.kind}(${e.operands.map(Vf).join(`,`)})`:`${e.kind}#${Bf.value++}`;return zf.set(e,n),n},Hf=(e,t)=>e.every((e,n)=>He(e,t[n])),Uf=e=>e.filter((t,n)=>n===0||e[n-1]!==t),Wf=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.successors.push([]),e.actions.push(/* @__PURE__ */ new Uint8Array),e.stateResults.push(/* @__PURE__ */ new Uint8Array),e.isWritten.push(!1),e.nodeStates.length-1),Gf=2**53-1,Kf=(e,t,n,r)=>{if(e.length===0)return;let i=t.map(e=>If(e.expression,e.scope,n)),a=e.map(e=>Q(`Not`,If(e.expression,e.scope,n))),o=a.length===1?a[0]:$d(`Or`,a),s=i.length===0?o:$d(`And`,[...i,o]),c=Ef(s);if(c.length===0)throw new m(`Temporal formula is a tautology (its negation is unsatisfiable)`);let l=/* @__PURE__ */ new Map,u=c.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=Vf(e),n=l.get(t)??l.size;return l.set(t,n),n}),nodeStates:[],nodeTableaux:[],successors:[],actions:[],stateResults:[],isWritten:[],initial:[],nodeIds:/* @__PURE__ */ new Map,nodesByState:/* @__PURE__ */ new Map,isDone:[],errorNode:void 0})),d={multiplier:1},f=!Wo(n),p={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},h=e=>{let t=p.states.get(e)??/* @__PURE__ */ new Map;return p.states.set(e,t),t},g=(e,t)=>{n.runtime.setLivenessSource(e);let r=t();return n.runtime.setLivenessSource(void 0),r},_=(e,t)=>Lf(e,t,void 0,n,f?h(t):/* @__PURE__ */ new Map),v=(e,t,n)=>g(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!_(e,n))),y=(e,t,r,i)=>g(t,()=>{let t=e.solution.actionChecks;if(!f)return Uint8Array.from(t,e=>+!!Lf(e,r,i,n,/* @__PURE__ */ new Map));let a=h(r),o=p.actions.get(r)??/* @__PURE__ */ new Map;p.actions.set(r,o);let s=o.get(i)??new Int8Array(l.size).fill(-1);return o.set(i,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!Lf(t[o],r,i,n,a)),s[e]))}),b=(e,t,n,r)=>g(n,()=>e.nodes[t].statePredicates.every(e=>_(e,r))),x=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},S=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),ee=(e,t,n)=>e.solution.tableau?e.nodeIds.get(t*e.solution.tableau.nodes.length+n):t,te=(e,t,n)=>{let r=Wf(e,t,n);e.nodeIds.set(t*(e.solution.tableau?.nodes.length??1)+n,r);let i=e.nodesByState.get(t);return i?i.push(r):e.nodesByState.set(t,[r]),r},C=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=new Uint8Array(n.length*i);n.forEach((e,t)=>a.set(e,t*i)),e.actions[t]=a,e.stateResults[t]=r,e.isWritten[t]=!0},w=(e,t,n)=>{let i={slots:Array.from({length:16*d.multiplier}),count:0},a=(e,t)=>{for(let n=(r.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&&Hf(r.state,t.state))return!1}},o=e=>{if(i.count>=i.slots.length>>1){let e=i.slots;i.slots=Array.from({length:2*e.length+1});for(let t of e)t&&a(i.slots,t)}a(i.slots,e)&&i.count++};return n.forEach(o),o({index:e,state:t}),i.slots.length>16*d.multiplier&&d.multiplier++,i.slots.filter(e=>e!==void 0)},ne=(e,t,n,i,a)=>{let o=v(e,i,n),s=t.nodes[e.nodeTableaux[a]],c=[],l=e.successors[a],u=s.successors.length>0?y(e,i,n,n):/* @__PURE__ */ new Uint8Array;for(let r of s.successors){if(!b(t,r,i,n))continue;if(x(t,r)&&e.errorNode===void 0&&S(e)){e.errorNode=a;return}let o=ee(e,i,r);if(o!==void 0&&l.includes(o))continue;let s=o??te(e,i,r);l.push(s),c.push(u),o===void 0&&ne(e,t,n,i,s)}for(let a of r.getSuccessors(n)){let r=y(e,i,n,a.state),o=e.isDone[a.index]===!0;for(let n of s.successors){if(!b(t,n,i,a.state))continue;let s=ee(e,a.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??te(e,a.index,n);l.push(u),c.push(r),s===void 0&&o&&ne(e,t,a.state,a.index,u)}}l.length>0&&C(e,a,c,o)},re=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>b(t,r,a,e.state)));e.isDone[a]=!0;for(let s of(e.nodesByState.get(a)??[]).slice()){let a=e.successors[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=ee(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??te(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&ne(e,t,n.state,n.index,d)}}),C(e,s,c,i)}if(e.errorNode!==void 0)return Uf(T(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},ie=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)Wf(e,e.nodeStates.length,-1);let a=e.successors[i],o=[];t.forEach((t,r)=>{e.isWritten[t.index]&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),C(e,i,o,r)},T=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)e.isWritten[t]&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of e.successors[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}e.isWritten[i]&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new m(`Couldn't re-create liveness trace (path) starting at: ${t}`)},E=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=(t,n,i)=>e.actions[t][n*r+i]===1,a=(e,n)=>t.eventuallyAlways.every(t=>i(e,n,t)),o=new Float64Array(e.nodeStates.length).fill(-1),s=e.initial.filter(t=>e.isWritten[t]),c=[],l=t=>{let n=e.successors[t].indexOf(t);return n!==-1&&a(t,n)},u=(t,r)=>n.tableau!==void 0&&Cf(n.tableau.nodes[e.nodeTableaux[t]].particle,r),d=r=>{let s=c.pop()??r;if(s===r&&!l(s)){o[s]=Gf;return}let d=/* @__PURE__ */ new Set,p=/* @__PURE__ */ new Map;for(let t=s;;t=c.pop()??r){d.add(t);let n=p.get(e.nodeStates[t]);if(n?n.push(t):p.set(e.nodeStates[t],[t]),o[t]=Gf,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...d].some(n=>e.stateResults[n][t]===1)),h=t.infinitelyOftenActions.every(t=>[...d].some(n=>e.successors[n].some((e,r)=>d.has(e)&&a(n,r)&&i(n,r,t)))),g=n.promises.every(e=>[...d].some(t=>u(t,e)));if(m&&h&&g)return f(r,d,p)},f=(r,o,s)=>{let c=Uf(T(e,r).reverse().map(t=>e.nodeStates[t])),l=[],d=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),h=t.infinitelyOftenActions.map(()=>!1),g=n.promises.map(()=>!1),_={count:f.length+h.length+g.length},v={node:r},y=e=>o.has(e),b=e=>{l.push(v.node),v.node=e};for(;_.count>0;){let r=_.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&e.stateResults[v.node][t]===1&&(f[n]=!0,_.count--)}),n.promises.forEach((e,t)=>{!g[t]&&u(v.node,e)&&(g[t]=!0,_.count--)}),!(_.count<=0);){let n={last:-1,unvisited:-1},o=_.count;if(e.successors[v.node].some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!a(v.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!h[t]&&i(v.node,c,e)&&(h[t]=!0,_.count--)})}return _.count<o?(b(r),d.clear(),!0):(y(r)&&!d.has(r)&&(n.unvisited=r),!1)}))break;if(_.count<r){b(n.last),d.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new m(`TLC failed to build the counterexample of a liveness property`);v.node=t,n.unvisited=e.successors[t].find(e=>y(e)&&!d.has(e))??-1}b(n.unvisited),d.add(n.unvisited)}}let x=p(r,v.node,s,a);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];x[x.length-1]!==n&&x.push(n)}let S=c[c.length-1];return x[x.length-1]===S&&x.pop(),{prefix:c.slice(0,-1),cycle:[S,...x.reverse()]}},p=(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 e.successors[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 m(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<s.length;t++){let n=[s[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),l=n.pop()??0;if(i===-42){if(o[l]===t){let e=d(l);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(o[l]!==-1){n.push(Math.min(t,o[l]));continue}o[l]=r.link,n.push(t,l,-42),c.push(l);let u={value:r.link++};e.successors[l].forEach((t,r)=>{e.isWritten[t]&&(a(l,r)?o[t]===-1?n.push(t,-1):u.value=Math.min(u.value,o[t]):o[t]===-1&&s.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{p.states.clear(),p.actions.clear();for(let n of u){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)b(r,i,void 0,t)&&n.initial.push(ee(n,e,i)??te(n,e,i))}},addState:(e,t,n)=>{p.states.clear(),p.actions.clear();let r=w(e,t,n);for(let n of u){let i=r.map(r=>y(n,e,t,r.state)),a=v(n,e,t),o=n.solution.tableau,s=o?re(n,o,r,i,a,e):ie(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of u)for(let t of e.solution.models){let n=E(e,t);if(n)return n}},getViolatedProperties:(t,r)=>[...new Set(e.filter((e,i)=>!Rf(a[i].body,t,r,0,n)).map(e=>e.name))]}},qf=`UnnamedAction`,Jf={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},Yf=e=>{let t=e.range??Jf;return jt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},Xf=e=>{let t=[[`name`,e.name],[`location`,Yf(e.location)]];return e.parameters.length===0?jt(t):jt([...t,[`context`,jt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},Zf=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),Qf=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),$f=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,ep=e=>e.kind===`Apply`?e.args:[],tp=(e,t,n)=>{let r=$f(e);if(r===void 0)return;if(W(e)){let e=Ka(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=go(r,n);return i?.kind===`Closure`?i:void 0},np=(e,t)=>{try{return X(e,Qf(t,void 0)),!0}catch(e){if(e instanceof d)return!1;throw e}},rp=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&$a(e,t)&&np(e.body,t),ip=(e,t)=>{let n=Za(e.name,t);return n?.body===e.body&&rp(n,t)},ap=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Ka(t,e.name);return n?.kind===`Thunk`?n:void 0},op=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Ka(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),sp=(e,t)=>{try{return e()}catch(e){if(e instanceof d)return t();throw e}},cp=(e,t,n,r,i)=>{let a=ep(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():sp(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,Qf(i,n))]),expression:t,scope:n}],o)},lp=(e,t,n,r,i)=>{let a=()=>({name:n?.name??qf,location:e.location,parameters:op(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return lp(e.body,Mo(e.definitions,Qf(r,t)),n,r,i);case`Label`:return lp(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>lp(e,t,n,r,i));case`Exists`:return sp(()=>{let o=[];return no(e.bounds,Qf(r,t),t=>(o.push(...lp(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get($f(e)??``),s=tp(e,t,r);if(o)return cp(o,e,t,s,r);if(!s)return[a()];let c=ep(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return ip(s,r)||c.some(e=>$(e,t,r)!==0)?l():sp(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,Qf(r,t))},parent:e}),s.scope);return lp(s.body,e,s,r,i)},l)},up=(e,t,n,r,i)=>{let a=(e,t)=>up(e,t,n,r,i);if(e.kind===`Let`){a(e.body,Mo(e.definitions,Qf(n,t)));return}let o=ap(e,t);if(o){a(o.expression,o.scope);return}let s=tp(e,t,n);if(s&&ip(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(Zf(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,Ao(s,e.args,Qf(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(Zf(qf,e));return}let c=$(e,t,n);c<=1?r.inits.push(Zf(qf,e)):c===3&&r.temporals.push(Zf(qf,e))},dp=(e,t,n,r,i)=>{let a=(t,n)=>dp(e,t,n,r,i);if(t.kind===`Let`){a(t.body,Mo(t.definitions,Qf(r,n)));return}let o=ap(t,n);if(o){a(o.expression,o.scope);return}let s=tp(t,n,r);if(s&&ip(s,r))return;if(s&&s.params.length===ep(t).length){a(s.body,t.kind===`Apply`?Ao(s,t.args,Qf(r,n)):s.scope);return}if(t.kind===`Forall`&&sp(()=>(no(t.bounds,Qf(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(Zf(e,a)):$(a,n,r)<2?i.invariants.push(Zf(e,a)):i.impliedTemporals.push(Zf(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(Zf(e,t)):c===3&&i.impliedTemporals.push(Zf(e,t))},fp=(e,t)=>{let n=Za(e,t);return n?.kind===`Operator`&&!rp(n,t)?n:void 0},pp=e=>jt([[`name`,e.name],[`location`,Yf(e.location)]]),mp=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:fp(e.specification,t);a&&(up(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...lp(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:go(e.init,t);o?.kind===`Closure`&&r.inits.push(Zf(e.init??``,o.body));let s=e.next===void 0?void 0:go(e.next,t);return s?.kind===`Closure`&&r.actions.push(...lp(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=fp(e,t);n&&r.invariants.push(Zf(e,n.body))}),e.properties.forEach(e=>{let n=fp(e,t);n&&dp(e,n.body,void 0,t,r)}),r},hp=(e,t,n)=>mp(e,t,n).actions,gp=e=>{let t=e.parameters.map(e=>U(e[1]));return`${e.name===qf?`Action`:e.name}${t.length===0?``:`(${t.join(`,`)})`} ${La(e.location.range??Jf)}`},_p=(e,t,n,r)=>{let i=mp(e,t,r),a=e=>ht(e.map(Xf)),o=e=>ht(e.flatMap(e=>{let n=fp(e,t);return n?[pp(n)]:[]}));return jt([[`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`,ht(t.variables.map((e,t)=>jt([[`name`,e],[`location`,Yf(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},vp=e=>[...e].map(([e,t])=>`${e}>${t.name}`).sort().join(`,`),yp=(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},bp=(e,t)=>{if(!M(e))throw new p(`The symmetry values of ${t} must be functions`);let n=H(e),r=/* @__PURE__ */ new Map;return n.domain.forEach((e,t)=>{let i=n.range[t];if(!N(e)||!N(i))throw new p(`Symmetry function must have model values as domain and range`);e.name!==i.name&&r.set(e.name,i)}),r},xp=(e,t)=>{let n=t.definitions.get(e);if(n?.kind!==`Operator`||n.params.length>0)throw new p(`The symmetry function ${e} must specify a set of permutations`);let r=X(n.body,{environment:t,scope:void 0,state:void 0,next:void 0});if(!j(r)||!z(r))throw new p(`The symmetry operator must specify a set of functions`);let i=B(r).elements.map(t=>bp(t,e));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(vp(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=yp(n,e),r=vp(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}))},Sp=(e,t)=>{for(let n=0;n<e.length;n++){let r=e[n],i=Tp(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(Tp(e[r],t));return a}},Cp=(e,t)=>{let n=[],r=[];for(let i of e){let e=Tp(i,t);e===i?n.push(i):r.push(e)}if(r.length===0)return;r.sort(L);let i=[],a=0,o=0;for(;a<n.length&&o<r.length;)i.push(L(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},wp=e=>e.kind===`Set`?e.elements.length:e.kind===`Function`?e.domain.length:0,Tp=(e,t)=>{if(typeof e!=`object`)return e;if(e.kind===`ModelValue`)return t.images.get(e.name)??e;let n=wp(e);if(n===0||n>64)return Ep(e,t);let r=t.cache.get(e);if(r!==void 0)return r;let i=Ep(e,t),a=i!==e&&He(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},Ep=(e,t)=>{let n=e.kind;if(n===`Set`){let n=Cp(e.elements,t);return n?Re(n):e}if(n===`Function`||n===`LazyFunction`&&z(e.domain)){let n=H(e),r=Sp(n.domain,t),i=Sp(n.range,t)??n.range;if(r){let e=xt(r.map((e,t)=>[e,i[t]]));return e.domain.every((e,t)=>e===n.domain[t])?ze(n.domain,e.range):e}return i===n.range?n:ze(n.domain,i)}if(n===`Interval`||!j(e)||!z(e))return e;let r=B(e),i=Sp(r.elements,t);return i?ht(i):r},Dp=(e,t,n)=>{for(let r=t.length;r<e.length;r++)t.push(Tp(e[r],n));return t},Op=(e,t,n,r)=>{let i=[];for(let a=0;a<e.length;a++){let o=r?r[a]:a,s=Tp(e[o],n),c=L(s,t[o]);if(c>0)return;if(r||i.push(s),c<0)return r?e.map(e=>Tp(e,n)):Dp(e,i,n)}},kp=(e,t,n)=>t.reduce((t,r)=>Op(e,t,r,n)??t,e),Ap=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],jp=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Mp=new Map(uu.flatMap(e=>e.map(t=>[t,e[0]]))),Np=e=>Mp.get(e)??e,Pp=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Fp=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Pp(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()}},Ip=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Lp=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Np(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Np(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}},Rp=(e,t)=>{let n=[];for(let r=t;;){let t=Lp(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},zp=e=>({line:e.line,column:e.column}),Bp=(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=Rp(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},Vp=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Hp={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Up=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Vp(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Vp(e[n+1],e[n+2])?n+=Vp(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=>Hp[e])}"`:r.text)}return t},Wp=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},Gp=(e,t)=>e.find(e=>e.name===t)??e.map(e=>Gp(e.modules,t)).find(Boolean),Kp=(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:mu.get(i)??t?.(i)??sc(e,i),s=o===void 0?[]:ae(o),c=Wp(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=lc(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>Gp(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},qp=(e,t)=>{let n=Kp(e,t),r=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],o=(e,n)=>{let i=Rp(t,e+1);r.push({location:zp(t[e]),apply:e=>i.forEach(t=>e.put(Ip(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,a)=>{let l=e.start+a,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:zp(u),apply:t=>t.put(Ip(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&o(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&o(l,`variable`),u.text===`RECURSIVE`&&Rp(t,l+1).every(e=>s.has(e))&&o(l,`definition`),jp.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(zp(u)),r.push({location:zp(u),apply:e=>e.put(Ip(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(Ip(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=Np(e.name);r.push({location:e.location,apply:n=>n.put(Ip(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=a(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),o=n.filter(e=>e.kind===`theorem`);[...i,...o].forEach(n=>{n.isLocal||t.put(Ip(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Ip(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>kr(e.location,t.location)?-1:+!!kr(t.location,e.location))},i=/* @__PURE__ */ new Map,a=e=>{let t=i.get(e??``);if(t)return t;let o=Fp();i.set(e??``,o),lu.toReversed().forEach(e=>o.put(Ip(e,`builtin`,!1)));let s=n(e);return s.getModule().extends.forEach(e=>a(e).inserted.forEach(e=>{e.isLocal||o.put(e)})),r(s).forEach(e=>e.apply(o)),o};return a(void 0).enumerate().filter(e=>e.kind===`variable`).map(e=>e.name).reverse()},Jp=(e,t,n)=>{let r=Kp(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)}),du.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=Bp(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;Up(s(void 0)).forEach((e,t)=>{t===3&&pu.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),Up(s(n)).forEach(a))}Ap.forEach(a);let x=/* @__PURE__ */ new Set,S=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(S),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return S(void 0),fu.forEach(a),[...i]},Yp=(e,t)=>e*((t-e)/2**64),Xp=e=>e.includes(`.`)?e:`${e}.0`,Zp=e=>{let t=Math.abs(e);if(t>=.001&&t<1e7)return Xp(String(e));let[n,r]=e.toExponential().split(`e`);return`${Xp(n)}E${r.replace(`+`,``)}`},Qp=e=>e!==void 0&&e>=`0`&&e<=`9`,$p=e=>{if(e===0)return`0.0`;let t=Zp(e),n={next:0,digits:0,result:``};for(;t[n.next]===`0`;)n.next++;for(;Qp(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(;Qp(t[n.next]);)n.next++;else{if(n.result+=`.`,n.digits===0)for(;t[n.next]===`0`;)n.result+=t[n.next++];for(;Qp(t[n.next])&&n.digits<2;)n.result+=t[n.next++],n.digits++;for(Qp(t[n.next])&&Number(t[n.next])>=5&&(n.result=em(n.result));Qp(t[n.next]);)n.next++}return n.next>=t.length?n.result:t[n.next]===`E`?`${n.result}${t.slice(n.next)}`:t},em=e=>{let t=e.length-1;if(t<0)return`1`;let n=e[t],r=e.slice(0,t);return n===`.`?`${em(r)}.`:n===`9`?`${em(r)}0`:`${r}${Number(n)+1}`},tm=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}`)},nm=(e,t,n)=>{if(Yp(e,t)<1e-10)return;let r=n().sort();return r.reduce((e,t,n)=>{let i=r[n-1];return n>0&&i<0n==t<0n&&t-i<e?t-i:e},9223372036854775807n)},rm=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}).`},im={line:0,column:0},am=`Failed to recover the initial state from its fingerprint.`,om=`Failed to recover the next state from its fingerprint.`,sm=e=>({kind:`Identifier`,name:e,location:im}),cm=/* @__PURE__ */ new Set([`name`,`property`]),lm=(e,t,n)=>{let r=Za(t,n);if(!r)throw new p(`The ${e} ${t} specified in the configuration file\nis not defined in the specification.`);if(r.kind===`Operator`&&r.params.length>0)throw new p(cm.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},um=(e,t,n)=>{let r=lm(e,t,n);if($a(r,n))throw new p(`The ${e} ${t} cannot be a constant.`);return r},dm=(e,t,n)=>{if($a(t,n)&&t.body.kind!==`Number`&&t.body.kind!==`String`)try{return X(sm(e),Am(n,void 0,void 0))}catch(e){if(e instanceof m)return;throw e}},fm=(e,t,n)=>{let r=lm(e,t,n),i=dm(t,r,n);if(i!==void 0&&i!==!0)throw new p(`The ${e} of ${t} is equal to ${U(i)}`);return i===void 0?r:void 0},pm=(e,t)=>{let n=Md({constants:new Set(t.constants.keys()),variables:new Set(t.variables),getDefinition:e=>Za(e,t)});return e.flatMap(e=>{let r=fm(`invariant`,e,t);if(!r)return[];let i=n.analyzeDefinition(r,/* @__PURE__ */ new Map);if(i.level>=2)throw new p(`The invariant ${e} is not a state predicate (one with no primes or temporal operators).${i.params.size===0?``:`
409
+ `]]),hu=/* @__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)`],[`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)`]])]]),gu=(e,t)=>e.every(e=>Jt(e,t)),_u=dt([!1,!0]),vu=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return gt(vu(e,t,r),vu(e,r,n))},yu=[`\\cup`,`\\cap`,`\\`],bu=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),xu=e=>typeof e==`object`&&e.kind===`MixedSet`,Su=e=>e.kind===`Interval`?B(e).elements:e.elements,Cu=(e,t,n)=>{let r=Su(t);if(e!==`\\cup`){let t=e===`\\cap`;return ft(r.filter(e=>Jt(e,n)===t))}if(r.length===0)return n;if(!bu(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!Jt(e,t));return ft([...r,...i])},wu=[Wn(`TRUE`,!0),Wn(`FALSE`,!1),Wn(`BOOLEAN`,_u),Wn(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),qn(`=`,lt),qn(`#`,(e,t)=>!lt(e,t)),K(`~`,1,e=>!In(e,0,`~`)),K(`<=>`,2,e=>In(e,0,`<=>`)===In(e,1,`<=>`)),K(`/\\`,2,e=>In(e,0,`/\\`)&&In(e,1,`/\\`)),K(`\\/`,2,e=>In(e,0,`\\/`)||In(e,1,`\\/`)),K(`=>`,2,e=>!In(e,0,`=>`)||In(e,1,`=>`)),K(`\\in`,2,e=>Jt(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!Jt(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=Ln(e,0,`\\subseteq`),n=Ln(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?gu(B(t.base).elements,n.base):gu(B(t).elements,n)}),...yu.map(e=>K(e,2,t=>{let n=Ln(t,0,e),r=Ln(t,1,e);return bu(n)&&bu(r)&&!xu(n)&&!xu(r)?e===`\\cup`&&V(n)?r:(e===`\\cup`?gt:e===`\\cap`?ht:mt)(B(n),B(r)):bu(n)?Cu(e,n,r):e!==`\\`&&bu(r)?Cu(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:Ln(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=Ln(e,0,`UNION`),n=Ze(t)?t.elements.filter(Ze):[];if(!Ze(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(xu(t)||n.some(xu)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{Jt(t,e)||e.elements.push(t)})),ft(e.elements)}return n.length===0?pt:vu(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!j(t))throw new u(`DOMAIN expects a function but received ${U(t)}`);return nn(t)})],Tu=ir(`DotDot`,`IntervalValue`,2),Eu=ir(`Neg`,`IntValue`,1),Du=[Wn(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),ar(`+`,`Plus`,(e,t)=>e+t),ar(`-`,`Minus`,(e,t)=>e-t),ar(`*`,`Times`,(e,t)=>e*t),ar(`^`,`Expt`,(e,t)=>{if(t<0)throw new d(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new d(`0^0 is undefined.`);return e**t}),ar(`\\div`,`Divide`,(e,t)=>{if(t===0)throw new d(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Jn(n))throw Yn(`${e} \\div ${t}`);return n}),ar(`%`,`Mod`,(e,t)=>{if(t<=0)throw new d(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),sr(`<`,(e,t)=>e<t),sr(`>`,(e,t)=>e>t),sr(`<=`,(e,t)=>e<=t),sr(`>=`,(e,t)=>e>=t),K(`..`,2,e=>({kind:`Interval`,low:rr(G(e,0,`..`),Tu),high:rr(G(e,1,`..`),Tu)}))],Ou=[Wn(`Int`,{kind:`InfiniteSet`,name:`Int`}),K(`-.`,1,e=>{let t=rr(G(e,0,`-`),Eu);if(Jn(-t))throw Yn(`-${t}`);return-t})],ku=(e,t,n)=>{let r=G(e,t,n),i=Gt(r);if(!i)throw new d(`${n}\n${U(r)}`);return i},Au=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:ku(e,t,n)},ju=(e,t,n)=>typeof e==`string`?P(e.slice(t,n)):R(e.slice(t,n)),Mu=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Nu=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,Pu=(e,t)=>{let n=hu.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?nr(e,t):e}):t},Fu=Pu(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>Au(e,0,Mu(``,`Len`)).length),K(`\\o`,2,e=>{let t=Au(e,0,Nu(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=ku(e,1,Nu(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new d(`${Nu(`t \\o s`,`string`)}\n${U(n)}`);return P(t+n)}),K(`Append`,2,e=>R([...ku(e,0,Nu(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=ku(e,0,Mu(``,`Head`));if(t.length===0)throw new d(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=Au(e,0,Mu(``,`Tail`));if(t.length===0)throw new d(`Attempted to apply Tail to the empty sequence.`);return ju(t,1)}),K(`SubSeq`,3,e=>{let t=Au(e,0,Mu(`first `,`SubSeq`)),n=Fn(e,1,`SubSeq`),r=Fn(e,2,`SubSeq`);if(n>r)return ju(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new d(`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 ju(t,n-1,r)}),Gn(`SelectSeq`,2,e=>{let t=Un(e,1,`SelectSeq`);return R(ku(e,0,Mu(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new d(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),Iu=Pu(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(A(t))return Ut(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new u(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${fe(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!A(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new d(`Attempted to compute cardinality of the value\n${U(t)}`);return Vt(t)})]),Lu=/* @__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`]]]),Ru=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:Du};case`Integers`:return{extends:[`Naturals`],operators:Ou};case`Sequences`:return{extends:[],operators:Fu};case`FiniteSets`:return{extends:[],operators:Iu};case`TLC`:return{extends:[],operators:Pu(`TLC`,cu(t,n))};case`Randomization`:return{extends:[],operators:Bl(n)};case`_Possible`:return{extends:[],operators:tu(t,n)};case`Json`:return{extends:[],operators:Pl(r)};case`Bags`:return{extends:[],operators:pl};case`TLCExt`:return{extends:[],operators:eu(t,n)};default:return}},zu=`$subexpression`,Bu=(e,t)=>new c(`${e} at line ${t.line}, column ${t.column}`),Vu=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Hu=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Uu=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}},Wu=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:Mr(e.bounds),body:e.body,sets:Vu(e.bounds)};case`SetMap`:return{names:Mr(e.bounds),body:e.expression,sets:Vu(e.bounds)};case`SetFilter`:return{names:jr(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:jr(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}},Gu=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Gu(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of jn(e)){let e=Gu(r,t,n);if(e)return e}},Ku=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,qu=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Ju=(e,t)=>{let n=e.location,r=qu(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 Bu(`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 Bu(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:zu,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:zu,args:e.args,location:n,resolution:xr},location:n}},Yu=(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:xr})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:xr}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:xr};return Ju({...t,params:[...t.params,...r]},a)},Xu=(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 Bu(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>mi(e)===l):t(l);if(u)return{definition:u,args:Ku(s,Er(u),r)};a.index++}throw Bu(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=Er(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Bu(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Bu(`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&&Gu(a.current,t.name,[]);if(!o)throw Bu(`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(...Ku(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Bu(`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`||Hu(t.operand,1)!==0)throw Bu(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Wu(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(...Ku(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[Hu(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Bu(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Hu(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Bu(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Bu(`Unexpected subexpression selector`,n);let c=s?s.sets:Uu(o),u=c?.[Hu(t.operand,c.length)];if(!u)throw Bu(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Yu(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 Bu(`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 Yu(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Bu(`Subexpression selection failed`,n);return Ju(i,a.current)},Zu=(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:[]}))]},Qu=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||jn(e).some(Qu),$u=(e,t)=>{if(!Qu(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return _i(e,e=>$u(e,n))}let n=_i(e,e=>$u(e,t));if(n.kind===`Subexpression`)return Xu(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Zu(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Xu(i,t,n.location,a);if(a.length>0)throw Bu(`Too many arguments for ${r}`,n.location);return o},ed=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},td=(e,t)=>{let n=ed(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:$u(e.expression,n)}))}},nd=(e,t)=>{let n=ed([...t,...e.definitions]);return e.definitions.some(e=>Qu(e.body))||e.assumptions.some(e=>Qu(e.expression))?{...e,definitions:e.definitions.map(e=>gi(e,e=>$u(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:$u(e.expression,n)}))}:e},rd=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}])),id=(e,t)=>`${e}${t}`,ad=(e,t,n)=>`${e}${t}${n}`,od=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},sd=(e,t,n)=>`${e},${t},${n}`,cd=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),ld=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),ud=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),dd=(e,t,n,r)=>({...cd(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),fd=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,pd=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,md=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,{...dd(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),hd=dd(`$Set`,0,[2],[1]),gd=dd(`$Junction`,0,[3],[1]),_d=dd(`$Choose`,0,[2],[1]),vd=dd(`$Function`,0,[3],[1]),yd=dd(`$FcnApply`,0,[2,2],[1,1]),bd=dd(`$RcdSelect`,0,[2,0],[1,1]),xd=dd(`'`,2,[1],[0]),Sd=dd(`ENABLED`,1,[2],[0]),Cd=dd(`[]`,3,[3],[0]),wd=dd(`$SquareAct`,2,[2,1],[0,0]),Td=dd(`$WF`,3,[1,2],[0,0]),Ed=dd(`$TemporalExists`,3,[3],[0]),Dd=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),Od=e=>e.map(e=>({name:e,arity:0})),kd=(e,t)=>new c(`${e} at line ${t.line}, column ${t.column}`),Ad=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),jd=e=>e.kind!==`Let`&&e.kind!==`Label`,Md=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:_(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:_(i,/* @__PURE__ */ new Map)};let a=md.get(t)??rd.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=cd(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(ad(e,n,t))}),t.data.constraints.forEach((e,t)=>ld(r.constraints,t,e)),ud(r.argConstraints,id(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>ud(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>fd(e,n))throw new c(`Level error in applying operator ${e.name}: The level of argument ${n+1} exceeds the maximum level allowed by the operator.`)}),n.some(e=>e.level>2))throw new c(`Level error in applying operator ${e.name}: The 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(sd(t,n,r)),s=cd(Math.max(e.level,...t.filter((t,n)=>pd(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)=>{pd(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)=>ld(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||ld(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>ld(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||ld(s.constraints,t,fd(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=>ld(s.constraints,e,fd(r,a)))}))}),e.argParams.forEach(e=>{let t=od(e),n=a(t.operator)?.operator;n&&ld(s.constraints,t.param,fd(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>ud(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>ud(s.argConstraints,id(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&ud(s.argConstraints,id(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=od(e),n=a(t.operator);n&&ud(s.argConstraints,id(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(od(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=od(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(ad(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(ad(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(ad(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=g(`LAMBDA`,Od(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=cd();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=Dd(n,Od(a));return i(e,o(t,s),r.map(e=>m(e,n)),a)},l=(e,t)=>e.kind===`Declared`?r(e.name,e.level,t):i(e.levels,t),u=(e,t)=>{let n=e.map(e=>e.data.level);if(n.includes(2)&&n.includes(3))throw kd(`Formula has both temporal formula and action as arguments`,t)},d=(e,t)=>{if((e.operator===`~>`||e.operator===`-+->`)&&t.some(e=>e.data.level===2))throw kd(`Action used where only temporal formula or state predicate allowed`,e.location);Ad.has(e.operator)&&u(t,e.location)},f=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&jd(n)&&n.kind!==r)throw kd(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e.location)},p=(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=_(e,n);t.constraints.forEach((e,t)=>ld(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>ud(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return cd();case`Identifier`:return l(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return d(e,r),l(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 u(n,e.location),i(gd,n)}case`Prime`:case`Unchanged`:return s(xd,[e.expression],t);case`Enabled`:return s(Sd,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return f(e,n.data.level),i(Cd,[n])}case`If`:return s(gd,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(gd,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return p(e,t);case`Forall`:case`Exists`:{let n=s(gd,[e.body],t,e.bounds.map(e=>e.set),Mr(e.bounds));if(n.level===3&&e.bounds.some(e=>m(e.set,t).level===2))throw kd(`Action-level bound of quantified temporal formula`,e.location);return n}case`UnboundedQuantifier`:return s(e.isTemporal?Ed:gd,[e.body],t,[],e.names);case`Choose`:return s(_d,[e.body],t,e.set?[e.set]:[],jr(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(hd,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(hd,[e.predicate],t,[e.bound.set],jr(e.bound.pattern));case`SetMap`:return s(hd,[e.expression],t,e.bounds.map(e=>e.set),Mr(e.bounds));case`FunctionConstruction`:return s(vd,[e.body],t,e.bounds.map(e=>e.set),Mr(e.bounds));case`Record`:return s(vd,e.fields.map(e=>e.value),t);case`RecordSet`:return s(hd,e.fields.map(e=>e.value),t);case`Except`:return s(hd,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(yd,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(hd,e.args,t)}]);case`FieldAccess`:return i(bd,[a(e.record,t),{data:cd()}]);case`BoxAction`:case`AngleAction`:return s(wd,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(Td,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return cd()}},h=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>h(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 jn(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,Dd(t,Od(e.names))),i;default:return _i(e,(e,n)=>(a(e,r,Dd(t,Od(n))),e)),i}},g=(e,t,n,r)=>{let i=Dd(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=h(n,i),c={...cd(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(id(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(ad(e.name,n,t.name))).map(e=>sd(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(od(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=od(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},_=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...cd(),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=g(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:_,toOperand:a}},Nd=(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`?Nd(e,r,n):n.analyze(e,r)}),n.analyze(e.conclusion,r)},Pd=(e,t)=>{let n=Md(t);e.definitions.filter(e=>!e.name.includes(`!`)).forEach(e=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)),e.assumptions.forEach(e=>n.analyze(e.expression,/* @__PURE__ */ new Map)),e.theorems.forEach(e=>e.statement.kind===`AssumeProve`?Nd(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map))},Fd=(e,t)=>e.maxLevels[t]??3,Id=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=Md({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=>ld(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>ld(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>ud(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=od(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(id(t.name,a));o!==void 0&&Fd(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=od(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=Fd(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 c([...o].join(`
410
+ `))},Ld=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 Pe(t.name);case`Set`:return dt(t.elements.map(Ld))}},Rd=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],zd=e=>new c(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),Bd=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:xr},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),Vd=(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 u(`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`)&&Ie(t,r)})});if(t)return t[1];throw new u(`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}},Hd=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||jn(e).some(e=>Hd(e,t)),Ud=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(Ei(e),n.get(e)??n.size)),n},Wd=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),Gd=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw Ba(e);if(e.kind===`Number`&&!Ao(e.value))throw Va(e);Gd(e.kind===`Let`?[...jn(e),...Wd(e.instances??[])]:jn(e))}),Kd=(e,t)=>{let n=lc(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=new Map(wu.map(e=>[e.name,e])),o=/* @__PURE__ */ new Map,s=Wc(e.checkDeadlock,t.seed),u=/* @__PURE__ */ new Map,d=/* @__PURE__ */ new Map,f=[],p=/* @__PURE__ */ new Map,m=[],h=[],g=(e,t)=>m.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),_={value:0},v=e=>`${e}#${_.value++}`,y=[],ee=/* @__PURE__ */ new Map,b=e=>{let n=o.get(e);if(n)return n;let r=Ru(e,t.print,s,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>b(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{a.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),o.set(e,i),i},te=e=>{let t=b(e);return t&&g(e,Lu.get(e)??[]),t},ne=e=>(Gd([...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]),...Wd(e.instances)]),e.modules.forEach(ne),e);ne(n);let re=(e,n)=>{let r=t.loadModule?.(e)??As.get(e)??sc(t.source,e);if(r===void 0)throw new c(`Cannot find source file for module ${e} imported in module ${n}.`);let i=lc(r);if(i.name!==e)throw new c(`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`);return ne(i)},x=e=>{let t=h.indexOf(e.name);if(t!==-1)throw new c(`Circular dependency among .tla files; dependency cycle is: ${[...h.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];h.push(e.name),m.push(n);let i=D(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});m.pop(),h.pop();let a=r.find(e=>n.has(e.name));if(a)throw zd(a);return{linked:i,closure:n}},S=(e,t)=>{let n=u.get(e);if(n)return g(e,p.get(e)??[]),n;let r=x(re(e,t));return u.set(e,r.linked),p.set(e,r.closure),g(e,r.closure),r.linked},ie=(e,t,n,a,o)=>{let s=o?void 0:te(e.module);if(s)return e.name===void 0?s:new Map([...s].map(([t,n])=>[`${e.name}!${t}`,n]));let c=o??S(e.module,t.name),l=Rd(c),u=`#${_.value++}`,d=new Map(e.params.map(e=>[e.name,`${e.name}${u}`])),f=si(td(e,t),l,t,n);y.push({module:e.module,instancer:t.name,lets:[],substitutions:f,location:e.location});let p=Ri({params:e.params.map(e=>({...e,name:`${e.name}${u}`})),substitutions:new Map([...f].map(([e,t])=>[e,di(t,d)])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(e,n)=>{let o=v(`${e}@${t.name}`);return r.set(o,n(o)),i.set(o,!a),o},createName:v}),m=new Set(l.map(e=>e.name)),h=/* @__PURE__ */ new Map;return c.exported.forEach((t,n)=>{if(m.has(n))return;if(e.name===void 0){let r=p.getKey(t.key);l.length>0&&ee.set(r,{name:n,location:e.location}),h.set(n,{key:r,arity:t.arity});return}let r=p.getQualifiedKey(t.key);l.length>0&&ee.set(r,{name:`${e.name}!${n}`,location:e.location}),h.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),h},C=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:xr})),ae=(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:C(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),w=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),oe=(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=w(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:C(r,n),location:n}}},T=(e,t,n,a)=>{let o=e.location,s=a?void 0:te(e.module);if(s)return e.name===void 0?[]:[...s].map(([t,n])=>{let r=w(n.arity);return ae(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??S(e.module,n),l=`#${_.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=Rd(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};y.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=>Hd(f(e),p),h=d.map(t=>{let n=oe(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=[],ee=Ri({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:C(e.params,o),location:o,resolution:xr}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:xr}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n)=>{let r=`${t}@${e.module}${l}.${g.length}`,i=n(r);return g.push(i.kind===`Operator`?{...i,name:r}:Bd(i,r)),r},createName:v}),b=new Set(d.map(e=>e.name)),ne=[...c.exported].filter(([e])=>!b.has(e)).map(([t,n])=>{let r=ee.getKey(n.key),i=w(n.arity),a=[...e.params,...i];return ae(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...ne]},E=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),D=(e,a)=>{let o=Rs(e,t.loadClass?.(e.name)),s=new Map([...wu.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u=[],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:te(e);if(n){g(n,!0);return}let r=t??S(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)),u.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,ee=e=>({imported:s,importedAt:y,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:v}),b=()=>new Map([...a.modules,...l]),ne=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>Tr(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>Tr(t.location,e)).map(e=>[e.name,{key:v(e),arity:Er(e)}])]),re=e=>{let t=b();if(t.has(e.name))throw zd(e);a.nested.push(e);let n=D(e,{id:`${a.id}/${e.name}`,symbols:ne(e.location),modules:t,nested:a.nested});l.set(e.name,n),d.has(e.name)||d.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=ie(e,o,ee(o),_,b().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:()=>re(e)}))].sort((e,t)=>Tr(e.location,t.location)?-1:1).forEach(e=>e.link()),ai(o,ee(o));let x=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&Tr(e.location,t.location)},C=e=>{let t=o.modules.find(t=>t.name===e.module);return t?x(t)?l.get(t.name):void 0:b().get(e.module)},ae=nd(Hi(o,(e,t)=>T(e,t,o.name,C(e))),E(s));ci(ae,ee(ae)),ae.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:Er(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),Pd(ae,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e)});let w={module:ae,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:l,extended:u};return f.push(w),w},O=x(n).linked,se=e=>O.visible.get(e)?.key??e;O.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let k=[],ce=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>ce(e,t)),k.push(...e.module.assumptions))};ce(O,/* @__PURE__ */ new Set);let le=O.constants.map(e=>e.name),ue=O.variables,de=e=>e.module===void 0?[e.name,se(e.name)]:e.module===n.name||le.includes(e.name)?[]:[(u.get(e.module)??d.get(e.module))?.visible.get(e.name)?.key??e.name],A=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:O.constants.find(t=>t.name===e)?.arity??0},j=/* @__PURE__ */ new Map,M=/* @__PURE__ */ new Set,fe=(e,t)=>{a.set(e,t),r.delete(e),j.delete(e),M.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=Ld(e.value);de(e).forEach(e=>{let n=A(e);n===0?j.set(e,t):fe(e,{kind:`Builtin`,name:e,arity:n,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0,isLazy:!0})})});let pe=/* @__PURE__ */ new Map;e.constants.forEach(e=>{if(e.args===void 0)return;let t=`${e.module??``}!${e.name}`,n=pe.get(t)??{name:e.name,module:e.module,rows:[]};if(n.rows.length>0&&n.rows[0][0].length!==e.args.length)throw new l(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(Ld),Ld(e.value)]),pe.set(t,n)}),pe.forEach(e=>de(e).forEach(t=>fe(t,Vd(e.name,A(t)||e.rows[0][0].length,e.rows))));let me=new Map(e.substitutions.flatMap(e=>de(e).map(t=>[t,se(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!le.includes(n)&&!O.visible.has(n))throw new l(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new l(`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 o=se(i),s=r.get(o);if(!(s!==void 0||a.has(o)||j.has(o)||le.includes(i)||ue.includes(i)))throw new l(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(O.constants.find(e=>e.name===n)?.arity??O.visible.get(n)?.arity))throw new l(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)}),le.forEach(e=>{if(!j.has(e)&&!me.has(e)&&!M.has(e))throw new l(`The constant ${e} is not assigned a value by the configuration`)});let he={runtime:s,definitions:r,builtins:a,constants:j,substitutions:me,variables:ue,variableIndex:Ud(ue,f.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};return Id(y,e=>{let t=u.get(e)??d.get(e)??O;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)}}),me.forEach((e,t)=>{let n=r.get(e);if(le.includes(t)&&n&&!Ya(n,he))throw new l(`The configuration file substitutes constant ${t} with non-constant ${e}`)}),{environment:he,assumptions:k,variableLocations:O.variableLocations,instanceActions:ee}},qd={kind:`Boolean`,value:!0},Jd={kind:`Boolean`,value:!1},Yd=e=>e?qd:Jd,Xd=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,Zd=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),Qd=(e,t,n)=>({kind:e,operands:[t,n]}),$d=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?$d(e,t.operands).operands:[t])}),ef=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return ef(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,ef(t)),0)}},tf=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 tf(e.body);case`And`:case`Or`:return e.operands.some(tf)}},nf=(e,t)=>e.kind===t.kind?e.kind===`Boolean`&&t.kind===`Boolean`?e.value===t.value:Xd(e)?e===t:`body`in e&&`body`in t?nf(e.body,t.body):`operands`in e&&`operands`in t&&e.operands.length===t.operands.length&&e.operands.every((e,n)=>nf(e,t.operands[n])):!1,rf=(e,t)=>e.some(e=>nf(e,t)),af=e=>e===`And`?`Or`:`And`,of=(e,t)=>{switch(e.kind){case`Boolean`:return t?Yd(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return of(e.body,!t);case`And`:case`Or`:return $d(t?af(e.kind):e.kind,e.operands.map(e=>of(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,of(e.body,t))}}},sf=e=>{switch(e.kind){case`Boolean`:return Yd(!e.value);case`Not`:return e.body;case`And`:case`Or`:return $d(af(e.kind),e.operands.map(sf));case`Always`:return Q(`Eventually`,sf(e.body));case`Eventually`:return Q(`Always`,sf(e.body));default:return Q(`Not`,e)}},cf=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=cf(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return Yd(t)}return n.length===0?Yd(!t):n.length===1?n[0]:$d(e.kind,n)}case`Not`:{let t=cf(e.body);return t.kind===`Boolean`?Yd(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=cf(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},lf=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,uf=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=uf(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new u(`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=>$d(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=uf(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=lf(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:$d(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return $d(`Or`,n)}case`Not`:return Xd(e.body)?e:uf(sf(e.body));default:return e}},df=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?df(e.operands[0]):$d(e.kind,e.operands.map(df));case`Not`:return e.body.kind===`Not`?df(e.body.body):Q(`Not`,df(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,df(e.body));default:return e}},ff=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return ff(e.operands[0]);let t=Math.floor(e.operands.length/2);return Qd(e.kind,ff($d(e.kind,e.operands.slice(0,t))),ff($d(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,ff(e.body));default:return e}},pf=(e,t)=>{e.kind===`Eventually`&&!rf(t,e)&&t.push(e),`body`in e&&pf(e.body,t),`operands`in e&&e.operands.forEach(e=>pf(e,t))},mf=e=>{let t=e.filter(Zd),n=e.flatMap(e=>e.kind===`Not`&&Zd(e.body)?[e.body]:[]);return!t.some(e=>rf(n,e))},hf=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 u(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},gf=(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]}},_f=(e,t,n)=>e.flatMap(e=>{let r=gf(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),vf=(e,t)=>e.every(e=>rf(t,e))&&t.every(t=>rf(e,t)),yf=(e,t)=>[...e.filter(e=>!t.some(t=>vf(e,t))),...t],bf=e=>{let t=hf(e),n=_f(t,`Always`,`And`),r=_f(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=gf(t,`Eventually`,`Or`);if(n&&!(rf(e,n.first)||rf(e,n.second)))return yf(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(rf(e,t.first)||rf(e,t.second))&&!rf(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!mf(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=gf(t[e],`Always`,`And`);n&&(rf(t,n.first)||t.push(n.first),rf(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)rf(t,e.first)&&rf(t,e.second)&&!rf(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!mf(t)?[]:i(t)};return a(e)},xf=e=>({particle:e,successors:[],statePredicates:e.filter(e=>ef(e)<=1)}),Sf=e=>{let t=bf([e]).map(xf),n=t.length;for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let r of bf(n)){let n=t.findIndex(e=>vf(e.particle,r));n===-1&&t.push(xf(r)),t[e].successors.push(n===-1?t.length-1:n)}}return{nodes:t,initialCount:n}},Cf=(e,t)=>!rf(e,t)||rf(e,t.body),wf=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&ef(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=lf(e);if(n){let e=ef(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(tf(e))throw new u(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},Tf=(e,t)=>{let n=e.findIndex(e=>nf(e,t));return n===-1?(e.push(t),e.length-1):n},Ef=e=>{let t=uf(cf(of(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=df(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])wf(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:$d(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:nf(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&ff(e.formula),n=[];t&&pf(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>Tf(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>Tf(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>Tf(i,e))}));return{tableau:t&&Sf(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Df=/* @__PURE__ */ new Set([`~>`,`-+->`]),Of=/* @__PURE__ */ new WeakMap,kf=/* @__PURE__ */ new WeakSet,Af=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),jf=e=>new u(`TLC cannot handle the temporal formula at ${J(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Ha(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=qa(e,n);if(t)return Mf(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 _i(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 Df.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},Mf=(e,t)=>{let n=Of.get(e);if(n!==void 0)return n;Of.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 Of.set(e,i),i},Nf=(e,t,n,r,i=/* @__PURE__ */ new Set)=>{let a=(e,t,a=i)=>Nf(e,t,n,r,a);if(e.kind===`And`)return e.operands.flatMap(e=>a(e,t));if(e.kind===`Label`)return a(e.body,t);if(e.kind===`Let`)return a(e.body,Pf(e,t,n));if(e.kind===`Identifier`){let r=W(e)?Ha(t,e.name):void 0;if(r?.kind===`Thunk`)return a(r.expression,r.scope);let o=n.constants.has(e.name)?void 0:qa(e.name,n);if(!r&&o?.kind===`Operator`&&o.params.length===0&&Mf(o,n)>0){if(i.has(o))throw new l(`The definition of ${e.name} refers to itself`);return a(o.body,void 0,/* @__PURE__ */ new Set([...i,o]))}}let o=Af(n,t);if(e.kind===`Apply`&&$(e,t,n)===3){let t=mo(e,o),r=W(e)?void 0:qa(e.operator,n);if(t?.kind===`Closure`&&!r?.isRecursive)return a(t.body,Eo(t,e.args,o))}if(r&&e.kind===`Forall`&&$(e.body,t,n)===3&&e.bounds.every(e=>$(e.set,t,n)===0)){let t=[];return Qa(e.bounds,o,n=>(t.push(...a(e.body,n)),!1)),t}return[{expression:e,scope:t}]},Pf=(e,t,n)=>{let r=Oo(e.definitions,Af(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&kf.add(e.binding);return r},Ff=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),If=(e,t,n)=>{let r=(e,t,r)=>{let i=r===0?$(e,t,n):r;if(i===0){let r=X(e,Af(n,t));if(typeof r!=`boolean`)throw new u(`TLC expected a boolean in the temporal formula at ${J(e)}`);return Yd(r)}return i===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},i={depth:0},a=(e,t,n,a)=>{if(i.depth>=100)throw new u(`TLC overflowed the stack while expanding the temporal formula at ${J(n)}`);i.depth++;let o=c(e,t);i.depth--;let s=ef(o);return s>2?o:r(n,a,s)},o=(e,t)=>{let r=e.kind===`Identifier`?e.name:e.operator,i=Af(n,t),o=W(e)||qa(r,n)===void 0?Ha(t,r):void 0;if(o?.kind===`Thunk`&&kf.has(o))return a(o.expression,o.scope,e,t);let s=o?.kind===`Operator`?o.operator:o?void 0:W(e)?ho(r,i):fo(r,n);if(s?.kind!==`Closure`)throw jf(e);let c=e.kind===`Apply`?e.args:[];return a(s.body,Eo(s,c,i),e,t)},s=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,n)===0))throw jf(e);let i=[];Qa(e.bounds,Af(n,t),t=>(i.push(c(e.body,t)),!1));let a=e.kind===`Forall`;if(i.length===0)return Yd(a);let o=$d(a?`And`:`Or`,i),s=ef(o);return s>2?o:r(e,t,s)},c=(e,t)=>{let i=$(e,t,n);if(i<=2)return r(e,t,i);switch(e.kind){case`Label`:return c(e.body,t);case`Let`:return c(e.body,Pf(e,t,n));case`Identifier`:return o(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,Qd(`Or`,Q(`Not`,c(n[0],t)),Q(`Eventually`,c(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,c(n[0],t)):e.operator===`=>`?Qd(`Or`,Q(`Not`,c(n[0],t)),c(n[1],t)):o(e,t)}case`And`:case`Or`:return $d(e.kind,e.operands.map(e=>c(e,t)));case`Forall`:case`Exists`:return s(e,t);case`If`:{if($(e.condition,t,n)===0){let r=X(e.condition,Af(n,t));if(typeof r==`boolean`)return c(r?e.consequent:e.alternative,t)}let r=c(e.condition,t);return Qd(`Or`,Qd(`And`,r,c(e.consequent,t)),Qd(`And`,Q(`Not`,r),c(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,c(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=Ff(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`,Qd(`Or`,i,a))):Qd(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw jf(e)}};return c(e,t)},Lf=(e,t,n,r,i)=>{let a=e=>Lf(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`?Ka(X(e.expression,a),`a temporal property predicate`):Oa(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&&Ka(X(e.unchanged,a),`a subscript`)?!1:Ka(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 Lf(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new u(`TLC cannot evaluate a temporal formula in a single step`)}},Rf=(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)=>Rf(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 Lf(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},zf=/* @__PURE__ */ new WeakMap,Bf={value:0},Vf=e=>{let t=zf.get(e);if(t!==void 0)return t;let n=e.kind===`Boolean`?String(e.value):`body`in e?`${e.kind}(${Vf(e.body)})`:`operands`in e?`${e.kind}(${e.operands.map(Vf).join(`,`)})`:`${e.kind}#${Bf.value++}`;return zf.set(e,n),n},Hf=(e,t)=>e.every((e,n)=>Re(e,t[n])),Uf=e=>e.filter((t,n)=>n===0||e[n-1]!==t),Wf=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.successors.push([]),e.actions.push(/* @__PURE__ */ new Uint8Array),e.stateResults.push(/* @__PURE__ */ new Uint8Array),e.isWritten.push(!1),e.nodeStates.length-1),Gf=2**53-1,Kf=(e,t,n,r)=>{if(e.length===0)return;let i=t.map(e=>If(e.expression,e.scope,n)),a=e.map(e=>Q(`Not`,If(e.expression,e.scope,n))),o=a.length===1?a[0]:$d(`Or`,a),s=i.length===0?o:$d(`And`,[...i,o]),c=Ef(s);if(c.length===0)throw new u(`Temporal formula is a tautology (its negation is unsatisfiable)`);let l=/* @__PURE__ */ new Map,d=c.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=Vf(e),n=l.get(t)??l.size;return l.set(t,n),n}),nodeStates:[],nodeTableaux:[],successors:[],actions:[],stateResults:[],isWritten:[],initial:[],nodeIds:/* @__PURE__ */ new Map,nodesByState:/* @__PURE__ */ new Map,isDone:[],errorNode:void 0})),f={multiplier:1},p=!Bo(n),m={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},h=e=>{let t=m.states.get(e)??/* @__PURE__ */ new Map;return m.states.set(e,t),t},g=(e,t)=>{n.runtime.setLivenessSource(e);let r=t();return n.runtime.setLivenessSource(void 0),r},_=(e,t)=>Lf(e,t,void 0,n,p?h(t):/* @__PURE__ */ new Map),v=(e,t,n)=>g(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!_(e,n))),y=(e,t,r,i)=>g(t,()=>{let t=e.solution.actionChecks;if(!p)return Uint8Array.from(t,e=>+!!Lf(e,r,i,n,/* @__PURE__ */ new Map));let a=h(r),o=m.actions.get(r)??/* @__PURE__ */ new Map;m.actions.set(r,o);let s=o.get(i)??new Int8Array(l.size).fill(-1);return o.set(i,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!Lf(t[o],r,i,n,a)),s[e]))}),ee=(e,t,n,r)=>g(n,()=>e.nodes[t].statePredicates.every(e=>_(e,r))),b=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},te=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),ne=(e,t,n)=>e.solution.tableau?e.nodeIds.get(t*e.solution.tableau.nodes.length+n):t,re=(e,t,n)=>{let r=Wf(e,t,n);e.nodeIds.set(t*(e.solution.tableau?.nodes.length??1)+n,r);let i=e.nodesByState.get(t);return i?i.push(r):e.nodesByState.set(t,[r]),r},x=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=new Uint8Array(n.length*i);n.forEach((e,t)=>a.set(e,t*i)),e.actions[t]=a,e.stateResults[t]=r,e.isWritten[t]=!0},S=(e,t,n)=>{let i={slots:Array.from({length:16*f.multiplier}),count:0},a=(e,t)=>{for(let n=(r.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&&Hf(r.state,t.state))return!1}},o=e=>{if(i.count>=i.slots.length>>1){let e=i.slots;i.slots=Array.from({length:2*e.length+1});for(let t of e)t&&a(i.slots,t)}a(i.slots,e)&&i.count++};return n.forEach(o),o({index:e,state:t}),i.slots.length>16*f.multiplier&&f.multiplier++,i.slots.filter(e=>e!==void 0)},ie=(e,t,n,i,a)=>{let o=v(e,i,n),s=t.nodes[e.nodeTableaux[a]],c=[],l=e.successors[a],u=s.successors.length>0?y(e,i,n,n):/* @__PURE__ */ new Uint8Array;for(let r of s.successors){if(!ee(t,r,i,n))continue;if(b(t,r)&&e.errorNode===void 0&&te(e)){e.errorNode=a;return}let o=ne(e,i,r);if(o!==void 0&&l.includes(o))continue;let s=o??re(e,i,r);l.push(s),c.push(u),o===void 0&&ie(e,t,n,i,s)}for(let a of r.getSuccessors(n)){let r=y(e,i,n,a.state),o=e.isDone[a.index]===!0;for(let n of s.successors){if(!ee(t,n,i,a.state))continue;let s=ne(e,a.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??re(e,a.index,n);l.push(u),c.push(r),s===void 0&&o&&ie(e,t,a.state,a.index,u)}}l.length>0&&x(e,a,c,o)},C=(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(e.nodesByState.get(a)??[]).slice()){let a=e.successors[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=ne(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??re(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&ie(e,t,n.state,n.index,d)}}),x(e,s,c,i)}if(e.errorNode!==void 0)return Uf(w(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},ae=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)Wf(e,e.nodeStates.length,-1);let a=e.successors[i],o=[];t.forEach((t,r)=>{e.isWritten[t.index]&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),x(e,i,o,r)},w=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)e.isWritten[t]&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of e.successors[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}e.isWritten[i]&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new u(`Couldn't re-create liveness trace (path) starting at: ${t}`)},oe=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=(t,n,i)=>e.actions[t][n*r+i]===1,a=(e,n)=>t.eventuallyAlways.every(t=>i(e,n,t)),o=new Float64Array(e.nodeStates.length).fill(-1),s=e.initial.filter(t=>e.isWritten[t]),c=[],l=t=>{let n=e.successors[t].indexOf(t);return n!==-1&&a(t,n)},d=(t,r)=>n.tableau!==void 0&&Cf(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let s=c.pop()??r;if(s===r&&!l(s)){o[s]=Gf;return}let u=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=s;;t=c.pop()??r){u.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),o[t]=Gf,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...u].some(n=>e.stateResults[n][t]===1)),h=t.infinitelyOftenActions.every(t=>[...u].some(n=>e.successors[n].some((e,r)=>u.has(e)&&a(n,r)&&i(n,r,t)))),g=n.promises.every(e=>[...u].some(t=>d(t,e)));if(m&&h&&g)return p(r,u,f)},p=(r,o,s)=>{let c=Uf(w(e,r).reverse().map(t=>e.nodeStates[t])),l=[],f=/* @__PURE__ */ new Set([r]),p=t.infinitelyOftenStates.map(()=>!1),h=t.infinitelyOftenActions.map(()=>!1),g=n.promises.map(()=>!1),_={count:p.length+h.length+g.length},v={node:r},y=e=>o.has(e),ee=e=>{l.push(v.node),v.node=e};for(;_.count>0;){let r=_.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!p[n]&&e.stateResults[v.node][t]===1&&(p[n]=!0,_.count--)}),n.promises.forEach((e,t)=>{!g[t]&&d(v.node,e)&&(g[t]=!0,_.count--)}),!(_.count<=0);){let n={last:-1,unvisited:-1},o=_.count;if(e.successors[v.node].some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!a(v.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!h[t]&&i(v.node,c,e)&&(h[t]=!0,_.count--)})}return _.count<o?(ee(r),f.clear(),!0):(y(r)&&!f.has(r)&&(n.unvisited=r),!1)}))break;if(_.count<r){ee(n.last),f.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new u(`TLC failed to build the counterexample of a liveness property`);v.node=t,n.unvisited=e.successors[t].find(e=>y(e)&&!f.has(e))??-1}ee(n.unvisited),f.add(n.unvisited)}}let b=m(r,v.node,s,a);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];b[b.length-1]!==n&&b.push(n)}let te=c[c.length-1];return b[b.length-1]===te&&b.pop(),{prefix:c.slice(0,-1),cycle:[te,...b.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,d=0;;d++){for(let u of r.get(n)??[])for(let[d,f]of e.successors[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 f=c[d];if(f===void 0)throw new u(`TLC failed to build the counterexample of a liveness property`);n=f[0],l=f[1]}};for(let t=0;t<s.length;t++){let n=[s[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),l=n.pop()??0;if(i===-42){if(o[l]===t){let e=f(l);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(o[l]!==-1){n.push(Math.min(t,o[l]));continue}o[l]=r.link,n.push(t,l,-42),c.push(l);let u={value:r.link++};e.successors[l].forEach((t,r)=>{e.isWritten[t]&&(a(l,r)?o[t]===-1?n.push(t,-1):u.value=Math.min(u.value,o[t]):o[t]===-1&&s.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{m.states.clear(),m.actions.clear();for(let n of d){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(ne(n,e,i)??re(n,e,i))}},addState:(e,t,n)=>{m.states.clear(),m.actions.clear();let r=S(e,t,n);for(let n of d){let i=r.map(r=>y(n,e,t,r.state)),a=v(n,e,t),o=n.solution.tableau,s=o?C(n,o,r,i,a,e):ae(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of d)for(let t of e.solution.models){let n=oe(e,t);if(n)return n}},getViolatedProperties:(t,r)=>[...new Set(e.filter((e,i)=>!Rf(a[i].body,t,r,0,n)).map(e=>e.name))]}},qf=`UnnamedAction`,Jf={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},Yf=e=>{let t=e.range??Jf;return Dt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},Xf=e=>{let t=[[`name`,e.name],[`location`,Yf(e.location)]];return e.parameters.length===0?Dt(t):Dt([...t,[`context`,Dt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},Zf=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),Qf=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),$f=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,ep=e=>e.kind===`Apply`?e.args:[],tp=(e,t,n)=>{let r=$f(e);if(r===void 0)return;if(W(e)){let e=Ha(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=fo(r,n);return i?.kind===`Closure`?i:void 0},np=(e,t)=>{try{return X(e,Qf(t,void 0)),!0}catch(e){if(e instanceof s)return!1;throw e}},rp=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&Ya(e,t)&&np(e.body,t),ip=(e,t)=>{let n=qa(e.name,t);return n?.body===e.body&&rp(n,t)},ap=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Ha(t,e.name);return n?.kind===`Thunk`?n:void 0},op=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Ha(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),sp=(e,t)=>{try{return e()}catch(e){if(e instanceof s)return t();throw e}},cp=(e,t,n,r,i)=>{let a=ep(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():sp(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,Qf(i,n))]),expression:t,scope:n}],o)},lp=(e,t,n,r,i)=>{let a=()=>({name:n?.name??qf,location:e.location,parameters:op(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return lp(e.body,Oo(e.definitions,Qf(r,t)),n,r,i);case`Label`:return lp(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>lp(e,t,n,r,i));case`Exists`:return sp(()=>{let o=[];return Qa(e.bounds,Qf(r,t),t=>(o.push(...lp(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get($f(e)??``),s=tp(e,t,r);if(o)return cp(o,e,t,s,r);if(!s)return[a()];let c=ep(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return ip(s,r)||c.some(e=>$(e,t,r)!==0)?l():sp(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,Qf(r,t))},parent:e}),s.scope);return lp(s.body,e,s,r,i)},l)},up=(e,t,n,r,i)=>{let a=(e,t)=>up(e,t,n,r,i);if(e.kind===`Let`){a(e.body,Oo(e.definitions,Qf(n,t)));return}let o=ap(e,t);if(o){a(o.expression,o.scope);return}let s=tp(e,t,n);if(s&&ip(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(Zf(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,Eo(s,e.args,Qf(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(Zf(qf,e));return}let c=$(e,t,n);c<=1?r.inits.push(Zf(qf,e)):c===3&&r.temporals.push(Zf(qf,e))},dp=(e,t,n,r,i)=>{let a=(t,n)=>dp(e,t,n,r,i);if(t.kind===`Let`){a(t.body,Oo(t.definitions,Qf(r,n)));return}let o=ap(t,n);if(o){a(o.expression,o.scope);return}let s=tp(t,n,r);if(s&&ip(s,r))return;if(s&&s.params.length===ep(t).length){a(s.body,t.kind===`Apply`?Eo(s,t.args,Qf(r,n)):s.scope);return}if(t.kind===`Forall`&&sp(()=>(Qa(t.bounds,Qf(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(Zf(e,a)):$(a,n,r)<2?i.invariants.push(Zf(e,a)):i.impliedTemporals.push(Zf(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(Zf(e,t)):c===3&&i.impliedTemporals.push(Zf(e,t))},fp=(e,t)=>{let n=qa(e,t);return n?.kind===`Operator`&&!rp(n,t)?n:void 0},pp=e=>Dt([[`name`,e.name],[`location`,Yf(e.location)]]),mp=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:fp(e.specification,t);a&&(up(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...lp(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:fo(e.init,t);o?.kind===`Closure`&&r.inits.push(Zf(e.init??``,o.body));let s=e.next===void 0?void 0:fo(e.next,t);return s?.kind===`Closure`&&r.actions.push(...lp(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=fp(e,t);n&&r.invariants.push(Zf(e,n.body))}),e.properties.forEach(e=>{let n=fp(e,t);n&&dp(e,n.body,void 0,t,r)}),r},hp=(e,t,n)=>mp(e,t,n).actions,gp=e=>{let t=e.parameters.map(e=>U(e[1]));return`${e.name===qf?`Action`:e.name}${t.length===0?``:`(${t.join(`,`)})`} ${Na(e.location.range??Jf)}`},_p=(e,t,n,r)=>{let i=mp(e,t,r),a=e=>dt(e.map(Xf)),o=e=>dt(e.flatMap(e=>{let n=fp(e,t);return n?[pp(n)]:[]}));return Dt([[`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`,dt(t.variables.map((e,t)=>Dt([[`name`,e],[`location`,Yf(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},vp=e=>[...e].map(([e,t])=>`${e}>${t.name}`).sort().join(`,`),yp=(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},bp=(e,t)=>{if(!j(e))throw new l(`The symmetry values of ${t} must be functions`);let n=H(e),r=/* @__PURE__ */ new Map;return n.domain.forEach((e,t)=>{let i=n.range[t];if(!M(e)||!M(i))throw new l(`Symmetry function must have model values as domain and range`);e.name!==i.name&&r.set(e.name,i)}),r},xp=(e,t)=>{let n=t.definitions.get(e);if(n?.kind!==`Operator`||n.params.length>0)throw new l(`The symmetry function ${e} must specify a set of permutations`);let r=X(n.body,{environment:t,scope:void 0,state:void 0,next:void 0});if(!A(r)||!z(r))throw new l(`The symmetry operator must specify a set of functions`);let i=B(r).elements.map(t=>bp(t,e));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(vp(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=yp(n,e),r=vp(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}))},Sp=(e,t)=>{for(let n=0;n<e.length;n++){let r=e[n],i=Tp(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(Tp(e[r],t));return a}},Cp=(e,t)=>{let n=[],r=[];for(let i of e){let e=Tp(i,t);e===i?n.push(i):r.push(e)}if(r.length===0)return;r.sort(I);let i=[],a=0,o=0;for(;a<n.length&&o<r.length;)i.push(I(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},wp=e=>e.kind===`Set`?e.elements.length:e.kind===`Function`?e.domain.length:0,Tp=(e,t)=>{if(typeof e!=`object`)return e;if(e.kind===`ModelValue`)return t.images.get(e.name)??e;let n=wp(e);if(n===0||n>64)return Ep(e,t);let r=t.cache.get(e);if(r!==void 0)return r;let i=Ep(e,t),a=i!==e&&Re(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},Ep=(e,t)=>{let n=e.kind;if(n===`Set`){let n=Cp(e.elements,t);return n?Fe(n):e}if(n===`Function`||n===`LazyFunction`&&z(e.domain)){let n=H(e),r=Sp(n.domain,t),i=Sp(n.range,t)??n.range;if(r){let e=_t(r.map((e,t)=>[e,i[t]]));return e.domain.every((e,t)=>e===n.domain[t])?L(n.domain,e.range):e}return i===n.range?n:L(n.domain,i)}if(n===`Interval`||!A(e)||!z(e))return e;let r=B(e),i=Sp(r.elements,t);return i?dt(i):r},Dp=(e,t,n)=>{for(let r=t.length;r<e.length;r++)t.push(Tp(e[r],n));return t},Op=(e,t,n,r)=>{let i=[];for(let a=0;a<e.length;a++){let o=r?r[a]:a,s=Tp(e[o],n),c=I(s,t[o]);if(c>0)return;if(r||i.push(s),c<0)return r?e.map(e=>Tp(e,n)):Dp(e,i,n)}},kp=(e,t,n)=>t.reduce((t,r)=>Op(e,t,r,n)??t,e),Ap=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],jp=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Mp=new Map(uu.flatMap(e=>e.map(t=>[t,e[0]]))),Np=e=>Mp.get(e)??e,Pp=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Fp=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Pp(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()}},Ip=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Lp=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Np(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Np(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}},Rp=(e,t)=>{let n=[];for(let r=t;;){let t=Lp(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},zp=e=>({line:e.line,column:e.column}),Bp=(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=Rp(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},Vp=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Hp={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Up=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Vp(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Vp(e[n+1],e[n+2])?n+=Vp(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=>Hp[e])}"`:r.text)}return t},Wp=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},Gp=(e,t)=>e.find(e=>e.name===t)??e.map(e=>Gp(e.modules,t)).find(Boolean),Kp=(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:mu.get(i)??t?.(i)??sc(e,i),s=o===void 0?[]:oe(o),c=Wp(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=lc(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>Gp(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},qp=(e,t)=>{let n=Kp(e,t),r=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],o=(e,n)=>{let i=Rp(t,e+1);r.push({location:zp(t[e]),apply:e=>i.forEach(t=>e.put(Ip(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,a)=>{let l=e.start+a,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:zp(u),apply:t=>t.put(Ip(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&o(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&o(l,`variable`),u.text===`RECURSIVE`&&Rp(t,l+1).every(e=>s.has(e))&&o(l,`definition`),jp.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(zp(u)),r.push({location:zp(u),apply:e=>e.put(Ip(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(Ip(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=Np(e.name);r.push({location:e.location,apply:n=>n.put(Ip(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=a(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),o=n.filter(e=>e.kind===`theorem`);[...i,...o].forEach(n=>{n.isLocal||t.put(Ip(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Ip(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>Tr(e.location,t.location)?-1:+!!Tr(t.location,e.location))},i=/* @__PURE__ */ new Map,a=e=>{let t=i.get(e??``);if(t)return t;let o=Fp();i.set(e??``,o),lu.toReversed().forEach(e=>o.put(Ip(e,`builtin`,!1)));let s=n(e);return s.getModule().extends.forEach(e=>a(e).inserted.forEach(e=>{e.isLocal||o.put(e)})),r(s).forEach(e=>e.apply(o)),o};return a(void 0).enumerate().filter(e=>e.kind===`variable`).map(e=>e.name).reverse()},Jp=(e,t,n)=>{let r=Kp(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)}),du.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=Bp(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;Up(s(void 0)).forEach((e,t)=>{t===3&&pu.forEach(a),a(e)});let ee=u(void 0);for(;;){let e=g(ee,/* @__PURE__ */ new Set)??_(ee,/* @__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),Up(s(n)).forEach(a))}Ap.forEach(a);let b=/* @__PURE__ */ new Set,te=e=>{if(b.has(e))return;b.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(te),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return te(void 0),fu.forEach(a),[...i]},Yp=(e,t)=>e*((t-e)/2**64),Xp=e=>e.includes(`.`)?e:`${e}.0`,Zp=e=>{let t=Math.abs(e);if(t>=.001&&t<1e7)return Xp(String(e));let[n,r]=e.toExponential().split(`e`);return`${Xp(n)}E${r.replace(`+`,``)}`},Qp=e=>e!==void 0&&e>=`0`&&e<=`9`,$p=e=>{if(e===0)return`0.0`;let t=Zp(e),n={next:0,digits:0,result:``};for(;t[n.next]===`0`;)n.next++;for(;Qp(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(;Qp(t[n.next]);)n.next++;else{if(n.result+=`.`,n.digits===0)for(;t[n.next]===`0`;)n.result+=t[n.next++];for(;Qp(t[n.next])&&n.digits<2;)n.result+=t[n.next++],n.digits++;for(Qp(t[n.next])&&Number(t[n.next])>=5&&(n.result=em(n.result));Qp(t[n.next]);)n.next++}return n.next>=t.length?n.result:t[n.next]===`E`?`${n.result}${t.slice(n.next)}`:t},em=e=>{let t=e.length-1;if(t<0)return`1`;let n=e[t],r=e.slice(0,t);return n===`.`?`${em(r)}.`:n===`9`?`${em(r)}0`:`${r}${Number(n)+1}`},tm=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}`)},nm=(e,t,n)=>{if(Yp(e,t)<1e-10)return;let r=n().sort();return r.reduce((e,t,n)=>{let i=r[n-1];return n>0&&i<0n==t<0n&&t-i<e?t-i:e},9223372036854775807n)},rm=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}).`},im={line:0,column:0},am=`Failed to recover the initial state from its fingerprint.`,om=`Failed to recover the next state from its fingerprint.`,sm=e=>({kind:`Identifier`,name:e,location:im}),cm=/* @__PURE__ */ new Set([`name`,`property`]),lm=(e,t,n)=>{let r=qa(t,n);if(!r)throw new l(`The ${e} ${t} specified in the configuration file\nis not defined in the specification.`);if(r.kind===`Operator`&&r.params.length>0)throw new l(cm.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},um=(e,t,n)=>{let r=lm(e,t,n);if(Ya(r,n))throw new l(`The ${e} ${t} cannot be a constant.`);return r},dm=(e,t,n)=>{if(Ya(t,n)&&t.body.kind!==`Number`&&t.body.kind!==`String`)try{return X(sm(e),Am(n,void 0,void 0))}catch(e){if(e instanceof u)return;throw e}},fm=(e,t,n)=>{let r=lm(e,t,n),i=dm(t,r,n);if(i!==void 0&&i!==!0)throw new l(`The ${e} of ${t} is equal to ${U(i)}`);return i===void 0?r:void 0},pm=(e,t)=>{let n=Md({constants:new Set(t.constants.keys()),variables:new Set(t.variables),getDefinition:e=>qa(e,t)});return e.flatMap(e=>{let r=fm(`invariant`,e,t);if(!r)return[];let i=n.analyzeDefinition(r,/* @__PURE__ */ new Map);if(i.level>=2)throw new l(`The invariant ${e} is not a state predicate (one with no primes or temporal operators).${i.params.size===0?``:`
411
411
  Note that a bug can cause TLC to incorrectly report this error.
412
412
  If you believe your TLA+ or PlusCal specification to be correct,
413
- please check if this bug described in LevelNode.java starting at line 590ff affects you.`}`);return[{name:e,expression:sm(e),scope:void 0}]})},mm=(e,t)=>{if(!M(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])))},hm=(e,t)=>{if(e.kind===`And`)return e.operands.flatMap(e=>hm(e,t));if(e.kind===`Identifier`&&!t.constants.has(e.name)){let n=Za(e.name,t);if(n?.kind===`Operator`&&n.params.length===0)return hm(n.body,t)}return[e]},gm=(e,t,n)=>{let r=e.expression;if(r.kind!==`Identifier`||$(r,e.scope,t)>0)return!1;let i=X(r,Am(t,void 0,void 0,e.scope));if(i===!1)throw new p(`The spec is trivially false because ${r.name} is false.`);if(i!==!0)throw new p(`The operator ${r.name}, which equals ${U(i)},\ncannot be used as a ${n}`);return!0},_m=(t,n)=>{if(t.specification===void 0){let e=(e,t)=>{if(e===void 0)return;let r=lm(t,e,n).body,i=sm(e);if(r.kind!==`Number`&&r.kind!==`String`&&$(i,void 0,n)===0)throw new p(`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 r=[],i=[],o=[],s=lm(`name`,t.specification,n),c=dm(t.specification,s,n);if(c!==void 0)throw new p(`The value of ${t.specification} is equal to ${U(c)}`);if(Nf(s.body,void 0,n,!1).forEach(s=>{let c=s.expression;if(gm(s,n,`spec`))return;if(c.kind===`UnboundedQuantifier`&&c.isTemporal)throw a(new p(`TLC does not support temporal existential, nor universal, quantification over state variables.`),e.error);if(c.kind===`Always`&&c.expression.kind===`BoxAction`){i.push({expression:c.expression.action,scope:s.scope});return}if(c.kind===`Always`&&$(c.expression,s.scope,n)<2)throw new p(`TLC cannot handle []P in the specification ${t.specification} when P is a state predicate`);let l=$(c,s.scope,n);if(l===3)o.push(s);else{if(l===2)throw new p(`TLC cannot handle the action-level conjunct of the specification ${t.specification}`);r.push(s)}}),i.length>1)throw new p(`The specification ${t.specification} must contain at most one [][Next]_vars`);let l=[...r,...i],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:r.length===0?void 0:{kind:`And`,operands:r.map(f),location:im},next:i.length===0?void 0:f(i[0],r.length),scope:d,temporals:o}},vm=(e,t)=>{let n={initialPredicates:[],invariants:[],actionProperties:[],liveness:[]};return e.properties.forEach(e=>{let r=fm(`property`,e,t);r&&Nf(r.body,void 0,t,!0).forEach(r=>{let i=r.expression;if(gm(r,t,`property`))return;if(i.kind===`Always`&&i.expression.kind===`BoxAction`){n.actionProperties.push({name:e,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){n.invariants.push({name:e,expression:i.expression,scope:r.scope});return}let a=$(i,r.scope,t);if(a<2)n.initialPredicates.push({name:e,expression:i,scope:r.scope});else{if(a===2)throw new p(`The property ${e} is an action-level formula`);n.liveness.push({name:e,expression:i,scope:r.scope})}})}),n},ym=(e,t,n)=>t.flatMap(t=>fm(e,t,n)?[{name:t,expression:sm(t),scope:void 0}]:[]),bm=(e,t)=>{let n=Za(e,t);return n?.kind===`Operator`?n.bodyRange:void 0},xm=(e,t)=>e.map((n,r)=>{if(e.indexOf(n)!==r)throw new p(`_POSSIBLE lists ${n} more than once`);um(`possible`,n,t);let i=sm(n);if($(i,void 0,t)===3)throw new p(`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}}),Sm=(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},Cm=(e,t)=>e.flatMap(e=>hm(e.expression,t).map(n=>{let r=ks(n,t);return{name:e.name,expression:n,scope:e.scope,variables:r,membership:Sm(n,r,t)}})),wm=(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},Tm=/[\u0100-\uffff]/,Em=/* @__PURE__ */ new Set([`JsonDeserialize`,`ndJsonDeserialize`]),Dm=e=>e.kind===`String`?Tm.test(e.value):e.kind===`Set`&&e.elements.some(Dm),Om=e=>e.kind===`String`&&Tm.test(e.value)||e.kind===`Apply`&&Em.has(e.operator)||Fn(e).some(Om),km=(e,t)=>e.constants.some(e=>Dm(e.value)||(e.args??[]).some(Dm))||[...t.definitions.values()].some(e=>Om(e.body)||e.kind===`Function`&&e.bounds.some(e=>Om(e.set))),Am=(e,t,n,r)=>({environment:e,scope:r,state:t,next:n}),jm=(e,t,n)=>Xa(X(e,t),n),Mm=(e,t,n=Nm)=>{let r=X(e,t);if(typeof r!=`boolean`)throw new m(n(e,t.environment));return r},Nm=(e,t)=>{let n=e.kind===`Identifier`?Za(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?La(i):Ra(r)}`},Pm=()=>{},Fm=(e,t,n)=>e.forEach(e=>{let r=t.possibleCounts.get(e.name)??0,i=jm(e.expression,n,`_POSSIBLE ${e.name}`);t.possibleCounts.set(e.name,i?r+1:r)}),Im=(e,t,n)=>{try{return jm(e,Am(t,void 0,void 0),n)?void 0:{message:void 0}}catch(e){if(e instanceof m)return{message:e.message};throw e}},Lm=(e,t)=>{for(let n of e.filter(e=>!e.isAxiom)){let e=Im(n.expression,t,`an assumption`);if(e)return{name:Ra(n.expression),trace:[],message:e.message}}},Rm=(t,n,r)=>{let i=pm(t.invariants,n),o=_m(t,n),s=vm(t,n),c=Cm([...i,...s.invariants],n),l=c.length>0||s.actionProperties.length>0||s.liveness.length>0;if(o.init===void 0&&(l||s.initialPredicates.length>0||n.variables.length>0))throw new p(`The configuration file did not specify the initial state predicate.`);if(o.next===void 0&&l)throw new p(`The configuration file did not specify the next state predicate.`);let d=Cm(ym(`constraint`,t.constraints,n),n),f=ym(`action constraint`,t.actionConstraints,n);t.rlReward!==void 0&&lm(`rlreward`,t.rlReward,n),t.periodic!==void 0&&lm(`periodic`,t.periodic,n);let m=xm(t.possible,n);if(n.variables.length===0)return;let h=t.symmetry===void 0?[]:xp(t.symmetry,n);t.view!==void 0&&lm(`view function`,t.view,n);let g=t.view===void 0?void 0:{name:t.view,expression:sm(t.view),scope:void 0},_=s.actionProperties.map(e=>{let t={kind:`Unchanged`,expression:e.subscript,location:im};return{...e,unchanged:t}}),v=e=>$(e.expression,void 0,n)>=2,y=m.filter(e=>!v(e)),b=m.filter(v),x=n.runtime,S={indices:void 0},ee=()=>{if(S.indices)return S.indices;let e=r(),t=t=>{let r=e.indexOf(n.variables[t]);return r===-1?n.variables.length:r};return S.indices=n.variables.map((e,t)=>t).sort((e,n)=>t(e)-t(n)),S.indices},te=h.length>0?ee():void 0,C=(e,t)=>X(e,Am(n,t,void 0)),w=e=>{let t=ee(),n=h.length===0?e:kp(e,h,t);return Ec(g===void 0?t.map(e=>n[e]):[C(g.expression,n)])},ne=km(t,n);x.getFingerprint=w;let re=()=>{let e=m.find(e=>!x.possibleCounts.get(e.name));if(!e)return;let t=bm(e.name,n),r=t?` at ${La(t)}`:``;return{name:e.name,message:`The _POSSIBLE predicate ${e.name}${r} 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:me(U(Gc(x),!0))}};return{properties:s,spec:o,isSymmetric:h.length>0,getTlcOrder:ee,getStoredFingerprints:(e,t)=>{if(g!==void 0||ne)return BigInt64Array.from(e,w);let n=ee(),r=kc();return BigInt64Array.from(t,e=>r(n.map(t=>e[t])))},getFingerprintState:e=>{if(ne)return[String(w(e))];let t=h.length===0?e:kp(e,h,te);return g===void 0?t:[C(g.expression,t)]},findViolatedInvariant:(t,r)=>c.find(i=>{if(wm(i,t,r))return!1;try{let e=Am(n,t,void 0,i.scope),a=i.membership;return r&&a?!$t(t[a.variable],r[a.variable],X(a.set,e)):!Mm(i.expression,e)}catch(t){throw r?zm(a(t,e.safetyEvaluationFailure),`Evaluating invariant ${i.name} failed.`):t}}),satisfiesConstraints:(e,t)=>d.every(r=>wm(r,e,t)||Mm(r.expression,Am(n,e,void 0))),findFailedInitialPredicate:e=>s.initialPredicates.find(t=>!Mm(t.expression,Am(n,e,void 0,t.scope))),findViolatedActionProperty:(e,t)=>_.find(r=>{try{return!Mm(r.action,Am(n,e,t,r.scope),()=>`Attempted to evaluate an expression of form [A]_e, but A was not a boolean.\n${Ra(r.box)}`)&&!jm(r.unchanged,Am(n,e,t,r.scope),`a subscript`)}catch(e){throw zm(e,`Evaluating action property ${r.name} failed.`)}}),satisfiesActionConstraints:(e,t)=>f.every(r=>Mm(r.expression,Am(n,e,t),e=>`${u}${Nm(e,n)}`)),trackStatePossible:y.length===0?Pm:e=>Fm(y,x,Am(n,e,void 0)),trackActionPossible:b.length===0?Pm:(e,t)=>Fm(b,x,Am(n,e,t)),findUnwitnessedPossible:re,findPostconditionViolation:()=>{let e=re();if(e)return e;for(let e of t.postconditions){let t=Im(sm(e),n,`a postcondition`);if(t)return{name:e,message:t.message??`Postcondition ${e} is false.`}}}}},zm=(e,t)=>e instanceof m?a(new m(`${t}\n${e.message}`,e),y(e)):e,Bm=e=>{i(!1);let t=typeof e.config==`string`?ce(e.config):e.config,n=e.onPrint??console.log,r={isMuted:!1},a=e=>{r.isMuted||n(e)},o=e=>{r.isMuted=!0;let t=e();return r.isMuted=!1,t};De(Jp(e.source,t,e.loadModule));let s=Kd(t,{source:e.source,loadModule:e.loadModule,loadClass:e.loadClass,print:a,files:{readFile:e.readFile,writeFile:e.writeFile},seed:e.seed}),c=s.environment,u=c.runtime;u.pause=e.onPause??(()=>{}),u.getSpecification=()=>_p(t,c,s.variableLocations,s.instanceActions);let d={depth:0},f=(e,t,n)=>({status:e,violation:t&&{...t,loopStart:t.loopStart},failure:n,generatedStates:u.generatedStates,distinctStates:u.distinctStates,queuedStates:u.queueSize,depth:u.generatedStates===0?0:Math.max(d.depth,1),outDegrees:void 0,fingerprintDistance:void 0}),g=Array.from({length:32},()=>0),_={newStates:0},v=()=>Math.min(_.newStates,31),b=()=>g.map((e,t)=>t===v()?e+1:e),x=()=>({...f(`success`),outDegrees:[...g],fingerprintDistance:nm(u.distinctStates,u.generatedStates,()=>S?S.getStoredFingerprints(O,k):BigInt64Array.from(O,u.getFingerprint))}),S=Rm(t,c,()=>qp(e.source,e.loadModule)),ee=Lm(s.assumptions,c);if(ee)return f(`assumption-violation`,ee);if(!S)return x();let te=t.postconditions.length>0||t.possible.length>0,C=(e,t,n)=>{if(te){let e=t.loopStart;u.counterExample=Jl(t.trace,e===void 0||!n?void 0:{start:e,action:n()})}let r=S.findUnwitnessedPossible();return r||S.findPostconditionViolation(),f(e,r?{...t,unwitnessed:r}:t)},w=S.spec,ne=S.getFingerprintState,re={value:void 0},ie=t.view!==void 0||t.symmetry!==void 0,T=[],E=l(()=>Kf(S.properties.liveness,w.temporals,c,{getFingerprint:e=>T[e]??=Number(BigInt.asIntN(32,u.getFingerprint(O[e]))),getSuccessors:e=>{let t=[];return w.next===void 0||Fa(w.next,e,c,n=>{if(le(n.state),!(S.satisfiesConstraints(n.state,e)&&S.satisfiesActionConstraints(e,n.state)))return!1;let r=ne(n.state),i=Se(be(r),r);return t.push({index:i,state:n.state}),!1},w.scope),t}})),D=S.isSymmetric||E!==void 0,O=[],k=[],ae=[],oe=[],A=[],se=/* @__PURE__ */ new Map,le=Pn(),ue=e=>Object.fromEntries(S.getTlcOrder().map(t=>[c.variables[t],e[t]])),de=(e,t,n,r)=>{let i=t[n].state,a=(t[n+1]??t[r??n]).state;u.getLevel=()=>n+1,u.getBehavior=()=>t.slice(0,n+1).map(e=>e.state);try{let t=um(`alias`,e,c).body,n=X(sm(e),Am(c,i,a)),r=t.kind===`Record`?t.fields.map(e=>e.name):[];return mm(n,r)??ue(i)}catch(e){if(!(e instanceof p||e instanceof m))throw e;return{...ue(i),_ALIASEvalError:e.message}}},fe=(e,n,r)=>{re.value??=hp(t,c,s.instanceActions);let i={...F};Object.assign(F,{index:e,isExpanding:!0,candidate:void 0});let a=ne(r),o=re.value.find(e=>Ia(e.expression,n,c,e.scope).some(e=>xe(ne(e.state),a)));return Object.assign(F,i),o&&gp(o)},pe=(e,n,r)=>{let i=t.alias,a=o(()=>(e.length>1&&Uo(c)&&me(),e.map((t,r)=>r===0||t.action===`Stuttering`?void 0:fe(n[r-1],e[r-1].state,t.state))));return e.map((t,n)=>({action:t.action,label:a[n],state:i===void 0?ue(t.state):de(i,e,n,r)}))},me=()=>w.init===void 0?[]:Pa(w.init,c,w.scope),j=e=>w.next===void 0?[]:Ia(w.next,e,c,w.scope),M=(e,t)=>xe(ne(e),k[t]),N=(e,t)=>j(e).find(e=>M(e.state,t)),he=(e,t)=>{let n=ie||Uo(c)?me().find(t=>M(t,e[0])):O[e[0]];if(!n)throw new m(am);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 m(t);r.push(a)}return r},ge=(e,t)=>{let n=[];for(let t=e;t!==-1;t=ae[t])n.unshift(t);let r=ie&&n.length>1?he(n,am):n.map(e=>({state:O[e],action:oe[e]}));if(!t)return pe(r,n);let i=ie?j(O[e]).find(e=>xe(e.state,t.state))?.action:t.action;return pe([...r,{state:t.state,action:i}],n)},_e=e=>ae[e]===-1?[{action:void 0,label:void 0,state:ue(O[e])}]:ge(e),ve=(e,t,n,r)=>{if(!(e instanceof m))throw e;return{...f(`error`,void 0,{message:e.message,trace:t,initialState:n&&!(e instanceof h)?ue(n):void 0,exitCode:y(e)}),outDegrees:r}},ye=(e,t)=>{let n=he(e,om),r=n[n.length-1].state;if(ie&&t!==void 0&&t!==e.length-1&&N(r,e[t])===void 0)throw new m(om);return n},be=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=dn(t,gn(e[n]));return t&1073741823},xe=(e,t)=>{for(let n=0;n<t.length;n++)if(!He(e[n],t[n]))return!1;return!0},Se=(e,t)=>{let n=se.get(e);return n===void 0?-1:typeof n==`number`?xe(k[n],t)?n:-1:n.find(e=>xe(k[e],t))??-1},P=(e,t)=>{let n=se.get(e);n===void 0?se.set(e,t):typeof n==`number`?se.set(e,[n,t]):n.push(t)},Ce=e=>{u.distinctStates=O.length+1,d.depth=Math.max(d.depth,e),u.diameter=Math.max(u.diameter,e)},we=(e,t,n,r)=>{let i=n===-1?1:A[n]+1;O.push(e),k.push(t),ae.push(n),oe.push(r),A.push(i)},F={index:-1,isExpanding:!1,candidate:void 0,candidateLevel:0,livenessSource:-1},Te=e=>e===-1?[]:[...Te(ae[e]),O[e]];u.isSeen=e=>{let t=ne(e);return Se(be(t),t)!==-1},u.getBehavior=e=>{let t=e===F.candidate?-1:O.indexOf(e);return t===-1?[...Te(F.index),e]:Te(t)},u.getCurrentState=()=>F.index===-1?void 0:O[F.index],u.setLivenessSource=e=>{F.livenessSource=e??-1},u.getLevel=e=>{let t=F.livenessSource;return t===-1?e===F.candidate?F.candidateLevel:F.index===-1?0:e===O[F.index]?A[F.index]:F.isExpanding?A[F.index]+1:0:e===O[t]?A[t]:A[t]+1};let Ee=e=>{le(e),u.generatedStates++,u.initialStates++,F.candidate=e,F.candidateLevel=1;let t=ne(e),n=be(t),r=S.satisfiesConstraints(e);if(r&&S.trackStatePossible(e),r&&Se(n,t)!==-1)return;r&&(Ce(1),u.queueSize++,E?.addInitialState(O.length,e));let i=S.findViolatedInvariant(e);if(i)return C(`invariant-violation`,{name:i.name,trace:pe([{action:void 0,state:e}],[])});let a=S.findFailedInitialPredicate(e);if(a)return C(`liveness-violation`,{name:a.name,trace:pe([{action:void 0,state:e}],[])});r&&(P(n,O.length),we(e,t,-1,void 0))},Oe=(e,t,n)=>{let r=O[e];u.generatedStates++,F.candidate=t.state,F.candidateLevel=A[e]+1,D&&le(t.state);let i=ne(t.state),a=be(i),o=Se(a,i),s=S.satisfiesConstraints(t.state,r);s&&S.trackStatePossible(t.state);let c=s&&S.satisfiesActionConstraints(r,t.state);c&&S.trackActionPossible(r,t.state);let l=c?o:-1;if(l!==-1&&E){let e=O[l],r=e.every((e,n)=>e===t.state[n]);n.push({index:l,state:r?e:t.state})}let d=c&&l===-1;if(d&&(Ce(A[e]+1),_.newStates++),l===-1)try{let n=S.findViolatedInvariant(t.state,r);if(n)return C(`invariant-violation`,{name:n.name,trace:ge(e,t)})}catch(n){return ve(n,ge(e,t),void 0,b())}let f=S.findViolatedActionProperty(r,t.state);if(f)return C(`liveness-violation`,{name:f.name,trace:ge(e,t)});d&&(D||le(t.state),P(a,O.length),E&&n.push({index:O.length,state:t.state}),we(t.state,i,e,t.action),u.queueSize++)},ke={result:void 0};if(w.init!==void 0)try{Na(w.init,c,e=>{try{ke.result=Ee(e)}catch(t){ke.result=ve(t,[],e)}return ke.result!==void 0},w.scope)}catch(e){return ve(e,[])}if(ke.result)return ke.result;let Ae=w.next;if(Ae===void 0){if(O.length>0)throw new m(`No next state actions defined to generate successor states from.`);return x()}let je=e=>{let n=O[e],r=[],i=Fa(Ae,n,c,t=>{try{ke.result=Oe(e,t,r)}catch(n){ke.result=ve(n,ge(e,t))}return ke.result!==void 0},w.scope);if(F.isExpanding=!1,ke.result)return ke.result;if(i===0&&t.checkDeadlock)return C(`deadlock`,{name:`deadlock`,trace:_e(e)});try{let t=E?.addState(e,n,r);if(!E||!t)return;let i=ye(t),a=E.getViolatedProperties(i.map(e=>e.state),i.length-1);return C(`property-violation`,{name:a[0],properties:a,trace:pe(i,t)})}catch(t){return ve(t,_e(e),void 0,b())}},I=(e,t)=>{let n=[...t.prefix,...t.cycle],r=t.prefix.length,i=ye(n,r),a=pe(i,n,r),s=e.getViolatedProperties(i.map(e=>e.state),r),c=n[r],l=n[n.length-1],u=i[i.length-1].state,d=c===l?void 0:o(()=>fe(l,u,O[c]));return C(`liveness-violation`,{name:s[0],properties:s,trace:a,loopStart:r,loopLabel:d},()=>c===l?a[a.length-1].action:N(u,c)?.action)},Me=E!==void 0&&e.livenessCheck!==`final`,Ne=performance.now(),Pe={at:Ne+3e3,size:1,time:0},Fe=e=>{let t=performance.now();if(Pe.at=t+6e4,!((e-Pe.size)/Pe.size>.1)||Pe.time>(t-Ne)*.2)return;Pe.size=e;let n=E?.findViolation();return Pe.time+=performance.now()-t,n};i(!0);for(let e=0;e<O.length&&!u.isStopped;e++){F.index=e,F.candidate=void 0,u.queueSize=O.length-e-1,F.isExpanding=!0;try{ke.result=je(e)}catch(t){ke.result=ve(t,_e(e))}if(ke.result)return ke.result;if(g[v()]++,_.newStates=0,Me&&performance.now()>=Pe.at){let t=Fe(e+1);if(E&&t)return I(E,t)}}F.index=-1,F.candidate=void 0;let L=E?.findViolation();if(E&&L)return I(E,L);let Ie=S.findPostconditionViolation();return Ie?f(`postcondition-violation`,{...Ie,trace:[]}):x()},Vm=e=>{let t=Math.imul(e^e>>>16,2146121005),n=Math.imul(t^t>>>15,2221713035);return n^n>>>16},Hm=(e,t)=>{let n=2166136261,r=1779033703;for(let t=0;t<e.length;t++)n=Math.imul(n^gn(e[t]),16777619),r=Math.imul(r^Cn(e[t]),1540483477);t[0]=Vm(n)||1,t[1]=Vm(r)},Um=()=>{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)}}},Wm=(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}},Gm=()=>({slots:new BigInt64Array(new SharedArrayBuffer(8192)),used:new Int32Array(new SharedArrayBuffer(4))}),Km=(e,t,n)=>{let r=BigInt.asIntN(64,BigInt(t)<<32n|BigInt(n>>>0));return Wm(e.slots,r)?(Atomics.add(e.used,0,1),!0):!1},qm=e=>Atomics.load(e.used,0)*2>=e.slots.length,Jm=e=>{let t=new BigInt64Array(new SharedArrayBuffer(e.slots.byteLength*2));for(let n of e.slots)n!==0n&&Wm(t,n);return{slots:t,used:e.used}},Ym=()=>{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=on(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})}},Xm=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 Le(t.strings[n[r.index++]]);if(e===7){let e=n[r.index++],t=n[r.index++],a=kt({kind:`Interval`,low:e,high:e+t-1});return ze(a,i(t))}let a=n[r.index++];if(e===5)return Re(i(a));let o=i(a);return ze(o,i(a))};return Array.from({length:t.count},()=>Array.from({length:e},()=>a()))};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Pa}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Uo}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Pn}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Jp}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Jm}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return lc}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Hm}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Lm}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return $p}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return rm}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Yp}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Gm}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Bm}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return nm}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Ym}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Km}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return tm}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Um}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return qm}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Xm}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Rm}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return qp}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Ia}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return uc}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Kd}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return y}});
413
+ please check if this bug described in LevelNode.java starting at line 590ff affects you.`}`);return[{name:e,expression:sm(e),scope:void 0}]})},mm=(e,t)=>{if(!j(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])))},hm=(e,t)=>{if(e.kind===`And`)return e.operands.flatMap(e=>hm(e,t));if(e.kind===`Identifier`&&!t.constants.has(e.name)){let n=qa(e.name,t);if(n?.kind===`Operator`&&n.params.length===0)return hm(n.body,t)}return[e]},gm=(e,t,n)=>{let r=e.expression;if(r.kind!==`Identifier`||$(r,e.scope,t)>0)return!1;let i=X(r,Am(t,void 0,void 0,e.scope));if(i===!1)throw new l(`The spec is trivially false because ${r.name} is false.`);if(i!==!0)throw new l(`The operator ${r.name}, which equals ${U(i)},\ncannot be used as a ${n}`);return!0},_m=(t,r)=>{if(t.specification===void 0){let e=(e,t)=>{if(e===void 0)return;let n=lm(t,e,r).body,i=sm(e);if(n.kind!==`Number`&&n.kind!==`String`&&$(i,void 0,r)===0)throw new l(`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=lm(`name`,t.specification,r),c=dm(t.specification,s,r);if(c!==void 0)throw new l(`The value of ${t.specification} is equal to ${U(c)}`);if(Nf(s.body,void 0,r,!1).forEach(s=>{let c=s.expression;if(gm(s,r,`spec`))return;if(c.kind===`UnboundedQuantifier`&&c.isTemporal)throw n(new l(`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 new l(`TLC cannot handle []P in the specification ${t.specification} when P is a state predicate`);let u=$(c,s.scope,r);if(u===3)o.push(s);else{if(u===2)throw new l(`TLC cannot handle the action-level conjunct of the specification ${t.specification}`);i.push(s)}}),a.length>1)throw new l(`The specification ${t.specification} must contain at most one [][Next]_vars`);let u=[...i,...a],d=e=>`$specification${e}`,f=u.reduce((e,t,n)=>t.scope===void 0?e:{name:d(n),binding:{kind:`Thunk`,expression:t.expression,scope:t.scope,state:void 0,next:void 0,cache:void 0},parent:e},void 0),p=(e,t)=>e.scope===void 0?e.expression:{kind:`Identifier`,name:d(t),location:e.expression.location,resolution:{kind:`Local`}};return{init:i.length===0?void 0:{kind:`And`,operands:i.map(p),location:im},next:a.length===0?void 0:p(a[0],i.length),scope:f,temporals:o}},vm=(e,t)=>{let n={initialPredicates:[],invariants:[],actionProperties:[],liveness:[]};return e.properties.forEach(e=>{let r=fm(`property`,e,t);r&&Nf(r.body,void 0,t,!0).forEach(r=>{let i=r.expression;if(gm(r,t,`property`))return;if(i.kind===`Always`&&i.expression.kind===`BoxAction`){n.actionProperties.push({name:e,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){n.invariants.push({name:e,expression:i.expression,scope:r.scope});return}let a=$(i,r.scope,t);if(a<2)n.initialPredicates.push({name:e,expression:i,scope:r.scope});else{if(a===2)throw new l(`The property ${e} is an action-level formula`);n.liveness.push({name:e,expression:i,scope:r.scope})}})}),n},ym=(e,t,n)=>t.flatMap(t=>fm(e,t,n)?[{name:t,expression:sm(t),scope:void 0}]:[]),bm=(e,t)=>{let n=qa(e,t);return n?.kind===`Operator`?n.bodyRange:void 0},xm=(e,t)=>e.map((n,r)=>{if(e.indexOf(n)!==r)throw new l(`_POSSIBLE lists ${n} more than once`);um(`possible`,n,t);let i=sm(n);if($(i,void 0,t)===3)throw new l(`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}}),Sm=(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},Cm=(e,t)=>e.flatMap(e=>hm(e.expression,t).map(n=>{let r=ks(n,t);return{name:e.name,expression:n,scope:e.scope,variables:r,membership:Sm(n,r,t)}})),wm=(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},Tm=/[\u0100-\uffff]/,Em=/* @__PURE__ */ new Set([`JsonDeserialize`,`ndJsonDeserialize`]),Dm=e=>e.kind===`String`?Tm.test(e.value):e.kind===`Set`&&e.elements.some(Dm),Om=e=>e.kind===`String`&&Tm.test(e.value)||e.kind===`Apply`&&Em.has(e.operator)||jn(e).some(Om),km=(e,t)=>e.constants.some(e=>Dm(e.value)||(e.args??[]).some(Dm))||[...t.definitions.values()].some(e=>Om(e.body)||e.kind===`Function`&&e.bounds.some(e=>Om(e.set))),Am=(e,t,n,r)=>({environment:e,scope:r,state:t,next:n}),jm=(e,t,n)=>Ka(X(e,t),n),Mm=(e,t,n=Nm)=>{let r=X(e,t);if(typeof r!=`boolean`)throw new u(n(e,t.environment));return r},Nm=(e,t)=>{let n=e.kind===`Identifier`?qa(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?Na(i):Pa(r)}`},Pm=()=>{},Fm=(e,t,n)=>e.forEach(e=>{let r=t.possibleCounts.get(e.name)??0,i=jm(e.expression,n,`_POSSIBLE ${e.name}`);t.possibleCounts.set(e.name,i?r+1:r)}),Im=(e,t,n)=>{try{return jm(e,Am(t,void 0,void 0),n)?void 0:{message:void 0}}catch(e){if(e instanceof u)return{message:e.message};throw e}},Lm=(e,t)=>{for(let n of e.filter(e=>!e.isAxiom)){let e=Im(n.expression,t,`an assumption`);if(e)return{name:Pa(n.expression),trace:[],message:e.message}}},Rm=(t,r,i)=>{let a=pm(t.invariants,r),s=_m(t,r),c=vm(t,r),u=Cm([...a,...c.invariants],r),d=u.length>0||c.actionProperties.length>0||c.liveness.length>0;if(s.init===void 0&&(d||c.initialPredicates.length>0||r.variables.length>0))throw new l(`The configuration file did not specify the initial state predicate.`);if(s.next===void 0&&d)throw new l(`The configuration file did not specify the next state predicate.`);let f=Cm(ym(`constraint`,t.constraints,r),r),p=ym(`action constraint`,t.actionConstraints,r);t.rlReward!==void 0&&lm(`rlreward`,t.rlReward,r),t.periodic!==void 0&&lm(`periodic`,t.periodic,r);let m=xm(t.possible,r);if(r.variables.length===0)return;let h=t.symmetry===void 0?[]:xp(t.symmetry,r);t.view!==void 0&&lm(`view function`,t.view,r);let g=t.view===void 0?void 0:{name:t.view,expression:sm(t.view),scope:void 0},_=c.actionProperties.map(e=>{let t={kind:`Unchanged`,expression:e.subscript,location:im};return{...e,unchanged:t}}),v=e=>$(e.expression,void 0,r)>=2,y=m.filter(e=>!v(e)),ee=m.filter(v),b=r.runtime,te={indices:void 0},ne=()=>{if(te.indices)return te.indices;let e=i(),t=t=>{let n=e.indexOf(r.variables[t]);return n===-1?r.variables.length:n};return te.indices=r.variables.map((e,t)=>t).sort((e,n)=>t(e)-t(n)),te.indices},re=h.length>0?ne():void 0,x=(e,t)=>X(e,Am(r,t,void 0)),S=e=>{let t=ne(),n=h.length===0?e:kp(e,h,t);return Ec(g===void 0?t.map(e=>n[e]):[x(g.expression,n)])},ie=km(t,r);b.getFingerprint=S;let C=()=>{let e=m.find(e=>!b.possibleCounts.get(e.name));if(!e)return;let t=bm(e.name,r),n=t?` at ${Na(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:de(U(Gc(b),!0))}};return{properties:c,spec:s,isSymmetric:h.length>0,getTlcOrder:ne,getStoredFingerprints:(e,t)=>{if(g!==void 0||ie)return BigInt64Array.from(e,S);let n=ne(),r=kc();return BigInt64Array.from(t,e=>r(n.map(t=>e[t])))},getFingerprintState:e=>{if(ie)return[String(S(e))];let t=h.length===0?e:kp(e,h,re);return g===void 0?t:[x(g.expression,t)]},findViolatedInvariant:(t,i)=>u.find(a=>{if(wm(a,t,i))return!1;try{let e=Am(r,t,void 0,a.scope),n=a.membership;return i&&n?!Yt(t[n.variable],i[n.variable],X(n.set,e)):!Mm(a.expression,e)}catch(t){throw i?Bm(n(t,e.safetyEvaluationFailure),`Evaluating invariant ${a.name} failed.`):t}}),satisfiesConstraints:(e,t)=>f.every(n=>wm(n,e,t)||Mm(n.expression,Am(r,e,void 0))),findFailedInitialPredicate:e=>c.initialPredicates.find(t=>!Mm(t.expression,Am(r,e,void 0,t.scope))),findViolatedActionProperty:(e,t)=>_.find(n=>{try{return!Mm(n.action,Am(r,e,t,n.scope),()=>`Attempted to evaluate an expression of form [A]_e, but A was not a boolean.\n${Pa(n.box)}`)&&!jm(n.unchanged,Am(r,e,t,n.scope),`a subscript`)}catch(e){throw Bm(zm(e),`Evaluating action property ${n.name} failed.`)}}),satisfiesActionConstraints:(e,t)=>p.every(n=>Mm(n.expression,Am(r,e,t),e=>`${o}${Nm(e,r)}`)),trackStatePossible:y.length===0?Pm:e=>Fm(y,b,Am(r,e,void 0)),trackActionPossible:ee.length===0?Pm:(e,t)=>Fm(ee,b,Am(r,e,t)),findUnwitnessedPossible:C,findPostconditionViolation:()=>{let e=C();if(e)return e;for(let e of t.postconditions){let t=Im(sm(e),r,`a postcondition`);if(t)return{name:e,message:t.message??`Postcondition ${e} is false.`}}}}},zm=e=>e instanceof d?n(e,e.exitCode):e,Bm=(e,t)=>e instanceof u?n(new u(`${t}\n${e.message}`,e),h(e)):e,Vm=e=>{let t=typeof e.config==`string`?O(e.config):e.config,n=e.onPrint??console.log,r={isMuted:!1},i=e=>{r.isMuted||n(e)},o=e=>{r.isMuted=!0;let t=e();return r.isMuted=!1,t};Te(Jp(e.source,t,e.loadModule));let s=Kd(t,{source:e.source,loadModule:e.loadModule,loadClass:e.loadClass,print:i,files:{readFile:e.readFile,writeFile:e.writeFile},seed:e.seed}),c=s.environment,f=c.runtime;f.pause=e.onPause??(()=>{}),f.getSpecification=()=>_p(t,c,s.variableLocations,s.instanceActions);let p={depth:0},m=(e,t,n)=>({status:e,violation:t&&{...t,loopStart:t.loopStart},failure:n,generatedStates:f.generatedStates,distinctStates:f.distinctStates,queuedStates:f.queueSize,depth:f.generatedStates===0?0:Math.max(p.depth,1),outDegrees:void 0,fingerprintDistance:void 0}),g=Array.from({length:32},()=>0),_={newStates:0},v=()=>Math.min(_.newStates,31),y=()=>g.map((e,t)=>t===v()?e+1:e),ee=()=>({...m(`success`),outDegrees:[...g],fingerprintDistance:nm(f.distinctStates,f.generatedStates,()=>b?b.getStoredFingerprints(T,E):BigInt64Array.from(T,f.getFingerprint))}),b=Rm(t,c,()=>qp(e.source,e.loadModule)),te=Lm(s.assumptions,c);if(te)return m(`assumption-violation`,te);if(!b)return ee();let ne=t.postconditions.length>0||t.possible.length>0,re=(e,t,n)=>{if(ne){let e=t.loopStart;f.counterExample=Jl(t.trace,e===void 0||!n?void 0:{start:e,action:n()})}let r=b.findUnwitnessedPossible();return r||b.findPostconditionViolation(),m(e,r?{...t,unwitnessed:r}:t)},x=b.spec,S=b.getFingerprintState,ie={value:void 0},C=t.view!==void 0||t.symmetry!==void 0,ae=[],w=a(()=>Kf(b.properties.liveness,x.temporals,c,{getFingerprint:e=>ae[e]??=Number(BigInt.asIntN(32,f.getFingerprint(T[e]))),getSuccessors:e=>{let t=[];return x.next===void 0||ja(x.next,e,c,n=>{if(le(n.state),!(b.satisfiesConstraints(n.state,e)&&b.satisfiesActionConstraints(e,n.state)))return!1;let r=S(n.state),i=Se(be(r),r);return t.push({index:i,state:n.state}),!1},x.scope),t}})),oe=b.isSymmetric||w!==void 0,T=[],E=[],D=[],se=[],k=[],ce=/* @__PURE__ */ new Map,le=An(),ue=e=>Object.fromEntries(b.getTlcOrder().map(t=>[c.variables[t],e[t]])),de=(e,t,n,r)=>{let i=t[n].state,a=(t[n+1]??t[r??n]).state;f.getLevel=()=>n+1,f.getBehavior=()=>t.slice(0,n+1).map(e=>e.state);try{let t=um(`alias`,e,c).body,n=X(sm(e),Am(c,i,a)),r=t.kind===`Record`?t.fields.map(e=>e.name):[];return mm(n,r)??ue(i)}catch(e){if(!(e instanceof l||e instanceof u))throw e;return{...ue(i),_ALIASEvalError:e.message}}},A=(e,n,r)=>{ie.value??=hp(t,c,s.instanceActions);let i={...P};Object.assign(P,{index:e,isExpanding:!0,candidate:void 0});let a=S(r),o=ie.value.find(e=>Ma(e.expression,n,c,e.scope).some(e=>xe(S(e.state),a)));return Object.assign(P,i),o&&gp(o)},j=(e,n,r)=>{let i=t.alias,a=o(()=>(e.length>1&&zo(c)&&M(),e.map((t,r)=>r===0||t.action===`Stuttering`?void 0:A(n[r-1],e[r-1].state,t.state))));return e.map((t,n)=>({action:t.action,label:a[n],state:i===void 0?ue(t.state):de(i,e,n,r)}))},M=()=>x.init===void 0?[]:Aa(x.init,c,x.scope),fe=e=>x.next===void 0?[]:Ma(x.next,e,c,x.scope),pe=(e,t)=>xe(S(e),E[t]),me=(e,t)=>fe(e).find(e=>pe(e.state,t)),he=(e,t)=>{let n=C||zo(c)?M().find(t=>pe(t,e[0])):T[e[0]];if(!n)throw new u(am);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=me(i,e[n]);if(!a)throw new u(t);r.push(a)}return r},ge=(e,t)=>{let n=[];for(let t=e;t!==-1;t=D[t])n.unshift(t);let r=C&&n.length>1?he(n,am):n.map(e=>({state:T[e],action:se[e]}));if(!t)return j(r,n);let i=C?fe(T[e]).find(e=>xe(e.state,t.state))?.action:t.action;return j([...r,{state:t.state,action:i}],n)},_e=e=>D[e]===-1?[{action:void 0,label:void 0,state:ue(T[e])}]:ge(e),ve=(e,t,n,r)=>{if(!(e instanceof u))throw e;return{...m(`error`,void 0,{message:e.message,trace:t,initialState:n&&!(e instanceof d)?ue(n):void 0,exitCode:h(e)}),outDegrees:r}},ye=(e,t)=>{let n=he(e,om),r=n[n.length-1].state;if(C&&t!==void 0&&t!==e.length-1&&me(r,e[t])===void 0)throw new u(om);return n},be=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=sn(t,fn(e[n]));return t&1073741823},xe=(e,t)=>{for(let n=0;n<t.length;n++)if(!Re(e[n],t[n]))return!1;return!0},Se=(e,t)=>{let n=ce.get(e);return n===void 0?-1:typeof n==`number`?xe(E[n],t)?n:-1:n.find(e=>xe(E[e],t))??-1},Ce=(e,t)=>{let n=ce.get(e);n===void 0?ce.set(e,t):typeof n==`number`?ce.set(e,[n,t]):n.push(t)},N=e=>{f.distinctStates=T.length+1,p.depth=Math.max(p.depth,e),f.diameter=Math.max(f.diameter,e)},we=(e,t,n,r)=>{let i=n===-1?1:k[n]+1;T.push(e),E.push(t),D.push(n),se.push(r),k.push(i)},P={index:-1,isExpanding:!1,candidate:void 0,candidateLevel:0,livenessSource:-1},Ee=e=>e===-1?[]:[...Ee(D[e]),T[e]];f.isSeen=e=>{let t=S(e);return Se(be(t),t)!==-1},f.getBehavior=e=>{let t=e===P.candidate?-1:T.indexOf(e);return t===-1?[...Ee(P.index),e]:Ee(t)},f.getCurrentState=()=>P.index===-1?void 0:T[P.index],f.setLivenessSource=e=>{P.livenessSource=e??-1},f.getLevel=e=>{let t=P.livenessSource;return t===-1?e===P.candidate?P.candidateLevel:P.index===-1?0:e===T[P.index]?k[P.index]:P.isExpanding?k[P.index]+1:0:e===T[t]?k[t]:k[t]+1};let De=e=>{le(e),f.generatedStates++,f.initialStates++,P.candidate=e,P.candidateLevel=1;let t=S(e),n=be(t),r=b.satisfiesConstraints(e);if(r&&b.trackStatePossible(e),r&&Se(n,t)!==-1)return;r&&(N(1),f.queueSize++,w?.addInitialState(T.length,e));let i=b.findViolatedInvariant(e);if(i)return re(`invariant-violation`,{name:i.name,trace:j([{action:void 0,state:e}],[])});let a=b.findFailedInitialPredicate(e);if(a)return re(`liveness-violation`,{name:a.name,trace:j([{action:void 0,state:e}],[])});r&&(Ce(n,T.length),we(e,t,-1,void 0))},Oe=(e,t,n)=>{let r=T[e];f.generatedStates++,P.candidate=t.state,P.candidateLevel=k[e]+1,oe&&le(t.state);let i=S(t.state),a=be(i),o=Se(a,i),s=b.satisfiesConstraints(t.state,r);s&&b.trackStatePossible(t.state);let c=s&&b.satisfiesActionConstraints(r,t.state);c&&b.trackActionPossible(r,t.state);let l=c?o:-1;if(l!==-1&&w){let e=T[l],r=e.every((e,n)=>e===t.state[n]);n.push({index:l,state:r?e:t.state})}let u=c&&l===-1;if(u&&(N(k[e]+1),_.newStates++),l===-1)try{let n=b.findViolatedInvariant(t.state,r);if(n)return re(`invariant-violation`,{name:n.name,trace:ge(e,t)})}catch(n){return ve(n,ge(e,t),void 0,y())}let d=b.findViolatedActionProperty(r,t.state);if(d)return re(`liveness-violation`,{name:d.name,trace:ge(e,t)});u&&(oe||le(t.state),Ce(a,T.length),w&&n.push({index:T.length,state:t.state}),we(t.state,i,e,t.action),f.queueSize++)},F={result:void 0};if(x.init!==void 0)try{ka(x.init,c,e=>{try{F.result=De(e)}catch(t){F.result=ve(t,[],e)}return F.result!==void 0},x.scope)}catch(e){return ve(e,[])}if(F.result)return F.result;let ke=x.next;if(ke===void 0){if(T.length>0)throw new u(`No next state actions defined to generate successor states from.`);return ee()}let Ae=e=>{let n=T[e],r=[],i=ja(ke,n,c,t=>{try{F.result=Oe(e,t,r)}catch(n){F.result=ve(n,ge(e,t))}return F.result!==void 0},x.scope);if(P.isExpanding=!1,F.result)return F.result;if(i===0&&t.checkDeadlock)return re(`deadlock`,{name:`deadlock`,trace:_e(e)});try{let t=w?.addState(e,n,r);if(!w||!t)return;let i=ye(t),a=w.getViolatedProperties(i.map(e=>e.state),i.length-1);return re(`property-violation`,{name:a[0],properties:a,trace:j(i,t)})}catch(t){return ve(t,_e(e),void 0,y())}},je=(e,t)=>{let n=[...t.prefix,...t.cycle],r=t.prefix.length,i=ye(n,r),a=j(i,n,r),s=e.getViolatedProperties(i.map(e=>e.state),r),c=n[r],l=n[n.length-1],u=i[i.length-1].state,d=c===l?void 0:o(()=>A(l,u,T[c]));return re(`liveness-violation`,{name:s[0],properties:s,trace:a,loopStart:r,loopLabel:d},()=>c===l?a[a.length-1].action:me(u,c)?.action)},Me=w!==void 0&&e.livenessCheck!==`final`,I=performance.now(),Ne={at:I+3e3,size:1,time:0},Pe=e=>{let t=performance.now();if(Ne.at=t+6e4,!((e-Ne.size)/Ne.size>.1)||Ne.time>(t-I)*.2)return;Ne.size=e;let n=w?.findViolation();return Ne.time+=performance.now()-t,n};for(let e=0;e<T.length&&!f.isStopped;e++){P.index=e,P.candidate=void 0,f.queueSize=T.length-e-1,P.isExpanding=!0;try{F.result=Ae(e)}catch(t){F.result=ve(zm(t),_e(e))}if(F.result)return F.result;if(g[v()]++,_.newStates=0,Me&&performance.now()>=Ne.at){let t=Pe(e+1);if(w&&t)return je(w,t)}}P.index=-1,P.candidate=void 0;let Fe=w?.findViolation();if(w&&Fe)return je(w,Fe);let L=b.findPostconditionViolation();return L?m(`postcondition-violation`,{...L,trace:[]}):ee()},Hm=e=>{let t=Math.imul(e^e>>>16,2146121005),n=Math.imul(t^t>>>15,2221713035);return n^n>>>16},Um=(e,t)=>{let n=2166136261,r=1779033703;for(let t=0;t<e.length;t++)n=Math.imul(n^fn(e[t]),16777619),r=Math.imul(r^yn(e[t]),1540483477);t[0]=Hm(n)||1,t[1]=Hm(r)},Wm=()=>{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)}}},Gm=(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}},Km=()=>({slots:new BigInt64Array(new SharedArrayBuffer(8192)),used:new Int32Array(new SharedArrayBuffer(4))}),qm=(e,t,n)=>{let r=BigInt.asIntN(64,BigInt(t)<<32n|BigInt(n>>>0));return Gm(e.slots,r)?(Atomics.add(e.used,0,1),!0):!1},Jm=e=>Atomics.load(e.used,0)*2>=e.slots.length,Ym=e=>{let t=new BigInt64Array(new SharedArrayBuffer(e.slots.byteLength*2));for(let n of e.slots)n!==0n&&Gm(t,n);return{slots:t,used:e.used}},Xm=()=>{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=tn(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})}},Zm=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 Pe(t.strings[n[r.index++]]);if(e===7){let e=n[r.index++],t=n[r.index++],a=Tt({kind:`Interval`,low:e,high:e+t-1});return L(a,i(t))}let a=n[r.index++];if(e===5)return Fe(i(a));let o=i(a);return L(o,i(a))};return Array.from({length:t.count},()=>Array.from({length:e},()=>a()))};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Aa}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return zo}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Jp}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Ym}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return lc}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Um}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Lm}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return $p}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return rm}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Yp}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Km}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Vm}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return nm}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Xm}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return qm}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return tm}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Wm}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Jm}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Zm}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Rm}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return qp}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Ma}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return uc}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Kd}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return h}});