tla 0.0.10-dev.5d66019c0 → 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.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
import{t as e}from"./rolldown-runtime.js";import{C as t,D as n,E as r,Et as i,F as a,Ft as o,H as s,J as c,N as l,O as u,P as d,S as f,T as p,U as m,X as h,Z as g,_t as _,at as v,et as y,gt as b,ht as x,it as S,k as C,lt as w,mt as T,ot as ee,pt as E,q as D,rt as O,ut as te,w as ne,wt as re,x as ie}from"./worker.js";import{$ as k,$t as ae,A as oe,At as se,B as ce,Bt as le,C as ue,Ct as de,D as fe,Dt as pe,E as me,Et as he,F as ge,Fn as _e,Ft as ve,G as ye,Gt as A,H as be,Ht as xe,I as Se,In as Ce,It as we,J as Te,Jt as Ee,K as De,Kt as Oe,L as ke,Ln as Ae,Lt as je,M as Me,Mt as Ne,N as Pe,Nt as Fe,O as Ie,On as Le,Ot as Re,P as ze,Pt as Be,Q as Ve,Qt as He,R as Ue,Rt as We,S as Ge,Sn as Ke,St as qe,T as Je,Tt as Ye,U as Xe,Ut as Ze,V as Qe,Vt as $e,W as et,Wt as tt,X as nt,Xt as rt,Y as it,Yt as at,Z as ot,Zt as st,_ as ct,_t as lt,a as ut,an as dt,ar as ft,at as pt,b as mt,bn as ht,bt as gt,c as _t,cr as vt,ct as yt,d as bt,dr as xt,dt as St,en as Ct,er as wt,et as Tt,f as Et,fr as j,ft as Dt,g as Ot,gt as kt,h as At,hr as jt,ht as Mt,in as Nt,ir as Pt,it as Ft,j as It,jt as Lt,k as Rt,kn as zt,kt as Bt,l as Vt,lr as Ht,lt as Ut,m as Wt,mr as Gt,mt as Kt,n as qt,nn as Jt,nr as Yt,nt as Xt,o as Zt,on as Qt,or as $t,ot as en,p as tn,pr as nn,pt as rn,q as an,qt as on,rn as sn,rr as cn,rt as ln,s as un,sr as dn,st as fn,t as pn,tn as mn,u as hn,ur as gn,ut as _n,v as vn,vt as yn,w as bn,wn as xn,wt as Sn,x as Cn,xn as wn,xt as Tn,y as En,yt as Dn,z as On,zt as kn}from"./order.js";import{C as An,a as jn,b as Mn,d as Nn,f as Pn,i as Fn,p as In,s as Ln,x as Rn,y as zn}from"./modules.js";const Bn=(e,t)=>t.rootKeys.get(e)??e,Vn=e=>`line ${e.location.line}, column ${e.location.column}`,M=e=>{let t=e.location.range;return t?b(t):Vn(e)},Hn=e=>e.kind===`Number`?e.text??String(e.value):M(e),Un=1e3,Wn={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:` `}},Gn=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},Kn=e=>e!==void 0&&/^\p{Nd}$/u.test(e),qn=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),Jn=e=>e.kind!==`Constant`,Yn=(e,t,n)=>({kind:e,first:t,last:n,children:[]}),Xn=`Parsed`,Zn=e=>{let t=t=>{let n=wt(e,t,Gn);return e[n]===void 0?void 0:n},n=(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 c=t(n.last);if(c!==void 0)return e[c]===i?(n.last=c,Xn):a===void 0?s(c):Yn(a,c,c)},r=(n,r,i)=>{if(!r)return s(n.last);if(n.children.length===1)return n.children=[n.children[0],r],n.last=r.last,Xn;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:s(o)},i=(i,a)=>{switch(i.kind){case`Set`:return n(i,a,`}`,void 0,`,`);case`Sequence`:{let t=n(i,a,`>`,void 0,`,`);return t===Xn?i.last+1>=e.length?void 0:(i.last++,Xn):t}case`Record`:return n(i,a,`]`,`RecordPair`,`,`);case`RecordPair`:return r(i,a,`|->`);case`Function`:return n(i,a,`)`,`FunctionPair`,`@@`);case`Subset`:{if(a)return i.children=[a],i.last=a.last,Xn;let e=t(i.last);return e===void 0?void 0:s(e)}case`FunctionPair`:return r(i,a,`:>`)}},a=t=>{let n=wt(e,t,Kn);if(e.startsWith(`..`,n)&&Kn(e[n+2]))return{kind:`Constant`,first:t,last:wt(e,n+2,Kn)-1,children:[]}},o=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=Kn(n)?a(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:wt(e,t+1,Kn)-1,children:[]};if(qn(n))return{kind:`Constant`,first:t,last:wt(e,t,qn)-1,children:[]}},s=n=>{let r=t(n);if(r!==void 0)switch(e[r]){case`{`:return Yn(`Set`,r,r+1);case`<`:return Yn(`Sequence`,r,r+2);case`[`:return Yn(`Record`,r,r+1);case`(`:return Yn(`Function`,r,r+1);default:return e.startsWith(`SUBSET`,r)?Yn(`Subset`,r,r+6):o(r)}},c=(e,t)=>{let n;if(t<Un)for(;;){let r=i(e,n);if(r===Xn)return e;if(r===void 0||(n=Jn(r)?c(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=i(e,n);if(t===void 0)return;t===Xn?(r.pop(),n=e):Jn(t)?(r.push(t),n=void 0):n=t}return n},l=s(0);return l&&Jn(l)?c(l,0):l},N=e=>{let t=e.length===0?void 0:Zn(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)},c=(e,t,n,r)=>{if(o!==void 0)return o.push({node:e,columnWidth:t,trailerWidth:n,leftPad:r}),!0;if(a<Un){a++;let i=l(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(!l(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},l=(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=Wn[e.kind],c=t-Math.max(o.open.length,o.pad.length),l=i+o.close.length,f=a+o.pad;s(o.open);let p=e.kind===`Function`||e.kind===`Record`?d(e.children,c,l,f,o):u(e.children,c,l,f,o.separator);return s(o.close),p},u=(e,t,n,r,i)=>{for(let a=0;a<e.length;a++){let o=a===e.length-1;if(!c(e[a],t,o?n:i.length,r))return!1;o||s(`${i}\n${r}`)}return!0},d=(e,t,i,a,o)=>{for(let l=0;l<e.length;l++){let u=l===e.length-1,d=e[l].children[0],f=e[l].children[1],p=u?``:`${o.separator}\n${a}`,m=r(d)+o.divider.length+1+r(f);if(u?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(!c(d,t,i+o.divider.length,a))return!1;if(s(`${o.divider}\n${a}${o.dividerPad}`),!c(f,t-o.dividerPad.length,u?i:o.separator.length,a+o.dividerPad))return!1;s(p)}}return!0};return l(t,80,0,``)?i:e},Qn=(e,t)=>t?e:N(e),$n=e=>e.kind!==`ModelValue`&&e.kind!==`Set`&&e.kind!==`Function`&&e.kind!==`Interval`&&e.kind!==`InfiniteSet`&&e.kind!==`LazyFunction`,er=2147483647,tr=e=>(e.flags|=16,e),nr=e=>typeof e==`object`&&e.kind===`Function`&&!!(e.flags&16);var rr=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=Ao(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 ir=e=>e instanceof rr,ar=(e,t)=>e.records[t]??=e.makeRecord(e,t),or=(e,t)=>e.writtenSlots!==void 0&&(e.writtenSlots[t>>5]>>>(t&31)&1)==1,sr=(e,t)=>{let n=e.records[t];return n!==void 0&&or(e,t)?Lu(n):e.hashes[t]},cr=e=>{let t=Wu;for(let n=0;n<e.records.length;n++){let r=e.records[n],i=r!==void 0&&or(e,n)?nd(r):e.hashes[n];if(i===qu)return qu;t=t+Ku(td(n+1),i)|0}return t},lr=e=>e.hash!==Iu&&e.hash!==qu,ur=(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 rr(e.edges,e.locations,e.plans,e.sources,i,e.hashes,Iu,e.makeRecord,r);return a.flags=64,a},dr=(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 rr(e.edges,e.locations,e.plans,e.sources,e.records.slice(0,t),e.hashes,Iu,e.makeRecord,r?n:void 0);if(i.flags=64,!lr(e))return i;let a=e.hash;for(let n=t;n<e.records.length;n++)a=a-Ku(td(n+1),sr(e,n))|0;return i.hash=a,i},fr=(e,t)=>e.records.length===256?F(e.range.concat([t])):ur(e,e.records.length,t),pr=e=>e.kind===`MixedSet`?e.enumerated!==void 0:!!(e.flags&1),mr=(e,t)=>{e.flags=t?e.flags|1:e.flags&-2},hr=1e6;let gr=hr;const _r=()=>gr,vr=()=>Math.max(gr,10),yr=()=>`Attempted to construct a set with too many elements (>${gr}).`,br=(e,t)=>{if(e.length===vr())throw new D(yr());e.push(t)},xr=e=>typeof e==`object`&&e.kind===`Interval`&&e.high-e.low>=vr(),Sr=(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)},Cr=2**27,wr=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`&&e.kind!==`Operator`,Tr=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),Er=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),Dr=e=>typeof e==`object`&&e.kind===`ModelValue`,Or=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),kr=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:e.kind===`Operator`?`operator`:wr(e)?`set`:`function`,Ar=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,jr=(e,t)=>(e.writtenKeys=t,e),Mr=e=>(e.hash!==0||e.fingerprint!==0?void 0:e.writtenKeys)??e.domain,Nr=e=>{let t=Mr(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]])},Pr=e=>e.domain.every(e=>typeof e==`number`)?e.domain.map((t,n)=>[t,e.range[n]]):Nr(e),Fr=(e,t,n,r)=>{let i=Array(t.length);for(let e=0;e<t.length;e++)i[e]=n[t[e]];return jr(Ro(e,i),r)},Ir=e=>{typeof e==`object`&&e.kind===`Function`&&(e.writtenKeys=void 0)},Lr=e=>{for(let t=0;t<e.length;t++)if(typeof e[t]!=`string`)return!1;return!0},Rr=e=>typeof e!=`object`||e.kind===`ModelValue`,zr=e=>{if(e.length===0)return!1;let t=e[e.length-1];return typeof t==`object`&&t.kind!==`ModelValue`},Br=(e,t)=>e.length>0&&t.length>0&&Lr(e)!==Lr(t),Vr=(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 Na(e,t);let n=e.domain,r=t.domain;if(n.length!==r.length)return Br(n,r)?Na(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=ki(a,o);if(s!==0)return Dr(a)===Dr(o)?s:Na(e,t)}else if(zr(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||Oi(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:ki(t,n);if(r!==0)return r}return 0},Hr=(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=ki(n[e],r[e]);if(t!==0)return t}return 0},Ur=(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`?ea(t,i):ki(t,i)===0))return!1}return!0},Wr=e=>Dr(e)?e.type:void 0,Gr=(e,t,n)=>{let r=ba(n);return Dr(e)&&Dr(t)?`Attempted to ${r} the differently-typed model values ${N(U(e))} and ${N(U(t))}`:Wr(e)===void 0?`Attempted to ${r} the typed model value ${N(U(t))} and the non-model value\n${N(U(e))}`:`Attempted to ${r}${n?``:` the`} typed model value ${N(U(e))} and non-model value\n${N(U(t))}`},Kr=(e,t,n)=>{let r=Wr(e),i=Wr(t);if((r!==void 0||i!==void 0)&&(!Dr(e)||!Dr(t)||r!==void 0&&i!==void 0&&r!==i))throw P(Gr,e,t,n)},qr=()=>({ranks:Object.create(null),texts:[],searchRank:void 0,unorderedString:void 0}),Jr=qr(),Yr=e=>{Object.assign(Jr,qr()),Ai.clear(),ji=!1,Ki=!1;for(let t of e)ui(t)},Xr=()=>{Jr.searchRank=Jr.texts.length,Jr.unorderedString=void 0},Zr=e=>{let t=Jr.texts;for(let n=e;n<t.length;n++)delete Jr.ranks[t[n]];t.length=e},Qr=()=>Jr.unorderedString;let $r=!1;const ei={isExpanded:!0,isViewPrinted:!1},ti=()=>ei.isExpanded,ni=e=>{$r=e.version===`1.7.4`,gr=e.maxSetSize??hr,ei.isExpanded=e.isLazyValueExpanded??!0,ei.isViewPrinted=e.isViewPrinted??!1},ri=/* @__PURE__ */ new WeakMap,ii=(e,t)=>(ei.isViewPrinted&&ri.set(e,t),e),ai=/* @__PURE__ */ new WeakMap,oi=/* @__PURE__ */ new WeakMap,si=(e,t)=>(ai.set(e,t),e),ci=(e,t)=>(oi.set(e,t),e),li=(e,t)=>oi.has(e)?t:oi.get(t)?.()??t,ui=e=>(Jr.ranks[e]===void 0&&(Jr.ranks[e]=Jr.texts.length,Jr.texts.push(e)),e),di=e=>Jr.ranks[ui(e)],fi=()=>Jr.texts.length,pi=(e=0)=>Jr.texts.slice(e),mi=(e,t)=>{if(e===t)return 0;let n=Jr.ranks,r=n[e],i=n[t],a=Jr.searchRank;return a!==void 0&&(r===void 0||r>=a)&&(i===void 0||i>=a)&&(Jr.unorderedString??=e),r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},hi=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),gi=(e,t)=>(hi(e)||hi(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`);let _i=`none`;const vi=()=>{if(_i===`stopping`)throw new g},yi=(e,...t)=>_i===`none`?e(...t):()=>e(...t),P=(e,...t)=>new n(yi(e,...t)),bi=(e,t)=>P(()=>hi(e)?`Attempted to compare overridden value ${N(U(e))} with non-overridden value:\n${N(U(t))}`:`Attempted to compare ${kr(e)} ${U(e)} with ${kr(t)} ${U(t)}`),xi=(e,t,n)=>`Attempted to ${e} the set ${N(U(L(t)))} with the value:\n${N(U(n))}`,Si=(e,t)=>`Attempted to compare ${N(U(e))} with the value\n${N(U(t))}`,Ci=(e,t,n)=>{if(!hi(e))throw P(xi,n,e,t);if(!hi(t))throw bi(e,t);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new s(yi(Si,e,t))},wi={kind:`InfiniteSet`,name:`Any`},Ti=e=>`Attempted to compare ANY with the value\n${N(U(e))}`,Ei=e=>new s(yi(Ti,e)),Di=e=>e.fingerprint!==0||e.hash!==0&&e.hash!==qu,Oi=(e,t)=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:return!0;case`Interval`:return il(e.low,e.high),!0;case`SequenceSet`:return Oi(e.base,!1);case`InfiniteSet`:if(e===wi)throw Ei(e);return!0;case`LazyFunction`:return Oi(V(e),t);case`Function`:{if(e.flags&4||Di(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=Oi(n[e],t)&&i;for(let e=0;e<r.length;e++)i=Oi(r[e],t)&&i;return i&&(e.flags|=4),i}case`Set`:{if(e.flags&4||Di(e))return!0;e.flags|=1;let n=e.elements,r=!0;for(let e=0;e<n.length;e++)r=Oi(n[e],t)&&r;return r&&(e.flags|=4),r}case`Subset`:return Oi(e.base,t);case`FunctionSet`:{if(!t)break;let n=e.cost?.charges,r=hc(n,e.domain),i=hc(n,e.domain);if(r||i)return!1;let a=hc(n,e.range),o=hc(n,e.range);return a||o||(Oi(e.domain,t),Oi(e.range,t)),!1}case`RecordSet`:case`ProductSet`:{if(!t)break;let n=e.cost?.charges,r=hc(n,e),i=hc(n,e);if(r||i)return!1;let a=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<a.length;e++)Oi(a[e],t);return!1}}let n=Ds(e);return Oi(n&&(oo||n.kind===`SetOperation`||n.kind===`Union`)?As(n,!0,L):L(e),t),$i(e),!1},ki=(e,t)=>{if(e===t)return Oi(e,!1),0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return Vr(e,t);if(n===`Set`&&r===`Set`)return Hr(e,t);if(n===`Interval`&&r===`Interval`){let n=il(e.low,e.high),r=il(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&&Kr(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Kr(e,t,!1),n===`ModelValue`?-1:1;if(e===wi||t===wi)throw Ei(e===wi?t:e);if(n===`SequenceSet`&&r===`SequenceSet`||n===`Subset`&&r===`Subset`)return no(e.base,t.base);if(wr(e)&&wr(t)&&gi(e,t))return Ci(e,t,`compare`);let i=wr(e);if(i!==wr(t))throw bi(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:Ds(e),a=r===`Set`?void 0:Ds(t),o=i?As(i,!0,L):L(e);return $i(e),Hr(o,a?As(a,!1,Es):Es(t))}return Vr(V(e),V(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return mi(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Kr(e,t,!1),Dr(e))return-1;if(Dr(t))return 1;throw bi(e,t)},Ai=/* @__PURE__ */ new Map;let ji=!1;const Mi=()=>ji,Ni=32768,Pi=e=>{let t=Ai.get(e);if(t)return t;if(Ai.size===Ni)throw new u(`TLC supports at most ${Ni} model values, but model value ${e} exceeds this limit.`);let n=e.length>2&&e[1]===`_`?e[0]:void 0;n!==void 0&&(ji=!0);let r={kind:`ModelValue`,name:e,type:n,rank:di(e),hash:Bu(Vu(Hu(e),109)),fingerprint:rd(id(e)^60)};return Ai.set(e,r),r},Fi=()=>[...Ai.values()];var Ii=class{kind=`Set`;elements;writtenElements=void 0;hash=0;fingerprint=0;flags=0;constructor(e){this.elements=e}};const Li=e=>new Ii(e),Ri=e=>{let t=Li(e);return t.flags=1,t};var zi=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 Bi=(e,t)=>new zi(e,t),Vi=(e,t)=>(t!==void 0&&(e.functionClass=t),e),Hi=e=>typeof e==`object`?e.kind===`LazyFunction`?`lambda`:e.kind===`Function`?e.functionClass:void 0:void 0,Ui=e=>typeof e==`object`&&e.kind===`LazyFunction`&&e.isApplicationObserved&&e.enumerated===void 0,Wi=(e,t)=>e.functionClass===`tuple`&&Ui(t),Gi=e=>$n(e)&&e.isCached===!0;let Ki=!1;const qi=()=>(Ki?2:0)|(ji?4:0),Ji=e=>{Ki||=!!(e&2),ji||=!!(e&4)},Yi=()=>Ai.size,Xi=e=>(Ki=!0,e),Zi=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),Qi=e=>Ki&&typeof e==`object`&&$n(e)&&Zi.has(e.kind),$i=e=>{Qi(e)&&(e.isCached=!0)},ea=(e,t)=>{if(e===t)return Oi(e,!0),!0;if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Kr(e,t,!0),ki(e,t)===0);if(e.kind===`Function`&&t.kind===`Function`)return Vr(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Ur(e,t);if(e.kind===`Interval`&&t.kind===`Interval`)return il(e.low,e.high)===0?il(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(Dr(e)||Dr(t))return e.kind===`LazyFunction`&&V(e),Kr(e,t,!0),Dr(e)&&Dr(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return to(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=e.cost?.charges??t.cost?.charges,r=hc(n,e.domain),i=hc(n,t.domain);if(r||i)return r===i;let a=hc(n,e.range),o=hc(n,t.range);return a||o?a===o:to(e.domain,t.domain)&&to(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){let n=e.cost?.charges??t.cost?.charges;if(hc(n,e))return hc(n,t);if(hc(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]&&to(e[1],i[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`){let n=e.cost?.charges??t.cost?.charges;return hc(n,e)?hc(n,t):!hc(n,t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>to(e,t.factors[n]))}let n=wr(e)&&wr(t)&&!(Jo(e)&&Jo(t));if(n&&gi(e,t))return Ci(e,t,`check equality of`)===0;if(n){if(!hi(e)){let n=L(e);if($i(e),!hi(t))return Hr(n,L(t))===0}return ki(e,t)===0}return e.kind===`Function`&&Wi(e,t)?Oa(e,t,!0)===0:ki(e,t)===0},ta=(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},na=(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},ra=(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},ia=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&&na(e.edges,t.edges)&&ra(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=sr(e,i),s=sr(t,i);if(o!==Iu&&s!==Iu&&o!==s||(!n||e.sources[i]!==t.sources[i]||or(e,i)||or(t,i)||!ta(e.edges,t.edges,i))&&!r(ar(e,i),ar(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&&ir(i)&&ir(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):dd(i)===dd(a);return r},aa=ia(!1),oa=ia(!0),sa=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},ca=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(ca(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(ca(e.domain[t])||ca(e.range[t]))return!0;return!1;case`ModelValue`:case`Interval`:case`InfiniteSet`:return!1;default:return!0}},la=(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=nd(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||oa(i,e))return i}if(e.kind===`Set`?sa(e.elements,a):(sa(e.domain,a),sa(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(nd(t),e)}}else i(o,r.length-1);return e};return e?e=>{for(let t=0;t<e.length;t++)ca(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}},ua=(e,t)=>t.length===0||Hi(e)===`tuple`?1:ku(t)?.low,da=e=>(e.kind===`Function`&&e.costModel!==void 0&&e.functionClass!==void 0&&(vi(),e.costModel.secondary[e.costModel.node]+=e.range.length),V(e)),fa=e=>e.costModel!==void 0&&e.functionClass===void 0&&ku(e.domain)===void 0?e.costModel:void 0,pa=e=>{if(e.kind!==`Function`)return;let t=fa(e);t!==void 0&&(vi(),t.secondary[t.node]+=e.range.length)},ma=e=>{if(typeof e==`object`)return e.kind===`LazyFunction`?eu(e)&&e.costModel.node>=0?e.costModel:void 0:e.kind===`Function`?fa(e):void 0},ha=e=>{if(!Er(e))return;let t=da(e);return{domain:t.domain,range:t.range,low:ua(e,t.domain)}},ga=e=>{if(!Er(e))return;Ir(e);let t=V(e);if(Lr(t.domain))return pa(e),t},_a=(e,t,n)=>(Kr(t,e,n),1),va={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`}},ya=(e,t,n)=>{let r=va[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${N(U(e))} with ${r.other}:\n${N(U(t))}`},ba=e=>e?`check equality of`:`compare`,xa=(e,t,n)=>`Attempted to ${ba(e)} operator ${N(U(t))} with value:\n${N(U(n))}`,Sa=(e,t,n)=>`Attempted to ${ba(e)} the function ${N(U(t))} with the value:\n${N(U(n))}`,Ca=(e,t,n)=>`Attempted to compare ${e?`an `:``}integer with non-integer${e||t?`:`:``}\n${N(U(n))}.`,wa=(e,t,n)=>`Attempted to ${ba(e)} record:\n${N(U(t))}\nwith non-record\n${N(U(n))}`,Ta=(e,t,n)=>`Attempted to ${ba(e)} the set ${N(U(t))} with the value:\n${N(U(n))}`,Ea=(e,t,n,r)=>{let i=ha(n);if(!i){if(Dr(n))return _a(n,t,r);throw P(Sa,r,t,n)}if(e.range.length!==i.range.length)return e.range.length-i.range.length;let a=()=>Da(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 Da(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(Ca,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()},Da=(e,t,n)=>{let r=z.sets;for(let i=0;i<e.length;i++){r?.push(e[i]);let a=Ma(e[i],t[i],n);if(r?.pop(),a!==0)return a}return 0},Oa=(e,t,n)=>{let r=V(e);if(Hi(e)===`tuple`){let i=Er(t)?pl(t):void 0;return i?r.range.length-i.length||Da(r.range,i,n):Ea({...da(e),low:1},e,t,n)}if(Hi(e)===`record`){let i=ga(t);if(!i){if(Dr(t))return _a(t,e,n);throw P(wa,n,e,t)}return r.domain.length-i.domain.length||Da(r.domain,i.domain,n)||Da(r.range,i.range,n)}return Ea({...r,low:ua(e,r.domain)},e,t,n)},ka=(e,t)=>hi(e)||hi(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),Aa=(e,t)=>{let n=Ds(t),r=Or(t)?t:n?As(n,!1,n.kind===`Subset`?L:Es):Es(t);return{elements:L(e).elements,otherElements:L(r).elements}},ja=(e,t,n)=>{if(hi(e)&&Dr(t))return 1;if(!n&&(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)){let n=Ds(e);return ja(n?As(n,!0,ks):ks(e),t,!1)}if(ka(e,t))return n?+!ea(e,t):ki(e,t);if(!Or(e)){let r=Ds(e),i=r?As(r,!0,ks):ks(e);return ja(i,t,n)}if(!wr(t)){if(Dr(t))return _a(t,e,n);throw P(Ta,n,e,t)}let r=Aa(e,t);return r.elements.length-r.otherElements.length||Da(r.elements,r.otherElements,n)},Ma=(e,t,n)=>{if(typeof e!=`object`){if(typeof t==typeof e)return n?e===t?0:1:ki(e,t);if(Dr(t))return _a(t,e,n);throw P(ya,e,t,n)}if(e.kind===`ModelValue`)return e.type!==void 0&&Kr(e,t,n),Dr(t)?n?e.name===t.name?0:1:e.rank-t.rank:-1;if(e.kind===`Operator`)throw P(xa,n,e,t);return Er(e)?Oa(e,t,n):ja(e,t,n)},Na=(e,t)=>Ma(e,t,!1),Pa=(e,t)=>Ma(e,t,!0)===0,Fa=e=>{let t=[];for(let n of e){let e=Ua(n,t);e.isFound||t.splice(e.index,0,n)}return t},Ia=(e,t)=>Li(t?e:Fa(e)),La=(e,t)=>{let n=z.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},Ra=(e,t)=>{for(let n=1;n<e.length;n++){let r=e[0],i=e[n];if(La(r,()=>Na(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&&La(r,()=>Na(r,e[a-1]))<0;)e[a]=e[a-1],t[a]=t[a-1],a--;e[a]=r,t[a]=i}},za=(e,t)=>(Ra(e,t),Bi(e,t)),Ba=e=>typeof e==`object`&&e.kind===`MixedSet`,Va=e=>Ba(e)||typeof e==`object`&&e.kind===`ProductSet`&&e.factors.some(Ba),Ha=(e,t,n)=>Ba(e)?za([...t],n):Bi(t,n),Ua=(e,t)=>{let n=0,r=t.length;for(;n<r;){let i=n+(r-n>>1),a=La(e,()=>Na(e,t[i]));if(a===0)return{index:i,isFound:!0};a<0?r=i:n=i+1}return{index:n,isFound:!1}},Wa=(e,t)=>t.some(t=>La(t,()=>Pa(t,e))),Ga=e=>e.kind===`MixedSet`?e.enumerated?.elements??e.elements:pr(e)?e.elements:e.writtenElements??e.elements,Ka=1e3,qa=(e,t,n)=>{if(typeof e!=`object`)return n;if(t===Ka){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=qa(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=qa(e.domain[n],t+1,r),r=qa(e.range[n],t+1,r)}return r},Ja=e=>{let t=qa(e,0,void 0);for(let e=t?.pop();e!==void 0;e=t?.pop())qa(e,0,t)},Ya=(e,t,n,r)=>{if(typeof e!=`object`)return n;if(t===Ka){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];Rr(a)||(i=Ya(a,t+1,i,r))}return i;case`MixedSet`:for(let n=0;n<e.elements.length;n++){let a=e.elements[n];Rr(a)||(i=Ya(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];Rr(a)||Ja(a),Rr(o)||(i=Ya(o,t+1,i,r))}return i;case`LazyFunction`:{if(e.enumerated)return Ya(e.enumerated,t+1,i,r);let n=ru(e);for(let e=n.length-1;e>=0;e--){let a=n[e];i=Ya(a.newValue,t+1,i,r);for(let e=0;e<a.path.length;e++)i=Ya(a.path[e],t+1,i,r)}return Ya(e.domain,t+1,i,r)}case`FilteredSet`:case`Subset`:case`Union`:return Ya(e.base,t+1,i,r);case`SetOperation`:return i=Ya(e.left,t+1,i,r),Ya(e.right,t+1,i,r);case`FunctionSet`:return i=Ya(e.domain,t+1,i,r),Ya(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=Ya(n[e],t+1,i,r);return i}default:return i}},Xa=e=>{let t=[],n=Ya(e,0,void 0,t);for(let e=n?.pop();e!==void 0;e=n?.pop())Ya(e,0,n,t);for(let e=0;e<t.length;e++)t[e].flags|=128},Za=e=>{if(typeof e!=`object`||Gi(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`:Za(e.base);break;case`SetOperation`:e.operator!==`\\cup`&&(Za(e.left),Za(e.right));break;case`FunctionSet`:Za(e.domain),Za(e.range);break;case`RecordSet`:for(let t of e.sets)Za(t);break;case`ProductSet`:for(let t of e.factors)Za(t)}t?.pop()},Qa=e=>typeof e==`object`&&$n(e)&&e.enumerated===void 0,$a=(e,t)=>typeof e==`object`&&(e.kind===`Function`&&Wi(e,t)||wr(e)&&!Dr(t)&&(ka(e,t)||wr(t)&&(Qa(e)?e.kind!==`MixedSet`:Qa(t)))),eo=(e,t)=>typeof e!=`object`&&typeof e==typeof t?e===t:yl(ea,Pa,e,t,$a),to=(e,t)=>{let n=z.sets;if(n===void 0)return eo(e,t);n.push(e);let r=eo(e,t);return n.pop(),r},no=(e,t)=>{let n=z.sets;if(n===void 0)return Na(e,t);n.push(e);let r=Na(e,t);return n.pop(),r},ro=e=>{for(let t=1;t<e.length;t++)if(ki(e[t],e[t-1])<=0)return!1;return!0},io=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},ao=e=>{if(e.length<2||ro(e))return Li(e);let t=[...e].sort(ki);for(let t=1;t<e.length;t++)$i(e[t]);let n=[t[0]];for(let e=1;e<t.length;e++)ki(n[n.length-1],t[e])!==0&&n.push(t[e]);return Li(n)};let oo=!1;const so=e=>{if(io(e))return Li(e);let t=oo;oo=!0;try{let t=yl(ao,e=>({kind:`MixedSet`,elements:e}),e,void 0);return t.kind===`Set`&&t.elements!==e&&(t.writtenElements=e),t}finally{oo=t}},co=Li([]),lo=(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&&ki(r[a],t)<0;)a++;a<r.length&&ki(r[a],t)===0||i.push(t)}return i.length===n.length?e:Li(i)},uo=(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&&ki(r[a],t)<0;)a++;a<r.length&&ki(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Li(i)},fo=(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=ki(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=Li(i);if(e.hash!==0&&e.hash!==qu){let t=e.hash,n=0;for(;n<a.length;n++){let e=nd(a[n]);if(e===qu)break;t=t+Gu(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+ad(a[e])|0;c.fingerprint=t}return c},po=e=>{let t=e.length<2?e:[...e].sort((e,t)=>ki(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&ki(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Bi(n,r)},mo=e=>typeof e!=`object`||e.kind===`ModelValue`&&e.type===void 0||e.kind===`Function`&&(!!(e.flags&4)||e.writtenKeys===void 0&&e.domain.every(ho)&&e.range.every(mo)),ho=e=>!Dr(e)&&mo(e),go=e=>e.flags&32?!0:e.domain.every(mo)?(e.flags|=32,!0):!1,_o=(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=ki(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]},vo=(e,t)=>{if(e.domain.length+t.domain.length>vr()){let n=Nr(e),r=[];for(let e of n)br(r,e);for(let e of Nr(t))n.some(t=>eo(e[0],t[0]))||br(r,e);return Do(r)}let n=Mr(e),r=Mr(t),i=yo(e,t)??new Set(r.filter(e=>n.some(t=>eo(e,t)))),a=[...n,...r.filter(e=>!i.has(e))],o=bo(e,t,i);if(!o){let n=Nr(e),r=Nr(t).filter(e=>!i.has(e[0]));return Do([...n,...r])}let s=Bi(o[0],o[1]);return s.flags|=32,a.every((e,t)=>e===s.domain[t])?s:jr(s,a)},yo=(e,t)=>{if(!go(e)||!go(t))return;let r=/* @__PURE__ */ new Set;try{for(let n of e.domain){let e=cl(t.domain,n);e!==-1&&r.add(t.domain[e])}}catch(e){if(e instanceof n)return;throw e}return r},bo=(e,t,r)=>{let i=r.size===0?t.domain:t.domain.filter(e=>!r.has(e)),a=r.size===0?t.range:t.range.filter((e,n)=>!r.has(t.domain[n]));if(go(e)&&(r.size===0?go(t):i.every(mo)))try{return _o(e.domain,e.range,i,a)}catch(e){if(e instanceof n)return;throw e}},xo=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][0];return t},So=(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 jr(e,xo(t));return e},Co=e=>So(po(e),e),wo=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][1];return t},To=e=>Bi(xo(e),wo(e)),Eo=e=>So(za(xo(e),wo(e)),e),Do=e=>yl(Co,Eo,e,void 0);var Oo=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 ko=[],Ao=e=>{let t=ko[e];if(t)return t;let n=new Oo({kind:`Interval`,low:1,high:e});return e<=1024&&(ko[e]=n),n},jo=e=>e.low===1&&e.high>=0?Ao(e.high):new Oo(e),Mo=e=>Reflect.get(e,`kind`)===`IntervalElements`,No=e=>{let t=/* @__PURE__ */ new Set,n=e=>{if(typeof e!=`object`||!e)return e;if(Mo(e))return jo({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`)&&(Ki=!0),e};for(let t of e)n(t);return[...e]},Po=e=>{if(R(e)>Cr)throw new m;if(e.low===1&&e.high>=1)return Ao(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Fo=e=>e instanceof Oo,Io=(e,t=!0)=>{let n=t?L(e).elements:_s(e);return Fo(n)&&(typeof e!=`object`||e.kind!==`Interval`)?[...n]:n},F=e=>Vi(Bi(Ao(e.length),e),`tuple`),Lo=e=>Vi(po(e),`record`),Ro=(e,t)=>Vi(Bi(e,t),`record`),zo=(e,t)=>(t!==void 0&&(e.costModel=t),e),Bo=e=>e?.node===void 0||e.charges===void 0?void 0:e.charges.costModels[e.node],Vo=(e,t)=>{let n=Bo(t);if(n===void 0)return e;for(let t=0;t<e.length;t++)e[t].costModel=n;return e},I=e=>wr(e)&&!hi(e),Ho=e=>`UNION(${U(e.base)})`,Uo=e=>`Attempted to enumerate the nonenumerable set:\n${Ho(e)}`,Wo=(e,t=e=>L(e).elements)=>{if(!I(e.base))throw P(Uo,e);return t(e.base)},Go=e=>typeof e==`object`&&e.kind===`Set`?e.elements:Uc(e),Ko=(e,t,n)=>t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${N(U(e))}\nwhen enumerating:\n${N(Ho(n))}`,qo=(e,t,n)=>{if(I(e))return e;throw P(Ko,e,t,n)},Jo=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 Jo(e.base);case`FunctionSet`:return Jo(e.domain)&&Jo(e.range)||Yo(e.domain)===!0||Yo(e)===!0;case`RecordSet`:return e.sets.every(Jo)||Yo(e)===!0;case`ProductSet`:return e.factors.every(Jo)||Yo(e)===!0;case`Union`:return Jo(e.base)&&(Or(e.base)?Ga(e.base):Uc(e.base)).every(Jo);case`SetOperation`:return e.operator===`\\cup`?Jo(e.left)&&Jo(e.right):e.operator===`\\cap`?Jo(e.left)||Jo(e.right):Jo(e.left);default:return!1}},Yo=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=Yo(e.domain);return t===void 0?void 0:!t&&Yo(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Yo(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return Jo(e)?L(e).elements.length===0:void 0;default:return}},Xo=(e,t)=>{let n=e.reduce((e,t)=>e*t.length,1);if(t&&n>vr())throw z.sets?.pop(),new D(yr());if(n>Cr)throw new m;let r=[],i=e.map(()=>0);for(let t=0;t<n;t++){r.push(e.map((e,t)=>e[i[t]]));for(let t=e.length-1;t>=0&&(i[t]++,!(i[t]<e[t].length));t--)i[t]=0}return r},Zo=(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},Qo=e=>{if(typeof e!=`object`||e.kind!==`Subset`||hi(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=[]:Zo(a,n.length)||(a=Array.from({length:a.length+1},(e,t)=>t)),i++;let t=Li(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)})},$o=(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=Li(a);if(t(n===void 0?o:{...o,costNode:n}))return!0}while(Zo(i,e.length))}return!1},es=(e,t)=>{let n=[];return $o(e,e=>(n.push(e),!1),t),n},ts=e=>`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${N(U(e.base))}`,ns=e=>{if(R(e.base)===0)return[];if(!wr(e.base))throw P(ts,e);return L(e.base).elements},rs=(e,t)=>`Attempted to enumerate a set of the form [D -> R],but the ${e}:\n${N(U(t))}\ncannot be enumerated.`,is=(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${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${N(U(e.factors[t]))}`,as=(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(hi(a))throw P(is,e,i);let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},os=e=>`Attempted to enumerate S \\cap T when neither S:\n${N(U(e.left))}\nnor T:\n${N(U(e.right))}\nis enumerable`,ss=e=>`Attempted to enumerate S \\ T when S:\n${N(U(e.left))}\nis not enumerable.`,cs=(e,t)=>{if(e.operator===`\\cap`&&!I(e.left)&&!I(e.right))throw P(os,e);if(e.operator===`\\`&&!I(e.left))throw P(ss,e);if(e.operator===`\\cup`)return L(so(Lc(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`)&&br(a,t),!1);return typeof r==`object`&&r.kind===`Interval`?Sr(r,o):Bc(r,t??Fc(r),o),L(so(a)).elements},ls=e=>{if(typeof e!=`object`||Gi(e))return!0;switch(e.kind){case`Set`:case`MixedSet`:return pr(e);case`Interval`:return!0;case`FilteredSet`:return ls(e.base);case`FunctionSet`:return ls(e.domain)&&ls(e.range);case`RecordSet`:return e.sets.every(ls);case`ProductSet`:return e.factors.every(ls);case`Operator`:throw new n(e.javaClass===`MethodValue`?`It is a TLC bug: Attempted to normalize an operator.`:`Should not normalize an operator.`);default:return!1}},us=(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===wi)return!0;break;case`ModelValue`:case`Interval`:break;default:return!0}return!1},ds=e=>us(e,!1),fs=e=>{for(let t=0;t<e.length;t++)if(us(e[t],!0))return!0;return!1},ps=(e,t)=>{for(let n=0;n<e.length;n++)if(ms(e[n],t))return!0;return!1},ms=(e,t)=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:return fs(e.elements);case`MixedSet`:return!0;case`FilteredSet`:case`Subset`:case`Union`:return ms(e.base,t);case`SetOperation`:return ms(e.left,t)||ms(e.right,t);case`FunctionSet`:return ms(e.domain,t)||ms(e.range,t);case`RecordSet`:return ps(e.sets,t);case`ProductSet`:return ps(e.factors,t);case`Operator`:return t;default:return!1}},hs=(e,t)=>!ms(e,t)||ls(e),gs=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`ProductSet`:case`FunctionSet`:case`RecordSet`:return hs(e,!0);case`FilteredSet`:return ls(e),!0;case`SetOperation`:return e.operator!==`\\cup`&&ls(e.left)&&e.operator===`\\cap`&&ls(e.right),!0;case`MixedSet`:case`Union`:case`Subset`:return!0;default:return!1}},_s=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=gs(e),n=z.sets?Pc(e,!1):void 0;return vs(e,n,t)},vs=(e,t,n)=>{let r=oo;oo=!1;let i;try{i=Cs(e,!1,void 0,t)}finally{oo=r}let a=Ia(i,n);return i.length<=vr()&&(e.enumerated=a),a.elements},ys=e=>{let t=Qo(e);return t!==void 0&&t.length>vr()?t:_s(e)},bs=e=>`Expected a set but found ${U(e)}`,xs=e=>`Attempted to enumerate { x \\in S : p(x) } when S:\n${N(U(e.base))}\nis not enumerable`,Ss=e=>`Attempted to enumerate the non-enumerable set ${U(e)}`,Cs=(e,t=!0,n=t?ys:_s,r)=>{if(typeof e!=`object`)throw P(bs,e);let i=Hs(e);if(i){let e=Ac(kc(i,r),t);return Kc(i)?Fa(e):e}switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return Fa(e.elements);case`Interval`:if(R(e)>Cr)throw new m;return jo(e);case`Subset`:{let t=ns(e);if(t.length>30)throw P(el,e);if(2**t.length>Cr)throw new m;return es(t,e.cost?.node)}case`FunctionSet`:{if(!$r&&Zc(e))return[];if(hi(e.domain))throw P(rs,`domain D`,e.domain);let r=Io(e.domain);if((r.length>0||$r)&&hi(e.range))throw P(rs,`range R`,e.range);let i=r.length===0?[]:n(e.range);return Vo(Xo(r.map(()=>i),t).map(e=>Bi(r,e)),e.cost)}case`RecordSet`:{if(!$r&&Zc(e))return[];let r=as(e,n);return Vo(Xo(r,t).map(t=>Ro(e.names,t)),e.cost)}case`ProductSet`:{if(!$r&&Zc(e))return[];let r=as(e,n);return Vo(Xo(r,t).map(F),e.cost)}case`FilteredSet`:{if(!wr(e.base)||hi(e.base))throw P(xs,e);let n=e.startPass?.(!0).test??Ws(e),i=[];return Bc(e.base,r??Fc(e.base),e=>(n(e)&&(t?br(i,e):i.push(e)),!1)),L(so(i)).elements}case`Union`:{let t=[];for(let[n,i]of(r?qc(e,r):Wo(e,Go)).entries()){let a=qo(i,n,e);if(xr(a))throw new D(yr());for(let i of r&&n===0&&Or(e.base)?Hc(a,r):Uc(a))br(t,i)}return L(so(t)).elements}case`SetOperation`:return cs(e,r);case`InfiniteSet`:case`SequenceSet`:throw P(Ss,e);default:throw P(bs,e)}},L=(e,t)=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Li(Cs(e));let n=typeof e==`object`&&$n(e)?e:void 0;return n?.enumerated?n.enumerated:ws(e,n,!1,t)},ws=(e,t,r,i)=>{if(oo&&t!==void 0&&Is(t))throw new n(`The set literal holds a filter`);let a=z.sets;r||a?.push(e);let o=i??gs(e),s=oo;oo=s&&t?.kind===`MixedSet`;let c;try{c=r?Cs(e,!0,void 0,Pc(e,!1)):Cs(e)}finally{oo=s}r||a?.pop();let l=Ia(c,o);return t&&(t.enumerated=l),l},Ts=e=>z.sets!==void 0&&!e.enumerated?ws(e,e,!0):L(e),Es=(e,t)=>{let n=typeof e==`object`&&$n(e)?e:void 0;if(n===void 0||n.enumerated)return L(e);let r=Is(n),i=n.kind===`SetOperation`||n.kind===`Union`?Ts(n):L(n,t);return r&&(n.enumerated=void 0),i},Ds=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}},Os=(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&&rc(e,t)!==void 0;default:return!1}},ks=(e,t)=>{if(typeof e==`object`&&e.kind===`FilteredSet`){let t=L(e);return e.isCached=!0,t}let n=L(e,t);return $i(e),n},As=(e,t,r)=>{if(oo)throw new n(`The set literal holds a charged set`);let i=e.cost;if(i?.charges===void 0)return r(e);let a=gs(e);a||vi();let o=i.charges.convertCharged(e,r,a);return t&&(i.charges=void 0),o},js=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isCached!==!0;case`SetOperation`:return e.hasFilter&&e.isCached!==!0&&(js(e.left)||js(e.right));case`Union`:return e.isCached!==!0&&typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&Ns(e.base.elements);case`FunctionSet`:case`RecordSet`:case`ProductSet`:return Ms(e);default:return!1}},Ms=e=>e.hasFilter&&e.isCached!==!0&&!e.enumerated&&(e.kind===`FunctionSet`?js(e.domain)||js(e.range):Ns(e.kind===`RecordSet`?e.sets:e.factors)),Ns=e=>{for(let t=0;t<e.length;t++)if(js(e[t]))return!0;return!1},Ps=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isPassObserved===!0||Ps(e.base);case`SetOperation`:return Ps(e.left)||Ps(e.right);case`Union`:return typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&Fs(e.base.elements);case`FunctionSet`:return Ps(e.domain)||Ps(e.range);case`RecordSet`:return Fs(e.sets);case`ProductSet`:return Fs(e.factors);default:return!1}},Fs=e=>{for(let t=0;t<e.length;t++)if(Ps(e[t]))return!0;return!1},Is=e=>js(e)&&Ps(e),Ls=(e,t,n)=>({kind:`FunctionSet`,domain:e,range:t,hasFilter:js(e)||js(t),cost:n}),Rs=(e,t,n)=>({kind:`RecordSet`,names:e,sets:t,hasFilter:Ns(t),cost:n}),zs=(e,t)=>({kind:`ProductSet`,factors:e,hasFilter:Ns(e),cost:t}),Bs=(e,t,n,r)=>({kind:`SetOperation`,operator:e,left:t,right:n,hasFilter:js(t)||js(n),cost:r}),Vs=(e,t)=>({kind:`Union`,base:e,cost:t}),Hs=e=>(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&Ms(e)?e:void 0,Us={kind:`List`,elements:[],position:0},Ws=e=>t=>e.test(t,!1),Gs=e=>{let t=typeof e==`object`&&$n(e)&&!e.enumerated&&Is(e)?e:void 0,n=Io(e);return t&&(t.enumerated=void 0),n},Ks=e=>{if(!$r&&Zc(e))return Us;let t={kind:`Product`,set:e,costModel:Bo(e.cost),domain:[],parts:[],current:[],isDone:!1};if(e.kind===`FunctionSet`){if(Pc(e.domain,!0),hi(e.domain))throw P(rs,`domain D`,e.domain);if(t.domain=Gs(e.domain),(t.domain.length>0||$r)&&hi(e.range))throw P(rs,`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`&&hi(n[r]))throw P(is,e,r);let i=qs(n[r]),a=ec(i);if(a===void 0)return Us;t.parts.push(i),t.current.push(a)}return t},qs=e=>{let t=z.sets;if(typeof e==`object`&&e.kind===`FilteredSet`&&!Gi(e)){t?.push(e),I(e.base)||L(e);let n=qs(e.base),r=e.startPass?.(!1),i={kind:`Filter`,set:e,base:n,test:r?.test??Ws(e),end:r?.end};return t?.pop(),i}if(typeof e==`object`&&(e.kind===`SetOperation`||e.kind===`Union`)&&js(e))return Ps(e)||z.sets!==void 0?Ys(e):yl(Js,Ys,e,void 0);let n=typeof e==`object`?Hs(e):void 0;if(n===void 0)return Js(e);t?.push(n);let r=Ks(n);return t?.pop(),r},Js=e=>({kind:`List`,elements:Uc(e),position:0}),Ys=e=>{let t=z.sets;t?.push(e);let n=e.kind===`Union`?Zs(e):Xs(e);return t?.pop(),n},Xs=e=>{if(e.operator===`\\cup`)return I(e.left)&&I(e.right)||L(e),{kind:`Concatenated`,left:qs(e.left),right:qs(e.right)};let t=e.operator===`\\`||I(e.left),n=t?e.left:e.right;return I(n)||L(e),{kind:`Selected`,base:qs(n),other:t?e.right:e.left,isIntersection:e.operator===`\\cap`}},Zs=e=>{let t=Wo(e);return{kind:`Unioned`,union:e,sets:t,index:0,part:t.length>0?qs(qo(t[0],0,e)):void 0}},Qs=(e,t)=>{$s(e.parts[t]);let n=ec(e.parts[t]);n===void 0?e.isDone=!0:e.current[t]=n},$s=e=>{switch(e.kind){case`List`:e.position=0;return;case`Filter`:{$s(e.base);let t=e.set.startPass?.(!1);e.test=t?.test??Ws(e.set),e.end=t?.end;return}case`Product`:e.isDone=!1;for(let t=0;t<e.parts.length;t++)Qs(e,t);return;case`Concatenated`:$s(e.left),$s(e.right);return;case`Selected`:$s(e.base);return;case`Unioned`:e.index=0,e.part=e.sets.length>0?qs(qo(e.sets[0],0,e.union)):void 0}},ec=e=>{switch(e.kind){case`List`:return e.position<e.elements.length?e.elements[e.position++]:void 0;case`Filter`:for(let t=ec(e.base);t!==void 0;t=ec(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=ec(e.parts[t]);if(n!==void 0){e.current[t]=n;break}t===0?e.isDone=!0:Qs(e,t)}let n=e.set;return zo(n.kind===`FunctionSet`?Bi(e.domain,t):n.kind===`RecordSet`?Ro(n.names,t):F(t),e.costModel)}case`Concatenated`:return ec(e.left)??ec(e.right);case`Selected`:for(let t=ec(e.base);t!==void 0;t=ec(e.base))if(B(t,e.other)===e.isIntersection)return t;return;case`Unioned`:for(;e.part!==void 0;){let t=ec(e.part);if(t!==void 0)return t;e.index++,e.part=e.index<e.sets.length?qs(qo(e.sets[e.index],e.index,e.union)):void 0}return}},tc=(e,t)=>{for(let n=ec(e);n!==void 0;n=ec(e))if(t(n))return!0;return!1},nc={kind:`Plain`,part:Us},rc=(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)}},ic=(e,t)=>{if(typeof t!=`object`)return;let n=Hs(t);if(n===void 0)return;if(n.kind===`FunctionSet`)return uc(e,n.range)?n:void 0;let r=n.kind===`RecordSet`?n.sets:n.factors;for(let t=0;t<r.length;t++)if(!uc(e,r[t]))return;return n},ac=e=>typeof e==`object`&&e.kind===`FilteredSet`&&e.isCached===!0,oc=(e,t)=>t.operator===`\\cup`&&t.enumerated===void 0&&(js(t)||ac(t.left)||ac(t.right))&&rc(e,t)!==void 0&&I(t.left)&&I(t.right)&&!xr(t.left)&&!xr(t.right)&&uc(e,t.left)&&uc(e,t.right),sc=e=>e.operator===`\\`||I(e.left)?e.left:e.right,cc=(e,t)=>t.enumerated===void 0&&js(t)&&I(sc(t))&&uc(e,sc(t)),lc=(e,t)=>t.operator===`\\cup`?oc(e,t):cc(e,t),uc=(e,t)=>typeof t==`object`?t.kind===`SetOperation`?lc(e,t):t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||rc(e,t)===void 0||ic(e,t)!==void 0:!0,dc=(e,t)=>typeof t==`object`&&(t.kind===`FilteredSet`||t.kind===`Subset`||(t.kind===`SetOperation`?lc(e,t):ic(e,t)!==void 0)),fc=(e,t)=>Gi(t)||!dc(e,t.base)?void 0:rc(e,t),pc=(e,t)=>{let n=typeof t!=`object`||t.kind===`FilteredSet`||t.kind===`Subset`?void 0:rc(e,t),r=z.sets;if(typeof t==`object`&&t.kind===`FilteredSet`){let n=fc(e,t);if(n===void 0){let n=t.isCached?rc(e,t):void 0;return n===void 0?{kind:`Plain`,part:qs(t)}:{kind:`ChargedLeaf`,node:n,part:qs(t)}}r?.push(t),I(t.base)||L(t);let i={kind:`ChargedFilter`,node:n,set:t,base:pc(e,t.base)};return r?.pop(),i}if(typeof t==`object`&&t.kind===`SetOperation`&&t.operator!==`\\cup`){r?.push(t);let n=sc(t),i={kind:`ChargedSelected`,base:pc(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:pc(e,t.left),right:pc(e,t.right)};return r?.pop(),i}let i=n===void 0||typeof t!=`object`?void 0:Hs(t);if(n!==void 0&&i!==void 0){r?.push(i);let t=_c(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:qs(t)};e.chargeSubsetElements(t)}let a=qs(t);return n===void 0?{kind:`Plain`,part:a}:{kind:`ChargedLeaf`,node:n,part:a}},mc=(e,t)=>{if(typeof t!=`object`||t.kind!==`SetOperation`&&t.kind!==`FilteredSet`&&t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||(t.kind===`FilteredSet`?fc(e,t)===void 0:(t.kind!==`SetOperation`||t.operator===`\\cup`)&&rc(e,t)===void 0))return Zc(t);let n=z.sets;n?.push(t);let r=t.kind===`SetOperation`||t.kind===`FilteredSet`?bc(e,pc(e,t))===void 0:t.kind===`FunctionSet`?!Zc(t.domain)&&mc(e,t.range):gc(e,t.kind===`RecordSet`?t.sets:t.factors);return n?.pop(),r},hc=(e,t)=>(e?.chargeIsEmpty(t),Zc(t)),gc=(e,t)=>{for(let n=0;n<t.length;n++)if(mc(e,t[n]))return!0;return!1},_c=(e,t,n)=>{if(!$r&&mc(e,t))return nc;let r={kind:`ChargedProduct`,node:n,costModel:e.costModels[n],set:t,domain:[],parts:[],current:[],isDone:!1};if(t.kind===`FunctionSet`){if(Pc(t.domain,!0),hi(t.domain))throw P(rs,`domain D`,t.domain);if(r.domain=Gs(t.domain),(r.domain.length>0||$r)&&hi(t.range))throw P(rs,`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`&&hi(i[n]))throw P(is,t,n);let a=pc(e,i[n]),o=bc(e,a);if(o===void 0)return nc;r.parts.push(a),r.current.push(o)}return r},vc=(e,t,n)=>{yc(e,t.parts[n]);let r=bc(e,t.parts[n]);r===void 0?t.isDone=!0:t.current[n]=r},yc=(e,t)=>{switch(t.kind){case`Plain`:case`ChargedLeaf`:$s(t.part);return;case`ChargedProduct`:t.isDone=!1;for(let n=0;n<t.parts.length;n++)vc(e,t,n);return;case`ChargedUnion`:yc(e,t.left),yc(e,t.right);return;case`ChargedSelected`:case`ChargedFilter`:yc(e,t.base)}},bc=(e,t)=>{switch(t.kind){case`Plain`:return ec(t.part);case`ChargedLeaf`:return e.secondary[t.node]++,ec(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=bc(e,t.parts[n]);if(r!==void 0){t.current[n]=r;break}n===0?t.isDone=!0:vc(e,t,n)}let r=t.set;return zo(r.kind===`FunctionSet`?Bi(t.domain,n):r.kind===`RecordSet`?Ro(r.names,n):F(n),t.costModel)}case`ChargedUnion`:return e.secondary[t.node]++,bc(e,t.left)??bc(e,t.right);case`ChargedSelected`:return xc(e,t);case`ChargedFilter`:return Sc(e,t)}},xc=(e,t)=>{for(let n=bc(e,t.base);n!==void 0;n=bc(e,t.base))if(e.isMember(n,t.other)===t.isIntersection)return n},Sc=(e,t)=>{for(let n=bc(e,t.base);n!==void 0;n=bc(e,t.base))if(e.secondary[t.node]++,t.set.test(n,!1))return n},Cc=(e,t)=>{let n=[];for(let r=bc(e,t);r!==void 0;r=bc(e,t))br(n,r);return n},wc=(e,t,n)=>{let r=fc(e,t);if(r===void 0||t.enumerated||!I(t.base)||oo)return;let i=z.sets;i?.push(t);let a=Cc(e,{kind:`ChargedFilter`,node:r,set:t,base:pc(e,t.base)});i?.pop(),e.secondary[r]+=a.length;let o=Li(L(so(a)).elements);return n&&(t.enumerated=o),o.elements},Tc=(e,t)=>t.kind===`FilteredSet`?!t.enumerated&&I(t.base)&&fc(e,t)!==void 0:t.kind===`SetOperation`?lc(e,t):ic(e,t)!==void 0&&rc(e,t)!==void 0,Ec=(e,t,n)=>{if(typeof t!=`object`||!Tc(e,t))return!1;let r=pc(e,t);for(let t=bc(e,r);t!==void 0;t=bc(e,r))n(t);return!0},Dc=(e,t,n)=>{let r=n.kind===`Subset`,i=r?t:n.base;if(typeof i!=`object`||!Tc(e,i))return;let a=z.sets;a?.push(n);let o=pc(e,i),s=!1;for(let i=bc(e,o);i!==void 0;i=bc(e,o))if(r?!e.isMember(i,n.base):e.isMember(t,i)){s=!0;break}return a?.pop(),r!==s},Oc=(e,t,n)=>{if(typeof t!=`object`)return;if(t.kind===`FilteredSet`)return wc(e,t,n);let r=rc(e,t),i=t.kind===`SetOperation`?lc(e,t)?t:void 0:r===void 0?void 0:ic(e,t);if(i===void 0)return;let a=Cc(e,pc(e,i));r!==void 0&&(e.secondary[r]+=a.length);let o=i.kind!==`SetOperation`&&Kc(i)?Fa(a):a,s=i.kind===`SetOperation`?Li(L(so(a)).elements):i.kind===`RecordSet`?ao(o):Li(o);return n&&(i.enumerated=s),s.elements},kc=(e,t)=>t===void 0||t.kind===`Cup`?Ks(e):t,Ac=(e,t)=>{let n=[];return tc(e,e=>(t?br(n,e):n.push(e),!1)),n},jc=(e,t)=>{if(!(typeof e!=`object`||Gi(e)))switch(e.kind){case`MixedSet`:L(e);return;case`FilteredSet`:return I(e.base)||L(e),Pc(e.base,t);case`Union`:{if(!Or(e.base)&&I(e.base))return Pc(e.base,t);let n=Wo(e);return n.length>0?Pc(qo(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=Pc(e.left,!0),n=Pc(e.right,!0);return t||n?{kind:`Cup`,left:t,right:n}:void 0}return Pc(e.operator===`\\cap`&&!I(e.left)?e.right:e.left,t);case`FunctionSet`:case`RecordSet`:case`ProductSet`:if(Ms(e))return Ks(e);t&&Mc(e);return;case`Subset`:t&&Mc(e);return;default:return}},Mc=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}ns(e);return}case`FunctionSet`:{if(e.enumerated||Zc(e))return;let t=e.domain;if(Pc(t,!0),hi(t))throw P(rs,`domain D`,t);if(typeof t==`object`&&$n(t)&&L(t),Zc(t))return;if(hi(e.range))throw P(rs,`range R`,e.range);typeof t==`object`&&t.kind===`Interval`&&Nc(e),Pc(e.range,!0);return}case`RecordSet`:case`ProductSet`:{if(e.enumerated||Zc(e))return;let t=e.kind===`RecordSet`?e.sets:e.factors;for(let n=0;n<t.length;n++){if(hi(t[n]))throw P(is,e,n);Pc(t[n],!0)}}}},Nc=e=>{let t=R(e.domain);if(t>Cr)throw z.sets?.push(e),new m;return t},Pc=(e,t)=>{let n=z.sets;n?.push(e);let r=jc(e,t||n!==void 0);return n?.pop(),r},Fc=e=>typeof e!=`object`||Gi(e)?void 0:Pc(e,!1),Ic=e=>`Attempted to enumerate S \\cup T when S:\n${N(U(e.left))}\nand T:\n${N(U(e.right))}\nare not both enumerable`,Lc=(e,t)=>{if(!I(e.left)||!I(e.right))throw P(Ic,e);let n=t?.kind===`Cup`?t:void 0,r=n?n.left:Pc(e.left,!0),i=n?n.right:Pc(e.right,!0);if(xr(e.left))throw new D(yr());let a=[],o=e=>(br(a,e),!1);if(Bc(e.left,r,o),xr(e.right))throw new D(yr());return Bc(e.right,i,o),a},Rc=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},zc=(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?Rc(e).elements:_s(e);let n=(e.kind===`Union`||e.hasFilter)&&Is(e),r=gs(e),i=Cs(e,!0,void 0,z.sets?Pc(e,!1):void 0),a=Ia(i,r);return n||(e.enumerated=a),a.elements},Bc=(e,t,n)=>typeof e!=`object`||Gi(e)?L(e).elements.some(n):Jc(e,n,t),Vc=(e,t)=>Bc(e,Fc(e),t),Hc=(e,t)=>{let n=[];return Bc(e,t,e=>(n.push(e),!1)),n},Uc=e=>Hc(e,Fc(e)),Wc=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,Gc=e=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:case`Interval`:return!0;case`Set`:return e.elements.every(Gc);case`Function`:return e.writtenKeys===void 0&&e.domain.every(Gc)&&e.range.every(Gc);case`SetOperation`:return e.operator!==`\\cup`&&Gc(e.left)&&Gc(e.right);case`FilteredSet`:return Gc(e.base);case`ProductSet`:return e.factors.every(Gc);default:return!1}},Kc=e=>typeof e!=`object`||Gi(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?Kc(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||Kc(e.left)||Kc(e.right):Wc(e)?.some(Kc)??!1,qc=(e,t)=>Wo(e,e=>Or(e)?Go(e):Hc(e,t)),Jc=(e,t,n)=>{if(e.kind===`Union`)return qc(e,n).some((r,i)=>{let a=qo(r,i,e);return i===0&&Or(e.base)?Bc(a,n,t):Vc(a,t)});if(e.kind===`FilteredSet`&&I(e.base)){let r=e.startPass?.(!1);return r?Bc(e.base,n,e=>r.test(e)&&t(e))?!0:(r.end(),!1):Bc(e.base,n,n=>e.test(n,!1)&&t(n))}if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&n!==void 0)return tc(kc(e,n),t);if(Wc(e)?.some(Kc))return Cs(e,!1,Uc).some(t);if(e.kind===`Subset`&&e.enumerated===void 0&&R(e.base)>20)return $o(ns(e),t,e.cost?.node);if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&!e.enumerated)return hs(e,!1)?vs(e,z.sets?Pc(e,!1):void 0,!0).some(t):tc(Ks(e),t);if(e.kind!==`SetOperation`)return _s(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 Bc(e.left,r?.left,t)||Bc(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)?Bc(i,n,n=>B(n,a)===(e.operator===`\\cap`)&&t(n)):L(e).elements.some(t)},Yc=()=>!0,Xc=e=>`Shouldn't call isEmpty() on value ${U(e)}`,Zc=e=>{if(typeof e!=`object`||!wr(e))throw z.sets?.push(e),P(Xc,e);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return il(e.low,e.high)===0;case`InfiniteSet`:if(e.name===`Any`)throw new n(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1}let t=z.sets;if(t===void 0)return Qc(e);t.push(e);let r=Qc(e);return t.pop(),r},Qc=e=>{switch(e.kind){case`ProductSet`:return e.factors.some(Zc);case`RecordSet`:return e.sets.some(Zc);case`FunctionSet`:return!Zc(e.domain)&&Zc(e.range);case`Union`:return Wo(e).every((t,n)=>Zc(qo(t,n,e)));default:return!Vc(e,Yc)}},$c=(e,t,n)=>e.reduce((e,r)=>{let i=e*R(r,t);if(i>2147483647)throw P(n);return i},1),el=e=>`Overflow when computing the number of elements in:\n${N(U(e))}`,tl=e=>`Attempted to compute the number of elements in the ${kr(e)} ${N(U(e))}.`,nl=e=>`Attempted to compute the number of elements in the model value ${N(U(e))}.`,rl=e=>`Attempted to compute the number of elements in the overridden value ${N(U(e))}.`,il=(e,t)=>{let r=Math.max(0,t-e+1);if(r>2147483647)throw new n(`Size of interval value exceeds the maximum representable size (32bits): ${e}..${t}.`);return r},R=(e,t)=>{if(typeof e!=`object`)throw P(tl,e);switch(e.kind){case`ModelValue`:throw P(nl,e);case`Operator`:throw P(tl,e);case`Function`:return e.domain.length;case`LazyFunction`:return R(e.domain,t);case`Interval`:return il(e.low,e.high);case`InfiniteSet`:case`SequenceSet`:throw P(rl,e);case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:{let n=z.sets;n?.push(e);let r=al(e,t);return n?.pop(),r}default:return ks(e).elements.length}},al=(e,t)=>{switch(e.kind){case`Subset`:{let n=R(e.base,t);if(n>=31)throw P(el,e);return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(Zc(e.domain))return 1;if(Zc(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(el,e);return i}case`RecordSet`:return t!==`1.7.4`&&Zc(e)?0:$c(e.sets,t,()=>el(e));case`ProductSet`:return t!==`1.7.4`&&Zc(e)?0:$c(e.factors,t,()=>`Overflow when computing the number of elements in ${N(U(e))}`)}},ol=e=>`Attempted to check if the set ${N(U(e))}is finite.`,sl=e=>{if(typeof e!=`object`||e.kind===`ModelValue`||e.kind===`Operator`)throw new n(`Attempted to check if the ${kr(e)} ${N(U(e))} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new n(`Attempted to check if the function:\n${N(U(e))}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return sl(e.base)&&Zc(e.base);case`Subset`:return sl(e.base);case`FunctionSet`:{let t=sl(e.domain);if(t&&Zc(e.domain))return!0;let n=sl(e.range);return n&&Zc(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(!sl(e))n=!1;else if(Zc(e))return!0;return n}case`Union`:if(!I(e.base))throw new n(`Attempted to check if the nonenumerable set:\n${Ho(e)}\nis a finite set.`);return L(e.base).elements.every(sl);case`SetOperation`:if(e.operator===`\\cup`)return sl(e.left)&&sl(e.right);if(e.operator===`\\cap`){if(!sl(e.left)&&!sl(e.right))throw new n(ol(e));return!0}if(sl(e.left))return!0;if(!sl(e.right))throw new n(ol(e));return!1;case`FilteredSet`:if(!sl(e.base))throw new n(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${N(U(e.base))}\nis finite.`);return!0}},cl=(e,t,n=ki)=>{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},ll=(e,t)=>{let n=e.elements;if(n.length>vr())throw new D(yr());let r=Array.from({length:n.length},()=>!1),i=t.filter(e=>{let t=cl(n,e);return!r[t]&&(r[t]=!0,!0)}),a=Li(n);return i.some((e,t)=>e!==n[t])&&(a.writtenElements=i),a},ul=e=>e instanceof Oo&&e.interval.low===1||e.every((e,t)=>e===t+1),dl=e=>{let t=_s(e.domain),n=[];for(let r=0;r<t.length;r++){if(t[r]!==r+1)return;n.push(e.apply(t[r]))}return eu(e)&&e.costModel.node>=0&&(e.costModel.secondary[e.costModel.node]+=t.length),n},fl=e=>typeof e.domain==`object`&&e.domain.kind===`Interval`?e.domain.low===1||e.domain.high<e.domain.low:ul(_s(e.domain)),pl=e=>{if(typeof e!=`object`||!Er(e))return;if(e.kind===`LazyFunction`){if(e.boundTupleLengths!==void 0)return;if(!wr(e.domain)||hi(e.domain))throw new n(`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||!fl(e)))return dl(e)}let t=V(e);if(ml(t.domain))return pa(e),t.range},ml=e=>e.length===0||e[0]===1&&e[e.length-1]===e.length,hl=(e,t)=>{if(typeof t==`object`&&t.kind===`Operator`)return`Attempted to check if the value:\n${N(U(e))}\nis an element of operator ${N(U(t))}`;let n=`Attempted to check if the value:\n${N(U(e))}\nis an element of the`;if(!Er(t))return`${n} ${kr(t)} ${N(U(t))}`;let r=Hi(t);return r===`record`?`Attempted to check if element:\n${N(U(e))}\nis in the record:\n${N(U(t))}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${N(U(t))}`},z={sets:void 0},gl=()=>{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}},_l=e=>{e!==void 0&&(z.sets&&(z.sets.length=e.depth),z.callStack&&(z.callStack.fingerprint=e.fingerprint))},vl=e=>{_l(e);let t=z.callStack;e!==void 0&&t&&(t.expressions.length=e.length,t.isFrozen=e.isFrozen)},yl=(e,t,r,i,a)=>{let o=gl(),s=_i;_i=`stopping`;try{let t=e(r,i);return _i=s,t}catch(e){if(_i=s,!(e instanceof g)){if(!(e instanceof n))throw e;if(a?.(r,i))throw xl(e)}return vl(o),t(r,i)}},bl=(e,t,r,i)=>{let a=gl(),o=_i;_i=`deferring`;try{let t=e(r,i);return _i=o,t}catch(e){if(_i=o,!(e instanceof n))throw e;return vl(a),t(r,i)}},xl=e=>(_i===`none`&&e.formatMessage(),e),Sl=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 jl(e,t);n.push(t);let r=jl(e,t);return n.pop(),r},Cl=(e,t)=>{let n=z.sets;n?.push(t);let r=Ol(e,t);return n?.pop(),r},wl=(e,t)=>{let n=z.sets;n?.push(t);let r=Ua(e,t.elements);return n?.pop(),r.isFound?r.index:-1},Tl=(e,t,n)=>{let r=z.sets;if(r===void 0)return Ql(e,t,n);r.push(t);let i=Ql(e,t,n);return r.pop(),i},El=(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},Dl=(e,t)=>cl(t.elements,e)!==-1,Ol=(e,t)=>pr(t)?Ua(e,t.elements).isFound:Wa(e,Ga(t)),kl=(e,t)=>`Attempted to check if the typed model value ${N(U(e))} is an element of\n${N(U(t))}`,Al=(e,t)=>{if(e.type!==void 0)throw P(kl,e,t);return!1},jl=(e,t)=>{if(typeof e==`number`&&typeof t==`object`){if(t.kind===`Set`&&!ji)return El(e,t)??Zl(e,t);if(t.kind===`Interval`)return e>=t.low&&e<=t.high}return Zl(e,t)},Ml=(e,t)=>`Attempted to check if the non-enumerable value\n${N(U(e))}\nis element of\n${N(U(t))}`,Nl=(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},Pl=(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`?Nl(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},Fl=(e,t,n)=>{if(!wr(e)||hi(e))throw P(Ml,e,t);return!Vc(e,e=>!n(e,t.base))},Il=(e,t)=>`Attempted to check if \n${U(e)}\nwhich is not a TLC function value, is in the set of functions:\n${N(U(t))}`,Ll=(e,t)=>`Attempted to check if non-record\n${U(e)}\nis in the set of records:\n${N(U(t))}`,Rl=(e,t)=>`Attempted to check if non-tuple\n${N(U(e))}\nis in the set of tuples:\n${N(U(t))}`,zl=(e,t)=>{if(!Er(e)){if(Dr(e))return Al(e,t);throw P(Il,e,t)}Ir(e);let n=da(e),r=ua(e,n.domain);return(r===void 0?to(t.domain,Li(n.domain)):eo({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range},Bl=(e,t)=>{Ir(e);let n=Er(e)?V(e):void 0;if(!n||!Lr(n.domain)){if(Dr(e))return Al(e,t);throw P(Ll,e,t)}return pa(n),n.domain.length===t.names.length&&n},Vl=(e,t)=>{let n=Er(e)?pl(e):void 0;if(n===void 0){let n=Er(e)&&da(e).domain.every(e=>typeof e==`number`);if(Dr(e))return Al(e,t);if(n)return!1;throw P(Rl,e,t)}return n.length===t.factors.length&&n},Hl=(e,t)=>e instanceof n&&zn(e)&&!Sl(t),Ul=(e,t)=>`Cannot decide if element:\n${N(U(e))}\n is element of:\n${N(U(t.base))}\nand satisfies the predicate ${t.source?.predicate}`,Wl=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},Gl=(e,t)=>`Attempted to check if:\n ${N(U(e))}\nis an element of the non-enumerable set:\n ${N(Ho(t))}`,Kl=(e,t,n)=>{if(!I(t.base))throw P(Gl,e,t);return Vc(t.base,t=>n(e,t))},ql=(e,t)=>`Attempted to check if the value:\n${N(U(e))}\nis an element of ${N(U(t))}.`,Jl=(e,t)=>{let n=pl(e);if(n===void 0){if(Dr(e))return Al(e,t);throw new s(yi(ql,e,t))}return n},Yl=(e,t)=>`Attempted to check if the value:\n${N(U(e))}\nis in the integer interval ${N(U(t))}`,Xl=(e,t)=>`Attempted to check if the value:\n${N(U(e))}\nis an element of ${t.name}.`,Zl=(e,t)=>{if(!wr(t))throw P(hl,e,t);switch(t.kind){case`Set`:return ji||Ui(e)||Qi(e)?Ol(e,t):yl(Dl,Ol,e,t);case`MixedSet`:return t.enumerated?Ua(e,t.enumerated.elements).isFound:Wa(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&(!Dr(e)||e.type!==void 0))throw P(Yl,e,t);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(Dr(e))return Al(e,t);if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new s(yi(Xl,e,t));return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:return typeof e==`object`&&e.kind===`Interval`?Pl(e,t.base,B):Tr(e)?L(e).elements.every(e=>B(e,t.base)):Fl(e,t,B);case`FunctionSet`:{let n=zl(e,t);return n!==!1&&n.every(e=>B(e,t.range))}case`RecordSet`:{let n=Bl(e,t);return n!==!1&&t.names.every((e,r)=>{let i=cl(n.domain,e);return i!==-1&&B(n.range[i],t.sets[r])})}case`ProductSet`:{let n=Vl(e,t);return n!==!1&&n.every((e,n)=>B(e,t.factors[n]))}case`FilteredSet`:{if(t.isCached)return B(e,L(t));let n=z.sets?.length??0;try{return B(e,t.base)&&t.test(e,!0)}catch(r){throw Hl(r,n)?P(Ul,e,t):r}}case`Union`:return Tr(t.base)?Wl(t.base).some(t=>B(e,t)):Kl(e,t,B);case`SetOperation`:return t.operator===`\\cup`?B(e,t.left)||B(e,t.right):B(e,t.left)&&B(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Jl(e,t);return n!==!1&&n.every(e=>B(e,t.base))}default:throw P(hl,e,t)}},Ql=(e,t,n)=>{if(typeof t!=`object`)return Zl(e,t);switch(t.kind){case`Subset`:return typeof e==`object`&&e.kind===`Interval`?Pl(e,t.base,n):Tr(e)?L(e).elements.every(e=>n(e,t.base)):Fl(e,t,n);case`FunctionSet`:{let r=zl(e,t);return r!==!1&&r.every(e=>n(e,t.range))}case`RecordSet`:{let r=Bl(e,t);return r!==!1&&t.names.every((e,i)=>{let a=cl(r.domain,e);return a!==-1&&n(r.range[a],t.sets[i])})}case`ProductSet`:{let r=Vl(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 Hl(n,r)?P(Ul,e,t):n}}case`Union`:return Tr(t.base)?Wl(t.base).some(t=>n(e,t)):Kl(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=Jl(e,t);return r!==!1&&r.every(e=>n(e,t.base))}default:return Zl(e,t)}},$l=(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)=>$l(e,t.range[r],n.range)),eu=e=>`costModel`in e,tu=e=>eu(e)?e.costModel.node:-1,nu=e=>`original`in e,ru=e=>{let t=[];for(let n=e;nu(n);n=n.original)t.push(n);return t},iu=(e,t)=>{let n=ru(e);return t.map(t=>{let r=e.applyBody(t);for(let e=n.length-1;e>=0;e--){let i=n[e];eo(i.path[i.depth],t)&&(r=Pu(r,i.path,i.depth+1,i.newValue))}return r})},au=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(oo)throw new n(`The set literal holds a lazy function`);let t=eu(e)?e.costModel.startConversion():void 0;if(R(e.domain),!wr(e.domain))throw new n(`The domains of formal parameters must be enumerable.`);let r=Io(e.domain,!1),i=nu(e)?iu(e,r):r.map(t=>e.apply(t));return e.enumerated=Ha(e.domain,r,i),t?.(),e.enumerated}throw P(au,e)},ou=(e,t,n)=>{let r=N(U(e)),i=N(U(t)),a=n===`1.7.4`;switch(Hi(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.`}},su=(e,t)=>{if(!$r)return ou(e,t);let n=N(U(t));return Hi(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},cu=(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},lu=e=>new n(`Attempted to apply function with integer domain to the non-integer argument ${N(U(e))}`),uu=(e,t)=>cl(e.domain,t),du=(e,t)=>{let n=Mr(e),r=e.domain;if(!$r&&n===r&&n.length>=32)return cl(n,t,(e,t)=>La(e,()=>Na(e,t)));let i=n.findIndex(e=>La(e,()=>Pa(e,t)));return i===-1||n===r?i:r.indexOf(n[i])},fu=(e,t,r)=>{let i=e.domain;if(typeof t!=typeof i[0]){let a=Hi(e),o=a===`tuple`?`number`:a===`record`?`string`:void 0;if(o!==void 0&&typeof t!==o)throw new n(r(e,t));if(o===void 0&&!$r&&typeof t!=`number`&&Fo(i))throw lu(t)}let a=cu(i,t);return a===-1?bl(uu,du,e,t):a},pu=(e,t)=>{let r=fu(e,t,ou);if(r===-1)throw new n(ou(e,t));return r},mu=(e,t,n,r)=>`In applying the function\n${N(U(e))},\nthe ${t} is:\n${N(U(n))}\nwhich ${r}.\n`,hu=(e,t)=>new n(mu(e,`argument list`,t,`does not match its formal parameter`)),gu=e=>new n(`Attempted to apply a function to ${U(e)}, which is not in its domain`),_u=(e,t,r,i)=>new n(mu(e,`argument number ${t+1}`,r,i===void 0?`is not in the function's domain ${U(e.domain)}`:`is not in its domain`)),vu=(e,t)=>typeof e==`object`&&e.kind===`Function`&&e.functionClass===`tuple`?e:F(t),yu=(e,t,r,i)=>{if(i===void 0)return r;let a=pl(r);if(a===void 0||a.length!==i)throw new n(mu(e,`argument number ${t+1}`,r,`does not match its formal parameter`));return vu(r,a)},bu=(e,t,n)=>{let r=e.domain,i=pl(n);if(i===void 0)throw hu(e,n);if(typeof r!=`object`||r.kind!==`ProductSet`)throw gu(n);let a=i;for(let o=0;o<t.length;o++){if(o>=i.length)throw hu(e,n);let s=i[o],c=t[o];if(!B(s,r.factors[o]))throw _u(e,o,s,c);let l=yu(e,o,s,c);l!==s&&(a===i&&(a=[...i]),a[o]=l)}if(i.length>t.length)throw hu(e,n);return a===i?vu(n,i):F(a)},xu=(e,t,n,r)=>{let i=e.domain,a=pl(n);if(a===void 0)throw hu(e,n);if(typeof i!=`object`||i.kind!==`ProductSet`)throw gu(n);let o=a;for(let s=0;s<t.length;s++){if(s>=a.length)throw hu(e,n);let c=a[s],l=t[s];if(!r(c,i.factors[s]))throw _u(e,s,c,l);let u=yu(e,s,c,l);u!==c&&(o===a&&(o=[...a]),o[s]=u)}if(a.length>t.length)throw hu(e,n);return o===a?vu(n,a):F(o)},Su=(e,t,r)=>{let i=e.boundTupleLengths;if(i!==void 0)return xu(e,i,t,r);if(!r(t,e.domain))throw new n(ou(e,t));return t},Cu=(e,t,n,r)=>t.apply(Su(e,n,r)),wu=(e,t,n)=>{if(e.boundTupleLengths!==void 0&&pl(n)===void 0)throw hu(e,n);return B(n,e.domain)?t.apply(n):void 0},Tu=(e,t,n)=>t.apply(n),Eu=(e,t,n,r)=>{let i,a=e;for(;nu(a);){if(eo(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=nu(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=Pu(s,t.path,t.depth+1,t.newValue)}return s},Du=(e,t,r)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(e.enumerated)return Du(e.enumerated,t,r);if(nu(e))return Eu(e,t,B,Cu);let i=e.boundTupleLengths;if(i!==void 0)return e.apply(bu(e,i,t));if(!B(t,e.domain))throw new n(ou(e,t));return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new n(`Attempted to apply ${U(e)}, which is not a function`);let i=r??ou,a=fu(e,t,i);if(a===-1)throw new n(i(e,t));return e.range[a]},Ou=(e,t,n,r)=>typeof e!=`object`||e.kind!==`LazyFunction`||e.enumerated!==void 0?Du(e,t,n):nu(e)?Eu(e,t,r,Cu):e.apply(Su(e,t,r)),ku=e=>e instanceof Oo?e.interval:void 0,Au=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return e.domain;let t=V(e),n=ku(t.domain);if(n)return n;let r=Li(t.domain);return t.functionClass===`record`?(t.writtenKeys&&(r.writtenElements=t.writtenKeys),r):(r.flags|=1,r)},ju=(e,t,n,r)=>{let i={kind:`LazyFunction`,domain:e.domain,apply:e=>Eu(i,e,B,Tu),source:e.source,boundTupleLengths:e.boundTupleLengths,isApplicationObserved:e.isApplicationObserved,original:e,path:t,depth:n,newValue:r,applyBody:nu(e)?e.applyBody:e.apply};return eu(e)?Object.assign(i,{costModel:e.costModel}):i},Mu=e=>{if(!Er(e))throw new n(`Attempted to apply EXCEPT construct to the value ${N(U(e))}.`);return V(e)},Nu=(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=Eu(r,n,B,wu);if(e===void 0)return;r=e;continue}let i=Mu(r),a=fu(i,n,su);if(a===-1)return;r=i.range[a]}return r},Pu=(e,t,n,r)=>{if(n===t.length)return r;if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return ju(e,t,n,r);let i=Mu(e),a=fu(i,t[n],su);return a===-1?i:zu(i,a,Pu(i.range[a],t,n+1,r))},Fu=(e,t,n,r)=>{if(n===t.length)return r(e);if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0){let i=Nu(e,t,n);return i===void 0?e:ju(e,t,n,r(i))}let i=Mu(e),a=fu(i,t[n],su);return a===-1?i:i instanceof rr?ur(i,a,Fu(ar(i,a),t,n+1,r)):zu(i,a,Fu(i.range[a],t,n+1,r))},Iu=0,Lu=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return nd(e);if(e.kind===`LazyFunction`)return e.enumerated===void 0?0:Lu(e.enumerated);if(e.kind===`Set`){if(!pr(e))return 0;if(e.hash!==0)return e.hash;let t=e.elements,n=Uu;for(let e=0;e<t.length;e++){let r=Lu(t[e]);if(r===0||r===qu)return r;n=n+Gu(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=Wu;for(let n=0;n<e.domain.length;n++){let r=Lu(e.domain[n]);if(r===0||r===qu)return r;let i=Lu(e.range[n]);if(i===0||i===qu)return i;t=t+Ku(r,i)|0}return e.hash=t,t},Ru=(e,t)=>{let n=Vi(Bi(e.domain,t),e.functionClass),r=e.hash!==0&&e.hash!==qu,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=Lu(o);if(s===0||s===qu){r=!1;continue}let c=nd(e.domain[n]);i=i-Ku(c,nd(a))+Ku(c,s)|0}return r&&(n.hash=i),n},zu=(e,t,n)=>{let r=[...e.range],i=e.range[t];r[t]=n;let a=Vi(Bi(e.domain,r),e.functionClass);a.writtenKeys=e.writtenKeys;let o=e.hash!==0&&e.hash!==qu;if(!o&&e.fingerprint===0)return a;let s=Lu(n);if(s===0||s===qu)return a;if(o){let r=nd(e.domain[t]);a.hash=i===n?e.hash:e.hash-Ku(r,nd(i))+Ku(r,s)|0}if(e.fingerprint!==0){let r=e.domain[t];a.fingerprint=i===n?e.fingerprint:e.fingerprint-od(r,i)+od(r,n)|0}return a},Bu=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Vu=(e,t)=>Math.imul(e^t,16777619),Hu=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Bu(t)},Uu=1940243425,Wu=1725019383,Gu=e=>Bu(e+2654435769|0),Ku=(e,t)=>Bu(Math.imul(e,668265261)+t|0),qu=795548749,Ju=e=>e===qu,Yu=e=>{if(e instanceof rr)return cr(e);if(e.kind===`Set`){let t=e.elements,n=Uu;for(let e=0;e<t.length;e++){let r=nd(t[e]);if(r===qu)return qu;n=n+Gu(r)|0}return n}let t=Wu;for(let n=0;n<e.domain.length;n++){let r=nd(e.domain[n]),i=nd(e.range[n]);if(r===qu||i===qu)return qu;t=t+Ku(r,i)|0}return t},Xu=e=>{let t=e.low+il(e.low,e.high),n=Uu;for(let r=e.low;r<t;r++)n=n+Gu(nd(r))|0;return n},Zu=e=>new n(`TLC has found a state in which the value of a variable contains ${N(U(e))}`),Qu=e=>{typeof e==`object`&&e.kind!==`ModelValue`&&La(e,()=>{if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw Zu(e);if(wr(e)){for(let t of L(e).elements)Qu(t);return}let t=V(e);for(let[e,n]of t.domain.entries())Qu(n),Qu(t.range[e])})},$u=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{nd(e)===qu&&Qu(e);return}catch(e){if(!(e instanceof n))throw e;return e}},ed=e=>{let t=z.sets,r=[];z.sets=r;try{Qu(e)}catch(e){if(!(e instanceof n))throw e}finally{z.sets=t}return r},td=e=>Bu(e^1540483477),nd=e=>{if(typeof e==`number`)return td(e);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Hu(e);if(e.kind===`Set`||e.kind===`Function`)return e.kind===`Set`&&(e.flags|=1),e.hash===0&&(e.hash=Yu(e),e.hash!==qu&&(e.flags|=4)),e.hash;if(e.kind===`ModelValue`)return e.hash;if(e.kind===`LazyFunction`)return Jo(e.domain)?nd(V(e)):qu;if(e.kind===`Interval`)return Xu(e);if(!Jo(e))return qu;let t=Ds(e),n=t?As(t,!0,L):L(e);return $i(e),nd(n)},rd=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},id=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return rd(t)},ad=e=>rd(ud(e)+2135587861|0),od=(e,t)=>rd(Math.imul(ud(e),374761393)+ud(t)|0),sd=461845907,cd=e=>{if(e.kind===`Set`){let t=e.elements,n=sd;for(let e=0;e<t.length;e++)n=n+ad(t[e])|0;return n}let t=1291169091;for(let n=0;n<e.domain.length;n++)t=t+od(e.domain[n],e.range[n])|0;return t},ld=e=>{let t=e.low+il(e.low,e.high),n=sd;for(let r=e.low;r<t;r++)n=n+ad(r)|0;return n},ud=e=>typeof e==`number`?rd(e^1759714724):typeof e==`boolean`?e?1000000007:521288629:typeof e==`string`?id(e):e.kind===`Set`||e.kind===`Function`?(e.fingerprint===0&&(e.fingerprint=cd(e)),e.fingerprint):e.kind===`ModelValue`?e.fingerprint:e.kind===`LazyFunction`?ud(V(e)):e.kind===`Interval`?ld(e):Jo(e)?ud(L(e)):id(dd(e)),dd=e=>typeof e==`boolean`?e?`T`:`F`:typeof e==`number`?String(e):typeof e==`string`?JSON.stringify(e):fd(e),fd=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${dd(e.base)}>`;if(e.kind===`FilteredSet`&&!Jo(e))throw new n(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(wr(e))return Jo(e)?`{${L(e).elements.map(dd).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let t=V(e);return`(${t.domain.map((e,n)=>`${dd(e)}:${dd(t.range[n])}`).join(`,`)})`},pd={'"':`\\"`,"\\":`\\\\`," ":`\\t`,"\n":`\\n`,"\f":`\\f`,"\r":`\\r`},md=e=>`"${e.replace(/["\\\t\n\f\r]/g,e=>pd[e])}"`,hd=1999,gd=e=>e.reduce((e,t)=>e===0?0:e*R(t),1),_d=e=>{let t=Ds(e);return t?As(t,!1,Es):Es(e)},vd=e=>{if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return _d(e);if(e.cost?.charges?.chargePrintedSize(e),e.kind===`Subset`)return R(e.base)>6?void 0:_d(e);if(e.kind===`FunctionSet`){let t=Zc(e.domain)?0:R(e.domain);return(t===0?1:R(e.range)**t)<=hd?_d(e):void 0}return gd(e.kind===`RecordSet`?e.sets:e.factors)<=hd?_d(e):void 0},yd=(e,t)=>{if(t||e.kind===`Subset`&&Er(e.base)&&(e.base.kind===`Function`||Jo(e.base.domain)))return vd(e);let r=gl();try{return vd(e)}catch(e){if(!(e instanceof n))throw e;_l(r);return}},H=(e,t)=>{e.pending===void 0?e.parts.push(t):e.pending.push(t)},bd=(e,t)=>{e.pending===void 0?t?.pop():e.pending.push({kind:`SetEnd`,sets:t})},xd=(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;zd(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},Sd=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?xd(e,t,n,r):(e.depth++,zd(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isStrict:n,isNormalized:r})},Cd=(e,t,n,r,i)=>{for(let a=0;a<t.length;a++)a>0&&H(e,n),Sd(e,t[a],r,i)},wd=/* @__PURE__ */ new Set([`Set`,`MixedSet`,`Interval`,`Subset`,`FunctionSet`,`RecordSet`,`ProductSet`,`SetOperation`,`FilteredSet`,`Union`]),Td=e=>!$r&&typeof e==`object`&&wd.has(e.kind),Ed=(e,t,n,r)=>{r&&H(e,`(`),Sd(e,t,n,!1),r&&H(e,`)`)},Dd=(e,t,n)=>{switch(t.kind){case`Subset`:return H(e,`SUBSET `),Ed(e,t.base,n,typeof t.base==`object`&&(t.base.kind===`Interval`||t.base.kind===`SetOperation`));case`FunctionSet`:return H(e,`[`),Sd(e,t.domain,n,!1),H(e,` -> `),Sd(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]}: `),Sd(e,t.sets[r],n,!1);return H(e,`]`);case`ProductSet`:return H(e,`(`),Cd(e,t.factors,` \\X `,n,!1),H(e,`)`);case`SetOperation`:return Ed(e,t.left,n,Td(t.left)),H(e,` ${t.operator} `),Ed(e,t.right,n,Td(t.right));case`FilteredSet`:return H(e,t.source?`{${t.source.names} \\in `:`{x \\in `),Sd(e,t.base,n,!1),H(e,t.source?` : <expression ${t.source.predicate}> }`:` : ...}`);case`Union`:return H(e,`UNION(`),Sd(e,t.base,n,!1),H(e,`)`)}},Od=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),kd=e=>{if(!Jo(e.domain))return;let t=gl();try{return V(e)}catch(e){if(!(e instanceof n)&&!re(e))throw e;_l(t);return}},Ad=(e,t,n)=>{t.kind===`Set`?mr(t,!0):L(t),n&&e.copies.push(t)},jd=(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(Gc),c=s?t.domain:[...t.domain];s||Ra(c,o);let l={...t,domain:c,range:o,writtenKeys:a};e.copies.push(n?{...n,enumerated:l}:l)},Md=(e,t,n)=>{e.pending===void 0?Ad(e,t,n):e.pending.push({kind:`SetEnd`,value:t,isCopied:n})},Nd=(e,t,n,r,i)=>{e.pending===void 0?jd(e,t,n,r,i):e.pending.push({kind:`FunctionEnd`,value:t,lazy:n,isWrittenOrderKept:r,isCopied:i})},Pd=(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`){Ad(e,t.value,t.isCopied);continue}if(t.kind===`FunctionEnd`){jd(e,t.value,t.lazy,t.isWrittenOrderKept,t.isCopied);continue}let n=i.length;Ld(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},Fd=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?Pd(e,t,n,r):(e.depth++,Ld(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isWrittenOrderKept:n,isCopied:r})},Id=(e,t,n,r)=>{for(let i=0;i<t.length;i++)Fd(e,t[i],n,r)},Ld=(e,t,n,r)=>{if(typeof t==`object`)switch(t.kind){case`Set`:case`MixedSet`:return Id(e,t.elements,n,!1),Md(e,t,r);case`Function`:return Id(e,t.range,n,r),Nd(e,t,void 0,n,r);case`LazyFunction`:if(t.enumerated)return Id(e,t.enumerated.range,!0,r),Nd(e,t.enumerated,t,!0,r);Fd(e,t.domain,n,!1),r&&e.copies.push({...t});return;case`SetOperation`:Fd(e,t.left,n,!1),Fd(e,t.right,n,!1);break;case`FunctionSet`:Fd(e,t.domain,n,!1),Fd(e,t.range,n,!1);break;case`RecordSet`:Id(e,t.sets,n,!1);break;case`ProductSet`:Id(e,t.factors,n,!1);break;case`Subset`:case`Union`:case`FilteredSet`:case`SequenceSet`:Fd(e,t.base,n,!1)}r&&e.copies.push(t)},Rd=e=>{let t={depth:0,pending:void 0,copies:[]};for(let n of e)Ld(t,n,!1,!0);return t.copies.map(e=>U(e,!0,!0))},zd=(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,md(t));switch(t.kind){case`ModelValue`:return H(e,t.name);case`Set`:return H(e,`{`),Cd(e,t.elements,`, `,n,r),H(e,`}`);case`MixedSet`:return Sd(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=ei.isExpanded?yd(t,n):void 0;return a?Sd(e,a,n,r):Dd(e,t,n),bd(e,i)}case`SequenceSet`:return H(e,`Seq(`),Sd(e,t.base,n,r),H(e,`)`);case`Function`:case`LazyFunction`:{let i=t.kind===`LazyFunction`?ei.isExpanded||!t.source?kd(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 `),Sd(e,r.domain,!1,!1)}return H(e,` |-> <expression ${n.body}>]`)}if(i.domain.length===0&&$r&&Hi(t)!==`tuple`)return H(e,`<< >>`);if(i.domain.length===0&&Hi(t)===`record`)return H(e,`[]`);let a=r&&Hi(t)!==`lambda`;if(ul(i.domain))return i.range.every(e=>typeof e==`number`)?H(e,`<<${i.range.join(`, `)}>>`):(H(e,`<<`),Cd(e,i.range,`, `,n,a),H(e,`>>`));let o=r?i.domain.map((e,t)=>[e,i.range[t]]):Pr(i);if(Hi(t)===`record`||i.domain.every(e=>typeof e==`string`&&Od(e))){H(e,`[`);for(let t=0;t<o.length;t++)H(e,`${t>0?`, `:``}${String(o[t][0])} |-> `),Sd(e,o[t][1],n,a);return H(e,`]`)}H(e,`(`);for(let t=0;t<o.length;t++)t>0&&H(e,` @@ `),Sd(e,o[t][0],n,r),H(e,` :> `),Sd(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 zd(r,e,t,n),r.parts.join(``)},Bd=(e,t)=>{if(e===void 0)return!1;try{return ea(e,t)}catch(r){if(r instanceof n)return e===t;throw r}},Vd=/%(\d+\$)?([-#+ 0,(<]*)(\d+)?(\.\d+)?(.?)/gs,Hd=(e,t)=>{let n=0,r=-1,i=!0,a=e.replace(Vd,(e,a,o=``,s,c,l=``)=>{let u=e=>o.includes(`-`)?e.padEnd(Number(s)):e.padStart(Number(s??0)),d=o.includes(`<`),f=o.replace(`<`,``);if(l===`n`&&e===`%n`)return`
|
|
9
|
+
import{t as e}from"./rolldown-runtime.js";import{C as t,D as n,E as r,Et as i,F as a,Ft as o,H as s,J as c,N as l,O as u,P as d,S as f,T as p,U as m,X as h,Z as g,_t as _,at as v,et as y,gt as b,ht as x,it as S,k as C,lt as w,mt as T,ot as ee,pt as E,q as D,rt as O,ut as te,w as ne,wt as re,x as ie}from"./worker.js";import{$ as k,$t as ae,A as oe,At as se,B as ce,Bt as le,C as ue,Ct as de,D as fe,Dt as pe,E as me,Et as he,F as ge,Fn as _e,Ft as ve,G as ye,Gt as A,H as be,Ht as xe,I as Se,In as Ce,It as we,J as Te,Jt as Ee,K as De,Kt as Oe,L as ke,Ln as Ae,Lt as je,M as Me,Mt as Ne,N as Pe,Nt as Fe,O as Ie,On as Le,Ot as Re,P as ze,Pt as Be,Q as Ve,Qt as He,R as Ue,Rt as We,S as Ge,Sn as Ke,St as qe,T as Je,Tt as Ye,U as Xe,Ut as Ze,V as Qe,Vt as $e,W as et,Wt as tt,X as nt,Xt as rt,Y as it,Yt as at,Z as ot,Zt as st,_ as ct,_t as lt,a as ut,an as dt,ar as ft,at as pt,b as mt,bn as ht,bt as gt,c as _t,cr as vt,ct as yt,d as bt,dr as xt,dt as St,en as Ct,er as wt,et as Tt,f as Et,fr as j,ft as Dt,g as Ot,gt as kt,h as At,hr as jt,ht as Mt,in as Nt,ir as Pt,it as Ft,j as It,jt as Lt,k as Rt,kn as zt,kt as Bt,l as Vt,lr as Ht,lt as Ut,m as Wt,mr as Gt,mt as Kt,n as qt,nn as Jt,nr as Yt,nt as Xt,o as Zt,on as Qt,or as $t,ot as en,p as tn,pr as nn,pt as rn,q as an,qt as on,rn as sn,rr as cn,rt as ln,s as un,sr as dn,st as fn,t as pn,tn as mn,u as hn,ur as gn,ut as _n,v as vn,vt as yn,w as bn,wn as xn,wt as Sn,x as Cn,xn as wn,xt as Tn,y as En,yt as Dn,z as On,zt as kn}from"./order.js";import{C as An,a as jn,b as Mn,d as Nn,f as Pn,i as Fn,p as In,s as Ln,x as Rn,y as zn}from"./modules.js";const Bn=(e,t)=>t.rootKeys.get(e)??e,Vn=e=>`line ${e.location.line}, column ${e.location.column}`,M=e=>{let t=e.location.range;return t?b(t):Vn(e)},Hn=e=>e.kind===`Number`?e.text??String(e.value):M(e),Un=1e3,Wn={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:` `}},Gn=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},Kn=e=>e!==void 0&&/^\p{Nd}$/u.test(e),qn=e=>e!==void 0&&/^[\p{L}\p{Nd}]$/u.test(e),Jn=e=>e.kind!==`Constant`,Yn=(e,t,n)=>({kind:e,first:t,last:n,children:[]}),Xn=`Parsed`,Zn=e=>{let t=t=>{let n=wt(e,t,Gn);return e[n]===void 0?void 0:n},n=(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 c=t(n.last);if(c!==void 0)return e[c]===i?(n.last=c,Xn):a===void 0?s(c):Yn(a,c,c)},r=(n,r,i)=>{if(!r)return s(n.last);if(n.children.length===1)return n.children=[n.children[0],r],n.last=r.last,Xn;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:s(o)},i=(i,a)=>{switch(i.kind){case`Set`:return n(i,a,`}`,void 0,`,`);case`Sequence`:{let t=n(i,a,`>`,void 0,`,`);return t===Xn?i.last+1>=e.length?void 0:(i.last++,Xn):t}case`Record`:return n(i,a,`]`,`RecordPair`,`,`);case`RecordPair`:return r(i,a,`|->`);case`Function`:return n(i,a,`)`,`FunctionPair`,`@@`);case`Subset`:{if(a)return i.children=[a],i.last=a.last,Xn;let e=t(i.last);return e===void 0?void 0:s(e)}case`FunctionPair`:return r(i,a,`:>`)}},a=t=>{let n=wt(e,t,Kn);if(e.startsWith(`..`,n)&&Kn(e[n+2]))return{kind:`Constant`,first:t,last:wt(e,n+2,Kn)-1,children:[]}},o=t=>{let n=e[t];if(n===`"`){let n=e.indexOf(`"`,t+1);return n===-1?void 0:{kind:`Constant`,first:t,last:n,children:[]}}let r=Kn(n)?a(t):void 0;if(r)return r;if(n===`-`)return t+1>=e.length?void 0:{kind:`Constant`,first:t,last:wt(e,t+1,Kn)-1,children:[]};if(qn(n))return{kind:`Constant`,first:t,last:wt(e,t,qn)-1,children:[]}},s=n=>{let r=t(n);if(r!==void 0)switch(e[r]){case`{`:return Yn(`Set`,r,r+1);case`<`:return Yn(`Sequence`,r,r+2);case`[`:return Yn(`Record`,r,r+1);case`(`:return Yn(`Function`,r,r+1);default:return e.startsWith(`SUBSET`,r)?Yn(`Subset`,r,r+6):o(r)}},c=(e,t)=>{let n;if(t<Un)for(;;){let r=i(e,n);if(r===Xn)return e;if(r===void 0||(n=Jn(r)?c(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=i(e,n);if(t===void 0)return;t===Xn?(r.pop(),n=e):Jn(t)?(r.push(t),n=void 0):n=t}return n},l=s(0);return l&&Jn(l)?c(l,0):l},N=e=>{let t=e.length===0?void 0:Zn(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)},c=(e,t,n,r)=>{if(o!==void 0)return o.push({node:e,columnWidth:t,trailerWidth:n,leftPad:r}),!0;if(a<Un){a++;let i=l(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(!l(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},l=(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=Wn[e.kind],c=t-Math.max(o.open.length,o.pad.length),l=i+o.close.length,f=a+o.pad;s(o.open);let p=e.kind===`Function`||e.kind===`Record`?d(e.children,c,l,f,o):u(e.children,c,l,f,o.separator);return s(o.close),p},u=(e,t,n,r,i)=>{for(let a=0;a<e.length;a++){let o=a===e.length-1;if(!c(e[a],t,o?n:i.length,r))return!1;o||s(`${i}\n${r}`)}return!0},d=(e,t,i,a,o)=>{for(let l=0;l<e.length;l++){let u=l===e.length-1,d=e[l].children[0],f=e[l].children[1],p=u?``:`${o.separator}\n${a}`,m=r(d)+o.divider.length+1+r(f);if(u?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(!c(d,t,i+o.divider.length,a))return!1;if(s(`${o.divider}\n${a}${o.dividerPad}`),!c(f,t-o.dividerPad.length,u?i:o.separator.length,a+o.dividerPad))return!1;s(p)}}return!0};return l(t,80,0,``)?i:e},Qn=(e,t)=>t?e:N(e),$n=e=>e.kind!==`ModelValue`&&e.kind!==`Set`&&e.kind!==`Function`&&e.kind!==`Interval`&&e.kind!==`InfiniteSet`&&e.kind!==`LazyFunction`,er=2147483647,tr=e=>(e.flags|=16,e),nr=e=>typeof e==`object`&&e.kind===`Function`&&!!(e.flags&16);var rr=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=Ao(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 ir=e=>e instanceof rr,ar=(e,t)=>e.records[t]??=e.makeRecord(e,t),or=(e,t)=>e.writtenSlots!==void 0&&(e.writtenSlots[t>>5]>>>(t&31)&1)==1,sr=(e,t)=>{let n=e.records[t];return n!==void 0&&or(e,t)?Lu(n):e.hashes[t]},cr=e=>{let t=Wu;for(let n=0;n<e.records.length;n++){let r=e.records[n],i=r!==void 0&&or(e,n)?nd(r):e.hashes[n];if(i===qu)return qu;t=t+Ku(td(n+1),i)|0}return t},lr=e=>e.hash!==Iu&&e.hash!==qu,ur=(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 rr(e.edges,e.locations,e.plans,e.sources,i,e.hashes,Iu,e.makeRecord,r);return a.flags=64,a},dr=(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 rr(e.edges,e.locations,e.plans,e.sources,e.records.slice(0,t),e.hashes,Iu,e.makeRecord,r?n:void 0);if(i.flags=64,!lr(e))return i;let a=e.hash;for(let n=t;n<e.records.length;n++)a=a-Ku(td(n+1),sr(e,n))|0;return i.hash=a,i},fr=(e,t)=>e.records.length===256?F(e.range.concat([t])):ur(e,e.records.length,t),pr=e=>e.kind===`MixedSet`?e.enumerated!==void 0:!!(e.flags&1),mr=(e,t)=>{e.flags=t?e.flags|1:e.flags&-2},hr=1e6;let gr=hr;const _r=()=>gr,vr=()=>Math.max(gr,10),yr=()=>`Attempted to construct a set with too many elements (>${gr}).`,br=(e,t)=>{if(e.length===vr())throw new D(yr());e.push(t)},xr=e=>typeof e==`object`&&e.kind===`Interval`&&e.high-e.low>=vr(),Sr=(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)},Cr=2**27,wr=e=>typeof e==`object`&&e.kind!==`ModelValue`&&e.kind!==`Function`&&e.kind!==`LazyFunction`&&e.kind!==`Operator`,Tr=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`||e.kind===`Interval`),Er=e=>typeof e==`object`&&(e.kind===`Function`||e.kind===`LazyFunction`),Dr=e=>typeof e==`object`&&e.kind===`ModelValue`,Or=e=>typeof e==`object`&&(e.kind===`Set`||e.kind===`MixedSet`),kr=e=>typeof e==`boolean`?`boolean`:typeof e==`number`?`integer`:typeof e==`string`?`string`:e.kind===`ModelValue`?`model value`:e.kind===`Operator`?`operator`:wr(e)?`set`:`function`,Ar=e=>Number.isInteger(e)&&e<=2147483647&&e>=-2147483648,jr=(e,t)=>(e.writtenKeys=t,e),Mr=e=>(e.hash!==0||e.fingerprint!==0?void 0:e.writtenKeys)??e.domain,Nr=e=>{let t=Mr(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]])},Pr=e=>e.domain.every(e=>typeof e==`number`)?e.domain.map((t,n)=>[t,e.range[n]]):Nr(e),Fr=(e,t,n,r)=>{let i=Array(t.length);for(let e=0;e<t.length;e++)i[e]=n[t[e]];return jr(Ro(e,i),r)},Ir=e=>{typeof e==`object`&&e.kind===`Function`&&(e.writtenKeys=void 0)},Lr=e=>{for(let t=0;t<e.length;t++)if(typeof e[t]!=`string`)return!1;return!0},Rr=e=>typeof e!=`object`||e.kind===`ModelValue`,zr=e=>{if(e.length===0)return!1;let t=e[e.length-1];return typeof t==`object`&&t.kind!==`ModelValue`},Br=(e,t)=>e.length>0&&t.length>0&&Lr(e)!==Lr(t),Vr=(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 Na(e,t);let n=e.domain,r=t.domain;if(n.length!==r.length)return Br(n,r)?Na(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=ki(a,o);if(s!==0)return Dr(a)===Dr(o)?s:Na(e,t)}else if(zr(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||Oi(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:ki(t,n);if(r!==0)return r}return 0},Hr=(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=ki(n[e],r[e]);if(t!==0)return t}return 0},Ur=(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`?ea(t,i):ki(t,i)===0))return!1}return!0},Wr=e=>Dr(e)?e.type:void 0,Gr=(e,t,n)=>{let r=ba(n);return Dr(e)&&Dr(t)?`Attempted to ${r} the differently-typed model values ${N(U(e))} and ${N(U(t))}`:Wr(e)===void 0?`Attempted to ${r} the typed model value ${N(U(t))} and the non-model value\n${N(U(e))}`:`Attempted to ${r}${n?``:` the`} typed model value ${N(U(e))} and non-model value\n${N(U(t))}`},Kr=(e,t,n)=>{let r=Wr(e),i=Wr(t);if((r!==void 0||i!==void 0)&&(!Dr(e)||!Dr(t)||r!==void 0&&i!==void 0&&r!==i))throw P(Gr,e,t,n)},qr=()=>({ranks:Object.create(null),texts:[],searchRank:void 0,unorderedString:void 0}),Jr=qr(),Yr=e=>{Object.assign(Jr,qr()),Ai.clear(),ji=!1,Ki=!1;for(let t of e)ui(t)},Xr=()=>{Jr.searchRank=Jr.texts.length,Jr.unorderedString=void 0},Zr=e=>{let t=Jr.texts;for(let n=e;n<t.length;n++)delete Jr.ranks[t[n]];t.length=e},Qr=()=>Jr.unorderedString;let $r=!1;const ei={isExpanded:!0,isViewPrinted:!1},ti=()=>ei.isExpanded,ni=e=>{$r=e.version===`1.7.4`,gr=e.maxSetSize??hr,ei.isExpanded=e.isLazyValueExpanded??!0,ei.isViewPrinted=e.isViewPrinted??!1},ri=/* @__PURE__ */ new WeakMap,ii=(e,t)=>(ei.isViewPrinted&&ri.set(e,t),e),ai=/* @__PURE__ */ new WeakMap,oi=/* @__PURE__ */ new WeakMap,si=(e,t)=>(ai.set(e,t),e),ci=(e,t)=>(oi.set(e,t),e),li=(e,t)=>oi.has(e)?t:oi.get(t)?.()??t,ui=e=>(Jr.ranks[e]===void 0&&(Jr.ranks[e]=Jr.texts.length,Jr.texts.push(e)),e),di=e=>Jr.ranks[ui(e)],fi=()=>Jr.texts.length,pi=(e=0)=>Jr.texts.slice(e),mi=(e,t)=>{if(e===t)return 0;let n=Jr.ranks,r=n[e],i=n[t],a=Jr.searchRank;return a!==void 0&&(r===void 0||r>=a)&&(i===void 0||i>=a)&&(Jr.unorderedString??=e),r!==void 0&&i!==void 0?r-i:r===void 0?i===void 0&&e<t?-1:1:-1},hi=e=>typeof e==`object`&&(e.kind===`InfiniteSet`||e.kind===`SequenceSet`),gi=(e,t)=>(hi(e)||hi(t))&&(typeof e!=`object`||e.kind!==`SequenceSet`||typeof t!=`object`||t.kind!==`SequenceSet`);let _i=`none`;const vi=()=>{if(_i===`stopping`)throw new g},yi=(e,...t)=>_i===`none`?e(...t):()=>e(...t),P=(e,...t)=>new n(yi(e,...t)),bi=(e,t)=>P(()=>hi(e)?`Attempted to compare overridden value ${N(U(e))} with non-overridden value:\n${N(U(t))}`:`Attempted to compare ${kr(e)} ${U(e)} with ${kr(t)} ${U(t)}`),xi=(e,t,n)=>`Attempted to ${e} the set ${N(U(L(t)))} with the value:\n${N(U(n))}`,Si=(e,t)=>`Attempted to compare ${N(U(e))} with the value\n${N(U(t))}`,Ci=(e,t,n)=>{if(!hi(e))throw P(xi,n,e,t);if(!hi(t))throw bi(e,t);let r=e.kind===`InfiniteSet`?e.name:void 0,i=t.kind===`InfiniteSet`?t.name:void 0;if(r!==void 0&&r===i)return 0;if(r===`Nat`&&i===`Int`||r===`Int`&&i===`Nat`)return r===`Nat`?-1:1;throw new s(yi(Si,e,t))},wi={kind:`InfiniteSet`,name:`Any`},Ti=e=>`Attempted to compare ANY with the value\n${N(U(e))}`,Ei=e=>new s(yi(Ti,e)),Di=e=>e.fingerprint!==0||e.hash!==0&&e.hash!==qu,Oi=(e,t)=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:return!0;case`Interval`:return il(e.low,e.high),!0;case`SequenceSet`:return Oi(e.base,!1);case`InfiniteSet`:if(e===wi)throw Ei(e);return!0;case`LazyFunction`:return Oi(V(e),t);case`Function`:{if(e.flags&4||Di(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=Oi(n[e],t)&&i;for(let e=0;e<r.length;e++)i=Oi(r[e],t)&&i;return i&&(e.flags|=4),i}case`Set`:{if(e.flags&4||Di(e))return!0;e.flags|=1;let n=e.elements,r=!0;for(let e=0;e<n.length;e++)r=Oi(n[e],t)&&r;return r&&(e.flags|=4),r}case`Subset`:return Oi(e.base,t);case`FunctionSet`:{if(!t)break;let n=e.cost?.charges,r=hc(n,e.domain),i=hc(n,e.domain);if(r||i)return!1;let a=hc(n,e.range),o=hc(n,e.range);return a||o||(Oi(e.domain,t),Oi(e.range,t)),!1}case`RecordSet`:case`ProductSet`:{if(!t)break;let n=e.cost?.charges,r=hc(n,e),i=hc(n,e);if(r||i)return!1;let a=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<a.length;e++)Oi(a[e],t);return!1}}let n=Ds(e);return Oi(n&&(oo||n.kind===`SetOperation`||n.kind===`Union`)?As(n,!0,L):L(e),t),$i(e),!1},ki=(e,t)=>{if(e===t)return Oi(e,!1),0;if(typeof e==`object`&&typeof t==`object`){let n=e.kind,r=t.kind;if(n===`Function`&&r===`Function`)return Vr(e,t);if(n===`Set`&&r===`Set`)return Hr(e,t);if(n===`Interval`&&r===`Interval`){let n=il(e.low,e.high),r=il(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&&Kr(e,t,!1),e.rank-t.rank;if(n===`ModelValue`||r===`ModelValue`)return Kr(e,t,!1),n===`ModelValue`?-1:1;if(e===wi||t===wi)throw Ei(e===wi?t:e);if(n===`SequenceSet`&&r===`SequenceSet`||n===`Subset`&&r===`Subset`)return no(e.base,t.base);if(wr(e)&&wr(t)&&gi(e,t))return Ci(e,t,`compare`);let i=wr(e);if(i!==wr(t))throw bi(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:Ds(e),a=r===`Set`?void 0:Ds(t),o=i?As(i,!0,L):L(e);return $i(e),Hr(o,a?As(a,!1,Es):Es(t))}return Vr(V(e),V(t))}if(typeof e==`number`&&typeof t==`number`)return e-t;if(typeof e==`string`&&typeof t==`string`)return mi(e,t);if(typeof e==`boolean`&&typeof t==`boolean`)return e<t?-1:1;if(Kr(e,t,!1),Dr(e))return-1;if(Dr(t))return 1;throw bi(e,t)},Ai=/* @__PURE__ */ new Map;let ji=!1;const Mi=()=>ji,Ni=32768,Pi=e=>{let t=Ai.get(e);if(t)return t;if(Ai.size===Ni)throw new u(`TLC supports at most ${Ni} model values, but model value ${e} exceeds this limit.`);let n=e.length>2&&e[1]===`_`?e[0]:void 0;n!==void 0&&(ji=!0);let r={kind:`ModelValue`,name:e,type:n,rank:di(e),hash:Bu(Vu(Hu(e),109)),fingerprint:rd(id(e)^60)};return Ai.set(e,r),r},Fi=()=>[...Ai.values()];var Ii=class{kind=`Set`;elements;writtenElements=void 0;hash=0;fingerprint=0;flags=0;constructor(e){this.elements=e}};const Li=e=>new Ii(e),Ri=e=>{let t=Li(e);return t.flags=1,t};var zi=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 Bi=(e,t)=>new zi(e,t),Vi=(e,t)=>(t!==void 0&&(e.functionClass=t),e),Hi=e=>typeof e==`object`?e.kind===`LazyFunction`?`lambda`:e.kind===`Function`?e.functionClass:void 0:void 0,Ui=e=>typeof e==`object`&&e.kind===`LazyFunction`&&e.isApplicationObserved&&e.enumerated===void 0,Wi=(e,t)=>e.functionClass===`tuple`&&Ui(t),Gi=e=>$n(e)&&e.isCached===!0;let Ki=!1;const qi=()=>(Ki?2:0)|(ji?4:0),Ji=e=>{Ki||=!!(e&2),ji||=!!(e&4)},Yi=()=>Ai.size,Xi=e=>(Ki=!0,e),Zi=/* @__PURE__ */ new Set([`Union`,`SetOperation`,`FilteredSet`,`ProductSet`,`RecordSet`,`FunctionSet`]),Qi=e=>Ki&&typeof e==`object`&&$n(e)&&Zi.has(e.kind),$i=e=>{Qi(e)&&(e.isCached=!0)},ea=(e,t)=>{if(e===t)return Oi(e,!0),!0;if(typeof e!=`object`||typeof t!=`object`)return typeof e!=typeof t&&((typeof e==`object`||typeof t==`object`)&&Kr(e,t,!0),ki(e,t)===0);if(e.kind===`Function`&&t.kind===`Function`)return Vr(e,t)===0;if(e.kind===`Set`&&t.kind===`Set`)return Ur(e,t);if(e.kind===`Interval`&&t.kind===`Interval`)return il(e.low,e.high)===0?il(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(Dr(e)||Dr(t))return e.kind===`LazyFunction`&&V(e),Kr(e,t,!0),Dr(e)&&Dr(t)&&e.name===t.name;if(e.kind===`Subset`&&t.kind===`Subset`)return to(e.base,t.base);if(e.kind===`FunctionSet`&&t.kind===`FunctionSet`){let n=e.cost?.charges??t.cost?.charges,r=hc(n,e.domain),i=hc(n,t.domain);if(r||i)return r===i;let a=hc(n,e.range),o=hc(n,t.range);return a||o?a===o:to(e.domain,t.domain)&&to(e.range,t.range)}if(e.kind===`RecordSet`&&t.kind===`RecordSet`){let n=e.cost?.charges??t.cost?.charges;if(hc(n,e))return hc(n,t);if(hc(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]&&to(e[1],i[t][1]))}if(e.kind===`ProductSet`&&t.kind===`ProductSet`){let n=e.cost?.charges??t.cost?.charges;return hc(n,e)?hc(n,t):!hc(n,t)&&e.factors.length===t.factors.length&&e.factors.every((e,n)=>to(e,t.factors[n]))}let n=wr(e)&&wr(t)&&!(Jo(e)&&Jo(t));if(n&&gi(e,t))return Ci(e,t,`check equality of`)===0;if(n){if(!hi(e)){let n=L(e);if($i(e),!hi(t))return Hr(n,L(t))===0}return ki(e,t)===0}return e.kind===`Function`&&Wi(e,t)?Oa(e,t,!0)===0:ki(e,t)===0},ta=(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},na=(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},ra=(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},ia=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&&na(e.edges,t.edges)&&ra(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=sr(e,i),s=sr(t,i);if(o!==Iu&&s!==Iu&&o!==s||(!n||e.sources[i]!==t.sources[i]||or(e,i)||or(t,i)||!ta(e.edges,t.edges,i))&&!r(ar(e,i),ar(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&&ir(i)&&ir(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):dd(i)===dd(a);return r},aa=ia(!1),oa=ia(!0),sa=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=t(e[n])},ca=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(ca(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(ca(e.domain[t])||ca(e.range[t]))return!0;return!1;case`ModelValue`:case`Interval`:case`InfiniteSet`:return!1;default:return!0}},la=(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=nd(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||oa(i,e))return i}if(e.kind===`Set`?sa(e.elements,a):(sa(e.domain,a),sa(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(nd(t),e)}}else i(o,r.length-1);return e};return e?e=>{for(let t=0;t<e.length;t++)ca(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}},ua=(e,t)=>t.length===0||Hi(e)===`tuple`?1:ku(t)?.low,da=e=>(e.kind===`Function`&&e.costModel!==void 0&&e.functionClass!==void 0&&(vi(),e.costModel.secondary[e.costModel.node]+=e.range.length),V(e)),fa=e=>e.costModel!==void 0&&e.functionClass===void 0&&ku(e.domain)===void 0?e.costModel:void 0,pa=e=>{if(e.kind!==`Function`)return;let t=fa(e);t!==void 0&&(vi(),t.secondary[t.node]+=e.range.length)},ma=e=>{if(typeof e==`object`)return e.kind===`LazyFunction`?eu(e)&&e.costModel.node>=0?e.costModel:void 0:e.kind===`Function`?fa(e):void 0},ha=e=>{if(!Er(e))return;let t=da(e);return{domain:t.domain,range:t.range,low:ua(e,t.domain)}},ga=e=>{if(!Er(e))return;Ir(e);let t=V(e);if(Lr(t.domain))return pa(e),t},_a=(e,t,n)=>(Kr(t,e,n),1),va={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`}},ya=(e,t,n)=>{let r=va[typeof e==`number`?`number`:typeof e==`string`?`string`:`boolean`];return`Attempted to ${n?r.equality:`compare`} ${r.name} ${N(U(e))} with ${r.other}:\n${N(U(t))}`},ba=e=>e?`check equality of`:`compare`,xa=(e,t,n)=>`Attempted to ${ba(e)} operator ${N(U(t))} with value:\n${N(U(n))}`,Sa=(e,t,n)=>`Attempted to ${ba(e)} the function ${N(U(t))} with the value:\n${N(U(n))}`,Ca=(e,t,n)=>`Attempted to compare ${e?`an `:``}integer with non-integer${e||t?`:`:``}\n${N(U(n))}.`,wa=(e,t,n)=>`Attempted to ${ba(e)} record:\n${N(U(t))}\nwith non-record\n${N(U(n))}`,Ta=(e,t,n)=>`Attempted to ${ba(e)} the set ${N(U(t))} with the value:\n${N(U(n))}`,Ea=(e,t,n,r)=>{let i=ha(n);if(!i){if(Dr(n))return _a(n,t,r);throw P(Sa,r,t,n)}if(Ir(t),Ir(n),e.range.length!==i.range.length)return e.range.length-i.range.length;let a=()=>Da(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 Da(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(Ca,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()},Da=(e,t,n)=>{let r=z.sets;for(let i=0;i<e.length;i++){r?.push(e[i]);let a=Ma(e[i],t[i],n);if(r?.pop(),a!==0)return a}return 0},Oa=(e,t,n)=>{let r=V(e);if(Hi(e)===`tuple`){let i=Er(t)?pl(t):void 0;return i?r.range.length-i.length||Da(r.range,i,n):Ea({...da(e),low:1},e,t,n)}if(Hi(e)===`record`){let i=ga(t);if(!i){if(Dr(t))return _a(t,e,n);throw P(wa,n,e,t)}return Ir(e),r.domain.length-i.domain.length||Da(r.domain,i.domain,n)||Da(r.range,i.range,n)}return Ea({...r,low:ua(e,r.domain)},e,t,n)},ka=(e,t)=>hi(e)||hi(t)||typeof t==`object`&&e.kind===t.kind&&(e.kind===`Interval`||e.kind===`Subset`||e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`),Aa=(e,t)=>{let n=Ds(t),r=Or(t)?t:n?As(n,!1,n.kind===`Subset`?L:Es):Es(t);return{elements:L(e).elements,otherElements:L(r).elements}},ja=(e,t,n)=>{if(hi(e)&&Dr(t))return 1;if(!n&&(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)){let n=Ds(e);return ja(n?As(n,!0,ks):ks(e),t,!1)}if(ka(e,t))return n?+!ea(e,t):ki(e,t);if(!Or(e)){let r=Ds(e),i=r?As(r,!0,ks):ks(e);return ja(i,t,n)}if(!wr(t)){if(Dr(t))return _a(t,e,n);throw P(Ta,n,e,t)}let r=Aa(e,t);return r.elements.length-r.otherElements.length||Da(r.elements,r.otherElements,n)},Ma=(e,t,n)=>{if(typeof e!=`object`){if(typeof t==typeof e)return n?e===t?0:1:ki(e,t);if(Dr(t))return _a(t,e,n);throw P(ya,e,t,n)}if(e.kind===`ModelValue`)return e.type!==void 0&&Kr(e,t,n),Dr(t)?n?e.name===t.name?0:1:e.rank-t.rank:-1;if(e.kind===`Operator`)throw P(xa,n,e,t);return Er(e)?Oa(e,t,n):ja(e,t,n)},Na=(e,t)=>Ma(e,t,!1),Pa=(e,t)=>Ma(e,t,!0)===0,Fa=e=>{let t=[];for(let n of e){let e=Ua(n,t);e.isFound||t.splice(e.index,0,n)}return t},Ia=(e,t)=>Li(t?e:Fa(e)),La=(e,t)=>{let n=z.sets;if(n===void 0)return t();n.push(e);let r=t();return n.pop(),r},Ra=(e,t)=>{for(let n=1;n<e.length;n++){let r=e[0],i=e[n];if(La(r,()=>Na(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&&La(r,()=>Na(r,e[a-1]))<0;)e[a]=e[a-1],t[a]=t[a-1],a--;e[a]=r,t[a]=i}},za=(e,t)=>(Ra(e,t),Bi(e,t)),Ba=e=>typeof e==`object`&&e.kind===`MixedSet`,Va=e=>Ba(e)||typeof e==`object`&&e.kind===`ProductSet`&&e.factors.some(Ba),Ha=(e,t,n)=>Ba(e)?za([...t],n):Bi(t,n),Ua=(e,t)=>{let n=0,r=t.length;for(;n<r;){let i=n+(r-n>>1),a=La(e,()=>Na(e,t[i]));if(a===0)return{index:i,isFound:!0};a<0?r=i:n=i+1}return{index:n,isFound:!1}},Wa=(e,t)=>t.some(t=>La(t,()=>Pa(t,e))),Ga=e=>e.kind===`MixedSet`?e.enumerated?.elements??e.elements:pr(e)?e.elements:e.writtenElements??e.elements,Ka=1e3,qa=(e,t,n)=>{if(typeof e!=`object`)return n;if(t===Ka){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=qa(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=qa(e.domain[n],t+1,r),r=qa(e.range[n],t+1,r)}return r},Ja=e=>{let t=qa(e,0,void 0);for(let e=t?.pop();e!==void 0;e=t?.pop())qa(e,0,t)},Ya=(e,t,n,r)=>{if(typeof e!=`object`)return n;if(t===Ka){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];Rr(a)||(i=Ya(a,t+1,i,r))}return i;case`MixedSet`:for(let n=0;n<e.elements.length;n++){let a=e.elements[n];Rr(a)||(i=Ya(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];Rr(a)||Ja(a),Rr(o)||(i=Ya(o,t+1,i,r))}return i;case`LazyFunction`:{if(e.enumerated)return Ya(e.enumerated,t+1,i,r);let n=ru(e);for(let e=n.length-1;e>=0;e--){let a=n[e];i=Ya(a.newValue,t+1,i,r);for(let e=0;e<a.path.length;e++)i=Ya(a.path[e],t+1,i,r)}return Ya(e.domain,t+1,i,r)}case`FilteredSet`:case`Subset`:case`Union`:return Ya(e.base,t+1,i,r);case`SetOperation`:return i=Ya(e.left,t+1,i,r),Ya(e.right,t+1,i,r);case`FunctionSet`:return i=Ya(e.domain,t+1,i,r),Ya(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=Ya(n[e],t+1,i,r);return i}default:return i}},Xa=e=>{let t=[],n=Ya(e,0,void 0,t);for(let e=n?.pop();e!==void 0;e=n?.pop())Ya(e,0,n,t);for(let e=0;e<t.length;e++)t[e].flags|=128},Za=e=>{if(typeof e!=`object`||Gi(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`:Za(e.base);break;case`SetOperation`:e.operator!==`\\cup`&&(Za(e.left),Za(e.right));break;case`FunctionSet`:Za(e.domain),Za(e.range);break;case`RecordSet`:for(let t of e.sets)Za(t);break;case`ProductSet`:for(let t of e.factors)Za(t)}t?.pop()},Qa=e=>typeof e==`object`&&$n(e)&&e.enumerated===void 0,$a=(e,t)=>typeof e==`object`&&(e.kind===`Function`&&Wi(e,t)||wr(e)&&!Dr(t)&&(ka(e,t)||wr(t)&&(Qa(e)?e.kind!==`MixedSet`:Qa(t)))),eo=(e,t)=>typeof e!=`object`&&typeof e==typeof t?e===t:yl(ea,Pa,e,t,$a),to=(e,t)=>{let n=z.sets;if(n===void 0)return eo(e,t);n.push(e);let r=eo(e,t);return n.pop(),r},no=(e,t)=>{let n=z.sets;if(n===void 0)return Na(e,t);n.push(e);let r=Na(e,t);return n.pop(),r},ro=e=>{for(let t=1;t<e.length;t++)if(ki(e[t],e[t-1])<=0)return!1;return!0},io=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},ao=e=>{if(e.length<2||ro(e))return Li(e);let t=[...e].sort(ki);for(let t=1;t<e.length;t++)$i(e[t]);let n=[t[0]];for(let e=1;e<t.length;e++)ki(n[n.length-1],t[e])!==0&&n.push(t[e]);return Li(n)};let oo=!1;const so=e=>{if(io(e))return Li(e);let t=oo;oo=!0;try{let t=yl(ao,e=>({kind:`MixedSet`,elements:e}),e,void 0);return t.kind===`Set`&&t.elements!==e&&(t.writtenElements=e),t}finally{oo=t}},co=Li([]),lo=(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&&ki(r[a],t)<0;)a++;a<r.length&&ki(r[a],t)===0||i.push(t)}return i.length===n.length?e:Li(i)},uo=(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&&ki(r[a],t)<0;)a++;a<r.length&&ki(r[a],t)===0&&i.push(t)}return i.length===n.length?e:Li(i)},fo=(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=ki(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=Li(i);if(e.hash!==0&&e.hash!==qu){let t=e.hash,n=0;for(;n<a.length;n++){let e=nd(a[n]);if(e===qu)break;t=t+Gu(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+ad(a[e])|0;c.fingerprint=t}return c},po=e=>{let t=e.length<2?e:[...e].sort((e,t)=>ki(e[0],t[0])),n=[],r=[];for(let e of t)n.length>0&&ki(n[n.length-1],e[0])===0||(n.push(e[0]),r.push(e[1]));return Bi(n,r)},mo=e=>typeof e!=`object`||e.kind===`ModelValue`&&e.type===void 0||e.kind===`Function`&&(!!(e.flags&4)||e.writtenKeys===void 0&&e.domain.every(ho)&&e.range.every(mo)),ho=e=>!Dr(e)&&mo(e),go=e=>e.flags&32?!0:e.domain.every(mo)?(e.flags|=32,!0):!1,_o=(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=ki(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]},vo=(e,t)=>{if(e.domain.length+t.domain.length>vr()){let n=Nr(e),r=[];for(let e of n)br(r,e);for(let e of Nr(t))n.some(t=>eo(e[0],t[0]))||br(r,e);return Do(r)}let n=Mr(e),r=Mr(t),i=yo(e,t)??new Set(r.filter(e=>n.some(t=>eo(e,t)))),a=[...n,...r.filter(e=>!i.has(e))],o=bo(e,t,i);if(!o){let n=Nr(e),r=Nr(t).filter(e=>!i.has(e[0]));return Do([...n,...r])}let s=Bi(o[0],o[1]);return s.flags|=32,a.every((e,t)=>e===s.domain[t])?s:jr(s,a)},yo=(e,t)=>{if(!go(e)||!go(t))return;let r=/* @__PURE__ */ new Set;try{for(let n of e.domain){let e=cl(t.domain,n);e!==-1&&r.add(t.domain[e])}}catch(e){if(e instanceof n)return;throw e}return r},bo=(e,t,r)=>{let i=r.size===0?t.domain:t.domain.filter(e=>!r.has(e)),a=r.size===0?t.range:t.range.filter((e,n)=>!r.has(t.domain[n]));if(go(e)&&(r.size===0?go(t):i.every(mo)))try{return _o(e.domain,e.range,i,a)}catch(e){if(e instanceof n)return;throw e}},xo=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][0];return t},So=(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 jr(e,xo(t));return e},Co=e=>So(po(e),e),wo=e=>{let t=Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n][1];return t},To=e=>Bi(xo(e),wo(e)),Eo=e=>So(za(xo(e),wo(e)),e),Do=e=>yl(Co,Eo,e,void 0);var Oo=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 ko=[],Ao=e=>{let t=ko[e];if(t)return t;let n=new Oo({kind:`Interval`,low:1,high:e});return e<=1024&&(ko[e]=n),n},jo=e=>e.low===1&&e.high>=0?Ao(e.high):new Oo(e),Mo=e=>Reflect.get(e,`kind`)===`IntervalElements`,No=e=>{let t=/* @__PURE__ */ new Set,n=e=>{if(typeof e!=`object`||!e)return e;if(Mo(e))return jo({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`)&&(Ki=!0),e};for(let t of e)n(t);return[...e]},Po=e=>{if(R(e)>Cr)throw new m;if(e.low===1&&e.high>=1)return Ao(e.high);let t=[];for(let n=e.low;n<=e.high;n++)t.push(n);return t},Fo=e=>e instanceof Oo,Io=(e,t=!0)=>{let n=t?L(e).elements:_s(e);return Fo(n)&&(typeof e!=`object`||e.kind!==`Interval`)?[...n]:n},F=e=>Vi(Bi(Ao(e.length),e),`tuple`),Lo=e=>Vi(po(e),`record`),Ro=(e,t)=>Vi(Bi(e,t),`record`),zo=(e,t)=>(t!==void 0&&(e.costModel=t),e),Bo=e=>e?.node===void 0||e.charges===void 0?void 0:e.charges.costModels[e.node],Vo=(e,t)=>{let n=Bo(t);if(n===void 0)return e;for(let t=0;t<e.length;t++)e[t].costModel=n;return e},I=e=>wr(e)&&!hi(e),Ho=e=>`UNION(${U(e.base)})`,Uo=e=>`Attempted to enumerate the nonenumerable set:\n${Ho(e)}`,Wo=(e,t=e=>L(e).elements)=>{if(!I(e.base))throw P(Uo,e);return t(e.base)},Go=e=>typeof e==`object`&&e.kind===`Set`?e.elements:Uc(e),Ko=(e,t,n)=>t===0?`Attempted to enumerate UNION(s), but some element of s is nonenumerable.`:`Attempted to enumerate the nonenumerable set:\n${N(U(e))}\nwhen enumerating:\n${N(Ho(n))}`,qo=(e,t,n)=>{if(I(e))return e;throw P(Ko,e,t,n)},Jo=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 Jo(e.base);case`FunctionSet`:return Jo(e.domain)&&Jo(e.range)||Yo(e.domain)===!0||Yo(e)===!0;case`RecordSet`:return e.sets.every(Jo)||Yo(e)===!0;case`ProductSet`:return e.factors.every(Jo)||Yo(e)===!0;case`Union`:return Jo(e.base)&&(Or(e.base)?Ga(e.base):Uc(e.base)).every(Jo);case`SetOperation`:return e.operator===`\\cup`?Jo(e.left)&&Jo(e.right):e.operator===`\\cap`?Jo(e.left)||Jo(e.right):Jo(e.left);default:return!1}},Yo=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=Yo(e.domain);return t===void 0?void 0:!t&&Yo(e.range)}case`RecordSet`:case`ProductSet`:for(let t of e.kind===`RecordSet`?e.sets:e.factors){let e=Yo(t);if(e!==!1)return e}return!1;case`SetOperation`:case`FilteredSet`:case`Union`:return Jo(e)?L(e).elements.length===0:void 0;default:return}},Xo=(e,t)=>{let n=e.reduce((e,t)=>e*t.length,1);if(t&&n>vr())throw z.sets?.pop(),new D(yr());if(n>Cr)throw new m;let r=[],i=e.map(()=>0);for(let t=0;t<n;t++){r.push(e.map((e,t)=>e[i[t]]));for(let t=e.length-1;t>=0&&(i[t]++,!(i[t]<e[t].length));t--)i[t]=0}return r},Zo=(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},Qo=e=>{if(typeof e!=`object`||e.kind!==`Subset`||hi(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=[]:Zo(a,n.length)||(a=Array.from({length:a.length+1},(e,t)=>t)),i++;let t=Li(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)})},$o=(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=Li(a);if(t(n===void 0?o:{...o,costNode:n}))return!0}while(Zo(i,e.length))}return!1},es=(e,t)=>{let n=[];return $o(e,e=>(n.push(e),!1),t),n},ts=e=>`Attempted to compute the value of an expression of form\nSUBSET S, but S is a non-enumerable value:\n${N(U(e.base))}`,ns=e=>{if(R(e.base)===0)return[];if(!wr(e.base))throw P(ts,e);return L(e.base).elements},rs=(e,t)=>`Attempted to enumerate a set of the form [D -> R],but the ${e}:\n${N(U(t))}\ncannot be enumerated.`,is=(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${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${N(U(e.factors[t]))}`,as=(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(hi(a))throw P(is,e,i);let o=t(a);if(o.length===0)return[[]];r.push(o)}return r},os=e=>`Attempted to enumerate S \\cap T when neither S:\n${N(U(e.left))}\nnor T:\n${N(U(e.right))}\nis enumerable`,ss=e=>`Attempted to enumerate S \\ T when S:\n${N(U(e.left))}\nis not enumerable.`,cs=(e,t)=>{if(e.operator===`\\cap`&&!I(e.left)&&!I(e.right))throw P(os,e);if(e.operator===`\\`&&!I(e.left))throw P(ss,e);if(e.operator===`\\cup`)return L(so(Lc(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`)&&br(a,t),!1);return typeof r==`object`&&r.kind===`Interval`?Sr(r,o):Bc(r,t??Fc(r),o),L(so(a)).elements},ls=e=>{if(typeof e!=`object`||Gi(e))return!0;switch(e.kind){case`Set`:case`MixedSet`:return pr(e);case`Interval`:return!0;case`FilteredSet`:return ls(e.base);case`FunctionSet`:return ls(e.domain)&&ls(e.range);case`RecordSet`:return e.sets.every(ls);case`ProductSet`:return e.factors.every(ls);case`Operator`:throw new n(e.javaClass===`MethodValue`?`It is a TLC bug: Attempted to normalize an operator.`:`Should not normalize an operator.`);default:return!1}},us=(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===wi)return!0;break;case`ModelValue`:case`Interval`:break;default:return!0}return!1},ds=e=>us(e,!1),fs=e=>{for(let t=0;t<e.length;t++)if(us(e[t],!0))return!0;return!1},ps=(e,t)=>{for(let n=0;n<e.length;n++)if(ms(e[n],t))return!0;return!1},ms=(e,t)=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:return fs(e.elements);case`MixedSet`:return!0;case`FilteredSet`:case`Subset`:case`Union`:return ms(e.base,t);case`SetOperation`:return ms(e.left,t)||ms(e.right,t);case`FunctionSet`:return ms(e.domain,t)||ms(e.range,t);case`RecordSet`:return ps(e.sets,t);case`ProductSet`:return ps(e.factors,t);case`Operator`:return t;default:return!1}},hs=(e,t)=>!ms(e,t)||ls(e),gs=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`ProductSet`:case`FunctionSet`:case`RecordSet`:return hs(e,!0);case`FilteredSet`:return ls(e),!0;case`SetOperation`:return e.operator!==`\\cup`&&ls(e.left)&&e.operator===`\\cap`&&ls(e.right),!0;case`MixedSet`:case`Union`:case`Subset`:return!0;default:return!1}},_s=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=gs(e),n=z.sets?Pc(e,!1):void 0;return vs(e,n,t)},vs=(e,t,n)=>{let r=oo;oo=!1;let i;try{i=Cs(e,!1,void 0,t)}finally{oo=r}let a=Ia(i,n);return i.length<=vr()&&(e.enumerated=a),a.elements},ys=e=>{let t=Qo(e);return t!==void 0&&t.length>vr()?t:_s(e)},bs=e=>`Expected a set but found ${U(e)}`,xs=e=>`Attempted to enumerate { x \\in S : p(x) } when S:\n${N(U(e.base))}\nis not enumerable`,Ss=e=>`Attempted to enumerate the non-enumerable set ${U(e)}`,Cs=(e,t=!0,n=t?ys:_s,r)=>{if(typeof e!=`object`)throw P(bs,e);let i=Hs(e);if(i){let e=Ac(kc(i,r),t);return Kc(i)?Fa(e):e}switch(e.kind){case`Set`:return e.elements;case`MixedSet`:return Fa(e.elements);case`Interval`:if(R(e)>Cr)throw new m;return jo(e);case`Subset`:{let t=ns(e);if(t.length>30)throw P(el,e);if(2**t.length>Cr)throw new m;return es(t,e.cost?.node)}case`FunctionSet`:{if(!$r&&Zc(e))return[];if(hi(e.domain))throw P(rs,`domain D`,e.domain);let r=Io(e.domain);if((r.length>0||$r)&&hi(e.range))throw P(rs,`range R`,e.range);let i=r.length===0?[]:n(e.range);return Vo(Xo(r.map(()=>i),t).map(e=>Bi(r,e)),e.cost)}case`RecordSet`:{if(!$r&&Zc(e))return[];let r=as(e,n);return Vo(Xo(r,t).map(t=>Ro(e.names,t)),e.cost)}case`ProductSet`:{if(!$r&&Zc(e))return[];let r=as(e,n);return Vo(Xo(r,t).map(F),e.cost)}case`FilteredSet`:{if(!wr(e.base)||hi(e.base))throw P(xs,e);let n=e.startPass?.(!0).test??Ws(e),i=[];return Bc(e.base,r??Fc(e.base),e=>(n(e)&&(t?br(i,e):i.push(e)),!1)),L(so(i)).elements}case`Union`:{let t=[];for(let[n,i]of(r?qc(e,r):Wo(e,Go)).entries()){let a=qo(i,n,e);if(xr(a))throw new D(yr());for(let i of r&&n===0&&Or(e.base)?Hc(a,r):Uc(a))br(t,i)}return L(so(t)).elements}case`SetOperation`:return cs(e,r);case`InfiniteSet`:case`SequenceSet`:throw P(Ss,e);default:throw P(bs,e)}},L=(e,t)=>{if(typeof e==`object`&&e.kind===`Set`)return e;if(typeof e==`object`&&e.kind===`Interval`)return Li(Cs(e));let n=typeof e==`object`&&$n(e)?e:void 0;return n?.enumerated?n.enumerated:ws(e,n,!1,t)},ws=(e,t,r,i)=>{if(oo&&t!==void 0&&Is(t))throw new n(`The set literal holds a filter`);let a=z.sets;r||a?.push(e);let o=i??gs(e),s=oo;oo=s&&t?.kind===`MixedSet`;let c;try{c=r?Cs(e,!0,void 0,Pc(e,!1)):Cs(e)}finally{oo=s}r||a?.pop();let l=Ia(c,o);return t&&(t.enumerated=l),l},Ts=e=>z.sets!==void 0&&!e.enumerated?ws(e,e,!0):L(e),Es=(e,t)=>{let n=typeof e==`object`&&$n(e)?e:void 0;if(n===void 0||n.enumerated)return L(e);let r=Is(n),i=n.kind===`SetOperation`||n.kind===`Union`?Ts(n):L(n,t);return r&&(n.enumerated=void 0),i},Ds=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}},Os=(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&&rc(e,t)!==void 0;default:return!1}},ks=(e,t)=>{if(typeof e==`object`&&e.kind===`FilteredSet`){let t=L(e);return e.isCached=!0,t}let n=L(e,t);return $i(e),n},As=(e,t,r)=>{if(oo)throw new n(`The set literal holds a charged set`);let i=e.cost;if(i?.charges===void 0)return r(e);let a=gs(e);a||vi();let o=i.charges.convertCharged(e,r,a);return t&&(i.charges=void 0),o},js=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isCached!==!0;case`SetOperation`:return e.hasFilter&&e.isCached!==!0&&(js(e.left)||js(e.right));case`Union`:return e.isCached!==!0&&typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&Ns(e.base.elements);case`FunctionSet`:case`RecordSet`:case`ProductSet`:return Ms(e);default:return!1}},Ms=e=>e.hasFilter&&e.isCached!==!0&&!e.enumerated&&(e.kind===`FunctionSet`?js(e.domain)||js(e.range):Ns(e.kind===`RecordSet`?e.sets:e.factors)),Ns=e=>{for(let t=0;t<e.length;t++)if(js(e[t]))return!0;return!1},Ps=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`FilteredSet`:return e.isPassObserved===!0||Ps(e.base);case`SetOperation`:return Ps(e.left)||Ps(e.right);case`Union`:return typeof e.base==`object`&&(e.base.kind===`Set`||e.base.kind===`MixedSet`)&&Fs(e.base.elements);case`FunctionSet`:return Ps(e.domain)||Ps(e.range);case`RecordSet`:return Fs(e.sets);case`ProductSet`:return Fs(e.factors);default:return!1}},Fs=e=>{for(let t=0;t<e.length;t++)if(Ps(e[t]))return!0;return!1},Is=e=>js(e)&&Ps(e),Ls=(e,t,n)=>({kind:`FunctionSet`,domain:e,range:t,hasFilter:js(e)||js(t),cost:n}),Rs=(e,t,n)=>({kind:`RecordSet`,names:e,sets:t,hasFilter:Ns(t),cost:n}),zs=(e,t)=>({kind:`ProductSet`,factors:e,hasFilter:Ns(e),cost:t}),Bs=(e,t,n,r)=>({kind:`SetOperation`,operator:e,left:t,right:n,hasFilter:js(t)||js(n),cost:r}),Vs=(e,t)=>({kind:`Union`,base:e,cost:t}),Hs=e=>(e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&Ms(e)?e:void 0,Us={kind:`List`,elements:[],position:0},Ws=e=>t=>e.test(t,!1),Gs=e=>{let t=typeof e==`object`&&$n(e)&&!e.enumerated&&Is(e)?e:void 0,n=Io(e);return t&&(t.enumerated=void 0),n},Ks=e=>{if(!$r&&Zc(e))return Us;let t={kind:`Product`,set:e,costModel:Bo(e.cost),domain:[],parts:[],current:[],isDone:!1};if(e.kind===`FunctionSet`){if(Pc(e.domain,!0),hi(e.domain))throw P(rs,`domain D`,e.domain);if(t.domain=Gs(e.domain),(t.domain.length>0||$r)&&hi(e.range))throw P(rs,`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`&&hi(n[r]))throw P(is,e,r);let i=qs(n[r]),a=ec(i);if(a===void 0)return Us;t.parts.push(i),t.current.push(a)}return t},qs=e=>{let t=z.sets;if(typeof e==`object`&&e.kind===`FilteredSet`&&!Gi(e)){t?.push(e),I(e.base)||L(e);let n=qs(e.base),r=e.startPass?.(!1),i={kind:`Filter`,set:e,base:n,test:r?.test??Ws(e),end:r?.end};return t?.pop(),i}if(typeof e==`object`&&(e.kind===`SetOperation`||e.kind===`Union`)&&js(e))return Ps(e)||z.sets!==void 0?Ys(e):yl(Js,Ys,e,void 0);let n=typeof e==`object`?Hs(e):void 0;if(n===void 0)return Js(e);t?.push(n);let r=Ks(n);return t?.pop(),r},Js=e=>({kind:`List`,elements:Uc(e),position:0}),Ys=e=>{let t=z.sets;t?.push(e);let n=e.kind===`Union`?Zs(e):Xs(e);return t?.pop(),n},Xs=e=>{if(e.operator===`\\cup`)return I(e.left)&&I(e.right)||L(e),{kind:`Concatenated`,left:qs(e.left),right:qs(e.right)};let t=e.operator===`\\`||I(e.left),n=t?e.left:e.right;return I(n)||L(e),{kind:`Selected`,base:qs(n),other:t?e.right:e.left,isIntersection:e.operator===`\\cap`}},Zs=e=>{let t=Wo(e);return{kind:`Unioned`,union:e,sets:t,index:0,part:t.length>0?qs(qo(t[0],0,e)):void 0}},Qs=(e,t)=>{$s(e.parts[t]);let n=ec(e.parts[t]);n===void 0?e.isDone=!0:e.current[t]=n},$s=e=>{switch(e.kind){case`List`:e.position=0;return;case`Filter`:{$s(e.base);let t=e.set.startPass?.(!1);e.test=t?.test??Ws(e.set),e.end=t?.end;return}case`Product`:e.isDone=!1;for(let t=0;t<e.parts.length;t++)Qs(e,t);return;case`Concatenated`:$s(e.left),$s(e.right);return;case`Selected`:$s(e.base);return;case`Unioned`:e.index=0,e.part=e.sets.length>0?qs(qo(e.sets[0],0,e.union)):void 0}},ec=e=>{switch(e.kind){case`List`:return e.position<e.elements.length?e.elements[e.position++]:void 0;case`Filter`:for(let t=ec(e.base);t!==void 0;t=ec(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=ec(e.parts[t]);if(n!==void 0){e.current[t]=n;break}t===0?e.isDone=!0:Qs(e,t)}let n=e.set;return zo(n.kind===`FunctionSet`?Bi(e.domain,t):n.kind===`RecordSet`?Ro(n.names,t):F(t),e.costModel)}case`Concatenated`:return ec(e.left)??ec(e.right);case`Selected`:for(let t=ec(e.base);t!==void 0;t=ec(e.base))if(B(t,e.other)===e.isIntersection)return t;return;case`Unioned`:for(;e.part!==void 0;){let t=ec(e.part);if(t!==void 0)return t;e.index++,e.part=e.index<e.sets.length?qs(qo(e.sets[e.index],e.index,e.union)):void 0}return}},tc=(e,t)=>{for(let n=ec(e);n!==void 0;n=ec(e))if(t(n))return!0;return!1},nc={kind:`Plain`,part:Us},rc=(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)}},ic=(e,t)=>{if(typeof t!=`object`)return;let n=Hs(t);if(n===void 0)return;if(n.kind===`FunctionSet`)return uc(e,n.range)?n:void 0;let r=n.kind===`RecordSet`?n.sets:n.factors;for(let t=0;t<r.length;t++)if(!uc(e,r[t]))return;return n},ac=e=>typeof e==`object`&&e.kind===`FilteredSet`&&e.isCached===!0,oc=(e,t)=>t.operator===`\\cup`&&t.enumerated===void 0&&(js(t)||ac(t.left)||ac(t.right))&&rc(e,t)!==void 0&&I(t.left)&&I(t.right)&&!xr(t.left)&&!xr(t.right)&&uc(e,t.left)&&uc(e,t.right),sc=e=>e.operator===`\\`||I(e.left)?e.left:e.right,cc=(e,t)=>t.enumerated===void 0&&js(t)&&I(sc(t))&&uc(e,sc(t)),lc=(e,t)=>t.operator===`\\cup`?oc(e,t):cc(e,t),uc=(e,t)=>typeof t==`object`?t.kind===`SetOperation`?lc(e,t):t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||rc(e,t)===void 0||ic(e,t)!==void 0:!0,dc=(e,t)=>typeof t==`object`&&(t.kind===`FilteredSet`||t.kind===`Subset`||(t.kind===`SetOperation`?lc(e,t):ic(e,t)!==void 0)),fc=(e,t)=>Gi(t)||!dc(e,t.base)?void 0:rc(e,t),pc=(e,t)=>{let n=typeof t!=`object`||t.kind===`FilteredSet`||t.kind===`Subset`?void 0:rc(e,t),r=z.sets;if(typeof t==`object`&&t.kind===`FilteredSet`){let n=fc(e,t);if(n===void 0){let n=t.isCached?rc(e,t):void 0;return n===void 0?{kind:`Plain`,part:qs(t)}:{kind:`ChargedLeaf`,node:n,part:qs(t)}}r?.push(t),I(t.base)||L(t);let i={kind:`ChargedFilter`,node:n,set:t,base:pc(e,t.base)};return r?.pop(),i}if(typeof t==`object`&&t.kind===`SetOperation`&&t.operator!==`\\cup`){r?.push(t);let n=sc(t),i={kind:`ChargedSelected`,base:pc(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:pc(e,t.left),right:pc(e,t.right)};return r?.pop(),i}let i=n===void 0||typeof t!=`object`?void 0:Hs(t);if(n!==void 0&&i!==void 0){r?.push(i);let t=_c(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:qs(t)};e.chargeSubsetElements(t)}let a=qs(t);return n===void 0?{kind:`Plain`,part:a}:{kind:`ChargedLeaf`,node:n,part:a}},mc=(e,t)=>{if(typeof t!=`object`||t.kind!==`SetOperation`&&t.kind!==`FilteredSet`&&t.kind!==`FunctionSet`&&t.kind!==`RecordSet`&&t.kind!==`ProductSet`||(t.kind===`FilteredSet`?fc(e,t)===void 0:(t.kind!==`SetOperation`||t.operator===`\\cup`)&&rc(e,t)===void 0))return Zc(t);let n=z.sets;n?.push(t);let r=t.kind===`SetOperation`||t.kind===`FilteredSet`?bc(e,pc(e,t))===void 0:t.kind===`FunctionSet`?!Zc(t.domain)&&mc(e,t.range):gc(e,t.kind===`RecordSet`?t.sets:t.factors);return n?.pop(),r},hc=(e,t)=>(e?.chargeIsEmpty(t),Zc(t)),gc=(e,t)=>{for(let n=0;n<t.length;n++)if(mc(e,t[n]))return!0;return!1},_c=(e,t,n)=>{if(!$r&&mc(e,t))return nc;let r={kind:`ChargedProduct`,node:n,costModel:e.costModels[n],set:t,domain:[],parts:[],current:[],isDone:!1};if(t.kind===`FunctionSet`){if(Pc(t.domain,!0),hi(t.domain))throw P(rs,`domain D`,t.domain);if(r.domain=Gs(t.domain),(r.domain.length>0||$r)&&hi(t.range))throw P(rs,`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`&&hi(i[n]))throw P(is,t,n);let a=pc(e,i[n]),o=bc(e,a);if(o===void 0)return nc;r.parts.push(a),r.current.push(o)}return r},vc=(e,t,n)=>{yc(e,t.parts[n]);let r=bc(e,t.parts[n]);r===void 0?t.isDone=!0:t.current[n]=r},yc=(e,t)=>{switch(t.kind){case`Plain`:case`ChargedLeaf`:$s(t.part);return;case`ChargedProduct`:t.isDone=!1;for(let n=0;n<t.parts.length;n++)vc(e,t,n);return;case`ChargedUnion`:yc(e,t.left),yc(e,t.right);return;case`ChargedSelected`:case`ChargedFilter`:yc(e,t.base)}},bc=(e,t)=>{switch(t.kind){case`Plain`:return ec(t.part);case`ChargedLeaf`:return e.secondary[t.node]++,ec(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=bc(e,t.parts[n]);if(r!==void 0){t.current[n]=r;break}n===0?t.isDone=!0:vc(e,t,n)}let r=t.set;return zo(r.kind===`FunctionSet`?Bi(t.domain,n):r.kind===`RecordSet`?Ro(r.names,n):F(n),t.costModel)}case`ChargedUnion`:return e.secondary[t.node]++,bc(e,t.left)??bc(e,t.right);case`ChargedSelected`:return xc(e,t);case`ChargedFilter`:return Sc(e,t)}},xc=(e,t)=>{for(let n=bc(e,t.base);n!==void 0;n=bc(e,t.base))if(e.isMember(n,t.other)===t.isIntersection)return n},Sc=(e,t)=>{for(let n=bc(e,t.base);n!==void 0;n=bc(e,t.base))if(e.secondary[t.node]++,t.set.test(n,!1))return n},Cc=(e,t)=>{let n=[];for(let r=bc(e,t);r!==void 0;r=bc(e,t))br(n,r);return n},wc=(e,t,n)=>{let r=fc(e,t);if(r===void 0||t.enumerated||!I(t.base)||oo)return;let i=z.sets;i?.push(t);let a=Cc(e,{kind:`ChargedFilter`,node:r,set:t,base:pc(e,t.base)});i?.pop(),e.secondary[r]+=a.length;let o=Li(L(so(a)).elements);return n&&(t.enumerated=o),o.elements},Tc=(e,t)=>t.kind===`FilteredSet`?!t.enumerated&&I(t.base)&&fc(e,t)!==void 0:t.kind===`SetOperation`?lc(e,t):ic(e,t)!==void 0&&rc(e,t)!==void 0,Ec=(e,t,n)=>{if(typeof t!=`object`||!Tc(e,t))return!1;let r=pc(e,t);for(let t=bc(e,r);t!==void 0;t=bc(e,r))n(t);return!0},Dc=(e,t,n)=>{let r=n.kind===`Subset`,i=r?t:n.base;if(typeof i!=`object`||!Tc(e,i))return;let a=z.sets;a?.push(n);let o=pc(e,i),s=!1;for(let i=bc(e,o);i!==void 0;i=bc(e,o))if(r?!e.isMember(i,n.base):e.isMember(t,i)){s=!0;break}return a?.pop(),r!==s},Oc=(e,t,n)=>{if(typeof t!=`object`)return;if(t.kind===`FilteredSet`)return wc(e,t,n);let r=rc(e,t),i=t.kind===`SetOperation`?lc(e,t)?t:void 0:r===void 0?void 0:ic(e,t);if(i===void 0)return;let a=Cc(e,pc(e,i));r!==void 0&&(e.secondary[r]+=a.length);let o=i.kind!==`SetOperation`&&Kc(i)?Fa(a):a,s=i.kind===`SetOperation`?Li(L(so(a)).elements):i.kind===`RecordSet`?ao(o):Li(o);return n&&(i.enumerated=s),s.elements},kc=(e,t)=>t===void 0||t.kind===`Cup`?Ks(e):t,Ac=(e,t)=>{let n=[];return tc(e,e=>(t?br(n,e):n.push(e),!1)),n},jc=(e,t)=>{if(!(typeof e!=`object`||Gi(e)))switch(e.kind){case`MixedSet`:L(e);return;case`FilteredSet`:return I(e.base)||L(e),Pc(e.base,t);case`Union`:{if(!Or(e.base)&&I(e.base))return Pc(e.base,t);let n=Wo(e);return n.length>0?Pc(qo(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=Pc(e.left,!0),n=Pc(e.right,!0);return t||n?{kind:`Cup`,left:t,right:n}:void 0}return Pc(e.operator===`\\cap`&&!I(e.left)?e.right:e.left,t);case`FunctionSet`:case`RecordSet`:case`ProductSet`:if(Ms(e))return Ks(e);t&&Mc(e);return;case`Subset`:t&&Mc(e);return;default:return}},Mc=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}ns(e);return}case`FunctionSet`:{if(e.enumerated||Zc(e))return;let t=e.domain;if(Pc(t,!0),hi(t))throw P(rs,`domain D`,t);if(typeof t==`object`&&$n(t)&&L(t),Zc(t))return;if(hi(e.range))throw P(rs,`range R`,e.range);typeof t==`object`&&t.kind===`Interval`&&Nc(e),Pc(e.range,!0);return}case`RecordSet`:case`ProductSet`:{if(e.enumerated||Zc(e))return;let t=e.kind===`RecordSet`?e.sets:e.factors;for(let n=0;n<t.length;n++){if(hi(t[n]))throw P(is,e,n);Pc(t[n],!0)}}}},Nc=e=>{let t=R(e.domain);if(t>Cr)throw z.sets?.push(e),new m;return t},Pc=(e,t)=>{let n=z.sets;n?.push(e);let r=jc(e,t||n!==void 0);return n?.pop(),r},Fc=e=>typeof e!=`object`||Gi(e)?void 0:Pc(e,!1),Ic=e=>`Attempted to enumerate S \\cup T when S:\n${N(U(e.left))}\nand T:\n${N(U(e.right))}\nare not both enumerable`,Lc=(e,t)=>{if(!I(e.left)||!I(e.right))throw P(Ic,e);let n=t?.kind===`Cup`?t:void 0,r=n?n.left:Pc(e.left,!0),i=n?n.right:Pc(e.right,!0);if(xr(e.left))throw new D(yr());let a=[],o=e=>(br(a,e),!1);if(Bc(e.left,r,o),xr(e.right))throw new D(yr());return Bc(e.right,i,o),a},Rc=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},zc=(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?Rc(e).elements:_s(e);let n=(e.kind===`Union`||e.hasFilter)&&Is(e),r=gs(e),i=Cs(e,!0,void 0,z.sets?Pc(e,!1):void 0),a=Ia(i,r);return n||(e.enumerated=a),a.elements},Bc=(e,t,n)=>typeof e!=`object`||Gi(e)?L(e).elements.some(n):Jc(e,n,t),Vc=(e,t)=>Bc(e,Fc(e),t),Hc=(e,t)=>{let n=[];return Bc(e,t,e=>(n.push(e),!1)),n},Uc=e=>Hc(e,Fc(e)),Wc=e=>e.kind===`ProductSet`?e.factors:e.kind===`RecordSet`?e.sets:e.kind===`FunctionSet`?[e.range]:void 0,Gc=e=>{if(typeof e!=`object`)return!0;switch(e.kind){case`ModelValue`:case`Interval`:return!0;case`Set`:return e.elements.every(Gc);case`Function`:return e.writtenKeys===void 0&&e.domain.every(Gc)&&e.range.every(Gc);case`SetOperation`:return e.operator!==`\\cup`&&Gc(e.left)&&Gc(e.right);case`FilteredSet`:return Gc(e.base);case`ProductSet`:return e.factors.every(Gc);default:return!1}},Kc=e=>typeof e!=`object`||Gi(e)?!1:e.kind===`Union`?!0:e.kind===`FilteredSet`?Kc(e.base):e.kind===`SetOperation`?e.operator===`\\cup`||Kc(e.left)||Kc(e.right):Wc(e)?.some(Kc)??!1,qc=(e,t)=>Wo(e,e=>Or(e)?Go(e):Hc(e,t)),Jc=(e,t,n)=>{if(e.kind===`Union`)return qc(e,n).some((r,i)=>{let a=qo(r,i,e);return i===0&&Or(e.base)?Bc(a,n,t):Vc(a,t)});if(e.kind===`FilteredSet`&&I(e.base)){let r=e.startPass?.(!1);return r?Bc(e.base,n,e=>r.test(e)&&t(e))?!0:(r.end(),!1):Bc(e.base,n,n=>e.test(n,!1)&&t(n))}if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&n!==void 0)return tc(kc(e,n),t);if(Wc(e)?.some(Kc))return Cs(e,!1,Uc).some(t);if(e.kind===`Subset`&&e.enumerated===void 0&&R(e.base)>20)return $o(ns(e),t,e.cost?.node);if((e.kind===`FunctionSet`||e.kind===`RecordSet`||e.kind===`ProductSet`)&&!e.enumerated)return hs(e,!1)?vs(e,z.sets?Pc(e,!1):void 0,!0).some(t):tc(Ks(e),t);if(e.kind!==`SetOperation`)return _s(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 Bc(e.left,r?.left,t)||Bc(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)?Bc(i,n,n=>B(n,a)===(e.operator===`\\cap`)&&t(n)):L(e).elements.some(t)},Yc=()=>!0,Xc=e=>`Shouldn't call isEmpty() on value ${U(e)}`,Zc=e=>{if(typeof e!=`object`||!wr(e))throw z.sets?.push(e),P(Xc,e);switch(e.kind){case`Set`:case`MixedSet`:return e.elements.length===0;case`Interval`:return il(e.low,e.high)===0;case`InfiniteSet`:if(e.name===`Any`)throw new n(`Shouldn't call isEmpty() on value ANY`);return!1;case`Subset`:case`SequenceSet`:return!1}let t=z.sets;if(t===void 0)return Qc(e);t.push(e);let r=Qc(e);return t.pop(),r},Qc=e=>{switch(e.kind){case`ProductSet`:return e.factors.some(Zc);case`RecordSet`:return e.sets.some(Zc);case`FunctionSet`:return!Zc(e.domain)&&Zc(e.range);case`Union`:return Wo(e).every((t,n)=>Zc(qo(t,n,e)));default:return!Vc(e,Yc)}},$c=(e,t,n)=>e.reduce((e,r)=>{let i=e*R(r,t);if(i>2147483647)throw P(n);return i},1),el=e=>`Overflow when computing the number of elements in:\n${N(U(e))}`,tl=e=>`Attempted to compute the number of elements in the ${kr(e)} ${N(U(e))}.`,nl=e=>`Attempted to compute the number of elements in the model value ${N(U(e))}.`,rl=e=>`Attempted to compute the number of elements in the overridden value ${N(U(e))}.`,il=(e,t)=>{let r=Math.max(0,t-e+1);if(r>2147483647)throw new n(`Size of interval value exceeds the maximum representable size (32bits): ${e}..${t}.`);return r},R=(e,t)=>{if(typeof e!=`object`)throw P(tl,e);switch(e.kind){case`ModelValue`:throw P(nl,e);case`Operator`:throw P(tl,e);case`Function`:return e.domain.length;case`LazyFunction`:return R(e.domain,t);case`Interval`:return il(e.low,e.high);case`InfiniteSet`:case`SequenceSet`:throw P(rl,e);case`Subset`:case`FunctionSet`:case`RecordSet`:case`ProductSet`:{let n=z.sets;n?.push(e);let r=al(e,t);return n?.pop(),r}default:return ks(e).elements.length}},al=(e,t)=>{switch(e.kind){case`Subset`:{let n=R(e.base,t);if(n>=31)throw P(el,e);return 2**n}case`FunctionSet`:{if(t!==`1.7.4`){if(Zc(e.domain))return 1;if(Zc(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(el,e);return i}case`RecordSet`:return t!==`1.7.4`&&Zc(e)?0:$c(e.sets,t,()=>el(e));case`ProductSet`:return t!==`1.7.4`&&Zc(e)?0:$c(e.factors,t,()=>`Overflow when computing the number of elements in ${N(U(e))}`)}},ol=e=>`Attempted to check if the set ${N(U(e))}is finite.`,sl=e=>{if(typeof e!=`object`||e.kind===`ModelValue`||e.kind===`Operator`)throw new n(`Attempted to check if the ${kr(e)} ${N(U(e))} is a finite set.`);switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:case`Function`:return!0;case`LazyFunction`:throw new n(`Attempted to check if the function:\n${N(U(e))}\nis a finite set.`);case`InfiniteSet`:return!1;case`SequenceSet`:return sl(e.base)&&Zc(e.base);case`Subset`:return sl(e.base);case`FunctionSet`:{let t=sl(e.domain);if(t&&Zc(e.domain))return!0;let n=sl(e.range);return n&&Zc(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(!sl(e))n=!1;else if(Zc(e))return!0;return n}case`Union`:if(!I(e.base))throw new n(`Attempted to check if the nonenumerable set:\n${Ho(e)}\nis a finite set.`);return L(e.base).elements.every(sl);case`SetOperation`:if(e.operator===`\\cup`)return sl(e.left)&&sl(e.right);if(e.operator===`\\cap`){if(!sl(e.left)&&!sl(e.right))throw new n(ol(e));return!0}if(sl(e.left))return!0;if(!sl(e.right))throw new n(ol(e));return!1;case`FilteredSet`:if(!sl(e.base))throw new n(`Attempted to check if expression of form {x \\in S : p(x)} is a finite set, but cannot check if S:\n${N(U(e.base))}\nis finite.`);return!0}},cl=(e,t,n=ki)=>{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},ll=(e,t)=>{let n=e.elements;if(n.length>vr())throw new D(yr());let r=Array.from({length:n.length},()=>!1),i=t.filter(e=>{let t=cl(n,e);return!r[t]&&(r[t]=!0,!0)}),a=Li(n);return i.some((e,t)=>e!==n[t])&&(a.writtenElements=i),a},ul=e=>e instanceof Oo&&e.interval.low===1||e.every((e,t)=>e===t+1),dl=e=>{let t=_s(e.domain),n=[];for(let r=0;r<t.length;r++){if(t[r]!==r+1)return;n.push(e.apply(t[r]))}return eu(e)&&e.costModel.node>=0&&(e.costModel.secondary[e.costModel.node]+=t.length),n},fl=e=>typeof e.domain==`object`&&e.domain.kind===`Interval`?e.domain.low===1||e.domain.high<e.domain.low:ul(_s(e.domain)),pl=e=>{if(typeof e!=`object`||!Er(e))return;if(e.kind===`LazyFunction`){if(e.boundTupleLengths!==void 0)return;if(!wr(e.domain)||hi(e.domain))throw new n(`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||!fl(e)))return dl(e)}let t=V(e);if(ml(t.domain))return pa(e),t.range},ml=e=>e.length===0||e[0]===1&&e[e.length-1]===e.length,hl=(e,t)=>{if(typeof t==`object`&&t.kind===`Operator`)return`Attempted to check if the value:\n${N(U(e))}\nis an element of operator ${N(U(t))}`;let n=`Attempted to check if the value:\n${N(U(e))}\nis an element of the`;if(!Er(t))return`${n} ${kr(t)} ${N(U(t))}`;let r=Hi(t);return r===`record`?`Attempted to check if element:\n${N(U(e))}\nis in the record:\n${N(U(t))}`:r===`tuple`?`Attempted to check set membership in a tuple value.`:`${n} function ${N(U(t))}`},z={sets:void 0},gl=()=>{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}},_l=e=>{e!==void 0&&(z.sets&&(z.sets.length=e.depth),z.callStack&&(z.callStack.fingerprint=e.fingerprint))},vl=e=>{_l(e);let t=z.callStack;e!==void 0&&t&&(t.expressions.length=e.length,t.isFrozen=e.isFrozen)},yl=(e,t,r,i,a)=>{let o=gl(),s=_i;_i=`stopping`;try{let t=e(r,i);return _i=s,t}catch(e){if(_i=s,!(e instanceof g)){if(!(e instanceof n))throw e;if(a?.(r,i))throw xl(e)}return vl(o),t(r,i)}},bl=(e,t,r,i)=>{let a=gl(),o=_i;_i=`deferring`;try{let t=e(r,i);return _i=o,t}catch(e){if(_i=o,!(e instanceof n))throw e;return vl(a),t(r,i)}},xl=e=>(_i===`none`&&e.formatMessage(),e),Sl=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 jl(e,t);n.push(t);let r=jl(e,t);return n.pop(),r},Cl=(e,t)=>{let n=z.sets;n?.push(t);let r=Ol(e,t);return n?.pop(),r},wl=(e,t)=>{let n=z.sets;n?.push(t);let r=Ua(e,t.elements);return n?.pop(),r.isFound?r.index:-1},Tl=(e,t,n)=>{let r=z.sets;if(r===void 0)return Ql(e,t,n);r.push(t);let i=Ql(e,t,n);return r.pop(),i},El=(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},Dl=(e,t)=>cl(t.elements,e)!==-1,Ol=(e,t)=>pr(t)?Ua(e,t.elements).isFound:Wa(e,Ga(t)),kl=(e,t)=>`Attempted to check if the typed model value ${N(U(e))} is an element of\n${N(U(t))}`,Al=(e,t)=>{if(e.type!==void 0)throw P(kl,e,t);return!1},jl=(e,t)=>{if(typeof e==`number`&&typeof t==`object`){if(t.kind===`Set`&&!ji)return El(e,t)??Zl(e,t);if(t.kind===`Interval`)return e>=t.low&&e<=t.high}return Zl(e,t)},Ml=(e,t)=>`Attempted to check if the non-enumerable value\n${N(U(e))}\nis element of\n${N(U(t))}`,Nl=(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},Pl=(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`?Nl(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},Fl=(e,t,n)=>{if(!wr(e)||hi(e))throw P(Ml,e,t);return!Vc(e,e=>!n(e,t.base))},Il=(e,t)=>`Attempted to check if \n${U(e)}\nwhich is not a TLC function value, is in the set of functions:\n${N(U(t))}`,Ll=(e,t)=>`Attempted to check if non-record\n${U(e)}\nis in the set of records:\n${N(U(t))}`,Rl=(e,t)=>`Attempted to check if non-tuple\n${N(U(e))}\nis in the set of tuples:\n${N(U(t))}`,zl=(e,t)=>{if(!Er(e)){if(Dr(e))return Al(e,t);throw P(Il,e,t)}Ir(e);let n=da(e),r=ua(e,n.domain);return(r===void 0?to(t.domain,Li(n.domain)):eo({kind:`Interval`,low:r,high:r+n.domain.length-1},t.domain))&&n.range},Bl=(e,t)=>{Ir(e);let n=Er(e)?V(e):void 0;if(!n||!Lr(n.domain)){if(Dr(e))return Al(e,t);throw P(Ll,e,t)}return pa(n),n.domain.length===t.names.length&&n},Vl=(e,t)=>{let n=Er(e)?pl(e):void 0;if(n===void 0){let n=Er(e)&&da(e).domain.every(e=>typeof e==`number`);if(Dr(e))return Al(e,t);if(n)return!1;throw P(Rl,e,t)}return n.length===t.factors.length&&n},Hl=(e,t)=>e instanceof n&&zn(e)&&!Sl(t),Ul=(e,t)=>`Cannot decide if element:\n${N(U(e))}\n is element of:\n${N(U(t.base))}\nand satisfies the predicate ${t.source?.predicate}`,Wl=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},Gl=(e,t)=>`Attempted to check if:\n ${N(U(e))}\nis an element of the non-enumerable set:\n ${N(Ho(t))}`,Kl=(e,t,n)=>{if(!I(t.base))throw P(Gl,e,t);return Vc(t.base,t=>n(e,t))},ql=(e,t)=>`Attempted to check if the value:\n${N(U(e))}\nis an element of ${N(U(t))}.`,Jl=(e,t)=>{let n=pl(e);if(n===void 0){if(Dr(e))return Al(e,t);throw new s(yi(ql,e,t))}return n},Yl=(e,t)=>`Attempted to check if the value:\n${N(U(e))}\nis in the integer interval ${N(U(t))}`,Xl=(e,t)=>`Attempted to check if the value:\n${N(U(e))}\nis an element of ${t.name}.`,Zl=(e,t)=>{if(!wr(t))throw P(hl,e,t);switch(t.kind){case`Set`:return ji||Ui(e)||Qi(e)?Ol(e,t):yl(Dl,Ol,e,t);case`MixedSet`:return t.enumerated?Ua(e,t.enumerated.elements).isFound:Wa(e,t.elements);case`Interval`:if(typeof e==`number`)return e>=t.low&&e<=t.high;if(t.low<=t.high&&(!Dr(e)||e.type!==void 0))throw P(Yl,e,t);return!1;case`InfiniteSet`:if(t.name===`Any`)return!0;if(Dr(e))return Al(e,t);if(!(t.name===`STRING`?typeof e==`string`:typeof e==`number`))throw new s(yi(Xl,e,t));return t.name!==`Nat`||typeof e==`number`&&e>=0;case`Subset`:return typeof e==`object`&&e.kind===`Interval`?Pl(e,t.base,B):Tr(e)?L(e).elements.every(e=>B(e,t.base)):Fl(e,t,B);case`FunctionSet`:{let n=zl(e,t);return n!==!1&&n.every(e=>B(e,t.range))}case`RecordSet`:{let n=Bl(e,t);return n!==!1&&t.names.every((e,r)=>{let i=cl(n.domain,e);return i!==-1&&B(n.range[i],t.sets[r])})}case`ProductSet`:{let n=Vl(e,t);return n!==!1&&n.every((e,n)=>B(e,t.factors[n]))}case`FilteredSet`:{if(t.isCached)return B(e,L(t));let n=z.sets?.length??0;try{return B(e,t.base)&&t.test(e,!0)}catch(r){throw Hl(r,n)?P(Ul,e,t):r}}case`Union`:return Tr(t.base)?Wl(t.base).some(t=>B(e,t)):Kl(e,t,B);case`SetOperation`:return t.operator===`\\cup`?B(e,t.left)||B(e,t.right):B(e,t.left)&&B(e,t.right)===(t.operator===`\\cap`);case`SequenceSet`:{let n=Jl(e,t);return n!==!1&&n.every(e=>B(e,t.base))}default:throw P(hl,e,t)}},Ql=(e,t,n)=>{if(typeof t!=`object`)return Zl(e,t);switch(t.kind){case`Subset`:return typeof e==`object`&&e.kind===`Interval`?Pl(e,t.base,n):Tr(e)?L(e).elements.every(e=>n(e,t.base)):Fl(e,t,n);case`FunctionSet`:{let r=zl(e,t);return r!==!1&&r.every(e=>n(e,t.range))}case`RecordSet`:{let r=Bl(e,t);return r!==!1&&t.names.every((e,i)=>{let a=cl(r.domain,e);return a!==-1&&n(r.range[a],t.sets[i])})}case`ProductSet`:{let r=Vl(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 Hl(n,r)?P(Ul,e,t):n}}case`Union`:return Tr(t.base)?Wl(t.base).some(t=>n(e,t)):Kl(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=Jl(e,t);return r!==!1&&r.every(e=>n(e,t.base))}default:return Zl(e,t)}},$l=(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)=>$l(e,t.range[r],n.range)),eu=e=>`costModel`in e,tu=e=>eu(e)?e.costModel.node:-1,nu=e=>`original`in e,ru=e=>{let t=[];for(let n=e;nu(n);n=n.original)t.push(n);return t},iu=(e,t)=>{let n=ru(e);return t.map(t=>{let r=e.applyBody(t);for(let e=n.length-1;e>=0;e--){let i=n[e];eo(i.path[i.depth],t)&&(r=Pu(r,i.path,i.depth+1,i.newValue))}return r})},au=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(oo)throw new n(`The set literal holds a lazy function`);let t=eu(e)?e.costModel.startConversion():void 0;if(R(e.domain),!wr(e.domain))throw new n(`The domains of formal parameters must be enumerable.`);let r=Io(e.domain,!1),i=nu(e)?iu(e,r):r.map(t=>e.apply(t));return e.enumerated=Ha(e.domain,r,i),t?.(),e.enumerated}throw P(au,e)},ou=(e,t,n)=>{let r=N(U(e)),i=N(U(t)),a=n===`1.7.4`;switch(Hi(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.`}},su=(e,t)=>{if(!$r)return ou(e,t);let n=N(U(t));return Hi(e)===`tuple`?`Attempted to apply tuple to a non-integer argument ${n}.`:`Attempted to apply record to a non-string argument ${n}.`},cu=(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},lu=e=>new n(`Attempted to apply function with integer domain to the non-integer argument ${N(U(e))}`),uu=(e,t)=>cl(e.domain,t),du=(e,t)=>{let n=Mr(e),r=e.domain;if(!$r&&n===r&&n.length>=32)return cl(n,t,(e,t)=>La(e,()=>Na(e,t)));let i=n.findIndex(e=>La(e,()=>Pa(e,t)));return i===-1||n===r?i:r.indexOf(n[i])},fu=(e,t,r)=>{let i=e.domain;if(typeof t!=typeof i[0]){let a=Hi(e),o=a===`tuple`?`number`:a===`record`?`string`:void 0;if(o!==void 0&&typeof t!==o)throw new n(r(e,t));if(o===void 0&&!$r&&typeof t!=`number`&&Fo(i))throw lu(t)}let a=cu(i,t);return a===-1?bl(uu,du,e,t):a},pu=(e,t)=>{let r=fu(e,t,ou);if(r===-1)throw new n(ou(e,t));return r},mu=(e,t,n,r)=>`In applying the function\n${N(U(e))},\nthe ${t} is:\n${N(U(n))}\nwhich ${r}.\n`,hu=(e,t)=>new n(mu(e,`argument list`,t,`does not match its formal parameter`)),gu=e=>new n(`Attempted to apply a function to ${U(e)}, which is not in its domain`),_u=(e,t,r,i)=>new n(mu(e,`argument number ${t+1}`,r,i===void 0?`is not in the function's domain ${U(e.domain)}`:`is not in its domain`)),vu=(e,t)=>typeof e==`object`&&e.kind===`Function`&&e.functionClass===`tuple`?e:F(t),yu=(e,t,r,i)=>{if(i===void 0)return r;let a=pl(r);if(a===void 0||a.length!==i)throw new n(mu(e,`argument number ${t+1}`,r,`does not match its formal parameter`));return vu(r,a)},bu=(e,t,n)=>{let r=e.domain,i=pl(n);if(i===void 0)throw hu(e,n);if(typeof r!=`object`||r.kind!==`ProductSet`)throw gu(n);let a=i;for(let o=0;o<t.length;o++){if(o>=i.length)throw hu(e,n);let s=i[o],c=t[o];if(!B(s,r.factors[o]))throw _u(e,o,s,c);let l=yu(e,o,s,c);l!==s&&(a===i&&(a=[...i]),a[o]=l)}if(i.length>t.length)throw hu(e,n);return a===i?vu(n,i):F(a)},xu=(e,t,n,r)=>{let i=e.domain,a=pl(n);if(a===void 0)throw hu(e,n);if(typeof i!=`object`||i.kind!==`ProductSet`)throw gu(n);let o=a;for(let s=0;s<t.length;s++){if(s>=a.length)throw hu(e,n);let c=a[s],l=t[s];if(!r(c,i.factors[s]))throw _u(e,s,c,l);let u=yu(e,s,c,l);u!==c&&(o===a&&(o=[...a]),o[s]=u)}if(a.length>t.length)throw hu(e,n);return o===a?vu(n,a):F(o)},Su=(e,t,r)=>{let i=e.boundTupleLengths;if(i!==void 0)return xu(e,i,t,r);if(!r(t,e.domain))throw new n(ou(e,t));return t},Cu=(e,t,n,r)=>t.apply(Su(e,n,r)),wu=(e,t,n)=>{if(e.boundTupleLengths!==void 0&&pl(n)===void 0)throw hu(e,n);return B(n,e.domain)?t.apply(n):void 0},Tu=(e,t,n)=>t.apply(n),Eu=(e,t,n,r)=>{let i,a=e;for(;nu(a);){if(eo(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=nu(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=Pu(s,t.path,t.depth+1,t.newValue)}return s},Du=(e,t,r)=>{if(typeof e==`object`&&e.kind===`LazyFunction`){if(e.enumerated)return Du(e.enumerated,t,r);if(nu(e))return Eu(e,t,B,Cu);let i=e.boundTupleLengths;if(i!==void 0)return e.apply(bu(e,i,t));if(!B(t,e.domain))throw new n(ou(e,t));return e.apply(t)}if(typeof e!=`object`||e.kind!==`Function`)throw new n(`Attempted to apply ${U(e)}, which is not a function`);let i=r??ou,a=fu(e,t,i);if(a===-1)throw new n(i(e,t));return e.range[a]},Ou=(e,t,n,r)=>typeof e!=`object`||e.kind!==`LazyFunction`||e.enumerated!==void 0?Du(e,t,n):nu(e)?Eu(e,t,r,Cu):e.apply(Su(e,t,r)),ku=e=>e instanceof Oo?e.interval:void 0,Au=e=>{if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return e.domain;let t=V(e),n=ku(t.domain);if(n)return n;let r=Li(t.domain);return t.functionClass===`record`?(t.writtenKeys&&(r.writtenElements=t.writtenKeys),r):(r.flags|=1,r)},ju=(e,t,n,r)=>{let i={kind:`LazyFunction`,domain:e.domain,apply:e=>Eu(i,e,B,Tu),source:e.source,boundTupleLengths:e.boundTupleLengths,isApplicationObserved:e.isApplicationObserved,original:e,path:t,depth:n,newValue:r,applyBody:nu(e)?e.applyBody:e.apply};return eu(e)?Object.assign(i,{costModel:e.costModel}):i},Mu=e=>{if(!Er(e))throw new n(`Attempted to apply EXCEPT construct to the value ${N(U(e))}.`);return V(e)},Nu=(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=Eu(r,n,B,wu);if(e===void 0)return;r=e;continue}let i=Mu(r),a=fu(i,n,su);if(a===-1)return;r=i.range[a]}return r},Pu=(e,t,n,r)=>{if(n===t.length)return r;if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0)return ju(e,t,n,r);let i=Mu(e),a=fu(i,t[n],su);return a===-1?i:zu(i,a,Pu(i.range[a],t,n+1,r))},Fu=(e,t,n,r)=>{if(n===t.length)return r(e);if(typeof e==`object`&&e.kind===`LazyFunction`&&e.enumerated===void 0){let i=Nu(e,t,n);return i===void 0?e:ju(e,t,n,r(i))}let i=Mu(e),a=fu(i,t[n],su);return a===-1?i:i instanceof rr?ur(i,a,Fu(ar(i,a),t,n+1,r)):zu(i,a,Fu(i.range[a],t,n+1,r))},Iu=0,Lu=e=>{if(typeof e!=`object`||e.kind===`ModelValue`)return nd(e);if(e.kind===`LazyFunction`)return e.enumerated===void 0?0:Lu(e.enumerated);if(e.kind===`Set`){if(!pr(e))return 0;if(e.hash!==0)return e.hash;let t=e.elements,n=Uu;for(let e=0;e<t.length;e++){let r=Lu(t[e]);if(r===0||r===qu)return r;n=n+Gu(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=Wu;for(let n=0;n<e.domain.length;n++){let r=Lu(e.domain[n]);if(r===0||r===qu)return r;let i=Lu(e.range[n]);if(i===0||i===qu)return i;t=t+Ku(r,i)|0}return e.hash=t,t},Ru=(e,t)=>{let n=Vi(Bi(e.domain,t),e.functionClass),r=e.hash!==0&&e.hash!==qu,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=Lu(o);if(s===0||s===qu){r=!1;continue}let c=nd(e.domain[n]);i=i-Ku(c,nd(a))+Ku(c,s)|0}return r&&(n.hash=i),n},zu=(e,t,n)=>{let r=[...e.range],i=e.range[t];r[t]=n;let a=Vi(Bi(e.domain,r),e.functionClass);a.writtenKeys=e.writtenKeys;let o=e.hash!==0&&e.hash!==qu;if(!o&&e.fingerprint===0)return a;let s=Lu(n);if(s===0||s===qu)return a;if(o){let r=nd(e.domain[t]);a.hash=i===n?e.hash:e.hash-Ku(r,nd(i))+Ku(r,s)|0}if(e.fingerprint!==0){let r=e.domain[t];a.fingerprint=i===n?e.fingerprint:e.fingerprint-od(r,i)+od(r,n)|0}return a},Bu=e=>{let t=Math.imul(e^e>>>16,2246822507),n=Math.imul(t^t>>>13,3266489909);return n^n>>>16},Vu=(e,t)=>Math.imul(e^t,16777619),Hu=e=>{let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return Bu(t)},Uu=1940243425,Wu=1725019383,Gu=e=>Bu(e+2654435769|0),Ku=(e,t)=>Bu(Math.imul(e,668265261)+t|0),qu=795548749,Ju=e=>e===qu,Yu=e=>{if(e instanceof rr)return cr(e);if(e.kind===`Set`){let t=e.elements,n=Uu;for(let e=0;e<t.length;e++){let r=nd(t[e]);if(r===qu)return qu;n=n+Gu(r)|0}return n}let t=Wu;for(let n=0;n<e.domain.length;n++){let r=nd(e.domain[n]),i=nd(e.range[n]);if(r===qu||i===qu)return qu;t=t+Ku(r,i)|0}return t},Xu=e=>{let t=e.low+il(e.low,e.high),n=Uu;for(let r=e.low;r<t;r++)n=n+Gu(nd(r))|0;return n},Zu=e=>new n(`TLC has found a state in which the value of a variable contains ${N(U(e))}`),Qu=e=>{typeof e==`object`&&e.kind!==`ModelValue`&&La(e,()=>{if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw Zu(e);if(wr(e)){for(let t of L(e).elements)Qu(t);return}let t=V(e);for(let[e,n]of t.domain.entries())Qu(n),Qu(t.range[e])})},$u=e=>{if(typeof e==`object`&&e.kind!==`ModelValue`)try{nd(e)===qu&&Qu(e);return}catch(e){if(!(e instanceof n))throw e;return e}},ed=e=>{let t=z.sets,r=[];z.sets=r;try{Qu(e)}catch(e){if(!(e instanceof n))throw e}finally{z.sets=t}return r},td=e=>Bu(e^1540483477),nd=e=>{if(typeof e==`number`)return td(e);if(typeof e==`boolean`)return e?729683222:682545830;if(typeof e==`string`)return Hu(e);if(e.kind===`Set`||e.kind===`Function`)return e.kind===`Set`&&(e.flags|=1),e.hash===0&&(e.hash=Yu(e),e.hash!==qu&&(e.flags|=4)),e.hash;if(e.kind===`ModelValue`)return e.hash;if(e.kind===`LazyFunction`)return Jo(e.domain)?nd(V(e)):qu;if(e.kind===`Interval`)return Xu(e);if(!Jo(e))return qu;let t=Ds(e),n=t?As(t,!0,L):L(e);return $i(e),nd(n)},rd=e=>{let t=Math.imul(e^e>>>15,739982445),n=Math.imul(t^t>>>12,695872825);return n^n>>>15},id=e=>{let t=2538058380;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),1540483477);return rd(t)},ad=e=>rd(ud(e)+2135587861|0),od=(e,t)=>rd(Math.imul(ud(e),374761393)+ud(t)|0),sd=461845907,cd=e=>{if(e.kind===`Set`){let t=e.elements,n=sd;for(let e=0;e<t.length;e++)n=n+ad(t[e])|0;return n}let t=1291169091;for(let n=0;n<e.domain.length;n++)t=t+od(e.domain[n],e.range[n])|0;return t},ld=e=>{let t=e.low+il(e.low,e.high),n=sd;for(let r=e.low;r<t;r++)n=n+ad(r)|0;return n},ud=e=>typeof e==`number`?rd(e^1759714724):typeof e==`boolean`?e?1000000007:521288629:typeof e==`string`?id(e):e.kind===`Set`||e.kind===`Function`?(e.fingerprint===0&&(e.fingerprint=cd(e)),e.fingerprint):e.kind===`ModelValue`?e.fingerprint:e.kind===`LazyFunction`?ud(V(e)):e.kind===`Interval`?ld(e):Jo(e)?ud(L(e)):id(dd(e)),dd=e=>typeof e==`boolean`?e?`T`:`F`:typeof e==`number`?String(e):typeof e==`string`?JSON.stringify(e):fd(e),fd=e=>{if(e.kind===`ModelValue`)return`@${e.name}`;if(e.kind===`InfiniteSet`)return`<${e.name}>`;if(e.kind===`SequenceSet`)return`<Seq ${dd(e.base)}>`;if(e.kind===`FilteredSet`&&!Jo(e))throw new n(`Attempted to compare the non-enumerable set ${U(e)} with another value`);if(wr(e))return Jo(e)?`{${L(e).elements.map(dd).join(`,`)}}`:`<${e.kind} ${U(e)}>`;let t=V(e);return`(${t.domain.map((e,n)=>`${dd(e)}:${dd(t.range[n])}`).join(`,`)})`},pd={'"':`\\"`,"\\":`\\\\`," ":`\\t`,"\n":`\\n`,"\f":`\\f`,"\r":`\\r`},md=e=>`"${e.replace(/["\\\t\n\f\r]/g,e=>pd[e])}"`,hd=1999,gd=e=>e.reduce((e,t)=>e===0?0:e*R(t),1),_d=e=>{let t=Ds(e);return t?As(t,!1,Es):Es(e)},vd=e=>{if(e.kind===`SetOperation`||e.kind===`FilteredSet`||e.kind===`Union`)return _d(e);if(e.cost?.charges?.chargePrintedSize(e),e.kind===`Subset`)return R(e.base)>6?void 0:_d(e);if(e.kind===`FunctionSet`){let t=Zc(e.domain)?0:R(e.domain);return(t===0?1:R(e.range)**t)<=hd?_d(e):void 0}return gd(e.kind===`RecordSet`?e.sets:e.factors)<=hd?_d(e):void 0},yd=(e,t)=>{if(t||e.kind===`Subset`&&Er(e.base)&&(e.base.kind===`Function`||Jo(e.base.domain)))return vd(e);let r=gl();try{return vd(e)}catch(e){if(!(e instanceof n))throw e;_l(r);return}},H=(e,t)=>{e.pending===void 0?e.parts.push(t):e.pending.push(t)},bd=(e,t)=>{e.pending===void 0?t?.pop():e.pending.push({kind:`SetEnd`,sets:t})},xd=(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;zd(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},Sd=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?xd(e,t,n,r):(e.depth++,zd(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isStrict:n,isNormalized:r})},Cd=(e,t,n,r,i)=>{for(let a=0;a<t.length;a++)a>0&&H(e,n),Sd(e,t[a],r,i)},wd=/* @__PURE__ */ new Set([`Set`,`MixedSet`,`Interval`,`Subset`,`FunctionSet`,`RecordSet`,`ProductSet`,`SetOperation`,`FilteredSet`,`Union`]),Td=e=>!$r&&typeof e==`object`&&wd.has(e.kind),Ed=(e,t,n,r)=>{r&&H(e,`(`),Sd(e,t,n,!1),r&&H(e,`)`)},Dd=(e,t,n)=>{switch(t.kind){case`Subset`:return H(e,`SUBSET `),Ed(e,t.base,n,typeof t.base==`object`&&(t.base.kind===`Interval`||t.base.kind===`SetOperation`));case`FunctionSet`:return H(e,`[`),Sd(e,t.domain,n,!1),H(e,` -> `),Sd(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]}: `),Sd(e,t.sets[r],n,!1);return H(e,`]`);case`ProductSet`:return H(e,`(`),Cd(e,t.factors,` \\X `,n,!1),H(e,`)`);case`SetOperation`:return Ed(e,t.left,n,Td(t.left)),H(e,` ${t.operator} `),Ed(e,t.right,n,Td(t.right));case`FilteredSet`:return H(e,t.source?`{${t.source.names} \\in `:`{x \\in `),Sd(e,t.base,n,!1),H(e,t.source?` : <expression ${t.source.predicate}> }`:` : ...}`);case`Union`:return H(e,`UNION(`),Sd(e,t.base,n,!1),H(e,`)`)}},Od=e=>/^[\p{L}\p{Nd}_]*$/u.test(e)&&/\p{L}/u.test(e)&&(e.length<4||!/^[WS]F_/.test(e)),kd=e=>{if(!Jo(e.domain))return;let t=gl();try{return V(e)}catch(e){if(!(e instanceof n)&&!re(e))throw e;_l(t);return}},Ad=(e,t,n)=>{t.kind===`Set`?mr(t,!0):L(t),n&&e.copies.push(t)},jd=(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(Gc),c=s?t.domain:[...t.domain];s||Ra(c,o);let l={...t,domain:c,range:o,writtenKeys:a};e.copies.push(n?{...n,enumerated:l}:l)},Md=(e,t,n)=>{e.pending===void 0?Ad(e,t,n):e.pending.push({kind:`SetEnd`,value:t,isCopied:n})},Nd=(e,t,n,r,i)=>{e.pending===void 0?jd(e,t,n,r,i):e.pending.push({kind:`FunctionEnd`,value:t,lazy:n,isWrittenOrderKept:r,isCopied:i})},Pd=(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`){Ad(e,t.value,t.isCopied);continue}if(t.kind===`FunctionEnd`){jd(e,t.value,t.lazy,t.isWrittenOrderKept,t.isCopied);continue}let n=i.length;Ld(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},Fd=(e,t,n,r)=>{e.pending===void 0?e.depth===1e3?Pd(e,t,n,r):(e.depth++,Ld(e,t,n,r),e.depth--):e.pending.push({kind:`Value`,value:t,isWrittenOrderKept:n,isCopied:r})},Id=(e,t,n,r)=>{for(let i=0;i<t.length;i++)Fd(e,t[i],n,r)},Ld=(e,t,n,r)=>{if(typeof t==`object`)switch(t.kind){case`Set`:case`MixedSet`:return Id(e,t.elements,n,!1),Md(e,t,r);case`Function`:return Id(e,t.range,n,r),Nd(e,t,void 0,n,r);case`LazyFunction`:if(t.enumerated)return Id(e,t.enumerated.range,!0,r),Nd(e,t.enumerated,t,!0,r);Fd(e,t.domain,n,!1),r&&e.copies.push({...t});return;case`SetOperation`:Fd(e,t.left,n,!1),Fd(e,t.right,n,!1);break;case`FunctionSet`:Fd(e,t.domain,n,!1),Fd(e,t.range,n,!1);break;case`RecordSet`:Id(e,t.sets,n,!1);break;case`ProductSet`:Id(e,t.factors,n,!1);break;case`Subset`:case`Union`:case`FilteredSet`:case`SequenceSet`:Fd(e,t.base,n,!1)}r&&e.copies.push(t)},Rd=e=>{let t={depth:0,pending:void 0,copies:[]};for(let n of e)Ld(t,n,!1,!0);return t.copies.map(e=>U(e,!0,!0))},zd=(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,md(t));switch(t.kind){case`ModelValue`:return H(e,t.name);case`Set`:return H(e,`{`),Cd(e,t.elements,`, `,n,r),H(e,`}`);case`MixedSet`:return Sd(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=ei.isExpanded?yd(t,n):void 0;return a?Sd(e,a,n,r):Dd(e,t,n),bd(e,i)}case`SequenceSet`:return H(e,`Seq(`),Sd(e,t.base,n,r),H(e,`)`);case`Function`:case`LazyFunction`:{let i=t.kind===`LazyFunction`?ei.isExpanded||!t.source?kd(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 `),Sd(e,r.domain,!1,!1)}return H(e,` |-> <expression ${n.body}>]`)}if(i.domain.length===0&&$r&&Hi(t)!==`tuple`)return H(e,`<< >>`);if(i.domain.length===0&&Hi(t)===`record`)return H(e,`[]`);let a=r&&Hi(t)!==`lambda`;if(ul(i.domain))return i.range.every(e=>typeof e==`number`)?H(e,`<<${i.range.join(`, `)}>>`):(H(e,`<<`),Cd(e,i.range,`, `,n,a),H(e,`>>`));let o=r?i.domain.map((e,t)=>[e,i.range[t]]):Pr(i);if(Hi(t)===`record`||i.domain.every(e=>typeof e==`string`&&Od(e))){H(e,`[`);for(let t=0;t<o.length;t++)H(e,`${t>0?`, `:``}${String(o[t][0])} |-> `),Sd(e,o[t][1],n,a);return H(e,`]`)}H(e,`(`);for(let t=0;t<o.length;t++)t>0&&H(e,` @@ `),Sd(e,o[t][0],n,r),H(e,` :> `),Sd(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 zd(r,e,t,n),r.parts.join(``)},Bd=(e,t)=>{if(e===void 0)return!1;try{return ea(e,t)}catch(r){if(r instanceof n)return e===t;throw r}},Vd=/%(\d+\$)?([-#+ 0,(<]*)(\d+)?(\.\d+)?(.?)/gs,Hd=(e,t)=>{let n=0,r=-1,i=!0,a=e.replace(Vd,(e,a,o=``,s,c,l=``)=>{let u=e=>o.includes(`-`)?e.padEnd(Number(s)):e.padStart(Number(s??0)),d=o.includes(`<`),f=o.replace(`<`,``);if(l===`n`&&e===`%n`)return`
|
|
10
10
|
`;if(l===`%`&&c===void 0&&/^-?$/.test(f))return f===`-`&&s===void 0&&(i=!1),u(`%`);let p=d?r:a===void 0?n++:Number(a.slice(0,-1))-1;r=p;let m=t[p];if(!`sSbBhH`.includes(l)||l===``||!/^-?$/.test(f)||f===`-`&&s===void 0||m===void 0)return i=!1,e;let h=l.toLowerCase(),g=h===`s`?m:h===`b`?`true`:(wn(m)>>>0).toString(16),_=u(c===void 0?g:g.slice(0,Number(c.slice(1))));return l===h?_:_.toUpperCase()});return i?a:void 0},Ud=(e,t)=>{let n=t?void 0:ri.get(e);if(n)return n();let r=Object.entries(e),i=ai.get(e),a=i!==void 0&&`_format`in e,o=a?e._format:r.length===1?`%s = %s
|
|
11
11
|
`:`/\\ %s = %s
|
|
12
12
|
`;if(typeof o!=`string`)throw new ie(`The _format field of the ALIAS ${i} is ${U(o)}, but it must be a string.`);return r.filter(e=>!(a&&e[0]===`_format`)).filter(e=>!t||e[0]===`_ALIASEvalError`||!Bd(t[e[0]],e[1])).map(e=>{let t=Hd(o,[e[0],N(U(e[1]))]);if(t===void 0)throw new ie(`The _format field of the ALIAS ${i} is ${U(o)}, but it must format two strings, the name and the value of a field.`);return t}).join(``)},Wd=(e,t,n)=>{let r=Ud(e,t);for(let e of n)Ja(e);return r},Gd=e=>Rn(()=>Ud(e)),Kd=[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],qd=/* @__PURE__ */ new Int32Array(256),Jd=/* @__PURE__ */ new Int32Array(256),Yd=/* @__PURE__ */ new Int32Array(256),Xd=/* @__PURE__ */ new Int32Array(256),Zd=/* @__PURE__ */ new Int32Array(256),Qd=/* @__PURE__ */ new Int32Array(256),$d=/* @__PURE__ */ new Int32Array(256),ef=/* @__PURE__ */ new Int32Array(256);let tf=0,nf=0;const rf=()=>BigInt(qd[128]>>>0)<<32n|BigInt(Zd[128]>>>0),af=e=>{let t=(e^nf)&255;nf=(nf>>>8|tf<<24)^Zd[t],tf=tf>>>8^qd[t]},of=e=>{let t=Kd[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);qd[e]=Number(BigInt.asIntN(32,t>>32n)),Zd[e]=Number(BigInt.asIntN(32,t))}let i=[qd,Jd,Yd,Xd],a=[Zd,Qd,$d,ef];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)^Zd[o],i[e][r]=t[r]>>>8^qd[o]}}};of(0);const sf=e=>{let t=nf^e,n=t&255,r=t>>>8&255,i=t>>>16&255,a=t>>>24;nf=tf^ef[n]^$d[r]^Qd[i]^Zd[a],tf=Xd[n]^Yd[r]^Jd[i]^qd[a]},cf=e=>{if(typeof e==`boolean`)return af(0),af(e?116:102),2;if(typeof e==`number`)return af(1),sf(e),5;if(typeof e==`string`){af(3),sf(e.length);let t=e.length&-4;for(let n=0;n<t;n+=4)sf(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++)af(e.charCodeAt(n));return 5+e.length}return af(21),sf(di(e.name)+1),5},lf=e=>{let t=tf,n=nf;tf=0,nf=0;let r=[xf(e),tf,nf];return tf=t,nf=n,r},uf=e=>`m = (${e} ^ l) & 255; l = ((l >>> 8) | (h << 24)) ^ L0[m]; h = (h >>> 8) ^ H0[m];`,df=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];`,ff=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)];`,pf=e=>`{ let r = ${e}; for (; r >= 4; r -= 4) { ${df(`0`)} } for (; r > 0; r--) { ${uf(`0`)} } }`,mf={integer:e=>`${uf(`1`)} ${df(e)}`,boolean:e=>`${uf(`0`)} ${uf(`(${e} ? 116 : 102)`)}`,set:e=>`${uf(`5`)} ${df(e)}`,function:e=>`${uf(`9`)} ${df(e)}`,scalar:(e,t,n)=>`${pf(e)} h ^= ${t}; l ^= ${n};`,scalarRun:(e,t,n)=>`{ const z = ${e}; ${ff(`z`)} } h ^= ${t}; l ^= ${n};`,scalarLookup:(e,t,n)=>`{ const z = Z[${e}]; if (z.length !== 0) { ${ff(`z`)} } else ${pf(e)} } h ^= ${t}; l ^= ${n};`},hf=(e,t)=>{let n=/* @__PURE__ */ new Int32Array,r=Array.from({length:t+1},()=>n),i=[Zd],a=[qd];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)^Zd[a],r[i]=t[i]>>>8^qd[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},gf=()=>({H0:qd,H1:Jd,H2:Yd,H3:Xd,L0:Zd,L1:Qd,L2:$d,L3:ef,initialHigh:qd[128],initialLow:Zd[128]}),_f=(e,t)=>{let n=tf,r=nf;nf=e[0],tf=e[1],xf(t),e[0]=nf,e[1]=tf,tf=n,nf=r},vf=e=>{af(5),sf(e)},yf=e=>{af(9),sf(e)},bf=e=>{if(e.kind===`InfiniteSet`||e.kind===`SequenceSet`)throw Zu(e);return L(e)},xf=e=>{if(typeof e!=`object`||Dr(e))return cf(e);if(Er(e)){let t=V(e);t.writtenKeys!==void 0&&(t.writtenKeys=void 0),yf(t.domain.length);let n=5;for(let e=0;e<t.domain.length;e++)n+=xf(t.domain[e]),n+=xf(t.range[e]);return n}if(e.kind===`Interval`){let t=il(e.low,e.high);vf(t);let n=e.low+t,r=5;for(let t=e.low;t<n;t++)r+=cf(t);return r}let t=e.kind===`Set`?e:bf(e);pr(t)||mr(t,!0);let n=t.elements;vf(n.length);let r=5;for(let e of n)r+=xf(e);return r},Sf=e=>{let t=tf,n=nf;tf=qd[128],nf=Zd[128];for(let t of e)xf(t);let r=BigInt(tf>>>0)<<32n|BigInt(nf>>>0);return tf=t,nf=n,r},Cf=(e,t)=>{let n=new BigInt64Array(e),r=new Int32Array(n.buffer),i=tf,a=nf;for(let n=0;n<e;n++)tf=qd[128],nf=Zd[128],t(n),r[2*n]=nf,r[2*n+1]=tf;return tf=i,nf=a,n},wf=(e,t)=>Cf(e.length,n=>{for(let r of t)xf(e[n][r])}),Tf=/* @__PURE__ */ new WeakMap,Ef=(e,t)=>{for(let n=t;n;n=n.parent)if(n.name===e)return Tf.get(n)},Df=/* @__PURE__ */ new Set([`FiniteSets`,`Sequences`,`Bags`,`Naturals`,`Integers`,`Reals`,`RealTime`,`Randomization`,`TLC`]),Of=1024,kf=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*Of),relations:[],substitutionNodes:/* @__PURE__ */ new Map,frames:[],hiddenFrames:[],nextState:`given`,isMember:B,convertCharged:(e,t,n)=>t(e,n),chargeSubsetElements:()=>{},chargePrintedSize:()=>{},chargeIsEmpty:()=>{}};return t.isMember=Wp(t),t.convertCharged=(e,n,r)=>Mp(t,e,n,r),t.chargeSubsetElements=e=>Fp(t,e),t.chargePrintedSize=e=>Ip(t,e),t.chargeIsEmpty=e=>Np(t,e),t},Af=(e,t)=>({...e,evaluators:/* @__PURE__ */ new WeakMap,entryEvaluators:/* @__PURE__ */ new WeakMap,definitionEvaluators:/* @__PURE__ */ new WeakMap,coverage:t}),jf=(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)}},Mf=(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},Nf=(e,t,n)=>e.relations.find(e=>e.kind===t&&e.expression===n)?.node,Pf=e=>e.location.range??(e.kind===`Let`?e.body.location.range:void 0),Ff=(e,t,n,r,i)=>{let a=t===`next`?Nf(e,t,r):void 0;if(a!==void 0)return a;let o=Mf(e,void 0,Pf(r),-1,!1);return e.relations.push({kind:t,label:n,expression:r,scope:i,node:o}),o},If=(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,Lf=e=>k(e).location.range??e.location.range,Rf=(e,t,n,r,i)=>{let a=e===void 0||r?void 0:Bn(e,n),o=a===void 0?void 0:n.substitutions.get(a)??a,s=o===void 0?void 0:n.definitions.get(o),c=r??(s?.kind===`Operator`?s.head:void 0),l=Pf(t),u=Lf(t)??l,d=r?e:o===void 0?void 0:n.instanceNames.get(o)??s?.name;if(d===void 0||!c){let e=k(t);return e.kind===`Number`?`Action ${Hn(e)}`:`Action ${u?b(u):`Unknown location`}`}return(r?If(i,Lf(t)):s&&If(Pf(s.body),l))||!u?`${d} ${b(c)}`:`${d} ${b(c)} (${u.start.line} ${u.start.column} ${u.end.line} ${u.end.column})`},zf=e=>`${e.module}:${e.start.line}:${e.start.column}:${e.end.line}:${e.end.column}`,Bf=(e,t)=>e&&t?{module:e.module,start:e.start,end:t.end}:void 0,Vf=(e,t)=>t&&{module:t.module,start:e.range?.start??{line:e.line,column:e.column},end:t.end},Hf=e=>{let t=Array.from({length:11},()=>[]);for(let n=0;n<e.length;n++){let r=e[n];if(n>=Math.floor(t.length*.75)){let e=Array.from({length:t.length*2+1},()=>[]);for(let n=t.length-1;n>=0;n--)for(let r of t[n])e[(wn(r.name)&2147483647)%e.length].unshift(r);t=e}t[(wn(r.name)&2147483647)%t.length].unshift(r)}return t.toReversed().flat()},Uf=e=>e.flatMap((t,n)=>n>0&&e[n-1].set===t.set?[]:[t.set]),Wf=(e,t,n)=>e.reduce((e,t,r)=>({name:t,definition:void 0,scope:void 0,operatorBody:n?.[r],parent:e}),t),Gf=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n},Kf=(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},qf=e=>e.flatMap(e=>e.pattern.kind===`Name`?[e.pattern.name]:e.pattern.names),Jf=e=>yn.get(e)?.find(e=>!Ve.has(e))?.location.range,Yf=(e,t)=>{let n=[];for(let r=e.firstChild[t];r!==-1;r=e.nextSibling[r])n.push(r);return n},Xf=(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||If(e.ranges[t],n)));a!==void 0&&(r.add(a),e.twins[i]=a,Xf(e,Yf(e,a),Yf(e,i)))}},Zf=(e,t)=>(yn.get(e)??[]).filter(e=>Ve.has(e)&&!t.includes(e)),Qf=(e,t,n)=>{let r=new Set(n.map(zf)),i=[],a=[],o=[],s=[],c=/* @__PURE__ */ new Map,l=/* @__PURE__ */ new Map,u,d=(e,n,r)=>{if(j(e)){let e=Gf(r,n);return e?.definition&&{definition:e.definition,scope:e.scope}}let i=t.substitutions.get(n)??n;if(t.variableIndex.has(i)||t.constants.has(i))return;let a=t.definitions.get(i),o=a?.location.range?.module??a?.body.location.range?.module;return a&&!Df.has(o??``)?{definition:a,scope:void 0}:void 0},f=(t,n,a,s=!1,d)=>{let f=Mf(e,t,n,i.at(-1)??-1,s);if(t)for(let n=i.length-1;n>=0;n--){let r=e.children[i[n]]??=/* @__PURE__ */ new Map;if(r.has(t)||r.set(t,f),!e.isPart[i[n]])break}e.isPrimed[f]=n!==void 0&&r.has(zf(n));let p=t===u?void 0:t&&l.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&&c.get(t);if(m)for(let t=0;t<i.length;t++){let n=i[t];e.expressions[n]===m&&(e.lets[n]??=[]).push(f)}if(d?.kind===`Operator`&&d.isRecursive){let t=i.findLast(e=>o[e]===d);t!==void 0&&(e.recursive[f]=t)}return o[f]=d,i.push(f),a(f),i.pop(),f},p=(e,t)=>{let n=e.definition;if(s.includes(n))return;s.push(n);let r=n.kind===`Function`?qf(n.bounds):n.params.map(e=>e.name);n.kind===`Function`?f(vt(n),n.location.range,()=>{y(n.body,Wf(r,e.scope));for(let t of Uf(n.bounds))y(t,e.scope)}):y(n.body,Wf(r,e.scope,t)),s.pop()},m=e=>e?.definition.kind===`Operator`&&e.definition.params.length>0,h=(e,t)=>{if(e.kind===`Lambda`)return e.body;if(e.kind!==`Identifier`)return;let n=d(e,e.name,t)?.definition;return n?.kind!==`Operator`||n.params.length===0?j(e)?Gf(t,e.name)?.operatorBody:void 0:k(n.body)===n.body?n.body:void 0},g=(e,n,r,i)=>{if(e.kind===`Lambda`)y(e.body,Wf(e.params,i));else{if(e.kind===`Identifier`){let a=d(e,e.name,i);if(r?.kind===`Operator`&&(r.params[n]?.arity??0)>0||m(a)){if(!a)return;let n=u;!j(e)&&t.substitutions.has(e.name)&&(u=a.definition.body),p(a),u=n;return}}y(e,i)}},_=(t,n,r,a)=>f(n===t.operands.length?t:void 0,r,()=>{let o=t.operands;if(n>2&&!t.isBulleted){let s=t.prefixEnds?.[n-3],c=_(t,n-1,r&&s?{...r,end:s}:r,a);e.prefixes[i.at(-1)??-1]=c,y(o[n-1],a)}else for(let e of o.slice(0,n))y(e,a)},n<t.operands.length),v=(t,n)=>{let r=Zf(t,a),o=i.at(-1)??-1;for(let t of r){for(let r of Ve.get(t)?.()??[]){y(r.replacement,n);let t=o===-1?-1:e.lastChild[o];if(t===-1||e.expressions[t]!==r.replacement)continue;let i=e.roots[t],a=e.substitutionNodes.get(i)??/* @__PURE__ */ new Map;e.substitutionNodes.set(i,a.set(r,t))}a.push(t)}return r.length},y=(e,t)=>{let n=v(e,t);b(e,t),a.length-=n},b=(n,r)=>{let i=n.location.range,o=e=>{for(let t of e)y(t,r)},s=lt.get(n);if(s&&s.replacement!==n)f(n,Jf(n),()=>void 0);else switch(n.kind){case`Number`:case`Decimal`:case`String`:case`ExceptAt`:case`Bracket`:case`Subexpression`:case`OperatorReference`:return;case`Label`:case`Lambda`:y(n.body,Wf(n.params,r));return;case`EnabledVariable`:{let e=v(n.substitution,r);f(n,Jf(n.substitution),()=>void 0),a.length-=e;return}case`Selection`:i===void 0?y(n.expression,r):f(n,i,()=>y(n.expression,r));return;case`Let`:{let i=Kf(n.definitions,r);for(let e of n.definitions)(e.kind===`Operator`||e.kind===`Function`)&&c.set(Ht(e),n.body);if(!t.boundSubstitutions.lets.has(n)){let t=[];for(let r of Hf(n.definitions)){if(r.name===`LAMBDA`||_n(r))continue;let n=e.expressions.length;if(p({definition:r,scope:i}),!Oe(r))continue;let a=[];for(let t=n;t!==-1&&t<e.expressions.length;t=e.nextSibling[t])a.push(t);Xf(e,t,a),t.push(...a.filter(t=>e.twins[t]===-1))}}y(n.body,i);return}case`Identifier`:{if(Dn.has(n))return;let e=d(n,n.name,r),a=t.boundSubstitutions.references.has(n)||e&&St(e.definition);f(n,a&&Jf(n)||i,()=>{e&&!a&&p(e)},!1,e?.definition);return}case`Apply`:{let a=d(n,n.operator,r),o=Qt.has(n)&&!n.resolution?.isSubstitute,s=j(n)?Gf(r,n.operator)?.operatorBody:void 0,c=()=>{if(a&&!n.hasSubstitutedOperator){let e=!j(n)&&t.substitutions.has(n.operator);p(a,e?void 0:n.args.map(e=>h(e,r)))}for(let[e,t]of n.args.entries())Dn.has(t)||g(t,e,a?.definition,r)};if(o){c();return}f(n,i,t=>{if(s){let n=l.get(s)??[];n.some(t=>If(e.ranges[t],i))||l.set(s,[...n,t])}c()},!1,a?.definition);return}case`And`:case`Or`:_(n,n.operands.length,i,r);return;case`Case`:f(n,i,()=>{for(let e of n.arms)f(void 0,Bf(e.condition.location.range,e.body.location.range),()=>o([e.condition,e.body]),!0);let e=n.other;e&&f(void 0,n.otherRange,()=>y(e,r),!0)});return;case`Record`:case`RecordSet`:f(n,i,()=>{for(let e of n.fields)f(void 0,Vf(e.location,e.value.location.range),()=>y(e.value,r),!0)});return;case`FunctionApplication`:f(n,i,()=>{y(n.function,r);let e=n.args;e.length===1?y(e[0],r):f(void 0,i,()=>o(e),!0)});return;case`Forall`:case`Exists`:case`FunctionConstruction`:f(n,i,()=>{y(n.body,Wf(qf(n.bounds),r)),o(Uf(n.bounds))});return;case`SetMap`:f(n,i,()=>{y(n.expression,Wf(qf(n.bounds),r)),o(Uf(n.bounds))});return;case`SetFilter`:f(n,i,()=>{y(n.predicate,Wf(qf([n.bound]),r)),y(n.bound.set,r)});return;case`Choose`:f(n,i,()=>{let e=n.pattern;y(n.body,Wf(e.kind===`Name`?[e.name]:e.names,r)),n.set&&y(n.set,r)});return;case`UnboundedQuantifier`:f(n,i,()=>y(n.body,Wf(n.names,r)));return;case`Except`:f(n,i,()=>{y(n.function,r);for(let e of n.updates)f(void 0,e.range,()=>{f(void 0,e.range,()=>{for(let t of e.path)t.kind===`Index`&&(t.args.length===1?o(t.args):f(void 0,t.tupleRange,()=>o(t.args),!0))},!0),y(e.value,r)},!0)});return;case`Prime`:case`Unchanged`:case`Enabled`:case`Always`:case`Eventually`:f(n,i,()=>y(n.expression,r));return;case`If`:f(n,i,()=>o([n.condition,n.consequent,n.alternative]));return;case`SetEnumeration`:case`Tuple`:f(n,i,()=>o(n.elements));return;case`Product`:f(n,i,()=>o(n.factors));return;case`FunctionSet`:f(n,i,()=>o([n.domain,n.range]));return;case`FieldAccess`:f(n,i,()=>y(n.record,r));return;case`BoxAction`:case`AngleAction`:f(n,i,()=>o([n.action,n.subscript]));return;case`WeakFairness`:case`StrongFairness`:f(n,i,()=>o([n.subscript,n.action]))}},x=e=>{let t=[];for(let n=e;n;n=n.parent){let e=Tf.get(n);e&&t.unshift(e)}return Kf(t,void 0)};for(let t=0;t<e.relations.length;t++){let n=e.relations[t];l.clear(),i.push(n.node),y(n.expression,x(n.scope)),i.pop()}},$f=(e,t,n)=>e.children[t]?.get(n)??e.appliedBodies[t]?.find(t=>e.expressions[t.node]===n)?.node??-1,ep=(e,t,n)=>{if(e.expressions[t]===n)return t;let r=$f(e,t,n);if(r!==-1)return r;let i=e.recursive[t],a=i===-1?-1:$f(e,i,n);return a===-1?e.lets[t]?.findLast(t=>e.expressions[t]===n)??t:a},tp=(e,t,n)=>ep(e,t,n.kind===`Let`&&e.roots[t]===t?n.body:n),np=(e,t)=>{for(let n=t;n!==-1;n=e.prefixes[n])e.primary[n]++},rp=(e,t,n)=>{t>=0&&e.expressions[t]===n&&np(e,e.lastChild[t])},ip=(e,t,n)=>{let r=e.current;e.current=t;try{return n()}finally{e.current=r}},ap=(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]}}},op=(e,t,n,r)=>{let i=n<0?-1:e.roots[n],a=0;for(let n=0;n<t.length;n++){let o=t[n];Ve.has(o)&&!sp(e,o,i)&&(e.frames.push({frame:o,root:i,isCached:r,counted:[],countedWithoutNext:[]}),a++)}return a},sp=(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}},cp=(e,t)=>{e.frames.length-=t},lp=e=>e.frames.length===0?void 0:e.frames.slice(),up=(e,t,n,r)=>{if(!n)return ip(e,t,r);let i=e.frames.length;e.frames.push(...n);try{return ip(e,t,r)}finally{e.frames.length=i}},dp=(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},fp=(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},pp=(e,t,n)=>{let r=sp(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)},mp=(e,t,n)=>{let r=rc(e,t);r!==void 0&&(e.secondary[r]+=n)},hp=(e,t,n,r,i,a)=>{let o=Tr(n)?n:t!==`\\`&&Tr(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||Os(e,n)||Os(e,r))?Xi(Bs(i.operator,i.left,i.right,{node:o,charges:e})):i}let s=o===n?r:n;if(t===`\\cup`){if(Zc(o))return i;if(!Tr(s)){let t=rc(e,o);return i.kind===`SetOperation`&&(t!==void 0||Os(e,s))?Xi(Bs(i.operator,i.left,i.right,{node:t,charges:e})):i}let t=rc(e,s);t!==void 0&&(e.secondary[t]+=R(s)+1)}let c=t===`\\cup`?void 0:rc(e,o);if(rc(e,i)===c)return i;let l=i===n||i===r||rc(e,i)!==void 0?{...i,costNode:void 0}:i;return c!==void 0&&e.values.set(l,c),l},gp={next:()=>!1,reset:()=>void 0},_p=(e,t,n)=>{let r=0;return{next:()=>(t!==void 0&&e.secondary[t]++,r++<n),reset:()=>{r=0}}},vp=(e,t,n,r)=>{if(r.includes(0))return gp;let i=n.map((t,n)=>Dp(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}}},yp=(e,t)=>{let n=Array(e.length),r,i=0,a=!1,o=1;for(let t=0;t<e.length;t++){let s=Sp(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},bp=(e,t,n)=>{let r=rc(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 Np(e,t),gp;let i=t.kind===`RecordSet`?t.sets:t.kind===`ProductSet`?t.factors:Array.from({length:Nc(t)},()=>t.range),a=yp(i,n);if(a===void 0)return;Np(e,t);let o=t.kind===`FunctionSet`&&!a.includes(0)?Ds(t.domain):void 0;return o&&jp(e,o),vp(e,r,i,a)},xp=(e,t,n)=>{if(typeof t==`object`&&(t.kind===`SetOperation`||t.kind===`Union`||t.kind===`Subset`)){let r=Sp(t);if(r===void 0)return;let i=Dp(e,t,r,!1);return n&&i.next(),i}let r=rc(e,t);return r===void 0||typeof t!=`object`||t.kind!==`RecordSet`&&t.kind!==`ProductSet`&&t.kind!==`FunctionSet`||t.cost?.charges!==void 0?bp(e,t,void 0):(n&&e.secondary[r]++,_p(e,r,R(t)))},Sp=e=>{if(typeof e==`object`)switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return R(e);case`Subset`:return Sp(e.base)===void 0?void 0:R(e);case`FilteredSet`:return e.isCached?R(e):void 0;case`FunctionSet`:return Sp(e.domain)===void 0||Sp(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(Sp(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=sc(e);return Sp(t)!==void 0&&Cp(t===e.left?e.right:e.left)?Uc(e).length:void 0}let t=Sp(e.left),n=Sp(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(Sp(e.base)===void 0)return;let t=Uc(e.base),n=0;for(let e=0;e<t.length;e++){let r=Sp(t[e]);if(r===void 0)return;n+=r}return n}default:return}},Cp=e=>{if(typeof e!=`object`)return!1;switch(e.kind){case`Set`:case`MixedSet`:case`Interval`:return!0;case`Subset`:return Cp(e.base);case`FilteredSet`:return e.isCached===!0;case`FunctionSet`:return Cp(e.domain)&&Cp(e.range);case`RecordSet`:case`ProductSet`:{let t=e.kind===`RecordSet`?e.sets:e.factors;for(let e=0;e<t.length;e++)if(!Cp(t[e]))return!1;return!0}case`SetOperation`:return!e.isCached&&Cp(e.left)&&Cp(e.right);default:return!1}},wp=(e,t,n,r,i)=>{if(t.cost?.charges===void 0)return;let a=Sp(t.left),o=Sp(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=Dp(e,t.left,s,!1),l=Dp(e,t.right,o??r-s,!1);return{next:()=>(n!==void 0&&e.secondary[n]++,c.next()||l.next()),reset:()=>{c.reset(),l.reset()}}},Tp=(e,t,n)=>{let r=Sp(t.base);if(t.cost?.charges===void 0||r===void 0)return;let i=Uc(t.base),a=Array(i.length);for(let e=0;e<i.length;e++){let t=Sp(i[e]);if(t===void 0)return;a[e]=t}let o=Dp(e,t.base,r,!1),s=0,c=o.next()?Dp(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=Dp(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()?Dp(e,i[0],a[0],!1):void 0}}},Ep=(e,t)=>{if(t.cost?.charges===void 0||Tr(t.left))return;let n=t.operator===`\\`;if(!n&&Tr(t.right))return;let r=sc(t),i=r===t.left?t.right:t.left,a=Sp(r);if(a===void 0||!Cp(i))return;let o=Uc(r),s=Dp(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}}},Dp=(e,t,n,r)=>{let i=rc(e,t);if(typeof t==`object`&&t.kind===`Subset`)return t.cost!==void 0&&t.cost.charges===void 0?_p(e,t.cost.node,n):(Fp(e,t),_p(e,void 0,n));if(typeof t==`object`&&!r&&t.kind===`FilteredSet`)return _p(e,t.isCached?i:void 0,n);let a=typeof t==`object`&&t.kind===`SetOperation`?t.operator===`\\cup`?wp(e,t,i,n,r):Ep(e,t):typeof t==`object`&&t.kind===`Union`?Tp(e,t,i):void 0,o=a??bp(e,t,n);if(!o||i===void 0&&!a)return _p(e,i,n);if(!r)return o;let s=0;for(;o.next();)s++;return i!==void 0&&(e.secondary[i]+=s),_p(e,i,a?n:s)},Op=/* @__PURE__ */ new Set([`Set`,`MixedSet`,`Interval`,`FunctionSet`,`RecordSet`,`ProductSet`]),kp=(e,t,n)=>{if(typeof t!=`object`||Op.has(t.kind))return;if(t.kind!==`Subset`){let r=Dp(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)},Ap=(e,t,n)=>{let r=Sp(t),i=r===void 0?void 0:Dp(e,t,r,!1),a=Vc(t,t=>(i?.next(),!e.isMember(t,n)));return a||i?.next(),!a},jp=(e,t)=>{let n=Sp(t);if(n===void 0)return;let r=Dp(e,t,n,!1);for(let e=0;e<=n;e++)r.next();let i=rc(e,t);i!==void 0&&(e.secondary[i]+=n)},Mp=(e,t,n,r)=>{if(t.kind===`Subset`){Pp(e,t),Fp(e,t);let i=n(t,r),a=t.cost?.node;return a!==void 0&&(e.secondary[a]+=i.elements.length),i}if(Sp(t)!==void 0)return jp(e,t),n(t,r);let i=n(t,r),a=i.elements.length,o=rc(e,t),s=t.kind===`FunctionSet`&&Sp(t.domain)===void 0?void 0:bp(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},Np=(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 Dp(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=Np(e,n[t]);if(r!==!1)return r}return!1}case`FunctionSet`:{let n=Np(e,t.domain);return n===void 0?void 0:!n&&Np(e,t.range)}case`SetOperation`:case`Union`:{let n=Sp(t);return n===void 0?void 0:(Dp(e,t,n,!1).next(),n===0)}default:return}},Pp=(e,t)=>{if(typeof t==`object`)switch(t.kind){case`SetOperation`:case`Union`:{if(t.cost?.charges===void 0)return;let n=Sp(t)!==void 0;jp(e,t),t.cost.charges=void 0,n&&R(t);return}case`RecordSet`:case`ProductSet`:{if(Np(e,t)!==!1)return;let n=t.kind===`RecordSet`?t.sets:t.factors;for(let t=0;t<n.length;t++)Pp(e,n[t]);return}case`FunctionSet`:if(Np(e,t.domain)!==!1||Np(e,t.range)!==!1||(Pp(e,t.range),R(t.range)===1))return;Pp(e,t.domain),Pp(e,t.range);return;case`Subset`:Pp(e,t.base)}},Fp=(e,t)=>{Pp(e,t.base);let n=Ds(t.base);n!==void 0&&Sp(n)!==0&&jp(e,n)},Ip=(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(Pp(e,n[t]),R(n[t])===0)return;return}case`FunctionSet`:if(Np(e,t.domain)!==!1)return;Pp(e,t.domain),Pp(e,t.range);return;case`Subset`:Pp(e,t.base)}},Lp=(e,t,n,r)=>Dp(e,t,Array.isArray(n)?n.length:n.high-n.low+1,r),Rp=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()}}),zp=(e,t,n,r)=>{let i=n?Oc(e,t,!1):void 0;return i===void 0?{kind:`Listed`,value:t,elements:r()}:{kind:`Drained`,value:t,elements:i}},Bp=(e,t)=>t.kind===`Drained`?_p(e,rc(e,t.value),t.elements.length):Lp(e,t.value,t.elements,!0),Vp=(e,t)=>Rp(t.map(t=>Bp(e,t))),Hp=(e,t,n,r)=>{let i=n.map(e=>R(e)),a=Rp(n.map((t,n)=>r?.[n]?_p(e,rc(e,t),i[n]):Dp(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)},Up=/* @__PURE__ */ new Set([`FunctionSet`,`RecordSet`,`ProductSet`,`FilteredSet`,`SetOperation`,`SequenceSet`]),Wp=e=>{let t=(n,r)=>{if(typeof r!=`object`)return B(n,r);if(r.kind===`Set`&&Os(e,n))return Cl(n,r);if(r.kind!==`Subset`&&r.kind!==`Union`)return Up.has(r.kind)?Tl(n,r,t):B(n,r);let i=Dc(e,n,r);if(i!==void 0)return i;let a=r.kind===`Subset`,o=0,s;try{return s=Tl(n,r,(e,n)=>(o++,t(e,n))),s}finally{let t=Dp(e,a?n:r.base,o,!1);for(let e=0;e<o;e++)t.next();s===a&&t.next()}};return t},Gp=e=>{let t=Number(e>>32n);return t===0?32+Math.clz32(Number(e&4294967295n)):Math.clz32(t)},Kp=(e,t,n)=>{for(let r=0;r<t.length;r++){let i=t[r];if(i===n?.[r])continue;let a=Sf([i]),o=Number(a>>BigInt(54)),s=BigInt.asUintN(64,a<<BigInt(10)|1n<<9n),c=r*Of+o;e.registers[c]=Math.max(e.registers[c],Gp(s)+1)}},qp=(e,t)=>{let n=e.registers.subarray(t*Of,(t+1)*Of),r=n.reduce((e,t)=>e+2**-t,0),i=.7205407583220416*Of*Of/r,a=n.filter(e=>e===0).length;return Math.trunc(i<=2.5*Of?a===0?i:Of*Math.log(Of/a):i>2**64/30?-(2**64)*Math.log(1-i/2**64):i)},Jp=e=>{let t=Math.imul(31,31+e.primary)+e.secondary|0;return t^t>>>16},Yp=e=>{let t=16;for(;e.length>t*.75;)t*=2;let n=e=>Jp(e)&t-1;return e.reduce((e,t)=>n(t)<n(e)?t:e)},Xp=(e,t)=>{e.some(e=>e.primary===t.primary&&e.secondary===t.secondary)||e.push(t)},Zp=(e,t)=>e.isPrimed[t]||e.isUnchanged[t],Qp=(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},$p=(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}},em=(e,t)=>{let n=[],r=/* @__PURE__ */ new Map,i=t=>({primary:t.reduce((t,n)=>t+e.primary[n],0),secondary:t.reduce((t,n)=>t+e.secondary[n],0)}),a=t=>{let n=[],o=i(t);(o.primary>0||o.secondary>0||Zp(e,t[0]))&&Xp(n,o);for(let r of Qp(e,t))for(let e of a(r))Xp(n,e);return r.set(t[0],n),n},o=(t,r,i,a)=>{let o=e.ranges[t[0]];n.push({location:o?b(o):`Unknown location`,depth:r,count:i,cost:a})},s=(e,t,n)=>o(e,t,n.primary,n.secondary),c=(t,n)=>{let l=Qp(e,t),u=[];for(let e of l)for(let t of r.get(e[0])??a(e))Xp(u,t);let d=i(t),f=Zp(e,t[0]),p=e=>{for(let t of l)c(t,e)};if(e.isUnchanged[t[0]]){let e=u.filter(e=>e.primary!==0||e.secondary!==0);e.length===0?s(t,n,d):o(t,n,Math.max(d.primary,Yp(e).primary),0);return}if(u.length===0){(d.primary!==0||f)&&s(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){s(t,n,d),p(n+1);return}if(!f&&m&&!r){o(t,n,e.primary,e.secondary);return}if(m&&r){f&&s(t,n,d),p(f?n+1:n);return}if(d.primary===e.primary&&d.secondary===e.secondary){s(t,n,d);return}}let h=!m||f;h&&s(t,n,d),p(h?n+1:n)};for(let n of Qp(e,[t]))a(n),c(n,0);return n},tm=[`init`,`next`,`invariant`,`constraint`,`implied`],nm=(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,rm=(e,t)=>nm(Lf(e.expression),Lf(t.expression))||nm(e.expression.location.range,t.expression.location.range),im=e=>tm.flatMap(t=>{let n=e.relations.filter(e=>e.kind===t);return t===`next`?n.toSorted(rm).filter((e,t,n)=>t===0||rm(n[t-1],e)!==0):n}),am=(e,t,n)=>({variables:n.map(n=>{let r=t.variableLocations[n]?.range;return{label:`${t.variables[n]} ${r?b(r):`Unknown location`}`,distinct:qp(e,n)}}),relations:im(e).map(t=>({kind:t.kind,label:t.label,...$p(e,t),expressions:em(e,t.node)}))}),om=(e,t,n)=>{let r=Nf(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]]]},sm=/* @__PURE__ */ new Set([`=`,`#`,`~`,`<=>`,`/\\`,`\\/`,`=>`,`\\in`,`\\notin`,`\\subseteq`,`\\cup`,`\\cap`,`\\`,`SUBSET`,`UNION`,`DOMAIN`,`+`,`-`,`*`,`^`,`\\div`,`%`,`..`,`Seq`,`IsFiniteSet`]),cm=(e,t)=>sm.has(e)?new n(t):new s(t),lm=(e,t,n,r)=>new s(`The ${e} argument of ${t} should be a ${n}, but instead it is:\n${N(U(r))}`),um=(e,t,n)=>new s(`Applying ${e} to the following value,\nwhich is not ${t}:\n${N(U(n))}`),dm=(e,t,n,r=e)=>{if(!wr(e)||hi(e))throw um(t,n,r);return L(e)},fm=e=>typeof e==`object`&&e.kind===`Operator`,W=(e,t,n)=>{let r=e[t];if(r===void 0)throw cm(n,`${n} expects a value as argument ${t+1}`);return r},pm=(e,t,n)=>{let r=W(e,t,n);if(typeof r!=`boolean`)throw cm(n,`${n} expects a boolean but received ${U(r)}`);return r},mm=(e,t,n)=>{let r=e[t];if(r===void 0||!fm(r))throw cm(n,`${n} expects an operator as argument ${t+1}`);return r},hm=(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}),gm=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0}),_m=(e,t,n)=>({kind:`Builtin`,name:e,arity:t,evaluate:n,evaluateUnary:void 0,evaluateBinary:void 0,isStateLevel:!0}),vm=(e,t)=>({kind:`Builtin`,name:e,arity:2,evaluate:n=>t(W(n,0,e),W(n,1,e)),evaluateUnary:void 0,evaluateBinary:t}),ym=e=>e>2147483647||e<-2147483648,bm=e=>new s(`Overflow when computing ${e}`),xm={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`},Sm={"\\cup":`SetCupValue`,"\\cap":`SetCapValue`,"\\":`SetDiffValue`},Cm={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`},wm={lambda:`FcnLambdaValue`,tuple:`TupleValue`,record:`RecordValue`},Tm=e=>{if(typeof e==`number`)return`IntValue`;if(typeof e==`string`)return`StringValue`;if(typeof e==`boolean`)return`BoolValue`;if(e.kind===`SetOperation`)return Sm[e.operator];if(e.kind===`Operator`)return e.javaClass;if(e.kind!==`Function`)return xm[e.kind];let t=Hi(e);return t===void 0?`FcnRcdValue`:wm[t]},Em=e=>Cm[Tm(e)],Dm=(e,t)=>new n(`class ${e} cannot be cast to class ${t} (${e} and ${t} are in unnamed module of loader 'app')`),Om=(e,t)=>new n(`Attempted to apply the operator overridden by the Java method\n${e},\nbut it produced the following error:\n${t}`),km=(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?Om(t,`cannot convert MethodHandle()${i} to (Value[])Value`):Om(t,n.length===0?`handle's method type (IValue[])${i} but found ()Value`:`array is not of length ${e.arity}`)}}),Am=(e,t)=>{let r=(r,i)=>{if(!(r instanceof n)||r instanceof p||r instanceof ne)return r;let a=Sl(i);return z.sets&&(z.sets.length=i),e.isLazy!==!0&&r instanceof s&&!a?r:(z.callStack&&(z.callStack.fingerprint=void 0),Om(t,r.message))},i=e.evaluate,a=e.evaluateUnary,o=e.evaluateBinary;return km({...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)}})},t)},jm=(e,t)=>{if(typeof e!=`number`)throw Om(t,`Cannot cast tlc2.value.impl.${Tm(e)} to tlc2.value.impl.IntValue`);return e},Mm=(e,t,n,r)=>`public static tlc2.value.impl.${n} tlc2.module.${e}.${t}(${Array.from({length:r},()=>`tlc2.value.impl.IntValue`).join(`,`)})`,Nm=(e,t,n,r)=>{let i=Mm(e,n,`IntValue`,2);return km(vm(t,(e,n)=>{let a=jm(n,i),o=jm(e,i),s=r(o,a);if(ym(s))throw bm(`${o}${t}${a}`);return s}),i)},Pm=(e,t,n)=>{if(typeof e!=`number`)throw new s(`The ${t} argument of ${n} should be an integer, but instead it is:\n${N(U(e))}`);return e},Fm=(e,t,n=e)=>vm(e,(e,r)=>t(Pm(e,`first`,n),Pm(r,`second`,n))),Im=(e,t,n)=>({..._m(e,t,n),isLazy:!0}),Lm=(e,t,n)=>{let r=mm(e,t,n);return()=>r.call([])},Rm=25214903917n,zm=(1n<<48n)-1n,Bm=e=>{let t=(BigInt.asUintN(64,e)^Rm)&zm,n=e=>(t=t*Rm+11n&zm,Number(BigInt.asIntN(32,t>>BigInt(48-e))));return{setSeed:e=>{t=(BigInt.asUintN(64,e)^Rm)&zm},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}},Vm=[],Hm=e=>{for(let t=2;t*t<=e;t++)if(e%t===0)return!1;return!0},Um=()=>{for(let e=1277011;Vm.length<1341;e++)Hm(e)&&Vm.push(e);return Vm},Wm=e=>{let t=Um(),n=t.length;for(;n===t.length;)n=Math.floor(e.nextDouble()*t.length);return t[n]},Gm=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},Km=e=>{for(let t=Math.max(e,9);;t++){let e=Gm(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)}}},qm={count:0,nextIndex:()=>0n},Jm=(e,t,n)=>{if(t<=0)return qm;let r=Km(t),i=BigInt(n.nextInt(t)),a=BigInt(Wm(n));return{count:e,nextIndex:()=>{do i=(r.multiplier*i+a)%r.modulus;while(i>=t);return i}}},Ym=(e,t,n)=>{if(t<=0)return qm;let r=BigInt(t<191?191:er),i=BigInt(n.nextInt(t));return{count:Math.min(e,t),nextIndex:e=>(r*BigInt(e)+i)%BigInt(t)}},Xm=(e,t,n,r)=>r===`1.7.4`?Ym(e,t,n):Jm(e,t,n),Zm=e=>Array.from({length:e.count},(t,n)=>e.nextIndex(n)),Qm=(1n<<63n)-1n-24n,$m=(e,t,n)=>{let r=n.nextLong(),i=BigInt.asIntN(64,r<0n?-r:r);return Array.from({length:e},(e,n)=>{let r=(Qm*BigInt(n)+i)%t;return r<0n?r+t:r})},eh=(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,th=e=>{if(typeof e==`object`){if(e.kind===`FunctionSet`){if(hi(e.domain))return;let t=Io(e.domain),n=I(e.range)?L(e.range).elements:[];return{lists:t.map(()=>n),create:e=>Bi(t,e)}}if(e.kind===`RecordSet`)return{lists:e.sets.map(e=>L(e).elements),create:t=>Lo(e.names.map((e,n)=>[e,t[n]]))};if(e.kind===`ProductSet`)return{lists:e.factors.map(e=>L(e).elements),create:F}}},nh=(e,t)=>t===`1.7.4`&&typeof e==`object`&&e.kind===`ProductSet`?e.factors:void 0,rh=(e,t,n,r)=>{if(Zc(t))return[];if(typeof t==`object`&&t.kind===`Interval`)return Zm(Xm(e,Math.max(0,t.high-t.low+1),n,r)).map(e=>t.low+Number(e));let i=nh(t,r)?void 0:th(t);if(i){let t=i.lists.reduce((e,t)=>e*BigInt(t.length),1n);return(t>BigInt(2147483647)?$m(e,t,n):Zm(Xm(e,Number(t),n,r))).map(e=>i.create(eh(i.lists,e)))}let a=L(t).elements;return Zm(Xm(e,a.length,n,r)).map(e=>a[Number(e)])},ih=(e,t,n)=>{let r=il(e.low,e.high),i=Xm(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}}},ah=(e,t)=>{if(typeof e==`object`&&e.kind===`FunctionSet`){let n=[...dm(e.domain,`RandomElement`,`a finite set`,e).elements];return Bi(n,n.map(()=>ah(e.range,t)))}if(typeof e==`object`&&e.kind===`RecordSet`)return Lo(e.names.map((n,r)=>[n,ah(e.sets[r],t)]));if(typeof e==`object`&&e.kind===`ProductSet`)return F(e.factors.map(e=>ah(e,t)));if(typeof e==`object`&&e.kind===`Interval`){let r=Math.max(0,e.high-e.low+1),i=Math.floor(t.nextDouble()*r);if(i>=r)throw new n(`Attempted to retrieve out-of-bounds element from the interval value ${N(U(e))}.`);return e.low+i}let r=dm(e,`RandomElement`,`a finite set`).elements,i=Math.floor(t.nextDouble()*r.length);if(i>=r.length)throw new n(`Index ${i} out of bounds for length ${r.length}`);return r[i]},oh=(e,t=0n)=>{let n=Bm(t),r=Bm(t),i,a=!1,o=!1,s,c={getLevel:()=>0,getBehavior:()=>[],getSpecification:()=>Lo([]),counterExample:void 0,counterExamples:/* @__PURE__ */ new WeakSet,deferred:void 0,isSeen:()=>!1,markExplored:void 0,getSuccessorAction:()=>void 0,toRecord:()=>({}),setLivenessSource:()=>{},getCurrentState:()=>void 0,getFingerprint:Sf,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=Bm(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},sh=[],ch=[],lh=e=>po([...e].map(e=>[e[0],e[1]])),uh=e=>e.sumPossibleCounts?.()??e.possibleCounts,dh=e=>lh(uh(e)),fh=e=>e.possibleCounts.size===0?e.namedRegisters:new Map([...e.namedRegisters,[`s:_possible`,lh(e.possibleCounts)]]),ph=e=>`isLetSubstitute`in e,mh=(e,t)=>t.bodyValues.has(e.body)?[]:$t(e),hh=1024,gh=2048,_h=/* @__PURE__ */ new Set([`Prime`,`Unchanged`,`BoxAction`,`AngleAction`]),vh=/* @__PURE__ */ new Set([`Always`,`Eventually`,`WeakFairness`,`StrongFairness`]),yh=/* @__PURE__ */ new Set([..._h,...vh,`Enabled`,`EnabledVariable`]),bh=/* @__PURE__ */ new Set([`~>`,`-+->`]),xh=/* @__PURE__ */ new Set([...bh,`\\cdot`]),Sh=/* @__PURE__ */ new Set([`Print`,`PrintT`,`Assert`,`JavaTime`,`RandomElement`,`TLCGet`,`TLCSet`,`JsonSerialize`,`ndJsonSerialize`,`JsonDeserialize`,`ndJsonDeserialize`,`Serialize`]),Ch=/* @__PURE__ */ new Set([`UNION`,`\\cup`]),wh=/* @__PURE__ */ new Set([`RandomSubset`,`RandomSetOfSubsets`,`RandomSubsetSet`]),Th=(e,t,n,r)=>{let i=new Uint32Array(n),a=[],o=[],s=-1,c=e=>{i[0]|=e,s!==-1&&r&&(r.effects[s]|=e)},l=e=>{let t=e.kind;if(_h.has(t)||t===`Apply`&&e.operator===`\\cdot`)return 96;if(t===`Enabled`||t===`EnabledVariable`)return 32;if(vh.has(t)||t===`UnboundedQuantifier`&&e.isTemporal===!0||t===`Apply`&&bh.has(e.operator))return 224},u=/* @__PURE__ */ new Map,d=(e,n,f,p)=>{let m=e.kind;if(m===`Selection`){let t=u.get(e.expression)??0,r=n?f?1:2:f?4:8;if((t&r)!==0)return;u.set(e.expression,t|r)}let h=f?1:513;(yh.has(m)||m===`UnboundedQuantifier`&&e.isTemporal===!0||m===`Apply`&&xh.has(e.operator))&&(i[0]|=h),yh.has(m)&&(i[0]|=16);let g=l(e);n&&g!==void 0&&(i[0]|=g);let _=n&&g===void 0,v=gn(e),y=v!==void 0&&j(e);if((y&&t.variableIndex.has(v)||Ut(e,t.variableIndex))&&(f||(i[0]|=512),_&&(i[0]|=32)),v!==void 0&&!y){let n=t.substitutions.get(v)??v,r=t.definitions.get(n),l=t.constants.has(v),u=t.variableIndex.get(v),d=t.builtins.get(n);if((u!==void 0||d?.isStateLevel||r&&t.variableIndex.has(r.name))&&(i[0]|=m===`Identifier`&&d&&d.arity>0?1:h),u!==void 0&&(_&&(i[0]|=32),l||(i[1+(u>>>5)]|=1<<(u&31))),r)a.push({name:v,callee:r,isOverridden:l,isLevelCounted:_,isBoundCounted:!(f||m===`OperatorReference`||m===`Identifier`&&r.kind===`Operator`&&r.params.length>0||t.theorems.has(n)),isSubstitute:n!==v,owner:s});else{let r=t.replacedDefinitions.get(n);r&&o.push({name:v,flags:(_?Mh:0)|(f||m===`OperatorReference`||m===`Identifier`&&r.kind===`Operator`&&r.params.length>0?0:Nh),owner:s});let a=d?.name??n,p=Sh.has(a)||d?.isStateLevel===!0,h=a===`TLCGet`&&e.kind===`Apply`&&e.args.length===1&&e.args[0].kind===`String`&&e.args[0].value===`level`;p&&c(2|(a===`Assert`||h?0:4)),Ch.has(a)&&c(8);let g=d!==void 0&&wh.has(d.name);g&&c(256),a===`TLCEval`&&c(hh),!l&&(p||g)&&(i[0]|=16),_&&!l&&u===void 0&&d?.isStateLevel&&!d.isLevelConstant&&(i[0]|=d.isActionLevel?96:32)}}let b=y?p?.get(v):void 0;if(b&&d(b.body,_,f,b.substitutes),m===`Let`&&(t.boundSubstitutions.lets.has(e)||e.definitions.some(e=>ph(e)||`standardDefinition`in e))){let n=t.boundSubstitutions.lets.has(e),r=new Map(p);for(let t of e.definitions)(n||ph(t))&&r.set(t.name,{body:t.body,substitutes:p});for(let t of e.definitions)if(!(n||ph(t))){if(`standardDefinition`in t){d(t.body,_,!0,r);for(let e of $t(t.standardDefinition))d(e,!1,f,void 0)}else for(let e of $t(t))d(e,_,f,r)}d(e.body,_,f,r);return}if(e.kind!==`Let`||!r){let t=ft(e),n=f||m===`Lambda`;for(let e=0;e<t.length;e++)d(t[e],_,n,p);return}let x=s;for(let t of e.definitions){s=r.parents.push(x)-1,r.effects.push(0),r.numbers.set(t,s);for(let e of $t(t))d(e,_,f,p);s=x}d(e.body,_,f,p)};for(let t of e)d(t,!0,!1,void 0);return{row:i,edges:a,replacedReferences:o}},Eh=/[\u0100-\uffff]/,Dh=/* @__PURE__ */ new Set([`JsonDeserialize`,`ndJsonDeserialize`]),Oh=e=>Eh.test(e),kh=e=>Dh.has(e),Ah=(e,t)=>{if(e.kind===`Selection`){if(t.has(e.expression))return!1;t.add(e.expression)}return e.kind===`String`&&Oh(e.value)||e.kind===`Apply`&&kh(e.operator)||ft(e).some(e=>Ah(e,t))},jh=(e,t)=>Ah(e.body,t)||e.kind===`Function`&&e.bounds.some(e=>Ah(e.set,t)),Mh=2,Nh=4,Ph=e=>(e.isLevelCounted?2:0)|(e.isBoundCounted?4:0),Fh=(e,t,n)=>{let r={numbers:/* @__PURE__ */ new Map,parents:[],effects:[]},i=Th(mh(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(Ph),...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:jh(e,/* @__PURE__ */ new Set)}},Ih=(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},Lh=(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},Rh=1294,zh=1286,Bh=(e,t,n,r,i)=>{let a=Th(mh(e,t),t,n,r);for(let e of a.edges)i(e.callee,Ph(e)|+!!e.isOverridden|(e.isSubstitute?8:0),e.owner);return a.row},Vh=(e,t)=>e.kind===`Operator`&&e.params.length===0&&!(t&513),Hh=(e,t)=>{let n=r=>{if(r.kind===`Let`)for(let i of r.definitions){t.set(i,e);for(let e of $t(i))n(e)}for(let e of ft(r))n(e)};for(let t of $t(e))n(t)},Uh=(e,t,n)=>{let r={numbers:/* @__PURE__ */ new Map,parents:[],effects:[]};Th(mh(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},Wh=(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]&gh?2:0),purity:i(t=>e.rows[t]&Rh),effects:i(t=>e.effects[t])}},Gh={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},Kh=(e,t,n=/* @__PURE__ */ new Map,r=Gh,i,a=[])=>{let o=[...new Set(e.definitions.values())],s=r.definitions.length,l=1+(e.variables.length+31>>>5),u=e=>e.every((e,t)=>o[t]===e);if(!u(r.definitions)||s>0&&r.rows.length!==s)throw new c(`base-definitions`,`a file's link changes its base's definitions`);if(i!==void 0&&(!u(i)||l!==1))throw new c(`base-definitions`,`the modules they share declare variables, or their config changes their definitions`);let d=new Map(r.ids);for(let e=0;e<o.length;e++){let t=o[e];e>=s&&d.set(t,e)}let f=Wh(r,l,o.length),p=f.reads,m=f.purity,h={numbers:/* @__PURE__ */ new Map,parents:[],effects:[]},g=new Int32Array(o.length).fill(-1),_=new Int32Array(o.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<o.length;t++){let r=o[t];if(_[t]=v.length,t<s)continue;let i=n.get(r),a=i!==void 0&&i.row.length===l;a&&(g[t]=h.parents.length);let c=a?Ih(i,e,h,x):Bh(r,e,l,h,x);p.set(c,t*l),m[t*l]=c[0]&Rh}_[o.length]=v.length;let S=e=>{let t=new Int32Array(o.length+1),n=[];for(let r=0;r<o.length;r++){t[r]=n.length;for(let t=_[r];t<_[r+1];t++)e(t)&&n.push(v[t])}return t[o.length]=n.length,{starts:t,targets:Int32Array.from(n)}},C=(e,t)=>(e.set(t.subarray(s*l),s*l),e),w=S(e=>!(y[e]&1)),T=Lh(p,l,w,17,s),ee=Lh(C(f.levels,p),l,S(e=>(y[e]&3)==2),224,s),E=Lh(C(f.startup,p),l,S(e=>(y[e]&5)==4),512,s),D=C(f.shown,m),O=e.substitutions.size>0?Lh(D,l,w,zh,s):D,te=Lh(m,l,S(e=>!Vh(o[v[e]],T[v[e]*l]|E[v[e]*l])||!!(y[e]&8)&&!!(O[v[e]*l]&zh)),Rh,s),ne=T.map((e,t)=>t<s*l?t%l===0?r.rows[t/l]:0:t%l===0?e&17|E[t]&512|ee[t]&224|te[t]&Rh|(O[t]&zh?gh:0):e);for(let e=0;e<v.length;e++){if(b[e]===-1)continue;let t=ne[v[e]*l];(!Vh(o[v[e]],t)||y[e]&8&&t&gh)&&(h.effects[b[e]]|=t&Rh)}for(let e=h.parents.length-1;e>=0;e--){let t=h.parents[e];t!==-1&&(h.effects[t]|=h.effects[e])}let re=[],ie=t=>{let n=a.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=(re[r]??=Uh(n,e,l)).indexOf(t);return i===-1?void 0:g[r]+i},k=e=>{let t=h.numbers.get(e)??ie(e);return t===void 0?r.getLetEffects(e):h.effects[t]},ae=Lh(C(f.effects,m),l,w,260,s),oe=t.filter(e=>!r.assumptions.has(e)),se=eg(o,oe,e,{ids:d,effects:ae,rows:ne,words:l},s,i!==void 0),ce=r.varying.hasEffectfulValue||se.hasEffectfulValue;return{ids:d,rows:ne,words:l,getLetEffects:k,isVaryingBody:e=>r.varying.bodies.has(e)||se.bodies.has(e)||ce&&(r.varying.parameterBodies.has(e)||se.parameterBodies.has(e)),isStreamedBody:e=>r.varying.streamedBodies.has(e)||se.streamedBodies.has(e),base:i&&(()=>{let e=i.length;return{definitions:i,ids:new Map(i.map((e,t)=>[e,t])),rows:ne.slice(0,e),effects:ae.slice(0,e),getLetEffects:k,varying:se,assumptions:new Set(t)}})()}},qh=(e,t)=>{let n=t.facts,r=n.ids.get(e);return r===void 0?Jh(mh(e,t),t):n.rows.subarray(r*n.words,(r+1)*n.words)},Jh=(e,t)=>{let n=t.facts.words,r=Th(e,t,n),i=r.row;for(let e of r.edges){let r=qh(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]}Yh(e,r[0])&&(i[0]|=r[0]&Rh)}return i},Yh=(e,t)=>!Vh(e.callee,t)||e.isSubstitute&&!!(t&gh),Xh=(e,t,n=3)=>{let r=0,i=e=>{let n=gn(e);n!==void 0&&(j(e)||e.kind===`OperatorReference`)&&(r|=t.get(n)??0);for(let t of ft(e))i(t)};if(t.size>0)for(let t of e)i(t);return r&n},Zh=(e,t,n)=>n===0?e:new Map([...e,...t.map(e=>[e,n])]),Qh=e=>e.kind!==`Function`&&e.params.length>0,$h=(e,t,n)=>{let r=gn(e);if(r===void 0||e.kind===`Apply`)return!1;if(j(e)||t.has(r))return!!((t.get(r)??0)&4);let i=n.substitutions.get(r)??r,a=n.definitions.get(i);return a===void 0?(n.builtins.get(i)?.arity??0)>0:Qh(a)},eg=(e,t,n,r,i,a)=>{let o=/* @__PURE__ */ new Set,s=/* @__PURE__ */ new Set,c=[],l=!1,u=r.words,d=e=>!!(r.effects[e*u]&260),f=e=>{let t=Th(e,n,u);return!!(t.row[0]&260)||t.edges.some(e=>!e.isOverridden&&d(r.ids.get(e.callee)??-1))},p=e=>{let t=Th(e,n,u);return!!(t.row[0]&8)||t.edges.some(e=>{let t=r.rows[(r.ids.get(e.callee)??-1)*u];return Yh(e,t)&&!!(t&8)})},m=(e,t,n)=>(n&&f(e)?2:0)|Xh(e,t),h=(e,t,n)=>(n&&f(e)?2:0)|(p(e)?8:0)|Xh(e,t,11),g=(e,t,n)=>{l||=n&&!!(m(e,t,!0)&2)},_=(e,t,n,r)=>{let i=Xh(e,n);i&2?o.add(t):i!==0&&c.push(t),g(e,n,r)},v=(e,t,n,r,i)=>{let a=e.map(e=>e.set);for(let e of a)b(e,r,i);let o=n|m(a,r,i);b(t,Zh(r,Be(e),o),i)},y=(e,t,n)=>{if(e.kind!==`Function`){let r=e.params.map(e=>e.name);b(e.body,Zh(t,r,1),n);return}let r=new Map(t).set(e.name,0);_([e.body],e.body,r,n),v(e.bounds,e.body,1,t,n)},b=(e,t,r)=>{if(r&&e.kind===`Apply`)for(let r of e.args)$h(r,t,n)&&g([r],t,!0);switch(e.kind){case`Lambda`:return g([e.body],t,r),b(e.body,Zh(t,e.params,1),r);case`Let`:{let n=e.definitions.some(e=>e.isRecursive),i=n?h(e.definitions.flatMap($t),t,r):0,a;for(let c of e.definitions){let e=n?i:h($t(c),a??t,r);e&2&&c.kind===`Operator`&&o.add(c.body),e&8&&s.add(c.body),e!==0&&(a??=new Map(t),a.set(c.name,Qh(c)?e|4:e))}let c=a??t;for(let t of e.definitions)y(t,c,r);return b(e.body,c,r)}case`FunctionConstruction`:return _([e.body],e.body,t,r),v(e.bounds,e.body,1,t,r);case`Forall`:case`Exists`:return v(e.bounds,e.body,0,t,r);case`SetMap`:return v(e.bounds,e.expression,0,t,r);case`SetFilter`:return _([e.bound.set,e.predicate],e.predicate,t,r),v([e.bound],e.predicate,1,t,r);case`Choose`:return e.set?v([{pattern:e.pattern,set:e.set}],e.body,0,t,r):b(e.body,t,r);default:for(let n of ft(e))b(n,t,r);return}},x=e=>!!(r.rows[e*u]&8),S=(e,t)=>{n.bodyValues.has(e.body)||y(e,/* @__PURE__ */ new Map,t)},C=e.slice(i);for(let e=0;e<C.length;e++){let t=C[e];d(i+e)&&S(t,!0)}for(let e of t)b(e,/* @__PURE__ */ new Map,f([e]));let w=l||a;for(let e=0;e<C.length;e++){let t=C[e],n=i+e;d(n)||(w||x(n))&&S(t,!1)}return{bodies:o,parameterBodies:new Set(c),hasEffectfulValue:l,streamedBodies:s}},tg=(e,t)=>!(qh(e,t)[0]&513),ng=(e,t)=>!(qh(e,t)[0]&512),rg=(e,t)=>!!(qh(e,t)[0]&2561),ig={any:2,repeated:4,streamed:8,replayed:260,varying:260,reevaluated:258},ag=(e,t,n)=>(Jh(e,t)[0]&ig[n])!==0,og=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},sg=(e,t,n)=>n.facts.isVaryingBody(t)||ag(e,n,`varying`),cg=(e,t,n=`any`)=>((t.facts.getLetEffects(e)??qh(e,t)[0])&ig[n])!==0,lg=(e,t)=>t.facts.isVaryingBody(e.body)||cg(e,t,`varying`),ug=(e,t)=>t.facts.isStreamedBody(e.body)||cg(e,t,`streamed`),dg=(e,t)=>!!(Jh([e],t)[0]&hh),fg=(e,t)=>{let n=qh(e,t)[0]&224;return n===224?3:n===96?2:+(n===32)},pg=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},mg=(e,t)=>{let n=Jh([e],t);return n[0]&16?void 0:pg(n)},hg=(e,t)=>!!(Jh([e],t)[0]&1),gg=(e,t)=>(Jh([e],t)[0]&96)==96,_g=e=>({expression:e,evaluator:void 0,tail:void 0}),vg=/* @__PURE__ */ new Set([`SUBSET`,`UNION`,`DOMAIN`,`\\cup`,`\\cap`,`\\`]),yg=/* @__PURE__ */ new Set([`SetEnumeration`,`SetFilter`,`SetMap`,`Tuple`,`FunctionSet`,`Record`,`RecordSet`,`Product`]),bg=e=>yg.has(e.kind)||e.kind===`Apply`&&vg.has(e.operator),xg=(e,t)=>{if(e.kind===`FunctionApplication`){let n=t.get(e.function);return n!==void 0&&Er(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&&Tr(n)?e.args[0]:e.args[1]}return e.operator===`\\in`||e.operator===`\\notin`?e.args[1]:void 0}},Sg=(e,t)=>{let n=Array(e.length);for(let r=0;r<e.length;r++)n[r]=e[r](t);return n},Cg={Always:`[]A`,Eventually:`<>A`,WeakFairness:`WF`,StrongFairness:`SF`},wg=(e,t)=>new n(`TLC encountered a temporal formula (${e}) when evaluating a predicate or action.\n${M(t)}`),Tg=(e,t)=>new n(`A non-boolean expression (${Em(t)}) was used as the condition of an IF.\n${M(e)}`),Eg=(e,t,r)=>{let i=e.location.range;if(i?.start.line===e.location.line&&i.start.column===e.location.column||!i)return new n(`A non-boolean expression (${Em(r)}) was used as a formula in a ${e.kind===`And`?`conjunction`:`disjunction`}.\n${Hn(e.operands[t])}`);let a=e.prefixEnds?.[Math.max(t,1)-1]??i.end;return new n(`Attempted to evaluate an expression of form P ${e.kind===`And`?`/\\`:`\\/`} Q when ${t===0?`P`:`Q`} was\n${Em(r)}.\n${M({...e,location:{...e.location,range:{...i,end:a}}})}`)},Dg=e=>{let t=e.field,r=n=>`Attempted to select nonexistent field "${t}" from the record\n${N(U(n))}\n${M(e)}`,i=e=>`Attempted to apply function:\n${N(U(e))}\nto argument "${t}", 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 n=0;n<e.length;n++)if(e[n]===t)return a.range[n]}if(!Er(a))throw new n(`Attempted to select field "${t}" from a non-record value ${N(U(a))}\n${M(e)}`);let o=Hi(a);if(o===`tuple`)throw da(a),lu(t);return Du(a.kind===`LazyFunction`?V(a):a,t,o===`record`?r:i)}},Og=e=>e===`1.7.4`?(t,n)=>ou(t,n,e):void 0,kg=e=>t=>{if(!Er(t))throw new n(`Attempted to apply the operator DOMAIN to a non-function\n(${Em(t)})\n${M(e)}`);return Au(t)},Ag=(e,t)=>(r,i)=>{if(!I(r))throw new n(`Attempted to evaluate an expression of form S \\subseteq T, but S was not enumerable.\n${M(e)}`);return t(r,i)},jg=e=>o(new n(`TLC can't handle real numbers.\n${e.text}`),i.configParseError),Mg=e=>o(new n(`TLC can't handle a number this big.\n${e.text??e.value}`),i.error),Ng=(e,t)=>new n(`In evaluation, the identifier ${je(e)} is either undefined or not an operator.\n${M(t)}`),Pg=(e,t)=>new O(`In evaluation, the identifier ${je(e)} is either undefined or not an operator.\n${M(t)}`,e),Fg=(e,t)=>e instanceof O&&t!==`1.7.4`?new n(`The action formula A appearing in a WF_v(A) or SF_v(A) operator does not specify the primed value of the variable ${je(e.variable)} occurring in the state formula v.\n`):e,Ig=(e,t)=>{for(let n=e;n;n=n.parent)if(n.name===t)return n.binding},Lg=(e,t)=>{let n=Ig(t,e.operator);return n?.kind===`Operator`&&n.operator.kind===`Closure`?n.operator:void 0},Rg=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n,argument:void 0,isSelf:!1},parent:e}),zg=(e,t,n)=>({name:t,binding:{kind:`Value`,value:n,argument:void 0,isSelf:!0},parent:e}),Bg=e=>{let t=e.ranges?.[0];return`Argument mismatch in operator application.${t?b(t):``}`},Vg=(e,t)=>`Attempted to check if the value:\n${N(U(t))}\nis an element of a set of ${e.names.length}-tuples.`,Hg=(e,t,r,i=Bg)=>{if(t.kind===`Name`)return Rg(e,t.name,r);let a=pl(r);if(!a||a.length!==t.names.length)throw new n(i(t,r));return t.names.reduce((e,t,n)=>Rg(e,t,a[n]),e)},Ug=(e,t)=>{if(Er(e))return e;throw new n(`A non-function (${Em(e)}) was applied as a function.\n${M(t)}`)},Wg=e=>e.isKeepLazy?e:{environment:e.environment,scope:e.scope,state:e.state,next:e.next,isKeepLazy:!0,isPrimed:e.isPrimed},Gg=(e,t)=>({environment:e.environment,scope:t,state:e.state,next:e.next,isKeepLazy:e.isKeepLazy,isPrimed:e.isPrimed}),Kg=(e,t)=>{if(typeof e!=`boolean`)throw new n(`Expected ${t} to be a boolean but found ${U(e)}`);return e},qg=(e,t,r)=>{if(typeof e!=`boolean`)throw new n(`Attempted to evaluate an expression of form P => Q when ${r} was\n${Em(e)}.\n${M(t)}`);return e},Jg=(e,t)=>{if(typeof e!=`boolean`)throw new n(`Attempted to apply the operator ~ to a non-boolean\n(${Em(e)})\n${M(t)}`);return!e},Yg=(e,t,r)=>{if(typeof e!=`boolean`||typeof t!=`boolean`)throw new n(`Attempted to evaluate an expression of form P <=> Q when P or Q was not a boolean.\n${M(r)}`);return e===t},Xg=(e,t)=>{if(typeof e!=`boolean`)throw new n(`TLC expected a boolean value, but did not find one. ${Hn(t)}`);return e},Zg=e=>e.properties.get(`tlc2.tool.impl.Tool.cdot`)?.toLowerCase()===`true`,Qg=(e,t)=>t.definitions.get(t.substitutions.get(e)??e),$g=(e,t)=>{if(t.constants.has(e))return;let n=Qg(e,t);return n?.kind===`Operator`&&n.params.length===0?n:void 0},e_=(e,t,n=/* @__PURE__ */ new Set,r=e)=>{if(e.kind===`Tuple`){let r=e.elements.map(e=>e_(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=$g(e.name,t);if(a)return n.add(e.name),e_(a.body,t,n,r)},t_=(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(!to(i,a))return!1}return!0}},n_=(e,t)=>t.filter((t,n)=>e[n]===void 0).sort(),r_=(e,t)=>t.builtins.get(t.substitutions.get(e)??e),i_=(e,t)=>r_(e,t)?.name??e,a_=(e,t)=>t.theorems.has(e)?void 0:Qg(e,t),o_=(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.`},s_=(e,t,r)=>{if(!wr(e)||hi(e)){let i=U(e),a=r===`1.7.4`?void 0:o_(e,i);throw new n(a===void 0?`TLC encountered a non-enumerable quantifier bound\n${i}.\n${Hn(t)}`:`TLC encountered the non-enumerable quantifier bound\n${i}\n${Hn(t)}\n${a}`)}},c_=(e,t,n,r=!0)=>(s_(e,t,n),typeof e==`object`&&e.kind===`Interval`?Po(e):Qo(e)??zc(e,r)),l_=(e,t,n)=>n===`1.7.4`?(s_(e,t,n),Qo(e)??Uc(e)):c_(e,t,n),u_=e=>{if(typeof e==`object`&&e.kind===`Interval`)return R(e),e},d_=(e,t,n)=>u_(e)??l_(e,t,n),f_=(e,t,n,r=!0)=>u_(e)??c_(e,t,n,r),p_=(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},m_=e=>Array.isArray(e)?e.length:il(e.low,e.high),h_=(e,t)=>Array.isArray(e)?e[t]:e.low+t,g_=(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),[]),__=(e,t)=>g_(e,e=>d_(q(e,t),e,t.environment.runtime.version)),v_=(e,t,n,r)=>{let i=(n,a)=>n<0?r(a):p_(t[n],t=>i(n-1,Hg(a,e[n].pattern,t)));return i(e.length-1,n)},y_=(e,t,n)=>v_(e,__(e,t),t.scope,n),b_=(e,t,n,r)=>g_(e,e=>{let i=q(e,t);return zp(n,i,r!==`1.7.4`,()=>d_(i,e,r))}),x_=(e,t,n,r)=>{let i=b_(e,t,n,t.environment.runtime.version),a=Vp(n,i),o=i.map(e=>e.elements);return v_(e,o,t.scope,e=>(a(),r(e)))},S_=(e,t)=>{let n=g_(e,e=>q(e,t));return n.length===1?n[0]:zs(n,void 0)},C_=(e,t,n)=>{if(e.length===1)return Hg(t,e[0].pattern,n);let r=pl(n)??[];return e.reduce((e,t,n)=>Hg(e,t.pattern,r[n]),t)},w_=e=>typeof e==`object`&&e.kind===`LazyFunction`&&`lambda`in e,T_=e=>Object.assign(e.value,{lambda:e}),E_=e=>w_(e)&&e.enumerated===void 0?e.lambda:void 0,D_=e=>({kind:`Tuple`,elements:e.args,location:e.location}),O_=(e,t,r,i)=>{let a=e.value,o=(e,n,r)=>`In applying the function\n${N(U(a))},\nthe ${e} is:\n${N(U(n))}${r}.\n${M(t.function)}`,s=e.bounds;if(s.length===1){if(!i(r,a.domain))throw new n(o(`first argument`,r,`which is not in its domain`));return C_(s,e.scope,r)}let c=pl(r),l=typeof a.domain==`object`&&a.domain.kind===`ProductSet`?a.domain.factors:[];if(c===void 0)throw new n(`Attempted to apply a function to an argument not in its domain.\n${M(t.function)}`);let u=()=>new n(`In applying the function\n${N(U(a))},\nthe argument list is:\n${N(U(r))}\nwhich does not match its formal parameter.\n`),d=c;for(let e=0;e<s.length;e++){let t=s[e].pattern;if(e>=c.length)throw u();let r=c[e],a=`argument number ${e+1}`;if(!i(r,l[e]))throw new n(o(a,r,`${t.kind===`Name`?``:`
|