tla-ts 0.0.3-dev.367c92f → 0.0.3-dev.3ce2f00

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
@@ -415,7 +415,7 @@ _CheckName(name) ==
415
415
  => (PrintT(counts) /\\ FALSE)
416
416
  _PrintCounts == PrintT(_Counts)
417
417
  =============================================================================
418
- `]]),gd=/* @__PURE__ */ new Map([[`FiniteSets`,/* @__PURE__ */ new Map([[`IsFiniteSet`,`public static tlc2.value.IBoolValue tlc2.module.FiniteSets.IsFiniteSet(tlc2.value.impl.Value)`],[`Cardinality`,`public static tlc2.value.impl.IntValue tlc2.module.FiniteSets.Cardinality(tlc2.value.impl.Value)`]])],[`Sequences`,/* @__PURE__ */ new Map([[`Seq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Seq(tlc2.value.impl.Value)`],[`Len`,`public static tlc2.value.impl.IntValue tlc2.module.Sequences.Len(tlc2.value.impl.Value)`],[`Head`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Head(tlc2.value.impl.Value)`],[`Tail`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Tail(tlc2.value.impl.Value)`],[`Append`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Append(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`\\o`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Concat(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SubSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SubSeq(tlc2.value.impl.Value,tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SelectSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SelectSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`]])],[`TLC`,/* @__PURE__ */ new Map([[`Print`,`public static tlc2.value.impl.Value tlc2.module.TLC.Print(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`PrintT`,`public static tlc2.value.impl.Value tlc2.module.TLC.PrintT(tlc2.value.impl.Value)`],[`ToString`,`public static tlc2.value.impl.Value tlc2.module.TLC.ToString(tlc2.value.impl.Value)`],[`Assert`,`public static tlc2.value.impl.Value tlc2.module.TLC.Assert(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`:>`,`public static tlc2.value.impl.Value tlc2.module.TLC.MakeFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`@@`,`public static tlc2.value.impl.Value tlc2.module.TLC.CombineFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SortSeq`,`public static tlc2.value.impl.Value tlc2.module.TLC.SortSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`Permutations`,`public static tlc2.value.impl.Value tlc2.module.TLC.Permutations(tlc2.value.impl.Value)`],[`RandomElement`,`public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)`],[`TLCGet`,`public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`],[`TLCEval`,`public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`]])]]),_d=(e,t)=>e.every(e=>Cn(e,t)),vd=Pt([!1,!0]),yd=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return zt(yd(e,t,r),yd(e,r,n))},bd=[`\\cup`,`\\cap`,`\\`],xd=e=>typeof e==`object`&&e.kind===`MixedSet`,Sd=e=>e.kind===`Interval`?B(e).elements:e.elements,Cd=(e,t,n)=>{let r=Sd(t);if(e!==`\\cup`){let t=e===`\\cap`;return Ft(r.filter(e=>Cn(e,n)===t))}if(r.length===0)return n;if(!je(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!Cn(e,t));return Ft([...r,...i])},wd=[Or(`TRUE`,!0),Or(`FALSE`,!1),Or(`BOOLEAN`,vd),Or(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),jr(`=`,Mt),jr(`#`,(e,t)=>!Mt(e,t)),K(`~`,1,e=>!br(e,0,`~`)),K(`<=>`,2,e=>br(e,0,`<=>`)===br(e,1,`<=>`)),K(`/\\`,2,e=>br(e,0,`/\\`)&&br(e,1,`/\\`)),K(`\\/`,2,e=>br(e,0,`\\/`)||br(e,1,`\\/`)),K(`=>`,2,e=>!br(e,0,`=>`)||br(e,1,`=>`)),K(`\\in`,2,e=>Cn(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!Cn(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=xr(e,0,`\\subseteq`),n=G(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?_d(B(t.base).elements,n.base):_d(B(t).elements,n)}),...bd.map(e=>K(e,2,t=>{let n=G(t,0,e),r=G(t,1,e);if(je(n)&&je(r)&&!xd(n)&&!xd(r)){if(e===`\\cup`&&V(n))return r;let t=e===`\\cup`?zt:e===`\\cap`?Rt:Lt;try{return t(B(n),B(r))}catch(e){if(!(e instanceof v))throw e}}return je(n)?Cd(e,n,r):e!==`\\`&&je(r)?Cd(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:xr(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=xr(e,0,`UNION`),n=bt(t)?t.elements.filter(bt):[];if(!bt(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(xd(t)||n.some(xd)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{Cn(t,e)||e.elements.push(t)})),Ft(e.elements)}return n.length===0?It:yd(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!P(t))throw new v(`DOMAIN expects a function but received ${U(t)}`);return Ln(t)})],Td=Hr(`Integers`,`Neg`,`IntValue`,1),Ed=e=>{let t=Hr(e,`DotDot`,`IntervalValue`,2);return[Ur(e,`+`,`Plus`,(e,t)=>e+t),Ur(e,`-`,`Minus`,(e,t)=>e-t),Ur(e,`*`,`Times`,(e,t)=>e*t),Ur(e,`^`,`Expt`,(e,t)=>{if(t<0)throw new y(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new y(`0^0 is undefined.`);return e**t}),Ur(e,`\\div`,`Divide`,(e,t)=>{if(t===0)throw new y(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Mr(n))throw Nr(`${e} \\div ${t}`);return n}),Ur(e,`%`,`Mod`,(e,t)=>{if(t<=0)throw new y(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),K(`..`,2,e=>({kind:`Interval`,low:Vr(G(e,0,`..`),t),high:Vr(G(e,1,`..`),t)}))]},Dd=[Or(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),...Ed(`Naturals`),Gr(`<`,(e,t)=>e<t),Gr(`>`,(e,t)=>e>t),Gr(`<=`,(e,t)=>e<=t),Gr(`>=`,(e,t)=>e>=t)],Od=[Or(`Int`,{kind:`InfiniteSet`,name:`Int`}),...Ed(`Integers`),K(`-.`,1,e=>{let t=Vr(G(e,0,`-`),Td);if(Mr(-t))throw Nr(`-${t}`);return-t})],kd=(e,t,n)=>{let r=G(e,t,n),i=yn(r);if(!i)throw new y(`${n}\n${U(r)}`);return i},Ad=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:kd(e,t,n)},jd=(e,t,n)=>typeof e==`string`?Ke(e.slice(t,n)):R(e.slice(t,n)),Md=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Nd=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,Pd=(e,t)=>{let n=gd.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?Br(e,t):e}):t},Fd=Pd(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>Ad(e,0,Md(``,`Len`)).length),K(`\\o`,2,e=>{let t=Ad(e,0,Nd(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=kd(e,1,Nd(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new y(`${Nd(`t \\o s`,`string`)}\n${U(n)}`);return Ke(t+n)}),K(`Append`,2,e=>R([...kd(e,0,Nd(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=kd(e,0,Md(``,`Head`));if(t.length===0)throw new y(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=Ad(e,0,Md(``,`Tail`));if(t.length===0)throw new y(`Attempted to apply Tail to the empty sequence.`);return jd(t,1)}),K(`SubSeq`,3,e=>{let t=Ad(e,0,Md(`first `,`SubSeq`)),n=yr(e,1,`SubSeq`),r=yr(e,2,`SubSeq`);if(n>r)return jd(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new y(`The ${i.position} argument of SubSeq must be in the domain of its first argument:\n${U(G(e,0,`SubSeq`))}\n, but instead it is\n${i.value}`);return jd(t,n-1,r)}),kr(`SelectSeq`,2,e=>{let t=Dr(e,1,`SelectSeq`);return R(kd(e,0,Md(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new y(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),Id=Pd(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(N(t))return _n(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new v(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${Me(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!N(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new y(`Attempted to compute cardinality of the value\n${U(t)}`);return hn(t)})]),Ld=/* @__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`]]]),Rd=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:Dd};case`Integers`:return{extends:[`Naturals`],operators:Od};case`Sequences`:return{extends:[],operators:Fd};case`FiniteSets`:return{extends:[],operators:Id};case`TLC`:return{extends:[],operators:Pd(`TLC`,ld(t,n))};case`Randomization`:return{extends:[],operators:Bu(n)};case`_Possible`:return{extends:[],operators:td(t,n)};case`Json`:return{extends:[],operators:Pu(r)};case`Bags`:return{extends:[],operators:pu};case`TLCExt`:return{extends:[],operators:ed(t,n)};default:return}},zd=`$subexpression`,Bd=(e,t)=>new p(`${e} at line ${t.line}, column ${t.column}`),Vd=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Hd=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Ud=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}},Wd=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:gi(e.bounds),body:e.body,sets:Vd(e.bounds)};case`SetMap`:return{names:gi(e.bounds),body:e.expression,sets:Vd(e.bounds)};case`SetFilter`:return{names:hi(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:hi(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}},Gd=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Gd(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of hr(e)){let e=Gd(r,t,n);if(e)return e}},Kd=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,qd=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Jd=(e,t)=>{let n=e.location,r=qd(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 Bd(`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 Bd(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:zd,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:zd,args:e.args,location:n,resolution:ai},location:n}},Yd=(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:ai})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:ai}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:ai};return Jd({...t,params:[...t.params,...r]},a)},Xd=(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 Bd(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>ta(e)===l):t(l);if(u)return{definition:u,args:Kd(s,ui(u),r)};a.index++}throw Bd(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=ui(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Bd(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Bd(`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&&Gd(a.current,t.name,[]);if(!o)throw Bd(`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(...Kd(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Bd(`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`||Hd(t.operand,1)!==0)throw Bd(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Wd(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(...Kd(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[Hd(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Bd(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Hd(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Bd(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Bd(`Unexpected subexpression selector`,n);let c=s?s.sets:Ud(o),u=c?.[Hd(t.operand,c.length)];if(!u)throw Bd(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Yd(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 Bd(`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 Yd(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Bd(`Subexpression selection failed`,n);return Jd(i,a.current)},Zd=(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:[]}))]},Qd=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||hr(e).some(Qd),$d=(e,t)=>{if(!Qd(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return ia(e,e=>$d(e,n))}let n=ia(e,e=>$d(e,t));if(n.kind===`Subexpression`)return Xd(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Zd(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Xd(i,t,n.location,a);if(a.length>0)throw Bd(`Too many arguments for ${r}`,n.location);return o},ef=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},tf=(e,t)=>{let n=ef(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:$d(e.expression,n)}))}},nf=(e,t)=>{let n=ef([...t,...e.definitions]);return e.definitions.some(e=>Qd(e.body))||e.assumptions.some(e=>Qd(e.expression))?{...e,definitions:e.definitions.map(e=>ra(e,e=>$d(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:$d(e.expression,n)}))}:e},rf=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}])),af=(e,t)=>`${e}${t}`,of=(e,t,n)=>`${e}${t}${n}`,sf=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},cf=(e,t,n)=>`${e},${t},${n}`,lf=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),uf=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),df=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),ff=(e,t,n,r)=>({...lf(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),pf=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,mf=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,hf=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,{...ff(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),gf=ff(`$Set`,0,[2],[1]),_f=ff(`$Junction`,0,[3],[1]),vf=ff(`$Choose`,0,[2],[1]),yf=ff(`$Function`,0,[3],[1]),bf=ff(`$FcnApply`,0,[2,2],[1,1]),xf=ff(`$RcdSelect`,0,[2,0],[1,1]),Sf=ff(`'`,2,[1],[0]),Cf=ff(`ENABLED`,1,[2],[0]),wf=ff(`[]`,3,[3],[0]),Tf=ff(`$SquareAct`,2,[2,1],[0,0]),Ef=ff(`$WF`,3,[1,2],[0,0]),Df=ff(`$TemporalExists`,3,[3],[0]),Of=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),kf=e=>e.map(e=>({name:e,arity:0})),Af=(e,t)=>t.location.range?g(`${e}.`,t.location.range):new p(`${e} at line ${t.location.line}, column ${t.location.column}`),jf=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),Mf=e=>e.kind!==`Let`&&e.kind!==`Label`,Nf=e=>{let t=/* @__PURE__ */ new Map,n=(t,n)=>{let r=n.get(t);if(r?.kind===`Formal`)return{kind:`Declared`,name:t,level:0,arity:r.arity};if(r?.kind===`Let`)return{kind:`Defined`,levels:v(r.definition,r.scope)};if(e.constants.has(t))return{kind:`Declared`,name:t,level:0,arity:0};if(e.variables.has(t))return{kind:`Declared`,name:t,level:1,arity:0};let i=e.getDefinition(t);if(i){let n=v(i,/* @__PURE__ */ new Map),r=e.getQualifiedName?.(t);return{kind:`Defined`,levels:r?{...n,name:r}:n}}let a=hf.get(t)??rf.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=lf(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(of(e,n,t))}),t.data.constraints.forEach((e,t)=>uf(r.constraints,t,e)),df(r.argConstraints,af(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>df(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>pf(e,n))throw new p(`Level error in applying operator ${e.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator`)}),n.some(e=>e.level>2))throw new p(`Level error in applying operator ${e.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`);let a=n=>{let r=e.formals.findIndex(e=>e.name===n);return r===-1?void 0:t[r]},o=(t,n,r)=>e.conditions.has(cf(t,n,r)),s=lf(Math.max(e.level,...t.filter((t,n)=>mf(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)=>{mf(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)=>uf(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||uf(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>uf(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||uf(s.constraints,t,pf(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=>uf(s.constraints,e,pf(r,a)))}))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator)?.operator;n&&uf(s.constraints,t.param,pf(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>df(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>df(s.argConstraints,af(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&df(s.argConstraints,af(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);n&&df(s.argConstraints,af(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(sf(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(of(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(of(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(of(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=_(`LAMBDA`,kf(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=lf();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=Of(n,kf(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 Af(`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 Af(`Action used where only temporal formula or state predicate allowed`,e);jf.has(e.operator)&&l(t,e)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&Mf(n)&&n.kind!==r)throw Af(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e)},f=(e,t)=>{let n=new Map(t);e.definitions.forEach(e=>n.set(e.name,{kind:`Let`,definition:e,scope:n}));let r=m(e.body,n),i={level:r.level,params:new Set(r.params),constraints:new Map(r.constraints),argConstraints:new Map(r.argConstraints),argParams:new Set(r.argParams)};return e.definitions.forEach(e=>{let t=v(e,n);t.constraints.forEach((e,t)=>uf(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>df(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{try{return h(e,t)}catch(t){throw!(t instanceof p)||t.sany?t:Af(t.message,e)}},h=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return lf();case`Identifier`:return c(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return u(e,r),c(n(e.operator,t),r)}case`OperatorReference`:case`Lambda`:return a(e,t).data;case`And`:case`Or`:{let n=o(e.operands,t);return l(n,e),i(_f,n)}case`Prime`:case`Unchanged`:return s(Sf,[e.expression],t);case`Enabled`:return s(Cf,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(wf,[n])}case`If`:return s(_f,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(_f,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return f(e,t);case`Forall`:case`Exists`:{let n=s(_f,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds)),r=n.level===3?e.bounds.find(e=>m(e.set,t).level===2):void 0;if(r)throw Af(`Action-level bound of quantified temporal formula`,r.set);return n}case`UnboundedQuantifier`:return s(e.isTemporal?Df:_f,[e.body],t,[],e.names);case`Choose`:return s(vf,[e.body],t,e.set?[e.set]:[],hi(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(gf,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(gf,[e.predicate],t,[e.bound.set],hi(e.bound.pattern));case`SetMap`:return s(gf,[e.expression],t,e.bounds.map(e=>e.set),gi(e.bounds));case`FunctionConstruction`:return s(yf,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds));case`Record`:return s(yf,e.fields.map(e=>e.value),t);case`RecordSet`:return s(gf,e.fields.map(e=>e.value),t);case`Except`:return s(gf,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(bf,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(gf,e.args,t)}]);case`FieldAccess`:return i(xf,[a(e.record,t),{data:lf()}]);case`BoxAction`:case`AngleAction`:return s(Tf,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(Ef,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return lf()}},g=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>g(e,a,n,i),o=(e,o)=>{let s=n(e,t);s.kind===`Declared`?(r&&i.add(e),o.forEach(e=>a(e))):o.forEach((e,t)=>a(e,r||s.levels.nonLeibniz.has(t)))};switch(e.kind){case`Identifier`:return o(e.name,[]),i;case`Apply`:return o(e.operator,e.args),i;case`Lambda`:case`Let`:return i;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:case`BoxAction`:case`AngleAction`:case`WeakFairness`:case`StrongFairness`:return hr(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,Of(t,kf(e.names))),i;default:return ia(e,(e,n)=>(a(e,r,Of(t,kf(n))),e)),i}},_=(e,t,n,r)=>{let i=Of(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=g(n,i),c={...lf(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(af(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(of(e.name,n,t.name))).map(e=>cf(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(sf(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=sf(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},v=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...lf(),name:e.name,formals:i,maxLevels:i.map(()=>3),weights:i.map(()=>0),minMaxLevels:i.map(()=>[]),conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set});let a=e.kind===`Function`?{kind:`FunctionConstruction`,bounds:e.bounds,body:e.body,location:e.location}:e.body,o=_(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:v,toOperand:a}},Pf=(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`?Pf(e,r,n):n.analyze(e,r)}),n.analyze(e.conclusion,r)},Ff=(e,t)=>{let n=Nf(t);Ji([...e.definitions.filter(e=>!e.name.includes(`!`)).map(e=>({location:e.location,check:()=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)})),...e.assumptions.map(e=>({location:e.location,check:()=>n.analyze(e.expression,/* @__PURE__ */ new Map)})),...e.theorems.map(e=>({location:e.location,check:()=>e.statement.kind===`AssumeProve`?Pf(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map)}))])},If=(e,t)=>e.maxLevels[t]??3,Lf=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=Nf({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=>uf(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>uf(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>df(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=sf(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 Map;if(e.forEach(e=>{let n=h(e.location.range??{module:e.instancer,start:e.location,end:e.location}),i=e=>o.set(`${n}\n${e}`,{location:n,message:e}),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}':\nThe level of the expression or operator substituted for '${t}' \nmust 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}':\n 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(af(t.name,a));o!==void 0&&If(r,a)<o&&i(`Level error in instantiating module '${e.module}':\nThe level of the argument ${a+1} of the operator ${r.name} \nmust be at least ${o}.`)})}),c.argParams.forEach(t=>{let n=sf(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=If(r,n.index);a.level>o&&i(`Level error when instantiating module '${e.module}':\nThe level of the argument ${n.index} of the operator ${n.operator}' \nmust be at most ${o}.`)})}),o.size>0)throw m([...o.values()])},Rf=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],zf=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Bf=new Map(dd.flatMap(e=>e.map(t=>[t,e[0]]))),Vf=e=>Bf.get(e)??e,Hf=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Uf=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Hf(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()}},Wf=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Gf=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Vf(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Vf(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}},Kf=(e,t)=>{let n=[];for(let r=t;;){let t=Gf(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},qf=e=>({line:e.line,column:e.column}),Jf=(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=Kf(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},Yf=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Xf={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Zf=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Yf(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Yf(e[n+1],e[n+2])?n+=Yf(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=>Xf[e])}"`:r.text)}return t},Qf=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},$f=(e,t)=>e.find(e=>e.name===t)??e.map(e=>$f(e.modules,t)).find(Boolean),ep=(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:hd.get(i)??t?.(i)??sl(e,i),s=o===void 0?[]:fe(o),c=Qf(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=ll(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>$f(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},tp=(e,t,n)=>{let r=ep(e,t),i=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],a=(e,n)=>{let i=Kf(t,e+1);r.push({location:qf(t[e]),apply:e=>i.forEach(t=>e.put(Wf(t,n,!1)))})},s=new Set(n.definitions.filter(e=>e.isRecursive).map(e=>e.name)),c={value:0};t.slice(e.start,e.end).forEach((n,o)=>{let l=e.start+o,u=t[l];if(u.kind===`Separator`&&t[l+1]?.text===`MODULE`){if(c.value++,c.value===2){let e=t[l+2].text;r.push({location:qf(u),apply:t=>t.put(Wf(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&a(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&a(l,`variable`),u.text===`RECURSIVE`&&Kf(t,l+1).every(e=>s.has(e))&&a(l,`definition`),zf.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(qf(u)),r.push({location:qf(u),apply:e=>e.put(Wf(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(Wf(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=Vf(e.name);r.push({location:e.location,apply:n=>n.put(Wf(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=o(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),a=n.filter(e=>e.kind===`theorem`);[...i,...a].forEach(n=>{n.isLocal||t.put(Wf(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Wf(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>li(e.location,t.location)?-1:+!!li(t.location,e.location))},a=/* @__PURE__ */ new Map,o=e=>{let t=a.get(e??``);if(t)return t;let n=Uf();a.set(e??``,n),ud.toReversed().forEach(e=>n.put(Wf(e,`builtin`,!1)));let s=r(e);return s.getModule().extends.forEach(e=>o(e).inserted.forEach(e=>{e.isLocal||n.put(e)})),i(s).forEach(e=>e.apply(n)),n};return o(void 0).enumerate().filter(e=>e.kind===n).map(e=>e.name).reverse()},np=(e,t,n)=>{let r=ep(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)}),fd.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=Jf(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;Zf(s(void 0)).forEach((e,t)=>{t===3&&md.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),Zf(s(n)).forEach(a))}Rf.forEach(a);let x=/* @__PURE__ */ new Set,ee=e=>{if(x.has(e))return;x.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(ee),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return ee(void 0),pd.forEach(a),[...i]},rp=t=>{switch(t.kind){case`Number`:try{return Ne(t.value)}catch(t){throw n(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return nt(t.name);case`Set`:return Pt(t.elements.map(rp))}},ip=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],ap=e=>new p(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),op=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:ai},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),sp=(e,t,n)=>{let r=`{ ${n.map(e=>`<${[...e[0],e[1]].map(e=>U(e)).join(`, `)}>`).join(`, `)}}`;return{kind:`Builtin`,name:e,arity:t,evaluate:e=>{let t=n.find(t=>{if(t[0].length!==e.length)throw new v(`Attempted to apply the operator ${r}\nwith wrong number of arguments.`);return t[0].every((t,n)=>{let r=e[n];return(typeof r!=`object`||r.kind!==`Operator`)&&at(t,r)})});if(t)return t[1];throw new v(`Attempted to apply operator:\n${r}\nto arguments (${e.map(e=>typeof e==`object`&&e.kind===`Operator`?e.name:U(e)).join(`, `)}), which is undefined.`)},evaluateUnary:void 0,evaluateBinary:void 0}},cp=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||hr(e).some(e=>cp(e,t)),lp=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(pa(e),n.get(e)??n.size)),n},up=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),dp=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw Po(e);if(e.kind===`Number`&&!Cs(e.value))throw Fo(e);dp(e.kind===`Let`?[...hr(e),...up(e.instances??[])]:hr(e))}),fp=(e,t)=>{let n=ll(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=new Map(wd.map(e=>[e.name,e])),s=/* @__PURE__ */ new Map,c=Wl(e.checkDeadlock,t.seed),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=[],f=/* @__PURE__ */ new Map,h=[],g=[],b=(e,t)=>h.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),x={value:0},ee=e=>`${e}#${x.value++}`,te=[],ne=/* @__PURE__ */ new Map,re=/* @__PURE__ */ new Map,ie=e=>{let n=s.get(e);if(n)return n;let r=Rd(e,t.print,c,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>ie(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{o.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),s.set(e,i),i},S=e=>{let t=ie(e),n=Ld.get(e)??[];return t&&b(e,n),t&&n.includes(`Integers`)&&ie(`Integers`),t},ae=e=>(dp([...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]),...up(e.instances)]),e.modules.forEach(ae),e);ae(n);let C=(e,n)=>{let r=t.loadModule?.(e)??Ac.get(e)??sl(t.source,e);if(r===void 0)throw m([{location:`In module ${n}`,message:`Cannot find source file for module ${e} imported in module ${n}.`}],!0);let i=ll(r);if(i.name!==e)throw m([{location:`Unknown location`,message:`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`}],!0);return ae(i)},oe=e=>{let t=g.indexOf(e.name);if(t!==-1)throw new p(`Circular dependency among .tla files; dependency cycle is: ${[...g.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];g.push(e.name),h.push(n);let i=le(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});h.pop(),g.pop();let a=r.find(e=>n.has(e.name));if(a)throw ap(a);return{linked:i,closure:n}},w=(e,t)=>{let n=l.get(e);if(n)return b(e,f.get(e)??[]),n;let r=oe(C(e,t));return l.set(e,r.linked),f.set(e,r.closure),b(e,r.closure),r.linked},T=(e,t,n,o,s)=>{let c=s?void 0:S(e.module);if(c)return e.name===void 0?c:new Map([...c].map(([t,n])=>[`${e.name}!${t}`,n]));let l=s??w(e.module,t.name),u=ip(l),d=`#${x.value++}`,f=new Map(e.params.map(e=>[e.name,`${e.name}${d}`])),p=qi(tf(e,t),u,t,n);te.push({module:e.module,instancer:t.name,lets:[],substitutions:p,location:e.location});let m=Ta({params:e.params.map(e=>({...e,name:`${e.name}${d}`})),substitutions:new Map([...p].map(([e,t])=>[e,Qi(t,f)])),variables:new Set(l.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(n,s,c)=>{let l=ee(`${s}@${t.name}`);return r.set(l,c(l)),i.set(l,!o),a.set(l,{source:n,prefix:e.params.length}),l},createName:ee}),h=new Set(u.map(e=>e.name)),g=/* @__PURE__ */ new Map;return l.exported.forEach((t,n)=>{if(h.has(n))return;if(e.name===void 0){let r=m.getKey(t.key);u.length>0&&ne.set(r,{name:n,location:e.location}),g.set(n,{key:r,arity:t.arity});return}let r=m.getQualifiedKey(t.key);u.length>0&&ne.set(r,{name:`${e.name}!${n}`,location:e.location}),re.set(r,`${e.name}!${n}`),g.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),g},E=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:ai})),se=(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:E(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),D=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),O=(e,t,n)=>{if(t.arity===0)return{params:[],body:e};if(e.kind===`Lambda`)return{params:e.params.map(e=>({name:e,arity:0})),body:e.body};let r=D(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:E(r,n),location:n}}},ce=(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=D(n.arity);return se(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??w(e.module,n),l=`#${x.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=ip(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};te.push({module:e.module,instancer:n,lets:t,substitutions:new Map(d.map(e=>[e.name,f(e)])),location:o});let p=new Set(e.params.map(e=>e.name)),m=e=>cp(f(e),p),h=d.map(t=>{let n=O(f(t),t,o);return{kind:`Operator`,name:`${t.name}${l}`,params:[...m(t)?e.params:[],...n.params],body:n.body,isLocal:!0,isRecursive:!1,location:o}}),g=[],_=Ta({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:E(e.params,o),location:o,resolution:ai}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:ai}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n,r)=>{let i=`${n}@${e.module}${l}.${g.length}`,a=r(i);return g.push(a.kind===`Operator`?{...a,name:i}:op(a,i)),i},createName:ee}),v=new Set(d.map(e=>e.name)),y=[...c.exported].filter(([e])=>!v.has(e)).map(([t,n])=>{let r=_.getKey(n.key),i=D(n.arity),a=[...e.params,...i];return se(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...y]},k=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),le=(e,a)=>{let o=Rc(e,t.loadClass?.(e.name)),s=new Map([...wd.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,f=[],p=[...o.constants],m=o.variables.map(e=>e.name),h=o.variables.map(e=>e.location),g=(e,t)=>e.forEach((e,n)=>{s.set(n,e),t&&c.set(n,e)});o.extends.forEach(e=>{let t=a.modules.get(e),n=t?void 0: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)=>l.set(t,e)),f.push(r)}),o.constants.forEach(e=>c.set(e.name,{key:e.name,arity:e.arity,declaration:`Constant`})),o.variables.forEach(e=>c.set(e.name,{key:e.name,arity:0,declaration:`Variable`}));let _=p.length===0&&m.length===0,v=e=>o===n?e.name:`${e.name}@${a.id}`,y=/* @__PURE__ */ new Map,b=e=>({imported:s,importedAt:y,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:v}),x=()=>new Map([...a.modules,...l]),ee=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>li(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>li(t.location,e)).map(e=>[e.name,{key:v(e),arity:ui(e)}])]),te=e=>{let t=x();if(t.has(e.name))throw ap(e);a.nested.push(e);let n=le(e,{id:`${a.id}/${e.name}`,symbols:ee(e.location),modules:t,nested:a.nested});l.set(e.name,n),u.has(e.name)||u.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=T(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)=>li(e.location,t.location)?-1:1).forEach(e=>e.link()),Gi(o,b(o));let ne=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&li(e.location,t.location)},ie=e=>{let t=o.modules.find(t=>t.name===e.module);return t?ne(t)?l.get(t.name):void 0:x().get(e.module)},ae=nf(ka(o,(e,t)=>ce(e,t,o.name,ie(e))),k(s));Yi(ae,b(ae)),ae.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:ui(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),Ff(ae,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e),getQualifiedName:e=>re.get(s.get(e)?.key??e)});let C={module:ae,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:l,extended:f};return d.push(C),C},ue=oe(n).linked,de=e=>ue.visible.get(e)?.key??e;ue.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let fe=[],pe=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>pe(e,t)),fe.push(...e.module.assumptions))};pe(ue,/* @__PURE__ */ new Set);let me=ue.constants.map(e=>e.name),he=ue.variables,A=e=>e.module===void 0?[e.name,de(e.name)]:e.module===n.name||me.includes(e.name)?[]:[(l.get(e.module)??u.get(e.module))?.visible.get(e.name)?.key??e.name],ge=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:ue.constants.find(t=>t.name===e)?.arity??0},_e=/* @__PURE__ */ new Map,ve=/* @__PURE__ */ new Set,ye=(e,t)=>{o.set(e,t),r.delete(e),_e.delete(e),ve.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=rp(e.value);A(e).forEach(e=>{let n=ge(e);n===0?_e.set(e,t):ye(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 _(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(rp),rp(e.value)]),j.set(t,n)}),j.forEach(e=>A(e).forEach(t=>ye(t,sp(e.name,ge(t)||e.rows[0][0].length,e.rows))));let be=new Map(e.substitutions.flatMap(e=>A(e).map(t=>[t,de(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!me.includes(n)&&!ue.visible.has(n))throw new _(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new _(`In the configuration file, the identifier ${i} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`);let a=de(i),s=r.get(a);if(!(s!==void 0||o.has(a)||_e.has(a)||me.includes(i)||he.includes(i)))throw new _(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(ue.constants.find(e=>e.name===n)?.arity??ue.visible.get(n)?.arity))throw new _(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)});let xe=new Set([...e.constants,...e.substitutions].filter(e=>e.module!==void 0).flatMap(A)),Se=(e,t)=>{if(xe.has(e))return{key:e,prefix:t};let n=a.get(e);return n&&Se(n.source,t+n.prefix)};a.forEach((e,t)=>{let n=Se(e.source,e.prefix),i=r.get(t);if(!n||!i)return;let a=i.kind===`Operator`?i.params:[],o=se(t,n.key,a,a.slice(n.prefix),i.location);r.set(t,o),ue.visible.forEach((e,n)=>{e.key===t&&n!==t&&r.set(n,o)})});let Ce=me.filter(e=>!_e.has(e)&&!be.has(e)&&!ve.has(e));if(Ce.length>0)throw new _(`The constant parameter ${tp(t.source,t.loadModule,`constant`).find(e=>Ce.includes(e))??Ce[0]} is not assigned a value by the configuration file.`);let we={runtime:c,definitions:r,builtins:o,constants:_e,substitutions:be,variables:he,variableIndex:lp(he,d.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};Lf(te,e=>{let t=l.get(e)??u.get(e)??ue;return{constants:t.constants,variables:t.variables,definitions:[...new Set([...t.visible.values()].flatMap(e=>r.get(e.key)??[]))],assumptions:t.module.assumptions.map(e=>e.expression),getDefinition:e=>r.get(t.visible.get(e)?.key??e)}});let Te=Nf({constants:new Set(_e.keys()),variables:/* @__PURE__ */ new Set([...he,...[`TLCGet`,`Trace`,`CounterExample`].filter(e=>o.has(e))]),getDefinition:e=>Vo(e,we)}),Ee=e=>{try{X(e,{environment:we,scope:void 0,state:void 0,next:void 0});return}catch(e){if(e instanceof v)return e;throw e}};return be.forEach((e,t)=>{let n=r.get(e),i=me.includes(t)&&n?.kind===`Operator`&&n.params.length===0&&Te.analyzeDefinition(n,/* @__PURE__ */ new Map).level>0?Ee(n.body):void 0;if(i)throw new _(`The configuration file substitutes constant ${t} with non-constant ${e}${i instanceof y?``:` - specifically: ${i.message}`}`)}),c.isStarted=!0,{environment:we,assumptions:fe,variableLocations:ue.variableLocations,instanceActions:ne}},pp={kind:`Boolean`,value:!0},mp={kind:`Boolean`,value:!1},hp=e=>e?pp:mp,gp=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,_p=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),vp=(e,t,n)=>({kind:e,operands:[t,n]}),yp=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?yp(e,t.operands).operands:[t])}),bp=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return bp(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,bp(t)),0)}},xp=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 xp(e.body);case`And`:case`Or`:return e.operands.some(xp)}},Sp=/* @__PURE__ */ new WeakMap,Cp={count:0},wp=e=>{let t=Sp.get(e);if(t!==void 0)return t;let n=(()=>{switch(e.kind){case`Boolean`:return String(e.value);case`State`:case`Enabled`:case`Action`:return`#${Cp.count++}`;case`And`:case`Or`:return`${e.kind}(${e.operands.map(wp).join(`,`)})`;default:return`${e.kind}(${wp(e.body)})`}})();return Sp.set(e,n),n},Tp=(e,t)=>e===t||wp(e)===wp(t),Ep=(e,t)=>{let n=wp(t);return e.some(e=>e===t||wp(e)===n)},Dp=e=>e===`And`?`Or`:`And`,Op=(e,t)=>{switch(e.kind){case`Boolean`:return t?hp(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return Op(e.body,!t);case`And`:case`Or`:return yp(t?Dp(e.kind):e.kind,e.operands.map(e=>Op(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,Op(e.body,t))}}},kp=e=>{switch(e.kind){case`Boolean`:return hp(!e.value);case`Not`:return e.body;case`And`:case`Or`:return yp(Dp(e.kind),e.operands.map(kp));case`Always`:return Q(`Eventually`,kp(e.body));case`Eventually`:return Q(`Always`,kp(e.body));default:return Q(`Not`,e)}},Ap=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=Ap(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return hp(t)}return n.length===0?hp(!t):n.length===1?n[0]:yp(e.kind,n)}case`Not`:{let t=Ap(e.body);return t.kind===`Boolean`?hp(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=Ap(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},jp=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,Mp=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=Mp(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new v(`TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form.`);t.push(e)}}if(n.value===1)return{kind:`And`,operands:t};let r=Array.from({length:n.value},()=>[]),i={groups:1,repeat:n.value};for(let e of t){if(e.kind!==`Or`){r.forEach(t=>t.push(e));continue}i.repeat/=e.operands.length;let t={value:0};for(let n=0;n<i.groups;n++)for(let n of e.operands)for(let e=0;e<i.repeat;e++)r[t.value++].push(n);i.groups*=e.operands.length}return{kind:`Or`,operands:r.map(e=>yp(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=Mp(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=jp(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:yp(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return yp(`Or`,n)}case`Not`:return gp(e.body)?e:Mp(kp(e.body));default:return e}},Np=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?Np(e.operands[0]):yp(e.kind,e.operands.map(Np));case`Not`:return e.body.kind===`Not`?Np(e.body.body):Q(`Not`,Np(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Np(e.body));default:return e}},Pp=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return Pp(e.operands[0]);let t=Math.floor(e.operands.length/2);return vp(e.kind,Pp(yp(e.kind,e.operands.slice(0,t))),Pp(yp(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Pp(e.body));default:return e}},Fp=(e,t)=>{e.kind===`Eventually`&&!Ep(t,e)&&t.push(e),`body`in e&&Fp(e.body,t),`operands`in e&&e.operands.forEach(e=>Fp(e,t))},Ip=e=>{let t=e.filter(_p),n=e.flatMap(e=>e.kind===`Not`&&_p(e.body)?[e.body]:[]);return!t.some(e=>Ep(n,e))},Lp=e=>{let t=[...e],n=[];for(;t.length>0;){let e=t.pop();if(!e)break;switch(e.kind){case`Not`:t.push(e.body);break;case`Next`:n.push(e),t.push(e.body);break;case`Always`:case`Eventually`:n.push(e,Q(`Next`,e)),t.push(e.body);break;case`And`:case`Or`:t.push(...e.operands),n.push(e);break;case`Action`:throw new v(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},Rp=(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]}},zp=(e,t,n)=>e.flatMap(e=>{let r=Rp(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),Bp=e=>[...new Set(e.map(wp))].sort().join(`|`),Vp=(e,t)=>{let n=new Set(t.map(Bp));return[...e.filter(e=>!n.has(Bp(e))),...t]},Hp=e=>{let t=Lp(e),n=zp(t,`Always`,`And`),r=zp(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=Rp(t,`Eventually`,`Or`);if(n&&!(Ep(e,n.first)||Ep(e,n.second)))return Vp(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(Ep(e,t.first)||Ep(e,t.second))&&!Ep(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!Ip(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=Rp(t[e],`Always`,`And`);n&&(Ep(t,n.first)||t.push(n.first),Ep(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)Ep(t,e.first)&&Ep(t,e.second)&&!Ep(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!Ip(t)?[]:i(t)};return a(e)},Up=e=>({particle:e,successors:[],statePredicates:e.filter(e=>bp(e)<=1)}),Wp=e=>{let t=Hp([e]).map(Up),n=t.length,r=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let n=Bp(e.particle);r.has(n)||r.set(n,t)});for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let i of Hp(n)){let n=Bp(i),a=r.get(n);a===void 0&&(r.set(n,t.length),t.push(Up(i))),t[e].successors.push(a??t.length-1)}}return{nodes:t,initialCount:n}},Gp=(e,t)=>!Ep(e,t)||Ep(e,t.body),Kp=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&bp(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=jp(e);if(n){let e=bp(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(xp(e))throw new v(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},qp=(e,t)=>{let n=e.findIndex(e=>Tp(e,t));return n===-1?(e.push(t),e.length-1):n},Jp=e=>{let t=Mp(Ap(Op(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=Np(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])Kp(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:yp(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:Tp(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&Pp(e.formula),n=[];t&&Fp(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>qp(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>qp(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>qp(i,e))}));return{tableau:t&&Wp(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Yp=/* @__PURE__ */ new Set([`~>`,`-+->`]),Xp=/* @__PURE__ */ new WeakMap,Zp=/* @__PURE__ */ new WeakSet,Qp=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),$p=(t,r)=>{try{return X(t,r)}catch(t){if(!(t instanceof v)||t instanceof y)throw t;let r=o(t);throw r===void 0?n(new v(`${l}${t.message}`,t),e.error):n(t,r)}},em=e=>new v(`TLC cannot handle the temporal formula at ${To(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Io(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=Vo(e,n);if(t)return tm(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 ia(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 Yp.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},tm=(e,t)=>{let n=Xp.get(e);if(n!==void 0)return n;Xp.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 Xp.set(e,i),i},nm=`Temporal formula is a tautology (its negation is unsatisfiable).`,rm=(t,r,i,a,o=``,s=/* @__PURE__ */ new Set)=>{let c=(e,t,n=o,r=s)=>rm(e,t,i,a,n,r);if(t.kind===`And`)return t.operands.flatMap(e=>c(e,r,Eo(e)));if(t.kind===`Label`)return c(t.body,r);if(t.kind===`Let`)return c(t.body,im(t,r,i));if(t.kind===`Identifier`){let o=W(t)?Io(r,t.name):void 0;if(o?.kind===`Thunk`)return c(o.expression,o.scope);let l=i.constants.has(t.name)?void 0:Vo(t.name,i);if(!o&&l?.kind===`Operator`&&l.params.length===0&&tm(l,i)>0){if(s.has(l))throw n(new v(u),e.error);let r=c(l.body,void 0,t.name,/* @__PURE__ */ new Set([...s,l]));return!a&&tm(l,i)<2?[{expression:l.body,scope:void 0,name:t.name}]:r}}let l=Qp(i,r);if(t.kind===`Apply`&&(e=>a||$(e,r,i)===3)(t)){let e=ss(t,l),n=W(t)?void 0:Vo(t.operator,i);if(e?.kind===`Closure`&&e.params.length===t.args.length&&!n?.isRecursive)return c(e.body,ys(e,t.args,l),t.operator)}if(a&&t.kind===`Forall`&&t.bounds.every(e=>$(e.set,r,i)===0)){let r=[],i={count:0};if(Ko(t.bounds,l,e=>(i.count++,r.push(...c(t.body,e,Eo(t.body))),!1)),i.count===0)throw n(new v(nm),e.livenessEvaluationFailure);return r}return[{expression:t,scope:r,name:o}]},im=(e,t,n)=>{let r=xs(e.definitions,Qp(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&Zp.add(e.binding);return r},am=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),om=(t,r,i)=>{let a=(e,t,n)=>{let r=n===0?$(e,t,i):n;if(r===0){let n=$p(e,Qp(i,t));if(typeof n!=`boolean`)throw new v(`TLC expected a boolean in the temporal formula at ${To(e)}`);return hp(n)}return r===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},o={depth:0},s=(t,r,i,s)=>{if(o.depth>=100)throw n(new v(u),e.error);o.depth++;let c=f(t,r);o.depth--;let l=bp(c);return l>2?c:a(i,s,l)},c=(e,t)=>{let n=e.kind===`Identifier`?e.name:e.operator,r=Qp(i,t),a=W(e)||Vo(n,i)===void 0?Io(t,n):void 0;if(a?.kind===`Thunk`&&Zp.has(a))return s(a.expression,a.scope,e,t);let o=a?.kind===`Operator`?a.operator:a?void 0:W(e)?cs(n,r):as(n,i);if(o?.kind!==`Closure`)throw em(e);let c=e.kind===`Apply`?e.args:[];return s(o.body,ys(o,c,r),e,t)},l=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,i)===0))throw em(e);let n=[];Ko(e.bounds,Qp(i,t),t=>(n.push(f(e.body,t)),!1));let r=e.kind===`Forall`;if(n.length===0)return hp(r);let o=yp(r?`And`:`Or`,n),s=bp(o);return s>2?o:a(e,t,s)},d=(e,t)=>{switch(e.kind){case`Label`:f(e.body,t);return;case`Let`:f(e.body,im(e,t,i));return;case`And`:case`Or`:for(let n of e.operands)f(n,t);return;case`Apply`:if(e.operator===`=>`||e.operator===`~`&&!W(e))for(let n of e.args)f(n,t);return;case`If`:{let n=f(e.condition,t),r=n.kind===`Boolean`?[n.value?e.consequent:e.alternative]:[e.consequent,e.alternative];for(let e of r)f(e,t)}}},f=(e,t)=>{let n=$(e,t,i);if(n<=2)return d(e,t),a(e,t,n);switch(e.kind){case`Label`:return f(e.body,t);case`Let`:return f(e.body,im(e,t,i));case`Identifier`:return c(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,vp(`Or`,Q(`Not`,f(n[0],t)),Q(`Eventually`,f(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,f(n[0],t)):e.operator===`=>`?vp(`Or`,Q(`Not`,f(n[0],t)),f(n[1],t)):c(e,t)}case`And`:case`Or`:return yp(e.kind,e.operands.map(e=>f(e,t)));case`Forall`:case`Exists`:return l(e,t);case`If`:{if($(e.condition,t,i)===0){let n=$p(e.condition,Qp(i,t));if(typeof n==`boolean`)return f(n?e.consequent:e.alternative,t)}let n=f(e.condition,t);return vp(`Or`,vp(`And`,n,f(e.consequent,t)),vp(`And`,Q(`Not`,n),f(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,f(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=am(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`,vp(`Or`,i,a))):vp(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw em(e)}};return f(t,r)},sm=(e,t,n,r,i)=>{let a=e=>sm(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`?Bo(X(e.expression,a),`a temporal property predicate`):bo(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&&Bo(X(e.unchanged,a),`a subscript`)?!1:Bo(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 sm(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new v(`TLC cannot evaluate a temporal formula in a single step`)}},cm=(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)=>cm(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 sm(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},lm=(e,t)=>e.every((e,n)=>st(e,t[n])),um=e=>e.filter((t,n)=>n===0||e[n-1]!==t),dm=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.pending.push(void 0),e.offsets.push(-1),e.edgeOffsets.push(-1),e.nodeStates.length-1),fm=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},pm=(e,t)=>(e.offsets[t]??-1)!==-1,mm=(e,t)=>e.pending[t]??=[],hm=(e,t)=>{let n=e.edgeOffsets[t];return e.edges.ids.subarray(n+1,n+1+e.edges.ids[n])},gm=(e,t,n)=>e.results.bytes[e.offsets[t]+n]===1,_m=2**53-1,vm=(t,r,i,a)=>{if(t.length===0)return;let o=r.map(e=>om(e.expression,e.scope,i)),s=t.map(e=>Q(`Not`,om(e.expression,e.scope,i))),c=s.length===1?s[0]:yp(`Or`,s),l=o.length===0?c:yp(`And`,[...o,c]),u=Jp(l);if(u.length===0)throw n(new v(nm),e.livenessEvaluationFailure);let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=wp(e),n=d.get(t)??d.size;return d.set(t,n),n}),nodeStates:[],nodeTableaux:[],pending:[],offsets:[],results:{bytes:/* @__PURE__ */ new Uint8Array(1024),length:0},edgeOffsets:[],edges:{ids:/* @__PURE__ */ new Int32Array(1024),length:0},initial:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!Ns(i),h={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},g=e=>{let t=h.states.get(e)??/* @__PURE__ */ new Map;return h.states.set(e,t),t},_=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},y=(e,t)=>sm(e,t,void 0,i,m?g(t):/* @__PURE__ */ new Map),b=(e,t,n)=>_(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!y(e,n))),x=(e,t,n,r)=>_(t,()=>{let t=e.solution.actionChecks;if(!m)return Uint8Array.from(t,e=>+!!sm(e,n,r,i,/* @__PURE__ */ new Map));let a=g(n),o=h.actions.get(n)??/* @__PURE__ */ new Map;h.actions.set(n,o);let s=o.get(r)??new Int8Array(d.size).fill(-1);return o.set(r,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!sm(t[o],n,r,i,a)),s[e]))}),ee=(e,t,n,r)=>_(n,()=>e.nodes[t].statePredicates.every(e=>y(e,r))),te=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},ne=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),re=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=fm(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},ie=(e,t,n)=>{let r=dm(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),fm(i,e[t]-1,e[t+1]))}return i.slots.set([t+1,n,r],fm(i,t,n)),r},S=(e,t,n)=>t.nodes.flatMap((t,r)=>re(e,n,r)??[]).sort((e,t)=>e-t),ae=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=e.results,o=a.length;if(a.length+=r.length+n.length*i,a.length>a.bytes.length){let e=new Uint8Array(Math.max(2*a.bytes.length,a.length));e.set(a.bytes),a.bytes=e}a.bytes.set(r,o),n.forEach((e,t)=>a.bytes.set(e,o+r.length+t*i)),e.offsets[t]=o;let s=e.pending[t]??[],c=e.edges,l=c.length;if(c.length+=s.length+1,c.length>c.ids.length){let e=new Int32Array(Math.max(2*c.ids.length,c.length));e.set(c.ids),c.ids=e}c.ids[l]=s.length,c.ids.set(s,l+1),e.edgeOffsets[t]=l,e.pending[t]=void 0},C=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t.index)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&lm(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},oe=(e,t,n,r,i)=>{let o=b(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=mm(e,i),u=s.successors.length>0?x(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ee(t,a,r,n))continue;if(te(t,a)&&e.errorNode===void 0&&ne(e)){e.errorNode=i;return}let o=re(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??ie(e,r,a);l.push(s),c.push(u),o===void 0&&oe(e,t,n,r,s)}for(let i of a.getSuccessors(n)){let a=x(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ee(t,n,r,i.state))continue;let s=re(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??ie(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&oe(e,t,i.state,i.index,u)}}l.length>0&&ae(e,i,c,o)},w=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ee(t,r,a,e.state)));e.isDone[a]=!0;for(let s of S(e,t,a)){let a=mm(e,s),c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=re(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??ie(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&oe(e,t,n.state,n.index,d)}}),ae(e,s,c,i)}if(e.errorNode!==void 0)return um(E(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},T=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)dm(e,e.nodeStates.length,-1);let a=mm(e,i),o=[];t.forEach((t,r)=>{pm(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),ae(e,i,o,r)},E=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)pm(e,t)&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of hm(e,a))if(!(i===a&&e.solution.tableau)){if(i===t){let e=[t];for(let t=a;t!==-1;t=n.get(t)??-1)e.push(t);return e}pm(e,i)&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new v(`Couldn't re-create liveness trace (path) starting at: ${t}`)},se=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=n.stateChecks.length,a=(t,n,a)=>e.results.bytes[e.offsets[t]+i+n*r+a]===1,o=(e,n)=>t.eventuallyAlways.every(t=>a(e,n,t)),s=new Float64Array(e.nodeStates.length).fill(-1),c=e.initial.filter(t=>pm(e,t)),l=[],u=t=>{let n=hm(e,t).indexOf(t);return n!==-1&&o(t,n)},d=(t,r)=>n.tableau!==void 0&&Gp(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let i=l.pop()??r;if(i===r&&!u(i)){s[i]=_m;return}let c=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=i;;t=l.pop()??r){c.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),s[t]=_m,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...c].some(n=>gm(e,n,t))),h=t.infinitelyOftenActions.every(t=>[...c].some(n=>hm(e,n).some((e,r)=>c.has(e)&&o(n,r)&&a(n,r,t)))),g=n.promises.every(e=>[...c].some(t=>d(t,e)));if(m&&h&&g)return p(r,c,f)},p=(r,i,s)=>{let c=um(E(e,r).reverse().map(t=>e.nodeStates[t])),l=[],u=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),p=t.infinitelyOftenActions.map(()=>!1),h=n.promises.map(()=>!1),g={count:f.length+p.length+h.length},_={node:r},y=e=>i.has(e),b=e=>{l.push(_.node),_.node=e};for(;g.count>0;){let r=g.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&gm(e,_.node,t)&&(f[n]=!0,g.count--)}),n.promises.forEach((e,t)=>{!h[t]&&d(_.node,e)&&(h[t]=!0,g.count--)}),!(g.count<=0);){let n={last:-1,unvisited:-1},i=g.count;if(hm(e,_.node).some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!o(_.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!p[t]&&a(_.node,c,e)&&(p[t]=!0,g.count--)})}return g.count<i?(b(r),u.clear(),!0):(y(r)&&!u.has(r)&&(n.unvisited=r),!1)}))break;if(g.count<r){b(n.last),u.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);_.node=t,n.unvisited=hm(e,t).find(e=>y(e)&&!u.has(e))??-1}b(n.unvisited),u.add(n.unvisited)}}let x=m(r,_.node,s,o);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];x[x.length-1]!==n&&x.push(n)}let ee=c[c.length-1];return x[x.length-1]===ee&&x.pop(),{prefix:c.slice(0,-1),cycle:[ee,...x.reverse()]}},m=(t,n,r,i)=>{if(n===t)return[];let a=e.nodeStates[n],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set([a]),c=[];for(let n=a,l=-1,u=0;;u++){for(let u of r.get(n)??[])for(let[d,f]of hm(e,u).entries()){if(f===u||!i(u,d))continue;if(f===t){let e=[];for(let t=n,r=l;t!==a;)e.push(t),t=r,r=o.get(t)??-1;return e.push(a),e}let p=e.nodeStates[f];r.has(p)&&!s.has(p)&&(s.add(p),c.push([p,n]))}o.set(n,l);let d=c[u];if(d===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<c.length;t++){let n=[c[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),a=n.pop()??0;if(i===-42){if(s[a]===t){let e=f(a);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(s[a]!==-1){n.push(Math.min(t,s[a]));continue}s[a]=r.link,n.push(t,a,-42),l.push(a);let u={value:r.link++};hm(e,a).forEach((t,r)=>{pm(e,t)&&(o(a,r)?s[t]===-1?n.push(t,-1):u.value=Math.min(u.value,s[t]):s[t]===-1&&c.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{h.states.clear(),h.actions.clear();for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ee(r,i,void 0,t)&&n.initial.push(re(n,e,i)??ie(n,e,i))}},addState:(e,t,n)=>{h.states.clear(),h.actions.clear();let r=C(e,t,n);for(let n of f){let i=r.map(r=>x(n,e,t,r.state)),a=b(n,e,t),o=n.solution.tableau,s=o?w(n,o,r,i,a,e):T(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=se(e,t);if(n)return n}},getViolatedProperties:(e,n)=>[...new Set(t.filter((t,r)=>!cm(s[r].body,e,n,0,i)).map(e=>e.name))]}},ym=`UnnamedAction`,bm={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},xm=e=>{let t=e.range??bm;return Xt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},Sm=e=>{let t=[[`name`,e.name],[`location`,xm(e.location)]];return e.parameters.length===0?Xt(t):Xt([...t,[`context`,Xt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},Cm=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),wm=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),Tm=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,Em=e=>e.kind===`Apply`?e.args:[],Dm=(e,t,n)=>{let r=Tm(e);if(r===void 0)return;if(W(e)){let e=Io(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=as(r,n);return i?.kind===`Closure`?i:void 0},Om=(e,t)=>{try{return X(e,wm(t,void 0)),!0}catch(e){if(e instanceof f)return!1;throw e}},km=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&Uo(e,t)&&Om(e.body,t),Am=(e,t)=>{let n=Vo(e.name,t);return n?.body===e.body&&km(n,t)},jm=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Io(t,e.name);return n?.kind===`Thunk`?n:void 0},Mm=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Io(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),Nm=(e,t)=>{try{return e()}catch(e){if(e instanceof f)return t();throw e}},Pm=(e,t,n,r,i)=>{let a=Em(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():Nm(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,wm(i,n))]),expression:t,scope:n}],o)},Fm=(e,t,n,r,i)=>{let a=()=>({name:n?.name??ym,location:e.location,parameters:Mm(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return Fm(e.body,xs(e.definitions,wm(r,t)),n,r,i);case`Label`:return Fm(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>Fm(e,t,n,r,i));case`Exists`:return Nm(()=>{let o=[];return Ko(e.bounds,wm(r,t),t=>(o.push(...Fm(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get(Tm(e)??``),s=Dm(e,t,r);if(o)return Pm(o,e,t,s,r);if(!s)return[a()];let c=Em(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return Am(s,r)||c.some(e=>$(e,t,r)!==0)?l():Nm(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,wm(r,t))},parent:e}),s.scope);return Fm(s.body,e,s,r,i)},l)},Im=(e,t,n,r,i)=>{let a=(e,t)=>Im(e,t,n,r,i);if(e.kind===`Let`){a(e.body,xs(e.definitions,wm(n,t)));return}let o=jm(e,t);if(o){a(o.expression,o.scope);return}let s=Dm(e,t,n);if(s&&Am(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(Cm(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,ys(s,e.args,wm(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(Cm(ym,e));return}let c=$(e,t,n);c<=1?r.inits.push(Cm(ym,e)):c===3&&r.temporals.push(Cm(ym,e))},Lm=(e,t,n,r,i)=>{let a=(t,n)=>Lm(e,t,n,r,i);if(t.kind===`Let`){a(t.body,xs(t.definitions,wm(r,n)));return}let o=jm(t,n);if(o){a(o.expression,o.scope);return}let s=Dm(t,n,r);if(s&&Am(s,r))return;if(s&&s.params.length===Em(t).length){a(s.body,t.kind===`Apply`?ys(s,t.args,wm(r,n)):s.scope);return}if(t.kind===`Forall`&&Nm(()=>(Ko(t.bounds,wm(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(Cm(e,a)):$(a,n,r)<2?i.invariants.push(Cm(e,a)):i.impliedTemporals.push(Cm(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(Cm(e,t)):c===3&&i.impliedTemporals.push(Cm(e,t))},Rm=(e,t)=>{let n=Vo(e,t);return n?.kind===`Operator`&&!km(n,t)?n:void 0},zm=e=>Xt([[`name`,e.name],[`location`,xm(e.location)]]),Bm=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:Rm(e.specification,t);a&&(Im(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...Fm(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:as(e.init,t);o?.kind===`Closure`&&r.inits.push(Cm(e.init??``,o.body));let s=e.next===void 0?void 0:as(e.next,t);return s?.kind===`Closure`&&r.actions.push(...Fm(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=Rm(e,t);n&&r.invariants.push(Cm(e,n.body))}),e.properties.forEach(e=>{let n=Rm(e,t);n&&Lm(e,n.body,void 0,t,r)}),r},Vm=(e,t,n)=>Bm(e,t,n).actions,Hm=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>U(e[1])).join(`,`)})`,Um=e=>`${e.name===ym?`Action`:e.name}${Hm(e)} ${h(e.location.range??bm)}`,Wm=e=>`${e.name}${Hm(e)}`,Gm=(e,t,n,r)=>{let i=Bm(e,t,r),a=e=>Pt(e.map(Sm)),o=e=>Pt(e.flatMap(e=>{let n=Rm(e,t);return n?[zm(n)]:[]}));return Xt([[`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`,Pt(t.variables.map((e,t)=>Xt([[`name`,e],[`location`,xm(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},Km=`paired12`,qm=(e,t=16)=>e<=t*.75?t:qm(e,t*2),Jm=(e,t)=>{let n=qm(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Ym=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Xm=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Zm=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Qm=e=>Zm(e).replaceAll(`
418
+ `]]),gd=/* @__PURE__ */ new Map([[`FiniteSets`,/* @__PURE__ */ new Map([[`IsFiniteSet`,`public static tlc2.value.IBoolValue tlc2.module.FiniteSets.IsFiniteSet(tlc2.value.impl.Value)`],[`Cardinality`,`public static tlc2.value.impl.IntValue tlc2.module.FiniteSets.Cardinality(tlc2.value.impl.Value)`]])],[`Sequences`,/* @__PURE__ */ new Map([[`Seq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Seq(tlc2.value.impl.Value)`],[`Len`,`public static tlc2.value.impl.IntValue tlc2.module.Sequences.Len(tlc2.value.impl.Value)`],[`Head`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Head(tlc2.value.impl.Value)`],[`Tail`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Tail(tlc2.value.impl.Value)`],[`Append`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Append(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`\\o`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Concat(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SubSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SubSeq(tlc2.value.impl.Value,tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SelectSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SelectSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`]])],[`TLC`,/* @__PURE__ */ new Map([[`Print`,`public static tlc2.value.impl.Value tlc2.module.TLC.Print(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`PrintT`,`public static tlc2.value.impl.Value tlc2.module.TLC.PrintT(tlc2.value.impl.Value)`],[`ToString`,`public static tlc2.value.impl.Value tlc2.module.TLC.ToString(tlc2.value.impl.Value)`],[`Assert`,`public static tlc2.value.impl.Value tlc2.module.TLC.Assert(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`:>`,`public static tlc2.value.impl.Value tlc2.module.TLC.MakeFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`@@`,`public static tlc2.value.impl.Value tlc2.module.TLC.CombineFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SortSeq`,`public static tlc2.value.impl.Value tlc2.module.TLC.SortSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`Permutations`,`public static tlc2.value.impl.Value tlc2.module.TLC.Permutations(tlc2.value.impl.Value)`],[`RandomElement`,`public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)`],[`TLCGet`,`public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`],[`TLCEval`,`public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`]])]]),_d=(e,t)=>e.every(e=>Cn(e,t)),vd=Pt([!1,!0]),yd=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return zt(yd(e,t,r),yd(e,r,n))},bd=[`\\cup`,`\\cap`,`\\`],xd=e=>typeof e==`object`&&e.kind===`MixedSet`,Sd=e=>e.kind===`Interval`?B(e).elements:e.elements,Cd=(e,t,n)=>{let r=Sd(t);if(e!==`\\cup`){let t=e===`\\cap`;return Ft(r.filter(e=>Cn(e,n)===t))}if(r.length===0)return n;if(!je(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!Cn(e,t));return Ft([...r,...i])},wd=[Or(`TRUE`,!0),Or(`FALSE`,!1),Or(`BOOLEAN`,vd),Or(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),jr(`=`,Mt),jr(`#`,(e,t)=>!Mt(e,t)),K(`~`,1,e=>!br(e,0,`~`)),K(`<=>`,2,e=>br(e,0,`<=>`)===br(e,1,`<=>`)),K(`/\\`,2,e=>br(e,0,`/\\`)&&br(e,1,`/\\`)),K(`\\/`,2,e=>br(e,0,`\\/`)||br(e,1,`\\/`)),K(`=>`,2,e=>!br(e,0,`=>`)||br(e,1,`=>`)),K(`\\in`,2,e=>Cn(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!Cn(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=xr(e,0,`\\subseteq`),n=G(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?_d(B(t.base).elements,n.base):_d(B(t).elements,n)}),...bd.map(e=>K(e,2,t=>{let n=G(t,0,e),r=G(t,1,e);if(je(n)&&je(r)&&!xd(n)&&!xd(r)){if(e===`\\cup`&&V(n))return r;let t=e===`\\cup`?zt:e===`\\cap`?Rt:Lt;try{return t(B(n),B(r))}catch(e){if(!(e instanceof v))throw e}}return je(n)?Cd(e,n,r):e!==`\\`&&je(r)?Cd(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:xr(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=xr(e,0,`UNION`),n=bt(t)?t.elements.filter(bt):[];if(!bt(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(xd(t)||n.some(xd)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{Cn(t,e)||e.elements.push(t)})),Ft(e.elements)}return n.length===0?It:yd(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!P(t))throw new v(`DOMAIN expects a function but received ${U(t)}`);return Ln(t)})],Td=Hr(`Integers`,`Neg`,`IntValue`,1),Ed=e=>{let t=Hr(e,`DotDot`,`IntervalValue`,2);return[Ur(e,`+`,`Plus`,(e,t)=>e+t),Ur(e,`-`,`Minus`,(e,t)=>e-t),Ur(e,`*`,`Times`,(e,t)=>e*t),Ur(e,`^`,`Expt`,(e,t)=>{if(t<0)throw new y(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new y(`0^0 is undefined.`);return e**t}),Ur(e,`\\div`,`Divide`,(e,t)=>{if(t===0)throw new y(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Mr(n))throw Nr(`${e} \\div ${t}`);return n}),Ur(e,`%`,`Mod`,(e,t)=>{if(t<=0)throw new y(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),K(`..`,2,e=>({kind:`Interval`,low:Vr(G(e,0,`..`),t),high:Vr(G(e,1,`..`),t)}))]},Dd=[Or(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),...Ed(`Naturals`),Gr(`<`,(e,t)=>e<t),Gr(`>`,(e,t)=>e>t),Gr(`<=`,(e,t)=>e<=t),Gr(`>=`,(e,t)=>e>=t)],Od=[Or(`Int`,{kind:`InfiniteSet`,name:`Int`}),...Ed(`Integers`),K(`-.`,1,e=>{let t=Vr(G(e,0,`-`),Td);if(Mr(-t))throw Nr(`-${t}`);return-t})],kd=(e,t,n)=>{let r=G(e,t,n),i=yn(r);if(!i)throw new y(`${n}\n${U(r)}`);return i},Ad=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:kd(e,t,n)},jd=(e,t,n)=>typeof e==`string`?Ke(e.slice(t,n)):R(e.slice(t,n)),Md=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Nd=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,Pd=(e,t)=>{let n=gd.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?Br(e,t):e}):t},Fd=Pd(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>Ad(e,0,Md(``,`Len`)).length),K(`\\o`,2,e=>{let t=Ad(e,0,Nd(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=kd(e,1,Nd(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new y(`${Nd(`t \\o s`,`string`)}\n${U(n)}`);return Ke(t+n)}),K(`Append`,2,e=>R([...kd(e,0,Nd(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=kd(e,0,Md(``,`Head`));if(t.length===0)throw new y(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=Ad(e,0,Md(``,`Tail`));if(t.length===0)throw new y(`Attempted to apply Tail to the empty sequence.`);return jd(t,1)}),K(`SubSeq`,3,e=>{let t=Ad(e,0,Md(`first `,`SubSeq`)),n=yr(e,1,`SubSeq`),r=yr(e,2,`SubSeq`);if(n>r)return jd(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new y(`The ${i.position} argument of SubSeq must be in the domain of its first argument:\n${U(G(e,0,`SubSeq`))}\n, but instead it is\n${i.value}`);return jd(t,n-1,r)}),kr(`SelectSeq`,2,e=>{let t=Dr(e,1,`SelectSeq`);return R(kd(e,0,Md(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new y(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),Id=Pd(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(N(t))return _n(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new v(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${Me(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!N(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new y(`Attempted to compute cardinality of the value\n${U(t)}`);return hn(t)})]),Ld=/* @__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`]]]),Rd=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:Dd};case`Integers`:return{extends:[`Naturals`],operators:Od};case`Sequences`:return{extends:[],operators:Fd};case`FiniteSets`:return{extends:[],operators:Id};case`TLC`:return{extends:[],operators:Pd(`TLC`,ld(t,n))};case`Randomization`:return{extends:[],operators:Bu(n)};case`_Possible`:return{extends:[],operators:td(t,n)};case`Json`:return{extends:[],operators:Pu(r)};case`Bags`:return{extends:[],operators:pu};case`TLCExt`:return{extends:[],operators:ed(t,n)};default:return}},zd=`$subexpression`,Bd=(e,t)=>new p(`${e} at line ${t.line}, column ${t.column}`),Vd=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Hd=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Ud=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}},Wd=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:gi(e.bounds),body:e.body,sets:Vd(e.bounds)};case`SetMap`:return{names:gi(e.bounds),body:e.expression,sets:Vd(e.bounds)};case`SetFilter`:return{names:hi(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:hi(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}},Gd=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Gd(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of hr(e)){let e=Gd(r,t,n);if(e)return e}},Kd=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,qd=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Jd=(e,t)=>{let n=e.location,r=qd(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 Bd(`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 Bd(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:zd,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:zd,args:e.args,location:n,resolution:ai},location:n}},Yd=(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:ai})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:ai}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:ai};return Jd({...t,params:[...t.params,...r]},a)},Xd=(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 Bd(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>ta(e)===l):t(l);if(u)return{definition:u,args:Kd(s,ui(u),r)};a.index++}throw Bd(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=ui(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Bd(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Bd(`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&&Gd(a.current,t.name,[]);if(!o)throw Bd(`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(...Kd(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Bd(`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`||Hd(t.operand,1)!==0)throw Bd(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Wd(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(...Kd(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[Hd(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Bd(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Hd(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Bd(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Bd(`Unexpected subexpression selector`,n);let c=s?s.sets:Ud(o),u=c?.[Hd(t.operand,c.length)];if(!u)throw Bd(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Yd(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 Bd(`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 Yd(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Bd(`Subexpression selection failed`,n);return Jd(i,a.current)},Zd=(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:[]}))]},Qd=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||hr(e).some(Qd),$d=(e,t)=>{if(!Qd(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return ia(e,e=>$d(e,n))}let n=ia(e,e=>$d(e,t));if(n.kind===`Subexpression`)return Xd(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Zd(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Xd(i,t,n.location,a);if(a.length>0)throw Bd(`Too many arguments for ${r}`,n.location);return o},ef=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},tf=(e,t)=>{let n=ef(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:$d(e.expression,n)}))}},nf=(e,t)=>{let n=ef([...t,...e.definitions]);return e.definitions.some(e=>Qd(e.body))||e.assumptions.some(e=>Qd(e.expression))?{...e,definitions:e.definitions.map(e=>ra(e,e=>$d(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:$d(e.expression,n)}))}:e},rf=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}])),af=(e,t)=>`${e}${t}`,of=(e,t,n)=>`${e}${t}${n}`,sf=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},cf=(e,t,n)=>`${e},${t},${n}`,lf=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),uf=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),df=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),ff=(e,t,n,r)=>({...lf(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),pf=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,mf=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,hf=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,{...ff(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),gf=ff(`$Set`,0,[2],[1]),_f=ff(`$Junction`,0,[3],[1]),vf=ff(`$Choose`,0,[2],[1]),yf=ff(`$Function`,0,[3],[1]),bf=ff(`$FcnApply`,0,[2,2],[1,1]),xf=ff(`$RcdSelect`,0,[2,0],[1,1]),Sf=ff(`'`,2,[1],[0]),Cf=ff(`ENABLED`,1,[2],[0]),wf=ff(`[]`,3,[3],[0]),Tf=ff(`$SquareAct`,2,[2,1],[0,0]),Ef=ff(`$WF`,3,[1,2],[0,0]),Df=ff(`$TemporalExists`,3,[3],[0]),Of=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),kf=e=>e.map(e=>({name:e,arity:0})),Af=(e,t)=>t.location.range?g(`${e}.`,t.location.range):new p(`${e} at line ${t.location.line}, column ${t.location.column}`),jf=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),Mf=e=>e.kind!==`Let`&&e.kind!==`Label`,Nf=e=>{let t=/* @__PURE__ */ new Map,n=(t,n)=>{let r=n.get(t);if(r?.kind===`Formal`)return{kind:`Declared`,name:t,level:0,arity:r.arity};if(r?.kind===`Let`)return{kind:`Defined`,levels:v(r.definition,r.scope)};if(e.constants.has(t))return{kind:`Declared`,name:t,level:0,arity:0};if(e.variables.has(t))return{kind:`Declared`,name:t,level:1,arity:0};let i=e.getDefinition(t);if(i){let n=v(i,/* @__PURE__ */ new Map),r=e.getQualifiedName?.(t);return{kind:`Defined`,levels:r?{...n,name:r}:n}}let a=hf.get(t)??rf.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=lf(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(of(e,n,t))}),t.data.constraints.forEach((e,t)=>uf(r.constraints,t,e)),df(r.argConstraints,af(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>df(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>pf(e,n))throw new p(`Level error in applying operator ${e.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator`)}),n.some(e=>e.level>2))throw new p(`Level error in applying operator ${e.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`);let a=n=>{let r=e.formals.findIndex(e=>e.name===n);return r===-1?void 0:t[r]},o=(t,n,r)=>e.conditions.has(cf(t,n,r)),s=lf(Math.max(e.level,...t.filter((t,n)=>mf(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)=>{mf(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)=>uf(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||uf(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>uf(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||uf(s.constraints,t,pf(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=>uf(s.constraints,e,pf(r,a)))}))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator)?.operator;n&&uf(s.constraints,t.param,pf(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>df(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>df(s.argConstraints,af(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&df(s.argConstraints,af(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);n&&df(s.argConstraints,af(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(sf(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(of(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(of(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(of(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=_(`LAMBDA`,kf(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=lf();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=Of(n,kf(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 Af(`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 Af(`Action used where only temporal formula or state predicate allowed`,e);jf.has(e.operator)&&l(t,e)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&Mf(n)&&n.kind!==r)throw Af(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e)},f=(e,t)=>{let n=new Map(t);e.definitions.forEach(e=>n.set(e.name,{kind:`Let`,definition:e,scope:n}));let r=m(e.body,n),i={level:r.level,params:new Set(r.params),constraints:new Map(r.constraints),argConstraints:new Map(r.argConstraints),argParams:new Set(r.argParams)};return e.definitions.forEach(e=>{let t=v(e,n);t.constraints.forEach((e,t)=>uf(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>df(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{try{return h(e,t)}catch(t){throw!(t instanceof p)||t.sany?t:Af(t.message,e)}},h=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return lf();case`Identifier`:return c(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return u(e,r),c(n(e.operator,t),r)}case`OperatorReference`:case`Lambda`:return a(e,t).data;case`And`:case`Or`:{let n=o(e.operands,t);return l(n,e),i(_f,n)}case`Prime`:case`Unchanged`:return s(Sf,[e.expression],t);case`Enabled`:return s(Cf,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(wf,[n])}case`If`:return s(_f,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(_f,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return f(e,t);case`Forall`:case`Exists`:{let n=s(_f,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds)),r=n.level===3?e.bounds.find(e=>m(e.set,t).level===2):void 0;if(r)throw Af(`Action-level bound of quantified temporal formula`,r.set);return n}case`UnboundedQuantifier`:return s(e.isTemporal?Df:_f,[e.body],t,[],e.names);case`Choose`:return s(vf,[e.body],t,e.set?[e.set]:[],hi(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(gf,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(gf,[e.predicate],t,[e.bound.set],hi(e.bound.pattern));case`SetMap`:return s(gf,[e.expression],t,e.bounds.map(e=>e.set),gi(e.bounds));case`FunctionConstruction`:return s(yf,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds));case`Record`:return s(yf,e.fields.map(e=>e.value),t);case`RecordSet`:return s(gf,e.fields.map(e=>e.value),t);case`Except`:return s(gf,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(bf,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(gf,e.args,t)}]);case`FieldAccess`:return i(xf,[a(e.record,t),{data:lf()}]);case`BoxAction`:case`AngleAction`:return s(Tf,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(Ef,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return lf()}},g=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>g(e,a,n,i),o=(e,o)=>{let s=n(e,t);s.kind===`Declared`?(r&&i.add(e),o.forEach(e=>a(e))):o.forEach((e,t)=>a(e,r||s.levels.nonLeibniz.has(t)))};switch(e.kind){case`Identifier`:return o(e.name,[]),i;case`Apply`:return o(e.operator,e.args),i;case`Lambda`:case`Let`:return i;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:case`BoxAction`:case`AngleAction`:case`WeakFairness`:case`StrongFairness`:return hr(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,Of(t,kf(e.names))),i;default:return ia(e,(e,n)=>(a(e,r,Of(t,kf(n))),e)),i}},_=(e,t,n,r)=>{let i=Of(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=g(n,i),c={...lf(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(af(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(of(e.name,n,t.name))).map(e=>cf(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(sf(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=sf(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},v=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...lf(),name:e.name,formals:i,maxLevels:i.map(()=>3),weights:i.map(()=>0),minMaxLevels:i.map(()=>[]),conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set});let a=e.kind===`Function`?{kind:`FunctionConstruction`,bounds:e.bounds,body:e.body,location:e.location}:e.body,o=_(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:v,toOperand:a}},Pf=(e,t,n)=>{let r=new Map(t),i=e.assumptions.flatMap(e=>{if(e.kind===`NewSymbol`){let t=e.set&&n.analyze(e.set,r);return r.set(e.name,{kind:`Formal`,arity:e.arity}),t?[t]:[]}return[e.kind===`AssumeProve`?Pf(e,r,n):n.analyze(e,r)]});i.push(n.analyze(e.conclusion,r));let a=lf(Math.max(...i.map(e=>e.level)));return i.forEach(e=>{e.params.forEach(e=>a.params.add(e)),e.constraints.forEach((e,t)=>uf(a.constraints,t,e)),e.argConstraints.forEach((e,t)=>df(a.argConstraints,t,e)),e.argParams.forEach(e=>a.argParams.add(e))}),a},Ff=(e,t)=>{let n=Nf(t);Ji([...e.definitions.filter(e=>!e.name.includes(`!`)).map(e=>({location:e.location,check:()=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)})),...e.assumptions.map(e=>({location:e.location,check:()=>n.analyze(e.expression,/* @__PURE__ */ new Map)})),...e.theorems.map(e=>({location:e.location,check:()=>e.statement.kind===`AssumeProve`?Pf(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map)}))])},If=(e,t)=>e.maxLevels[t]??3,Lf=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=Nf({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=>uf(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>uf(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>df(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=sf(e);t(n.operator,n.param)&&c.argParams.add(e)})};s.forEach(e=>l(e,(t,n)=>e.formals.every(e=>e.name!==t&&e.name!==n)));let u=e=>{l(e,()=>!0),a.constants.forEach(t=>{e.params.has(t.name)&&uf(c.constraints,t.name,2)})};return a.assumptions.forEach(e=>u(o.analyze(e,/* @__PURE__ */ new Map))),a.theorems.forEach(e=>e.statement.kind===`AssumeProve`?u(Pf(e.statement,/* @__PURE__ */ new Map,o)):l(o.analyze(e.statement,/* @__PURE__ */ new Map),()=>!0)),i.set(e,c),c},o=/* @__PURE__ */ new Map;if(e.forEach(e=>{let n=h(e.location.range??{module:e.instancer,start:e.location,end:e.location}),i=e=>o.set(`${n}\n${e}`,{location:n,message:e}),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}':\nThe level of the expression or operator substituted for '${t}' \nmust 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}':\n 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(af(t.name,a));o!==void 0&&If(r,a)<o&&i(`Level error in instantiating module '${e.module}':\nThe level of the argument ${a+1} of the operator ${r.name} \nmust be at least ${o}.`)})}),c.argParams.forEach(t=>{let n=sf(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=If(r,n.index);a.level>o&&i(`Level error when instantiating module '${e.module}':\nThe level of the argument ${n.index} of the operator ${n.operator}' \nmust be at most ${o}.`)})}),o.size>0)throw m([...o.values()])},Rf=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],zf=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Bf=new Map(dd.flatMap(e=>e.map(t=>[t,e[0]]))),Vf=e=>Bf.get(e)??e,Hf=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Uf=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Hf(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()}},Wf=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Gf=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Vf(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Vf(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}},Kf=(e,t)=>{let n=[];for(let r=t;;){let t=Gf(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},qf=e=>({line:e.line,column:e.column}),Jf=(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=Kf(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},Yf=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Xf={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Zf=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Yf(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Yf(e[n+1],e[n+2])?n+=Yf(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=>Xf[e])}"`:r.text)}return t},Qf=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},$f=(e,t)=>e.find(e=>e.name===t)??e.map(e=>$f(e.modules,t)).find(Boolean),ep=(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:hd.get(i)??t?.(i)??sl(e,i),s=o===void 0?[]:fe(o),c=Qf(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=ll(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>$f(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},tp=(e,t,n)=>{let r=ep(e,t),i=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],a=(e,n)=>{let i=Kf(t,e+1);r.push({location:qf(t[e]),apply:e=>i.forEach(t=>e.put(Wf(t,n,!1)))})},s=new Set(n.definitions.filter(e=>e.isRecursive).map(e=>e.name)),c={value:0};t.slice(e.start,e.end).forEach((n,o)=>{let l=e.start+o,u=t[l];if(u.kind===`Separator`&&t[l+1]?.text===`MODULE`){if(c.value++,c.value===2){let e=t[l+2].text;r.push({location:qf(u),apply:t=>t.put(Wf(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&a(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&a(l,`variable`),u.text===`RECURSIVE`&&Kf(t,l+1).every(e=>s.has(e))&&a(l,`definition`),zf.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(qf(u)),r.push({location:qf(u),apply:e=>e.put(Wf(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(Wf(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=Vf(e.name);r.push({location:e.location,apply:n=>n.put(Wf(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=o(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),a=n.filter(e=>e.kind===`theorem`);[...i,...a].forEach(n=>{n.isLocal||t.put(Wf(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Wf(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>li(e.location,t.location)?-1:+!!li(t.location,e.location))},a=/* @__PURE__ */ new Map,o=e=>{let t=a.get(e??``);if(t)return t;let n=Uf();a.set(e??``,n),ud.toReversed().forEach(e=>n.put(Wf(e,`builtin`,!1)));let s=r(e);return s.getModule().extends.forEach(e=>o(e).inserted.forEach(e=>{e.isLocal||n.put(e)})),i(s).forEach(e=>e.apply(n)),n};return o(void 0).enumerate().filter(e=>e.kind===n).map(e=>e.name).reverse()},np=(e,t,n)=>{let r=ep(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)}),fd.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=Jf(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;Zf(s(void 0)).forEach((e,t)=>{t===3&&md.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),Zf(s(n)).forEach(a))}Rf.forEach(a);let x=/* @__PURE__ */ new Set,ee=e=>{if(x.has(e))return;x.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(ee),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return ee(void 0),pd.forEach(a),[...i]},rp=t=>{switch(t.kind){case`Number`:try{return Ne(t.value)}catch(t){throw n(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return nt(t.name);case`Set`:return Pt(t.elements.map(rp))}},ip=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],ap=e=>new p(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),op=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:ai},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),sp=(e,t,n)=>{let r=`{ ${n.map(e=>`<${[...e[0],e[1]].map(e=>U(e)).join(`, `)}>`).join(`, `)}}`;return{kind:`Builtin`,name:e,arity:t,evaluate:e=>{let t=n.find(t=>{if(t[0].length!==e.length)throw new v(`Attempted to apply the operator ${r}\nwith wrong number of arguments.`);return t[0].every((t,n)=>{let r=e[n];return(typeof r!=`object`||r.kind!==`Operator`)&&at(t,r)})});if(t)return t[1];throw new v(`Attempted to apply operator:\n${r}\nto arguments (${e.map(e=>typeof e==`object`&&e.kind===`Operator`?e.name:U(e)).join(`, `)}), which is undefined.`)},evaluateUnary:void 0,evaluateBinary:void 0}},cp=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||hr(e).some(e=>cp(e,t)),lp=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(pa(e),n.get(e)??n.size)),n},up=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),dp=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw Po(e);if(e.kind===`Number`&&!Cs(e.value))throw Fo(e);dp(e.kind===`Let`?[...hr(e),...up(e.instances??[])]:hr(e))}),fp=(e,t)=>{let n=ll(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=new Map(wd.map(e=>[e.name,e])),s=/* @__PURE__ */ new Map,c=Wl(e.checkDeadlock,t.seed),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=[],f=/* @__PURE__ */ new Map,h=[],g=[],b=(e,t)=>h.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),x={value:0},ee=e=>`${e}#${x.value++}`,te=[],ne=/* @__PURE__ */ new Map,re=/* @__PURE__ */ new Map,ie=e=>{let n=s.get(e);if(n)return n;let r=Rd(e,t.print,c,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>ie(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{o.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),s.set(e,i),i},S=e=>{let t=ie(e),n=Ld.get(e)??[];return t&&b(e,n),t&&n.includes(`Integers`)&&ie(`Integers`),t},ae=e=>(dp([...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]),...up(e.instances)]),e.modules.forEach(ae),e);ae(n);let C=(e,n)=>{let r=t.loadModule?.(e)??Ac.get(e)??sl(t.source,e);if(r===void 0)throw m([{location:`In module ${n}`,message:`Cannot find source file for module ${e} imported in module ${n}.`}],!0);let i=ll(r);if(i.name!==e)throw m([{location:`Unknown location`,message:`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`}],!0);return ae(i)},oe=e=>{let t=g.indexOf(e.name);if(t!==-1)throw new p(`Circular dependency among .tla files; dependency cycle is: ${[...g.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];g.push(e.name),h.push(n);let i=le(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});h.pop(),g.pop();let a=r.find(e=>n.has(e.name));if(a)throw ap(a);return{linked:i,closure:n}},w=(e,t)=>{let n=l.get(e);if(n)return b(e,f.get(e)??[]),n;let r=oe(C(e,t));return l.set(e,r.linked),f.set(e,r.closure),b(e,r.closure),r.linked},T=(e,t,n,o,s)=>{let c=s?void 0:S(e.module);if(c)return e.name===void 0?c:new Map([...c].map(([t,n])=>[`${e.name}!${t}`,n]));let l=s??w(e.module,t.name),u=ip(l),d=`#${x.value++}`,f=new Map(e.params.map(e=>[e.name,`${e.name}${d}`])),p=qi(tf(e,t),u,t,n);te.push({module:e.module,instancer:t.name,lets:[],substitutions:p,location:e.location});let m=Ta({params:e.params.map(e=>({...e,name:`${e.name}${d}`})),substitutions:new Map([...p].map(([e,t])=>[e,Qi(t,f)])),variables:new Set(l.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(n,s,c)=>{let l=ee(`${s}@${t.name}`);return r.set(l,c(l)),i.set(l,!o),a.set(l,{source:n,prefix:e.params.length}),l},createName:ee}),h=new Set(u.map(e=>e.name)),g=/* @__PURE__ */ new Map;return l.exported.forEach((t,n)=>{if(h.has(n))return;if(e.name===void 0){let r=m.getKey(t.key);u.length>0&&ne.set(r,{name:n,location:e.location}),g.set(n,{key:r,arity:t.arity});return}let r=m.getQualifiedKey(t.key);u.length>0&&ne.set(r,{name:`${e.name}!${n}`,location:e.location}),re.set(r,`${e.name}!${n}`),g.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),g},E=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:ai})),se=(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:E(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),D=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),O=(e,t,n)=>{if(t.arity===0)return{params:[],body:e};if(e.kind===`Lambda`)return{params:e.params.map(e=>({name:e,arity:0})),body:e.body};let r=D(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:E(r,n),location:n}}},ce=(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=D(n.arity);return se(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??w(e.module,n),l=`#${x.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=ip(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};te.push({module:e.module,instancer:n,lets:t,substitutions:new Map(d.map(e=>[e.name,f(e)])),location:o});let p=new Set(e.params.map(e=>e.name)),m=e=>cp(f(e),p),h=d.map(t=>{let n=O(f(t),t,o);return{kind:`Operator`,name:`${t.name}${l}`,params:[...m(t)?e.params:[],...n.params],body:n.body,isLocal:!0,isRecursive:!1,location:o}}),g=[],_=Ta({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:E(e.params,o),location:o,resolution:ai}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:ai}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n,r)=>{let i=`${n}@${e.module}${l}.${g.length}`,a=r(i);return g.push(a.kind===`Operator`?{...a,name:i}:op(a,i)),i},createName:ee}),v=new Set(d.map(e=>e.name)),y=[...c.exported].filter(([e])=>!v.has(e)).map(([t,n])=>{let r=_.getKey(n.key),i=D(n.arity),a=[...e.params,...i];return se(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...y]},k=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),le=(e,a)=>{let o=Rc(e,t.loadClass?.(e.name)),s=new Map([...wd.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,f=[],p=[...o.constants],m=o.variables.map(e=>e.name),h=o.variables.map(e=>e.location),g=(e,t)=>e.forEach((e,n)=>{s.set(n,e),t&&c.set(n,e)});o.extends.forEach(e=>{let t=a.modules.get(e),n=t?void 0: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)=>l.set(t,e)),f.push(r)}),o.constants.forEach(e=>c.set(e.name,{key:e.name,arity:e.arity,declaration:`Constant`})),o.variables.forEach(e=>c.set(e.name,{key:e.name,arity:0,declaration:`Variable`}));let _=p.length===0&&m.length===0,v=e=>o===n?e.name:`${e.name}@${a.id}`,y=/* @__PURE__ */ new Map,b=e=>({imported:s,importedAt:y,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:v}),x=()=>new Map([...a.modules,...l]),ee=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>li(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>li(t.location,e)).map(e=>[e.name,{key:v(e),arity:ui(e)}])]),te=e=>{let t=x();if(t.has(e.name))throw ap(e);a.nested.push(e);let n=le(e,{id:`${a.id}/${e.name}`,symbols:ee(e.location),modules:t,nested:a.nested});l.set(e.name,n),u.has(e.name)||u.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=T(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)=>li(e.location,t.location)?-1:1).forEach(e=>e.link()),Gi(o,b(o));let ne=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&li(e.location,t.location)},ie=e=>{let t=o.modules.find(t=>t.name===e.module);return t?ne(t)?l.get(t.name):void 0:x().get(e.module)},ae=nf(ka(o,(e,t)=>ce(e,t,o.name,ie(e))),k(s));Yi(ae,b(ae)),ae.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:ui(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),Ff(ae,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e),getQualifiedName:e=>re.get(s.get(e)?.key??e)});let C={module:ae,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:l,extended:f};return d.push(C),C},ue=oe(n).linked,de=e=>ue.visible.get(e)?.key??e;ue.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let fe=[],pe=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>pe(e,t)),fe.push(...e.module.assumptions))};pe(ue,/* @__PURE__ */ new Set);let me=ue.constants.map(e=>e.name),he=ue.variables,A=e=>e.module===void 0?[e.name,de(e.name)]:e.module===n.name||me.includes(e.name)?[]:[(l.get(e.module)??u.get(e.module))?.visible.get(e.name)?.key??e.name],ge=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:ue.constants.find(t=>t.name===e)?.arity??0},_e=/* @__PURE__ */ new Map,ve=/* @__PURE__ */ new Set,ye=(e,t)=>{o.set(e,t),r.delete(e),_e.delete(e),ve.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=rp(e.value);A(e).forEach(e=>{let n=ge(e);n===0?_e.set(e,t):ye(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 _(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(rp),rp(e.value)]),j.set(t,n)}),j.forEach(e=>A(e).forEach(t=>ye(t,sp(e.name,ge(t)||e.rows[0][0].length,e.rows))));let be=new Map(e.substitutions.flatMap(e=>A(e).map(t=>[t,de(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!me.includes(n)&&!ue.visible.has(n))throw new _(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new _(`In the configuration file, the identifier ${i} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`);let a=de(i),s=r.get(a);if(!(s!==void 0||o.has(a)||_e.has(a)||me.includes(i)||he.includes(i)))throw new _(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(ue.constants.find(e=>e.name===n)?.arity??ue.visible.get(n)?.arity))throw new _(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)});let xe=new Set([...e.constants,...e.substitutions].filter(e=>e.module!==void 0).flatMap(A)),Se=(e,t)=>{if(xe.has(e))return{key:e,prefix:t};let n=a.get(e);return n&&Se(n.source,t+n.prefix)};a.forEach((e,t)=>{let n=Se(e.source,e.prefix),i=r.get(t);if(!n||!i)return;let a=i.kind===`Operator`?i.params:[],o=se(t,n.key,a,a.slice(n.prefix),i.location);r.set(t,o),ue.visible.forEach((e,n)=>{e.key===t&&n!==t&&r.set(n,o)})});let Ce=me.filter(e=>!_e.has(e)&&!be.has(e)&&!ve.has(e));if(Ce.length>0)throw new _(`The constant parameter ${tp(t.source,t.loadModule,`constant`).find(e=>Ce.includes(e))??Ce[0]} is not assigned a value by the configuration file.`);let we={runtime:c,definitions:r,builtins:o,constants:_e,substitutions:be,variables:he,variableIndex:lp(he,d.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};Lf(te,e=>{let t=l.get(e)??u.get(e)??ue;return{constants:t.constants,variables:t.variables,definitions:[...new Set([...t.visible.values()].flatMap(e=>r.get(e.key)??[]))],assumptions:t.module.assumptions.map(e=>e.expression),theorems:t.module.theorems,getDefinition:e=>r.get(t.visible.get(e)?.key??e)}});let Te=Nf({constants:new Set(_e.keys()),variables:/* @__PURE__ */ new Set([...he,...[`TLCGet`,`Trace`,`CounterExample`].filter(e=>o.has(e))]),getDefinition:e=>Vo(e,we)}),Ee=e=>{try{X(e,{environment:we,scope:void 0,state:void 0,next:void 0});return}catch(e){if(e instanceof v)return e;throw e}};return be.forEach((e,t)=>{let n=r.get(e),i=me.includes(t)&&n?.kind===`Operator`&&n.params.length===0&&Te.analyzeDefinition(n,/* @__PURE__ */ new Map).level>0?Ee(n.body):void 0;if(i)throw new _(`The configuration file substitutes constant ${t} with non-constant ${e}${i instanceof y?``:` - specifically: ${i.message}`}`)}),c.isStarted=!0,{environment:we,assumptions:fe,variableLocations:ue.variableLocations,instanceActions:ne}},pp={kind:`Boolean`,value:!0},mp={kind:`Boolean`,value:!1},hp=e=>e?pp:mp,gp=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,_p=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),vp=(e,t,n)=>({kind:e,operands:[t,n]}),yp=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?yp(e,t.operands).operands:[t])}),bp=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return bp(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,bp(t)),0)}},xp=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 xp(e.body);case`And`:case`Or`:return e.operands.some(xp)}},Sp=/* @__PURE__ */ new WeakMap,Cp={count:0},wp=e=>{let t=Sp.get(e);if(t!==void 0)return t;let n=(()=>{switch(e.kind){case`Boolean`:return String(e.value);case`State`:case`Enabled`:case`Action`:return`#${Cp.count++}`;case`And`:case`Or`:return`${e.kind}(${e.operands.map(wp).join(`,`)})`;default:return`${e.kind}(${wp(e.body)})`}})();return Sp.set(e,n),n},Tp=(e,t)=>e===t||wp(e)===wp(t),Ep=(e,t)=>{let n=wp(t);return e.some(e=>e===t||wp(e)===n)},Dp=e=>e===`And`?`Or`:`And`,Op=(e,t)=>{switch(e.kind){case`Boolean`:return t?hp(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return Op(e.body,!t);case`And`:case`Or`:return yp(t?Dp(e.kind):e.kind,e.operands.map(e=>Op(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,Op(e.body,t))}}},kp=e=>{switch(e.kind){case`Boolean`:return hp(!e.value);case`Not`:return e.body;case`And`:case`Or`:return yp(Dp(e.kind),e.operands.map(kp));case`Always`:return Q(`Eventually`,kp(e.body));case`Eventually`:return Q(`Always`,kp(e.body));default:return Q(`Not`,e)}},Ap=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=Ap(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return hp(t)}return n.length===0?hp(!t):n.length===1?n[0]:yp(e.kind,n)}case`Not`:{let t=Ap(e.body);return t.kind===`Boolean`?hp(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=Ap(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},jp=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,Mp=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=Mp(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new v(`TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form.`);t.push(e)}}if(n.value===1)return{kind:`And`,operands:t};let r=Array.from({length:n.value},()=>[]),i={groups:1,repeat:n.value};for(let e of t){if(e.kind!==`Or`){r.forEach(t=>t.push(e));continue}i.repeat/=e.operands.length;let t={value:0};for(let n=0;n<i.groups;n++)for(let n of e.operands)for(let e=0;e<i.repeat;e++)r[t.value++].push(n);i.groups*=e.operands.length}return{kind:`Or`,operands:r.map(e=>yp(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=Mp(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=jp(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:yp(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return yp(`Or`,n)}case`Not`:return gp(e.body)?e:Mp(kp(e.body));default:return e}},Np=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?Np(e.operands[0]):yp(e.kind,e.operands.map(Np));case`Not`:return e.body.kind===`Not`?Np(e.body.body):Q(`Not`,Np(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Np(e.body));default:return e}},Pp=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return Pp(e.operands[0]);let t=Math.floor(e.operands.length/2);return vp(e.kind,Pp(yp(e.kind,e.operands.slice(0,t))),Pp(yp(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Pp(e.body));default:return e}},Fp=(e,t)=>{e.kind===`Eventually`&&!Ep(t,e)&&t.push(e),`body`in e&&Fp(e.body,t),`operands`in e&&e.operands.forEach(e=>Fp(e,t))},Ip=e=>{let t=e.filter(_p),n=e.flatMap(e=>e.kind===`Not`&&_p(e.body)?[e.body]:[]);return!t.some(e=>Ep(n,e))},Lp=e=>{let t=[...e],n=[];for(;t.length>0;){let e=t.pop();if(!e)break;switch(e.kind){case`Not`:t.push(e.body);break;case`Next`:n.push(e),t.push(e.body);break;case`Always`:case`Eventually`:n.push(e,Q(`Next`,e)),t.push(e.body);break;case`And`:case`Or`:t.push(...e.operands),n.push(e);break;case`Action`:throw new v(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},Rp=(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]}},zp=(e,t,n)=>e.flatMap(e=>{let r=Rp(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),Bp=e=>[...new Set(e.map(wp))].sort().join(`|`),Vp=(e,t)=>{let n=new Set(t.map(Bp));return[...e.filter(e=>!n.has(Bp(e))),...t]},Hp=e=>{let t=Lp(e),n=zp(t,`Always`,`And`),r=zp(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=Rp(t,`Eventually`,`Or`);if(n&&!(Ep(e,n.first)||Ep(e,n.second)))return Vp(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(Ep(e,t.first)||Ep(e,t.second))&&!Ep(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!Ip(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=Rp(t[e],`Always`,`And`);n&&(Ep(t,n.first)||t.push(n.first),Ep(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)Ep(t,e.first)&&Ep(t,e.second)&&!Ep(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!Ip(t)?[]:i(t)};return a(e)},Up=e=>({particle:e,successors:[],statePredicates:e.filter(e=>bp(e)<=1)}),Wp=e=>{let t=Hp([e]).map(Up),n=t.length,r=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let n=Bp(e.particle);r.has(n)||r.set(n,t)});for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let i of Hp(n)){let n=Bp(i),a=r.get(n);a===void 0&&(r.set(n,t.length),t.push(Up(i))),t[e].successors.push(a??t.length-1)}}return{nodes:t,initialCount:n}},Gp=(e,t)=>!Ep(e,t)||Ep(e,t.body),Kp=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&bp(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=jp(e);if(n){let e=bp(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(xp(e))throw new v(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},qp=(e,t)=>{let n=e.findIndex(e=>Tp(e,t));return n===-1?(e.push(t),e.length-1):n},Jp=e=>{let t=Mp(Ap(Op(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=Np(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])Kp(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:yp(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:Tp(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&Pp(e.formula),n=[];t&&Fp(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>qp(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>qp(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>qp(i,e))}));return{tableau:t&&Wp(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Yp=/* @__PURE__ */ new Set([`~>`,`-+->`]),Xp=/* @__PURE__ */ new WeakMap,Zp=/* @__PURE__ */ new WeakSet,Qp=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),$p=(t,r)=>{try{return X(t,r)}catch(t){if(!(t instanceof v)||t instanceof y)throw t;let r=o(t);throw r===void 0?n(new v(`${l}${t.message}`,t),e.error):n(t,r)}},em=e=>new v(`TLC cannot handle the temporal formula at ${To(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Io(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=Vo(e,n);if(t)return tm(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 ia(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 Yp.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},tm=(e,t)=>{let n=Xp.get(e);if(n!==void 0)return n;Xp.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 Xp.set(e,i),i},nm=`Temporal formula is a tautology (its negation is unsatisfiable).`,rm=(t,r,i,a,o=``,s=/* @__PURE__ */ new Set)=>{let c=(e,t,n=o,r=s)=>rm(e,t,i,a,n,r);if(t.kind===`And`)return t.operands.flatMap(e=>c(e,r,Eo(e)));if(t.kind===`Label`)return c(t.body,r);if(t.kind===`Let`)return c(t.body,im(t,r,i));if(t.kind===`Identifier`){let o=W(t)?Io(r,t.name):void 0;if(o?.kind===`Thunk`)return c(o.expression,o.scope);let l=i.constants.has(t.name)?void 0:Vo(t.name,i);if(!o&&l?.kind===`Operator`&&l.params.length===0&&tm(l,i)>0){if(s.has(l))throw n(new v(u),e.error);let r=c(l.body,void 0,t.name,/* @__PURE__ */ new Set([...s,l]));return!a&&tm(l,i)<2?[{expression:l.body,scope:void 0,name:t.name}]:r}}let l=Qp(i,r);if(t.kind===`Apply`&&(e=>a||$(e,r,i)===3)(t)){let e=ss(t,l),n=W(t)?void 0:Vo(t.operator,i);if(e?.kind===`Closure`&&e.params.length===t.args.length&&!n?.isRecursive)return c(e.body,ys(e,t.args,l),t.operator)}if(a&&t.kind===`Forall`&&t.bounds.every(e=>$(e.set,r,i)===0)){let r=[],i={count:0};if(Ko(t.bounds,l,e=>(i.count++,r.push(...c(t.body,e,Eo(t.body))),!1)),i.count===0)throw n(new v(nm),e.livenessEvaluationFailure);return r}return[{expression:t,scope:r,name:o}]},im=(e,t,n)=>{let r=xs(e.definitions,Qp(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&Zp.add(e.binding);return r},am=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),om=(t,r,i)=>{let a=(e,t,n)=>{let r=n===0?$(e,t,i):n;if(r===0){let n=$p(e,Qp(i,t));if(typeof n!=`boolean`)throw new v(`TLC expected a boolean in the temporal formula at ${To(e)}`);return hp(n)}return r===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},o={depth:0},s=(t,r,i,s)=>{if(o.depth>=100)throw n(new v(u),e.error);o.depth++;let c=f(t,r);o.depth--;let l=bp(c);return l>2?c:a(i,s,l)},c=(e,t)=>{let n=e.kind===`Identifier`?e.name:e.operator,r=Qp(i,t),a=W(e)||Vo(n,i)===void 0?Io(t,n):void 0;if(a?.kind===`Thunk`&&Zp.has(a))return s(a.expression,a.scope,e,t);let o=a?.kind===`Operator`?a.operator:a?void 0:W(e)?cs(n,r):as(n,i);if(o?.kind!==`Closure`)throw em(e);let c=e.kind===`Apply`?e.args:[];return s(o.body,ys(o,c,r),e,t)},l=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,i)===0))throw em(e);let n=[];Ko(e.bounds,Qp(i,t),t=>(n.push(f(e.body,t)),!1));let r=e.kind===`Forall`;if(n.length===0)return hp(r);let o=yp(r?`And`:`Or`,n),s=bp(o);return s>2?o:a(e,t,s)},d=(e,t)=>{switch(e.kind){case`Label`:f(e.body,t);return;case`Let`:f(e.body,im(e,t,i));return;case`And`:case`Or`:for(let n of e.operands)f(n,t);return;case`Apply`:if(e.operator===`=>`||e.operator===`~`&&!W(e))for(let n of e.args)f(n,t);return;case`If`:{let n=f(e.condition,t),r=n.kind===`Boolean`?[n.value?e.consequent:e.alternative]:[e.consequent,e.alternative];for(let e of r)f(e,t)}}},f=(e,t)=>{let n=$(e,t,i);if(n<=2)return d(e,t),a(e,t,n);switch(e.kind){case`Label`:return f(e.body,t);case`Let`:return f(e.body,im(e,t,i));case`Identifier`:return c(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,vp(`Or`,Q(`Not`,f(n[0],t)),Q(`Eventually`,f(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,f(n[0],t)):e.operator===`=>`?vp(`Or`,Q(`Not`,f(n[0],t)),f(n[1],t)):c(e,t)}case`And`:case`Or`:return yp(e.kind,e.operands.map(e=>f(e,t)));case`Forall`:case`Exists`:return l(e,t);case`If`:{if($(e.condition,t,i)===0){let n=$p(e.condition,Qp(i,t));if(typeof n==`boolean`)return f(n?e.consequent:e.alternative,t)}let n=f(e.condition,t);return vp(`Or`,vp(`And`,n,f(e.consequent,t)),vp(`And`,Q(`Not`,n),f(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,f(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=am(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`,vp(`Or`,i,a))):vp(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw em(e)}};return f(t,r)},sm=(e,t,n,r,i)=>{let a=e=>sm(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`?Bo(X(e.expression,a),`a temporal property predicate`):bo(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&&Bo(X(e.unchanged,a),`a subscript`)?!1:Bo(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 sm(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new v(`TLC cannot evaluate a temporal formula in a single step`)}},cm=(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)=>cm(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 sm(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},lm=(e,t)=>e.every((e,n)=>st(e,t[n])),um=e=>e.filter((t,n)=>n===0||e[n-1]!==t),dm=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.pending.push(void 0),e.offsets.push(-1),e.edgeOffsets.push(-1),e.nodeStates.length-1),fm=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},pm=(e,t)=>(e.offsets[t]??-1)!==-1,mm=(e,t)=>e.pending[t]??=[],hm=(e,t)=>{let n=e.edgeOffsets[t];return e.edges.ids.subarray(n+1,n+1+e.edges.ids[n])},gm=(e,t,n)=>e.results.bytes[e.offsets[t]+n]===1,_m=2**53-1,vm=(t,r,i,a)=>{if(t.length===0)return;let o=r.map(e=>om(e.expression,e.scope,i)),s=t.map(e=>Q(`Not`,om(e.expression,e.scope,i))),c=s.length===1?s[0]:yp(`Or`,s),l=o.length===0?c:yp(`And`,[...o,c]),u=Jp(l);if(u.length===0)throw n(new v(nm),e.livenessEvaluationFailure);let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=wp(e),n=d.get(t)??d.size;return d.set(t,n),n}),nodeStates:[],nodeTableaux:[],pending:[],offsets:[],results:{bytes:/* @__PURE__ */ new Uint8Array(1024),length:0},edgeOffsets:[],edges:{ids:/* @__PURE__ */ new Int32Array(1024),length:0},initial:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!Ns(i),h={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},g=e=>{let t=h.states.get(e)??/* @__PURE__ */ new Map;return h.states.set(e,t),t},_=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},y=(e,t)=>sm(e,t,void 0,i,m?g(t):/* @__PURE__ */ new Map),b=(e,t,n)=>_(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!y(e,n))),x=(e,t,n,r)=>_(t,()=>{let t=e.solution.actionChecks;if(!m)return Uint8Array.from(t,e=>+!!sm(e,n,r,i,/* @__PURE__ */ new Map));let a=g(n),o=h.actions.get(n)??/* @__PURE__ */ new Map;h.actions.set(n,o);let s=o.get(r)??new Int8Array(d.size).fill(-1);return o.set(r,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!sm(t[o],n,r,i,a)),s[e]))}),ee=(e,t,n,r)=>_(n,()=>e.nodes[t].statePredicates.every(e=>y(e,r))),te=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},ne=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),re=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=fm(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},ie=(e,t,n)=>{let r=dm(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),fm(i,e[t]-1,e[t+1]))}return i.slots.set([t+1,n,r],fm(i,t,n)),r},S=(e,t,n)=>t.nodes.flatMap((t,r)=>re(e,n,r)??[]).sort((e,t)=>e-t),ae=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=e.results,o=a.length;if(a.length+=r.length+n.length*i,a.length>a.bytes.length){let e=new Uint8Array(Math.max(2*a.bytes.length,a.length));e.set(a.bytes),a.bytes=e}a.bytes.set(r,o),n.forEach((e,t)=>a.bytes.set(e,o+r.length+t*i)),e.offsets[t]=o;let s=e.pending[t]??[],c=e.edges,l=c.length;if(c.length+=s.length+1,c.length>c.ids.length){let e=new Int32Array(Math.max(2*c.ids.length,c.length));e.set(c.ids),c.ids=e}c.ids[l]=s.length,c.ids.set(s,l+1),e.edgeOffsets[t]=l,e.pending[t]=void 0},C=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t.index)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&lm(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},oe=(e,t,n,r,i)=>{let o=b(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=mm(e,i),u=s.successors.length>0?x(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ee(t,a,r,n))continue;if(te(t,a)&&e.errorNode===void 0&&ne(e)){e.errorNode=i;return}let o=re(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??ie(e,r,a);l.push(s),c.push(u),o===void 0&&oe(e,t,n,r,s)}for(let i of a.getSuccessors(n)){let a=x(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ee(t,n,r,i.state))continue;let s=re(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??ie(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&oe(e,t,i.state,i.index,u)}}l.length>0&&ae(e,i,c,o)},w=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ee(t,r,a,e.state)));e.isDone[a]=!0;for(let s of S(e,t,a)){let a=mm(e,s),c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=re(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??ie(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&oe(e,t,n.state,n.index,d)}}),ae(e,s,c,i)}if(e.errorNode!==void 0)return um(E(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},T=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)dm(e,e.nodeStates.length,-1);let a=mm(e,i),o=[];t.forEach((t,r)=>{pm(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),ae(e,i,o,r)},E=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)pm(e,t)&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of hm(e,a))if(!(i===a&&e.solution.tableau)){if(i===t){let e=[t];for(let t=a;t!==-1;t=n.get(t)??-1)e.push(t);return e}pm(e,i)&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new v(`Couldn't re-create liveness trace (path) starting at: ${t}`)},se=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=n.stateChecks.length,a=(t,n,a)=>e.results.bytes[e.offsets[t]+i+n*r+a]===1,o=(e,n)=>t.eventuallyAlways.every(t=>a(e,n,t)),s=new Float64Array(e.nodeStates.length).fill(-1),c=e.initial.filter(t=>pm(e,t)),l=[],u=t=>{let n=hm(e,t).indexOf(t);return n!==-1&&o(t,n)},d=(t,r)=>n.tableau!==void 0&&Gp(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let i=l.pop()??r;if(i===r&&!u(i)){s[i]=_m;return}let c=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=i;;t=l.pop()??r){c.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),s[t]=_m,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...c].some(n=>gm(e,n,t))),h=t.infinitelyOftenActions.every(t=>[...c].some(n=>hm(e,n).some((e,r)=>c.has(e)&&o(n,r)&&a(n,r,t)))),g=n.promises.every(e=>[...c].some(t=>d(t,e)));if(m&&h&&g)return p(r,c,f)},p=(r,i,s)=>{let c=um(E(e,r).reverse().map(t=>e.nodeStates[t])),l=[],u=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),p=t.infinitelyOftenActions.map(()=>!1),h=n.promises.map(()=>!1),g={count:f.length+p.length+h.length},_={node:r},y=e=>i.has(e),b=e=>{l.push(_.node),_.node=e};for(;g.count>0;){let r=g.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&gm(e,_.node,t)&&(f[n]=!0,g.count--)}),n.promises.forEach((e,t)=>{!h[t]&&d(_.node,e)&&(h[t]=!0,g.count--)}),!(g.count<=0);){let n={last:-1,unvisited:-1},i=g.count;if(hm(e,_.node).some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!o(_.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!p[t]&&a(_.node,c,e)&&(p[t]=!0,g.count--)})}return g.count<i?(b(r),u.clear(),!0):(y(r)&&!u.has(r)&&(n.unvisited=r),!1)}))break;if(g.count<r){b(n.last),u.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);_.node=t,n.unvisited=hm(e,t).find(e=>y(e)&&!u.has(e))??-1}b(n.unvisited),u.add(n.unvisited)}}let x=m(r,_.node,s,o);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];x[x.length-1]!==n&&x.push(n)}let ee=c[c.length-1];return x[x.length-1]===ee&&x.pop(),{prefix:c.slice(0,-1),cycle:[ee,...x.reverse()]}},m=(t,n,r,i)=>{if(n===t)return[];let a=e.nodeStates[n],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set([a]),c=[];for(let n=a,l=-1,u=0;;u++){for(let u of r.get(n)??[])for(let[d,f]of hm(e,u).entries()){if(f===u||!i(u,d))continue;if(f===t){let e=[];for(let t=n,r=l;t!==a;)e.push(t),t=r,r=o.get(t)??-1;return e.push(a),e}let p=e.nodeStates[f];r.has(p)&&!s.has(p)&&(s.add(p),c.push([p,n]))}o.set(n,l);let d=c[u];if(d===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<c.length;t++){let n=[c[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),a=n.pop()??0;if(i===-42){if(s[a]===t){let e=f(a);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(s[a]!==-1){n.push(Math.min(t,s[a]));continue}s[a]=r.link,n.push(t,a,-42),l.push(a);let u={value:r.link++};hm(e,a).forEach((t,r)=>{pm(e,t)&&(o(a,r)?s[t]===-1?n.push(t,-1):u.value=Math.min(u.value,s[t]):s[t]===-1&&c.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{h.states.clear(),h.actions.clear();for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ee(r,i,void 0,t)&&n.initial.push(re(n,e,i)??ie(n,e,i))}},addState:(e,t,n)=>{h.states.clear(),h.actions.clear();let r=C(e,t,n);for(let n of f){let i=r.map(r=>x(n,e,t,r.state)),a=b(n,e,t),o=n.solution.tableau,s=o?w(n,o,r,i,a,e):T(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=se(e,t);if(n)return n}},getViolatedProperties:(e,n)=>[...new Set(t.filter((t,r)=>!cm(s[r].body,e,n,0,i)).map(e=>e.name))]}},ym=`UnnamedAction`,bm={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},xm=e=>{let t=e.range??bm;return Xt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},Sm=e=>{let t=[[`name`,e.name],[`location`,xm(e.location)]];return e.parameters.length===0?Xt(t):Xt([...t,[`context`,Xt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},Cm=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),wm=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),Tm=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,Em=e=>e.kind===`Apply`?e.args:[],Dm=(e,t,n)=>{let r=Tm(e);if(r===void 0)return;if(W(e)){let e=Io(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=as(r,n);return i?.kind===`Closure`?i:void 0},Om=(e,t)=>{try{return X(e,wm(t,void 0)),!0}catch(e){if(e instanceof f)return!1;throw e}},km=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&Uo(e,t)&&Om(e.body,t),Am=(e,t)=>{let n=Vo(e.name,t);return n?.body===e.body&&km(n,t)},jm=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Io(t,e.name);return n?.kind===`Thunk`?n:void 0},Mm=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Io(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),Nm=(e,t)=>{try{return e()}catch(e){if(e instanceof f)return t();throw e}},Pm=(e,t,n,r,i)=>{let a=Em(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():Nm(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,wm(i,n))]),expression:t,scope:n}],o)},Fm=(e,t,n,r,i)=>{let a=()=>({name:n?.name??ym,location:e.location,parameters:Mm(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return Fm(e.body,xs(e.definitions,wm(r,t)),n,r,i);case`Label`:return Fm(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>Fm(e,t,n,r,i));case`Exists`:return Nm(()=>{let o=[];return Ko(e.bounds,wm(r,t),t=>(o.push(...Fm(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get(Tm(e)??``),s=Dm(e,t,r);if(o)return Pm(o,e,t,s,r);if(!s)return[a()];let c=Em(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return Am(s,r)||c.some(e=>$(e,t,r)!==0)?l():Nm(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,wm(r,t))},parent:e}),s.scope);return Fm(s.body,e,s,r,i)},l)},Im=(e,t,n,r,i)=>{let a=(e,t)=>Im(e,t,n,r,i);if(e.kind===`Let`){a(e.body,xs(e.definitions,wm(n,t)));return}let o=jm(e,t);if(o){a(o.expression,o.scope);return}let s=Dm(e,t,n);if(s&&Am(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(Cm(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,ys(s,e.args,wm(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(Cm(ym,e));return}let c=$(e,t,n);c<=1?r.inits.push(Cm(ym,e)):c===3&&r.temporals.push(Cm(ym,e))},Lm=(e,t,n,r,i)=>{let a=(t,n)=>Lm(e,t,n,r,i);if(t.kind===`Let`){a(t.body,xs(t.definitions,wm(r,n)));return}let o=jm(t,n);if(o){a(o.expression,o.scope);return}let s=Dm(t,n,r);if(s&&Am(s,r))return;if(s&&s.params.length===Em(t).length){a(s.body,t.kind===`Apply`?ys(s,t.args,wm(r,n)):s.scope);return}if(t.kind===`Forall`&&Nm(()=>(Ko(t.bounds,wm(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(Cm(e,a)):$(a,n,r)<2?i.invariants.push(Cm(e,a)):i.impliedTemporals.push(Cm(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(Cm(e,t)):c===3&&i.impliedTemporals.push(Cm(e,t))},Rm=(e,t)=>{let n=Vo(e,t);return n?.kind===`Operator`&&!km(n,t)?n:void 0},zm=e=>Xt([[`name`,e.name],[`location`,xm(e.location)]]),Bm=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:Rm(e.specification,t);a&&(Im(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...Fm(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:as(e.init,t);o?.kind===`Closure`&&r.inits.push(Cm(e.init??``,o.body));let s=e.next===void 0?void 0:as(e.next,t);return s?.kind===`Closure`&&r.actions.push(...Fm(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=Rm(e,t);n&&r.invariants.push(Cm(e,n.body))}),e.properties.forEach(e=>{let n=Rm(e,t);n&&Lm(e,n.body,void 0,t,r)}),r},Vm=(e,t,n)=>Bm(e,t,n).actions,Hm=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>U(e[1])).join(`,`)})`,Um=e=>`${e.name===ym?`Action`:e.name}${Hm(e)} ${h(e.location.range??bm)}`,Wm=e=>`${e.name}${Hm(e)}`,Gm=(e,t,n,r)=>{let i=Bm(e,t,r),a=e=>Pt(e.map(Sm)),o=e=>Pt(e.flatMap(e=>{let n=Rm(e,t);return n?[zm(n)]:[]}));return Xt([[`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`,Pt(t.variables.map((e,t)=>Xt([[`name`,e],[`location`,xm(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},Km=`paired12`,qm=(e,t=16)=>e<=t*.75?t:qm(e,t*2),Jm=(e,t)=>{let n=qm(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Ym=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Xm=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Zm=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Qm=e=>Zm(e).replaceAll(`
419
419
  `,`\\n`),$m=(e,t)=>{let n=[],r=e=>n.push(`State ${n.length+1}:\n${e.getText()}\n`);return{writeInitialState:r,writeSuccessor:(e,t,n)=>{n||r(t)},close:()=>t?.(e.path,n.join(``))}},eh=(e,t)=>{let n=[`strict digraph DiskGraph {
420
420
  `,`node [shape=box,style=rounded]
421
421
  `,e.colorize?`edge [colorscheme="${Km}"]\n`:``,`nodesep=0.35;
package/dist/transfer.js CHANGED
@@ -415,7 +415,7 @@ _CheckName(name) ==
415
415
  => (PrintT(counts) /\\ FALSE)
416
416
  _PrintCounts == PrintT(_Counts)
417
417
  =============================================================================
418
- `]]),gd=/* @__PURE__ */ new Map([[`FiniteSets`,/* @__PURE__ */ new Map([[`IsFiniteSet`,`public static tlc2.value.IBoolValue tlc2.module.FiniteSets.IsFiniteSet(tlc2.value.impl.Value)`],[`Cardinality`,`public static tlc2.value.impl.IntValue tlc2.module.FiniteSets.Cardinality(tlc2.value.impl.Value)`]])],[`Sequences`,/* @__PURE__ */ new Map([[`Seq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Seq(tlc2.value.impl.Value)`],[`Len`,`public static tlc2.value.impl.IntValue tlc2.module.Sequences.Len(tlc2.value.impl.Value)`],[`Head`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Head(tlc2.value.impl.Value)`],[`Tail`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Tail(tlc2.value.impl.Value)`],[`Append`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Append(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`\\o`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Concat(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SubSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SubSeq(tlc2.value.impl.Value,tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SelectSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SelectSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`]])],[`TLC`,/* @__PURE__ */ new Map([[`Print`,`public static tlc2.value.impl.Value tlc2.module.TLC.Print(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`PrintT`,`public static tlc2.value.impl.Value tlc2.module.TLC.PrintT(tlc2.value.impl.Value)`],[`ToString`,`public static tlc2.value.impl.Value tlc2.module.TLC.ToString(tlc2.value.impl.Value)`],[`Assert`,`public static tlc2.value.impl.Value tlc2.module.TLC.Assert(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`:>`,`public static tlc2.value.impl.Value tlc2.module.TLC.MakeFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`@@`,`public static tlc2.value.impl.Value tlc2.module.TLC.CombineFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SortSeq`,`public static tlc2.value.impl.Value tlc2.module.TLC.SortSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`Permutations`,`public static tlc2.value.impl.Value tlc2.module.TLC.Permutations(tlc2.value.impl.Value)`],[`RandomElement`,`public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)`],[`TLCGet`,`public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`],[`TLCEval`,`public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`]])]]),_d=(e,t)=>e.every(e=>Cn(e,t)),vd=Pt([!1,!0]),yd=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return zt(yd(e,t,r),yd(e,r,n))},bd=[`\\cup`,`\\cap`,`\\`],xd=e=>typeof e==`object`&&e.kind===`MixedSet`,Sd=e=>e.kind===`Interval`?B(e).elements:e.elements,Cd=(e,t,n)=>{let r=Sd(t);if(e!==`\\cup`){let t=e===`\\cap`;return Ft(r.filter(e=>Cn(e,n)===t))}if(r.length===0)return n;if(!je(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!Cn(e,t));return Ft([...r,...i])},wd=[Or(`TRUE`,!0),Or(`FALSE`,!1),Or(`BOOLEAN`,vd),Or(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),jr(`=`,Mt),jr(`#`,(e,t)=>!Mt(e,t)),K(`~`,1,e=>!br(e,0,`~`)),K(`<=>`,2,e=>br(e,0,`<=>`)===br(e,1,`<=>`)),K(`/\\`,2,e=>br(e,0,`/\\`)&&br(e,1,`/\\`)),K(`\\/`,2,e=>br(e,0,`\\/`)||br(e,1,`\\/`)),K(`=>`,2,e=>!br(e,0,`=>`)||br(e,1,`=>`)),K(`\\in`,2,e=>Cn(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!Cn(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=xr(e,0,`\\subseteq`),n=G(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?_d(B(t.base).elements,n.base):_d(B(t).elements,n)}),...bd.map(e=>K(e,2,t=>{let n=G(t,0,e),r=G(t,1,e);if(je(n)&&je(r)&&!xd(n)&&!xd(r)){if(e===`\\cup`&&V(n))return r;let t=e===`\\cup`?zt:e===`\\cap`?Rt:Lt;try{return t(B(n),B(r))}catch(e){if(!(e instanceof v))throw e}}return je(n)?Cd(e,n,r):e!==`\\`&&je(r)?Cd(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:xr(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=xr(e,0,`UNION`),n=bt(t)?t.elements.filter(bt):[];if(!bt(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(xd(t)||n.some(xd)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{Cn(t,e)||e.elements.push(t)})),Ft(e.elements)}return n.length===0?It:yd(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!P(t))throw new v(`DOMAIN expects a function but received ${U(t)}`);return Ln(t)})],Td=Hr(`Integers`,`Neg`,`IntValue`,1),Ed=e=>{let t=Hr(e,`DotDot`,`IntervalValue`,2);return[Ur(e,`+`,`Plus`,(e,t)=>e+t),Ur(e,`-`,`Minus`,(e,t)=>e-t),Ur(e,`*`,`Times`,(e,t)=>e*t),Ur(e,`^`,`Expt`,(e,t)=>{if(t<0)throw new y(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new y(`0^0 is undefined.`);return e**t}),Ur(e,`\\div`,`Divide`,(e,t)=>{if(t===0)throw new y(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Mr(n))throw Nr(`${e} \\div ${t}`);return n}),Ur(e,`%`,`Mod`,(e,t)=>{if(t<=0)throw new y(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),K(`..`,2,e=>({kind:`Interval`,low:Vr(G(e,0,`..`),t),high:Vr(G(e,1,`..`),t)}))]},Dd=[Or(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),...Ed(`Naturals`),Gr(`<`,(e,t)=>e<t),Gr(`>`,(e,t)=>e>t),Gr(`<=`,(e,t)=>e<=t),Gr(`>=`,(e,t)=>e>=t)],Od=[Or(`Int`,{kind:`InfiniteSet`,name:`Int`}),...Ed(`Integers`),K(`-.`,1,e=>{let t=Vr(G(e,0,`-`),Td);if(Mr(-t))throw Nr(`-${t}`);return-t})],kd=(e,t,n)=>{let r=G(e,t,n),i=yn(r);if(!i)throw new y(`${n}\n${U(r)}`);return i},Ad=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:kd(e,t,n)},jd=(e,t,n)=>typeof e==`string`?Ke(e.slice(t,n)):R(e.slice(t,n)),Md=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Nd=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,Pd=(e,t)=>{let n=gd.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?Br(e,t):e}):t},Fd=Pd(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>Ad(e,0,Md(``,`Len`)).length),K(`\\o`,2,e=>{let t=Ad(e,0,Nd(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=kd(e,1,Nd(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new y(`${Nd(`t \\o s`,`string`)}\n${U(n)}`);return Ke(t+n)}),K(`Append`,2,e=>R([...kd(e,0,Nd(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=kd(e,0,Md(``,`Head`));if(t.length===0)throw new y(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=Ad(e,0,Md(``,`Tail`));if(t.length===0)throw new y(`Attempted to apply Tail to the empty sequence.`);return jd(t,1)}),K(`SubSeq`,3,e=>{let t=Ad(e,0,Md(`first `,`SubSeq`)),n=yr(e,1,`SubSeq`),r=yr(e,2,`SubSeq`);if(n>r)return jd(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new y(`The ${i.position} argument of SubSeq must be in the domain of its first argument:\n${U(G(e,0,`SubSeq`))}\n, but instead it is\n${i.value}`);return jd(t,n-1,r)}),kr(`SelectSeq`,2,e=>{let t=Dr(e,1,`SelectSeq`);return R(kd(e,0,Md(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new y(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),Id=Pd(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(N(t))return _n(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new v(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${Me(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!N(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new y(`Attempted to compute cardinality of the value\n${U(t)}`);return hn(t)})]),Ld=/* @__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`]]]),Rd=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:Dd};case`Integers`:return{extends:[`Naturals`],operators:Od};case`Sequences`:return{extends:[],operators:Fd};case`FiniteSets`:return{extends:[],operators:Id};case`TLC`:return{extends:[],operators:Pd(`TLC`,ld(t,n))};case`Randomization`:return{extends:[],operators:Bu(n)};case`_Possible`:return{extends:[],operators:td(t,n)};case`Json`:return{extends:[],operators:Pu(r)};case`Bags`:return{extends:[],operators:pu};case`TLCExt`:return{extends:[],operators:ed(t,n)};default:return}},zd=`$subexpression`,Bd=(e,t)=>new p(`${e} at line ${t.line}, column ${t.column}`),Vd=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Hd=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Ud=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}},Wd=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:gi(e.bounds),body:e.body,sets:Vd(e.bounds)};case`SetMap`:return{names:gi(e.bounds),body:e.expression,sets:Vd(e.bounds)};case`SetFilter`:return{names:hi(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:hi(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}},Gd=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Gd(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of hr(e)){let e=Gd(r,t,n);if(e)return e}},Kd=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,qd=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Jd=(e,t)=>{let n=e.location,r=qd(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 Bd(`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 Bd(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:zd,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:zd,args:e.args,location:n,resolution:ai},location:n}},Yd=(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:ai})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:ai}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:ai};return Jd({...t,params:[...t.params,...r]},a)},Xd=(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 Bd(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>ta(e)===l):t(l);if(u)return{definition:u,args:Kd(s,ui(u),r)};a.index++}throw Bd(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=ui(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Bd(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Bd(`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&&Gd(a.current,t.name,[]);if(!o)throw Bd(`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(...Kd(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Bd(`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`||Hd(t.operand,1)!==0)throw Bd(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Wd(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(...Kd(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[Hd(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Bd(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Hd(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Bd(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Bd(`Unexpected subexpression selector`,n);let c=s?s.sets:Ud(o),u=c?.[Hd(t.operand,c.length)];if(!u)throw Bd(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Yd(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 Bd(`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 Yd(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Bd(`Subexpression selection failed`,n);return Jd(i,a.current)},Zd=(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:[]}))]},Qd=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||hr(e).some(Qd),$d=(e,t)=>{if(!Qd(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return ia(e,e=>$d(e,n))}let n=ia(e,e=>$d(e,t));if(n.kind===`Subexpression`)return Xd(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Zd(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Xd(i,t,n.location,a);if(a.length>0)throw Bd(`Too many arguments for ${r}`,n.location);return o},ef=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},tf=(e,t)=>{let n=ef(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:$d(e.expression,n)}))}},nf=(e,t)=>{let n=ef([...t,...e.definitions]);return e.definitions.some(e=>Qd(e.body))||e.assumptions.some(e=>Qd(e.expression))?{...e,definitions:e.definitions.map(e=>ra(e,e=>$d(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:$d(e.expression,n)}))}:e},rf=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}])),af=(e,t)=>`${e}${t}`,of=(e,t,n)=>`${e}${t}${n}`,sf=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},cf=(e,t,n)=>`${e},${t},${n}`,lf=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),uf=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),df=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),ff=(e,t,n,r)=>({...lf(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),pf=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,mf=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,hf=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,{...ff(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),gf=ff(`$Set`,0,[2],[1]),_f=ff(`$Junction`,0,[3],[1]),vf=ff(`$Choose`,0,[2],[1]),yf=ff(`$Function`,0,[3],[1]),bf=ff(`$FcnApply`,0,[2,2],[1,1]),xf=ff(`$RcdSelect`,0,[2,0],[1,1]),Sf=ff(`'`,2,[1],[0]),Cf=ff(`ENABLED`,1,[2],[0]),wf=ff(`[]`,3,[3],[0]),Tf=ff(`$SquareAct`,2,[2,1],[0,0]),Ef=ff(`$WF`,3,[1,2],[0,0]),Df=ff(`$TemporalExists`,3,[3],[0]),Of=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),kf=e=>e.map(e=>({name:e,arity:0})),Af=(e,t)=>t.location.range?g(`${e}.`,t.location.range):new p(`${e} at line ${t.location.line}, column ${t.location.column}`),jf=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),Mf=e=>e.kind!==`Let`&&e.kind!==`Label`,Nf=e=>{let t=/* @__PURE__ */ new Map,n=(t,n)=>{let r=n.get(t);if(r?.kind===`Formal`)return{kind:`Declared`,name:t,level:0,arity:r.arity};if(r?.kind===`Let`)return{kind:`Defined`,levels:v(r.definition,r.scope)};if(e.constants.has(t))return{kind:`Declared`,name:t,level:0,arity:0};if(e.variables.has(t))return{kind:`Declared`,name:t,level:1,arity:0};let i=e.getDefinition(t);if(i){let n=v(i,/* @__PURE__ */ new Map),r=e.getQualifiedName?.(t);return{kind:`Defined`,levels:r?{...n,name:r}:n}}let a=hf.get(t)??rf.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=lf(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(of(e,n,t))}),t.data.constraints.forEach((e,t)=>uf(r.constraints,t,e)),df(r.argConstraints,af(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>df(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>pf(e,n))throw new p(`Level error in applying operator ${e.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator`)}),n.some(e=>e.level>2))throw new p(`Level error in applying operator ${e.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`);let a=n=>{let r=e.formals.findIndex(e=>e.name===n);return r===-1?void 0:t[r]},o=(t,n,r)=>e.conditions.has(cf(t,n,r)),s=lf(Math.max(e.level,...t.filter((t,n)=>mf(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)=>{mf(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)=>uf(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||uf(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>uf(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||uf(s.constraints,t,pf(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=>uf(s.constraints,e,pf(r,a)))}))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator)?.operator;n&&uf(s.constraints,t.param,pf(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>df(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>df(s.argConstraints,af(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&df(s.argConstraints,af(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);n&&df(s.argConstraints,af(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(sf(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(of(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(of(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(of(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=_(`LAMBDA`,kf(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=lf();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=Of(n,kf(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 Af(`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 Af(`Action used where only temporal formula or state predicate allowed`,e);jf.has(e.operator)&&l(t,e)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&Mf(n)&&n.kind!==r)throw Af(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e)},f=(e,t)=>{let n=new Map(t);e.definitions.forEach(e=>n.set(e.name,{kind:`Let`,definition:e,scope:n}));let r=m(e.body,n),i={level:r.level,params:new Set(r.params),constraints:new Map(r.constraints),argConstraints:new Map(r.argConstraints),argParams:new Set(r.argParams)};return e.definitions.forEach(e=>{let t=v(e,n);t.constraints.forEach((e,t)=>uf(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>df(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{try{return h(e,t)}catch(t){throw!(t instanceof p)||t.sany?t:Af(t.message,e)}},h=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return lf();case`Identifier`:return c(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return u(e,r),c(n(e.operator,t),r)}case`OperatorReference`:case`Lambda`:return a(e,t).data;case`And`:case`Or`:{let n=o(e.operands,t);return l(n,e),i(_f,n)}case`Prime`:case`Unchanged`:return s(Sf,[e.expression],t);case`Enabled`:return s(Cf,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(wf,[n])}case`If`:return s(_f,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(_f,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return f(e,t);case`Forall`:case`Exists`:{let n=s(_f,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds)),r=n.level===3?e.bounds.find(e=>m(e.set,t).level===2):void 0;if(r)throw Af(`Action-level bound of quantified temporal formula`,r.set);return n}case`UnboundedQuantifier`:return s(e.isTemporal?Df:_f,[e.body],t,[],e.names);case`Choose`:return s(vf,[e.body],t,e.set?[e.set]:[],hi(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(gf,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(gf,[e.predicate],t,[e.bound.set],hi(e.bound.pattern));case`SetMap`:return s(gf,[e.expression],t,e.bounds.map(e=>e.set),gi(e.bounds));case`FunctionConstruction`:return s(yf,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds));case`Record`:return s(yf,e.fields.map(e=>e.value),t);case`RecordSet`:return s(gf,e.fields.map(e=>e.value),t);case`Except`:return s(gf,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(bf,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(gf,e.args,t)}]);case`FieldAccess`:return i(xf,[a(e.record,t),{data:lf()}]);case`BoxAction`:case`AngleAction`:return s(Tf,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(Ef,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return lf()}},g=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>g(e,a,n,i),o=(e,o)=>{let s=n(e,t);s.kind===`Declared`?(r&&i.add(e),o.forEach(e=>a(e))):o.forEach((e,t)=>a(e,r||s.levels.nonLeibniz.has(t)))};switch(e.kind){case`Identifier`:return o(e.name,[]),i;case`Apply`:return o(e.operator,e.args),i;case`Lambda`:case`Let`:return i;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:case`BoxAction`:case`AngleAction`:case`WeakFairness`:case`StrongFairness`:return hr(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,Of(t,kf(e.names))),i;default:return ia(e,(e,n)=>(a(e,r,Of(t,kf(n))),e)),i}},_=(e,t,n,r)=>{let i=Of(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=g(n,i),c={...lf(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(af(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(of(e.name,n,t.name))).map(e=>cf(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(sf(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=sf(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},v=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...lf(),name:e.name,formals:i,maxLevels:i.map(()=>3),weights:i.map(()=>0),minMaxLevels:i.map(()=>[]),conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set});let a=e.kind===`Function`?{kind:`FunctionConstruction`,bounds:e.bounds,body:e.body,location:e.location}:e.body,o=_(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:v,toOperand:a}},Pf=(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`?Pf(e,r,n):n.analyze(e,r)}),n.analyze(e.conclusion,r)},Ff=(e,t)=>{let n=Nf(t);Ji([...e.definitions.filter(e=>!e.name.includes(`!`)).map(e=>({location:e.location,check:()=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)})),...e.assumptions.map(e=>({location:e.location,check:()=>n.analyze(e.expression,/* @__PURE__ */ new Map)})),...e.theorems.map(e=>({location:e.location,check:()=>e.statement.kind===`AssumeProve`?Pf(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map)}))])},If=(e,t)=>e.maxLevels[t]??3,Lf=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=Nf({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=>uf(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>uf(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>df(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=sf(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 Map;if(e.forEach(e=>{let n=h(e.location.range??{module:e.instancer,start:e.location,end:e.location}),i=e=>o.set(`${n}\n${e}`,{location:n,message:e}),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}':\nThe level of the expression or operator substituted for '${t}' \nmust 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}':\n 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(af(t.name,a));o!==void 0&&If(r,a)<o&&i(`Level error in instantiating module '${e.module}':\nThe level of the argument ${a+1} of the operator ${r.name} \nmust be at least ${o}.`)})}),c.argParams.forEach(t=>{let n=sf(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=If(r,n.index);a.level>o&&i(`Level error when instantiating module '${e.module}':\nThe level of the argument ${n.index} of the operator ${n.operator}' \nmust be at most ${o}.`)})}),o.size>0)throw m([...o.values()])},Rf=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],zf=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Bf=new Map(dd.flatMap(e=>e.map(t=>[t,e[0]]))),Vf=e=>Bf.get(e)??e,Hf=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Uf=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Hf(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()}},Wf=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Gf=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Vf(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Vf(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}},Kf=(e,t)=>{let n=[];for(let r=t;;){let t=Gf(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},qf=e=>({line:e.line,column:e.column}),Jf=(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=Kf(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},Yf=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Xf={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Zf=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Yf(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Yf(e[n+1],e[n+2])?n+=Yf(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=>Xf[e])}"`:r.text)}return t},Qf=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},$f=(e,t)=>e.find(e=>e.name===t)??e.map(e=>$f(e.modules,t)).find(Boolean),ep=(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:hd.get(i)??t?.(i)??sl(e,i),s=o===void 0?[]:fe(o),c=Qf(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=ll(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>$f(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},tp=(e,t,n)=>{let r=ep(e,t),i=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],a=(e,n)=>{let i=Kf(t,e+1);r.push({location:qf(t[e]),apply:e=>i.forEach(t=>e.put(Wf(t,n,!1)))})},s=new Set(n.definitions.filter(e=>e.isRecursive).map(e=>e.name)),c={value:0};t.slice(e.start,e.end).forEach((n,o)=>{let l=e.start+o,u=t[l];if(u.kind===`Separator`&&t[l+1]?.text===`MODULE`){if(c.value++,c.value===2){let e=t[l+2].text;r.push({location:qf(u),apply:t=>t.put(Wf(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&a(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&a(l,`variable`),u.text===`RECURSIVE`&&Kf(t,l+1).every(e=>s.has(e))&&a(l,`definition`),zf.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(qf(u)),r.push({location:qf(u),apply:e=>e.put(Wf(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(Wf(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=Vf(e.name);r.push({location:e.location,apply:n=>n.put(Wf(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=o(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),a=n.filter(e=>e.kind===`theorem`);[...i,...a].forEach(n=>{n.isLocal||t.put(Wf(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Wf(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>li(e.location,t.location)?-1:+!!li(t.location,e.location))},a=/* @__PURE__ */ new Map,o=e=>{let t=a.get(e??``);if(t)return t;let n=Uf();a.set(e??``,n),ud.toReversed().forEach(e=>n.put(Wf(e,`builtin`,!1)));let s=r(e);return s.getModule().extends.forEach(e=>o(e).inserted.forEach(e=>{e.isLocal||n.put(e)})),i(s).forEach(e=>e.apply(n)),n};return o(void 0).enumerate().filter(e=>e.kind===n).map(e=>e.name).reverse()},np=(e,t,n)=>{let r=ep(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)}),fd.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=Jf(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;Zf(s(void 0)).forEach((e,t)=>{t===3&&md.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),Zf(s(n)).forEach(a))}Rf.forEach(a);let x=/* @__PURE__ */ new Set,ee=e=>{if(x.has(e))return;x.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(ee),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return ee(void 0),pd.forEach(a),[...i]},rp=t=>{switch(t.kind){case`Number`:try{return Ne(t.value)}catch(t){throw n(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return nt(t.name);case`Set`:return Pt(t.elements.map(rp))}},ip=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],ap=e=>new p(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),op=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:ai},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),sp=(e,t,n)=>{let r=`{ ${n.map(e=>`<${[...e[0],e[1]].map(e=>U(e)).join(`, `)}>`).join(`, `)}}`;return{kind:`Builtin`,name:e,arity:t,evaluate:e=>{let t=n.find(t=>{if(t[0].length!==e.length)throw new v(`Attempted to apply the operator ${r}\nwith wrong number of arguments.`);return t[0].every((t,n)=>{let r=e[n];return(typeof r!=`object`||r.kind!==`Operator`)&&at(t,r)})});if(t)return t[1];throw new v(`Attempted to apply operator:\n${r}\nto arguments (${e.map(e=>typeof e==`object`&&e.kind===`Operator`?e.name:U(e)).join(`, `)}), which is undefined.`)},evaluateUnary:void 0,evaluateBinary:void 0}},cp=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||hr(e).some(e=>cp(e,t)),lp=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(pa(e),n.get(e)??n.size)),n},up=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),dp=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw Po(e);if(e.kind===`Number`&&!Cs(e.value))throw Fo(e);dp(e.kind===`Let`?[...hr(e),...up(e.instances??[])]:hr(e))}),fp=(e,t)=>{let n=ll(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=new Map(wd.map(e=>[e.name,e])),s=/* @__PURE__ */ new Map,c=Wl(e.checkDeadlock,t.seed),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=[],f=/* @__PURE__ */ new Map,h=[],g=[],b=(e,t)=>h.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),x={value:0},ee=e=>`${e}#${x.value++}`,te=[],ne=/* @__PURE__ */ new Map,re=/* @__PURE__ */ new Map,ie=e=>{let n=s.get(e);if(n)return n;let r=Rd(e,t.print,c,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>ie(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{o.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),s.set(e,i),i},S=e=>{let t=ie(e),n=Ld.get(e)??[];return t&&b(e,n),t&&n.includes(`Integers`)&&ie(`Integers`),t},ae=e=>(dp([...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]),...up(e.instances)]),e.modules.forEach(ae),e);ae(n);let C=(e,n)=>{let r=t.loadModule?.(e)??Ac.get(e)??sl(t.source,e);if(r===void 0)throw m([{location:`In module ${n}`,message:`Cannot find source file for module ${e} imported in module ${n}.`}],!0);let i=ll(r);if(i.name!==e)throw m([{location:`Unknown location`,message:`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`}],!0);return ae(i)},oe=e=>{let t=g.indexOf(e.name);if(t!==-1)throw new p(`Circular dependency among .tla files; dependency cycle is: ${[...g.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];g.push(e.name),h.push(n);let i=le(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});h.pop(),g.pop();let a=r.find(e=>n.has(e.name));if(a)throw ap(a);return{linked:i,closure:n}},w=(e,t)=>{let n=l.get(e);if(n)return b(e,f.get(e)??[]),n;let r=oe(C(e,t));return l.set(e,r.linked),f.set(e,r.closure),b(e,r.closure),r.linked},T=(e,t,n,o,s)=>{let c=s?void 0:S(e.module);if(c)return e.name===void 0?c:new Map([...c].map(([t,n])=>[`${e.name}!${t}`,n]));let l=s??w(e.module,t.name),u=ip(l),d=`#${x.value++}`,f=new Map(e.params.map(e=>[e.name,`${e.name}${d}`])),p=qi(tf(e,t),u,t,n);te.push({module:e.module,instancer:t.name,lets:[],substitutions:p,location:e.location});let m=Ta({params:e.params.map(e=>({...e,name:`${e.name}${d}`})),substitutions:new Map([...p].map(([e,t])=>[e,Qi(t,f)])),variables:new Set(l.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(n,s,c)=>{let l=ee(`${s}@${t.name}`);return r.set(l,c(l)),i.set(l,!o),a.set(l,{source:n,prefix:e.params.length}),l},createName:ee}),h=new Set(u.map(e=>e.name)),g=/* @__PURE__ */ new Map;return l.exported.forEach((t,n)=>{if(h.has(n))return;if(e.name===void 0){let r=m.getKey(t.key);u.length>0&&ne.set(r,{name:n,location:e.location}),g.set(n,{key:r,arity:t.arity});return}let r=m.getQualifiedKey(t.key);u.length>0&&ne.set(r,{name:`${e.name}!${n}`,location:e.location}),re.set(r,`${e.name}!${n}`),g.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),g},E=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:ai})),se=(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:E(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),D=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),O=(e,t,n)=>{if(t.arity===0)return{params:[],body:e};if(e.kind===`Lambda`)return{params:e.params.map(e=>({name:e,arity:0})),body:e.body};let r=D(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:E(r,n),location:n}}},ce=(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=D(n.arity);return se(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??w(e.module,n),l=`#${x.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=ip(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};te.push({module:e.module,instancer:n,lets:t,substitutions:new Map(d.map(e=>[e.name,f(e)])),location:o});let p=new Set(e.params.map(e=>e.name)),m=e=>cp(f(e),p),h=d.map(t=>{let n=O(f(t),t,o);return{kind:`Operator`,name:`${t.name}${l}`,params:[...m(t)?e.params:[],...n.params],body:n.body,isLocal:!0,isRecursive:!1,location:o}}),g=[],_=Ta({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:E(e.params,o),location:o,resolution:ai}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:ai}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n,r)=>{let i=`${n}@${e.module}${l}.${g.length}`,a=r(i);return g.push(a.kind===`Operator`?{...a,name:i}:op(a,i)),i},createName:ee}),v=new Set(d.map(e=>e.name)),y=[...c.exported].filter(([e])=>!v.has(e)).map(([t,n])=>{let r=_.getKey(n.key),i=D(n.arity),a=[...e.params,...i];return se(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...y]},k=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),le=(e,a)=>{let o=Rc(e,t.loadClass?.(e.name)),s=new Map([...wd.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,f=[],p=[...o.constants],m=o.variables.map(e=>e.name),h=o.variables.map(e=>e.location),g=(e,t)=>e.forEach((e,n)=>{s.set(n,e),t&&c.set(n,e)});o.extends.forEach(e=>{let t=a.modules.get(e),n=t?void 0: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)=>l.set(t,e)),f.push(r)}),o.constants.forEach(e=>c.set(e.name,{key:e.name,arity:e.arity,declaration:`Constant`})),o.variables.forEach(e=>c.set(e.name,{key:e.name,arity:0,declaration:`Variable`}));let _=p.length===0&&m.length===0,v=e=>o===n?e.name:`${e.name}@${a.id}`,y=/* @__PURE__ */ new Map,b=e=>({imported:s,importedAt:y,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:v}),x=()=>new Map([...a.modules,...l]),ee=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>li(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>li(t.location,e)).map(e=>[e.name,{key:v(e),arity:ui(e)}])]),te=e=>{let t=x();if(t.has(e.name))throw ap(e);a.nested.push(e);let n=le(e,{id:`${a.id}/${e.name}`,symbols:ee(e.location),modules:t,nested:a.nested});l.set(e.name,n),u.has(e.name)||u.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=T(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)=>li(e.location,t.location)?-1:1).forEach(e=>e.link()),Gi(o,b(o));let ne=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&li(e.location,t.location)},ie=e=>{let t=o.modules.find(t=>t.name===e.module);return t?ne(t)?l.get(t.name):void 0:x().get(e.module)},ae=nf(ka(o,(e,t)=>ce(e,t,o.name,ie(e))),k(s));Yi(ae,b(ae)),ae.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:ui(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),Ff(ae,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e),getQualifiedName:e=>re.get(s.get(e)?.key??e)});let C={module:ae,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:l,extended:f};return d.push(C),C},ue=oe(n).linked,de=e=>ue.visible.get(e)?.key??e;ue.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let fe=[],pe=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>pe(e,t)),fe.push(...e.module.assumptions))};pe(ue,/* @__PURE__ */ new Set);let me=ue.constants.map(e=>e.name),he=ue.variables,A=e=>e.module===void 0?[e.name,de(e.name)]:e.module===n.name||me.includes(e.name)?[]:[(l.get(e.module)??u.get(e.module))?.visible.get(e.name)?.key??e.name],ge=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:ue.constants.find(t=>t.name===e)?.arity??0},_e=/* @__PURE__ */ new Map,ve=/* @__PURE__ */ new Set,ye=(e,t)=>{o.set(e,t),r.delete(e),_e.delete(e),ve.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=rp(e.value);A(e).forEach(e=>{let n=ge(e);n===0?_e.set(e,t):ye(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 _(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(rp),rp(e.value)]),j.set(t,n)}),j.forEach(e=>A(e).forEach(t=>ye(t,sp(e.name,ge(t)||e.rows[0][0].length,e.rows))));let be=new Map(e.substitutions.flatMap(e=>A(e).map(t=>[t,de(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!me.includes(n)&&!ue.visible.has(n))throw new _(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new _(`In the configuration file, the identifier ${i} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`);let a=de(i),s=r.get(a);if(!(s!==void 0||o.has(a)||_e.has(a)||me.includes(i)||he.includes(i)))throw new _(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(ue.constants.find(e=>e.name===n)?.arity??ue.visible.get(n)?.arity))throw new _(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)});let xe=new Set([...e.constants,...e.substitutions].filter(e=>e.module!==void 0).flatMap(A)),Se=(e,t)=>{if(xe.has(e))return{key:e,prefix:t};let n=a.get(e);return n&&Se(n.source,t+n.prefix)};a.forEach((e,t)=>{let n=Se(e.source,e.prefix),i=r.get(t);if(!n||!i)return;let a=i.kind===`Operator`?i.params:[],o=se(t,n.key,a,a.slice(n.prefix),i.location);r.set(t,o),ue.visible.forEach((e,n)=>{e.key===t&&n!==t&&r.set(n,o)})});let Ce=me.filter(e=>!_e.has(e)&&!be.has(e)&&!ve.has(e));if(Ce.length>0)throw new _(`The constant parameter ${tp(t.source,t.loadModule,`constant`).find(e=>Ce.includes(e))??Ce[0]} is not assigned a value by the configuration file.`);let we={runtime:c,definitions:r,builtins:o,constants:_e,substitutions:be,variables:he,variableIndex:lp(he,d.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};Lf(te,e=>{let t=l.get(e)??u.get(e)??ue;return{constants:t.constants,variables:t.variables,definitions:[...new Set([...t.visible.values()].flatMap(e=>r.get(e.key)??[]))],assumptions:t.module.assumptions.map(e=>e.expression),getDefinition:e=>r.get(t.visible.get(e)?.key??e)}});let Te=Nf({constants:new Set(_e.keys()),variables:/* @__PURE__ */ new Set([...he,...[`TLCGet`,`Trace`,`CounterExample`].filter(e=>o.has(e))]),getDefinition:e=>Vo(e,we)}),Ee=e=>{try{X(e,{environment:we,scope:void 0,state:void 0,next:void 0});return}catch(e){if(e instanceof v)return e;throw e}};return be.forEach((e,t)=>{let n=r.get(e),i=me.includes(t)&&n?.kind===`Operator`&&n.params.length===0&&Te.analyzeDefinition(n,/* @__PURE__ */ new Map).level>0?Ee(n.body):void 0;if(i)throw new _(`The configuration file substitutes constant ${t} with non-constant ${e}${i instanceof y?``:` - specifically: ${i.message}`}`)}),c.isStarted=!0,{environment:we,assumptions:fe,variableLocations:ue.variableLocations,instanceActions:ne}},pp={kind:`Boolean`,value:!0},mp={kind:`Boolean`,value:!1},hp=e=>e?pp:mp,gp=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,_p=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),vp=(e,t,n)=>({kind:e,operands:[t,n]}),yp=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?yp(e,t.operands).operands:[t])}),bp=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return bp(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,bp(t)),0)}},xp=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 xp(e.body);case`And`:case`Or`:return e.operands.some(xp)}},Sp=/* @__PURE__ */ new WeakMap,Cp={count:0},wp=e=>{let t=Sp.get(e);if(t!==void 0)return t;let n=(()=>{switch(e.kind){case`Boolean`:return String(e.value);case`State`:case`Enabled`:case`Action`:return`#${Cp.count++}`;case`And`:case`Or`:return`${e.kind}(${e.operands.map(wp).join(`,`)})`;default:return`${e.kind}(${wp(e.body)})`}})();return Sp.set(e,n),n},Tp=(e,t)=>e===t||wp(e)===wp(t),Ep=(e,t)=>{let n=wp(t);return e.some(e=>e===t||wp(e)===n)},Dp=e=>e===`And`?`Or`:`And`,Op=(e,t)=>{switch(e.kind){case`Boolean`:return t?hp(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return Op(e.body,!t);case`And`:case`Or`:return yp(t?Dp(e.kind):e.kind,e.operands.map(e=>Op(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,Op(e.body,t))}}},kp=e=>{switch(e.kind){case`Boolean`:return hp(!e.value);case`Not`:return e.body;case`And`:case`Or`:return yp(Dp(e.kind),e.operands.map(kp));case`Always`:return Q(`Eventually`,kp(e.body));case`Eventually`:return Q(`Always`,kp(e.body));default:return Q(`Not`,e)}},Ap=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=Ap(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return hp(t)}return n.length===0?hp(!t):n.length===1?n[0]:yp(e.kind,n)}case`Not`:{let t=Ap(e.body);return t.kind===`Boolean`?hp(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=Ap(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},jp=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,Mp=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=Mp(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new v(`TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form.`);t.push(e)}}if(n.value===1)return{kind:`And`,operands:t};let r=Array.from({length:n.value},()=>[]),i={groups:1,repeat:n.value};for(let e of t){if(e.kind!==`Or`){r.forEach(t=>t.push(e));continue}i.repeat/=e.operands.length;let t={value:0};for(let n=0;n<i.groups;n++)for(let n of e.operands)for(let e=0;e<i.repeat;e++)r[t.value++].push(n);i.groups*=e.operands.length}return{kind:`Or`,operands:r.map(e=>yp(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=Mp(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=jp(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:yp(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return yp(`Or`,n)}case`Not`:return gp(e.body)?e:Mp(kp(e.body));default:return e}},Np=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?Np(e.operands[0]):yp(e.kind,e.operands.map(Np));case`Not`:return e.body.kind===`Not`?Np(e.body.body):Q(`Not`,Np(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Np(e.body));default:return e}},Pp=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return Pp(e.operands[0]);let t=Math.floor(e.operands.length/2);return vp(e.kind,Pp(yp(e.kind,e.operands.slice(0,t))),Pp(yp(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Pp(e.body));default:return e}},Fp=(e,t)=>{e.kind===`Eventually`&&!Ep(t,e)&&t.push(e),`body`in e&&Fp(e.body,t),`operands`in e&&e.operands.forEach(e=>Fp(e,t))},Ip=e=>{let t=e.filter(_p),n=e.flatMap(e=>e.kind===`Not`&&_p(e.body)?[e.body]:[]);return!t.some(e=>Ep(n,e))},Lp=e=>{let t=[...e],n=[];for(;t.length>0;){let e=t.pop();if(!e)break;switch(e.kind){case`Not`:t.push(e.body);break;case`Next`:n.push(e),t.push(e.body);break;case`Always`:case`Eventually`:n.push(e,Q(`Next`,e)),t.push(e.body);break;case`And`:case`Or`:t.push(...e.operands),n.push(e);break;case`Action`:throw new v(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},Rp=(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]}},zp=(e,t,n)=>e.flatMap(e=>{let r=Rp(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),Bp=e=>[...new Set(e.map(wp))].sort().join(`|`),Vp=(e,t)=>{let n=new Set(t.map(Bp));return[...e.filter(e=>!n.has(Bp(e))),...t]},Hp=e=>{let t=Lp(e),n=zp(t,`Always`,`And`),r=zp(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=Rp(t,`Eventually`,`Or`);if(n&&!(Ep(e,n.first)||Ep(e,n.second)))return Vp(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(Ep(e,t.first)||Ep(e,t.second))&&!Ep(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!Ip(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=Rp(t[e],`Always`,`And`);n&&(Ep(t,n.first)||t.push(n.first),Ep(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)Ep(t,e.first)&&Ep(t,e.second)&&!Ep(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!Ip(t)?[]:i(t)};return a(e)},Up=e=>({particle:e,successors:[],statePredicates:e.filter(e=>bp(e)<=1)}),Wp=e=>{let t=Hp([e]).map(Up),n=t.length,r=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let n=Bp(e.particle);r.has(n)||r.set(n,t)});for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let i of Hp(n)){let n=Bp(i),a=r.get(n);a===void 0&&(r.set(n,t.length),t.push(Up(i))),t[e].successors.push(a??t.length-1)}}return{nodes:t,initialCount:n}},Gp=(e,t)=>!Ep(e,t)||Ep(e,t.body),Kp=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&bp(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=jp(e);if(n){let e=bp(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(xp(e))throw new v(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},qp=(e,t)=>{let n=e.findIndex(e=>Tp(e,t));return n===-1?(e.push(t),e.length-1):n},Jp=e=>{let t=Mp(Ap(Op(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=Np(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])Kp(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:yp(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:Tp(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&Pp(e.formula),n=[];t&&Fp(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>qp(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>qp(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>qp(i,e))}));return{tableau:t&&Wp(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Yp=/* @__PURE__ */ new Set([`~>`,`-+->`]),Xp=/* @__PURE__ */ new WeakMap,Zp=/* @__PURE__ */ new WeakSet,Qp=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),$p=(t,r)=>{try{return X(t,r)}catch(t){if(!(t instanceof v)||t instanceof y)throw t;let r=o(t);throw r===void 0?n(new v(`${l}${t.message}`,t),e.error):n(t,r)}},em=e=>new v(`TLC cannot handle the temporal formula at ${To(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Io(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=Vo(e,n);if(t)return tm(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 ia(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 Yp.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},tm=(e,t)=>{let n=Xp.get(e);if(n!==void 0)return n;Xp.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 Xp.set(e,i),i},nm=`Temporal formula is a tautology (its negation is unsatisfiable).`,rm=(t,r,i,a,o=``,s=/* @__PURE__ */ new Set)=>{let c=(e,t,n=o,r=s)=>rm(e,t,i,a,n,r);if(t.kind===`And`)return t.operands.flatMap(e=>c(e,r,Eo(e)));if(t.kind===`Label`)return c(t.body,r);if(t.kind===`Let`)return c(t.body,im(t,r,i));if(t.kind===`Identifier`){let o=W(t)?Io(r,t.name):void 0;if(o?.kind===`Thunk`)return c(o.expression,o.scope);let l=i.constants.has(t.name)?void 0:Vo(t.name,i);if(!o&&l?.kind===`Operator`&&l.params.length===0&&tm(l,i)>0){if(s.has(l))throw n(new v(u),e.error);let r=c(l.body,void 0,t.name,/* @__PURE__ */ new Set([...s,l]));return!a&&tm(l,i)<2?[{expression:l.body,scope:void 0,name:t.name}]:r}}let l=Qp(i,r);if(t.kind===`Apply`&&(e=>a||$(e,r,i)===3)(t)){let e=ss(t,l),n=W(t)?void 0:Vo(t.operator,i);if(e?.kind===`Closure`&&e.params.length===t.args.length&&!n?.isRecursive)return c(e.body,ys(e,t.args,l),t.operator)}if(a&&t.kind===`Forall`&&t.bounds.every(e=>$(e.set,r,i)===0)){let r=[],i={count:0};if(Ko(t.bounds,l,e=>(i.count++,r.push(...c(t.body,e,Eo(t.body))),!1)),i.count===0)throw n(new v(nm),e.livenessEvaluationFailure);return r}return[{expression:t,scope:r,name:o}]},im=(e,t,n)=>{let r=xs(e.definitions,Qp(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&Zp.add(e.binding);return r},am=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),om=(t,r,i)=>{let a=(e,t,n)=>{let r=n===0?$(e,t,i):n;if(r===0){let n=$p(e,Qp(i,t));if(typeof n!=`boolean`)throw new v(`TLC expected a boolean in the temporal formula at ${To(e)}`);return hp(n)}return r===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},o={depth:0},s=(t,r,i,s)=>{if(o.depth>=100)throw n(new v(u),e.error);o.depth++;let c=f(t,r);o.depth--;let l=bp(c);return l>2?c:a(i,s,l)},c=(e,t)=>{let n=e.kind===`Identifier`?e.name:e.operator,r=Qp(i,t),a=W(e)||Vo(n,i)===void 0?Io(t,n):void 0;if(a?.kind===`Thunk`&&Zp.has(a))return s(a.expression,a.scope,e,t);let o=a?.kind===`Operator`?a.operator:a?void 0:W(e)?cs(n,r):as(n,i);if(o?.kind!==`Closure`)throw em(e);let c=e.kind===`Apply`?e.args:[];return s(o.body,ys(o,c,r),e,t)},l=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,i)===0))throw em(e);let n=[];Ko(e.bounds,Qp(i,t),t=>(n.push(f(e.body,t)),!1));let r=e.kind===`Forall`;if(n.length===0)return hp(r);let o=yp(r?`And`:`Or`,n),s=bp(o);return s>2?o:a(e,t,s)},d=(e,t)=>{switch(e.kind){case`Label`:f(e.body,t);return;case`Let`:f(e.body,im(e,t,i));return;case`And`:case`Or`:for(let n of e.operands)f(n,t);return;case`Apply`:if(e.operator===`=>`||e.operator===`~`&&!W(e))for(let n of e.args)f(n,t);return;case`If`:{let n=f(e.condition,t),r=n.kind===`Boolean`?[n.value?e.consequent:e.alternative]:[e.consequent,e.alternative];for(let e of r)f(e,t)}}},f=(e,t)=>{let n=$(e,t,i);if(n<=2)return d(e,t),a(e,t,n);switch(e.kind){case`Label`:return f(e.body,t);case`Let`:return f(e.body,im(e,t,i));case`Identifier`:return c(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,vp(`Or`,Q(`Not`,f(n[0],t)),Q(`Eventually`,f(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,f(n[0],t)):e.operator===`=>`?vp(`Or`,Q(`Not`,f(n[0],t)),f(n[1],t)):c(e,t)}case`And`:case`Or`:return yp(e.kind,e.operands.map(e=>f(e,t)));case`Forall`:case`Exists`:return l(e,t);case`If`:{if($(e.condition,t,i)===0){let n=$p(e.condition,Qp(i,t));if(typeof n==`boolean`)return f(n?e.consequent:e.alternative,t)}let n=f(e.condition,t);return vp(`Or`,vp(`And`,n,f(e.consequent,t)),vp(`And`,Q(`Not`,n),f(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,f(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=am(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`,vp(`Or`,i,a))):vp(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw em(e)}};return f(t,r)},sm=(e,t,n,r,i)=>{let a=e=>sm(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`?Bo(X(e.expression,a),`a temporal property predicate`):bo(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&&Bo(X(e.unchanged,a),`a subscript`)?!1:Bo(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 sm(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new v(`TLC cannot evaluate a temporal formula in a single step`)}},cm=(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)=>cm(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 sm(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},lm=(e,t)=>e.every((e,n)=>st(e,t[n])),um=e=>e.filter((t,n)=>n===0||e[n-1]!==t),dm=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.pending.push(void 0),e.offsets.push(-1),e.edgeOffsets.push(-1),e.nodeStates.length-1),fm=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},pm=(e,t)=>(e.offsets[t]??-1)!==-1,mm=(e,t)=>e.pending[t]??=[],hm=(e,t)=>{let n=e.edgeOffsets[t];return e.edges.ids.subarray(n+1,n+1+e.edges.ids[n])},gm=(e,t,n)=>e.results.bytes[e.offsets[t]+n]===1,_m=2**53-1,vm=(t,r,i,a)=>{if(t.length===0)return;let o=r.map(e=>om(e.expression,e.scope,i)),s=t.map(e=>Q(`Not`,om(e.expression,e.scope,i))),c=s.length===1?s[0]:yp(`Or`,s),l=o.length===0?c:yp(`And`,[...o,c]),u=Jp(l);if(u.length===0)throw n(new v(nm),e.livenessEvaluationFailure);let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=wp(e),n=d.get(t)??d.size;return d.set(t,n),n}),nodeStates:[],nodeTableaux:[],pending:[],offsets:[],results:{bytes:/* @__PURE__ */ new Uint8Array(1024),length:0},edgeOffsets:[],edges:{ids:/* @__PURE__ */ new Int32Array(1024),length:0},initial:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!Ns(i),h={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},g=e=>{let t=h.states.get(e)??/* @__PURE__ */ new Map;return h.states.set(e,t),t},_=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},y=(e,t)=>sm(e,t,void 0,i,m?g(t):/* @__PURE__ */ new Map),b=(e,t,n)=>_(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!y(e,n))),x=(e,t,n,r)=>_(t,()=>{let t=e.solution.actionChecks;if(!m)return Uint8Array.from(t,e=>+!!sm(e,n,r,i,/* @__PURE__ */ new Map));let a=g(n),o=h.actions.get(n)??/* @__PURE__ */ new Map;h.actions.set(n,o);let s=o.get(r)??new Int8Array(d.size).fill(-1);return o.set(r,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!sm(t[o],n,r,i,a)),s[e]))}),ee=(e,t,n,r)=>_(n,()=>e.nodes[t].statePredicates.every(e=>y(e,r))),te=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},ne=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),re=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=fm(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},ie=(e,t,n)=>{let r=dm(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),fm(i,e[t]-1,e[t+1]))}return i.slots.set([t+1,n,r],fm(i,t,n)),r},S=(e,t,n)=>t.nodes.flatMap((t,r)=>re(e,n,r)??[]).sort((e,t)=>e-t),ae=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=e.results,o=a.length;if(a.length+=r.length+n.length*i,a.length>a.bytes.length){let e=new Uint8Array(Math.max(2*a.bytes.length,a.length));e.set(a.bytes),a.bytes=e}a.bytes.set(r,o),n.forEach((e,t)=>a.bytes.set(e,o+r.length+t*i)),e.offsets[t]=o;let s=e.pending[t]??[],c=e.edges,l=c.length;if(c.length+=s.length+1,c.length>c.ids.length){let e=new Int32Array(Math.max(2*c.ids.length,c.length));e.set(c.ids),c.ids=e}c.ids[l]=s.length,c.ids.set(s,l+1),e.edgeOffsets[t]=l,e.pending[t]=void 0},C=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t.index)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&lm(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},oe=(e,t,n,r,i)=>{let o=b(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=mm(e,i),u=s.successors.length>0?x(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ee(t,a,r,n))continue;if(te(t,a)&&e.errorNode===void 0&&ne(e)){e.errorNode=i;return}let o=re(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??ie(e,r,a);l.push(s),c.push(u),o===void 0&&oe(e,t,n,r,s)}for(let i of a.getSuccessors(n)){let a=x(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ee(t,n,r,i.state))continue;let s=re(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??ie(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&oe(e,t,i.state,i.index,u)}}l.length>0&&ae(e,i,c,o)},w=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ee(t,r,a,e.state)));e.isDone[a]=!0;for(let s of S(e,t,a)){let a=mm(e,s),c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=re(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??ie(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&oe(e,t,n.state,n.index,d)}}),ae(e,s,c,i)}if(e.errorNode!==void 0)return um(E(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},T=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)dm(e,e.nodeStates.length,-1);let a=mm(e,i),o=[];t.forEach((t,r)=>{pm(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),ae(e,i,o,r)},E=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)pm(e,t)&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of hm(e,a))if(!(i===a&&e.solution.tableau)){if(i===t){let e=[t];for(let t=a;t!==-1;t=n.get(t)??-1)e.push(t);return e}pm(e,i)&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new v(`Couldn't re-create liveness trace (path) starting at: ${t}`)},se=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=n.stateChecks.length,a=(t,n,a)=>e.results.bytes[e.offsets[t]+i+n*r+a]===1,o=(e,n)=>t.eventuallyAlways.every(t=>a(e,n,t)),s=new Float64Array(e.nodeStates.length).fill(-1),c=e.initial.filter(t=>pm(e,t)),l=[],u=t=>{let n=hm(e,t).indexOf(t);return n!==-1&&o(t,n)},d=(t,r)=>n.tableau!==void 0&&Gp(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let i=l.pop()??r;if(i===r&&!u(i)){s[i]=_m;return}let c=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=i;;t=l.pop()??r){c.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),s[t]=_m,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...c].some(n=>gm(e,n,t))),h=t.infinitelyOftenActions.every(t=>[...c].some(n=>hm(e,n).some((e,r)=>c.has(e)&&o(n,r)&&a(n,r,t)))),g=n.promises.every(e=>[...c].some(t=>d(t,e)));if(m&&h&&g)return p(r,c,f)},p=(r,i,s)=>{let c=um(E(e,r).reverse().map(t=>e.nodeStates[t])),l=[],u=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),p=t.infinitelyOftenActions.map(()=>!1),h=n.promises.map(()=>!1),g={count:f.length+p.length+h.length},_={node:r},y=e=>i.has(e),b=e=>{l.push(_.node),_.node=e};for(;g.count>0;){let r=g.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&gm(e,_.node,t)&&(f[n]=!0,g.count--)}),n.promises.forEach((e,t)=>{!h[t]&&d(_.node,e)&&(h[t]=!0,g.count--)}),!(g.count<=0);){let n={last:-1,unvisited:-1},i=g.count;if(hm(e,_.node).some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!o(_.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!p[t]&&a(_.node,c,e)&&(p[t]=!0,g.count--)})}return g.count<i?(b(r),u.clear(),!0):(y(r)&&!u.has(r)&&(n.unvisited=r),!1)}))break;if(g.count<r){b(n.last),u.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);_.node=t,n.unvisited=hm(e,t).find(e=>y(e)&&!u.has(e))??-1}b(n.unvisited),u.add(n.unvisited)}}let x=m(r,_.node,s,o);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];x[x.length-1]!==n&&x.push(n)}let ee=c[c.length-1];return x[x.length-1]===ee&&x.pop(),{prefix:c.slice(0,-1),cycle:[ee,...x.reverse()]}},m=(t,n,r,i)=>{if(n===t)return[];let a=e.nodeStates[n],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set([a]),c=[];for(let n=a,l=-1,u=0;;u++){for(let u of r.get(n)??[])for(let[d,f]of hm(e,u).entries()){if(f===u||!i(u,d))continue;if(f===t){let e=[];for(let t=n,r=l;t!==a;)e.push(t),t=r,r=o.get(t)??-1;return e.push(a),e}let p=e.nodeStates[f];r.has(p)&&!s.has(p)&&(s.add(p),c.push([p,n]))}o.set(n,l);let d=c[u];if(d===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<c.length;t++){let n=[c[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),a=n.pop()??0;if(i===-42){if(s[a]===t){let e=f(a);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(s[a]!==-1){n.push(Math.min(t,s[a]));continue}s[a]=r.link,n.push(t,a,-42),l.push(a);let u={value:r.link++};hm(e,a).forEach((t,r)=>{pm(e,t)&&(o(a,r)?s[t]===-1?n.push(t,-1):u.value=Math.min(u.value,s[t]):s[t]===-1&&c.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{h.states.clear(),h.actions.clear();for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ee(r,i,void 0,t)&&n.initial.push(re(n,e,i)??ie(n,e,i))}},addState:(e,t,n)=>{h.states.clear(),h.actions.clear();let r=C(e,t,n);for(let n of f){let i=r.map(r=>x(n,e,t,r.state)),a=b(n,e,t),o=n.solution.tableau,s=o?w(n,o,r,i,a,e):T(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=se(e,t);if(n)return n}},getViolatedProperties:(e,n)=>[...new Set(t.filter((t,r)=>!cm(s[r].body,e,n,0,i)).map(e=>e.name))]}},ym=`UnnamedAction`,bm={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},xm=e=>{let t=e.range??bm;return Xt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},Sm=e=>{let t=[[`name`,e.name],[`location`,xm(e.location)]];return e.parameters.length===0?Xt(t):Xt([...t,[`context`,Xt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},Cm=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),wm=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),Tm=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,Em=e=>e.kind===`Apply`?e.args:[],Dm=(e,t,n)=>{let r=Tm(e);if(r===void 0)return;if(W(e)){let e=Io(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=as(r,n);return i?.kind===`Closure`?i:void 0},Om=(e,t)=>{try{return X(e,wm(t,void 0)),!0}catch(e){if(e instanceof f)return!1;throw e}},km=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&Uo(e,t)&&Om(e.body,t),Am=(e,t)=>{let n=Vo(e.name,t);return n?.body===e.body&&km(n,t)},jm=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Io(t,e.name);return n?.kind===`Thunk`?n:void 0},Mm=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Io(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),Nm=(e,t)=>{try{return e()}catch(e){if(e instanceof f)return t();throw e}},Pm=(e,t,n,r,i)=>{let a=Em(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():Nm(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,wm(i,n))]),expression:t,scope:n}],o)},Fm=(e,t,n,r,i)=>{let a=()=>({name:n?.name??ym,location:e.location,parameters:Mm(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return Fm(e.body,xs(e.definitions,wm(r,t)),n,r,i);case`Label`:return Fm(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>Fm(e,t,n,r,i));case`Exists`:return Nm(()=>{let o=[];return Ko(e.bounds,wm(r,t),t=>(o.push(...Fm(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get(Tm(e)??``),s=Dm(e,t,r);if(o)return Pm(o,e,t,s,r);if(!s)return[a()];let c=Em(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return Am(s,r)||c.some(e=>$(e,t,r)!==0)?l():Nm(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,wm(r,t))},parent:e}),s.scope);return Fm(s.body,e,s,r,i)},l)},Im=(e,t,n,r,i)=>{let a=(e,t)=>Im(e,t,n,r,i);if(e.kind===`Let`){a(e.body,xs(e.definitions,wm(n,t)));return}let o=jm(e,t);if(o){a(o.expression,o.scope);return}let s=Dm(e,t,n);if(s&&Am(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(Cm(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,ys(s,e.args,wm(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(Cm(ym,e));return}let c=$(e,t,n);c<=1?r.inits.push(Cm(ym,e)):c===3&&r.temporals.push(Cm(ym,e))},Lm=(e,t,n,r,i)=>{let a=(t,n)=>Lm(e,t,n,r,i);if(t.kind===`Let`){a(t.body,xs(t.definitions,wm(r,n)));return}let o=jm(t,n);if(o){a(o.expression,o.scope);return}let s=Dm(t,n,r);if(s&&Am(s,r))return;if(s&&s.params.length===Em(t).length){a(s.body,t.kind===`Apply`?ys(s,t.args,wm(r,n)):s.scope);return}if(t.kind===`Forall`&&Nm(()=>(Ko(t.bounds,wm(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(Cm(e,a)):$(a,n,r)<2?i.invariants.push(Cm(e,a)):i.impliedTemporals.push(Cm(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(Cm(e,t)):c===3&&i.impliedTemporals.push(Cm(e,t))},Rm=(e,t)=>{let n=Vo(e,t);return n?.kind===`Operator`&&!km(n,t)?n:void 0},zm=e=>Xt([[`name`,e.name],[`location`,xm(e.location)]]),Bm=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:Rm(e.specification,t);a&&(Im(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...Fm(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:as(e.init,t);o?.kind===`Closure`&&r.inits.push(Cm(e.init??``,o.body));let s=e.next===void 0?void 0:as(e.next,t);return s?.kind===`Closure`&&r.actions.push(...Fm(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=Rm(e,t);n&&r.invariants.push(Cm(e,n.body))}),e.properties.forEach(e=>{let n=Rm(e,t);n&&Lm(e,n.body,void 0,t,r)}),r},Vm=(e,t,n)=>Bm(e,t,n).actions,Hm=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>U(e[1])).join(`,`)})`,Um=e=>`${e.name===ym?`Action`:e.name}${Hm(e)} ${h(e.location.range??bm)}`,Wm=e=>`${e.name}${Hm(e)}`,Gm=(e,t,n,r)=>{let i=Bm(e,t,r),a=e=>Pt(e.map(Sm)),o=e=>Pt(e.flatMap(e=>{let n=Rm(e,t);return n?[zm(n)]:[]}));return Xt([[`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`,Pt(t.variables.map((e,t)=>Xt([[`name`,e],[`location`,xm(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},Km=`paired12`,qm=(e,t=16)=>e<=t*.75?t:qm(e,t*2),Jm=(e,t)=>{let n=qm(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Ym=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Xm=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Zm=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Qm=e=>Zm(e).replaceAll(`
418
+ `]]),gd=/* @__PURE__ */ new Map([[`FiniteSets`,/* @__PURE__ */ new Map([[`IsFiniteSet`,`public static tlc2.value.IBoolValue tlc2.module.FiniteSets.IsFiniteSet(tlc2.value.impl.Value)`],[`Cardinality`,`public static tlc2.value.impl.IntValue tlc2.module.FiniteSets.Cardinality(tlc2.value.impl.Value)`]])],[`Sequences`,/* @__PURE__ */ new Map([[`Seq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Seq(tlc2.value.impl.Value)`],[`Len`,`public static tlc2.value.impl.IntValue tlc2.module.Sequences.Len(tlc2.value.impl.Value)`],[`Head`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Head(tlc2.value.impl.Value)`],[`Tail`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Tail(tlc2.value.impl.Value)`],[`Append`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Append(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`\\o`,`public static tlc2.value.impl.Value tlc2.module.Sequences.Concat(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SubSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SubSeq(tlc2.value.impl.Value,tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SelectSeq`,`public static tlc2.value.impl.Value tlc2.module.Sequences.SelectSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`]])],[`TLC`,/* @__PURE__ */ new Map([[`Print`,`public static tlc2.value.impl.Value tlc2.module.TLC.Print(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`PrintT`,`public static tlc2.value.impl.Value tlc2.module.TLC.PrintT(tlc2.value.impl.Value)`],[`ToString`,`public static tlc2.value.impl.Value tlc2.module.TLC.ToString(tlc2.value.impl.Value)`],[`Assert`,`public static tlc2.value.impl.Value tlc2.module.TLC.Assert(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`:>`,`public static tlc2.value.impl.Value tlc2.module.TLC.MakeFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`@@`,`public static tlc2.value.impl.Value tlc2.module.TLC.CombineFcn(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`SortSeq`,`public static tlc2.value.impl.Value tlc2.module.TLC.SortSeq(tlc2.value.impl.Value,tlc2.value.impl.Value)`],[`Permutations`,`public static tlc2.value.impl.Value tlc2.module.TLC.Permutations(tlc2.value.impl.Value)`],[`RandomElement`,`public static tlc2.value.impl.Value tlc2.module.TLC.RandomElement(tlc2.value.impl.Value)`],[`TLCGet`,`public static tlc2.value.impl.Value tlc2.module.TLCGetSet.TLCGetEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`],[`TLCEval`,`public static tlc2.value.impl.Value tlc2.module.TLCEval.tlcEval(tlc2.tool.impl.Tool,tla2sany.semantic.ExprOrOpArgNode[],tlc2.util.Context,tlc2.tool.TLCState,tlc2.tool.TLCState,int,tlc2.tool.coverage.CostModel)`]])]]),_d=(e,t)=>e.every(e=>Cn(e,t)),vd=Pt([!1,!0]),yd=(e,t,n)=>{if(n-t===1)return e[t];let r=t+n>>1;return zt(yd(e,t,r),yd(e,r,n))},bd=[`\\cup`,`\\cap`,`\\`],xd=e=>typeof e==`object`&&e.kind===`MixedSet`,Sd=e=>e.kind===`Interval`?B(e).elements:e.elements,Cd=(e,t,n)=>{let r=Sd(t);if(e!==`\\cup`){let t=e===`\\cap`;return Ft(r.filter(e=>Cn(e,n)===t))}if(r.length===0)return n;if(!je(n))return{kind:`SetOperation`,operator:e,left:t,right:n};let i=B(n).elements.filter(e=>!Cn(e,t));return Ft([...r,...i])},wd=[Or(`TRUE`,!0),Or(`FALSE`,!1),Or(`BOOLEAN`,vd),Or(`STRING`,{kind:`InfiniteSet`,name:`STRING`}),jr(`=`,Mt),jr(`#`,(e,t)=>!Mt(e,t)),K(`~`,1,e=>!br(e,0,`~`)),K(`<=>`,2,e=>br(e,0,`<=>`)===br(e,1,`<=>`)),K(`/\\`,2,e=>br(e,0,`/\\`)&&br(e,1,`/\\`)),K(`\\/`,2,e=>br(e,0,`\\/`)||br(e,1,`\\/`)),K(`=>`,2,e=>!br(e,0,`=>`)||br(e,1,`=>`)),K(`\\in`,2,e=>Cn(G(e,0,`\\in`),G(e,1,`\\in`))),K(`\\notin`,2,e=>!Cn(G(e,0,`\\notin`),G(e,1,`\\notin`))),K(`\\subseteq`,2,e=>{let t=xr(e,0,`\\subseteq`),n=G(e,1,`\\subseteq`);return typeof t==`object`&&t.kind===`Subset`&&typeof n==`object`&&n.kind===`Subset`&&z(t.base)?_d(B(t.base).elements,n.base):_d(B(t).elements,n)}),...bd.map(e=>K(e,2,t=>{let n=G(t,0,e),r=G(t,1,e);if(je(n)&&je(r)&&!xd(n)&&!xd(r)){if(e===`\\cup`&&V(n))return r;let t=e===`\\cup`?zt:e===`\\cap`?Rt:Lt;try{return t(B(n),B(r))}catch(e){if(!(e instanceof v))throw e}}return je(n)?Cd(e,n,r):e!==`\\`&&je(r)?Cd(e,r,n):{kind:`SetOperation`,operator:e,left:n,right:r}})),K(`SUBSET`,1,e=>({kind:`Subset`,base:xr(e,0,`SUBSET`)})),K(`UNION`,1,e=>{let t=xr(e,0,`UNION`),n=bt(t)?t.elements.filter(bt):[];if(!bt(t)||n.length!==t.elements.length)return{kind:`Union`,base:t};if(xd(t)||n.some(xd)){let e={kind:`MixedSet`,elements:[]};return n.forEach(t=>t.elements.forEach(t=>{Cn(t,e)||e.elements.push(t)})),Ft(e.elements)}return n.length===0?It:yd(n.map(B),0,n.length)}),K(`DOMAIN`,1,e=>{let t=G(e,0,`DOMAIN`);if(!P(t))throw new v(`DOMAIN expects a function but received ${U(t)}`);return Ln(t)})],Td=Hr(`Integers`,`Neg`,`IntValue`,1),Ed=e=>{let t=Hr(e,`DotDot`,`IntervalValue`,2);return[Ur(e,`+`,`Plus`,(e,t)=>e+t),Ur(e,`-`,`Minus`,(e,t)=>e-t),Ur(e,`*`,`Times`,(e,t)=>e*t),Ur(e,`^`,`Expt`,(e,t)=>{if(t<0)throw new y(`The second argument of ^ should be a natural number, but instead it is:\n${t}`);if(e===0&&t===0)throw new y(`0^0 is undefined.`);return e**t}),Ur(e,`\\div`,`Divide`,(e,t)=>{if(t===0)throw new y(`The second argument of \\div is 0.`);let n=Math.floor(e/t);if(Mr(n))throw Nr(`${e} \\div ${t}`);return n}),Ur(e,`%`,`Mod`,(e,t)=>{if(t<=0)throw new y(`The second argument of % should be a positive number, but instead it is:\n${t}`);return(e%t+t)%t}),K(`..`,2,e=>({kind:`Interval`,low:Vr(G(e,0,`..`),t),high:Vr(G(e,1,`..`),t)}))]},Dd=[Or(`Nat`,{kind:`InfiniteSet`,name:`Nat`}),...Ed(`Naturals`),Gr(`<`,(e,t)=>e<t),Gr(`>`,(e,t)=>e>t),Gr(`<=`,(e,t)=>e<=t),Gr(`>=`,(e,t)=>e>=t)],Od=[Or(`Int`,{kind:`InfiniteSet`,name:`Int`}),...Ed(`Integers`),K(`-.`,1,e=>{let t=Vr(G(e,0,`-`),Td);if(Mr(-t))throw Nr(`-${t}`);return-t})],kd=(e,t,n)=>{let r=G(e,t,n),i=yn(r);if(!i)throw new y(`${n}\n${U(r)}`);return i},Ad=(e,t,n)=>{let r=G(e,t,n);return typeof r==`string`?r:kd(e,t,n)},jd=(e,t,n)=>typeof e==`string`?Ke(e.slice(t,n)):R(e.slice(t,n)),Md=(e,t)=>`The ${e}argument of ${t} should be a sequence, but instead it is:`,Nd=(e,t)=>`Evaluating an expression of the form ${e} when s is not a ${t}:`,Pd=(e,t)=>{let n=gd.get(e);return n?t.map(e=>{let t=n.get(e.name);return t?Br(e,t):e}):t},Fd=Pd(`Sequences`,[K(`Seq`,1,e=>({kind:`SequenceSet`,base:G(e,0,`Seq`)})),K(`Len`,1,e=>Ad(e,0,Md(``,`Len`)).length),K(`\\o`,2,e=>{let t=Ad(e,0,Nd(`s \\o t`,`sequence`));if(typeof t!=`string`){let n=kd(e,1,Nd(`t \\o s`,`sequence`));return R([...t,...n])}let n=G(e,1,`\\o`);if(typeof n!=`string`)throw new y(`${Nd(`t \\o s`,`string`)}\n${U(n)}`);return Ke(t+n)}),K(`Append`,2,e=>R([...kd(e,0,Nd(`Append(s, v)`,`sequence`)),G(e,1,`Append`)])),K(`Head`,1,e=>{let t=kd(e,0,Md(``,`Head`));if(t.length===0)throw new y(`Attempted to apply Head to the empty sequence.`);return t[0]}),K(`Tail`,1,e=>{let t=Ad(e,0,Md(``,`Tail`));if(t.length===0)throw new y(`Attempted to apply Tail to the empty sequence.`);return jd(t,1)}),K(`SubSeq`,3,e=>{let t=Ad(e,0,Md(`first `,`SubSeq`)),n=yr(e,1,`SubSeq`),r=yr(e,2,`SubSeq`);if(n>r)return jd(t,0,0);let i=n<1?{position:`second`,value:n}:r>t.length?{position:`third`,value:r}:void 0;if(i)throw new y(`The ${i.position} argument of SubSeq must be in the domain of its first argument:\n${U(G(e,0,`SubSeq`))}\n, but instead it is\n${i.value}`);return jd(t,n-1,r)}),kr(`SelectSeq`,2,e=>{let t=Dr(e,1,`SelectSeq`);return R(kd(e,0,Md(`first `,`SelectSeq`)).filter(e=>{let n=t.call([e]);if(typeof n!=`boolean`)throw new y(`The second argument of SelectSeq should be a operator, but instead it is:\n${U(n)}`);return n}))})]),Id=Pd(`FiniteSets`,[K(`IsFiniteSet`,1,e=>{let t=G(e,0,`IsFiniteSet`);if(N(t))return _n(t);if(typeof t==`object`&&t.kind===`Function`)return!0;throw new v(typeof t==`object`&&t.kind===`LazyFunction`?`Attempted to check if the function:\n${U(t)}\nis a finite set.`:`Attempted to check if the ${Me(t)} ${U(t)} is a finite set.`)}),K(`Cardinality`,1,e=>{let t=G(e,0,`Cardinality`);if(!N(t)||typeof t==`object`&&(t.kind===`InfiniteSet`||t.kind===`SequenceSet`))throw new y(`Attempted to compute cardinality of the value\n${U(t)}`);return hn(t)})]),Ld=/* @__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`]]]),Rd=(e,t,n,r)=>{switch(e){case`Naturals`:return{extends:[],operators:Dd};case`Integers`:return{extends:[`Naturals`],operators:Od};case`Sequences`:return{extends:[],operators:Fd};case`FiniteSets`:return{extends:[],operators:Id};case`TLC`:return{extends:[],operators:Pd(`TLC`,ld(t,n))};case`Randomization`:return{extends:[],operators:Bu(n)};case`_Possible`:return{extends:[],operators:td(t,n)};case`Json`:return{extends:[],operators:Pu(r)};case`Bags`:return{extends:[],operators:pu};case`TLCExt`:return{extends:[],operators:ed(t,n)};default:return}},zd=`$subexpression`,Bd=(e,t)=>new p(`${e} at line ${t.line}, column ${t.column}`),Vd=e=>e.filter((t,n)=>n===0||e[n-1].set!==t.set).map(e=>e.set),Hd=(e,t)=>typeof e==`number`?e>=1&&e<=t?e-1:-1:e===`<<`?t>0?0:-1:t===2?1:-1,Ud=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}},Wd=e=>{switch(e.kind){case`Forall`:case`Exists`:case`FunctionConstruction`:return{names:gi(e.bounds),body:e.body,sets:Vd(e.bounds)};case`SetMap`:return{names:gi(e.bounds),body:e.expression,sets:Vd(e.bounds)};case`SetFilter`:return{names:hi(e.bound.pattern),body:e.predicate,sets:[e.bound.set]};case`Choose`:return{names:hi(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}},Gd=(e,t,n)=>{if(e.kind===`Label`)return e.name===t?{label:e,lets:n}:void 0;if(e.kind===`Let`)return Gd(e.body,t,[...n,e.definitions]);if(e.kind!==`Lambda`)for(let r of hr(e)){let e=Gd(r,t,n);if(e)return e}},Kd=(e,t,n)=>e.length===0&&n.length>0?n.splice(0,t):e,qd=(e,t,n)=>t.reduceRight((e,t)=>({kind:`Let`,definitions:t,body:e,location:n}),e),Jd=(e,t)=>{let n=e.location,r=qd(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 Bd(`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 Bd(`The subexpression requires ${e.params.length} arguments but received ${e.args.length}`,n);return{kind:`Let`,definitions:[{kind:`Operator`,name:zd,params:e.params,body:r,isLocal:!0,isRecursive:!1,location:n}],body:{kind:`Apply`,operator:zd,args:e.args,location:n,resolution:ai},location:n}},Yd=(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:ai})),a=i.length===0?{kind:`Identifier`,name:e.name,location:n,resolution:ai}:{kind:`Apply`,operator:e.name,args:i,location:n,resolution:ai};return Jd({...t,params:[...t.params,...r]},a)},Xd=(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 Bd(`Expected an operator name`,n);o.push(c.name),s.push(...c.args);let l=o.join(`!`),u=i?i.find(e=>ta(e)===l):t(l);if(u)return{definition:u,args:Kd(s,ui(u),r)};a.index++}throw Bd(`Unknown operator ${o.join(`!`)}`,n)},s=t=>{let r=o(t),s=r.definition,c=ui(s),l=a.index===e.length-1;if(r.args.length!==c&&r.args.length!==0)throw Bd(`The operator ${s.name} requires ${c} arguments`,n);if(l)return{definition:s,args:r.args};if(s.kind!==`Operator`)throw Bd(`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&&Gd(a.current,t.name,[]);if(!o)throw Bd(`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(...Kd(t.args,o.label.params.length,r)),a.current=o.label.body,a.index++}},l=t=>{let o=a.current;if(!o)throw Bd(`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`||Hd(t.operand,1)!==0)throw Bd(`A LET/IN expression has only one operand`,n);i.lets.push(o.definitions),a.current=o.body;return}let s=Wd(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(...Kd(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[Hd(t.operand,r.length)],s=e[a.index+1];if(!i||s?.kind!==`Operand`)throw Bd(`A subexpression of CASE must have the form !i!j`,n);a.index++;let c=Hd(s.operand,2),l=c===0?i.condition:c===1?i.body:void 0;if(!l)throw Bd(`Nonexistent CASE operand`,n);a.current=l;return}if(t.kind!==`Operand`)throw Bd(`Unexpected subexpression selector`,n);let c=s?s.sets:Ud(o),u=c?.[Hd(t.operand,c.length)];if(!u)throw Bd(`Nonexistent operand specified by the selector`,n);a.current=u},u=s(void 0);if(u)return Yd(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 Bd(`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 Yd(e.definition,{...i,args:[...i.args,...e.args]});c()}else l(t),a.index++}if(!a.current)throw Bd(`Subexpression selection failed`,n);return Jd(i,a.current)},Zd=(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:[]}))]},Qd=e=>e.kind===`Subexpression`||e.kind===`Identifier`&&e.name.includes(`!`)||e.kind===`Apply`&&e.operator.includes(`!`)||hr(e).some(Qd),$d=(e,t)=>{if(!Qd(e))return e;if(e.kind===`Let`){let n=n=>e.definitions.find(e=>e.name===n)??t(n);return ia(e,e=>$d(e,n))}let n=ia(e,e=>$d(e,t));if(n.kind===`Subexpression`)return Xd(n.selectors,t,n.location,[]);let r=n.kind===`Identifier`?n.name:n.kind===`Apply`?n.operator:``,i=Zd(r,t);if(!i)return n;let a=n.kind===`Apply`?[...n.args]:[],o=Xd(i,t,n.location,a);if(a.length>0)throw Bd(`Too many arguments for ${r}`,n.location);return o},ef=e=>{let t=new Map(e.map(e=>[e.name,e]));return e=>t.get(e)},tf=(e,t)=>{let n=ef(t.definitions);return{...e,substitutions:e.substitutions.map(e=>({name:e.name,expression:$d(e.expression,n)}))}},nf=(e,t)=>{let n=ef([...t,...e.definitions]);return e.definitions.some(e=>Qd(e.body))||e.assumptions.some(e=>Qd(e.expression))?{...e,definitions:e.definitions.map(e=>ra(e,e=>$d(e,n))),assumptions:e.assumptions.map(e=>({...e,expression:$d(e.expression,n)}))}:e},rf=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}])),af=(e,t)=>`${e}${t}`,of=(e,t,n)=>`${e}${t}${n}`,sf=e=>{let t=e.split(`\0`);return{operator:t[0],index:Number(t[1]),param:t[2]}},cf=(e,t,n)=>`${e},${t},${n}`,lf=(e=0)=>({level:e,params:/* @__PURE__ */ new Set,constraints:/* @__PURE__ */ new Map,argConstraints:/* @__PURE__ */ new Map,argParams:/* @__PURE__ */ new Set}),uf=(e,t,n)=>e.set(t,Math.min(n,e.get(t)??3)),df=(e,t,n)=>e.set(t,Math.max(n,e.get(t)??0)),ff=(e,t,n,r)=>({...lf(t),name:e,formals:[],maxLevels:n,weights:r,minMaxLevels:[],conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set}),pf=(e,t)=>e.formals.length===0&&e.maxLevels.length>0?e.maxLevels[Math.min(t,e.maxLevels.length-1)]:e.maxLevels[t]??3,mf=(e,t)=>e.formals.length===0&&e.weights.length>0?e.weights[Math.min(t,e.weights.length-1)]:e.weights[t]??1,hf=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,{...ff(e,t,[...n],[...r]),nonLeibniz:new Set(t>1?[0,1]:[])}])),gf=ff(`$Set`,0,[2],[1]),_f=ff(`$Junction`,0,[3],[1]),vf=ff(`$Choose`,0,[2],[1]),yf=ff(`$Function`,0,[3],[1]),bf=ff(`$FcnApply`,0,[2,2],[1,1]),xf=ff(`$RcdSelect`,0,[2,0],[1,1]),Sf=ff(`'`,2,[1],[0]),Cf=ff(`ENABLED`,1,[2],[0]),wf=ff(`[]`,3,[3],[0]),Tf=ff(`$SquareAct`,2,[2,1],[0,0]),Ef=ff(`$WF`,3,[1,2],[0,0]),Df=ff(`$TemporalExists`,3,[3],[0]),Of=(e,t)=>t.length===0?e:new Map([...e,...t.map(e=>[e.name,{kind:`Formal`,arity:e.arity}])]),kf=e=>e.map(e=>({name:e,arity:0})),Af=(e,t)=>t.location.range?g(`${e}.`,t.location.range):new p(`${e} at line ${t.location.line}, column ${t.location.column}`),jf=/* @__PURE__ */ new Set([`/\\`,`\\/`,`=>`,`<=>`]),Mf=e=>e.kind!==`Let`&&e.kind!==`Label`,Nf=e=>{let t=/* @__PURE__ */ new Map,n=(t,n)=>{let r=n.get(t);if(r?.kind===`Formal`)return{kind:`Declared`,name:t,level:0,arity:r.arity};if(r?.kind===`Let`)return{kind:`Defined`,levels:v(r.definition,r.scope)};if(e.constants.has(t))return{kind:`Declared`,name:t,level:0,arity:0};if(e.variables.has(t))return{kind:`Declared`,name:t,level:1,arity:0};let i=e.getDefinition(t);if(i){let n=v(i,/* @__PURE__ */ new Map),r=e.getQualifiedName?.(t);return{kind:`Defined`,levels:r?{...n,name:r}:n}}let a=hf.get(t)??rf.get(t);return a?{kind:`Defined`,levels:a}:{kind:`Declared`,name:t,level:0,arity:0}},r=(e,t,n)=>{let r=lf(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(of(e,n,t))}),t.data.constraints.forEach((e,t)=>uf(r.constraints,t,e)),df(r.argConstraints,af(e,n),t.data.level),t.data.argConstraints.forEach((e,t)=>df(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>pf(e,n))throw new p(`Level error in applying operator ${e.name}:\nThe level of argument ${n+1} exceeds the maximum level allowed by the operator`)}),n.some(e=>e.level>2))throw new p(`Level error in applying operator ${e.name}:\nThe level of the range for a bounded variable exceeds the maximum level allowed by the operator`);let a=n=>{let r=e.formals.findIndex(e=>e.name===n);return r===-1?void 0:t[r]},o=(t,n,r)=>e.conditions.has(cf(t,n,r)),s=lf(Math.max(e.level,...t.filter((t,n)=>mf(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)=>{mf(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)=>uf(s.constraints,t,e)),t.forEach(e=>e.data.constraints.forEach((e,t)=>{i(t)||uf(s.constraints,t,e)})),n.forEach(e=>e.constraints.forEach((e,t)=>uf(s.constraints,t,e))),t.forEach((t,n)=>t.data.params.forEach(t=>{i(t)||uf(s.constraints,t,pf(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=>uf(s.constraints,e,pf(r,a)))}))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator)?.operator;n&&uf(s.constraints,t.param,pf(n,t.index))}),[e.argConstraints,...t.map(e=>e.data.argConstraints),...n.map(e=>e.argConstraints)].forEach(e=>e.forEach((e,t)=>df(s.argConstraints,t,e))),t.forEach((n,r)=>{let i=n.declared;i&&(Array.from({length:i.arity},(t,n)=>df(s.argConstraints,af(i.name,n),e.minMaxLevels[r]?.[n]??0)),t.forEach((e,t)=>Array.from({length:i.arity},(n,a)=>{o(r,t,a)&&df(s.argConstraints,af(i.name,a),e.data.level)})))}),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);n&&df(s.argConstraints,af(t.operator,t.index),n.data.level)}),t.forEach(e=>e.data.argParams.forEach(e=>{i(sf(e).param)||s.argParams.add(e)})),n.forEach(e=>e.argParams.forEach(e=>s.argParams.add(e))),e.argParams.forEach(e=>{let t=sf(e),n=a(t.operator);if(n)n.declared&&s.argParams.add(of(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(of(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(of(r.name,a,e)))}))}),s},a=(e,t)=>{if(e.kind===`Lambda`){let n=_(`LAMBDA`,kf(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=lf();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=Of(n,kf(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 Af(`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 Af(`Action used where only temporal formula or state predicate allowed`,e);jf.has(e.operator)&&l(t,e)},d=(e,t)=>{let n=e.expression,r=e.kind===`Always`?`BoxAction`:`AngleAction`;if(t===2&&Mf(n)&&n.kind!==r)throw Af(e.kind===`Always`?`[] followed by action not of form [A]_v`:`<> followed by action not of form <<A>>_v`,e)},f=(e,t)=>{let n=new Map(t);e.definitions.forEach(e=>n.set(e.name,{kind:`Let`,definition:e,scope:n}));let r=m(e.body,n),i={level:r.level,params:new Set(r.params),constraints:new Map(r.constraints),argConstraints:new Map(r.argConstraints),argParams:new Set(r.argParams)};return e.definitions.forEach(e=>{let t=v(e,n);t.constraints.forEach((e,t)=>uf(i.constraints,t,e)),t.argConstraints.forEach((e,t)=>df(i.argConstraints,t,e)),t.argParams.forEach(e=>i.argParams.add(e))}),i},m=(e,t)=>{try{return h(e,t)}catch(t){throw!(t instanceof p)||t.sany?t:Af(t.message,e)}},h=(e,t)=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:return lf();case`Identifier`:return c(n(e.name,t),[]);case`Apply`:{let r=o(e.args,t);return u(e,r),c(n(e.operator,t),r)}case`OperatorReference`:case`Lambda`:return a(e,t).data;case`And`:case`Or`:{let n=o(e.operands,t);return l(n,e),i(_f,n)}case`Prime`:case`Unchanged`:return s(Sf,[e.expression],t);case`Enabled`:return s(Cf,[e.expression],t);case`Always`:case`Eventually`:{let n=a(e.expression,t);return d(e,n.data.level),i(wf,[n])}case`If`:return s(_f,[e.condition,e.consequent,e.alternative],t);case`Case`:return s(_f,[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]],t);case`Let`:return f(e,t);case`Forall`:case`Exists`:{let n=s(_f,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds)),r=n.level===3?e.bounds.find(e=>m(e.set,t).level===2):void 0;if(r)throw Af(`Action-level bound of quantified temporal formula`,r.set);return n}case`UnboundedQuantifier`:return s(e.isTemporal?Df:_f,[e.body],t,[],e.names);case`Choose`:return s(vf,[e.body],t,e.set?[e.set]:[],hi(e.pattern));case`SetEnumeration`:case`Tuple`:case`FunctionSet`:case`Product`:return s(gf,e.kind===`FunctionSet`?[e.domain,e.range]:e.kind===`Product`?e.factors:e.elements,t);case`SetFilter`:return s(gf,[e.predicate],t,[e.bound.set],hi(e.bound.pattern));case`SetMap`:return s(gf,[e.expression],t,e.bounds.map(e=>e.set),gi(e.bounds));case`FunctionConstruction`:return s(yf,[e.body],t,e.bounds.map(e=>e.set),gi(e.bounds));case`Record`:return s(yf,e.fields.map(e=>e.value),t);case`RecordSet`:return s(gf,e.fields.map(e=>e.value),t);case`Except`:return s(gf,[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])],t);case`FunctionApplication`:return i(bf,[a(e.function,t),e.args.length===1?a(e.args[0],t):{data:s(gf,e.args,t)}]);case`FieldAccess`:return i(xf,[a(e.record,t),{data:lf()}]);case`BoxAction`:case`AngleAction`:return s(Tf,[e.action,e.subscript],t);case`WeakFairness`:case`StrongFairness`:return s(Ef,[e.subscript,e.action],t);case`Label`:return m(e.body,t);case`Subexpression`:return lf()}},g=(e,t,r=!1,i=/* @__PURE__ */ new Set)=>{let a=(e,n=r,a=t)=>g(e,a,n,i),o=(e,o)=>{let s=n(e,t);s.kind===`Declared`?(r&&i.add(e),o.forEach(e=>a(e))):o.forEach((e,t)=>a(e,r||s.levels.nonLeibniz.has(t)))};switch(e.kind){case`Identifier`:return o(e.name,[]),i;case`Apply`:return o(e.operator,e.args),i;case`Lambda`:case`Let`:return i;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:case`BoxAction`:case`AngleAction`:case`WeakFairness`:case`StrongFairness`:return hr(e).forEach(e=>a(e,!0)),i;case`UnboundedQuantifier`:return a(e.body,r||e.isTemporal===!0,Of(t,kf(e.names))),i;default:return ia(e,(e,n)=>(a(e,r,Of(t,kf(n))),e)),i}},_=(e,t,n,r)=>{let i=Of(r,t),a=m(n,i),o=e=>t.some(t=>t.name===e),s=g(n,i),c={...lf(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(af(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(of(e.name,n,t.name))).map(e=>cf(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(sf(t).operator)||c.argConstraints.set(t,e)}),a.argParams.forEach(e=>{let t=sf(e);o(t.operator)&&o(t.param)||c.argParams.add(e)}),c},v=(e,n)=>{let r=t.get(e);if(r)return r;let i=e.kind===`Operator`?e.params:[];t.set(e,{...lf(),name:e.name,formals:i,maxLevels:i.map(()=>3),weights:i.map(()=>0),minMaxLevels:i.map(()=>[]),conditions:/* @__PURE__ */ new Set,nonLeibniz:/* @__PURE__ */ new Set});let a=e.kind===`Function`?{kind:`FunctionConstruction`,bounds:e.bounds,body:e.body,location:e.location}:e.body,o=_(e.name,i,a,n);return t.set(e,o),o};return{analyze:m,analyzeDefinition:v,toOperand:a}},Pf=(e,t,n)=>{let r=new Map(t),i=e.assumptions.flatMap(e=>{if(e.kind===`NewSymbol`){let t=e.set&&n.analyze(e.set,r);return r.set(e.name,{kind:`Formal`,arity:e.arity}),t?[t]:[]}return[e.kind===`AssumeProve`?Pf(e,r,n):n.analyze(e,r)]});i.push(n.analyze(e.conclusion,r));let a=lf(Math.max(...i.map(e=>e.level)));return i.forEach(e=>{e.params.forEach(e=>a.params.add(e)),e.constraints.forEach((e,t)=>uf(a.constraints,t,e)),e.argConstraints.forEach((e,t)=>df(a.argConstraints,t,e)),e.argParams.forEach(e=>a.argParams.add(e))}),a},Ff=(e,t)=>{let n=Nf(t);Ji([...e.definitions.filter(e=>!e.name.includes(`!`)).map(e=>({location:e.location,check:()=>n.analyzeDefinition(e,/* @__PURE__ */ new Map)})),...e.assumptions.map(e=>({location:e.location,check:()=>n.analyze(e.expression,/* @__PURE__ */ new Map)})),...e.theorems.map(e=>({location:e.location,check:()=>e.statement.kind===`AssumeProve`?Pf(e.statement,/* @__PURE__ */ new Map,n):n.analyze(e.statement,/* @__PURE__ */ new Map)}))])},If=(e,t)=>e.maxLevels[t]??3,Lf=(e,t)=>{let n=/* @__PURE__ */ new Map,r=e=>{let r=n.get(e);if(r)return r;let i=t(e),a=Nf({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=>uf(c.constraints,e.name,0));let l=(e,t)=>{e.constraints.forEach((e,t)=>uf(c.constraints,t,e)),e.argConstraints.forEach((e,t)=>df(c.argConstraints,t,e)),e.argParams.forEach(e=>{let n=sf(e);t(n.operator,n.param)&&c.argParams.add(e)})};s.forEach(e=>l(e,(t,n)=>e.formals.every(e=>e.name!==t&&e.name!==n)));let u=e=>{l(e,()=>!0),a.constants.forEach(t=>{e.params.has(t.name)&&uf(c.constraints,t.name,2)})};return a.assumptions.forEach(e=>u(o.analyze(e,/* @__PURE__ */ new Map))),a.theorems.forEach(e=>e.statement.kind===`AssumeProve`?u(Pf(e.statement,/* @__PURE__ */ new Map,o)):l(o.analyze(e.statement,/* @__PURE__ */ new Map),()=>!0)),i.set(e,c),c},o=/* @__PURE__ */ new Map;if(e.forEach(e=>{let n=h(e.location.range??{module:e.instancer,start:e.location,end:e.location}),i=e=>o.set(`${n}\n${e}`,{location:n,message:e}),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}':\nThe level of the expression or operator substituted for '${t}' \nmust 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}':\n 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(af(t.name,a));o!==void 0&&If(r,a)<o&&i(`Level error in instantiating module '${e.module}':\nThe level of the argument ${a+1} of the operator ${r.name} \nmust be at least ${o}.`)})}),c.argParams.forEach(t=>{let n=sf(t),r=d.find(e=>e.name===n.operator)?.operator,a=d.find(e=>e.name===n.param);if(!r||!a)return;let o=If(r,n.index);a.level>o&&i(`Level error when instantiating module '${e.module}':\nThe level of the argument ${n.index} of the operator ${n.operator}' \nmust be at most ${o}.`)})}),o.size>0)throw m([...o.values()])},Rf=[`LAMBDA`,`$$InAssume`,`nullODN`,`nullOpArg`,`nullLabelNode`],zf=/* @__PURE__ */ new Set([`THEOREM`,`LEMMA`,`COROLLARY`,`PROPOSITION`]),Bf=new Map(dd.flatMap(e=>e.map(t=>[t,e[0]]))),Vf=e=>Bf.get(e)??e,Hf=e=>{let t=0;for(let n=0;n<e.length;n++)t=Math.imul(t,31)+e.charCodeAt(n)|0;return t},Uf=()=>{let e={buckets:Array.from({length:11},()=>[]),threshold:8},t=/* @__PURE__ */ new Set,n=[],r=(e,t)=>(Hf(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()}},Wf=(e,t,n)=>({key:t===`module`?`module ${e}`:e,name:e,kind:t,isLocal:n}),Gf=(e,t)=>{let n=e[t],r=e[t+1];if(n.text===`_`&&r.kind===`Operator`)return e[t+2]?.text===`_`?{name:Vf(r.text),end:t+3}:{name:r.text,end:t+2};if(n.kind===`Operator`)return{name:n.text===`-`?`-.`:Vf(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}},Kf=(e,t)=>{let n=[];for(let r=t;;){let t=Gf(e,r);if(n.push(t.name),e[t.end]?.text!==`,`)return n;r=t.end+1}},qf=e=>({line:e.line,column:e.column}),Jf=(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=Kf(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},Yf=(e,t)=>t!==void 0&&t.line===e.line&&t.column===e.column+e.text.length,Xf={"\\":`\\\\`,'"':`\\"`,"\n":`\\n`," ":`\\t`,"\r":`\\r`,"\f":`\\f`},Zf=e=>{let t=[];for(let n=0;n<e.length;n++){let r=e[n];r.text===`<`&&Yf(r,e[n+1])&&/^(\d+|\*|\+)$/.test(e[n+1].text)&&e[n+2]?.text===`>`&&Yf(e[n+1],e[n+2])?n+=Yf(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=>Xf[e])}"`:r.text)}return t},Qf=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},$f=(e,t)=>e.find(e=>e.name===t)??e.map(e=>$f(e.modules,t)).find(Boolean),ep=(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:hd.get(i)??t?.(i)??sl(e,i),s=o===void 0?[]:fe(o),c=Qf(s),l=c.get(s[2]?.text??``)??{start:0,end:0},u={module:void 0},d={tokens:s,...l,getModule:()=>u.module??=ll(o??``)};return n.set(i??``,d),c.forEach((e,t)=>{e.start===l.start||r.has(t)||r.set(t,{tokens:s,...e,getModule:()=>$f(d.getModule().modules,t)??d.getModule()})}),d};return i(void 0),e=>(e===void 0?void 0:r.get(e))??i(e)},tp=(e,t,n)=>{let r=ep(e,t),i=e=>{let t=e.tokens,n=e.getModule(),r=[],i=[],a=(e,n)=>{let i=Kf(t,e+1);r.push({location:qf(t[e]),apply:e=>i.forEach(t=>e.put(Wf(t,n,!1)))})},s=new Set(n.definitions.filter(e=>e.isRecursive).map(e=>e.name)),c={value:0};t.slice(e.start,e.end).forEach((n,o)=>{let l=e.start+o,u=t[l];if(u.kind===`Separator`&&t[l+1]?.text===`MODULE`){if(c.value++,c.value===2){let e=t[l+2].text;r.push({location:qf(u),apply:t=>t.put(Wf(e,`module`,!1))})}}else u.kind===`ModuleEnd`&&c.value--,c.value===1&&u.kind===`Keyword`&&((u.text===`CONSTANT`||u.text===`CONSTANTS`)&&a(l,`constant`),(u.text===`VARIABLE`||u.text===`VARIABLES`)&&a(l,`variable`),u.text===`RECURSIVE`&&Kf(t,l+1).every(e=>s.has(e))&&a(l,`definition`),zf.has(u.text)&&t[l+1]?.kind===`Identifier`&&t[l+2]?.text===`==`&&(i.push(qf(u)),r.push({location:qf(u),apply:e=>e.put(Wf(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(Wf(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=Vf(e.name);r.push({location:e.location,apply:n=>n.put(Wf(t,`definition`,e.isLocal))})}),n.instances.forEach(e=>{r.push({location:e.location,apply:t=>{let n=o(e.module).enumerate(),r=e.name===void 0?``:`${e.name}!`,i=n.filter(e=>e.kind===`definition`),a=n.filter(e=>e.kind===`theorem`);[...i,...a].forEach(n=>{n.isLocal||t.put(Wf(`${r}${n.name}`,n.kind,e.isLocal))}),e.name!==void 0&&t.put(Wf(e.name,`definition`,e.isLocal))}})}),r.sort((e,t)=>li(e.location,t.location)?-1:+!!li(t.location,e.location))},a=/* @__PURE__ */ new Map,o=e=>{let t=a.get(e??``);if(t)return t;let n=Uf();a.set(e??``,n),ud.toReversed().forEach(e=>n.put(Wf(e,`builtin`,!1)));let s=r(e);return s.getModule().extends.forEach(e=>o(e).inserted.forEach(e=>{e.isLocal||n.put(e)})),i(s).forEach(e=>e.apply(n)),n};return o(void 0).enumerate().filter(e=>e.kind===n).map(e=>e.name).reverse()},np=(e,t,n)=>{let r=ep(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)}),fd.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=Jf(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;Zf(s(void 0)).forEach((e,t)=>{t===3&&md.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),Zf(s(n)).forEach(a))}Rf.forEach(a);let x=/* @__PURE__ */ new Set,ee=e=>{if(x.has(e))return;x.add(e);let t=y.get(e)??[],n=u(e).allExtends;[...t.filter(e=>n.has(e)),...t.filter(e=>!n.has(e))].forEach(ee),s(e).forEach(e=>{e.kind===`String`&&a(e.text)})};return ee(void 0),pd.forEach(a),[...i]},rp=t=>{switch(t.kind){case`Number`:try{return Ne(t.value)}catch(t){throw n(t,e.error)}case`String`:case`Boolean`:return t.value;case`ModelValue`:return nt(t.name);case`Set`:return Pt(t.elements.map(rp))}},ip=e=>[...e.constants,...e.variables.map(e=>({name:e,arity:0}))],ap=e=>new p(`Multiply-defined module '${e.name}' at line ${e.location.line}, column ${e.location.column}`),op=(e,t)=>({kind:`Operator`,name:t,params:[],body:{kind:`Let`,definitions:[e],body:{kind:`Identifier`,name:e.name,location:e.location,resolution:ai},location:e.location},isLocal:!0,isRecursive:!1,location:e.location}),sp=(e,t,n)=>{let r=`{ ${n.map(e=>`<${[...e[0],e[1]].map(e=>U(e)).join(`, `)}>`).join(`, `)}}`;return{kind:`Builtin`,name:e,arity:t,evaluate:e=>{let t=n.find(t=>{if(t[0].length!==e.length)throw new v(`Attempted to apply the operator ${r}\nwith wrong number of arguments.`);return t[0].every((t,n)=>{let r=e[n];return(typeof r!=`object`||r.kind!==`Operator`)&&at(t,r)})});if(t)return t[1];throw new v(`Attempted to apply operator:\n${r}\nto arguments (${e.map(e=>typeof e==`object`&&e.kind===`Operator`?e.name:U(e)).join(`, `)}), which is undefined.`)},evaluateUnary:void 0,evaluateBinary:void 0}},cp=(e,t)=>e.kind===`Identifier`&&t.has(e.name)||e.kind===`Apply`&&t.has(e.operator)||hr(e).some(e=>cp(e,t)),lp=(e,t)=>{let n=new Map(e.map((e,t)=>[e,t]));return new Set(t).forEach(e=>n.set(pa(e),n.get(e)??n.size)),n},up=e=>e.flatMap(e=>e.substitutions.map(e=>e.expression)),dp=e=>e.forEach(e=>{if(e.kind===`Decimal`)throw Po(e);if(e.kind===`Number`&&!Cs(e.value))throw Fo(e);dp(e.kind===`Let`?[...hr(e),...up(e.instances??[])]:hr(e))}),fp=(e,t)=>{let n=ll(t.source),r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=new Map(wd.map(e=>[e.name,e])),s=/* @__PURE__ */ new Map,c=Wl(e.checkDeadlock,t.seed),l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d=[],f=/* @__PURE__ */ new Map,h=[],g=[],b=(e,t)=>h.forEach(n=>{n.add(e),[...t].forEach(e=>n.add(e))}),x={value:0},ee=e=>`${e}#${x.value++}`,te=[],ne=/* @__PURE__ */ new Map,re=/* @__PURE__ */ new Map,ie=e=>{let n=s.get(e);if(n)return n;let r=Rd(e,t.print,c,t.files);if(!r)return;let i=/* @__PURE__ */ new Map;return r.extends.forEach(e=>ie(e)?.forEach((e,t)=>i.set(t,e))),r.operators.forEach(e=>{o.set(e.name,e),i.set(e.name,{key:e.name,arity:e.arity})}),s.set(e,i),i},S=e=>{let t=ie(e),n=Ld.get(e)??[];return t&&b(e,n),t&&n.includes(`Integers`)&&ie(`Integers`),t},ae=e=>(dp([...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]),...up(e.instances)]),e.modules.forEach(ae),e);ae(n);let C=(e,n)=>{let r=t.loadModule?.(e)??Ac.get(e)??sl(t.source,e);if(r===void 0)throw m([{location:`In module ${n}`,message:`Cannot find source file for module ${e} imported in module ${n}.`}],!0);let i=ll(r);if(i.name!==e)throw m([{location:`Unknown location`,message:`File name '${e}' does not match the name '${i.name}' of the top level module it contains.`}],!0);return ae(i)},oe=e=>{let t=g.indexOf(e.name);if(t!==-1)throw new p(`Circular dependency among .tla files; dependency cycle is: ${[...g.slice(t),e.name].map(e=>`${e}.tla`).join(` --> `)}`);let n=/* @__PURE__ */ new Set,r=[];g.push(e.name),h.push(n);let i=le(e,{id:e.name,symbols:/* @__PURE__ */ new Map,modules:/* @__PURE__ */ new Map,nested:r});h.pop(),g.pop();let a=r.find(e=>n.has(e.name));if(a)throw ap(a);return{linked:i,closure:n}},w=(e,t)=>{let n=l.get(e);if(n)return b(e,f.get(e)??[]),n;let r=oe(C(e,t));return l.set(e,r.linked),f.set(e,r.closure),b(e,r.closure),r.linked},T=(e,t,n,o,s)=>{let c=s?void 0:S(e.module);if(c)return e.name===void 0?c:new Map([...c].map(([t,n])=>[`${e.name}!${t}`,n]));let l=s??w(e.module,t.name),u=ip(l),d=`#${x.value++}`,f=new Map(e.params.map(e=>[e.name,`${e.name}${d}`])),p=qi(tf(e,t),u,t,n);te.push({module:e.module,instancer:t.name,lets:[],substitutions:p,location:e.location});let m=Ta({params:e.params.map(e=>({...e,name:`${e.name}${d}`})),substitutions:new Map([...p].map(([e,t])=>[e,Qi(t,f)])),variables:new Set(l.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(n,s,c)=>{let l=ee(`${s}@${t.name}`);return r.set(l,c(l)),i.set(l,!o),a.set(l,{source:n,prefix:e.params.length}),l},createName:ee}),h=new Set(u.map(e=>e.name)),g=/* @__PURE__ */ new Map;return l.exported.forEach((t,n)=>{if(h.has(n))return;if(e.name===void 0){let r=m.getKey(t.key);u.length>0&&ne.set(r,{name:n,location:e.location}),g.set(n,{key:r,arity:t.arity});return}let r=m.getQualifiedKey(t.key);u.length>0&&ne.set(r,{name:`${e.name}!${n}`,location:e.location}),re.set(r,`${e.name}!${n}`),g.set(`${e.name}!${n}`,{key:r,arity:t.arity+e.params.length})}),g},E=(e,t)=>e.map(e=>({kind:`Identifier`,name:e.name,location:t,resolution:ai})),se=(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:E(r,i),location:i},isLocal:!0,isRecursive:!1,location:i}),D=e=>Array.from({length:e},(e,t)=>({name:`argument${t}`,arity:0})),O=(e,t,n)=>{if(t.arity===0)return{params:[],body:e};if(e.kind===`Lambda`)return{params:e.params.map(e=>({name:e,arity:0})),body:e.body};let r=D(t.arity);return{params:r,body:{kind:`Apply`,operator:e.kind===`Identifier`?e.name:e.kind===`OperatorReference`?e.operator:t.name,args:E(r,n),location:n}}},ce=(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=D(n.arity);return se(`${e.name}!${t}`,n.key,[...e.params,...r],r,o)});let c=a??w(e.module,n),l=`#${x.value++}`,u=new Map(e.substitutions.map(e=>[e.name,e.expression])),d=ip(c),f=e=>u.get(e.name)??{kind:`Identifier`,name:e.name,location:o};te.push({module:e.module,instancer:n,lets:t,substitutions:new Map(d.map(e=>[e.name,f(e)])),location:o});let p=new Set(e.params.map(e=>e.name)),m=e=>cp(f(e),p),h=d.map(t=>{let n=O(f(t),t,o);return{kind:`Operator`,name:`${t.name}${l}`,params:[...m(t)?e.params:[],...n.params],body:n.body,isLocal:!0,isRecursive:!1,location:o}}),g=[],_=Ta({params:e.params,substitutions:new Map(d.map(t=>[t.name,m(t)?{kind:`Apply`,operator:`${t.name}${l}`,args:E(e.params,o),location:o,resolution:ai}:{kind:`Identifier`,name:`${t.name}${l}`,location:o,resolution:ai}])),variables:new Set(c.variables),getDefinition:e=>r.get(e),isParameterized:e=>i.get(e)===!0,addDefinition:(t,n,r)=>{let i=`${n}@${e.module}${l}.${g.length}`,a=r(i);return g.push(a.kind===`Operator`?{...a,name:i}:op(a,i)),i},createName:ee}),v=new Set(d.map(e=>e.name)),y=[...c.exported].filter(([e])=>!v.has(e)).map(([t,n])=>{let r=_.getKey(n.key),i=D(n.arity),a=[...e.params,...i];return se(e.name===void 0?t:`${e.name}!${t}`,r,a,r===n.key?i:a,o)});return[...h,...g,...y]},k=e=>[...e].flatMap(([e,t])=>{let n=r.get(t.key);return n?[{...n,name:e}]:[]}),le=(e,a)=>{let o=Rc(e,t.loadClass?.(e.name)),s=new Map([...wd.map(e=>[e.name,{key:e.name,arity:e.arity}]),...a.symbols]),c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,f=[],p=[...o.constants],m=o.variables.map(e=>e.name),h=o.variables.map(e=>e.location),g=(e,t)=>e.forEach((e,n)=>{s.set(n,e),t&&c.set(n,e)});o.extends.forEach(e=>{let t=a.modules.get(e),n=t?void 0: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)=>l.set(t,e)),f.push(r)}),o.constants.forEach(e=>c.set(e.name,{key:e.name,arity:e.arity,declaration:`Constant`})),o.variables.forEach(e=>c.set(e.name,{key:e.name,arity:0,declaration:`Variable`}));let _=p.length===0&&m.length===0,v=e=>o===n?e.name:`${e.name}@${a.id}`,y=/* @__PURE__ */ new Map,b=e=>({imported:s,importedAt:y,definitions:new Map(e.definitions.map(e=>[e.name,e])),getKey:v}),x=()=>new Map([...a.modules,...l]),ee=e=>new Map([...s,...[...o.constants.map(e=>({...e,kind:`Constant`})),...o.variables.map(e=>({...e,kind:`Variable`}))].filter(t=>li(t.location,e)).map(e=>[e.name,{key:e.name,arity:e.arity,declaration:e.kind}]),...o.definitions.filter(t=>li(t.location,e)).map(e=>[e.name,{key:v(e),arity:ui(e)}])]),te=e=>{let t=x();if(t.has(e.name))throw ap(e);a.nested.push(e);let n=le(e,{id:`${a.id}/${e.name}`,symbols:ee(e.location),modules:t,nested:a.nested});l.set(e.name,n),u.has(e.name)||u.set(e.name,n)};[...o.instances.map(e=>({location:e.location,link:()=>{let t=T(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)=>li(e.location,t.location)?-1:1).forEach(e=>e.link()),Gi(o,b(o));let ne=e=>{let t=o.instances.find(t=>t.module===e.name);return t!==void 0&&li(e.location,t.location)},ie=e=>{let t=o.modules.find(t=>t.name===e.module);return t?ne(t)?l.get(t.name):void 0:x().get(e.module)},ae=nf(ka(o,(e,t)=>ce(e,t,o.name,ie(e))),k(s));Yi(ae,b(ae)),ae.definitions.forEach(e=>{let t=v(e);r.set(t,e),i.set(t,!_);let n={key:t,arity:ui(e)};s.set(e.name,n),e.isLocal||c.set(e.name,n)}),Ff(ae,{constants:new Set(p.map(e=>e.name)),variables:new Set(m),getDefinition:e=>r.get(s.get(e)?.key??e),getQualifiedName:e=>re.get(s.get(e)?.key??e)});let C={module:ae,constants:p,variables:m,variableLocations:h,visible:s,exported:c,modules:l,extended:f};return d.push(C),C},ue=oe(n).linked,de=e=>ue.visible.get(e)?.key??e;ue.visible.forEach((e,t)=>{let n=r.get(e.key);n&&e.key!==t&&r.set(t,n)});let fe=[],pe=(e,t)=>{t.has(e)||(t.add(e),e.extended.forEach(e=>pe(e,t)),fe.push(...e.module.assumptions))};pe(ue,/* @__PURE__ */ new Set);let me=ue.constants.map(e=>e.name),he=ue.variables,A=e=>e.module===void 0?[e.name,de(e.name)]:e.module===n.name||me.includes(e.name)?[]:[(l.get(e.module)??u.get(e.module))?.visible.get(e.name)?.key??e.name],ge=e=>{let t=r.get(e);return t?.kind===`Operator`?t.params.length:ue.constants.find(t=>t.name===e)?.arity??0},_e=/* @__PURE__ */ new Map,ve=/* @__PURE__ */ new Set,ye=(e,t)=>{o.set(e,t),r.delete(e),_e.delete(e),ve.add(e)};e.constants.filter(e=>e.args===void 0).forEach(e=>{let t=rp(e.value);A(e).forEach(e=>{let n=ge(e);n===0?_e.set(e,t):ye(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 _(`The arity of the operator ${e.name} is inconsistent in the configuration file.`);n.rows.push([e.args.map(rp),rp(e.value)]),j.set(t,n)}),j.forEach(e=>A(e).forEach(t=>ye(t,sp(e.name,ge(t)||e.rows[0][0].length,e.rows))));let be=new Map(e.substitutions.flatMap(e=>A(e).map(t=>[t,de(e.target)])));e.substitutions.filter(e=>e.module===void 0).forEach(t=>{let n=t.name,i=t.target;if(!me.includes(n)&&!ue.visible.has(n))throw new _(`In the configuration file, the identifier ${n} does not appear in the specification.`);if(e.substitutions.some(e=>e.name===i))throw new _(`In the configuration file, the identifier ${i} appears\non the right-hand side of a <- after already appearing on the\nleft-hand side of one.`);let a=de(i),s=r.get(a);if(!(s!==void 0||o.has(a)||_e.has(a)||me.includes(i)||he.includes(i)))throw new _(`The configuration file substitutes for ${n} with the undefined identifier ${i}.`);if(s?.kind===`Operator`&&s.params.length!==(ue.constants.find(e=>e.name===n)?.arity??ue.visible.get(n)?.arity))throw new _(`The configuration file substitutes for ${n} with ${i} of different number of arguments.`)});let xe=new Set([...e.constants,...e.substitutions].filter(e=>e.module!==void 0).flatMap(A)),Se=(e,t)=>{if(xe.has(e))return{key:e,prefix:t};let n=a.get(e);return n&&Se(n.source,t+n.prefix)};a.forEach((e,t)=>{let n=Se(e.source,e.prefix),i=r.get(t);if(!n||!i)return;let a=i.kind===`Operator`?i.params:[],o=se(t,n.key,a,a.slice(n.prefix),i.location);r.set(t,o),ue.visible.forEach((e,n)=>{e.key===t&&n!==t&&r.set(n,o)})});let Ce=me.filter(e=>!_e.has(e)&&!be.has(e)&&!ve.has(e));if(Ce.length>0)throw new _(`The constant parameter ${tp(t.source,t.loadModule,`constant`).find(e=>Ce.includes(e))??Ce[0]} is not assigned a value by the configuration file.`);let we={runtime:c,definitions:r,builtins:o,constants:_e,substitutions:be,variables:he,variableIndex:lp(he,d.flatMap(e=>e.module.variables.map(e=>e.name))),definitionValues:/* @__PURE__ */ new Map,constantLevels:/* @__PURE__ */ new Map,evaluators:/* @__PURE__ */ new WeakMap};Lf(te,e=>{let t=l.get(e)??u.get(e)??ue;return{constants:t.constants,variables:t.variables,definitions:[...new Set([...t.visible.values()].flatMap(e=>r.get(e.key)??[]))],assumptions:t.module.assumptions.map(e=>e.expression),theorems:t.module.theorems,getDefinition:e=>r.get(t.visible.get(e)?.key??e)}});let Te=Nf({constants:new Set(_e.keys()),variables:/* @__PURE__ */ new Set([...he,...[`TLCGet`,`Trace`,`CounterExample`].filter(e=>o.has(e))]),getDefinition:e=>Vo(e,we)}),Ee=e=>{try{X(e,{environment:we,scope:void 0,state:void 0,next:void 0});return}catch(e){if(e instanceof v)return e;throw e}};return be.forEach((e,t)=>{let n=r.get(e),i=me.includes(t)&&n?.kind===`Operator`&&n.params.length===0&&Te.analyzeDefinition(n,/* @__PURE__ */ new Map).level>0?Ee(n.body):void 0;if(i)throw new _(`The configuration file substitutes constant ${t} with non-constant ${e}${i instanceof y?``:` - specifically: ${i.message}`}`)}),c.isStarted=!0,{environment:we,assumptions:fe,variableLocations:ue.variableLocations,instanceActions:ne}},pp={kind:`Boolean`,value:!0},mp={kind:`Boolean`,value:!1},hp=e=>e?pp:mp,gp=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Action`,_p=e=>e.kind===`State`||e.kind===`Enabled`||e.kind===`Boolean`,Q=(e,t)=>({kind:e,body:t}),vp=(e,t,n)=>({kind:e,operands:[t,n]}),yp=(e,t)=>({kind:e,operands:t.flatMap(t=>t.kind===e?yp(e,t.operands).operands:[t])}),bp=e=>{switch(e.kind){case`Boolean`:return 0;case`State`:case`Enabled`:return 1;case`Action`:case`Next`:return 2;case`Not`:return bp(e.body);case`Always`:case`Eventually`:return 3;case`And`:case`Or`:return e.operands.reduce((e,t)=>Math.max(e,bp(t)),0)}},xp=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 xp(e.body);case`And`:case`Or`:return e.operands.some(xp)}},Sp=/* @__PURE__ */ new WeakMap,Cp={count:0},wp=e=>{let t=Sp.get(e);if(t!==void 0)return t;let n=(()=>{switch(e.kind){case`Boolean`:return String(e.value);case`State`:case`Enabled`:case`Action`:return`#${Cp.count++}`;case`And`:case`Or`:return`${e.kind}(${e.operands.map(wp).join(`,`)})`;default:return`${e.kind}(${wp(e.body)})`}})();return Sp.set(e,n),n},Tp=(e,t)=>e===t||wp(e)===wp(t),Ep=(e,t)=>{let n=wp(t);return e.some(e=>e===t||wp(e)===n)},Dp=e=>e===`And`?`Or`:`And`,Op=(e,t)=>{switch(e.kind){case`Boolean`:return t?hp(!e.value):e;case`State`:case`Enabled`:case`Action`:case`Next`:return t?Q(`Not`,e):e;case`Not`:return Op(e.body,!t);case`And`:case`Or`:return yp(t?Dp(e.kind):e.kind,e.operands.map(e=>Op(e,t)));case`Always`:case`Eventually`:{let n=t===(e.kind===`Always`)?`Eventually`:`Always`;return Q(n,Op(e.body,t))}}},kp=e=>{switch(e.kind){case`Boolean`:return hp(!e.value);case`Not`:return e.body;case`And`:case`Or`:return yp(Dp(e.kind),e.operands.map(kp));case`Always`:return Q(`Eventually`,kp(e.body));case`Eventually`:return Q(`Always`,kp(e.body));default:return Q(`Not`,e)}},Ap=e=>{switch(e.kind){case`And`:case`Or`:{let t=e.kind===`Or`,n=[];for(let r of e.operands){let e=Ap(r);if(e.kind!==`Boolean`)n.push(e);else if(e.value===t)return hp(t)}return n.length===0?hp(!t):n.length===1?n[0]:yp(e.kind,n)}case`Not`:{let t=Ap(e.body);return t.kind===`Boolean`?hp(!t.value):Q(`Not`,t)}case`Always`:case`Eventually`:{let t=Ap(e.body);return Q(e.kind,t.kind===e.kind?t.body:t)}default:return e}},jp=e=>e.kind===`Always`&&e.body.kind===`Eventually`?e.body.body:void 0,Mp=e=>{switch(e.kind){case`And`:{let t=[],n={value:1};for(let r of e.operands){let e=Mp(r);if(e.kind===`And`)t.push(...e.operands);else{if(e.kind===`Or`&&(n.value*=e.operands.length,n.value>2147483647))throw new v(`TLC cannot handle the temporal formula because it exceeds the maximum supported size in disjunctive normal form.`);t.push(e)}}if(n.value===1)return{kind:`And`,operands:t};let r=Array.from({length:n.value},()=>[]),i={groups:1,repeat:n.value};for(let e of t){if(e.kind!==`Or`){r.forEach(t=>t.push(e));continue}i.repeat/=e.operands.length;let t={value:0};for(let n=0;n<i.groups;n++)for(let n of e.operands)for(let e=0;e<i.repeat;e++)r[t.value++].push(n);i.groups*=e.operands.length}return{kind:`Or`,operands:r.map(e=>yp(`And`,e))}}case`Or`:{let t=[],n=[];for(let r of e.operands){let e=Mp(r);for(let r of e.kind===`Or`?e.operands:[e]){let e=jp(r);e?t.push(e):n.push(r)}}if(t.length>0){let e=t.length===1?t[0]:yp(`Or`,t);n.push(Q(`Always`,Q(`Eventually`,e)))}return yp(`Or`,n)}case`Not`:return gp(e.body)?e:Mp(kp(e.body));default:return e}},Np=e=>{switch(e.kind){case`And`:case`Or`:return e.operands.length===1?Np(e.operands[0]):yp(e.kind,e.operands.map(Np));case`Not`:return e.body.kind===`Not`?Np(e.body.body):Q(`Not`,Np(e.body));case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Np(e.body));default:return e}},Pp=e=>{switch(e.kind){case`And`:case`Or`:{if(e.operands.length===1)return Pp(e.operands[0]);let t=Math.floor(e.operands.length/2);return vp(e.kind,Pp(yp(e.kind,e.operands.slice(0,t))),Pp(yp(e.kind,e.operands.slice(t))))}case`Not`:case`Always`:case`Eventually`:case`Next`:return Q(e.kind,Pp(e.body));default:return e}},Fp=(e,t)=>{e.kind===`Eventually`&&!Ep(t,e)&&t.push(e),`body`in e&&Fp(e.body,t),`operands`in e&&e.operands.forEach(e=>Fp(e,t))},Ip=e=>{let t=e.filter(_p),n=e.flatMap(e=>e.kind===`Not`&&_p(e.body)?[e.body]:[]);return!t.some(e=>Ep(n,e))},Lp=e=>{let t=[...e],n=[];for(;t.length>0;){let e=t.pop();if(!e)break;switch(e.kind){case`Not`:t.push(e.body);break;case`Next`:n.push(e),t.push(e.body);break;case`Always`:case`Eventually`:n.push(e,Q(`Next`,e)),t.push(e.body);break;case`And`:case`Or`:t.push(...e.operands),n.push(e);break;case`Action`:throw new v(`TLC encountered actions while constructing the tableau`);default:n.push(e)}}return n},Rp=(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]}},zp=(e,t,n)=>e.flatMap(e=>{let r=Rp(e,t,n);return r?[{whole:e,first:r.first,second:r.second}]:[]}),Bp=e=>[...new Set(e.map(wp))].sort().join(`|`),Vp=(e,t)=>{let n=new Set(t.map(Bp));return[...e.filter(e=>!n.has(Bp(e))),...t]},Hp=e=>{let t=Lp(e),n=zp(t,`Always`,`And`),r=zp(t,`Eventually`,`Or`),i=e=>{for(let t of e){let n=Rp(t,`Eventually`,`Or`);if(n&&!(Ep(e,n.first)||Ep(e,n.second)))return Vp(a([...e,n.first]),a([...e,n.second]))}let t=r.find(t=>(Ep(e,t.first)||Ep(e,t.second))&&!Ep(e,t.whole));return t?a([...e,t.whole]):[e]},a=e=>{if(!Ip(e))return[];let t=[...e];for(let e=0;e<t.length;e++){let n=Rp(t[e],`Always`,`And`);n&&(Ep(t,n.first)||t.push(n.first),Ep(t,n.second)||t.push(n.second))}let r={isChanged:!0};for(;r.isChanged;){r.isChanged=!1;for(let e of n)Ep(t,e.first)&&Ep(t,e.second)&&!Ep(t,e.whole)&&(t.push(e.whole),r.isChanged=!0)}return t.length>e.length&&!Ip(t)?[]:i(t)};return a(e)},Up=e=>({particle:e,successors:[],statePredicates:e.filter(e=>bp(e)<=1)}),Wp=e=>{let t=Hp([e]).map(Up),n=t.length,r=/* @__PURE__ */ new Map;t.forEach((e,t)=>{let n=Bp(e.particle);r.has(n)||r.set(n,t)});for(let e=0;e<t.length;e++){let n=t[e].particle.flatMap(e=>e.kind===`Next`?[e.body]:[]);for(let i of Hp(n)){let n=Bp(i),a=r.get(n);a===void 0&&(r.set(n,t.length),t.push(Up(i))),t[e].successors.push(a??t.length-1)}}return{nodes:t,initialCount:n}},Gp=(e,t)=>!Ep(e,t)||Ep(e,t.body),Kp=(e,t)=>{if(e.kind===`Eventually`&&e.body.kind===`Always`&&bp(e.body.body)<3){t.eventuallyAlways.push(e.body.body);return}let n=jp(e);if(n){let e=bp(n);if(e<=1){t.infinitelyOftenStates.push(n);return}if(e===2){t.infinitelyOftenActions.push(n);return}}if(xp(e))throw new v(`TLC cannot handle the temporal formula: actions may only appear as []<>A or <>[]A`);t.formulas.push(e)},qp=(e,t)=>{let n=e.findIndex(e=>Tp(e,t));return n===-1?(e.push(t),e.length-1):n},Jp=e=>{let t=Mp(Ap(Op(e,!1)));if(t.kind===`Boolean`&&!t.value)return[];let n=[];for(let e of t.kind===`Or`?t.operands:[t]){let t=Np(e),r={eventuallyAlways:[],infinitelyOftenStates:[],infinitelyOftenActions:[],formulas:[]};for(let e of t.kind===`And`?t.operands:[t])Kp(e,r);let i=r.formulas,a=i.length===0?void 0:i.length===1?i[0]:yp(`And`,i),o=n.find(e=>e.formula===void 0||a===void 0?e.formula===a:Tp(e.formula,a));o?o.classifications.push(r):n.push({formula:a,classifications:[r]})}return n.map(e=>{let t=e.formula&&Pp(e.formula),n=[];t&&Fp(t,n);let r=[],i=[],a=e.classifications.map(e=>({infinitelyOftenActions:e.infinitelyOftenActions.map(e=>qp(i,e)),infinitelyOftenStates:e.infinitelyOftenStates.map(e=>qp(r,e)),eventuallyAlways:e.eventuallyAlways.map(e=>qp(i,e))}));return{tableau:t&&Wp(t),promises:n,stateChecks:r,actionChecks:i,models:a}})},Yp=/* @__PURE__ */ new Set([`~>`,`-+->`]),Xp=/* @__PURE__ */ new WeakMap,Zp=/* @__PURE__ */ new WeakSet,Qp=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),$p=(t,r)=>{try{return X(t,r)}catch(t){if(!(t instanceof v)||t instanceof y)throw t;let r=o(t);throw r===void 0?n(new v(`${l}${t.message}`,t),e.error):n(t,r)}},em=e=>new v(`TLC cannot handle the temporal formula at ${To(e)}`),$=(e,t,n,r=/* @__PURE__ */ new Set)=>{let i=e=>{let r=Io(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=Vo(e,n);if(t)return tm(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 ia(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 Yp.has(e.operator)?3:e.operator===`\\cdot`?2:Math.max(o(e.operator,e),s(e));default:return s(e)}},tm=(e,t)=>{let n=Xp.get(e);if(n!==void 0)return n;Xp.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 Xp.set(e,i),i},nm=`Temporal formula is a tautology (its negation is unsatisfiable).`,rm=(t,r,i,a,o=``,s=/* @__PURE__ */ new Set)=>{let c=(e,t,n=o,r=s)=>rm(e,t,i,a,n,r);if(t.kind===`And`)return t.operands.flatMap(e=>c(e,r,Eo(e)));if(t.kind===`Label`)return c(t.body,r);if(t.kind===`Let`)return c(t.body,im(t,r,i));if(t.kind===`Identifier`){let o=W(t)?Io(r,t.name):void 0;if(o?.kind===`Thunk`)return c(o.expression,o.scope);let l=i.constants.has(t.name)?void 0:Vo(t.name,i);if(!o&&l?.kind===`Operator`&&l.params.length===0&&tm(l,i)>0){if(s.has(l))throw n(new v(u),e.error);let r=c(l.body,void 0,t.name,/* @__PURE__ */ new Set([...s,l]));return!a&&tm(l,i)<2?[{expression:l.body,scope:void 0,name:t.name}]:r}}let l=Qp(i,r);if(t.kind===`Apply`&&(e=>a||$(e,r,i)===3)(t)){let e=ss(t,l),n=W(t)?void 0:Vo(t.operator,i);if(e?.kind===`Closure`&&e.params.length===t.args.length&&!n?.isRecursive)return c(e.body,ys(e,t.args,l),t.operator)}if(a&&t.kind===`Forall`&&t.bounds.every(e=>$(e.set,r,i)===0)){let r=[],i={count:0};if(Ko(t.bounds,l,e=>(i.count++,r.push(...c(t.body,e,Eo(t.body))),!1)),i.count===0)throw n(new v(nm),e.livenessEvaluationFailure);return r}return[{expression:t,scope:r,name:o}]},im=(e,t,n)=>{let r=xs(e.definitions,Qp(n,t));for(let e=r;e&&e!==t;e=e.parent)e.binding.kind===`Thunk`&&Zp.add(e.binding);return r},am=(e,t)=>({kind:`AngleAction`,action:e,subscript:t,location:e.location}),om=(t,r,i)=>{let a=(e,t,n)=>{let r=n===0?$(e,t,i):n;if(r===0){let n=$p(e,Qp(i,t));if(typeof n!=`boolean`)throw new v(`TLC expected a boolean in the temporal formula at ${To(e)}`);return hp(n)}return r===1?{kind:`State`,expression:e,scope:t}:{kind:`Action`,expression:e,unchanged:void 0,scope:t}},o={depth:0},s=(t,r,i,s)=>{if(o.depth>=100)throw n(new v(u),e.error);o.depth++;let c=f(t,r);o.depth--;let l=bp(c);return l>2?c:a(i,s,l)},c=(e,t)=>{let n=e.kind===`Identifier`?e.name:e.operator,r=Qp(i,t),a=W(e)||Vo(n,i)===void 0?Io(t,n):void 0;if(a?.kind===`Thunk`&&Zp.has(a))return s(a.expression,a.scope,e,t);let o=a?.kind===`Operator`?a.operator:a?void 0:W(e)?cs(n,r):as(n,i);if(o?.kind!==`Closure`)throw em(e);let c=e.kind===`Apply`?e.args:[];return s(o.body,ys(o,c,r),e,t)},l=(e,t)=>{if(!e.bounds.every(e=>$(e.set,t,i)===0))throw em(e);let n=[];Ko(e.bounds,Qp(i,t),t=>(n.push(f(e.body,t)),!1));let r=e.kind===`Forall`;if(n.length===0)return hp(r);let o=yp(r?`And`:`Or`,n),s=bp(o);return s>2?o:a(e,t,s)},d=(e,t)=>{switch(e.kind){case`Label`:f(e.body,t);return;case`Let`:f(e.body,im(e,t,i));return;case`And`:case`Or`:for(let n of e.operands)f(n,t);return;case`Apply`:if(e.operator===`=>`||e.operator===`~`&&!W(e))for(let n of e.args)f(n,t);return;case`If`:{let n=f(e.condition,t),r=n.kind===`Boolean`?[n.value?e.consequent:e.alternative]:[e.consequent,e.alternative];for(let e of r)f(e,t)}}},f=(e,t)=>{let n=$(e,t,i);if(n<=2)return d(e,t),a(e,t,n);switch(e.kind){case`Label`:return f(e.body,t);case`Let`:return f(e.body,im(e,t,i));case`Identifier`:return c(e,t);case`Apply`:{let n=e.args;return e.operator===`~>`?Q(`Always`,vp(`Or`,Q(`Not`,f(n[0],t)),Q(`Eventually`,f(n[1],t)))):e.operator===`~`&&!W(e)?Q(`Not`,f(n[0],t)):e.operator===`=>`?vp(`Or`,Q(`Not`,f(n[0],t)),f(n[1],t)):c(e,t)}case`And`:case`Or`:return yp(e.kind,e.operands.map(e=>f(e,t)));case`Forall`:case`Exists`:return l(e,t);case`If`:{if($(e.condition,t,i)===0){let n=$p(e.condition,Qp(i,t));if(typeof n==`boolean`)return f(n?e.consequent:e.alternative,t)}let n=f(e.condition,t);return vp(`Or`,vp(`And`,n,f(e.consequent,t)),vp(`And`,Q(`Not`,n),f(e.alternative,t)))}case`Always`:case`Eventually`:return Q(e.kind,f(e.expression,t));case`WeakFairness`:case`StrongFairness`:{let n=am(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`,vp(`Or`,i,a))):vp(`Or`,Q(`Eventually`,Q(`Always`,i)),Q(`Always`,Q(`Eventually`,a)))}default:throw em(e)}};return f(t,r)},sm=(e,t,n,r,i)=>{let a=e=>sm(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`?Bo(X(e.expression,a),`a temporal property predicate`):bo(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&&Bo(X(e.unchanged,a),`a subscript`)?!1:Bo(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 sm(e.body,n??t,void 0,r,/* @__PURE__ */ new Map);case`Always`:case`Eventually`:throw new v(`TLC cannot evaluate a temporal formula in a single step`)}},cm=(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)=>cm(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 sm(e,t[r],t[a(r)],i,/* @__PURE__ */ new Map)}},lm=(e,t)=>e.every((e,n)=>st(e,t[n])),um=e=>e.filter((t,n)=>n===0||e[n-1]!==t),dm=(e,t,n)=>(e.nodeStates.push(t),e.nodeTableaux.push(n),e.pending.push(void 0),e.offsets.push(-1),e.edgeOffsets.push(-1),e.nodeStates.length-1),fm=(e,t,n)=>{let r=e.slots.length/3-1,i=Math.imul(Math.imul(t,2654435761)^n,2246822507)>>>e.shift;for(let a=i;;a=a+1&r){let r=a*3,i=e.slots[r];if(i===0||i===t+1&&e.slots[r+1]===n)return r}},pm=(e,t)=>(e.offsets[t]??-1)!==-1,mm=(e,t)=>e.pending[t]??=[],hm=(e,t)=>{let n=e.edgeOffsets[t];return e.edges.ids.subarray(n+1,n+1+e.edges.ids[n])},gm=(e,t,n)=>e.results.bytes[e.offsets[t]+n]===1,_m=2**53-1,vm=(t,r,i,a)=>{if(t.length===0)return;let o=r.map(e=>om(e.expression,e.scope,i)),s=t.map(e=>Q(`Not`,om(e.expression,e.scope,i))),c=s.length===1?s[0]:yp(`Or`,s),l=o.length===0?c:yp(`And`,[...o,c]),u=Jp(l);if(u.length===0)throw n(new v(nm),e.livenessEvaluationFailure);let d=/* @__PURE__ */ new Map,f=u.map(e=>({solution:e,actionIds:Int32Array.from(e.actionChecks,e=>{let t=wp(e),n=d.get(t)??d.size;return d.set(t,n),n}),nodeStates:[],nodeTableaux:[],pending:[],offsets:[],results:{bytes:/* @__PURE__ */ new Uint8Array(1024),length:0},edgeOffsets:[],edges:{ids:/* @__PURE__ */ new Int32Array(1024),length:0},initial:[],nodeIds:{slots:/* @__PURE__ */ new Int32Array(3072),size:0,shift:22},isDone:[],errorNode:void 0})),p={multiplier:1},m=!Ns(i),h={states:/* @__PURE__ */ new Map,actions:/* @__PURE__ */ new Map},g=e=>{let t=h.states.get(e)??/* @__PURE__ */ new Map;return h.states.set(e,t),t},_=(e,t)=>{i.runtime.setLivenessSource(e);let n=t();return i.runtime.setLivenessSource(void 0),n},y=(e,t)=>sm(e,t,void 0,i,m?g(t):/* @__PURE__ */ new Map),b=(e,t,n)=>_(t,()=>Uint8Array.from(e.solution.stateChecks,e=>+!!y(e,n))),x=(e,t,n,r)=>_(t,()=>{let t=e.solution.actionChecks;if(!m)return Uint8Array.from(t,e=>+!!sm(e,n,r,i,/* @__PURE__ */ new Map));let a=g(n),o=h.actions.get(n)??/* @__PURE__ */ new Map;h.actions.set(n,o);let s=o.get(r)??new Int8Array(d.size).fill(-1);return o.set(r,s),Uint8Array.from(e.actionIds,(e,o)=>(s[e]===-1&&(s[e]=+!!sm(t[o],n,r,i,a)),s[e]))}),ee=(e,t,n,r)=>_(n,()=>e.nodes[t].statePredicates.every(e=>y(e,r))),te=(e,t)=>{let n=e.nodes[t];return n.particle.length===0&&n.successors.length===1&&n.successors[0]===t},ne=e=>e.solution.models.some(e=>e.eventuallyAlways.length===0&&e.infinitelyOftenStates.length===0&&e.infinitelyOftenActions.length===0),re=(e,t,n)=>{if(!e.solution.tableau)return t;let r=e.nodeIds.slots,i=fm(e.nodeIds,t,n);return r[i]===0?void 0:r[i+2]},ie=(e,t,n)=>{let r=dm(e,t,n),i=e.nodeIds;if(++i.size*2>i.slots.length/3){let e=i.slots;i.slots=new Int32Array(e.length*2),i.shift--;for(let t=0;t<e.length;t+=3)e[t]!==0&&i.slots.set(e.subarray(t,t+3),fm(i,e[t]-1,e[t+1]))}return i.slots.set([t+1,n,r],fm(i,t,n)),r},S=(e,t,n)=>t.nodes.flatMap((t,r)=>re(e,n,r)??[]).sort((e,t)=>e-t),ae=(e,t,n,r)=>{let i=e.solution.actionChecks.length,a=e.results,o=a.length;if(a.length+=r.length+n.length*i,a.length>a.bytes.length){let e=new Uint8Array(Math.max(2*a.bytes.length,a.length));e.set(a.bytes),a.bytes=e}a.bytes.set(r,o),n.forEach((e,t)=>a.bytes.set(e,o+r.length+t*i)),e.offsets[t]=o;let s=e.pending[t]??[],c=e.edges,l=c.length;if(c.length+=s.length+1,c.length>c.ids.length){let e=new Int32Array(Math.max(2*c.ids.length,c.length));e.set(c.ids),c.ids=e}c.ids[l]=s.length,c.ids.set(s,l+1),e.edgeOffsets[t]=l,e.pending[t]=void 0},C=(e,t,n)=>{let r={slots:Array.from({length:16*p.multiplier}),count:0},i=(e,t)=>{for(let n=(a.getFingerprint(t.index)&2147483647)%e.length;;n=(n+1)%e.length){let r=e[n];if(r===void 0)return e[n]=t,!0;if(r.index===t.index&&lm(r.state,t.state))return!1}},o=e=>{if(r.count>=r.slots.length>>1){let e=r.slots;r.slots=Array.from({length:2*e.length+1});for(let t of e)t&&i(r.slots,t)}i(r.slots,e)&&r.count++};return n.forEach(o),o({index:e,state:t}),r.slots.length>16*p.multiplier&&p.multiplier++,r.slots.filter(e=>e!==void 0)},oe=(e,t,n,r,i)=>{let o=b(e,r,n),s=t.nodes[e.nodeTableaux[i]],c=[],l=mm(e,i),u=s.successors.length>0?x(e,r,n,n):/* @__PURE__ */ new Uint8Array;for(let a of s.successors){if(!ee(t,a,r,n))continue;if(te(t,a)&&e.errorNode===void 0&&ne(e)){e.errorNode=i;return}let o=re(e,r,a);if(o!==void 0&&l.includes(o))continue;let s=o??ie(e,r,a);l.push(s),c.push(u),o===void 0&&oe(e,t,n,r,s)}for(let i of a.getSuccessors(n)){let a=x(e,r,n,i.state),o=e.isDone[i.index]===!0;for(let n of s.successors){if(!ee(t,n,r,i.state))continue;let s=re(e,i.index,n);if(s!==void 0&&l.includes(s))continue;let u=s??ie(e,i.index,n);l.push(u),c.push(a),s===void 0&&o&&oe(e,t,i.state,i.index,u)}}l.length>0&&ae(e,i,c,o)},w=(e,t,n,r,i,a)=>{let o=t.nodes.map((e,r)=>n.map(e=>ee(t,r,a,e.state)));e.isDone[a]=!0;for(let s of S(e,t,a)){let a=mm(e,s),c=[];n.forEach((n,i)=>{let l=e.isDone[n.index]===!0;for(let u of t.nodes[e.nodeTableaux[s]].successors){if(!o[u][i])continue;let s=re(e,n.index,u);if(s!==void 0&&a.includes(s))continue;let d=s??ie(e,n.index,u);a.push(d),c.push(r[i]),s===void 0&&l&&oe(e,t,n.state,n.index,d)}}),ae(e,s,c,i)}if(e.errorNode!==void 0)return um(E(e,e.errorNode).reverse().map(t=>e.nodeStates[t]))},T=(e,t,n,r,i)=>{for(;e.nodeStates.length<=i;)dm(e,e.nodeStates.length,-1);let a=mm(e,i),o=[];t.forEach((t,r)=>{pm(e,t.index)&&a.includes(t.index)||(a.push(t.index),o.push(n[r]))}),ae(e,i,o,r)},E=(e,t)=>{if(e.initial.includes(t))return[t];let n=/* @__PURE__ */ new Map,r=[];for(let t of e.initial)pm(e,t)&&(r.push(t),n.set(t,-1));for(let i=0;i<r.length;i++){let a=r[i];for(let i of hm(e,a))if(!(i===a&&e.solution.tableau)){if(i===t){let e=[t];for(let t=a;t!==-1;t=n.get(t)??-1)e.push(t);return e}pm(e,i)&&!n.has(i)&&(n.set(i,a),r.push(i))}}throw new v(`Couldn't re-create liveness trace (path) starting at: ${t}`)},se=(e,t)=>{let n=e.solution,r=n.actionChecks.length,i=n.stateChecks.length,a=(t,n,a)=>e.results.bytes[e.offsets[t]+i+n*r+a]===1,o=(e,n)=>t.eventuallyAlways.every(t=>a(e,n,t)),s=new Float64Array(e.nodeStates.length).fill(-1),c=e.initial.filter(t=>pm(e,t)),l=[],u=t=>{let n=hm(e,t).indexOf(t);return n!==-1&&o(t,n)},d=(t,r)=>n.tableau!==void 0&&Gp(n.tableau.nodes[e.nodeTableaux[t]].particle,r),f=r=>{let i=l.pop()??r;if(i===r&&!u(i)){s[i]=_m;return}let c=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Map;for(let t=i;;t=l.pop()??r){c.add(t);let n=f.get(e.nodeStates[t]);if(n?n.push(t):f.set(e.nodeStates[t],[t]),s[t]=_m,t===r)break}let m=t.infinitelyOftenStates.every(t=>[...c].some(n=>gm(e,n,t))),h=t.infinitelyOftenActions.every(t=>[...c].some(n=>hm(e,n).some((e,r)=>c.has(e)&&o(n,r)&&a(n,r,t)))),g=n.promises.every(e=>[...c].some(t=>d(t,e)));if(m&&h&&g)return p(r,c,f)},p=(r,i,s)=>{let c=um(E(e,r).reverse().map(t=>e.nodeStates[t])),l=[],u=/* @__PURE__ */ new Set([r]),f=t.infinitelyOftenStates.map(()=>!1),p=t.infinitelyOftenActions.map(()=>!1),h=n.promises.map(()=>!1),g={count:f.length+p.length+h.length},_={node:r},y=e=>i.has(e),b=e=>{l.push(_.node),_.node=e};for(;g.count>0;){let r=g.count;for(;t.infinitelyOftenStates.forEach((t,n)=>{!f[n]&&gm(e,_.node,t)&&(f[n]=!0,g.count--)}),n.promises.forEach((e,t)=>{!h[t]&&d(_.node,e)&&(h[t]=!0,g.count--)}),!(g.count<=0);){let n={last:-1,unvisited:-1},i=g.count;if(hm(e,_.node).some((r,c)=>{if(s.has(e.nodeStates[r])){if(!y(r)||!o(_.node,c))return!1;n.last=r,t.infinitelyOftenActions.forEach((e,t)=>{!p[t]&&a(_.node,c,e)&&(p[t]=!0,g.count--)})}return g.count<i?(b(r),u.clear(),!0):(y(r)&&!u.has(r)&&(n.unvisited=r),!1)}))break;if(g.count<r){b(n.last),u.clear();break}for(;n.unvisited===-1;){let t=l.pop();if(t===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);_.node=t,n.unvisited=hm(e,t).find(e=>y(e)&&!u.has(e))??-1}b(n.unvisited),u.add(n.unvisited)}}let x=m(r,_.node,s,o);for(let t=l.length-1;t>=0;t--){let n=e.nodeStates[l[t]];x[x.length-1]!==n&&x.push(n)}let ee=c[c.length-1];return x[x.length-1]===ee&&x.pop(),{prefix:c.slice(0,-1),cycle:[ee,...x.reverse()]}},m=(t,n,r,i)=>{if(n===t)return[];let a=e.nodeStates[n],o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set([a]),c=[];for(let n=a,l=-1,u=0;;u++){for(let u of r.get(n)??[])for(let[d,f]of hm(e,u).entries()){if(f===u||!i(u,d))continue;if(f===t){let e=[];for(let t=n,r=l;t!==a;)e.push(t),t=r,r=o.get(t)??-1;return e.push(a),e}let p=e.nodeStates[f];r.has(p)&&!s.has(p)&&(s.add(p),c.push([p,n]))}o.set(n,l);let d=c[u];if(d===void 0)throw new v(`TLC failed to build the counterexample of a liveness property`);n=d[0],l=d[1]}};for(let t=0;t<c.length;t++){let n=[c[t],-1,0],r={link:0};for(;n.length>=3;){let t=n.pop()??0,i=n.pop(),a=n.pop()??0;if(i===-42){if(s[a]===t){let e=f(a);if(e)return e}n.push(Math.min(n.pop()??t,t));continue}if(s[a]!==-1){n.push(Math.min(t,s[a]));continue}s[a]=r.link,n.push(t,a,-42),l.push(a);let u={value:r.link++};hm(e,a).forEach((t,r)=>{pm(e,t)&&(o(a,r)?s[t]===-1?n.push(t,-1):u.value=Math.min(u.value,s[t]):s[t]===-1&&c.push(t))}),n.push(u.value)}}};return{addInitialState:(e,t)=>{h.states.clear(),h.actions.clear();for(let n of f){let r=n.solution.tableau;if(!r)n.initial.push(e);else for(let i=0;i<r.initialCount;i++)ee(r,i,void 0,t)&&n.initial.push(re(n,e,i)??ie(n,e,i))}},addState:(e,t,n)=>{h.states.clear(),h.actions.clear();let r=C(e,t,n);for(let n of f){let i=r.map(r=>x(n,e,t,r.state)),a=b(n,e,t),o=n.solution.tableau,s=o?w(n,o,r,i,a,e):T(n,r,i,a,e);if(s)return s}},findViolation:()=>{for(let e of f)for(let t of e.solution.models){let n=se(e,t);if(n)return n}},getViolatedProperties:(e,n)=>[...new Set(t.filter((t,r)=>!cm(s[r].body,e,n,0,i)).map(e=>e.name))]}},ym=`UnnamedAction`,bm={module:`--TLA+ BUILTINS--`,start:{line:0,column:0},end:{line:0,column:0}},xm=e=>{let t=e.range??bm;return Xt([[`beginLine`,t.start.line],[`beginColumn`,t.start.column],[`endLine`,t.end.line],[`endColumn`,t.end.column],[`module`,t.module]])},Sm=e=>{let t=[[`name`,e.name],[`location`,xm(e.location)]];return e.parameters.length===0?Xt(t):Xt([...t,[`context`,Xt(e.parameters)],[`parameters`,R(e.parameters.map(e=>e[0]))]])},Cm=(e,t)=>({name:e,location:t.location,parameters:[],expression:t,scope:void 0}),wm=(e,t)=>({environment:e,scope:t,state:void 0,next:void 0}),Tm=e=>e.kind===`Identifier`?e.name:e.kind===`Apply`?e.operator:void 0,Em=e=>e.kind===`Apply`?e.args:[],Dm=(e,t,n)=>{let r=Tm(e);if(r===void 0)return;if(W(e)){let e=Io(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=as(r,n);return i?.kind===`Closure`?i:void 0},Om=(e,t)=>{try{return X(e,wm(t,void 0)),!0}catch(e){if(e instanceof f)return!1;throw e}},km=(e,t)=>e?.kind===`Operator`&&e.params.length===0&&e.body.kind!==`Number`&&e.body.kind!==`String`&&Uo(e,t)&&Om(e.body,t),Am=(e,t)=>{let n=Vo(e.name,t);return n?.body===e.body&&km(n,t)},jm=(e,t)=>{if(e.kind!==`Identifier`||!W(e))return;let n=Io(t,e.name);return n?.kind===`Thunk`?n:void 0},Mm=(e,t)=>(e?.params??[]).flatMap(e=>{let n=Io(t,e.name);return n?.kind===`Value`?[[e.name,n.value]]:[]}),Nm=(e,t)=>{try{return e()}catch(e){if(e instanceof f)return t();throw e}},Pm=(e,t,n,r,i)=>{let a=Em(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():Nm(()=>[{...e,parameters:a.map((e,t)=>[r.params[t].name.replace(/#\d+$/,``),X(e,wm(i,n))]),expression:t,scope:n}],o)},Fm=(e,t,n,r,i)=>{let a=()=>({name:n?.name??ym,location:e.location,parameters:Mm(n,t),expression:e,scope:t});switch(e.kind){case`Let`:return Fm(e.body,xs(e.definitions,wm(r,t)),n,r,i);case`Label`:return Fm(e.body,t,n,r,i);case`Or`:return e.operands.flatMap(e=>Fm(e,t,n,r,i));case`Exists`:return Nm(()=>{let o=[];return Ko(e.bounds,wm(r,t),t=>(o.push(...Fm(e.body,t,n,r,i)),!1)),o.length===0?[a()]:o},()=>[a()])}let o=W(e)?void 0:i.get(Tm(e)??``),s=Dm(e,t,r);if(o)return Pm(o,e,t,s,r);if(!s)return[a()];let c=Em(e),l=()=>[{name:s.name,location:e.location,parameters:[],expression:e,scope:t}];return Am(s,r)||c.some(e=>$(e,t,r)!==0)?l():Nm(()=>{let e=c.reduce((e,n,i)=>({name:s.params[i].name,binding:{kind:`Value`,value:X(n,wm(r,t))},parent:e}),s.scope);return Fm(s.body,e,s,r,i)},l)},Im=(e,t,n,r,i)=>{let a=(e,t)=>Im(e,t,n,r,i);if(e.kind===`Let`){a(e.body,xs(e.definitions,wm(n,t)));return}let o=jm(e,t);if(o){a(o.expression,o.scope);return}let s=Dm(e,t,n);if(s&&Am(s,n))return;if(s&&s.params.length===0){if($(s.body,s.scope,n)===1){r.inits.push(Cm(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,ys(s,e.args,wm(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(Cm(ym,e));return}let c=$(e,t,n);c<=1?r.inits.push(Cm(ym,e)):c===3&&r.temporals.push(Cm(ym,e))},Lm=(e,t,n,r,i)=>{let a=(t,n)=>Lm(e,t,n,r,i);if(t.kind===`Let`){a(t.body,xs(t.definitions,wm(r,n)));return}let o=jm(t,n);if(o){a(o.expression,o.scope);return}let s=Dm(t,n,r);if(s&&Am(s,r))return;if(s&&s.params.length===Em(t).length){a(s.body,t.kind===`Apply`?ys(s,t.args,wm(r,n)):s.scope);return}if(t.kind===`Forall`&&Nm(()=>(Ko(t.bounds,wm(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(Cm(e,a)):$(a,n,r)<2?i.invariants.push(Cm(e,a)):i.impliedTemporals.push(Cm(e,t));return}let c=$(t,n,r);c<=1?i.impliedInits.push(Cm(e,t)):c===3&&i.impliedTemporals.push(Cm(e,t))},Rm=(e,t)=>{let n=Vo(e,t);return n?.kind===`Operator`&&!km(n,t)?n:void 0},zm=e=>Xt([[`name`,e.name],[`location`,xm(e.location)]]),Bm=(e,t,n)=>{let r={inits:[],actions:[],temporals:[],invariants:[],impliedInits:[],impliedActions:[],impliedTemporals:[]},i=[],a=e.specification===void 0?void 0:Rm(e.specification,t);a&&(Im(a.body,void 0,t,r,i),i.forEach(e=>r.actions.push(...Fm(e.expression,e.scope,void 0,t,n))));let o=e.init===void 0?void 0:as(e.init,t);o?.kind===`Closure`&&r.inits.push(Cm(e.init??``,o.body));let s=e.next===void 0?void 0:as(e.next,t);return s?.kind===`Closure`&&r.actions.push(...Fm(s.body,s.scope,s,t,n)),e.invariants.forEach(e=>{let n=Rm(e,t);n&&r.invariants.push(Cm(e,n.body))}),e.properties.forEach(e=>{let n=Rm(e,t);n&&Lm(e,n.body,void 0,t,r)}),r},Vm=(e,t,n)=>Bm(e,t,n).actions,Hm=e=>e.parameters.length===0?``:`(${e.parameters.map(e=>U(e[1])).join(`,`)})`,Um=e=>`${e.name===ym?`Action`:e.name}${Hm(e)} ${h(e.location.range??bm)}`,Wm=e=>`${e.name}${Hm(e)}`,Gm=(e,t,n,r)=>{let i=Bm(e,t,r),a=e=>Pt(e.map(Sm)),o=e=>Pt(e.flatMap(e=>{let n=Rm(e,t);return n?[zm(n)]:[]}));return Xt([[`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`,Pt(t.variables.map((e,t)=>Xt([[`name`,e],[`location`,xm(n[t])]])))],[`actionconstraints`,o(e.actionConstraints)],[`constraints`,o(e.constraints)]])},Km=`paired12`,qm=(e,t=16)=>e<=t*.75?t:qm(e,t*2),Jm=(e,t)=>{let n=qm(e.length)-1,r=e=>{let r=t(e);return(r^r>>>16)&n};return e.map((e,t)=>({key:e,position:t,bucket:r(e)})).sort((e,t)=>e.bucket-t.bucket||e.position-t.position).map(e=>e.key)},Ym=e=>Number(BigInt.asIntN(32,e^BigInt.asUintN(64,e)>>32n)),Xm=e=>[...Array(e.length).keys()].reduce((t,n)=>Math.imul(31,t)+e.charCodeAt(n)|0,0),Zm=e=>e.replaceAll(`\\`,`\\\\`).replaceAll(`"`,`\\"`).trim(),Qm=e=>Zm(e).replaceAll(`
419
419
  `,`\\n`),$m=(e,t)=>{let n=[],r=e=>n.push(`State ${n.length+1}:\n${e.getText()}\n`);return{writeInitialState:r,writeSuccessor:(e,t,n)=>{n||r(t)},close:()=>t?.(e.path,n.join(``))}},eh=(e,t)=>{let n=[`strict digraph DiskGraph {
420
420
  `,`node [shape=box,style=rounded]
421
421
  `,e.colorize?`edge [colorscheme="${Km}"]\n`:``,`nodesep=0.35;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.3-dev.367c92f",
3
+ "version": "0.0.3-dev.3ce2f00",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
@@ -974,6 +974,7 @@ export const createEnvironment = (
974
974
  ),
975
975
  ],
976
976
  assumptions: linked.module.assumptions.map((assumption) => assumption.expression),
977
+ theorems: linked.module.theorems,
977
978
  getDefinition: (symbol) => definitions.get(linked.visible.get(symbol)?.key ?? symbol),
978
979
  };
979
980
  });
package/src/levels.ts CHANGED
@@ -842,22 +842,33 @@ export const createLevelAnalyzer = (context: LevelContext) => {
842
842
  return { analyze, analyzeDefinition, toOperand };
843
843
  };
844
844
 
845
- const analyzeAssumeProve = (
845
+ export const analyzeAssumeProve = (
846
846
  assumeProve: AssumeProve,
847
847
  scope: Scope,
848
848
  analyzer: ReturnType<typeof createLevelAnalyzer>,
849
- ) => {
849
+ ): LevelData => {
850
850
  const inner = new Map(scope);
851
- assumeProve.assumptions.forEach((assumption) => {
851
+ const parts = assumeProve.assumptions.flatMap((assumption) => {
852
852
  if (assumption.kind === "NewSymbol") {
853
- if (assumption.set) analyzer.analyze(assumption.set, inner);
853
+ const set = assumption.set && analyzer.analyze(assumption.set, inner);
854
854
  inner.set(assumption.name, { kind: "Formal", arity: assumption.arity });
855
- return;
855
+ return set ? [set] : [];
856
856
  }
857
- if (assumption.kind === "AssumeProve") analyzeAssumeProve(assumption, inner, analyzer);
858
- else analyzer.analyze(assumption, inner);
857
+ return [
858
+ assumption.kind === "AssumeProve"
859
+ ? analyzeAssumeProve(assumption, inner, analyzer)
860
+ : analyzer.analyze(assumption, inner),
861
+ ];
862
+ });
863
+ parts.push(analyzer.analyze(assumeProve.conclusion, inner));
864
+ const data = createData(Math.max(...parts.map((part) => part.level)));
865
+ parts.forEach((part) => {
866
+ part.params.forEach((param) => data.params.add(param));
867
+ part.constraints.forEach((value, key) => putConstraint(data.constraints, key, value));
868
+ part.argConstraints.forEach((value, key) => putArgConstraint(data.argConstraints, key, value));
869
+ part.argParams.forEach((key) => data.argParams.add(key));
859
870
  });
860
- analyzer.analyze(assumeProve.conclusion, inner);
871
+ return data;
861
872
  };
862
873
 
863
874
  // SANY checks the level of every definition, assumption, and theorem of a module.
@@ -1,6 +1,8 @@
1
- import type { Declaration, Definition, Expression, SourceLocation } from "./ast";
1
+ import type { Declaration, Definition, Expression, SourceLocation, Theorem } from "./ast";
2
2
  import { createSanyError, formatRange } from "./errors";
3
3
  import {
4
+ ACTION_LEVEL,
5
+ analyzeAssumeProve,
4
6
  createLevelAnalyzer,
5
7
  getArgumentKey,
6
8
  MAX_LEVEL,
@@ -24,6 +26,7 @@ interface ModuleContext {
24
26
  variables: string[];
25
27
  definitions: Definition[];
26
28
  assumptions: Expression[];
29
+ theorems: Theorem[];
27
30
  getDefinition: (name: string) => Definition | undefined;
28
31
  }
29
32
 
@@ -101,8 +104,21 @@ export const checkInstances = (
101
104
  definition.formals.every((formal) => formal.name !== operator && formal.name !== param),
102
105
  ),
103
106
  );
107
+ const addAssumedLevels = (data: ReturnType<typeof analyzeAssumeProve>) => {
108
+ addLevels(data, () => true);
109
+ module.constants.forEach((constant) => {
110
+ if (data.params.has(constant.name)) {
111
+ putConstraint(levels.constraints, constant.name, ACTION_LEVEL);
112
+ }
113
+ });
114
+ };
104
115
  module.assumptions.forEach((assumption) =>
105
- addLevels(analyzer.analyze(assumption, new Map()), () => true),
116
+ addAssumedLevels(analyzer.analyze(assumption, new Map())),
117
+ );
118
+ module.theorems.forEach((theorem) =>
119
+ theorem.statement.kind === "AssumeProve"
120
+ ? addAssumedLevels(analyzeAssumeProve(theorem.statement, new Map(), analyzer))
121
+ : addLevels(analyzer.analyze(theorem.statement, new Map()), () => true),
106
122
  );
107
123
  moduleLevels.set(name, levels);
108
124
  return levels;