tla-ts 0.0.4-dev.a0009b7 → 0.0.4-dev.e4c2d0e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -571,6 +571,7 @@ interface SetValue {
571
571
  elements: Value[];
572
572
  hash: number;
573
573
  fingerprint: number;
574
+ isFingerprinted: boolean;
574
575
  }
575
576
  interface MixedSetValue {
576
577
  kind: "MixedSet";
@@ -584,6 +585,7 @@ interface FunctionValue {
584
585
  fingerprint: number;
585
586
  writtenKeys: Value[] | undefined;
586
587
  functionClass: FunctionClass | undefined;
588
+ isFingerprinted: boolean;
587
589
  }
588
590
  interface IntervalValue {
589
591
  kind: "Interval";
package/dist/index.d.ts CHANGED
@@ -571,6 +571,7 @@ interface SetValue {
571
571
  elements: Value[];
572
572
  hash: number;
573
573
  fingerprint: number;
574
+ isFingerprinted: boolean;
574
575
  }
575
576
  interface MixedSetValue {
576
577
  kind: "MixedSet";
@@ -584,6 +585,7 @@ interface FunctionValue {
584
585
  fingerprint: number;
585
586
  writtenKeys: Value[] | undefined;
586
587
  functionClass: FunctionClass | undefined;
588
+ isFingerprinted: boolean;
587
589
  }
588
590
  interface IntervalValue {
589
591
  kind: "Interval";
package/dist/run-cli.cjs CHANGED
@@ -6,7 +6,7 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- const e=require("./transfer.cjs"),t=require("./parallel.cjs");let n=require("node:path"),r=require("node:fs"),i=require("node:child_process"),a=require("node:crypto"),o=require("node:os"),s=require("node:url"),c=require("node:v8"),l=require("fflate");var u=`0.0.4-dev.a0009b7`;const d=e=>{let t=e.isRequired?e.flag:`[${e.flag}]`;return e.isRepeatable?`${t}...`:t},f=(e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,e.getArity??(()=>n.length)]}));return{usage:e.replace(`{options}`,t.map(d).join(` `)),parse:e=>{let t=[],r=[],i=[],a=[];for(let o=0;o<e.length;o++){let s=n.get(e[o]);if(s===void 0){(e[o].startsWith(`-`)?i:r).push(e[o]);continue}let c=s(e.slice(o+1)),l={name:e[o],values:e.slice(o+1,o+1+c)};t.push(l),l.values.length<c&&a.push(l),o+=c}return{options:t,positionals:r,unknown:i,incomplete:a[0],has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}},p=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},m=e=>`File ${JSON.stringify(e.file)}, ${p(e)}`,h=e=>`${e?m(e):`<unknown location>`}:\n`,g=(e,t)=>({text:`${h(e)}Error: ${t}`,channel:`stderr`}),_=e=>e?`${m(e)} :\n`:``,v=e=>({kind:`Shift`,amount:e}),y=(e,t)=>({kind:`Cons`,expression:e,rest:t}),b=(e,t)=>e.reduce((e,t)=>y(t,e),t),x=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},S=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},C=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},w=(e,t,n)=>S({kind:`Apply`,operator:S({kind:`Internal`,builtin:e},n),args:t},n),T=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},E=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),ee=(e,t)=>t.reduce(E,e),D=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},te=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(C(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},ne=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},O=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},k=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),re=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),ie=(e,t,n)=>{switch(e.kind){case`Shift`:return S({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?S(M(e.expression),n):ie(e.rest,t-1,n);case`Compose`:return P(e.outer,ie(e.inner,t,n));case`Bump`:return t<=e.amount?S({kind:`Ix`,index:t},n):P(v(e.amount),ie(e.rest,t-e.amount,n))}},A=(e,t)=>t.map(t=>P(e,t)),j=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e.ut(`Arity mismatch`);return M(P(b(n,v(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?M(t):{kind:`Apply`,operator:t,args:n}},M=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},N=(e,t)=>[x(t.length,e),me(t,t=>P(e,t))],ae=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return _e(t,t=>P(e,t));case`Instance`:{let n=x(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:P(n,e.expression)}))}}}}},oe=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:P(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ae(e,t.definition)};case`Fact`:return{...t,expression:P(e,t.expression)}}},se=(e,t)=>{let[n,r]=O(e,t.context,(e,t)=>[x(1,e),oe(e,t)]);return{context:r,active:P(n,t.active)}},P=(e,t)=>{let n=t=>P(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return ie(e,t.index,t);case`Apply`:return S(j(n(t.operator),A(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>he(e,n))};case`Lambda`:return{...t,body:P(x(t.params.length,e),t.body)};case`Let`:{let[n,r]=O(e,t.definitions,(e,t)=>[x(1,e),ae(e,t)]);return{...t,definitions:r,body:P(n,t.body)}}case`Sequent`:return{...t,sequent:se(e,t.sequent)};case`With`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:A(e,t.items)};case`Quant`:{let[n,r]=N(e,t.bounds);return{...t,bounds:r,body:P(n,t.body)}}case`Tquant`:return{...t,body:P(x(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:P(x(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:P(x(1,e),t.body)};case`SetOf`:{let[n,r]=N(e,t.bounds);return{...t,bounds:r,element:P(n,t.element)}}case`SetEnum`:return{...t,elements:A(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`Fcn`:{let[n,r]=N(e,t.bounds);return{...t,bounds:r,body:P(n,t.body)}}case`FcnApp`:return{...t,function:n(t.function),args:A(e,t.args)};case`Product`:return{...t,factors:A(e,t.factors)};case`Tuple`:return{...t,elements:A(e,t.elements)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:ge(t.specs,n)};case`Dot`:return{...t,expression:n(t.expression)};case`Sub`:case`Tsub`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Fair`:return{...t,subscript:n(t.subscript),action:n(t.action)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)};case`Parens`:return{...t,expression:n(t.expression)}}},F=(e,t)=>e===0?t:P(v(e),t),I=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),ce=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!L(t,n))return!1}return!0},le=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&L(e.domain.expression,t.domain.expression)),ue=(e,t)=>{if(e.kind!==t.kind)return!1;switch(e.kind){case`Number`:return t.kind===`Number`&&e.value===t.value;case`Instance`:return t.kind===`Instance`&&I(e.args,t.args,L);case`Label`:return t.kind===`Label`&&e.label===t.label&&I(e.args,t.args,L);default:return!0}},de=(e,t)=>{if(e.kind===`Operator`&&t.kind===`Operator`||e.kind===`Bpragma`&&t.kind===`Bpragma`)return L(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return I(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&ce(n,r)}return!1},fe=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level!==t.level||e.shape!==t.shape?!1:!e.domain||!t.domain?!e.domain&&!t.domain:L(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?de(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&L(e.expression,t.expression),pe=(e,t)=>I(e.context,t.context,fe)&&L(e.active,t.active),L=(e,t)=>{if(e.kind===`Parens`)return L(e.expression,t);if(t.kind===`Parens`)return L(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&L(e.body,t.body);case`Apply`:return t.kind===`Apply`&&L(e.operator,t.operator)&&I(e.args,t.args,L);case`Sequent`:return t.kind===`Sequent`&&pe(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&L(e.expression,t.expression)&&I(e.selectors,t.selectors,ue);case`With`:return t.kind===`With`&&L(e.expression,t.expression);case`Let`:return t.kind===`Let`&&I(e.definitions,t.definitions,de)&&L(e.body,t.body);case`If`:return t.kind===`If`&&L(e.condition,t.condition)&&L(e.consequent,t.consequent)&&L(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&I(e.items,t.items,L);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&I(e.bounds,t.bounds,le)&&L(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&I(e.names,t.names,(e,t)=>e===t)&&L(e.body,t.body);case`Choose`:return t.kind===`Choose`?e.domain&&t.domain?L(e.domain,t.domain)&&L(e.body,t.body):!e.domain&&!t.domain&&L(e.body,t.body):!1;case`SetSt`:return t.kind===`SetSt`&&L(e.domain,t.domain)&&L(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&L(e.element,t.element)&&I(e.bounds,t.bounds,le);case`SetEnum`:return t.kind===`SetEnum`&&I(e.elements,t.elements,L);case`Arrow`:return t.kind===`Arrow`&&L(e.domain,t.domain)&&L(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&I(e.bounds,t.bounds,le)&&L(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&I([e.function,...e.args],[t.function,...t.args],L);case`Tuple`:return t.kind===`Tuple`&&I(e.elements,t.elements,L);case`Product`:return t.kind===`Product`&&I(e.factors,t.factors,L);case`Rect`:return t.kind===`Rect`&&ce(e.fields,t.fields);case`Record`:return t.kind===`Record`&&ce(e.fields,t.fields);case`Except`:return t.kind===`Except`&&L(e.function,t.function)&&I(e.specs,t.specs,(e,t)=>I(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&L(e.expression,t.expression))&&L(e.value,t.value));case`Dot`:return t.kind===`Dot`&&L(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&L(e.action,t.action)&&L(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&L(e.subscript,t.subscript)&&L(e.action,t.action);case`Case`:return t.kind!==`Case`||!(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:L(e.arms[0].condition,t.arms[0].condition)&&L(e.arms[0].body,t.arms[0].body))?!1:e.other&&t.other?L(e.other,t.other):!e.other&&!t.other;case`String`:return t.kind===`String`&&e.value===t.value;case`Num`:return t.kind===`Num`&&e.integer===t.integer&&e.fraction===t.fraction;case`At`:return t.kind===`At`&&e.isExcept===t.isExcept}},me=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),he=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,ge=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),_e=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,ve=(e,t,n)=>e.kind===`Fresh`?e.domain?{...e,domain:t(e.domain)}:e:e.kind===`Flex`||n===`visible`&&e.visibility===`Hidden`?e:e.kind===`Defn`?{...e,definition:_e(e.definition,t)}:{...e,expression:t(e.expression)},ye=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,k(t.name,t.level)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=k(t.name,`Unknown`,t.shape);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=O(e,t.sequent.context,(e,t)=>{let a=ve(t,t=>n(e,t),i);return[r(e,a),a]});return{...t,sequent:{context:o,active:n(a,t.sequent.active)}}}case`Let`:{let[i,a]=O(e,t.definitions,(e,t)=>{let i=_e(t,t=>n(e,t));return[r(e,{kind:`Defn`,definition:i,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=me(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=me(t.bounds,a);return{...t,bounds:e,element:n(o(e),t.element)}}case`Tquant`:{let i=t.names.reduce((e,t)=>r(e,{kind:`Flex`,name:t}),e);return{...t,body:n(i,t.body)}}case`Choose`:{let i=t.domain&&a(t.domain),o=i?re(t.name,i):k(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=re(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>he(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=ge(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},be=(e,t)=>ye(void 0,e,(e,n)=>t(n),()=>void 0,`all`),xe=e=>{let t=[];return be(e,e=>(t.push(e),e)),t},Se={kind:`Opaque`,name:`$Bad`},Ce=e=>e.kind===`Opaque`&&e.name===Se.name,we=e=>{let t=e.kind===`Parens`?we(e.expression):be(e,we);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Te=e=>e.kind===`Let`?S({kind:`Let`,definitions:e.definitions,body:Te(e.body)},e.body):e.kind===`Parens`?Te(e.expression):be(e,Te),Ee=e=>e.kind===`Ix`?e.index<=0:xe(e).some(Ee),De=(e,t,n)=>{let r=(e,r=n)=>De(e,t,r),i=(e,t)=>e.reduce((e,t)=>e??(t.domain.kind===`Domain`?r(t.domain.expression):void 0),void 0)??r(t,[...n,...e.map(e=>k(e.name,e.level))]);switch(e.kind){case`Parens`:return e.form.kind===`Xlabel`?e.form.label===t?{context:n,expression:e.expression,indices:e.form.indices}:void 0:r(e.expression);case`Lambda`:return r(e.body,[...n,...e.params.map(e=>k(e.name,`Unknown`,e.shape))]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,k(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of xe(e)){let e=r(t);if(e)return e}return}},Oe=(e,t)=>b(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),v(e+t)),R=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),ke=(t,n,r)=>{switch(n.kind){case`Quant`:case`Fcn`:case`SetOf`:{if(n.bounds.length!==r.length){let i=n.bounds.length,a=`Arity mismatch in subexpression instance.\nExpected ${i} argument${i===1?``:`s`}, but found${r.length<i?` only`:``} ${r.length}.`;throw t(g(n.location,a)),new e.ut(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return P(b(r,v(0)),i)}case`Tquant`:return ke(t,S({kind:`Quant`,quantifier:n.quantifier,bounds:n.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`Lambda`:return ke(t,S({kind:`Quant`,quantifier:`Forall`,bounds:n.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`SetSt`:case`Choose`:if(r.length!==1){let i=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${r.length}.`;throw t(g(n.location,i)),new e.ut(i,{failure:`Expr.Deref.deref_inst`})}return P(b(r,v(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(g(n.location,r)),new e.ut(r,{failure:`Expr.Deref.deref_inst`})}}},Ae=(t,n,r)=>{let i=(()=>{switch(r.kind){case`Quant`:case`Fcn`:case`SetOf`:return r.bounds.map(e=>({name:e.name,shape:0}));case`Tquant`:return r.names.map(e=>({name:e,shape:0}));case`Lambda`:return r.params;case`SetSt`:case`Choose`:return[{name:r.name,shape:0}];default:{let n=`Cannot abstract over bound variables in a non-binding expression`;throw t(g(r.location,n)),new e.ut(n,{failure:`Expr.Deref.deref_at`})}}})(),a=P(Oe(n,i.length),r);return[i,ke(t,a,R(i.length))]},je=(t,n,r,i,a,o)=>{let s=n=>{if(!(i<=n))throw t(g(a.location,o)),new e.ut(o,{failure:`Expr.Deref.deref_num`})},c=e=>(s(e.length),e[i-1]),l=(()=>{switch(r.kind){case`Sequent`:{let a=r.sequent;s(a.context.length+1);let o=a.context[i-1];if(o&&o.kind!==`Fact`){let n=`subexpression reference does not resolve to an expression`;throw t(g(r.location,n)),new e.ut(n,{failure:`Expr.Deref.deref_num`})}let c=P(v(-(i-1)),o?o.expression:a.active);if(Ee(c))throw t(g(r.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
9
+ const e=require("./transfer.cjs"),t=require("./parallel.cjs");let n=require("node:path"),r=require("node:fs"),i=require("node:child_process"),a=require("node:crypto"),o=require("node:os"),s=require("node:url"),c=require("node:v8"),l=require("fflate");var u=`0.0.4-dev.e4c2d0e`;const d=e=>{let t=e.isRequired?e.flag:`[${e.flag}]`;return e.isRepeatable?`${t}...`:t},f=(e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,e.getArity??(()=>n.length)]}));return{usage:e.replace(`{options}`,t.map(d).join(` `)),parse:e=>{let t=[],r=[],i=[],a=[];for(let o=0;o<e.length;o++){let s=n.get(e[o]);if(s===void 0){(e[o].startsWith(`-`)?i:r).push(e[o]);continue}let c=s(e.slice(o+1)),l={name:e[o],values:e.slice(o+1,o+1+c)};t.push(l),l.values.length<c&&a.push(l),o+=c}return{options:t,positionals:r,unknown:i,incomplete:a[0],has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}},p=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},m=e=>`File ${JSON.stringify(e.file)}, ${p(e)}`,h=e=>`${e?m(e):`<unknown location>`}:\n`,g=(e,t)=>({text:`${h(e)}Error: ${t}`,channel:`stderr`}),_=e=>e?`${m(e)} :\n`:``,v=e=>({kind:`Shift`,amount:e}),y=(e,t)=>({kind:`Cons`,expression:e,rest:t}),b=(e,t)=>e.reduce((e,t)=>y(t,e),t),x=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},S=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},C=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},w=(e,t,n)=>S({kind:`Apply`,operator:S({kind:`Internal`,builtin:e},n),args:t},n),T=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},E=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),ee=(e,t)=>t.reduce(E,e),D=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},te=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(C(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},ne=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},O=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},k=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),re=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),ie=(e,t,n)=>{switch(e.kind){case`Shift`:return S({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?S(M(e.expression),n):ie(e.rest,t-1,n);case`Compose`:return P(e.outer,ie(e.inner,t,n));case`Bump`:return t<=e.amount?S({kind:`Ix`,index:t},n):P(v(e.amount),ie(e.rest,t-e.amount,n))}},A=(e,t)=>t.map(t=>P(e,t)),j=(t,n)=>{if(t.kind===`Lambda`){if(t.params.length!==n.length)throw new e.ut(`Arity mismatch`);return M(P(b(n,v(0)),t.body))}return t.kind===`Apply`?{kind:`Apply`,operator:t.operator,args:[...t.args,...n]}:n.length===0?M(t):{kind:`Apply`,operator:t,args:n}},M=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},N=(e,t)=>[x(t.length,e),me(t,t=>P(e,t))],ae=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return _e(t,t=>P(e,t));case`Instance`:{let n=x(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:P(n,e.expression)}))}}}}},oe=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:P(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ae(e,t.definition)};case`Fact`:return{...t,expression:P(e,t.expression)}}},se=(e,t)=>{let[n,r]=O(e,t.context,(e,t)=>[x(1,e),oe(e,t)]);return{context:r,active:P(n,t.active)}},P=(e,t)=>{let n=t=>P(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return ie(e,t.index,t);case`Apply`:return S(j(n(t.operator),A(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>he(e,n))};case`Lambda`:return{...t,body:P(x(t.params.length,e),t.body)};case`Let`:{let[n,r]=O(e,t.definitions,(e,t)=>[x(1,e),ae(e,t)]);return{...t,definitions:r,body:P(n,t.body)}}case`Sequent`:return{...t,sequent:se(e,t.sequent)};case`With`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:A(e,t.items)};case`Quant`:{let[n,r]=N(e,t.bounds);return{...t,bounds:r,body:P(n,t.body)}}case`Tquant`:return{...t,body:P(x(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:P(x(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:P(x(1,e),t.body)};case`SetOf`:{let[n,r]=N(e,t.bounds);return{...t,bounds:r,element:P(n,t.element)}}case`SetEnum`:return{...t,elements:A(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`Fcn`:{let[n,r]=N(e,t.bounds);return{...t,bounds:r,body:P(n,t.body)}}case`FcnApp`:return{...t,function:n(t.function),args:A(e,t.args)};case`Product`:return{...t,factors:A(e,t.factors)};case`Tuple`:return{...t,elements:A(e,t.elements)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:ge(t.specs,n)};case`Dot`:return{...t,expression:n(t.expression)};case`Sub`:case`Tsub`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Fair`:return{...t,subscript:n(t.subscript),action:n(t.action)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)};case`Parens`:return{...t,expression:n(t.expression)}}},F=(e,t)=>e===0?t:P(v(e),t),I=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),ce=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!L(t,n))return!1}return!0},le=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&L(e.domain.expression,t.domain.expression)),ue=(e,t)=>{if(e.kind!==t.kind)return!1;switch(e.kind){case`Number`:return t.kind===`Number`&&e.value===t.value;case`Instance`:return t.kind===`Instance`&&I(e.args,t.args,L);case`Label`:return t.kind===`Label`&&e.label===t.label&&I(e.args,t.args,L);default:return!0}},de=(e,t)=>{if(e.kind===`Operator`&&t.kind===`Operator`||e.kind===`Bpragma`&&t.kind===`Bpragma`)return L(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return I(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&ce(n,r)}return!1},fe=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level!==t.level||e.shape!==t.shape?!1:!e.domain||!t.domain?!e.domain&&!t.domain:L(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?de(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&L(e.expression,t.expression),pe=(e,t)=>I(e.context,t.context,fe)&&L(e.active,t.active),L=(e,t)=>{if(e.kind===`Parens`)return L(e.expression,t);if(t.kind===`Parens`)return L(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&L(e.body,t.body);case`Apply`:return t.kind===`Apply`&&L(e.operator,t.operator)&&I(e.args,t.args,L);case`Sequent`:return t.kind===`Sequent`&&pe(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&L(e.expression,t.expression)&&I(e.selectors,t.selectors,ue);case`With`:return t.kind===`With`&&L(e.expression,t.expression);case`Let`:return t.kind===`Let`&&I(e.definitions,t.definitions,de)&&L(e.body,t.body);case`If`:return t.kind===`If`&&L(e.condition,t.condition)&&L(e.consequent,t.consequent)&&L(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&I(e.items,t.items,L);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&I(e.bounds,t.bounds,le)&&L(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&I(e.names,t.names,(e,t)=>e===t)&&L(e.body,t.body);case`Choose`:return t.kind===`Choose`?e.domain&&t.domain?L(e.domain,t.domain)&&L(e.body,t.body):!e.domain&&!t.domain&&L(e.body,t.body):!1;case`SetSt`:return t.kind===`SetSt`&&L(e.domain,t.domain)&&L(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&L(e.element,t.element)&&I(e.bounds,t.bounds,le);case`SetEnum`:return t.kind===`SetEnum`&&I(e.elements,t.elements,L);case`Arrow`:return t.kind===`Arrow`&&L(e.domain,t.domain)&&L(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&I(e.bounds,t.bounds,le)&&L(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&I([e.function,...e.args],[t.function,...t.args],L);case`Tuple`:return t.kind===`Tuple`&&I(e.elements,t.elements,L);case`Product`:return t.kind===`Product`&&I(e.factors,t.factors,L);case`Rect`:return t.kind===`Rect`&&ce(e.fields,t.fields);case`Record`:return t.kind===`Record`&&ce(e.fields,t.fields);case`Except`:return t.kind===`Except`&&L(e.function,t.function)&&I(e.specs,t.specs,(e,t)=>I(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&L(e.expression,t.expression))&&L(e.value,t.value));case`Dot`:return t.kind===`Dot`&&L(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&L(e.action,t.action)&&L(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&L(e.subscript,t.subscript)&&L(e.action,t.action);case`Case`:return t.kind!==`Case`||!(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:L(e.arms[0].condition,t.arms[0].condition)&&L(e.arms[0].body,t.arms[0].body))?!1:e.other&&t.other?L(e.other,t.other):!e.other&&!t.other;case`String`:return t.kind===`String`&&e.value===t.value;case`Num`:return t.kind===`Num`&&e.integer===t.integer&&e.fraction===t.fraction;case`At`:return t.kind===`At`&&e.isExcept===t.isExcept}},me=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),he=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,ge=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),_e=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,ve=(e,t,n)=>e.kind===`Fresh`?e.domain?{...e,domain:t(e.domain)}:e:e.kind===`Flex`||n===`visible`&&e.visibility===`Hidden`?e:e.kind===`Defn`?{...e,definition:_e(e.definition,t)}:{...e,expression:t(e.expression)},ye=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,k(t.name,t.level)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=k(t.name,`Unknown`,t.shape);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=O(e,t.sequent.context,(e,t)=>{let a=ve(t,t=>n(e,t),i);return[r(e,a),a]});return{...t,sequent:{context:o,active:n(a,t.sequent.active)}}}case`Let`:{let[i,a]=O(e,t.definitions,(e,t)=>{let i=_e(t,t=>n(e,t));return[r(e,{kind:`Defn`,definition:i,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=me(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=me(t.bounds,a);return{...t,bounds:e,element:n(o(e),t.element)}}case`Tquant`:{let i=t.names.reduce((e,t)=>r(e,{kind:`Flex`,name:t}),e);return{...t,body:n(i,t.body)}}case`Choose`:{let i=t.domain&&a(t.domain),o=i?re(t.name,i):k(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=re(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>he(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=ge(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},be=(e,t)=>ye(void 0,e,(e,n)=>t(n),()=>void 0,`all`),xe=e=>{let t=[];return be(e,e=>(t.push(e),e)),t},Se={kind:`Opaque`,name:`$Bad`},Ce=e=>e.kind===`Opaque`&&e.name===Se.name,we=e=>{let t=e.kind===`Parens`?we(e.expression):be(e,we);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},Te=e=>e.kind===`Let`?S({kind:`Let`,definitions:e.definitions,body:Te(e.body)},e.body):e.kind===`Parens`?Te(e.expression):be(e,Te),Ee=e=>e.kind===`Ix`?e.index<=0:xe(e).some(Ee),De=(e,t,n)=>{let r=(e,r=n)=>De(e,t,r),i=(e,t)=>e.reduce((e,t)=>e??(t.domain.kind===`Domain`?r(t.domain.expression):void 0),void 0)??r(t,[...n,...e.map(e=>k(e.name,e.level))]);switch(e.kind){case`Parens`:return e.form.kind===`Xlabel`?e.form.label===t?{context:n,expression:e.expression,indices:e.form.indices}:void 0:r(e.expression);case`Lambda`:return r(e.body,[...n,...e.params.map(e=>k(e.name,`Unknown`,e.shape))]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,k(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of xe(e)){let e=r(t);if(e)return e}return}},Oe=(e,t)=>b(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),v(e+t)),R=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),ke=(t,n,r)=>{switch(n.kind){case`Quant`:case`Fcn`:case`SetOf`:{if(n.bounds.length!==r.length){let i=n.bounds.length,a=`Arity mismatch in subexpression instance.\nExpected ${i} argument${i===1?``:`s`}, but found${r.length<i?` only`:``} ${r.length}.`;throw t(g(n.location,a)),new e.ut(a,{failure:`Expr.Deref.deref_inst`})}let i=n.kind===`SetOf`?n.element:n.body;return P(b(r,v(0)),i)}case`Tquant`:return ke(t,S({kind:`Quant`,quantifier:n.quantifier,bounds:n.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`Lambda`:return ke(t,S({kind:`Quant`,quantifier:`Forall`,bounds:n.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:n.body},n),r);case`SetSt`:case`Choose`:if(r.length!==1){let i=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${r.length}.`;throw t(g(n.location,i)),new e.ut(i,{failure:`Expr.Deref.deref_inst`})}return P(b(r,v(0)),n.body);default:{let r=`Cannot instantiate non-binding expression`;throw t(g(n.location,r)),new e.ut(r,{failure:`Expr.Deref.deref_inst`})}}},Ae=(t,n,r)=>{let i=(()=>{switch(r.kind){case`Quant`:case`Fcn`:case`SetOf`:return r.bounds.map(e=>({name:e.name,shape:0}));case`Tquant`:return r.names.map(e=>({name:e,shape:0}));case`Lambda`:return r.params;case`SetSt`:case`Choose`:return[{name:r.name,shape:0}];default:{let n=`Cannot abstract over bound variables in a non-binding expression`;throw t(g(r.location,n)),new e.ut(n,{failure:`Expr.Deref.deref_at`})}}})(),a=P(Oe(n,i.length),r);return[i,ke(t,a,R(i.length))]},je=(t,n,r,i,a,o)=>{let s=n=>{if(!(i<=n))throw t(g(a.location,o)),new e.ut(o,{failure:`Expr.Deref.deref_num`})},c=e=>(s(e.length),e[i-1]),l=(()=>{switch(r.kind){case`Sequent`:{let a=r.sequent;s(a.context.length+1);let o=a.context[i-1];if(o&&o.kind!==`Fact`){let n=`subexpression reference does not resolve to an expression`;throw t(g(r.location,n)),new e.ut(n,{failure:`Expr.Deref.deref_num`})}let c=P(v(-(i-1)),o?o.expression:a.active);if(Ee(c))throw t(g(r.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
10
10
  Tlapm does not handle yet such subexpression namings.`)),new e.ut(`Subexpression of ASSUME/PROVE uses identifiers declared therein
11
11
 
12
12
  Tlapm does not handle yet such subexpression namings.`,{failure:`Expr.Deref.deref_num`});return[n,c]}case`Apply`:return[n,c(r.args)];case`With`:return je(t,n,r.expression,i,a,o);case`If`:return[n,c([r.condition,r.consequent,r.alternative])];case`List`:return[n,c(r.items)];case`SetEnum`:case`Tuple`:return[n,c(r.elements)];case`Product`:return[n,c(r.factors)];case`Let`:return s(1),[[...n,...r.definitions],r.body];case`Quant`:case`SetOf`:case`Fcn`:return[n,c(r.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]))];case`Choose`:case`SetSt`:if(!r.domain)break;return[n,c([r.domain])];case`Arrow`:return[n,c([r.domain,r.range])];case`FcnApp`:{let e=r.args.length===1?r.args[0]:S({kind:`Tuple`,elements:r.args},r);return[n,c([r.function,e])]}case`Rect`:case`Record`:return[n,c(r.fields.map(e=>e.value))];case`Dot`:return[n,c([r.expression,S({kind:`String`,value:r.field},r)])];case`Except`:return[n,c([r.function,...r.specs.map(e=>e.value)])];case`Sub`:case`Tsub`:return[n,c([r.action,r.subscript])];case`Fair`:return[n,c([r.subscript,r.action])];case`Case`:return[n,c([...r.arms.map(e=>S({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...r.other?[S({kind:`Tuple`,elements:[Se,r.other]},r.other)]:[]])]}let l=`Expression has no subexpressions`;throw t(g(r.location,l)),new e.ut(l,{failure:`Expr.Deref.deref_num`})})();if(Ce(l[1])){let n=`Cannot resolve subexpression reference !${i}`;throw t(g(r.location,n)),new e.ut(n,{failure:`Expr.Deref.deref_num`})}return l},Me=(e,t)=>{let n=e.length,r=e;for(let e=n-1;e>=0;e--)r.includes(n-e)||(r=r.map(t=>t+e<n?t:t-1));return r.map(e=>t[n-e])},Ne=(t,n,r,i,a)=>{let o=De(r,i,[]);if(!o)return t(g(r.location,`Could not find label ${i}`)),{params:[],definitions:[],expression:Se};let s=o.indices;if(s.length!==a.length&&a.length>0){let n=s.length===1?``:`s`,r=`Expected ${s.length} argument${n} for labelled reference !${i}, but found ${a.length}`;throw t(g(o.expression.location,r)),new e.ut(r,{failure:`Expr.Deref.deref_lsub`})}let c=a.length===0?s.map(e=>({name:e.name,shape:0})):[],l=a.length===0?R(s.length):a,u=o.context.reduceRight((e,t)=>t.kind===`Defn`?S({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?S({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):P(v(-1),e),o.expression),d=P(Oe(n,c.length),u),f=[],p=d,m=Me(s.map(e=>e.index),l);for(;m.length>0;)if(p.kind===`Let`&&p.definitions.length===1)f.push(p.definitions[0]),p=p.body,m=m.map(e=>P(v(1),e));else{if(p.kind!==`Quant`||p.bounds.length!==1)throw new e.mt(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);p=P(y(m[0],v(0)),p.body),m=m.slice(1)}return{params:c,definitions:f,expression:p}},Pe=(t,n,r,i,a)=>{if(r.kind!==`Let`)throw t(g(r.location,`not a LET expression`)),new e.ut(`not a LET expression`,{failure:`Expr.Deref.deref_letop`});let o=r.definitions.findIndex(e=>e.kind===`Operator`&&e.name===i),s=r.definitions[o];if(!s||s.kind!==`Operator`){let n=`no definition of operator ${i}`;throw t(g(r.location,n)),new e.ut(n,{failure:`Expr.Deref.deref_letop`})}let c=s.body,l=c.kind===`Lambda`?S({...c,body:S({kind:`Parens`,expression:c.body,form:{kind:`Xlabel`,label:i,indices:c.params.map((e,t)=>({name:e.name,index:c.params.length-t}))}},c.body)},c):S({kind:`Parens`,expression:c,form:{kind:`Xlabel`,label:i,indices:[]}},c);return Ne(t,n,S({kind:`Let`,definitions:r.definitions.slice(0,o),body:l},c),i,a)},Fe=(t,n,r,i)=>{let[a,...o]=i;if(!a){let e=r.definitions.length===0?r.expression:S({kind:`Let`,definitions:r.definitions,body:r.expression},r.expression),t=r.params.length===0?e:S({kind:`Lambda`,params:r.params,body:e},e);return{...we(t),isAtomic:!0}}if(r.expression.isAtomic)return t(g(r.expression.location,`Expression has no subexpressions`)),Se;let s=n?r.expression:Te(r.expression),c=r.definitions.length,l=(()=>{let i=(e,n)=>{let[i,a]=je(t,[],s,e,r.expression,n);return{params:[],definitions:i,expression:a,rest:o,isLabel:!1}};switch(a.kind){case`Down`:{let[r,...i]=o;if(s.kind===`Let`&&r?.kind===`Label`&&n)return{...Pe(t,c,s,r.label,r.args),rest:i,isLabel:!0};if(n)return{params:[],definitions:[],expression:s,rest:o,isLabel:!1};throw new e.ut(`!: is forbidden for this expression.
package/dist/run-cli.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
- import{$ as e,A as t,B as n,C as r,D as i,E as a,H as o,I as s,K as c,L as l,M as u,O as d,Q as f,R as p,T as m,U as h,V as g,W as _,Z as v,_ as y,_t as b,at as x,ct as S,dt as ee,et as C,ft as w,gt as T,h as E,ht as te,it as ne,j as D,k as re,lt as ie,m as ae,mt as O,nt as oe,ot as se,pt as ce,rt as k,st as A,tt as le,ut as j,v as ue,vt as de,w as fe,yt as pe,z as me}from"./transfer.js";import{t as he}from"./parallel.js";import{basename as ge,delimiter as _e,dirname as ve,isAbsolute as M,join as ye,resolve as be}from"node:path";import{existsSync as xe,globSync as Se,mkdirSync as Ce,readFileSync as we,readSync as Te,realpathSync as Ee,writeFileSync as De}from"node:fs";import{spawnSync as Oe}from"node:child_process";import{createHash as ke}from"node:crypto";import{arch as Ae,availableParallelism as je,release as Me,tmpdir as Ne,type as Pe}from"node:os";import{pathToFileURL as N}from"node:url";import{getHeapStatistics as Fe}from"node:v8";import{strFromU8 as Ie,unzipSync as Le}from"fflate";var Re=`0.0.4-dev.a0009b7`;const ze=e=>{let t=e.isRequired?e.flag:`[${e.flag}]`;return e.isRepeatable?`${t}...`:t},Be=(e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,e.getArity??(()=>n.length)]}));return{usage:e.replace(`{options}`,t.map(ze).join(` `)),parse:e=>{let t=[],r=[],i=[],a=[];for(let o=0;o<e.length;o++){let s=n.get(e[o]);if(s===void 0){(e[o].startsWith(`-`)?i:r).push(e[o]);continue}let c=s(e.slice(o+1)),l={name:e[o],values:e.slice(o+1,o+1+c)};t.push(l),l.values.length<c&&a.push(l),o+=c}return{options:t,positionals:r,unknown:i,incomplete:a[0],has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}},Ve=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},He=e=>`File ${JSON.stringify(e.file)}, ${Ve(e)}`,Ue=e=>`${e?He(e):`<unknown location>`}:\n`,P=(e,t)=>({text:`${Ue(e)}Error: ${t}`,channel:`stderr`}),We=e=>e?`${He(e)} :\n`:``,F=e=>({kind:`Shift`,amount:e}),Ge=(e,t)=>({kind:`Cons`,expression:e,rest:t}),Ke=(e,t)=>e.reduce((e,t)=>Ge(t,e),t),qe=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},I=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},Je=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},Ye=(e,t,n)=>I({kind:`Apply`,operator:I({kind:`Internal`,builtin:e},n),args:t},n),Xe=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},Ze=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),Qe=(e,t)=>t.reduce(Ze,e),$e=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},et=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(Je(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},tt=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},nt=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},rt=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),it=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),at=(e,t,n)=>{switch(e.kind){case`Shift`:return I({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?I(ct(e.expression),n):at(e.rest,t-1,n);case`Compose`:return L(e.outer,at(e.inner,t,n));case`Bump`:return t<=e.amount?I({kind:`Ix`,index:t},n):L(F(e.amount),at(e.rest,t-e.amount,n))}},ot=(e,t)=>t.map(t=>L(e,t)),st=(e,t)=>{if(e.kind===`Lambda`){if(e.params.length!==t.length)throw new j(`Arity mismatch`);return ct(L(Ke(t,F(0)),e.body))}return e.kind===`Apply`?{kind:`Apply`,operator:e.operator,args:[...e.args,...t]}:t.length===0?ct(e):{kind:`Apply`,operator:e,args:t}},ct=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},lt=(e,t)=>[qe(t.length,e),bt(t,t=>L(e,t))],ut=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return Ct(t,t=>L(e,t));case`Instance`:{let n=qe(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:L(n,e.expression)}))}}}}},dt=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:L(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ut(e,t.definition)};case`Fact`:return{...t,expression:L(e,t.expression)}}},ft=(e,t)=>{let[n,r]=nt(e,t.context,(e,t)=>[qe(1,e),dt(e,t)]);return{context:r,active:L(n,t.active)}},L=(e,t)=>{let n=t=>L(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return at(e,t.index,t);case`Apply`:return I(st(n(t.operator),ot(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>xt(e,n))};case`Lambda`:return{...t,body:L(qe(t.params.length,e),t.body)};case`Let`:{let[n,r]=nt(e,t.definitions,(e,t)=>[qe(1,e),ut(e,t)]);return{...t,definitions:r,body:L(n,t.body)}}case`Sequent`:return{...t,sequent:ft(e,t.sequent)};case`With`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:ot(e,t.items)};case`Quant`:{let[n,r]=lt(e,t.bounds);return{...t,bounds:r,body:L(n,t.body)}}case`Tquant`:return{...t,body:L(qe(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:L(qe(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:L(qe(1,e),t.body)};case`SetOf`:{let[n,r]=lt(e,t.bounds);return{...t,bounds:r,element:L(n,t.element)}}case`SetEnum`:return{...t,elements:ot(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`Fcn`:{let[n,r]=lt(e,t.bounds);return{...t,bounds:r,body:L(n,t.body)}}case`FcnApp`:return{...t,function:n(t.function),args:ot(e,t.args)};case`Product`:return{...t,factors:ot(e,t.factors)};case`Tuple`:return{...t,elements:ot(e,t.elements)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:St(t.specs,n)};case`Dot`:return{...t,expression:n(t.expression)};case`Sub`:case`Tsub`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Fair`:return{...t,subscript:n(t.subscript),action:n(t.action)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)};case`Parens`:return{...t,expression:n(t.expression)}}},R=(e,t)=>e===0?t:L(F(e),t),pt=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),mt=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!z(t,n))return!1}return!0},ht=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&z(e.domain.expression,t.domain.expression)),gt=(e,t)=>{if(e.kind!==t.kind)return!1;switch(e.kind){case`Number`:return t.kind===`Number`&&e.value===t.value;case`Instance`:return t.kind===`Instance`&&pt(e.args,t.args,z);case`Label`:return t.kind===`Label`&&e.label===t.label&&pt(e.args,t.args,z);default:return!0}},_t=(e,t)=>{if(e.kind===`Operator`&&t.kind===`Operator`||e.kind===`Bpragma`&&t.kind===`Bpragma`)return z(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return pt(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&mt(n,r)}return!1},vt=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level!==t.level||e.shape!==t.shape?!1:!e.domain||!t.domain?!e.domain&&!t.domain:z(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?_t(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&z(e.expression,t.expression),yt=(e,t)=>pt(e.context,t.context,vt)&&z(e.active,t.active),z=(e,t)=>{if(e.kind===`Parens`)return z(e.expression,t);if(t.kind===`Parens`)return z(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&z(e.body,t.body);case`Apply`:return t.kind===`Apply`&&z(e.operator,t.operator)&&pt(e.args,t.args,z);case`Sequent`:return t.kind===`Sequent`&&yt(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&z(e.expression,t.expression)&&pt(e.selectors,t.selectors,gt);case`With`:return t.kind===`With`&&z(e.expression,t.expression);case`Let`:return t.kind===`Let`&&pt(e.definitions,t.definitions,_t)&&z(e.body,t.body);case`If`:return t.kind===`If`&&z(e.condition,t.condition)&&z(e.consequent,t.consequent)&&z(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&pt(e.items,t.items,z);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&pt(e.bounds,t.bounds,ht)&&z(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&pt(e.names,t.names,(e,t)=>e===t)&&z(e.body,t.body);case`Choose`:return t.kind===`Choose`?e.domain&&t.domain?z(e.domain,t.domain)&&z(e.body,t.body):!e.domain&&!t.domain&&z(e.body,t.body):!1;case`SetSt`:return t.kind===`SetSt`&&z(e.domain,t.domain)&&z(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&z(e.element,t.element)&&pt(e.bounds,t.bounds,ht);case`SetEnum`:return t.kind===`SetEnum`&&pt(e.elements,t.elements,z);case`Arrow`:return t.kind===`Arrow`&&z(e.domain,t.domain)&&z(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&pt(e.bounds,t.bounds,ht)&&z(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&pt([e.function,...e.args],[t.function,...t.args],z);case`Tuple`:return t.kind===`Tuple`&&pt(e.elements,t.elements,z);case`Product`:return t.kind===`Product`&&pt(e.factors,t.factors,z);case`Rect`:return t.kind===`Rect`&&mt(e.fields,t.fields);case`Record`:return t.kind===`Record`&&mt(e.fields,t.fields);case`Except`:return t.kind===`Except`&&z(e.function,t.function)&&pt(e.specs,t.specs,(e,t)=>pt(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&z(e.expression,t.expression))&&z(e.value,t.value));case`Dot`:return t.kind===`Dot`&&z(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&z(e.action,t.action)&&z(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&z(e.subscript,t.subscript)&&z(e.action,t.action);case`Case`:return t.kind!==`Case`||!(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:z(e.arms[0].condition,t.arms[0].condition)&&z(e.arms[0].body,t.arms[0].body))?!1:e.other&&t.other?z(e.other,t.other):!e.other&&!t.other;case`String`:return t.kind===`String`&&e.value===t.value;case`Num`:return t.kind===`Num`&&e.integer===t.integer&&e.fraction===t.fraction;case`At`:return t.kind===`At`&&e.isExcept===t.isExcept}},bt=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),xt=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,St=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),Ct=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,wt=(e,t,n)=>e.kind===`Fresh`?e.domain?{...e,domain:t(e.domain)}:e:e.kind===`Flex`||n===`visible`&&e.visibility===`Hidden`?e:e.kind===`Defn`?{...e,definition:Ct(e.definition,t)}:{...e,expression:t(e.expression)},Tt=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,rt(t.name,t.level)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=rt(t.name,`Unknown`,t.shape);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=nt(e,t.sequent.context,(e,t)=>{let a=wt(t,t=>n(e,t),i);return[r(e,a),a]});return{...t,sequent:{context:o,active:n(a,t.sequent.active)}}}case`Let`:{let[i,a]=nt(e,t.definitions,(e,t)=>{let i=Ct(t,t=>n(e,t));return[r(e,{kind:`Defn`,definition:i,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=bt(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=bt(t.bounds,a);return{...t,bounds:e,element:n(o(e),t.element)}}case`Tquant`:{let i=t.names.reduce((e,t)=>r(e,{kind:`Flex`,name:t}),e);return{...t,body:n(i,t.body)}}case`Choose`:{let i=t.domain&&a(t.domain),o=i?it(t.name,i):rt(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=it(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>xt(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=St(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},Et=(e,t)=>Tt(void 0,e,(e,n)=>t(n),()=>void 0,`all`),Dt=e=>{let t=[];return Et(e,e=>(t.push(e),e)),t},Ot={kind:`Opaque`,name:`$Bad`},kt=e=>e.kind===`Opaque`&&e.name===Ot.name,At=e=>{let t=e.kind===`Parens`?At(e.expression):Et(e,At);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},jt=e=>e.kind===`Let`?I({kind:`Let`,definitions:e.definitions,body:jt(e.body)},e.body):e.kind===`Parens`?jt(e.expression):Et(e,jt),Mt=e=>e.kind===`Ix`?e.index<=0:Dt(e).some(Mt),Nt=(e,t,n)=>{let r=(e,r=n)=>Nt(e,t,r),i=(e,t)=>e.reduce((e,t)=>e??(t.domain.kind===`Domain`?r(t.domain.expression):void 0),void 0)??r(t,[...n,...e.map(e=>rt(e.name,e.level))]);switch(e.kind){case`Parens`:return e.form.kind===`Xlabel`?e.form.label===t?{context:n,expression:e.expression,indices:e.form.indices}:void 0:r(e.expression);case`Lambda`:return r(e.body,[...n,...e.params.map(e=>rt(e.name,`Unknown`,e.shape))]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,rt(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of Dt(e)){let e=r(t);if(e)return e}return}},Pt=(e,t)=>Ke(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),F(e+t)),Ft=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),It=(e,t,n)=>{switch(t.kind){case`Quant`:case`Fcn`:case`SetOf`:{if(t.bounds.length!==n.length){let r=t.bounds.length,i=`Arity mismatch in subexpression instance.\nExpected ${r} argument${r===1?``:`s`}, but found${n.length<r?` only`:``} ${n.length}.`;throw e(P(t.location,i)),new j(i,{failure:`Expr.Deref.deref_inst`})}let r=t.kind===`SetOf`?t.element:t.body;return L(Ke(n,F(0)),r)}case`Tquant`:return It(e,I({kind:`Quant`,quantifier:t.quantifier,bounds:t.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:t.body},t),n);case`Lambda`:return It(e,I({kind:`Quant`,quantifier:`Forall`,bounds:t.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:t.body},t),n);case`SetSt`:case`Choose`:if(n.length!==1){let r=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${n.length}.`;throw e(P(t.location,r)),new j(r,{failure:`Expr.Deref.deref_inst`})}return L(Ke(n,F(0)),t.body);default:{let n=`Cannot instantiate non-binding expression`;throw e(P(t.location,n)),new j(n,{failure:`Expr.Deref.deref_inst`})}}},Lt=(e,t,n)=>{let r=(()=>{switch(n.kind){case`Quant`:case`Fcn`:case`SetOf`:return n.bounds.map(e=>({name:e.name,shape:0}));case`Tquant`:return n.names.map(e=>({name:e,shape:0}));case`Lambda`:return n.params;case`SetSt`:case`Choose`:return[{name:n.name,shape:0}];default:{let t=`Cannot abstract over bound variables in a non-binding expression`;throw e(P(n.location,t)),new j(t,{failure:`Expr.Deref.deref_at`})}}})(),i=L(Pt(t,r.length),n);return[r,It(e,i,Ft(r.length))]},Rt=(e,t,n,r,i,a)=>{let o=t=>{if(!(r<=t))throw e(P(i.location,a)),new j(a,{failure:`Expr.Deref.deref_num`})},s=e=>(o(e.length),e[r-1]),c=(()=>{switch(n.kind){case`Sequent`:{let i=n.sequent;o(i.context.length+1);let a=i.context[r-1];if(a&&a.kind!==`Fact`){let t=`subexpression reference does not resolve to an expression`;throw e(P(n.location,t)),new j(t,{failure:`Expr.Deref.deref_num`})}let s=L(F(-(r-1)),a?a.expression:i.active);if(Mt(s))throw e(P(n.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
9
+ import{$ as e,A as t,B as n,C as r,D as i,E as a,H as o,I as s,K as c,L as l,M as u,O as d,Q as f,R as p,T as m,U as h,V as g,W as _,Z as v,_ as y,_t as b,at as x,ct as S,dt as ee,et as C,ft as w,gt as T,h as E,ht as te,it as ne,j as D,k as re,lt as ie,m as ae,mt as O,nt as oe,ot as se,pt as ce,rt as k,st as A,tt as le,ut as j,v as ue,vt as de,w as fe,yt as pe,z as me}from"./transfer.js";import{t as he}from"./parallel.js";import{basename as ge,delimiter as _e,dirname as ve,isAbsolute as M,join as ye,resolve as be}from"node:path";import{existsSync as xe,globSync as Se,mkdirSync as Ce,readFileSync as we,readSync as Te,realpathSync as Ee,writeFileSync as De}from"node:fs";import{spawnSync as Oe}from"node:child_process";import{createHash as ke}from"node:crypto";import{arch as Ae,availableParallelism as je,release as Me,tmpdir as Ne,type as Pe}from"node:os";import{pathToFileURL as N}from"node:url";import{getHeapStatistics as Fe}from"node:v8";import{strFromU8 as Ie,unzipSync as Le}from"fflate";var Re=`0.0.4-dev.e4c2d0e`;const ze=e=>{let t=e.isRequired?e.flag:`[${e.flag}]`;return e.isRepeatable?`${t}...`:t},Be=(e,t)=>{let n=new Map(t.map(e=>{let[t,...n]=e.flag.split(` `);return[t,e.getArity??(()=>n.length)]}));return{usage:e.replace(`{options}`,t.map(ze).join(` `)),parse:e=>{let t=[],r=[],i=[],a=[];for(let o=0;o<e.length;o++){let s=n.get(e[o]);if(s===void 0){(e[o].startsWith(`-`)?i:r).push(e[o]);continue}let c=s(e.slice(o+1)),l={name:e[o],values:e.slice(o+1,o+1+c)};t.push(l),l.values.length<c&&a.push(l),o+=c}return{options:t,positionals:r,unknown:i,incomplete:a[0],has:e=>t.some(t=>t.name===e),get:e=>t.findLast(t=>t.name===e)?.values}}}},Ve=e=>{let t=e.endColumn-1;return e.startLine===e.endLine?e.startColumn>=t?`line ${e.startLine}, character ${e.startColumn}`:`line ${e.startLine}, characters ${e.startColumn}-${t}`:`line ${e.startLine}, character ${e.startColumn} to line ${e.endLine}, character ${t}`},He=e=>`File ${JSON.stringify(e.file)}, ${Ve(e)}`,Ue=e=>`${e?He(e):`<unknown location>`}:\n`,P=(e,t)=>({text:`${Ue(e)}Error: ${t}`,channel:`stderr`}),We=e=>e?`${He(e)} :\n`:``,F=e=>({kind:`Shift`,amount:e}),Ge=(e,t)=>({kind:`Cons`,expression:e,rest:t}),Ke=(e,t)=>e.reduce((e,t)=>Ge(t,e),t),qe=(e,t)=>t.kind===`Bump`?{kind:`Bump`,amount:t.amount+e,rest:t.rest}:{kind:`Bump`,amount:e,rest:t},I=(e,t)=>{let n=t.location?{...e,location:t.location}:e;return t.isAtomic?{...n,isAtomic:!0}:n},Je=e=>{switch(e.kind){case`Fresh`:case`Flex`:return e.name;case`Defn`:return e.definition.name;case`Fact`:return}},Ye=(e,t,n)=>I({kind:`Apply`,operator:I({kind:`Internal`,builtin:e},n),args:t},n),Xe=e=>e.context.length===0?e.active:{kind:`Sequent`,sequent:e},Ze=(e,t)=>({hyp:t,rest:e,size:(e?.size??0)+1}),Qe=(e,t)=>t.reduce(Ze,e),$e=e=>{let t=[];for(let n=e;n;n=n.rest)t.push(n.hyp);return t.reverse()},et=(e,t)=>{let n=0;for(let r=e;r;r=r.rest){if(Je(r.hyp)===t)return{depth:n,hyp:r.hyp};n++}},tt=(e,t)=>{let n=e;for(let e=0;e<t&&n;e++)n=n.rest;return n},nt=(e,t,n)=>{let r=[];return[t.reduce((e,t)=>{let[i,a]=n(e,t);return r.push(a),i},e),r]},rt=(e,t,n=0)=>({kind:`Fresh`,name:e,shape:n,level:t,domain:void 0,domainVisibility:`Visible`}),it=(e,t)=>({kind:`Fresh`,name:e,shape:0,level:`Constant`,domain:t,domainVisibility:`Visible`}),at=(e,t,n)=>{switch(e.kind){case`Shift`:return I({kind:`Ix`,index:e.amount+t},n);case`Cons`:return t===1?I(ct(e.expression),n):at(e.rest,t-1,n);case`Compose`:return L(e.outer,at(e.inner,t,n));case`Bump`:return t<=e.amount?I({kind:`Ix`,index:t},n):L(F(e.amount),at(e.rest,t-e.amount,n))}},ot=(e,t)=>t.map(t=>L(e,t)),st=(e,t)=>{if(e.kind===`Lambda`){if(e.params.length!==t.length)throw new j(`Arity mismatch`);return ct(L(Ke(t,F(0)),e.body))}return e.kind===`Apply`?{kind:`Apply`,operator:e.operator,args:[...e.args,...t]}:t.length===0?ct(e):{kind:`Apply`,operator:e,args:t}},ct=e=>{if(!e.location&&!e.isAtomic)return e;let{location:t,isAtomic:n,...r}=e;return r},lt=(e,t)=>[qe(t.length,e),bt(t,t=>L(e,t))],ut=(e,t)=>{switch(t.kind){case`Recursive`:case`Operator`:case`Bpragma`:return Ct(t,t=>L(e,t));case`Instance`:{let n=qe(t.instance.args.length,e);return{...t,instance:{...t.instance,substitutions:t.instance.substitutions.map(e=>({name:e.name,expression:L(n,e.expression)}))}}}}},dt=(e,t)=>{switch(t.kind){case`Fresh`:return t.domain?{...t,domain:L(e,t.domain)}:t;case`Flex`:return t;case`Defn`:return{...t,definition:ut(e,t.definition)};case`Fact`:return{...t,expression:L(e,t.expression)}}},ft=(e,t)=>{let[n,r]=nt(e,t.context,(e,t)=>[qe(1,e),dt(e,t)]);return{context:r,active:L(n,t.active)}},L=(e,t)=>{let n=t=>L(e,t);switch(t.kind){case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Ix`:return at(e,t.index,t);case`Apply`:return I(st(n(t.operator),ot(e,t.args)),t);case`Bang`:return{...t,expression:n(t.expression),selectors:t.selectors.map(e=>xt(e,n))};case`Lambda`:return{...t,body:L(qe(t.params.length,e),t.body)};case`Let`:{let[n,r]=nt(e,t.definitions,(e,t)=>[qe(1,e),ut(e,t)]);return{...t,definitions:r,body:L(n,t.body)}}case`Sequent`:return{...t,sequent:ft(e,t.sequent)};case`With`:return{...t,expression:n(t.expression)};case`If`:return{...t,condition:n(t.condition),consequent:n(t.consequent),alternative:n(t.alternative)};case`List`:return{...t,items:ot(e,t.items)};case`Quant`:{let[n,r]=lt(e,t.bounds);return{...t,bounds:r,body:L(n,t.body)}}case`Tquant`:return{...t,body:L(qe(t.names.length,e),t.body)};case`Choose`:return{...t,domain:t.domain&&n(t.domain),body:L(qe(1,e),t.body)};case`SetSt`:return{...t,domain:n(t.domain),body:L(qe(1,e),t.body)};case`SetOf`:{let[n,r]=lt(e,t.bounds);return{...t,bounds:r,element:L(n,t.element)}}case`SetEnum`:return{...t,elements:ot(e,t.elements)};case`Arrow`:return{...t,domain:n(t.domain),range:n(t.range)};case`Fcn`:{let[n,r]=lt(e,t.bounds);return{...t,bounds:r,body:L(n,t.body)}}case`FcnApp`:return{...t,function:n(t.function),args:ot(e,t.args)};case`Product`:return{...t,factors:ot(e,t.factors)};case`Tuple`:return{...t,elements:ot(e,t.elements)};case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:n(e.value)}))};case`Except`:return{...t,function:n(t.function),specs:St(t.specs,n)};case`Dot`:return{...t,expression:n(t.expression)};case`Sub`:case`Tsub`:return{...t,action:n(t.action),subscript:n(t.subscript)};case`Fair`:return{...t,subscript:n(t.subscript),action:n(t.action)};case`Case`:return{...t,arms:t.arms.map(e=>({condition:n(e.condition),body:n(e.body)})),other:t.other&&n(t.other)};case`Parens`:return{...t,expression:n(t.expression)}}},R=(e,t)=>e===0?t:L(F(e),t),pt=(e,t,n)=>e.length===t.length&&e.every((e,r)=>n(e,t[r])),mt=(e,t)=>{let n=new Map(e.map(e=>[e.name,e.value])),r=new Map(t.map(e=>[e.name,e.value]));if(n.size!==r.size)return!1;for(let[e,t]of n){let n=r.get(e);if(!n||!z(t,n))return!1}return!0},ht=(e,t)=>e.level===t.level&&e.domain.kind===t.domain.kind&&(e.domain.kind!==`Domain`||t.domain.kind===`Domain`&&z(e.domain.expression,t.domain.expression)),gt=(e,t)=>{if(e.kind!==t.kind)return!1;switch(e.kind){case`Number`:return t.kind===`Number`&&e.value===t.value;case`Instance`:return t.kind===`Instance`&&pt(e.args,t.args,z);case`Label`:return t.kind===`Label`&&e.label===t.label&&pt(e.args,t.args,z);default:return!0}},_t=(e,t)=>{if(e.kind===`Operator`&&t.kind===`Operator`||e.kind===`Bpragma`&&t.kind===`Bpragma`)return z(e.body,t.body);if(e.kind===`Instance`&&t.kind===`Instance`){let n=e.instance.substitutions.map(e=>({name:e.name,value:e.expression})),r=t.instance.substitutions.map(e=>({name:e.name,value:e.expression}));return pt(e.instance.args,t.instance.args,(e,t)=>e===t)&&e.instance.module===t.instance.module&&mt(n,r)}return!1},vt=(e,t)=>e.kind===`Fresh`&&t.kind===`Fresh`?e.level!==t.level||e.shape!==t.shape?!1:!e.domain||!t.domain?!e.domain&&!t.domain:z(e.domain,t.domain):e.kind===`Flex`&&t.kind===`Flex`?!0:e.kind===`Defn`&&t.kind===`Defn`?_t(e.definition,t.definition)&&e.isLocal===t.isLocal:e.kind===`Fact`&&t.kind===`Fact`&&z(e.expression,t.expression),yt=(e,t)=>pt(e.context,t.context,vt)&&z(e.active,t.active),z=(e,t)=>{if(e.kind===`Parens`)return z(e.expression,t);if(t.kind===`Parens`)return z(e,t.expression);switch(e.kind){case`Ix`:return t.kind===`Ix`&&e.index===t.index;case`Opaque`:return t.kind===`Opaque`&&e.name===t.name;case`Internal`:return t.kind===`Internal`&&e.builtin===t.builtin;case`Lambda`:return t.kind===`Lambda`&&e.params.length===t.params.length&&z(e.body,t.body);case`Apply`:return t.kind===`Apply`&&z(e.operator,t.operator)&&pt(e.args,t.args,z);case`Sequent`:return t.kind===`Sequent`&&yt(e.sequent,t.sequent);case`Bang`:return t.kind===`Bang`&&z(e.expression,t.expression)&&pt(e.selectors,t.selectors,gt);case`With`:return t.kind===`With`&&z(e.expression,t.expression);case`Let`:return t.kind===`Let`&&pt(e.definitions,t.definitions,_t)&&z(e.body,t.body);case`If`:return t.kind===`If`&&z(e.condition,t.condition)&&z(e.consequent,t.consequent)&&z(e.alternative,t.alternative);case`List`:return t.kind===`List`&&e.bullet===t.bullet&&pt(e.items,t.items,z);case`Quant`:return t.kind===`Quant`&&e.quantifier===t.quantifier&&pt(e.bounds,t.bounds,ht)&&z(e.body,t.body);case`Tquant`:return t.kind===`Tquant`&&e.quantifier===t.quantifier&&pt(e.names,t.names,(e,t)=>e===t)&&z(e.body,t.body);case`Choose`:return t.kind===`Choose`?e.domain&&t.domain?z(e.domain,t.domain)&&z(e.body,t.body):!e.domain&&!t.domain&&z(e.body,t.body):!1;case`SetSt`:return t.kind===`SetSt`&&z(e.domain,t.domain)&&z(e.body,t.body);case`SetOf`:return t.kind===`SetOf`&&z(e.element,t.element)&&pt(e.bounds,t.bounds,ht);case`SetEnum`:return t.kind===`SetEnum`&&pt(e.elements,t.elements,z);case`Arrow`:return t.kind===`Arrow`&&z(e.domain,t.domain)&&z(e.range,t.range);case`Fcn`:return t.kind===`Fcn`&&pt(e.bounds,t.bounds,ht)&&z(e.body,t.body);case`FcnApp`:return t.kind===`FcnApp`&&pt([e.function,...e.args],[t.function,...t.args],z);case`Tuple`:return t.kind===`Tuple`&&pt(e.elements,t.elements,z);case`Product`:return t.kind===`Product`&&pt(e.factors,t.factors,z);case`Rect`:return t.kind===`Rect`&&mt(e.fields,t.fields);case`Record`:return t.kind===`Record`&&mt(e.fields,t.fields);case`Except`:return t.kind===`Except`&&z(e.function,t.function)&&pt(e.specs,t.specs,(e,t)=>pt(e.trail,t.trail,(e,t)=>e.kind===`Dot`?t.kind===`Dot`&&e.field===t.field:t.kind===`Apply`&&z(e.expression,t.expression))&&z(e.value,t.value));case`Dot`:return t.kind===`Dot`&&z(e.expression,t.expression)&&e.field===t.field;case`Sub`:case`Tsub`:return t.kind===e.kind&&e.modal===t.modal&&z(e.action,t.action)&&z(e.subscript,t.subscript);case`Fair`:return t.kind===`Fair`&&e.fairness===t.fairness&&z(e.subscript,t.subscript)&&z(e.action,t.action);case`Case`:return t.kind!==`Case`||!(e.arms.length===0||t.arms.length===0?e.arms.length===t.arms.length:z(e.arms[0].condition,t.arms[0].condition)&&z(e.arms[0].body,t.arms[0].body))?!1:e.other&&t.other?z(e.other,t.other):!e.other&&!t.other;case`String`:return t.kind===`String`&&e.value===t.value;case`Num`:return t.kind===`Num`&&e.integer===t.integer&&e.fraction===t.fraction;case`At`:return t.kind===`At`&&e.isExcept===t.isExcept}},bt=(e,t)=>e.map(e=>e.domain.kind===`Domain`?{...e,domain:{kind:`Domain`,expression:t(e.domain.expression)}}:e),xt=(e,t)=>e.kind===`Instance`||e.kind===`Label`?{...e,args:e.args.map(t)}:e,St=(e,t)=>e.map(e=>{let n=t(e.value);return{trail:e.trail.map(e=>e.kind===`Apply`?{kind:`Apply`,expression:t(e.expression)}:e),value:n}}),Ct=(e,t)=>e.kind===`Operator`||e.kind===`Bpragma`?{...e,body:t(e.body)}:e,wt=(e,t,n)=>e.kind===`Fresh`?e.domain?{...e,domain:t(e.domain)}:e:e.kind===`Flex`||n===`visible`&&e.visibility===`Hidden`?e:e.kind===`Defn`?{...e,definition:Ct(e.definition,t)}:{...e,expression:t(e.expression)},Tt=(e,t,n,r,i=`visible`)=>{let a=t=>n(e,t),o=t=>t.reduce((e,t)=>r(e,rt(t.name,t.level)),e);switch(t.kind){case`Ix`:case`Internal`:case`Opaque`:case`String`:case`Num`:case`At`:return t;case`Lambda`:{let i=t.params.reduce((e,t)=>{let n=rt(t.name,`Unknown`,t.shape);return r(e,t.location?{...n,location:t.location}:n)},e);return{...t,body:n(i,t.body)}}case`Sequent`:{let[a,o]=nt(e,t.sequent.context,(e,t)=>{let a=wt(t,t=>n(e,t),i);return[r(e,a),a]});return{...t,sequent:{context:o,active:n(a,t.sequent.active)}}}case`Let`:{let[i,a]=nt(e,t.definitions,(e,t)=>{let i=Ct(t,t=>n(e,t));return[r(e,{kind:`Defn`,definition:i,whereDefined:`User`,visibility:`Visible`,isLocal:!0}),i]});return{...t,definitions:a,body:n(i,t.body)}}case`Quant`:case`Fcn`:{let e=bt(t.bounds,a);return{...t,bounds:e,body:n(o(e),t.body)}}case`SetOf`:{let e=bt(t.bounds,a);return{...t,bounds:e,element:n(o(e),t.element)}}case`Tquant`:{let i=t.names.reduce((e,t)=>r(e,{kind:`Flex`,name:t}),e);return{...t,body:n(i,t.body)}}case`Choose`:{let i=t.domain&&a(t.domain),o=i?it(t.name,i):rt(t.name,`Constant`);return{...t,domain:i,body:n(r(e,o),t.body)}}case`SetSt`:{let i=a(t.domain),o=it(t.name,i);return{...t,domain:i,body:n(r(e,o),t.body)}}case`Bang`:{let e=t.selectors.map(e=>xt(e,a));return{...t,expression:a(t.expression),selectors:e}}case`Apply`:{let e=t.args.map(a);return{...t,operator:a(t.operator),args:e}}case`With`:case`Dot`:case`Parens`:return{...t,expression:a(t.expression)};case`If`:{let e=a(t.alternative),n=a(t.consequent);return{...t,condition:a(t.condition),consequent:n,alternative:e}}case`List`:return{...t,items:t.items.map(a)};case`SetEnum`:case`Tuple`:return{...t,elements:t.elements.map(a)};case`Product`:return{...t,factors:t.factors.map(a)};case`FcnApp`:{let e=t.args.map(a);return{...t,function:a(t.function),args:e}}case`Arrow`:{let e=a(t.range);return{...t,domain:a(t.domain),range:e}}case`Rect`:case`Record`:return{...t,fields:t.fields.map(e=>({name:e.name,value:a(e.value)}))};case`Except`:{let e=St(t.specs,a);return{...t,function:a(t.function),specs:e}}case`Sub`:case`Tsub`:case`Fair`:return{...t,subscript:a(t.subscript),action:a(t.action)};case`Case`:{let e=t.other&&a(t.other),n=t.arms.map(e=>{let t=a(e.body);return{condition:a(e.condition),body:t}});return{...t,arms:n,other:e}}}},Et=(e,t)=>Tt(void 0,e,(e,n)=>t(n),()=>void 0,`all`),Dt=e=>{let t=[];return Et(e,e=>(t.push(e),e)),t},Ot={kind:`Opaque`,name:`$Bad`},kt=e=>e.kind===`Opaque`&&e.name===Ot.name,At=e=>{let t=e.kind===`Parens`?At(e.expression):Et(e,At);if(!t.isAtomic)return t;let{isAtomic:n,...r}=t;return r},jt=e=>e.kind===`Let`?I({kind:`Let`,definitions:e.definitions,body:jt(e.body)},e.body):e.kind===`Parens`?jt(e.expression):Et(e,jt),Mt=e=>e.kind===`Ix`?e.index<=0:Dt(e).some(Mt),Nt=(e,t,n)=>{let r=(e,r=n)=>Nt(e,t,r),i=(e,t)=>e.reduce((e,t)=>e??(t.domain.kind===`Domain`?r(t.domain.expression):void 0),void 0)??r(t,[...n,...e.map(e=>rt(e.name,e.level))]);switch(e.kind){case`Parens`:return e.form.kind===`Xlabel`?e.form.label===t?{context:n,expression:e.expression,indices:e.form.indices}:void 0:r(e.expression);case`Lambda`:return r(e.body,[...n,...e.params.map(e=>rt(e.name,`Unknown`,e.shape))]);case`Let`:{let t=[...n];for(let n of e.definitions){let e=n.kind===`Operator`||n.kind===`Bpragma`?r(n.body,[...t]):void 0;if(e)return e;t.push({kind:`Defn`,definition:n,whereDefined:`Builtin`,visibility:`Visible`,isLocal:!0})}return r(e.body,t)}case`Quant`:case`Fcn`:return i(e.bounds,e.body);case`SetOf`:return i(e.bounds,e.element);case`Tquant`:return r(e.body,[...n,...e.names.map(e=>({kind:`Flex`,name:e}))]);case`Choose`:case`SetSt`:return(e.domain&&r(e.domain))??r(e.body,[...n,rt(e.name,`Constant`)]);case`Sequent`:{let t=[...n];for(let n of e.sequent.context){if(n.kind!==`Fact`)return;let e=r(n.expression,[...t]);if(e)return e;t.push(n)}return r(e.sequent.active,t)}default:for(let t of Dt(e)){let e=r(t);if(e)return e}return}},Pt=(e,t)=>Ke(Array.from({length:e},(e,t)=>({kind:`Ix`,index:t+1})),F(e+t)),Ft=e=>Array.from({length:e},(t,n)=>({kind:`Ix`,index:e-n})),It=(e,t,n)=>{switch(t.kind){case`Quant`:case`Fcn`:case`SetOf`:{if(t.bounds.length!==n.length){let r=t.bounds.length,i=`Arity mismatch in subexpression instance.\nExpected ${r} argument${r===1?``:`s`}, but found${n.length<r?` only`:``} ${n.length}.`;throw e(P(t.location,i)),new j(i,{failure:`Expr.Deref.deref_inst`})}let r=t.kind===`SetOf`?t.element:t.body;return L(Ke(n,F(0)),r)}case`Tquant`:return It(e,I({kind:`Quant`,quantifier:t.quantifier,bounds:t.names.map(e=>({name:e,level:`State`,domain:{kind:`NoDomain`}})),body:t.body},t),n);case`Lambda`:return It(e,I({kind:`Quant`,quantifier:`Forall`,bounds:t.params.map(e=>({name:e.name,level:`Unknown`,domain:{kind:`NoDomain`}})),body:t.body},t),n);case`SetSt`:case`Choose`:if(n.length!==1){let r=`Arity mismatch in subexpression instance.\nExpected 1 argument, but found ${n.length}.`;throw e(P(t.location,r)),new j(r,{failure:`Expr.Deref.deref_inst`})}return L(Ke(n,F(0)),t.body);default:{let n=`Cannot instantiate non-binding expression`;throw e(P(t.location,n)),new j(n,{failure:`Expr.Deref.deref_inst`})}}},Lt=(e,t,n)=>{let r=(()=>{switch(n.kind){case`Quant`:case`Fcn`:case`SetOf`:return n.bounds.map(e=>({name:e.name,shape:0}));case`Tquant`:return n.names.map(e=>({name:e,shape:0}));case`Lambda`:return n.params;case`SetSt`:case`Choose`:return[{name:n.name,shape:0}];default:{let t=`Cannot abstract over bound variables in a non-binding expression`;throw e(P(n.location,t)),new j(t,{failure:`Expr.Deref.deref_at`})}}})(),i=L(Pt(t,r.length),n);return[r,It(e,i,Ft(r.length))]},Rt=(e,t,n,r,i,a)=>{let o=t=>{if(!(r<=t))throw e(P(i.location,a)),new j(a,{failure:`Expr.Deref.deref_num`})},s=e=>(o(e.length),e[r-1]),c=(()=>{switch(n.kind){case`Sequent`:{let i=n.sequent;o(i.context.length+1);let a=i.context[r-1];if(a&&a.kind!==`Fact`){let t=`subexpression reference does not resolve to an expression`;throw e(P(n.location,t)),new j(t,{failure:`Expr.Deref.deref_num`})}let s=L(F(-(r-1)),a?a.expression:i.active);if(Mt(s))throw e(P(n.location,`subexpression of ASSUME/PROVE uses identifiers declared therein
10
10
  Tlapm does not handle yet such subexpression namings.`)),new j(`Subexpression of ASSUME/PROVE uses identifiers declared therein
11
11
 
12
12
  Tlapm does not handle yet such subexpression namings.`,{failure:`Expr.Deref.deref_num`});return[t,s]}case`Apply`:return[t,s(n.args)];case`With`:return Rt(e,t,n.expression,r,i,a);case`If`:return[t,s([n.condition,n.consequent,n.alternative])];case`List`:return[t,s(n.items)];case`SetEnum`:case`Tuple`:return[t,s(n.elements)];case`Product`:return[t,s(n.factors)];case`Let`:return o(1),[[...t,...n.definitions],n.body];case`Quant`:case`SetOf`:case`Fcn`:return[t,s(n.bounds.flatMap(e=>e.domain.kind===`Domain`?[e.domain.expression]:[]))];case`Choose`:case`SetSt`:if(!n.domain)break;return[t,s([n.domain])];case`Arrow`:return[t,s([n.domain,n.range])];case`FcnApp`:{let e=n.args.length===1?n.args[0]:I({kind:`Tuple`,elements:n.args},n);return[t,s([n.function,e])]}case`Rect`:case`Record`:return[t,s(n.fields.map(e=>e.value))];case`Dot`:return[t,s([n.expression,I({kind:`String`,value:n.field},n)])];case`Except`:return[t,s([n.function,...n.specs.map(e=>e.value)])];case`Sub`:case`Tsub`:return[t,s([n.action,n.subscript])];case`Fair`:return[t,s([n.subscript,n.action])];case`Case`:return[t,s([...n.arms.map(e=>I({kind:`Tuple`,elements:[e.condition,e.body]},e.body)),...n.other?[I({kind:`Tuple`,elements:[Ot,n.other]},n.other)]:[]])]}let c=`Expression has no subexpressions`;throw e(P(n.location,c)),new j(c,{failure:`Expr.Deref.deref_num`})})();if(kt(c[1])){let t=`Cannot resolve subexpression reference !${r}`;throw e(P(n.location,t)),new j(t,{failure:`Expr.Deref.deref_num`})}return c},zt=(e,t)=>{let n=e.length,r=e;for(let e=n-1;e>=0;e--)r.includes(n-e)||(r=r.map(t=>t+e<n?t:t-1));return r.map(e=>t[n-e])},Bt=(e,t,n,r,i)=>{let a=Nt(n,r,[]);if(!a)return e(P(n.location,`Could not find label ${r}`)),{params:[],definitions:[],expression:Ot};let o=a.indices;if(o.length!==i.length&&i.length>0){let t=o.length===1?``:`s`,n=`Expected ${o.length} argument${t} for labelled reference !${r}, but found ${i.length}`;throw e(P(a.expression.location,n)),new j(n,{failure:`Expr.Deref.deref_lsub`})}let s=i.length===0?o.map(e=>({name:e.name,shape:0})):[],c=i.length===0?Ft(o.length):i,l=a.context.reduceRight((e,t)=>t.kind===`Defn`?I({kind:`Let`,definitions:[t.definition],body:e},e):t.kind===`Fresh`?I({kind:`Quant`,quantifier:`Forall`,bounds:[{name:t.name,level:`Constant`,domain:{kind:`NoDomain`}}],body:e},e):L(F(-1),e),a.expression),u=L(Pt(t,s.length),l),d=[],f=u,p=zt(o.map(e=>e.index),c);for(;p.length>0;)if(f.kind===`Let`&&f.definitions.length===1)d.push(f.definitions[0]),f=f.body,p=p.map(e=>L(F(1),e));else{if(f.kind!==`Quant`||f.bounds.length!==1)throw new O(`File "src/expr/e_deref.ml", line 477, characters 21-33: Assertion failed`);f=L(Ge(p[0],F(0)),f.body),p=p.slice(1)}return{params:s,definitions:d,expression:f}},Vt=(e,t,n,r,i)=>{if(n.kind!==`Let`)throw e(P(n.location,`not a LET expression`)),new j(`not a LET expression`,{failure:`Expr.Deref.deref_letop`});let a=n.definitions.findIndex(e=>e.kind===`Operator`&&e.name===r),o=n.definitions[a];if(!o||o.kind!==`Operator`){let t=`no definition of operator ${r}`;throw e(P(n.location,t)),new j(t,{failure:`Expr.Deref.deref_letop`})}let s=o.body,c=s.kind===`Lambda`?I({...s,body:I({kind:`Parens`,expression:s.body,form:{kind:`Xlabel`,label:r,indices:s.params.map((e,t)=>({name:e.name,index:s.params.length-t}))}},s.body)},s):I({kind:`Parens`,expression:s,form:{kind:`Xlabel`,label:r,indices:[]}},s);return Bt(e,t,I({kind:`Let`,definitions:n.definitions.slice(0,a),body:c},s),r,i)},Ht=(e,t,n,r)=>{let[i,...a]=r;if(!i){let e=n.definitions.length===0?n.expression:I({kind:`Let`,definitions:n.definitions,body:n.expression},n.expression),t=n.params.length===0?e:I({kind:`Lambda`,params:n.params,body:e},e);return{...At(t),isAtomic:!0}}if(n.expression.isAtomic)return e(P(n.expression.location,`Expression has no subexpressions`)),Ot;let o=t?n.expression:jt(n.expression),s=n.definitions.length,c=(()=>{let r=(t,r)=>{let[i,s]=Rt(e,[],o,t,n.expression,r);return{params:[],definitions:i,expression:s,rest:a,isLabel:!1}};switch(i.kind){case`Down`:{let[n,...r]=a;if(o.kind===`Let`&&n?.kind===`Label`&&t)return{...Vt(e,s,o,n.label,n.args),rest:r,isLabel:!0};if(t)return{params:[],definitions:[],expression:o,rest:a,isLabel:!1};throw new j(`!: is forbidden for this expression.
package/dist/transfer.cjs CHANGED
@@ -25,7 +25,7 @@ to an element in its putative domain.`;var x=class extends y{constructor(){super
25
25
  \r`.includes(e[t]))n.offset++;else if(e.startsWith(`(*`,t)||e.startsWith(`\\*`,t)){let e=o();if(e!==void 0)return e}else{let i=ze(e,t);if(i.length===0){let n=We(e,t),r=Math.min(t+n.length+1,e.length),i=e.slice(t,r),o=r<e.length?n:i.length>1?i:``;return a(t,r,o)}let o=r(i.kind,t,i.length);return n.offset+=i.length,o}}return i()}},Ke=/* @__PURE__ */ new Map([[`\b`,`\\b`],[` `,`\\t`],[`
26
26
  `,`\\n`],[`\f`,`\\f`],[`\r`,`\\r`],[`"`,`\\"`],[`'`,`\\'`],[`\\`,`\\\\`]]),qe=e=>e.replace(/[\0-\x1f"'\\\x7f-\uffff]/g,e=>Ke.get(e)??(e===`\0`?``:`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)),Je=(e,t,n,r)=>`Lexical error at line ${e}, column ${t}. Encountered: ${n===void 0?`<EOF> `:`"${qe(n)}" (${n.charCodeAt(0)}), `}after : "${qe(r)}"`,Ye=e=>{let t=Ge(e);for(let e=t();typeof e!=`string`&&e.kind!==A(`EOF`);e=t()){let t=e.image.split(``).findIndex(e=>{let t=e.charCodeAt(0);return t>255&&(t&255)<128});if(t===-1)continue;let n=e.image.slice(1,t+1).split(``).reduce((e,t)=>t===` `?Be(e):e+1,e.beginColumn);return Je(e.beginLine,n,e.image[t],e.image.slice(0,t))}},Xe=[`CONSTANT`,`CONSTANTS`,`INIT`,`NEXT`,`SPECIFICATION`,`INVARIANT`,`INVARIANTS`,`PROPERTY`,`PROPERTIES`,`CONSTRAINT`,`CONSTRAINTS`,`ACTION_CONSTRAINT`,`ACTION_CONSTRAINTS`,`SYMMETRY`,`VIEW`,`CHECK_DEADLOCK`],Ze=/* @__PURE__ */ new Set([...Xe,`ALIAS`,`POSTCONDITION`,`POSTCONDITIONS`,`_POSSIBLE`,`_PERIODIC`,`_RL_REWARD`]),Qe=[`TYPE`,`TYPE_CONSTRAINT`],$e=/* @__PURE__ */ new Set([...Xe,...Qe]),et=[`<-`,`<<`,`>>`,`=`,`{`,`}`,`,`,`[`,`]`,`(`,`)`,`!`],tt=e=>{let t=[],n={index:0,line:1,lineStart:0},r=(r,i)=>{t.push({kind:`Error`,text:Je(n.line,r-n.lineStart+1,e[r],i),line:n.line})},i=e=>{t.push({kind:`Error`,text:Je(n.line+1,0,void 0,e),line:n.line})},a=e=>{let t=e.split(`
27
27
  `);t.length>1&&(n.line+=t.length-1,n.lineStart=n.index+e.length-t[t.length-1].length),n.index+=e.length};for(;n.index<e.length;){let o=e.slice(n.index),s=/^\s+/.exec(o)?.[0];if(s){a(s);continue}if(o.startsWith(`\\*`)){let e=o.indexOf(`
28
- `);a(e===-1?o:o.slice(0,e));continue}if(o.startsWith(`(*`)){let e=o.indexOf(`*)`);if(e===-1)return a(o),i(``),t;a(o.slice(0,e+2));continue}let c=n.line,l=/^\d+(?![A-Za-z_])/.exec(o)?.[0];if(l){t.push({kind:`Number`,text:l,line:c}),a(l);continue}let u=/^[A-Za-z0-9_]+/.exec(o)?.[0];if(u){t.push({kind:`Word`,text:u,line:c}),a(u);continue}if(o.startsWith(`"`)){let s=/^"((?:[^"\\\n]|\\[^\n])*)("?)/.exec(o),l=s?.[0]??`"`;if(s?.[2]!==`"`)return a(l),n.index===e.length?i(`${l}\n`):r(n.index,l),t;t.push({kind:`String`,text:s[1],line:c}),a(l);continue}let d=et.find(e=>o.startsWith(e));if(d){t.push({kind:`Symbol`,text:d,line:c}),a(d);continue}let f=_e(e,n.index)??O(e,n.index);if(!f)return r(n.index,``),t;t.push({kind:`Word`,text:f.text,line:c}),a(e.slice(n.index,n.index+f.length))}return t.push({kind:`End`,text:``,line:n.line}),t},nt=(e,t)=>new v(`TLC found an error in the configuration file at line ${e}\n${t}`),rt=(e,t)=>nt(e,`The keyword ${t} appeared twice.`),M=/* @__PURE__ */ new Map([[`INIT`,`init`],[`NEXT`,`next`],[`SPECIFICATION`,`specification`],[`VIEW`,`view`],[`SYMMETRY`,`symmetry`],[`ALIAS`,`alias`],[`_PERIODIC`,`periodic`],[`_RL_REWARD`,`rlReward`]]),it=/* @__PURE__ */ new Map([[`INVARIANT`,`invariants`],[`INVARIANTS`,`invariants`],[`PROPERTY`,`properties`],[`PROPERTIES`,`properties`],[`CONSTRAINT`,`constraints`],[`CONSTRAINTS`,`constraints`],[`ACTION_CONSTRAINT`,`actionConstraints`],[`ACTION_CONSTRAINTS`,`actionConstraints`],[`POSTCONDITION`,`postconditions`],[`POSTCONDITIONS`,`postconditions`],[`_POSSIBLE`,`possible`]]),at=(e,t=`master`)=>{let n=t===`1.7.4`?$e:Ze,r=tt(e),i={index:0},a={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},o={isSet:!1},s=/* @__PURE__ */ new Set,c=()=>{let e=r[Math.min(i.index++,r.length-1)];if(e.kind===`Error`)throw new v(`TLC found an error in the configuration file:\n${e.text}`);return e},l=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t={token:c()};if(t.token.text!==`}`)for(;e.push(l(t.token)),t.token=c(),t.token.text===`,`;)t.token=c();if(t.token.text!==`}`)throw nt(t.token.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw nt(e.line,`It was expecting a value, but did not find it.`)},u=e=>{let t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after ${e}[.`);let n=c();if(n.text!==`]`)throw nt(n.line,`It was expecting ], but did not find it.`);return t.text},d=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;let r={token:c(),name:t.text};for(;r.token.text===`!`;)r.name=`${r.name}!${c().text}`,r.token=c();let i=r.name;if(r.token.text===`<-`){if(r.token=c(),r.token.text===`[`){let e=u(`<-`),t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after <-[mod].`);a.substitutions.push({name:i,target:t.text,module:e});continue}if(r.token.kind===`End`)throw nt(r.token.line,`Expected an identifier after <-.`);a.substitutions.push({name:i,target:r.token.text});continue}let o=[],s=r.token.text===`(`;if(s){for(;o.push(l(c())),r.token=c(),r.token.text===`,`;);if(r.token.text!==`)`)throw nt(e,``);r.token=c()}if(r.token.text!==`=`)throw nt(r.token.line,`It was expecting = or <-, but did not find it.`);r.token=c();let d=r.token.text===`[`?u(`=`):void 0,f=l(d===void 0?r.token:c());a.constants.push({name:i,value:f,...s&&{args:o},...d!==void 0&&{module:d}})}},f=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;e.push(t.text)}},p={token:c()};for(;p.token.kind!==`End`;){let e=p.token.text,t=p.token.line,r=n.has(e)?M.get(e):void 0,i=n.has(e)?it.get(e):void 0,l=()=>{let n=c();if(n.kind===`End`)throw nt(t,`The keyword ${e} was not followed by an identifier.`);return n};if(r!==void 0){let n=l();if(a[r]!==void 0)throw rt(t,e);a[r]=n.text,p.token=c()}else if(i!==void 0)p.token=f(a[i]);else if(e===`CONSTANT`||e===`CONSTANTS`)p.token=d(t);else if(e===`CHECK_DEADLOCK`){let n=l();if(n.text!==`TRUE`&&n.text!==`FALSE`)throw nt(n.line,`It was expecting TRUE or FALSE, but did not find it.`);if(o.isSet)throw rt(t,e);o.isSet=!0,a.checkDeadlock=n.text===`TRUE`,p.token=c()}else{if(!n.has(e)||!Qe.includes(e))throw nt(t,`It was expecting a keyword, but did not find it.`);if(l(),s.has(e))throw rt(t,e);s.add(e),p.token=c()}}return a},ot={Set:{open:`{ `,close:` }`,pad:` `,separator:`,`,divider:``,dividerPad:``},Sequence:{open:`<< `,close:` >>`,pad:` `,separator:`,`,divider:``,dividerPad:``},Subset:{open:`SUBSET `,close:` `,pad:` `,separator:`,`,divider:``,dividerPad:``},Function:{open:`( `,close:` )`,pad:` `,separator:` @@`,divider:` :>`,dividerPad:` `},Record:{open:`[ `,close:` ]`,pad:` `,separator:`,`,divider:` |->`,dividerPad:` `}},st=e=>{if(e===void 0)return!1;let t=e.charCodeAt(0);return t>=9&&t<=13||t>=28&&t<=32||t===5760||t>=8192&&t<=8202&&t!==8199||t===8232||t===8233||t===8287||t===12288},ct=e=>e!==void 0&&/^\p{Nd}$/u.test(e),lt=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),ut=e=>{let t=t=>{let n=ye(e,t,st);return e[n]===void 0?void 0:n},n=(n,r,i,a,o,s)=>{let c={kind:n,first:r,last:r,children:[]},l={index:t(i)};for(;l.index!==void 0&&e[l.index]!==a;){let n=o(l.index);if(!n)return;c.children.push(n);let r=t(n.last+1);if(r===void 0)return;let i=e.startsWith(s,r)?r+s.length:r;l.index=t(i)}if(l.index!==void 0)return c.last=l.index,c},r=(n,r)=>{let i=o(n);if(!i)return;let a=t(i.last+1);if(a===void 0||!e.startsWith(r,a))return;let s=t(a+r.length),c=s===void 0?void 0:o(s);if(c)return{kind:`Pair`,first:n,last:c.last,children:[i,c]}},i=t=>{let n=ye(e,t,ct);if(e.startsWith(`..`,n)&&ct(e[n+2]))return{kind:`Constant`,first:t,last:ye(e,n+2,ct)-1,children:[]}},a=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=ct(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:ye(e,t+1,ct)-1,children:[]};if(lt(n))return{kind:`Constant`,first:t,last:ye(e,t,lt)-1,children:[]}},o=i=>{let s=t(i);if(s!==void 0)switch(e[s]){case`{`:return n(`Set`,s,s+1,`}`,o,`,`);case`<`:{let t=n(`Sequence`,s,s+2,`>`,o,`,`);return!t||t.last+1>=e.length?void 0:{...t,last:t.last+1}}case`[`:return n(`Record`,s,s+1,`]`,e=>r(e,`|->`),`,`);case`(`:return n(`Function`,s,s+1,`)`,e=>r(e,`:>`),`@@`);default:{if(!e.startsWith(`SUBSET`,s))return a(s);let n=t(s+6),r=n===void 0?void 0:o(n);return r?{kind:`Subset`,first:s,last:r.last,children:[r]}:void 0}}};return o(0)},dt=e=>{let t=e.length===0?void 0:ut(e);if(!t||t.last<e.length-1)return e;let n=t=>e.slice(t.first,t.last+1),r=e=>e.last-e.first+1,i=(e,t,i,s)=>{if(r(e)<=t-i||e.kind===`Constant`)return n(e);if(e.kind===`Pair`)return;let c=ot[e.kind],l=t-Math.max(c.open.length,c.pad.length),u=i+c.close.length,d=s+c.pad,f=e.kind===`Function`||e.kind===`Record`?o(e.children,l,u,d,c):a(e.children,l,u,d,c.separator);return f===void 0?void 0:c.open+f+c.close},a=(e,t,n,r,a)=>{let o=e.map((o,s)=>{let c=s===e.length-1,l=i(o,t,c?n:a.length,r);return l===void 0||c?l:`${l}${a}\n${r}`});return o.includes(void 0)?void 0:o.join(``)},o=(e,t,a,o,s)=>{let c=e.map((c,l)=>{let u=l===e.length-1,d=c.children[0],f=c.children[1],p=u?``:`${s.separator}\n${o}`,m=r(d)+s.divider.length+1+r(f);if(u?m<=t-a:m+s.separator.length<=t)return`${n(d)}${s.divider} ${n(f)}${p}`;let h=r(d)+s.divider.length<=t?n(d):i(d,t,a+s.divider.length,o),g=i(f,t-s.dividerPad.length,u?a:s.separator.length,o+s.dividerPad);return h===void 0||g===void 0?void 0:`${h}${s.divider}\n${o}${s.dividerPad}${g}${p}`});return c.includes(void 0)?void 0:c.join(``)};return i(t,80,0,``)??e},N=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,ft=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),P=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),F=e=>typeof e==`object`&&e.kind===`ModelValue`,pt=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:N(e)?`set`:`function`,mt=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new S(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},ht={isUsed:!1},gt=(e,t)=>(ht.isUsed=!0,e.writtenKeys=t,e),_t=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[Sr(e.domain,t)]]),vt=(e,t,n)=>gt(tn(e,t),n),yt=e=>{if(!(typeof e!=`object`||e.kind!==`Function`&&e.kind!==`Set`)&&e.hash===0&&e.fingerprint===0){if(e.kind===`Set`)return e.elements.forEach(yt);e.writtenKeys=void 0,e.range.forEach(yt)}},bt=e=>e.every(e=>typeof e==`string`),xt=(e,t)=>e.length>0&&t.length>0&&bt(e)!==bt(t),St=(e,t)=>{ht.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return xt(n,r)?Cn(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=zt(i[e],a[e]);if(t!==0)return t}return 0},Ct=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return n.length-r.length;if(n===r)return 0;for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}return 0},wt=e=>F(e)?e.type:void 0,Tt=(e,t,n)=>{let r=wt(e),i=wt(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(F(e)&&F(t)){if(r===void 0||i===void 0||r===i)return;throw new y(`Attempted to ${a} the differently-typed model values ${z(e)} and ${z(t)}`)}throw r===void 0?new y(`Attempted to ${a} the typed model value ${z(t)} and the non-model value\n${z(e)}`):new y(`Attempted to ${a}${n?``:` the`} typed model value ${z(e)} and non-model value\n${z(t)}`)},Et={ranks:Object.create(null),size:0},Dt=e=>{Et.ranks=Object.create(null),Et.size=0,Bt.clear();for(let t of e)At(t)},Ot={is174:!1},kt=e=>{Ot.is174=e===`1.7.4`},At=e=>(Et.ranks[e]===void 0&&(Et.ranks[e]=Et.size++),e),jt=()=>Et.size,Mt=e=>Et.ranks[At(e)],Nt=(e,t)=>{if(e===t)return 0;let n=Et.ranks,r=n[e],i=n[t];return r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},Pt=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),Ft=(e,t)=>(Pt(e)||Pt(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),It=(e,t,n)=>{if(!Pt(e))throw new y(`Attempted to ${n} the set ${z(I(e)?L(e):e,!0)} with the value:\n${z(t,!0)}`);if(!Pt(t))throw new y(`Attempted to compare overridden value ${z(e,!0)} with non-overridden value:\n${z(t,!0)}`);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new y(`Attempted to compare ${z(e,!0)} with the value\n${z(t,!0)}`)},Lt={kind:`InfiniteSet`,name:`Any`},Rt=e=>{throw new y(`Attempted to compare ANY with the value\n${z(e)}`)},zt=(e,t)=>{if(e===t)return ht.isUsed&&yt(e),e===Lt?Rt(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return St(e,t);if(n===`Set`&&r===`Set`)return Ct(e,t);if(n===`Interval`&&r===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.max(0,t.high-t.low+1);return n!==r||n===0?n-r:e.low-t.low}if(n===`ModelValue`&&r===`ModelValue`)return e.type!==void 0&&t.type!==void 0&&Tt(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Tt(e,t,!1),n===`ModelValue`?-1:1;if(e===Lt||t===Lt)return Rt(e===Lt?t:e);if(N(e)&&N(t)&&Ft(e,t))return It(e,t,`compare`);let i=N(e);if(i!==N(t))throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`);return i?Ct(L(e),L(t)):St(Ar(e),Ar(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Nt(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Tt(e,t,!1),F(e))return-1;if(F(t))return 1;throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`)},Bt=/* @__PURE__ */ new Map,Vt=e=>{let t=Bt.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Mt(e)};return Bt.set(e,n),n},Ht=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0}),Ut=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0,functionClass:void 0}),Wt={isPresent:!1},Gt=(e,t)=>(t===`lambda`&&(Wt.isPresent=!0),t!==void 0&&(e.functionClass=t),e),Kt=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`)?e.functionClass:void 0,qt=e=>Gt(e,`lambda`),Jt=/* @__PURE__ */ new WeakSet,Yt=/* @__PURE__ */ new WeakSet,Xt={isPresent:!1},Zt=e=>(Xt.isPresent=!0,e),Qt=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),$t=e=>{Xt.isPresent&&typeof e==`object`&&Qt.has(e.kind)&&Yt.add(e)},en=e=>{!Wt.isPresent&&!Xt.isPresent||typeof e!=`object`||Jt.has(e)||(Jt.add(e),e.kind===`Function`?(e.functionClass===`lambda`&&(e.functionClass=void 0),e.domain.forEach(en),e.range.forEach(en)):e.kind===`Set`||e.kind===`MixedSet`?e.elements.forEach(en):N(e)&&I(e)&&($t(e),L(e).elements.forEach(en)))},tn=(e,t)=>Gt(Ut(e,t),`record`),nn=(e,t)=>{if($t(e),e===t)return ht.isUsed&&yt(e),e!==Lt||Rt(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Tt(e,t,!0),zt(e,t)===0);if((e.kind===`Set`||e.kind===`Function`)&&(t.kind===`Set`||t.kind===`Function`)&&e.hash!==0&&t.hash!==0&&e.hash!==t.hash)return!1;if(e.kind===`Function`&&t.kind===`Function`)return St(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Ct(e,t)===0;if(F(e)||F(t))return Tt(e,t,!0),F(e)&&F(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return nn(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=R(e.domain),r=R(t.domain);if(n||r)return n===r;let i=R(e.range),a=R(t.range);return i||a?i===a:nn(e.domain,t.domain)&&nn(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){if(R(e))return R(t);if(R(t))return!1;let n=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),r=n(t);return e.names.length===t.names.length&&n(e).every((e,t)=>e[0]===r[t][0]&&nn(e[1],r[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`)return R(e)?R(t):!R(t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>nn(e,t.factors[n]));let n=N(e)&&N(t)&&!(I(e)&&I(t));if(n&&Ft(e,t))return It(e,t,`check equality of`)===0;if(n){if(!Pt(e)){let n=L(e);if(!Pt(t))return Ct(n,L(t))===0}return oi(e)===oi(t)}return zt(e,t)===0},rn=e=>{let t=(e,t)=>e===t||e.length===t.length&&e.every((e,r)=>n(e,t[r])),n=(n,r)=>n===r?!0:typeof n!=`object`||typeof r!=`object`?!1:n.kind===`Set`&&r.kind===`Set`?(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.elements,r.elements):n.kind===`Function`&&r.kind===`Function`?(!e||n.functionClass===r.functionClass)&&(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.domain,r.domain)&&t(n.range,r.range):oi(n)===oi(r);return n},an=rn(!1),on=rn(!0),sn=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},cn=e=>{if(!P(e))return;let t=Ar(e);return{domain:t.domain,range:t.range,low:sn(t.domain)}},ln=e=>{if(!P(e))return;let t=Ar(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},un=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to compare the typed model value ${z(e)} and the non-model value\n${z(t)}`);return 1},dn=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to check equality of the typed model value ${z(e)} and the non-model value\n${z(t)}`);return!1},fn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)?e.rank-t.rank:-1;if(!F(t))throw new y(`Attempted to compare the typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to compare the differently-typed model values ${z(e)} and ${z(t)}`);return e.rank-t.rank},pn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)&&e.name===t.name;if(!F(t))throw new y(`Attempted to check equality of typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to check equality of the differently-typed model values ${z(e)} and ${z(t)}`);return e.name===t.name},mn={number:{name:`integer`,other:`non-integer`,equality:`check equality of`},string:{name:`string`,other:`non-string`,equality:`check equality of`},boolean:{name:`boolean`,other:`non-boolean`,equality:`compare equality of`}},hn=(e,t,n)=>{let r=mn[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${z(e)} with ${r.other}:\n${z(t)}`},gn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return un(n,t);throw new y(`Attempted to compare the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return e.range.length-r.range.length;let i=()=>_n(e.range,r.range);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&r.low!==void 0)return e.low===r.low?i():e.low-r.low;let a=e.low??r.low;if(a===void 0)return _n(e.domain,r.domain)||i();let o=e.low===void 0?e.domain:r.domain;for(let t=0;t<o.length;t++){let n=o[t];if(typeof n!=`number`)throw new y(`Attempted to compare integer with non-integer${e.low===void 0?``:`:`}\n${z(n)}.`);let r=e.low===void 0?n-(a+t):a+t-n;if(r!==0)return r}return i()},_n=(e,t)=>{for(let n=0;n<e.length;n++){let r=Cn(e[n],t[n]);if(r!==0)return r}return 0},vn=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length-r.length||_n(n.range,r):gn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return un(t,e);throw new y(`Attempted to compare record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length-r.domain.length||_n(n.domain,r.domain)||_n(n.range,r.range)}return gn({...n,low:sn(n.domain)},e,t)},yn=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),bn=(e,t)=>Pt(e)||Pt(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),xn=(e,t)=>{let n=yn(t)?t:L(t);return{elements:L(e).elements,otherElements:L(n).elements}},Sn=(e,t)=>{if(bn(e,t))return zt(e,t);if(!yn(e))return Sn(L(e),t);if(!N(t)){if(F(t))return un(t,e);throw new y(`Attempted to compare the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length-n.otherElements.length||_n(n.elements,n.otherElements)},Cn=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return zt(e,t);if(F(t))return un(t,e);throw new y(hn(e,t,!1))}return e.kind===`ModelValue`?fn(e,t):P(e)?vn(e,t):Sn(e,t)},wn=(e,t)=>e.every((e,n)=>On(e,t[n])),Tn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return dn(n,t);throw new y(`Attempted to check equality of the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return!1;if(e.low!==void 0&&r.low!==void 0)return(e.range.length===0||e.low===r.low)&&wn(e.range,r.range);let i=e.low??r.low;return i===void 0?wn(e.domain,r.domain)&&wn(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new y(`Attempted to compare an integer with non-integer:\n${z(e)}.`);return e===i+t})&&wn(e.range,r.range)},En=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length===r.length&&wn(n.range,r):Tn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length===r.domain.length&&wn(n.domain,r.domain)&&wn(n.range,r.range)}return Tn({...n,low:sn(n.domain)},e,t)},Dn=(e,t)=>{if(bn(e,t))return nn(e,t);if(!yn(e))return Dn(L(e),t);if(!N(t)){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length===n.otherElements.length&&wn(n.elements,n.otherElements)},On=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(F(t))return dn(t,e);throw new y(hn(e,t,!0))}return e.kind===`ModelValue`?pn(e,t):P(e)?En(e,t):Dn(e,t)},kn=e=>{let t=[];for(let n of e){let e=jn(n,t);e.isFound||t.splice(e.index,0,n)}return t},An=(e,t)=>{let n=Tr.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},jn=(e,t)=>{let n={low:0,high:t.length};for(;n.low<n.high;){let r=n.low+(n.high-n.low>>1),i=An(e,()=>Cn(e,t[r]));if(i===0)return{index:r,isFound:!0};i<0?n.high=r:n.low=r+1}return{index:n.low,isFound:!1}},Mn=(e,t)=>t.some(t=>An(t,()=>On(t,e))),Nn=/* @__PURE__ */ new WeakSet,Pn=e=>{typeof e==`object`&&(e.kind===`Set`&&(Nn.add(e),e.elements.forEach(Pn)),e.kind===`Function`&&(e.domain.forEach(Pn),e.range.forEach(Pn)))},Fn=(e,t)=>Er(()=>nn(e,t),()=>On(e,t)),In=e=>{for(let t=1;t<e.length;t++)if(zt(e[t-1],e[t])>=0)return!1;return!0},Ln=e=>{for(let t=1;t<e.length;t++)$t(e[t]);if(e.length<2||In(e))return Ht(e);let t=[...e].sort(zt),n=[t[0]];for(let e=1;e<t.length;e++)zt(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ht(n)},Rn=e=>Er(()=>Ln(e),()=>({kind:`MixedSet`,elements:e})),zn=Ht([]),Bn=(e,t)=>{if(e.elements.length===0||t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ht(i)},Vn=(e,t)=>{let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ht(i)},Hn=(e,t)=>{if(e.elements.length===0)return t;if(t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=[],o=0,s=0;for(;o<n.length&&s<r.length;){let e=zt(n[o],r[s]);e<0?i.push(n[o++]):e>0?(a.push(r[s]),i.push(r[s++])):(i.push(n[o++]),s++)}for(;o<n.length;)i.push(n[o++]);for(;s<r.length;)a.push(r[s]),i.push(r[s++]);if(a.length===0)return e;let c=Ht(i);if(e.hash!==0&&e.hash!==Kr){let t=e.hash,n=0;for(;n<a.length;n++){let e=Zr(a[n]);if(e===Kr)break;t=t+Wr(e)|0}n===a.length&&(c.hash=t)}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+ti(a[e])|0;c.fingerprint=t}return c},Un=e=>{let t=e.length<2?e:[...e].sort((e,t)=>zt(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&zt(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Ut(n,r)},Wn=e=>{let t=Un(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:gt(t,e.map(e=>e[0]))},Gn=[],Kn=[],qn=/* @__PURE__ */ new WeakMap,Jn=e=>{let t=Gn[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Gn[e]=n,n},Yn=e=>{if(yr(e),e.low===1&&e.high>=1)return Jn(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Xn=e=>e.length>0&&(e===Gn[e.length]||qn.has(e)),Zn=e=>{let t=L(e).elements;return Xn(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Qn=e=>{let t=Kn[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return Kn[e]=n,n},$n=e=>Gt(Ut(Jn(e.length),e),`tuple`),er=e=>Gt(Un(e),`record`),tr=e=>N(e)&&!Pt(e),nr=(e,t=!1)=>`UNION(${z(e.base,t)})`,rr=(e,t=e=>L(e).elements)=>{if(!tr(e.base))throw new y(`Attempted to enumerate the nonenumerable set:\n${nr(e)}`);return t(e.base)},ir=(e,t,n)=>{if(tr(e))return e;throw new y(t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${z(e)}\nwhen enumerating:\n${nr(n)}`)},I=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`InfiniteSet`:case`SequenceSet`:return!1;case`Subset`:case`FilteredSet`:return I(e.base);case`FunctionSet`:return I(e.domain)&&I(e.range)||ar(e.domain)===!0||ar(e)===!0;case`RecordSet`:return e.sets.every(I)||ar(e)===!0;case`ProductSet`:return e.factors.every(I)||ar(e)===!0;case`Union`:return I(e.base)&&pr(e.base).every(I);case`SetOperation`:return e.operator===`\\cup`?I(e.left)&&I(e.right):e.operator===`\\cap`?I(e.left)||I(e.right):I(e.left);default:return!1}},ar=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:return e.name===`Any`&&void 0;case`Subset`:case`SequenceSet`:return!1;case`FunctionSet`:{let t=ar(e.domain);return t===void 0?void 0:!t&&ar(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=ar(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return I(e)?L(e).elements.length===0:void 0;default:return}},or=e=>{let t=e.reduce((e,t)=>e*t.length,1),n=[],r=e.map(()=>0);for(let i=0;i<t;i++){n.push(e.map((e,t)=>e[r[t]]));for(let t=e.length-1;t>=0&&(r[t]++,!(r[t]<e[t].length));t--)r[t]=0}return n},sr=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]<t-e.length+n){e[n]++;for(let t=n+1;t<e.length;t++)e[t]=e[t-1]+1;return!0}return!1},cr=e=>{if(typeof e!=`object`||e.kind!==`Subset`||Pt(e.base))return;let t=L(e.base).elements;if(t.length<=30)return;let n={index:-1,indices:[0]},r=e=>{for(e<=n.index&&(n.index=-1);n.index<e;)n.index===-1?n.indices=[]:sr(n.indices,t.length)||(n.indices=Array.from({length:n.indices.length+1},(e,t)=>t)),n.index++;return Ht(n.indices.map(e=>t[e]))},i=2**t.length,a=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<i;return new Proxy([],{get:(e,t,n)=>t===`length`?i:a(t)?r(Number(t)):Reflect.get(e,t,n),has:(e,t)=>a(t)||Reflect.has(e,t)})},lr=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Ht(r.map(t=>e[t])));while(sr(r,e.length))}return t},ur=(e,t,n)=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i];if(Pt(a))throw new y(n(a,i));let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},dr=(e,t=e=>L(e).elements)=>{if(typeof e!=`object`)throw new y(`Expected a set but found ${z(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return kn(e.elements);case`Interval`:{let t=Yn(e);return t!==Gn[t.length]&&qn.set(t,e),t}case`Subset`:{if(yr(e.base)===0)return lr([]);if(!N(e.base))throw new y(`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${dt(z(e.base))}`);let t=L(e.base).elements;if(t.length>30)throw new y(vr(e));return lr(t)}case`FunctionSet`:{if(!Ot.is174&&R(e))return[];if(Pt(e.domain))throw new y(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${z(e.domain)}\ncannot be enumerated.`);let n=Zn(e.domain);if((n.length>0||Ot.is174)&&Pt(e.range))throw new y(`Attempted to enumerate a set of the form [D -> R],but the range R:\n${z(e.range)}\ncannot be enumerated.`);let r=n.length===0?[]:t(e.range);return or(n.map(()=>r)).map(e=>Ut(n,e))}case`RecordSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.sets,t,(t,n)=>`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[n]}' field:\n${z(t)}`);return or(n).map(t=>er(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.factors,t,(e,t)=>`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${z(e)}`);return or(n).map($n)}case`FilteredSet`:if(!N(e.base)||Pt(e.base))throw new y(`Attempted to enumerate { x \\in S : p(x) } when S:\n${z(e.base)}\nis not enumerable`);return L(e.base).elements.filter(e.test);case`Union`:{let t=rr(e).flatMap((t,n)=>L(ir(t,n,e)).elements);return L(Rn(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(!tr(e.left)||!tr(e.right)))throw new y(`Attempted to enumerate S \\cup T when S:\n${z(e.left)}\nand T:\n${z(e.right)}\nare not both enumerable`);if(e.operator===`\\cap`&&!tr(e.left)&&!tr(e.right))throw new y(`Attempted to enumerate S \\cap T when neither S:\n${z(e.left)}\nnor T:\n${z(e.right)}\nis enumerable`);if(e.operator===`\\`&&!tr(e.left))throw new y(`Attempted to enumerate S \\ T when S:\n${z(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return Hn(L(e.left),L(e.right)).elements;let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return L(n).elements.filter(t=>Dr(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to enumerate the non-enumerable set ${z(e)}`);default:throw new y(`Expected a set but found ${z(e)}`)}},fr=/* @__PURE__ */ new WeakMap,L=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ht(dr(e));let t=typeof e==`object`?fr.get(e):void 0;if(t)return t;let n=Tr.sets;n?.push(e);let r=dr(e);n?.pop();let i=typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Ht(r):Ln(r);return typeof e==`object`&&fr.set(e,i),i},pr=e=>{if(typeof e!=`object`||Yt.has(e))return L(e).elements;let t=Tr.sets;t?.push(e);let n=gr(e);return t?.pop(),n},mr=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,hr=e=>typeof e!=`object`||Yt.has(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?hr(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||hr(e.left)||hr(e.right):mr(e)?.some(hr)??!1,gr=e=>{if(e.kind===`Union`)return rr(e,pr).flatMap((t,n)=>pr(ir(t,n,e)));if(e.kind===`FilteredSet`&&!Pt(e.base))return pr(e.base).filter(e.test);if(mr(e)?.some(hr))return dr(e,pr);if(e.kind!==`SetOperation`)return L(e).elements;if(e.operator===`\\cup`)return!tr(e.left)||!tr(e.right)?L(e).elements:[...pr(e.left),...pr(e.right)];let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return tr(n)?pr(n).filter(t=>Dr(t,r)===(e.operator===`\\cap`)):L(e).elements},R=e=>{if(typeof e!=`object`||!N(e))throw new y(`Shouldn't call isEmpty() on value ${z(e)}`);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:if(e.name===`Any`)throw new y(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1;case`ProductSet`:return e.factors.some(R);case`RecordSet`:return e.sets.some(R);case`FunctionSet`:return!R(e.domain)&&R(e.range);case`Union`:return rr(e).every((t,n)=>R(ir(t,n,e)));default:return L(e).elements.length===0}},_r=(e,t,n)=>e.reduce((e,r)=>{let i=e*yr(r,t);if(i>2147483647)throw new y(n());return i},1),vr=e=>`Overflow when computing the number of elements in:\n${z(e)}`,yr=(e,t)=>{if(typeof e!=`object`)throw new y(`Attempted to compute the number of elements in the ${typeof e==`number`?`integer`:typeof e==`string`?`string`:`boolean`} ${z(e)}.`);switch(e.kind){case`ModelValue`:throw new y(`Attempted to compute the number of elements in the model value ${z(e)}.`);case`Function`:return e.domain.length;case`LazyFunction`:return yr(e.domain,t);case`Interval`:{let t=Math.max(0,e.high-e.low+1);if(t>2147483647)throw new y(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to compute the number of elements in the overridden value ${z(e)}.`);case`Subset`:{let n=yr(e.base,t);if(n>=31)throw new y(vr(e));return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(R(e.domain))return 1;if(R(e.range))return 0;if(yr(e.range,t)===1)return 1}let n=yr(e.domain,t),r=yr(e.range,t);if(r<=1)return n===0?1:r;let i={value:1};for(let t=0;t<n;t++)if(i.value*=r,i.value>2147483647)throw new y(vr(e));return i.value}case`RecordSet`:return t!==`1.7.4`&&R(e)?0:_r(e.sets,t,()=>vr(e));case`ProductSet`:return t!==`1.7.4`&&R(e)?0:_r(e.factors,t,()=>`Overflow when computing the number of elements in ${z(e)}`);default:return $t(e),L(e).elements.length}},br=e=>`Attempted to check if the set ${z(e)}is finite.`,xr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new y(`Attempted to check if the ${pt(e)} ${z(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new y(`Attempted to check if the function:\n${z(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return xr(e.base)&&R(e.base);case`Subset`:return xr(e.base);case`FunctionSet`:{let t=xr(e.domain);if(t&&R(e.domain))return!0;let n=xr(e.range);return n&&R(e.range)?!0:n&&(t||yr(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n={isAllFinite:!0};for(let e of t)if(!xr(e))n.isAllFinite=!1;else if(R(e))return!0;return n.isAllFinite}case`Union`:if(!tr(e.base))throw new y(`Attempted to check if the nonenumerable set:\n${nr(e)}\nis a finite set.`);return L(e.base).elements.every(xr);case`SetOperation`:if(e.operator===`\\cup`)return xr(e.left)&&xr(e.right);if(e.operator===`\\cap`){if(!xr(e.left)&&!xr(e.right))throw new y(br(e));return!0}if(xr(e.left))return!0;if(!xr(e.right))throw new y(br(e));return!1;case`FilteredSet`:if(!xr(e.base))throw new y(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${z(e.base)}\nis finite.`);return!0}},Sr=(e,t,n=zt)=>{let r={low:0,high:e.length-1};for(;r.low<=r.high;){let i=r.low+r.high>>1,a=n(e[i],t);if(a===0)return i;a<0?r.low=i+1:r.high=i-1}return-1},Cr=e=>{if(typeof e!=`object`||!P(e))return;let t=Ar(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},wr=(e,t)=>{let n=`Attempted to check if the value:\n${z(e)}\nis an element of the`;if(!P(t))return`${n} ${pt(t)} ${z(t)}`;let r=Kt(t);return r===`record`?`Attempted to check if element:\n${z(e)}\nis in the record:\n${z(t)}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${z(t)}`},Tr={sets:void 0},Er=(e,t)=>{let n=Tr.sets,r=Tr.callStack,i=n?.length??0,a=r&&{...r,length:r.expressions.length};try{return e()}catch(e){if(!(e instanceof y))throw e;return n&&(n.length=i),r&&a&&(r.expressions.length=a.length,r.isFrozen=a.isFrozen,r.fingerprint=a.fingerprint),t(e)}},Dr=(e,t)=>{let n=Tr.sets;if(n===void 0)return Or(e,t);n.push(t);let r=Or(e,t);return n.pop(),r},Or=(e,t)=>{if(!N(t))throw new y(wr(e,t));switch(t.kind){case`Set`:return $t(e),Er(()=>Sr(t.elements,e)!==-1,()=>Nn.has(t)?jn(e,t.elements).isFound:Mn(e,t.elements));case`MixedSet`:return Mn(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!F(e))throw new y(`Attempted to check if the value:\n${z(e)}\nis in the integer interval ${z(t)}`);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(F(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new y(`Attempted to check if the value:\n${z(e)}\nis an element of ${t.name}.`);return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:if(!N(e)||Pt(e))throw new y(`Attempted to check if the non-enumerable value\n${dt(z(e))}\nis element of\n${dt(z(t))}`);return L(e).elements.every(e=>Dr(e,t.base));case`FunctionSet`:{if(!P(e)){if(F(e))return!1;throw new y(`Attempted to check if \n${z(e)}\nwhich is not a TLC function value, is in the set of functions:\n${dt(z(t))}`)}let n=Ar(e),r=sn(n.domain);return(r===void 0?Fn(t.domain,Ht(n.domain)):Fn({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>Dr(e,t.range))}case`RecordSet`:{let n=P(e)?Ar(e):void 0;if(!n||!bt(n.domain)){if(F(e))return!1;throw new y(`Attempted to check if non-record\n${z(e)}\nis in the set of records:\n${z(t)}`)}return n.domain.length===t.names.length&&t.names.every((e,r)=>{let i=Sr(n.domain,e);return i!==-1&&Dr(n.range[i],t.sets[r])})}case`ProductSet`:{let n=P(e)?Cr(e):void 0;if(n===void 0){if(P(e)&&Ar(e).domain.every(e=>typeof e==`number`)||F(e))return!1;throw new y(`Attempted to check if non-tuple\n${z(e)}\nis in the set of tuples:\n${z(t)}`)}return n.length===t.factors.length&&n.every((e,n)=>Dr(e,t.factors[n]))}case`FilteredSet`:return Dr(e,t.base)&&t.test(e);case`Union`:if(!tr(t.base))throw new y(`Attempted to check if:\n ${z(e)}\nis an element of the non-enumerable set:\n ${nr(t)}`);return L(t.base).elements.some(t=>Dr(e,t));case`SetOperation`:return t.operator===`\\cup`?Dr(e,t.left)||Dr(e,t.right):Dr(e,t.left)&&Dr(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Cr(e);if(n===void 0){if(F(e))return!1;throw new y(`Attempted to check if the value:\n${dt(z(e))}\nis an element of ${dt(z(t))}.`)}return n.every(e=>Dr(e,t.base))}default:throw new y(wr(e,t))}},kr=(e,t,n)=>e===t?!0:typeof e!=`object`||typeof t!=`object`||typeof n!=`object`||e.kind!==`Function`||t.kind!==`Function`||n.kind!==`FunctionSet`||e.domain!==t.domain?Dr(e,n):e.range.every((e,r)=>kr(e,t.range[r],n.range)),Ar=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){I(e.domain)||yr(e.domain);let t=Zn(e.domain);return Gt(Ut(t,t.map(t=>e.apply(t))),Kt(e))}throw new y(`Expected a function but found ${z(e)}`)},jr=(e,t,n)=>{let r=dt(z(e)),i=dt(z(t)),a=n===`1.7.4`;switch(Kt(e)){case`lambda`:return`In applying the function\n${r},\nthe first argument is:\n${i}\nwhich is not in its domain.\n`;case`tuple`:return typeof t==`number`?a?`Attempted to apply tuple\n${r}\nto integer ${t} which is out of domain.`:`Attempted to access index ${t} of tuple\n${r}\nwhich is out of bounds.`:a?`Attempted to apply tuple to a non-integer argument.`:`Attempted to access tuple at a non integral index: ${i}`;case`record`:return typeof t==`string`?a?`Attempted to apply the record\n${r}\nto nonexistent record field ${t}.`:`Attempted to access nonexistent field '${t}' of record\n${r}`:a?`Attempted to apply record to a non-string value ${i}.`:`Attempted to access record by a non-string argument: ${i}`;default:return`Attempted to apply function:\n${r}\nto argument ${i}, which is not in the domain of the function.`}},Mr=(e,t)=>{if(!Ot.is174)return jr(e,t);let n=dt(z(t));return Kt(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},Nr=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}if(e.length<=8){for(let n=0;n<e.length;n++)if(e[n]===t)return n}return Sr(e,t)},Pr=e=>new y(`Attempted to apply function with integer domain to the non-integer argument ${dt(z(e))}`),Fr=(e,t,n)=>{let r=e.domain;if(typeof t!=typeof r[0]){let i=Kt(e),a=i===`tuple`?`number`:i===`record`?`string`:void 0;if(a!==void 0&&typeof t!==a)throw new y(n(e,t));if(a===void 0&&!Ot.is174&&Xn(r))throw Pr(t)}return Er(()=>Nr(r,t),e=>{throw Ot.is174||r.length<32?r.forEach(e=>On(e,t)):Sr(r,t,Cn),e})},Ir=(e,t,n)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!Dr(t,e.domain))throw new y(Kt(e)===`lambda`?jr(e,t):`Attempted to apply a function to ${z(t)}, which is not in its domain`);return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new y(`Attempted to apply ${z(e)}, which is not a function`);let r=n??jr,i=Fr(e,t,r);if(i===-1)throw new y(r(e,t));return e.range[i]},Lr=e=>Xn(e)?qn.get(e)??Qn(e.length):void 0,Rr=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=Ar(e).domain;return Lr(t)??Ht(t)},zr=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!I(e.domain))){if(!Dr(t,e.domain))return e;let r=n(e.apply(t));return Gt({kind:`LazyFunction`,domain:e.domain,apply:n=>Fn(t,n)?r:e.apply(n),source:e.source},Kt(e))}if(!P(e))throw new y(`Attempted to apply EXCEPT construct to the value ${dt(z(e))}.`);let i=Ar(e),a=Fr(i,t,Mr);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=Gt(Ut(i.domain,o),Kt(i));if(l.writtenKeys=i.writtenKeys,i.hash!==0&&i.hash!==Kr){let e=Zr(c);if(e!==Kr){let t=Zr(i.domain[a]);l.hash=s===c?i.hash:i.hash-Gr(t,Zr(s))+Gr(t,e)|0}}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-ni(e,s)+ni(e,c)|0}return l},Br=/* @__PURE__ */ new WeakMap,Vr=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Hr=(e,t)=>Math.imul(e^t,16777619),Ur=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Vr(t)},Wr=e=>Vr(e+2654435769|0),Gr=(e,t)=>Vr(Math.imul(e,668265261)+t|0),Kr=795548749,qr=e=>{if(e.kind===`ModelValue`)return Vr(Hr(Ur(e.name),109));if(N(e)){if(!I(e))return Kr;let t=L(e).elements,n=1940243425;for(let e=0;e<t.length;e++){let r=Zr(t[e]);if(r===Kr)return Kr;n=n+Wr(r)|0}return n}if(e.kind===`LazyFunction`&&!I(e.domain))return Kr;let t=Ar(e),n=1725019383;for(let e=0;e<t.domain.length;e++){let r=Zr(t.domain[e]),i=Zr(t.range[e]);if(r===Kr||i===Kr)return Kr;n=n+Gr(r,i)|0}return n},Jr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return;if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw new y(`TLC has found a state in which the value of a variable contains ${z(e)}`);if(N(e)){L(e).elements.forEach(Jr);return}let t=Ar(e);t.domain.forEach(Jr),t.range.forEach(Jr)},Yr=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{Zr(e)===Kr&&Jr(e);return}catch(e){if(!(e instanceof y))throw e;return e}},Xr=e=>{switch(e.kind){case`Set`:case`MixedSet`:return e.elements;case`Function`:return[...e.domain,...e.range];case`Subset`:case`SequenceSet`:case`FilteredSet`:case`Union`:return[e.base];case`FunctionSet`:return[e.domain,e.range];case`RecordSet`:return e.sets;case`ProductSet`:return e.factors;case`SetOperation`:return[e.left,e.right];case`LazyFunction`:return[e.domain];default:return[]}},Zr=e=>{if(typeof e==`number`)return Vr(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Ur(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=qr(e)),e.hash;let t=Br.get(e);if(t!==void 0)return t;let n=qr(e);return Br.set(e,n),n},Qr=/* @__PURE__ */ new WeakMap,$r=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},ei=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return $r(t)},ti=e=>$r(ii(e)+2135587861|0),ni=(e,t)=>$r(Math.imul(ii(e),374761393)+ii(t)|0),ri=e=>{if(e.kind===`ModelValue`)return $r(ei(e.name)^60);if(N(e)){if(!I(e))return ei(oi(e));let t=L(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+ti(t[e])|0;return n}let t=Ar(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+ni(t.domain[e],t.range[e])|0;return n},ii=e=>{if(typeof e==`number`)return $r(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return ei(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=ri(e)),e.fingerprint;let t=Qr.get(e);if(t!==void 0)return t;let n=ri(e);return Qr.set(e,n),n},ai=/* @__PURE__ */ new WeakMap,oi=e=>{if(typeof e==`boolean`)return e?`T`:`F`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return JSON.stringify(e);let t=ai.get(e);if(t!==void 0)return t;let n=si(e);return ai.set(e,n),n},si=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${oi(e.base)}>`;if(e.kind===`FilteredSet`&&!I(e))throw new y(`Attempted to compare the non-enumerable set ${z(e)} with another value`);if(N(e))return I(e)?`{${L(e).elements.map(oi).join(`,`)}}`:`<${e.kind} ${z(e)}>`;let t=Ar(e);return`(${t.domain.map((e,n)=>`${oi(e)}:${oi(t.range[n])}`).join(`,`)})`},ci=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,li=e=>e.reduce((e,t)=>e===0?0:e*yr(t),1),ui=e=>{if(e.kind===`Subset`)return yr(e.base)<=6?L(e):void 0;if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return L(e);if(e.kind===`FunctionSet`&&I(e.domain)&&yr(e.domain)===0)return Ht([Ut([],[])]);let t=e.kind===`FunctionSet`?yr(e.range)**yr(e.domain):li(e.kind===`RecordSet`?e.sets:e.factors);return t===0?zn:t<=1999?L(e):void 0},di=(e,t)=>{if(t)return ui(e);if(I(e))try{return ui(e)}catch(e){if(e instanceof y)return;throw e}},fi=(e,t)=>{let n=e=>z(e,t);switch(e.kind){case`Subset`:return typeof e.base==`object`&&e.base.kind===`Interval`?`SUBSET (${n(e.base)})`:`SUBSET ${n(e.base)}`;case`FunctionSet`:return`[${n(e.domain)} -> ${n(e.range)}]`;case`RecordSet`:return`[${e.names.map((t,r)=>`${t}: ${n(e.sets[r])}`).join(`, `)}]`;case`ProductSet`:return`(${e.factors.map(n).join(` \\X `)})`;case`SetOperation`:return`${n(e.left)} ${e.operator} ${n(e.right)}`;case`FilteredSet`:return e.source?`{${e.source.names} \\in ${n(e.base)} : <expression ${e.source.predicate}> }`:`{x \\in ${n(e.base)} : ...}`;case`Union`:return nr(e,t)}},pi=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),mi=e=>{if(I(e.domain))try{return Ar(e)}catch(e){if(e instanceof y)return;throw e}},z=(e,t=!1,n=!1)=>{let r=e=>z(e,t,n);if(typeof e==`boolean`)return e?`TRUE`:`FALSE`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return ci(e);switch(e.kind){case`ModelValue`:return e.name;case`Set`:return`{${e.elements.map(r).join(`, `)}}`;case`MixedSet`:return r(L(e));case`Interval`:return e.low<=e.high?`${e.low}..${e.high}`:`{}`;case`InfiniteSet`:return e.name===`Any`?`ANY`:e.name;case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let n=di(e,t);return n?r(n):fi(e,t)}case`SequenceSet`:return`Seq(${r(e.base)})`;case`Function`:case`LazyFunction`:{let i=e.kind===`LazyFunction`?mi(e):e;if(i===void 0){let t=e.kind===`LazyFunction`?e.source:void 0;return t?`[${t.parameters.map(e=>`${e.name} \\in ${z(e.domain)}`).join(`, `)} |-> <expression ${t.body}>]`:`<function>`}if(i.domain.length===0&&Ot.is174&&Kt(e)!==`tuple`)return`<< >>`;let a=r=>z(r,t,n&&Kt(e)!==`lambda`);return i.domain.every((e,t)=>e===t+1)?`<<${i.range.map(a).join(`, `)}>>`:Kt(e)===`record`||i.domain.every(e=>typeof e==`string`&&pi(e))?`[${(n||i.hash!==0||i.fingerprint!==0?i.domain.map((e,t)=>[e,i.range[t]]):_t(i)).map(e=>`${String(e[0])} |-> ${a(e[1])}`).join(`, `)}]`:`(${i.domain.map((e,t)=>`${r(e)} :> ${a(i.range[t])}`).join(` @@ `)})`}}},hi=e=>{let t=Object.entries(e);return t.map(([e,n])=>`${t.length===1?``:`/\\ `}${e} = ${dt(z(n))}\n`).join(``)},gi=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},_i=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=Zr(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||on(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||on(i[e],n))return i[e]}return n.kind===`Set`?gi(n.elements,t):(gi(n.domain,t),gi(n.range,t)),i===void 0?e.set(r,n):Array.isArray(i)?i.push(n):e.set(r,[i,n]),n};return e=>{for(let n=0;n<e.length;n++)e[n]=t(e[n]);return e}},vi=e=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return[];case`Apply`:return e.args;case`Lambda`:return[e.body];case`And`:case`Or`:return e.operands;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`If`:return[e.condition,e.consequent,e.alternative];case`Case`:return[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]];case`Let`:return[...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),e.body];case`Forall`:case`Exists`:return[...e.bounds.map(e=>e.set),e.body];case`UnboundedQuantifier`:return[e.body];case`Choose`:return[...e.set?[e.set]:[],e.body];case`SetEnumeration`:case`Tuple`:return e.elements;case`SetFilter`:return[e.bound.set,e.predicate];case`SetMap`:return[e.expression,...e.bounds.map(e=>e.set)];case`FunctionConstruction`:return[...e.bounds.map(e=>e.set),e.body];case`FunctionSet`:return[e.domain,e.range];case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`Except`:return[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])];case`FunctionApplication`:return[e.function,...e.args];case`Bracket`:return e.args;case`FieldAccess`:return[e.record];case`Product`:return e.factors;case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`Label`:return[e.body];case`Subexpression`:return e.selectors.flatMap(e=>`args`in e?e.args:[])}},B=e=>(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`,yi=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),bi=(e,t)=>yi.has(e)?new y(t):new S(t),xi=e=>typeof e==`object`&&e.kind===`Operator`,V=(e,t,n)=>{let r=e[t];if(r===void 0||xi(r))throw bi(n,`${n} expects a value as argument ${t+1}`);return r},Si=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`number`)throw bi(n,`${n} expects an integer but received ${z(r)}`);return r},Ci=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`boolean`)throw bi(n,`${n} expects a boolean but received ${z(r)}`);return r},wi=(e,t,n)=>{let r=V(e,t,n);if(!N(r))throw bi(n,`${n} expects a set but received ${z(r)}`);return r},Ti=(e,t,n)=>{let r=wi(e,t,n);if(!I(r))throw bi(n,`${n} cannot enumerate the non-enumerable set ${z(r)}`);return r},Ei=(e,t,n)=>L(Ti(e,t,n)),Di=(e,t,n)=>Ei(e,t,n).elements,Oi=(e,t,n)=>{let r=V(e,t,n),i=Cr(r);if(!i)throw bi(n,`${n} expects a sequence but received ${z(r)}`);return i},ki=(e,t,n)=>{let r=V(e,t,n);if(!P(r))throw bi(n,`${n} expects a function but received ${z(r)}`);return Ar(r)},Ai=(e,t,n)=>{let r=e[t];if(r===void 0||!xi(r))throw bi(n,`${n} expects an operator as argument ${t+1}`);return r},ji=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),H=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:t===1?e=>n([e]):void 0,evaluateBinary:t===2?(e,t)=>n([e,t]):void 0}),Mi=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Ni=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),Pi=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(V(n,0,e),V(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Fi=e=>e>2147483647||e<-2147483648,Ii=e=>new S(`Overflow when computing ${e}`),Li={ModelValue:`ModelValue`,Set:`SetEnumValue`,Interval:`IntervalValue`,InfiniteSet:`UserValue`,SequenceSet:`UserValue`,Subset:`SubsetValue`,FunctionSet:`SetOfFcnsValue`,RecordSet:`SetOfRcdsValue`,ProductSet:`SetOfTuplesValue`,FilteredSet:`SetPredValue`,LazyFunction:`FcnLambdaValue`,Union:`UnionValue`,MixedSet:`SetEnumValue`},Ri={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},zi={BoolValue:`a Boolean value`,IntValue:`an integer`,StringValue:`a string`,RecordValue:`a record`,SetEnumValue:`a set of the form {e1, ... ,eN}`,SetPredValue:`a set of the form {x \\in S : expr}`,TupleValue:`a tuple`,FcnLambdaValue:`a function of the form [x \\in S |-> expr]`,FcnRcdValue:`a function of the form (d1 :> e1 @@ ... @@ dN :> eN)`,SetOfFcnsValue:`a set of the form [S -> T]`,SetOfRcdsValue:`a set of the form [d1 : S1, ... , dN : SN]`,SetOfTuplesValue:`a cartesian product`,SubsetValue:`a set of the form SUBSET S`,SetDiffValue:`a set of the form S \\ T`,SetCapValue:`a set of the form S \\cap T`,SetCupValue:`a set of the form S \\cup T`,ModelValue:`a model value`,UserValue:`a special set constant`,IntervalValue:`a set of the form i..j`,UnionValue:`a set of the form UNION S`},Bi={lambda:`FcnLambdaValue`,tuple:`TupleValue`,record:`RecordValue`},Vi=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Ri[e.operator];if(e.kind!==`Function`)return Li[e.kind];let t=Kt(e);return t===void 0?`FcnRcdValue`:Bi[t]},Hi=e=>zi[Vi(e)],Ui=(e,t)=>new y(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),Wi=(e,t)=>{let n=n=>(...r)=>{let i=Tr.sets?.length??0;try{return n(...r)}catch(n){throw n instanceof y&&(e.isLazy===!0||!(n instanceof S))?(Tr.sets&&(Tr.sets.length=i),Ui(t,n.message)):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},Gi=(e,t)=>{if(typeof e!=`number`)throw Ui(t,`Cannot cast tlc2.value.impl.${Vi(e)} to tlc2.value.impl.IntValue`);return e},Ki=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,qi=(e,t,n,r)=>{let i=Ki(e,n,`IntValue`,2);return Pi(t,(e,n)=>{let a=Gi(e,i),o=Gi(n,i),s=r(a,o);if(Fi(s))throw Ii(`${a}${t}${o}`);return s})},Ji=(e,t,n)=>{if(typeof e!=`number`)throw new S(`The ${t} argument of ${n} should be an integer, but instead it is:\n${z(e)}`);return e},Yi=(e,t,n=e)=>Pi(e,(e,r)=>t(Ji(e,`first`,n),Ji(r,`second`,n))),Xi=(e,t,n)=>({...Ni(e,t,n),isLazy:!0}),Zi=(e,t,n)=>{let r=Ai(e,t,n);return()=>r.call([])},Qi=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),$i=()=>({bool:gl,condition:(e,t)=>{if(typeof e!=`boolean`)throw nl(t,e);return e},junct:(e,t,n)=>{if(typeof e!=`boolean`)throw rl(t,n,e);return e},apply:Ir,expectFunction:pl,tuple:$n,set:Rn,record:tn,writtenRecord:vt,equal:nn,enumerate:Dl,unassigned:(e,t)=>{throw Dd(e,t)},primeOutsideAction:e=>{throw kd(e)},prime:e=>({environment:e.environment,scope:e.scope,state:e.next,next:void 0,isKeepLazy:e.isKeepLazy}),keepLazyContext:ml,extend:(e,t,n)=>({environment:e.environment,scope:t.reduce((e,t,r)=>dl(e,t,n[r]),e.scope),state:e.state,next:e.next,isKeepLazy:e.isKeepLazy})}),ea={value:void 0},ta=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),na=e=>`local${e.counter++}`,ra=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),vi(e).forEach(e=>ra(e,t)),t),ia=(e,t,n)=>{let r=ta(e,Wu(t,e.environment)),i=ra(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=ta(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},aa=(e,t,n)=>{let r=t.kind===`Forall`,i=JSON.stringify(r?`the body of \\A`:`the body of \\E`),a=`quantifier${e.counter++}`,o=[...n.locals.values()],s={context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:new Map(n.locals)},c=t.bounds.map(()=>na(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${ca(e,t.set,s)}, ${ta(e,t.set)}, ${JSON.stringify(e.environment.runtime.version)});`),u=t.bounds.map(t=>{let n=na(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${ca(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=na(e),a=na(e),o=na(e),s=c[r];return`for (let ${i} = 0, ${a} = ${s}.low, ${o} = ${a} === undefined ? ${s}.length : ${s}.high - ${a} + 1; ${i} < ${o}; ${i}++) { const ${n} = ${a} === undefined ? ${s}[${i}] : ${a} + ${i}; ${t} }`},d),p=o.map(e=>`, ${e}`).join(``);return e.helpers.push(`function ${a}(context, state, next${p}) { let primed; ${l.join(` `)} ${f} return ${r}; }`),`${a}(${n.context}, ${n.state}, ${n.isPrimed?`undefined`:n.next}${p})`},oa=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${ca(e,r[0],n)}, "the left side of =>") ? bool(${ca(e,r[1],n)}, "the right side of =>") : true)`;if(B(t))return ia(e,t,n);let i=$l(t.operator,e.environment);if(i?.kind!==`Builtin`)return ia(e,t,n);if(i.name===`DOMAIN`)return`${ta(e,ol(t))}(${ca(e,r[0],n)})`;if(i.name===`TLCEval`)return ia(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${ta(e,sl(t,i))}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&Zu(r[0],a))return`${ta(e,i.evaluateUnary)}(${ca(e,r[0],n)})`;let o=r.length===2&&Zu(r[0],a)&&Zu(r[1],a);return i.evaluateBinary&&o?`${ta(e,i.evaluateBinary)}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`:ia(e,t,n)},sa=(e,t,n)=>{switch(e.kind){case`Identifier`:{if(t.locals.has(e.name))return!0;if(B(e))return!1;let r=lu(e.name,n);return r?.kind===`Variable`||r?.kind===`Value`}case`Prime`:return sa(e.expression,t,n);case`FieldAccess`:return sa(e.record,t,n);case`FunctionApplication`:return[e.function,...e.args].every(e=>sa(e,t,n));default:return!1}},ca=(e,t,n)=>{let r=(t,r=n)=>ca(e,t,r);if(Fu(t)&&Au(t,e.environment))return ia(e,t,n);switch(t.kind){case`Number`:return _u(t.value)?String(t.value):ia(e,t,n);case`String`:return JSON.stringify(t.value);case`Identifier`:{let r=n.locals.get(t.name);if(r)return r;if(B(t))return ia(e,t,n);let i=lu(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=ta(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?ta(e,i.value):ia(e,t,n)}case`Apply`:return oa(e,t,n);case`And`:case`Or`:{let n=ta(e,t),i=t.kind===`And`?` && `:` || `;return`(${t.operands.map((e,t)=>`junct(${r(e)}, ${n}, ${t})`).join(i)})`}case`If`:return`(condition(${r(t.condition)}, ${ta(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{xd(t.function);let i=`expectFunction(${sa(t.function,n,e.environment)?r(t.function):ia(e,t.function,{...n,context:`keepLazyContext(${n.context})`})}, ${ta(e,t)})`,a=al(e.environment.runtime.version),o=a?`, ${ta(e,a)}`:``;return t.args.length===1?`apply(${i}, ${r(t.args[0])}${o})`:`apply(${i}, tuple([${t.args.map(e=>r(e)).join(`, `)}])${o})`}case`FieldAccess`:return`${ta(e,il(t))}(${r(t.record)})`;case`Record`:{let i=Td(t.fields);if(Ed(i))return ia(e,t,n);let a=ta(e,i.map(e=>e.name)),o=`[${i.map(e=>r(e.value)).join(`, `)}]`,s=t.fields.map(e=>e.name);return s.every((e,t)=>e===i[t].name)?`record(${a}, ${o})`:`writtenRecord(${a}, ${o}, ${ta(e,s)})`}case`Tuple`:return`tuple([${t.elements.map(e=>r(e)).join(`, `)}])`;case`SetEnumeration`:return`set([${t.elements.map(e=>r(e)).join(`, `)}])`;case`Prime`:{let i=ta(e,t);if(n.isPrimed)return`primeOutsideAction(${i})`;let a={context:`(primed ??= prime(${n.context}))`,state:n.next,next:`undefined`,isPrimed:!0,locals:n.locals};return`(${n.next} === undefined ? primeOutsideAction(${i}) : ${r(t.expression,a)})`}case`Unchanged`:return`equal(${r({kind:`Prime`,expression:t.expression,location:t.location})}, ${r(t.expression)})`;case`Forall`:case`Exists`:return t.bounds.every(e=>e.pattern.kind===`Name`)?aa(e,t,n):ia(e,t,n);default:return ia(e,t,n)}},la=(e,t)=>{if(!Qi.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=ca(n,e,{context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:/* @__PURE__ */ new Map}),i=n.references.map((e,t)=>`reference${t}`),a=`${n.helpers.join(`
28
+ `);a(e===-1?o:o.slice(0,e));continue}if(o.startsWith(`(*`)){let e=o.indexOf(`*)`);if(e===-1)return a(o),i(``),t;a(o.slice(0,e+2));continue}let c=n.line,l=/^\d+(?![A-Za-z_])/.exec(o)?.[0];if(l){t.push({kind:`Number`,text:l,line:c}),a(l);continue}let u=/^[A-Za-z0-9_]+/.exec(o)?.[0];if(u){t.push({kind:`Word`,text:u,line:c}),a(u);continue}if(o.startsWith(`"`)){let s=/^"((?:[^"\\\n]|\\[^\n])*)("?)/.exec(o),l=s?.[0]??`"`;if(s?.[2]!==`"`)return a(l),n.index===e.length?i(`${l}\n`):r(n.index,l),t;t.push({kind:`String`,text:s[1],line:c}),a(l);continue}let d=et.find(e=>o.startsWith(e));if(d){t.push({kind:`Symbol`,text:d,line:c}),a(d);continue}let f=_e(e,n.index)??O(e,n.index);if(!f)return r(n.index,``),t;t.push({kind:`Word`,text:f.text,line:c}),a(e.slice(n.index,n.index+f.length))}return t.push({kind:`End`,text:``,line:n.line}),t},nt=(e,t)=>new v(`TLC found an error in the configuration file at line ${e}\n${t}`),rt=(e,t)=>nt(e,`The keyword ${t} appeared twice.`),M=/* @__PURE__ */ new Map([[`INIT`,`init`],[`NEXT`,`next`],[`SPECIFICATION`,`specification`],[`VIEW`,`view`],[`SYMMETRY`,`symmetry`],[`ALIAS`,`alias`],[`_PERIODIC`,`periodic`],[`_RL_REWARD`,`rlReward`]]),it=/* @__PURE__ */ new Map([[`INVARIANT`,`invariants`],[`INVARIANTS`,`invariants`],[`PROPERTY`,`properties`],[`PROPERTIES`,`properties`],[`CONSTRAINT`,`constraints`],[`CONSTRAINTS`,`constraints`],[`ACTION_CONSTRAINT`,`actionConstraints`],[`ACTION_CONSTRAINTS`,`actionConstraints`],[`POSTCONDITION`,`postconditions`],[`POSTCONDITIONS`,`postconditions`],[`_POSSIBLE`,`possible`]]),at=(e,t=`master`)=>{let n=t===`1.7.4`?$e:Ze,r=tt(e),i={index:0},a={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},o={isSet:!1},s=/* @__PURE__ */ new Set,c=()=>{let e=r[Math.min(i.index++,r.length-1)];if(e.kind===`Error`)throw new v(`TLC found an error in the configuration file:\n${e.text}`);return e},l=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t={token:c()};if(t.token.text!==`}`)for(;e.push(l(t.token)),t.token=c(),t.token.text===`,`;)t.token=c();if(t.token.text!==`}`)throw nt(t.token.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw nt(e.line,`It was expecting a value, but did not find it.`)},u=e=>{let t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after ${e}[.`);let n=c();if(n.text!==`]`)throw nt(n.line,`It was expecting ], but did not find it.`);return t.text},d=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;let r={token:c(),name:t.text};for(;r.token.text===`!`;)r.name=`${r.name}!${c().text}`,r.token=c();let i=r.name;if(r.token.text===`<-`){if(r.token=c(),r.token.text===`[`){let e=u(`<-`),t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after <-[mod].`);a.substitutions.push({name:i,target:t.text,module:e});continue}if(r.token.kind===`End`)throw nt(r.token.line,`Expected an identifier after <-.`);a.substitutions.push({name:i,target:r.token.text});continue}let o=[],s=r.token.text===`(`;if(s){for(;o.push(l(c())),r.token=c(),r.token.text===`,`;);if(r.token.text!==`)`)throw nt(e,``);r.token=c()}if(r.token.text!==`=`)throw nt(r.token.line,`It was expecting = or <-, but did not find it.`);r.token=c();let d=r.token.text===`[`?u(`=`):void 0,f=l(d===void 0?r.token:c());a.constants.push({name:i,value:f,...s&&{args:o},...d!==void 0&&{module:d}})}},f=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;e.push(t.text)}},p={token:c()};for(;p.token.kind!==`End`;){let e=p.token.text,t=p.token.line,r=n.has(e)?M.get(e):void 0,i=n.has(e)?it.get(e):void 0,l=()=>{let n=c();if(n.kind===`End`)throw nt(t,`The keyword ${e} was not followed by an identifier.`);return n};if(r!==void 0){let n=l();if(a[r]!==void 0)throw rt(t,e);a[r]=n.text,p.token=c()}else if(i!==void 0)p.token=f(a[i]);else if(e===`CONSTANT`||e===`CONSTANTS`)p.token=d(t);else if(e===`CHECK_DEADLOCK`){let n=l();if(n.text!==`TRUE`&&n.text!==`FALSE`)throw nt(n.line,`It was expecting TRUE or FALSE, but did not find it.`);if(o.isSet)throw rt(t,e);o.isSet=!0,a.checkDeadlock=n.text===`TRUE`,p.token=c()}else{if(!n.has(e)||!Qe.includes(e))throw nt(t,`It was expecting a keyword, but did not find it.`);if(l(),s.has(e))throw rt(t,e);s.add(e),p.token=c()}}return a},ot={Set:{open:`{ `,close:` }`,pad:` `,separator:`,`,divider:``,dividerPad:``},Sequence:{open:`<< `,close:` >>`,pad:` `,separator:`,`,divider:``,dividerPad:``},Subset:{open:`SUBSET `,close:` `,pad:` `,separator:`,`,divider:``,dividerPad:``},Function:{open:`( `,close:` )`,pad:` `,separator:` @@`,divider:` :>`,dividerPad:` `},Record:{open:`[ `,close:` ]`,pad:` `,separator:`,`,divider:` |->`,dividerPad:` `}},st=e=>{if(e===void 0)return!1;let t=e.charCodeAt(0);return t>=9&&t<=13||t>=28&&t<=32||t===5760||t>=8192&&t<=8202&&t!==8199||t===8232||t===8233||t===8287||t===12288},ct=e=>e!==void 0&&/^\p{Nd}$/u.test(e),lt=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),ut=e=>{let t=t=>{let n=ye(e,t,st);return e[n]===void 0?void 0:n},n=(n,r,i,a,o,s)=>{let c={kind:n,first:r,last:r,children:[]},l={index:t(i)};for(;l.index!==void 0&&e[l.index]!==a;){let n=o(l.index);if(!n)return;c.children.push(n);let r=t(n.last+1);if(r===void 0)return;let i=e.startsWith(s,r)?r+s.length:r;l.index=t(i)}if(l.index!==void 0)return c.last=l.index,c},r=(n,r)=>{let i=o(n);if(!i)return;let a=t(i.last+1);if(a===void 0||!e.startsWith(r,a))return;let s=t(a+r.length),c=s===void 0?void 0:o(s);if(c)return{kind:`Pair`,first:n,last:c.last,children:[i,c]}},i=t=>{let n=ye(e,t,ct);if(e.startsWith(`..`,n)&&ct(e[n+2]))return{kind:`Constant`,first:t,last:ye(e,n+2,ct)-1,children:[]}},a=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=ct(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:ye(e,t+1,ct)-1,children:[]};if(lt(n))return{kind:`Constant`,first:t,last:ye(e,t,lt)-1,children:[]}},o=i=>{let s=t(i);if(s!==void 0)switch(e[s]){case`{`:return n(`Set`,s,s+1,`}`,o,`,`);case`<`:{let t=n(`Sequence`,s,s+2,`>`,o,`,`);return!t||t.last+1>=e.length?void 0:{...t,last:t.last+1}}case`[`:return n(`Record`,s,s+1,`]`,e=>r(e,`|->`),`,`);case`(`:return n(`Function`,s,s+1,`)`,e=>r(e,`:>`),`@@`);default:{if(!e.startsWith(`SUBSET`,s))return a(s);let n=t(s+6),r=n===void 0?void 0:o(n);return r?{kind:`Subset`,first:s,last:r.last,children:[r]}:void 0}}};return o(0)},dt=e=>{let t=e.length===0?void 0:ut(e);if(!t||t.last<e.length-1)return e;let n=t=>e.slice(t.first,t.last+1),r=e=>e.last-e.first+1,i=(e,t,i,s)=>{if(r(e)<=t-i||e.kind===`Constant`)return n(e);if(e.kind===`Pair`)return;let c=ot[e.kind],l=t-Math.max(c.open.length,c.pad.length),u=i+c.close.length,d=s+c.pad,f=e.kind===`Function`||e.kind===`Record`?o(e.children,l,u,d,c):a(e.children,l,u,d,c.separator);return f===void 0?void 0:c.open+f+c.close},a=(e,t,n,r,a)=>{let o=e.map((o,s)=>{let c=s===e.length-1,l=i(o,t,c?n:a.length,r);return l===void 0||c?l:`${l}${a}\n${r}`});return o.includes(void 0)?void 0:o.join(``)},o=(e,t,a,o,s)=>{let c=e.map((c,l)=>{let u=l===e.length-1,d=c.children[0],f=c.children[1],p=u?``:`${s.separator}\n${o}`,m=r(d)+s.divider.length+1+r(f);if(u?m<=t-a:m+s.separator.length<=t)return`${n(d)}${s.divider} ${n(f)}${p}`;let h=r(d)+s.divider.length<=t?n(d):i(d,t,a+s.divider.length,o),g=i(f,t-s.dividerPad.length,u?a:s.separator.length,o+s.dividerPad);return h===void 0||g===void 0?void 0:`${h}${s.divider}\n${o}${s.dividerPad}${g}${p}`});return c.includes(void 0)?void 0:c.join(``)};return i(t,80,0,``)??e},N=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,ft=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),P=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),F=e=>typeof e==`object`&&e.kind===`ModelValue`,pt=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:N(e)?`set`:`function`,mt=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new S(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},ht={isUsed:!1},gt=(e,t)=>(ht.isUsed=!0,e.writtenKeys=t,e),_t=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[Sr(e.domain,t)]]),vt=(e,t,n)=>gt(tn(e,t),n),yt=e=>{if(!(typeof e!=`object`||e.kind!==`Function`&&e.kind!==`Set`)&&e.hash===0&&e.fingerprint===0){if(e.kind===`Set`)return e.elements.forEach(yt);e.writtenKeys=void 0,e.range.forEach(yt)}},bt=e=>e.every(e=>typeof e==`string`),xt=(e,t)=>e.length>0&&t.length>0&&bt(e)!==bt(t),St=(e,t)=>{ht.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return xt(n,r)?Cn(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=zt(i[e],a[e]);if(t!==0)return t}return 0},Ct=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return n.length-r.length;if(n===r)return 0;for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}return 0},wt=e=>F(e)?e.type:void 0,Tt=(e,t,n)=>{let r=wt(e),i=wt(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(F(e)&&F(t)){if(r===void 0||i===void 0||r===i)return;throw new y(`Attempted to ${a} the differently-typed model values ${z(e)} and ${z(t)}`)}throw r===void 0?new y(`Attempted to ${a} the typed model value ${z(t)} and the non-model value\n${z(e)}`):new y(`Attempted to ${a}${n?``:` the`} typed model value ${z(e)} and non-model value\n${z(t)}`)},Et={ranks:Object.create(null),size:0},Dt=e=>{Et.ranks=Object.create(null),Et.size=0,Bt.clear();for(let t of e)At(t)},Ot={is174:!1},kt=e=>{Ot.is174=e===`1.7.4`},At=e=>(Et.ranks[e]===void 0&&(Et.ranks[e]=Et.size++),e),jt=()=>Et.size,Mt=e=>Et.ranks[At(e)],Nt=(e,t)=>{if(e===t)return 0;let n=Et.ranks,r=n[e],i=n[t];return r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},Pt=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),Ft=(e,t)=>(Pt(e)||Pt(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),It=(e,t,n)=>{if(!Pt(e))throw new y(`Attempted to ${n} the set ${z(I(e)?L(e):e,!0)} with the value:\n${z(t,!0)}`);if(!Pt(t))throw new y(`Attempted to compare overridden value ${z(e,!0)} with non-overridden value:\n${z(t,!0)}`);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new y(`Attempted to compare ${z(e,!0)} with the value\n${z(t,!0)}`)},Lt={kind:`InfiniteSet`,name:`Any`},Rt=e=>{throw new y(`Attempted to compare ANY with the value\n${z(e)}`)},zt=(e,t)=>{if(e===t)return ht.isUsed&&yt(e),e===Lt?Rt(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return St(e,t);if(n===`Set`&&r===`Set`)return Ct(e,t);if(n===`Interval`&&r===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.max(0,t.high-t.low+1);return n!==r||n===0?n-r:e.low-t.low}if(n===`ModelValue`&&r===`ModelValue`)return e.type!==void 0&&t.type!==void 0&&Tt(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Tt(e,t,!1),n===`ModelValue`?-1:1;if(e===Lt||t===Lt)return Rt(e===Lt?t:e);if(N(e)&&N(t)&&Ft(e,t))return It(e,t,`compare`);let i=N(e);if(i!==N(t))throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`);return i?Ct(L(e),L(t)):St(Ar(e),Ar(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Nt(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Tt(e,t,!1),F(e))return-1;if(F(t))return 1;throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`)},Bt=/* @__PURE__ */ new Map,Vt=e=>{let t=Bt.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Mt(e)};return Bt.set(e,n),n},Ht=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0,isFingerprinted:!1}),Ut=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0,functionClass:void 0,isFingerprinted:!1}),Wt={isPresent:!1},Gt=(e,t)=>(t===`lambda`&&(Wt.isPresent=!0),t!==void 0&&(e.functionClass=t),e),Kt=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`)?e.functionClass:void 0,qt=e=>Gt(e,`lambda`),Jt=/* @__PURE__ */ new WeakSet,Yt=/* @__PURE__ */ new WeakSet,Xt={isPresent:!1},Zt=e=>(Xt.isPresent=!0,e),Qt=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),$t=e=>{Xt.isPresent&&typeof e==`object`&&Qt.has(e.kind)&&Yt.add(e)},en=e=>{if((Wt.isPresent||Xt.isPresent)&&typeof e==`object`){if(e.kind===`Function`||e.kind===`Set`){if(e.isFingerprinted)return;e.isFingerprinted=!0}else{if(Jt.has(e))return;Jt.add(e)}e.kind===`Function`?(e.functionClass===`lambda`&&(e.functionClass=void 0),e.domain.forEach(en),e.range.forEach(en)):e.kind===`Set`||e.kind===`MixedSet`?e.elements.forEach(en):N(e)&&I(e)&&($t(e),L(e).elements.forEach(en))}},tn=(e,t)=>Gt(Ut(e,t),`record`),nn=(e,t)=>{if($t(e),e===t)return ht.isUsed&&yt(e),e!==Lt||Rt(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Tt(e,t,!0),zt(e,t)===0);if((e.kind===`Set`||e.kind===`Function`)&&(t.kind===`Set`||t.kind===`Function`)&&e.hash!==0&&t.hash!==0&&e.hash!==t.hash)return!1;if(e.kind===`Function`&&t.kind===`Function`)return St(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Ct(e,t)===0;if(F(e)||F(t))return Tt(e,t,!0),F(e)&&F(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return nn(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=R(e.domain),r=R(t.domain);if(n||r)return n===r;let i=R(e.range),a=R(t.range);return i||a?i===a:nn(e.domain,t.domain)&&nn(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){if(R(e))return R(t);if(R(t))return!1;let n=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),r=n(t);return e.names.length===t.names.length&&n(e).every((e,t)=>e[0]===r[t][0]&&nn(e[1],r[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`)return R(e)?R(t):!R(t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>nn(e,t.factors[n]));let n=N(e)&&N(t)&&!(I(e)&&I(t));if(n&&Ft(e,t))return It(e,t,`check equality of`)===0;if(n){if(!Pt(e)){let n=L(e);if(!Pt(t))return Ct(n,L(t))===0}return oi(e)===oi(t)}return zt(e,t)===0},rn=e=>{let t=(e,t)=>e===t||e.length===t.length&&e.every((e,r)=>n(e,t[r])),n=(n,r)=>n===r?!0:typeof n!=`object`||typeof r!=`object`?!1:n.kind===`Set`&&r.kind===`Set`?(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.elements,r.elements):n.kind===`Function`&&r.kind===`Function`?(!e||n.functionClass===r.functionClass)&&(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.domain,r.domain)&&t(n.range,r.range):oi(n)===oi(r);return n},an=rn(!1),on=rn(!0),sn=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},cn=e=>{if(!P(e))return;let t=Ar(e);return{domain:t.domain,range:t.range,low:sn(t.domain)}},ln=e=>{if(!P(e))return;let t=Ar(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},un=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to compare the typed model value ${z(e)} and the non-model value\n${z(t)}`);return 1},dn=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to check equality of the typed model value ${z(e)} and the non-model value\n${z(t)}`);return!1},fn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)?e.rank-t.rank:-1;if(!F(t))throw new y(`Attempted to compare the typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to compare the differently-typed model values ${z(e)} and ${z(t)}`);return e.rank-t.rank},pn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)&&e.name===t.name;if(!F(t))throw new y(`Attempted to check equality of typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to check equality of the differently-typed model values ${z(e)} and ${z(t)}`);return e.name===t.name},mn={number:{name:`integer`,other:`non-integer`,equality:`check equality of`},string:{name:`string`,other:`non-string`,equality:`check equality of`},boolean:{name:`boolean`,other:`non-boolean`,equality:`compare equality of`}},hn=(e,t,n)=>{let r=mn[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${z(e)} with ${r.other}:\n${z(t)}`},gn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return un(n,t);throw new y(`Attempted to compare the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return e.range.length-r.range.length;let i=()=>_n(e.range,r.range);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&r.low!==void 0)return e.low===r.low?i():e.low-r.low;let a=e.low??r.low;if(a===void 0)return _n(e.domain,r.domain)||i();let o=e.low===void 0?e.domain:r.domain;for(let t=0;t<o.length;t++){let n=o[t];if(typeof n!=`number`)throw new y(`Attempted to compare integer with non-integer${e.low===void 0?``:`:`}\n${z(n)}.`);let r=e.low===void 0?n-(a+t):a+t-n;if(r!==0)return r}return i()},_n=(e,t)=>{for(let n=0;n<e.length;n++){let r=Cn(e[n],t[n]);if(r!==0)return r}return 0},vn=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length-r.length||_n(n.range,r):gn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return un(t,e);throw new y(`Attempted to compare record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length-r.domain.length||_n(n.domain,r.domain)||_n(n.range,r.range)}return gn({...n,low:sn(n.domain)},e,t)},yn=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),bn=(e,t)=>Pt(e)||Pt(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),xn=(e,t)=>{let n=yn(t)?t:L(t);return{elements:L(e).elements,otherElements:L(n).elements}},Sn=(e,t)=>{if(bn(e,t))return zt(e,t);if(!yn(e))return Sn(L(e),t);if(!N(t)){if(F(t))return un(t,e);throw new y(`Attempted to compare the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length-n.otherElements.length||_n(n.elements,n.otherElements)},Cn=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return zt(e,t);if(F(t))return un(t,e);throw new y(hn(e,t,!1))}return e.kind===`ModelValue`?fn(e,t):P(e)?vn(e,t):Sn(e,t)},wn=(e,t)=>e.every((e,n)=>On(e,t[n])),Tn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return dn(n,t);throw new y(`Attempted to check equality of the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return!1;if(e.low!==void 0&&r.low!==void 0)return(e.range.length===0||e.low===r.low)&&wn(e.range,r.range);let i=e.low??r.low;return i===void 0?wn(e.domain,r.domain)&&wn(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new y(`Attempted to compare an integer with non-integer:\n${z(e)}.`);return e===i+t})&&wn(e.range,r.range)},En=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length===r.length&&wn(n.range,r):Tn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length===r.domain.length&&wn(n.domain,r.domain)&&wn(n.range,r.range)}return Tn({...n,low:sn(n.domain)},e,t)},Dn=(e,t)=>{if(bn(e,t))return nn(e,t);if(!yn(e))return Dn(L(e),t);if(!N(t)){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length===n.otherElements.length&&wn(n.elements,n.otherElements)},On=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(F(t))return dn(t,e);throw new y(hn(e,t,!0))}return e.kind===`ModelValue`?pn(e,t):P(e)?En(e,t):Dn(e,t)},kn=e=>{let t=[];for(let n of e){let e=jn(n,t);e.isFound||t.splice(e.index,0,n)}return t},An=(e,t)=>{let n=Tr.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},jn=(e,t)=>{let n={low:0,high:t.length};for(;n.low<n.high;){let r=n.low+(n.high-n.low>>1),i=An(e,()=>Cn(e,t[r]));if(i===0)return{index:r,isFound:!0};i<0?n.high=r:n.low=r+1}return{index:n.low,isFound:!1}},Mn=(e,t)=>t.some(t=>An(t,()=>On(t,e))),Nn=/* @__PURE__ */ new WeakSet,Pn=e=>{typeof e==`object`&&(e.kind===`Set`&&(Nn.add(e),e.elements.forEach(Pn)),e.kind===`Function`&&(e.domain.forEach(Pn),e.range.forEach(Pn)))},Fn=(e,t)=>Er(()=>nn(e,t),()=>On(e,t)),In=e=>{for(let t=1;t<e.length;t++)if(zt(e[t-1],e[t])>=0)return!1;return!0},Ln=e=>{for(let t=1;t<e.length;t++)$t(e[t]);if(e.length<2||In(e))return Ht(e);let t=[...e].sort(zt),n=[t[0]];for(let e=1;e<t.length;e++)zt(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ht(n)},Rn=e=>Er(()=>Ln(e),()=>({kind:`MixedSet`,elements:e})),zn=Ht([]),Bn=(e,t)=>{if(e.elements.length===0||t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ht(i)},Vn=(e,t)=>{let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ht(i)},Hn=(e,t)=>{if(e.elements.length===0)return t;if(t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=[],o=0,s=0;for(;o<n.length&&s<r.length;){let e=zt(n[o],r[s]);e<0?i.push(n[o++]):e>0?(a.push(r[s]),i.push(r[s++])):(i.push(n[o++]),s++)}for(;o<n.length;)i.push(n[o++]);for(;s<r.length;)a.push(r[s]),i.push(r[s++]);if(a.length===0)return e;let c=Ht(i);if(e.hash!==0&&e.hash!==Kr){let t=e.hash,n=0;for(;n<a.length;n++){let e=Zr(a[n]);if(e===Kr)break;t=t+Wr(e)|0}n===a.length&&(c.hash=t)}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+ti(a[e])|0;c.fingerprint=t}return c},Un=e=>{let t=e.length<2?e:[...e].sort((e,t)=>zt(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&zt(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Ut(n,r)},Wn=e=>{let t=Un(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:gt(t,e.map(e=>e[0]))},Gn=[],Kn=[],qn=/* @__PURE__ */ new WeakMap,Jn=e=>{let t=Gn[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Gn[e]=n,n},Yn=e=>{if(yr(e),e.low===1&&e.high>=1)return Jn(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Xn=e=>e.length>0&&(e===Gn[e.length]||qn.has(e)),Zn=e=>{let t=L(e).elements;return Xn(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Qn=e=>{let t=Kn[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return Kn[e]=n,n},$n=e=>Gt(Ut(Jn(e.length),e),`tuple`),er=e=>Gt(Un(e),`record`),tr=e=>N(e)&&!Pt(e),nr=(e,t=!1)=>`UNION(${z(e.base,t)})`,rr=(e,t=e=>L(e).elements)=>{if(!tr(e.base))throw new y(`Attempted to enumerate the nonenumerable set:\n${nr(e)}`);return t(e.base)},ir=(e,t,n)=>{if(tr(e))return e;throw new y(t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${z(e)}\nwhen enumerating:\n${nr(n)}`)},I=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`InfiniteSet`:case`SequenceSet`:return!1;case`Subset`:case`FilteredSet`:return I(e.base);case`FunctionSet`:return I(e.domain)&&I(e.range)||ar(e.domain)===!0||ar(e)===!0;case`RecordSet`:return e.sets.every(I)||ar(e)===!0;case`ProductSet`:return e.factors.every(I)||ar(e)===!0;case`Union`:return I(e.base)&&pr(e.base).every(I);case`SetOperation`:return e.operator===`\\cup`?I(e.left)&&I(e.right):e.operator===`\\cap`?I(e.left)||I(e.right):I(e.left);default:return!1}},ar=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:return e.name===`Any`&&void 0;case`Subset`:case`SequenceSet`:return!1;case`FunctionSet`:{let t=ar(e.domain);return t===void 0?void 0:!t&&ar(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=ar(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return I(e)?L(e).elements.length===0:void 0;default:return}},or=e=>{let t=e.reduce((e,t)=>e*t.length,1),n=[],r=e.map(()=>0);for(let i=0;i<t;i++){n.push(e.map((e,t)=>e[r[t]]));for(let t=e.length-1;t>=0&&(r[t]++,!(r[t]<e[t].length));t--)r[t]=0}return n},sr=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]<t-e.length+n){e[n]++;for(let t=n+1;t<e.length;t++)e[t]=e[t-1]+1;return!0}return!1},cr=e=>{if(typeof e!=`object`||e.kind!==`Subset`||Pt(e.base))return;let t=L(e.base).elements;if(t.length<=30)return;let n={index:-1,indices:[0]},r=e=>{for(e<=n.index&&(n.index=-1);n.index<e;)n.index===-1?n.indices=[]:sr(n.indices,t.length)||(n.indices=Array.from({length:n.indices.length+1},(e,t)=>t)),n.index++;return Ht(n.indices.map(e=>t[e]))},i=2**t.length,a=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<i;return new Proxy([],{get:(e,t,n)=>t===`length`?i:a(t)?r(Number(t)):Reflect.get(e,t,n),has:(e,t)=>a(t)||Reflect.has(e,t)})},lr=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Ht(r.map(t=>e[t])));while(sr(r,e.length))}return t},ur=(e,t,n)=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i];if(Pt(a))throw new y(n(a,i));let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},dr=(e,t=e=>L(e).elements)=>{if(typeof e!=`object`)throw new y(`Expected a set but found ${z(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return kn(e.elements);case`Interval`:{let t=Yn(e);return t!==Gn[t.length]&&qn.set(t,e),t}case`Subset`:{if(yr(e.base)===0)return lr([]);if(!N(e.base))throw new y(`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${dt(z(e.base))}`);let t=L(e.base).elements;if(t.length>30)throw new y(vr(e));return lr(t)}case`FunctionSet`:{if(!Ot.is174&&R(e))return[];if(Pt(e.domain))throw new y(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${z(e.domain)}\ncannot be enumerated.`);let n=Zn(e.domain);if((n.length>0||Ot.is174)&&Pt(e.range))throw new y(`Attempted to enumerate a set of the form [D -> R],but the range R:\n${z(e.range)}\ncannot be enumerated.`);let r=n.length===0?[]:t(e.range);return or(n.map(()=>r)).map(e=>Ut(n,e))}case`RecordSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.sets,t,(t,n)=>`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[n]}' field:\n${z(t)}`);return or(n).map(t=>er(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.factors,t,(e,t)=>`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${z(e)}`);return or(n).map($n)}case`FilteredSet`:if(!N(e.base)||Pt(e.base))throw new y(`Attempted to enumerate { x \\in S : p(x) } when S:\n${z(e.base)}\nis not enumerable`);return L(e.base).elements.filter(e.test);case`Union`:{let t=rr(e).flatMap((t,n)=>L(ir(t,n,e)).elements);return L(Rn(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(!tr(e.left)||!tr(e.right)))throw new y(`Attempted to enumerate S \\cup T when S:\n${z(e.left)}\nand T:\n${z(e.right)}\nare not both enumerable`);if(e.operator===`\\cap`&&!tr(e.left)&&!tr(e.right))throw new y(`Attempted to enumerate S \\cap T when neither S:\n${z(e.left)}\nnor T:\n${z(e.right)}\nis enumerable`);if(e.operator===`\\`&&!tr(e.left))throw new y(`Attempted to enumerate S \\ T when S:\n${z(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return Hn(L(e.left),L(e.right)).elements;let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return L(n).elements.filter(t=>Dr(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to enumerate the non-enumerable set ${z(e)}`);default:throw new y(`Expected a set but found ${z(e)}`)}},fr=/* @__PURE__ */ new WeakMap,L=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ht(dr(e));let t=typeof e==`object`?fr.get(e):void 0;if(t)return t;let n=Tr.sets;n?.push(e);let r=dr(e);n?.pop();let i=typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Ht(r):Ln(r);return typeof e==`object`&&fr.set(e,i),i},pr=e=>{if(typeof e!=`object`||Yt.has(e))return L(e).elements;let t=Tr.sets;t?.push(e);let n=gr(e);return t?.pop(),n},mr=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,hr=e=>typeof e!=`object`||Yt.has(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?hr(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||hr(e.left)||hr(e.right):mr(e)?.some(hr)??!1,gr=e=>{if(e.kind===`Union`)return rr(e,pr).flatMap((t,n)=>pr(ir(t,n,e)));if(e.kind===`FilteredSet`&&!Pt(e.base))return pr(e.base).filter(e.test);if(mr(e)?.some(hr))return dr(e,pr);if(e.kind!==`SetOperation`)return L(e).elements;if(e.operator===`\\cup`)return!tr(e.left)||!tr(e.right)?L(e).elements:[...pr(e.left),...pr(e.right)];let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return tr(n)?pr(n).filter(t=>Dr(t,r)===(e.operator===`\\cap`)):L(e).elements},R=e=>{if(typeof e!=`object`||!N(e))throw new y(`Shouldn't call isEmpty() on value ${z(e)}`);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:if(e.name===`Any`)throw new y(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1;case`ProductSet`:return e.factors.some(R);case`RecordSet`:return e.sets.some(R);case`FunctionSet`:return!R(e.domain)&&R(e.range);case`Union`:return rr(e).every((t,n)=>R(ir(t,n,e)));default:return L(e).elements.length===0}},_r=(e,t,n)=>e.reduce((e,r)=>{let i=e*yr(r,t);if(i>2147483647)throw new y(n());return i},1),vr=e=>`Overflow when computing the number of elements in:\n${z(e)}`,yr=(e,t)=>{if(typeof e!=`object`)throw new y(`Attempted to compute the number of elements in the ${typeof e==`number`?`integer`:typeof e==`string`?`string`:`boolean`} ${z(e)}.`);switch(e.kind){case`ModelValue`:throw new y(`Attempted to compute the number of elements in the model value ${z(e)}.`);case`Function`:return e.domain.length;case`LazyFunction`:return yr(e.domain,t);case`Interval`:{let t=Math.max(0,e.high-e.low+1);if(t>2147483647)throw new y(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to compute the number of elements in the overridden value ${z(e)}.`);case`Subset`:{let n=yr(e.base,t);if(n>=31)throw new y(vr(e));return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(R(e.domain))return 1;if(R(e.range))return 0;if(yr(e.range,t)===1)return 1}let n=yr(e.domain,t),r=yr(e.range,t);if(r<=1)return n===0?1:r;let i={value:1};for(let t=0;t<n;t++)if(i.value*=r,i.value>2147483647)throw new y(vr(e));return i.value}case`RecordSet`:return t!==`1.7.4`&&R(e)?0:_r(e.sets,t,()=>vr(e));case`ProductSet`:return t!==`1.7.4`&&R(e)?0:_r(e.factors,t,()=>`Overflow when computing the number of elements in ${z(e)}`);default:return $t(e),L(e).elements.length}},br=e=>`Attempted to check if the set ${z(e)}is finite.`,xr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new y(`Attempted to check if the ${pt(e)} ${z(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new y(`Attempted to check if the function:\n${z(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return xr(e.base)&&R(e.base);case`Subset`:return xr(e.base);case`FunctionSet`:{let t=xr(e.domain);if(t&&R(e.domain))return!0;let n=xr(e.range);return n&&R(e.range)?!0:n&&(t||yr(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n={isAllFinite:!0};for(let e of t)if(!xr(e))n.isAllFinite=!1;else if(R(e))return!0;return n.isAllFinite}case`Union`:if(!tr(e.base))throw new y(`Attempted to check if the nonenumerable set:\n${nr(e)}\nis a finite set.`);return L(e.base).elements.every(xr);case`SetOperation`:if(e.operator===`\\cup`)return xr(e.left)&&xr(e.right);if(e.operator===`\\cap`){if(!xr(e.left)&&!xr(e.right))throw new y(br(e));return!0}if(xr(e.left))return!0;if(!xr(e.right))throw new y(br(e));return!1;case`FilteredSet`:if(!xr(e.base))throw new y(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${z(e.base)}\nis finite.`);return!0}},Sr=(e,t,n=zt)=>{let r={low:0,high:e.length-1};for(;r.low<=r.high;){let i=r.low+r.high>>1,a=n(e[i],t);if(a===0)return i;a<0?r.low=i+1:r.high=i-1}return-1},Cr=e=>{if(typeof e!=`object`||!P(e))return;let t=Ar(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},wr=(e,t)=>{let n=`Attempted to check if the value:\n${z(e)}\nis an element of the`;if(!P(t))return`${n} ${pt(t)} ${z(t)}`;let r=Kt(t);return r===`record`?`Attempted to check if element:\n${z(e)}\nis in the record:\n${z(t)}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${z(t)}`},Tr={sets:void 0},Er=(e,t)=>{let n=Tr.sets,r=Tr.callStack,i=n?.length??0,a=r&&{...r,length:r.expressions.length};try{return e()}catch(e){if(!(e instanceof y))throw e;return n&&(n.length=i),r&&a&&(r.expressions.length=a.length,r.isFrozen=a.isFrozen,r.fingerprint=a.fingerprint),t(e)}},Dr=(e,t)=>{let n=Tr.sets;if(n===void 0)return Or(e,t);n.push(t);let r=Or(e,t);return n.pop(),r},Or=(e,t)=>{if(!N(t))throw new y(wr(e,t));switch(t.kind){case`Set`:return $t(e),Er(()=>Sr(t.elements,e)!==-1,()=>Nn.has(t)?jn(e,t.elements).isFound:Mn(e,t.elements));case`MixedSet`:return Mn(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!F(e))throw new y(`Attempted to check if the value:\n${z(e)}\nis in the integer interval ${z(t)}`);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(F(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new y(`Attempted to check if the value:\n${z(e)}\nis an element of ${t.name}.`);return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:if(!N(e)||Pt(e))throw new y(`Attempted to check if the non-enumerable value\n${dt(z(e))}\nis element of\n${dt(z(t))}`);return L(e).elements.every(e=>Dr(e,t.base));case`FunctionSet`:{if(!P(e)){if(F(e))return!1;throw new y(`Attempted to check if \n${z(e)}\nwhich is not a TLC function value, is in the set of functions:\n${dt(z(t))}`)}let n=Ar(e),r=sn(n.domain);return(r===void 0?Fn(t.domain,Ht(n.domain)):Fn({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>Dr(e,t.range))}case`RecordSet`:{let n=P(e)?Ar(e):void 0;if(!n||!bt(n.domain)){if(F(e))return!1;throw new y(`Attempted to check if non-record\n${z(e)}\nis in the set of records:\n${z(t)}`)}return n.domain.length===t.names.length&&t.names.every((e,r)=>{let i=Sr(n.domain,e);return i!==-1&&Dr(n.range[i],t.sets[r])})}case`ProductSet`:{let n=P(e)?Cr(e):void 0;if(n===void 0){if(P(e)&&Ar(e).domain.every(e=>typeof e==`number`)||F(e))return!1;throw new y(`Attempted to check if non-tuple\n${z(e)}\nis in the set of tuples:\n${z(t)}`)}return n.length===t.factors.length&&n.every((e,n)=>Dr(e,t.factors[n]))}case`FilteredSet`:return Dr(e,t.base)&&t.test(e);case`Union`:if(!tr(t.base))throw new y(`Attempted to check if:\n ${z(e)}\nis an element of the non-enumerable set:\n ${nr(t)}`);return L(t.base).elements.some(t=>Dr(e,t));case`SetOperation`:return t.operator===`\\cup`?Dr(e,t.left)||Dr(e,t.right):Dr(e,t.left)&&Dr(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Cr(e);if(n===void 0){if(F(e))return!1;throw new y(`Attempted to check if the value:\n${dt(z(e))}\nis an element of ${dt(z(t))}.`)}return n.every(e=>Dr(e,t.base))}default:throw new y(wr(e,t))}},kr=(e,t,n)=>e===t?!0:typeof e!=`object`||typeof t!=`object`||typeof n!=`object`||e.kind!==`Function`||t.kind!==`Function`||n.kind!==`FunctionSet`||e.domain!==t.domain?Dr(e,n):e.range.every((e,r)=>kr(e,t.range[r],n.range)),Ar=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){I(e.domain)||yr(e.domain);let t=Zn(e.domain);return Gt(Ut(t,t.map(t=>e.apply(t))),Kt(e))}throw new y(`Expected a function but found ${z(e)}`)},jr=(e,t,n)=>{let r=dt(z(e)),i=dt(z(t)),a=n===`1.7.4`;switch(Kt(e)){case`lambda`:return`In applying the function\n${r},\nthe first argument is:\n${i}\nwhich is not in its domain.\n`;case`tuple`:return typeof t==`number`?a?`Attempted to apply tuple\n${r}\nto integer ${t} which is out of domain.`:`Attempted to access index ${t} of tuple\n${r}\nwhich is out of bounds.`:a?`Attempted to apply tuple to a non-integer argument.`:`Attempted to access tuple at a non integral index: ${i}`;case`record`:return typeof t==`string`?a?`Attempted to apply the record\n${r}\nto nonexistent record field ${t}.`:`Attempted to access nonexistent field '${t}' of record\n${r}`:a?`Attempted to apply record to a non-string value ${i}.`:`Attempted to access record by a non-string argument: ${i}`;default:return`Attempted to apply function:\n${r}\nto argument ${i}, which is not in the domain of the function.`}},Mr=(e,t)=>{if(!Ot.is174)return jr(e,t);let n=dt(z(t));return Kt(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},Nr=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}if(e.length<=8){for(let n=0;n<e.length;n++)if(e[n]===t)return n}return Sr(e,t)},Pr=e=>new y(`Attempted to apply function with integer domain to the non-integer argument ${dt(z(e))}`),Fr=(e,t,n)=>{let r=e.domain;if(typeof t!=typeof r[0]){let i=Kt(e),a=i===`tuple`?`number`:i===`record`?`string`:void 0;if(a!==void 0&&typeof t!==a)throw new y(n(e,t));if(a===void 0&&!Ot.is174&&Xn(r))throw Pr(t)}return Er(()=>Nr(r,t),e=>{throw Ot.is174||r.length<32?r.forEach(e=>On(e,t)):Sr(r,t,Cn),e})},Ir=(e,t,n)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!Dr(t,e.domain))throw new y(Kt(e)===`lambda`?jr(e,t):`Attempted to apply a function to ${z(t)}, which is not in its domain`);return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new y(`Attempted to apply ${z(e)}, which is not a function`);let r=n??jr,i=Fr(e,t,r);if(i===-1)throw new y(r(e,t));return e.range[i]},Lr=e=>Xn(e)?qn.get(e)??Qn(e.length):void 0,Rr=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=Ar(e).domain;return Lr(t)??Ht(t)},zr=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!I(e.domain))){if(!Dr(t,e.domain))return e;let r=n(e.apply(t));return Gt({kind:`LazyFunction`,domain:e.domain,apply:n=>Fn(t,n)?r:e.apply(n),source:e.source},Kt(e))}if(!P(e))throw new y(`Attempted to apply EXCEPT construct to the value ${dt(z(e))}.`);let i=Ar(e),a=Fr(i,t,Mr);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=Gt(Ut(i.domain,o),Kt(i));if(l.writtenKeys=i.writtenKeys,i.hash!==0&&i.hash!==Kr){let e=Zr(c);if(e!==Kr){let t=Zr(i.domain[a]);l.hash=s===c?i.hash:i.hash-Gr(t,Zr(s))+Gr(t,e)|0}}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-ni(e,s)+ni(e,c)|0}return l},Br=/* @__PURE__ */ new WeakMap,Vr=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Hr=(e,t)=>Math.imul(e^t,16777619),Ur=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Vr(t)},Wr=e=>Vr(e+2654435769|0),Gr=(e,t)=>Vr(Math.imul(e,668265261)+t|0),Kr=795548749,qr=e=>{if(e.kind===`ModelValue`)return Vr(Hr(Ur(e.name),109));if(N(e)){if(!I(e))return Kr;let t=L(e).elements,n=1940243425;for(let e=0;e<t.length;e++){let r=Zr(t[e]);if(r===Kr)return Kr;n=n+Wr(r)|0}return n}if(e.kind===`LazyFunction`&&!I(e.domain))return Kr;let t=Ar(e),n=1725019383;for(let e=0;e<t.domain.length;e++){let r=Zr(t.domain[e]),i=Zr(t.range[e]);if(r===Kr||i===Kr)return Kr;n=n+Gr(r,i)|0}return n},Jr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return;if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw new y(`TLC has found a state in which the value of a variable contains ${z(e)}`);if(N(e)){L(e).elements.forEach(Jr);return}let t=Ar(e);t.domain.forEach(Jr),t.range.forEach(Jr)},Yr=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{Zr(e)===Kr&&Jr(e);return}catch(e){if(!(e instanceof y))throw e;return e}},Xr=e=>{switch(e.kind){case`Set`:case`MixedSet`:return e.elements;case`Function`:return[...e.domain,...e.range];case`Subset`:case`SequenceSet`:case`FilteredSet`:case`Union`:return[e.base];case`FunctionSet`:return[e.domain,e.range];case`RecordSet`:return e.sets;case`ProductSet`:return e.factors;case`SetOperation`:return[e.left,e.right];case`LazyFunction`:return[e.domain];default:return[]}},Zr=e=>{if(typeof e==`number`)return Vr(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Ur(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=qr(e)),e.hash;let t=Br.get(e);if(t!==void 0)return t;let n=qr(e);return Br.set(e,n),n},Qr=/* @__PURE__ */ new WeakMap,$r=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},ei=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return $r(t)},ti=e=>$r(ii(e)+2135587861|0),ni=(e,t)=>$r(Math.imul(ii(e),374761393)+ii(t)|0),ri=e=>{if(e.kind===`ModelValue`)return $r(ei(e.name)^60);if(N(e)){if(!I(e))return ei(oi(e));let t=L(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+ti(t[e])|0;return n}let t=Ar(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+ni(t.domain[e],t.range[e])|0;return n},ii=e=>{if(typeof e==`number`)return $r(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return ei(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=ri(e)),e.fingerprint;let t=Qr.get(e);if(t!==void 0)return t;let n=ri(e);return Qr.set(e,n),n},ai=/* @__PURE__ */ new WeakMap,oi=e=>{if(typeof e==`boolean`)return e?`T`:`F`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return JSON.stringify(e);let t=ai.get(e);if(t!==void 0)return t;let n=si(e);return ai.set(e,n),n},si=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${oi(e.base)}>`;if(e.kind===`FilteredSet`&&!I(e))throw new y(`Attempted to compare the non-enumerable set ${z(e)} with another value`);if(N(e))return I(e)?`{${L(e).elements.map(oi).join(`,`)}}`:`<${e.kind} ${z(e)}>`;let t=Ar(e);return`(${t.domain.map((e,n)=>`${oi(e)}:${oi(t.range[n])}`).join(`,`)})`},ci=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,li=e=>e.reduce((e,t)=>e===0?0:e*yr(t),1),ui=e=>{if(e.kind===`Subset`)return yr(e.base)<=6?L(e):void 0;if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return L(e);if(e.kind===`FunctionSet`&&I(e.domain)&&yr(e.domain)===0)return Ht([Ut([],[])]);let t=e.kind===`FunctionSet`?yr(e.range)**yr(e.domain):li(e.kind===`RecordSet`?e.sets:e.factors);return t===0?zn:t<=1999?L(e):void 0},di=(e,t)=>{if(t)return ui(e);if(I(e))try{return ui(e)}catch(e){if(e instanceof y)return;throw e}},fi=(e,t)=>{let n=e=>z(e,t);switch(e.kind){case`Subset`:return typeof e.base==`object`&&e.base.kind===`Interval`?`SUBSET (${n(e.base)})`:`SUBSET ${n(e.base)}`;case`FunctionSet`:return`[${n(e.domain)} -> ${n(e.range)}]`;case`RecordSet`:return`[${e.names.map((t,r)=>`${t}: ${n(e.sets[r])}`).join(`, `)}]`;case`ProductSet`:return`(${e.factors.map(n).join(` \\X `)})`;case`SetOperation`:return`${n(e.left)} ${e.operator} ${n(e.right)}`;case`FilteredSet`:return e.source?`{${e.source.names} \\in ${n(e.base)} : <expression ${e.source.predicate}> }`:`{x \\in ${n(e.base)} : ...}`;case`Union`:return nr(e,t)}},pi=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),mi=e=>{if(I(e.domain))try{return Ar(e)}catch(e){if(e instanceof y)return;throw e}},z=(e,t=!1,n=!1)=>{let r=e=>z(e,t,n);if(typeof e==`boolean`)return e?`TRUE`:`FALSE`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return ci(e);switch(e.kind){case`ModelValue`:return e.name;case`Set`:return`{${e.elements.map(r).join(`, `)}}`;case`MixedSet`:return r(L(e));case`Interval`:return e.low<=e.high?`${e.low}..${e.high}`:`{}`;case`InfiniteSet`:return e.name===`Any`?`ANY`:e.name;case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let n=di(e,t);return n?r(n):fi(e,t)}case`SequenceSet`:return`Seq(${r(e.base)})`;case`Function`:case`LazyFunction`:{let i=e.kind===`LazyFunction`?mi(e):e;if(i===void 0){let t=e.kind===`LazyFunction`?e.source:void 0;return t?`[${t.parameters.map(e=>`${e.name} \\in ${z(e.domain)}`).join(`, `)} |-> <expression ${t.body}>]`:`<function>`}if(i.domain.length===0&&Ot.is174&&Kt(e)!==`tuple`)return`<< >>`;let a=r=>z(r,t,n&&Kt(e)!==`lambda`);return i.domain.every((e,t)=>e===t+1)?`<<${i.range.map(a).join(`, `)}>>`:Kt(e)===`record`||i.domain.every(e=>typeof e==`string`&&pi(e))?`[${(n||i.hash!==0||i.fingerprint!==0?i.domain.map((e,t)=>[e,i.range[t]]):_t(i)).map(e=>`${String(e[0])} |-> ${a(e[1])}`).join(`, `)}]`:`(${i.domain.map((e,t)=>`${r(e)} :> ${a(i.range[t])}`).join(` @@ `)})`}}},hi=e=>{let t=Object.entries(e);return t.map(([e,n])=>`${t.length===1?``:`/\\ `}${e} = ${dt(z(n))}\n`).join(``)},gi=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},_i=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=Zr(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||on(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||on(i[e],n))return i[e]}return n.kind===`Set`?gi(n.elements,t):(gi(n.domain,t),gi(n.range,t)),i===void 0?e.set(r,n):Array.isArray(i)?i.push(n):e.set(r,[i,n]),n};return e=>{for(let n=0;n<e.length;n++)e[n]=t(e[n]);return e}},vi=e=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return[];case`Apply`:return e.args;case`Lambda`:return[e.body];case`And`:case`Or`:return e.operands;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`If`:return[e.condition,e.consequent,e.alternative];case`Case`:return[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]];case`Let`:return[...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),e.body];case`Forall`:case`Exists`:return[...e.bounds.map(e=>e.set),e.body];case`UnboundedQuantifier`:return[e.body];case`Choose`:return[...e.set?[e.set]:[],e.body];case`SetEnumeration`:case`Tuple`:return e.elements;case`SetFilter`:return[e.bound.set,e.predicate];case`SetMap`:return[e.expression,...e.bounds.map(e=>e.set)];case`FunctionConstruction`:return[...e.bounds.map(e=>e.set),e.body];case`FunctionSet`:return[e.domain,e.range];case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`Except`:return[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])];case`FunctionApplication`:return[e.function,...e.args];case`Bracket`:return e.args;case`FieldAccess`:return[e.record];case`Product`:return e.factors;case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`Label`:return[e.body];case`Subexpression`:return e.selectors.flatMap(e=>`args`in e?e.args:[])}},B=e=>(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`,yi=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),bi=(e,t)=>yi.has(e)?new y(t):new S(t),xi=e=>typeof e==`object`&&e.kind===`Operator`,V=(e,t,n)=>{let r=e[t];if(r===void 0||xi(r))throw bi(n,`${n} expects a value as argument ${t+1}`);return r},Si=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`number`)throw bi(n,`${n} expects an integer but received ${z(r)}`);return r},Ci=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`boolean`)throw bi(n,`${n} expects a boolean but received ${z(r)}`);return r},wi=(e,t,n)=>{let r=V(e,t,n);if(!N(r))throw bi(n,`${n} expects a set but received ${z(r)}`);return r},Ti=(e,t,n)=>{let r=wi(e,t,n);if(!I(r))throw bi(n,`${n} cannot enumerate the non-enumerable set ${z(r)}`);return r},Ei=(e,t,n)=>L(Ti(e,t,n)),Di=(e,t,n)=>Ei(e,t,n).elements,Oi=(e,t,n)=>{let r=V(e,t,n),i=Cr(r);if(!i)throw bi(n,`${n} expects a sequence but received ${z(r)}`);return i},ki=(e,t,n)=>{let r=V(e,t,n);if(!P(r))throw bi(n,`${n} expects a function but received ${z(r)}`);return Ar(r)},Ai=(e,t,n)=>{let r=e[t];if(r===void 0||!xi(r))throw bi(n,`${n} expects an operator as argument ${t+1}`);return r},ji=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),H=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:t===1?e=>n([e]):void 0,evaluateBinary:t===2?(e,t)=>n([e,t]):void 0}),Mi=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Ni=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),Pi=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(V(n,0,e),V(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Fi=e=>e>2147483647||e<-2147483648,Ii=e=>new S(`Overflow when computing ${e}`),Li={ModelValue:`ModelValue`,Set:`SetEnumValue`,Interval:`IntervalValue`,InfiniteSet:`UserValue`,SequenceSet:`UserValue`,Subset:`SubsetValue`,FunctionSet:`SetOfFcnsValue`,RecordSet:`SetOfRcdsValue`,ProductSet:`SetOfTuplesValue`,FilteredSet:`SetPredValue`,LazyFunction:`FcnLambdaValue`,Union:`UnionValue`,MixedSet:`SetEnumValue`},Ri={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},zi={BoolValue:`a Boolean value`,IntValue:`an integer`,StringValue:`a string`,RecordValue:`a record`,SetEnumValue:`a set of the form {e1, ... ,eN}`,SetPredValue:`a set of the form {x \\in S : expr}`,TupleValue:`a tuple`,FcnLambdaValue:`a function of the form [x \\in S |-> expr]`,FcnRcdValue:`a function of the form (d1 :> e1 @@ ... @@ dN :> eN)`,SetOfFcnsValue:`a set of the form [S -> T]`,SetOfRcdsValue:`a set of the form [d1 : S1, ... , dN : SN]`,SetOfTuplesValue:`a cartesian product`,SubsetValue:`a set of the form SUBSET S`,SetDiffValue:`a set of the form S \\ T`,SetCapValue:`a set of the form S \\cap T`,SetCupValue:`a set of the form S \\cup T`,ModelValue:`a model value`,UserValue:`a special set constant`,IntervalValue:`a set of the form i..j`,UnionValue:`a set of the form UNION S`},Bi={lambda:`FcnLambdaValue`,tuple:`TupleValue`,record:`RecordValue`},Vi=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Ri[e.operator];if(e.kind!==`Function`)return Li[e.kind];let t=Kt(e);return t===void 0?`FcnRcdValue`:Bi[t]},Hi=e=>zi[Vi(e)],Ui=(e,t)=>new y(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),Wi=(e,t)=>{let n=n=>(...r)=>{let i=Tr.sets?.length??0;try{return n(...r)}catch(n){throw n instanceof y&&(e.isLazy===!0||!(n instanceof S))?(Tr.sets&&(Tr.sets.length=i),Ui(t,n.message)):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},Gi=(e,t)=>{if(typeof e!=`number`)throw Ui(t,`Cannot cast tlc2.value.impl.${Vi(e)} to tlc2.value.impl.IntValue`);return e},Ki=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,qi=(e,t,n,r)=>{let i=Ki(e,n,`IntValue`,2);return Pi(t,(e,n)=>{let a=Gi(e,i),o=Gi(n,i),s=r(a,o);if(Fi(s))throw Ii(`${a}${t}${o}`);return s})},Ji=(e,t,n)=>{if(typeof e!=`number`)throw new S(`The ${t} argument of ${n} should be an integer, but instead it is:\n${z(e)}`);return e},Yi=(e,t,n=e)=>Pi(e,(e,r)=>t(Ji(e,`first`,n),Ji(r,`second`,n))),Xi=(e,t,n)=>({...Ni(e,t,n),isLazy:!0}),Zi=(e,t,n)=>{let r=Ai(e,t,n);return()=>r.call([])},Qi=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),$i=()=>({bool:gl,condition:(e,t)=>{if(typeof e!=`boolean`)throw nl(t,e);return e},junct:(e,t,n)=>{if(typeof e!=`boolean`)throw rl(t,n,e);return e},apply:Ir,expectFunction:pl,tuple:$n,set:Rn,record:tn,writtenRecord:vt,equal:nn,enumerate:Dl,unassigned:(e,t)=>{throw Dd(e,t)},primeOutsideAction:e=>{throw kd(e)},prime:e=>({environment:e.environment,scope:e.scope,state:e.next,next:void 0,isKeepLazy:e.isKeepLazy}),keepLazyContext:ml,extend:(e,t,n)=>({environment:e.environment,scope:t.reduce((e,t,r)=>dl(e,t,n[r]),e.scope),state:e.state,next:e.next,isKeepLazy:e.isKeepLazy})}),ea={value:void 0},ta=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),na=e=>`local${e.counter++}`,ra=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),vi(e).forEach(e=>ra(e,t)),t),ia=(e,t,n)=>{let r=ta(e,Wu(t,e.environment)),i=ra(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=ta(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},aa=(e,t,n)=>{let r=t.kind===`Forall`,i=JSON.stringify(r?`the body of \\A`:`the body of \\E`),a=`quantifier${e.counter++}`,o=[...n.locals.values()],s={context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:new Map(n.locals)},c=t.bounds.map(()=>na(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${ca(e,t.set,s)}, ${ta(e,t.set)}, ${JSON.stringify(e.environment.runtime.version)});`),u=t.bounds.map(t=>{let n=na(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${ca(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=na(e),a=na(e),o=na(e),s=c[r];return`for (let ${i} = 0, ${a} = ${s}.low, ${o} = ${a} === undefined ? ${s}.length : ${s}.high - ${a} + 1; ${i} < ${o}; ${i}++) { const ${n} = ${a} === undefined ? ${s}[${i}] : ${a} + ${i}; ${t} }`},d),p=o.map(e=>`, ${e}`).join(``);return e.helpers.push(`function ${a}(context, state, next${p}) { let primed; ${l.join(` `)} ${f} return ${r}; }`),`${a}(${n.context}, ${n.state}, ${n.isPrimed?`undefined`:n.next}${p})`},oa=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${ca(e,r[0],n)}, "the left side of =>") ? bool(${ca(e,r[1],n)}, "the right side of =>") : true)`;if(B(t))return ia(e,t,n);let i=$l(t.operator,e.environment);if(i?.kind!==`Builtin`)return ia(e,t,n);if(i.name===`DOMAIN`)return`${ta(e,ol(t))}(${ca(e,r[0],n)})`;if(i.name===`TLCEval`)return ia(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${ta(e,sl(t,i))}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&Zu(r[0],a))return`${ta(e,i.evaluateUnary)}(${ca(e,r[0],n)})`;let o=r.length===2&&Zu(r[0],a)&&Zu(r[1],a);return i.evaluateBinary&&o?`${ta(e,i.evaluateBinary)}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`:ia(e,t,n)},sa=(e,t,n)=>{switch(e.kind){case`Identifier`:{if(t.locals.has(e.name))return!0;if(B(e))return!1;let r=lu(e.name,n);return r?.kind===`Variable`||r?.kind===`Value`}case`Prime`:return sa(e.expression,t,n);case`FieldAccess`:return sa(e.record,t,n);case`FunctionApplication`:return[e.function,...e.args].every(e=>sa(e,t,n));default:return!1}},ca=(e,t,n)=>{let r=(t,r=n)=>ca(e,t,r);if(Fu(t)&&Au(t,e.environment))return ia(e,t,n);switch(t.kind){case`Number`:return _u(t.value)?String(t.value):ia(e,t,n);case`String`:return JSON.stringify(t.value);case`Identifier`:{let r=n.locals.get(t.name);if(r)return r;if(B(t))return ia(e,t,n);let i=lu(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=ta(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?ta(e,i.value):ia(e,t,n)}case`Apply`:return oa(e,t,n);case`And`:case`Or`:{let n=ta(e,t),i=t.kind===`And`?` && `:` || `;return`(${t.operands.map((e,t)=>`junct(${r(e)}, ${n}, ${t})`).join(i)})`}case`If`:return`(condition(${r(t.condition)}, ${ta(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{xd(t.function);let i=`expectFunction(${sa(t.function,n,e.environment)?r(t.function):ia(e,t.function,{...n,context:`keepLazyContext(${n.context})`})}, ${ta(e,t)})`,a=al(e.environment.runtime.version),o=a?`, ${ta(e,a)}`:``;return t.args.length===1?`apply(${i}, ${r(t.args[0])}${o})`:`apply(${i}, tuple([${t.args.map(e=>r(e)).join(`, `)}])${o})`}case`FieldAccess`:return`${ta(e,il(t))}(${r(t.record)})`;case`Record`:{let i=Td(t.fields);if(Ed(i))return ia(e,t,n);let a=ta(e,i.map(e=>e.name)),o=`[${i.map(e=>r(e.value)).join(`, `)}]`,s=t.fields.map(e=>e.name);return s.every((e,t)=>e===i[t].name)?`record(${a}, ${o})`:`writtenRecord(${a}, ${o}, ${ta(e,s)})`}case`Tuple`:return`tuple([${t.elements.map(e=>r(e)).join(`, `)}])`;case`SetEnumeration`:return`set([${t.elements.map(e=>r(e)).join(`, `)}])`;case`Prime`:{let i=ta(e,t);if(n.isPrimed)return`primeOutsideAction(${i})`;let a={context:`(primed ??= prime(${n.context}))`,state:n.next,next:`undefined`,isPrimed:!0,locals:n.locals};return`(${n.next} === undefined ? primeOutsideAction(${i}) : ${r(t.expression,a)})`}case`Unchanged`:return`equal(${r({kind:`Prime`,expression:t.expression,location:t.location})}, ${r(t.expression)})`;case`Forall`:case`Exists`:return t.bounds.every(e=>e.pattern.kind===`Name`)?aa(e,t,n):ia(e,t,n);default:return ia(e,t,n)}},la=(e,t)=>{if(!Qi.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=ca(n,e,{context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:/* @__PURE__ */ new Map}),i=n.references.map((e,t)=>`reference${t}`),a=`${n.helpers.join(`
29
29
  `)}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${r}; };`;ea.value??=$i();let o=ea.value,s=Object.keys(o);return Function(...s,...i,a)(...Object.values(o),...n.references)},ua={general:1e3,commandLineError:1102,initialState:2102,nestedExpression:2103,assumptionFalse:2104,assumptionEvaluationError:2105,exceptAppliedToUnknownField:2144,fingerprintFailed:2147,invariantViolatedInitial:2107,incompleteSuccessor:2109,propertyViolatedInitial:2108,invariantViolatedBehavior:2110,invariantEvaluationFailed:2111,actionPropertyViolatedBehavior:2112,actionPropertyEvaluationFailed:2113,deadlockReached:2114,temporalPropertyViolated:2116,behaviorUpToThisPoint:2121,backToState:2122,constantLevelInvariant:2149,javaOverrideLoaded:2168,starting:2185,modelChecking:2187,finished:2186,computingInit:2189,initGenerated1:2190,initGenerated2:2191,checkingTemporal:2192,success:2193,searchDepth:2194,stats:2199,progress:2200,temporalBranches:2212,statePrint2:2217,statePrint3:2218,sanyFinished:2219,startingSany:2220,stateLevelProperty:2255,version:2262,noSpecificationButProperty:2257,noFairnessButProperty:2259,counterExample:2264,checkingTemporalEnd:2267,stateGraphOutdegree:2268,computingInitProgress:2269,livenessSymmetry:2279,livenessConstraints:2284,symmetrySetTooSmall:2300,javaOverrideMismatch:2400,postconditionFalse:2404,postconditionFailed:2405,possibleUnwitnessed:2780,parsingFailed:3002,configFileError:5001},da={none:0,error:1,warning:3,state:4},fa={0:``,1:`Error: `,3:`Warning: `,4:`State `},pa=(e,t=!0,n=`master`)=>{let r=/* @__PURE__ */ new Set;return{isTool:e,version:n,print:(n,i,a)=>{let o=i===da.warning;if(o&&!t)return;let s=o&&!e&&r.size===0?`
30
30
  (Use the -nowarning option to disable this warning.)`:``,c=e?`@!@!@STARTMSG ${n}:${i} @!@!@\n${a}\n@!@!@ENDMSG ${n} @!@!@`:`${fa[i]}${a}${s}`;o&&r.has(c)||(o&&r.add(c),console.log(c))}}},ma=`The configuration file did not specify the initial state predicate.
31
31
  Can also be caused by trying to run TLC on a specification from
package/dist/transfer.js CHANGED
@@ -25,7 +25,7 @@ to an element in its putative domain.`;var x=class extends y{constructor(){super
25
25
  \r`.includes(e[t]))n.offset++;else if(e.startsWith(`(*`,t)||e.startsWith(`\\*`,t)){let e=o();if(e!==void 0)return e}else{let i=ze(e,t);if(i.length===0){let n=We(e,t),r=Math.min(t+n.length+1,e.length),i=e.slice(t,r),o=r<e.length?n:i.length>1?i:``;return a(t,r,o)}let o=r(i.kind,t,i.length);return n.offset+=i.length,o}}return i()}},Ke=/* @__PURE__ */ new Map([[`\b`,`\\b`],[` `,`\\t`],[`
26
26
  `,`\\n`],[`\f`,`\\f`],[`\r`,`\\r`],[`"`,`\\"`],[`'`,`\\'`],[`\\`,`\\\\`]]),qe=e=>e.replace(/[\0-\x1f"'\\\x7f-\uffff]/g,e=>Ke.get(e)??(e===`\0`?``:`\\u${e.charCodeAt(0).toString(16).padStart(4,`0`)}`)),Je=(e,t,n,r)=>`Lexical error at line ${e}, column ${t}. Encountered: ${n===void 0?`<EOF> `:`"${qe(n)}" (${n.charCodeAt(0)}), `}after : "${qe(r)}"`,Ye=e=>{let t=Ge(e);for(let e=t();typeof e!=`string`&&e.kind!==A(`EOF`);e=t()){let t=e.image.split(``).findIndex(e=>{let t=e.charCodeAt(0);return t>255&&(t&255)<128});if(t===-1)continue;let n=e.image.slice(1,t+1).split(``).reduce((e,t)=>t===` `?Be(e):e+1,e.beginColumn);return Je(e.beginLine,n,e.image[t],e.image.slice(0,t))}},Xe=[`CONSTANT`,`CONSTANTS`,`INIT`,`NEXT`,`SPECIFICATION`,`INVARIANT`,`INVARIANTS`,`PROPERTY`,`PROPERTIES`,`CONSTRAINT`,`CONSTRAINTS`,`ACTION_CONSTRAINT`,`ACTION_CONSTRAINTS`,`SYMMETRY`,`VIEW`,`CHECK_DEADLOCK`],Ze=/* @__PURE__ */ new Set([...Xe,`ALIAS`,`POSTCONDITION`,`POSTCONDITIONS`,`_POSSIBLE`,`_PERIODIC`,`_RL_REWARD`]),Qe=[`TYPE`,`TYPE_CONSTRAINT`],$e=/* @__PURE__ */ new Set([...Xe,...Qe]),et=[`<-`,`<<`,`>>`,`=`,`{`,`}`,`,`,`[`,`]`,`(`,`)`,`!`],tt=e=>{let t=[],n={index:0,line:1,lineStart:0},r=(r,i)=>{t.push({kind:`Error`,text:Je(n.line,r-n.lineStart+1,e[r],i),line:n.line})},i=e=>{t.push({kind:`Error`,text:Je(n.line+1,0,void 0,e),line:n.line})},a=e=>{let t=e.split(`
27
27
  `);t.length>1&&(n.line+=t.length-1,n.lineStart=n.index+e.length-t[t.length-1].length),n.index+=e.length};for(;n.index<e.length;){let o=e.slice(n.index),s=/^\s+/.exec(o)?.[0];if(s){a(s);continue}if(o.startsWith(`\\*`)){let e=o.indexOf(`
28
- `);a(e===-1?o:o.slice(0,e));continue}if(o.startsWith(`(*`)){let e=o.indexOf(`*)`);if(e===-1)return a(o),i(``),t;a(o.slice(0,e+2));continue}let c=n.line,l=/^\d+(?![A-Za-z_])/.exec(o)?.[0];if(l){t.push({kind:`Number`,text:l,line:c}),a(l);continue}let u=/^[A-Za-z0-9_]+/.exec(o)?.[0];if(u){t.push({kind:`Word`,text:u,line:c}),a(u);continue}if(o.startsWith(`"`)){let s=/^"((?:[^"\\\n]|\\[^\n])*)("?)/.exec(o),l=s?.[0]??`"`;if(s?.[2]!==`"`)return a(l),n.index===e.length?i(`${l}\n`):r(n.index,l),t;t.push({kind:`String`,text:s[1],line:c}),a(l);continue}let d=et.find(e=>o.startsWith(e));if(d){t.push({kind:`Symbol`,text:d,line:c}),a(d);continue}let f=_e(e,n.index)??O(e,n.index);if(!f)return r(n.index,``),t;t.push({kind:`Word`,text:f.text,line:c}),a(e.slice(n.index,n.index+f.length))}return t.push({kind:`End`,text:``,line:n.line}),t},nt=(e,t)=>new v(`TLC found an error in the configuration file at line ${e}\n${t}`),rt=(e,t)=>nt(e,`The keyword ${t} appeared twice.`),M=/* @__PURE__ */ new Map([[`INIT`,`init`],[`NEXT`,`next`],[`SPECIFICATION`,`specification`],[`VIEW`,`view`],[`SYMMETRY`,`symmetry`],[`ALIAS`,`alias`],[`_PERIODIC`,`periodic`],[`_RL_REWARD`,`rlReward`]]),it=/* @__PURE__ */ new Map([[`INVARIANT`,`invariants`],[`INVARIANTS`,`invariants`],[`PROPERTY`,`properties`],[`PROPERTIES`,`properties`],[`CONSTRAINT`,`constraints`],[`CONSTRAINTS`,`constraints`],[`ACTION_CONSTRAINT`,`actionConstraints`],[`ACTION_CONSTRAINTS`,`actionConstraints`],[`POSTCONDITION`,`postconditions`],[`POSTCONDITIONS`,`postconditions`],[`_POSSIBLE`,`possible`]]),at=(e,t=`master`)=>{let n=t===`1.7.4`?$e:Ze,r=tt(e),i={index:0},a={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},o={isSet:!1},s=/* @__PURE__ */ new Set,c=()=>{let e=r[Math.min(i.index++,r.length-1)];if(e.kind===`Error`)throw new v(`TLC found an error in the configuration file:\n${e.text}`);return e},l=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t={token:c()};if(t.token.text!==`}`)for(;e.push(l(t.token)),t.token=c(),t.token.text===`,`;)t.token=c();if(t.token.text!==`}`)throw nt(t.token.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw nt(e.line,`It was expecting a value, but did not find it.`)},u=e=>{let t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after ${e}[.`);let n=c();if(n.text!==`]`)throw nt(n.line,`It was expecting ], but did not find it.`);return t.text},d=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;let r={token:c(),name:t.text};for(;r.token.text===`!`;)r.name=`${r.name}!${c().text}`,r.token=c();let i=r.name;if(r.token.text===`<-`){if(r.token=c(),r.token.text===`[`){let e=u(`<-`),t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after <-[mod].`);a.substitutions.push({name:i,target:t.text,module:e});continue}if(r.token.kind===`End`)throw nt(r.token.line,`Expected an identifier after <-.`);a.substitutions.push({name:i,target:r.token.text});continue}let o=[],s=r.token.text===`(`;if(s){for(;o.push(l(c())),r.token=c(),r.token.text===`,`;);if(r.token.text!==`)`)throw nt(e,``);r.token=c()}if(r.token.text!==`=`)throw nt(r.token.line,`It was expecting = or <-, but did not find it.`);r.token=c();let d=r.token.text===`[`?u(`=`):void 0,f=l(d===void 0?r.token:c());a.constants.push({name:i,value:f,...s&&{args:o},...d!==void 0&&{module:d}})}},f=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;e.push(t.text)}},p={token:c()};for(;p.token.kind!==`End`;){let e=p.token.text,t=p.token.line,r=n.has(e)?M.get(e):void 0,i=n.has(e)?it.get(e):void 0,l=()=>{let n=c();if(n.kind===`End`)throw nt(t,`The keyword ${e} was not followed by an identifier.`);return n};if(r!==void 0){let n=l();if(a[r]!==void 0)throw rt(t,e);a[r]=n.text,p.token=c()}else if(i!==void 0)p.token=f(a[i]);else if(e===`CONSTANT`||e===`CONSTANTS`)p.token=d(t);else if(e===`CHECK_DEADLOCK`){let n=l();if(n.text!==`TRUE`&&n.text!==`FALSE`)throw nt(n.line,`It was expecting TRUE or FALSE, but did not find it.`);if(o.isSet)throw rt(t,e);o.isSet=!0,a.checkDeadlock=n.text===`TRUE`,p.token=c()}else{if(!n.has(e)||!Qe.includes(e))throw nt(t,`It was expecting a keyword, but did not find it.`);if(l(),s.has(e))throw rt(t,e);s.add(e),p.token=c()}}return a},ot={Set:{open:`{ `,close:` }`,pad:` `,separator:`,`,divider:``,dividerPad:``},Sequence:{open:`<< `,close:` >>`,pad:` `,separator:`,`,divider:``,dividerPad:``},Subset:{open:`SUBSET `,close:` `,pad:` `,separator:`,`,divider:``,dividerPad:``},Function:{open:`( `,close:` )`,pad:` `,separator:` @@`,divider:` :>`,dividerPad:` `},Record:{open:`[ `,close:` ]`,pad:` `,separator:`,`,divider:` |->`,dividerPad:` `}},st=e=>{if(e===void 0)return!1;let t=e.charCodeAt(0);return t>=9&&t<=13||t>=28&&t<=32||t===5760||t>=8192&&t<=8202&&t!==8199||t===8232||t===8233||t===8287||t===12288},ct=e=>e!==void 0&&/^\p{Nd}$/u.test(e),lt=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),ut=e=>{let t=t=>{let n=ye(e,t,st);return e[n]===void 0?void 0:n},n=(n,r,i,a,o,s)=>{let c={kind:n,first:r,last:r,children:[]},l={index:t(i)};for(;l.index!==void 0&&e[l.index]!==a;){let n=o(l.index);if(!n)return;c.children.push(n);let r=t(n.last+1);if(r===void 0)return;let i=e.startsWith(s,r)?r+s.length:r;l.index=t(i)}if(l.index!==void 0)return c.last=l.index,c},r=(n,r)=>{let i=o(n);if(!i)return;let a=t(i.last+1);if(a===void 0||!e.startsWith(r,a))return;let s=t(a+r.length),c=s===void 0?void 0:o(s);if(c)return{kind:`Pair`,first:n,last:c.last,children:[i,c]}},i=t=>{let n=ye(e,t,ct);if(e.startsWith(`..`,n)&&ct(e[n+2]))return{kind:`Constant`,first:t,last:ye(e,n+2,ct)-1,children:[]}},a=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=ct(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:ye(e,t+1,ct)-1,children:[]};if(lt(n))return{kind:`Constant`,first:t,last:ye(e,t,lt)-1,children:[]}},o=i=>{let s=t(i);if(s!==void 0)switch(e[s]){case`{`:return n(`Set`,s,s+1,`}`,o,`,`);case`<`:{let t=n(`Sequence`,s,s+2,`>`,o,`,`);return!t||t.last+1>=e.length?void 0:{...t,last:t.last+1}}case`[`:return n(`Record`,s,s+1,`]`,e=>r(e,`|->`),`,`);case`(`:return n(`Function`,s,s+1,`)`,e=>r(e,`:>`),`@@`);default:{if(!e.startsWith(`SUBSET`,s))return a(s);let n=t(s+6),r=n===void 0?void 0:o(n);return r?{kind:`Subset`,first:s,last:r.last,children:[r]}:void 0}}};return o(0)},dt=e=>{let t=e.length===0?void 0:ut(e);if(!t||t.last<e.length-1)return e;let n=t=>e.slice(t.first,t.last+1),r=e=>e.last-e.first+1,i=(e,t,i,s)=>{if(r(e)<=t-i||e.kind===`Constant`)return n(e);if(e.kind===`Pair`)return;let c=ot[e.kind],l=t-Math.max(c.open.length,c.pad.length),u=i+c.close.length,d=s+c.pad,f=e.kind===`Function`||e.kind===`Record`?o(e.children,l,u,d,c):a(e.children,l,u,d,c.separator);return f===void 0?void 0:c.open+f+c.close},a=(e,t,n,r,a)=>{let o=e.map((o,s)=>{let c=s===e.length-1,l=i(o,t,c?n:a.length,r);return l===void 0||c?l:`${l}${a}\n${r}`});return o.includes(void 0)?void 0:o.join(``)},o=(e,t,a,o,s)=>{let c=e.map((c,l)=>{let u=l===e.length-1,d=c.children[0],f=c.children[1],p=u?``:`${s.separator}\n${o}`,m=r(d)+s.divider.length+1+r(f);if(u?m<=t-a:m+s.separator.length<=t)return`${n(d)}${s.divider} ${n(f)}${p}`;let h=r(d)+s.divider.length<=t?n(d):i(d,t,a+s.divider.length,o),g=i(f,t-s.dividerPad.length,u?a:s.separator.length,o+s.dividerPad);return h===void 0||g===void 0?void 0:`${h}${s.divider}\n${o}${s.dividerPad}${g}${p}`});return c.includes(void 0)?void 0:c.join(``)};return i(t,80,0,``)??e},N=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,ft=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),P=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),F=e=>typeof e==`object`&&e.kind===`ModelValue`,pt=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:N(e)?`set`:`function`,mt=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new S(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},ht={isUsed:!1},gt=(e,t)=>(ht.isUsed=!0,e.writtenKeys=t,e),_t=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[Sr(e.domain,t)]]),vt=(e,t,n)=>gt(tn(e,t),n),yt=e=>{if(!(typeof e!=`object`||e.kind!==`Function`&&e.kind!==`Set`)&&e.hash===0&&e.fingerprint===0){if(e.kind===`Set`)return e.elements.forEach(yt);e.writtenKeys=void 0,e.range.forEach(yt)}},bt=e=>e.every(e=>typeof e==`string`),xt=(e,t)=>e.length>0&&t.length>0&&bt(e)!==bt(t),St=(e,t)=>{ht.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return xt(n,r)?Cn(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=zt(i[e],a[e]);if(t!==0)return t}return 0},Ct=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return n.length-r.length;if(n===r)return 0;for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}return 0},wt=e=>F(e)?e.type:void 0,Tt=(e,t,n)=>{let r=wt(e),i=wt(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(F(e)&&F(t)){if(r===void 0||i===void 0||r===i)return;throw new y(`Attempted to ${a} the differently-typed model values ${z(e)} and ${z(t)}`)}throw r===void 0?new y(`Attempted to ${a} the typed model value ${z(t)} and the non-model value\n${z(e)}`):new y(`Attempted to ${a}${n?``:` the`} typed model value ${z(e)} and non-model value\n${z(t)}`)},Et={ranks:Object.create(null),size:0},Dt=e=>{Et.ranks=Object.create(null),Et.size=0,Bt.clear();for(let t of e)At(t)},Ot={is174:!1},kt=e=>{Ot.is174=e===`1.7.4`},At=e=>(Et.ranks[e]===void 0&&(Et.ranks[e]=Et.size++),e),jt=()=>Et.size,Mt=e=>Et.ranks[At(e)],Nt=(e,t)=>{if(e===t)return 0;let n=Et.ranks,r=n[e],i=n[t];return r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},Pt=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),Ft=(e,t)=>(Pt(e)||Pt(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),It=(e,t,n)=>{if(!Pt(e))throw new y(`Attempted to ${n} the set ${z(I(e)?L(e):e,!0)} with the value:\n${z(t,!0)}`);if(!Pt(t))throw new y(`Attempted to compare overridden value ${z(e,!0)} with non-overridden value:\n${z(t,!0)}`);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new y(`Attempted to compare ${z(e,!0)} with the value\n${z(t,!0)}`)},Lt={kind:`InfiniteSet`,name:`Any`},Rt=e=>{throw new y(`Attempted to compare ANY with the value\n${z(e)}`)},zt=(e,t)=>{if(e===t)return ht.isUsed&&yt(e),e===Lt?Rt(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return St(e,t);if(n===`Set`&&r===`Set`)return Ct(e,t);if(n===`Interval`&&r===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.max(0,t.high-t.low+1);return n!==r||n===0?n-r:e.low-t.low}if(n===`ModelValue`&&r===`ModelValue`)return e.type!==void 0&&t.type!==void 0&&Tt(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Tt(e,t,!1),n===`ModelValue`?-1:1;if(e===Lt||t===Lt)return Rt(e===Lt?t:e);if(N(e)&&N(t)&&Ft(e,t))return It(e,t,`compare`);let i=N(e);if(i!==N(t))throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`);return i?Ct(L(e),L(t)):St(Ar(e),Ar(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Nt(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Tt(e,t,!1),F(e))return-1;if(F(t))return 1;throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`)},Bt=/* @__PURE__ */ new Map,Vt=e=>{let t=Bt.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Mt(e)};return Bt.set(e,n),n},Ht=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0}),Ut=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0,functionClass:void 0}),Wt={isPresent:!1},Gt=(e,t)=>(t===`lambda`&&(Wt.isPresent=!0),t!==void 0&&(e.functionClass=t),e),Kt=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`)?e.functionClass:void 0,qt=e=>Gt(e,`lambda`),Jt=/* @__PURE__ */ new WeakSet,Yt=/* @__PURE__ */ new WeakSet,Xt={isPresent:!1},Zt=e=>(Xt.isPresent=!0,e),Qt=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),$t=e=>{Xt.isPresent&&typeof e==`object`&&Qt.has(e.kind)&&Yt.add(e)},en=e=>{!Wt.isPresent&&!Xt.isPresent||typeof e!=`object`||Jt.has(e)||(Jt.add(e),e.kind===`Function`?(e.functionClass===`lambda`&&(e.functionClass=void 0),e.domain.forEach(en),e.range.forEach(en)):e.kind===`Set`||e.kind===`MixedSet`?e.elements.forEach(en):N(e)&&I(e)&&($t(e),L(e).elements.forEach(en)))},tn=(e,t)=>Gt(Ut(e,t),`record`),nn=(e,t)=>{if($t(e),e===t)return ht.isUsed&&yt(e),e!==Lt||Rt(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Tt(e,t,!0),zt(e,t)===0);if((e.kind===`Set`||e.kind===`Function`)&&(t.kind===`Set`||t.kind===`Function`)&&e.hash!==0&&t.hash!==0&&e.hash!==t.hash)return!1;if(e.kind===`Function`&&t.kind===`Function`)return St(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Ct(e,t)===0;if(F(e)||F(t))return Tt(e,t,!0),F(e)&&F(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return nn(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=R(e.domain),r=R(t.domain);if(n||r)return n===r;let i=R(e.range),a=R(t.range);return i||a?i===a:nn(e.domain,t.domain)&&nn(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){if(R(e))return R(t);if(R(t))return!1;let n=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),r=n(t);return e.names.length===t.names.length&&n(e).every((e,t)=>e[0]===r[t][0]&&nn(e[1],r[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`)return R(e)?R(t):!R(t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>nn(e,t.factors[n]));let n=N(e)&&N(t)&&!(I(e)&&I(t));if(n&&Ft(e,t))return It(e,t,`check equality of`)===0;if(n){if(!Pt(e)){let n=L(e);if(!Pt(t))return Ct(n,L(t))===0}return oi(e)===oi(t)}return zt(e,t)===0},rn=e=>{let t=(e,t)=>e===t||e.length===t.length&&e.every((e,r)=>n(e,t[r])),n=(n,r)=>n===r?!0:typeof n!=`object`||typeof r!=`object`?!1:n.kind===`Set`&&r.kind===`Set`?(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.elements,r.elements):n.kind===`Function`&&r.kind===`Function`?(!e||n.functionClass===r.functionClass)&&(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.domain,r.domain)&&t(n.range,r.range):oi(n)===oi(r);return n},an=rn(!1),on=rn(!0),sn=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},cn=e=>{if(!P(e))return;let t=Ar(e);return{domain:t.domain,range:t.range,low:sn(t.domain)}},ln=e=>{if(!P(e))return;let t=Ar(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},un=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to compare the typed model value ${z(e)} and the non-model value\n${z(t)}`);return 1},dn=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to check equality of the typed model value ${z(e)} and the non-model value\n${z(t)}`);return!1},fn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)?e.rank-t.rank:-1;if(!F(t))throw new y(`Attempted to compare the typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to compare the differently-typed model values ${z(e)} and ${z(t)}`);return e.rank-t.rank},pn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)&&e.name===t.name;if(!F(t))throw new y(`Attempted to check equality of typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to check equality of the differently-typed model values ${z(e)} and ${z(t)}`);return e.name===t.name},mn={number:{name:`integer`,other:`non-integer`,equality:`check equality of`},string:{name:`string`,other:`non-string`,equality:`check equality of`},boolean:{name:`boolean`,other:`non-boolean`,equality:`compare equality of`}},hn=(e,t,n)=>{let r=mn[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${z(e)} with ${r.other}:\n${z(t)}`},gn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return un(n,t);throw new y(`Attempted to compare the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return e.range.length-r.range.length;let i=()=>_n(e.range,r.range);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&r.low!==void 0)return e.low===r.low?i():e.low-r.low;let a=e.low??r.low;if(a===void 0)return _n(e.domain,r.domain)||i();let o=e.low===void 0?e.domain:r.domain;for(let t=0;t<o.length;t++){let n=o[t];if(typeof n!=`number`)throw new y(`Attempted to compare integer with non-integer${e.low===void 0?``:`:`}\n${z(n)}.`);let r=e.low===void 0?n-(a+t):a+t-n;if(r!==0)return r}return i()},_n=(e,t)=>{for(let n=0;n<e.length;n++){let r=Cn(e[n],t[n]);if(r!==0)return r}return 0},vn=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length-r.length||_n(n.range,r):gn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return un(t,e);throw new y(`Attempted to compare record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length-r.domain.length||_n(n.domain,r.domain)||_n(n.range,r.range)}return gn({...n,low:sn(n.domain)},e,t)},yn=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),bn=(e,t)=>Pt(e)||Pt(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),xn=(e,t)=>{let n=yn(t)?t:L(t);return{elements:L(e).elements,otherElements:L(n).elements}},Sn=(e,t)=>{if(bn(e,t))return zt(e,t);if(!yn(e))return Sn(L(e),t);if(!N(t)){if(F(t))return un(t,e);throw new y(`Attempted to compare the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length-n.otherElements.length||_n(n.elements,n.otherElements)},Cn=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return zt(e,t);if(F(t))return un(t,e);throw new y(hn(e,t,!1))}return e.kind===`ModelValue`?fn(e,t):P(e)?vn(e,t):Sn(e,t)},wn=(e,t)=>e.every((e,n)=>On(e,t[n])),Tn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return dn(n,t);throw new y(`Attempted to check equality of the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return!1;if(e.low!==void 0&&r.low!==void 0)return(e.range.length===0||e.low===r.low)&&wn(e.range,r.range);let i=e.low??r.low;return i===void 0?wn(e.domain,r.domain)&&wn(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new y(`Attempted to compare an integer with non-integer:\n${z(e)}.`);return e===i+t})&&wn(e.range,r.range)},En=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length===r.length&&wn(n.range,r):Tn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length===r.domain.length&&wn(n.domain,r.domain)&&wn(n.range,r.range)}return Tn({...n,low:sn(n.domain)},e,t)},Dn=(e,t)=>{if(bn(e,t))return nn(e,t);if(!yn(e))return Dn(L(e),t);if(!N(t)){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length===n.otherElements.length&&wn(n.elements,n.otherElements)},On=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(F(t))return dn(t,e);throw new y(hn(e,t,!0))}return e.kind===`ModelValue`?pn(e,t):P(e)?En(e,t):Dn(e,t)},kn=e=>{let t=[];for(let n of e){let e=jn(n,t);e.isFound||t.splice(e.index,0,n)}return t},An=(e,t)=>{let n=Tr.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},jn=(e,t)=>{let n={low:0,high:t.length};for(;n.low<n.high;){let r=n.low+(n.high-n.low>>1),i=An(e,()=>Cn(e,t[r]));if(i===0)return{index:r,isFound:!0};i<0?n.high=r:n.low=r+1}return{index:n.low,isFound:!1}},Mn=(e,t)=>t.some(t=>An(t,()=>On(t,e))),Nn=/* @__PURE__ */ new WeakSet,Pn=e=>{typeof e==`object`&&(e.kind===`Set`&&(Nn.add(e),e.elements.forEach(Pn)),e.kind===`Function`&&(e.domain.forEach(Pn),e.range.forEach(Pn)))},Fn=(e,t)=>Er(()=>nn(e,t),()=>On(e,t)),In=e=>{for(let t=1;t<e.length;t++)if(zt(e[t-1],e[t])>=0)return!1;return!0},Ln=e=>{for(let t=1;t<e.length;t++)$t(e[t]);if(e.length<2||In(e))return Ht(e);let t=[...e].sort(zt),n=[t[0]];for(let e=1;e<t.length;e++)zt(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ht(n)},Rn=e=>Er(()=>Ln(e),()=>({kind:`MixedSet`,elements:e})),zn=Ht([]),Bn=(e,t)=>{if(e.elements.length===0||t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ht(i)},Vn=(e,t)=>{let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ht(i)},Hn=(e,t)=>{if(e.elements.length===0)return t;if(t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=[],o=0,s=0;for(;o<n.length&&s<r.length;){let e=zt(n[o],r[s]);e<0?i.push(n[o++]):e>0?(a.push(r[s]),i.push(r[s++])):(i.push(n[o++]),s++)}for(;o<n.length;)i.push(n[o++]);for(;s<r.length;)a.push(r[s]),i.push(r[s++]);if(a.length===0)return e;let c=Ht(i);if(e.hash!==0&&e.hash!==Kr){let t=e.hash,n=0;for(;n<a.length;n++){let e=Zr(a[n]);if(e===Kr)break;t=t+Wr(e)|0}n===a.length&&(c.hash=t)}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+ti(a[e])|0;c.fingerprint=t}return c},Un=e=>{let t=e.length<2?e:[...e].sort((e,t)=>zt(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&zt(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Ut(n,r)},Wn=e=>{let t=Un(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:gt(t,e.map(e=>e[0]))},Gn=[],Kn=[],qn=/* @__PURE__ */ new WeakMap,Jn=e=>{let t=Gn[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Gn[e]=n,n},Yn=e=>{if(yr(e),e.low===1&&e.high>=1)return Jn(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Xn=e=>e.length>0&&(e===Gn[e.length]||qn.has(e)),Zn=e=>{let t=L(e).elements;return Xn(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Qn=e=>{let t=Kn[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return Kn[e]=n,n},$n=e=>Gt(Ut(Jn(e.length),e),`tuple`),er=e=>Gt(Un(e),`record`),tr=e=>N(e)&&!Pt(e),nr=(e,t=!1)=>`UNION(${z(e.base,t)})`,rr=(e,t=e=>L(e).elements)=>{if(!tr(e.base))throw new y(`Attempted to enumerate the nonenumerable set:\n${nr(e)}`);return t(e.base)},ir=(e,t,n)=>{if(tr(e))return e;throw new y(t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${z(e)}\nwhen enumerating:\n${nr(n)}`)},I=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`InfiniteSet`:case`SequenceSet`:return!1;case`Subset`:case`FilteredSet`:return I(e.base);case`FunctionSet`:return I(e.domain)&&I(e.range)||ar(e.domain)===!0||ar(e)===!0;case`RecordSet`:return e.sets.every(I)||ar(e)===!0;case`ProductSet`:return e.factors.every(I)||ar(e)===!0;case`Union`:return I(e.base)&&pr(e.base).every(I);case`SetOperation`:return e.operator===`\\cup`?I(e.left)&&I(e.right):e.operator===`\\cap`?I(e.left)||I(e.right):I(e.left);default:return!1}},ar=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:return e.name===`Any`&&void 0;case`Subset`:case`SequenceSet`:return!1;case`FunctionSet`:{let t=ar(e.domain);return t===void 0?void 0:!t&&ar(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=ar(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return I(e)?L(e).elements.length===0:void 0;default:return}},or=e=>{let t=e.reduce((e,t)=>e*t.length,1),n=[],r=e.map(()=>0);for(let i=0;i<t;i++){n.push(e.map((e,t)=>e[r[t]]));for(let t=e.length-1;t>=0&&(r[t]++,!(r[t]<e[t].length));t--)r[t]=0}return n},sr=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]<t-e.length+n){e[n]++;for(let t=n+1;t<e.length;t++)e[t]=e[t-1]+1;return!0}return!1},cr=e=>{if(typeof e!=`object`||e.kind!==`Subset`||Pt(e.base))return;let t=L(e.base).elements;if(t.length<=30)return;let n={index:-1,indices:[0]},r=e=>{for(e<=n.index&&(n.index=-1);n.index<e;)n.index===-1?n.indices=[]:sr(n.indices,t.length)||(n.indices=Array.from({length:n.indices.length+1},(e,t)=>t)),n.index++;return Ht(n.indices.map(e=>t[e]))},i=2**t.length,a=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<i;return new Proxy([],{get:(e,t,n)=>t===`length`?i:a(t)?r(Number(t)):Reflect.get(e,t,n),has:(e,t)=>a(t)||Reflect.has(e,t)})},lr=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Ht(r.map(t=>e[t])));while(sr(r,e.length))}return t},ur=(e,t,n)=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i];if(Pt(a))throw new y(n(a,i));let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},dr=(e,t=e=>L(e).elements)=>{if(typeof e!=`object`)throw new y(`Expected a set but found ${z(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return kn(e.elements);case`Interval`:{let t=Yn(e);return t!==Gn[t.length]&&qn.set(t,e),t}case`Subset`:{if(yr(e.base)===0)return lr([]);if(!N(e.base))throw new y(`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${dt(z(e.base))}`);let t=L(e.base).elements;if(t.length>30)throw new y(vr(e));return lr(t)}case`FunctionSet`:{if(!Ot.is174&&R(e))return[];if(Pt(e.domain))throw new y(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${z(e.domain)}\ncannot be enumerated.`);let n=Zn(e.domain);if((n.length>0||Ot.is174)&&Pt(e.range))throw new y(`Attempted to enumerate a set of the form [D -> R],but the range R:\n${z(e.range)}\ncannot be enumerated.`);let r=n.length===0?[]:t(e.range);return or(n.map(()=>r)).map(e=>Ut(n,e))}case`RecordSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.sets,t,(t,n)=>`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[n]}' field:\n${z(t)}`);return or(n).map(t=>er(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.factors,t,(e,t)=>`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${z(e)}`);return or(n).map($n)}case`FilteredSet`:if(!N(e.base)||Pt(e.base))throw new y(`Attempted to enumerate { x \\in S : p(x) } when S:\n${z(e.base)}\nis not enumerable`);return L(e.base).elements.filter(e.test);case`Union`:{let t=rr(e).flatMap((t,n)=>L(ir(t,n,e)).elements);return L(Rn(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(!tr(e.left)||!tr(e.right)))throw new y(`Attempted to enumerate S \\cup T when S:\n${z(e.left)}\nand T:\n${z(e.right)}\nare not both enumerable`);if(e.operator===`\\cap`&&!tr(e.left)&&!tr(e.right))throw new y(`Attempted to enumerate S \\cap T when neither S:\n${z(e.left)}\nnor T:\n${z(e.right)}\nis enumerable`);if(e.operator===`\\`&&!tr(e.left))throw new y(`Attempted to enumerate S \\ T when S:\n${z(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return Hn(L(e.left),L(e.right)).elements;let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return L(n).elements.filter(t=>Dr(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to enumerate the non-enumerable set ${z(e)}`);default:throw new y(`Expected a set but found ${z(e)}`)}},fr=/* @__PURE__ */ new WeakMap,L=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ht(dr(e));let t=typeof e==`object`?fr.get(e):void 0;if(t)return t;let n=Tr.sets;n?.push(e);let r=dr(e);n?.pop();let i=typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Ht(r):Ln(r);return typeof e==`object`&&fr.set(e,i),i},pr=e=>{if(typeof e!=`object`||Yt.has(e))return L(e).elements;let t=Tr.sets;t?.push(e);let n=gr(e);return t?.pop(),n},mr=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,hr=e=>typeof e!=`object`||Yt.has(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?hr(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||hr(e.left)||hr(e.right):mr(e)?.some(hr)??!1,gr=e=>{if(e.kind===`Union`)return rr(e,pr).flatMap((t,n)=>pr(ir(t,n,e)));if(e.kind===`FilteredSet`&&!Pt(e.base))return pr(e.base).filter(e.test);if(mr(e)?.some(hr))return dr(e,pr);if(e.kind!==`SetOperation`)return L(e).elements;if(e.operator===`\\cup`)return!tr(e.left)||!tr(e.right)?L(e).elements:[...pr(e.left),...pr(e.right)];let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return tr(n)?pr(n).filter(t=>Dr(t,r)===(e.operator===`\\cap`)):L(e).elements},R=e=>{if(typeof e!=`object`||!N(e))throw new y(`Shouldn't call isEmpty() on value ${z(e)}`);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:if(e.name===`Any`)throw new y(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1;case`ProductSet`:return e.factors.some(R);case`RecordSet`:return e.sets.some(R);case`FunctionSet`:return!R(e.domain)&&R(e.range);case`Union`:return rr(e).every((t,n)=>R(ir(t,n,e)));default:return L(e).elements.length===0}},_r=(e,t,n)=>e.reduce((e,r)=>{let i=e*yr(r,t);if(i>2147483647)throw new y(n());return i},1),vr=e=>`Overflow when computing the number of elements in:\n${z(e)}`,yr=(e,t)=>{if(typeof e!=`object`)throw new y(`Attempted to compute the number of elements in the ${typeof e==`number`?`integer`:typeof e==`string`?`string`:`boolean`} ${z(e)}.`);switch(e.kind){case`ModelValue`:throw new y(`Attempted to compute the number of elements in the model value ${z(e)}.`);case`Function`:return e.domain.length;case`LazyFunction`:return yr(e.domain,t);case`Interval`:{let t=Math.max(0,e.high-e.low+1);if(t>2147483647)throw new y(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to compute the number of elements in the overridden value ${z(e)}.`);case`Subset`:{let n=yr(e.base,t);if(n>=31)throw new y(vr(e));return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(R(e.domain))return 1;if(R(e.range))return 0;if(yr(e.range,t)===1)return 1}let n=yr(e.domain,t),r=yr(e.range,t);if(r<=1)return n===0?1:r;let i={value:1};for(let t=0;t<n;t++)if(i.value*=r,i.value>2147483647)throw new y(vr(e));return i.value}case`RecordSet`:return t!==`1.7.4`&&R(e)?0:_r(e.sets,t,()=>vr(e));case`ProductSet`:return t!==`1.7.4`&&R(e)?0:_r(e.factors,t,()=>`Overflow when computing the number of elements in ${z(e)}`);default:return $t(e),L(e).elements.length}},br=e=>`Attempted to check if the set ${z(e)}is finite.`,xr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new y(`Attempted to check if the ${pt(e)} ${z(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new y(`Attempted to check if the function:\n${z(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return xr(e.base)&&R(e.base);case`Subset`:return xr(e.base);case`FunctionSet`:{let t=xr(e.domain);if(t&&R(e.domain))return!0;let n=xr(e.range);return n&&R(e.range)?!0:n&&(t||yr(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n={isAllFinite:!0};for(let e of t)if(!xr(e))n.isAllFinite=!1;else if(R(e))return!0;return n.isAllFinite}case`Union`:if(!tr(e.base))throw new y(`Attempted to check if the nonenumerable set:\n${nr(e)}\nis a finite set.`);return L(e.base).elements.every(xr);case`SetOperation`:if(e.operator===`\\cup`)return xr(e.left)&&xr(e.right);if(e.operator===`\\cap`){if(!xr(e.left)&&!xr(e.right))throw new y(br(e));return!0}if(xr(e.left))return!0;if(!xr(e.right))throw new y(br(e));return!1;case`FilteredSet`:if(!xr(e.base))throw new y(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${z(e.base)}\nis finite.`);return!0}},Sr=(e,t,n=zt)=>{let r={low:0,high:e.length-1};for(;r.low<=r.high;){let i=r.low+r.high>>1,a=n(e[i],t);if(a===0)return i;a<0?r.low=i+1:r.high=i-1}return-1},Cr=e=>{if(typeof e!=`object`||!P(e))return;let t=Ar(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},wr=(e,t)=>{let n=`Attempted to check if the value:\n${z(e)}\nis an element of the`;if(!P(t))return`${n} ${pt(t)} ${z(t)}`;let r=Kt(t);return r===`record`?`Attempted to check if element:\n${z(e)}\nis in the record:\n${z(t)}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${z(t)}`},Tr={sets:void 0},Er=(e,t)=>{let n=Tr.sets,r=Tr.callStack,i=n?.length??0,a=r&&{...r,length:r.expressions.length};try{return e()}catch(e){if(!(e instanceof y))throw e;return n&&(n.length=i),r&&a&&(r.expressions.length=a.length,r.isFrozen=a.isFrozen,r.fingerprint=a.fingerprint),t(e)}},Dr=(e,t)=>{let n=Tr.sets;if(n===void 0)return Or(e,t);n.push(t);let r=Or(e,t);return n.pop(),r},Or=(e,t)=>{if(!N(t))throw new y(wr(e,t));switch(t.kind){case`Set`:return $t(e),Er(()=>Sr(t.elements,e)!==-1,()=>Nn.has(t)?jn(e,t.elements).isFound:Mn(e,t.elements));case`MixedSet`:return Mn(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!F(e))throw new y(`Attempted to check if the value:\n${z(e)}\nis in the integer interval ${z(t)}`);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(F(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new y(`Attempted to check if the value:\n${z(e)}\nis an element of ${t.name}.`);return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:if(!N(e)||Pt(e))throw new y(`Attempted to check if the non-enumerable value\n${dt(z(e))}\nis element of\n${dt(z(t))}`);return L(e).elements.every(e=>Dr(e,t.base));case`FunctionSet`:{if(!P(e)){if(F(e))return!1;throw new y(`Attempted to check if \n${z(e)}\nwhich is not a TLC function value, is in the set of functions:\n${dt(z(t))}`)}let n=Ar(e),r=sn(n.domain);return(r===void 0?Fn(t.domain,Ht(n.domain)):Fn({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>Dr(e,t.range))}case`RecordSet`:{let n=P(e)?Ar(e):void 0;if(!n||!bt(n.domain)){if(F(e))return!1;throw new y(`Attempted to check if non-record\n${z(e)}\nis in the set of records:\n${z(t)}`)}return n.domain.length===t.names.length&&t.names.every((e,r)=>{let i=Sr(n.domain,e);return i!==-1&&Dr(n.range[i],t.sets[r])})}case`ProductSet`:{let n=P(e)?Cr(e):void 0;if(n===void 0){if(P(e)&&Ar(e).domain.every(e=>typeof e==`number`)||F(e))return!1;throw new y(`Attempted to check if non-tuple\n${z(e)}\nis in the set of tuples:\n${z(t)}`)}return n.length===t.factors.length&&n.every((e,n)=>Dr(e,t.factors[n]))}case`FilteredSet`:return Dr(e,t.base)&&t.test(e);case`Union`:if(!tr(t.base))throw new y(`Attempted to check if:\n ${z(e)}\nis an element of the non-enumerable set:\n ${nr(t)}`);return L(t.base).elements.some(t=>Dr(e,t));case`SetOperation`:return t.operator===`\\cup`?Dr(e,t.left)||Dr(e,t.right):Dr(e,t.left)&&Dr(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Cr(e);if(n===void 0){if(F(e))return!1;throw new y(`Attempted to check if the value:\n${dt(z(e))}\nis an element of ${dt(z(t))}.`)}return n.every(e=>Dr(e,t.base))}default:throw new y(wr(e,t))}},kr=(e,t,n)=>e===t?!0:typeof e!=`object`||typeof t!=`object`||typeof n!=`object`||e.kind!==`Function`||t.kind!==`Function`||n.kind!==`FunctionSet`||e.domain!==t.domain?Dr(e,n):e.range.every((e,r)=>kr(e,t.range[r],n.range)),Ar=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){I(e.domain)||yr(e.domain);let t=Zn(e.domain);return Gt(Ut(t,t.map(t=>e.apply(t))),Kt(e))}throw new y(`Expected a function but found ${z(e)}`)},jr=(e,t,n)=>{let r=dt(z(e)),i=dt(z(t)),a=n===`1.7.4`;switch(Kt(e)){case`lambda`:return`In applying the function\n${r},\nthe first argument is:\n${i}\nwhich is not in its domain.\n`;case`tuple`:return typeof t==`number`?a?`Attempted to apply tuple\n${r}\nto integer ${t} which is out of domain.`:`Attempted to access index ${t} of tuple\n${r}\nwhich is out of bounds.`:a?`Attempted to apply tuple to a non-integer argument.`:`Attempted to access tuple at a non integral index: ${i}`;case`record`:return typeof t==`string`?a?`Attempted to apply the record\n${r}\nto nonexistent record field ${t}.`:`Attempted to access nonexistent field '${t}' of record\n${r}`:a?`Attempted to apply record to a non-string value ${i}.`:`Attempted to access record by a non-string argument: ${i}`;default:return`Attempted to apply function:\n${r}\nto argument ${i}, which is not in the domain of the function.`}},Mr=(e,t)=>{if(!Ot.is174)return jr(e,t);let n=dt(z(t));return Kt(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},Nr=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}if(e.length<=8){for(let n=0;n<e.length;n++)if(e[n]===t)return n}return Sr(e,t)},Pr=e=>new y(`Attempted to apply function with integer domain to the non-integer argument ${dt(z(e))}`),Fr=(e,t,n)=>{let r=e.domain;if(typeof t!=typeof r[0]){let i=Kt(e),a=i===`tuple`?`number`:i===`record`?`string`:void 0;if(a!==void 0&&typeof t!==a)throw new y(n(e,t));if(a===void 0&&!Ot.is174&&Xn(r))throw Pr(t)}return Er(()=>Nr(r,t),e=>{throw Ot.is174||r.length<32?r.forEach(e=>On(e,t)):Sr(r,t,Cn),e})},Ir=(e,t,n)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!Dr(t,e.domain))throw new y(Kt(e)===`lambda`?jr(e,t):`Attempted to apply a function to ${z(t)}, which is not in its domain`);return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new y(`Attempted to apply ${z(e)}, which is not a function`);let r=n??jr,i=Fr(e,t,r);if(i===-1)throw new y(r(e,t));return e.range[i]},Lr=e=>Xn(e)?qn.get(e)??Qn(e.length):void 0,Rr=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=Ar(e).domain;return Lr(t)??Ht(t)},zr=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!I(e.domain))){if(!Dr(t,e.domain))return e;let r=n(e.apply(t));return Gt({kind:`LazyFunction`,domain:e.domain,apply:n=>Fn(t,n)?r:e.apply(n),source:e.source},Kt(e))}if(!P(e))throw new y(`Attempted to apply EXCEPT construct to the value ${dt(z(e))}.`);let i=Ar(e),a=Fr(i,t,Mr);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=Gt(Ut(i.domain,o),Kt(i));if(l.writtenKeys=i.writtenKeys,i.hash!==0&&i.hash!==Kr){let e=Zr(c);if(e!==Kr){let t=Zr(i.domain[a]);l.hash=s===c?i.hash:i.hash-Gr(t,Zr(s))+Gr(t,e)|0}}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-ni(e,s)+ni(e,c)|0}return l},Br=/* @__PURE__ */ new WeakMap,Vr=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Hr=(e,t)=>Math.imul(e^t,16777619),Ur=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Vr(t)},Wr=e=>Vr(e+2654435769|0),Gr=(e,t)=>Vr(Math.imul(e,668265261)+t|0),Kr=795548749,qr=e=>{if(e.kind===`ModelValue`)return Vr(Hr(Ur(e.name),109));if(N(e)){if(!I(e))return Kr;let t=L(e).elements,n=1940243425;for(let e=0;e<t.length;e++){let r=Zr(t[e]);if(r===Kr)return Kr;n=n+Wr(r)|0}return n}if(e.kind===`LazyFunction`&&!I(e.domain))return Kr;let t=Ar(e),n=1725019383;for(let e=0;e<t.domain.length;e++){let r=Zr(t.domain[e]),i=Zr(t.range[e]);if(r===Kr||i===Kr)return Kr;n=n+Gr(r,i)|0}return n},Jr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return;if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw new y(`TLC has found a state in which the value of a variable contains ${z(e)}`);if(N(e)){L(e).elements.forEach(Jr);return}let t=Ar(e);t.domain.forEach(Jr),t.range.forEach(Jr)},Yr=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{Zr(e)===Kr&&Jr(e);return}catch(e){if(!(e instanceof y))throw e;return e}},Xr=e=>{switch(e.kind){case`Set`:case`MixedSet`:return e.elements;case`Function`:return[...e.domain,...e.range];case`Subset`:case`SequenceSet`:case`FilteredSet`:case`Union`:return[e.base];case`FunctionSet`:return[e.domain,e.range];case`RecordSet`:return e.sets;case`ProductSet`:return e.factors;case`SetOperation`:return[e.left,e.right];case`LazyFunction`:return[e.domain];default:return[]}},Zr=e=>{if(typeof e==`number`)return Vr(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Ur(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=qr(e)),e.hash;let t=Br.get(e);if(t!==void 0)return t;let n=qr(e);return Br.set(e,n),n},Qr=/* @__PURE__ */ new WeakMap,$r=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},ei=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return $r(t)},ti=e=>$r(ii(e)+2135587861|0),ni=(e,t)=>$r(Math.imul(ii(e),374761393)+ii(t)|0),ri=e=>{if(e.kind===`ModelValue`)return $r(ei(e.name)^60);if(N(e)){if(!I(e))return ei(oi(e));let t=L(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+ti(t[e])|0;return n}let t=Ar(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+ni(t.domain[e],t.range[e])|0;return n},ii=e=>{if(typeof e==`number`)return $r(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return ei(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=ri(e)),e.fingerprint;let t=Qr.get(e);if(t!==void 0)return t;let n=ri(e);return Qr.set(e,n),n},ai=/* @__PURE__ */ new WeakMap,oi=e=>{if(typeof e==`boolean`)return e?`T`:`F`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return JSON.stringify(e);let t=ai.get(e);if(t!==void 0)return t;let n=si(e);return ai.set(e,n),n},si=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${oi(e.base)}>`;if(e.kind===`FilteredSet`&&!I(e))throw new y(`Attempted to compare the non-enumerable set ${z(e)} with another value`);if(N(e))return I(e)?`{${L(e).elements.map(oi).join(`,`)}}`:`<${e.kind} ${z(e)}>`;let t=Ar(e);return`(${t.domain.map((e,n)=>`${oi(e)}:${oi(t.range[n])}`).join(`,`)})`},ci=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,li=e=>e.reduce((e,t)=>e===0?0:e*yr(t),1),ui=e=>{if(e.kind===`Subset`)return yr(e.base)<=6?L(e):void 0;if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return L(e);if(e.kind===`FunctionSet`&&I(e.domain)&&yr(e.domain)===0)return Ht([Ut([],[])]);let t=e.kind===`FunctionSet`?yr(e.range)**yr(e.domain):li(e.kind===`RecordSet`?e.sets:e.factors);return t===0?zn:t<=1999?L(e):void 0},di=(e,t)=>{if(t)return ui(e);if(I(e))try{return ui(e)}catch(e){if(e instanceof y)return;throw e}},fi=(e,t)=>{let n=e=>z(e,t);switch(e.kind){case`Subset`:return typeof e.base==`object`&&e.base.kind===`Interval`?`SUBSET (${n(e.base)})`:`SUBSET ${n(e.base)}`;case`FunctionSet`:return`[${n(e.domain)} -> ${n(e.range)}]`;case`RecordSet`:return`[${e.names.map((t,r)=>`${t}: ${n(e.sets[r])}`).join(`, `)}]`;case`ProductSet`:return`(${e.factors.map(n).join(` \\X `)})`;case`SetOperation`:return`${n(e.left)} ${e.operator} ${n(e.right)}`;case`FilteredSet`:return e.source?`{${e.source.names} \\in ${n(e.base)} : <expression ${e.source.predicate}> }`:`{x \\in ${n(e.base)} : ...}`;case`Union`:return nr(e,t)}},pi=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),mi=e=>{if(I(e.domain))try{return Ar(e)}catch(e){if(e instanceof y)return;throw e}},z=(e,t=!1,n=!1)=>{let r=e=>z(e,t,n);if(typeof e==`boolean`)return e?`TRUE`:`FALSE`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return ci(e);switch(e.kind){case`ModelValue`:return e.name;case`Set`:return`{${e.elements.map(r).join(`, `)}}`;case`MixedSet`:return r(L(e));case`Interval`:return e.low<=e.high?`${e.low}..${e.high}`:`{}`;case`InfiniteSet`:return e.name===`Any`?`ANY`:e.name;case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let n=di(e,t);return n?r(n):fi(e,t)}case`SequenceSet`:return`Seq(${r(e.base)})`;case`Function`:case`LazyFunction`:{let i=e.kind===`LazyFunction`?mi(e):e;if(i===void 0){let t=e.kind===`LazyFunction`?e.source:void 0;return t?`[${t.parameters.map(e=>`${e.name} \\in ${z(e.domain)}`).join(`, `)} |-> <expression ${t.body}>]`:`<function>`}if(i.domain.length===0&&Ot.is174&&Kt(e)!==`tuple`)return`<< >>`;let a=r=>z(r,t,n&&Kt(e)!==`lambda`);return i.domain.every((e,t)=>e===t+1)?`<<${i.range.map(a).join(`, `)}>>`:Kt(e)===`record`||i.domain.every(e=>typeof e==`string`&&pi(e))?`[${(n||i.hash!==0||i.fingerprint!==0?i.domain.map((e,t)=>[e,i.range[t]]):_t(i)).map(e=>`${String(e[0])} |-> ${a(e[1])}`).join(`, `)}]`:`(${i.domain.map((e,t)=>`${r(e)} :> ${a(i.range[t])}`).join(` @@ `)})`}}},hi=e=>{let t=Object.entries(e);return t.map(([e,n])=>`${t.length===1?``:`/\\ `}${e} = ${dt(z(n))}\n`).join(``)},gi=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},_i=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=Zr(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||on(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||on(i[e],n))return i[e]}return n.kind===`Set`?gi(n.elements,t):(gi(n.domain,t),gi(n.range,t)),i===void 0?e.set(r,n):Array.isArray(i)?i.push(n):e.set(r,[i,n]),n};return e=>{for(let n=0;n<e.length;n++)e[n]=t(e[n]);return e}},vi=e=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return[];case`Apply`:return e.args;case`Lambda`:return[e.body];case`And`:case`Or`:return e.operands;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`If`:return[e.condition,e.consequent,e.alternative];case`Case`:return[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]];case`Let`:return[...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),e.body];case`Forall`:case`Exists`:return[...e.bounds.map(e=>e.set),e.body];case`UnboundedQuantifier`:return[e.body];case`Choose`:return[...e.set?[e.set]:[],e.body];case`SetEnumeration`:case`Tuple`:return e.elements;case`SetFilter`:return[e.bound.set,e.predicate];case`SetMap`:return[e.expression,...e.bounds.map(e=>e.set)];case`FunctionConstruction`:return[...e.bounds.map(e=>e.set),e.body];case`FunctionSet`:return[e.domain,e.range];case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`Except`:return[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])];case`FunctionApplication`:return[e.function,...e.args];case`Bracket`:return e.args;case`FieldAccess`:return[e.record];case`Product`:return e.factors;case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`Label`:return[e.body];case`Subexpression`:return e.selectors.flatMap(e=>`args`in e?e.args:[])}},B=e=>(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`,yi=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),bi=(e,t)=>yi.has(e)?new y(t):new S(t),xi=e=>typeof e==`object`&&e.kind===`Operator`,V=(e,t,n)=>{let r=e[t];if(r===void 0||xi(r))throw bi(n,`${n} expects a value as argument ${t+1}`);return r},Si=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`number`)throw bi(n,`${n} expects an integer but received ${z(r)}`);return r},Ci=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`boolean`)throw bi(n,`${n} expects a boolean but received ${z(r)}`);return r},wi=(e,t,n)=>{let r=V(e,t,n);if(!N(r))throw bi(n,`${n} expects a set but received ${z(r)}`);return r},Ti=(e,t,n)=>{let r=wi(e,t,n);if(!I(r))throw bi(n,`${n} cannot enumerate the non-enumerable set ${z(r)}`);return r},Ei=(e,t,n)=>L(Ti(e,t,n)),Di=(e,t,n)=>Ei(e,t,n).elements,Oi=(e,t,n)=>{let r=V(e,t,n),i=Cr(r);if(!i)throw bi(n,`${n} expects a sequence but received ${z(r)}`);return i},ki=(e,t,n)=>{let r=V(e,t,n);if(!P(r))throw bi(n,`${n} expects a function but received ${z(r)}`);return Ar(r)},Ai=(e,t,n)=>{let r=e[t];if(r===void 0||!xi(r))throw bi(n,`${n} expects an operator as argument ${t+1}`);return r},ji=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),H=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:t===1?e=>n([e]):void 0,evaluateBinary:t===2?(e,t)=>n([e,t]):void 0}),Mi=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Ni=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),Pi=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(V(n,0,e),V(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Fi=e=>e>2147483647||e<-2147483648,Ii=e=>new S(`Overflow when computing ${e}`),Li={ModelValue:`ModelValue`,Set:`SetEnumValue`,Interval:`IntervalValue`,InfiniteSet:`UserValue`,SequenceSet:`UserValue`,Subset:`SubsetValue`,FunctionSet:`SetOfFcnsValue`,RecordSet:`SetOfRcdsValue`,ProductSet:`SetOfTuplesValue`,FilteredSet:`SetPredValue`,LazyFunction:`FcnLambdaValue`,Union:`UnionValue`,MixedSet:`SetEnumValue`},Ri={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},zi={BoolValue:`a Boolean value`,IntValue:`an integer`,StringValue:`a string`,RecordValue:`a record`,SetEnumValue:`a set of the form {e1, ... ,eN}`,SetPredValue:`a set of the form {x \\in S : expr}`,TupleValue:`a tuple`,FcnLambdaValue:`a function of the form [x \\in S |-> expr]`,FcnRcdValue:`a function of the form (d1 :> e1 @@ ... @@ dN :> eN)`,SetOfFcnsValue:`a set of the form [S -> T]`,SetOfRcdsValue:`a set of the form [d1 : S1, ... , dN : SN]`,SetOfTuplesValue:`a cartesian product`,SubsetValue:`a set of the form SUBSET S`,SetDiffValue:`a set of the form S \\ T`,SetCapValue:`a set of the form S \\cap T`,SetCupValue:`a set of the form S \\cup T`,ModelValue:`a model value`,UserValue:`a special set constant`,IntervalValue:`a set of the form i..j`,UnionValue:`a set of the form UNION S`},Bi={lambda:`FcnLambdaValue`,tuple:`TupleValue`,record:`RecordValue`},Vi=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Ri[e.operator];if(e.kind!==`Function`)return Li[e.kind];let t=Kt(e);return t===void 0?`FcnRcdValue`:Bi[t]},Hi=e=>zi[Vi(e)],Ui=(e,t)=>new y(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),Wi=(e,t)=>{let n=n=>(...r)=>{let i=Tr.sets?.length??0;try{return n(...r)}catch(n){throw n instanceof y&&(e.isLazy===!0||!(n instanceof S))?(Tr.sets&&(Tr.sets.length=i),Ui(t,n.message)):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},Gi=(e,t)=>{if(typeof e!=`number`)throw Ui(t,`Cannot cast tlc2.value.impl.${Vi(e)} to tlc2.value.impl.IntValue`);return e},Ki=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,qi=(e,t,n,r)=>{let i=Ki(e,n,`IntValue`,2);return Pi(t,(e,n)=>{let a=Gi(e,i),o=Gi(n,i),s=r(a,o);if(Fi(s))throw Ii(`${a}${t}${o}`);return s})},Ji=(e,t,n)=>{if(typeof e!=`number`)throw new S(`The ${t} argument of ${n} should be an integer, but instead it is:\n${z(e)}`);return e},Yi=(e,t,n=e)=>Pi(e,(e,r)=>t(Ji(e,`first`,n),Ji(r,`second`,n))),Xi=(e,t,n)=>({...Ni(e,t,n),isLazy:!0}),Zi=(e,t,n)=>{let r=Ai(e,t,n);return()=>r.call([])},Qi=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),$i=()=>({bool:gl,condition:(e,t)=>{if(typeof e!=`boolean`)throw nl(t,e);return e},junct:(e,t,n)=>{if(typeof e!=`boolean`)throw rl(t,n,e);return e},apply:Ir,expectFunction:pl,tuple:$n,set:Rn,record:tn,writtenRecord:vt,equal:nn,enumerate:Dl,unassigned:(e,t)=>{throw Dd(e,t)},primeOutsideAction:e=>{throw kd(e)},prime:e=>({environment:e.environment,scope:e.scope,state:e.next,next:void 0,isKeepLazy:e.isKeepLazy}),keepLazyContext:ml,extend:(e,t,n)=>({environment:e.environment,scope:t.reduce((e,t,r)=>dl(e,t,n[r]),e.scope),state:e.state,next:e.next,isKeepLazy:e.isKeepLazy})}),ea={value:void 0},ta=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),na=e=>`local${e.counter++}`,ra=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),vi(e).forEach(e=>ra(e,t)),t),ia=(e,t,n)=>{let r=ta(e,Wu(t,e.environment)),i=ra(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=ta(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},aa=(e,t,n)=>{let r=t.kind===`Forall`,i=JSON.stringify(r?`the body of \\A`:`the body of \\E`),a=`quantifier${e.counter++}`,o=[...n.locals.values()],s={context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:new Map(n.locals)},c=t.bounds.map(()=>na(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${ca(e,t.set,s)}, ${ta(e,t.set)}, ${JSON.stringify(e.environment.runtime.version)});`),u=t.bounds.map(t=>{let n=na(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${ca(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=na(e),a=na(e),o=na(e),s=c[r];return`for (let ${i} = 0, ${a} = ${s}.low, ${o} = ${a} === undefined ? ${s}.length : ${s}.high - ${a} + 1; ${i} < ${o}; ${i}++) { const ${n} = ${a} === undefined ? ${s}[${i}] : ${a} + ${i}; ${t} }`},d),p=o.map(e=>`, ${e}`).join(``);return e.helpers.push(`function ${a}(context, state, next${p}) { let primed; ${l.join(` `)} ${f} return ${r}; }`),`${a}(${n.context}, ${n.state}, ${n.isPrimed?`undefined`:n.next}${p})`},oa=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${ca(e,r[0],n)}, "the left side of =>") ? bool(${ca(e,r[1],n)}, "the right side of =>") : true)`;if(B(t))return ia(e,t,n);let i=$l(t.operator,e.environment);if(i?.kind!==`Builtin`)return ia(e,t,n);if(i.name===`DOMAIN`)return`${ta(e,ol(t))}(${ca(e,r[0],n)})`;if(i.name===`TLCEval`)return ia(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${ta(e,sl(t,i))}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&Zu(r[0],a))return`${ta(e,i.evaluateUnary)}(${ca(e,r[0],n)})`;let o=r.length===2&&Zu(r[0],a)&&Zu(r[1],a);return i.evaluateBinary&&o?`${ta(e,i.evaluateBinary)}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`:ia(e,t,n)},sa=(e,t,n)=>{switch(e.kind){case`Identifier`:{if(t.locals.has(e.name))return!0;if(B(e))return!1;let r=lu(e.name,n);return r?.kind===`Variable`||r?.kind===`Value`}case`Prime`:return sa(e.expression,t,n);case`FieldAccess`:return sa(e.record,t,n);case`FunctionApplication`:return[e.function,...e.args].every(e=>sa(e,t,n));default:return!1}},ca=(e,t,n)=>{let r=(t,r=n)=>ca(e,t,r);if(Fu(t)&&Au(t,e.environment))return ia(e,t,n);switch(t.kind){case`Number`:return _u(t.value)?String(t.value):ia(e,t,n);case`String`:return JSON.stringify(t.value);case`Identifier`:{let r=n.locals.get(t.name);if(r)return r;if(B(t))return ia(e,t,n);let i=lu(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=ta(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?ta(e,i.value):ia(e,t,n)}case`Apply`:return oa(e,t,n);case`And`:case`Or`:{let n=ta(e,t),i=t.kind===`And`?` && `:` || `;return`(${t.operands.map((e,t)=>`junct(${r(e)}, ${n}, ${t})`).join(i)})`}case`If`:return`(condition(${r(t.condition)}, ${ta(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{xd(t.function);let i=`expectFunction(${sa(t.function,n,e.environment)?r(t.function):ia(e,t.function,{...n,context:`keepLazyContext(${n.context})`})}, ${ta(e,t)})`,a=al(e.environment.runtime.version),o=a?`, ${ta(e,a)}`:``;return t.args.length===1?`apply(${i}, ${r(t.args[0])}${o})`:`apply(${i}, tuple([${t.args.map(e=>r(e)).join(`, `)}])${o})`}case`FieldAccess`:return`${ta(e,il(t))}(${r(t.record)})`;case`Record`:{let i=Td(t.fields);if(Ed(i))return ia(e,t,n);let a=ta(e,i.map(e=>e.name)),o=`[${i.map(e=>r(e.value)).join(`, `)}]`,s=t.fields.map(e=>e.name);return s.every((e,t)=>e===i[t].name)?`record(${a}, ${o})`:`writtenRecord(${a}, ${o}, ${ta(e,s)})`}case`Tuple`:return`tuple([${t.elements.map(e=>r(e)).join(`, `)}])`;case`SetEnumeration`:return`set([${t.elements.map(e=>r(e)).join(`, `)}])`;case`Prime`:{let i=ta(e,t);if(n.isPrimed)return`primeOutsideAction(${i})`;let a={context:`(primed ??= prime(${n.context}))`,state:n.next,next:`undefined`,isPrimed:!0,locals:n.locals};return`(${n.next} === undefined ? primeOutsideAction(${i}) : ${r(t.expression,a)})`}case`Unchanged`:return`equal(${r({kind:`Prime`,expression:t.expression,location:t.location})}, ${r(t.expression)})`;case`Forall`:case`Exists`:return t.bounds.every(e=>e.pattern.kind===`Name`)?aa(e,t,n):ia(e,t,n);default:return ia(e,t,n)}},la=(e,t)=>{if(!Qi.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=ca(n,e,{context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:/* @__PURE__ */ new Map}),i=n.references.map((e,t)=>`reference${t}`),a=`${n.helpers.join(`
28
+ `);a(e===-1?o:o.slice(0,e));continue}if(o.startsWith(`(*`)){let e=o.indexOf(`*)`);if(e===-1)return a(o),i(``),t;a(o.slice(0,e+2));continue}let c=n.line,l=/^\d+(?![A-Za-z_])/.exec(o)?.[0];if(l){t.push({kind:`Number`,text:l,line:c}),a(l);continue}let u=/^[A-Za-z0-9_]+/.exec(o)?.[0];if(u){t.push({kind:`Word`,text:u,line:c}),a(u);continue}if(o.startsWith(`"`)){let s=/^"((?:[^"\\\n]|\\[^\n])*)("?)/.exec(o),l=s?.[0]??`"`;if(s?.[2]!==`"`)return a(l),n.index===e.length?i(`${l}\n`):r(n.index,l),t;t.push({kind:`String`,text:s[1],line:c}),a(l);continue}let d=et.find(e=>o.startsWith(e));if(d){t.push({kind:`Symbol`,text:d,line:c}),a(d);continue}let f=_e(e,n.index)??O(e,n.index);if(!f)return r(n.index,``),t;t.push({kind:`Word`,text:f.text,line:c}),a(e.slice(n.index,n.index+f.length))}return t.push({kind:`End`,text:``,line:n.line}),t},nt=(e,t)=>new v(`TLC found an error in the configuration file at line ${e}\n${t}`),rt=(e,t)=>nt(e,`The keyword ${t} appeared twice.`),M=/* @__PURE__ */ new Map([[`INIT`,`init`],[`NEXT`,`next`],[`SPECIFICATION`,`specification`],[`VIEW`,`view`],[`SYMMETRY`,`symmetry`],[`ALIAS`,`alias`],[`_PERIODIC`,`periodic`],[`_RL_REWARD`,`rlReward`]]),it=/* @__PURE__ */ new Map([[`INVARIANT`,`invariants`],[`INVARIANTS`,`invariants`],[`PROPERTY`,`properties`],[`PROPERTIES`,`properties`],[`CONSTRAINT`,`constraints`],[`CONSTRAINTS`,`constraints`],[`ACTION_CONSTRAINT`,`actionConstraints`],[`ACTION_CONSTRAINTS`,`actionConstraints`],[`POSTCONDITION`,`postconditions`],[`POSTCONDITIONS`,`postconditions`],[`_POSSIBLE`,`possible`]]),at=(e,t=`master`)=>{let n=t===`1.7.4`?$e:Ze,r=tt(e),i={index:0},a={init:void 0,next:void 0,specification:void 0,invariants:[],properties:[],constraints:[],actionConstraints:[],constants:[],substitutions:[],checkDeadlock:!0,symmetry:void 0,view:void 0,alias:void 0,postconditions:[],possible:[],periodic:void 0,rlReward:void 0},o={isSet:!1},s=/* @__PURE__ */ new Set,c=()=>{let e=r[Math.min(i.index++,r.length-1)];if(e.kind===`Error`)throw new v(`TLC found an error in the configuration file:\n${e.text}`);return e},l=e=>{if(e.kind===`Number`)return{kind:`Number`,value:Number(e.text)};if(e.kind===`String`)return{kind:`String`,value:e.text};if(e.text===`TRUE`||e.text===`FALSE`)return{kind:`Boolean`,value:e.text===`TRUE`};if(e.text===`{`){let e=[],t={token:c()};if(t.token.text!==`}`)for(;e.push(l(t.token)),t.token=c(),t.token.text===`,`;)t.token=c();if(t.token.text!==`}`)throw nt(t.token.line,`It was expecting }, but did not find it.`);return{kind:`Set`,elements:e}}if(e.kind!==`End`)return{kind:`ModelValue`,name:e.text};throw nt(e.line,`It was expecting a value, but did not find it.`)},u=e=>{let t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after ${e}[.`);let n=c();if(n.text!==`]`)throw nt(n.line,`It was expecting ], but did not find it.`);return t.text},d=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;let r={token:c(),name:t.text};for(;r.token.text===`!`;)r.name=`${r.name}!${c().text}`,r.token=c();let i=r.name;if(r.token.text===`<-`){if(r.token=c(),r.token.text===`[`){let e=u(`<-`),t=c();if(t.kind===`End`)throw nt(t.line,`Expected an identifier after <-[mod].`);a.substitutions.push({name:i,target:t.text,module:e});continue}if(r.token.kind===`End`)throw nt(r.token.line,`Expected an identifier after <-.`);a.substitutions.push({name:i,target:r.token.text});continue}let o=[],s=r.token.text===`(`;if(s){for(;o.push(l(c())),r.token=c(),r.token.text===`,`;);if(r.token.text!==`)`)throw nt(e,``);r.token=c()}if(r.token.text!==`=`)throw nt(r.token.line,`It was expecting = or <-, but did not find it.`);r.token=c();let d=r.token.text===`[`?u(`=`):void 0,f=l(d===void 0?r.token:c());a.constants.push({name:i,value:f,...s&&{args:o},...d!==void 0&&{module:d}})}},f=e=>{for(;;){let t=c();if(t.kind===`End`||n.has(t.text))return t;e.push(t.text)}},p={token:c()};for(;p.token.kind!==`End`;){let e=p.token.text,t=p.token.line,r=n.has(e)?M.get(e):void 0,i=n.has(e)?it.get(e):void 0,l=()=>{let n=c();if(n.kind===`End`)throw nt(t,`The keyword ${e} was not followed by an identifier.`);return n};if(r!==void 0){let n=l();if(a[r]!==void 0)throw rt(t,e);a[r]=n.text,p.token=c()}else if(i!==void 0)p.token=f(a[i]);else if(e===`CONSTANT`||e===`CONSTANTS`)p.token=d(t);else if(e===`CHECK_DEADLOCK`){let n=l();if(n.text!==`TRUE`&&n.text!==`FALSE`)throw nt(n.line,`It was expecting TRUE or FALSE, but did not find it.`);if(o.isSet)throw rt(t,e);o.isSet=!0,a.checkDeadlock=n.text===`TRUE`,p.token=c()}else{if(!n.has(e)||!Qe.includes(e))throw nt(t,`It was expecting a keyword, but did not find it.`);if(l(),s.has(e))throw rt(t,e);s.add(e),p.token=c()}}return a},ot={Set:{open:`{ `,close:` }`,pad:` `,separator:`,`,divider:``,dividerPad:``},Sequence:{open:`<< `,close:` >>`,pad:` `,separator:`,`,divider:``,dividerPad:``},Subset:{open:`SUBSET `,close:` `,pad:` `,separator:`,`,divider:``,dividerPad:``},Function:{open:`( `,close:` )`,pad:` `,separator:` @@`,divider:` :>`,dividerPad:` `},Record:{open:`[ `,close:` ]`,pad:` `,separator:`,`,divider:` |->`,dividerPad:` `}},st=e=>{if(e===void 0)return!1;let t=e.charCodeAt(0);return t>=9&&t<=13||t>=28&&t<=32||t===5760||t>=8192&&t<=8202&&t!==8199||t===8232||t===8233||t===8287||t===12288},ct=e=>e!==void 0&&/^\p{Nd}$/u.test(e),lt=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),ut=e=>{let t=t=>{let n=ye(e,t,st);return e[n]===void 0?void 0:n},n=(n,r,i,a,o,s)=>{let c={kind:n,first:r,last:r,children:[]},l={index:t(i)};for(;l.index!==void 0&&e[l.index]!==a;){let n=o(l.index);if(!n)return;c.children.push(n);let r=t(n.last+1);if(r===void 0)return;let i=e.startsWith(s,r)?r+s.length:r;l.index=t(i)}if(l.index!==void 0)return c.last=l.index,c},r=(n,r)=>{let i=o(n);if(!i)return;let a=t(i.last+1);if(a===void 0||!e.startsWith(r,a))return;let s=t(a+r.length),c=s===void 0?void 0:o(s);if(c)return{kind:`Pair`,first:n,last:c.last,children:[i,c]}},i=t=>{let n=ye(e,t,ct);if(e.startsWith(`..`,n)&&ct(e[n+2]))return{kind:`Constant`,first:t,last:ye(e,n+2,ct)-1,children:[]}},a=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=ct(n)?i(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:ye(e,t+1,ct)-1,children:[]};if(lt(n))return{kind:`Constant`,first:t,last:ye(e,t,lt)-1,children:[]}},o=i=>{let s=t(i);if(s!==void 0)switch(e[s]){case`{`:return n(`Set`,s,s+1,`}`,o,`,`);case`<`:{let t=n(`Sequence`,s,s+2,`>`,o,`,`);return!t||t.last+1>=e.length?void 0:{...t,last:t.last+1}}case`[`:return n(`Record`,s,s+1,`]`,e=>r(e,`|->`),`,`);case`(`:return n(`Function`,s,s+1,`)`,e=>r(e,`:>`),`@@`);default:{if(!e.startsWith(`SUBSET`,s))return a(s);let n=t(s+6),r=n===void 0?void 0:o(n);return r?{kind:`Subset`,first:s,last:r.last,children:[r]}:void 0}}};return o(0)},dt=e=>{let t=e.length===0?void 0:ut(e);if(!t||t.last<e.length-1)return e;let n=t=>e.slice(t.first,t.last+1),r=e=>e.last-e.first+1,i=(e,t,i,s)=>{if(r(e)<=t-i||e.kind===`Constant`)return n(e);if(e.kind===`Pair`)return;let c=ot[e.kind],l=t-Math.max(c.open.length,c.pad.length),u=i+c.close.length,d=s+c.pad,f=e.kind===`Function`||e.kind===`Record`?o(e.children,l,u,d,c):a(e.children,l,u,d,c.separator);return f===void 0?void 0:c.open+f+c.close},a=(e,t,n,r,a)=>{let o=e.map((o,s)=>{let c=s===e.length-1,l=i(o,t,c?n:a.length,r);return l===void 0||c?l:`${l}${a}\n${r}`});return o.includes(void 0)?void 0:o.join(``)},o=(e,t,a,o,s)=>{let c=e.map((c,l)=>{let u=l===e.length-1,d=c.children[0],f=c.children[1],p=u?``:`${s.separator}\n${o}`,m=r(d)+s.divider.length+1+r(f);if(u?m<=t-a:m+s.separator.length<=t)return`${n(d)}${s.divider} ${n(f)}${p}`;let h=r(d)+s.divider.length<=t?n(d):i(d,t,a+s.divider.length,o),g=i(f,t-s.dividerPad.length,u?a:s.separator.length,o+s.dividerPad);return h===void 0||g===void 0?void 0:`${h}${s.divider}\n${o}${s.dividerPad}${g}${p}`});return c.includes(void 0)?void 0:c.join(``)};return i(t,80,0,``)??e},N=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`,ft=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),P=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),F=e=>typeof e==`object`&&e.kind===`ModelValue`,pt=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:N(e)?`set`:`function`,mt=e=>{if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new S(`Integer overflow: ${e} is outside TLC's 32-bit range`);return e},ht={isUsed:!1},gt=(e,t)=>(ht.isUsed=!0,e.writtenKeys=t,e),_t=e=>(e.writtenKeys??e.domain).map(t=>[t,e.range[Sr(e.domain,t)]]),vt=(e,t,n)=>gt(tn(e,t),n),yt=e=>{if(!(typeof e!=`object`||e.kind!==`Function`&&e.kind!==`Set`)&&e.hash===0&&e.fingerprint===0){if(e.kind===`Set`)return e.elements.forEach(yt);e.writtenKeys=void 0,e.range.forEach(yt)}},bt=e=>e.every(e=>typeof e==`string`),xt=(e,t)=>e.length>0&&t.length>0&&bt(e)!==bt(t),St=(e,t)=>{ht.isUsed&&(e.writtenKeys=void 0,t.writtenKeys=void 0);let n=e.domain,r=t.domain;if(n.length!==r.length)return xt(n,r)?Cn(e,t):n.length-r.length;if(n!==r)for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=zt(i[e],a[e]);if(t!==0)return t}return 0},Ct=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return n.length-r.length;if(n===r)return 0;for(let e=0;e<n.length;e++){let t=zt(n[e],r[e]);if(t!==0)return t}return 0},wt=e=>F(e)?e.type:void 0,Tt=(e,t,n)=>{let r=wt(e),i=wt(t);if(r===void 0&&i===void 0)return;let a=n?`check equality of`:`compare`;if(F(e)&&F(t)){if(r===void 0||i===void 0||r===i)return;throw new y(`Attempted to ${a} the differently-typed model values ${z(e)} and ${z(t)}`)}throw r===void 0?new y(`Attempted to ${a} the typed model value ${z(t)} and the non-model value\n${z(e)}`):new y(`Attempted to ${a}${n?``:` the`} typed model value ${z(e)} and non-model value\n${z(t)}`)},Et={ranks:Object.create(null),size:0},Dt=e=>{Et.ranks=Object.create(null),Et.size=0,Bt.clear();for(let t of e)At(t)},Ot={is174:!1},kt=e=>{Ot.is174=e===`1.7.4`},At=e=>(Et.ranks[e]===void 0&&(Et.ranks[e]=Et.size++),e),jt=()=>Et.size,Mt=e=>Et.ranks[At(e)],Nt=(e,t)=>{if(e===t)return 0;let n=Et.ranks,r=n[e],i=n[t];return r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},Pt=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),Ft=(e,t)=>(Pt(e)||Pt(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`),It=(e,t,n)=>{if(!Pt(e))throw new y(`Attempted to ${n} the set ${z(I(e)?L(e):e,!0)} with the value:\n${z(t,!0)}`);if(!Pt(t))throw new y(`Attempted to compare overridden value ${z(e,!0)} with non-overridden value:\n${z(t,!0)}`);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new y(`Attempted to compare ${z(e,!0)} with the value\n${z(t,!0)}`)},Lt={kind:`InfiniteSet`,name:`Any`},Rt=e=>{throw new y(`Attempted to compare ANY with the value\n${z(e)}`)},zt=(e,t)=>{if(e===t)return ht.isUsed&&yt(e),e===Lt?Rt(e):0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return St(e,t);if(n===`Set`&&r===`Set`)return Ct(e,t);if(n===`Interval`&&r===`Interval`){let n=Math.max(0,e.high-e.low+1),r=Math.max(0,t.high-t.low+1);return n!==r||n===0?n-r:e.low-t.low}if(n===`ModelValue`&&r===`ModelValue`)return e.type!==void 0&&t.type!==void 0&&Tt(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Tt(e,t,!1),n===`ModelValue`?-1:1;if(e===Lt||t===Lt)return Rt(e===Lt?t:e);if(N(e)&&N(t)&&Ft(e,t))return It(e,t,`compare`);let i=N(e);if(i!==N(t))throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`);return i?Ct(L(e),L(t)):St(Ar(e),Ar(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return Nt(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Tt(e,t,!1),F(e))return-1;if(F(t))return 1;throw new y(`Attempted to compare ${pt(e)} ${z(e)} with ${pt(t)} ${z(t)}`)},Bt=/* @__PURE__ */ new Map,Vt=e=>{let t=Bt.get(e);if(t)return t;let n={kind:`ModelValue`,name:e,type:e.length>2&&e[1]===`_`?e[0]:void 0,rank:Mt(e)};return Bt.set(e,n),n},Ht=e=>({kind:`Set`,elements:e,hash:0,fingerprint:0,isFingerprinted:!1}),Ut=(e,t)=>({kind:`Function`,domain:e,range:t,hash:0,fingerprint:0,writtenKeys:void 0,functionClass:void 0,isFingerprinted:!1}),Wt={isPresent:!1},Gt=(e,t)=>(t===`lambda`&&(Wt.isPresent=!0),t!==void 0&&(e.functionClass=t),e),Kt=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`)?e.functionClass:void 0,qt=e=>Gt(e,`lambda`),Jt=/* @__PURE__ */ new WeakSet,Yt=/* @__PURE__ */ new WeakSet,Xt={isPresent:!1},Zt=e=>(Xt.isPresent=!0,e),Qt=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),$t=e=>{Xt.isPresent&&typeof e==`object`&&Qt.has(e.kind)&&Yt.add(e)},en=e=>{if((Wt.isPresent||Xt.isPresent)&&typeof e==`object`){if(e.kind===`Function`||e.kind===`Set`){if(e.isFingerprinted)return;e.isFingerprinted=!0}else{if(Jt.has(e))return;Jt.add(e)}e.kind===`Function`?(e.functionClass===`lambda`&&(e.functionClass=void 0),e.domain.forEach(en),e.range.forEach(en)):e.kind===`Set`||e.kind===`MixedSet`?e.elements.forEach(en):N(e)&&I(e)&&($t(e),L(e).elements.forEach(en))}},tn=(e,t)=>Gt(Ut(e,t),`record`),nn=(e,t)=>{if($t(e),e===t)return ht.isUsed&&yt(e),e!==Lt||Rt(e);if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Tt(e,t,!0),zt(e,t)===0);if((e.kind===`Set`||e.kind===`Function`)&&(t.kind===`Set`||t.kind===`Function`)&&e.hash!==0&&t.hash!==0&&e.hash!==t.hash)return!1;if(e.kind===`Function`&&t.kind===`Function`)return St(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Ct(e,t)===0;if(F(e)||F(t))return Tt(e,t,!0),F(e)&&F(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return nn(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=R(e.domain),r=R(t.domain);if(n||r)return n===r;let i=R(e.range),a=R(t.range);return i||a?i===a:nn(e.domain,t.domain)&&nn(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){if(R(e))return R(t);if(R(t))return!1;let n=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),r=n(t);return e.names.length===t.names.length&&n(e).every((e,t)=>e[0]===r[t][0]&&nn(e[1],r[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`)return R(e)?R(t):!R(t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>nn(e,t.factors[n]));let n=N(e)&&N(t)&&!(I(e)&&I(t));if(n&&Ft(e,t))return It(e,t,`check equality of`)===0;if(n){if(!Pt(e)){let n=L(e);if(!Pt(t))return Ct(n,L(t))===0}return oi(e)===oi(t)}return zt(e,t)===0},rn=e=>{let t=(e,t)=>e===t||e.length===t.length&&e.every((e,r)=>n(e,t[r])),n=(n,r)=>n===r?!0:typeof n!=`object`||typeof r!=`object`?!1:n.kind===`Set`&&r.kind===`Set`?(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.elements,r.elements):n.kind===`Function`&&r.kind===`Function`?(!e||n.functionClass===r.functionClass)&&(n.hash===0||r.hash===0||n.hash===r.hash)&&t(n.domain,r.domain)&&t(n.range,r.range):oi(n)===oi(r);return n},an=rn(!1),on=rn(!0),sn=e=>{let t=e.length===0?1:e[0];return typeof t==`number`&&e.every((e,n)=>e===t+n)?t:void 0},cn=e=>{if(!P(e))return;let t=Ar(e);return{domain:t.domain,range:t.range,low:sn(t.domain)}},ln=e=>{if(!P(e))return;let t=Ar(e);return t.domain.every(e=>typeof e==`string`)?t:void 0},un=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to compare the typed model value ${z(e)} and the non-model value\n${z(t)}`);return 1},dn=(e,t)=>{if(wt(e)!==void 0)throw new y(`Attempted to check equality of the typed model value ${z(e)} and the non-model value\n${z(t)}`);return!1},fn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)?e.rank-t.rank:-1;if(!F(t))throw new y(`Attempted to compare the typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to compare the differently-typed model values ${z(e)} and ${z(t)}`);return e.rank-t.rank},pn=(e,t)=>{let n=wt(e);if(n===void 0)return F(t)&&e.name===t.name;if(!F(t))throw new y(`Attempted to check equality of typed model value ${z(e)} and non-model value\n${z(t)}`);let r=wt(t);if(r!==void 0&&r!==n)throw new y(`Attempted to check equality of the differently-typed model values ${z(e)} and ${z(t)}`);return e.name===t.name},mn={number:{name:`integer`,other:`non-integer`,equality:`check equality of`},string:{name:`string`,other:`non-string`,equality:`check equality of`},boolean:{name:`boolean`,other:`non-boolean`,equality:`compare equality of`}},hn=(e,t,n)=>{let r=mn[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${z(e)} with ${r.other}:\n${z(t)}`},gn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return un(n,t);throw new y(`Attempted to compare the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return e.range.length-r.range.length;let i=()=>_n(e.range,r.range);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&r.low!==void 0)return e.low===r.low?i():e.low-r.low;let a=e.low??r.low;if(a===void 0)return _n(e.domain,r.domain)||i();let o=e.low===void 0?e.domain:r.domain;for(let t=0;t<o.length;t++){let n=o[t];if(typeof n!=`number`)throw new y(`Attempted to compare integer with non-integer${e.low===void 0?``:`:`}\n${z(n)}.`);let r=e.low===void 0?n-(a+t):a+t-n;if(r!==0)return r}return i()},_n=(e,t)=>{for(let n=0;n<e.length;n++){let r=Cn(e[n],t[n]);if(r!==0)return r}return 0},vn=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length-r.length||_n(n.range,r):gn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return un(t,e);throw new y(`Attempted to compare record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length-r.domain.length||_n(n.domain,r.domain)||_n(n.range,r.range)}return gn({...n,low:sn(n.domain)},e,t)},yn=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),bn=(e,t)=>Pt(e)||Pt(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),xn=(e,t)=>{let n=yn(t)?t:L(t);return{elements:L(e).elements,otherElements:L(n).elements}},Sn=(e,t)=>{if(bn(e,t))return zt(e,t);if(!yn(e))return Sn(L(e),t);if(!N(t)){if(F(t))return un(t,e);throw new y(`Attempted to compare the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length-n.otherElements.length||_n(n.elements,n.otherElements)},Cn=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return zt(e,t);if(F(t))return un(t,e);throw new y(hn(e,t,!1))}return e.kind===`ModelValue`?fn(e,t):P(e)?vn(e,t):Sn(e,t)},wn=(e,t)=>e.every((e,n)=>On(e,t[n])),Tn=(e,t,n)=>{let r=cn(n);if(!r){if(F(n))return dn(n,t);throw new y(`Attempted to check equality of the function ${z(t)} with the value:\n${z(n)}`)}if(e.range.length!==r.range.length)return!1;if(e.low!==void 0&&r.low!==void 0)return(e.range.length===0||e.low===r.low)&&wn(e.range,r.range);let i=e.low??r.low;return i===void 0?wn(e.domain,r.domain)&&wn(e.range,r.range):(e.low===void 0?e.domain:r.domain).every((e,t)=>{if(typeof e!=`number`)throw new y(`Attempted to compare an integer with non-integer:\n${z(e)}.`);return e===i+t})&&wn(e.range,r.range)},En=(e,t)=>{let n=Ar(e);if(e.kind===`Function`&&Cr(n)!==void 0){let r=P(t)?Cr(t):void 0;return r?n.range.length===r.length&&wn(n.range,r):Tn({...n,low:1},e,t)}if(Kt(e)===`record`){let r=ln(t);if(!r){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of record:\n${z(e)}\nwith non-record\n${z(t)}`)}return n.domain.length===r.domain.length&&wn(n.domain,r.domain)&&wn(n.range,r.range)}return Tn({...n,low:sn(n.domain)},e,t)},Dn=(e,t)=>{if(bn(e,t))return nn(e,t);if(!yn(e))return Dn(L(e),t);if(!N(t)){if(F(t))return dn(t,e);throw new y(`Attempted to check equality of the set ${z(e)} with the value:\n${z(t)}`)}let n=xn(e,t);return n.elements.length===n.otherElements.length&&wn(n.elements,n.otherElements)},On=(e,t)=>{if(typeof e!=`object`){if(typeof t==typeof e)return e===t;if(F(t))return dn(t,e);throw new y(hn(e,t,!0))}return e.kind===`ModelValue`?pn(e,t):P(e)?En(e,t):Dn(e,t)},kn=e=>{let t=[];for(let n of e){let e=jn(n,t);e.isFound||t.splice(e.index,0,n)}return t},An=(e,t)=>{let n=Tr.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},jn=(e,t)=>{let n={low:0,high:t.length};for(;n.low<n.high;){let r=n.low+(n.high-n.low>>1),i=An(e,()=>Cn(e,t[r]));if(i===0)return{index:r,isFound:!0};i<0?n.high=r:n.low=r+1}return{index:n.low,isFound:!1}},Mn=(e,t)=>t.some(t=>An(t,()=>On(t,e))),Nn=/* @__PURE__ */ new WeakSet,Pn=e=>{typeof e==`object`&&(e.kind===`Set`&&(Nn.add(e),e.elements.forEach(Pn)),e.kind===`Function`&&(e.domain.forEach(Pn),e.range.forEach(Pn)))},Fn=(e,t)=>Er(()=>nn(e,t),()=>On(e,t)),In=e=>{for(let t=1;t<e.length;t++)if(zt(e[t-1],e[t])>=0)return!1;return!0},Ln=e=>{for(let t=1;t<e.length;t++)$t(e[t]);if(e.length<2||In(e))return Ht(e);let t=[...e].sort(zt),n=[t[0]];for(let e=1;e<t.length;e++)zt(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ht(n)},Rn=e=>Er(()=>Ln(e),()=>({kind:`MixedSet`,elements:e})),zn=Ht([]),Bn=(e,t)=>{if(e.elements.length===0||t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ht(i)},Vn=(e,t)=>{let n=e.elements,r=t.elements,i=[],a=0;for(let e=0;e<n.length;e++){let t=n[e];for(;a<r.length&&zt(r[a],t)<0;)a++;a<r.length&&zt(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ht(i)},Hn=(e,t)=>{if(e.elements.length===0)return t;if(t.elements.length===0)return e;let n=e.elements,r=t.elements,i=[],a=[],o=0,s=0;for(;o<n.length&&s<r.length;){let e=zt(n[o],r[s]);e<0?i.push(n[o++]):e>0?(a.push(r[s]),i.push(r[s++])):(i.push(n[o++]),s++)}for(;o<n.length;)i.push(n[o++]);for(;s<r.length;)a.push(r[s]),i.push(r[s++]);if(a.length===0)return e;let c=Ht(i);if(e.hash!==0&&e.hash!==Kr){let t=e.hash,n=0;for(;n<a.length;n++){let e=Zr(a[n]);if(e===Kr)break;t=t+Wr(e)|0}n===a.length&&(c.hash=t)}if(e.fingerprint!==0){let t=e.fingerprint;for(let e=0;e<a.length;e++)t=t+ti(a[e])|0;c.fingerprint=t}return c},Un=e=>{let t=e.length<2?e:[...e].sort((e,t)=>zt(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&zt(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Ut(n,r)},Wn=e=>{let t=Un(e);return t.domain.length!==e.length||e.some(e=>typeof e[0]!=`string`)||e.every((e,n)=>e[0]===t.domain[n])?t:gt(t,e.map(e=>e[0]))},Gn=[],Kn=[],qn=/* @__PURE__ */ new WeakMap,Jn=e=>{let t=Gn[e];if(t)return t;let n=Array.from({length:e},(e,t)=>t+1);return Gn[e]=n,n},Yn=e=>{if(yr(e),e.low===1&&e.high>=1)return Jn(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Xn=e=>e.length>0&&(e===Gn[e.length]||qn.has(e)),Zn=e=>{let t=L(e).elements;return Xn(t)&&(typeof e!=`object`||e.kind!==`Interval`)?[...t]:t},Qn=e=>{let t=Kn[e];if(t)return t;let n={kind:`Interval`,low:1,high:e};return Kn[e]=n,n},$n=e=>Gt(Ut(Jn(e.length),e),`tuple`),er=e=>Gt(Un(e),`record`),tr=e=>N(e)&&!Pt(e),nr=(e,t=!1)=>`UNION(${z(e.base,t)})`,rr=(e,t=e=>L(e).elements)=>{if(!tr(e.base))throw new y(`Attempted to enumerate the nonenumerable set:\n${nr(e)}`);return t(e.base)},ir=(e,t,n)=>{if(tr(e))return e;throw new y(t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${z(e)}\nwhen enumerating:\n${nr(n)}`)},I=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`InfiniteSet`:case`SequenceSet`:return!1;case`Subset`:case`FilteredSet`:return I(e.base);case`FunctionSet`:return I(e.domain)&&I(e.range)||ar(e.domain)===!0||ar(e)===!0;case`RecordSet`:return e.sets.every(I)||ar(e)===!0;case`ProductSet`:return e.factors.every(I)||ar(e)===!0;case`Union`:return I(e.base)&&pr(e.base).every(I);case`SetOperation`:return e.operator===`\\cup`?I(e.left)&&I(e.right):e.operator===`\\cap`?I(e.left)||I(e.right):I(e.left);default:return!1}},ar=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:return e.name===`Any`&&void 0;case`Subset`:case`SequenceSet`:return!1;case`FunctionSet`:{let t=ar(e.domain);return t===void 0?void 0:!t&&ar(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=ar(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return I(e)?L(e).elements.length===0:void 0;default:return}},or=e=>{let t=e.reduce((e,t)=>e*t.length,1),n=[],r=e.map(()=>0);for(let i=0;i<t;i++){n.push(e.map((e,t)=>e[r[t]]));for(let t=e.length-1;t>=0&&(r[t]++,!(r[t]<e[t].length));t--)r[t]=0}return n},sr=(e,t)=>{for(let n=e.length-1;n>=0;n--)if(e[n]<t-e.length+n){e[n]++;for(let t=n+1;t<e.length;t++)e[t]=e[t-1]+1;return!0}return!1},cr=e=>{if(typeof e!=`object`||e.kind!==`Subset`||Pt(e.base))return;let t=L(e.base).elements;if(t.length<=30)return;let n={index:-1,indices:[0]},r=e=>{for(e<=n.index&&(n.index=-1);n.index<e;)n.index===-1?n.indices=[]:sr(n.indices,t.length)||(n.indices=Array.from({length:n.indices.length+1},(e,t)=>t)),n.index++;return Ht(n.indices.map(e=>t[e]))},i=2**t.length,a=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<i;return new Proxy([],{get:(e,t,n)=>t===`length`?i:a(t)?r(Number(t)):Reflect.get(e,t,n),has:(e,t)=>a(t)||Reflect.has(e,t)})},lr=e=>{let t=[];for(let n=0;n<=e.length;n++){let r=Array.from({length:n},(e,t)=>t);do t.push(Ht(r.map(t=>e[t])));while(sr(r,e.length))}return t},ur=(e,t,n)=>{let r=[];for(let i=0;i<e.length;i++){let a=e[i];if(Pt(a))throw new y(n(a,i));let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},dr=(e,t=e=>L(e).elements)=>{if(typeof e!=`object`)throw new y(`Expected a set but found ${z(e)}`);switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return kn(e.elements);case`Interval`:{let t=Yn(e);return t!==Gn[t.length]&&qn.set(t,e),t}case`Subset`:{if(yr(e.base)===0)return lr([]);if(!N(e.base))throw new y(`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${dt(z(e.base))}`);let t=L(e.base).elements;if(t.length>30)throw new y(vr(e));return lr(t)}case`FunctionSet`:{if(!Ot.is174&&R(e))return[];if(Pt(e.domain))throw new y(`Attempted to enumerate a set of the form [D -> R],but the domain D:\n${z(e.domain)}\ncannot be enumerated.`);let n=Zn(e.domain);if((n.length>0||Ot.is174)&&Pt(e.range))throw new y(`Attempted to enumerate a set of the form [D -> R],but the range R:\n${z(e.range)}\ncannot be enumerated.`);let r=n.length===0?[]:t(e.range);return or(n.map(()=>r)).map(e=>Ut(n,e))}case`RecordSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.sets,t,(t,n)=>`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[n]}' field:\n${z(t)}`);return or(n).map(t=>er(e.names.map((e,n)=>[e,t[n]])))}case`ProductSet`:{if(!Ot.is174&&R(e))return[];let n=ur(e.factors,t,(e,t)=>`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${z(e)}`);return or(n).map($n)}case`FilteredSet`:if(!N(e.base)||Pt(e.base))throw new y(`Attempted to enumerate { x \\in S : p(x) } when S:\n${z(e.base)}\nis not enumerable`);return L(e.base).elements.filter(e.test);case`Union`:{let t=rr(e).flatMap((t,n)=>L(ir(t,n,e)).elements);return L(Rn(t)).elements}case`SetOperation`:{if(e.operator===`\\cup`&&(!tr(e.left)||!tr(e.right)))throw new y(`Attempted to enumerate S \\cup T when S:\n${z(e.left)}\nand T:\n${z(e.right)}\nare not both enumerable`);if(e.operator===`\\cap`&&!tr(e.left)&&!tr(e.right))throw new y(`Attempted to enumerate S \\cap T when neither S:\n${z(e.left)}\nnor T:\n${z(e.right)}\nis enumerable`);if(e.operator===`\\`&&!tr(e.left))throw new y(`Attempted to enumerate S \\ T when S:\n${z(e.left)}\nis not enumerable.`);if(e.operator===`\\cup`)return Hn(L(e.left),L(e.right)).elements;let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return L(n).elements.filter(t=>Dr(t,r)===(e.operator===`\\cap`))}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to enumerate the non-enumerable set ${z(e)}`);default:throw new y(`Expected a set but found ${z(e)}`)}},fr=/* @__PURE__ */ new WeakMap,L=e=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ht(dr(e));let t=typeof e==`object`?fr.get(e):void 0;if(t)return t;let n=Tr.sets;n?.push(e);let r=dr(e);n?.pop();let i=typeof e==`object`&&(e.kind===`MixedSet`||e.kind===`Union`||e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`ProductSet`||e.kind===`FunctionSet`||e.kind===`Subset`)?Ht(r):Ln(r);return typeof e==`object`&&fr.set(e,i),i},pr=e=>{if(typeof e!=`object`||Yt.has(e))return L(e).elements;let t=Tr.sets;t?.push(e);let n=gr(e);return t?.pop(),n},mr=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,hr=e=>typeof e!=`object`||Yt.has(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?hr(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||hr(e.left)||hr(e.right):mr(e)?.some(hr)??!1,gr=e=>{if(e.kind===`Union`)return rr(e,pr).flatMap((t,n)=>pr(ir(t,n,e)));if(e.kind===`FilteredSet`&&!Pt(e.base))return pr(e.base).filter(e.test);if(mr(e)?.some(hr))return dr(e,pr);if(e.kind!==`SetOperation`)return L(e).elements;if(e.operator===`\\cup`)return!tr(e.left)||!tr(e.right)?L(e).elements:[...pr(e.left),...pr(e.right)];let t=e.operator===`\\`||tr(e.left),n=t?e.left:e.right,r=t?e.right:e.left;return tr(n)?pr(n).filter(t=>Dr(t,r)===(e.operator===`\\cap`)):L(e).elements},R=e=>{if(typeof e!=`object`||!N(e))throw new y(`Shouldn't call isEmpty() on value ${z(e)}`);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return e.low>e.high;case`InfiniteSet`:if(e.name===`Any`)throw new y(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1;case`ProductSet`:return e.factors.some(R);case`RecordSet`:return e.sets.some(R);case`FunctionSet`:return!R(e.domain)&&R(e.range);case`Union`:return rr(e).every((t,n)=>R(ir(t,n,e)));default:return L(e).elements.length===0}},_r=(e,t,n)=>e.reduce((e,r)=>{let i=e*yr(r,t);if(i>2147483647)throw new y(n());return i},1),vr=e=>`Overflow when computing the number of elements in:\n${z(e)}`,yr=(e,t)=>{if(typeof e!=`object`)throw new y(`Attempted to compute the number of elements in the ${typeof e==`number`?`integer`:typeof e==`string`?`string`:`boolean`} ${z(e)}.`);switch(e.kind){case`ModelValue`:throw new y(`Attempted to compute the number of elements in the model value ${z(e)}.`);case`Function`:return e.domain.length;case`LazyFunction`:return yr(e.domain,t);case`Interval`:{let t=Math.max(0,e.high-e.low+1);if(t>2147483647)throw new y(`Size of interval value exceeds the maximum representable size (32bits): ${e.low}..${e.high}.`);return t}case`InfiniteSet`:case`SequenceSet`:throw new y(`Attempted to compute the number of elements in the overridden value ${z(e)}.`);case`Subset`:{let n=yr(e.base,t);if(n>=31)throw new y(vr(e));return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(R(e.domain))return 1;if(R(e.range))return 0;if(yr(e.range,t)===1)return 1}let n=yr(e.domain,t),r=yr(e.range,t);if(r<=1)return n===0?1:r;let i={value:1};for(let t=0;t<n;t++)if(i.value*=r,i.value>2147483647)throw new y(vr(e));return i.value}case`RecordSet`:return t!==`1.7.4`&&R(e)?0:_r(e.sets,t,()=>vr(e));case`ProductSet`:return t!==`1.7.4`&&R(e)?0:_r(e.factors,t,()=>`Overflow when computing the number of elements in ${z(e)}`);default:return $t(e),L(e).elements.length}},br=e=>`Attempted to check if the set ${z(e)}is finite.`,xr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)throw new y(`Attempted to check if the ${pt(e)} ${z(e)} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new y(`Attempted to check if the function:\n${z(e)}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return xr(e.base)&&R(e.base);case`Subset`:return xr(e.base);case`FunctionSet`:{let t=xr(e.domain);if(t&&R(e.domain))return!0;let n=xr(e.range);return n&&R(e.range)?!0:n&&(t||yr(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n={isAllFinite:!0};for(let e of t)if(!xr(e))n.isAllFinite=!1;else if(R(e))return!0;return n.isAllFinite}case`Union`:if(!tr(e.base))throw new y(`Attempted to check if the nonenumerable set:\n${nr(e)}\nis a finite set.`);return L(e.base).elements.every(xr);case`SetOperation`:if(e.operator===`\\cup`)return xr(e.left)&&xr(e.right);if(e.operator===`\\cap`){if(!xr(e.left)&&!xr(e.right))throw new y(br(e));return!0}if(xr(e.left))return!0;if(!xr(e.right))throw new y(br(e));return!1;case`FilteredSet`:if(!xr(e.base))throw new y(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${z(e.base)}\nis finite.`);return!0}},Sr=(e,t,n=zt)=>{let r={low:0,high:e.length-1};for(;r.low<=r.high;){let i=r.low+r.high>>1,a=n(e[i],t);if(a===0)return i;a<0?r.low=i+1:r.high=i-1}return-1},Cr=e=>{if(typeof e!=`object`||!P(e))return;let t=Ar(e);return t.domain.every((e,t)=>e===t+1)?t.range:void 0},wr=(e,t)=>{let n=`Attempted to check if the value:\n${z(e)}\nis an element of the`;if(!P(t))return`${n} ${pt(t)} ${z(t)}`;let r=Kt(t);return r===`record`?`Attempted to check if element:\n${z(e)}\nis in the record:\n${z(t)}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${z(t)}`},Tr={sets:void 0},Er=(e,t)=>{let n=Tr.sets,r=Tr.callStack,i=n?.length??0,a=r&&{...r,length:r.expressions.length};try{return e()}catch(e){if(!(e instanceof y))throw e;return n&&(n.length=i),r&&a&&(r.expressions.length=a.length,r.isFrozen=a.isFrozen,r.fingerprint=a.fingerprint),t(e)}},Dr=(e,t)=>{let n=Tr.sets;if(n===void 0)return Or(e,t);n.push(t);let r=Or(e,t);return n.pop(),r},Or=(e,t)=>{if(!N(t))throw new y(wr(e,t));switch(t.kind){case`Set`:return $t(e),Er(()=>Sr(t.elements,e)!==-1,()=>Nn.has(t)?jn(e,t.elements).isFound:Mn(e,t.elements));case`MixedSet`:return Mn(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&!F(e))throw new y(`Attempted to check if the value:\n${z(e)}\nis in the integer interval ${z(t)}`);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(F(e))return!1;if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new y(`Attempted to check if the value:\n${z(e)}\nis an element of ${t.name}.`);return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:if(!N(e)||Pt(e))throw new y(`Attempted to check if the non-enumerable value\n${dt(z(e))}\nis element of\n${dt(z(t))}`);return L(e).elements.every(e=>Dr(e,t.base));case`FunctionSet`:{if(!P(e)){if(F(e))return!1;throw new y(`Attempted to check if \n${z(e)}\nwhich is not a TLC function value, is in the set of functions:\n${dt(z(t))}`)}let n=Ar(e),r=sn(n.domain);return(r===void 0?Fn(t.domain,Ht(n.domain)):Fn({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range.every(e=>Dr(e,t.range))}case`RecordSet`:{let n=P(e)?Ar(e):void 0;if(!n||!bt(n.domain)){if(F(e))return!1;throw new y(`Attempted to check if non-record\n${z(e)}\nis in the set of records:\n${z(t)}`)}return n.domain.length===t.names.length&&t.names.every((e,r)=>{let i=Sr(n.domain,e);return i!==-1&&Dr(n.range[i],t.sets[r])})}case`ProductSet`:{let n=P(e)?Cr(e):void 0;if(n===void 0){if(P(e)&&Ar(e).domain.every(e=>typeof e==`number`)||F(e))return!1;throw new y(`Attempted to check if non-tuple\n${z(e)}\nis in the set of tuples:\n${z(t)}`)}return n.length===t.factors.length&&n.every((e,n)=>Dr(e,t.factors[n]))}case`FilteredSet`:return Dr(e,t.base)&&t.test(e);case`Union`:if(!tr(t.base))throw new y(`Attempted to check if:\n ${z(e)}\nis an element of the non-enumerable set:\n ${nr(t)}`);return L(t.base).elements.some(t=>Dr(e,t));case`SetOperation`:return t.operator===`\\cup`?Dr(e,t.left)||Dr(e,t.right):Dr(e,t.left)&&Dr(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Cr(e);if(n===void 0){if(F(e))return!1;throw new y(`Attempted to check if the value:\n${dt(z(e))}\nis an element of ${dt(z(t))}.`)}return n.every(e=>Dr(e,t.base))}default:throw new y(wr(e,t))}},kr=(e,t,n)=>e===t?!0:typeof e!=`object`||typeof t!=`object`||typeof n!=`object`||e.kind!==`Function`||t.kind!==`Function`||n.kind!==`FunctionSet`||e.domain!==t.domain?Dr(e,n):e.range.every((e,r)=>kr(e,t.range[r],n.range)),Ar=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){I(e.domain)||yr(e.domain);let t=Zn(e.domain);return Gt(Ut(t,t.map(t=>e.apply(t))),Kt(e))}throw new y(`Expected a function but found ${z(e)}`)},jr=(e,t,n)=>{let r=dt(z(e)),i=dt(z(t)),a=n===`1.7.4`;switch(Kt(e)){case`lambda`:return`In applying the function\n${r},\nthe first argument is:\n${i}\nwhich is not in its domain.\n`;case`tuple`:return typeof t==`number`?a?`Attempted to apply tuple\n${r}\nto integer ${t} which is out of domain.`:`Attempted to access index ${t} of tuple\n${r}\nwhich is out of bounds.`:a?`Attempted to apply tuple to a non-integer argument.`:`Attempted to access tuple at a non integral index: ${i}`;case`record`:return typeof t==`string`?a?`Attempted to apply the record\n${r}\nto nonexistent record field ${t}.`:`Attempted to access nonexistent field '${t}' of record\n${r}`:a?`Attempted to apply record to a non-string value ${i}.`:`Attempted to access record by a non-string argument: ${i}`;default:return`Attempted to apply function:\n${r}\nto argument ${i}, which is not in the domain of the function.`}},Mr=(e,t)=>{if(!Ot.is174)return jr(e,t);let n=dt(z(t));return Kt(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},Nr=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}if(e.length<=8){for(let n=0;n<e.length;n++)if(e[n]===t)return n}return Sr(e,t)},Pr=e=>new y(`Attempted to apply function with integer domain to the non-integer argument ${dt(z(e))}`),Fr=(e,t,n)=>{let r=e.domain;if(typeof t!=typeof r[0]){let i=Kt(e),a=i===`tuple`?`number`:i===`record`?`string`:void 0;if(a!==void 0&&typeof t!==a)throw new y(n(e,t));if(a===void 0&&!Ot.is174&&Xn(r))throw Pr(t)}return Er(()=>Nr(r,t),e=>{throw Ot.is174||r.length<32?r.forEach(e=>On(e,t)):Sr(r,t,Cn),e})},Ir=(e,t,n)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(!Dr(t,e.domain))throw new y(Kt(e)===`lambda`?jr(e,t):`Attempted to apply a function to ${z(t)}, which is not in its domain`);return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new y(`Attempted to apply ${z(e)}, which is not a function`);let r=n??jr,i=Fr(e,t,r);if(i===-1)throw new y(r(e,t));return e.range[i]},Lr=e=>Xn(e)?qn.get(e)??Qn(e.length):void 0,Rr=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`)return e.domain;let t=Ar(e).domain;return Lr(t)??Ht(t)},zr=(e,t,n,r=!1)=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&(r||!I(e.domain))){if(!Dr(t,e.domain))return e;let r=n(e.apply(t));return Gt({kind:`LazyFunction`,domain:e.domain,apply:n=>Fn(t,n)?r:e.apply(n),source:e.source},Kt(e))}if(!P(e))throw new y(`Attempted to apply EXCEPT construct to the value ${dt(z(e))}.`);let i=Ar(e),a=Fr(i,t,Mr);if(a===-1)return i;let o=[...i.range],s=i.range[a],c=n(s);o[a]=c;let l=Gt(Ut(i.domain,o),Kt(i));if(l.writtenKeys=i.writtenKeys,i.hash!==0&&i.hash!==Kr){let e=Zr(c);if(e!==Kr){let t=Zr(i.domain[a]);l.hash=s===c?i.hash:i.hash-Gr(t,Zr(s))+Gr(t,e)|0}}if(i.fingerprint!==0){let e=i.domain[a];l.fingerprint=s===c?i.fingerprint:i.fingerprint-ni(e,s)+ni(e,c)|0}return l},Br=/* @__PURE__ */ new WeakMap,Vr=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Hr=(e,t)=>Math.imul(e^t,16777619),Ur=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Vr(t)},Wr=e=>Vr(e+2654435769|0),Gr=(e,t)=>Vr(Math.imul(e,668265261)+t|0),Kr=795548749,qr=e=>{if(e.kind===`ModelValue`)return Vr(Hr(Ur(e.name),109));if(N(e)){if(!I(e))return Kr;let t=L(e).elements,n=1940243425;for(let e=0;e<t.length;e++){let r=Zr(t[e]);if(r===Kr)return Kr;n=n+Wr(r)|0}return n}if(e.kind===`LazyFunction`&&!I(e.domain))return Kr;let t=Ar(e),n=1725019383;for(let e=0;e<t.domain.length;e++){let r=Zr(t.domain[e]),i=Zr(t.range[e]);if(r===Kr||i===Kr)return Kr;n=n+Gr(r,i)|0}return n},Jr=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return;if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw new y(`TLC has found a state in which the value of a variable contains ${z(e)}`);if(N(e)){L(e).elements.forEach(Jr);return}let t=Ar(e);t.domain.forEach(Jr),t.range.forEach(Jr)},Yr=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{Zr(e)===Kr&&Jr(e);return}catch(e){if(!(e instanceof y))throw e;return e}},Xr=e=>{switch(e.kind){case`Set`:case`MixedSet`:return e.elements;case`Function`:return[...e.domain,...e.range];case`Subset`:case`SequenceSet`:case`FilteredSet`:case`Union`:return[e.base];case`FunctionSet`:return[e.domain,e.range];case`RecordSet`:return e.sets;case`ProductSet`:return e.factors;case`SetOperation`:return[e.left,e.right];case`LazyFunction`:return[e.domain];default:return[]}},Zr=e=>{if(typeof e==`number`)return Vr(e^1540483477);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Ur(e);if(e.kind===`Set`||e.kind===`Function`)return e.hash===0&&(e.hash=qr(e)),e.hash;let t=Br.get(e);if(t!==void 0)return t;let n=qr(e);return Br.set(e,n),n},Qr=/* @__PURE__ */ new WeakMap,$r=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},ei=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return $r(t)},ti=e=>$r(ii(e)+2135587861|0),ni=(e,t)=>$r(Math.imul(ii(e),374761393)+ii(t)|0),ri=e=>{if(e.kind===`ModelValue`)return $r(ei(e.name)^60);if(N(e)){if(!I(e))return ei(oi(e));let t=L(e).elements,n=461845907;for(let e=0;e<t.length;e++)n=n+ti(t[e])|0;return n}let t=Ar(e),n=1291169091;for(let e=0;e<t.domain.length;e++)n=n+ni(t.domain[e],t.range[e])|0;return n},ii=e=>{if(typeof e==`number`)return $r(e^1759714724);if(typeof e==`boolean`)return e?1000000007:521288629;if(typeof e==`string`)return ei(e);if(e.kind===`Set`||e.kind===`Function`)return e.fingerprint===0&&(e.fingerprint=ri(e)),e.fingerprint;let t=Qr.get(e);if(t!==void 0)return t;let n=ri(e);return Qr.set(e,n),n},ai=/* @__PURE__ */ new WeakMap,oi=e=>{if(typeof e==`boolean`)return e?`T`:`F`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return JSON.stringify(e);let t=ai.get(e);if(t!==void 0)return t;let n=si(e);return ai.set(e,n),n},si=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${oi(e.base)}>`;if(e.kind===`FilteredSet`&&!I(e))throw new y(`Attempted to compare the non-enumerable set ${z(e)} with another value`);if(N(e))return I(e)?`{${L(e).elements.map(oi).join(`,`)}}`:`<${e.kind} ${z(e)}>`;let t=Ar(e);return`(${t.domain.map((e,n)=>`${oi(e)}:${oi(t.range[n])}`).join(`,`)})`},ci=e=>`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\t/g,`\\t`)}"`,li=e=>e.reduce((e,t)=>e===0?0:e*yr(t),1),ui=e=>{if(e.kind===`Subset`)return yr(e.base)<=6?L(e):void 0;if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return L(e);if(e.kind===`FunctionSet`&&I(e.domain)&&yr(e.domain)===0)return Ht([Ut([],[])]);let t=e.kind===`FunctionSet`?yr(e.range)**yr(e.domain):li(e.kind===`RecordSet`?e.sets:e.factors);return t===0?zn:t<=1999?L(e):void 0},di=(e,t)=>{if(t)return ui(e);if(I(e))try{return ui(e)}catch(e){if(e instanceof y)return;throw e}},fi=(e,t)=>{let n=e=>z(e,t);switch(e.kind){case`Subset`:return typeof e.base==`object`&&e.base.kind===`Interval`?`SUBSET (${n(e.base)})`:`SUBSET ${n(e.base)}`;case`FunctionSet`:return`[${n(e.domain)} -> ${n(e.range)}]`;case`RecordSet`:return`[${e.names.map((t,r)=>`${t}: ${n(e.sets[r])}`).join(`, `)}]`;case`ProductSet`:return`(${e.factors.map(n).join(` \\X `)})`;case`SetOperation`:return`${n(e.left)} ${e.operator} ${n(e.right)}`;case`FilteredSet`:return e.source?`{${e.source.names} \\in ${n(e.base)} : <expression ${e.source.predicate}> }`:`{x \\in ${n(e.base)} : ...}`;case`Union`:return nr(e,t)}},pi=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),mi=e=>{if(I(e.domain))try{return Ar(e)}catch(e){if(e instanceof y)return;throw e}},z=(e,t=!1,n=!1)=>{let r=e=>z(e,t,n);if(typeof e==`boolean`)return e?`TRUE`:`FALSE`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return ci(e);switch(e.kind){case`ModelValue`:return e.name;case`Set`:return`{${e.elements.map(r).join(`, `)}}`;case`MixedSet`:return r(L(e));case`Interval`:return e.low<=e.high?`${e.low}..${e.high}`:`{}`;case`InfiniteSet`:return e.name===`Any`?`ANY`:e.name;case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let n=di(e,t);return n?r(n):fi(e,t)}case`SequenceSet`:return`Seq(${r(e.base)})`;case`Function`:case`LazyFunction`:{let i=e.kind===`LazyFunction`?mi(e):e;if(i===void 0){let t=e.kind===`LazyFunction`?e.source:void 0;return t?`[${t.parameters.map(e=>`${e.name} \\in ${z(e.domain)}`).join(`, `)} |-> <expression ${t.body}>]`:`<function>`}if(i.domain.length===0&&Ot.is174&&Kt(e)!==`tuple`)return`<< >>`;let a=r=>z(r,t,n&&Kt(e)!==`lambda`);return i.domain.every((e,t)=>e===t+1)?`<<${i.range.map(a).join(`, `)}>>`:Kt(e)===`record`||i.domain.every(e=>typeof e==`string`&&pi(e))?`[${(n||i.hash!==0||i.fingerprint!==0?i.domain.map((e,t)=>[e,i.range[t]]):_t(i)).map(e=>`${String(e[0])} |-> ${a(e[1])}`).join(`, `)}]`:`(${i.domain.map((e,t)=>`${r(e)} :> ${a(i.range[t])}`).join(` @@ `)})`}}},hi=e=>{let t=Object.entries(e);return t.map(([e,n])=>`${t.length===1?``:`/\\ `}${e} = ${dt(z(n))}\n`).join(``)},gi=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},_i=()=>{let e=/* @__PURE__ */ new Map,t=n=>{if(typeof n!=`object`||n.kind!==`Set`&&n.kind!==`Function`)return n;let r=Zr(n),i=e.get(r);if(i!==void 0&&!Array.isArray(i)&&(i===n||on(i,n)))return i;if(Array.isArray(i)){for(let e=0;e<i.length;e++)if(i[e]===n||on(i[e],n))return i[e]}return n.kind===`Set`?gi(n.elements,t):(gi(n.domain,t),gi(n.range,t)),i===void 0?e.set(r,n):Array.isArray(i)?i.push(n):e.set(r,[i,n]),n};return e=>{for(let n=0;n<e.length;n++)e[n]=t(e[n]);return e}},vi=e=>{switch(e.kind){case`Number`:case`Decimal`:case`String`:case`Identifier`:case`OperatorReference`:case`ExceptAt`:return[];case`Apply`:return e.args;case`Lambda`:return[e.body];case`And`:case`Or`:return e.operands;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:return[e.expression];case`If`:return[e.condition,e.consequent,e.alternative];case`Case`:return[...e.arms.flatMap(e=>[e.condition,e.body]),...e.other?[e.other]:[]];case`Let`:return[...e.definitions.flatMap(e=>e.kind===`Function`?[...e.bounds.map(e=>e.set),e.body]:[e.body]),e.body];case`Forall`:case`Exists`:return[...e.bounds.map(e=>e.set),e.body];case`UnboundedQuantifier`:return[e.body];case`Choose`:return[...e.set?[e.set]:[],e.body];case`SetEnumeration`:case`Tuple`:return e.elements;case`SetFilter`:return[e.bound.set,e.predicate];case`SetMap`:return[e.expression,...e.bounds.map(e=>e.set)];case`FunctionConstruction`:return[...e.bounds.map(e=>e.set),e.body];case`FunctionSet`:return[e.domain,e.range];case`Record`:case`RecordSet`:return e.fields.map(e=>e.value);case`Except`:return[e.function,...e.updates.flatMap(e=>[...e.path.flatMap(e=>e.kind===`Index`?e.args:[]),e.value])];case`FunctionApplication`:return[e.function,...e.args];case`Bracket`:return e.args;case`FieldAccess`:return[e.record];case`Product`:return e.factors;case`BoxAction`:case`AngleAction`:return[e.action,e.subscript];case`WeakFairness`:case`StrongFairness`:return[e.subscript,e.action];case`Label`:return[e.body];case`Subexpression`:return e.selectors.flatMap(e=>`args`in e?e.args:[])}},B=e=>(e.kind===`Identifier`||e.kind===`Apply`)&&e.resolution?.kind===`Local`,yi=/* @__PURE__ */ new Set(/* @__PURE__ */ `=,#,~,<=>,/\\,\\/,=>,\\in,\\notin,\\subseteq,\\cup,\\cap,\\,SUBSET,UNION,DOMAIN,+,-,*,^,\\div,%,..,Seq,IsFiniteSet,RandomElement`.split(`,`)),bi=(e,t)=>yi.has(e)?new y(t):new S(t),xi=e=>typeof e==`object`&&e.kind===`Operator`,V=(e,t,n)=>{let r=e[t];if(r===void 0||xi(r))throw bi(n,`${n} expects a value as argument ${t+1}`);return r},Si=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`number`)throw bi(n,`${n} expects an integer but received ${z(r)}`);return r},Ci=(e,t,n)=>{let r=V(e,t,n);if(typeof r!=`boolean`)throw bi(n,`${n} expects a boolean but received ${z(r)}`);return r},wi=(e,t,n)=>{let r=V(e,t,n);if(!N(r))throw bi(n,`${n} expects a set but received ${z(r)}`);return r},Ti=(e,t,n)=>{let r=wi(e,t,n);if(!I(r))throw bi(n,`${n} cannot enumerate the non-enumerable set ${z(r)}`);return r},Ei=(e,t,n)=>L(Ti(e,t,n)),Di=(e,t,n)=>Ei(e,t,n).elements,Oi=(e,t,n)=>{let r=V(e,t,n),i=Cr(r);if(!i)throw bi(n,`${n} expects a sequence but received ${z(r)}`);return i},ki=(e,t,n)=>{let r=V(e,t,n);if(!P(r))throw bi(n,`${n} expects a function but received ${z(r)}`);return Ar(r)},Ai=(e,t,n)=>{let r=e[t];if(r===void 0||!xi(r))throw bi(n,`${n} expects an operator as argument ${t+1}`);return r},ji=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),H=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:t===1?e=>n([e]):void 0,evaluateBinary:t===2?(e,t)=>n([e,t]):void 0}),Mi=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),Ni=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),Pi=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(V(n,0,e),V(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),Fi=e=>e>2147483647||e<-2147483648,Ii=e=>new S(`Overflow when computing ${e}`),Li={ModelValue:`ModelValue`,Set:`SetEnumValue`,Interval:`IntervalValue`,InfiniteSet:`UserValue`,SequenceSet:`UserValue`,Subset:`SubsetValue`,FunctionSet:`SetOfFcnsValue`,RecordSet:`SetOfRcdsValue`,ProductSet:`SetOfTuplesValue`,FilteredSet:`SetPredValue`,LazyFunction:`FcnLambdaValue`,Union:`UnionValue`,MixedSet:`SetEnumValue`},Ri={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},zi={BoolValue:`a Boolean value`,IntValue:`an integer`,StringValue:`a string`,RecordValue:`a record`,SetEnumValue:`a set of the form {e1, ... ,eN}`,SetPredValue:`a set of the form {x \\in S : expr}`,TupleValue:`a tuple`,FcnLambdaValue:`a function of the form [x \\in S |-> expr]`,FcnRcdValue:`a function of the form (d1 :> e1 @@ ... @@ dN :> eN)`,SetOfFcnsValue:`a set of the form [S -> T]`,SetOfRcdsValue:`a set of the form [d1 : S1, ... , dN : SN]`,SetOfTuplesValue:`a cartesian product`,SubsetValue:`a set of the form SUBSET S`,SetDiffValue:`a set of the form S \\ T`,SetCapValue:`a set of the form S \\cap T`,SetCupValue:`a set of the form S \\cup T`,ModelValue:`a model value`,UserValue:`a special set constant`,IntervalValue:`a set of the form i..j`,UnionValue:`a set of the form UNION S`},Bi={lambda:`FcnLambdaValue`,tuple:`TupleValue`,record:`RecordValue`},Vi=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Ri[e.operator];if(e.kind!==`Function`)return Li[e.kind];let t=Kt(e);return t===void 0?`FcnRcdValue`:Bi[t]},Hi=e=>zi[Vi(e)],Ui=(e,t)=>new y(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),Wi=(e,t)=>{let n=n=>(...r)=>{let i=Tr.sets?.length??0;try{return n(...r)}catch(n){throw n instanceof y&&(e.isLazy===!0||!(n instanceof S))?(Tr.sets&&(Tr.sets.length=i),Ui(t,n.message)):n}};return{...e,evaluate:n(e.evaluate),evaluateUnary:e.evaluateUnary&&n(e.evaluateUnary),evaluateBinary:e.evaluateBinary&&n(e.evaluateBinary)}},Gi=(e,t)=>{if(typeof e!=`number`)throw Ui(t,`Cannot cast tlc2.value.impl.${Vi(e)} to tlc2.value.impl.IntValue`);return e},Ki=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,qi=(e,t,n,r)=>{let i=Ki(e,n,`IntValue`,2);return Pi(t,(e,n)=>{let a=Gi(e,i),o=Gi(n,i),s=r(a,o);if(Fi(s))throw Ii(`${a}${t}${o}`);return s})},Ji=(e,t,n)=>{if(typeof e!=`number`)throw new S(`The ${t} argument of ${n} should be an integer, but instead it is:\n${z(e)}`);return e},Yi=(e,t,n=e)=>Pi(e,(e,r)=>t(Ji(e,`first`,n),Ji(r,`second`,n))),Xi=(e,t,n)=>({...Ni(e,t,n),isLazy:!0}),Zi=(e,t,n)=>{let r=Ai(e,t,n);return()=>r.call([])},Qi=/* @__PURE__ */ new Set([`Apply`,`And`,`Or`,`If`,`FunctionApplication`,`FieldAccess`,`Record`,`Tuple`,`SetEnumeration`,`Prime`,`Unchanged`,`Forall`,`Exists`]),$i=()=>({bool:gl,condition:(e,t)=>{if(typeof e!=`boolean`)throw nl(t,e);return e},junct:(e,t,n)=>{if(typeof e!=`boolean`)throw rl(t,n,e);return e},apply:Ir,expectFunction:pl,tuple:$n,set:Rn,record:tn,writtenRecord:vt,equal:nn,enumerate:Dl,unassigned:(e,t)=>{throw Dd(e,t)},primeOutsideAction:e=>{throw kd(e)},prime:e=>({environment:e.environment,scope:e.scope,state:e.next,next:void 0,isKeepLazy:e.isKeepLazy}),keepLazyContext:ml,extend:(e,t,n)=>({environment:e.environment,scope:t.reduce((e,t,r)=>dl(e,t,n[r]),e.scope),state:e.state,next:e.next,isKeepLazy:e.isKeepLazy})}),ea={value:void 0},ta=(e,t)=>(e.references.push(t),`reference${e.references.length-1}`),na=e=>`local${e.counter++}`,ra=(e,t=/* @__PURE__ */ new Set)=>(e.kind===`Identifier`&&t.add(e.name),e.kind===`Apply`&&t.add(e.operator),vi(e).forEach(e=>ra(e,t)),t),ia=(e,t,n)=>{let r=ta(e,Wu(t,e.environment)),i=ra(t),a=[...n.locals].filter(([e])=>i.has(e));if(a.length===0)return`${r}(${n.context})`;let o=ta(e,a.map(([e])=>e));return`${r}(extend(${n.context}, ${o}, [${a.map(([,e])=>e).join(`, `)}]))`},aa=(e,t,n)=>{let r=t.kind===`Forall`,i=JSON.stringify(r?`the body of \\A`:`the body of \\E`),a=`quantifier${e.counter++}`,o=[...n.locals.values()],s={context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:new Map(n.locals)},c=t.bounds.map(()=>na(e)),l=t.bounds.map((t,n)=>`const ${c[n]} = enumerate(${ca(e,t.set,s)}, ${ta(e,t.set)}, ${JSON.stringify(e.environment.runtime.version)});`),u=t.bounds.map(t=>{let n=na(e);return t.pattern.kind===`Name`&&s.locals.set(t.pattern.name,n),n}),d=`if (bool(${ca(e,t.body,s)}, ${i}) !== ${r}) return ${!r};`,f=u.reduce((t,n,r)=>{let i=na(e),a=na(e),o=na(e),s=c[r];return`for (let ${i} = 0, ${a} = ${s}.low, ${o} = ${a} === undefined ? ${s}.length : ${s}.high - ${a} + 1; ${i} < ${o}; ${i}++) { const ${n} = ${a} === undefined ? ${s}[${i}] : ${a} + ${i}; ${t} }`},d),p=o.map(e=>`, ${e}`).join(``);return e.helpers.push(`function ${a}(context, state, next${p}) { let primed; ${l.join(` `)} ${f} return ${r}; }`),`${a}(${n.context}, ${n.state}, ${n.isPrimed?`undefined`:n.next}${p})`},oa=(e,t,n)=>{let r=t.args;if(t.operator===`=>`)return`(bool(${ca(e,r[0],n)}, "the left side of =>") ? bool(${ca(e,r[1],n)}, "the right side of =>") : true)`;if(B(t))return ia(e,t,n);let i=$l(t.operator,e.environment);if(i?.kind!==`Builtin`)return ia(e,t,n);if(i.name===`DOMAIN`)return`${ta(e,ol(t))}(${ca(e,r[0],n)})`;if(i.name===`TLCEval`)return ia(e,t,n);if(i.name===`\\subseteq`&&r.length===2)return`${ta(e,sl(t,i))}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`;let a=e.environment;if(i.evaluateUnary&&r.length===1&&Zu(r[0],a))return`${ta(e,i.evaluateUnary)}(${ca(e,r[0],n)})`;let o=r.length===2&&Zu(r[0],a)&&Zu(r[1],a);return i.evaluateBinary&&o?`${ta(e,i.evaluateBinary)}(${ca(e,r[0],n)}, ${ca(e,r[1],n)})`:ia(e,t,n)},sa=(e,t,n)=>{switch(e.kind){case`Identifier`:{if(t.locals.has(e.name))return!0;if(B(e))return!1;let r=lu(e.name,n);return r?.kind===`Variable`||r?.kind===`Value`}case`Prime`:return sa(e.expression,t,n);case`FieldAccess`:return sa(e.record,t,n);case`FunctionApplication`:return[e.function,...e.args].every(e=>sa(e,t,n));default:return!1}},ca=(e,t,n)=>{let r=(t,r=n)=>ca(e,t,r);if(Fu(t)&&Au(t,e.environment))return ia(e,t,n);switch(t.kind){case`Number`:return _u(t.value)?String(t.value):ia(e,t,n);case`String`:return JSON.stringify(t.value);case`Identifier`:{let r=n.locals.get(t.name);if(r)return r;if(B(t))return ia(e,t,n);let i=lu(t.name,e.environment);if(i?.kind===`Variable`){let r=JSON.stringify(t.name),a=ta(e,t);return`(${n.state}?.[${i.index}] ?? unassigned(${r}, ${a}))`}return i?.kind===`Value`?ta(e,i.value):ia(e,t,n)}case`Apply`:return oa(e,t,n);case`And`:case`Or`:{let n=ta(e,t),i=t.kind===`And`?` && `:` || `;return`(${t.operands.map((e,t)=>`junct(${r(e)}, ${n}, ${t})`).join(i)})`}case`If`:return`(condition(${r(t.condition)}, ${ta(e,t)}) ? ${r(t.consequent)} : ${r(t.alternative)})`;case`FunctionApplication`:{xd(t.function);let i=`expectFunction(${sa(t.function,n,e.environment)?r(t.function):ia(e,t.function,{...n,context:`keepLazyContext(${n.context})`})}, ${ta(e,t)})`,a=al(e.environment.runtime.version),o=a?`, ${ta(e,a)}`:``;return t.args.length===1?`apply(${i}, ${r(t.args[0])}${o})`:`apply(${i}, tuple([${t.args.map(e=>r(e)).join(`, `)}])${o})`}case`FieldAccess`:return`${ta(e,il(t))}(${r(t.record)})`;case`Record`:{let i=Td(t.fields);if(Ed(i))return ia(e,t,n);let a=ta(e,i.map(e=>e.name)),o=`[${i.map(e=>r(e.value)).join(`, `)}]`,s=t.fields.map(e=>e.name);return s.every((e,t)=>e===i[t].name)?`record(${a}, ${o})`:`writtenRecord(${a}, ${o}, ${ta(e,s)})`}case`Tuple`:return`tuple([${t.elements.map(e=>r(e)).join(`, `)}])`;case`SetEnumeration`:return`set([${t.elements.map(e=>r(e)).join(`, `)}])`;case`Prime`:{let i=ta(e,t);if(n.isPrimed)return`primeOutsideAction(${i})`;let a={context:`(primed ??= prime(${n.context}))`,state:n.next,next:`undefined`,isPrimed:!0,locals:n.locals};return`(${n.next} === undefined ? primeOutsideAction(${i}) : ${r(t.expression,a)})`}case`Unchanged`:return`equal(${r({kind:`Prime`,expression:t.expression,location:t.location})}, ${r(t.expression)})`;case`Forall`:case`Exists`:return t.bounds.every(e=>e.pattern.kind===`Name`)?aa(e,t,n):ia(e,t,n);default:return ia(e,t,n)}},la=(e,t)=>{if(!Qi.has(e.kind))return;let n={environment:t,references:[],helpers:[],counter:0},r=ca(n,e,{context:`context`,state:`state`,next:`next`,isPrimed:!1,locals:/* @__PURE__ */ new Map}),i=n.references.map((e,t)=>`reference${t}`),a=`${n.helpers.join(`
29
29
  `)}\nreturn (context) => { const state = context.state; const next = context.next; let primed; return ${r}; };`;ea.value??=$i();let o=ea.value,s=Object.keys(o);return Function(...s,...i,a)(...Object.values(o),...n.references)},ua={general:1e3,commandLineError:1102,initialState:2102,nestedExpression:2103,assumptionFalse:2104,assumptionEvaluationError:2105,exceptAppliedToUnknownField:2144,fingerprintFailed:2147,invariantViolatedInitial:2107,incompleteSuccessor:2109,propertyViolatedInitial:2108,invariantViolatedBehavior:2110,invariantEvaluationFailed:2111,actionPropertyViolatedBehavior:2112,actionPropertyEvaluationFailed:2113,deadlockReached:2114,temporalPropertyViolated:2116,behaviorUpToThisPoint:2121,backToState:2122,constantLevelInvariant:2149,javaOverrideLoaded:2168,starting:2185,modelChecking:2187,finished:2186,computingInit:2189,initGenerated1:2190,initGenerated2:2191,checkingTemporal:2192,success:2193,searchDepth:2194,stats:2199,progress:2200,temporalBranches:2212,statePrint2:2217,statePrint3:2218,sanyFinished:2219,startingSany:2220,stateLevelProperty:2255,version:2262,noSpecificationButProperty:2257,noFairnessButProperty:2259,counterExample:2264,checkingTemporalEnd:2267,stateGraphOutdegree:2268,computingInitProgress:2269,livenessSymmetry:2279,livenessConstraints:2284,symmetrySetTooSmall:2300,javaOverrideMismatch:2400,postconditionFalse:2404,postconditionFailed:2405,possibleUnwitnessed:2780,parsingFailed:3002,configFileError:5001},da={none:0,error:1,warning:3,state:4},fa={0:``,1:`Error: `,3:`Warning: `,4:`State `},pa=(e,t=!0,n=`master`)=>{let r=/* @__PURE__ */ new Set;return{isTool:e,version:n,print:(n,i,a)=>{let o=i===da.warning;if(o&&!t)return;let s=o&&!e&&r.size===0?`
30
30
  (Use the -nowarning option to disable this warning.)`:``,c=e?`@!@!@STARTMSG ${n}:${i} @!@!@\n${a}\n@!@!@ENDMSG ${n} @!@!@`:`${fa[i]}${a}${s}`;o&&r.has(c)||(o&&r.add(c),console.log(c))}}},ma=`The configuration file did not specify the initial state predicate.
31
31
  Can also be caused by trying to run TLC on a specification from
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tla-ts",
3
- "version": "0.0.4-dev.a0009b7",
3
+ "version": "0.0.4-dev.e4c2d0e",
4
4
  "description": "A TLA+ interpreter and model checker in TypeScript, 2× faster than TLC",
5
5
  "keywords": [
6
6
  "formal verification",
package/src/values.ts CHANGED
@@ -14,6 +14,7 @@ export interface SetValue {
14
14
  elements: Value[];
15
15
  hash: number;
16
16
  fingerprint: number;
17
+ isFingerprinted: boolean;
17
18
  }
18
19
 
19
20
  // A set enumeration whose elements TLC can't sort, such as {1, "a"}. TLC sorts a set enumeration
@@ -31,6 +32,7 @@ export interface FunctionValue {
31
32
  fingerprint: number;
32
33
  writtenKeys: Value[] | undefined;
33
34
  functionClass: FunctionClass | undefined;
35
+ isFingerprinted: boolean;
34
36
  }
35
37
 
36
38
  export interface IntervalValue {
@@ -433,6 +435,7 @@ export const createSortedSet = (elements: Value[]): SetValue => ({
433
435
  elements,
434
436
  hash: 0,
435
437
  fingerprint: 0,
438
+ isFingerprinted: false,
436
439
  });
437
440
 
438
441
  export const createSortedFunction = (domain: Value[], range: Value[]): FunctionValue => ({
@@ -443,6 +446,7 @@ export const createSortedFunction = (domain: Value[], range: Value[]): FunctionV
443
446
  fingerprint: 0,
444
447
  writtenKeys: undefined,
445
448
  functionClass: undefined,
449
+ isFingerprinted: false,
446
450
  });
447
451
 
448
452
  // TLC words a failed function application by the Java class of the function: FcnLambdaValue for
@@ -512,14 +516,16 @@ const cacheSet = (value: Value) => {
512
516
  // FcnLambdaValue#fingerPrint caches the FcnRcdValue the function enumerates to, which applies it
513
517
  // from then on, so a function TLC has fingerprinted is no longer a lambda.
514
518
  export const markFingerprinted = (value: Value): void => {
515
- if (
516
- (!lambdaPresence.isPresent && !streamedSetPresence.isPresent) ||
517
- typeof value !== "object" ||
518
- fingerprintedValues.has(value)
519
- ) {
519
+ if ((!lambdaPresence.isPresent && !streamedSetPresence.isPresent) || typeof value !== "object") {
520
520
  return;
521
521
  }
522
- fingerprintedValues.add(value);
522
+ if (value.kind === "Function" || value.kind === "Set") {
523
+ if (value.isFingerprinted) return;
524
+ value.isFingerprinted = true;
525
+ } else {
526
+ if (fingerprintedValues.has(value)) return;
527
+ fingerprintedValues.add(value);
528
+ }
523
529
  if (value.kind === "Function") {
524
530
  if (value.functionClass === "lambda") value.functionClass = undefined;
525
531
  value.domain.forEach(markFingerprinted);