tla 0.0.10-dev.80b1ac396 → 0.0.10-dev.85b8486e0
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/run.cjs +1 -1
- package/dist/run.js +1 -1
- package/dist/search.cjs +1 -1
- package/dist/search.js +1 -1
- package/package.json +1 -1
- package/src/values.ts +4 -1
package/dist/search.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("./rolldown-runtime.cjs"),t=require("./worker.cjs"),n=require("./order.cjs"),r=require("./modules.cjs"),i=(e,t)=>t.rootKeys.get(e)??e,a=e=>`line ${e.location.line}, column ${e.location.column}`,o=e=>{let n=e.location.range;return n?t.gt(n):a(e)},s=e=>e.kind===`Number`?e.text??String(e.value):o(e),c=1e3,l={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:` `}},u=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},d=e=>e!==void 0&&/^\p{Nd}$/u.test(e),f=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),p=e=>e.kind!==`Constant`,m=(e,t,n)=>({kind:e,first:t,last:n,children:[]}),h=`Parsed`,g=e=>{let t=t=>{let r=n.er(e,t,u);return e[r]===void 0?void 0:r},r=(n,r,i,a,o)=>{if(r){n.children.push(r);let i=t(r.last+1);if(i===void 0)return;n.last=e.startsWith(o,i)?i+o.length:i}let s=t(n.last);if(s!==void 0)return e[s]===i?(n.last=s,h):a===void 0?l(s):m(a,s,s)},i=(n,r,i)=>{if(!r)return l(n.last);if(n.children.length===1)return n.children=[n.children[0],r],n.last=r.last,h;n.children=[r];let a=t(r.last+1);if(a===void 0||!e.startsWith(i,a))return;let o=t(a+i.length);return o===void 0?void 0:l(o)},a=(n,a)=>{switch(n.kind){case`Set`:return r(n,a,`}`,void 0,`,`);case`Sequence`:{let t=r(n,a,`>`,void 0,`,`);return t===h?n.last+1>=e.length?void 0:(n.last++,h):t}case`Record`:return r(n,a,`]`,`RecordPair`,`,`);case`RecordPair`:return i(n,a,`|->`);case`Function`:return r(n,a,`)`,`FunctionPair`,`@@`);case`Subset`:{if(a)return n.children=[a],n.last=a.last,h;let e=t(n.last);return e===void 0?void 0:l(e)}case`FunctionPair`:return i(n,a,`:>`)}},o=t=>{let r=n.er(e,t,d);if(e.startsWith(`..`,r)&&d(e[r+2]))return{kind:`Constant`,first:t,last:n.er(e,r+2,d)-1,children:[]}},s=t=>{let r=e[t];if(r===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let i=d(r)?o(t):void 0;if(i)return i;if(r===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:n.er(e,t+1,d)-1,children:[]};if(f(r))return{kind:`Constant`,first:t,last:n.er(e,t,f)-1,children:[]}},l=n=>{let r=t(n);if(r!==void 0)switch(e[r]){case`{`:return m(`Set`,r,r+1);case`<`:return m(`Sequence`,r,r+2);case`[`:return m(`Record`,r,r+1);case`(`:return m(`Function`,r,r+1);default:return e.startsWith(`SUBSET`,r)?m(`Subset`,r,r+6):s(r)}},g=(e,t)=>{let n;if(t<c)for(;;){let r=a(e,n);if(r===h)return e;if(r===void 0||(n=p(r)?g(r,t+1):r,n===void 0))return}let r=[e];for(let e=r.at(-1);e!==void 0;e=r.at(-1)){let t=a(e,n);if(t===void 0)return;t===h?(r.pop(),n=e):p(t)?(r.push(t),n=void 0):n=t}return n},_=l(0);return _&&p(_)?g(_,0):_},_=e=>{let t=e.length===0?void 0:g(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=``,a=0,o,s=e=>{o===void 0?i+=e:o.push(e)},u=(e,t,n,r)=>{if(o!==void 0)return o.push({node:e,columnWidth:t,trailerWidth:n,leftPad:r}),!0;if(a<c){a++;let i=d(e,t,n,r);return a--,i}let s=[{node:e,columnWidth:t,trailerWidth:n,leftPad:r}];o=s;for(let e=s.pop();e!==void 0;e=s.pop()){if(typeof e==`string`){i+=e;continue}let t=s.length;if(!d(e.node,e.columnWidth,e.trailerWidth,e.leftPad))return!1;for(let e=t,n=s.length-1;e<n;e++,n--){let t=s[e];s[e]=s[n],s[n]=t}}return o=void 0,!0},d=(e,t,i,a)=>{if(r(e)<=t-i||e.kind===`Constant`)return s(n(e)),!0;if(e.kind===`RecordPair`||e.kind===`FunctionPair`)return!1;let o=l[e.kind],c=t-Math.max(o.open.length,o.pad.length),u=i+o.close.length,d=a+o.pad;s(o.open);let m=e.kind===`Function`||e.kind===`Record`?p(e.children,c,u,d,o):f(e.children,c,u,d,o.separator);return s(o.close),m},f=(e,t,n,r,i)=>{for(let a=0;a<e.length;a++){let o=a===e.length-1;if(!u(e[a],t,o?n:i.length,r))return!1;o||s(`${i}\n${r}`)}return!0},p=(e,t,i,a,o)=>{for(let c=0;c<e.length;c++){let l=c===e.length-1,d=e[c].children[0],f=e[c].children[1],p=l?``:`${o.separator}\n${a}`,m=r(d)+o.divider.length+1+r(f);if(l?m<=t-i:m+o.separator.length<=t)s(`${n(d)}${o.divider} ${n(f)}${p}`);else{if(r(d)+o.divider.length<=t)s(n(d));else if(!u(d,t,i+o.divider.length,a))return!1;if(s(`${o.divider}\n${a}${o.dividerPad}`),!u(f,t-o.dividerPad.length,l?i:o.separator.length,a+o.dividerPad))return!1;s(p)}}return!0};return d(t,80,0,``)?i:e},v=(e,t)=>t?e:_(e),y=e=>e.kind!==`ModelValue`&&e.kind!==`Set`&&e.kind!==`Function`&&e.kind!==`Interval`&&e.kind!==`InfiniteSet`&&e.kind!==`LazyFunction`,b=2147483647,x=e=>(e.flags|=16,e),S=e=>typeof e==`object`&&e.kind===`Function`&&!!(e.flags&16);var C=class{kind=`Function`;domain;hash;fingerprint=0;writtenKeys=void 0;functionClass=`tuple`;flags=80;edges;locations;plans;sources;records;hashes;makeRecord;writtenSlots;made=void 0;constructor(e,t,n,r,i,a,o,s,c){this.domain=gr(i.length),this.hash=o,this.edges=e,this.locations=t,this.plans=n,this.sources=r,this.records=i,this.hashes=a,this.makeRecord=s,this.writtenSlots=c}get range(){if(this.made!==void 0)return this.made;let e=this.records.map((e,t)=>e??this.makeRecord(this,t));return this.records=e,this.made=e,e}};const w=e=>e instanceof C,ee=(e,t)=>e.records[t]??=e.makeRecord(e,t),T=(e,t)=>e.writtenSlots!==void 0&&(e.writtenSlots[t>>5]>>>(t&31)&1)==1,te=(e,t)=>{let n=e.records[t];return n!==void 0&&T(e,t)?ws(n):e.hashes[t]},ne=e=>{let t=js;for(let n=0;n<e.records.length;n++){let r=e.records[n],i=r!==void 0&&T(e,n)?Us(r):e.hashes[n];if(i===Ps)return Ps;t=t+Ns(Hs(n+1),i)|0}return t},E=e=>e.hash!==Cs&&e.hash!==Ps,D=(e,t,n)=>{let r=e.writtenSlots?.slice()??/* @__PURE__ */ new Int32Array(8);r[t>>5]|=1<<(t&31);let i=e.records.slice();i[t]=n;let a=new C(e.edges,e.locations,e.plans,e.sources,i,e.hashes,Cs,e.makeRecord,r);return a.flags=64,a},O=(e,t)=>{let n=e.writtenSlots?.slice(),r=!1;if(n!==void 0){for(let r=t;r<e.records.length;r++)n[r>>5]&=~(1<<(r&31));for(let e=0;e<n.length;e++)r||=n[e]!==0}let i=new C(e.edges,e.locations,e.plans,e.sources,e.records.slice(0,t),e.hashes,Cs,e.makeRecord,r?n:void 0);if(i.flags=64,!E(e))return i;let a=e.hash;for(let n=t;n<e.records.length;n++)a=a-Ns(Hs(n+1),te(e,n))|0;return i.hash=a,i},k=(e,t)=>e.records.length===256?F(e.range.concat([t])):D(e,e.records.length,t),re=e=>e.kind===`MixedSet`?e.enumerated!==void 0:!!(e.flags&1),ie=(e,t)=>{e.flags=t?e.flags|1:e.flags&-2},ae=1e6;let oe=ae;const se=()=>oe,ce=()=>Math.max(oe,10),le=()=>`Attempted to construct a set with too many elements (>${oe}).`,A=(e,n)=>{if(e.length===ce())throw new t.q(le());e.push(n)},ue=e=>typeof e==`object`&&e.kind===`Interval`&&e.high-e.low>=ce(),de=(e,t)=>{if(Array.isArray(e))for(let n=0;n<e.length;n++)t(e[n]);else for(let n=e.low;n<=e.high;n++)t(n)},fe=2**27,j=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`&&e.kind!==`Operator`,pe=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),me=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),M=e=>typeof e==`object`&&e.kind===`ModelValue`,he=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),ge=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:e.kind===`Operator`?`operator`:j(e)?`set`:`function`,_e=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,ve=(e,t)=>(e.writtenKeys=t,e),ye=e=>(e.hash!==0||e.fingerprint!==0?void 0:e.writtenKeys)??e.domain,be=e=>{let t=ye(e),n=e.domain,r=e.range;if(t===n)return n.map((e,t)=>[e,r[t]]);let i=/* @__PURE__ */ new Map;for(let e=0;e<n.length;e++){let t=n[e];i.has(t)||i.set(t,e)}return t.map(e=>[e,r[i.get(e)??-1]])},xe=e=>e.domain.every(e=>typeof e==`number`)?e.domain.map((t,n)=>[t,e.range[n]]):be(e),Se=(e,t,n,r)=>{let i=Array(t.length);for(let e=0;e<t.length;e++)i[e]=n[t[e]];return ve(wr(e,i),r)},Ce=e=>{typeof e==`object`&&e.kind===`Function`&&(e.writtenKeys=void 0)},N=e=>{for(let t=0;t<e.length;t++)if(typeof e[t]!=`string`)return!1;return!0},we=e=>typeof e!=`object`||e.kind===`ModelValue`,Te=e=>{if(e.length===0)return!1;let t=e[e.length-1];return typeof t==`object`&&t.kind!==`ModelValue`},Ee=(e,t)=>e.length>0&&t.length>0&&N(e)!==N(t),De=(e,t)=>{if(e.writtenKeys!==void 0&&(e.writtenKeys=void 0),t.writtenKeys!==void 0&&(t.writtenKeys=void 0),(e.costModel!==void 0||t.costModel!==void 0)&&e.functionClass!==t.functionClass)return bn(e,t);let n=e.domain,r=t.domain;if(n.length!==r.length)return Ee(n,r)?bn(e,t):n.length-r.length;if(n!==r)for(let i=0;i<n.length;i++){let a=n[i],o=r[i],s=ht(a,o);if(s!==0)return M(a)===M(o)?s:bn(e,t)}else if(Te(n))for(let e=0;e<n.length;e++){let t=n[e];typeof t!=`object`||(t.kind===`Function`||t.kind===`Set`)&&t.flags&4||mt(t,!1)}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=i[e],n=a[e],r=typeof t==`number`&&typeof n==`number`?t-n:ht(t,n);if(r!==0)return r}return 0},Oe=(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=ht(n[e],r[e]);if(t!==0)return t}return 0},ke=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return!1;if(n===r)return!0;for(let e=0;e<n.length;e++){let t=n[e],i=r[e];if(!(typeof t==`object`&&t.kind!==`Function`?Bt(t,i):ht(t,i)===0))return!1}return!0},Ae=e=>M(e)?e.type:void 0,je=(e,t,n)=>{let r=sn(n);return M(e)&&M(t)?`Attempted to ${r} the differently-typed model values ${_(U(e))} and ${_(U(t))}`:Ae(e)===void 0?`Attempted to ${r} the typed model value ${_(U(t))} and the non-model value\n${_(U(e))}`:`Attempted to ${r}${n?``:` the`} typed model value ${_(U(e))} and non-model value\n${_(U(t))}`},Me=(e,t,n)=>{let r=Ae(e),i=Ae(t);if((r!==void 0||i!==void 0)&&(!M(e)||!M(t)||r!==void 0&&i!==void 0&&r!==i))throw P(je,e,t,n)},Ne=()=>({ranks:Object.create(null),texts:[],searchRank:void 0,unorderedString:void 0}),Pe=Ne(),Fe=e=>{Object.assign(Pe,Ne()),gt.clear(),_t=!1,Mt=!1;for(let t of e)Xe(t)},Ie=()=>{Pe.searchRank=Pe.texts.length,Pe.unorderedString=void 0},Le=e=>{let t=Pe.texts;for(let n=e;n<t.length;n++)delete Pe.ranks[t[n]];t.length=e},Re=()=>Pe.unorderedString;let ze=!1;const Be={isExpanded:!0,isViewPrinted:!1},Ve=()=>Be.isExpanded,He=e=>{ze=e.version===`1.7.4`,oe=e.maxSetSize??ae,Be.isExpanded=e.isLazyValueExpanded??!0,Be.isViewPrinted=e.isViewPrinted??!1},Ue=/* @__PURE__ */ new WeakMap,We=(e,t)=>(Be.isViewPrinted&&Ue.set(e,t),e),Ge=/* @__PURE__ */ new WeakMap,Ke=/* @__PURE__ */ new WeakMap,qe=(e,t)=>(Ge.set(e,t),e),Je=(e,t)=>(Ke.set(e,t),e),Ye=(e,t)=>Ke.has(e)?t:Ke.get(t)?.()??t,Xe=e=>(Pe.ranks[e]===void 0&&(Pe.ranks[e]=Pe.texts.length,Pe.texts.push(e)),e),Ze=e=>Pe.ranks[Xe(e)],Qe=()=>Pe.texts.length,$e=(e=0)=>Pe.texts.slice(e),et=(e,t)=>{if(e===t)return 0;let n=Pe.ranks,r=n[e],i=n[t],a=Pe.searchRank;return a!==void 0&&(r===void 0||r>=a)&&(i===void 0||i>=a)&&(Pe.unorderedString??=e),r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},tt=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),nt=(e,t)=>(tt(e)||tt(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`);let rt=`none`;const it=()=>{if(rt===`stopping`)throw new t.Z},at=(e,...t)=>rt===`none`?e(...t):()=>e(...t),P=(e,...n)=>new t.D(at(e,...n)),ot=(e,t)=>P(()=>tt(e)?`Attempted to compare overridden value ${_(U(e))} with non-overridden value:\n${_(U(t))}`:`Attempted to compare ${ge(e)} ${U(e)} with ${ge(t)} ${U(t)}`),st=(e,t,n)=>`Attempted to ${e} the set ${_(U(L(t)))} with the value:\n${_(U(n))}`,ct=(e,t)=>`Attempted to compare ${_(U(e))} with the value\n${_(U(t))}`,lt=(e,n,r)=>{if(!tt(e))throw P(st,r,e,n);if(!tt(n))throw ot(e,n);let i=e.kind===`InfiniteSet`?e.name:void 0,a=n.kind===`InfiniteSet`?n.name:void 0;if(i!==void 0&&i===a)return 0;if(i===`Nat`&&a===`Int`||i===`Int`&&a===`Nat`)return i===`Nat`?-1:1;throw new t.H(at(ct,e,n))},ut={kind:`InfiniteSet`,name:`Any`},dt=e=>`Attempted to compare ANY with the value\n${_(U(e))}`,ft=e=>new t.H(at(dt,e)),pt=e=>e.fingerprint!==0||e.hash!==0&&e.hash!==Ps,mt=(e,t)=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:return!0;case`Interval`:return Wa(e.low,e.high),!0;case`SequenceSet`:return mt(e.base,!1);case`InfiniteSet`:if(e===ut)throw ft(e);return!0;case`LazyFunction`:return mt(V(e),t);case`Function`:{if(e.flags&4||pt(e))return!0;e.writtenKeys!==void 0&&(e.writtenKeys=void 0);let n=e.domain,r=e.range,i=!0;for(let e=0;e<n.length;e++)i=mt(n[e],t)&&i;for(let e=0;e<r.length;e++)i=mt(r[e],t)&&i;return i&&(e.flags|=4),i}case`Set`:{if(e.flags&4||pt(e))return!0;e.flags|=1;let n=e.elements,r=!0;for(let e=0;e<n.length;e++)r=mt(n[e],t)&&r;return r&&(e.flags|=4),r}case`Subset`:return mt(e.base,t);case`FunctionSet`:{if(!t)break;let n=e.cost?.charges,r=ta(n,e.domain),i=ta(n,e.domain);if(r||i)return!1;let a=ta(n,e.range),o=ta(n,e.range);return a||o||(mt(e.domain,t),mt(e.range,t)),!1}case`RecordSet`:case`ProductSet`:{if(!t)break;let n=e.cost?.charges,r=ta(n,e),i=ta(n,e);if(r||i)return!1;let a=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<a.length;e++)mt(a[e],t);return!1}}let n=pi(e);return mt(n&&(qn||n.kind===`SetOperation`||n.kind===`Union`)?gi(n,!0,L):L(e),t),zt(e),!1},ht=(e,t)=>{if(e===t)return mt(e,!1),0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return De(e,t);if(n===`Set`&&r===`Set`)return Oe(e,t);if(n===`Interval`&&r===`Interval`){let n=Wa(e.low,e.high),r=Wa(t.low,t.high);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&&Me(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Me(e,t,!1),n===`ModelValue`?-1:1;if(e===ut||t===ut)throw ft(e===ut?t:e);if(n===`SequenceSet`&&r===`SequenceSet`||n===`Subset`&&r===`Subset`)return Un(e.base,t.base);if(j(e)&&j(t)&&nt(e,t))return lt(e,t,`compare`);let i=j(e);if(i!==j(t))throw ot(e,t);if(n===`Interval`&&r===`Set`){let n=R(e)-t.elements.length;if(n!==0)return n}if(n===`Set`&&r===`Interval`){let n=e.elements.length-R(t);if(n!==0)return n}if(i){let i=n===`Set`?void 0:pi(e),a=r===`Set`?void 0:pi(t),o=i?gi(i,!0,L):L(e);return zt(e),Oe(o,a?gi(a,!1,fi):fi(t))}return De(V(e),V(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return et(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Me(e,t,!1),M(e))return-1;if(M(t))return 1;throw ot(e,t)},gt=/* @__PURE__ */ new Map;let _t=!1;const vt=()=>_t,yt=32768,bt=e=>{let n=gt.get(e);if(n)return n;if(gt.size===yt)throw new t.O(`TLC supports at most ${yt} model values, but model value ${e} exceeds this limit.`);let r=e.length>2&&e[1]===`_`?e[0]:void 0;r!==void 0&&(_t=!0);let i={kind:`ModelValue`,name:e,type:r,rank:Ze(e),hash:Ds(Os(ks(e),109)),fingerprint:Ws(Gs(e)^60)};return gt.set(e,i),i},xt=()=>[...gt.values()];var St=class{kind=`Set`;elements;writtenElements=void 0;hash=0;fingerprint=0;flags=0;constructor(e){this.elements=e}};const Ct=e=>new St(e),wt=e=>{let t=Ct(e);return t.flags=1,t};var Tt=class{kind=`Function`;domain;range;hash=0;fingerprint=0;writtenKeys=void 0;functionClass=void 0;flags=0;constructor(e,t){this.domain=e,this.range=t}};const Et=(e,t)=>new Tt(e,t),Dt=(e,t)=>(t!==void 0&&(e.functionClass=t),e),Ot=e=>typeof e==`object`?e.kind===`LazyFunction`?`lambda`:e.kind===`Function`?e.functionClass:void 0:void 0,kt=e=>typeof e==`object`&&e.kind===`LazyFunction`&&e.isApplicationObserved&&e.enumerated===void 0,At=(e,t)=>e.functionClass===`tuple`&&kt(t),jt=e=>y(e)&&e.isCached===!0;let Mt=!1;const Nt=()=>(Mt?2:0)|(_t?4:0),Pt=e=>{Mt||=!!(e&2),_t||=!!(e&4)},Ft=()=>gt.size,It=e=>(Mt=!0,e),Lt=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),Rt=e=>Mt&&typeof e==`object`&&y(e)&&Lt.has(e.kind),zt=e=>{Rt(e)&&(e.isCached=!0)},Bt=(e,t)=>{if(e===t)return mt(e,!0),!0;if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Me(e,t,!0),ht(e,t)===0);if(e.kind===`Function`&&t.kind===`Function`)return De(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return ke(e,t);if(e.kind===`Interval`&&t.kind===`Interval`)return Wa(e.low,e.high)===0?Wa(t.low,t.high)===0:e.low===t.low&&e.high===t.high;if(e.kind===`Interval`&&t.kind===`Set`&&R(e)!==t.elements.length||e.kind===`Set`&&t.kind===`Interval`&&e.elements.length!==R(t))return!1;if(M(e)||M(t))return e.kind===`LazyFunction`&&V(e),Me(e,t,!0),M(e)&&M(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return Hn(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=e.cost?.charges??t.cost?.charges,r=ta(n,e.domain),i=ta(n,t.domain);if(r||i)return r===i;let a=ta(n,e.range),o=ta(n,t.range);return a||o?a===o:Hn(e.domain,t.domain)&&Hn(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){let n=e.cost?.charges??t.cost?.charges;if(ta(n,e))return ta(n,t);if(ta(n,t))return!1;let r=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),i=r(t);return e.names.length===t.names.length&&r(e).every((e,t)=>e[0]===i[t][0]&&Hn(e[1],i[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`){let n=e.cost?.charges??t.cost?.charges;return ta(n,e)?ta(n,t):!ta(n,t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>Hn(e,t.factors[n]))}let n=j(e)&&j(t)&&!(Pr(e)&&Pr(t));if(n&&nt(e,t))return lt(e,t,`check equality of`)===0;if(n){if(!tt(e)){let n=L(e);if(zt(e),!tt(t))return Oe(n,L(t))===0}return ht(e,t)===0}return e.kind===`Function`&&At(e,t)?hn(e,t,!0)===0:ht(e,t)===0},Vt=(e,t,n)=>{let r=e[34+n],i=t[34+n],a=e[34+n+1]-r;if(a!==t[34+n+1]-i)return!1;for(let n=0;n<a;n++)if(e[r+n]!==t[i+n])return!1;return!0},Ht=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},Ut=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},Wt=e=>{let t=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0},n=(e,t)=>{if(e.writtenSlots===void 0&&t.writtenSlots===void 0&&Ht(e.edges,t.edges)&&Ut(e.sources,t.sources))return!0;let n=e.edges[0]===t.edges[0]&&e.edges[1]===t.edges[1];for(let i=0;i<e.domain.length;i++){let a=e.records[i];if(a!==void 0&&a===t.records[i])continue;let o=te(e,i),s=te(t,i);if(o!==Cs&&s!==Cs&&o!==s||(!n||e.sources[i]!==t.sources[i]||T(e,i)||T(t,i)||!Vt(e.edges,t.edges,i))&&!r(ee(e,i),ee(t,i)))return!1}return!0},r=(i,a)=>i===a?!0:typeof i!=`object`||typeof a!=`object`?!1:i.kind===`Set`&&a.kind===`Set`?(i.hash===0||a.hash===0||i.hash===a.hash)&&t(i.elements,a.elements):i.kind===`Function`&&a.kind===`Function`?(!e||i.functionClass===a.functionClass)&&(i.hash===0||a.hash===0||i.hash===a.hash)&&t(i.domain,a.domain)&&(i.flags&a.flags&64&&w(i)&&w(a)?n(i,a):t(i.range,a.range)):i.kind===`Interval`&&a.kind===`Interval`?i.low>i.high?a.low>a.high:i.low===a.low&&i.high===a.high:i.kind===`LazyFunction`&&i.enumerated?r(i.enumerated,a):a.kind===`LazyFunction`&&a.enumerated?r(i,a.enumerated):Qs(i)===Qs(a);return r},Gt=Wt(!1),Kt=Wt(!0),qt=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},Jt=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:if(e.hash!==0)return!1;for(let t=0;t<e.elements.length;t++)if(Jt(e.elements[t]))return!0;return!1;case`Function`:if(e.hash!==0)return!1;for(let t=0;t<e.domain.length;t++)if(Jt(e.domain[t])||Jt(e.range[t]))return!0;return!1;case`ModelValue`:case`Interval`:case`InfiniteSet`:return!1;default:return!0}},Yt=(e=!1,t={count:0})=>{let n=/* @__PURE__ */ new Int32Array(2048),r=[],i=(e,t)=>{let r=n.length-1,i=Math.imul(e,2654435761)>>>0&r&-2;for(;n[i+1]!==0;)i=i+2&r;n[i]=e,n[i+1]=t+1},a=e=>{if(typeof e!=`object`||e.kind!==`Set`&&e.kind!==`Function`)return e;let o=Us(e),s=n.length-1;for(let t=Math.imul(o,2654435761)>>>0&s&-2;n[t+1]!==0;t=t+2&s){if(n[t]!==o)continue;let i=r[n[t+1]-1];if(i===e||Kt(i,e))return i}if(e.kind===`Set`?qt(e.elements,a):(qt(e.domain,a),qt(e.range,a)),r.push(e),t.count+=e.kind===`Set`?e.elements.length:e.domain.length+e.range.length,r.length*4>n.length){n=new Int32Array(n.length*2);for(let e=0;e<r.length;e++){let t=r[e];i(Us(t),e)}}else i(o,r.length-1);return e};return e?e=>{for(let t=0;t<e.length;t++)Jt(e[t])||(e[t]=a(e[t]));return e}:e=>{for(let t=0;t<e.length;t++)e[t]=a(e[t]);return e}},Xt=(e,t)=>t.length===0||Ot(e)===`tuple`?1:gs(t)?.low,Zt=e=>(e.kind===`Function`&&e.costModel!==void 0&&e.functionClass!==void 0&&(it(),e.costModel.secondary[e.costModel.node]+=e.range.length),V(e)),Qt=e=>e.costModel!==void 0&&e.functionClass===void 0&&gs(e.domain)===void 0?e.costModel:void 0,$t=e=>{if(e.kind!==`Function`)return;let t=Qt(e);t!==void 0&&(it(),t.secondary[t.node]+=e.range.length)},en=e=>{if(typeof e==`object`)return e.kind===`LazyFunction`?Vo(e)&&e.costModel.node>=0?e.costModel:void 0:e.kind===`Function`?Qt(e):void 0},tn=e=>{if(!me(e))return;let t=Zt(e);return{domain:t.domain,range:t.range,low:Xt(e,t.domain)}},nn=e=>{if(!me(e))return;Ce(e);let t=V(e);if(N(t.domain))return $t(e),t},rn=(e,t,n)=>(Me(t,e,n),1),an={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`}},on=(e,t,n)=>{let r=an[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${_(U(e))} with ${r.other}:\n${_(U(t))}`},sn=e=>e?`check equality of`:`compare`,cn=(e,t,n)=>`Attempted to ${sn(e)} operator ${_(U(t))} with value:\n${_(U(n))}`,ln=(e,t,n)=>`Attempted to ${sn(e)} the function ${_(U(t))} with the value:\n${_(U(n))}`,un=(e,t,n)=>`Attempted to compare ${e?`an `:``}integer with non-integer${e||t?`:`:``}\n${_(U(n))}.`,dn=(e,t,n)=>`Attempted to ${sn(e)} record:\n${_(U(t))}\nwith non-record\n${_(U(n))}`,fn=(e,t,n)=>`Attempted to ${sn(e)} the set ${_(U(t))} with the value:\n${_(U(n))}`,pn=(e,t,n,r)=>{let i=tn(n);if(!i){if(M(n))return rn(n,t,r);throw P(ln,r,t,n)}if(e.range.length!==i.range.length)return e.range.length-i.range.length;let a=()=>mn(e.range,i.range,r);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&i.low!==void 0)return e.low===i.low?a():e.low-i.low;let o=e.low??i.low;if(o===void 0)return mn(e.domain,i.domain,r)||a();let s=e.low===void 0?e.domain:i.domain;for(let t=0;t<s.length;t++){let n=s[t];if(typeof n!=`number`)throw P(un,r,e.low!==void 0,n);let i=e.low===void 0?n-(o+t):o+t-n;if(i!==0)return i}return a()},mn=(e,t,n)=>{let r=z.sets;for(let i=0;i<e.length;i++){r?.push(e[i]);let a=yn(e[i],t[i],n);if(r?.pop(),a!==0)return a}return 0},hn=(e,t,n)=>{let r=V(e);if(Ot(e)===`tuple`){let i=me(t)?$a(t):void 0;return i?r.range.length-i.length||mn(r.range,i,n):pn({...Zt(e),low:1},e,t,n)}if(Ot(e)===`record`){let i=nn(t);if(!i){if(M(t))return rn(t,e,n);throw P(dn,n,e,t)}return r.domain.length-i.domain.length||mn(r.domain,i.domain,n)||mn(r.range,i.range,n)}return pn({...r,low:Xt(e,r.domain)},e,t,n)},gn=(e,t)=>tt(e)||tt(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),_n=(e,t)=>{let n=pi(t),r=he(t)?t:n?gi(n,!1,n.kind===`Subset`?L:fi):fi(t);return{elements:L(e).elements,otherElements:L(r).elements}},vn=(e,t,n)=>{if(tt(e)&&M(t))return 1;if(!n&&(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)){let n=pi(e);return vn(n?gi(n,!0,hi):hi(e),t,!1)}if(gn(e,t))return n?+!Bt(e,t):ht(e,t);if(!he(e)){let r=pi(e),i=r?gi(r,!0,hi):hi(e);return vn(i,t,n)}if(!j(t)){if(M(t))return rn(t,e,n);throw P(fn,n,e,t)}let r=_n(e,t);return r.elements.length-r.otherElements.length||mn(r.elements,r.otherElements,n)},yn=(e,t,n)=>{if(typeof e!=`object`){if(typeof t==typeof e)return n?e===t?0:1:ht(e,t);if(M(t))return rn(t,e,n);throw P(on,e,t,n)}if(e.kind===`ModelValue`)return e.type!==void 0&&Me(e,t,n),M(t)?n?e.name===t.name?0:1:e.rank-t.rank:-1;if(e.kind===`Operator`)throw P(cn,n,e,t);return me(e)?hn(e,t,n):vn(e,t,n)},bn=(e,t)=>yn(e,t,!1),xn=(e,t)=>yn(e,t,!0)===0,Sn=e=>{let t=[];for(let n of e){let e=An(n,t);e.isFound||t.splice(e.index,0,n)}return t},Cn=(e,t)=>Ct(t?e:Sn(e)),wn=(e,t)=>{let n=z.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},Tn=(e,t)=>{for(let n=1;n<e.length;n++){let r=e[0],i=e[n];if(wn(r,()=>bn(r,i))>0){e[0]=i,e[n]=r;let a=t[0];t[0]=t[n],t[n]=a}}for(let n=2;n<e.length;n++){let r=e[n],i=t[n],a=n;for(;a>0&&wn(r,()=>bn(r,e[a-1]))<0;)e[a]=e[a-1],t[a]=t[a-1],a--;e[a]=r,t[a]=i}},En=(e,t)=>(Tn(e,t),Et(e,t)),Dn=e=>typeof e==`object`&&e.kind===`MixedSet`,On=e=>Dn(e)||typeof e==`object`&&e.kind===`ProductSet`&&e.factors.some(Dn),kn=(e,t,n)=>Dn(e)?En([...t],n):Et(t,n),An=(e,t)=>{let n=0,r=t.length;for(;n<r;){let i=n+(r-n>>1),a=wn(e,()=>bn(e,t[i]));if(a===0)return{index:i,isFound:!0};a<0?r=i:n=i+1}return{index:n,isFound:!1}},jn=(e,t)=>t.some(t=>wn(t,()=>xn(t,e))),Mn=e=>e.kind===`MixedSet`?e.enumerated?.elements??e.elements:re(e)?e.elements:e.writtenElements??e.elements,Nn=1e3,Pn=(e,t,n)=>{if(typeof e!=`object`)return n;if(t===Nn){let t=n??[];return t.push(e),t}let r=n;if(e.kind===`Set`&&!(e.flags&8)){e.flags|=9;for(let n=0;n<e.elements.length;n++)r=Pn(e.elements[n],t+1,r)}if(e.kind===`Function`&&!(e.flags&8)){e.flags|=8,e.writtenKeys=void 0;for(let n=0;n<e.domain.length;n++)r=Pn(e.domain[n],t+1,r),r=Pn(e.range[n],t+1,r)}return r},Fn=e=>{let t=Pn(e,0,void 0);for(let e=t?.pop();e!==void 0;e=t?.pop())Pn(e,0,t)},In=(e,t,n,r)=>{if(typeof e!=`object`)return n;if(t===Nn){let t=n??[];return t.push(e),t}let i=n;switch(e.kind){case`Set`:if(e.flags&128)return i;r.push(e),e.flags|=1;for(let n=0;n<e.elements.length;n++){let a=e.elements[n];we(a)||(i=In(a,t+1,i,r))}return i;case`MixedSet`:for(let n=0;n<e.elements.length;n++){let a=e.elements[n];we(a)||(i=In(a,t+1,i,r))}return L(e),i;case`Function`:if(e.flags&128)return i;r.push(e),e.writtenKeys=void 0;for(let n=0;n<e.domain.length;n++){let a=e.domain[n],o=e.range[n];we(a)||Fn(a),we(o)||(i=In(o,t+1,i,r))}return i;case`LazyFunction`:{if(e.enumerated)return In(e.enumerated,t+1,i,r);let n=Wo(e);for(let e=n.length-1;e>=0;e--){let a=n[e];i=In(a.newValue,t+1,i,r);for(let e=0;e<a.path.length;e++)i=In(a.path[e],t+1,i,r)}return In(e.domain,t+1,i,r)}case`FilteredSet`:case`Subset`:case`Union`:return In(e.base,t+1,i,r);case`SetOperation`:return i=In(e.left,t+1,i,r),In(e.right,t+1,i,r);case`FunctionSet`:return i=In(e.domain,t+1,i,r),In(e.range,t+1,i,r);case`RecordSet`:case`ProductSet`:{let n=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<n.length;e++)i=In(n[e],t+1,i,r);return i}default:return i}},Ln=e=>{let t=[],n=In(e,0,void 0,t);for(let e=n?.pop();e!==void 0;e=n?.pop())In(e,0,n,t);for(let e=0;e<t.length;e++)t[e].flags|=128},Rn=e=>{if(typeof e!=`object`||jt(e))return;if(e.kind===`Set`){e.flags|=1;return}if(e.kind===`MixedSet`){L(e);return}let t=z.sets;switch(t?.push(e),e.kind){case`FilteredSet`:case`Subset`:Rn(e.base);break;case`SetOperation`:e.operator!==`\\cup`&&(Rn(e.left),Rn(e.right));break;case`FunctionSet`:Rn(e.domain),Rn(e.range);break;case`RecordSet`:for(let t of e.sets)Rn(t);break;case`ProductSet`:for(let t of e.factors)Rn(t)}t?.pop()},zn=e=>typeof e==`object`&&y(e)&&e.enumerated===void 0,Bn=(e,t)=>typeof e==`object`&&(e.kind===`Function`&&At(e,t)||j(e)&&!M(t)&&(gn(e,t)||j(t)&&(zn(e)?e.kind!==`MixedSet`:zn(t)))),Vn=(e,t)=>typeof e!=`object`&&typeof e==typeof t?e===t:ao(Bt,xn,e,t,Bn),Hn=(e,t)=>{let n=z.sets;if(n===void 0)return Vn(e,t);n.push(e);let r=Vn(e,t);return n.pop(),r},Un=(e,t)=>{let n=z.sets;if(n===void 0)return bn(e,t);n.push(e);let r=bn(e,t);return n.pop(),r},Wn=e=>{for(let t=1;t<e.length;t++)if(ht(e[t],e[t-1])<=0)return!1;return!0},Gn=e=>{for(let t=0;t<e.length;t++){let n=e[t],r=t>0?e[t-1]:void 0;if(typeof n!=`number`||typeof r==`number`&&r>=n)return!1}return!0},Kn=e=>{if(e.length<2||Wn(e))return Ct(e);let t=[...e].sort(ht);for(let t=1;t<e.length;t++)zt(e[t]);let n=[t[0]];for(let e=1;e<t.length;e++)ht(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ct(n)};let qn=!1;const Jn=e=>{if(Gn(e))return Ct(e);let t=qn;qn=!0;try{let t=ao(Kn,e=>({kind:`MixedSet`,elements:e}),e,void 0);return t.kind===`Set`&&t.elements!==e&&(t.writtenElements=e),t}finally{qn=t}},Yn=Ct([]),Xn=(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&&ht(r[a],t)<0;)a++;a<r.length&&ht(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ct(i)},Zn=(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&&ht(r[a],t)<0;)a++;a<r.length&&ht(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ct(i)},Qn=(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=ht(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=Ct(i);if(e.hash!==0&&e.hash!==Ps){let t=e.hash,n=0;for(;n<a.length;n++){let e=Us(a[n]);if(e===Ps)break;t=t+Ms(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+Ks(a[e])|0;c.fingerprint=t}return c},$n=e=>{let t=e.length<2?e:[...e].sort((e,t)=>ht(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&ht(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Et(n,r)},er=e=>typeof e!=`object`||e.kind===`ModelValue`&&e.type===void 0||e.kind===`Function`&&(!!(e.flags&4)||e.writtenKeys===void 0&&e.domain.every(tr)&&e.range.every(er)),tr=e=>!M(e)&&er(e),nr=e=>e.flags&32?!0:e.domain.every(er)?(e.flags|=32,!0):!1,rr=(e,t,n,r)=>{let i=n.length<=e.length,a=i?e:n,o=i?t:r,s=i?n:e,c=i?r:t,l=[],u=[],d=0,f=e=>{for(;d<e;d++)l.push(a[d]),u.push(o[d])};for(let e=0;e<s.length;e++){let t=s[e],n=d,r=a.length;for(;n<r;){let e=n+r>>1,i=ht(a[e],t);if(i===0)return;i<0?n=e+1:r=e}f(n),l.push(t),u.push(c[e])}return f(a.length),[l,u]},ir=(e,t)=>{if(e.domain.length+t.domain.length>ce()){let n=be(e),r=[];for(let e of n)A(r,e);for(let e of be(t))n.some(t=>Vn(e[0],t[0]))||A(r,e);return pr(r)}let n=ye(e),r=ye(t),i=ar(e,t)??new Set(r.filter(e=>n.some(t=>Vn(e,t)))),a=[...n,...r.filter(e=>!i.has(e))],o=or(e,t,i);if(!o){let n=be(e),r=be(t).filter(e=>!i.has(e[0]));return pr([...n,...r])}let s=Et(o[0],o[1]);return s.flags|=32,a.every((e,t)=>e===s.domain[t])?s:ve(s,a)},ar=(e,n)=>{if(!nr(e)||!nr(n))return;let r=/* @__PURE__ */ new Set;try{for(let t of e.domain){let e=Ja(n.domain,t);e!==-1&&r.add(n.domain[e])}}catch(e){if(e instanceof t.D)return;throw e}return r},or=(e,n,r)=>{let i=r.size===0?n.domain:n.domain.filter(e=>!r.has(e)),a=r.size===0?n.range:n.range.filter((e,t)=>!r.has(n.domain[t]));if(nr(e)&&(r.size===0?nr(n):i.every(er)))try{return rr(e.domain,e.range,i,a)}catch(e){if(e instanceof t.D)return;throw e}},sr=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][0];return t},cr=(e,t)=>{let n=e.domain;if(n.length!==t.length)return e;for(let r=0;r<t.length;r++)if(t[r][0]!==n[r])return ve(e,sr(t));return e},lr=e=>cr($n(e),e),ur=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][1];return t},dr=e=>Et(sr(e),ur(e)),fr=e=>cr(En(sr(e),ur(e)),e),pr=e=>ao(lr,fr,e,void 0);var mr=class extends Array{static get[Symbol.species](){return Array}interval;constructor(e){super(Math.max(e.high-e.low+1,0)),this.interval=e;for(let t=0;t<this.length;t++)this[t]=e.low+t}};const hr=[],gr=e=>{let t=hr[e];if(t)return t;let n=new mr({kind:`Interval`,low:1,high:e});return e<=1024&&(hr[e]=n),n},_r=e=>e.low===1&&e.high>=0?gr(e.high):new mr(e),vr=e=>Reflect.get(e,`kind`)===`IntervalElements`,yr=e=>{let t=/* @__PURE__ */ new Set,n=e=>{if(typeof e!=`object`||!e)return e;if(vr(e))return _r({kind:`Interval`,low:e.low,high:e.high});if(t.has(e))return e;if(t.add(e),Array.isArray(e)){for(let t=0;t<e.length;t++)e[t]=n(e[t]);return e}for(let t of Object.keys(e))Reflect.set(e,t,n(Reflect.get(e,t)));let r=Reflect.get(e,`kind`);return(r===`Union`||r===`SetOperation`)&&(Mt=!0),e};for(let t of e)n(t);return[...e]},br=e=>{if(R(e)>fe)throw new t.U;if(e.low===1&&e.high>=1)return gr(e.high);let n=[];for(let t=e.low;t<=e.high;t++)n.push(t);return n},xr=e=>e instanceof mr,Sr=(e,t=!0)=>{let n=t?L(e).elements:ri(e);return xr(n)&&(typeof e!=`object`||e.kind!==`Interval`)?[...n]:n},F=e=>Dt(Et(gr(e.length),e),`tuple`),Cr=e=>Dt($n(e),`record`),wr=(e,t)=>Dt(Et(e,t),`record`),Tr=(e,t)=>(t!==void 0&&(e.costModel=t),e),Er=e=>e?.node===void 0||e.charges===void 0?void 0:e.charges.costModels[e.node],Dr=(e,t)=>{let n=Er(t);if(n===void 0)return e;for(let t=0;t<e.length;t++)e[t].costModel=n;return e},I=e=>j(e)&&!tt(e),Or=e=>`UNION(${U(e.base)})`,kr=e=>`Attempted to enumerate the nonenumerable set:\n${Or(e)}`,Ar=(e,t=e=>L(e).elements)=>{if(!I(e.base))throw P(kr,e);return t(e.base)},jr=e=>typeof e==`object`&&e.kind===`Set`?e.elements:ka(e),Mr=(e,t,n)=>t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${_(U(e))}\nwhen enumerating:\n${_(Or(n))}`,Nr=(e,t,n)=>{if(I(e))return e;throw P(Mr,e,t,n)},Pr=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 Pr(e.base);case`FunctionSet`:return Pr(e.domain)&&Pr(e.range)||Fr(e.domain)===!0||Fr(e)===!0;case`RecordSet`:return e.sets.every(Pr)||Fr(e)===!0;case`ProductSet`:return e.factors.every(Pr)||Fr(e)===!0;case`Union`:return Pr(e.base)&&(he(e.base)?Mn(e.base):ka(e.base)).every(Pr);case`SetOperation`:return e.operator===`\\cup`?Pr(e.left)&&Pr(e.right):e.operator===`\\cap`?Pr(e.left)||Pr(e.right):Pr(e.left);default:return!1}},Fr=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=Fr(e.domain);return t===void 0?void 0:!t&&Fr(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Fr(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return Pr(e)?L(e).elements.length===0:void 0;default:return}},Ir=(e,n)=>{let r=e.reduce((e,t)=>e*t.length,1);if(n&&r>ce())throw z.sets?.pop(),new t.q(le());if(r>fe)throw new t.U;let i=[],a=e.map(()=>0);for(let t=0;t<r;t++){i.push(e.map((e,t)=>e[a[t]]));for(let t=e.length-1;t>=0&&(a[t]++,!(a[t]<e[t].length));t--)a[t]=0}return i},Lr=(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},Rr=e=>{if(typeof e!=`object`||e.kind!==`Subset`||tt(e.base))return;let t=z.sets;t?.push(e);let n=L(e.base).elements;if(t?.pop(),n.length<=20)return;let r=e.cost?.node,i=-1,a=[0],o=e=>{for(e<=i&&(i=-1);i<e;)i===-1?a=[]:Lr(a,n.length)||(a=Array.from({length:a.length+1},(e,t)=>t)),i++;let t=Ct(a.map(e=>n[e]));return r===void 0?t:{...t,costNode:r}},s=2**n.length,c=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<s;return new Proxy([],{get:(e,t,n)=>t===`length`?s:c(t)?o(Number(t)):Reflect.get(e,t,n),has:(e,t)=>c(t)||Reflect.has(e,t)})},zr=(e,t,n)=>{for(let r=0;r<=e.length;r++){let i=Array.from({length:r},(e,t)=>t);do{let a=Array(r);for(let t=0;t<r;t++)a[t]=e[i[t]];let o=Ct(a);if(t(n===void 0?o:{...o,costNode:n}))return!0}while(Lr(i,e.length))}return!1},Br=(e,t)=>{let n=[];return zr(e,e=>(n.push(e),!1),t),n},Vr=e=>`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${_(U(e.base))}`,Hr=e=>{if(R(e.base)===0)return[];if(!j(e.base))throw P(Vr,e);return L(e.base).elements},Ur=(e,t)=>`Attempted to enumerate a set of the form [D -> R],but the ${e}:\n${_(U(t))}\ncannot be enumerated.`,Wr=(e,t)=>e.kind===`RecordSet`?`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[t]}' field:\n${_(U(e.sets[t]))}`:`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${_(U(e.factors[t]))}`,Gr=(e,t)=>{let n=e.kind===`RecordSet`?e.sets:e.factors,r=[];for(let i=0;i<n.length;i++){let a=n[i];if(tt(a))throw P(Wr,e,i);let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},Kr=e=>`Attempted to enumerate S \\cap T when neither S:\n${_(U(e.left))}\nnor T:\n${_(U(e.right))}\nis enumerable`,qr=e=>`Attempted to enumerate S \\ T when S:\n${_(U(e.left))}\nis not enumerable.`,Jr=(e,t)=>{if(e.operator===`\\cap`&&!I(e.left)&&!I(e.right))throw P(Kr,e);if(e.operator===`\\`&&!I(e.left))throw P(qr,e);if(e.operator===`\\cup`)return L(Jn(Ca(e,t))).elements;let n=e.operator===`\\`||I(e.left),r=n?e.left:e.right,i=n?e.right:e.left,a=[],o=t=>(B(t,i)===(e.operator===`\\cap`)&&A(a,t),!1);return typeof r==`object`&&r.kind===`Interval`?de(r,o):Ea(r,t??xa(r),o),L(Jn(a)).elements},Yr=e=>{if(typeof e!=`object`||jt(e))return!0;switch(e.kind){case`Set`:case`MixedSet`:return re(e);case`Interval`:return!0;case`FilteredSet`:return Yr(e.base);case`FunctionSet`:return Yr(e.domain)&&Yr(e.range);case`RecordSet`:return e.sets.every(Yr);case`ProductSet`:return e.factors.every(Yr);case`Operator`:throw new t.D(e.javaClass===`MethodValue`?`It is a TLC bug: Attempted to normalize an operator.`:`Should not normalize an operator.`);default:return!1}},Xr=(e,t)=>{if(typeof e!=`object`||e.kind===`ModelValue`)return!1;let n=[e];for(let e=n.pop();e!==void 0;e=n.pop())if(typeof e==`object`)switch(e.kind){case`Set`:for(let t=0;t<e.elements.length;t++)n.push(e.elements[t]);break;case`Function`:for(let t=0;t<e.domain.length;t++)n.push(e.domain[t],e.range[t]);break;case`InfiniteSet`:if(t&&e===ut)return!0;break;case`ModelValue`:case`Interval`:break;default:return!0}return!1},Zr=e=>Xr(e,!1),Qr=e=>{for(let t=0;t<e.length;t++)if(Xr(e[t],!0))return!0;return!1},$r=(e,t)=>{for(let n=0;n<e.length;n++)if(ei(e[n],t))return!0;return!1},ei=(e,t)=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:return Qr(e.elements);case`MixedSet`:return!0;case`FilteredSet`:case`Subset`:case`Union`:return ei(e.base,t);case`SetOperation`:return ei(e.left,t)||ei(e.right,t);case`FunctionSet`:return ei(e.domain,t)||ei(e.range,t);case`RecordSet`:return $r(e.sets,t);case`ProductSet`:return $r(e.factors,t);case`Operator`:return t;default:return!1}},ti=(e,t)=>!ei(e,t)||Yr(e),ni=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`ProductSet`:case`FunctionSet`:case`RecordSet`:return ti(e,!0);case`FilteredSet`:return Yr(e),!0;case`SetOperation`:return e.operator!==`\\cup`&&Yr(e.left)&&e.operator===`\\cap`&&Yr(e.right),!0;case`MixedSet`:case`Union`:case`Subset`:return!0;default:return!1}},ri=e=>{if(typeof e!=`object`||e.kind!==`FunctionSet`&&e.kind!==`RecordSet`&&e.kind!==`ProductSet`&&e.kind!==`FilteredSet`||e.enumerated)return L(e).elements;let t=ni(e),n=z.sets?ba(e,!1):void 0;return ii(e,n,t)},ii=(e,t,n)=>{let r=qn;qn=!1;let i;try{i=li(e,!1,void 0,t)}finally{qn=r}let a=Cn(i,n);return i.length<=ce()&&(e.enumerated=a),a.elements},ai=e=>{let t=Rr(e);return t!==void 0&&t.length>ce()?t:ri(e)},oi=e=>`Expected a set but found ${U(e)}`,si=e=>`Attempted to enumerate { x \\in S : p(x) } when S:\n${_(U(e.base))}\nis not enumerable`,ci=e=>`Attempted to enumerate the non-enumerable set ${U(e)}`,li=(e,n=!0,r=n?ai:ri,i)=>{if(typeof e!=`object`)throw P(oi,e);let a=Oi(e);if(a){let e=ga(ha(a,i),n);return Ma(a)?Sn(e):e}switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return Sn(e.elements);case`Interval`:if(R(e)>fe)throw new t.U;return _r(e);case`Subset`:{let n=Hr(e);if(n.length>30)throw P(Ba,e);if(2**n.length>fe)throw new t.U;return Br(n,e.cost?.node)}case`FunctionSet`:{if(!ze&&La(e))return[];if(tt(e.domain))throw P(Ur,`domain D`,e.domain);let t=Sr(e.domain);if((t.length>0||ze)&&tt(e.range))throw P(Ur,`range R`,e.range);let i=t.length===0?[]:r(e.range);return Dr(Ir(t.map(()=>i),n).map(e=>Et(t,e)),e.cost)}case`RecordSet`:{if(!ze&&La(e))return[];let t=Gr(e,r);return Dr(Ir(t,n).map(t=>wr(e.names,t)),e.cost)}case`ProductSet`:{if(!ze&&La(e))return[];let t=Gr(e,r);return Dr(Ir(t,n).map(F),e.cost)}case`FilteredSet`:{if(!j(e.base)||tt(e.base))throw P(si,e);let t=e.startPass?.(!0).test??Ai(e),r=[];return Ea(e.base,i??xa(e.base),e=>(t(e)&&(n?A(r,e):r.push(e)),!1)),L(Jn(r)).elements}case`Union`:{let n=[];for(let[r,a]of(i?Na(e,i):Ar(e,jr)).entries()){let o=Nr(a,r,e);if(ue(o))throw new t.q(le());for(let t of i&&r===0&&he(e.base)?Oa(o,i):ka(o))A(n,t)}return L(Jn(n)).elements}case`SetOperation`:return Jr(e,i);case`InfiniteSet`:case`SequenceSet`:throw P(ci,e);default:throw P(oi,e)}},L=(e,t)=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ct(li(e));let n=typeof e==`object`&&y(e)?e:void 0;return n?.enumerated?n.enumerated:ui(e,n,!1,t)},ui=(e,n,r,i)=>{if(qn&&n!==void 0&&Si(n))throw new t.D(`The set literal holds a filter`);let a=z.sets;r||a?.push(e);let o=i??ni(e),s=qn;qn=s&&n?.kind===`MixedSet`;let c;try{c=r?li(e,!0,void 0,ba(e,!1)):li(e)}finally{qn=s}r||a?.pop();let l=Cn(c,o);return n&&(n.enumerated=l),l},di=e=>z.sets!==void 0&&!e.enumerated?ui(e,e,!0):L(e),fi=(e,t)=>{let n=typeof e==`object`&&y(e)?e:void 0;if(n===void 0||n.enumerated)return L(e);let r=Si(n),i=n.kind===`SetOperation`||n.kind===`Union`?di(n):L(n,t);return r&&(n.enumerated=void 0),i},pi=e=>{if(typeof e==`object`)switch(e.kind){case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`Union`:return e.cost?.charges===void 0?void 0:e;default:return}},mi=(e,t)=>{if(typeof t!=`object`)return!1;switch(t.kind){case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`Union`:return t.cost!==void 0&&(t.cost.node!==void 0||t.cost.charges!==void 0);case`FilteredSet`:return t.isCached===!0&&Ui(e,t)!==void 0;default:return!1}},hi=(e,t)=>{if(typeof e==`object`&&e.kind===`FilteredSet`){let t=L(e);return e.isCached=!0,t}let n=L(e,t);return zt(e),n},gi=(e,n,r)=>{if(qn)throw new t.D(`The set literal holds a charged set`);let i=e.cost;if(i?.charges===void 0)return r(e);let a=ni(e);a||it();let o=i.charges.convertCharged(e,r,a);return n&&(i.charges=void 0),o},_i=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isCached!==!0;case`SetOperation`:return e.hasFilter&&e.isCached!==!0&&(_i(e.left)||_i(e.right));case`Union`:return e.isCached!==!0&&typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&yi(e.base.elements);case`FunctionSet`:case`RecordSet`:case`ProductSet`:return vi(e);default:return!1}},vi=e=>e.hasFilter&&e.isCached!==!0&&!e.enumerated&&(e.kind===`FunctionSet`?_i(e.domain)||_i(e.range):yi(e.kind===`RecordSet`?e.sets:e.factors)),yi=e=>{for(let t=0;t<e.length;t++)if(_i(e[t]))return!0;return!1},bi=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isPassObserved===!0||bi(e.base);case`SetOperation`:return bi(e.left)||bi(e.right);case`Union`:return typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&xi(e.base.elements);case`FunctionSet`:return bi(e.domain)||bi(e.range);case`RecordSet`:return xi(e.sets);case`ProductSet`:return xi(e.factors);default:return!1}},xi=e=>{for(let t=0;t<e.length;t++)if(bi(e[t]))return!0;return!1},Si=e=>_i(e)&&bi(e),Ci=(e,t,n)=>({kind:`FunctionSet`,domain:e,range:t,hasFilter:_i(e)||_i(t),cost:n}),wi=(e,t,n)=>({kind:`RecordSet`,names:e,sets:t,hasFilter:yi(t),cost:n}),Ti=(e,t)=>({kind:`ProductSet`,factors:e,hasFilter:yi(e),cost:t}),Ei=(e,t,n,r)=>({kind:`SetOperation`,operator:e,left:t,right:n,hasFilter:_i(t)||_i(n),cost:r}),Di=(e,t)=>({kind:`Union`,base:e,cost:t}),Oi=e=>(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&vi(e)?e:void 0,ki={kind:`List`,elements:[],position:0},Ai=e=>t=>e.test(t,!1),ji=e=>{let t=typeof e==`object`&&y(e)&&!e.enumerated&&Si(e)?e:void 0,n=Sr(e);return t&&(t.enumerated=void 0),n},Mi=e=>{if(!ze&&La(e))return ki;let t={kind:`Product`,set:e,costModel:Er(e.cost),domain:[],parts:[],current:[],isDone:!1};if(e.kind===`FunctionSet`){if(ba(e.domain,!0),tt(e.domain))throw P(Ur,`domain D`,e.domain);if(t.domain=ji(e.domain),(t.domain.length>0||ze)&&tt(e.range))throw P(Ur,`range R`,e.range)}let n=e.kind===`FunctionSet`?t.domain.map(()=>e.range):e.kind===`RecordSet`?e.sets:e.factors;for(let r=0;r<n.length;r++){if(e.kind!==`FunctionSet`&&tt(n[r]))throw P(Wr,e,r);let i=Ni(n[r]),a=Bi(i);if(a===void 0)return ki;t.parts.push(i),t.current.push(a)}return t},Ni=e=>{let t=z.sets;if(typeof e==`object`&&e.kind===`FilteredSet`&&!jt(e)){t?.push(e),I(e.base)||L(e);let n=Ni(e.base),r=e.startPass?.(!1),i={kind:`Filter`,set:e,base:n,test:r?.test??Ai(e),end:r?.end};return t?.pop(),i}if(typeof e==`object`&&(e.kind===`SetOperation`||e.kind===`Union`)&&_i(e))return bi(e)||z.sets!==void 0?Fi(e):ao(Pi,Fi,e,void 0);let n=typeof e==`object`?Oi(e):void 0;if(n===void 0)return Pi(e);t?.push(n);let r=Mi(n);return t?.pop(),r},Pi=e=>({kind:`List`,elements:ka(e),position:0}),Fi=e=>{let t=z.sets;t?.push(e);let n=e.kind===`Union`?Li(e):Ii(e);return t?.pop(),n},Ii=e=>{if(e.operator===`\\cup`)return I(e.left)&&I(e.right)||L(e),{kind:`Concatenated`,left:Ni(e.left),right:Ni(e.right)};let t=e.operator===`\\`||I(e.left),n=t?e.left:e.right;return I(n)||L(e),{kind:`Selected`,base:Ni(n),other:t?e.right:e.left,isIntersection:e.operator===`\\cap`}},Li=e=>{let t=Ar(e);return{kind:`Unioned`,union:e,sets:t,index:0,part:t.length>0?Ni(Nr(t[0],0,e)):void 0}},Ri=(e,t)=>{zi(e.parts[t]);let n=Bi(e.parts[t]);n===void 0?e.isDone=!0:e.current[t]=n},zi=e=>{switch(e.kind){case`List`:e.position=0;return;case`Filter`:{zi(e.base);let t=e.set.startPass?.(!1);e.test=t?.test??Ai(e.set),e.end=t?.end;return}case`Product`:e.isDone=!1;for(let t=0;t<e.parts.length;t++)Ri(e,t);return;case`Concatenated`:zi(e.left),zi(e.right);return;case`Selected`:zi(e.base);return;case`Unioned`:e.index=0,e.part=e.sets.length>0?Ni(Nr(e.sets[0],0,e.union)):void 0}},Bi=e=>{switch(e.kind){case`List`:return e.position<e.elements.length?e.elements[e.position++]:void 0;case`Filter`:for(let t=Bi(e.base);t!==void 0;t=Bi(e.base))if(e.test(t))return t;e.end?.();return;case`Product`:{if(e.isDone)return;let t=[...e.current];e.isDone=e.parts.length===0;for(let t=e.parts.length-1;t>=0&&!e.isDone;t--){let n=Bi(e.parts[t]);if(n!==void 0){e.current[t]=n;break}t===0?e.isDone=!0:Ri(e,t)}let n=e.set;return Tr(n.kind===`FunctionSet`?Et(e.domain,t):n.kind===`RecordSet`?wr(n.names,t):F(t),e.costModel)}case`Concatenated`:return Bi(e.left)??Bi(e.right);case`Selected`:for(let t=Bi(e.base);t!==void 0;t=Bi(e.base))if(B(t,e.other)===e.isIntersection)return t;return;case`Unioned`:for(;e.part!==void 0;){let t=Bi(e.part);if(t!==void 0)return t;e.index++,e.part=e.index<e.sets.length?Ni(Nr(e.sets[e.index],e.index,e.union)):void 0}return}},Vi=(e,t)=>{for(let n=Bi(e);n!==void 0;n=Bi(e))if(t(n))return!0;return!1},Hi={kind:`Plain`,part:ki},Ui=(e,t)=>{if(typeof t==`object`)switch(t.kind){case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`Union`:return t.cost?.node;case`Set`:return e.values.get(t)??t.costNode;default:return e.values.get(t)}},Wi=(e,t)=>{if(typeof t!=`object`)return;let n=Oi(t);if(n===void 0)return;if(n.kind===`FunctionSet`)return Xi(e,n.range)?n:void 0;let r=n.kind===`RecordSet`?n.sets:n.factors;for(let t=0;t<r.length;t++)if(!Xi(e,r[t]))return;return n},Gi=e=>typeof e==`object`&&e.kind===`FilteredSet`&&e.isCached===!0,Ki=(e,t)=>t.operator===`\\cup`&&t.enumerated===void 0&&(_i(t)||Gi(t.left)||Gi(t.right))&&Ui(e,t)!==void 0&&I(t.left)&&I(t.right)&&!ue(t.left)&&!ue(t.right)&&Xi(e,t.left)&&Xi(e,t.right),qi=e=>e.operator===`\\`||I(e.left)?e.left:e.right,Ji=(e,t)=>t.enumerated===void 0&&_i(t)&&I(qi(t))&&Xi(e,qi(t)),Yi=(e,t)=>t.operator===`\\cup`?Ki(e,t):Ji(e,t),Xi=(e,t)=>typeof t==`object`?t.kind===`SetOperation`?Yi(e,t):t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||Ui(e,t)===void 0||Wi(e,t)!==void 0:!0,Zi=(e,t)=>typeof t==`object`&&(t.kind===`FilteredSet`||t.kind===`Subset`||(t.kind===`SetOperation`?Yi(e,t):Wi(e,t)!==void 0)),Qi=(e,t)=>jt(t)||!Zi(e,t.base)?void 0:Ui(e,t),$i=(e,t)=>{let n=typeof t!=`object`||t.kind===`FilteredSet`||t.kind===`Subset`?void 0:Ui(e,t),r=z.sets;if(typeof t==`object`&&t.kind===`FilteredSet`){let n=Qi(e,t);if(n===void 0){let n=t.isCached?Ui(e,t):void 0;return n===void 0?{kind:`Plain`,part:Ni(t)}:{kind:`ChargedLeaf`,node:n,part:Ni(t)}}r?.push(t),I(t.base)||L(t);let i={kind:`ChargedFilter`,node:n,set:t,base:$i(e,t.base)};return r?.pop(),i}if(typeof t==`object`&&t.kind===`SetOperation`&&t.operator!==`\\cup`){r?.push(t);let n=qi(t),i={kind:`ChargedSelected`,base:$i(e,n),other:n===t.left?t.right:t.left,isIntersection:t.operator===`\\cap`};return r?.pop(),i}if(n!==void 0&&typeof t==`object`&&t.kind===`SetOperation`){r?.push(t);let i={kind:`ChargedUnion`,node:n,left:$i(e,t.left),right:$i(e,t.right)};return r?.pop(),i}let i=n===void 0||typeof t!=`object`?void 0:Oi(t);if(n!==void 0&&i!==void 0){r?.push(i);let t=ra(e,i,n);return r?.pop(),t}if(typeof t==`object`&&t.kind===`Subset`&&t.cost?.node!==void 0){if(t.cost.charges===void 0)return{kind:`ChargedLeaf`,node:t.cost.node,part:Ni(t)};e.chargeSubsetElements(t)}let a=Ni(t);return n===void 0?{kind:`Plain`,part:a}:{kind:`ChargedLeaf`,node:n,part:a}},ea=(e,t)=>{if(typeof t!=`object`||t.kind!==`SetOperation`&&t.kind!==`FilteredSet`&&t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||(t.kind===`FilteredSet`?Qi(e,t)===void 0:(t.kind!==`SetOperation`||t.operator===`\\cup`)&&Ui(e,t)===void 0))return La(t);let n=z.sets;n?.push(t);let r=t.kind===`SetOperation`||t.kind===`FilteredSet`?oa(e,$i(e,t))===void 0:t.kind===`FunctionSet`?!La(t.domain)&&ea(e,t.range):na(e,t.kind===`RecordSet`?t.sets:t.factors);return n?.pop(),r},ta=(e,t)=>(e?.chargeIsEmpty(t),La(t)),na=(e,t)=>{for(let n=0;n<t.length;n++)if(ea(e,t[n]))return!0;return!1},ra=(e,t,n)=>{if(!ze&&ea(e,t))return Hi;let r={kind:`ChargedProduct`,node:n,costModel:e.costModels[n],set:t,domain:[],parts:[],current:[],isDone:!1};if(t.kind===`FunctionSet`){if(ba(t.domain,!0),tt(t.domain))throw P(Ur,`domain D`,t.domain);if(r.domain=ji(t.domain),(r.domain.length>0||ze)&&tt(t.range))throw P(Ur,`range R`,t.range)}let i=t.kind===`FunctionSet`?r.domain.map(()=>t.range):t.kind===`RecordSet`?t.sets:t.factors;for(let n=0;n<i.length;n++){if(t.kind!==`FunctionSet`&&tt(i[n]))throw P(Wr,t,n);let a=$i(e,i[n]),o=oa(e,a);if(o===void 0)return Hi;r.parts.push(a),r.current.push(o)}return r},ia=(e,t,n)=>{aa(e,t.parts[n]);let r=oa(e,t.parts[n]);r===void 0?t.isDone=!0:t.current[n]=r},aa=(e,t)=>{switch(t.kind){case`Plain`:case`ChargedLeaf`:zi(t.part);return;case`ChargedProduct`:t.isDone=!1;for(let n=0;n<t.parts.length;n++)ia(e,t,n);return;case`ChargedUnion`:aa(e,t.left),aa(e,t.right);return;case`ChargedSelected`:case`ChargedFilter`:aa(e,t.base)}},oa=(e,t)=>{switch(t.kind){case`Plain`:return Bi(t.part);case`ChargedLeaf`:return e.secondary[t.node]++,Bi(t.part);case`ChargedProduct`:{if(t.isDone)return;let n=[...t.current];e.secondary[t.node]+=Math.max(t.parts.length,1),t.isDone=t.parts.length===0;for(let n=t.parts.length-1;n>=0&&!t.isDone;n--){let r=oa(e,t.parts[n]);if(r!==void 0){t.current[n]=r;break}n===0?t.isDone=!0:ia(e,t,n)}let r=t.set;return Tr(r.kind===`FunctionSet`?Et(t.domain,n):r.kind===`RecordSet`?wr(r.names,n):F(n),t.costModel)}case`ChargedUnion`:return e.secondary[t.node]++,oa(e,t.left)??oa(e,t.right);case`ChargedSelected`:return sa(e,t);case`ChargedFilter`:return ca(e,t)}},sa=(e,t)=>{for(let n=oa(e,t.base);n!==void 0;n=oa(e,t.base))if(e.isMember(n,t.other)===t.isIntersection)return n},ca=(e,t)=>{for(let n=oa(e,t.base);n!==void 0;n=oa(e,t.base))if(e.secondary[t.node]++,t.set.test(n,!1))return n},la=(e,t)=>{let n=[];for(let r=oa(e,t);r!==void 0;r=oa(e,t))A(n,r);return n},ua=(e,t,n)=>{let r=Qi(e,t);if(r===void 0||t.enumerated||!I(t.base)||qn)return;let i=z.sets;i?.push(t);let a=la(e,{kind:`ChargedFilter`,node:r,set:t,base:$i(e,t.base)});i?.pop(),e.secondary[r]+=a.length;let o=Ct(L(Jn(a)).elements);return n&&(t.enumerated=o),o.elements},da=(e,t)=>t.kind===`FilteredSet`?!t.enumerated&&I(t.base)&&Qi(e,t)!==void 0:t.kind===`SetOperation`?Yi(e,t):Wi(e,t)!==void 0&&Ui(e,t)!==void 0,fa=(e,t,n)=>{if(typeof t!=`object`||!da(e,t))return!1;let r=$i(e,t);for(let t=oa(e,r);t!==void 0;t=oa(e,r))n(t);return!0},pa=(e,t,n)=>{let r=n.kind===`Subset`,i=r?t:n.base;if(typeof i!=`object`||!da(e,i))return;let a=z.sets;a?.push(n);let o=$i(e,i),s=!1;for(let i=oa(e,o);i!==void 0;i=oa(e,o))if(r?!e.isMember(i,n.base):e.isMember(t,i)){s=!0;break}return a?.pop(),r!==s},ma=(e,t,n)=>{if(typeof t!=`object`)return;if(t.kind===`FilteredSet`)return ua(e,t,n);let r=Ui(e,t),i=t.kind===`SetOperation`?Yi(e,t)?t:void 0:r===void 0?void 0:Wi(e,t);if(i===void 0)return;let a=la(e,$i(e,i));r!==void 0&&(e.secondary[r]+=a.length);let o=i.kind!==`SetOperation`&&Ma(i)?Sn(a):a,s=i.kind===`SetOperation`?Ct(L(Jn(a)).elements):i.kind===`RecordSet`?Kn(o):Ct(o);return n&&(i.enumerated=s),s.elements},ha=(e,t)=>t===void 0||t.kind===`Cup`?Mi(e):t,ga=(e,t)=>{let n=[];return Vi(e,e=>(t?A(n,e):n.push(e),!1)),n},_a=(e,t)=>{if(!(typeof e!=`object`||jt(e)))switch(e.kind){case`MixedSet`:L(e);return;case`FilteredSet`:return I(e.base)||L(e),ba(e.base,t);case`Union`:{if(!he(e.base)&&I(e.base))return ba(e.base,t);let n=Ar(e);return n.length>0?ba(Nr(n[0],0,e),t):void 0}case`SetOperation`:if(e.operator===`\\`&&!I(e.left)&&L(e),e.operator===`\\cap`&&!I(e.left)&&!I(e.right)&&L(e),e.operator===`\\cup`){I(e.left)&&I(e.right)||L(e);let t=ba(e.left,!0),n=ba(e.right,!0);return t||n?{kind:`Cup`,left:t,right:n}:void 0}return ba(e.operator===`\\cap`&&!I(e.left)?e.right:e.left,t);case`FunctionSet`:case`RecordSet`:case`ProductSet`:if(vi(e))return Mi(e);t&&va(e);return;case`Subset`:t&&va(e);return;default:return}},va=e=>{switch(e.kind){case`Subset`:{let t=e.base;if(e.enumerated||typeof t==`object`&&t.kind===`Set`)return;if(typeof t==`object`&&t.kind===`Interval`){R(t);return}Hr(e);return}case`FunctionSet`:{if(e.enumerated||La(e))return;let t=e.domain;if(ba(t,!0),tt(t))throw P(Ur,`domain D`,t);if(typeof t==`object`&&y(t)&&L(t),La(t))return;if(tt(e.range))throw P(Ur,`range R`,e.range);typeof t==`object`&&t.kind===`Interval`&&ya(e),ba(e.range,!0);return}case`RecordSet`:case`ProductSet`:{if(e.enumerated||La(e))return;let t=e.kind===`RecordSet`?e.sets:e.factors;for(let n=0;n<t.length;n++){if(tt(t[n]))throw P(Wr,e,n);ba(t[n],!0)}}}},ya=e=>{let n=R(e.domain);if(n>fe)throw z.sets?.push(e),new t.U;return n},ba=(e,t)=>{let n=z.sets;n?.push(e);let r=_a(e,t||n!==void 0);return n?.pop(),r},xa=e=>typeof e!=`object`||jt(e)?void 0:ba(e,!1),Sa=e=>`Attempted to enumerate S \\cup T when S:\n${_(U(e.left))}\nand T:\n${_(U(e.right))}\nare not both enumerable`,Ca=(e,n)=>{if(!I(e.left)||!I(e.right))throw P(Sa,e);let r=n?.kind===`Cup`?n:void 0,i=r?r.left:ba(e.left,!0),a=r?r.right:ba(e.right,!0);if(ue(e.left))throw new t.q(le());let o=[],s=e=>(A(o,e),!1);if(Ea(e.left,i,s),ue(e.right))throw new t.q(le());return Ea(e.right,a,s),o},wa=e=>{if(typeof e!=`object`||e.kind!==`FilteredSet`||e.isPassObserved!==!0||e.isCached===!0||e.enumerated)return L(e);let t=L(e);return e.enumerated=void 0,t},Ta=(e,t)=>{if(typeof e!=`object`||e.kind!==`SetOperation`&&e.kind!==`Union`&&(!t||e.kind!==`FunctionSet`&&e.kind!==`RecordSet`&&e.kind!==`ProductSet`)||e.enumerated)return t?wa(e).elements:ri(e);let n=(e.kind===`Union`||e.hasFilter)&&Si(e),r=ni(e),i=li(e,!0,void 0,z.sets?ba(e,!1):void 0),a=Cn(i,r);return n||(e.enumerated=a),a.elements},Ea=(e,t,n)=>typeof e!=`object`||jt(e)?L(e).elements.some(n):Pa(e,n,t),Da=(e,t)=>Ea(e,xa(e),t),Oa=(e,t)=>{let n=[];return Ea(e,t,e=>(n.push(e),!1)),n},ka=e=>Oa(e,xa(e)),Aa=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,ja=e=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:case`Interval`:return!0;case`Set`:return e.elements.every(ja);case`Function`:return e.writtenKeys===void 0&&e.domain.every(ja)&&e.range.every(ja);case`SetOperation`:return e.operator!==`\\cup`&&ja(e.left)&&ja(e.right);case`FilteredSet`:return ja(e.base);case`ProductSet`:return e.factors.every(ja);default:return!1}},Ma=e=>typeof e!=`object`||jt(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?Ma(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||Ma(e.left)||Ma(e.right):Aa(e)?.some(Ma)??!1,Na=(e,t)=>Ar(e,e=>he(e)?jr(e):Oa(e,t)),Pa=(e,t,n)=>{if(e.kind===`Union`)return Na(e,n).some((r,i)=>{let a=Nr(r,i,e);return i===0&&he(e.base)?Ea(a,n,t):Da(a,t)});if(e.kind===`FilteredSet`&&I(e.base)){let r=e.startPass?.(!1);return r?Ea(e.base,n,e=>r.test(e)&&t(e))?!0:(r.end(),!1):Ea(e.base,n,n=>e.test(n,!1)&&t(n))}if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&n!==void 0)return Vi(ha(e,n),t);if(Aa(e)?.some(Ma))return li(e,!1,ka).some(t);if(e.kind===`Subset`&&e.enumerated===void 0&&R(e.base)>20)return zr(Hr(e),t,e.cost?.node);if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&!e.enumerated)return ti(e,!1)?ii(e,z.sets?ba(e,!1):void 0,!0).some(t):Vi(Mi(e),t);if(e.kind!==`SetOperation`)return ri(e).some(t);if(e.operator===`\\cup`){if(!I(e.left)||!I(e.right))return L(e).elements.some(t);let r=n?.kind===`Cup`?n:void 0;return Ea(e.left,r?.left,t)||Ea(e.right,r?.right,t)}let r=e.operator===`\\`||I(e.left),i=r?e.left:e.right,a=r?e.right:e.left;return I(i)?Ea(i,n,n=>B(n,a)===(e.operator===`\\cap`)&&t(n)):L(e).elements.some(t)},Fa=()=>!0,Ia=e=>`Shouldn't call isEmpty() on value ${U(e)}`,La=e=>{if(typeof e!=`object`||!j(e))throw z.sets?.push(e),P(Ia,e);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return Wa(e.low,e.high)===0;case`InfiniteSet`:if(e.name===`Any`)throw new t.D(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1}let n=z.sets;if(n===void 0)return Ra(e);n.push(e);let r=Ra(e);return n.pop(),r},Ra=e=>{switch(e.kind){case`ProductSet`:return e.factors.some(La);case`RecordSet`:return e.sets.some(La);case`FunctionSet`:return!La(e.domain)&&La(e.range);case`Union`:return Ar(e).every((t,n)=>La(Nr(t,n,e)));default:return!Da(e,Fa)}},za=(e,t,n)=>e.reduce((e,r)=>{let i=e*R(r,t);if(i>2147483647)throw P(n);return i},1),Ba=e=>`Overflow when computing the number of elements in:\n${_(U(e))}`,Va=e=>`Attempted to compute the number of elements in the ${ge(e)} ${_(U(e))}.`,Ha=e=>`Attempted to compute the number of elements in the model value ${_(U(e))}.`,Ua=e=>`Attempted to compute the number of elements in the overridden value ${_(U(e))}.`,Wa=(e,n)=>{let r=Math.max(0,n-e+1);if(r>2147483647)throw new t.D(`Size of interval value exceeds the maximum representable size (32bits): ${e}..${n}.`);return r},R=(e,t)=>{if(typeof e!=`object`)throw P(Va,e);switch(e.kind){case`ModelValue`:throw P(Ha,e);case`Operator`:throw P(Va,e);case`Function`:return e.domain.length;case`LazyFunction`:return R(e.domain,t);case`Interval`:return Wa(e.low,e.high);case`InfiniteSet`:case`SequenceSet`:throw P(Ua,e);case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:{let n=z.sets;n?.push(e);let r=Ga(e,t);return n?.pop(),r}default:return hi(e).elements.length}},Ga=(e,t)=>{switch(e.kind){case`Subset`:{let n=R(e.base,t);if(n>=31)throw P(Ba,e);return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(La(e.domain))return 1;if(La(e.range))return 0;if(R(e.range,t)===1)return 1}let n=R(e.domain,t),r=R(e.range,t);if(r<=1)return n===0?1:r;let i=1;for(let t=0;t<n;t++)if(i*=r,i>2147483647)throw P(Ba,e);return i}case`RecordSet`:return t!==`1.7.4`&&La(e)?0:za(e.sets,t,()=>Ba(e));case`ProductSet`:return t!==`1.7.4`&&La(e)?0:za(e.factors,t,()=>`Overflow when computing the number of elements in ${_(U(e))}`)}},Ka=e=>`Attempted to check if the set ${_(U(e))}is finite.`,qa=e=>{if(typeof e!=`object`||e.kind===`ModelValue`||e.kind===`Operator`)throw new t.D(`Attempted to check if the ${ge(e)} ${_(U(e))} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new t.D(`Attempted to check if the function:\n${_(U(e))}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return qa(e.base)&&La(e.base);case`Subset`:return qa(e.base);case`FunctionSet`:{let t=qa(e.domain);if(t&&La(e.domain))return!0;let n=qa(e.range);return n&&La(e.range)?!0:n&&(t||R(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n=!0;for(let e of t)if(!qa(e))n=!1;else if(La(e))return!0;return n}case`Union`:if(!I(e.base))throw new t.D(`Attempted to check if the nonenumerable set:\n${Or(e)}\nis a finite set.`);return L(e.base).elements.every(qa);case`SetOperation`:if(e.operator===`\\cup`)return qa(e.left)&&qa(e.right);if(e.operator===`\\cap`){if(!qa(e.left)&&!qa(e.right))throw new t.D(Ka(e));return!0}if(qa(e.left))return!0;if(!qa(e.right))throw new t.D(Ka(e));return!1;case`FilteredSet`:if(!qa(e.base))throw new t.D(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${_(U(e.base))}\nis finite.`);return!0}},Ja=(e,t,n=ht)=>{let r=0,i=e.length-1;for(;r<=i;){let a=r+i>>1,o=n(e[a],t);if(o===0)return a;o<0?r=a+1:i=a-1}return-1},Ya=(e,n)=>{let r=e.elements;if(r.length>ce())throw new t.q(le());let i=Array.from({length:r.length},()=>!1),a=n.filter(e=>{let t=Ja(r,e);return!i[t]&&(i[t]=!0,!0)}),o=Ct(r);return a.some((e,t)=>e!==r[t])&&(o.writtenElements=a),o},Xa=e=>e instanceof mr&&e.interval.low===1||e.every((e,t)=>e===t+1),Za=e=>{let t=ri(e.domain),n=[];for(let r=0;r<t.length;r++){if(t[r]!==r+1)return;n.push(e.apply(t[r]))}return Vo(e)&&e.costModel.node>=0&&(e.costModel.secondary[e.costModel.node]+=t.length),n},Qa=e=>typeof e.domain==`object`&&e.domain.kind===`Interval`?e.domain.low===1||e.domain.high<e.domain.low:Xa(ri(e.domain)),$a=e=>{if(typeof e!=`object`||!me(e))return;if(e.kind===`LazyFunction`){if(e.boundTupleLengths!==void 0)return;if(!j(e.domain)||tt(e.domain))throw new t.D(`To convert a function of form [x \\in S |-> f(x)] to a tuple, the set S must be enumerable.`);if(!e.enumerated&&(e.isApplicationObserved||!Qa(e)))return Za(e)}let n=V(e);if(eo(n.domain))return $t(e),n.range},eo=e=>e.length===0||e[0]===1&&e[e.length-1]===e.length,to=(e,t)=>{if(typeof t==`object`&&t.kind===`Operator`)return`Attempted to check if the value:\n${_(U(e))}\nis an element of operator ${_(U(t))}`;let n=`Attempted to check if the value:\n${_(U(e))}\nis an element of the`;if(!me(t))return`${n} ${ge(t)} ${_(U(t))}`;let r=Ot(t);return r===`record`?`Attempted to check if element:\n${_(U(e))}\nis in the record:\n${_(U(t))}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${_(U(t))}`},z={sets:void 0},no=()=>{let e=z.sets,t=z.callStack;if(e!==void 0||t!==void 0)return{depth:e?.length??0,length:t?.expressions.length??0,isFrozen:t?.isFrozen??!1,fingerprint:t?.fingerprint}},ro=e=>{e!==void 0&&(z.sets&&(z.sets.length=e.depth),z.callStack&&(z.callStack.fingerprint=e.fingerprint))},io=e=>{ro(e);let t=z.callStack;e!==void 0&&t&&(t.expressions.length=e.length,t.isFrozen=e.isFrozen)},ao=(e,n,r,i,a)=>{let o=no(),s=rt;rt=`stopping`;try{let t=e(r,i);return rt=s,t}catch(e){if(rt=s,!(e instanceof t.Z)){if(!(e instanceof t.D))throw e;if(a?.(r,i))throw so(e)}return io(o),n(r,i)}},oo=(e,n,r,i)=>{let a=no(),o=rt;rt=`deferring`;try{let t=e(r,i);return rt=o,t}catch(e){if(rt=o,!(e instanceof t.D))throw e;return io(a),n(r,i)}},so=e=>(rt===`none`&&e.formatMessage(),e),co=e=>(z.sets??[]).slice(e).some(e=>typeof e==`object`&&z.callStack?.sources.has(e)===!0),B=(e,t)=>{let n=z.sets;if(n===void 0)return vo(e,t);n.push(t);let r=vo(e,t);return n.pop(),r},lo=(e,t)=>{let n=z.sets;n?.push(t);let r=ho(e,t);return n?.pop(),r},uo=(e,t)=>{let n=z.sets;n?.push(t);let r=An(e,t.elements);return n?.pop(),r.isFound?r.index:-1},fo=(e,t,n)=>{let r=z.sets;if(r===void 0)return zo(e,t,n);r.push(t);let i=zo(e,t,n);return r.pop(),i},po=(e,t)=>{let n=t.elements,r=0,i=n.length-1;for(;r<=i;){let t=r+i>>1,a=n[t];if(typeof a!=`number`)return;if(a===e)return!0;a<e?r=t+1:i=t-1}return!1},mo=(e,t)=>Ja(t.elements,e)!==-1,ho=(e,t)=>re(t)?An(e,t.elements).isFound:jn(e,Mn(t)),go=(e,t)=>`Attempted to check if the typed model value ${_(U(e))} is an element of\n${_(U(t))}`,_o=(e,t)=>{if(e.type!==void 0)throw P(go,e,t);return!1},vo=(e,t)=>{if(typeof e==`number`&&typeof t==`object`){if(t.kind===`Set`&&!_t)return po(e,t)??Ro(e,t);if(t.kind===`Interval`)return e>=t.low&&e<=t.high}return Ro(e,t)},yo=(e,t)=>`Attempted to check if the non-enumerable value\n${_(U(e))}\nis element of\n${_(U(t))}`,bo=(e,t)=>{let n=t.elements,r=0,i=n.length;for(;r<i;){let t=r+i>>1,a=n[t];if(typeof a!=`number`)return;a<e.low?r=t+1:i=t}for(let t=e.low;t<=e.high;t++,r++){if(r===n.length)return!1;let e=n[r];if(e!==t)return typeof e!=`number`&&void 0}return!0},xo=(e,t,n)=>{if(typeof t==`object`&&(t.kind===`Interval`?t.low<=e.low&&t.high>=e.high:t.kind===`InfiniteSet`&&(t.name===`Int`||t.name===`Nat`&&e.low>=0)))return!0;let r=typeof t==`object`&&t.kind===`Set`?bo(e,t):void 0;if(r!==void 0)return r;for(let r=e.low;r<=e.high;r++)if(!n(r,t))return!1;return!0},So=(e,t,n)=>{if(!j(e)||tt(e))throw P(yo,e,t);return!Da(e,e=>!n(e,t.base))},Co=(e,t)=>`Attempted to check if \n${U(e)}\nwhich is not a TLC function value, is in the set of functions:\n${_(U(t))}`,wo=(e,t)=>`Attempted to check if non-record\n${U(e)}\nis in the set of records:\n${_(U(t))}`,To=(e,t)=>`Attempted to check if non-tuple\n${_(U(e))}\nis in the set of tuples:\n${_(U(t))}`,Eo=(e,t)=>{if(!me(e)){if(M(e))return _o(e,t);throw P(Co,e,t)}Ce(e);let n=Zt(e),r=Xt(e,n.domain);return(r===void 0?Hn(t.domain,Ct(n.domain)):Vn({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range},Do=(e,t)=>{Ce(e);let n=me(e)?V(e):void 0;if(!n||!N(n.domain)){if(M(e))return _o(e,t);throw P(wo,e,t)}return $t(n),n.domain.length===t.names.length&&n},Oo=(e,t)=>{let n=me(e)?$a(e):void 0;if(n===void 0){let n=me(e)&&Zt(e).domain.every(e=>typeof e==`number`);if(M(e))return _o(e,t);if(n)return!1;throw P(To,e,t)}return n.length===t.factors.length&&n},ko=(e,n)=>e instanceof t.D&&r.y(e)&&!co(n),Ao=(e,t)=>`Cannot decide if element:\n${_(U(e))}\n is element of:\n${_(U(t.base))}\nand satisfies the predicate ${t.source?.predicate}`,jo=e=>{let t=L(e).elements;if(t.length>1)for(let e of t)typeof e==`object`&&e.kind===`Set`&&(e.flags|=1);return t},Mo=(e,t)=>`Attempted to check if:\n ${_(U(e))}\nis an element of the non-enumerable set:\n ${_(Or(t))}`,No=(e,t,n)=>{if(!I(t.base))throw P(Mo,e,t);return Da(t.base,t=>n(e,t))},Po=(e,t)=>`Attempted to check if the value:\n${_(U(e))}\nis an element of ${_(U(t))}.`,Fo=(e,n)=>{let r=$a(e);if(r===void 0){if(M(e))return _o(e,n);throw new t.H(at(Po,e,n))}return r},Io=(e,t)=>`Attempted to check if the value:\n${_(U(e))}\nis in the integer interval ${_(U(t))}`,Lo=(e,t)=>`Attempted to check if the value:\n${_(U(e))}\nis an element of ${t.name}.`,Ro=(e,n)=>{if(!j(n))throw P(to,e,n);switch(n.kind){case`Set`:return _t||kt(e)||Rt(e)?ho(e,n):ao(mo,ho,e,n);case`MixedSet`:return n.enumerated?An(e,n.enumerated.elements).isFound:jn(e,n.elements);case`Interval`:if(typeof e==`number`)return e>=n.low&&e<=n.high;if(n.low<=n.high&&(!M(e)||e.type!==void 0))throw P(Io,e,n);return!1;case`InfiniteSet`:if(n.name===`Any`)return!0;if(M(e))return _o(e,n);if(!(n.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new t.H(at(Lo,e,n));return n.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:return typeof e==`object`&&e.kind===`Interval`?xo(e,n.base,B):pe(e)?L(e).elements.every(e=>B(e,n.base)):So(e,n,B);case`FunctionSet`:{let t=Eo(e,n);return t!==!1&&t.every(e=>B(e,n.range))}case`RecordSet`:{let t=Do(e,n);return t!==!1&&n.names.every((e,r)=>{let i=Ja(t.domain,e);return i!==-1&&B(t.range[i],n.sets[r])})}case`ProductSet`:{let t=Oo(e,n);return t!==!1&&t.every((e,t)=>B(e,n.factors[t]))}case`FilteredSet`:{if(n.isCached)return B(e,L(n));let t=z.sets?.length??0;try{return B(e,n.base)&&n.test(e,!0)}catch(r){throw ko(r,t)?P(Ao,e,n):r}}case`Union`:return pe(n.base)?jo(n.base).some(t=>B(e,t)):No(e,n,B);case`SetOperation`:return n.operator===`\\cup`?B(e,n.left)||B(e,n.right):B(e,n.left)&&B(e,n.right)===(n.operator===`\\cap`);case`SequenceSet`:{let t=Fo(e,n);return t!==!1&&t.every(e=>B(e,n.base))}default:throw P(to,e,n)}},zo=(e,t,n)=>{if(typeof t!=`object`)return Ro(e,t);switch(t.kind){case`Subset`:return typeof e==`object`&&e.kind===`Interval`?xo(e,t.base,n):pe(e)?L(e).elements.every(e=>n(e,t.base)):So(e,t,n);case`FunctionSet`:{let r=Eo(e,t);return r!==!1&&r.every(e=>n(e,t.range))}case`RecordSet`:{let r=Do(e,t);return r!==!1&&t.names.every((e,i)=>{let a=Ja(r.domain,e);return a!==-1&&n(r.range[a],t.sets[i])})}case`ProductSet`:{let r=Oo(e,t);return r!==!1&&r.every((e,r)=>n(e,t.factors[r]))}case`FilteredSet`:{if(t.isCached)return n(e,L(t));let r=z.sets?.length??0;try{return n(e,t.base)&&t.test(e,!0)}catch(n){throw ko(n,r)?P(Ao,e,t):n}}case`Union`:return pe(t.base)?jo(t.base).some(t=>n(e,t)):No(e,t,n);case`SetOperation`:return t.operator===`\\cup`?n(e,t.left)||n(e,t.right):n(e,t.left)&&n(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let r=Fo(e,t);return r!==!1&&r.every(e=>n(e,t.base))}default:return Ro(e,t)}},Bo=(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?B(e,n):e.range.every((e,r)=>Bo(e,t.range[r],n.range)),Vo=e=>`costModel`in e,Ho=e=>Vo(e)?e.costModel.node:-1,Uo=e=>`original`in e,Wo=e=>{let t=[];for(let n=e;Uo(n);n=n.original)t.push(n);return t},Go=(e,t)=>{let n=Wo(e);return t.map(t=>{let r=e.applyBody(t);for(let e=n.length-1;e>=0;e--){let i=n[e];Vn(i.path[i.depth],t)&&(r=xs(r,i.path,i.depth+1,i.newValue))}return r})},Ko=e=>`Expected a function but found ${U(e)}`,V=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){if(e.enumerated)return e.enumerated;if(qn)throw new t.D(`The set literal holds a lazy function`);let n=Vo(e)?e.costModel.startConversion():void 0;if(R(e.domain),!j(e.domain))throw new t.D(`The domains of formal parameters must be enumerable.`);let r=Sr(e.domain,!1),i=Uo(e)?Go(e,r):r.map(t=>e.apply(t));return e.enumerated=kn(e.domain,r,i),n?.(),e.enumerated}throw P(Ko,e)},qo=(e,t,n)=>{let r=_(U(e)),i=_(U(t)),a=n===`1.7.4`;switch(Ot(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.`}},Jo=(e,t)=>{if(!ze)return qo(e,t);let n=_(U(t));return Ot(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},Yo=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}return e.length<=8?e.indexOf(t):-1},Xo=e=>new t.D(`Attempted to apply function with integer domain to the non-integer argument ${_(U(e))}`),Zo=(e,t)=>Ja(e.domain,t),Qo=(e,t)=>{let n=ye(e),r=e.domain;if(!ze&&n===r&&n.length>=32)return Ja(n,t,(e,t)=>wn(e,()=>bn(e,t)));let i=n.findIndex(e=>wn(e,()=>xn(e,t)));return i===-1||n===r?i:r.indexOf(n[i])},$o=(e,n,r)=>{let i=e.domain;if(typeof n!=typeof i[0]){let a=Ot(e),o=a===`tuple`?`number`:a===`record`?`string`:void 0;if(o!==void 0&&typeof n!==o)throw new t.D(r(e,n));if(o===void 0&&!ze&&typeof n!=`number`&&xr(i))throw Xo(n)}let a=Yo(i,n);return a===-1?oo(Zo,Qo,e,n):a},es=(e,n)=>{let r=$o(e,n,qo);if(r===-1)throw new t.D(qo(e,n));return r},ts=(e,t,n,r)=>`In applying the function\n${_(U(e))},\nthe ${t} is:\n${_(U(n))}\nwhich ${r}.\n`,ns=(e,n)=>new t.D(ts(e,`argument list`,n,`does not match its formal parameter`)),rs=e=>new t.D(`Attempted to apply a function to ${U(e)}, which is not in its domain`),is=(e,n,r,i)=>new t.D(ts(e,`argument number ${n+1}`,r,i===void 0?`is not in the function's domain ${U(e.domain)}`:`is not in its domain`)),as=(e,t)=>typeof e==`object`&&e.kind===`Function`&&e.functionClass===`tuple`?e:F(t),os=(e,n,r,i)=>{if(i===void 0)return r;let a=$a(r);if(a===void 0||a.length!==i)throw new t.D(ts(e,`argument number ${n+1}`,r,`does not match its formal parameter`));return as(r,a)},ss=(e,t,n)=>{let r=e.domain,i=$a(n);if(i===void 0)throw ns(e,n);if(typeof r!=`object`||r.kind!==`ProductSet`)throw rs(n);let a=i;for(let o=0;o<t.length;o++){if(o>=i.length)throw ns(e,n);let s=i[o],c=t[o];if(!B(s,r.factors[o]))throw is(e,o,s,c);let l=os(e,o,s,c);l!==s&&(a===i&&(a=[...i]),a[o]=l)}if(i.length>t.length)throw ns(e,n);return a===i?as(n,i):F(a)},cs=(e,t,n,r)=>{let i=e.domain,a=$a(n);if(a===void 0)throw ns(e,n);if(typeof i!=`object`||i.kind!==`ProductSet`)throw rs(n);let o=a;for(let s=0;s<t.length;s++){if(s>=a.length)throw ns(e,n);let c=a[s],l=t[s];if(!r(c,i.factors[s]))throw is(e,s,c,l);let u=os(e,s,c,l);u!==c&&(o===a&&(o=[...a]),o[s]=u)}if(a.length>t.length)throw ns(e,n);return o===a?as(n,a):F(o)},ls=(e,n,r)=>{let i=e.boundTupleLengths;if(i!==void 0)return cs(e,i,n,r);if(!r(n,e.domain))throw new t.D(qo(e,n));return n},us=(e,t,n,r)=>t.apply(ls(e,n,r)),ds=(e,t,n)=>{if(e.boundTupleLengths!==void 0&&$a(n)===void 0)throw ns(e,n);return B(n,e.domain)?t.apply(n):void 0},fs=(e,t,n)=>t.apply(n),ps=(e,t,n,r)=>{let i,a=e;for(;Uo(a);){if(Vn(a.path[a.depth],t)){if(a.depth===a.path.length-1)break;i===void 0&&(i=[]),i.push(a)}a=a.original}let o=Uo(a)?a.newValue:r(e,a,t,n);if(i===void 0||o===void 0)return o;let s=o;for(let e=i.length-1;e>=0;e--){let t=i[e];s=xs(s,t.path,t.depth+1,t.newValue)}return s},ms=(e,n,r)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(e.enumerated)return ms(e.enumerated,n,r);if(Uo(e))return ps(e,n,B,us);let i=e.boundTupleLengths;if(i!==void 0)return e.apply(ss(e,i,n));if(!B(n,e.domain))throw new t.D(qo(e,n));return e.apply(n)}if(typeof e!=`object`||e.kind!==`Function`)throw new t.D(`Attempted to apply ${U(e)}, which is not a function`);let i=r??qo,a=$o(e,n,i);if(a===-1)throw new t.D(i(e,n));return e.range[a]},hs=(e,t,n,r)=>typeof e!=`object`||e.kind!==`LazyFunction`||e.enumerated!==void 0?ms(e,t,n):Uo(e)?ps(e,t,r,us):e.apply(ls(e,t,r)),gs=e=>e instanceof mr?e.interval:void 0,_s=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return e.domain;let t=V(e),n=gs(t.domain);if(n)return n;let r=Ct(t.domain);return t.functionClass===`record`?(t.writtenKeys&&(r.writtenElements=t.writtenKeys),r):(r.flags|=1,r)},vs=(e,t,n,r)=>{let i={kind:`LazyFunction`,domain:e.domain,apply:e=>ps(i,e,B,fs),source:e.source,boundTupleLengths:e.boundTupleLengths,isApplicationObserved:e.isApplicationObserved,original:e,path:t,depth:n,newValue:r,applyBody:Uo(e)?e.applyBody:e.apply};return Vo(e)?Object.assign(i,{costModel:e.costModel}):i},ys=e=>{if(!me(e))throw new t.D(`Attempted to apply EXCEPT construct to the value ${_(U(e))}.`);return V(e)},bs=(e,t,n)=>{let r=e;for(let e=n;e<t.length;e++){let n=t[e];if(typeof r==`object`&&r.kind===`LazyFunction`&&r.enumerated===void 0){let e=ps(r,n,B,ds);if(e===void 0)return;r=e;continue}let i=ys(r),a=$o(i,n,Jo);if(a===-1)return;r=i.range[a]}return r},xs=(e,t,n,r)=>{if(n===t.length)return r;if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return vs(e,t,n,r);let i=ys(e),a=$o(i,t[n],Jo);return a===-1?i:Es(i,a,xs(i.range[a],t,n+1,r))},Ss=(e,t,n,r)=>{if(n===t.length)return r(e);if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0){let i=bs(e,t,n);return i===void 0?e:vs(e,t,n,r(i))}let i=ys(e),a=$o(i,t[n],Jo);return a===-1?i:i instanceof C?D(i,a,Ss(ee(i,a),t,n+1,r)):Es(i,a,Ss(i.range[a],t,n+1,r))},Cs=0,ws=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return Us(e);if(e.kind===`LazyFunction`)return e.enumerated===void 0?0:ws(e.enumerated);if(e.kind===`Set`){if(!re(e))return 0;if(e.hash!==0)return e.hash;let t=e.elements,n=As;for(let e=0;e<t.length;e++){let r=ws(t[e]);if(r===0||r===Ps)return r;n=n+Ms(r)|0}return e.hash=n,n}if(e.kind!==`Function`)return 0;if(e.hash!==0||e.flags&64)return e.hash;let t=js;for(let n=0;n<e.domain.length;n++){let r=ws(e.domain[n]);if(r===0||r===Ps)return r;let i=ws(e.range[n]);if(i===0||i===Ps)return i;t=t+Ns(r,i)|0}return e.hash=t,t},Ts=(e,t)=>{let n=Dt(Et(e.domain,t),e.functionClass),r=e.hash!==0&&e.hash!==Ps,i=e.hash;for(let n=0;n<t.length&&r;n++){let a=e.range[n],o=t[n];if(o===a)continue;let s=ws(o);if(s===0||s===Ps){r=!1;continue}let c=Us(e.domain[n]);i=i-Ns(c,Us(a))+Ns(c,s)|0}return r&&(n.hash=i),n},Es=(e,t,n)=>{let r=[...e.range],i=e.range[t];r[t]=n;let a=Dt(Et(e.domain,r),e.functionClass);a.writtenKeys=e.writtenKeys;let o=e.hash!==0&&e.hash!==Ps;if(!o&&e.fingerprint===0)return a;let s=ws(n);if(s===0||s===Ps)return a;if(o){let r=Us(e.domain[t]);a.hash=i===n?e.hash:e.hash-Ns(r,Us(i))+Ns(r,s)|0}if(e.fingerprint!==0){let r=e.domain[t];a.fingerprint=i===n?e.fingerprint:e.fingerprint-qs(r,i)+qs(r,n)|0}return a},Ds=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Os=(e,t)=>Math.imul(e^t,16777619),ks=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Ds(t)},As=1940243425,js=1725019383,Ms=e=>Ds(e+2654435769|0),Ns=(e,t)=>Ds(Math.imul(e,668265261)+t|0),Ps=795548749,Fs=e=>e===Ps,Is=e=>{if(e instanceof C)return ne(e);if(e.kind===`Set`){let t=e.elements,n=As;for(let e=0;e<t.length;e++){let r=Us(t[e]);if(r===Ps)return Ps;n=n+Ms(r)|0}return n}let t=js;for(let n=0;n<e.domain.length;n++){let r=Us(e.domain[n]),i=Us(e.range[n]);if(r===Ps||i===Ps)return Ps;t=t+Ns(r,i)|0}return t},Ls=e=>{let t=e.low+Wa(e.low,e.high),n=As;for(let r=e.low;r<t;r++)n=n+Ms(Us(r))|0;return n},Rs=e=>new t.D(`TLC has found a state in which the value of a variable contains ${_(U(e))}`),zs=e=>{typeof e==`object`&&e.kind!==`ModelValue`&&wn(e,()=>{if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw Rs(e);if(j(e)){for(let t of L(e).elements)zs(t);return}let t=V(e);for(let[e,n]of t.domain.entries())zs(n),zs(t.range[e])})},Bs=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{Us(e)===Ps&&zs(e);return}catch(e){if(!(e instanceof t.D))throw e;return e}},Vs=e=>{let n=z.sets,r=[];z.sets=r;try{zs(e)}catch(e){if(!(e instanceof t.D))throw e}finally{z.sets=n}return r},Hs=e=>Ds(e^1540483477),Us=e=>{if(typeof e==`number`)return Hs(e);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return ks(e);if(e.kind===`Set`||e.kind===`Function`)return e.kind===`Set`&&(e.flags|=1),e.hash===0&&(e.hash=Is(e),e.hash!==Ps&&(e.flags|=4)),e.hash;if(e.kind===`ModelValue`)return e.hash;if(e.kind===`LazyFunction`)return Pr(e.domain)?Us(V(e)):Ps;if(e.kind===`Interval`)return Ls(e);if(!Pr(e))return Ps;let t=pi(e),n=t?gi(t,!0,L):L(e);return zt(e),Us(n)},Ws=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},Gs=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return Ws(t)},Ks=e=>Ws(Zs(e)+2135587861|0),qs=(e,t)=>Ws(Math.imul(Zs(e),374761393)+Zs(t)|0),Js=461845907,Ys=e=>{if(e.kind===`Set`){let t=e.elements,n=Js;for(let e=0;e<t.length;e++)n=n+Ks(t[e])|0;return n}let t=1291169091;for(let n=0;n<e.domain.length;n++)t=t+qs(e.domain[n],e.range[n])|0;return t},Xs=e=>{let t=e.low+Wa(e.low,e.high),n=Js;for(let r=e.low;r<t;r++)n=n+Ks(r)|0;return n},Zs=e=>typeof e==`number`?Ws(e^1759714724):typeof e==`boolean`?e?1000000007:521288629:typeof e==`string`?Gs(e):e.kind===`Set`||e.kind===`Function`?(e.fingerprint===0&&(e.fingerprint=Ys(e)),e.fingerprint):e.kind===`ModelValue`?e.fingerprint:e.kind===`LazyFunction`?Zs(V(e)):e.kind===`Interval`?Xs(e):Pr(e)?Zs(L(e)):Gs(Qs(e)),Qs=e=>typeof e==`boolean`?e?`T`:`F`:typeof e==`number`?String(e):typeof e==`string`?JSON.stringify(e):$s(e),$s=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${Qs(e.base)}>`;if(e.kind===`FilteredSet`&&!Pr(e))throw new t.D(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(j(e))return Pr(e)?`{${L(e).elements.map(Qs).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let n=V(e);return`(${n.domain.map((e,t)=>`${Qs(e)}:${Qs(n.range[t])}`).join(`,`)})`},ec={'"':`\\"`,"\\":`\\\\`," ":`\\t`,"\n":`\\n`,"\f":`\\f`,"\r":`\\r`},tc=e=>`"${e.replace(/["\\\t\n\f\r]/g,e=>ec[e])}"`,nc=1999,rc=e=>e.reduce((e,t)=>e===0?0:e*R(t),1),ic=e=>{let t=pi(e);return t?gi(t,!1,fi):fi(e)},ac=e=>{if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return ic(e);if(e.cost?.charges?.chargePrintedSize(e),e.kind===`Subset`)return R(e.base)>6?void 0:ic(e);if(e.kind===`FunctionSet`){let t=La(e.domain)?0:R(e.domain);return(t===0?1:R(e.range)**t)<=nc?ic(e):void 0}return rc(e.kind===`RecordSet`?e.sets:e.factors)<=nc?ic(e):void 0},oc=(e,n)=>{if(n||e.kind===`Subset`&&me(e.base)&&(e.base.kind===`Function`||Pr(e.base.domain)))return ac(e);let r=no();try{return ac(e)}catch(e){if(!(e instanceof t.D))throw e;ro(r);return}},H=(e,t)=>{e.pending===void 0?e.parts.push(t):e.pending.push(t)},sc=(e,t)=>{e.pending===void 0?t?.pop():e.pending.push({kind:`SetEnd`,sets:t})},cc=(e,t,n,r)=>{let i=[{kind:`Value`,value:t,isStrict:n,isNormalized:r}];e.pending=i;for(let t=i.pop();t!==void 0;t=i.pop()){if(typeof t==`string`){e.parts.push(t);continue}if(t.kind===`SetEnd`){t.sets?.pop();continue}let n=i.length;Ec(e,t.value,t.isStrict,t.isNormalized);for(let e=n,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}e.pending=void 0},lc=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?cc(e,t,n,r):(e.depth++,Ec(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isStrict:n,isNormalized:r})},uc=(e,t,n,r,i)=>{for(let a=0;a<t.length;a++)a>0&&H(e,n),lc(e,t[a],r,i)},dc=/* @__PURE__ */ new Set([`Set`,`MixedSet`,`Interval`,`Subset`,`FunctionSet`,`RecordSet`,`ProductSet`,`SetOperation`,`FilteredSet`,`Union`]),fc=e=>!ze&&typeof e==`object`&&dc.has(e.kind),pc=(e,t,n,r)=>{r&&H(e,`(`),lc(e,t,n,!1),r&&H(e,`)`)},mc=(e,t,n)=>{switch(t.kind){case`Subset`:return H(e,`SUBSET `),pc(e,t.base,n,typeof t.base==`object`&&(t.base.kind===`Interval`||t.base.kind===`SetOperation`));case`FunctionSet`:return H(e,`[`),lc(e,t.domain,n,!1),H(e,` -> `),lc(e,t.range,n,!1),H(e,`]`);case`RecordSet`:H(e,`[`);for(let r=0;r<t.names.length;r++)H(e,`${r>0?`, `:``}${t.names[r]}: `),lc(e,t.sets[r],n,!1);return H(e,`]`);case`ProductSet`:return H(e,`(`),uc(e,t.factors,` \\X `,n,!1),H(e,`)`);case`SetOperation`:return pc(e,t.left,n,fc(t.left)),H(e,` ${t.operator} `),pc(e,t.right,n,fc(t.right));case`FilteredSet`:return H(e,t.source?`{${t.source.names} \\in `:`{x \\in `),lc(e,t.base,n,!1),H(e,t.source?` : <expression ${t.source.predicate}> }`:` : ...}`);case`Union`:return H(e,`UNION(`),lc(e,t.base,n,!1),H(e,`)`)}},hc=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),gc=e=>{if(!Pr(e.domain))return;let n=no();try{return V(e)}catch(e){if(!(e instanceof t.D)&&!t.wt(e))throw e;ro(n);return}},_c=(e,t,n)=>{t.kind===`Set`?ie(t,!0):L(t),n&&e.copies.push(t)},vc=(e,t,n,r,i)=>{let a=r?t.writtenKeys:void 0;if(!i){t.writtenKeys=a;return}let o=e.copies.splice(e.copies.length-t.range.length),s=t.domain.every(ja),c=s?t.domain:[...t.domain];s||Tn(c,o);let l={...t,domain:c,range:o,writtenKeys:a};e.copies.push(n?{...n,enumerated:l}:l)},yc=(e,t,n)=>{e.pending===void 0?_c(e,t,n):e.pending.push({kind:`SetEnd`,value:t,isCopied:n})},bc=(e,t,n,r,i)=>{e.pending===void 0?vc(e,t,n,r,i):e.pending.push({kind:`FunctionEnd`,value:t,lazy:n,isWrittenOrderKept:r,isCopied:i})},xc=(e,t,n,r)=>{let i=[{kind:`Value`,value:t,isWrittenOrderKept:n,isCopied:r}];e.pending=i;for(let t=i.pop();t!==void 0;t=i.pop()){if(t.kind===`SetEnd`){_c(e,t.value,t.isCopied);continue}if(t.kind===`FunctionEnd`){vc(e,t.value,t.lazy,t.isWrittenOrderKept,t.isCopied);continue}let n=i.length;wc(e,t.value,t.isWrittenOrderKept,t.isCopied);for(let e=n,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}e.pending=void 0},Sc=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?xc(e,t,n,r):(e.depth++,wc(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isWrittenOrderKept:n,isCopied:r})},Cc=(e,t,n,r)=>{for(let i=0;i<t.length;i++)Sc(e,t[i],n,r)},wc=(e,t,n,r)=>{if(typeof t==`object`)switch(t.kind){case`Set`:case`MixedSet`:return Cc(e,t.elements,n,!1),yc(e,t,r);case`Function`:return Cc(e,t.range,n,r),bc(e,t,void 0,n,r);case`LazyFunction`:if(t.enumerated)return Cc(e,t.enumerated.range,!0,r),bc(e,t.enumerated,t,!0,r);Sc(e,t.domain,n,!1),r&&e.copies.push({...t});return;case`SetOperation`:Sc(e,t.left,n,!1),Sc(e,t.right,n,!1);break;case`FunctionSet`:Sc(e,t.domain,n,!1),Sc(e,t.range,n,!1);break;case`RecordSet`:Cc(e,t.sets,n,!1);break;case`ProductSet`:Cc(e,t.factors,n,!1);break;case`Subset`:case`Union`:case`FilteredSet`:case`SequenceSet`:Sc(e,t.base,n,!1)}r&&e.copies.push(t)},Tc=e=>{let t={depth:0,pending:void 0,copies:[]};for(let n of e)wc(t,n,!1,!0);return t.copies.map(e=>U(e,!0,!0))},Ec=(e,t,n,r)=>{if(typeof t==`boolean`)return H(e,t?`TRUE`:`FALSE`);if(typeof t==`number`)return H(e,String(t));if(typeof t==`string`)return H(e,tc(t));switch(t.kind){case`ModelValue`:return H(e,t.name);case`Set`:return H(e,`{`),uc(e,t.elements,`, `,n,r),H(e,`}`);case`MixedSet`:return lc(e,L(t),n,r);case`Interval`:return H(e,t.low<=t.high?`${t.low}..${t.high}`:`{}`);case`InfiniteSet`:return H(e,t.name===`Any`?`ANY`:t.name);case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let i=z.sets;i?.push(t);let a=Be.isExpanded?oc(t,n):void 0;return a?lc(e,a,n,r):mc(e,t,n),sc(e,i)}case`SequenceSet`:return H(e,`Seq(`),lc(e,t.base,n,r),H(e,`)`);case`Function`:case`LazyFunction`:{let i=t.kind===`LazyFunction`?Be.isExpanded||!t.source?gc(t):void 0:t;if(i===void 0){let n=t.kind===`LazyFunction`?t.source:void 0;if(!n)return H(e,`<function>`);H(e,`[`);for(let t=0;t<n.parameters.length;t++){let r=n.parameters[t];H(e,`${t>0?`, `:``}${r.name} \\in `),lc(e,r.domain,!1,!1)}return H(e,` |-> <expression ${n.body}>]`)}if(i.domain.length===0&&ze&&Ot(t)!==`tuple`)return H(e,`<< >>`);if(i.domain.length===0&&Ot(t)===`record`)return H(e,`[]`);let a=r&&Ot(t)!==`lambda`;if(Xa(i.domain))return i.range.every(e=>typeof e==`number`)?H(e,`<<${i.range.join(`, `)}>>`):(H(e,`<<`),uc(e,i.range,`, `,n,a),H(e,`>>`));let o=r?i.domain.map((e,t)=>[e,i.range[t]]):xe(i);if(Ot(t)===`record`||i.domain.every(e=>typeof e==`string`&&hc(e))){H(e,`[`);for(let t=0;t<o.length;t++)H(e,`${t>0?`, `:``}${String(o[t][0])} |-> `),lc(e,o[t][1],n,a);return H(e,`]`)}H(e,`(`);for(let t=0;t<o.length;t++)t>0&&H(e,` @@ `),lc(e,o[t][0],n,r),H(e,` :> `),lc(e,o[t][1],n,a);return H(e,`)`)}case`Operator`:return H(e,t.javaClass===`MethodValue`?`<Java Method: ${t.signature}>`:`<Operator ${t.name}>`)}},U=(e,t=!1,n=!1)=>{let r={parts:[],depth:0,pending:void 0};return Ec(r,e,t,n),r.parts.join(``)},Dc=(e,n)=>{if(e===void 0)return!1;try{return Bt(e,n)}catch(r){if(r instanceof t.D)return e===n;throw r}},Oc=/%(\d+\$)?([-#+ 0,(<]*)(\d+)?(\.\d+)?(.?)/gs,kc=(e,t)=>{let r=0,i=-1,a=!0,o=e.replace(Oc,(e,o,s=``,c,l,u=``)=>{let d=e=>s.includes(`-`)?e.padEnd(Number(c)):e.padStart(Number(c??0)),f=s.includes(`<`),p=s.replace(`<`,``);if(u===`n`&&e===`%n`)return`
|
|
9
|
+
const e=require("./rolldown-runtime.cjs"),t=require("./worker.cjs"),n=require("./order.cjs"),r=require("./modules.cjs"),i=(e,t)=>t.rootKeys.get(e)??e,a=e=>`line ${e.location.line}, column ${e.location.column}`,o=e=>{let n=e.location.range;return n?t.gt(n):a(e)},s=e=>e.kind===`Number`?e.text??String(e.value):o(e),c=1e3,l={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:` `}},u=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},d=e=>e!==void 0&&/^\p{Nd}$/u.test(e),f=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),p=e=>e.kind!==`Constant`,m=(e,t,n)=>({kind:e,first:t,last:n,children:[]}),h=`Parsed`,g=e=>{let t=t=>{let r=n.er(e,t,u);return e[r]===void 0?void 0:r},r=(n,r,i,a,o)=>{if(r){n.children.push(r);let i=t(r.last+1);if(i===void 0)return;n.last=e.startsWith(o,i)?i+o.length:i}let s=t(n.last);if(s!==void 0)return e[s]===i?(n.last=s,h):a===void 0?l(s):m(a,s,s)},i=(n,r,i)=>{if(!r)return l(n.last);if(n.children.length===1)return n.children=[n.children[0],r],n.last=r.last,h;n.children=[r];let a=t(r.last+1);if(a===void 0||!e.startsWith(i,a))return;let o=t(a+i.length);return o===void 0?void 0:l(o)},a=(n,a)=>{switch(n.kind){case`Set`:return r(n,a,`}`,void 0,`,`);case`Sequence`:{let t=r(n,a,`>`,void 0,`,`);return t===h?n.last+1>=e.length?void 0:(n.last++,h):t}case`Record`:return r(n,a,`]`,`RecordPair`,`,`);case`RecordPair`:return i(n,a,`|->`);case`Function`:return r(n,a,`)`,`FunctionPair`,`@@`);case`Subset`:{if(a)return n.children=[a],n.last=a.last,h;let e=t(n.last);return e===void 0?void 0:l(e)}case`FunctionPair`:return i(n,a,`:>`)}},o=t=>{let r=n.er(e,t,d);if(e.startsWith(`..`,r)&&d(e[r+2]))return{kind:`Constant`,first:t,last:n.er(e,r+2,d)-1,children:[]}},s=t=>{let r=e[t];if(r===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let i=d(r)?o(t):void 0;if(i)return i;if(r===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:n.er(e,t+1,d)-1,children:[]};if(f(r))return{kind:`Constant`,first:t,last:n.er(e,t,f)-1,children:[]}},l=n=>{let r=t(n);if(r!==void 0)switch(e[r]){case`{`:return m(`Set`,r,r+1);case`<`:return m(`Sequence`,r,r+2);case`[`:return m(`Record`,r,r+1);case`(`:return m(`Function`,r,r+1);default:return e.startsWith(`SUBSET`,r)?m(`Subset`,r,r+6):s(r)}},g=(e,t)=>{let n;if(t<c)for(;;){let r=a(e,n);if(r===h)return e;if(r===void 0||(n=p(r)?g(r,t+1):r,n===void 0))return}let r=[e];for(let e=r.at(-1);e!==void 0;e=r.at(-1)){let t=a(e,n);if(t===void 0)return;t===h?(r.pop(),n=e):p(t)?(r.push(t),n=void 0):n=t}return n},_=l(0);return _&&p(_)?g(_,0):_},_=e=>{let t=e.length===0?void 0:g(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=``,a=0,o,s=e=>{o===void 0?i+=e:o.push(e)},u=(e,t,n,r)=>{if(o!==void 0)return o.push({node:e,columnWidth:t,trailerWidth:n,leftPad:r}),!0;if(a<c){a++;let i=d(e,t,n,r);return a--,i}let s=[{node:e,columnWidth:t,trailerWidth:n,leftPad:r}];o=s;for(let e=s.pop();e!==void 0;e=s.pop()){if(typeof e==`string`){i+=e;continue}let t=s.length;if(!d(e.node,e.columnWidth,e.trailerWidth,e.leftPad))return!1;for(let e=t,n=s.length-1;e<n;e++,n--){let t=s[e];s[e]=s[n],s[n]=t}}return o=void 0,!0},d=(e,t,i,a)=>{if(r(e)<=t-i||e.kind===`Constant`)return s(n(e)),!0;if(e.kind===`RecordPair`||e.kind===`FunctionPair`)return!1;let o=l[e.kind],c=t-Math.max(o.open.length,o.pad.length),u=i+o.close.length,d=a+o.pad;s(o.open);let m=e.kind===`Function`||e.kind===`Record`?p(e.children,c,u,d,o):f(e.children,c,u,d,o.separator);return s(o.close),m},f=(e,t,n,r,i)=>{for(let a=0;a<e.length;a++){let o=a===e.length-1;if(!u(e[a],t,o?n:i.length,r))return!1;o||s(`${i}\n${r}`)}return!0},p=(e,t,i,a,o)=>{for(let c=0;c<e.length;c++){let l=c===e.length-1,d=e[c].children[0],f=e[c].children[1],p=l?``:`${o.separator}\n${a}`,m=r(d)+o.divider.length+1+r(f);if(l?m<=t-i:m+o.separator.length<=t)s(`${n(d)}${o.divider} ${n(f)}${p}`);else{if(r(d)+o.divider.length<=t)s(n(d));else if(!u(d,t,i+o.divider.length,a))return!1;if(s(`${o.divider}\n${a}${o.dividerPad}`),!u(f,t-o.dividerPad.length,l?i:o.separator.length,a+o.dividerPad))return!1;s(p)}}return!0};return d(t,80,0,``)?i:e},v=(e,t)=>t?e:_(e),y=e=>e.kind!==`ModelValue`&&e.kind!==`Set`&&e.kind!==`Function`&&e.kind!==`Interval`&&e.kind!==`InfiniteSet`&&e.kind!==`LazyFunction`,b=2147483647,x=e=>(e.flags|=16,e),S=e=>typeof e==`object`&&e.kind===`Function`&&!!(e.flags&16);var C=class{kind=`Function`;domain;hash;fingerprint=0;writtenKeys=void 0;functionClass=`tuple`;flags=80;edges;locations;plans;sources;records;hashes;makeRecord;writtenSlots;made=void 0;constructor(e,t,n,r,i,a,o,s,c){this.domain=gr(i.length),this.hash=o,this.edges=e,this.locations=t,this.plans=n,this.sources=r,this.records=i,this.hashes=a,this.makeRecord=s,this.writtenSlots=c}get range(){if(this.made!==void 0)return this.made;let e=this.records.map((e,t)=>e??this.makeRecord(this,t));return this.records=e,this.made=e,e}};const w=e=>e instanceof C,ee=(e,t)=>e.records[t]??=e.makeRecord(e,t),T=(e,t)=>e.writtenSlots!==void 0&&(e.writtenSlots[t>>5]>>>(t&31)&1)==1,te=(e,t)=>{let n=e.records[t];return n!==void 0&&T(e,t)?ws(n):e.hashes[t]},ne=e=>{let t=js;for(let n=0;n<e.records.length;n++){let r=e.records[n],i=r!==void 0&&T(e,n)?Us(r):e.hashes[n];if(i===Ps)return Ps;t=t+Ns(Hs(n+1),i)|0}return t},E=e=>e.hash!==Cs&&e.hash!==Ps,D=(e,t,n)=>{let r=e.writtenSlots?.slice()??/* @__PURE__ */ new Int32Array(8);r[t>>5]|=1<<(t&31);let i=e.records.slice();i[t]=n;let a=new C(e.edges,e.locations,e.plans,e.sources,i,e.hashes,Cs,e.makeRecord,r);return a.flags=64,a},O=(e,t)=>{let n=e.writtenSlots?.slice(),r=!1;if(n!==void 0){for(let r=t;r<e.records.length;r++)n[r>>5]&=~(1<<(r&31));for(let e=0;e<n.length;e++)r||=n[e]!==0}let i=new C(e.edges,e.locations,e.plans,e.sources,e.records.slice(0,t),e.hashes,Cs,e.makeRecord,r?n:void 0);if(i.flags=64,!E(e))return i;let a=e.hash;for(let n=t;n<e.records.length;n++)a=a-Ns(Hs(n+1),te(e,n))|0;return i.hash=a,i},k=(e,t)=>e.records.length===256?F(e.range.concat([t])):D(e,e.records.length,t),re=e=>e.kind===`MixedSet`?e.enumerated!==void 0:!!(e.flags&1),ie=(e,t)=>{e.flags=t?e.flags|1:e.flags&-2},ae=1e6;let oe=ae;const se=()=>oe,ce=()=>Math.max(oe,10),le=()=>`Attempted to construct a set with too many elements (>${oe}).`,A=(e,n)=>{if(e.length===ce())throw new t.q(le());e.push(n)},ue=e=>typeof e==`object`&&e.kind===`Interval`&&e.high-e.low>=ce(),de=(e,t)=>{if(Array.isArray(e))for(let n=0;n<e.length;n++)t(e[n]);else for(let n=e.low;n<=e.high;n++)t(n)},fe=2**27,j=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`&&e.kind!==`Operator`,pe=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),me=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),M=e=>typeof e==`object`&&e.kind===`ModelValue`,he=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),ge=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:e.kind===`Operator`?`operator`:j(e)?`set`:`function`,_e=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,ve=(e,t)=>(e.writtenKeys=t,e),ye=e=>(e.hash!==0||e.fingerprint!==0?void 0:e.writtenKeys)??e.domain,be=e=>{let t=ye(e),n=e.domain,r=e.range;if(t===n)return n.map((e,t)=>[e,r[t]]);let i=/* @__PURE__ */ new Map;for(let e=0;e<n.length;e++){let t=n[e];i.has(t)||i.set(t,e)}return t.map(e=>[e,r[i.get(e)??-1]])},xe=e=>e.domain.every(e=>typeof e==`number`)?e.domain.map((t,n)=>[t,e.range[n]]):be(e),Se=(e,t,n,r)=>{let i=Array(t.length);for(let e=0;e<t.length;e++)i[e]=n[t[e]];return ve(wr(e,i),r)},Ce=e=>{typeof e==`object`&&e.kind===`Function`&&(e.writtenKeys=void 0)},N=e=>{for(let t=0;t<e.length;t++)if(typeof e[t]!=`string`)return!1;return!0},we=e=>typeof e!=`object`||e.kind===`ModelValue`,Te=e=>{if(e.length===0)return!1;let t=e[e.length-1];return typeof t==`object`&&t.kind!==`ModelValue`},Ee=(e,t)=>e.length>0&&t.length>0&&N(e)!==N(t),De=(e,t)=>{if(e.writtenKeys!==void 0&&(e.writtenKeys=void 0),t.writtenKeys!==void 0&&(t.writtenKeys=void 0),(e.costModel!==void 0||t.costModel!==void 0)&&e.functionClass!==t.functionClass)return bn(e,t);let n=e.domain,r=t.domain;if(n.length!==r.length)return Ee(n,r)?bn(e,t):n.length-r.length;if(n!==r)for(let i=0;i<n.length;i++){let a=n[i],o=r[i],s=ht(a,o);if(s!==0)return M(a)===M(o)?s:bn(e,t)}else if(Te(n))for(let e=0;e<n.length;e++){let t=n[e];typeof t!=`object`||(t.kind===`Function`||t.kind===`Set`)&&t.flags&4||mt(t,!1)}let i=e.range,a=t.range;if(i===a)return 0;for(let e=0;e<i.length;e++){let t=i[e],n=a[e],r=typeof t==`number`&&typeof n==`number`?t-n:ht(t,n);if(r!==0)return r}return 0},Oe=(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=ht(n[e],r[e]);if(t!==0)return t}return 0},ke=(e,t)=>{let n=e.elements,r=t.elements;if(n.length!==r.length)return!1;if(n===r)return!0;for(let e=0;e<n.length;e++){let t=n[e],i=r[e];if(!(typeof t==`object`&&t.kind!==`Function`?Bt(t,i):ht(t,i)===0))return!1}return!0},Ae=e=>M(e)?e.type:void 0,je=(e,t,n)=>{let r=sn(n);return M(e)&&M(t)?`Attempted to ${r} the differently-typed model values ${_(U(e))} and ${_(U(t))}`:Ae(e)===void 0?`Attempted to ${r} the typed model value ${_(U(t))} and the non-model value\n${_(U(e))}`:`Attempted to ${r}${n?``:` the`} typed model value ${_(U(e))} and non-model value\n${_(U(t))}`},Me=(e,t,n)=>{let r=Ae(e),i=Ae(t);if((r!==void 0||i!==void 0)&&(!M(e)||!M(t)||r!==void 0&&i!==void 0&&r!==i))throw P(je,e,t,n)},Ne=()=>({ranks:Object.create(null),texts:[],searchRank:void 0,unorderedString:void 0}),Pe=Ne(),Fe=e=>{Object.assign(Pe,Ne()),gt.clear(),_t=!1,Mt=!1;for(let t of e)Xe(t)},Ie=()=>{Pe.searchRank=Pe.texts.length,Pe.unorderedString=void 0},Le=e=>{let t=Pe.texts;for(let n=e;n<t.length;n++)delete Pe.ranks[t[n]];t.length=e},Re=()=>Pe.unorderedString;let ze=!1;const Be={isExpanded:!0,isViewPrinted:!1},Ve=()=>Be.isExpanded,He=e=>{ze=e.version===`1.7.4`,oe=e.maxSetSize??ae,Be.isExpanded=e.isLazyValueExpanded??!0,Be.isViewPrinted=e.isViewPrinted??!1},Ue=/* @__PURE__ */ new WeakMap,We=(e,t)=>(Be.isViewPrinted&&Ue.set(e,t),e),Ge=/* @__PURE__ */ new WeakMap,Ke=/* @__PURE__ */ new WeakMap,qe=(e,t)=>(Ge.set(e,t),e),Je=(e,t)=>(Ke.set(e,t),e),Ye=(e,t)=>Ke.has(e)?t:Ke.get(t)?.()??t,Xe=e=>(Pe.ranks[e]===void 0&&(Pe.ranks[e]=Pe.texts.length,Pe.texts.push(e)),e),Ze=e=>Pe.ranks[Xe(e)],Qe=()=>Pe.texts.length,$e=(e=0)=>Pe.texts.slice(e),et=(e,t)=>{if(e===t)return 0;let n=Pe.ranks,r=n[e],i=n[t],a=Pe.searchRank;return a!==void 0&&(r===void 0||r>=a)&&(i===void 0||i>=a)&&(Pe.unorderedString??=e),r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},tt=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),nt=(e,t)=>(tt(e)||tt(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`);let rt=`none`;const it=()=>{if(rt===`stopping`)throw new t.Z},at=(e,...t)=>rt===`none`?e(...t):()=>e(...t),P=(e,...n)=>new t.D(at(e,...n)),ot=(e,t)=>P(()=>tt(e)?`Attempted to compare overridden value ${_(U(e))} with non-overridden value:\n${_(U(t))}`:`Attempted to compare ${ge(e)} ${U(e)} with ${ge(t)} ${U(t)}`),st=(e,t,n)=>`Attempted to ${e} the set ${_(U(L(t)))} with the value:\n${_(U(n))}`,ct=(e,t)=>`Attempted to compare ${_(U(e))} with the value\n${_(U(t))}`,lt=(e,n,r)=>{if(!tt(e))throw P(st,r,e,n);if(!tt(n))throw ot(e,n);let i=e.kind===`InfiniteSet`?e.name:void 0,a=n.kind===`InfiniteSet`?n.name:void 0;if(i!==void 0&&i===a)return 0;if(i===`Nat`&&a===`Int`||i===`Int`&&a===`Nat`)return i===`Nat`?-1:1;throw new t.H(at(ct,e,n))},ut={kind:`InfiniteSet`,name:`Any`},dt=e=>`Attempted to compare ANY with the value\n${_(U(e))}`,ft=e=>new t.H(at(dt,e)),pt=e=>e.fingerprint!==0||e.hash!==0&&e.hash!==Ps,mt=(e,t)=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:return!0;case`Interval`:return Wa(e.low,e.high),!0;case`SequenceSet`:return mt(e.base,!1);case`InfiniteSet`:if(e===ut)throw ft(e);return!0;case`LazyFunction`:return mt(V(e),t);case`Function`:{if(e.flags&4||pt(e))return!0;e.writtenKeys!==void 0&&(e.writtenKeys=void 0);let n=e.domain,r=e.range,i=!0;for(let e=0;e<n.length;e++)i=mt(n[e],t)&&i;for(let e=0;e<r.length;e++)i=mt(r[e],t)&&i;return i&&(e.flags|=4),i}case`Set`:{if(e.flags&4||pt(e))return!0;e.flags|=1;let n=e.elements,r=!0;for(let e=0;e<n.length;e++)r=mt(n[e],t)&&r;return r&&(e.flags|=4),r}case`Subset`:return mt(e.base,t);case`FunctionSet`:{if(!t)break;let n=e.cost?.charges,r=ta(n,e.domain),i=ta(n,e.domain);if(r||i)return!1;let a=ta(n,e.range),o=ta(n,e.range);return a||o||(mt(e.domain,t),mt(e.range,t)),!1}case`RecordSet`:case`ProductSet`:{if(!t)break;let n=e.cost?.charges,r=ta(n,e),i=ta(n,e);if(r||i)return!1;let a=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<a.length;e++)mt(a[e],t);return!1}}let n=pi(e);return mt(n&&(qn||n.kind===`SetOperation`||n.kind===`Union`)?gi(n,!0,L):L(e),t),zt(e),!1},ht=(e,t)=>{if(e===t)return mt(e,!1),0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return De(e,t);if(n===`Set`&&r===`Set`)return Oe(e,t);if(n===`Interval`&&r===`Interval`){let n=Wa(e.low,e.high),r=Wa(t.low,t.high);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&&Me(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Me(e,t,!1),n===`ModelValue`?-1:1;if(e===ut||t===ut)throw ft(e===ut?t:e);if(n===`SequenceSet`&&r===`SequenceSet`||n===`Subset`&&r===`Subset`)return Un(e.base,t.base);if(j(e)&&j(t)&&nt(e,t))return lt(e,t,`compare`);let i=j(e);if(i!==j(t))throw ot(e,t);if(n===`Interval`&&r===`Set`){let n=R(e)-t.elements.length;if(n!==0)return n}if(n===`Set`&&r===`Interval`){let n=e.elements.length-R(t);if(n!==0)return n}if(i){let i=n===`Set`?void 0:pi(e),a=r===`Set`?void 0:pi(t),o=i?gi(i,!0,L):L(e);return zt(e),Oe(o,a?gi(a,!1,fi):fi(t))}return De(V(e),V(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return et(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Me(e,t,!1),M(e))return-1;if(M(t))return 1;throw ot(e,t)},gt=/* @__PURE__ */ new Map;let _t=!1;const vt=()=>_t,yt=32768,bt=e=>{let n=gt.get(e);if(n)return n;if(gt.size===yt)throw new t.O(`TLC supports at most ${yt} model values, but model value ${e} exceeds this limit.`);let r=e.length>2&&e[1]===`_`?e[0]:void 0;r!==void 0&&(_t=!0);let i={kind:`ModelValue`,name:e,type:r,rank:Ze(e),hash:Ds(Os(ks(e),109)),fingerprint:Ws(Gs(e)^60)};return gt.set(e,i),i},xt=()=>[...gt.values()];var St=class{kind=`Set`;elements;writtenElements=void 0;hash=0;fingerprint=0;flags=0;constructor(e){this.elements=e}};const Ct=e=>new St(e),wt=e=>{let t=Ct(e);return t.flags=1,t};var Tt=class{kind=`Function`;domain;range;hash=0;fingerprint=0;writtenKeys=void 0;functionClass=void 0;flags=0;constructor(e,t){this.domain=e,this.range=t}};const Et=(e,t)=>new Tt(e,t),Dt=(e,t)=>(t!==void 0&&(e.functionClass=t),e),Ot=e=>typeof e==`object`?e.kind===`LazyFunction`?`lambda`:e.kind===`Function`?e.functionClass:void 0:void 0,kt=e=>typeof e==`object`&&e.kind===`LazyFunction`&&e.isApplicationObserved&&e.enumerated===void 0,At=(e,t)=>e.functionClass===`tuple`&&kt(t),jt=e=>y(e)&&e.isCached===!0;let Mt=!1;const Nt=()=>(Mt?2:0)|(_t?4:0),Pt=e=>{Mt||=!!(e&2),_t||=!!(e&4)},Ft=()=>gt.size,It=e=>(Mt=!0,e),Lt=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),Rt=e=>Mt&&typeof e==`object`&&y(e)&&Lt.has(e.kind),zt=e=>{Rt(e)&&(e.isCached=!0)},Bt=(e,t)=>{if(e===t)return mt(e,!0),!0;if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Me(e,t,!0),ht(e,t)===0);if(e.kind===`Function`&&t.kind===`Function`)return De(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return ke(e,t);if(e.kind===`Interval`&&t.kind===`Interval`)return Wa(e.low,e.high)===0?Wa(t.low,t.high)===0:e.low===t.low&&e.high===t.high;if(e.kind===`Interval`&&t.kind===`Set`&&R(e)!==t.elements.length||e.kind===`Set`&&t.kind===`Interval`&&e.elements.length!==R(t))return!1;if(M(e)||M(t))return e.kind===`LazyFunction`&&V(e),Me(e,t,!0),M(e)&&M(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return Hn(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=e.cost?.charges??t.cost?.charges,r=ta(n,e.domain),i=ta(n,t.domain);if(r||i)return r===i;let a=ta(n,e.range),o=ta(n,t.range);return a||o?a===o:Hn(e.domain,t.domain)&&Hn(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){let n=e.cost?.charges??t.cost?.charges;if(ta(n,e))return ta(n,t);if(ta(n,t))return!1;let r=e=>e.names.map((t,n)=>[t,e.sets[n]]).sort((e,t)=>e[0]<t[0]?-1:1),i=r(t);return e.names.length===t.names.length&&r(e).every((e,t)=>e[0]===i[t][0]&&Hn(e[1],i[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`){let n=e.cost?.charges??t.cost?.charges;return ta(n,e)?ta(n,t):!ta(n,t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>Hn(e,t.factors[n]))}let n=j(e)&&j(t)&&!(Pr(e)&&Pr(t));if(n&&nt(e,t))return lt(e,t,`check equality of`)===0;if(n){if(!tt(e)){let n=L(e);if(zt(e),!tt(t))return Oe(n,L(t))===0}return ht(e,t)===0}return e.kind===`Function`&&At(e,t)?hn(e,t,!0)===0:ht(e,t)===0},Vt=(e,t,n)=>{let r=e[34+n],i=t[34+n],a=e[34+n+1]-r;if(a!==t[34+n+1]-i)return!1;for(let n=0;n<a;n++)if(e[r+n]!==t[i+n])return!1;return!0},Ht=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},Ut=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0},Wt=e=>{let t=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!r(e[n],t[n]))return!1;return!0},n=(e,t)=>{if(e.writtenSlots===void 0&&t.writtenSlots===void 0&&Ht(e.edges,t.edges)&&Ut(e.sources,t.sources))return!0;let n=e.edges[0]===t.edges[0]&&e.edges[1]===t.edges[1];for(let i=0;i<e.domain.length;i++){let a=e.records[i];if(a!==void 0&&a===t.records[i])continue;let o=te(e,i),s=te(t,i);if(o!==Cs&&s!==Cs&&o!==s||(!n||e.sources[i]!==t.sources[i]||T(e,i)||T(t,i)||!Vt(e.edges,t.edges,i))&&!r(ee(e,i),ee(t,i)))return!1}return!0},r=(i,a)=>i===a?!0:typeof i!=`object`||typeof a!=`object`?!1:i.kind===`Set`&&a.kind===`Set`?(i.hash===0||a.hash===0||i.hash===a.hash)&&t(i.elements,a.elements):i.kind===`Function`&&a.kind===`Function`?(!e||i.functionClass===a.functionClass)&&(i.hash===0||a.hash===0||i.hash===a.hash)&&t(i.domain,a.domain)&&(i.flags&a.flags&64&&w(i)&&w(a)?n(i,a):t(i.range,a.range)):i.kind===`Interval`&&a.kind===`Interval`?i.low>i.high?a.low>a.high:i.low===a.low&&i.high===a.high:i.kind===`LazyFunction`&&i.enumerated?r(i.enumerated,a):a.kind===`LazyFunction`&&a.enumerated?r(i,a.enumerated):Qs(i)===Qs(a);return r},Gt=Wt(!1),Kt=Wt(!0),qt=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},Jt=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:if(e.hash!==0)return!1;for(let t=0;t<e.elements.length;t++)if(Jt(e.elements[t]))return!0;return!1;case`Function`:if(e.hash!==0)return!1;for(let t=0;t<e.domain.length;t++)if(Jt(e.domain[t])||Jt(e.range[t]))return!0;return!1;case`ModelValue`:case`Interval`:case`InfiniteSet`:return!1;default:return!0}},Yt=(e=!1,t={count:0})=>{let n=/* @__PURE__ */ new Int32Array(2048),r=[],i=(e,t)=>{let r=n.length-1,i=Math.imul(e,2654435761)>>>0&r&-2;for(;n[i+1]!==0;)i=i+2&r;n[i]=e,n[i+1]=t+1},a=e=>{if(typeof e!=`object`||e.kind!==`Set`&&e.kind!==`Function`)return e;let o=Us(e),s=n.length-1;for(let t=Math.imul(o,2654435761)>>>0&s&-2;n[t+1]!==0;t=t+2&s){if(n[t]!==o)continue;let i=r[n[t+1]-1];if(i===e||Kt(i,e))return i}if(e.kind===`Set`?qt(e.elements,a):(qt(e.domain,a),qt(e.range,a)),r.push(e),t.count+=e.kind===`Set`?e.elements.length:e.domain.length+e.range.length,r.length*4>n.length){n=new Int32Array(n.length*2);for(let e=0;e<r.length;e++){let t=r[e];i(Us(t),e)}}else i(o,r.length-1);return e};return e?e=>{for(let t=0;t<e.length;t++)Jt(e[t])||(e[t]=a(e[t]));return e}:e=>{for(let t=0;t<e.length;t++)e[t]=a(e[t]);return e}},Xt=(e,t)=>t.length===0||Ot(e)===`tuple`?1:gs(t)?.low,Zt=e=>(e.kind===`Function`&&e.costModel!==void 0&&e.functionClass!==void 0&&(it(),e.costModel.secondary[e.costModel.node]+=e.range.length),V(e)),Qt=e=>e.costModel!==void 0&&e.functionClass===void 0&&gs(e.domain)===void 0?e.costModel:void 0,$t=e=>{if(e.kind!==`Function`)return;let t=Qt(e);t!==void 0&&(it(),t.secondary[t.node]+=e.range.length)},en=e=>{if(typeof e==`object`)return e.kind===`LazyFunction`?Vo(e)&&e.costModel.node>=0?e.costModel:void 0:e.kind===`Function`?Qt(e):void 0},tn=e=>{if(!me(e))return;let t=Zt(e);return{domain:t.domain,range:t.range,low:Xt(e,t.domain)}},nn=e=>{if(!me(e))return;Ce(e);let t=V(e);if(N(t.domain))return $t(e),t},rn=(e,t,n)=>(Me(t,e,n),1),an={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`}},on=(e,t,n)=>{let r=an[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${_(U(e))} with ${r.other}:\n${_(U(t))}`},sn=e=>e?`check equality of`:`compare`,cn=(e,t,n)=>`Attempted to ${sn(e)} operator ${_(U(t))} with value:\n${_(U(n))}`,ln=(e,t,n)=>`Attempted to ${sn(e)} the function ${_(U(t))} with the value:\n${_(U(n))}`,un=(e,t,n)=>`Attempted to compare ${e?`an `:``}integer with non-integer${e||t?`:`:``}\n${_(U(n))}.`,dn=(e,t,n)=>`Attempted to ${sn(e)} record:\n${_(U(t))}\nwith non-record\n${_(U(n))}`,fn=(e,t,n)=>`Attempted to ${sn(e)} the set ${_(U(t))} with the value:\n${_(U(n))}`,pn=(e,t,n,r)=>{let i=tn(n);if(!i){if(M(n))return rn(n,t,r);throw P(ln,r,t,n)}if(Ce(t),Ce(n),e.range.length!==i.range.length)return e.range.length-i.range.length;let a=()=>mn(e.range,i.range,r);if(e.low!==void 0&&e.range.length===0)return 0;if(e.low!==void 0&&i.low!==void 0)return e.low===i.low?a():e.low-i.low;let o=e.low??i.low;if(o===void 0)return mn(e.domain,i.domain,r)||a();let s=e.low===void 0?e.domain:i.domain;for(let t=0;t<s.length;t++){let n=s[t];if(typeof n!=`number`)throw P(un,r,e.low!==void 0,n);let i=e.low===void 0?n-(o+t):o+t-n;if(i!==0)return i}return a()},mn=(e,t,n)=>{let r=z.sets;for(let i=0;i<e.length;i++){r?.push(e[i]);let a=yn(e[i],t[i],n);if(r?.pop(),a!==0)return a}return 0},hn=(e,t,n)=>{let r=V(e);if(Ot(e)===`tuple`){let i=me(t)?$a(t):void 0;return i?r.range.length-i.length||mn(r.range,i,n):pn({...Zt(e),low:1},e,t,n)}if(Ot(e)===`record`){let i=nn(t);if(!i){if(M(t))return rn(t,e,n);throw P(dn,n,e,t)}return Ce(e),r.domain.length-i.domain.length||mn(r.domain,i.domain,n)||mn(r.range,i.range,n)}return pn({...r,low:Xt(e,r.domain)},e,t,n)},gn=(e,t)=>tt(e)||tt(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),_n=(e,t)=>{let n=pi(t),r=he(t)?t:n?gi(n,!1,n.kind===`Subset`?L:fi):fi(t);return{elements:L(e).elements,otherElements:L(r).elements}},vn=(e,t,n)=>{if(tt(e)&&M(t))return 1;if(!n&&(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)){let n=pi(e);return vn(n?gi(n,!0,hi):hi(e),t,!1)}if(gn(e,t))return n?+!Bt(e,t):ht(e,t);if(!he(e)){let r=pi(e),i=r?gi(r,!0,hi):hi(e);return vn(i,t,n)}if(!j(t)){if(M(t))return rn(t,e,n);throw P(fn,n,e,t)}let r=_n(e,t);return r.elements.length-r.otherElements.length||mn(r.elements,r.otherElements,n)},yn=(e,t,n)=>{if(typeof e!=`object`){if(typeof t==typeof e)return n?e===t?0:1:ht(e,t);if(M(t))return rn(t,e,n);throw P(on,e,t,n)}if(e.kind===`ModelValue`)return e.type!==void 0&&Me(e,t,n),M(t)?n?e.name===t.name?0:1:e.rank-t.rank:-1;if(e.kind===`Operator`)throw P(cn,n,e,t);return me(e)?hn(e,t,n):vn(e,t,n)},bn=(e,t)=>yn(e,t,!1),xn=(e,t)=>yn(e,t,!0)===0,Sn=e=>{let t=[];for(let n of e){let e=An(n,t);e.isFound||t.splice(e.index,0,n)}return t},Cn=(e,t)=>Ct(t?e:Sn(e)),wn=(e,t)=>{let n=z.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},Tn=(e,t)=>{for(let n=1;n<e.length;n++){let r=e[0],i=e[n];if(wn(r,()=>bn(r,i))>0){e[0]=i,e[n]=r;let a=t[0];t[0]=t[n],t[n]=a}}for(let n=2;n<e.length;n++){let r=e[n],i=t[n],a=n;for(;a>0&&wn(r,()=>bn(r,e[a-1]))<0;)e[a]=e[a-1],t[a]=t[a-1],a--;e[a]=r,t[a]=i}},En=(e,t)=>(Tn(e,t),Et(e,t)),Dn=e=>typeof e==`object`&&e.kind===`MixedSet`,On=e=>Dn(e)||typeof e==`object`&&e.kind===`ProductSet`&&e.factors.some(Dn),kn=(e,t,n)=>Dn(e)?En([...t],n):Et(t,n),An=(e,t)=>{let n=0,r=t.length;for(;n<r;){let i=n+(r-n>>1),a=wn(e,()=>bn(e,t[i]));if(a===0)return{index:i,isFound:!0};a<0?r=i:n=i+1}return{index:n,isFound:!1}},jn=(e,t)=>t.some(t=>wn(t,()=>xn(t,e))),Mn=e=>e.kind===`MixedSet`?e.enumerated?.elements??e.elements:re(e)?e.elements:e.writtenElements??e.elements,Nn=1e3,Pn=(e,t,n)=>{if(typeof e!=`object`)return n;if(t===Nn){let t=n??[];return t.push(e),t}let r=n;if(e.kind===`Set`&&!(e.flags&8)){e.flags|=9;for(let n=0;n<e.elements.length;n++)r=Pn(e.elements[n],t+1,r)}if(e.kind===`Function`&&!(e.flags&8)){e.flags|=8,e.writtenKeys=void 0;for(let n=0;n<e.domain.length;n++)r=Pn(e.domain[n],t+1,r),r=Pn(e.range[n],t+1,r)}return r},Fn=e=>{let t=Pn(e,0,void 0);for(let e=t?.pop();e!==void 0;e=t?.pop())Pn(e,0,t)},In=(e,t,n,r)=>{if(typeof e!=`object`)return n;if(t===Nn){let t=n??[];return t.push(e),t}let i=n;switch(e.kind){case`Set`:if(e.flags&128)return i;r.push(e),e.flags|=1;for(let n=0;n<e.elements.length;n++){let a=e.elements[n];we(a)||(i=In(a,t+1,i,r))}return i;case`MixedSet`:for(let n=0;n<e.elements.length;n++){let a=e.elements[n];we(a)||(i=In(a,t+1,i,r))}return L(e),i;case`Function`:if(e.flags&128)return i;r.push(e),e.writtenKeys=void 0;for(let n=0;n<e.domain.length;n++){let a=e.domain[n],o=e.range[n];we(a)||Fn(a),we(o)||(i=In(o,t+1,i,r))}return i;case`LazyFunction`:{if(e.enumerated)return In(e.enumerated,t+1,i,r);let n=Wo(e);for(let e=n.length-1;e>=0;e--){let a=n[e];i=In(a.newValue,t+1,i,r);for(let e=0;e<a.path.length;e++)i=In(a.path[e],t+1,i,r)}return In(e.domain,t+1,i,r)}case`FilteredSet`:case`Subset`:case`Union`:return In(e.base,t+1,i,r);case`SetOperation`:return i=In(e.left,t+1,i,r),In(e.right,t+1,i,r);case`FunctionSet`:return i=In(e.domain,t+1,i,r),In(e.range,t+1,i,r);case`RecordSet`:case`ProductSet`:{let n=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<n.length;e++)i=In(n[e],t+1,i,r);return i}default:return i}},Ln=e=>{let t=[],n=In(e,0,void 0,t);for(let e=n?.pop();e!==void 0;e=n?.pop())In(e,0,n,t);for(let e=0;e<t.length;e++)t[e].flags|=128},Rn=e=>{if(typeof e!=`object`||jt(e))return;if(e.kind===`Set`){e.flags|=1;return}if(e.kind===`MixedSet`){L(e);return}let t=z.sets;switch(t?.push(e),e.kind){case`FilteredSet`:case`Subset`:Rn(e.base);break;case`SetOperation`:e.operator!==`\\cup`&&(Rn(e.left),Rn(e.right));break;case`FunctionSet`:Rn(e.domain),Rn(e.range);break;case`RecordSet`:for(let t of e.sets)Rn(t);break;case`ProductSet`:for(let t of e.factors)Rn(t)}t?.pop()},zn=e=>typeof e==`object`&&y(e)&&e.enumerated===void 0,Bn=(e,t)=>typeof e==`object`&&(e.kind===`Function`&&At(e,t)||j(e)&&!M(t)&&(gn(e,t)||j(t)&&(zn(e)?e.kind!==`MixedSet`:zn(t)))),Vn=(e,t)=>typeof e!=`object`&&typeof e==typeof t?e===t:ao(Bt,xn,e,t,Bn),Hn=(e,t)=>{let n=z.sets;if(n===void 0)return Vn(e,t);n.push(e);let r=Vn(e,t);return n.pop(),r},Un=(e,t)=>{let n=z.sets;if(n===void 0)return bn(e,t);n.push(e);let r=bn(e,t);return n.pop(),r},Wn=e=>{for(let t=1;t<e.length;t++)if(ht(e[t],e[t-1])<=0)return!1;return!0},Gn=e=>{for(let t=0;t<e.length;t++){let n=e[t],r=t>0?e[t-1]:void 0;if(typeof n!=`number`||typeof r==`number`&&r>=n)return!1}return!0},Kn=e=>{if(e.length<2||Wn(e))return Ct(e);let t=[...e].sort(ht);for(let t=1;t<e.length;t++)zt(e[t]);let n=[t[0]];for(let e=1;e<t.length;e++)ht(n[n.length-1],t[e])!==0&&n.push(t[e]);return Ct(n)};let qn=!1;const Jn=e=>{if(Gn(e))return Ct(e);let t=qn;qn=!0;try{let t=ao(Kn,e=>({kind:`MixedSet`,elements:e}),e,void 0);return t.kind===`Set`&&t.elements!==e&&(t.writtenElements=e),t}finally{qn=t}},Yn=Ct([]),Xn=(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&&ht(r[a],t)<0;)a++;a<r.length&&ht(r[a],t)===0||i.push(t)}return i.length===n.length?e:Ct(i)},Zn=(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&&ht(r[a],t)<0;)a++;a<r.length&&ht(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Ct(i)},Qn=(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=ht(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=Ct(i);if(e.hash!==0&&e.hash!==Ps){let t=e.hash,n=0;for(;n<a.length;n++){let e=Us(a[n]);if(e===Ps)break;t=t+Ms(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+Ks(a[e])|0;c.fingerprint=t}return c},$n=e=>{let t=e.length<2?e:[...e].sort((e,t)=>ht(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&ht(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Et(n,r)},er=e=>typeof e!=`object`||e.kind===`ModelValue`&&e.type===void 0||e.kind===`Function`&&(!!(e.flags&4)||e.writtenKeys===void 0&&e.domain.every(tr)&&e.range.every(er)),tr=e=>!M(e)&&er(e),nr=e=>e.flags&32?!0:e.domain.every(er)?(e.flags|=32,!0):!1,rr=(e,t,n,r)=>{let i=n.length<=e.length,a=i?e:n,o=i?t:r,s=i?n:e,c=i?r:t,l=[],u=[],d=0,f=e=>{for(;d<e;d++)l.push(a[d]),u.push(o[d])};for(let e=0;e<s.length;e++){let t=s[e],n=d,r=a.length;for(;n<r;){let e=n+r>>1,i=ht(a[e],t);if(i===0)return;i<0?n=e+1:r=e}f(n),l.push(t),u.push(c[e])}return f(a.length),[l,u]},ir=(e,t)=>{if(e.domain.length+t.domain.length>ce()){let n=be(e),r=[];for(let e of n)A(r,e);for(let e of be(t))n.some(t=>Vn(e[0],t[0]))||A(r,e);return pr(r)}let n=ye(e),r=ye(t),i=ar(e,t)??new Set(r.filter(e=>n.some(t=>Vn(e,t)))),a=[...n,...r.filter(e=>!i.has(e))],o=or(e,t,i);if(!o){let n=be(e),r=be(t).filter(e=>!i.has(e[0]));return pr([...n,...r])}let s=Et(o[0],o[1]);return s.flags|=32,a.every((e,t)=>e===s.domain[t])?s:ve(s,a)},ar=(e,n)=>{if(!nr(e)||!nr(n))return;let r=/* @__PURE__ */ new Set;try{for(let t of e.domain){let e=Ja(n.domain,t);e!==-1&&r.add(n.domain[e])}}catch(e){if(e instanceof t.D)return;throw e}return r},or=(e,n,r)=>{let i=r.size===0?n.domain:n.domain.filter(e=>!r.has(e)),a=r.size===0?n.range:n.range.filter((e,t)=>!r.has(n.domain[t]));if(nr(e)&&(r.size===0?nr(n):i.every(er)))try{return rr(e.domain,e.range,i,a)}catch(e){if(e instanceof t.D)return;throw e}},sr=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][0];return t},cr=(e,t)=>{let n=e.domain;if(n.length!==t.length)return e;for(let r=0;r<t.length;r++)if(t[r][0]!==n[r])return ve(e,sr(t));return e},lr=e=>cr($n(e),e),ur=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][1];return t},dr=e=>Et(sr(e),ur(e)),fr=e=>cr(En(sr(e),ur(e)),e),pr=e=>ao(lr,fr,e,void 0);var mr=class extends Array{static get[Symbol.species](){return Array}interval;constructor(e){super(Math.max(e.high-e.low+1,0)),this.interval=e;for(let t=0;t<this.length;t++)this[t]=e.low+t}};const hr=[],gr=e=>{let t=hr[e];if(t)return t;let n=new mr({kind:`Interval`,low:1,high:e});return e<=1024&&(hr[e]=n),n},_r=e=>e.low===1&&e.high>=0?gr(e.high):new mr(e),vr=e=>Reflect.get(e,`kind`)===`IntervalElements`,yr=e=>{let t=/* @__PURE__ */ new Set,n=e=>{if(typeof e!=`object`||!e)return e;if(vr(e))return _r({kind:`Interval`,low:e.low,high:e.high});if(t.has(e))return e;if(t.add(e),Array.isArray(e)){for(let t=0;t<e.length;t++)e[t]=n(e[t]);return e}for(let t of Object.keys(e))Reflect.set(e,t,n(Reflect.get(e,t)));let r=Reflect.get(e,`kind`);return(r===`Union`||r===`SetOperation`)&&(Mt=!0),e};for(let t of e)n(t);return[...e]},br=e=>{if(R(e)>fe)throw new t.U;if(e.low===1&&e.high>=1)return gr(e.high);let n=[];for(let t=e.low;t<=e.high;t++)n.push(t);return n},xr=e=>e instanceof mr,Sr=(e,t=!0)=>{let n=t?L(e).elements:ri(e);return xr(n)&&(typeof e!=`object`||e.kind!==`Interval`)?[...n]:n},F=e=>Dt(Et(gr(e.length),e),`tuple`),Cr=e=>Dt($n(e),`record`),wr=(e,t)=>Dt(Et(e,t),`record`),Tr=(e,t)=>(t!==void 0&&(e.costModel=t),e),Er=e=>e?.node===void 0||e.charges===void 0?void 0:e.charges.costModels[e.node],Dr=(e,t)=>{let n=Er(t);if(n===void 0)return e;for(let t=0;t<e.length;t++)e[t].costModel=n;return e},I=e=>j(e)&&!tt(e),Or=e=>`UNION(${U(e.base)})`,kr=e=>`Attempted to enumerate the nonenumerable set:\n${Or(e)}`,Ar=(e,t=e=>L(e).elements)=>{if(!I(e.base))throw P(kr,e);return t(e.base)},jr=e=>typeof e==`object`&&e.kind===`Set`?e.elements:ka(e),Mr=(e,t,n)=>t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${_(U(e))}\nwhen enumerating:\n${_(Or(n))}`,Nr=(e,t,n)=>{if(I(e))return e;throw P(Mr,e,t,n)},Pr=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 Pr(e.base);case`FunctionSet`:return Pr(e.domain)&&Pr(e.range)||Fr(e.domain)===!0||Fr(e)===!0;case`RecordSet`:return e.sets.every(Pr)||Fr(e)===!0;case`ProductSet`:return e.factors.every(Pr)||Fr(e)===!0;case`Union`:return Pr(e.base)&&(he(e.base)?Mn(e.base):ka(e.base)).every(Pr);case`SetOperation`:return e.operator===`\\cup`?Pr(e.left)&&Pr(e.right):e.operator===`\\cap`?Pr(e.left)||Pr(e.right):Pr(e.left);default:return!1}},Fr=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=Fr(e.domain);return t===void 0?void 0:!t&&Fr(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Fr(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return Pr(e)?L(e).elements.length===0:void 0;default:return}},Ir=(e,n)=>{let r=e.reduce((e,t)=>e*t.length,1);if(n&&r>ce())throw z.sets?.pop(),new t.q(le());if(r>fe)throw new t.U;let i=[],a=e.map(()=>0);for(let t=0;t<r;t++){i.push(e.map((e,t)=>e[a[t]]));for(let t=e.length-1;t>=0&&(a[t]++,!(a[t]<e[t].length));t--)a[t]=0}return i},Lr=(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},Rr=e=>{if(typeof e!=`object`||e.kind!==`Subset`||tt(e.base))return;let t=z.sets;t?.push(e);let n=L(e.base).elements;if(t?.pop(),n.length<=20)return;let r=e.cost?.node,i=-1,a=[0],o=e=>{for(e<=i&&(i=-1);i<e;)i===-1?a=[]:Lr(a,n.length)||(a=Array.from({length:a.length+1},(e,t)=>t)),i++;let t=Ct(a.map(e=>n[e]));return r===void 0?t:{...t,costNode:r}},s=2**n.length,c=e=>typeof e==`string`&&/^\d+$/.test(e)&&Number(e)<s;return new Proxy([],{get:(e,t,n)=>t===`length`?s:c(t)?o(Number(t)):Reflect.get(e,t,n),has:(e,t)=>c(t)||Reflect.has(e,t)})},zr=(e,t,n)=>{for(let r=0;r<=e.length;r++){let i=Array.from({length:r},(e,t)=>t);do{let a=Array(r);for(let t=0;t<r;t++)a[t]=e[i[t]];let o=Ct(a);if(t(n===void 0?o:{...o,costNode:n}))return!0}while(Lr(i,e.length))}return!1},Br=(e,t)=>{let n=[];return zr(e,e=>(n.push(e),!1),t),n},Vr=e=>`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${_(U(e.base))}`,Hr=e=>{if(R(e.base)===0)return[];if(!j(e.base))throw P(Vr,e);return L(e.base).elements},Ur=(e,t)=>`Attempted to enumerate a set of the form [D -> R],but the ${e}:\n${_(U(t))}\ncannot be enumerated.`,Wr=(e,t)=>e.kind===`RecordSet`?`Attempted to enumerate a set of the form [l1 : v1, ..., ln : vn],\nbut can't enumerate the value of the \`${e.names[t]}' field:\n${_(U(e.sets[t]))}`:`Attempted to enumerate a set of the form s1 \\X s2 ... \\X sn,\nbut can't enumerate s${t}:\n${_(U(e.factors[t]))}`,Gr=(e,t)=>{let n=e.kind===`RecordSet`?e.sets:e.factors,r=[];for(let i=0;i<n.length;i++){let a=n[i];if(tt(a))throw P(Wr,e,i);let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},Kr=e=>`Attempted to enumerate S \\cap T when neither S:\n${_(U(e.left))}\nnor T:\n${_(U(e.right))}\nis enumerable`,qr=e=>`Attempted to enumerate S \\ T when S:\n${_(U(e.left))}\nis not enumerable.`,Jr=(e,t)=>{if(e.operator===`\\cap`&&!I(e.left)&&!I(e.right))throw P(Kr,e);if(e.operator===`\\`&&!I(e.left))throw P(qr,e);if(e.operator===`\\cup`)return L(Jn(Ca(e,t))).elements;let n=e.operator===`\\`||I(e.left),r=n?e.left:e.right,i=n?e.right:e.left,a=[],o=t=>(B(t,i)===(e.operator===`\\cap`)&&A(a,t),!1);return typeof r==`object`&&r.kind===`Interval`?de(r,o):Ea(r,t??xa(r),o),L(Jn(a)).elements},Yr=e=>{if(typeof e!=`object`||jt(e))return!0;switch(e.kind){case`Set`:case`MixedSet`:return re(e);case`Interval`:return!0;case`FilteredSet`:return Yr(e.base);case`FunctionSet`:return Yr(e.domain)&&Yr(e.range);case`RecordSet`:return e.sets.every(Yr);case`ProductSet`:return e.factors.every(Yr);case`Operator`:throw new t.D(e.javaClass===`MethodValue`?`It is a TLC bug: Attempted to normalize an operator.`:`Should not normalize an operator.`);default:return!1}},Xr=(e,t)=>{if(typeof e!=`object`||e.kind===`ModelValue`)return!1;let n=[e];for(let e=n.pop();e!==void 0;e=n.pop())if(typeof e==`object`)switch(e.kind){case`Set`:for(let t=0;t<e.elements.length;t++)n.push(e.elements[t]);break;case`Function`:for(let t=0;t<e.domain.length;t++)n.push(e.domain[t],e.range[t]);break;case`InfiniteSet`:if(t&&e===ut)return!0;break;case`ModelValue`:case`Interval`:break;default:return!0}return!1},Zr=e=>Xr(e,!1),Qr=e=>{for(let t=0;t<e.length;t++)if(Xr(e[t],!0))return!0;return!1},$r=(e,t)=>{for(let n=0;n<e.length;n++)if(ei(e[n],t))return!0;return!1},ei=(e,t)=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:return Qr(e.elements);case`MixedSet`:return!0;case`FilteredSet`:case`Subset`:case`Union`:return ei(e.base,t);case`SetOperation`:return ei(e.left,t)||ei(e.right,t);case`FunctionSet`:return ei(e.domain,t)||ei(e.range,t);case`RecordSet`:return $r(e.sets,t);case`ProductSet`:return $r(e.factors,t);case`Operator`:return t;default:return!1}},ti=(e,t)=>!ei(e,t)||Yr(e),ni=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`ProductSet`:case`FunctionSet`:case`RecordSet`:return ti(e,!0);case`FilteredSet`:return Yr(e),!0;case`SetOperation`:return e.operator!==`\\cup`&&Yr(e.left)&&e.operator===`\\cap`&&Yr(e.right),!0;case`MixedSet`:case`Union`:case`Subset`:return!0;default:return!1}},ri=e=>{if(typeof e!=`object`||e.kind!==`FunctionSet`&&e.kind!==`RecordSet`&&e.kind!==`ProductSet`&&e.kind!==`FilteredSet`||e.enumerated)return L(e).elements;let t=ni(e),n=z.sets?ba(e,!1):void 0;return ii(e,n,t)},ii=(e,t,n)=>{let r=qn;qn=!1;let i;try{i=li(e,!1,void 0,t)}finally{qn=r}let a=Cn(i,n);return i.length<=ce()&&(e.enumerated=a),a.elements},ai=e=>{let t=Rr(e);return t!==void 0&&t.length>ce()?t:ri(e)},oi=e=>`Expected a set but found ${U(e)}`,si=e=>`Attempted to enumerate { x \\in S : p(x) } when S:\n${_(U(e.base))}\nis not enumerable`,ci=e=>`Attempted to enumerate the non-enumerable set ${U(e)}`,li=(e,n=!0,r=n?ai:ri,i)=>{if(typeof e!=`object`)throw P(oi,e);let a=Oi(e);if(a){let e=ga(ha(a,i),n);return Ma(a)?Sn(e):e}switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return Sn(e.elements);case`Interval`:if(R(e)>fe)throw new t.U;return _r(e);case`Subset`:{let n=Hr(e);if(n.length>30)throw P(Ba,e);if(2**n.length>fe)throw new t.U;return Br(n,e.cost?.node)}case`FunctionSet`:{if(!ze&&La(e))return[];if(tt(e.domain))throw P(Ur,`domain D`,e.domain);let t=Sr(e.domain);if((t.length>0||ze)&&tt(e.range))throw P(Ur,`range R`,e.range);let i=t.length===0?[]:r(e.range);return Dr(Ir(t.map(()=>i),n).map(e=>Et(t,e)),e.cost)}case`RecordSet`:{if(!ze&&La(e))return[];let t=Gr(e,r);return Dr(Ir(t,n).map(t=>wr(e.names,t)),e.cost)}case`ProductSet`:{if(!ze&&La(e))return[];let t=Gr(e,r);return Dr(Ir(t,n).map(F),e.cost)}case`FilteredSet`:{if(!j(e.base)||tt(e.base))throw P(si,e);let t=e.startPass?.(!0).test??Ai(e),r=[];return Ea(e.base,i??xa(e.base),e=>(t(e)&&(n?A(r,e):r.push(e)),!1)),L(Jn(r)).elements}case`Union`:{let n=[];for(let[r,a]of(i?Na(e,i):Ar(e,jr)).entries()){let o=Nr(a,r,e);if(ue(o))throw new t.q(le());for(let t of i&&r===0&&he(e.base)?Oa(o,i):ka(o))A(n,t)}return L(Jn(n)).elements}case`SetOperation`:return Jr(e,i);case`InfiniteSet`:case`SequenceSet`:throw P(ci,e);default:throw P(oi,e)}},L=(e,t)=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Ct(li(e));let n=typeof e==`object`&&y(e)?e:void 0;return n?.enumerated?n.enumerated:ui(e,n,!1,t)},ui=(e,n,r,i)=>{if(qn&&n!==void 0&&Si(n))throw new t.D(`The set literal holds a filter`);let a=z.sets;r||a?.push(e);let o=i??ni(e),s=qn;qn=s&&n?.kind===`MixedSet`;let c;try{c=r?li(e,!0,void 0,ba(e,!1)):li(e)}finally{qn=s}r||a?.pop();let l=Cn(c,o);return n&&(n.enumerated=l),l},di=e=>z.sets!==void 0&&!e.enumerated?ui(e,e,!0):L(e),fi=(e,t)=>{let n=typeof e==`object`&&y(e)?e:void 0;if(n===void 0||n.enumerated)return L(e);let r=Si(n),i=n.kind===`SetOperation`||n.kind===`Union`?di(n):L(n,t);return r&&(n.enumerated=void 0),i},pi=e=>{if(typeof e==`object`)switch(e.kind){case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`Union`:return e.cost?.charges===void 0?void 0:e;default:return}},mi=(e,t)=>{if(typeof t!=`object`)return!1;switch(t.kind){case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`Union`:return t.cost!==void 0&&(t.cost.node!==void 0||t.cost.charges!==void 0);case`FilteredSet`:return t.isCached===!0&&Ui(e,t)!==void 0;default:return!1}},hi=(e,t)=>{if(typeof e==`object`&&e.kind===`FilteredSet`){let t=L(e);return e.isCached=!0,t}let n=L(e,t);return zt(e),n},gi=(e,n,r)=>{if(qn)throw new t.D(`The set literal holds a charged set`);let i=e.cost;if(i?.charges===void 0)return r(e);let a=ni(e);a||it();let o=i.charges.convertCharged(e,r,a);return n&&(i.charges=void 0),o},_i=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isCached!==!0;case`SetOperation`:return e.hasFilter&&e.isCached!==!0&&(_i(e.left)||_i(e.right));case`Union`:return e.isCached!==!0&&typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&yi(e.base.elements);case`FunctionSet`:case`RecordSet`:case`ProductSet`:return vi(e);default:return!1}},vi=e=>e.hasFilter&&e.isCached!==!0&&!e.enumerated&&(e.kind===`FunctionSet`?_i(e.domain)||_i(e.range):yi(e.kind===`RecordSet`?e.sets:e.factors)),yi=e=>{for(let t=0;t<e.length;t++)if(_i(e[t]))return!0;return!1},bi=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isPassObserved===!0||bi(e.base);case`SetOperation`:return bi(e.left)||bi(e.right);case`Union`:return typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&xi(e.base.elements);case`FunctionSet`:return bi(e.domain)||bi(e.range);case`RecordSet`:return xi(e.sets);case`ProductSet`:return xi(e.factors);default:return!1}},xi=e=>{for(let t=0;t<e.length;t++)if(bi(e[t]))return!0;return!1},Si=e=>_i(e)&&bi(e),Ci=(e,t,n)=>({kind:`FunctionSet`,domain:e,range:t,hasFilter:_i(e)||_i(t),cost:n}),wi=(e,t,n)=>({kind:`RecordSet`,names:e,sets:t,hasFilter:yi(t),cost:n}),Ti=(e,t)=>({kind:`ProductSet`,factors:e,hasFilter:yi(e),cost:t}),Ei=(e,t,n,r)=>({kind:`SetOperation`,operator:e,left:t,right:n,hasFilter:_i(t)||_i(n),cost:r}),Di=(e,t)=>({kind:`Union`,base:e,cost:t}),Oi=e=>(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&vi(e)?e:void 0,ki={kind:`List`,elements:[],position:0},Ai=e=>t=>e.test(t,!1),ji=e=>{let t=typeof e==`object`&&y(e)&&!e.enumerated&&Si(e)?e:void 0,n=Sr(e);return t&&(t.enumerated=void 0),n},Mi=e=>{if(!ze&&La(e))return ki;let t={kind:`Product`,set:e,costModel:Er(e.cost),domain:[],parts:[],current:[],isDone:!1};if(e.kind===`FunctionSet`){if(ba(e.domain,!0),tt(e.domain))throw P(Ur,`domain D`,e.domain);if(t.domain=ji(e.domain),(t.domain.length>0||ze)&&tt(e.range))throw P(Ur,`range R`,e.range)}let n=e.kind===`FunctionSet`?t.domain.map(()=>e.range):e.kind===`RecordSet`?e.sets:e.factors;for(let r=0;r<n.length;r++){if(e.kind!==`FunctionSet`&&tt(n[r]))throw P(Wr,e,r);let i=Ni(n[r]),a=Bi(i);if(a===void 0)return ki;t.parts.push(i),t.current.push(a)}return t},Ni=e=>{let t=z.sets;if(typeof e==`object`&&e.kind===`FilteredSet`&&!jt(e)){t?.push(e),I(e.base)||L(e);let n=Ni(e.base),r=e.startPass?.(!1),i={kind:`Filter`,set:e,base:n,test:r?.test??Ai(e),end:r?.end};return t?.pop(),i}if(typeof e==`object`&&(e.kind===`SetOperation`||e.kind===`Union`)&&_i(e))return bi(e)||z.sets!==void 0?Fi(e):ao(Pi,Fi,e,void 0);let n=typeof e==`object`?Oi(e):void 0;if(n===void 0)return Pi(e);t?.push(n);let r=Mi(n);return t?.pop(),r},Pi=e=>({kind:`List`,elements:ka(e),position:0}),Fi=e=>{let t=z.sets;t?.push(e);let n=e.kind===`Union`?Li(e):Ii(e);return t?.pop(),n},Ii=e=>{if(e.operator===`\\cup`)return I(e.left)&&I(e.right)||L(e),{kind:`Concatenated`,left:Ni(e.left),right:Ni(e.right)};let t=e.operator===`\\`||I(e.left),n=t?e.left:e.right;return I(n)||L(e),{kind:`Selected`,base:Ni(n),other:t?e.right:e.left,isIntersection:e.operator===`\\cap`}},Li=e=>{let t=Ar(e);return{kind:`Unioned`,union:e,sets:t,index:0,part:t.length>0?Ni(Nr(t[0],0,e)):void 0}},Ri=(e,t)=>{zi(e.parts[t]);let n=Bi(e.parts[t]);n===void 0?e.isDone=!0:e.current[t]=n},zi=e=>{switch(e.kind){case`List`:e.position=0;return;case`Filter`:{zi(e.base);let t=e.set.startPass?.(!1);e.test=t?.test??Ai(e.set),e.end=t?.end;return}case`Product`:e.isDone=!1;for(let t=0;t<e.parts.length;t++)Ri(e,t);return;case`Concatenated`:zi(e.left),zi(e.right);return;case`Selected`:zi(e.base);return;case`Unioned`:e.index=0,e.part=e.sets.length>0?Ni(Nr(e.sets[0],0,e.union)):void 0}},Bi=e=>{switch(e.kind){case`List`:return e.position<e.elements.length?e.elements[e.position++]:void 0;case`Filter`:for(let t=Bi(e.base);t!==void 0;t=Bi(e.base))if(e.test(t))return t;e.end?.();return;case`Product`:{if(e.isDone)return;let t=[...e.current];e.isDone=e.parts.length===0;for(let t=e.parts.length-1;t>=0&&!e.isDone;t--){let n=Bi(e.parts[t]);if(n!==void 0){e.current[t]=n;break}t===0?e.isDone=!0:Ri(e,t)}let n=e.set;return Tr(n.kind===`FunctionSet`?Et(e.domain,t):n.kind===`RecordSet`?wr(n.names,t):F(t),e.costModel)}case`Concatenated`:return Bi(e.left)??Bi(e.right);case`Selected`:for(let t=Bi(e.base);t!==void 0;t=Bi(e.base))if(B(t,e.other)===e.isIntersection)return t;return;case`Unioned`:for(;e.part!==void 0;){let t=Bi(e.part);if(t!==void 0)return t;e.index++,e.part=e.index<e.sets.length?Ni(Nr(e.sets[e.index],e.index,e.union)):void 0}return}},Vi=(e,t)=>{for(let n=Bi(e);n!==void 0;n=Bi(e))if(t(n))return!0;return!1},Hi={kind:`Plain`,part:ki},Ui=(e,t)=>{if(typeof t==`object`)switch(t.kind){case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`Union`:return t.cost?.node;case`Set`:return e.values.get(t)??t.costNode;default:return e.values.get(t)}},Wi=(e,t)=>{if(typeof t!=`object`)return;let n=Oi(t);if(n===void 0)return;if(n.kind===`FunctionSet`)return Xi(e,n.range)?n:void 0;let r=n.kind===`RecordSet`?n.sets:n.factors;for(let t=0;t<r.length;t++)if(!Xi(e,r[t]))return;return n},Gi=e=>typeof e==`object`&&e.kind===`FilteredSet`&&e.isCached===!0,Ki=(e,t)=>t.operator===`\\cup`&&t.enumerated===void 0&&(_i(t)||Gi(t.left)||Gi(t.right))&&Ui(e,t)!==void 0&&I(t.left)&&I(t.right)&&!ue(t.left)&&!ue(t.right)&&Xi(e,t.left)&&Xi(e,t.right),qi=e=>e.operator===`\\`||I(e.left)?e.left:e.right,Ji=(e,t)=>t.enumerated===void 0&&_i(t)&&I(qi(t))&&Xi(e,qi(t)),Yi=(e,t)=>t.operator===`\\cup`?Ki(e,t):Ji(e,t),Xi=(e,t)=>typeof t==`object`?t.kind===`SetOperation`?Yi(e,t):t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||Ui(e,t)===void 0||Wi(e,t)!==void 0:!0,Zi=(e,t)=>typeof t==`object`&&(t.kind===`FilteredSet`||t.kind===`Subset`||(t.kind===`SetOperation`?Yi(e,t):Wi(e,t)!==void 0)),Qi=(e,t)=>jt(t)||!Zi(e,t.base)?void 0:Ui(e,t),$i=(e,t)=>{let n=typeof t!=`object`||t.kind===`FilteredSet`||t.kind===`Subset`?void 0:Ui(e,t),r=z.sets;if(typeof t==`object`&&t.kind===`FilteredSet`){let n=Qi(e,t);if(n===void 0){let n=t.isCached?Ui(e,t):void 0;return n===void 0?{kind:`Plain`,part:Ni(t)}:{kind:`ChargedLeaf`,node:n,part:Ni(t)}}r?.push(t),I(t.base)||L(t);let i={kind:`ChargedFilter`,node:n,set:t,base:$i(e,t.base)};return r?.pop(),i}if(typeof t==`object`&&t.kind===`SetOperation`&&t.operator!==`\\cup`){r?.push(t);let n=qi(t),i={kind:`ChargedSelected`,base:$i(e,n),other:n===t.left?t.right:t.left,isIntersection:t.operator===`\\cap`};return r?.pop(),i}if(n!==void 0&&typeof t==`object`&&t.kind===`SetOperation`){r?.push(t);let i={kind:`ChargedUnion`,node:n,left:$i(e,t.left),right:$i(e,t.right)};return r?.pop(),i}let i=n===void 0||typeof t!=`object`?void 0:Oi(t);if(n!==void 0&&i!==void 0){r?.push(i);let t=ra(e,i,n);return r?.pop(),t}if(typeof t==`object`&&t.kind===`Subset`&&t.cost?.node!==void 0){if(t.cost.charges===void 0)return{kind:`ChargedLeaf`,node:t.cost.node,part:Ni(t)};e.chargeSubsetElements(t)}let a=Ni(t);return n===void 0?{kind:`Plain`,part:a}:{kind:`ChargedLeaf`,node:n,part:a}},ea=(e,t)=>{if(typeof t!=`object`||t.kind!==`SetOperation`&&t.kind!==`FilteredSet`&&t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||(t.kind===`FilteredSet`?Qi(e,t)===void 0:(t.kind!==`SetOperation`||t.operator===`\\cup`)&&Ui(e,t)===void 0))return La(t);let n=z.sets;n?.push(t);let r=t.kind===`SetOperation`||t.kind===`FilteredSet`?oa(e,$i(e,t))===void 0:t.kind===`FunctionSet`?!La(t.domain)&&ea(e,t.range):na(e,t.kind===`RecordSet`?t.sets:t.factors);return n?.pop(),r},ta=(e,t)=>(e?.chargeIsEmpty(t),La(t)),na=(e,t)=>{for(let n=0;n<t.length;n++)if(ea(e,t[n]))return!0;return!1},ra=(e,t,n)=>{if(!ze&&ea(e,t))return Hi;let r={kind:`ChargedProduct`,node:n,costModel:e.costModels[n],set:t,domain:[],parts:[],current:[],isDone:!1};if(t.kind===`FunctionSet`){if(ba(t.domain,!0),tt(t.domain))throw P(Ur,`domain D`,t.domain);if(r.domain=ji(t.domain),(r.domain.length>0||ze)&&tt(t.range))throw P(Ur,`range R`,t.range)}let i=t.kind===`FunctionSet`?r.domain.map(()=>t.range):t.kind===`RecordSet`?t.sets:t.factors;for(let n=0;n<i.length;n++){if(t.kind!==`FunctionSet`&&tt(i[n]))throw P(Wr,t,n);let a=$i(e,i[n]),o=oa(e,a);if(o===void 0)return Hi;r.parts.push(a),r.current.push(o)}return r},ia=(e,t,n)=>{aa(e,t.parts[n]);let r=oa(e,t.parts[n]);r===void 0?t.isDone=!0:t.current[n]=r},aa=(e,t)=>{switch(t.kind){case`Plain`:case`ChargedLeaf`:zi(t.part);return;case`ChargedProduct`:t.isDone=!1;for(let n=0;n<t.parts.length;n++)ia(e,t,n);return;case`ChargedUnion`:aa(e,t.left),aa(e,t.right);return;case`ChargedSelected`:case`ChargedFilter`:aa(e,t.base)}},oa=(e,t)=>{switch(t.kind){case`Plain`:return Bi(t.part);case`ChargedLeaf`:return e.secondary[t.node]++,Bi(t.part);case`ChargedProduct`:{if(t.isDone)return;let n=[...t.current];e.secondary[t.node]+=Math.max(t.parts.length,1),t.isDone=t.parts.length===0;for(let n=t.parts.length-1;n>=0&&!t.isDone;n--){let r=oa(e,t.parts[n]);if(r!==void 0){t.current[n]=r;break}n===0?t.isDone=!0:ia(e,t,n)}let r=t.set;return Tr(r.kind===`FunctionSet`?Et(t.domain,n):r.kind===`RecordSet`?wr(r.names,n):F(n),t.costModel)}case`ChargedUnion`:return e.secondary[t.node]++,oa(e,t.left)??oa(e,t.right);case`ChargedSelected`:return sa(e,t);case`ChargedFilter`:return ca(e,t)}},sa=(e,t)=>{for(let n=oa(e,t.base);n!==void 0;n=oa(e,t.base))if(e.isMember(n,t.other)===t.isIntersection)return n},ca=(e,t)=>{for(let n=oa(e,t.base);n!==void 0;n=oa(e,t.base))if(e.secondary[t.node]++,t.set.test(n,!1))return n},la=(e,t)=>{let n=[];for(let r=oa(e,t);r!==void 0;r=oa(e,t))A(n,r);return n},ua=(e,t,n)=>{let r=Qi(e,t);if(r===void 0||t.enumerated||!I(t.base)||qn)return;let i=z.sets;i?.push(t);let a=la(e,{kind:`ChargedFilter`,node:r,set:t,base:$i(e,t.base)});i?.pop(),e.secondary[r]+=a.length;let o=Ct(L(Jn(a)).elements);return n&&(t.enumerated=o),o.elements},da=(e,t)=>t.kind===`FilteredSet`?!t.enumerated&&I(t.base)&&Qi(e,t)!==void 0:t.kind===`SetOperation`?Yi(e,t):Wi(e,t)!==void 0&&Ui(e,t)!==void 0,fa=(e,t,n)=>{if(typeof t!=`object`||!da(e,t))return!1;let r=$i(e,t);for(let t=oa(e,r);t!==void 0;t=oa(e,r))n(t);return!0},pa=(e,t,n)=>{let r=n.kind===`Subset`,i=r?t:n.base;if(typeof i!=`object`||!da(e,i))return;let a=z.sets;a?.push(n);let o=$i(e,i),s=!1;for(let i=oa(e,o);i!==void 0;i=oa(e,o))if(r?!e.isMember(i,n.base):e.isMember(t,i)){s=!0;break}return a?.pop(),r!==s},ma=(e,t,n)=>{if(typeof t!=`object`)return;if(t.kind===`FilteredSet`)return ua(e,t,n);let r=Ui(e,t),i=t.kind===`SetOperation`?Yi(e,t)?t:void 0:r===void 0?void 0:Wi(e,t);if(i===void 0)return;let a=la(e,$i(e,i));r!==void 0&&(e.secondary[r]+=a.length);let o=i.kind!==`SetOperation`&&Ma(i)?Sn(a):a,s=i.kind===`SetOperation`?Ct(L(Jn(a)).elements):i.kind===`RecordSet`?Kn(o):Ct(o);return n&&(i.enumerated=s),s.elements},ha=(e,t)=>t===void 0||t.kind===`Cup`?Mi(e):t,ga=(e,t)=>{let n=[];return Vi(e,e=>(t?A(n,e):n.push(e),!1)),n},_a=(e,t)=>{if(!(typeof e!=`object`||jt(e)))switch(e.kind){case`MixedSet`:L(e);return;case`FilteredSet`:return I(e.base)||L(e),ba(e.base,t);case`Union`:{if(!he(e.base)&&I(e.base))return ba(e.base,t);let n=Ar(e);return n.length>0?ba(Nr(n[0],0,e),t):void 0}case`SetOperation`:if(e.operator===`\\`&&!I(e.left)&&L(e),e.operator===`\\cap`&&!I(e.left)&&!I(e.right)&&L(e),e.operator===`\\cup`){I(e.left)&&I(e.right)||L(e);let t=ba(e.left,!0),n=ba(e.right,!0);return t||n?{kind:`Cup`,left:t,right:n}:void 0}return ba(e.operator===`\\cap`&&!I(e.left)?e.right:e.left,t);case`FunctionSet`:case`RecordSet`:case`ProductSet`:if(vi(e))return Mi(e);t&&va(e);return;case`Subset`:t&&va(e);return;default:return}},va=e=>{switch(e.kind){case`Subset`:{let t=e.base;if(e.enumerated||typeof t==`object`&&t.kind===`Set`)return;if(typeof t==`object`&&t.kind===`Interval`){R(t);return}Hr(e);return}case`FunctionSet`:{if(e.enumerated||La(e))return;let t=e.domain;if(ba(t,!0),tt(t))throw P(Ur,`domain D`,t);if(typeof t==`object`&&y(t)&&L(t),La(t))return;if(tt(e.range))throw P(Ur,`range R`,e.range);typeof t==`object`&&t.kind===`Interval`&&ya(e),ba(e.range,!0);return}case`RecordSet`:case`ProductSet`:{if(e.enumerated||La(e))return;let t=e.kind===`RecordSet`?e.sets:e.factors;for(let n=0;n<t.length;n++){if(tt(t[n]))throw P(Wr,e,n);ba(t[n],!0)}}}},ya=e=>{let n=R(e.domain);if(n>fe)throw z.sets?.push(e),new t.U;return n},ba=(e,t)=>{let n=z.sets;n?.push(e);let r=_a(e,t||n!==void 0);return n?.pop(),r},xa=e=>typeof e!=`object`||jt(e)?void 0:ba(e,!1),Sa=e=>`Attempted to enumerate S \\cup T when S:\n${_(U(e.left))}\nand T:\n${_(U(e.right))}\nare not both enumerable`,Ca=(e,n)=>{if(!I(e.left)||!I(e.right))throw P(Sa,e);let r=n?.kind===`Cup`?n:void 0,i=r?r.left:ba(e.left,!0),a=r?r.right:ba(e.right,!0);if(ue(e.left))throw new t.q(le());let o=[],s=e=>(A(o,e),!1);if(Ea(e.left,i,s),ue(e.right))throw new t.q(le());return Ea(e.right,a,s),o},wa=e=>{if(typeof e!=`object`||e.kind!==`FilteredSet`||e.isPassObserved!==!0||e.isCached===!0||e.enumerated)return L(e);let t=L(e);return e.enumerated=void 0,t},Ta=(e,t)=>{if(typeof e!=`object`||e.kind!==`SetOperation`&&e.kind!==`Union`&&(!t||e.kind!==`FunctionSet`&&e.kind!==`RecordSet`&&e.kind!==`ProductSet`)||e.enumerated)return t?wa(e).elements:ri(e);let n=(e.kind===`Union`||e.hasFilter)&&Si(e),r=ni(e),i=li(e,!0,void 0,z.sets?ba(e,!1):void 0),a=Cn(i,r);return n||(e.enumerated=a),a.elements},Ea=(e,t,n)=>typeof e!=`object`||jt(e)?L(e).elements.some(n):Pa(e,n,t),Da=(e,t)=>Ea(e,xa(e),t),Oa=(e,t)=>{let n=[];return Ea(e,t,e=>(n.push(e),!1)),n},ka=e=>Oa(e,xa(e)),Aa=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,ja=e=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:case`Interval`:return!0;case`Set`:return e.elements.every(ja);case`Function`:return e.writtenKeys===void 0&&e.domain.every(ja)&&e.range.every(ja);case`SetOperation`:return e.operator!==`\\cup`&&ja(e.left)&&ja(e.right);case`FilteredSet`:return ja(e.base);case`ProductSet`:return e.factors.every(ja);default:return!1}},Ma=e=>typeof e!=`object`||jt(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?Ma(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||Ma(e.left)||Ma(e.right):Aa(e)?.some(Ma)??!1,Na=(e,t)=>Ar(e,e=>he(e)?jr(e):Oa(e,t)),Pa=(e,t,n)=>{if(e.kind===`Union`)return Na(e,n).some((r,i)=>{let a=Nr(r,i,e);return i===0&&he(e.base)?Ea(a,n,t):Da(a,t)});if(e.kind===`FilteredSet`&&I(e.base)){let r=e.startPass?.(!1);return r?Ea(e.base,n,e=>r.test(e)&&t(e))?!0:(r.end(),!1):Ea(e.base,n,n=>e.test(n,!1)&&t(n))}if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&n!==void 0)return Vi(ha(e,n),t);if(Aa(e)?.some(Ma))return li(e,!1,ka).some(t);if(e.kind===`Subset`&&e.enumerated===void 0&&R(e.base)>20)return zr(Hr(e),t,e.cost?.node);if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&!e.enumerated)return ti(e,!1)?ii(e,z.sets?ba(e,!1):void 0,!0).some(t):Vi(Mi(e),t);if(e.kind!==`SetOperation`)return ri(e).some(t);if(e.operator===`\\cup`){if(!I(e.left)||!I(e.right))return L(e).elements.some(t);let r=n?.kind===`Cup`?n:void 0;return Ea(e.left,r?.left,t)||Ea(e.right,r?.right,t)}let r=e.operator===`\\`||I(e.left),i=r?e.left:e.right,a=r?e.right:e.left;return I(i)?Ea(i,n,n=>B(n,a)===(e.operator===`\\cap`)&&t(n)):L(e).elements.some(t)},Fa=()=>!0,Ia=e=>`Shouldn't call isEmpty() on value ${U(e)}`,La=e=>{if(typeof e!=`object`||!j(e))throw z.sets?.push(e),P(Ia,e);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return Wa(e.low,e.high)===0;case`InfiniteSet`:if(e.name===`Any`)throw new t.D(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1}let n=z.sets;if(n===void 0)return Ra(e);n.push(e);let r=Ra(e);return n.pop(),r},Ra=e=>{switch(e.kind){case`ProductSet`:return e.factors.some(La);case`RecordSet`:return e.sets.some(La);case`FunctionSet`:return!La(e.domain)&&La(e.range);case`Union`:return Ar(e).every((t,n)=>La(Nr(t,n,e)));default:return!Da(e,Fa)}},za=(e,t,n)=>e.reduce((e,r)=>{let i=e*R(r,t);if(i>2147483647)throw P(n);return i},1),Ba=e=>`Overflow when computing the number of elements in:\n${_(U(e))}`,Va=e=>`Attempted to compute the number of elements in the ${ge(e)} ${_(U(e))}.`,Ha=e=>`Attempted to compute the number of elements in the model value ${_(U(e))}.`,Ua=e=>`Attempted to compute the number of elements in the overridden value ${_(U(e))}.`,Wa=(e,n)=>{let r=Math.max(0,n-e+1);if(r>2147483647)throw new t.D(`Size of interval value exceeds the maximum representable size (32bits): ${e}..${n}.`);return r},R=(e,t)=>{if(typeof e!=`object`)throw P(Va,e);switch(e.kind){case`ModelValue`:throw P(Ha,e);case`Operator`:throw P(Va,e);case`Function`:return e.domain.length;case`LazyFunction`:return R(e.domain,t);case`Interval`:return Wa(e.low,e.high);case`InfiniteSet`:case`SequenceSet`:throw P(Ua,e);case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:{let n=z.sets;n?.push(e);let r=Ga(e,t);return n?.pop(),r}default:return hi(e).elements.length}},Ga=(e,t)=>{switch(e.kind){case`Subset`:{let n=R(e.base,t);if(n>=31)throw P(Ba,e);return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(La(e.domain))return 1;if(La(e.range))return 0;if(R(e.range,t)===1)return 1}let n=R(e.domain,t),r=R(e.range,t);if(r<=1)return n===0?1:r;let i=1;for(let t=0;t<n;t++)if(i*=r,i>2147483647)throw P(Ba,e);return i}case`RecordSet`:return t!==`1.7.4`&&La(e)?0:za(e.sets,t,()=>Ba(e));case`ProductSet`:return t!==`1.7.4`&&La(e)?0:za(e.factors,t,()=>`Overflow when computing the number of elements in ${_(U(e))}`)}},Ka=e=>`Attempted to check if the set ${_(U(e))}is finite.`,qa=e=>{if(typeof e!=`object`||e.kind===`ModelValue`||e.kind===`Operator`)throw new t.D(`Attempted to check if the ${ge(e)} ${_(U(e))} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new t.D(`Attempted to check if the function:\n${_(U(e))}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return qa(e.base)&&La(e.base);case`Subset`:return qa(e.base);case`FunctionSet`:{let t=qa(e.domain);if(t&&La(e.domain))return!0;let n=qa(e.range);return n&&La(e.range)?!0:n&&(t||R(e.range)===1)}case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors,n=!0;for(let e of t)if(!qa(e))n=!1;else if(La(e))return!0;return n}case`Union`:if(!I(e.base))throw new t.D(`Attempted to check if the nonenumerable set:\n${Or(e)}\nis a finite set.`);return L(e.base).elements.every(qa);case`SetOperation`:if(e.operator===`\\cup`)return qa(e.left)&&qa(e.right);if(e.operator===`\\cap`){if(!qa(e.left)&&!qa(e.right))throw new t.D(Ka(e));return!0}if(qa(e.left))return!0;if(!qa(e.right))throw new t.D(Ka(e));return!1;case`FilteredSet`:if(!qa(e.base))throw new t.D(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${_(U(e.base))}\nis finite.`);return!0}},Ja=(e,t,n=ht)=>{let r=0,i=e.length-1;for(;r<=i;){let a=r+i>>1,o=n(e[a],t);if(o===0)return a;o<0?r=a+1:i=a-1}return-1},Ya=(e,n)=>{let r=e.elements;if(r.length>ce())throw new t.q(le());let i=Array.from({length:r.length},()=>!1),a=n.filter(e=>{let t=Ja(r,e);return!i[t]&&(i[t]=!0,!0)}),o=Ct(r);return a.some((e,t)=>e!==r[t])&&(o.writtenElements=a),o},Xa=e=>e instanceof mr&&e.interval.low===1||e.every((e,t)=>e===t+1),Za=e=>{let t=ri(e.domain),n=[];for(let r=0;r<t.length;r++){if(t[r]!==r+1)return;n.push(e.apply(t[r]))}return Vo(e)&&e.costModel.node>=0&&(e.costModel.secondary[e.costModel.node]+=t.length),n},Qa=e=>typeof e.domain==`object`&&e.domain.kind===`Interval`?e.domain.low===1||e.domain.high<e.domain.low:Xa(ri(e.domain)),$a=e=>{if(typeof e!=`object`||!me(e))return;if(e.kind===`LazyFunction`){if(e.boundTupleLengths!==void 0)return;if(!j(e.domain)||tt(e.domain))throw new t.D(`To convert a function of form [x \\in S |-> f(x)] to a tuple, the set S must be enumerable.`);if(!e.enumerated&&(e.isApplicationObserved||!Qa(e)))return Za(e)}let n=V(e);if(eo(n.domain))return $t(e),n.range},eo=e=>e.length===0||e[0]===1&&e[e.length-1]===e.length,to=(e,t)=>{if(typeof t==`object`&&t.kind===`Operator`)return`Attempted to check if the value:\n${_(U(e))}\nis an element of operator ${_(U(t))}`;let n=`Attempted to check if the value:\n${_(U(e))}\nis an element of the`;if(!me(t))return`${n} ${ge(t)} ${_(U(t))}`;let r=Ot(t);return r===`record`?`Attempted to check if element:\n${_(U(e))}\nis in the record:\n${_(U(t))}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${_(U(t))}`},z={sets:void 0},no=()=>{let e=z.sets,t=z.callStack;if(e!==void 0||t!==void 0)return{depth:e?.length??0,length:t?.expressions.length??0,isFrozen:t?.isFrozen??!1,fingerprint:t?.fingerprint}},ro=e=>{e!==void 0&&(z.sets&&(z.sets.length=e.depth),z.callStack&&(z.callStack.fingerprint=e.fingerprint))},io=e=>{ro(e);let t=z.callStack;e!==void 0&&t&&(t.expressions.length=e.length,t.isFrozen=e.isFrozen)},ao=(e,n,r,i,a)=>{let o=no(),s=rt;rt=`stopping`;try{let t=e(r,i);return rt=s,t}catch(e){if(rt=s,!(e instanceof t.Z)){if(!(e instanceof t.D))throw e;if(a?.(r,i))throw so(e)}return io(o),n(r,i)}},oo=(e,n,r,i)=>{let a=no(),o=rt;rt=`deferring`;try{let t=e(r,i);return rt=o,t}catch(e){if(rt=o,!(e instanceof t.D))throw e;return io(a),n(r,i)}},so=e=>(rt===`none`&&e.formatMessage(),e),co=e=>(z.sets??[]).slice(e).some(e=>typeof e==`object`&&z.callStack?.sources.has(e)===!0),B=(e,t)=>{let n=z.sets;if(n===void 0)return vo(e,t);n.push(t);let r=vo(e,t);return n.pop(),r},lo=(e,t)=>{let n=z.sets;n?.push(t);let r=ho(e,t);return n?.pop(),r},uo=(e,t)=>{let n=z.sets;n?.push(t);let r=An(e,t.elements);return n?.pop(),r.isFound?r.index:-1},fo=(e,t,n)=>{let r=z.sets;if(r===void 0)return zo(e,t,n);r.push(t);let i=zo(e,t,n);return r.pop(),i},po=(e,t)=>{let n=t.elements,r=0,i=n.length-1;for(;r<=i;){let t=r+i>>1,a=n[t];if(typeof a!=`number`)return;if(a===e)return!0;a<e?r=t+1:i=t-1}return!1},mo=(e,t)=>Ja(t.elements,e)!==-1,ho=(e,t)=>re(t)?An(e,t.elements).isFound:jn(e,Mn(t)),go=(e,t)=>`Attempted to check if the typed model value ${_(U(e))} is an element of\n${_(U(t))}`,_o=(e,t)=>{if(e.type!==void 0)throw P(go,e,t);return!1},vo=(e,t)=>{if(typeof e==`number`&&typeof t==`object`){if(t.kind===`Set`&&!_t)return po(e,t)??Ro(e,t);if(t.kind===`Interval`)return e>=t.low&&e<=t.high}return Ro(e,t)},yo=(e,t)=>`Attempted to check if the non-enumerable value\n${_(U(e))}\nis element of\n${_(U(t))}`,bo=(e,t)=>{let n=t.elements,r=0,i=n.length;for(;r<i;){let t=r+i>>1,a=n[t];if(typeof a!=`number`)return;a<e.low?r=t+1:i=t}for(let t=e.low;t<=e.high;t++,r++){if(r===n.length)return!1;let e=n[r];if(e!==t)return typeof e!=`number`&&void 0}return!0},xo=(e,t,n)=>{if(typeof t==`object`&&(t.kind===`Interval`?t.low<=e.low&&t.high>=e.high:t.kind===`InfiniteSet`&&(t.name===`Int`||t.name===`Nat`&&e.low>=0)))return!0;let r=typeof t==`object`&&t.kind===`Set`?bo(e,t):void 0;if(r!==void 0)return r;for(let r=e.low;r<=e.high;r++)if(!n(r,t))return!1;return!0},So=(e,t,n)=>{if(!j(e)||tt(e))throw P(yo,e,t);return!Da(e,e=>!n(e,t.base))},Co=(e,t)=>`Attempted to check if \n${U(e)}\nwhich is not a TLC function value, is in the set of functions:\n${_(U(t))}`,wo=(e,t)=>`Attempted to check if non-record\n${U(e)}\nis in the set of records:\n${_(U(t))}`,To=(e,t)=>`Attempted to check if non-tuple\n${_(U(e))}\nis in the set of tuples:\n${_(U(t))}`,Eo=(e,t)=>{if(!me(e)){if(M(e))return _o(e,t);throw P(Co,e,t)}Ce(e);let n=Zt(e),r=Xt(e,n.domain);return(r===void 0?Hn(t.domain,Ct(n.domain)):Vn({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range},Do=(e,t)=>{Ce(e);let n=me(e)?V(e):void 0;if(!n||!N(n.domain)){if(M(e))return _o(e,t);throw P(wo,e,t)}return $t(n),n.domain.length===t.names.length&&n},Oo=(e,t)=>{let n=me(e)?$a(e):void 0;if(n===void 0){let n=me(e)&&Zt(e).domain.every(e=>typeof e==`number`);if(M(e))return _o(e,t);if(n)return!1;throw P(To,e,t)}return n.length===t.factors.length&&n},ko=(e,n)=>e instanceof t.D&&r.y(e)&&!co(n),Ao=(e,t)=>`Cannot decide if element:\n${_(U(e))}\n is element of:\n${_(U(t.base))}\nand satisfies the predicate ${t.source?.predicate}`,jo=e=>{let t=L(e).elements;if(t.length>1)for(let e of t)typeof e==`object`&&e.kind===`Set`&&(e.flags|=1);return t},Mo=(e,t)=>`Attempted to check if:\n ${_(U(e))}\nis an element of the non-enumerable set:\n ${_(Or(t))}`,No=(e,t,n)=>{if(!I(t.base))throw P(Mo,e,t);return Da(t.base,t=>n(e,t))},Po=(e,t)=>`Attempted to check if the value:\n${_(U(e))}\nis an element of ${_(U(t))}.`,Fo=(e,n)=>{let r=$a(e);if(r===void 0){if(M(e))return _o(e,n);throw new t.H(at(Po,e,n))}return r},Io=(e,t)=>`Attempted to check if the value:\n${_(U(e))}\nis in the integer interval ${_(U(t))}`,Lo=(e,t)=>`Attempted to check if the value:\n${_(U(e))}\nis an element of ${t.name}.`,Ro=(e,n)=>{if(!j(n))throw P(to,e,n);switch(n.kind){case`Set`:return _t||kt(e)||Rt(e)?ho(e,n):ao(mo,ho,e,n);case`MixedSet`:return n.enumerated?An(e,n.enumerated.elements).isFound:jn(e,n.elements);case`Interval`:if(typeof e==`number`)return e>=n.low&&e<=n.high;if(n.low<=n.high&&(!M(e)||e.type!==void 0))throw P(Io,e,n);return!1;case`InfiniteSet`:if(n.name===`Any`)return!0;if(M(e))return _o(e,n);if(!(n.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new t.H(at(Lo,e,n));return n.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:return typeof e==`object`&&e.kind===`Interval`?xo(e,n.base,B):pe(e)?L(e).elements.every(e=>B(e,n.base)):So(e,n,B);case`FunctionSet`:{let t=Eo(e,n);return t!==!1&&t.every(e=>B(e,n.range))}case`RecordSet`:{let t=Do(e,n);return t!==!1&&n.names.every((e,r)=>{let i=Ja(t.domain,e);return i!==-1&&B(t.range[i],n.sets[r])})}case`ProductSet`:{let t=Oo(e,n);return t!==!1&&t.every((e,t)=>B(e,n.factors[t]))}case`FilteredSet`:{if(n.isCached)return B(e,L(n));let t=z.sets?.length??0;try{return B(e,n.base)&&n.test(e,!0)}catch(r){throw ko(r,t)?P(Ao,e,n):r}}case`Union`:return pe(n.base)?jo(n.base).some(t=>B(e,t)):No(e,n,B);case`SetOperation`:return n.operator===`\\cup`?B(e,n.left)||B(e,n.right):B(e,n.left)&&B(e,n.right)===(n.operator===`\\cap`);case`SequenceSet`:{let t=Fo(e,n);return t!==!1&&t.every(e=>B(e,n.base))}default:throw P(to,e,n)}},zo=(e,t,n)=>{if(typeof t!=`object`)return Ro(e,t);switch(t.kind){case`Subset`:return typeof e==`object`&&e.kind===`Interval`?xo(e,t.base,n):pe(e)?L(e).elements.every(e=>n(e,t.base)):So(e,t,n);case`FunctionSet`:{let r=Eo(e,t);return r!==!1&&r.every(e=>n(e,t.range))}case`RecordSet`:{let r=Do(e,t);return r!==!1&&t.names.every((e,i)=>{let a=Ja(r.domain,e);return a!==-1&&n(r.range[a],t.sets[i])})}case`ProductSet`:{let r=Oo(e,t);return r!==!1&&r.every((e,r)=>n(e,t.factors[r]))}case`FilteredSet`:{if(t.isCached)return n(e,L(t));let r=z.sets?.length??0;try{return n(e,t.base)&&t.test(e,!0)}catch(n){throw ko(n,r)?P(Ao,e,t):n}}case`Union`:return pe(t.base)?jo(t.base).some(t=>n(e,t)):No(e,t,n);case`SetOperation`:return t.operator===`\\cup`?n(e,t.left)||n(e,t.right):n(e,t.left)&&n(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let r=Fo(e,t);return r!==!1&&r.every(e=>n(e,t.base))}default:return Ro(e,t)}},Bo=(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?B(e,n):e.range.every((e,r)=>Bo(e,t.range[r],n.range)),Vo=e=>`costModel`in e,Ho=e=>Vo(e)?e.costModel.node:-1,Uo=e=>`original`in e,Wo=e=>{let t=[];for(let n=e;Uo(n);n=n.original)t.push(n);return t},Go=(e,t)=>{let n=Wo(e);return t.map(t=>{let r=e.applyBody(t);for(let e=n.length-1;e>=0;e--){let i=n[e];Vn(i.path[i.depth],t)&&(r=xs(r,i.path,i.depth+1,i.newValue))}return r})},Ko=e=>`Expected a function but found ${U(e)}`,V=e=>{if(typeof e==`object`&&e.kind===`Function`)return e;if(typeof e==`object`&&e.kind===`LazyFunction`){if(e.enumerated)return e.enumerated;if(qn)throw new t.D(`The set literal holds a lazy function`);let n=Vo(e)?e.costModel.startConversion():void 0;if(R(e.domain),!j(e.domain))throw new t.D(`The domains of formal parameters must be enumerable.`);let r=Sr(e.domain,!1),i=Uo(e)?Go(e,r):r.map(t=>e.apply(t));return e.enumerated=kn(e.domain,r,i),n?.(),e.enumerated}throw P(Ko,e)},qo=(e,t,n)=>{let r=_(U(e)),i=_(U(t)),a=n===`1.7.4`;switch(Ot(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.`}},Jo=(e,t)=>{if(!ze)return qo(e,t);let n=_(U(t));return Ot(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},Yo=(e,t)=>{let n=e[0];if(typeof t==`number`&&typeof n==`number`){let r=t-n;if(e[r]===t)return r}return e.length<=8?e.indexOf(t):-1},Xo=e=>new t.D(`Attempted to apply function with integer domain to the non-integer argument ${_(U(e))}`),Zo=(e,t)=>Ja(e.domain,t),Qo=(e,t)=>{let n=ye(e),r=e.domain;if(!ze&&n===r&&n.length>=32)return Ja(n,t,(e,t)=>wn(e,()=>bn(e,t)));let i=n.findIndex(e=>wn(e,()=>xn(e,t)));return i===-1||n===r?i:r.indexOf(n[i])},$o=(e,n,r)=>{let i=e.domain;if(typeof n!=typeof i[0]){let a=Ot(e),o=a===`tuple`?`number`:a===`record`?`string`:void 0;if(o!==void 0&&typeof n!==o)throw new t.D(r(e,n));if(o===void 0&&!ze&&typeof n!=`number`&&xr(i))throw Xo(n)}let a=Yo(i,n);return a===-1?oo(Zo,Qo,e,n):a},es=(e,n)=>{let r=$o(e,n,qo);if(r===-1)throw new t.D(qo(e,n));return r},ts=(e,t,n,r)=>`In applying the function\n${_(U(e))},\nthe ${t} is:\n${_(U(n))}\nwhich ${r}.\n`,ns=(e,n)=>new t.D(ts(e,`argument list`,n,`does not match its formal parameter`)),rs=e=>new t.D(`Attempted to apply a function to ${U(e)}, which is not in its domain`),is=(e,n,r,i)=>new t.D(ts(e,`argument number ${n+1}`,r,i===void 0?`is not in the function's domain ${U(e.domain)}`:`is not in its domain`)),as=(e,t)=>typeof e==`object`&&e.kind===`Function`&&e.functionClass===`tuple`?e:F(t),os=(e,n,r,i)=>{if(i===void 0)return r;let a=$a(r);if(a===void 0||a.length!==i)throw new t.D(ts(e,`argument number ${n+1}`,r,`does not match its formal parameter`));return as(r,a)},ss=(e,t,n)=>{let r=e.domain,i=$a(n);if(i===void 0)throw ns(e,n);if(typeof r!=`object`||r.kind!==`ProductSet`)throw rs(n);let a=i;for(let o=0;o<t.length;o++){if(o>=i.length)throw ns(e,n);let s=i[o],c=t[o];if(!B(s,r.factors[o]))throw is(e,o,s,c);let l=os(e,o,s,c);l!==s&&(a===i&&(a=[...i]),a[o]=l)}if(i.length>t.length)throw ns(e,n);return a===i?as(n,i):F(a)},cs=(e,t,n,r)=>{let i=e.domain,a=$a(n);if(a===void 0)throw ns(e,n);if(typeof i!=`object`||i.kind!==`ProductSet`)throw rs(n);let o=a;for(let s=0;s<t.length;s++){if(s>=a.length)throw ns(e,n);let c=a[s],l=t[s];if(!r(c,i.factors[s]))throw is(e,s,c,l);let u=os(e,s,c,l);u!==c&&(o===a&&(o=[...a]),o[s]=u)}if(a.length>t.length)throw ns(e,n);return o===a?as(n,a):F(o)},ls=(e,n,r)=>{let i=e.boundTupleLengths;if(i!==void 0)return cs(e,i,n,r);if(!r(n,e.domain))throw new t.D(qo(e,n));return n},us=(e,t,n,r)=>t.apply(ls(e,n,r)),ds=(e,t,n)=>{if(e.boundTupleLengths!==void 0&&$a(n)===void 0)throw ns(e,n);return B(n,e.domain)?t.apply(n):void 0},fs=(e,t,n)=>t.apply(n),ps=(e,t,n,r)=>{let i,a=e;for(;Uo(a);){if(Vn(a.path[a.depth],t)){if(a.depth===a.path.length-1)break;i===void 0&&(i=[]),i.push(a)}a=a.original}let o=Uo(a)?a.newValue:r(e,a,t,n);if(i===void 0||o===void 0)return o;let s=o;for(let e=i.length-1;e>=0;e--){let t=i[e];s=xs(s,t.path,t.depth+1,t.newValue)}return s},ms=(e,n,r)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(e.enumerated)return ms(e.enumerated,n,r);if(Uo(e))return ps(e,n,B,us);let i=e.boundTupleLengths;if(i!==void 0)return e.apply(ss(e,i,n));if(!B(n,e.domain))throw new t.D(qo(e,n));return e.apply(n)}if(typeof e!=`object`||e.kind!==`Function`)throw new t.D(`Attempted to apply ${U(e)}, which is not a function`);let i=r??qo,a=$o(e,n,i);if(a===-1)throw new t.D(i(e,n));return e.range[a]},hs=(e,t,n,r)=>typeof e!=`object`||e.kind!==`LazyFunction`||e.enumerated!==void 0?ms(e,t,n):Uo(e)?ps(e,t,r,us):e.apply(ls(e,t,r)),gs=e=>e instanceof mr?e.interval:void 0,_s=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return e.domain;let t=V(e),n=gs(t.domain);if(n)return n;let r=Ct(t.domain);return t.functionClass===`record`?(t.writtenKeys&&(r.writtenElements=t.writtenKeys),r):(r.flags|=1,r)},vs=(e,t,n,r)=>{let i={kind:`LazyFunction`,domain:e.domain,apply:e=>ps(i,e,B,fs),source:e.source,boundTupleLengths:e.boundTupleLengths,isApplicationObserved:e.isApplicationObserved,original:e,path:t,depth:n,newValue:r,applyBody:Uo(e)?e.applyBody:e.apply};return Vo(e)?Object.assign(i,{costModel:e.costModel}):i},ys=e=>{if(!me(e))throw new t.D(`Attempted to apply EXCEPT construct to the value ${_(U(e))}.`);return V(e)},bs=(e,t,n)=>{let r=e;for(let e=n;e<t.length;e++){let n=t[e];if(typeof r==`object`&&r.kind===`LazyFunction`&&r.enumerated===void 0){let e=ps(r,n,B,ds);if(e===void 0)return;r=e;continue}let i=ys(r),a=$o(i,n,Jo);if(a===-1)return;r=i.range[a]}return r},xs=(e,t,n,r)=>{if(n===t.length)return r;if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return vs(e,t,n,r);let i=ys(e),a=$o(i,t[n],Jo);return a===-1?i:Es(i,a,xs(i.range[a],t,n+1,r))},Ss=(e,t,n,r)=>{if(n===t.length)return r(e);if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0){let i=bs(e,t,n);return i===void 0?e:vs(e,t,n,r(i))}let i=ys(e),a=$o(i,t[n],Jo);return a===-1?i:i instanceof C?D(i,a,Ss(ee(i,a),t,n+1,r)):Es(i,a,Ss(i.range[a],t,n+1,r))},Cs=0,ws=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return Us(e);if(e.kind===`LazyFunction`)return e.enumerated===void 0?0:ws(e.enumerated);if(e.kind===`Set`){if(!re(e))return 0;if(e.hash!==0)return e.hash;let t=e.elements,n=As;for(let e=0;e<t.length;e++){let r=ws(t[e]);if(r===0||r===Ps)return r;n=n+Ms(r)|0}return e.hash=n,n}if(e.kind!==`Function`)return 0;if(e.hash!==0||e.flags&64)return e.hash;let t=js;for(let n=0;n<e.domain.length;n++){let r=ws(e.domain[n]);if(r===0||r===Ps)return r;let i=ws(e.range[n]);if(i===0||i===Ps)return i;t=t+Ns(r,i)|0}return e.hash=t,t},Ts=(e,t)=>{let n=Dt(Et(e.domain,t),e.functionClass),r=e.hash!==0&&e.hash!==Ps,i=e.hash;for(let n=0;n<t.length&&r;n++){let a=e.range[n],o=t[n];if(o===a)continue;let s=ws(o);if(s===0||s===Ps){r=!1;continue}let c=Us(e.domain[n]);i=i-Ns(c,Us(a))+Ns(c,s)|0}return r&&(n.hash=i),n},Es=(e,t,n)=>{let r=[...e.range],i=e.range[t];r[t]=n;let a=Dt(Et(e.domain,r),e.functionClass);a.writtenKeys=e.writtenKeys;let o=e.hash!==0&&e.hash!==Ps;if(!o&&e.fingerprint===0)return a;let s=ws(n);if(s===0||s===Ps)return a;if(o){let r=Us(e.domain[t]);a.hash=i===n?e.hash:e.hash-Ns(r,Us(i))+Ns(r,s)|0}if(e.fingerprint!==0){let r=e.domain[t];a.fingerprint=i===n?e.fingerprint:e.fingerprint-qs(r,i)+qs(r,n)|0}return a},Ds=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Os=(e,t)=>Math.imul(e^t,16777619),ks=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Ds(t)},As=1940243425,js=1725019383,Ms=e=>Ds(e+2654435769|0),Ns=(e,t)=>Ds(Math.imul(e,668265261)+t|0),Ps=795548749,Fs=e=>e===Ps,Is=e=>{if(e instanceof C)return ne(e);if(e.kind===`Set`){let t=e.elements,n=As;for(let e=0;e<t.length;e++){let r=Us(t[e]);if(r===Ps)return Ps;n=n+Ms(r)|0}return n}let t=js;for(let n=0;n<e.domain.length;n++){let r=Us(e.domain[n]),i=Us(e.range[n]);if(r===Ps||i===Ps)return Ps;t=t+Ns(r,i)|0}return t},Ls=e=>{let t=e.low+Wa(e.low,e.high),n=As;for(let r=e.low;r<t;r++)n=n+Ms(Us(r))|0;return n},Rs=e=>new t.D(`TLC has found a state in which the value of a variable contains ${_(U(e))}`),zs=e=>{typeof e==`object`&&e.kind!==`ModelValue`&&wn(e,()=>{if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw Rs(e);if(j(e)){for(let t of L(e).elements)zs(t);return}let t=V(e);for(let[e,n]of t.domain.entries())zs(n),zs(t.range[e])})},Bs=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{Us(e)===Ps&&zs(e);return}catch(e){if(!(e instanceof t.D))throw e;return e}},Vs=e=>{let n=z.sets,r=[];z.sets=r;try{zs(e)}catch(e){if(!(e instanceof t.D))throw e}finally{z.sets=n}return r},Hs=e=>Ds(e^1540483477),Us=e=>{if(typeof e==`number`)return Hs(e);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return ks(e);if(e.kind===`Set`||e.kind===`Function`)return e.kind===`Set`&&(e.flags|=1),e.hash===0&&(e.hash=Is(e),e.hash!==Ps&&(e.flags|=4)),e.hash;if(e.kind===`ModelValue`)return e.hash;if(e.kind===`LazyFunction`)return Pr(e.domain)?Us(V(e)):Ps;if(e.kind===`Interval`)return Ls(e);if(!Pr(e))return Ps;let t=pi(e),n=t?gi(t,!0,L):L(e);return zt(e),Us(n)},Ws=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},Gs=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return Ws(t)},Ks=e=>Ws(Zs(e)+2135587861|0),qs=(e,t)=>Ws(Math.imul(Zs(e),374761393)+Zs(t)|0),Js=461845907,Ys=e=>{if(e.kind===`Set`){let t=e.elements,n=Js;for(let e=0;e<t.length;e++)n=n+Ks(t[e])|0;return n}let t=1291169091;for(let n=0;n<e.domain.length;n++)t=t+qs(e.domain[n],e.range[n])|0;return t},Xs=e=>{let t=e.low+Wa(e.low,e.high),n=Js;for(let r=e.low;r<t;r++)n=n+Ks(r)|0;return n},Zs=e=>typeof e==`number`?Ws(e^1759714724):typeof e==`boolean`?e?1000000007:521288629:typeof e==`string`?Gs(e):e.kind===`Set`||e.kind===`Function`?(e.fingerprint===0&&(e.fingerprint=Ys(e)),e.fingerprint):e.kind===`ModelValue`?e.fingerprint:e.kind===`LazyFunction`?Zs(V(e)):e.kind===`Interval`?Xs(e):Pr(e)?Zs(L(e)):Gs(Qs(e)),Qs=e=>typeof e==`boolean`?e?`T`:`F`:typeof e==`number`?String(e):typeof e==`string`?JSON.stringify(e):$s(e),$s=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${Qs(e.base)}>`;if(e.kind===`FilteredSet`&&!Pr(e))throw new t.D(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(j(e))return Pr(e)?`{${L(e).elements.map(Qs).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let n=V(e);return`(${n.domain.map((e,t)=>`${Qs(e)}:${Qs(n.range[t])}`).join(`,`)})`},ec={'"':`\\"`,"\\":`\\\\`," ":`\\t`,"\n":`\\n`,"\f":`\\f`,"\r":`\\r`},tc=e=>`"${e.replace(/["\\\t\n\f\r]/g,e=>ec[e])}"`,nc=1999,rc=e=>e.reduce((e,t)=>e===0?0:e*R(t),1),ic=e=>{let t=pi(e);return t?gi(t,!1,fi):fi(e)},ac=e=>{if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return ic(e);if(e.cost?.charges?.chargePrintedSize(e),e.kind===`Subset`)return R(e.base)>6?void 0:ic(e);if(e.kind===`FunctionSet`){let t=La(e.domain)?0:R(e.domain);return(t===0?1:R(e.range)**t)<=nc?ic(e):void 0}return rc(e.kind===`RecordSet`?e.sets:e.factors)<=nc?ic(e):void 0},oc=(e,n)=>{if(n||e.kind===`Subset`&&me(e.base)&&(e.base.kind===`Function`||Pr(e.base.domain)))return ac(e);let r=no();try{return ac(e)}catch(e){if(!(e instanceof t.D))throw e;ro(r);return}},H=(e,t)=>{e.pending===void 0?e.parts.push(t):e.pending.push(t)},sc=(e,t)=>{e.pending===void 0?t?.pop():e.pending.push({kind:`SetEnd`,sets:t})},cc=(e,t,n,r)=>{let i=[{kind:`Value`,value:t,isStrict:n,isNormalized:r}];e.pending=i;for(let t=i.pop();t!==void 0;t=i.pop()){if(typeof t==`string`){e.parts.push(t);continue}if(t.kind===`SetEnd`){t.sets?.pop();continue}let n=i.length;Ec(e,t.value,t.isStrict,t.isNormalized);for(let e=n,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}e.pending=void 0},lc=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?cc(e,t,n,r):(e.depth++,Ec(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isStrict:n,isNormalized:r})},uc=(e,t,n,r,i)=>{for(let a=0;a<t.length;a++)a>0&&H(e,n),lc(e,t[a],r,i)},dc=/* @__PURE__ */ new Set([`Set`,`MixedSet`,`Interval`,`Subset`,`FunctionSet`,`RecordSet`,`ProductSet`,`SetOperation`,`FilteredSet`,`Union`]),fc=e=>!ze&&typeof e==`object`&&dc.has(e.kind),pc=(e,t,n,r)=>{r&&H(e,`(`),lc(e,t,n,!1),r&&H(e,`)`)},mc=(e,t,n)=>{switch(t.kind){case`Subset`:return H(e,`SUBSET `),pc(e,t.base,n,typeof t.base==`object`&&(t.base.kind===`Interval`||t.base.kind===`SetOperation`));case`FunctionSet`:return H(e,`[`),lc(e,t.domain,n,!1),H(e,` -> `),lc(e,t.range,n,!1),H(e,`]`);case`RecordSet`:H(e,`[`);for(let r=0;r<t.names.length;r++)H(e,`${r>0?`, `:``}${t.names[r]}: `),lc(e,t.sets[r],n,!1);return H(e,`]`);case`ProductSet`:return H(e,`(`),uc(e,t.factors,` \\X `,n,!1),H(e,`)`);case`SetOperation`:return pc(e,t.left,n,fc(t.left)),H(e,` ${t.operator} `),pc(e,t.right,n,fc(t.right));case`FilteredSet`:return H(e,t.source?`{${t.source.names} \\in `:`{x \\in `),lc(e,t.base,n,!1),H(e,t.source?` : <expression ${t.source.predicate}> }`:` : ...}`);case`Union`:return H(e,`UNION(`),lc(e,t.base,n,!1),H(e,`)`)}},hc=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),gc=e=>{if(!Pr(e.domain))return;let n=no();try{return V(e)}catch(e){if(!(e instanceof t.D)&&!t.wt(e))throw e;ro(n);return}},_c=(e,t,n)=>{t.kind===`Set`?ie(t,!0):L(t),n&&e.copies.push(t)},vc=(e,t,n,r,i)=>{let a=r?t.writtenKeys:void 0;if(!i){t.writtenKeys=a;return}let o=e.copies.splice(e.copies.length-t.range.length),s=t.domain.every(ja),c=s?t.domain:[...t.domain];s||Tn(c,o);let l={...t,domain:c,range:o,writtenKeys:a};e.copies.push(n?{...n,enumerated:l}:l)},yc=(e,t,n)=>{e.pending===void 0?_c(e,t,n):e.pending.push({kind:`SetEnd`,value:t,isCopied:n})},bc=(e,t,n,r,i)=>{e.pending===void 0?vc(e,t,n,r,i):e.pending.push({kind:`FunctionEnd`,value:t,lazy:n,isWrittenOrderKept:r,isCopied:i})},xc=(e,t,n,r)=>{let i=[{kind:`Value`,value:t,isWrittenOrderKept:n,isCopied:r}];e.pending=i;for(let t=i.pop();t!==void 0;t=i.pop()){if(t.kind===`SetEnd`){_c(e,t.value,t.isCopied);continue}if(t.kind===`FunctionEnd`){vc(e,t.value,t.lazy,t.isWrittenOrderKept,t.isCopied);continue}let n=i.length;wc(e,t.value,t.isWrittenOrderKept,t.isCopied);for(let e=n,t=i.length-1;e<t;e++,t--){let n=i[e];i[e]=i[t],i[t]=n}}e.pending=void 0},Sc=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?xc(e,t,n,r):(e.depth++,wc(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isWrittenOrderKept:n,isCopied:r})},Cc=(e,t,n,r)=>{for(let i=0;i<t.length;i++)Sc(e,t[i],n,r)},wc=(e,t,n,r)=>{if(typeof t==`object`)switch(t.kind){case`Set`:case`MixedSet`:return Cc(e,t.elements,n,!1),yc(e,t,r);case`Function`:return Cc(e,t.range,n,r),bc(e,t,void 0,n,r);case`LazyFunction`:if(t.enumerated)return Cc(e,t.enumerated.range,!0,r),bc(e,t.enumerated,t,!0,r);Sc(e,t.domain,n,!1),r&&e.copies.push({...t});return;case`SetOperation`:Sc(e,t.left,n,!1),Sc(e,t.right,n,!1);break;case`FunctionSet`:Sc(e,t.domain,n,!1),Sc(e,t.range,n,!1);break;case`RecordSet`:Cc(e,t.sets,n,!1);break;case`ProductSet`:Cc(e,t.factors,n,!1);break;case`Subset`:case`Union`:case`FilteredSet`:case`SequenceSet`:Sc(e,t.base,n,!1)}r&&e.copies.push(t)},Tc=e=>{let t={depth:0,pending:void 0,copies:[]};for(let n of e)wc(t,n,!1,!0);return t.copies.map(e=>U(e,!0,!0))},Ec=(e,t,n,r)=>{if(typeof t==`boolean`)return H(e,t?`TRUE`:`FALSE`);if(typeof t==`number`)return H(e,String(t));if(typeof t==`string`)return H(e,tc(t));switch(t.kind){case`ModelValue`:return H(e,t.name);case`Set`:return H(e,`{`),uc(e,t.elements,`, `,n,r),H(e,`}`);case`MixedSet`:return lc(e,L(t),n,r);case`Interval`:return H(e,t.low<=t.high?`${t.low}..${t.high}`:`{}`);case`InfiniteSet`:return H(e,t.name===`Any`?`ANY`:t.name);case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:case`SetOperation`:case`FilteredSet`:case`Union`:{let i=z.sets;i?.push(t);let a=Be.isExpanded?oc(t,n):void 0;return a?lc(e,a,n,r):mc(e,t,n),sc(e,i)}case`SequenceSet`:return H(e,`Seq(`),lc(e,t.base,n,r),H(e,`)`);case`Function`:case`LazyFunction`:{let i=t.kind===`LazyFunction`?Be.isExpanded||!t.source?gc(t):void 0:t;if(i===void 0){let n=t.kind===`LazyFunction`?t.source:void 0;if(!n)return H(e,`<function>`);H(e,`[`);for(let t=0;t<n.parameters.length;t++){let r=n.parameters[t];H(e,`${t>0?`, `:``}${r.name} \\in `),lc(e,r.domain,!1,!1)}return H(e,` |-> <expression ${n.body}>]`)}if(i.domain.length===0&&ze&&Ot(t)!==`tuple`)return H(e,`<< >>`);if(i.domain.length===0&&Ot(t)===`record`)return H(e,`[]`);let a=r&&Ot(t)!==`lambda`;if(Xa(i.domain))return i.range.every(e=>typeof e==`number`)?H(e,`<<${i.range.join(`, `)}>>`):(H(e,`<<`),uc(e,i.range,`, `,n,a),H(e,`>>`));let o=r?i.domain.map((e,t)=>[e,i.range[t]]):xe(i);if(Ot(t)===`record`||i.domain.every(e=>typeof e==`string`&&hc(e))){H(e,`[`);for(let t=0;t<o.length;t++)H(e,`${t>0?`, `:``}${String(o[t][0])} |-> `),lc(e,o[t][1],n,a);return H(e,`]`)}H(e,`(`);for(let t=0;t<o.length;t++)t>0&&H(e,` @@ `),lc(e,o[t][0],n,r),H(e,` :> `),lc(e,o[t][1],n,a);return H(e,`)`)}case`Operator`:return H(e,t.javaClass===`MethodValue`?`<Java Method: ${t.signature}>`:`<Operator ${t.name}>`)}},U=(e,t=!1,n=!1)=>{let r={parts:[],depth:0,pending:void 0};return Ec(r,e,t,n),r.parts.join(``)},Dc=(e,n)=>{if(e===void 0)return!1;try{return Bt(e,n)}catch(r){if(r instanceof t.D)return e===n;throw r}},Oc=/%(\d+\$)?([-#+ 0,(<]*)(\d+)?(\.\d+)?(.?)/gs,kc=(e,t)=>{let r=0,i=-1,a=!0,o=e.replace(Oc,(e,o,s=``,c,l,u=``)=>{let d=e=>s.includes(`-`)?e.padEnd(Number(c)):e.padStart(Number(c??0)),f=s.includes(`<`),p=s.replace(`<`,``);if(u===`n`&&e===`%n`)return`
|
|
10
10
|
`;if(u===`%`&&l===void 0&&/^-?$/.test(p))return p===`-`&&c===void 0&&(a=!1),d(`%`);let m=f?i:o===void 0?r++:Number(o.slice(0,-1))-1;i=m;let h=t[m];if(!`sSbBhH`.includes(u)||u===``||!/^-?$/.test(p)||p===`-`&&c===void 0||h===void 0)return a=!1,e;let g=u.toLowerCase(),_=g===`s`?h:g===`b`?`true`:(n.xn(h)>>>0).toString(16),v=d(l===void 0?_:_.slice(0,Number(l.slice(1))));return u===g?v:v.toUpperCase()});return a?o:void 0},Ac=(e,n)=>{let r=n?void 0:Ue.get(e);if(r)return r();let i=Object.entries(e),a=Ge.get(e),o=a!==void 0&&`_format`in e,s=o?e._format:i.length===1?`%s = %s
|
|
11
11
|
`:`/\\ %s = %s
|
|
12
12
|
`;if(typeof s!=`string`)throw new t.x(`The _format field of the ALIAS ${a} is ${U(s)}, but it must be a string.`);return i.filter(e=>!(o&&e[0]===`_format`)).filter(e=>!n||e[0]===`_ALIASEvalError`||!Dc(n[e[0]],e[1])).map(e=>{let n=kc(s,[e[0],_(U(e[1]))]);if(n===void 0)throw new t.x(`The _format field of the ALIAS ${a} is ${U(s)}, but it must format two strings, the name and the value of a field.`);return n}).join(``)},jc=(e,t,n)=>{let r=Ac(e,t);for(let e of n)Fn(e);return r},Mc=e=>r.x(()=>Ac(e)),Nc=[10454148508367108822n,15747411856486957441n,13848313129918172575n,15427004735118145554n,14338780731064426356n,15931650522396165332n,17670238537108149059n,12816660938095048951n,13192168525635896882n,16119298732711755075n,13564417994159519395n,15831473429641889162n,17671735485712653535n,14582471876431321160n,9288673424107444897n,12345523232675890545n,13774063780198914517n,10636128657019767374n,13227535641082688945n,10085966873248490402n,17056045221983369811n,18027133543548002442n,13033986364717636900n,12663388180492401538n,11007194744055901935n,16251515628090973732n,18046429724439772544n,9876734796024595817n,14949643787442512870n,16960057143726945461n,10590203213448744021n,12248592797044284137n,9558805810925624286n,16993321702164258530n,11754329512098378960n,12074934892440206921n,15696745233288286746n,10531590977001201739n,18107999685377398317n,12149369488538049728n,12923655455904407421n,10507099144397364930n,17322088528956367024n,14653973644796244054n,15165509594857513400n,13554280709034297251n,16228911470502883382n,17115369786458865383n,11179220607102683830n,16708422618246866334n,12295941796329322556n,18336630348474106240n,13989616001589685348n,14822072159597151759n,14264172520427195041n,11642530518213145397n,11877331515501935358n,13913116192159715440n,17054474839259161580n,13461230878584418056n,16058025410470398786n,11100471369705097435n,11133782763824505275n,13192312712502684421n,17456091706045076157n,13237272598629075916n,12914531898895761383n,15801841604014567326n,16446055517513626294n,16780923767715884464n,15104658705803254918n,10882049990920163451n,12728112724252049190n,11720209067562733740n,16476221075563830086n,16602801460297162326n,16206898064012585915n,12158475401238648099n,13742285336487677729n,15543703592025073839n,9615783578189153721n,16710542608962839044n,11960730242263336692n,13328718558362718101n,12971616006464047952n,17057853503483465676n,16180230282101315295n,15483523553568578902n,17773465781871025571n,18047252642493037509n,11580640560664688668n,10121963531818974651n,14218267149826330657n,12715294421139777506n,10584764766358778171n,12666843443693621286n,17403948736867619210n,17907955559063099692n,15179434392748515198n,15413469521140985247n,13455040338347572751n,15419348191054617477n,12340568220039846914n,13236419189535069162n,18074463254581147189n,10818750974828329405n,9859349269386152082n,15035006154709018396n,13627907273947709876n,9549035931546940138n,16199589727945564820n,10285831968679942330n,17737018494601061698n,15477896647372134857n,13595764249822586512n,10556855812148546550n,12421897615105552821n,15477767459253848096n,17421607461439241175n,12409061346569762725n,13621778224251023638n,10680972825126675886n,16494492050207190715n,16801324317763555620n,12664650400804916358n,16134230614391269483n,10027806175083075147n,9259037851175017999n,11803214621941906429n,9537357587847606069n,10517495000576890277n],Pc=/* @__PURE__ */ new Int32Array(256),Fc=/* @__PURE__ */ new Int32Array(256),Ic=/* @__PURE__ */ new Int32Array(256),Lc=/* @__PURE__ */ new Int32Array(256),Rc=/* @__PURE__ */ new Int32Array(256),zc=/* @__PURE__ */ new Int32Array(256),Bc=/* @__PURE__ */ new Int32Array(256),Vc=/* @__PURE__ */ new Int32Array(256);let Hc=0,Uc=0;const Wc=()=>BigInt(Pc[128]>>>0)<<32n|BigInt(Rc[128]>>>0),Gc=e=>{let t=(e^Uc)&255;Uc=(Uc>>>8|Hc<<24)^Rc[t],Hc=Hc>>>8^Pc[t]},Kc=e=>{let t=Nc[e],n=[];for(let e=1n<<63n;n.length<72;)n.push(e),e=e>>1n^((e&1n)==0n?0n:t);let r=n.slice(64,72).reverse();for(let e=0;e<256;e++){let t=r.reduce((t,n,r)=>e>>r&1?t^n:t,0n);Pc[e]=Number(BigInt.asIntN(32,t>>32n)),Rc[e]=Number(BigInt.asIntN(32,t))}let i=[Pc,Fc,Ic,Lc],a=[Rc,zc,Bc,Vc];for(let e=1;e<4;e++){let t=i[e-1],n=a[e-1];for(let r=0;r<256;r++){let o=n[r]&255;a[e][r]=(n[r]>>>8|t[r]<<24)^Rc[o],i[e][r]=t[r]>>>8^Pc[o]}}};Kc(0);const qc=e=>{let t=Uc^e,n=t&255,r=t>>>8&255,i=t>>>16&255,a=t>>>24;Uc=Hc^Vc[n]^Bc[r]^zc[i]^Rc[a],Hc=Lc[n]^Ic[r]^Fc[i]^Pc[a]},Jc=e=>{if(typeof e==`boolean`)return Gc(0),Gc(e?116:102),2;if(typeof e==`number`)return Gc(1),qc(e),5;if(typeof e==`string`){Gc(3),qc(e.length);let t=e.length&-4;for(let n=0;n<t;n+=4)qc(e.charCodeAt(n)&255|(e.charCodeAt(n+1)&255)<<8|(e.charCodeAt(n+2)&255)<<16|(e.charCodeAt(n+3)&255)<<24);for(let n=t;n<e.length;n++)Gc(e.charCodeAt(n));return 5+e.length}return Gc(21),qc(Ze(e.name)+1),5},Yc=e=>{let t=Hc,n=Uc;Hc=0,Uc=0;let r=[sl(e),Hc,Uc];return Hc=t,Uc=n,r},Xc=e=>`m = (${e} ^ l) & 255; l = ((l >>> 8) | (h << 24)) ^ L0[m]; h = (h >>> 8) ^ H0[m];`,Zc=e=>`m = l ^ ${e}; l = h ^ L3[m & 255] ^ L2[(m >>> 8) & 255] ^ L1[(m >>> 16) & 255] ^ L0[m >>> 24]; h = H3[m & 255] ^ H2[(m >>> 8) & 255] ^ H1[(m >>> 16) & 255] ^ H0[m >>> 24];`,Qc=e=>`m = l; g = h; l = ${e}[m & 255] ^ ${e}[256 | ((m >>> 8) & 255)] ^ ${e}[512 | ((m >>> 16) & 255)] ^ ${e}[768 | (m >>> 24)] ^ ${e}[1024 | (g & 255)] ^ ${e}[1280 | ((g >>> 8) & 255)] ^ ${e}[1536 | ((g >>> 16) & 255)] ^ ${e}[1792 | (g >>> 24)]; h = ${e}[2048 | (m & 255)] ^ ${e}[2304 | ((m >>> 8) & 255)] ^ ${e}[2560 | ((m >>> 16) & 255)] ^ ${e}[2816 | (m >>> 24)] ^ ${e}[3072 | (g & 255)] ^ ${e}[3328 | ((g >>> 8) & 255)] ^ ${e}[3584 | ((g >>> 16) & 255)] ^ ${e}[3840 | (g >>> 24)];`,$c=e=>`{ let r = ${e}; for (; r >= 4; r -= 4) { ${Zc(`0`)} } for (; r > 0; r--) { ${Xc(`0`)} } }`,el={integer:e=>`${Xc(`1`)} ${Zc(e)}`,boolean:e=>`${Xc(`0`)} ${Xc(`(${e} ? 116 : 102)`)}`,set:e=>`${Xc(`5`)} ${Zc(e)}`,function:e=>`${Xc(`9`)} ${Zc(e)}`,scalar:(e,t,n)=>`${$c(e)} h ^= ${t}; l ^= ${n};`,scalarRun:(e,t,n)=>`{ const z = ${e}; ${Qc(`z`)} } h ^= ${t}; l ^= ${n};`,scalarLookup:(e,t,n)=>`{ const z = Z[${e}]; if (z.length !== 0) { ${Qc(`z`)} } else ${$c(e)} } h ^= ${t}; l ^= ${n};`},tl=(e,t)=>{let n=/* @__PURE__ */ new Int32Array,r=Array.from({length:t+1},()=>n),i=[Rc],a=[Pc];for(let t of e){for(;i.length<t;){let e=i[i.length-1],t=a[a.length-1],n=/* @__PURE__ */ new Int32Array(256),r=/* @__PURE__ */ new Int32Array(256);for(let i=0;i<256;i++){let a=e[i]&255;n[i]=(e[i]>>>8|t[i]<<24)^Rc[a],r[i]=t[i]>>>8^Pc[a]}i.push(n),a.push(r)}let e=/* @__PURE__ */ new Int32Array(4096);for(let n=0;n<8;n++)e.set(i[t-1-n],n*256),e.set(a[t-1-n],2048+n*256);r[t]=e}return r},nl=()=>({H0:Pc,H1:Fc,H2:Ic,H3:Lc,L0:Rc,L1:zc,L2:Bc,L3:Vc,initialHigh:Pc[128],initialLow:Rc[128]}),rl=(e,t)=>{let n=Hc,r=Uc;Uc=e[0],Hc=e[1],sl(t),e[0]=Uc,e[1]=Hc,Hc=n,Uc=r},il=e=>{Gc(5),qc(e)},al=e=>{Gc(9),qc(e)},ol=e=>{if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw Rs(e);return L(e)},sl=e=>{if(typeof e!=`object`||M(e))return Jc(e);if(me(e)){let t=V(e);t.writtenKeys!==void 0&&(t.writtenKeys=void 0),al(t.domain.length);let n=5;for(let e=0;e<t.domain.length;e++)n+=sl(t.domain[e]),n+=sl(t.range[e]);return n}if(e.kind===`Interval`){let t=Wa(e.low,e.high);il(t);let n=e.low+t,r=5;for(let t=e.low;t<n;t++)r+=Jc(t);return r}let t=e.kind===`Set`?e:ol(e);re(t)||ie(t,!0);let n=t.elements;il(n.length);let r=5;for(let e of n)r+=sl(e);return r},cl=e=>{let t=Hc,n=Uc;Hc=Pc[128],Uc=Rc[128];for(let t of e)sl(t);let r=BigInt(Hc>>>0)<<32n|BigInt(Uc>>>0);return Hc=t,Uc=n,r},ll=(e,t)=>{let n=new BigInt64Array(e),r=new Int32Array(n.buffer),i=Hc,a=Uc;for(let n=0;n<e;n++)Hc=Pc[128],Uc=Rc[128],t(n),r[2*n]=Uc,r[2*n+1]=Hc;return Hc=i,Uc=a,n},ul=(e,t)=>ll(e.length,n=>{for(let r of t)sl(e[n][r])}),dl=/* @__PURE__ */ new WeakMap,fl=(e,t)=>{for(let n=t;n;n=n.parent)if(n.name===e)return dl.get(n)},pl=/* @__PURE__ */ new Set([`FiniteSets`,`Sequences`,`Bags`,`Naturals`,`Integers`,`Reals`,`RealTime`,`Randomization`,`TLC`]),ml=1024,hl=e=>{let t={current:-1,expressions:[],ranges:[],firstChild:[],lastChild:[],nextSibling:[],prefixes:[],isPart:[],isPrimed:[],isUnchanged:[],recursive:[],twins:[],lets:[],appliedBodies:[],children:[],roots:[],primary:[],secondary:[],costModels:[],covered:/* @__PURE__ */ new WeakSet,values:/* @__PURE__ */ new WeakMap,registers:new Uint8Array(e*ml),relations:[],substitutionNodes:/* @__PURE__ */ new Map,frames:[],hiddenFrames:[],nextState:`given`,isMember:B,convertCharged:(e,t,n)=>t(e,n),chargeSubsetElements:()=>{},chargePrintedSize:()=>{},chargeIsEmpty:()=>{}};return t.isMember=Au(t),t.convertCharged=(e,n,r)=>vu(t,e,n,r),t.chargeSubsetElements=e=>xu(t,e),t.chargePrintedSize=e=>Su(t,e),t.chargeIsEmpty=e=>yu(t,e),t},gl=(e,t)=>({...e,evaluators:/* @__PURE__ */ new WeakMap,entryEvaluators:/* @__PURE__ */ new WeakMap,definitionEvaluators:/* @__PURE__ */ new WeakMap,coverage:t}),_l=(e,t)=>{if(!e)return t();let n=e.primary.slice(),r=e.secondary.slice();try{return t()}finally{Object.assign(e.primary,n),Object.assign(e.secondary,r)}},vl=(e,t,n,r,i)=>{let a=e.expressions.length;if(e.expressions.push(t),e.ranges.push(n),e.firstChild.push(-1),e.lastChild.push(-1),e.nextSibling.push(-1),e.prefixes.push(-1),e.isPart.push(i),e.isPrimed.push(!1),e.isUnchanged.push(t?.kind===`Unchanged`),e.recursive.push(-1),e.twins.push(-1),e.lets.push(void 0),e.appliedBodies.push(void 0),e.children.push(void 0),e.roots.push(r===-1?a:e.roots[r]),e.primary.push(0),e.secondary.push(0),e.costModels.push({secondary:e.secondary,node:a}),t&&e.covered.add(t),r===-1)return a;let o=e.lastChild[r];return o===-1&&(e.firstChild[r]=a),o!==-1&&(e.nextSibling[o]=a),e.lastChild[r]=a,a},yl=(e,t,n)=>e.relations.find(e=>e.kind===t&&e.expression===n)?.node,bl=e=>e.location.range??(e.kind===`Let`?e.body.location.range:void 0),xl=(e,t,n,r,i)=>{let a=t===`next`?yl(e,t,r):void 0;if(a!==void 0)return a;let o=vl(e,void 0,bl(r),-1,!1);return e.relations.push({kind:t,label:n,expression:r,scope:i,node:o}),o},Sl=(e,t)=>e!==void 0&&t!==void 0&&e.module===t.module&&e.start.line===t.start.line&&e.start.column===t.start.column&&e.end.line===t.end.line&&e.end.column===t.end.column,Cl=e=>n.$(e).location.range??e.location.range,wl=(e,r,a,o,c)=>{let l=e===void 0||o?void 0:i(e,a),u=l===void 0?void 0:a.substitutions.get(l)??l,d=u===void 0?void 0:a.definitions.get(u),f=o??(d?.kind===`Operator`?d.head:void 0),p=bl(r),m=Cl(r)??p,h=o?e:u===void 0?void 0:a.instanceNames.get(u)??d?.name;if(h===void 0||!f){let e=n.$(r);return e.kind===`Number`?`Action ${s(e)}`:`Action ${m?t.gt(m):`Unknown location`}`}return(o?Sl(c,Cl(r)):d&&Sl(bl(d.body),p))||!m?`${h} ${t.gt(f)}`:`${h} ${t.gt(f)} (${m.start.line} ${m.start.column} ${m.end.line} ${m.end.column})`},Tl=e=>`${e.module}:${e.start.line}:${e.start.column}:${e.end.line}:${e.end.column}`,El=(e,t)=>e&&t?{module:e.module,start:e.start,end:t.end}:void 0,Dl=(e,t)=>t&&{module:t.module,start:e.range?.start??{line:e.line,column:e.column},end:t.end},Ol=e=>{let t=Array.from({length:11},()=>[]);for(let r=0;r<e.length;r++){let i=e[r];if(r>=Math.floor(t.length*.75)){let e=Array.from({length:t.length*2+1},()=>[]);for(let r=t.length-1;r>=0;r--)for(let i of t[r])e[(n.xn(i.name)&2147483647)%e.length].unshift(i);t=e}t[(n.xn(i.name)&2147483647)%t.length].unshift(i)}return t.toReversed().flat()},kl=e=>e.flatMap((t,n)=>n>0&&e[n-1].set===t.set?[]:[t.set]),Al=(e,t,n)=>e.reduce((e,t,r)=>({name:t,definition:void 0,scope:void 0,operatorBody:n?.[r],parent:e}),t),jl=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n},Ml=(e,t)=>{let n=e.reduce((e,t)=>({name:t.name,definition:t,scope:void 0,operatorBody:void 0,parent:e}),t);for(let e=n;e!==t&&e;e=e.parent)e.scope=n;return n},Nl=e=>e.flatMap(e=>e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names),Pl=e=>n.vt.get(e)?.find(e=>!n.Q.has(e))?.location.range,Fl=(e,t)=>{let n=[];for(let r=e.firstChild[t];r!==-1;r=e.nextSibling[r])n.push(r);return n},Il=(e,t,n)=>{let r=/* @__PURE__ */ new Set;for(let i of n){let n=e.ranges[i],a=t.find(t=>!r.has(t)&&(e.ranges[t]===n||Sl(e.ranges[t],n)));a!==void 0&&(r.add(a),e.twins[i]=a,Il(e,Fl(e,a),Fl(e,i)))}},Ll=(e,t)=>(n.vt.get(e)??[]).filter(e=>n.Q.has(e)&&!t.includes(e)),Rl=(e,t,r)=>{let i=new Set(r.map(Tl)),a=[],o=[],s=[],c=[],l=/* @__PURE__ */ new Map,u=/* @__PURE__ */ new Map,d,f=(e,r,i)=>{if(n.fr(e)){let e=jl(i,r);return e?.definition&&{definition:e.definition,scope:e.scope}}let a=t.substitutions.get(r)??r;if(t.variableIndex.has(a)||t.constants.has(a))return;let o=t.definitions.get(a),s=o?.location.range?.module??o?.body.location.range?.module;return o&&!pl.has(s??``)?{definition:o,scope:void 0}:void 0},p=(t,n,r,o=!1,c)=>{let f=vl(e,t,n,a.at(-1)??-1,o);if(t)for(let n=a.length-1;n>=0;n--){let r=e.children[a[n]]??=/* @__PURE__ */ new Map;if(r.has(t)||r.set(t,f),!e.isPart[a[n]])break}e.isPrimed[f]=n!==void 0&&i.has(Tl(n));let p=t===d?void 0:t&&u.get(t);for(let n of p??[]){let r=e.appliedBodies[n]??=[],i=r.find(n=>e.expressions[n.node]===t);i?i.node=f:r.push({after:e.lastChild[n],node:f})}let m=t&&l.get(t);if(m)for(let t=0;t<a.length;t++){let n=a[t];e.expressions[n]===m&&(e.lets[n]??=[]).push(f)}if(c?.kind===`Operator`&&c.isRecursive){let t=a.findLast(e=>s[e]===c);t!==void 0&&(e.recursive[f]=t)}return s[f]=c,a.push(f),r(f),a.pop(),f},m=(e,t)=>{let r=e.definition;if(c.includes(r))return;c.push(r);let i=r.kind===`Function`?Nl(r.bounds):r.params.map(e=>e.name);r.kind===`Function`?p(n.cr(r),r.location.range,()=>{b(r.body,Al(i,e.scope));for(let t of kl(r.bounds))b(t,e.scope)}):b(r.body,Al(i,e.scope,t)),c.pop()},h=e=>e?.definition.kind===`Operator`&&e.definition.params.length>0,g=(e,t)=>{if(e.kind===`Lambda`)return e.body;if(e.kind!==`Identifier`)return;let r=f(e,e.name,t)?.definition;return r?.kind!==`Operator`||r.params.length===0?n.fr(e)?jl(t,e.name)?.operatorBody:void 0:n.$(r.body)===r.body?r.body:void 0},_=(e,r,i,a)=>{if(e.kind===`Lambda`)b(e.body,Al(e.params,a));else{if(e.kind===`Identifier`){let o=f(e,e.name,a);if(i?.kind===`Operator`&&(i.params[r]?.arity??0)>0||h(o)){if(!o)return;let r=d;!n.fr(e)&&t.substitutions.has(e.name)&&(d=o.definition.body),m(o),d=r;return}}b(e,a)}},v=(t,n,r,i)=>p(n===t.operands.length?t:void 0,r,()=>{let o=t.operands;if(n>2&&!t.isBulleted){let s=t.prefixEnds?.[n-3],c=v(t,n-1,r&&s?{...r,end:s}:r,i);e.prefixes[a.at(-1)??-1]=c,b(o[n-1],i)}else for(let e of o.slice(0,n))b(e,i)},n<t.operands.length),y=(t,r)=>{let i=Ll(t,o),s=a.at(-1)??-1;for(let t of i){for(let i of n.Q.get(t)?.()??[]){b(i.replacement,r);let t=s===-1?-1:e.lastChild[s];if(t===-1||e.expressions[t]!==i.replacement)continue;let n=e.roots[t],a=e.substitutionNodes.get(n)??/* @__PURE__ */ new Map;e.substitutionNodes.set(n,a.set(i,t))}o.push(t)}return i.length},b=(e,t)=>{let n=y(e,t);x(e,t),o.length-=n},x=(r,i)=>{let a=r.location.range,s=e=>{for(let t of e)b(t,i)},c=n._t.get(r);if(c&&c.replacement!==r)p(r,Pl(r),()=>void 0);else switch(r.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:case`Bracket`:case`Subexpression`:case`OperatorReference`:return;case`Label`:case`Lambda`:b(r.body,Al(r.params,i));return;case`EnabledVariable`:{let e=y(r.substitution,i);p(r,Pl(r.substitution),()=>void 0),o.length-=e;return}case`Selection`:a===void 0?b(r.expression,i):p(r,a,()=>b(r.expression,i));return;case`Let`:{let a=Ml(r.definitions,i);for(let e of r.definitions)(e.kind===`Operator`||e.kind===`Function`)&&l.set(n.lr(e),r.body);if(!t.boundSubstitutions.lets.has(r)){let t=[];for(let i of Ol(r.definitions)){if(i.name===`LAMBDA`||n.ut(i))continue;let r=e.expressions.length;if(m({definition:i,scope:a}),!n.Kt(i))continue;let o=[];for(let t=r;t!==-1&&t<e.expressions.length;t=e.nextSibling[t])o.push(t);Il(e,t,o),t.push(...o.filter(t=>e.twins[t]===-1))}}b(r.body,a);return}case`Identifier`:{if(n.yt.has(r))return;let e=f(r,r.name,i),o=t.boundSubstitutions.references.has(r)||e&&n.dt(e.definition);p(r,o&&Pl(r)||a,()=>{e&&!o&&m(e)},!1,e?.definition);return}case`Apply`:{let o=f(r,r.operator,i),s=n.on.has(r)&&!r.resolution?.isSubstitute,c=n.fr(r)?jl(i,r.operator)?.operatorBody:void 0,l=()=>{if(o&&!r.hasSubstitutedOperator){let e=!n.fr(r)&&t.substitutions.has(r.operator);m(o,e?void 0:r.args.map(e=>g(e,i)))}for(let[e,t]of r.args.entries())n.yt.has(t)||_(t,e,o?.definition,i)};if(s){l();return}p(r,a,t=>{if(c){let n=u.get(c)??[];n.some(t=>Sl(e.ranges[t],a))||u.set(c,[...n,t])}l()},!1,o?.definition);return}case`And`:case`Or`:v(r,r.operands.length,a,i);return;case`Case`:p(r,a,()=>{for(let e of r.arms)p(void 0,El(e.condition.location.range,e.body.location.range),()=>s([e.condition,e.body]),!0);let e=r.other;e&&p(void 0,r.otherRange,()=>b(e,i),!0)});return;case`Record`:case`RecordSet`:p(r,a,()=>{for(let e of r.fields)p(void 0,Dl(e.location,e.value.location.range),()=>b(e.value,i),!0)});return;case`FunctionApplication`:p(r,a,()=>{b(r.function,i);let e=r.args;e.length===1?b(e[0],i):p(void 0,a,()=>s(e),!0)});return;case`Forall`:case`Exists`:case`FunctionConstruction`:p(r,a,()=>{b(r.body,Al(Nl(r.bounds),i)),s(kl(r.bounds))});return;case`SetMap`:p(r,a,()=>{b(r.expression,Al(Nl(r.bounds),i)),s(kl(r.bounds))});return;case`SetFilter`:p(r,a,()=>{b(r.predicate,Al(Nl([r.bound]),i)),b(r.bound.set,i)});return;case`Choose`:p(r,a,()=>{let e=r.pattern;b(r.body,Al(e.kind===`Name`?[e.name]:e.names,i)),r.set&&b(r.set,i)});return;case`UnboundedQuantifier`:p(r,a,()=>b(r.body,Al(r.names,i)));return;case`Except`:p(r,a,()=>{b(r.function,i);for(let e of r.updates)p(void 0,e.range,()=>{p(void 0,e.range,()=>{for(let t of e.path)t.kind===`Index`&&(t.args.length===1?s(t.args):p(void 0,t.tupleRange,()=>s(t.args),!0))},!0),b(e.value,i)},!0)});return;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:p(r,a,()=>b(r.expression,i));return;case`If`:p(r,a,()=>s([r.condition,r.consequent,r.alternative]));return;case`SetEnumeration`:case`Tuple`:p(r,a,()=>s(r.elements));return;case`Product`:p(r,a,()=>s(r.factors));return;case`FunctionSet`:p(r,a,()=>s([r.domain,r.range]));return;case`FieldAccess`:p(r,a,()=>b(r.record,i));return;case`BoxAction`:case`AngleAction`:p(r,a,()=>s([r.action,r.subscript]));return;case`WeakFairness`:case`StrongFairness`:p(r,a,()=>s([r.subscript,r.action]))}},S=e=>{let t=[];for(let n=e;n;n=n.parent){let e=dl.get(n);e&&t.unshift(e)}return Ml(t,void 0)};for(let t=0;t<e.relations.length;t++){let n=e.relations[t];u.clear(),a.push(n.node),b(n.expression,S(n.scope)),a.pop()}},zl=(e,t,n)=>e.children[t]?.get(n)??e.appliedBodies[t]?.find(t=>e.expressions[t.node]===n)?.node??-1,Bl=(e,t,n)=>{if(e.expressions[t]===n)return t;let r=zl(e,t,n);if(r!==-1)return r;let i=e.recursive[t],a=i===-1?-1:zl(e,i,n);return a===-1?e.lets[t]?.findLast(t=>e.expressions[t]===n)??t:a},Vl=(e,t,n)=>Bl(e,t,n.kind===`Let`&&e.roots[t]===t?n.body:n),Hl=(e,t)=>{for(let n=t;n!==-1;n=e.prefixes[n])e.primary[n]++},Ul=(e,t,n)=>{t>=0&&e.expressions[t]===n&&Hl(e,e.lastChild[t])},Wl=(e,t,n)=>{let r=e.current;e.current=t;try{return n()}finally{e.current=r}},Gl=(e,t,n)=>{let r=new Set(e.substitutionNodes.get(e.roots[t])?.values()),i=[],a=t=>{r.has(t)||i.push(t,e.primary[t],e.secondary[t])};for(let n=-3;n<i.length;n+=3){let r=n===-3?t:i[n];for(let t=e.firstChild[r];t!==-1;t=e.nextSibling[t])a(t);for(let t of e.appliedBodies[r]??[])a(t.node)}try{return n()}finally{for(let n=0;n<i.length;n+=3){let r=i[n];e.primary[t]+=e.primary[r]-i[n+1],e.secondary[t]+=e.secondary[r]-i[n+2],e.primary[r]=i[n+1],e.secondary[r]=i[n+2]}}},Kl=(e,t,r,i)=>{let a=r<0?-1:e.roots[r],o=0;for(let r=0;r<t.length;r++){let s=t[r];n.Q.has(s)&&!ql(e,s,a)&&(e.frames.push({frame:s,root:a,isCached:i,counted:[],countedWithoutNext:[]}),o++)}return o},ql=(e,t,n)=>{for(let r=e.frames.length-1;r>=0;r--){let i=e.frames[r];if(i.frame===t&&(n===void 0||i.root===n))return i}},Jl=(e,t)=>{e.frames.length-=t},Yl=e=>e.frames.length===0?void 0:e.frames.slice(),Xl=(e,t,n,r)=>{if(!n)return Wl(e,t,r);let i=e.frames.length;e.frames.push(...n);try{return Wl(e,t,r)}finally{e.frames.length=i}},Zl=(e,t)=>{let n=e.frames,r=n.length-t;for(let r=t;r<n.length;r++)e.hiddenFrames.push(n[r]);return n.length=t,r},Ql=(e,t)=>{let n=e.hiddenFrames,r=n.length-t;for(let t=r;t<n.length;t++)e.frames.push(n[t]);n.length=r},$l=(e,t,n)=>{let r=ql(e,t.frame,void 0);if(!r)return-1;let i=e.substitutionNodes.get(r.root)?.get(t)??-1;return!r.isCached||n?i:r.countedWithoutNext.includes(t)?-1:e.nextState===`empty`?(r.countedWithoutNext.push(t),i):r.counted.includes(t)?-1:(r.counted.push(t),i)},eu=(e,t,n)=>{let r=Ui(e,t);r!==void 0&&(e.secondary[r]+=n)},tu=(e,t,n,r,i,a)=>{let o=pe(n)?n:t!==`\\`&&pe(r)?r:void 0;if(typeof i!=`object`)return i;if(o===void 0){let o=t===`\\cup`?a:void 0;return i.kind===`SetOperation`&&(o!==void 0||mi(e,n)||mi(e,r))?It(Ei(i.operator,i.left,i.right,{node:o,charges:e})):i}let s=o===n?r:n;if(t===`\\cup`){if(La(o))return i;if(!pe(s)){let t=Ui(e,o);return i.kind===`SetOperation`&&(t!==void 0||mi(e,s))?It(Ei(i.operator,i.left,i.right,{node:t,charges:e})):i}let t=Ui(e,s);t!==void 0&&(e.secondary[t]+=R(s)+1)}let c=t===`\\cup`?void 0:Ui(e,o);if(Ui(e,i)===c)return i;let l=i===n||i===r||Ui(e,i)!==void 0?{...i,costNode:void 0}:i;return c!==void 0&&e.values.set(l,c),l},nu={next:()=>!1,reset:()=>void 0},ru=(e,t,n)=>{let r=0;return{next:()=>(t!==void 0&&e.secondary[t]++,r++<n),reset:()=>{r=0}}},iu=(e,t,n,r)=>{if(r.includes(0))return nu;let i=n.map((t,n)=>pu(e,t,r[n],!1)),a=()=>{for(let e=i.length-1;e>0;e--){if(i[e].next())return!0;i[e].reset(),i[e].next()}return i.length>0&&i[0].next()},o=!i.every(e=>e.next());return{next:()=>!o&&(e.secondary[t]+=Math.max(i.length,1),o=!a(),!0),reset:()=>{for(let e of i)e.reset(),e.next();o=!1}}},au=(e,t)=>{let n=Array(e.length),r,i=0,a=!1,o=1;for(let t=0;t<e.length;t++){let s=cu(e[t]);n[t]=s??-1,s===void 0?(i>0&&e[t]!==r&&(a=!0),i===0&&(r=e[t]),i++):o*=s}if(a||i>0&&t===void 0)return;let s=i===0||o===0?0:Math.round(((t??0)/o)**(1/i));for(let e=0;e<n.length;e++)n[e]<0&&(n[e]=s);return n},ou=(e,t,n)=>{let r=Ui(e,t);if(r===void 0||typeof t!=`object`||t.kind!==`RecordSet`&&t.kind!==`ProductSet`&&t.kind!==`FunctionSet`||t.cost?.charges===void 0)return;if(t.kind===`FunctionSet`&&n===0)return yu(e,t),nu;let i=t.kind===`RecordSet`?t.sets:t.kind===`ProductSet`?t.factors:Array.from({length:ya(t)},()=>t.range),a=au(i,n);if(a===void 0)return;yu(e,t);let o=t.kind===`FunctionSet`&&!a.includes(0)?pi(t.domain):void 0;return o&&_u(e,o),iu(e,r,i,a)},su=(e,t,n)=>{if(typeof t==`object`&&(t.kind===`SetOperation`||t.kind===`Union`||t.kind===`Subset`)){let r=cu(t);if(r===void 0)return;let i=pu(e,t,r,!1);return n&&i.next(),i}let r=Ui(e,t);return r===void 0||typeof t!=`object`||t.kind!==`RecordSet`&&t.kind!==`ProductSet`&&t.kind!==`FunctionSet`||t.cost?.charges!==void 0?ou(e,t,void 0):(n&&e.secondary[r]++,ru(e,r,R(t)))},cu=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return R(e);case`Subset`:return cu(e.base)===void 0?void 0:R(e);case`FilteredSet`:return e.isCached?R(e):void 0;case`FunctionSet`:return cu(e.domain)===void 0||cu(e.range)===void 0?void 0:R(e);case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<t.length;e++)if(cu(t[e])===void 0)return;return R(e)}case`SetOperation`:{if(e.cost?.charges===void 0)return e.enumerated?.elements.length;if(e.operator!==`\\cup`){let t=qi(e);return cu(t)!==void 0&&lu(t===e.left?e.right:e.left)?ka(e).length:void 0}let t=cu(e.left),n=cu(e.right);return t===void 0||n===void 0?void 0:t+n}case`Union`:{if(e.cost?.charges===void 0)return e.enumerated?.elements.length;if(cu(e.base)===void 0)return;let t=ka(e.base),n=0;for(let e=0;e<t.length;e++){let r=cu(t[e]);if(r===void 0)return;n+=r}return n}default:return}},lu=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`Subset`:return lu(e.base);case`FilteredSet`:return e.isCached===!0;case`FunctionSet`:return lu(e.domain)&&lu(e.range);case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<t.length;e++)if(!lu(t[e]))return!1;return!0}case`SetOperation`:return!e.isCached&&lu(e.left)&&lu(e.right);default:return!1}},uu=(e,t,n,r,i)=>{if(t.cost?.charges===void 0)return;let a=cu(t.left),o=cu(t.right);if(i&&(a===void 0||o===void 0))return;let s=a??(o===void 0?void 0:r-o);if(s===void 0)return;let c=pu(e,t.left,s,!1),l=pu(e,t.right,o??r-s,!1);return{next:()=>(n!==void 0&&e.secondary[n]++,c.next()||l.next()),reset:()=>{c.reset(),l.reset()}}},du=(e,t,n)=>{let r=cu(t.base);if(t.cost?.charges===void 0||r===void 0)return;let i=ka(t.base),a=Array(i.length);for(let e=0;e<i.length;e++){let t=cu(i[e]);if(t===void 0)return;a[e]=t}let o=pu(e,t.base,r,!1),s=0,c=o.next()?pu(e,i[0],a[0],!1):void 0;return{next:()=>{let t=0,r=!1;for(;c!==void 0&&!r;)r=c.next(),r?t++:o.next()?(s++,c=pu(e,i[s],a[s],!1),t++):c=void 0;return n!==void 0&&(e.secondary[n]+=t),r},reset:()=>{o.reset(),s=0,c=o.next()?pu(e,i[0],a[0],!1):void 0}}},fu=(e,t)=>{if(t.cost?.charges===void 0||pe(t.left))return;let n=t.operator===`\\`;if(!n&&pe(t.right))return;let r=qi(t),i=r===t.left?t.right:t.left,a=cu(r);if(a===void 0||!lu(i))return;let o=ka(r),s=pu(e,r,a,!1),c=0;return{next:()=>{for(;s.next();)if(e.isMember(o[c++],i)!==n)return!0;return!1},reset:()=>{s.reset(),c=0}}},pu=(e,t,n,r)=>{let i=Ui(e,t);if(typeof t==`object`&&t.kind===`Subset`)return t.cost!==void 0&&t.cost.charges===void 0?ru(e,t.cost.node,n):(xu(e,t),ru(e,void 0,n));if(typeof t==`object`&&!r&&t.kind===`FilteredSet`)return ru(e,t.isCached?i:void 0,n);let a=typeof t==`object`&&t.kind===`SetOperation`?t.operator===`\\cup`?uu(e,t,i,n,r):fu(e,t):typeof t==`object`&&t.kind===`Union`?du(e,t,i):void 0,o=a??ou(e,t,n);if(!o||i===void 0&&!a)return ru(e,i,n);if(!r)return o;let s=0;for(;o.next();)s++;return i!==void 0&&(e.secondary[i]+=s),ru(e,i,a?n:s)},mu=/* @__PURE__ */ new Set([`Set`,`MixedSet`,`Interval`,`FunctionSet`,`RecordSet`,`ProductSet`]),hu=(e,t,n)=>{if(typeof t!=`object`||mu.has(t.kind))return;if(t.kind!==`Subset`){let r=pu(e,t,n,!1);for(let e=0;e<=n;e++)r.next();return}let r=t.cost?.node;r!==void 0&&(e.secondary[r]+=n)},gu=(e,t,n)=>{let r=cu(t),i=r===void 0?void 0:pu(e,t,r,!1),a=Da(t,t=>(i?.next(),!e.isMember(t,n)));return a||i?.next(),!a},_u=(e,t)=>{let n=cu(t);if(n===void 0)return;let r=pu(e,t,n,!1);for(let e=0;e<=n;e++)r.next();let i=Ui(e,t);i!==void 0&&(e.secondary[i]+=n)},vu=(e,t,n,r)=>{if(t.kind===`Subset`){bu(e,t),xu(e,t);let i=n(t,r),a=t.cost?.node;return a!==void 0&&(e.secondary[a]+=i.elements.length),i}if(cu(t)!==void 0)return _u(e,t),n(t,r);let i=n(t,r),a=i.elements.length,o=Ui(e,t),s=t.kind===`FunctionSet`&&cu(t.domain)===void 0?void 0:ou(e,t,a);if(s===void 0||o===void 0)return i;for(let e=0;e<=a;e++)s.next();return e.secondary[o]+=a,i},yu=(e,t)=>{if(typeof t==`object`)switch(t.kind){case`Set`:case`MixedSet`:return t.elements.length===0;case`Interval`:return t.low>t.high;case`Subset`:return!1;case`FilteredSet`:{if(!t.isCached)return;let n=R(t);return pu(e,t,n,!1).next(),n===0}case`RecordSet`:case`ProductSet`:{let n=t.kind===`RecordSet`?t.sets:t.factors;for(let t=0;t<n.length;t++){let r=yu(e,n[t]);if(r!==!1)return r}return!1}case`FunctionSet`:{let n=yu(e,t.domain);return n===void 0?void 0:!n&&yu(e,t.range)}case`SetOperation`:case`Union`:{let n=cu(t);return n===void 0?void 0:(pu(e,t,n,!1).next(),n===0)}default:return}},bu=(e,t)=>{if(typeof t==`object`)switch(t.kind){case`SetOperation`:case`Union`:{if(t.cost?.charges===void 0)return;let n=cu(t)!==void 0;_u(e,t),t.cost.charges=void 0,n&&R(t);return}case`RecordSet`:case`ProductSet`:{if(yu(e,t)!==!1)return;let n=t.kind===`RecordSet`?t.sets:t.factors;for(let t=0;t<n.length;t++)bu(e,n[t]);return}case`FunctionSet`:if(yu(e,t.domain)!==!1||yu(e,t.range)!==!1||(bu(e,t.range),R(t.range)===1))return;bu(e,t.domain),bu(e,t.range);return;case`Subset`:bu(e,t.base)}},xu=(e,t)=>{bu(e,t.base);let n=pi(t.base);n!==void 0&&cu(n)!==0&&_u(e,n)},Su=(e,t)=>{if(typeof t==`object`)switch(t.kind){case`RecordSet`:case`ProductSet`:{let n=t.kind===`RecordSet`?t.sets:t.factors;for(let t=0;t<n.length;t++)if(bu(e,n[t]),R(n[t])===0)return;return}case`FunctionSet`:if(yu(e,t.domain)!==!1)return;bu(e,t.domain),bu(e,t.range);return;case`Subset`:bu(e,t.base)}},Cu=(e,t,n,r)=>pu(e,t,Array.isArray(n)?n.length:n.high-n.low+1,r),wu=e=>(e.every(e=>e.next()),()=>{for(let t=0;t<e.length;t++){if(e[t].next()||t===e.length-1)return;e[t].reset(),e[t].next()}}),Tu=(e,t,n,r)=>{let i=n?ma(e,t,!1):void 0;return i===void 0?{kind:`Listed`,value:t,elements:r()}:{kind:`Drained`,value:t,elements:i}},Eu=(e,t)=>t.kind===`Drained`?ru(e,Ui(e,t.value),t.elements.length):Cu(e,t.value,t.elements,!0),Du=(e,t)=>wu(t.map(t=>Eu(e,t))),Ou=(e,t,n,r)=>{let i=n.map(e=>R(e)),a=wu(n.map((t,n)=>r?.[n]?ru(e,Ui(e,t),i[n]):pu(e,t,i[n],typeof t==`object`&&t.kind===`FilteredSet`))),o=i.reduce((e,t)=>e*t,1);for(let e=0;e<o;e++)a();t>=0&&(e.secondary[t]+=o)},ku=/* @__PURE__ */ new Set([`FunctionSet`,`RecordSet`,`ProductSet`,`FilteredSet`,`SetOperation`,`SequenceSet`]),Au=e=>{let t=(n,r)=>{if(typeof r!=`object`)return B(n,r);if(r.kind===`Set`&&mi(e,n))return lo(n,r);if(r.kind!==`Subset`&&r.kind!==`Union`)return ku.has(r.kind)?fo(n,r,t):B(n,r);let i=pa(e,n,r);if(i!==void 0)return i;let a=r.kind===`Subset`,o=0,s;try{return s=fo(n,r,(e,n)=>(o++,t(e,n))),s}finally{let t=pu(e,a?n:r.base,o,!1);for(let e=0;e<o;e++)t.next();s===a&&t.next()}};return t},ju=e=>{let t=Number(e>>32n);return t===0?32+Math.clz32(Number(e&4294967295n)):Math.clz32(t)},Mu=(e,t,n)=>{for(let r=0;r<t.length;r++){let i=t[r];if(i===n?.[r])continue;let a=cl([i]),o=Number(a>>BigInt(54)),s=BigInt.asUintN(64,a<<BigInt(10)|1n<<9n),c=r*ml+o;e.registers[c]=Math.max(e.registers[c],ju(s)+1)}},Nu=(e,t)=>{let n=e.registers.subarray(t*ml,(t+1)*ml),r=n.reduce((e,t)=>e+2**-t,0),i=.7205407583220416*ml*ml/r,a=n.filter(e=>e===0).length;return Math.trunc(i<=2.5*ml?a===0?i:ml*Math.log(ml/a):i>2**64/30?-(2**64)*Math.log(1-i/2**64):i)},Pu=e=>{let t=Math.imul(31,31+e.primary)+e.secondary|0;return t^t>>>16},Fu=e=>{let t=16;for(;e.length>t*.75;)t*=2;let n=e=>Pu(e)&t-1;return e.reduce((e,t)=>n(t)<n(e)?t:e)},Iu=(e,t)=>{e.some(e=>e.primary===t.primary&&e.secondary===t.secondary)||e.push(t)},Lu=(e,t)=>e.isPrimed[t]||e.isUnchanged[t],Ru=(e,t)=>{let n=[],r=t=>{let r=e.twins[t],i=r===-1?void 0:n.find(e=>e.includes(r));i?i.push(t):n.push([t])};for(let n of t){let t=e.appliedBodies[n],i=e=>{for(let n of t??[])n.after===e&&r(n.node)};i(-1);for(let t=e.firstChild[n];t!==-1;t=e.nextSibling[t])r(t),i(t)}return n},zu=(e,t)=>{let n=e.primary[t.node],r=e.secondary[t.node];return t.kind===`init`?{distinct:n,generated:n+r}:t.kind===`next`?{distinct:r,generated:n}:t.kind===`constraint`?{distinct:r,generated:n+r}:{distinct:0,generated:0}},Bu=(e,n)=>{let r=[],i=/* @__PURE__ */ new Map,a=t=>({primary:t.reduce((t,n)=>t+e.primary[n],0),secondary:t.reduce((t,n)=>t+e.secondary[n],0)}),o=t=>{let n=[],r=a(t);(r.primary>0||r.secondary>0||Lu(e,t[0]))&&Iu(n,r);for(let r of Ru(e,t))for(let e of o(r))Iu(n,e);return i.set(t[0],n),n},s=(n,i,a,o)=>{let s=e.ranges[n[0]];r.push({location:s?t.gt(s):`Unknown location`,depth:i,count:a,cost:o})},c=(e,t,n)=>s(e,t,n.primary,n.secondary),l=(t,n)=>{let r=Ru(e,t),u=[];for(let e of r)for(let t of i.get(e[0])??o(e))Iu(u,t);let d=a(t),f=Lu(e,t[0]),p=e=>{for(let t of r)l(t,e)};if(e.isUnchanged[t[0]]){let e=u.filter(e=>e.primary!==0||e.secondary!==0);e.length===0?c(t,n,d):s(t,n,Math.max(d.primary,Fu(e).primary),0);return}if(u.length===0){(d.primary!==0||f)&&c(t,n,d);return}let m=d.primary===0&&d.secondary===0;if(u.length===1){let e=u[0],r=e.primary===0&&e.secondary===0;if(e.primary<d.primary){c(t,n,d),p(n+1);return}if(!f&&m&&!r){s(t,n,e.primary,e.secondary);return}if(m&&r){f&&c(t,n,d),p(f?n+1:n);return}if(d.primary===e.primary&&d.secondary===e.secondary){c(t,n,d);return}}let h=!m||f;h&&c(t,n,d),p(h?n+1:n)};for(let t of Ru(e,[n]))o(t),l(t,0);return r},Vu=[`init`,`next`,`invariant`,`constraint`,`implied`],Hu=(e,t)=>!e||!t?e?1:t?-1:0:e.module===t.module?e.start.line-t.start.line||e.start.column-t.start.column||e.end.line-t.end.line||e.end.column-t.end.column:e.module<t.module?-1:1,Uu=(e,t)=>Hu(Cl(e.expression),Cl(t.expression))||Hu(e.expression.location.range,t.expression.location.range),Wu=e=>Vu.flatMap(t=>{let n=e.relations.filter(e=>e.kind===t);return t===`next`?n.toSorted(Uu).filter((e,t,n)=>t===0||Uu(n[t-1],e)!==0):n}),Gu=(e,n,r)=>({variables:r.map(r=>{let i=n.variableLocations[r]?.range;return{label:`${n.variables[r]} ${i?t.gt(i):`Unknown location`}`,distinct:Nu(e,r)}}),relations:Wu(e).map(t=>({kind:t.kind,label:t.label,...zu(e,t),expressions:Bu(e,t.node)}))}),Ku=(e,t,n)=>{let r=yl(e,t,n);if(r===void 0)return;let i=e.primary[r],a=e.secondary[r];if(t===`init`)return[[`generated`,i+a],[`distinct`,i]];if(t===`next`)return[[`generated`,i],[`distinct`,a]];let o=e.firstChild[r];return[[`count`,o===-1?i:e.primary[o]]]},qu=/* @__PURE__ */ new Set([`=`,`#`,`~`,`<=>`,`/\\`,`\\/`,`=>`,`\\in`,`\\notin`,`\\subseteq`,`\\cup`,`\\cap`,`\\`,`SUBSET`,`UNION`,`DOMAIN`,`+`,`-`,`*`,`^`,`\\div`,`%`,`..`,`Seq`,`IsFiniteSet`]),Ju=(e,n)=>qu.has(e)?new t.D(n):new t.H(n),Yu=(e,n,r,i)=>new t.H(`The ${e} argument of ${n} should be a ${r}, but instead it is:\n${_(U(i))}`),Xu=(e,n,r)=>new t.H(`Applying ${e} to the following value,\nwhich is not ${n}:\n${_(U(r))}`),Zu=(e,t,n,r=e)=>{if(!j(e)||tt(e))throw Xu(t,n,r);return L(e)},Qu=e=>typeof e==`object`&&e.kind===`Operator`,W=(e,t,n)=>{let r=e[t];if(r===void 0)throw Ju(n,`${n} expects a value as argument ${t+1}`);return r},$u=(e,t,n)=>{let r=W(e,t,n);if(typeof r!=`boolean`)throw Ju(n,`${n} expects a boolean but received ${U(r)}`);return r},ed=(e,t,n)=>{let r=e[t];if(r===void 0||!Qu(r))throw Ju(n,`${n} expects an operator as argument ${t+1}`);return r},td=(e,t)=>({kind:`Builtin`,name:e,arity:0,evaluate:()=>t,evaluateUnary:void 0,evaluateBinary:void 0}),G=(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}),nd=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),rd=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),id=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(W(n,0,e),W(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),ad=e=>e>2147483647||e<-2147483648,od=e=>new t.H(`Overflow when computing ${e}`),sd={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`},cd={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},ld={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)`,OpLambdaValue:`an operator`,MethodValue:`a java method`,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`},ud={lambda:`FcnLambdaValue`,tuple:`TupleValue`,record:`RecordValue`},dd=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return cd[e.operator];if(e.kind===`Operator`)return e.javaClass;if(e.kind!==`Function`)return sd[e.kind];let t=Ot(e);return t===void 0?`FcnRcdValue`:ud[t]},fd=e=>ld[dd(e)],pd=(e,n)=>new t.D(`class ${e} cannot be cast to class ${n} (${e} and ${n} are in unnamed module of loader 'app')`),md=(e,n)=>new t.D(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${n}`),hd=(e,t)=>({...e,signature:t,evaluate:(n,r)=>{if(n.length===e.arity)return e.evaluate(n,r);let i=/(\w+) \S+\(/.exec(t)?.[1];throw e.arity===0?md(t,`cannot convert MethodHandle()${i} to (Value[])Value`):md(t,n.length===0?`handle's method type (IValue[])${i} but found ()Value`:`array is not of length ${e.arity}`)}}),gd=(e,n)=>{let r=(r,i)=>{if(!(r instanceof t.D)||r instanceof t.T||r instanceof t.w)return r;let a=co(i);return z.sets&&(z.sets.length=i),e.isLazy!==!0&&r instanceof t.H&&!a?r:(z.callStack&&(z.callStack.fingerprint=void 0),md(n,r.message))},i=e.evaluate,a=e.evaluateUnary,o=e.evaluateBinary;return hd({...e,evaluate:(e,t)=>{let n=z.sets?.length??0;try{return i(e,t)}catch(e){throw r(e,n)}},evaluateUnary:a&&(e=>{let t=z.sets?.length??0;try{return a(e)}catch(e){throw r(e,t)}}),evaluateBinary:o&&((e,t)=>{let n=z.sets?.length??0;try{return o(e,t)}catch(e){throw r(e,n)}})},n)},_d=(e,t)=>{if(typeof e!=`number`)throw md(t,`Cannot cast tlc2.value.impl.${dd(e)} to tlc2.value.impl.IntValue`);return e},vd=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,yd=(e,t,n,r)=>{let i=vd(e,n,`IntValue`,2);return hd(id(t,(e,n)=>{let a=_d(n,i),o=_d(e,i),s=r(o,a);if(ad(s))throw od(`${o}${t}${a}`);return s}),i)},bd=(e,n,r)=>{if(typeof e!=`number`)throw new t.H(`The ${n} argument of ${r} should be an integer, but instead it is:\n${_(U(e))}`);return e},xd=(e,t,n=e)=>id(e,(e,r)=>t(bd(e,`first`,n),bd(r,`second`,n))),Sd=(e,t,n)=>({...rd(e,t,n),isLazy:!0}),Cd=(e,t,n)=>{let r=ed(e,t,n);return()=>r.call([])},wd=25214903917n,Td=(1n<<48n)-1n,Ed=e=>{let t=(BigInt.asUintN(64,e)^wd)&Td,n=e=>(t=t*wd+11n&Td,Number(BigInt.asIntN(32,t>>BigInt(48-e))));return{setSeed:e=>{t=(BigInt.asUintN(64,e)^wd)&Td},nextInt:e=>{let t=n(31),r=e-1;if((e&r)===0)return Number(BigInt(e)*BigInt(t)>>31n);for(let i=t;;i=n(31)){let t=i%e;if(i-t+r<=2147483647)return t}},nextLong:()=>BigInt.asIntN(64,(BigInt(n(32))<<32n)+BigInt(n(32))),nextDouble:()=>(n(26)*2**27+n(27))*2**-53}},Dd=[],Od=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},kd=()=>{for(let e=1277011;Dd.length<1341;e++)Od(e)&&Dd.push(e);return Dd},Ad=e=>{let t=kd(),n=t.length;for(;n===t.length;)n=Math.floor(e.nextDouble()*t.length);return t[n]},jd=e=>{let t=[],n=e;for(let e=2;e*e<=n;e++)for(;n%e===0;)t.push(e),n/=e;return n>1&&t.push(n),t},Md=e=>{for(let t=Math.max(e,9);;t++){let e=jd(t),n=new Set(e);if(t%4!=0&&n.size!==e.length)return{modulus:BigInt(t),multiplier:BigInt([...n].reduce((e,t)=>e*t,1)+1)}}},Nd={count:0,nextIndex:()=>0n},Pd=(e,t,n)=>{if(t<=0)return Nd;let r=Md(t),i=BigInt(n.nextInt(t)),a=BigInt(Ad(n));return{count:e,nextIndex:()=>{do i=(r.multiplier*i+a)%r.modulus;while(i>=t);return i}}},Fd=(e,t,n)=>{if(t<=0)return Nd;let r=BigInt(t<191?191:b),i=BigInt(n.nextInt(t));return{count:Math.min(e,t),nextIndex:e=>(r*BigInt(e)+i)%BigInt(t)}},Id=(e,t,n,r)=>r===`1.7.4`?Fd(e,t,n):Pd(e,t,n),Ld=e=>Array.from({length:e.count},(t,n)=>e.nextIndex(n)),Rd=(1n<<63n)-1n-24n,zd=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Rd*BigInt(n)+i)%t;return r<0n?r+t:r})},Bd=(e,t)=>e.reduceRight((e,t)=>({remaining:e.remaining/BigInt(t.length),elements:[t[Number(e.remaining%BigInt(t.length))],...e.elements]}),{remaining:t,elements:[]}).elements,Vd=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){if(tt(e.domain))return;let t=Sr(e.domain),n=I(e.range)?L(e.range).elements:[];return{lists:t.map(()=>n),create:e=>Et(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>L(e).elements),create:t=>Cr(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>L(e).elements),create:F}}},Hd=(e,t)=>t===`1.7.4`&&typeof e==`object`&&e.kind===`ProductSet`?e.factors:void 0,Ud=(e,t,n,r)=>{if(La(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Ld(Id(e,Math.max(0,t.high-t.low+1),n,r)).map(e=>t.low+Number(e));let i=Hd(t,r)?void 0:Vd(t);if(i){let t=i.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(2147483647)?zd(e,t,n):Ld(Id(e,Number(t),n,r))).map(e=>i.create(Bd(i.lists,e)))}let a=L(t).elements;return Ld(Id(e,a.length,n,r)).map(e=>a[Number(e)])},Wd=(e,t,n)=>{let r=Wa(e.low,e.high),i=Id(r,r,t,n);return{kind:`RandomInterval`,some:t=>{for(let n=0;n<i.count;n++)if(t(e.low+Number(i.nextIndex(n))))return!0;return!1}}},Gd=(e,n)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let t=[...Zu(e.domain,`RandomElement`,`a finite set`,e).elements];return Et(t,t.map(()=>Gd(e.range,n)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Cr(e.names.map((t,r)=>[t,Gd(e.sets[r],n)]));if(typeof e==`object`&&e.kind===`ProductSet`)return F(e.factors.map(e=>Gd(e,n)));if(typeof e==`object`&&e.kind===`Interval`){let r=Math.max(0,e.high-e.low+1),i=Math.floor(n.nextDouble()*r);if(i>=r)throw new t.D(`Attempted to retrieve out-of-bounds element from the interval value ${_(U(e))}.`);return e.low+i}let r=Zu(e,`RandomElement`,`a finite set`).elements,i=Math.floor(n.nextDouble()*r.length);if(i>=r.length)throw new t.D(`Index ${i} out of bounds for length ${r.length}`);return r[i]},Kd=(e,t=0n)=>{let n=Ed(t),r=Ed(t),i,a=!1,o=!1,s,c={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Cr([]),counterExample:void 0,counterExamples:/* @__PURE__ */ new WeakSet,deferred:void 0,isSeen:()=>!1,markExplored:void 0,getSuccessorAction:()=>void 0,toRecord:()=>({}),setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:cl,getSimulationValue:void 0,setEveryWorkerRegister:void 0,sumPossibleCounts:void 0,getRandom:()=>{if(a)return n;let e=o?s:c.getCurrentState();return e===void 0?o?r:n:(e!==i&&(r.setSeed(c.getFingerprint(e)^BigInt.asUintN(64,t)),i=e),r)},reseedRandom:()=>{i=void 0},runWithNewRandom:e=>{let n=r,a=i;r=Ed(t),i=void 0;try{return e()}finally{r=n,i=a}},runWithCurrentState:(e,t)=>{let n=o,r=s;o=!0,s=e;try{return t()}finally{o=n,s=r}},runWithEvalControl:(e,t)=>{let n=c.evalControl;c.evalControl=e;try{return t()}finally{c.evalControl=n}},evaluateAtStartup:e=>{let t=a;a=!0;try{return e()}finally{a=t}},pause:void 0,readLine:void 0,printPrompt:()=>{},warn:()=>{},isWarningEnabled:!0,isTool:!1,hasUserFile:!1,version:`master`,seed:t,workers:1,generatedStates:0,distinctStates:0,initialStates:0,queueSize:0,diameter:1,registers:/* @__PURE__ */ new Map,namedRegisters:/* @__PURE__ */ new Map,properties:/* @__PURE__ */ new Map,possibleCounts:/* @__PURE__ */ new Map,idleWorker:void 0,isStopped:!1,isStarted:!1,checkDeadlock:e,startedAt:Date.now(),evalControl:`Clear`};return c},qd=[],Jd=[],Yd=e=>$n([...e].map(e=>[e[0],e[1]])),Xd=e=>e.sumPossibleCounts?.()??e.possibleCounts,Zd=e=>Yd(Xd(e)),Qd=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,Yd(e.possibleCounts)]]),$d=e=>`isLetSubstitute`in e,ef=(e,t)=>t.bodyValues.has(e.body)?[]:n.or(e),tf=1024,nf=2048,rf=/* @__PURE__ */ new Set([`Prime`,`Unchanged`,`BoxAction`,`AngleAction`]),af=/* @__PURE__ */ new Set([`Always`,`Eventually`,`WeakFairness`,`StrongFairness`]),of=/* @__PURE__ */ new Set([...rf,...af,`Enabled`,`EnabledVariable`]),sf=/* @__PURE__ */ new Set([`~>`,`-+->`]),cf=/* @__PURE__ */ new Set([...sf,`\\cdot`]),lf=/* @__PURE__ */ new Set([`Print`,`PrintT`,`Assert`,`JavaTime`,`RandomElement`,`TLCGet`,`TLCSet`,`JsonSerialize`,`ndJsonSerialize`,`JsonDeserialize`,`ndJsonDeserialize`,`Serialize`]),uf=/* @__PURE__ */ new Set([`UNION`,`\\cup`]),df=/* @__PURE__ */ new Set([`RandomSubset`,`RandomSetOfSubsets`,`RandomSubsetSet`]),ff=(e,t,r,i)=>{let a=new Uint32Array(r),o=[],s=[],c=-1,l=e=>{a[0]|=e,c!==-1&&i&&(i.effects[c]|=e)},u=e=>{let t=e.kind;if(rf.has(t)||t===`Apply`&&e.operator===`\\cdot`)return 96;if(t===`Enabled`||t===`EnabledVariable`)return 32;if(af.has(t)||t===`UnboundedQuantifier`&&e.isTemporal===!0||t===`Apply`&&sf.has(e.operator))return 224},d=/* @__PURE__ */ new Map,f=(e,r,p,m)=>{let h=e.kind;if(h===`Selection`){let t=d.get(e.expression)??0,n=r?p?1:2:p?4:8;if((t&n)!==0)return;d.set(e.expression,t|n)}let g=p?1:513;(of.has(h)||h===`UnboundedQuantifier`&&e.isTemporal===!0||h===`Apply`&&cf.has(e.operator))&&(a[0]|=g),of.has(h)&&(a[0]|=16);let _=u(e);r&&_!==void 0&&(a[0]|=_);let v=r&&_===void 0,y=n.ur(e),b=y!==void 0&&n.fr(e);if((b&&t.variableIndex.has(y)||n.lt(e,t.variableIndex))&&(p||(a[0]|=512),v&&(a[0]|=32)),y!==void 0&&!b){let n=t.substitutions.get(y)??y,r=t.definitions.get(n),i=t.constants.has(y),u=t.variableIndex.get(y),d=t.builtins.get(n);if((u!==void 0||d?.isStateLevel||r&&t.variableIndex.has(r.name))&&(a[0]|=h===`Identifier`&&d&&d.arity>0?1:g),u!==void 0&&(v&&(a[0]|=32),i||(a[1+(u>>>5)]|=1<<(u&31))),r)o.push({name:y,callee:r,isOverridden:i,isLevelCounted:v,isBoundCounted:!(p||h===`OperatorReference`||h===`Identifier`&&r.kind===`Operator`&&r.params.length>0||t.theorems.has(n)),isSubstitute:n!==y,owner:c});else{let r=t.replacedDefinitions.get(n);r&&s.push({name:y,flags:(v?yf:0)|(p||h===`OperatorReference`||h===`Identifier`&&r.kind===`Operator`&&r.params.length>0?0:bf),owner:c});let o=d?.name??n,f=lf.has(o)||d?.isStateLevel===!0,m=o===`TLCGet`&&e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`String`&&e.args[0].value===`level`;f&&l(2|(o===`Assert`||m?0:4)),uf.has(o)&&l(8);let g=d!==void 0&&df.has(d.name);g&&l(256),o===`TLCEval`&&l(tf),!i&&(f||g)&&(a[0]|=16),v&&!i&&u===void 0&&d?.isStateLevel&&!d.isLevelConstant&&(a[0]|=d.isActionLevel?96:32)}}let x=b?m?.get(y):void 0;if(x&&f(x.body,v,p,x.substitutes),h===`Let`&&(t.boundSubstitutions.lets.has(e)||e.definitions.some(e=>$d(e)||`standardDefinition`in e))){let r=t.boundSubstitutions.lets.has(e),i=new Map(m);for(let t of e.definitions)(r||$d(t))&&i.set(t.name,{body:t.body,substitutes:m});for(let t of e.definitions)if(!(r||$d(t))){if(`standardDefinition`in t){f(t.body,v,!0,i);for(let e of n.or(t.standardDefinition))f(e,!1,p,void 0)}else for(let e of n.or(t))f(e,v,p,i)}f(e.body,v,p,i);return}if(e.kind!==`Let`||!i){let t=n.ar(e),r=p||h===`Lambda`;for(let e=0;e<t.length;e++)f(t[e],v,r,m);return}let S=c;for(let t of e.definitions){c=i.parents.push(S)-1,i.effects.push(0),i.numbers.set(t,c);for(let e of n.or(t))f(e,v,p,m);c=S}f(e.body,v,p,m)};for(let t of e)f(t,!0,!1,void 0);return{row:a,edges:o,replacedReferences:s}},pf=/[\u0100-\uffff]/,mf=/* @__PURE__ */ new Set([`JsonDeserialize`,`ndJsonDeserialize`]),hf=e=>pf.test(e),gf=e=>mf.has(e),_f=(e,t)=>{if(e.kind===`Selection`){if(t.has(e.expression))return!1;t.add(e.expression)}return e.kind===`String`&&hf(e.value)||e.kind===`Apply`&&gf(e.operator)||n.ar(e).some(e=>_f(e,t))},vf=(e,t)=>_f(e.body,t)||e.kind===`Function`&&e.bounds.some(e=>_f(e.set,t)),yf=2,bf=4,xf=e=>(e.isLevelCounted?2:0)|(e.isBoundCounted?4:0),Sf=(e,t,n)=>{let r={numbers:/* @__PURE__ */ new Map,parents:[],effects:[]},i=ff(ef(e,t),t,n,r),a=i.replacedReferences;return{row:i.row,names:[...i.edges.map(e=>e.name),...a.map(e=>e.name)],edgeFlags:Uint8Array.from([...i.edges.map(xf),...a.map(e=>e.flags)]),owners:Int32Array.from([...i.edges.map(e=>e.owner),...a.map(e=>e.owner)]),letParents:Int32Array.from(r.parents),letEffects:Uint32Array.from(r.effects),isWide:vf(e,/* @__PURE__ */ new Set)}},Cf=(e,t,n,r)=>{let i=n.parents.length;for(let[t,r]of e.letParents.entries())n.parents.push(r===-1?-1:i+r),n.effects.push(e.letEffects[t]);for(let[n,a]of e.names.entries()){let o=t.definitions.get(t.substitutions.get(a)??a);if(o===void 0)continue;let s=e.owners[n];r(o,e.edgeFlags[n]|+!!t.constants.has(a)|(t.substitutions.has(a)?8:0),s===-1?-1:i+s)}return e.row},wf=(e,t,n,r,i=0)=>{let a=n.starts.length-1,o=n.starts,s=n.targets,c=e.slice(),l=new Int32Array(a).fill(-1,i),u=new Int32Array(a),d=new Int32Array(a).fill(-2,0,i).fill(-1,i),f=[],p=[],m=0,h=0,g=(e,n)=>{for(let i=0;i<t;i++){let a=c[n*t+i];c[e*t+i]|=i===0?a&r:a}},_=e=>{p.push(e,0),l[e]=u[e]=m++,f.push(e)};for(let e=i;e<a;e++)if(l[e]===-1)for(_(e);p.length>0;){let e=p[p.length-2],t=p[p.length-1];if(o[e]+t<o[e+1]){p[p.length-1]=t+1;let n=s[o[e]+t];l[n]===-1?_(n):d[n]===-1&&(u[e]=Math.min(u[e],l[n]));continue}if(p.length-=2,p.length>0){let t=p[p.length-2];u[t]=Math.min(u[t],u[e])}if(u[e]!==l[e])continue;let n=f.length-1;for(;f[n]!==e;)n--;let r=f.length-1,i=f[r];for(let e=r;e>=n;e--)d[f[e]]=h;h++;for(let e=r;e>=n;e--){let t=f[e];t!==i&&g(i,t);for(let e=o[t];e<o[t+1];e++)d[s[e]]!==d[i]&&g(i,s[e])}for(let e=r-1;e>=n;e--)g(f[e],i);f.length=n}return c},Tf=1294,Ef=1286,Df=(e,t,n,r,i)=>{let a=ff(ef(e,t),t,n,r);for(let e of a.edges)i(e.callee,xf(e)|+!!e.isOverridden|(e.isSubstitute?8:0),e.owner);return a.row},Of=(e,t)=>e.kind===`Operator`&&e.params.length===0&&!(t&513),kf=(e,t)=>{let r=i=>{if(i.kind===`Let`)for(let a of i.definitions){t.set(a,e);for(let e of n.or(a))r(e)}for(let e of n.ar(i))r(e)};for(let t of n.or(e))r(t)},Af=(e,t,n)=>{let r={numbers:/* @__PURE__ */ new Map,parents:[],effects:[]};ff(ef(e,t),t,n,r);let i=Array.from({length:r.parents.length});for(let[e,t]of r.numbers)i[t]=e;return i},jf=(e,t,n)=>{let r=e.definitions.length,i=e=>{let i=new Uint32Array(n*t);for(let n=0;n<r;n++)i[n*t]=e(n);return i};return{reads:i(t=>e.rows[t]&17),levels:i(t=>e.rows[t]&224),startup:i(t=>e.rows[t]&512),shown:i(t=>e.rows[t]&nf?2:0),purity:i(t=>e.rows[t]&Tf),effects:i(t=>e.effects[t])}},Mf={definitions:[],ids:/* @__PURE__ */ new Map,rows:/* @__PURE__ */ new Uint32Array,effects:/* @__PURE__ */ new Uint32Array,getLetEffects:()=>void 0,varying:{bodies:/* @__PURE__ */ new Set,parameterBodies:/* @__PURE__ */ new Set,hasEffectfulValue:!1,streamedBodies:/* @__PURE__ */ new Set},assumptions:/* @__PURE__ */ new Set},Nf=(e,n,r=/* @__PURE__ */ new Map,i=Mf,a,o=[])=>{let s=[...new Set(e.definitions.values())],c=i.definitions.length,l=1+(e.variables.length+31>>>5),u=e=>e.every((e,t)=>s[t]===e);if(!u(i.definitions)||c>0&&i.rows.length!==c)throw new t.J(`base-definitions`,`a file's link changes its base's definitions`);if(a!==void 0&&(!u(a)||l!==1))throw new t.J(`base-definitions`,`the modules they share declare variables, or their config changes their definitions`);let d=new Map(i.ids);for(let e=0;e<s.length;e++){let t=s[e];e>=c&&d.set(t,e)}let f=jf(i,l,s.length),p=f.reads,m=f.purity,h={numbers:/* @__PURE__ */ new Map,parents:[],effects:[]},g=new Int32Array(s.length).fill(-1),_=new Int32Array(s.length+1),v=[],y=[],b=[],x=(e,t,n)=>{v.push(d.get(e)??-1),y.push(t),b.push(n)};for(let t=0;t<s.length;t++){let n=s[t];if(_[t]=v.length,t<c)continue;let i=r.get(n),a=i!==void 0&&i.row.length===l;a&&(g[t]=h.parents.length);let o=a?Cf(i,e,h,x):Df(n,e,l,h,x);p.set(o,t*l),m[t*l]=o[0]&Tf}_[s.length]=v.length;let S=e=>{let t=new Int32Array(s.length+1),n=[];for(let r=0;r<s.length;r++){t[r]=n.length;for(let t=_[r];t<_[r+1];t++)e(t)&&n.push(v[t])}return t[s.length]=n.length,{starts:t,targets:Int32Array.from(n)}},C=(e,t)=>(e.set(t.subarray(c*l),c*l),e),w=S(e=>!(y[e]&1)),ee=wf(p,l,w,17,c),T=wf(C(f.levels,p),l,S(e=>(y[e]&3)==2),224,c),te=wf(C(f.startup,p),l,S(e=>(y[e]&5)==4),512,c),ne=C(f.shown,m),E=e.substitutions.size>0?wf(ne,l,w,Ef,c):ne,D=wf(m,l,S(e=>!Of(s[v[e]],ee[v[e]*l]|te[v[e]*l])||!!(y[e]&8)&&!!(E[v[e]*l]&Ef)),Tf,c),O=ee.map((e,t)=>t<c*l?t%l===0?i.rows[t/l]:0:t%l===0?e&17|te[t]&512|T[t]&224|D[t]&Tf|(E[t]&Ef?nf:0):e);for(let e=0;e<v.length;e++){if(b[e]===-1)continue;let t=O[v[e]*l];(!Of(s[v[e]],t)||y[e]&8&&t&nf)&&(h.effects[b[e]]|=t&Tf)}for(let e=h.parents.length-1;e>=0;e--){let t=h.parents[e];t!==-1&&(h.effects[t]|=h.effects[e])}let k=[],re=t=>{let n=o.find(e=>e.has(t))?.get(t),r=n===void 0?void 0:d.get(n);if(n===void 0||r===void 0||g[r]===-1)return;let i=(k[r]??=Af(n,e,l)).indexOf(t);return i===-1?void 0:g[r]+i},ie=e=>{let t=h.numbers.get(e)??re(e);return t===void 0?i.getLetEffects(e):h.effects[t]},ae=wf(C(f.effects,m),l,w,260,c),oe=n.filter(e=>!i.assumptions.has(e)),se=Vf(s,oe,e,{ids:d,effects:ae,rows:O,words:l},c,a!==void 0),ce=i.varying.hasEffectfulValue||se.hasEffectfulValue;return{ids:d,rows:O,words:l,getLetEffects:ie,isVaryingBody:e=>i.varying.bodies.has(e)||se.bodies.has(e)||ce&&(i.varying.parameterBodies.has(e)||se.parameterBodies.has(e)),isStreamedBody:e=>i.varying.streamedBodies.has(e)||se.streamedBodies.has(e),base:a&&(()=>{let e=a.length;return{definitions:a,ids:new Map(a.map((e,t)=>[e,t])),rows:O.slice(0,e),effects:ae.slice(0,e),getLetEffects:ie,varying:se,assumptions:new Set(n)}})()}},Pf=(e,t)=>{let n=t.facts,r=n.ids.get(e);return r===void 0?Ff(ef(e,t),t):n.rows.subarray(r*n.words,(r+1)*n.words)},Ff=(e,t)=>{let n=t.facts.words,r=ff(e,t,n),i=r.row;for(let e of r.edges){let r=Pf(e.callee,t);if(!e.isOverridden){i[0]|=r[0]&17,e.isBoundCounted&&(i[0]|=r[0]&512),e.isLevelCounted&&(i[0]|=r[0]&224);for(let e=1;e<n;e++)i[e]|=r[e]}If(e,r[0])&&(i[0]|=r[0]&Tf)}return i},If=(e,t)=>!Of(e.callee,t)||e.isSubstitute&&!!(t&nf),Lf=(e,t,r=3)=>{let i=0,a=e=>{let r=n.ur(e);r!==void 0&&(n.fr(e)||e.kind===`OperatorReference`)&&(i|=t.get(r)??0);for(let t of n.ar(e))a(t)};if(t.size>0)for(let t of e)a(t);return i&r},Rf=(e,t,n)=>n===0?e:new Map([...e,...t.map(e=>[e,n])]),zf=e=>e.kind!==`Function`&&e.params.length>0,Bf=(e,t,r)=>{let i=n.ur(e);if(i===void 0||e.kind===`Apply`)return!1;if(n.fr(e)||t.has(i))return!!((t.get(i)??0)&4);let a=r.substitutions.get(i)??i,o=r.definitions.get(a);return o===void 0?(r.builtins.get(a)?.arity??0)>0:zf(o)},Vf=(e,t,r,i,a,o)=>{let s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Set,l=[],u=!1,d=i.words,f=e=>!!(i.effects[e*d]&260),p=e=>{let t=ff(e,r,d);return!!(t.row[0]&260)||t.edges.some(e=>!e.isOverridden&&f(i.ids.get(e.callee)??-1))},m=e=>{let t=ff(e,r,d);return!!(t.row[0]&8)||t.edges.some(e=>{let t=i.rows[(i.ids.get(e.callee)??-1)*d];return If(e,t)&&!!(t&8)})},h=(e,t,n)=>(n&&p(e)?2:0)|Lf(e,t),g=(e,t,n)=>(n&&p(e)?2:0)|(m(e)?8:0)|Lf(e,t,11),_=(e,t,n)=>{u||=n&&!!(h(e,t,!0)&2)},v=(e,t,n,r)=>{let i=Lf(e,n);i&2?s.add(t):i!==0&&l.push(t),_(e,n,r)},y=(e,t,r,i,a)=>{let o=e.map(e=>e.set);for(let e of o)x(e,i,a);let s=r|h(o,i,a);x(t,Rf(i,n.Pt(e),s),a)},b=(e,t,n)=>{if(e.kind!==`Function`){let r=e.params.map(e=>e.name);x(e.body,Rf(t,r,1),n);return}let r=new Map(t).set(e.name,0);v([e.body],e.body,r,n),y(e.bounds,e.body,1,t,n)},x=(e,t,i)=>{if(i&&e.kind===`Apply`)for(let n of e.args)Bf(n,t,r)&&_([n],t,!0);switch(e.kind){case`Lambda`:return _([e.body],t,i),x(e.body,Rf(t,e.params,1),i);case`Let`:{let r=e.definitions.some(e=>e.isRecursive),a=r?g(e.definitions.flatMap(n.or),t,i):0,o;for(let l of e.definitions){let e=r?a:g(n.or(l),o??t,i);e&2&&l.kind===`Operator`&&s.add(l.body),e&8&&c.add(l.body),e!==0&&(o??=new Map(t),o.set(l.name,zf(l)?e|4:e))}let l=o??t;for(let t of e.definitions)b(t,l,i);return x(e.body,l,i)}case`FunctionConstruction`:return v([e.body],e.body,t,i),y(e.bounds,e.body,1,t,i);case`Forall`:case`Exists`:return y(e.bounds,e.body,0,t,i);case`SetMap`:return y(e.bounds,e.expression,0,t,i);case`SetFilter`:return v([e.bound.set,e.predicate],e.predicate,t,i),y([e.bound],e.predicate,1,t,i);case`Choose`:return e.set?y([{pattern:e.pattern,set:e.set}],e.body,0,t,i):x(e.body,t,i);default:for(let r of n.ar(e))x(r,t,i);return}},S=e=>!!(i.rows[e*d]&8),C=(e,t)=>{r.bodyValues.has(e.body)||b(e,/* @__PURE__ */ new Map,t)},w=e.slice(a);for(let e=0;e<w.length;e++){let t=w[e];f(a+e)&&C(t,!0)}for(let e of t)x(e,/* @__PURE__ */ new Map,p([e]));let ee=u||o;for(let e=0;e<w.length;e++){let t=w[e],n=a+e;f(n)||(ee||S(n))&&C(t,!1)}return{bodies:s,parameterBodies:new Set(l),hasEffectfulValue:u,streamedBodies:c}},Hf=(e,t)=>!(Pf(e,t)[0]&513),Uf=(e,t)=>!(Pf(e,t)[0]&512),Wf=(e,t)=>!!(Pf(e,t)[0]&2561),Gf={any:2,repeated:4,streamed:8,replayed:260,varying:260,reevaluated:258},Kf=(e,t,n)=>(Ff(e,t)[0]&Gf[n])!==0,qf=e=>{let t=e.facts;for(let e=0;e<t.ids.size;e++)if(t.rows[e*t.words]&260)return!0;return!1},Jf=(e,t,n)=>n.facts.isVaryingBody(t)||Kf(e,n,`varying`),Yf=(e,t,n=`any`)=>((t.facts.getLetEffects(e)??Pf(e,t)[0])&Gf[n])!==0,Xf=(e,t)=>t.facts.isVaryingBody(e.body)||Yf(e,t,`varying`),Zf=(e,t)=>t.facts.isStreamedBody(e.body)||Yf(e,t,`streamed`),Qf=(e,t)=>!!(Ff([e],t)[0]&tf),$f=(e,t)=>{let n=Pf(e,t)[0]&224;return n===224?3:n===96?2:+(n===32)},ep=e=>{let t=[];for(let n=1;n<e.length;n++)for(let r=e[n];r!==0;r&=r-1)t.push((n-1<<5)+(31-Math.clz32(r&-r)));return t},tp=(e,t)=>{let n=Ff([e],t);return n[0]&16?void 0:ep(n)},np=(e,t)=>!!(Ff([e],t)[0]&1),rp=(e,t)=>(Ff([e],t)[0]&96)==96,ip=e=>({expression:e,evaluator:void 0,tail:void 0}),ap=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`\\cup`,`\\cap`,`\\`]),op=/* @__PURE__ */ new Set([`SetEnumeration`,`SetFilter`,`SetMap`,`Tuple`,`FunctionSet`,`Record`,`RecordSet`,`Product`]),sp=e=>op.has(e.kind)||e.kind===`Apply`&&ap.has(e.operator),cp=(e,t)=>{if(e.kind===`FunctionApplication`){let n=t.get(e.function);return n!==void 0&&me(n)?e.function:void 0}if(e.kind===`Except`)return e.function;if(e.kind===`Apply`&&e.args.length===2){if([`=`,`#`,`\\`].includes(e.operator))return e.args[0];if(e.operator===`\\subseteq`){let n=t.get(e.args[0]);return n!==void 0&&I(n)?e.args[0]:void 0}if(e.operator===`\\cap`||e.operator===`\\cup`){let n=t.get(e.args[0]);return n!==void 0&&pe(n)?e.args[0]:e.args[1]}return e.operator===`\\in`||e.operator===`\\notin`?e.args[1]:void 0}},lp=(e,t)=>{let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r](t);return n},up={Always:`[]A`,Eventually:`<>A`,WeakFairness:`WF`,StrongFairness:`SF`},dp=(e,n)=>new t.D(`TLC encountered a temporal formula (${e}) when evaluating a predicate or action.\n${o(n)}`),fp=(e,n)=>new t.D(`A non-boolean expression (${fd(n)}) was used as the condition of an IF.\n${o(e)}`),pp=(e,n,r)=>{let i=e.location.range;if(i?.start.line===e.location.line&&i.start.column===e.location.column||!i)return new t.D(`A non-boolean expression (${fd(r)}) was used as a formula in a ${e.kind===`And`?`conjunction`:`disjunction`}.\n${s(e.operands[n])}`);let a=e.prefixEnds?.[Math.max(n,1)-1]??i.end;return new t.D(`Attempted to evaluate an expression of form P ${e.kind===`And`?`/\\`:`\\/`} Q when ${n===0?`P`:`Q`} was\n${fd(r)}.\n${o({...e,location:{...e.location,range:{...i,end:a}}})}`)},mp=e=>{let n=e.field,r=t=>`Attempted to select nonexistent field "${n}" from the record\n${_(U(t))}\n${o(e)}`,i=e=>`Attempted to apply function:\n${_(U(e))}\nto argument "${n}", which is not in the domain of the function.`;return a=>{if(typeof a==`object`&&a.kind===`Function`&&a.functionClass===`record`){let e=a.domain;for(let t=0;t<e.length;t++)if(e[t]===n)return a.range[t]}if(!me(a))throw new t.D(`Attempted to select field "${n}" from a non-record value ${_(U(a))}\n${o(e)}`);let s=Ot(a);if(s===`tuple`)throw Zt(a),Xo(n);return ms(a.kind===`LazyFunction`?V(a):a,n,s===`record`?r:i)}},hp=e=>e===`1.7.4`?(t,n)=>qo(t,n,e):void 0,gp=e=>n=>{if(!me(n))throw new t.D(`Attempted to apply the operator DOMAIN to a non-function\n(${fd(n)})\n${o(e)}`);return _s(n)},_p=(e,n)=>(r,i)=>{if(!I(r))throw new t.D(`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${o(e)}`);return n(r,i)},vp=e=>t.Ft(new t.D(`TLC can't handle real numbers.\n${e.text}`),t.Et.configParseError),yp=e=>t.Ft(new t.D(`TLC can't handle a number this big.\n${e.text??e.value}`),t.Et.error),bp=(e,r)=>new t.D(`In evaluation, the identifier ${n.Lt(e)} is either undefined or not an operator.\n${o(r)}`),xp=(e,r)=>new t.rt(`In evaluation, the identifier ${n.Lt(e)} is either undefined or not an operator.\n${o(r)}`,e),Sp=(e,r)=>e instanceof t.rt&&r!==`1.7.4`?new t.D(`The action formula A appearing in a WF_v(A) or SF_v(A) operator does not specify the primed value of the variable ${n.Lt(e.variable)} occurring in the state formula v.\n`):e,Cp=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n.binding},wp=(e,t)=>{let n=Cp(t,e.operator);return n?.kind===`Operator`&&n.operator.kind===`Closure`?n.operator:void 0},Tp=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n,argument:void 0,isSelf:!1},parent:e}),Ep=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n,argument:void 0,isSelf:!0},parent:e}),Dp=e=>{let n=e.ranges?.[0];return`Argument mismatch in operator application.${n?t.gt(n):``}`},Op=(e,t)=>`Attempted to check if the value:\n${_(U(t))}\nis an element of a set of ${e.names.length}-tuples.`,kp=(e,n,r,i=Dp)=>{if(n.kind===`Name`)return Tp(e,n.name,r);let a=$a(r);if(!a||a.length!==n.names.length)throw new t.D(i(n,r));return n.names.reduce((e,t,n)=>Tp(e,t,a[n]),e)},Ap=(e,n)=>{if(me(e))return e;throw new t.D(`A non-function (${fd(e)}) was applied as a function.\n${o(n)}`)},jp=e=>e.isKeepLazy?e:{environment:e.environment,scope:e.scope,state:e.state,next:e.next,isKeepLazy:!0,isPrimed:e.isPrimed},Mp=(e,t)=>({environment:e.environment,scope:t,state:e.state,next:e.next,isKeepLazy:e.isKeepLazy,isPrimed:e.isPrimed}),Np=(e,n)=>{if(typeof e!=`boolean`)throw new t.D(`Expected ${n} to be a boolean but found ${U(e)}`);return e},Pp=(e,n,r)=>{if(typeof e!=`boolean`)throw new t.D(`Attempted to evaluate an expression of form P => Q when ${r} was\n${fd(e)}.\n${o(n)}`);return e},Fp=(e,n)=>{if(typeof e!=`boolean`)throw new t.D(`Attempted to apply the operator ~ to a non-boolean\n(${fd(e)})\n${o(n)}`);return!e},Ip=(e,n,r)=>{if(typeof e!=`boolean`||typeof n!=`boolean`)throw new t.D(`Attempted to evaluate an expression of form P <=> Q when P or Q was not a boolean.\n${o(r)}`);return e===n},Lp=(e,n)=>{if(typeof e!=`boolean`)throw new t.D(`TLC expected a boolean value, but did not find one. ${s(n)}`);return e},Rp=e=>e.properties.get(`tlc2.tool.impl.Tool.cdot`)?.toLowerCase()===`true`,zp=(e,t)=>t.definitions.get(t.substitutions.get(e)??e),Bp=(e,t)=>{if(t.constants.has(e))return;let n=zp(e,t);return n?.kind===`Operator`&&n.params.length===0?n:void 0},Vp=(e,t,n=/* @__PURE__ */ new Set,r=e)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>Vp(e,t,n));return r.every(e=>e!==void 0)?r.flat():void 0}if(e.kind!==`Identifier`||n.has(e.name))return;let i=t.variableIndex.get(e.name);if(i!==void 0)return[{index:i,expression:r}];let a=Bp(e.name,t);if(a)return n.add(e.name),Vp(a.body,t,n,r)},Hp=(e,t,n)=>{if(t!==void 0&&n!==void 0){for(let r=0;r<e.length;r++)if(t[e[r]]===void 0||n[e[r]]===void 0)return;for(let r=0;r<e.length;r++){let i=t[e[r]],a=n[e[r]];if(i===void 0||a===void 0)return;if(!Hn(i,a))return!1}return!0}},Up=(e,t)=>t.filter((t,n)=>e[n]===void 0).sort(),Wp=(e,t)=>t.builtins.get(t.substitutions.get(e)??e),Gp=(e,t)=>Wp(e,t)?.name??e,Kp=(e,t)=>t.theorems.has(e)?void 0:zp(e,t),qp=(e,t)=>{let n=`universally (\\A) or existentially (\\E) quantify over ${t}, because this would require checking an\ninfinite number of cases.`;if(typeof e==`object`&&e.kind===`SequenceSet`)return`In TLA+, Seq(S) represents the set of all finite sequences whose elements come from the set S. Even when S\nis a finite set, the number of possible sequences in Seq(S) is unbounded because sequences can have any\nfinite length (e.g., length 0, 1, 2, and so on). As a result, TLC cannot evaluate expressions that\n${n} Note that for a finite set of sequences s, TLC handles s \\subseteq Seq(S).\nSee https://explain.tlapl.us/seq-unenumerable for additional details.`;if(typeof e==`object`&&e.kind===`InfiniteSet`&&e.name!==`STRING`&&e.name!==`Any`)return`The set ${e.name} contains infinitely many elements. As a result, TLC cannot evaluate expressions that\n${n} Note that TLC handles set membership like T \\subseteq ${e.name} for any finite set T.`},Jp=(e,n,r)=>{if(!j(e)||tt(e)){let i=U(e),a=r===`1.7.4`?void 0:qp(e,i);throw new t.D(a===void 0?`TLC encountered a non-enumerable quantifier bound\n${i}.\n${s(n)}`:`TLC encountered the non-enumerable quantifier bound\n${i}\n${s(n)}\n${a}`)}},Yp=(e,t,n,r=!0)=>(Jp(e,t,n),typeof e==`object`&&e.kind===`Interval`?br(e):Rr(e)??Ta(e,r)),Xp=(e,t,n)=>n===`1.7.4`?(Jp(e,t,n),Rr(e)??ka(e)):Yp(e,t,n),Zp=e=>{if(typeof e==`object`&&e.kind===`Interval`)return R(e),e},Qp=(e,t,n)=>Zp(e)??Xp(e,t,n),$p=(e,t,n,r=!0)=>Zp(e)??Yp(e,t,n,r),em=(e,t)=>{if(Array.isArray(e)||e.kind===`RandomInterval`)return e.some(t);for(let n=e.low;n<=e.high;n++)if(t(n))return!0;return!1},tm=e=>Array.isArray(e)?e.length:Wa(e.low,e.high),nm=(e,t)=>Array.isArray(e)?e[t]:e.low+t,rm=(e,t)=>e.reduce((n,r,i)=>(n.push(i>0&&e[i-1].set===r.set?n[i-1]:t(r.set,i)),n),[]),im=(e,t)=>rm(e,e=>Qp(q(e,t),e,t.environment.runtime.version)),am=(e,t,n,r)=>{let i=(n,a)=>n<0?r(a):em(t[n],t=>i(n-1,kp(a,e[n].pattern,t)));return i(e.length-1,n)},om=(e,t,n)=>am(e,im(e,t),t.scope,n),sm=(e,t,n,r)=>rm(e,e=>{let i=q(e,t);return Tu(n,i,r!==`1.7.4`,()=>Qp(i,e,r))}),cm=(e,t,n,r)=>{let i=sm(e,t,n,t.environment.runtime.version),a=Du(n,i),o=i.map(e=>e.elements);return am(e,o,t.scope,e=>(a(),r(e)))},lm=(e,t)=>{let n=rm(e,e=>q(e,t));return n.length===1?n[0]:Ti(n,void 0)},um=(e,t,n)=>{if(e.length===1)return kp(t,e[0].pattern,n);let r=$a(n)??[];return e.reduce((e,t,n)=>kp(e,t.pattern,r[n]),t)},dm=e=>typeof e==`object`&&e.kind===`LazyFunction`&&`lambda`in e,fm=e=>Object.assign(e.value,{lambda:e}),pm=e=>dm(e)&&e.enumerated===void 0?e.lambda:void 0,mm=e=>({kind:`Tuple`,elements:e.args,location:e.location}),hm=(e,n,r,i)=>{let a=e.value,s=(e,t,r)=>`In applying the function\n${_(U(a))},\nthe ${e} is:\n${_(U(t))}${r}.\n${o(n.function)}`,c=e.bounds;if(c.length===1){if(!i(r,a.domain))throw new t.D(s(`first argument`,r,`which is not in its domain`));return um(c,e.scope,r)}let l=$a(r),u=typeof a.domain==`object`&&a.domain.kind===`ProductSet`?a.domain.factors:[];if(l===void 0)throw new t.D(`Attempted to apply a function to an argument not in its domain.\n${o(n.function)}`);let d=()=>new t.D(`In applying the function\n${_(U(a))},\nthe argument list is:\n${_(U(r))}\nwhich does not match its formal parameter.\n`),f=l;for(let e=0;e<c.length;e++){let n=c[e].pattern;if(e>=l.length)throw d();let r=l[e],a=`argument number ${e+1}`;if(!i(r,u[e]))throw new t.D(s(a,r,`${n.kind===`Name`?``:`
|