@mathzetta/inlinemath 0.3.0 → 0.4.0

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.
@@ -1,2 +0,0 @@
1
- /* Inline Math 0.3.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
2
- import{j as t,k as n,m as e,h as r,o,q as i,r as a}from"./lite-Bo8THzyq.js";function s(t){return Array.isArray(t)&&t.length>0&&t.every(n=>Array.isArray(n)&&n.length>0&&n.length===t[0].length&&!n.some(Array.isArray))}const u=t=>Array.isArray(t)&&t.length>0&&!t.some(Array.isArray);function c(t){const n=t,e=n.make??(t=>t),r=n.size??(()=>1),o=n.charge??(()=>{}),i=t=>`${t.length} by ${t[0].length}`,a=(t,r)=>e(Array.from({length:t},(e,r)=>Array.from({length:t},(t,e)=>r===e?n.one():n.zero())),r);function u(t,r){return t[0].length!==r.length&&n.fail(`a ${i(t)} matrix times a ${i(r)} one`),o(t.length*r.length*r[0].length),e(t.map(t=>r[0].map((e,o)=>t.reduce((t,e,i)=>n.add(t,n.mul(e,r[i][o])),n.zero()))),t)}function c(t){const e=t.map(t=>t.slice()),i=e.length,a=e[0].length;o(i*i*a);let s=n.one(),u=0;for(let t=0;t<a&&u<i;t++){let o=-1;for(let a=u;a<i;a++)n.isZero(e[a][t])||(o<0||r(e[a][t])>r(e[o][t]))&&(o=a);if(o<0){s=n.zero();continue}o!==u&&([e[o],e[u]]=[e[u],e[o]],s=n.sub(n.zero(),s));const a=e[u][t];s=n.mul(s,a),e[u]=e[u].map(t=>n.div(t,a));for(let r=0;r<i;r++){if(r===u||n.isZero(e[r][t]))continue;const o=e[r][t];e[r]=e[r].map((t,r)=>n.sub(t,n.mul(o,e[u][r])))}u++}return u<i&&(s=n.zero()),{M:e,det:s,rank:u}}function l(t){const r=t.length;r!==t[0].length&&n.fail(`a ${i(t)} matrix has no inverse`);const o=a(r),{M:s,rank:u}=c(t.map((t,n)=>[...t,...o[n]]));return(u<r||s.some((t,e)=>n.isZero(t[e])))&&n.fail("the matrix has no inverse (its determinant is 0)"),e(s.map(t=>t.slice(r)),t)}return{identity:a,transpose:t=>e(t[0].map((n,e)=>t.map(t=>t[e])),t),times:u,det:function(t){return t.length!==t[0].length&&n.fail(`a ${i(t)} matrix has no determinant`),c(t).det},inverse:l,power:function(t,e){t.length!==t[0].length&&n.fail(`a ${i(t)} matrix has no powers`);let r=e<0n?l(t):t,o=e<0n?-e:e,s=a(t.length,t);for(;o>0n;)1n&o&&(s=u(s,r)),r=u(r,r),o>>=1n;return s},trace:t=>(t.length!==t[0].length&&n.fail(`a ${i(t)} matrix has no trace`),t.reduce((t,e,r)=>n.add(t,e[r]),n.zero())),dot:(t,e)=>(t.length!==e.length&&n.fail("vectors of different lengths"),t.reduce((t,r,o)=>n.add(t,n.mul(r,e[o])),n.zero())),cross:(t,e)=>(3===t.length&&3===e.length||n.fail("the cross product is for vectors of 3 numbers"),[n.sub(n.mul(t[1],e[2]),n.mul(t[2],e[1])),n.sub(n.mul(t[2],e[0]),n.mul(t[0],e[2])),n.sub(n.mul(t[0],e[1]),n.mul(t[1],e[0]))]),solve:function(t,n){return s(n)?u(l(t),n):u(l(t),n.map(t=>[t])).map(t=>t[0])},rank:t=>c(t).rank,rref:t=>e(c(t).M,t),timesVector:(t,n)=>u(t,n.map(t=>[t])).map(t=>t[0]),vectorTimes:(t,n)=>u([t],n)[0]}}const l=c({add:(t,n)=>t+n,sub:(t,n)=>t-n,mul:(t,n)=>t*n,div:(t,n)=>t/n,isZero:t=>Math.abs(t)<1e-12,zero:()=>0,one:()=>1,size:Math.abs,charge:t=>{if(F+=t/16,F>$)throw new Error("Too much to work out")},fail:t=>{throw new Error(t)}}),f=t=>s(t)&&(t.length>1||t[0].length>1),h=t=>u(t)&&!f(t),m=t=>{const n=(e,r)=>{if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)throw new Error("Lists of different lengths");return e.map((t,e)=>n(t,r[e]))}return Array.isArray(e)?e.map(t=>n(t,r)):Array.isArray(r)?r.map(t=>n(e,t)):t(e,r)};return n},g=(t,n)=>f(t)&&f(n)?l.times(t,n):f(t)&&h(n)?l.timesVector(t,n):h(t)&&f(n)?l.vectorTimes(t,n):m((t,n)=>t*n)(t,n),p=(t,n)=>e=>{const r=e.length>1&&e.every(h)?e:e[0];if(!s(r))throw new Error(`${n}() needs a matrix`);return t(r)},d=(t,n)=>([e,r])=>{if(!u(e)||!u(r))throw new Error(`${n}() needs two lists`);return t(e,r)},b={det:p(l.det,"det"),inv:p(l.inverse,"inv"),inverse:p(l.inverse,"inverse"),transpose:p(l.transpose,"transpose"),trace:p(l.trace,"trace"),tr:p(l.trace,"tr"),rank:p(l.rank,"rank"),rref:p(l.rref,"rref"),identity:([t])=>{if(!Number.isInteger(t)||t<1||t>100)throw new Error("identity(n) takes a whole number from 1 to 100");return l.identity(t)},dot:d(l.dot,"dot"),cross:d(l.cross,"cross"),linsolve:([t,n])=>{if(!s(t)||!Array.isArray(n))throw new Error("linsolve() needs a matrix and a list");return l.solve(t,n)}},w=(t,n)=>t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args.map(t=>k(t,n)):[k(t,n)]),M={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},y=(t,n)=>n?y(n,t%n):Math.abs(t),v=(t,n)=>(t%n+n)%n,x=(t,n)=>Array.isArray(t)&&Array.isArray(n)?t.length===n.length&&t.every((t,e)=>x(t,n[e])):t==n,N={neg:t=>-t,pm:t=>[t,-t],"!":t=>{if(!Number.isInteger(t)||t<0)return NaN;if(t>170)return 1/0;let n=1;for(let e=2;e<=t;e++)n*=e;return n},"\\not":t=>!t,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,det:t=>b.det([t]),ln:Math.log,loglog:t=>Math.log(Math.log(t)),logloglog:t=>Math.log(Math.log(Math.log(t))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:t=>1/Math.sin(t),sec:t=>1/Math.cos(t),cot:t=>1/Math.tan(t),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},I={"+":(t,n)=>Array.isArray(t)||Array.isArray(n)?m((t,n)=>t+n)(t,n):t+n,"-":(t,n)=>Array.isArray(t)||Array.isArray(n)?m((t,n)=>t-n)(t,n):t-n,"*":g,"/":(t,n)=>f(n)?g(t,l.inverse(n)):Array.isArray(t)||Array.isArray(n)?m((t,n)=>t/n)(t,n):t/n,"^":(t,n)=>{if(!f(t))return Array.isArray(t)?m((t,n)=>t**n)(t,n):t**n;if(!Number.isInteger(n))throw new Error("A matrix to a power that is not a whole number");return l.power(t,BigInt(n))},mod:v,log:(t,n)=>Math.log(n)/Math.log(t),root:(t,n)=>n<0&&Number.isInteger(t)&&t%2!=0?-((-n)**(1/t)):n**(1/t),atan2:Math.atan2,round:(t,n)=>(t=>Math.sign(t)*Math.round(Math.abs(t)))(t*10**n)/10**n,"±":(t,n)=>[t+n,t-n],fixed:(t,n)=>{const e=Math.trunc(n);if(!(e>=0&&e<=100))throw new Error("fixed() takes 0 to 100 decimals");return Number(t).toFixed(e)},perm:(t,n)=>{if(!Number.isInteger(t)||!Number.isInteger(n)||n<0||n>t)return NaN;let e=1;for(let r=t-n+1;r<=t&&e!==1/0;r++)e*=r;return e},comb:(t,n)=>{if(!Number.isInteger(t)||!Number.isInteger(n)||n<0||n>t)return NaN;n=Math.min(n,t-n);let e=1;for(let r=1;r<=n&&e!==1/0;r++)e=e*(t-n+r)/r;return Math.round(e)},"=":x,"===":(t,n)=>t===n,"≠":(t,n)=>!x(t,n),"≠=":(t,n)=>t!==n,"≈":(t,n)=>Math.abs(t-n)<1e-9,"≡":(t,n)=>t===n,"∪":(t,n)=>[...new Set([...[].concat(t),...[].concat(n)])],"∩":(t,n)=>[].concat(t).filter(t=>[].concat(n).includes(t)),"<":(t,n)=>t<n,">":(t,n)=>t>n,"≤":(t,n)=>t<=n,"≥":(t,n)=>t>=n,"&":(t,n)=>t&&n,"|":(t,n)=>t||n,"\\xor":(t,n)=>Boolean(t)!==Boolean(n),"\\nor":(t,n)=>!(t||n),"\\nand":(t,n)=>!(t&&n)},A={max:t=>Math.max(...t),min:t=>Math.min(...t),sum:t=>t.reduce((t,n)=>t+n,0),prod:t=>t.reduce((t,n)=>t*n,1),mean:t=>t.reduce((t,n)=>t+n,0)/t.length,gcd:t=>t.reduce(y,0),"()":t=>t,"[]":t=>t,"{}":t=>t};const $=5e6;let F=0,B=0;function k(t,o){if(++F>$)throw new Error("Too much to work out");switch(t.type){case"number":return Number(t.value);case"string":return t.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(o,t.value))return o[t.value];if(Object.prototype.hasOwnProperty.call(M,t.value))return M[t.value];if(n(t.value))return Number(n(t.value));throw new Error(`No value for '${t.value}'`)}const i=e(t);if(i)return k(i,o);const{op:a,args:s}=t;if("?:"===a)return k(s[0],o)?k(s[1],o):k(s[2],o);if("∈"===a||"∉"===a)return function(t,n){const[e,r]=t.args,o=k(e,n);let i;if("symbol"===r.type&&O[r.value])return i=O[r.value](o),"∈"===t.op?i:!i;if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,e]=r.args.map(t=>k(t,n)),a="["===r.op[0]?o>=t:o>t,s="]"===r.op[1]?o<=e:o<e;i=a&&s}else{const t=k(r,n);i=Array.isArray(t)&&t.includes(o)}return"∈"===t.op?i:!i}(t,o);if("random"===a)return Math.random();if(("\\sumidx"===a||"\\prodidx"===a)&&3===s.length){const t="op"===s[1].type&&"="===s[1].op&&"symbol"===s[1].args[0].type,[n,e,i]=[s[0],t?s[1].args[1]:s[1],s[2]],u=t?s[1].args[0].value:r(n);if(!u)throw new Error(`Can't evaluate '${a}' without an index`);const c=k(e,o),l=k(i,o);if(!Number.isFinite(c)||!Number.isFinite(l)||l-c>1e6||Math.abs(c)>Number.MAX_SAFE_INTEGER||Math.abs(l)>Number.MAX_SAFE_INTEGER)throw new Error(`Can't evaluate '${a}' over that range`);let f="\\sumidx"===a?0:1;for(let t=c;t<=l;t++){const e=k(n,{...o,[u]:t});f="\\sumidx"===a?f+e:f*e}return f}if("pmod"===a){const[t,n]=s,e=k(n,o);if("op"===t.type&&["≡","="].includes(t.op)){const[n,r]=t.args.map(t=>k(t,o));return(n-r)%e===0}return v(k(t,o),e)}if("pmatrix"===a||"bmatrix"===a)return w(t,o);if("vmatrix"===a)return l.det(w(t,o));if("^"===a&&"symbol"===s[1].type&&"T"===s[1].value&&!Object.prototype.hasOwnProperty.call(o,"T")){const t=k(s[0],o);if(f(t))return l.transpose(t)}const u=s.map(t=>k(t,o));if(a.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(b,a.slice(2)))return b[a.slice(2)](u);if(N[a]&&1===u.length)return N[a](u[0]);if(I[a]&&2===u.length)return I[a](u[0],u[1]);if(A[a])return A[a](u);throw new Error(`Can't evaluate '${a}'`)}const O={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":t=>Number.isInteger(t)&&t>0,"ℚ":Number.isFinite,"ℂ":t=>"number"==typeof t&&!Number.isNaN(t)};for(const t of[M,N,I,A,O,b])Object.setPrototypeOf(t,null);class S extends Error{}class E extends Error{}const P={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let j=0;function z(t){if(j+=t,j>P.steps)throw new E("too much to work out")}const T=(t,n)=>z(Number(t)*(n/64)/128);let _=0;const W=t=>t<0n?-t:t,q=0xFFFFFFFFFFFFn,Z=t=>0n===t?0:W(t).toString(2).length;function C(t,n){for(t=W(t),n=W(n);n;)[t,n]=[n,t%n];return t}function D(t,n=1n){if(0n===n)throw new S("division by zero");if(n<0n&&(t=-t,n=-n),n>q&&(t>q||-t>q)){const e=Math.min(t.toString(16).length-(t<0n?1:0),n.toString(16).length)/16;if(j+=1+e*e/2,j>P.steps)throw new E("too much to work out")}const e=C(t,n)||1n;return{n:t/e,d:n/e}}const G=D(0n),L=D(1n),R=(t,n)=>D(t.n*n.d+n.n*t.d,t.d*n.d),V=(t,n)=>D(t.n*n.n,t.d*n.d),X=(t,n)=>D(t.n*n.d,t.d*n.n),J=t=>({n:-t.n,d:t.d}),H=(t,n)=>{const e=t.n*n.d-n.n*t.d;return e<0n?-1:e>0n?1:0},K=t=>{const n=t.n/t.d;return t.n<0n&&n*t.d!==t.n?n-1n:n};function Q(t){if(t.n<0n)return-Q(J(t));const n=Z(t.n),e=Z(t.d);if(n<1e3&&e<1e3)return Number(t.n)/Number(t.d);const r=BigInt(Math.max(n,e)-1e3),o=t.d>>r;return 0n===o?t.n<0n?-1/0:1/0:Number(t.n>>r)/Number(o)}function U(t){let n=String(t).trim(),e=1n;n.startsWith("-")&&(e=-1n,n=n.slice(1));const r=n.endsWith("..");r&&(n=n.slice(0,-2));let o=0;const i=n.search(/e/i);i>=0&&(o=Number(n.slice(i+1)),n=n.slice(0,i));const[a="",s=""]=n.split(".");if(!(/^\d*$/.test(a)&&/^\d*$/.test(s)&&a+s))throw new E(`'${t}' is not a number`);let u;if(r&&s){let t=1;for(let n=1;2*n<=s.length;n++)if(s.slice(-n)===s.slice(-2*n,-n)){t=n;break}const n=s.slice(-t);let e=s;for(;e.endsWith(n);)e=e.slice(0,-t);const r=BigInt(e||"0"),o=BigInt(e+n);u=R(D(BigInt(a||"0")),D(o-r,(10n**BigInt(t)-1n)*10n**BigInt(e.length)))}else u=D(BigInt(a+s||"0"),10n**BigInt(s.length));if(Math.abs(o)>P.bits/3)throw new E("too large to calculate");return o&&(u=o>0?V(u,D(10n**BigInt(o))):X(u,D(10n**BigInt(-o)))),e<0n?J(u):u}function Y(t,n=0,e=0,r=null){return 0n===t.n?{kind:"x",c:G,pi:0,e:0,root:null}:{kind:"x",c:t,pi:n,e:e,root:r}}const tt=(t,n=1n)=>Y(D(BigInt(t),BigInt(n))),nt=Y(L,1),et=Y(L,0,1),rt=t=>null!==t&&"object"==typeof t&&"x"===t.kind,ot=t=>rt(t)&&!t.pi&&!t.e&&!t.root,it=t=>rt(t)?0n===t.c.n:0===t,at=t=>ot(t)&&1n===t.c.d?t.c.n:null,st=(t,n)=>Object.assign(t,{group:n}),ut=t=>({kind:"s",text:t});function ct(t,n){return t&&n?t.n===n.n&&t.r===n.r:t===n}const lt=(t,n)=>0===H(t.c,n.c)&&t.pi===n.pi&&t.e===n.e&&ct(t.root,n.root);function ft(t){const n=Math.max(0,Z(t)-60);return n+Math.log2(Number(t>>BigInt(n)))}function ht(t){if("number"==typeof t)return t;if(rt(t)){let n=Q(t.c);if(t.pi&&(n*=Math.PI**t.pi),t.e&&(n*=Math.E**t.e),t.root){const e=function(t,n){const e=Number(t);return Number.isFinite(e)?e**(1/n):2**(ft(t)/n)}(t.root.r,t.root.n);if(!(0n===t.c.n||0!==n&&Number.isFinite(n)&&Number.isFinite(e))){const n=ft(t.c.n<0n?-t.c.n:t.c.n)-ft(t.c.d)+ft(t.root.r)/t.root.n+t.pi*Math.log2(Math.PI)+t.e*Math.LOG2E;return(t.c.n<0n?-1:1)*2**n}n*=e}return n}if("boolean"==typeof t)return t?1:0;throw new E("not a number")}function mt(t,...n){if(Number.isNaN(t))throw new S("undefined");if(!Number.isFinite(t)&&n.every(Number.isFinite))throw new E("too large to calculate");return t}const gt=t=>"boolean"==typeof t?t:rt(t)?0n!==t.c.n:"number"==typeof t?0!==t:Boolean(t);function pt(t){if("bigint"==typeof t)return Y(D(t));if("number"==typeof t)return Number.isFinite(t)?Y(Number.isInteger(t)&&Math.abs(t)<=Number.MAX_SAFE_INTEGER?D(BigInt(t)):U(String(t))):t;if("boolean"==typeof t)return t;if("string"==typeof t)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(t.trim())?Y(U(t)):fn(o(t),{});if(Array.isArray(t))return!t.group&&s(t)?st(t.map(t=>st(t.map(pt),"[]")),"[]"):st(t.map(pt),t.group||"()");if(rt(t)||"function"==typeof t)return t;throw new E(`can't use ${typeof t} as a value`)}function dt(t){return Array.isArray(t)?t.map(dt):t&&"s"===t.kind?t.text:"boolean"==typeof t?t:ht(t)}function bt(t,n){if(t<2n)return t;const e=BigInt(n);let r=1n<<BigInt(Math.ceil(Z(t)/n));for(;;){const n=((e-1n)*r+t/r**(e-1n))/e;if(n>=r)return r;r=n}}function wt(t,n,e,r=0,o=0){if(0n===e)return Y(G);const{coef:i,root:a}=function(t,n){let e=1n,r=n;const o=BigInt(t),i=r<10n**24n?1000000n:10000n;let a=0;for(let t=2n;t<=i&&t*t<=r;t+=2n===t?1n:2n){const n=t**o;for(;r%n===0n;)r/=n,e*=t;a++}j+=a/4;const s=bt(r,t);if(s**o===r&&(e*=s,r=1n),1n===r)return{coef:e,root:null};for(let n=t;n>=2;n--){if(t%n!==0)continue;const o=bt(r,n);if(o**BigInt(n)===r)return{coef:e,root:{n:t/n,r:o}}}return{coef:e,root:{n:t,r:r}}}(n,e);return a&&1===a.n?Y(V(t,D(i*a.r)),r,o):Y(V(t,D(i)),r,o,a)}function Mt(t,n){const e=V(t.c,n.c);if(Z(e.n)+Z(e.d)>P.bits)return null;const r=t.pi+n.pi,o=t.e+n.e;if(!t.root||!n.root)return Y(e,r,o,t.root||n.root);const i=Jt(t.root.n,n.root.n);if(i>P.rootIndex)return null;const a=t.root.r**BigInt(i/t.root.n)*n.root.r**BigInt(i/n.root.n);return Z(a)>4e3?null:wt(e,i,a,r,o)}function yt(t){if(0n===t.c.n)throw new S("division by zero");const n=Y(X(L,t.c),-t.pi,-t.e);if(!t.root)return n;const{n:e,r:r}=t.root;return Z(r)*(e-1)>4e3?null:Mt(n,wt(D(1n,r),e,r**BigInt(e-1)))}function vt(t,n){if(0n===n){if(0n===t.c.n)throw new S("0^0 is undefined");return Y(L)}if(n<0n){const e=yt(t);return e&&vt(e,-n)}if((Z(t.c.n)+Z(t.c.d)+(t.root?Z(t.root.r):0))*Number(n)>P.bits||n>100000n)return null;const e=D(t.c.n**n,t.c.d**n),r=Number(n);if(!t.root)return Y(e,t.pi*r,t.e*r);const{n:o,r:i}=t.root,a=i**(n/BigInt(o));return wt(V(e,D(a)),o,i**(n%BigInt(o))||1n,t.pi*r,t.e*r)}function xt(t,n,e){if(!ot(t)||e>1000n)return null;const r=vt(t,n);if(!r)return null;let{n:o,d:i}=r.c,a=!1;if(o<0n){if(e%2n==0n)throw new S("not a real number");a=!0,o=-o}const s=function(t,n){const e=t.n*t.d**BigInt(n-1);return Z(e)>4e3?null:wt(D(1n,t.d),n,e)}({n:o,d:i},Number(e));return s?a?Y(J(s.c),s.pi,s.e,s.root):s:null}function Nt(t){return n=>Array.isArray(n)?st(n.map(n=>Nt(t)(n)),n.group):t(n)}function It(t){const n=(e,r)=>{const o=Array.isArray(e),i=Array.isArray(r);if(o&&i){if(e.length!==r.length)throw new S("lists of different lengths");return st(e.map((t,e)=>n(t,r[e])),e.group)}return o?st(e.map(t=>n(t,r)),e.group):i?st(r.map(t=>n(e,t)),r.group):t(e,r)};return n}const At=It((t,n)=>rt(t)&&rt(n)&&function(t,n){if(0n===t.c.n)return n;if(0n===n.c.n)return t;if(t.pi!==n.pi||t.e!==n.e||!ct(t.root,n.root))return null;const e=R(t.c,n.c);return Z(e.n)+Z(e.d)>P.bits?null:Y(e,t.pi,t.e,t.root)}(t,n)||mt(ht(t)+ht(n),ht(t),ht(n))),$t=Nt(t=>rt(t)?Y(J(t.c),t.pi,t.e,t.root):-ht(t)),Ft=(t,n)=>At(t,$t(n)),Bt=It((t,n)=>rt(t)&&rt(n)&&Mt(t,n)||mt(ht(t)*ht(n),ht(t),ht(n))),kt=It((t,n)=>{if(it(n))throw new S("division by zero");if(rt(t)&&rt(n)){const e=yt(n),r=e&&Mt(t,e);if(r)return r}return mt(ht(t)/ht(n),ht(t),ht(n))}),Ot=It((t,n)=>{if(rt(t)&&ot(n)){const{n:e,d:r}=n.c,o=1n===r?vt(t,e):xt(t,e,r);if(o)return o}const e=ht(t),r=ht(n);if(0===e&&0===r)throw new S("0^0 is undefined");if(0===e&&r<0)throw new S("division by zero");if(e<0&&!Number.isInteger(r))throw new S("not a real number");const o=e**r;if(0===o&&0!==e)throw new E("too small to calculate");return mt(o,e,r)});function St(t,n){if(ot(t)&&ot(n))return H(t.c,n.c);if(rt(t)&&rt(n)&&lt(t,n))return 0;const e=ht(t),r=ht(n);if(e===r)return 0;const o=rt(t)&&rt(n)?Math.max(Math.abs(e),Math.abs(r)):Math.max(1,Math.abs(e),Math.abs(r));return Number.isFinite(e)&&Number.isFinite(r)&&Math.abs(e-r)<=1e-12*o?0:e<r?-1:1}function Et(t,n){return Array.isArray(t)||Array.isArray(n)?Array.isArray(t)&&Array.isArray(n)&&t.length===n.length&&t.every((t,e)=>Et(t,n[e])):t&&"s"===t.kind||n&&"s"===n.kind?Boolean(t&&"s"===t.kind&&n&&"s"===n.kind&&t.text===n.text):"boolean"==typeof t||"boolean"==typeof n?t===n:0===St(t,n)}const Pt={0:()=>tt(0),2:()=>tt(1,2),3:()=>wt(D(1n,2n),2,2n),4:()=>wt(D(1n,2n),2,3n),6:()=>tt(1)};function jt(t){t=(t%24+24)%24;const[n,e]=t<=6?[t,1]:t<=12?[12-t,1]:t<=18?[t-12,-1]:[24-t,-1],r=Pt[n];return r?e<0?$t(r()):r():null}const zt=t=>jt(t+6),Tt=(t,n)=>Math.abs(t)<1e-15&&Math.abs(n)>1e-6?0:t;function _t(t,n){const e=function(t){if(it(t))return 0;if(!rt(t)||1!==t.pi||t.e||t.root)return null;const n=V(t.c,D(12n));return 1n!==n.d?null:Number((n.n%24n+24n)%24n)}(n);if(null!==e){const n=jt(e),r=zt(e);if(n&&r)switch(t){case"sin":return n;case"cos":return r;case"tan":return kt(n,r);case"cot":return kt(r,n);case"sec":return kt(tt(1),r);case"csc":return kt(tt(1),n)}}const r=ht(n),o=Tt(Math.sin(r),r),i=Tt(Math.cos(r),r),a={sin:o,cos:i,tan:o/i,cot:i/o,sec:1/i,csc:1/o}[t];if(!Number.isFinite(a)&&Number.isFinite(r))throw new S("undefined");return mt(a)}function Wt(t,n){const e={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[t],r=n=>"arcsin"===t?jt(n):"arccos"===t?zt(n):zt(n)&&!it(zt(n))?kt(jt(n),zt(n)):null;if(rt(n))for(let t=e[0];t<=e[1];t++){const e=r(t);if(e&&rt(e)&&lt(e,n))return Y(D(BigInt(t),12n),1)}const o=ht(n);if("arctan"!==t&&Math.abs(o)>1)throw new S("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[t](o)}function qt(t){if(rt(t)){if(0n===t.c.n)throw new S("ln 0 is undefined");if(t.c.n<0n)throw new S("not a real number");if(1n===t.c.n&&1n===t.c.d&&!t.pi&&!t.root)return tt(t.e)}const n=ht(t);if(n<=0)throw new S(0===n?"ln 0 is undefined":"not a real number");return Math.log(n)}function Zt(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*Zt(1-t));const n=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];let e=n[0];const r=(t-=1)+7+.5;for(let r=1;r<9;r++)e+=n[r]/(t+r);return Math.sqrt(2*Math.PI)*r**(t+.5)*Math.exp(-r)*e}function Ct(t,n){const e=at(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null===e)throw new S(`${n} needs whole numbers`);return e}const Dt=(t,n)=>Number(n)*Z(t)>P.bits;const Gt=Nt(t=>ot(t)?Y(D(K(t.c))):pt(Math.floor(ht(t)))),Lt=Nt(t=>ot(t)?Y(D(-K(J(t.c)))):pt(Math.ceil(ht(t))));function Rt(t,n){const e=Number(Ct(n,"round"));if(Math.abs(e)>P.places)throw new E("too many decimal places");if(ot(t)){const n=D(10n**BigInt(Math.abs(e))),r=e>=0?V(t.c,n):X(t.c,n),o=K(R(V(D(2n),D(W(r.n),r.d)),L))/2n,i=D(r.n<0n?-o:o);return Y(e>=0?X(i,n):V(i,n))}if(e>15)return ht(t);const r=10**e;return 0===r?0:Math.sign(ht(t))*Math.round(Math.abs(ht(t))*r)/r}const Vt=(t,n)=>t.toFixed(Math.min(n,100))+(n>100?"0".repeat(n-100):"");function Xt(t,n){if(it(n))throw new S("division by zero");if(ot(t)&&ot(n))return Y(R(t.c,J(V(n.c,D(K(X(t.c,n.c)))))));const e=ht(t),r=ht(n);return mt((e%r+r)%r)}const Jt=(t,n)=>t/Ht(t,n)*n,Ht=(t,n)=>n?Ht(n,t%n):t,Kt={pi:()=>nt,"π":()=>nt,tau:()=>Y(D(2n),1),"τ":()=>Y(D(2n),1),e:()=>et,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},Qt={abs:t=>rt(t)?Y(D(W(t.c.n),t.c.d),t.pi,t.e,t.root):Math.abs(ht(t)),floor:Gt,ceil:Lt,sqrt:t=>Ot(t,tt(1,2)),ln:Nt(qt),loglog:Nt(t=>qt(qt(t))),logloglog:Nt(t=>qt(qt(qt(t)))),expm1:Nt(t=>it(t)?tt(0):Math.expm1(ht(t))),sinh:Nt(t=>it(t)?tt(0):Math.sinh(ht(t))),cosh:Nt(t=>it(t)?tt(1):Math.cosh(ht(t))),tanh:Nt(t=>it(t)?tt(0):Math.tanh(ht(t))),arcsinh:Nt(t=>it(t)?tt(0):Math.asinh(ht(t))),arccosh:Nt(t=>{const n=ht(t);if(n<1)throw new S("not a real number");return 1===n?tt(0):Math.acosh(n)}),arctanh:Nt(t=>{const n=ht(t);if(Math.abs(n)>=1)throw new S("undefined");return it(t)?tt(0):Math.atanh(n)}),"!":Nt(function(t){const n=at(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null!==n){if(n<0n)throw new S("factorial of a negative number");if(n>BigInt(P.factorial))throw new E("too large to calculate");T(n,Number(n)*Math.log2(Number(n)+1));let t=1n;for(let e=2n;e<=n;e++)t*=e;return Y(D(t))}const e=ht(t);if(e<0&&Number.isInteger(e))throw new S("factorial of a negative number");return mt(Zt(e+1),e)}),neg:$t,pm:t=>st([t,$t(t)],"pm"),"\\not":t=>!gt(t),det:t=>an.det(t)};for(const t of["sin","cos","tan","csc","sec","cot"])Qt[t]=Nt(n=>_t(t,n));for(const t of["arcsin","arccos","arctan"])Qt[t]=Nt(n=>Wt(t,n));const Ut=new Set(["pmatrix","bmatrix"]),Yt=t=>s(t)&&(Ut.has(t.group)||"[]"===t.group&&t.every(t=>"[]"===t.group)&&(t.length>1||t[0].length>1)),tn=t=>u(t)&&!Yt(t)&&"pm"!==t.group,nn=c({add:At,sub:Ft,mul:Bt,div:kt,charge:z,isZero:t=>rt(t)?0n===t.c.n:Math.abs(ht(t))<1e-12,zero:()=>tt(0),one:()=>tt(1),size:t=>Math.abs(ht(t)),fail:t=>{throw new S(t)},make:(t,n)=>st(t.map(t=>st(t,"[]")),n&&n.group?n.group:"bmatrix")}),en=(t,n)=>st(t,n&&n.group?n.group:"[]"),rn=(t,n)=>(...e)=>{const r=e.length>1&&e.every(tn)?st(e.map(t=>st(t,"[]")),"[]"):e[0];if(e.length>1&&r===e[0])throw new E(`${t} of more than one thing`);if(!Yt(r))throw new E(`${t} of something that isn't a matrix`);return n(r)};function on(t,n){return Yt(t)&&Yt(n)?nn.times(t,n):Yt(t)&&tn(n)?en(nn.timesVector(t,n),n):tn(t)&&Yt(n)?en(nn.vectorTimes(t,n),t):Bt(t,n)}const an={det:rn("det",nn.det),inv:rn("inv",nn.inverse),inverse:rn("inverse",nn.inverse),transpose:rn("transpose",nn.transpose),trace:rn("trace",nn.trace),tr:rn("tr",nn.trace),rank:rn("rank",t=>tt(nn.rank(t))),rref:rn("rref",nn.rref),identity:t=>{const n=at(t);if(null===n||n<1n||n>100n)throw new E("identity(n) needs a whole number n");return nn.identity(Number(n))},dot:(t,n)=>{if(!tn(t)||!tn(n))throw new E("dot of something that isn't a vector");return nn.dot(t,n)},cross:(t,n)=>{if(!tn(t)||!tn(n))throw new E("cross of something that isn't a vector");return en(nn.cross(t,n),t)},linsolve:(t,n)=>{if(!Yt(t)||!Yt(n)&&!tn(n))throw new E("linsolve(A, b) needs a matrix and a vector");return Yt(n)?nn.solve(t,n):en(nn.solve(t,n),n)}};function sn(t,n){const e=t.args.map(t=>st("op"===t.type&&"[]"===t.op?t.args.map(n):[n(t)],"[]"));if(e.some(t=>t.length!==e[0].length))throw new S("rows of different lengths");return st(e,"vmatrix"===t.op?"bmatrix":t.op)}const un={"+":At,"-":Ft,"*":on,"/":(t,n)=>Yt(n)?on(t,nn.inverse(n)):kt(t,n),"^":function(t,n){if(!Yt(t))return Ot(t,n);const e=at(n);if(null===e)throw new E("a matrix to a power that is not a whole number");return nn.power(t,e)},"±":(t,n)=>st([At(t,n),Ft(t,n)],"pm"),mod:It(Xt),log:It(function(t,n){if(rt(t)&&lt(t,et))return qt(n);const e=ht(t),r=ht(n);if(e<=0||1===e)throw new S("not a valid base");if(r<=0)throw new S(0===r?"log 0 is undefined":"not a real number");const o=Math.log(r)/Math.log(e);if(ot(t)&&ot(n))for(let e=1n;e<=12n;e++){const r=Math.round(o*Number(e));if(Math.abs(o*Number(e)-r)>1e-9)continue;const i=vt(t,BigInt(r)),a=vt(n,e);if(i&&a&&lt(i,a))return Y(D(BigInt(r),e))}return o}),root:It((t,n)=>Ot(n,kt(tt(1),t))),atan2:(t,n)=>Math.atan2(ht(t),ht(n)),round:Rt,fixed:function(t,n){const e=Number(Ct(n,"fixed"));if(e<0)throw new S("fixed needs 0 or more decimal places");const r=Rt(t,n);if(ot(r)){const t=r.c.n*10n**BigInt(e)/r.c.d,n=(t<0n?-t:t).toString().padStart(e+1,"0");return ut(`${t<0n?"-":""}${n.slice(0,n.length-e)}${e?"."+n.slice(-e):""}`)}return ut(Vt(ht(r),e))},perm:function(t,n){const e=Ct(t,"permutations"),r=Ct(n,"permutations");if(r<0n||r>e)throw new S("undefined");if(r>BigInt(P.terms)||Dt(e,r))throw new E("too large to calculate");T(r,Number(r)*Z(e));let o=1n;for(let t=e-r+1n;t<=e;t++)o*=t;return Y(D(o))},comb:function(t,n){const e=Ct(t,"combinations");let r=Ct(n,"combinations");if(r<0n||r>e)throw new S("undefined");if(e-r<r&&(r=e-r),r>BigInt(P.terms)||Dt(e,r))throw new E("too large to calculate");T(2n*r,Number(r)*Z(e));let o=1n;for(let t=1n;t<=r;t++)o=o*(e-r+t)/t;return Y(D(o))},"=":(t,n)=>Et(t,n),"===":(t,n)=>Et(t,n),"≠":(t,n)=>!Et(t,n),"≠=":(t,n)=>!Et(t,n),"≈":(t,n)=>Math.abs(ht(t)-ht(n))<=1e-9*Math.max(1,Math.abs(ht(t)),Math.abs(ht(n))),"<":(t,n)=>St(t,n)<0,">":(t,n)=>St(t,n)>0,"≤":(t,n)=>St(t,n)<=0,"≥":(t,n)=>St(t,n)>=0,"&":(t,n)=>gt(t)&&gt(n),"|":(t,n)=>gt(t)||gt(n),"\\xor":(t,n)=>gt(t)!==gt(n),"\\nor":(t,n)=>!(gt(t)||gt(n)),"\\nand":(t,n)=>!(gt(t)&&gt(n))},cn={sum:t=>t.reduce((t,n)=>At(t,n),tt(0)),prod:t=>t.reduce((t,n)=>Bt(t,n),tt(1)),max:t=>t.reduce((t,n)=>St(n,t)>0?n:t),min:t=>t.reduce((t,n)=>St(n,t)<0?n:t),mean:t=>kt(cn.sum(t),tt(t.length)),gcd:t=>Y(D(t.map(t=>Ct(t,"gcd")).reduce(C)))},ln=["∈","∉","∪","∩","pmod","random","(]","[)"];function fn(n,o){if(++j>P.steps)throw new E("too much to work out");switch(n.type){case"number":return Y(U(n.value));case"string":return ut(n.value.slice(1,-1));case"symbol":return hn(n.value,o)}const i=e(n);if(i)return fn(i,o);const{op:a,args:s}=n,u=t=>fn(t,o);if("?:"===a)return gt(u(s[0]))?u(s[1]):u(s[2]);if("_"===a){if(s.every(t=>"op"!==t.type))return hn(`${s[0].value}_${s[1].value}`,o);throw new E("subscript")}if("der"===a)return function(t,n){const[e,r]=t.args;if("op"===r.type&&"="===r.op){const t=dn(r.args[0]);if(!t)throw new E("a derivative at a point names its variable: der(f, x = a)");return bn(e,t,ht(fn(r.args[1],n)),n)}const o=dn(r);if(!o||!n[mn]?.has(o))throw new E(`a derivative needs a point: der(f, ${o||"x"} = a)`);return bn(e,o,ht(n[o]),n)}(n,o);if("int"===a)return function(t,n){const[e,o,i,a]=t,s=t=>t&&"symbol"===t.type&&/^[a-zA-Zʹ-Ͽ]$/.test(t.value);let u,c,l;if(4===t.length)[u,c,l]=[dn(o),i,a];else{if(3!==t.length||s(o))throw new E("an integral needs limits to be calculated");[u,c,l]=[r(e)||"x",o,i]}let f=ht(fn(c,n)),h=ht(fn(l,n));if(f===h)return tt(0);let m=1;f>h&&([f,h]=[h,f],m=-1);const g=pn(e,u,n),{value:p,error:d}=wn(g,f,h);return Nn(m*p,d)}(s,o);if("lim"===a)return function(t,n){const[e,o,i,a]=t;let s,u,c=0;if(2===t.length&&"op"===o.type&&"→"===o.op)[s,u]=[dn(o.args[0]),o.args[1]];else if(2===t.length)[s,u]=[r(e),o];else{if(!(t.length>=3))throw new E("a limit needs a point");[s,u]=[dn(o),i]}if(4===t.length){const t="op"===a.type?"":String(a.value).toLowerCase();c=t.startsWith("r")||"+"===t?1:-1}if(!s)throw new E("a limit needs a variable");const l=fn(u,n),f=ht(l),h=pn(e,s,n);let m,g;if(Number.isFinite(f))if(c){({value:m,error:g}=yn(t=>h(f+c*t*Math.max(1,Math.abs(f)))));try{const t=fn(e,gn(n,s,l));if(Math.abs(ht(t)-m)<=Math.max(g,1e-6*Math.max(1,Math.abs(m))))return t}catch(t){if(!(t instanceof S))throw t}}else{const t=yn(t=>h(f+t*Math.max(1,Math.abs(f)))),r=yn(t=>h(f-t*Math.max(1,Math.abs(f))));if(t.value===r.value)({value:m,error:g}=t);else{if(!(Number.isFinite(t.value)&&Number.isFinite(r.value)&&Math.abs(t.value-r.value)<=1e-6*Math.max(1,Math.abs(t.value))))throw new S("the limit does not exist");m=(t.value+r.value)/2,g=Math.max(t.error,r.error,Math.abs(t.value-r.value))}try{const t=fn(e,gn(n,s,l));if(Math.abs(ht(t)-m)<=1e-6*Math.max(1,Math.abs(m)))return t}catch(t){if(!(t instanceof S))throw t}}else({value:m,error:g}=yn(t=>h(Math.sign(f)/t)));return Number.isFinite(m)?Nn(m,g):m}(s,o);if("\\sumidx"===a||"\\prodidx"===a)return function(t,n,e){const[o,i,a]=n;if(n.length<3)throw new E("a sum needs its limits");let s,u=i;"op"===i.type&&"="===i.op&&"symbol"===i.args[0].type?[s,u]=[i.args[0].value,i.args[1]]:s=r(o)||"n";const c=Ct(fn(u,e),"a sum"),l=fn(a,e),f=t?At:Bt;if(l===1/0){if(!t)throw new E("an infinite product");return function(t,n){const e=[],r=[];let o=0,i=n;for(let a=4;a<=17;a++){const s=2**a;for(;i<n+s;i++){const n=t(i);if(!Number.isFinite(n))throw new S("undefined");o+=n}if(e.push(s),r.push(o),a>=6&&r[r.length-1]===r[r.length-2]&&!xn(t,n,i))return Nn(o,0)}if(xn(t,n,i))throw new S("the series diverges");const a=r[r.length-1]-r[r.length-2],s=r[r.length-2]-r[r.length-3],u=r[r.length-3]-r[r.length-4],c=a/s;if(Math.abs(a)>1e-12&&c>=.999&&s/u>=.999)throw new S("the series diverges");if(Math.abs(a)>1e-6*Math.max(1,Math.abs(o))&&c>=.9)throw new E("the series grows too slowly to tell whether it has a sum");const l=e.slice(-7).map(t=>1/t),f=r.slice(-7),h=r.slice(-8,-1),m=(t,n)=>{const e=n.slice();for(let n=1;n<t.length;n++)for(let r=0;r<t.length-n;r++)e[r]=(t[r+n]*e[r]-t[r]*e[r+1])/(t[r+n]-t[r]);return e[0]},g=m(l,f),p=m(e.slice(-8,-1).map(t=>1/t),h);return Nn(g,Math.abs(g-p))}(pn(o,s,e),Number(c))}const h=Ct(l,"a sum");if(h-c+1n>BigInt(P.terms))throw new E("too many terms to add one by one");let m=tt(t?0:1);for(let t=c;t<=h;t++)m=f(m,fn(o,gn(e,s,Y(D(t)))));return m}("\\sumidx"===a,s,o);if(["()","[]","{}"].includes(a))return st(s.map(u),a);if("pmatrix"===a||"bmatrix"===a)return sn(n,u);if("vmatrix"===a)return nn.det(sn(n,u));if("^"===a&&"symbol"===s[1].type&&"T"===s[1].value&&!Object.prototype.hasOwnProperty.call(o,"T")){const t=u(s[0]);if(Yt(t))return nn.transpose(t)}if("pmod"===a)return function([t,n],e){const r=e(n);return"op"===t.type&&["≡","="].includes(t.op)&&2===t.args.length?it(Xt(Ft(e(t.args[0]),e(t.args[1])),r)):Xt(e(t),r)}(s,u);if("∈"===a||"∉"===a){const t=function(t,n){const[e,r]=t.args,o=n(e);let i;if("symbol"===r.type&&["ℤ","ℕ","ℚ","ℝ"].includes(r.value)&&rt(o))i="ℝ"===r.value||("ℚ"===r.value?ot(o):ot(o)&&1n===o.c.d&&("ℤ"===r.value||o.c.n>0n));else if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,e]=r.args.map(n),a=St(o,t),s=St(o,e);i=("["===r.op[0]?a>=0:a>0)&&("]"===r.op[1]?s<=0:s<0)}else{if("op"!==r.type||"{}"!==r.op)return;i=r.args.some(t=>Et(o,n(t)))}return"∈"===t.op?i:!i}(n,u);if(void 0!==t)return t}if(ln.includes(a))return function(n,e){const r={};for(const[t,n]of Object.entries(e))"function"!=typeof n&&(r[t]=dt(n));try{return pt(function(n,e={}){0===B&&(F=0),B++;try{return k(t(n),e)}finally{B--}}(n,r))}catch(t){throw new E(t.message)}}(n,o);if(a.startsWith("\\:")){const t=a.slice(2),n=Object.prototype.hasOwnProperty.call(o,t)?o[t]:void 0;if("function"!=typeof n&&Object.prototype.hasOwnProperty.call(an,t))return an[t](...s.map(u));if("function"!=typeof n)throw new E(`no function ${a.slice(2)}`);return pt(n(...s.map(t=>dt(u(t)))))}if(Qt[a]&&1===s.length)return Qt[a](u(s[0]));if(un[a]&&2===s.length)return un[a](u(s[0]),u(s[1]));if(cn[a])return cn[a](s.map(u));throw new E(`can't calculate '${a}'`)}function hn(t,e){if(Object.prototype.hasOwnProperty.call(e,t))return e[t];if(Object.prototype.hasOwnProperty.call(Kt,t))return Kt[t]();if(n(t))return Y(U(n(t)));throw new E(`no value for '${t}'`)}const mn=Symbol("bound"),gn=(t,n,e)=>({...t,[n]:e,[mn]:new Set([...t[mn]??[],n])});function pn(t,n,e){return r=>{try{return ht(fn(t,gn(e,n,r)))}catch(t){if(t instanceof S)return NaN;throw t}}}const dn=t=>"symbol"===t.type?t.value:null;function bn(t,n,e,r){const o=pn(t,n,r);if(!Number.isFinite(o(e)))throw new S("undefined");const i=1e-6*Math.max(1,Math.abs(e)),a=(o(e+i)-o(e))/i,s=(o(e)-o(e-i))/i;if(!Number.isFinite(a)||!Number.isFinite(s)||Math.abs(a-s)>.001*Math.max(1,Math.abs(a)))throw new S("not differentiable here");let u=.1*Math.max(1,Math.abs(e));const c=1.4,l=[[(o(e+u)-o(e-u))/(2*u)]];let f=l[0][0],h=1/0;for(let t=1;t<12;t++){u/=c,l[t]=[(o(e+u)-o(e-u))/(2*u)];let n=c*c;for(let e=1;e<=t;e++){l[t][e]=(l[t][e-1]*n-l[t-1][e-1])/(n-1),n*=c*c;const r=Math.max(Math.abs(l[t][e]-l[t][e-1]),Math.abs(l[t][e]-l[t-1][e-1]));r<=h&&(h=r,f=l[t][e])}if(Math.abs(l[t][t]-l[t-1][t-1])>=2*h)break}if(!Number.isFinite(f))throw new S("not differentiable here");return Nn(f,h)}function wn(t,n,e){if(n===-1/0&&e===1/0){const n=wn(t,-1/0,0),e=wn(t,0,1/0);return{value:n.value+e.value,error:n.error+e.error}}return e===1/0?Mn(e=>t(n+e/(1-e))/((1-e)*(1-e)),0,1):n===-1/0?Mn(n=>t(e-n/(1-n))/((1-n)*(1-n)),0,1):Mn(t,n,e)}function Mn(t,n,e,r=0){try{return function(t,n,e){const r=(e-n)/2,o=4;let i=1,a=0,s=NaN,u=NaN,c=0;const l=i=>{const a=Math.PI/2*Math.sinh(Math.abs(i)),s=Math.exp(-2*a),u=2*r*s/(1+s),l=r*(Math.PI/2)*Math.cosh(i)*(4*s)/((1+s)*(1+s));if(0===u||0===l)return 0;const f=i>0?e-u:n+u;if(0!==i&&(f<=n||f>=e))return 0;const h=t(0===i?(n+e)/2:f);if(!Number.isFinite(h)){if(u<1e-6*r)return 0;throw new S("the integral diverges")}return Math.abs(i)>o-.5&&(c=Math.max(c,Math.abs(l*h))),l*h};a=l(0);for(let t=i;t<=o;t+=i)a+=l(t)+l(-t);s=i*a;for(let t=1;t<=8;t++){i/=2;for(let t=i;t<=o;t+=2*i)a+=l(t)+l(-t);u=s,s=i*a;const n=Math.max(1,Math.abs(s));if(c>1e-8*n)throw new S("the integral diverges");if(t>=3&&Math.abs(s-u)<=1e-13*n)break}const f=Math.abs(s-u);if(!Number.isFinite(s)||f>1e-6*Math.max(1,Math.abs(s)))throw new S("the integral does not converge");return{value:s,error:f}}(t,n,e)}catch(t){if(!(t instanceof S)||"the integral does not converge"!==t.message||r>=10)throw t}const o=(n+e)/2,i=Mn(t,n,o,r+1),a=Mn(t,o,e,r+1);return{value:i.value+a.value,error:i.error+a.error}}function yn(t){const n=vn(t),e=vn(n=>t(.7548776662466927*n));if(n.value===e.value)return n;if(!Number.isFinite(n.value)||!Number.isFinite(e.value))throw new S("the limit does not exist");const r=Math.max(1,Math.abs(n.value)),o=Math.max(n.error,e.error,1e-6*r);if(o>.001*r)throw new S("the limit could not be found");if(Math.abs(n.value-e.value)<=o)return n;throw new S("the limit does not exist")}function vn(t){const n=[],e=[];for(let r=0;r<30;r++){const o=.1/2**r,i=t(o);Number.isFinite(i)&&(n.push(o),e.push(i))}if(e.length<6)throw new S("undefined");const r=e.slice(1).map((t,n)=>t-e[n]).slice(-6);if(r.every(t=>Math.sign(t)===Math.sign(r[0])&&0!==t)&&Math.abs(r[5])>=.95*Math.abs(r[0])&&Math.abs(e[e.length-1])>10)return{value:Math.sign(r[0])*(1/0),error:0};const o=t=>{const r=n.slice(t,t+8),o=e.slice(t,t+8);for(let t=1;t<r.length;t++)for(let n=0;n<r.length-t;n++)o[n]=(r[n+t]*o[n]-r[n]*o[n+1])/(r[n+t]-r[n]);return o[0]};let i=null;for(let t=0;t+9<=e.length;t++){const n=o(t),e=o(t+1),r=Math.abs(n-e);Number.isFinite(n)&&(!i||r<i.error)&&(i={value:n,error:r})}const a=t=>{const n=e[t+1]-e[t],r=e[t+2]-e[t+1];return r===n?e[t+2]:e[t+2]-r*r/(r-n)},s=t=>(e[t+2]-e[t+1])/(e[t+1]-e[t]),u=t=>[t,t+1].every(t=>s(t)>0&&s(t)<.95)&&Math.abs(s(t)-s(t+1))<.05;for(let t=0;t+3<e.length;t++){if(!u(t))continue;const n=a(t),e=Math.abs(n-a(t+1));Number.isFinite(n)&&(!i||e<i.error)&&(i={value:n,error:e})}const c=e[e.length-1],l=Math.abs(c-e[e.length-2]);if(!i||i.error>Math.max(l,1e-6*Math.max(1,Math.abs(c)))){if(l<=1e-6*Math.max(1,Math.abs(c)))return{value:c,error:10*l};throw new S("the limit could not be found")}return i}function xn(t,n,e){const r=n=>Math.max(...Array.from({length:8},(e,r)=>Math.abs(t(n+r)))),o=r(e);return o>1e-12&&o>=.5*r(n+Math.floor((e-n)/16))}function Nn(t,n=0){if(!Number.isFinite(t))return t;const e=Math.max(1e-10,4*n)*Math.max(1,Math.abs(t));if(e>1e-6*Math.max(1,Math.abs(t)))return function(t,n){if(!(n>0)||0===t)return t;const e=Math.floor(-Math.log10(n/Math.abs(t)));return e>=15?t:Number(t.toPrecision(Math.max(1,e)))}(t,n);if(Math.abs(t)<=Math.max(4*n,1e-15))return tt(0);if(Math.abs(t)<1e-10)return t;const r=[[tt(1),1e3],[nt,100],[Y(L,2),100],[et,100],...[2n,3n,5n,6n,7n].map(t=>[Y(L,0,0,{n:2,r:t}),100])];for(const[n,o]of r){const r=t/ht(n),i=In(r,o);if(i&&Math.abs(Number(i.n)/Number(i.d)-r)*ht(n)<=e)return Mt(Y(i),n)}return t}function In(t,n){if(!Number.isFinite(t)||Math.abs(t)>1e12)return null;let[e,r,o,i]=[0,1,1,0],a=t;for(let t=0;t<40;t++){const t=Math.floor(a),s=t*r+e,u=t*i+o;if(u>n)break;if([e,r,o,i]=[r,s,i,u],Math.abs(a-t)<1e-15)break;a=1/(a-t)}return i?D(BigInt(r),BigInt(i)):null}function An(t,n){if("boolean"==typeof t)return String(t);if(t&&"s"===t.kind)return JSON.stringify(t.text);if(Array.isArray(t)){if("pm"===t.group&&2===t.length&&Et(t[1],$t(t[0])))return`±${$n(t[0],n)}`;if(Ut.has(t.group)&&s(t))return`${t.group}(${t.map(t=>`[${t.map(t=>An(t,n)).join(", ")}]`).join(", ")})`;const[e,r]={"()":"()","[]":"[]","{}":"{}"}[t.group]||"{}";return e+t.map(t=>An(t,n)).join(", ")+r}return"number"==typeof t?Fn(t,n):n.decimal||null!==n.places?function(t,n){if(ot(t)&&null===n.places){let e=t.c.d,r=0,o=0;for(;e%2n==0n;)e/=2n,r++;for(;e%5n==0n;)e/=5n,o++;const i=Math.max(r,o);if(1n===e&&i<=n.digits){const e=t.c.n*10n**BigInt(i)/t.c.d,r=e<0n,o=W(e).toString().padStart(i+1,"0"),a=i?`${o.slice(0,-i)}.${o.slice(-i)}`:o;if(o.length<=n.maxDigits)return(r?"-":"")+Bn(a)}}return ot(t)&&null!==n.places?An(Rt(t,tt(n.places)),{...n,places:null,decimal:!0}):Fn(ht(t),n)}(t,n):function(t,n){const{c:e}=t,r=W(e.n);if(r.toString().length>n.maxDigits||e.d.toString().length>n.maxDigits)return function(t,n){if(!ot(t))return Fn(ht(t),n);if(1n!==t.c.d){const e=ht(t);if(0!==e&&Number.isFinite(e))return Fn(e,n);const r=W(t.c.n),o=t.c.d,i=n.digits+1-(r.toString().length-o.toString().length),a=(i>=0?r*10n**BigInt(i)/o:r/(o*10n**BigInt(-i))).toString(),s=((BigInt(a.slice(0,n.digits+1))+5n)/10n).toString(),u=a.length-1-i+(s.length>n.digits?1:0),c=Bn(`${s[0]}.${s.slice(1,n.digits)}`);return`${t.c.n<0n?"-":""}${c}*10^(${u})`}const e=W(t.c.n).toString(),r=BigInt(e.slice(0,n.digits+1)),o=((r+5n)/10n).toString(),i=e.length-1+(o.length>n.digits?1:0),a=Bn(`${o[0]}.${o.slice(1,n.digits)}`);return`${t.c.n<0n?"-":""}${a}*10^(${i})`}(t,n);const o=(t,n)=>1===n?t:`${t}^${n}`,i=[],a=[];t.pi>0&&i.push(o("pi",t.pi));t.pi<0&&a.push(o("pi",-t.pi));t.e>0&&i.push(o("e",t.e));t.e<0&&a.push(o("e",-t.e));t.root&&i.push(2===t.root.n?`sqrt(${t.root.r})`:`root(${t.root.n}, ${t.root.r})`);1n===r&&i.length||i.unshift(r.toString());1n!==e.d&&a.unshift(e.d.toString());const s=t=>t.length>1?`(${t.join("*")})`:t[0],u=a.length?`${s(i)}/${s(a)}`:i.join("*");return(e.n<0n?"-":"")+u}(t,n)}const $n=(t,n)=>{const e=An(t,n);return/^[\d.]+$|^[a-zπ]+$/i.test(e)?e:`(${e})`};function Fn(t,n){if(t===1/0)return"∞";if(t===-1/0)return"-∞";if(Object.is(t,-0)||0===t)return"0";if(null!==n.places&&Math.abs(t)<1e21)return Vt(t,n.places);const e=Math.abs(t);if(e>=1e15||e<1e-6){const[e,r]=t.toExponential(n.digits-1).split("e");return`${Bn(e)}*10^(${Number(r)})`}return String(Number(t.toPrecision(n.digits)))}const Bn=t=>t.includes(".")?t.replace(/\.?0+$/,""):t;function kn(t,n={},e={}){0===_&&(j=0);const r="string"==typeof t?o(t):i(t),a={};for(const[t,e]of Object.entries(n))a[t]=pt(e);let s;_++;try{s=fn(r,a)}finally{_--}const u={decimal:!1,places:null,digits:12,maxDigits:50,...e};if(void 0===u.places&&(u.places=null),null!==u.places&&!(Number.isInteger(u.places)&&u.places>=0&&u.places<=P.places))throw new E(`places is a whole number from 0 to ${P.places}`);const c=t=>Array.isArray(t)?t.every(c):"number"!=typeof t;return{value:dt(s),text:An(s,u),exact:c(s)}}function On(t,n={}){let e=t.trim();const r={},o=/^(~|≈)\s*(\d+)?/.exec(e);o&&(r.decimal=!0,void 0!==o[2]&&(r.places=Number(o[2])),e=e.slice(o[0].length)),/\d\.\d|\.\d/.test(e)&&(r.decimal=!0);try{const{text:t}=kn(e,n,r);return t.startsWith('"')||/^\d+(\.\d+)?$/.test(t)?t:`(${t})`}catch(t){if(t instanceof S)return'"undefined"';if(t instanceof E)return`(${e})`;throw t}}a(On);for(const t of[P,Pt,Kt,Qt,un,cn])Object.setPrototypeOf(t,null);Object.setPrototypeOf(an,null);export{kn as a,On as c};
@@ -1,2 +0,0 @@
1
- /* Inline Math 0.3.0 — MIT license; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate (and mathzetta/text, for cas.external.js) with an import map */
2
- import{GREEK as t,isCustomFunction as e,matrixRows as r,unaryNeedsBrackets as s,bracketOp as i,precedenceOf as n,isMinusOneTimes as a,needsBrackets as l,bracketedSides as o,isImplicitProduct as h,customName as c,derivativeOrder as u,isVariable as d,firstLeaf as p,firstVariable as f,MATRICES as m,walk as g,toPostfix as b,operator as v,VARIADIC as $,parseTree as x,fromPostfix as y}from"mathzetta";import{toAudioSpeech as w}from"mathzetta/speech";const L={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0.015"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function M(t,e,r=""){const s=L[t];return`<svg class="${e}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${r?` style="${r}"`:""}>${s.fill?`<path d="${s.fill}" fill="currentColor"/>`:`<path d="${s.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const k=.8,C=.2,z=.25,j=.7,P="−",A={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},F={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Z={"±":"±","∪":"∪","∩":"∩",mod:"mod"},q=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],O={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},B=[...q,...Object.keys(O),"ln","det"],S={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},W={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},E=["int","lim","\\sumidx","\\prodidx"],_={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},I={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},N=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,T=e=>"symbol"===e?.type&&N.test(t[e.value]??e.value),D=["boxed","overline","bar","underline","cancel",...Object.keys(I)],R={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},G=t=>String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),H=t=>+t.toFixed(3)+"em",J=(t,e=k,r=C)=>({html:t,h:e,d:r});function K(...t){const e=t.flat().filter(Boolean);return{html:e.map(t=>t.html).join(""),h:Math.max(k,...e.map(t=>t.h)),d:Math.max(C,...e.map(t=>t.d))}}function Q(t,e={}){const r=new U({...R,...e}),s=r.render(t,{level:0}),i=`${r.p}${r.o.display?` ${r.p}-display`:""}`,n="function"==typeof r.o.mathml?function(t,e,r,s){try{return String(t(e)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${r}-sr-math"${s?' display="block"':""}>`)}catch{return""}}(r.o.mathml,t,r.p,r.o.display):"",a=n?null:function(t,e){if(!1===e||null===e)return null;if("string"==typeof e)return e;try{return"function"==typeof e?e(t):w(t)}catch{return null}}(t,r.o.label),l=null!==a||n?s.html.replace(/^<span /,'<span aria-hidden="true" '):s.html;return{html:`<span class="${i}"${null===a?"":` role="math" aria-label="${G(a)}"`}>${l}${n}</span>`,h:s.h,d:s.d}}class U{constructor(t){this.o=t,this.p=t.prefix}el(t,e,r="",s=""){return`<span class="${t.split(" ").map(t=>`${this.p}-${t}`).join(" ")}"${r?` style="${r}"`:""}${s}>${e}</span>`}text(t,e){const r=J(this.el(t,G(e)));return r.leaf={kind:t,content:G(e)},r}bin(t){return this.text("bin",t)}rel(t){return this.text("rel",t)}punct(t){return this.text("punct",t)}word(t){return this.text("word",t)}wrap(t,e,r){let s="";void 0!==t.id&&(s+=` data-node="${t.id}"`),"op"===t.type&&(s+=` data-op="${G(t.op)}"`);const i=this.o.attributes&&this.o.attributes(t)||{};for(const[t,e]of Object.entries(i))"class"!==t&&"style"!==t&&/^[A-Za-z_:][\w:.-]*$/.test(t)&&(s+=` ${t}="${G(e)}"`);const n=[i.style,this.o.style&&this.o.style(t)].filter(Boolean).join(";"),a=(r.leaf?["n",...e,r.leaf.kind]:["n",...e]).map(t=>`${this.p}-${t}`).concat(i.class?[G(i.class)]:[]).join(" "),l=r.leaf?r.leaf.content:r.html;return{html:`<span class="${a}"${n?` style="${G(n)}"`:""}${s}>${l}</span>`,h:r.h,d:r.d}}render(t,e){return"number"===t.type?this.number(t):"string"===t.type?this.wrap(t,["text"],this.text("text",t.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===t.type?this.wrap(t,["symbol"],this.symbol(t.value)):this.operation(t,e)}number(t){return this.wrap(t,["number"],this.text("num",t.value.replace(/^-/,P)))}symbol(e){return t[e]&&(e=t[e]),_[e]?this.text("ord",_[e]):"\\+"===e||"\\-"===e?this.text("ord",e[1]):"-∞"===e?this.text("ord","−∞"):/^[A-Za-z]$/.test(e)||/^[α-ω]$/.test(e)?this.text("var",e):/^[A-Za-z]′+$/.test(e)?J(this.el("var",G(e[0]))+this.el("prime",G(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?J(this.el("ord","Δ")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(t,o){const{op:h,args:c}=t,[u,d]=c,p=(t,e={})=>this.render(t,{...o,...e,forceParens:e.forceParens||!1,before:e.before||!1,leftFactor:!1}),f=A[h]??(/^[a-z0-9]+$/i.test(h)?h:"other"),m=e=>this.wrap(t,["op",`op-${f}`],e),g=(e,r)=>l(t,e,r)&&"/"!==e.op?this.fence(p(e)):p(e);if(B.includes(h)||"log"===h)return m(this.named(t,o));if(S[h])return m(K(this.word(S[h]),this.fence(this.list(c,o))));if(e(h))return m(this.custom(t,o));const b=r(t);if(b)return m(this.matrix(t,b,o));if(W[h])return m(this.fence(this.list(c,o),...W[h]));if(("|"===h||"&"===h)&&c.length>=2&&c.every(Y)){const t=t=>"|"!==t.op&&"&"!==t.op||t.op===h?p(t):this.fence(p(t));return m(K(c.map((e,r)=>r?[this.text("conj","|"===h?"or":"and"),t(e)]:[t(e)]).flat()))}if(F[h]&&2===c.length)return m(K(g(u,"left"),this.rel(F[h]),g(d,"right")));if(Z[h]&&2===c.length)return m(K(g(u,"left"),this.bin(Z[h]),g(d,"right")));switch(h){case"+":if(a(d)){const t=d.args[1],e=l({op:"-"},t,"right")?this.fence(p(t)):p(t);return m(K(g(u,"left"),this.bin(P),this.wrap(d,["op","op-mul"],e)))}return"number"===d.type&&d.value.startsWith("-")?m(K(g(u,"left"),this.bin(P),this.wrap(d,["number"],this.text("num",d.value.slice(1))))):m(K(g(u,"left"),this.bin("+"),this.signed(d,g(d,"right"))));case"-":return m(K(g(u,"left"),this.bin(P),this.signed(d,g(d,"right"))));case"*":return m(this.product(t,o));case"/":return m(this.fraction(t,o));case"^":return m(this.power(t,o));case"_":{const t=i(u)&&n(i(u))<100;return m(this.script(t?this.fence(p(u)):p(u,{forceParens:!0}),null,o,p(d,{level:o.level+1})))}case"neg":return m(K(this.text("sign",P),s(h,u)?this.fence(p(u)):p(u,{before:o.before})));case"pm":return m(K(this.text("sign","±"),s(h,u)?this.fence(p(u)):p(u)));case"!":return m(K(s(h,u)?this.fence(p(u)):p(u,{forceParens:!0}),this.text("ord","!")));case"\\not":return m(K(this.text("sign","¬"),s(h,u)?this.fence(p(u)):p(u)));case"pmod":return m(K(p(u),this.fence(K(this.word("mod"),this.text("space",""),p(d)))));case"sqrt":return m(this.radical(p(u)));case"root":return m(this.radical(p(d),this.render(u,{level:o.level+2})));case"abs":return m(this.fence(p(u),"|","|"));case"floor":return m(this.fence(p(u),"⌊","⌋"));case"ceil":return m(this.fence(p(u),"⌈","⌉"));case"loglog":return m(K(this.word("ln"),this.fence(K(this.word("ln"),this.fence(p(u))))));case"logloglog":return m(K(this.word("ln"),this.fence(K(this.word("ln"),this.fence(K(this.word("ln"),this.fence(p(u))))))));case"perm":return m(this.script(this.script(J(""),this.render(u,{level:o.level+1}),o),null,o,this.render(d,{level:o.level+1}),this.word("P")));case"comb":return m(this.fence(this.stack(p(u),p(d),!1)));case"?:":return m(this.o.cases?this.cases(t,o):K(p(u),this.bin("?"),p(d),this.bin(":"),p(c[2])));case"sum":case"prod":{const t={op:"sum"===h?"+":"*"},e=(e,r)=>l(t,e,r?"right":"left")?this.fence(p(e)):p(e);return m(K(c.map((t,r)=>r?[this.bin("sum"===h?"+":"·"),e(t,r)]:[e(t,r)]).flat()))}case"der":return m(this.derivative(t,o));case"int":return m(this.integral(c,o));case"lim":return m(this.limit(c,o));case"\\sumidx":return m(this.bigOperator("sum",c,o));case"\\prodidx":return m(this.bigOperator("prod",c,o))}throw new Error(`Inline Math cannot draw '${h}'`)}signed(t,e){return("number"===t.type?t.value.startsWith("-"):"neg"===t.op||"pm"===t.op)&&!e.fenced?this.fence(e):e}list(t,e){return K(t.map((t,r)=>r?[this.punct(","),this.render(t,e)]:[this.render(t,e)]).flat())}product(t,r){const[i,n]=t.args;if(a(t))return K(this.text("sign",P),s("neg",n)?this.fence(this.render(n,r)):this.render(n,r));const l=o(t);E.includes(i.op)&&(l.left=!0);const c=!t.written&&h(i,n,l),u=function(t){for(;"op"===t.type;){if(B.includes(t.op)||"log"===t.op||S[t.op]||e(t.op))return!0;if("^"!==t.op&&"*"!==t.op)return!1;t=t.args[0]}return!1}(n),d=l.left?this.fence(this.render(i,r)):this.render(i,{...r,before:c&&!u,leftFactor:!0}),p=l.right?this.fence(this.render(n,r)):this.render(n,{...r,before:r.before});return K(d,c?J(this.el(u?"fnspace":"times","")):this.bin("cross"===t.written?"×":"·"),p)}named(t,e,r=null){const{op:s,args:i}=t,n="log"===s?i[1]:i[0];let a;a=O[s]&&"power"===this.o.inverseTrig?this.script(this.word(O[s]),this.text("num","−1"),e):this.word(s),r&&(a=this.script(a,r,e)),"log"===s&&(a=this.script(a,null,e,this.render(i[0],{level:e.level+1})));const l="auto"===this.o.fnParens&&!e.forceParens&&!e.before&&V(n),o=this.render(n,{...e,forceParens:!1,before:!1});return K(a,l?K(J(this.el("fnspace","")),o):this.fence(o))}custom(t,e){const r=c(t.op),s=t.args;if(D.includes(r)&&1===s.length)return this.decorate(r,this.render(s[0],e),s[0]);return K(/^[A-Za-z]′*(⁻¹)?$/.test(r)?this.symbol(r):this.word(r),J(this.el("callgap","")),this.fence(this.list(s,e)))}decorate(t,e,r){switch(t){case"boxed":return J(this.el("boxed",e.html),e.h+.22,e.d+.22);case"cancel":return J(this.el("cancel",e.html+M("cancel",`${this.p}-cancel-line`)),e.h,e.d);case"underline":return J(this.el("underline",e.html),e.h,e.d+.12);case"overline":case"bar":return J(this.el("over"+(T(r)?" over-low":""),e.html),e.h+.14,e.d);default:{const s=T(r);return J(this.el("accent"+(s?" accent-low":""),this.el(`accent-mark accent-${t}`,I[t])+e.html),e.h+.3,e.d)}}}fraction(t,e){const[r,s]=t.args;if(e.level>0&&"slash"===this.o.scriptFractions&&V(r,!0)&&V(s,!0)){const t={...e,leftFactor:!1},i=(e,r)=>"op"!==e.type||V(e)&&(!r||"*"!==e.op||a(e))?this.render(e,t):this.fence(this.render(e,t)),n=K("op"===r.type&&"neg"===r.op?this.render(r,t):i(r,!1),this.text("ord","/"),i(s,!0));return e.leftFactor?this.fence(n):n}const i=e.level>0||e.inFraction||!this.o.display?.8:1,n={...e,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(r,n),this.render(s,n),!0,i)}stack(t,e,r=!0,s=1){const i=t=>1===s?t.html:this.el("scaled",t.html,`font-size:${H(s)}`),n=r?.06:0,a=z+n/2+.1+Math.max(C,s*t.d),l=this.el("frac"+(r?"":" frac-nobar"),this.el("numer",i(t))+this.el("denom",i(e)),`vertical-align:${H(a)}`);return J(l,a+Math.max(k,s*t.h),Math.max(k,s*e.h)+Math.max(C,s*e.d)+.1+n/2-z)}power(t,e){const[r,s]=t.args,i={...e,level:e.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},n=()=>this.render(s,i);if(this.o.trigPowers&&q.includes(r.op)&&et(s))return this.wrap(r,["op",`op-${r.op}`],this.named(r,e,n()));if("_"===r.op){const t=this.render(r.args[1],i);return this.wrap(r,["op","op-subscript"],this.script(this.render(r.args[0],{...e,forceParens:!0}),n(),e,t))}const a=l(t,r,"left")||"number"===r.type&&r.value.startsWith("-")||"/"===r.op||B.includes(r.op)||E.includes(r.op)?this.fence(this.render(r,e)):this.render(r,{...e,forceParens:!0});return this.script(a,n(),e)}script(t,e,r,s=null,i=null){const n=r.level>0?.8:j,a=i?K(t,i):t;let l=e?Math.max(.42,t.h-.38,n*e.d+.12):0,o=s?Math.max(.2,t.d-.05,n*s.h-.45):0;if(e&&s){const t=.1-(l-n*e.d-(n*s.h-o));t>0&&(o+=t)}const h=t=>this.el("script",t.html,`font-size:${H(n)}`);if(e&&!s)return J(t.html+this.el("sup",e.html,`font-size:${H(n)};vertical-align:${H(l/n)}`),Math.max(a.h,l+n*e.h),Math.max(a.d,n*e.d-l));if(s&&!e)return J(a.html+this.el("sub",s.html,`font-size:${H(n)};vertical-align:${H(-o/n)}`),Math.max(a.h,n*s.h-o),Math.max(a.d,o+n*s.d));const c=l+n*e.h,u=o+n*s.d,d=this.el("subsup",h(e)+h(s),`vertical-align:${H(l)};height:${H(c+u)}`);return J(a.html+d,Math.max(a.h,c),Math.max(a.d,u))}radical(t,e=null){const r=Math.max(t.h,k)+.1+.06,s=Math.max(t.d,C),i=r+s,n=M("sqrt",`${this.p}-hook`,`height:${H(i)};width:${H(.5+.06*(i-1))};vertical-align:${H(-s)}`);let a="";if(e){const t=.8*j;a=this.el("rootindex",e.html,`font-size:${H(t)};vertical-align:${H((.55*i-s)/t)}`)}return J(this.el("sqrt",a+n+this.el("radicand",t.html)),r,s)}fence(t,e="(",r=")"){const s=Math.max(t.h,k)+Math.max(t.d,C),i=s>1.25,n=i?.1:0,a=(t,e)=>{if(!t)return{html:"",w:0};const r={"(":.26,")":.26,"{":.36,"}":.36}[t];if(r){const n=r+(i?Math.min(.2,.05*(s-1)):0);return{html:M(t,`${this.p}-delim ${this.p}-delim-${e}`,`width:${H(n)}`),w:n+.1}}const n={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[t];return{html:this.el(`delim ${n} delim-${e}`,""),w:"|"===t?.18:.3}},l=a(e,"l"),o=a(r,"r"),h=`padding:${H(n)} ${H(o.w)} ${H(n)} ${H(l.w)}`,c=J(this.el("fence",l.html+t.html+o.html,h),Math.max(t.h,k)+n,Math.max(t.d,C)+n);return c.fenced=!0,c}derivative(t,e){const r=this.leibniz(t,e),{by:s,at:i}=u(t);if(!i)return r;const n=t.args[1],a=this.render({...n,args:[{...s,id:void 0},i]},{...e,level:e.level+1});return this.script(this.fence(r,"","|"),null,e,a)}leibniz(t,e){const{n:r,body:s,by:a,variable:l}=u(t),o={...e,level:e.level+1},h=()=>this.text("d","d"),c=()=>r>1?this.render({type:"number",value:String(r)},o):null,d={...e,inFraction:!0},p=K(h(),c()?this.script(this.render(a,d),c(),d):this.render(a,d)),f=t=>K(c()?this.script(h(),c(),d):h(),t||[]),m=e.level>0||e.inFraction||!this.o.display?.8:1;if(l)return this.stack(f(this.render(s,d)),p,!0,m);const g=i(s)&&n(i(s))<100,[b,v]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],$=g?this.fence(this.render(s,e),b,v):this.render(s,e);return K(this.stack(f(),p,!0,m),$)}integral(t,e){const[r,s,i,n]=t,a=t=>this.render(t,e),l=t=>t?this.render(t,{...e,level:e.level+1}):null,o=()=>this.text("var",f(r)||"x");let h,c=null,u=null;switch(t.length){case 1:h=o();break;case 2:d(s)?h=a(s):(h=o(),c=l(s));break;case 3:d(s)?(h=a(s),c=l(i)):(h=o(),c=l(s),u=l(i));break;default:h=a(s),c=l(i),u=l(n)}const p=a(r),m=J(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return K(this.bigSign("int",p,c,u,e),p,m)}bigSign(t,e,r,s,i){const n=!this.o.display||i.level>0,a=Math.max(n?.6:.95,Math.max(e.h-z,e.d+z)+.12),l=M(t,`${this.p}-bigsign ${this.p}-${t}sign`,`height:${H(2*a)};width:${H(n?.38:.5)};vertical-align:${H(z-a)}`);if(!r&&!s)return J(l,z+a,a-z);const o=j,h=s||J(""),c=r||J(""),u=z+a-o*h.h;c.d;const d=this.el("limits",this.el("script",h.html,`font-size:${H(o)}`)+this.el("script lower",c.html,`font-size:${H(o)}`),`vertical-align:${H(u)};height:${H(2*a)}`);return J(l+d,z+a,a-z)}limit(t,e){const[r,s,i,n]=t,a={...e,level:e.level+1},l=t=>this.render(t,a),o=()=>this.rel("→");let h;switch(t.length){case 1:return K(this.word("lim"),J(this.el("fnspace","")),this.body(r,e));case 2:{const t=f(r),e="number"===s.type||"symbol"===s.type&&s.value.includes("∞");h=t&&e?K(this.text("var",t),o(),l(s)):l(s);break}case 3:h=K(l(s),o(),l(i));break;default:{const t=p(n).toLowerCase().startsWith("r")?"+":P;h=K(l(s),o(),this.script(l(i),this.wrap(n,["symbol"],this.text("ord",t)),a))}}return K(this.under(this.word("lim"),h,e),this.body(r,e))}under(t,e,r){return!this.o.display||r.level>0?this.script(t,null,r,e):J(this.el("under",t.html+this.el("script",e.html,`font-size:${H(.7)}`)),t.h,Math.max(t.d,C)+.05+.7*(e.h+e.d))}body(t,e){const r=i(t);return r&&n(r)<n("*")?this.fence(this.render(t,e)):this.render(t,e)}bigOperator(t,e,r){const[s,i,n]=e,a={...r,level:r.level+1},l=i?this.render(i,a):null,o=n?this.render(n,a):null,h=this.body(s,r);if(!this.o.display||r.level>0){const e=.55,s=M(t,`${this.p}-bigsign`,`height:${H(2*e)};width:${H(.8)};vertical-align:${H(z-e)}`);return K(this.script(J(s,z+e,e-z),o,r,l),h)}const c=.68,u=j,d=M(t,`${this.p}-bigsign`,`height:${H(1.36)};width:${H("sum"===t?1:1.05)}`),p=o?1.01+u*o.d:z-c,f=t=>this.el("script",t.html,`font-size:${H(u)}`),m=this.el("bigop",(o?f(o):"")+d+(l?f(l):""),`vertical-align:${H(p)}`);return K(J(m,.93+(o?.08+u*(o.h+o.d):0),c-z+(l?.08+u*(l.h+l.d):0)),h)}matrix(t,e,r){const s=e.map(t=>t.map(t=>this.render(t,r))),i=s.map(t=>({h:Math.max(k,...t.map(t=>t.h)),d:Math.max(C,...t.map(t=>t.d))})),n=i.reduce((t,e)=>t+e.h+e.d,0)+.3*(e.length-1),a=z+n/2-i[0].h,l=s.map((e,r)=>{const s=e.map(t=>this.el("matrix-cell",t.html)).join(""),i=t.args[r];return i&&"op"===i.type&&"[]"===i.op?this.wrap(i,["op","op-list","matrix-row"],J(s)).html:s}).join(""),o=e[0].length,h=J(this.el("matrix",l,`grid-template-columns:repeat(${o},auto);vertical-align:${H(a)}`),z+n/2,n/2-z),[c,u]=m[t.op]??["[","]"];return this.fence(h,c,u)}cases(t,e){const r=[];let s=t;for(;"op"===s.type&&"?:"===s.op;)r.push([this.render(s.args[1],e),K(this.word("if"),this.text("space",""),this.render(s.args[0],e))]),s=s.args[2];"symbol"===s.type&&"unchanged"===s.value||r.push([this.render(s,e),this.word("otherwise")]);const i=r.map(([t,e])=>({h:Math.max(t.h,e.h),d:Math.max(t.d,e.d)})),n=i.reduce((t,e)=>t+e.h+e.d,0)+.25*(r.length-1),a=z+n/2-i[0].h,l=r.map(([t,e])=>this.el("case-value",t.html)+this.el("case-cond",e.html)).join(""),o=J(this.el("cases",l,`vertical-align:${H(a)}`),z+n/2,n/2-z);return this.fence(o,"{","")}}function V(t,e=!1){return"number"===t.type?!t.value.startsWith("-")||e:"symbol"===t.type||"op"===t.type&&("abs"===t.op||r(t)?!e:!e||"neg"!==t.op&&"^"!==t.op?"*"===t.op&&!a(t)&&t.args.every(t=>"number"===t.type&&!t.value.startsWith("-")||tt(t)||"*"===t.op&&V(t,e)):V(t.args[0],!0)&&("neg"===t.op||V(t.args[1],!0)))}const X=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],Y=t=>"op"===t.type&&t.args.length>=2&&(2===t.args.length&&X.includes(t.op)||("|"===t.op||"&"===t.op)&&t.args.every(Y)),tt=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(t[e.value])),et=t=>"number"===t.type&&/^[1-9]\d*$/.test(t.value)&&Number(t.value)<10;for(const t of[A,F,Z,O,S,W,_,I])Object.setPrototypeOf(t,null);function rt(t){const{id:e,from:r,...s}=t;return s.args&&(s.args=s.args.map(rt)),s}const st=t=>b(t).join(" ");function it(t,e){const r=new Set;nt(t,e,r);const s=[];return g(t,t=>{r.has(t)&&s.push(t)}),s}function nt(t,e,r){if(null!=e)if(Array.isArray(e))e.forEach(e=>nt(t,e,r));else if("number"!=typeof e)if("function"!=typeof e){if("string"==typeof e){const s=st(x(e));return void g(t,t=>{st(t)===s&&r.add(t)})}if(e.path){const s=at(t,e.path);return void(s&&r.add(s))}if(e.type){const s=st(e);g(t,t=>{t!==e&&st(t)!==s||r.add(t)})}}else g(t,(t,s)=>{e(t,s)&&r.add(t)});else g(t,t=>{t.id===e&&r.add(t)})}function at(t,e){let r=t;for(const t of e){if("op"!==r.type||!r.args[t])return null;r=r.args[t]}return r}function lt(t,e){const r=[],s=t=>{if(t.id===e)return!0;if("op"!==t.type)return!1;for(let e=0;e<t.args.length;e++){if(r.push(e),s(t.args[e]))return!0;r.pop()}return!1};return s(t)?r:null}function ot(t){let e=0;const r=t=>{"op"===t.type&&(t.args.forEach(r),v(t.op)?.arity===$&&e++),t.id=e++};return r(t),t}function ht(t,e={}){const{blocks:r}=e;if("string"==typeof t)return x(t,r?{blocks:t=>r(t,e.scope)}:{});if(Array.isArray(t))return y(t);if(t&&"object"==typeof t&&t.type){if(void 0!==t.id)return t;const e=structuredClone(t);return g(e,t=>{"op"!==t.type&&void 0!==t.value&&(t.value=String(t.value))}),ot(e)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function ct(t,e={}){const r=ht(t,e);return Q(r,ut(r,e)).html}function ut(t,e){const{colors:r,highlight:s,scope:i,blocks:n,...a}=e,l=new Map;for(const[e,s]of function(t){return t?Array.isArray(t)?t:Object.entries(t).map(([t,e])=>[/^\d+$/.test(t)?Number(t):t,e]):[]}(r))if(dt(s))for(const r of it(t,e))l.set(r,`color:${s}`);const o=new Set(void 0===s?[]:it(t,s));if(!l.size&&!o.size)return a;const h=a.prefix||"mv";return{...a,style:t=>[l.get(t),a.style&&a.style(t)].filter(Boolean).join(";"),attributes:t=>{const e={...a.attributes?a.attributes(t):{}};return o.has(t)&&(e.class=[e.class,`${h}-hl`].filter(Boolean).join(" ")),e}}}function dt(t){return"string"==typeof t&&/^[#\w\s.,%()/+-]+$/.test(t)&&!/url\s*\(|expression/i.test(t)}export{R as D,L as P,ht as a,ut as b,at as c,st as d,rt as e,Q as l,ot as n,lt as p,it as s,ct as t};
@@ -1,2 +0,0 @@
1
- /* Inline Math 0.3.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
2
- import{c as o}from"./calculate-BGMEvf3f.js";import{e as s,f as t}from"./lite-Bo8THzyq.js";function c(s,c={}){return t(s,{...c,blocks:c.blocks??o})}function r(t,c={}){return s(t,{...c,blocks:c.blocks??o})}export{r as a,c as t};
@@ -1,2 +0,0 @@
1
- /* Inline Math 0.3.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
2
- const e=-1,t={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt:n(1),abs:n(1),floor:n(1),ceil:n(1),det:n(1),ln:n(1),loglog:n(1),logloglog:n(1),expm1:n(1),sin:n(1),cos:n(1),tan:n(1),csc:n(1),sec:n(1),cot:n(1),sinh:n(1),cosh:n(1),tanh:n(1),arcsin:n(1),arccos:n(1),arctan:n(1),arcsinh:n(1),arccosh:n(1),arctanh:n(1),random:n(0),log:n(2),root:n(2),atan2:n(2),round:n(2),fixed:n(2),perm:n(2),comb:n(2),der:n(2),max:n(e),min:n(e),gcd:n(e),mean:n(e),sum:n(e),prod:n(e),int:n(e),lim:n(e),"\\sumidx":n(e),"\\prodidx":n(e),pmatrix:n(e),bmatrix:n(e),vmatrix:n(e),"()":s(),"[]":s(),"{}":s(),"(]":s(),"[)":s(),"=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"===":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"<":{prec:34,assoc:"left",arity:2,fixity:"infix"},">":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≤":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≥":{prec:34,assoc:"left",arity:2,fixity:"infix"},"∈":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∉":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∪":{prec:33,assoc:"left",arity:2,fixity:"infix"},"∩":{prec:33,assoc:"left",arity:2,fixity:"infix"},"≈":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≡":{prec:30,assoc:"left",arity:2,fixity:"infix"},pmod:{prec:2,assoc:"left",arity:2,fixity:"infix"},"→":{prec:38,assoc:"left",arity:2,fixity:"infix"},"\\not":{prec:85,assoc:"none",arity:1,fixity:"prefix"},"&":{prec:20,assoc:"left",arity:2,fixity:"infix"},"\\xor":{prec:19,assoc:"left",arity:2,fixity:"infix"},"|":{prec:18,assoc:"left",arity:2,fixity:"infix"},"\\nor":{prec:17,assoc:"left",arity:2,fixity:"infix"},"\\nand":{prec:17,assoc:"left",arity:2,fixity:"infix"},"?:":{prec:10,assoc:"right",arity:3,fixity:"infix"}};function n(e){return{prec:100,assoc:"none",arity:e,fixity:"prefix"}}function s(){return{prec:5,assoc:"left",arity:e,fixity:"none",group:!0}}const r="\\:",i=e=>"string"==typeof e&&e.startsWith(r)&&e.length>2;function o(e){return Object.prototype.hasOwnProperty.call(t,e)?t[e]:i(e)?a:void 0}const a=n(e),l=e=>o(e)?.prec;function c(e,t,n){if("mod"===e&&t)return l(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const s=l(e),r=l(t);if(!s||!r)return!1;if(r!==s)return r<s;const i=o(e).assoc;return"left"===i?"right"===n:"right"===i&&"left"===n}const h=100,u="",p="",f={[u]:"dot",[p]:"cross"},d="",m={ln:h,log:h,loglog:h,logloglog:h,sqrt:h,sqrtpow:h,pow:h,expm1:h,der:h,lim:h,int:h,round:h,fixed:h,floor:h,ceil:h,abs:h,random:h,sum:h,prod:h,"\\sumidx":h,"\\prodidx":h,perm:h,comb:h,"\\perm":h,"\\comb":h,"\\binom":h,max:h,min:h,gcd:h,mean:h,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,[u]:70,[p]:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"?:":10,"?":9,",":5},g=e=>Object.prototype.hasOwnProperty.call(m,e),$=new Set(["^","?:","?","log"]),x=["(","{","["],y=[")","}","]"];function b(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[m])Object.setPrototypeOf(e,null);const w=e=>({type:"number",value:String(e)}),v=e=>({type:"symbol",value:e}),k=(e,t)=>({type:"op",op:e,args:t}),E=['"',"'","`"];function M(e){return b(e,!0)?w(e):E.includes(e[0])?{type:"string",value:e}:v(e)}const _={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function A(t){if(!Array.isArray(t)||0===t.length)throw new Error("Empty postfix");const n=[],s=[];if(t.forEach((t,r)=>{const a=_[t]??String(t),l=o(a);if(!l)return n.push({...M(a),id:r}),void s.push(1);let c=l.arity;if(c===e){const e=n.pop();if(s.pop(),c=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(c)||c<0)throw new Error(`'${a}' takes a variable number of arguments, so it must follow a count`);if(0===c&&!l.group&&!i(a))throw new Error(`'${a}' needs at least one argument`)}if(n.length<c)throw new Error(`'${a}' needs ${c} operand${1===c?"":"s"}`);const h=1+Math.max(0,...s.splice(s.length-c,c));if(h>1e3)throw new Error("Nested too deeply (more than 1000 levels)");s.push(h),n.push({...k(a,n.splice(n.length-c,c)),id:r})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function O(t,n){const s=[];return function t(r){"op"===r.type?(r.args.forEach(t),o(r.op)?.arity===e&&s.push(String(r.args.length)),n&&r.written&&(n[s.length]=r.written),s.push(r.op)):s.push(r.value)}(t),s}function q(e){if(Array.isArray(e))return A(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}function N(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>N(n,t,e))}function S(e){let t="";return N(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[_])Object.setPrototypeOf(e,null);function L(e){const t=new Map;for(const[n,s,r]of e)if(n&&""!==n.trim()&&(t.set(n,s),!r))for(const e of C(n))t.get(e)||t.set(e,s);const n=new Map;for(const e of t.keys()){let t=n;for(let n=0;n<e.length;n++)t.has(e[n])||t.set(e[n],new Map),t=t.get(e[n]);t.end=!0}return e=>{let s="",r=0;for(;r<e.length;){const i=z(n,e,r);i?(s+=t.get(e.slice(r,r+i)),r+=i):s+=e[r++]}return s}}function z(e,t,n){let s=e,r=0;for(let e=n;e<t.length&&(s=s.get(t[e]),s);e++)s.end&&(r=e-n+1);return r}function C(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),I(e)]);return t.delete(e),t}function I(e){let t="",n=!1;for(const s of e){const e=s>="a"&&s<="z",r=s>="A"&&s<="Z";t+=!n&&e?s.toUpperCase():s,n=e||r}return t}const R=[["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\cfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\%","%"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot",u],["\\times",p],["×",p],["·",u],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],...["","\\"].flatMap(e=>["(","{"].flatMap(t=>[2,3,4,5,6,7,8,9,10].map(n=>[`${e}log${n}${t}`,`log_{${n}}${t}`]))),["\\log_10","log_{10}"],["log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left.",d],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⅕","(1/5)"],["⅖","(2/5)"],["⅗","(3/5)"],["⅘","(4/5)"],["⅙","(1/6)"],["⅚","(5/6)"],["⅐","(1/7)"],["⅑","(1/9)"],["⅒","(1/10)"],["⊕"," \\xor "],["∞","∞"],["⋅",u],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0]];const T=e=>" "===e||"\t"===e||"\n"===e,j="({[",Z=")}]";const P={__proto__:null},F={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((e,t)=>{P[e]=String(t)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((e,t)=>{F[e]=String(t)}),Object.assign(P,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g","ʰ":"h","ⁱ":"i","ʲ":"j","ᵏ":"k","ˡ":"l","ᵐ":"m","ⁿ":"n","ᵒ":"o","ᵖ":"p","ʳ":"r","ˢ":"s","ᵗ":"t","ᵘ":"u","ᵛ":"v","ʷ":"w","ˣ":"x","ʸ":"y","ᶻ":"z"}),Object.assign(F,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const W=new RegExp(`[${Object.keys(P).join("")}]+|[${Object.keys(F).join("")}]+`,"g");const D={__proto__:null,"½":"1/2","⅓":"1/3","⅔":"2/3","¼":"1/4","¾":"3/4","⅕":"1/5","⅖":"2/5","⅗":"3/5","⅘":"4/5","⅙":"1/6","⅚":"5/6","⅐":"1/7","⅛":"1/8","⅜":"3/8","⅝":"5/8","⅞":"7/8","⅑":"1/9","⅒":"1/10"},U=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys(D).join("")}])`,"g"),B=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,G=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function H(e){const t=e.replace(/^\s*(?:\\(?:text|textrm|mathrm)\s*\{\s*(?:if|for|when|where)\s*\}|\b(?:if|for|when|where)\b)\s*,?/,"").replace(/[\s,.;]+$/,"").trim();return/^(?:\\(?:text|textrm|mathrm)\s*\{\s*)?(?:otherwise|else)\s*\}?$/.test(t)?"":t}function Q(e,t){const n=[];let s=0,r=0;for(let i=0;i<e.length;i++)j.includes(e[i])?s++:Z.includes(e[i])?s--:0===s&&e.startsWith(t,i)&&(n.push(e.slice(r,i)),i+=t.length-1,r=i+1);return n.push(e.slice(r)),n}function V(e,t,n){let s=0;const r=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(j.includes(e[n]))s++;else if(Z.includes(e[n])){if(--s<0)return-1}else if(0===s&&(r.lastIndex=n,r.test(e)))return n;return-1}function X(e,t){let n=0;for(let s=t;s<e.length;s++)if(j.includes(e[s]))n++;else if(Z.includes(e[s])&&--n<0)return s;return e.length}function J(e,t){let n=1;for(let s=t+1;s<e.length;s++)if("?"===e[s])n++;else if(":"===e[s]&&0===--n)return e.slice(0,t+1)+"("+e.slice(t+1,s)+")?:"+e.slice(s+1);return e}function K(e){for(let t=2;t<e.length;t++)if("g"===e[t]&&"log"===e.slice(t-2,t+1))if("_"===e[t+1]){if(j.includes(e[t+2]))continue;const n=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(e.slice(t+2))?.[0];if(!n)continue;const s=t+2+n.length;e=e.slice(0,t+2)+"{"+n+"}"+e.slice(s)}else if("("===e[t+1]){let n=1,s=0,r="",i="",o=0;for(let a=t+2;a<e.length;a++){if(")]".includes(e[a])?n--:"([".includes(e[a])&&n++,0===n){o=a;break}1===n&&","===e[a]?s++:0===s?r+=e[a]:i+=e[a]}1===s&&o>0&&(e=e.slice(0,t+1)+"_{"+i+"}("+r+")"+e.slice(o+1))}return e}function Y(e){const t="⌈"===e[0]?"ceil":"floor";let n=1;for(let s=1;s<e.length;s++)if("⌊"===e[s]||"⌈"===e[s]?n++:"⌋"!==e[s]&&"⌉"!==e[s]||n--,0===n)return t+"("+e.slice(1,s)+")"+e.slice(s+1);return e}function ee(e){let t=1;for(let n=0;n<e.length;n++){if(")]".includes(e[n])?t--:"([".includes(e[n])&&t++,0!==t)continue;const s=e.slice(0,n),r=e[n+1];if("{"===r||"("===r)return r+s+","+e.slice(n+2);const i=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(e.slice(n+1))?.[0]??"";return"{"+s+","+i+"}"+e.slice(n+1+i.length)}return e}const te=new Set(["pmatrix","bmatrix","vmatrix"]);function ne(e){const t=e.indexOf("}"),n=e.indexOf("{");if(t<0||n>=0&&n<t)return!1;const s=e.slice(0,t);if(!s.includes("matrix"))return!1;const r=e.indexOf("\\end{"+s+"}"),i=e.indexOf("\\begin{"+s+"}",t+1);if(r<0||-1!==i&&i<r)return!1;const o=e.slice(t+1,r).trim().split("\\\\").map(e=>e.trim()).filter(e=>e.length).map(e=>"["+e.replace(/&/g,", ")+"]"),a=e.slice(r+6+s.length);return te.has(s)?s+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function se(e,t){if("{"!==e[t+1])return[e[t+1],t+2];let n=1,s="";for(let r=t+2;r<e.length;r++){if("{"===e[r])n++;else if("}"===e[r]&&0===--n)return[s,r+1];s+=e[r]}return[s,e.length]}function re(e){const{lower:t,upper:n,next:s}=function(e){let t="",n="",s=0;return"_"===e[0]&&([t,s]=se(e,0),"^"===e[s]&&([n,s]=se(e,s))),{lower:t,upper:n,next:s}}(e),r=e.slice(s),i=e=>e.replace(/\\,/g,"").replace(/\\!/g,"");let o,a="",l="",c=r.indexOf("\\mathrm{d}");if(c>=0){o=r.slice(0,c);const e=/^\{([^{}]*)\}/.exec(r.slice(c+10));a=e?e[1]:r[c+10],l=r.slice(c+10+(e?e[0].length:1))}else(c=function(e){let t=0;for(let n=0;n<e.length;n++)if(j.includes(e[n]))t++;else if(Z.includes(e[n]))t--;else if(0===t&&"d"===e[n]&&/[A-Za-z\u0370-\u03FF]/.test(e[n+1]??"")&&!/[A-Za-z]/.test(e[n+2]??""))return n;return-1}(r))>=0?(o=r.slice(0,c),a=r[c+1],l=r.slice(c+2)):o=r;if(!a){const e=/frac\{d([A-Za-z])\}/.exec(o);e&&(a=e[1],o=o.replace(e[0],"frac{1}"))}if(!a&&/^[A-Za-z]$/.test(t)){a=[...i(o).matchAll(/(?<![A-Za-z\\])([A-Za-z])(?![A-Za-z(])/g)].map(e=>e[1]).find(e=>e!==t&&e!==n)??"x"}let h="int("+(i(o).trim()?i(o):"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function ie(e){const t=e[0];if(!(t>="A"&&t<="Z"||t>="a"&&t<="z"||t>="α"&&t<="ω"))return!1;const n=e.slice(2);let s=1;for(let e=0;e<n.length;e++)if(Z.includes(n[e])?s--:j.includes(n[e])&&s++,0===s)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function oe(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const ae=/[A-Za-z\u0370-\u03FF]/;function le(e,t){if("{"!==e[t])return null;let n=0;for(let s=t;s<e.length;s++)if("{"===e[s])n++;else if("}"===e[s]&&0===--n)return[e.slice(t+1,s),s+1];return null}function ce(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function he(e,t){const n=e.replace(/\\mathrm\{d\}/g,"d"),s=t.replace(/\\mathrm\{d\}/g,"d"),r=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(n),i=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(s);return r&&i?{n:Number(r[1]??1),of:r[2],by:i[1]}:null}function ue(e,t){if(j.includes(e[t])){let n=0;for(let s=t;s<e.length;s++)if(j.includes(e[s]))n++;else if(Z.includes(e[s])&&0===--n)return[e.slice(t,s+1),s+1];return[e.slice(t),e.length]}let n=0;for(let s=t;s<e.length;s++)if(j.includes(e[s]))n++;else{if(Z.includes(e[s])&&--n<0)return[e.slice(t,s),s];if(0===n&&("="===e[s]||","===e[s]))return[e.slice(t,s),s]}return[e.slice(t),e.length]}const pe=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const fe="strtktk",de="ABCDEFGHIJ",me=e=>fe+[...String(e)].map(e=>de[e]).join(""),ge=new RegExp(`^${fe}[${de}]+$`);function $e(e){let t="";for(let n=0;n<e.length;n++){const s=e[n];if('"'===s||"`"===s){const s=xe(e,n);t+=e.slice(n,s+1),n=s}else if("'"===s)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(t[t.length-1]??""))t+="′";else{const s=xe(e,n);t+=e.slice(n,s+1),n=s}else t+=s}return t}function xe(e,t){let n=!1;for(let s=t+1;s<e.length;s++)if(n)n=!1;else if("\\"===e[s])n=!0;else if(e[s]===e[t])return s;return e.length-1}const ye=new RegExp(`${fe}[${de}]+|§\\d+§`,"g");function be(e,t){return t&&0!==t.size?e.map(e=>"string"!=typeof e?e:e.replace(ye,e=>{const n=t.get(e);if(void 0!==n)return n;for(let n=e.length-1;n>7;n--){const s=t.get(e.slice(0,n));if(void 0!==s)return s+e.slice(n)}return e})):e}const we={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))"};for(const e of[we])Object.setPrototypeOf(e,null);const ve="([{",ke=")]}";function Ee(e,t){let n=0;for(let s=t;s<e.length;s++)if(ve.includes(e[s]))n++;else if(ke.includes(e[s])&&0===--n)return s;return-1}function Me(e){if(!e.trim())return[];const t=[];let n=0,s=0;for(let r=0;r<e.length;r++)ve.includes(e[r])?n++:ke.includes(e[r])?n--:","===e[r]&&0===n&&(t.push(e.slice(s,r).trim()),s=r+1);return t.push(e.slice(s).trim()),t}function _e(e,t,n){const s=[...e.matchAll(t)];for(let t=s.length-1;t>=0;t--){const r=s[t],i=r.index+r[0].length-1,o=Ee(e,i);if(o<0)continue;const a=n(Me(e.slice(i+1,o)),r,e.slice(o+1));if(null==a)continue;const[l,c=0]=Array.isArray(a)?a:[a];if((e=e.slice(0,r.index)+l+e.slice(o+1+c)).length>1e5)throw new Error("The expression expands too much when read")}return e}const Ae=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),Oe=e=>`(${e})`,qe=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const Ne={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(Oe).join(" & ")})`,OR:e=>e.length&&`(${e.map(Oe).join(" ∨ ")})`,NOT:e=>1===e.length&&`(!(${e[0]}))`,XOR:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,LOG:e=>2===e.length?`log_{${e[1]}}(${e[0]})`:1===e.length&&`log_{10}(${e[0]})`,ATAN2:e=>2===e.length&&`atan2(${e[1]}, ${e[0]})`,INT:e=>1===e.length&&`floor(${e[0]})`,FIXED:e=>(1===e.length||2===e.length)&&`fixed(${e[0]}, ${e[1]??2})`,"FLOOR.MATH":e=>1===e.length&&`floor(${e[0]})`,"CEILING.MATH":e=>1===e.length&&`ceil(${e[0]})`,FACT:e=>1===e.length&&`((${e[0]})!)`,COMBIN:e=>2===e.length&&`comb(${e.join(", ")})`,PERMUT:e=>2===e.length&&`perm(${e.join(", ")})`,AVERAGE:e=>`mean(${e.join(", ")})`,SUM:e=>`sum(${e.join(", ")})`,PRODUCT:e=>`prod(${e.join(", ")})`,MAX:e=>`max(${e.join(", ")})`,MIN:e=>`min(${e.join(", ")})`,MEDIAN:e=>`median(${e.join(", ")})`,"STDEV.P":e=>`stdev(${e.join(", ")})`,STDEVP:e=>`stdev(${e.join(", ")})`,CEILING:e=>(1===e.length||2===e.length&&"1"===e[1].trim())&&`ceil(${e[0]})`,RAND:e=>!e.length&&"random()",ISNUMBER:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,LOG10:e=>1===e.length&&`log_{10}(${e[0]})`};function Se(e,t){for(let n=t,s=0;n>=0;n--)if(")"===e[n])s++;else if("("===e[n]&&0===--s)return n;return-1}function Le(e){const t="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";return e=function(e,t){const n=new RegExp(`^(?:${t})`,"u"),s=new RegExp(`(?:${t})$`,"u"),r=/[\p{L}_][\p{L}\p{N}_.]*$/u;for(let t=e.indexOf("^");t>=0;t=e.indexOf("^",t+1)){let i,o=t+1;for(;/\s/.test(e[o]??"");)o++;if("("===e[o])i=Ee(e,o)+1;else{const t=n.exec(e.slice(o));i=t?o+t[0].length:0,t&&"("===e[i]&&(i=Ee(e,i)+1)}if(i<=o||!/^\s*\^/.test(e.slice(i)))continue;let a,l=t;for(;l>0&&/\s/.test(e[l-1]);)l--;if(")"===e[l-1]){a=Se(e,l-1);const t=a>0&&r.exec(e.slice(Math.max(0,a-64),a));t&&(a-=t[0].length)}else{const t=s.exec(e.slice(Math.max(0,l-64),l));a=t?l-t[0].length:-1}a<0||(e=`${e.slice(0,a)}(${e.slice(a,i)})${e.slice(i)}`,t=i+1)}return e}(e=(e=(e=e.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${t})(?=\\s*\\^)`,"gu"),"$1(-$2)"),t),_e(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>Ne[t[1]]?.(e)||null)}const ze={POWER:"pow",SQRT:"sqrt",ABS:"abs",LN:"ln",EXP:"exp",FLOOR:"floor",CEIL:"ceil",CEILING:"ceil",ROUND:"round",GREATEST:"max",LEAST:"min",MOD:"mod",ATAN2:"atan2",FACTORIAL:"factorial",SIN:"sin",COS:"cos",TAN:"tan",SEC:"sec",CSC:"csc",COT:"cot",ASIN:"asin",ACOS:"acos",ATAN:"atan",SINH:"sinh",COSH:"cosh",TANH:"tanh",ASINH:"asinh",ACOSH:"acosh",ATANH:"atanh",COMB:"comb",PERM:"perm",GCD:"gcd",DERIVATIVE:"derivative",LIMIT:"limit",UNION:"union",EXPM1:"expm1",TRUNC:"trunc",SUMMATION:"sum"},Ce="strtktk[A-J]+";function Ie(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${Ce})\\s*\\|\\|\\s*(${Ce})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${Ce},\\s*${Ce}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const s=Ee(e,n),r=s>0&&t.exec(e.slice(n,s+1));if(!r)continue;const[,i,o]=r,a=new Map([[`${i} = TRUNC(${i})`,"ℤ"],[`${i} = TRUNC(${i}) AND ${i} > 0`,"ℕ"],[`ABS(${i}) < ∞`,"ℝ"]]).get(o.trim());a&&(e=`${e.slice(0,n)}((${i}) ∈ ${a})${e.slice(s+1)}`)}e=_e(e,/(?<![\w.])CAST\s*\(/gi,e=>{const t=1===e.length&&/^(.*)\s+AS\s+(?:REAL|FLOAT|DOUBLE(?:\s+PRECISION)?|NUMERIC|DECIMAL|INTEGER|INT)\s*$/is.exec(e[0]);return t?`(${t[1]})`:null}),e=(e=(e=_e(e=function(e){for(let t=0;t<50;t++){const t=[...e.matchAll(/\bCASE\s+WHEN\b/gi)];if(!t.length)return e;const n=t[t.length-1].index,s=/\bEND\b/i.exec(e.slice(n));if(!s)return e;const r=e.slice(n+4,n+s.index).split(/\b(WHEN|THEN|ELSE)\b/i).map(e=>e.trim()),i=[];let o="null";for(let e=1;e<r.length;e+=2){const t=r[e].toUpperCase();"WHEN"===t?i.push([r[e+1],r[e+3]]):"ELSE"===t&&(o=r[e+1])}const a=i.reduceRight((e,[t,n])=>`((${t}) ? (${n}) : ${e})`,Oe(o));e=e.slice(0,n)+a+e.slice(n+s.index+3)}return e}(e=e.replace(/(?<![\w.])ARRAY\s*\[/g,"[")),/(?<![\w.])LOG\s*\(/g,e=>2===e.length?`log_{${e[0]}}(${e[1]})`:`log_{10}(${e[0]})`)).replace(/(?<![\w.])PI\s*\(\s*\)/g,"π")).replace(/(?<![\w.])([A-Z][A-Z0-9]*)(?=\s*\()/g,e=>ze[e]??e);for(const[t,n]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let s=t.exec(e);s;s=t.exec(e)){const r=s.index+s[0].length-1,i=Ee(e,r);if(i<0)break;e=`${e.slice(0,s.index)}${n} {${e.slice(r+1,i)}}${e.slice(i+1)}`,t.lastIndex=0}return e.replace(/<>/g," ≠ ")}const Re={sin:"sin",cos:"cos",tan:"tan",sinh:"sinh",cosh:"cosh",tanh:"tanh",arcsin:"asin",arccos:"acos",arctan:"atan",arcsinh:"asinh",arccosh:"acosh",arctanh:"atanh",arctan2:"atan2",sqrt:"sqrt",cbrt:"cbrt",exp:"exp",expm1:"expm1",log:"log",log2:"log2",log10:"log10",floor:"floor",ceil:"ceil",round:"round",power:"pow",abs:"abs",absolute:"abs",fabs:"abs",pi:"PI",e:"E",gcd:"gcd"},Te={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc",union1d:"union",intersect1d:"intersection"};const je={inf:"∞",nan:"NaN"};function Ze(e){return(e=(e=function(e){return e=e.replace(/(?<![\w.])sympy\.Interval\.(open|Lopen|Ropen)\s*\(/g,(e,t)=>`sympy_interval_${t}(`),e=e.replace(/(?<![\w.])sympy\.S\.(\w+)/g,(e,t)=>Fe[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>Fe[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>We[t]??Pe[t]??e)}(e=(e=(e=(e=(e=(e=(e=e.replace(/(?<![\w.])(?:np|numpy)\.random\.random\(\s*\)|(?<![\w.])random\.random\(\s*\)/g,"Math.random()")).replace(/(?<![\w.])(?:np|numpy)\.linalg\.(det|inv)\b/g,"$1")).replace(/(?<![\w.])(?:np|numpy)\.array\s*\(/g,"(")).replace(/(?<![\w.])(?:np|numpy)\.(\w+)/g,(e,t)=>Re[t]?`Math.${Re[t]}`:Te[t]?Te[t]:je[t]??e)).replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>je[t]??t)).replace(/(?<![\w.])Number\.(isInteger|isFinite)\b/g,(e,t)=>t.toLowerCase())).replace(/(?<![\w.])scipy\.(?:special|integrate)\.(\w+)/g,"$1"))).replace(/\bMZ_INFINITY\b/g,"∞")).replace(/(?<![\w.])mz_(?=\w+\s*\()/g,"")}const Pe={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Fe={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},We={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",real_root:"sympy_root",det:"det",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},De={open:"()",Lopen:"(]",Ropen:"[)"};const Ue=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?Me(t[1]):null},Be=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Ge=e=>Ue(e)??[e],He={where:e=>3===e.length&&`((${e[0]}) ? (${e[1]}) : (${e[2]}))`,logical_and:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,logical_or:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,logical_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,logical_not:e=>1===e.length&&`(!(${e[0]}))`,isin:e=>2===e.length&&`((${e[0]}) ∈ ${qe(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${qe(e[0])})`,isclose:e=>e.length>=2&&`((${e[0]}) ≈ (${e[1]}))`,isfinite:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,isinteger:e=>1===e.length&&`((${e[0]}) ∈ ℤ)`,factorial:e=>1===e.length&&`((${e[0]})!)`,union:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,union_:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,intersection:e=>2===e.length&&`((${e[0]}) ∩ (${e[1]}))`,sq:e=>1===e.length&&`((${e[0]})^2)`,cube:e=>1===e.length&&`((${e[0]})^3)`,fract:e=>1===e.length&&`((${e[0]}) - floor(${e[0]}))`,inversesqrt:e=>1===e.length&&`(1/sqrt(${e[0]}))`,mod:e=>2===e.length&&`((${e[0]}) \\mod (${e[1]}))`,atan:e=>2===e.length&&`atan2(${e[0]}, ${e[1]})`,exp2:e=>1===e.length&&`((2)^(${e[0]}))`,trunc:e=>1===e.length&&`((${e[0]}) < 0 ? (ceil(${e[0]})) : floor(${e[0]}))`,vec2:e=>`(${e.join(", ")})`,vec3:e=>`(${e.join(", ")})`,vec4:e=>`(${e.join(", ")})`,derivative:e=>e.length>=2&&`der(${e.join(", ")})`,sympy_rational:e=>2===e.length&&`((${e[0]})/(${e[1]}))`,sympy_value:e=>1===e.length&&`(${e[0]})`,sympy_eq:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,sympy_ne:e=>2===e.length&&`((${e[0]}) ≠ (${e[1]}))`,sympy_and:e=>e.length&&`(${e.map(Oe).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(Oe).join(" ∨ ")})`,sympy_not:e=>1===e.length&&`(!(${e[0]}))`,sympy_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,sympy_nand:e=>2===e.length&&`((${e[0]}) \\nand (${e[1]}))`,sympy_nor:e=>2===e.length&&`((${e[0]}) \\nor (${e[1]}))`,sympy_piecewise:e=>{const t=e.map(Ue);return!t.length||t.some(e=>!e||2!==e.length)?null:t.reduceRight((e,[t,n])=>null===e||/^True$|^true$/.test(n.trim())&&void 0===e?`(${t})`:`((${n}) ? (${t}) : ${e??"(null)"})`,void 0)},sympy_set:e=>`{${e.join(", ")}}`,sympy_interval:Be("[]"),sympy_interval_open:Be("()"),sympy_interval_Lopen:Be("(]"),sympy_interval_Ropen:Be("[)"),sympy_contains:e=>2===e.length&&`((${e[0]}) ∈ ${e[1]})`,sympy_list_gcd:e=>1===e.length&&`gcd(${e[0].trim().replace(/^\[|\]$/g,"")})`,sympy_root:e=>2===e.length&&`root(${e[1]}, ${e[0]})`,sympy_integrate:e=>{if(2!==e.length)return null;const t=Ge(e[1]);return 3===t.length?`int(${e[0]}, ${t.join(", ")})`:1===t.length?`int(${e[0]}, ${t[0]})`:null},sympy_limit:e=>e.length>=3&&`lim(${e.slice(0,3).join(", ")}${e[3]?`, ${e[3]}`:""})`,sympy_summation:e=>{if(3===e.length&&/^\s*[A-Za-z]\w*\s*==/.test(e[1]))return`sum(${e[0]}, ${e[1].replace("==","=")}, ${e[2]})`;const t=2===e.length&&Ge(e[1]);return 3===t?.length&&`(\\sum_{${t[0]}=${t[1]}}^{${t[2]}} (${e[0]}))`},sympy_product:e=>{if(3===e.length&&/^\s*[A-Za-z]\w*\s*==/.test(e[1]))return`prod(${e[0]}, ${e[1].replace("==","=")}, ${e[2]})`;const t=2===e.length&&Ge(e[1]);return 3===t?.length&&`(\\prod_{${t[0]}=${t[1]}}^{${t[2]}} (${e[0]}))`},limit:e=>e.length>=3&&`lim(${e.join(", ")})`,summation:e=>3===e.length&&/^\s*[A-Za-z]\w*\s*==/.test(e[1])&&`sum(${e[0]}, ${e[1].replace("==","=")}, ${e[2]})`,sum:Qe("sum"),prod:Qe("prod")};function Qe(e){return t=>{const n=1===t.length&&/^(.*?)\s+for\s+(\w+)\s+in\s+range\((.*)\)\s*$/s.exec(t[0]);if(!n)return null;const s=Me(n[3]),[r,i]=1===s.length?["0",s[0]]:s,o=/\s*\+\s*1$/.test(i)?i.replace(/\s*\+\s*1$/,""):`(${i}) - 1`;return`(\\${e}_{${n[2]}=${r}}^{${o}} (${n[1]}))`}}function Ve(e){e=function(e){for(let t=e.lastIndexOf("(lambda");t>=0;t=t>0?e.lastIndexOf("(lambda",t-1):-1){const n=Ee(e,t);if(n<0||"("!==e[n+1])continue;const s=Ee(e,n+1),r=/^\(lambda\s+([\w\s,]+?)\s*:\s*([\s\S]*)\)$/.exec(e.slice(t,n+1));if(s<0||!r)continue;const i=r[1].split(",").map(e=>e.trim()),o=Me(e.slice(n+2,s));if(o.length!==i.length||!i.every(e=>/^[A-Za-z_]\w*$/.test(e)))continue;const a=new Map(i.map((e,t)=>[e,o[t]])),l=r[2].replace(new RegExp(`(?<![\\w.])(${i.join("|")})(?!\\w)`,"g"),e=>`(${a.get(e)})`);if((e=e.slice(0,t)+`(${l})`+e.slice(s+1)).length>1e5)throw new Error("The expression expands too much when read")}return e}(e),e=_e(e,Ae("quad"),(e,t,n)=>{const s=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(e[0]??"");if(!s||3!==e.length)return null;const r=/^\s*\[\s*0\s*\]/.exec(n);return[`int(${s[2]}, ${s[1]}, ${e[1]}, ${e[2]})`,r?r[0].length:0]}),e=_e(e,Ae(Object.keys(He).join("|")),(e,t)=>He[t[1]](e)||null);for(let t=(e=_e(e,Ae("float"),(e,t,n)=>{const s=/^\s*\.is_integer\(\s*\)/.exec(n);return s&&1===e.length?[`((${e[0]}) ∈ ℤ)`,s[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,s=Ee(e,n);let r=t;if(ke.includes(e[t-1])){let n=0;for(r=t-1;r>=0;r--)if(ke.includes(e[r]))n++;else if(ve.includes(e[r])&&0===--n)break}else for(;r>0&&/[\w.]/.test(e[r-1]);)r--;s<0||r<0||r===t||(e=`${e.slice(0,r)}((${e.slice(n+1,s)}) ∈ ${qe(e.slice(r,t))})${e.slice(s+1)}`)}return e}for(const e of[Ne,ze,Re,Te,Pe,Fe,We,De,He,je])Object.setPrototypeOf(e,null);const Xe=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Je=e=>e.trim().split(/\s+/).join(String.raw`\s+`),Ke=e=>new RegExp(String.raw`(?<![\w.])${Je(e)}(?![\w.])`,"gi"),Ye=[["is greater than or equal to","≥"],["is more than or equal to","≥"],["is at least","≥"],["is no less than","≥"],["is not less than","≥"],["is less than or equal to","≤"],["is at most","≤"],["is no more than","≤"],["is not more than","≤"],["is not greater than","≤"],["is greater than",">"],["is more than",">"],["is bigger than",">"],["is larger than",">"],["is above",">"],["exceeds",">"],["is less than","<"],["is smaller than","<"],["is fewer than","<"],["is below","<"],["is not equal to","≠"],["does not equal","≠"],["doesn't equal","≠"],["is different from","≠"],["is approximately equal to","≈"],["is approximately","≈"],["is about","≈"],["is roughly","≈"],["is close to","≈"],["is equal to","="],["is the same as","="],["equals","="],["greater than or equal to","≥"],["less than or equal to","≤"],["at least","≥"],["at most","≤"],["greater than",">"],["more than",">"],["less than","<"],["not equal to","≠"],["equal to","="]],et="[<>≤≥=≠≈]",tt={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(tt,null);const nt=Object.entries({sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"}).sort((e,t)=>t[0].length-e[0].length),st=[["is non-negative","≥ 0"],["is nonnegative","≥ 0"],["is not negative","≥ 0"],["is non-positive","≤ 0"],["is nonpositive","≤ 0"],["is not positive","≤ 0"],["is positive","> 0"],["is negative","< 0"],["is non-zero","≠ 0"],["is nonzero","≠ 0"],["is not zero","≠ 0"],["is zero","= 0"],["is a whole number","∈ ℤ"],["is an integer","∈ ℤ"],["is not an integer","∉ ℤ"],["is a natural number","∈ ℕ"],["is a real number","∈ ℝ"],["is real","∈ ℝ"],["is a rational number","∈ ℚ"],["is rational","∈ ℚ"]],rt=/(?<![A-Za-z])(?:is|between|exceeds|equals?|does|doesn't|least|most|than|divides|and|or|of|to|squared|cubed|twice|percent|by|over|times|plus|minus|modulo)(?![A-Za-z])/i;Ye.map(([e])=>e),st.map(([e])=>e),nt.map(([e])=>`${e} of`);const it=L([[" And "," & "],[" Or "," ∨ "],[" Not In "," ∉ "],[" Nor "," \\nor "],[" Xor "," \\xor "],[" Nand "," \\nand "],[" In "," ∈ "],[" Mod "," \\mod "],[" % ","%"],[" Perm ","\\perm "],[" P ","\\perm",!0],[" Comb ","\\comb "],[" C ","\\comb",!0],[" choose ","\\comb "],["! ","!_"],["\\in ","∈"],["\\notin ","∉"],["\\not\\in ","∉"],["\\to ","→"],["===","=...="]]),ot=L([...R,...function(){const e=[],t=(t,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const e of["","h"]){const s=n+e,r="arc"+n+e;e&&(t("Math."+s,s),t("\\"+s,s));for(const n of["^-1","^{-1}","-1"])t("\\"+s+n,r),t(s+n,r),e||t("Math."+s+n,r);e||t("\\a"+s,r),t("\\arc"+s,r),t("Math.a"+s,r),t("Math.arc"+s,r)}return e}()]),at=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=Le(e)),(e=(e=(e=function(e){for(let t=0;t<50;t++){let t=!0;for(const n of e.matchAll(/\bif\b/g)){const s=n.index;let r=0,i=-1,o=e.length;for(let t=s+2;t<e.length;t++)if(ve.includes(e[t]))r++;else{if(ke.includes(e[t])&&--r<0){o=t;break}if(0===r&&","===e[t]){o=t;break}if(0===r&&/^then\b/.test(e.slice(t))&&/\W/.test(e[t-1])){i=-2;break}0===r&&i<0&&/^else\b/.test(e.slice(t))&&/\W/.test(e[t-1])&&(i=t)}if(i<0)continue;r=0;let a=0;for(let t=s-1;t>=0;t--)if(ke.includes(e[t]))r++;else{if(ve.includes(e[t])&&--r<0){a=t+1;break}if(0===r&&","===e[t]){a=t+1;break}}const l=e.slice(a,s).trim();if(!l)continue;const c=`((${e.slice(s+2,i).trim()}) ? (${l}) : (${e.slice(i+4,o).trim()}))`;e=e.slice(0,a)+c+e.slice(o),t=!1;break}if(t)return e}return e}(e=Ve(e=function(e){return e.includes("sorted")?_e(e,/(?<![\w.])sorted\s*\(/g,e=>{if(1!==e.length)return null;const t=e[0];for(let e=0,n=0;e<t.length;e++)if("([{".includes(t[e]))n++;else if(")]}".includes(t[e]))n--;else if(0===n&&("|"===t[e]||"&"===t[e])){const n=e=>{const t=e.trim(),n=/^set\s*\(/.exec(t);return n&&Ee(t,n[0].length-1)===t.length-1?t.slice(n[0].length,-1):null},[s,r]=[n(t.slice(0,e)),n(t.slice(e+1))];return null!==s&&null!==r?`((${s}) ${"|"===t[e]?"∪":"∩"} (${r}))`:null}return null}):e}(e=Ze(e=Ie(e=(e=(e=function(e){for(const[t,n]of Object.entries(we))for(let s=e.lastIndexOf(n);s>=0;s=s>0?e.lastIndexOf(n,s-1):-1){const r=s+n.length,i="("===e[r]?Ee(e,r):-1;if(i<0)continue;let o=e.slice(r+1,i);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===t?`((${o})!)`:`${t}(${o})`;e=e.slice(0,s)+a+e.slice(i+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const n=t+10-1,s=Ee(e,n),r=e.lastIndexOf("Number(",t);s<0||r<0||Ee(e,r+7-1)!==t||(e=e.slice(0,r)+`fixed(${e.slice(r+7,t)}, ${e.slice(n+1,s)})`+e.slice(s+1))}return e.replace(/\(\(\)=>\{let (sum|prod) = [01]; let loopCount = 0; for \(let (\w+)=(.*?);\2<=(.*?);\2\+\+\) \{if \(loopCount\+\+ > 1000000\)\{break\};\1 [+*]= (.*?);\}; return \1;\}\)\(\)/g,(e,t,n,s,r,i)=>`(\\${"sum"===t?"sum":"prod"}_{${n}=${s}}^{${r}} (${i}))`)}(e)).replace(/(?<![\w.])9e999\b/g,"∞")).replace(/(?<![\w.])(\d+(?:\.\d+)?)[eE]([+-]?\d+)(?![\w.])/g,"($1*10^{$2})"))))))).replace(/\b(?:True|TRUE)\b/g,"true").replace(/\b(?:False|FALSE)\b/g,"false").replace(/\b(?:None|NULL)\b/g,"null")).replace(/\^\^/g," \\xor ")).replace(/%(?=\s*(?:[(-]|[A-Za-z_][\w.]*\s*\())/g," \\mod ")):e}],["english",function(e){if(!rt.test(e))return e;let t=e;const n=(e,n,s,r="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Je(e)}\s+(${Xe})\s+(?:and|to)\s+(${Xe})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(e,t,i,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[n,s];return` ${r} ${a}${t}, ${i}${l} `})};n("is not strictly between","(",")","∉"),n("is not between","[","]","∉"),n("is strictly between","(",")"),n("is between","[","]"),n("between","[","]"),t=t.replace(new RegExp(String.raw`(?<![\w.])is\s+(not\s+)?in\s+the\s+(open|closed|half-open)\s+interval\s+from\s+(${Xe})\s+to\s+(${Xe})`,"gi"),(e,t,n,s,r)=>{const[i,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[n.toLowerCase()];return` ${t?"∉":"∈"} ${i}${s}, ${r}${o} `});const s=String.raw`(${Xe})\s+`;t=t.replace(new RegExp(s+String.raw`is\s+(not\s+)?within\s+(${Xe})\s*(%|\s+percent)?\s+of\s+(${Xe})`,"gi"),(e,t,n,s,r,i)=>`(abs((${t}) - (${i})) ${n?">":"≤"} ${r?`(${s})/100 * ${/^\d+(\.\d+)?$/.test(i)?i:`abs(${i})`}`:`(${s})`})`),t=t.replace(new RegExp(s+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${Xe})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(s+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Xe})`,"gi"),(e,t,n,s)=>`((${t}) mod (${s}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${Xe})\s+divides\s+(${Xe})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(s+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,n,s)=>`((${t}) mod 2 ${"even"===s.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[e,n]of st)t=t.replace(Ke(e),` ${n} `);t=t.replace(Ke("is not in")," ∉ ").replace(Ke("is in")," ∈ ").replace(Ke("is an element of")," ∈ ");for(const[e,n]of Ye)t=t.replace(Ke(e),` ${n} `);t=t.replace(Ke("is not")," ≠ "),t=t.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let e=!0;e;){const n=t;t=t.replace(new RegExp(String.raw`(${Xe})\s*(${et})\s*(${Xe})\s+(and|or)\s+(${et})`,"gi"),"$1 $2 $3 $4 $1 $5"),e=t!==n}t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${Xe})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${Xe})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${Xe})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+power\s+of\s+(${Xe})`,"gi"),"($1)^($2)"),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+(${Object.keys(tt).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,s)=>`(${t})^(${tt[n.toLowerCase()]??s})`),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+(${Xe})(?![\w.])`,"gi"),"($1)^($2)");for(const[e,n]of nt)t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Je(e)}\s+of\s+(${Xe})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${Xe})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${Xe})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${Xe})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${Xe})`,"gi"),"2*($1)"),t=t.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const r=e=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${Je(e)}(?=\s+[\w.(\[{-])`,"gi");for(const[e,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(r(e),` ${n} `);return t}],["words",it],["spaced",function(e){e=K(e=function(e){for(let t=0;t<e.length;t++){const n=n=>e.slice(Math.max(0,t-n),t+1);if("t"===e[t]&&"\\text"===n(4)&&"{"===e[t+1]){let n=1,s=t+2,r="";for(;n>0&&s<e.length;)"{"===e[s]?n++:"}"===e[s]?n--:r+=e[s],s++;e=e.slice(0,t-4)+r+e.slice(s)}}return e}(e=(e=(e=function(e){for(let t=0;t<100;t++){const t=[...e.matchAll(/\bif\b/gi)];if(!t.length)return e;const n=t[t.length-1].index,s=V(e,n+2,"then");if(s<0)return e;const r=e.slice(n+2,s),i=V(e,s+4,"else"),o=X(e,i<0?s+4:i+4),a=e.slice(s+4,i<0?o:i),l=i<0?"unchanged":e.slice(i+4,o).trim();e=`${e.slice(0,n)}((${r.trim()}) ? (${a.trim()}) : (${l}))${e.slice(o)}`}return e}(e=function(e){for(let t=e.lastIndexOf("\\sqrt");t>=0;t=t>0?e.lastIndexOf("\\sqrt",t-1):-1){let n=t+5;if(/[A-Za-z]/.test(e[n]??""))continue;for(;T(e[n]);)n++;const s=e.slice(n);let r=/^(?:§\d+§|-?(?:\d+(?:\.\d+)?|\.\d+)|-?[A-Za-zͰ-Ͽ])/.exec(s)?.[0];if(!r&&/^\\[A-Za-z]/.test(s)&&!s.startsWith("\\left")){let e=/^\\[A-Za-z]+/.exec(s)[0].length;if(/^\d\d/.exec(s.slice(e))&&/frac$/.test(s.slice(0,e)))e+=2;else{const t=/^\s*\[[^\[\]{}]*\]/.exec(s.slice(e));for(t&&(e+=t[0].length);;){let t=e;for(;T(s[t]);)t++;if("{"!==s[t])break;let n=0,r=-1;for(let e=t;e<s.length;e++)if("{"===s[e])n++;else if("}"===s[e]&&0===--n){r=e;break}if(r<0)break;e=r+1}}r=s.slice(0,e)}r&&(e=`${e.slice(0,t)}\\sqrt{${r}}${e.slice(n+r.length)}`)}return e}(function(e){return e=e.replace(U,(e,t,n)=>`(${t}+${D[n]})`),e=e.replace(B,(e,t,n,s)=>Number(n)<Number(s)&&3!==n.length?`(${t}+${n}/${s})`:e),e.replace(G,(e,t,n,s,r,i)=>{const[o,a]=[n??r,s??i];return Number(o)<Number(a)?`(${t}+\\frac{${o}}{${a}})`:e})}(function(e){return e.replace(W,e=>{const t=e[0]in P;return`${t?"^":"_"}{${[...e].map(e=>(t?P:F)[e]).join("")}}`})}(e))))).replace(/\(\s*\\?b?mod\s+([^()\s](?:[^()]*[^()\s])?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")));for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=J(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}const s=("^"===e[t]||/[A-Za-z}]/.test(e[t-1]??""))&&/^\\[A-Za-z]+(?![A-Za-z{\d])/.exec(e.slice(t+1));if(s){e=`${e.slice(0,t+1)}{${s[0]}}${e.slice(t+1+s[0].length)}`;continue}let r=t+1;for("-"===e[r]&&r++;r<e.length&&".0123456789".includes(e[r]);)r++;if(r===t+2&&"-"===e[t+1]&&(r=t+1),"-"===e[t+1]&&/^\s*[\^!]/.test(e.slice(r,r+8)))continue;r>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,r)+"}"+e.slice(r))}return e}],["squeeze",function(e){return e.replace(/\s+/g,(t,n)=>{const s=e[n-1]??"",r=e[n+t.length]??"";return"Δ"===s?"":/[A-Za-z\u0370-\u03FF′]/.test(s)&&/[A-Za-z\u0370-\u03FF]/.test(r)?" ":""})}],["symbols",ot],["bar",function(e){let t=0;for(let n=e.indexOf(d,t);n>=0;n=e.indexOf(d,t)){let s=0,r=-1;for(let t=n+1;t<e.length;t++)if("([{".includes(e[t]))s++;else if(")]}".includes(e[t]))s--;else if(0===s&&e.startsWith("|_",t)){r=t;break}r<0&&lt(),e=`${e.slice(0,n+1)}(${e.slice(n+1,r)})${e.slice(r)}`,t=n+1}return e}],["compact",function(e){if(e=function(e){for(let t=0;t<e.length;t++){const n=t>0&&ae.test(e[t-1]);let s,r=null,i=t;if(e.startsWith("frac{",t)){const n=le(e,t+4),s=n&&le(e,n[1]);r=s&&he(n[0],s[0]),r&&(i=s[1])}else if("d"===e[t]&&!n){let[n,s]=ce(e,t+1),o="";if(ae.test(e[s]??"")&&"/"===e[s+1]&&(o=e[s++]),"/"===e[s]&&"d"===e[s+1]&&ae.test(e[s+2]??"")){const t=e[s+2],[,a]=ce(e,s+3);r={n:n,of:o,by:t},i=a}}if(r){if(r.of)s=pe(r.of,r.by,r.n);else{const[t,n]=ue(e,i);if(!t)continue;s=pe(t,r.by,r.n),i=n}e=e.slice(0,t)+s+e.slice(i),t+=3}}return e}(e=function(e){for(let t=e.indexOf(")′");t>=0;t=e.indexOf(")′",t+1)){let n=0,s=-1;for(let r=t;r>=0;r--)if(")"===e[r])n++;else if("("===e[r]&&0===--n){s=r;break}if(s<0)continue;for(;s>0&&/[A-Za-z\u0370-\u03FF′]/.test(e[s-1]);)s--;let r=0;for(;"′"===e[t+1+r];)r++;e=e.slice(0,s)+pe(e.slice(s,t+1),"x",r)+e.slice(t+1+r),t=s}return e}(e=(e=K(e)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}"))),e.split("\\int").length>101)throw new Error("More than 100 integrals");for(let t=0;t<e.length;t++){const n=e[t],s=n=>e.slice(Math.max(0,t-n),t),r=n=>e.slice(Math.max(0,t-n),t+1);if("{"===n){if("\\begin"===s(6)){const n=ne(e.slice(t+1));n&&(e=e.slice(0,t-6)+n)}}else if("["===n)"\\sqrt"===s(5)?e=e.slice(0,t-5)+"sqrt"+ee(e.slice(t+1)):"sqrt"===s(4)&&(e=e.slice(0,t-4)+"sqrt"+ee(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+Y(e.slice(t));else if("t"===n)"\\int"===r(3)&&(e=e.slice(0,t-3)+re(e.slice(t+1)));else if("m"===n)"\\binom"===r(5)&&(e=e.slice(0,t-5)+"\\binom"+oe(e.slice(t+1)));else if("d"===n&&"dd"===r(1)&&"("===e[t+2]){const n=ie(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return(e=e.replace(/\\(?:text|textrm|textit|mathrm|mathit|mathbf|mathsf|operatorname)\{([A-Za-z])\}/g,"$1")).replace(/\\log/g,"log")}],["bars",function(e){for(let t=e.indexOf(d);t>=0;t=e.indexOf(d)){const n=lt;e.startsWith("(der(",t+1)||n();const s=ct(e,t+1,"(",")"),r=ct(e,t+5,"(",")");(r<0||s!==r+1)&&n();const i=ht(e.slice(t+6,r));(i.length<2||i.length>3||!e.startsWith("|_",s+1))&&n();const o=s;let a,l;"{"===e[o+3]?(l=ct(e,o+3,"{","}"),l<0&&n(),a=e.slice(o+4,l)):(l=o+3,a=e[l]??"");const[c,h,u]=i;a.trim()||n();const p=a.includes("=")?a:`${h}=${a}`;e=`${e.slice(0,t)}der(${c},${p}${u?`,${u}`:""})${e.slice(l+1)}`}return e}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]],lt=()=>{throw new Error("An evaluation bar (\\left. … \\right|_{x = a}) is read only after a derivative: \\left.\\frac{d}{dx} f\\right|_{x=a}")};function ct(e,t,n,s){let r=0;for(let i=t;i<e.length;i++)if(e[i]===n)r++;else if(e[i]===s&&0===--r)return i;return-1}function ht(e){const t=[];let n=0,s=0;for(let r=0;r<e.length;r++)"([{".includes(e[r])?n++:")]}".includes(e[r])?n--:","===e[r]&&0===n&&(t.push(e.slice(s,r)),s=r+1);return t.push(e.slice(s)),t}function ut(e,t={}){if("string"!=typeof e)throw new Error("Expression must be a string");const{text:n,strings:s}=function(e){const t=new Map;let n="",s=0;for(;s<e.length;){const r=e[s];if('"'!==r&&"'"!==r&&"`"!==r){n+=e[s++];continue}let i=s+1,o="",a=!1;for(;i<e.length&&(a||e[i]!==r);)a=!a&&"\\"===e[i],o+=e[i++];const l=me(t.size);t.set(l,r+o+r),n+=l,s=i+1}return{text:n,strings:t}}($e(e));let r=n.replace(/\t/g," ");t.evaluate&&(r=function(e,t,n){const s=/\\[A-Za-z]/.test(e);let r=0;for(;;){let i=e.indexOf("{{",r);if(i<0)return e;let o=!1;const a=s&&pt.test(e.slice(0,i));if(ft(e,i)||a&&"{"===e[i+2]?i+=1:o=a,!e.startsWith("{{",i)){r=i;continue}const l=dt(e,i);if(l<0)return e;let c=e.slice(i+2,l).trim();for(const[e,n]of t)c=c.split(e).join(n);try{let s=n(c);if(/^["'`]/.test(s)){const e=me(t.size);t.set(e,s),s=e}const a=e.slice(0,i).trimEnd(),h=e.slice(l+2).trimStart();/^[\d.]/.test(s)&&(/[\d.]$/.test(a)||/^[\d.]/.test(h))&&(s=`(${s})`),o&&(s=`{${s}}`),e=e.slice(0,i)+" "+s+" "+e.slice(l+2),r=i+1+s.length}catch{r=l+2}}}(r,s,t.evaluate));const i=[["strings",r]];for(const[e,t]of at){if(r=t(r),r.length>1e5)throw new Error("The expression expands too much when read");i.push([e,r])}return{cleaned:r,stringMap:s,steps:i}}const pt=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function ft(e,t){let n=0;for(;"\\"===e[t-1-n];)n++;return n%2==1}function dt(e,t){let n=0;for(let s=t+2;s<e.length;s++){if(e.startsWith("}}",s)&&0===n)return s;"{"===e[s]?n++:"}"===e[s]&&n--}return-1}const mt={alpha:"α",beta:"β",gamma:"γ",delta:"δ",epsilon:"ε",zeta:"ζ",eta:"η",theta:"θ",iota:"ι",kappa:"κ",lambda:"λ",mu:"μ",nu:"ν",xi:"ξ",omicron:"ο",pi:"π",rho:"ρ",sigma:"σ",tau:"τ",upsilon:"υ",phi:"φ",chi:"χ",psi:"ψ",omega:"ω",Alpha:"Α",Beta:"Β",Gamma:"Γ",Delta:"Δ",Epsilon:"Ε",Zeta:"Ζ",Eta:"Η",Theta:"Θ",Iota:"Ι",Kappa:"Κ",Lambda:"Λ",Mu:"Μ",Nu:"Ν",Xi:"Ξ",Omicron:"Ο",Pi:"Π",Rho:"Ρ",Sigma:"Σ",Tau:"Τ",Upsilon:"Υ",Phi:"Φ",Chi:"Χ",Psi:"Ψ",Omega:"Ω"};function gt(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function $t(e){const t="string"==typeof e&&/^(-?)(\d*)(?:\.(\d*))?%$/.exec(e);if(!t||!t[2]&&!t[3])return null;const n=(t[2]||"0").padStart(3,"0")+(t[3]??""),s=n.length-(t[3]??"").length-2,r=`${n.slice(0,s).replace(/^0+(?=\d)/,"")}.${n.slice(s)}`.replace(/\.?0+$/,"");return t[1]+(""===r?"0":r)}function xt(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==gt(n)}function yt(e){return"op"!==e.type||o(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":xt(e)?"neg":e.op}const bt=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),wt=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!bt.has(e.op))&&c(e.op,yt(t),n);function vt(e,t){const n=yt(t),s=n&&o(n)?.prec;return s?"!"===e?s<=o("!").prec:"\\not"===e?s<o("\\not").prec:s<70||qt(t)||"\\not"===n:"\\not"!==e&&qt(t)}function kt(e,t,n={}){const s=n.left?"bracket":At(e),r=n.right?"bracket":_t(t);return"digit"!==r&&"sign"!==r&&"word"!==s&&"word"!==r&&"other"!==s&&("frac"!==r||"digit"!==s&&"frac"!==s)}function Et(e){return 1===e.length||Boolean(mt[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function Mt(e){return"op"===e.type&&!o(e.op)?.group&&(o(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function _t(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&Et(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||xt(e)?"sign":"/"===t?"frac":o(t)?.group||Mt(e)?"bracket":Ot(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?Mt(e.args[0])?"bracket":_t(e.args[0]):["*","sum","prod","perm"].includes(t)?_t(e.args[0]):"other"}function At(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&Et(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":o(t)?.group||Mt(e)||Ot(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?At(e.args[e.args.length-1]):"other"}function Ot(e){if("op"!==e.type)return!1;const t=o(e.op);return"prefix"===t?.fixity&&100===t.prec}function qt(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||xt(e))return!0;const t=o(e.op);return"infix"===t?.fixity&&!wt(e,e.args[0],"left")&&qt(e.args[0])}const Nt=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),St=e=>e.slice(2);function Lt(e){const t="op"===e.args[1].type&&"="===e.args[1].op?e.args[1]:null,n=t?t.args[0]:e.args[1],s=t?t.args[1]:null;let r=1,i=e.args[0];for(;"op"===i.type&&"der"===i.op&&zt(i.args[1],n);)r++,i=i.args[0];return{n:r,body:i,by:n,at:s,variable:"symbol"===i.type&&Et(i.value)}}const zt=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,Ct=new Set(["<",">","≤","≥","=","===","≠","≠=","&","|","\\not","\\xor","\\nand","\\nor","∈","∉","≈","≡"]);function It(e){return"op"===e.type&&(!!("="===e.op&&(t=e.args[1],"op"===t.type&&Ct.has(t.op)||"symbol"===t.type&&("true"===t.value||"false"===t.value)))||e.args.some(It));var t}const Rt=new Set(["<",">","≤","≥","=","≠"]);function Tt(e){if("op"!==e.type||!Rt.has(e.op)||2!==e.args.length)return null;const[t,n]=e.args;if("op"!==t.type||!Rt.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[Tt(t)??t,{type:"op",op:e.op,args:[t.args[1],n]}]}}for(const e of[mt])Object.setPrototypeOf(e,null);function jt(e){if(e.length>1e6)throw new Error("The output would be too long");return e}const Zt={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function Pt(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(Zt,e.op))return e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args:[e]);if("[]"!==e.op||!e.args.length||!e.args.every(e=>"op"===e.type&&"[]"===e.op))return null;const t=e.args[0].args.length;return!t||!e.args.every(e=>e.args.length===t)||e.args.length<2&&t<2?null:e.args.map(e=>e.args)}const Ft=Object.keys(m).filter(e=>100===m[e]&&/^[a-z]{2,}$/.test(e)),Wt=["frac"],Dt=[...Object.keys(mt),"pi","tau","inf","infinity","exp"],Ut="\n cost costs coast cosine cosines cosy sine sines since sincere sinus single\n tank tanks tango stand stank\n point points print prints paint paints pint pints mint hint hints lint tint saint faint joint into\n spin spine pipe pipes pine pines pick picks pink pity pie pies pilot pivot pixel pizza piano\n order orders under wonder border render older elder ladder cider rider wider bidder\n logic logo logs blog clog login slog\n model models mode modes modal modest modern module modules\n limb limbs slim lime limo limit limits climb\n maxi minute minutes mince mind mine mines\n sums sumo summit rounds floors ceils means meant sect sects secs expo kiln\n meta metal metals taxi must mute muse nut nuts\n".trim().split(/\s+/),Bt=new Set([...Dt,...Ut,"true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),Gt=/^[a-zA-ZͰ-Ͽ]$/,Ht=new Set(["f","g","h","u","v","F","G","H"]),Qt=e=>Ft.includes(e)||Wt.includes(e),Vt=[...Ft,...Wt,...Dt].sort((e,t)=>t.length-e.length),Xt=[...Ft,...Wt,"pi"].sort((e,t)=>t.length-e.length);function Jt(e,t=Vt){const n=[];let s=0;for(;s<e.length;){const r=t.find(t=>e.startsWith(t,s))??e[s];n.push(r),s+=r.length}return n}function Kt(e){if(Qt(e))return!0;const t=Jt(e,Xt);return t.length>1&&Qt(t[t.length-1])&&!Bt.has(e)}function Yt(e,{mode:t="plain",followed:n=!0}={}){if(e.includes("′")&&/^[a-zA-Z′]+$/.test(e)&&!/^.′+$/.test(e))return e.match(/[a-zA-Z]′*/g);if(!((s=e).length>0&&[...s].every(e=>Gt.test(e)))||1===e.length||Bt.has(e)||Qt(e))return[e];var s;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return en(Jt(e),n);if(e.length<=2)return[...e];const r=en(Jt(e,Xt),n),i=r.findIndex(e=>e.length>1);if(i<0)return[e];if("pi"===r[i]&&!r.some(e=>Ft.includes(e)))return 3===e.length?r:[e];const o=i;let a=0,l=0;for(const e of r.slice(i))a=1===e.length?a+1:0,l=Math.max(l,a);return o<=1&&l<=2?r:[e]}function en(e,t){const n=e[e.length-1];return t||!Ft.includes(n)?e:[...e.slice(0,-1),...n]}const tn="§",nn=/[A-Za-zͰ-Ͽ′]/,sn=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function rn(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let s="";const i=e=>{s&&(sn(s)?n.push(...function(e,t,n){if((e=>ge.test(e))(e))return[e];if(x.includes(t))return function(e,t){if(/^[a-zA-Z]′+$/.test(e))return[r+e];if("if"===e.toLowerCase())return["\\:if"];if(1===e.length)return Ht.has(e)?[r+e]:[e];if(g(e))return[e];const n=Yt(e,{mode:t,followed:!0});return n.length>1?n:e.length<=2?[...e]:[r+e]}(e,n);const s=void 0!==t&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(t);return Yt(e,{mode:n,followed:s})}(s,e,t)):n.push(s),s="")};for(let t=0;t<e.length;t++){const o=e[t];if(o===tn){i(o);const s=e.indexOf(tn,t+1);if(s<0)throw new Error(`An unmatched ${tn}`);const a=e.slice(t,s+1);n.push(x.includes(e[s+1])?r+a:a),t=s;continue}if(sn(s)&&/[0-9]/.test(o)&&g(s+o)){const{op:r,end:i}=on(e,t,s+o);n.push(r),s="",t=i;continue}if(nn.test(o)&&"′"!==o&&b(s)&&(n.push(s),s=""),nn.test(o)&&(""===s?"′"!==o:sn(s)))s+=o;else if(/[0-9]/.test(o)&&sn(s)&&!Kt(s))s+=o;else if(sn(s)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))s&&n.push(...an(s,o)),s="",n.push(o);else if("_"!==o&&" "!==o){if(g(s+o)){const{op:r,end:i}=on(e,t,s+o);n.push(r),s="",t=i;continue}if(g(o)){i(o);const{op:s,end:r}=on(e,t,o);n.push(s),t=r;continue}s+=o}else i(e[t+1]),"_"===o&&n.push("_")}if(i(void 0),n.some(e=>/^:/.test(e)))throw new Error("Unmatched ':'");return n}function on(e,t,n){let s=t;for(;s+1<e.length&&g(n+e[s+1]);)n+=e[s+1],s++;return"!"===n&&"_"===e[s+1]&&s++,{op:n,end:s}}function an(e,t){if(!x.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[g(t)?t:r+t]}return b(e)?[e,"*"]:g(e)||Qt(e)||b(e[0])?[e]:[r+e]}const ln=70,cn=100,hn="%mod",un=e=>x.includes(e),pn=e=>y.includes(e),fn=e=>i(e)||m[e]===cn&&"_"!==e,dn=new Set(["\\comb","\\perm","comb","perm"]),mn={frac:"/","\\binom":"\\binom"},gn=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","∈","∉","true","false"]),$n={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class xn{constructor(e){this.tokens=e,this.pos=0,this.out=[],this.absDepth=0,this.frames=[]}peek(e=0){return this.tokens[this.pos+e]}next(){return this.tokens[this.pos++]}emit(...e){this.out.push(...e)}parseAll(){if(!this.tokens.length)throw new Error("Empty expression");this.parseExpression(0);const e=this.peek();if(void 0!==e)throw new Error(pn(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){this.parseOperand(),this.absorb(e,t)}absorb(e,t=!1){for(;;){const n=this.peek();if(void 0===n||pn(n))return;const s=this.operatorAt(n,t);if(!s||s.lbp<=e)return;s.run()}}operatorAt(e,t){if("|"===e)return this.pipe();if(","===e)return{lbp:5,run:()=>{this.next(),this.frames.length&&(this.frames[this.frames.length-1].comma=!0),this.parseExpression(5),this.emit(",")}};if("?"===e)return{lbp:9,run:()=>this.ternary()};if("mod"===e)return{lbp:m.mod,run:()=>this.modulo()};if(e===hn)return{lbp:ln,run:()=>{this.next(),this.parseExpression(ln),this.emit("mod")}};if("pmod"===e)return{lbp:m.pmod,run:()=>{this.next(),this.parseScript(),this.emit("pmod")}};if("?:"===e)return{lbp:10,run:()=>{throw new Error("Unmatched ':'")}};if("!"===e)return{lbp:90,run:()=>{this.next(),this.emit("!")}};if("_"===e)return{lbp:cn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(dn.has(e))return{lbp:cn,run:()=>{this.next(),this.parseExpression(cn),this.emit(e)}};const n=m[e];if("="===e&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!fn(e)&&"\\not"!==e&&!(e in mn)){const t=$.has(e)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:t&&!fn(e)?71:ln,run:()=>{this.parseExpression(ln),this.emit("*")}}}startsOperand(e){return void 0===e||pn(e)||"|"===e?"|"===e:e!==hn&&(!!(un(e)||fn(e)||e in mn)||!g(e))}pipe(){if(this.absDepth>0)return null;let e=0;for(let t=this.pos;t<this.tokens.length;t++)"|"===this.tokens[t]&&e++;const t="|"===this.peek(1);return e%2==0&&!t&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:m["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(m["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(ln,!0),this.emit("mod")}equals(e){this.next(),this.parseExpression(e),gn.has(this.out[this.out.length-1])&&this.questionAhead()&&this.absorb(8),this.emit("=")}questionAhead(){let e=0;for(let t=this.pos;t<this.tokens.length;t++){const n=this.tokens[t];if(un(n))e++;else if(pn(n)){if(0===e--)return!1}else{if(0===e&&","===n)return!1;if(0===e&&"?"===n)return!0}}return!1}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const e=this.next(),t=this.tokens[this.pos-2],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(un(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||pn(n))||un(t)&&pn(n)?this.emit("\\"+e):"+"===e?this.parseExpression(75):this.negate()}if("±"===e)return this.parseExpression(75),this.emit("pm");if("!"===e||"\\not"===e)return this.parseExpression(85),this.emit("\\not");if(e in mn)return this.parseScript(),this.parseScript(),this.emit(mn[e]);if("log"===e)return this.logarithm();if("lim"===e&&"_"===n)return this.limit();if(("\\sumidx"===e||"\\prodidx"===e)&&"_"===n)return this.bigOperator(e);if(fn(e))return this.functionCall(e);if(e===hn)throw new Error("'%' is missing an operand");if(pn(e)||g(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!b(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(pn(this.peek()))return void this.emit("∅",e+this.next());this.frames.push({comma:!1}),this.parseExpression(0);const{comma:n}=this.frames.pop(),s=this.peek();pn(s)&&(this.next(),n?this.emit(e+s):t&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const e=this.peek();if(un(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(fn(e))return this.parseOperand();if(this.next(),void 0===e||pn(e)||g(e))throw new Error("Missing a sub- or superscript");this.emit(e)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const e=this.out.length;this.parseScript();const t=this.out.splice(e);this.parseExpression(m["+"],!0),this.emit(...t,",","()","lim")}bigOperator(e){this.next();const t=this.out.length;this.parseScript();let n=this.out.splice(t);"^"===this.peek()&&(this.next(),this.parseScript(),n=[...n,...this.out.splice(t),","]),this.parseExpression(m["+"],!0),this.emit(...n,",","()",e)}functionCall(e){if(void 0===this.peek())return this.emit(e);let t=null;if("^"===this.peek()){this.next();const e=this.out.length;this.parseScript(),t=this.out.splice(e)}if(0===o(e)?.arity&&!un(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(un(e))return this.next(),this.bracket(e);this.parseExpression(ln,!0)}}function yn(e,t){e=function(e){const t=[];for(let n=0;n<e.length;n++){const s=e[n],i=e=>"string"==typeof e&&/^[a-zA-Z]$/.test(e);if(Ht.has(s)&&"^ { - 1 } ("===e.slice(n+1,n+7).join(" ")){t.push(r+s+"⁻¹"),n+=5;continue}const[o,a,l]=e.slice(n+1,n+4),c=i(a)?a!==s:b(a);i(s)&&"e"!==s&&"("===o&&c&&")"===l?t.push(r+s):t.push(s)}return t}(e);const n=[];for(const s of e)g(s)||un(s)||pn(s)||"_"===s||i(s)||b(s)?n.push(s):n.push(...bn(s,t));return n}function bn(e,t){if("%"===e)return[hn];if(!e.includes("%"))return wn(e,t);const n=e.split("%");n.length>1&&""===n[n.length-1]&&(n.pop(),n[n.length-1]+="%");const s=[];return n.forEach((e,n)=>{n>0&&s.push(hn),""!==e&&s.push(...wn(e,t))}),s}function wn(e,t){let n=0;for(;n<e.length&&b(e.slice(0,n+1));)n++;if(0===n||n===e.length)return[e];const s=e.slice(n);return"%"===s?[e]:[e.slice(0,n),...(r=s,yn(rn(r,t),t))];var r}for(const e of[mn,$n])Object.setPrototypeOf(e,null);const vn=new Set(["()","[]","{}","(]","[)"]),kn={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(f).map(e=>[e,"*"]))},En=new Set(["round","fixed","der"]),Mn=e=>i(e)||100===m[e];function _n(t){const n=[],s=e=>{if(!n.length)throw new Error(`'${e}' is missing an operand`);return n.pop()},r=e=>e.list?e.list:[e],i=(e,t)=>{if(e.list)throw new Error(`A list of values needs brackets around it (near '${t}')`);return e};if(t.forEach((a,l)=>{if("∅"===a)return void n.push({list:[]});if(","===a){const e=s(a),t=s(a);return void n.push({list:[...r(t),...r(e)]})}if(vn.has(a)){const e=r(s(a));if(!e.length&&!Mn(t[l+1]))throw new Error("Empty brackets");return void n.push(k(a,e))}const c=kn[a]??a,h=o(c);if(!h){if("?"===a||"abs("===a)throw new Error(`Unmatched '${a[0]}'`);return void n.push(M(a))}let u;if(Mn(a)&&vn.has(t[l-1])&&n[n.length-1]?.op===t[l-1])u=n.pop().args;else{let t=h.arity===e||En.has(c)?1:h.arity;if(n.length<t)throw new Error(`'${a}' needs ${t} operand${1===t?"":"s"}`);u=n.splice(n.length-t,t).map(e=>i(e,a))}const p=function(e,t){switch(e){case"sqrt":if(2===t.length)return k("root",t);break;case"round":if(1===t.length)return k("round",[t[0],w(0)]);break;case"sum":case"prod":{const n=t[1];if("op"===n?.type&&"symbol"===n.args[0]?.type&&(3===t.length&&"="===n.op||2===t.length&&"∈"===n.op))return k("sum"===e?"\\sumidx":"\\prodidx",t);break}case"det":if(t.length>1&&t.every(e=>"op"===e.type&&"[]"===e.op))return k("det",[k("[]",t)]);break;case"fixed":if(1===t.length)return k("fixed",[t[0],w(2)]);break;case"der":if(1===t.length)return k("der",[t[0],v("x")]);if(3===t.length)return function([e,t,n]){const s="number"===n.type?Number(n.value):NaN;if(!Number.isInteger(s)||s<1||s>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");const r="op"===t.type&&"="===t.op?t:null,i=r?r.args[0]:t;let o=e;for(let e=0;e<s;e++)o=k("der",[o,r&&e===s-1?r:i]);return o}(t);break;case"log":if(2===t.length&&"symbol"===t[0].type&&"e"===t[0].value)return k("ln",[t[1]]);break;case"lim":return On(e,t),k("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?An[e.args[1].value]:void 0,[n,s,r]=e;if(2===e.length&&"op"===s.type&&"→"===s.op&&t(s.args[1])){const[e,r]=s.args;return[n,e,r.args[0],v(t(r))]}return 3===e.length&&t(r)?[n,s,r.args[0],v(t(r))]:e}(t));case"\\:if":if(2===t.length||3===t.length)return k("?:",[t[0],t[1],t[2]??v("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return On(e,t),k(e,t)}(c,u);f[a]&&"*"===p.op&&(p.written=f[a]),n.push(p)}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return i(n[0],"end")}const An={"\\+":"r","\\-":"l"};function On(t,n){const{arity:s}=o(t);if(s!==e){if(n.length!==s){throw new Error(`'${t}' takes ${s} argument${1===s?"":"s"}, not ${n.length}`)}}else if(0===n.length&&!i(t))throw new Error(`'${t}' needs at least one argument`)}for(const e of[kn,An])Object.setPrototypeOf(e,null);const qn=new RegExp(`[${Object.keys(f).join("")}]`,"g"),Nn=e=>e.replace(qn,"*"),Sn=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Ln=e=>/^[a-z][a-z0-9]*$/.test(e)&&g(e);function zn(e){return e.includes("\\")?(e=function(e){for(let t=0;t<50;t++){const t=e.lastIndexOf("\\begin{cases}"),n=t<0?-1:e.indexOf("\\end{cases}",t);if(n<0)return e;const s=Q(e.slice(t+13,n),"\\\\").map(e=>Q(e,"&")).filter(e=>e.join("").trim());let r=null;for(let e=s.length-1;e>=0;e--){const t=s[e][0].trim(),n=H(s[e].slice(1).join("&"));r=null!==r||n?`((${n||"true"}) ? (${t}) : ${r??"(unchanged)"})`:`(${t})`}e=e.slice(0,t)+(r??"")+e.slice(n+11)}return e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):e}function Cn(e){In=e}let In=null;function Rn(e,t={}){const n={original:e};try{if("string"!=typeof e)throw new Error("Expression must be a string");const s=t.maxLength??5e3;if(e.length>s)throw new Error(`Longer than ${s} characters (options.maxLength)`);if(e.includes(""))throw new Error("The character U+E000 can't be read: MathZetta uses it to hold § in strings");if((e=function(e,t,n){if(!e.includes(t))return e;const s=$e(e);let r="";for(let i=0;i<s.length;i++){const o=s[i];if('"'===o||"`"===o||"'"===o){const o=xe(s,i);r+=e.slice(i,o+1).replaceAll(t,n),i=o}else r+=e[i]}return r}(e,tn,"")).includes(tn))throw new Error(`The character ${tn} can't be read: MathZetta uses it to mark names`);const r=/^\s*=(?!=)/.test(e);r&&(e=e.replace(/("(?:[^"]|"")*")|\$(?=[A-Za-z]{0,3}\d|[A-Za-z]{1,3}\$?\d)/g,(e,t)=>t??""));const i=r?[...new Set(e.replace(/"(?:[^"]|"")*"/g,"").match(/(?<![\w.])[A-Za-z]{1,3}\d+(?::[A-Za-z]{1,3}\d+)?(?![\w.(])/g)??[])]:[],{text:o,protectedNames:a}=function(e,t=[],n=[]){const s=new Map,r=new Map,i=e=>{let t=r.get(e);return void 0===t&&(t=`${tn}${s.size}${tn}`,s.set(t,e),r.set(e,t)),t};e=e.replace(Sn,(e,t)=>Ln(t.trim())?` ${t.trim()}`:i(t.trim()));for(const n of[...t].sort((e,t)=>t.length-e.length)){const t=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${t}(?![A-Za-z0-9_])`,"g"),()=>i(n))}for(const t of[...n].sort((e,t)=>t.length-e.length)){const n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(e,n,s)=>i(t)+(s?" * (":n))}return{text:e,protectedNames:s}}(zn(e),t.names,[...t.values??[],...i]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=function(e,t={}){const n=void 0===t.blocks?In:t.blocks;return ut(e,{evaluate:n?e=>n(e,t.scope):void 0})}(o,{blocks:t.blocks,scope:t.scope}),p=e=>be(be(e,h),a).map(e=>"string"==typeof e?e.replaceAll("",tn):e);n.mode=l,n.cleaned=Nn(p([c])[0]),n.cleanSteps=u.map(([e,t])=>[e,Nn(t)]);const f=rn(c,l);n.tokens=f.map(Nn);const d=p(function(e,t="plain"){return new xn(yn(e,t)).parseAll().map(e=>$n[e]??e)}(f,l));n.rawPostfix=d.map(Nn);const m={},g=O(_n(d),m);n.postfix=g,n.written=m,n.tree=A(g),Object.keys(m).length&&N(n.tree,e=>{m[e.id]&&(e.written=m[e.id])})}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}const Tn=e=>"string"==typeof e&&e.length>80?`${e.slice(0,77)}…`:e;function jn(e,t={}){const n=Rn(e,t);if(t.keepIntermediateSteps)return n;if(!n.error)return n.postfix;if(t.allowUnvalidated&&n.rawPostfix)return n.rawPostfix;throw new Error(`Failed to parse expression "${Tn(e)}": ${n.error}`)}function Zn(e,t={}){const n=Rn(e,t);if(n.error)throw new Error(`Failed to parse expression "${Tn(e)}": ${n.error}`);return n.tree}const Pn=(e,t)=>"string"==typeof e?Zn(e,t):q(e),Fn=e=>Array.isArray(e)&&0===e.length,Wn=e=>"op"===e.type&&i(e.op)&&["vec","hat"].includes(St(e.op)),Dn={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",dot:"dot",cross:"cross",vector:"vector",hat:"hat",at:"at",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",matrix:(e,t)=>`the ${e} by ${t} matrix`,row:e=>`row ${e}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},Un={sin:"sine",cos:"cosine",tan:"tangent",csc:"cosecant",sec:"secant",cot:"cotangent",sinh:"hyperbolic sine",cosh:"hyperbolic cosine",tanh:"hyperbolic tangent",arcsin:"inverse sine",arccos:"inverse cosine",arctan:"inverse tangent",arcsinh:"inverse hyperbolic sine",arccosh:"inverse hyperbolic cosine",arctanh:"inverse hyperbolic tangent",ln:"the natural log",log:"log",loglog:"the log of the log",logloglog:"the log of the log of the log",expm1:"e to the power, minus 1, of",max:"the maximum",min:"the minimum",gcd:"the greatest common divisor",mean:"the mean",det:"the determinant",atan2:"the arctangent",round:"round",fixed:"fixed",random:"random"},Bn=Object.fromEntries(Object.entries(mt).map(([e,t])=>[t,e]));function Gn(e,t={}){return Qn(function(e,t={}){return Hn(e,t,!0)}(e,t))}function Hn(e,t,n){return function(e){let t=e.length;for(;t>0&&(e[t-1].close||!e[t-1].text.replace(/,/g,"").trim());)t--;const n=[];for(const{text:s,id:r}of e.slice(0,t)){const e=s.trim();if(!e)continue;const t=e.startsWith(","),i=t?e.slice(1).trim():e;t&&n.length&&!n[n.length-1].text.endsWith(",")&&(n[n.length-1].text+=","),i&&n.push({text:i,id:r})}n.length&&(n[n.length-1].text=n[n.length-1].text.replace(/,$/,""));return n}(new Jn({...Dn,...t.words},{...Un,...t.names},t.say||{},n).speak(e))}function Qn(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const Vn={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},Xn={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class Jn{constructor(e,t,n,s=!1){this.w=e,this.names=t,this.say=n,this.audio=s}speak(e){const t=this.say["op"===e.type?e.op:e.type];if(t){return[{text:t("op"===e.type?e.args.map(e=>Qn(this.speak(e))):[e.value],e,e=>Qn(this.speak(e))),id:e.id}]}return"number"===e.type?[this.seg(e,this.number(e.value))]:"string"===e.type?[this.seg(e,e.value.slice(1,-1))]:"symbol"===e.type?[this.seg(e,this.symbol(e.value))]:this.operation(e)}seg(e,t){return{text:t,id:e.id}}number(e){const t=this.w;return e.endsWith("..")?`${e.replace(/\.+$/,"")} ${t.repeating}`:e.startsWith("-")?`${t.negative} ${e.slice(1)}`:e}symbol(e){const t=this.w;if("∞"===e)return t.infinity;if("-∞"===e)return`${t.negative} ${t.infinity}`;if("pi"===e||"π"===e)return t.pi;if("tau"===e||"τ"===e)return"tau";if("\\+"===e)return t.plus;if("\\-"===e)return t.minus;if("°"===e)return t.degrees;if(Xn[e])return t[Xn[e]];if(Bn[e])return Bn[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=l(e.op);return void 0!==t&&t<=50&&!o(e.op).group}quantity(e,t="endQuantity"){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}grouped(e,t,n){return this.isCompound(e)||this.audio&&n?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[s,r]=n,o=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(o.comma),...this.listed(e)]:this.listed(e));if(Vn[t])return[...this.speak(s),a(o[Vn[t]]),...this.speak(r)];if(i(t)){if(1===n.length&&"symbol"===s.type&&"vec"===St(t))return[a(o.vector),...this.speak(s)];if(1===n.length&&"symbol"===s.type&&"hat"===St(t))return[...this.speak(s),a(o.hat)];const e=this.symbol(St(t));return n.length?[a(`${e} ${o.of}`),...this.arguments(n)]:[a(e)]}if(this.names[t]&&!["log","round","fixed","atan2","random","expm1"].includes(t))return[a(`${this.names[t]} ${o.of}`),...this.arguments(n)];switch(t){case"+":return xt(r)?[...this.leftSide(s),a(o.minus),...this.quantityIfSum(r.args[1])]:[...this.leftSide(s),a(o.plus),...this.speak(r)];case"-":return xt(r)?[...this.leftSide(s),a(o.plus),...this.speak(r.args[1])]:[...this.leftSide(s),a(o.minus),...this.quantityIfSum(r)];case"*":return this.product(e);case"/":return this.fraction(e);case"^":return this.power(e);case"_":return[...this.speak(s),a(o.sub),...this.audio?this.grouped(r,"endSub","op"===r.type):this.speak(r)];case"neg":return this.isCompound(s)||"op"===s.type&&"neg"===s.op?[a(`${o.negative} ${o.quantity}`),...this.speak(s),...this.closer(s,"endQuantity")]:[a(o.negative),...this.speak(s)];case"pm":return[a(o.plusOrMinus),...this.speak(s)];case"!":return[...this.grouped(s,"endQuantity","op"===s.type||"number"===s.type&&s.value.startsWith("-")),a(o.factorial)];case"\\not":return[a(o.not),...this.quantity(s)];case"sqrt":return[a(o.squareRoot),...this.contents(s,"endRoot")];case"root":{const e="number"===s.type?Number(s.value):NaN,t=3===e?o.cubeRoot:2===e?o.squareRoot:o.nthRoot(e?this.ordinal(e):Qn(this.speak(s))+"th");return[a(t),...this.contents(r,"endRoot")]}case"abs":return[a(o.absoluteValue),...this.contents(s,"endAbsoluteValue")];case"floor":return[a(o.floor),...this.contents(s,"endFloor")];case"ceil":return[a(o.ceiling),...this.contents(s,"endCeiling")];case"log":return"symbol"===s.type&&"e"===s.value?[a(`${this.names.ln} ${o.of}`),...this.argument(r)]:[a(`${o.logBase}`),...this.speak(s),a(o.of),...this.argument(r)];case"mod":return[...this.quantity(s),a(o.mod),...this.quantity(r)];case"pmod":return[...this.speak(s),a(`${o.comma} ${o.mod}`),...this.speak(r)];case"perm":return[...this.quantity(s),a(o.permute),...this.quantity(r)];case"comb":return[...this.quantity(s),a(o.choose),...this.quantity(r)];case"round":{const e=0===("number"===r.type?Number(r.value):NaN)?o.nearestWholeNumber:`${Qn(this.speak(r))} ${o.decimalPlaces}`;return[...this.speak(s),a(`${o.comma} ${o.rounded} ${e}`)]}case"fixed":return 0===("number"===r.type?Number(r.value):NaN)?[...this.speak(s),a(`${o.comma} ${o.asWholeNumber}`)]:[...this.speak(s),a(`${o.comma} ${o.writtenTo}`),...this.speak(r),a(o.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${o.of}`),...this.speak(s),a(o.over),...this.speak(r)];case"random":return[a(o.randomNumber)];case"expm1":return[a(o.eToThe),...this.speak(s),a(`${o.comma} ${o.minus} 1`)];case"?:":{const e=[a(o.if),...this.speak(s),a(`${o.comma} ${o.then}`),...this.speak(r)];return(e=>"symbol"===e.type&&"unchanged"===e.value)(n[2])?e:[...e,a(`${o.comma} ${o.otherwise}`),...this.speak(n[2])]}case"sum":return n.flatMap((e,t)=>t?[a(o.plus),...this.speak(e)]:this.speak(e));case"prod":return n.flatMap((e,t)=>t?[a(o.times),...this.quantity(e)]:this.quantity(e));case"mean":case"max":case"min":case"gcd":return[a(`${this.names[t]} ${o.of}`),...l()];case"()":return 2===n.length?[a(o.openInterval),...this.speak(s),a(o.to),...this.speak(r)]:l();case"pmatrix":case"bmatrix":return this.matrix(e);case"vmatrix":return[a(o.determinantOf),...this.matrix(e)];case"[]":return Pt(e)?this.matrix(e):2===n.length?[a(o.closedInterval),...this.speak(s),a(o.to),...this.speak(r)]:[a(o.theList),...l()];case"(]":case"[)":return[a(o.halfOpenInterval),...this.speak(s),a(o.to),...this.speak(r)];case"{}":return[a(o.theSet),...l()];case"der":return this.derivative(e);case"int":return this.integral(e);case"lim":return this.limit(e);case"\\sumidx":return this.bigOperator(e,o.sumFrom,o.sumOver,o.sumOf,"endSum");case"\\prodidx":return this.bigOperator(e,o.productFrom,o.productOver,o.productOf,"endProduct")}throw new Error(`No speech for '${t}'`)}matrix(e){const t=this.w,n=Pt(e),s=[this.seg(e,t.matrix(n.length,n[0].length))];return n.forEach((n,r)=>{const i=e.args[r];s.push(this.seg(e,t.comma),this.seg("op"===i.type&&"[]"===i.op?i:e,`${t.row(r+1)}:`)),n.forEach((n,r)=>s.push(...r?[this.seg(e,t.comma)]:[],...this.speak(n)))}),[...s,...this.closer(e,"endMatrix")]}arguments(e){return 1===e.length?this.argument(e[0]):e.flatMap((e,t)=>t?[{text:this.w.comma,id:e.id},...this.listed(e)]:this.listed(e))}listed(e){return this.audio?this.quantity(e):this.speak(e)}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}leftSide(e){return this.audio&&"op"===e.type&&"?:"===e.op?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,"endQuantity")]:this.speak(e)}quantityIfSum(e){return this.quantity(e)}product(e){const[t,n]=e.args,s=this.w;if(xt(e))return this.speak({...e,op:"neg",args:[n]});if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,s.degrees)];const r=this.audio&&"op"===t.type&&"/"===t.op&&!t.args.every(e=>"number"===e.type&&/^\d$|^10$/.test(e.value))?[this.seg(t,s.quantity),...this.speak(t),...this.closer(t,"endFraction")]:this.quantity(t);this.audio&&"op"===t.type&&"^"===t.op&&"number"!==t.args[1].type&&r.push(...this.closer(t.args[1],"endExponent"));const i=this.quantity(n);if(e.written&&[t,n].some(Wn))return[...r,this.seg(e,s[e.written]),...i];return Boolean(e.written)||this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||i[0].text.startsWith("the ")?[...r,this.seg(e,s.times),...i]:[...r,...i]}isWord(e){return"symbol"===e.type&&/^[A-Za-z]{2,}$/.test(e.value)&&!mt[e.value]&&!["pi","tau"].includes(e.value)}isCall(e){return"op"===e.type&&(i(e.op)||"prefix"===o(e.op)?.fixity&&100===l(e.op))}startsWithNumber(e){let t=e;for(;"op"===t.type&&t.args.length;)t=t.args[0];return"number"===t.type}fraction(e){const[t,n]=e.args,s=this.w,r=t=>this.seg(e,t);if("number"===t.type&&"number"===n.type&&/^[1-9]$/.test(t.value)&&/^([2-9]|10)$/.test(n.value)){const e=Number(t.value),i=Number(n.value),o=2===i?1===e?s.half:s.halves:s.ordinals[i]+(1===e?"":"s");return[r(`${s.numerators[e]} ${o}`)]}const i=(e,...t)=>"op"===e.type&&t.includes(e.op)&&!xt(e);return[...this.grouped(t,null,i(t,"/")),...this.isCall(t)?[r(s.comma)]:[],r(s.over),...this.grouped(n,"endFraction",i(n,"/"))]}power(e){const[t,n]=e.args,s=this.w,r=t=>this.seg(e,t),i=this.isCompound(t)||this.isCall(t)||"number"===t.type&&t.value.startsWith("-")||"op"===t.type&&"/"===t.op||this.audio&&"op"===t.type&&("^"===t.op||"neg"===t.op||xt(t))?[r(s.quantity),...this.speak(t),...this.closer(t,"endQuantity")]:this.speak(t);if(this.isCall(t)&&this.names[t.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===t.args.length){const e=2===Number(n.value)?s.squared:s.cubed;return[r(`${this.names[t.op]} ${e} ${s.of}`),...this.argument(t.args[0])]}if("number"===n.type&&/^(?:[1-9]|10)$/.test(n.value)){const e=Number(n.value);return 2===e||3===e?[...i,r(s.powers[e])]:[...i,r(`${s.toThe} ${s.powers[e]}`)]}if("number"===n.type&&/^\d+$/.test(n.value))return[...i,r(`${s.toThe} ${this.ordinal(Number(n.value))}`)];if(!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))){const e=this.speak(n),t=e[0]&&e[0].text.startsWith(s.quantity);return[...i,r(t?s.toThePowerOf:s.toThe),...e]}return this.audio?[...i,r(s.toThePowerOf),r(s.quantity),...this.speak(n),...this.closer(n,"endExponent")]:[...i,r(s.toThePowerOf),...this.speak(n),r(s.comma)]}ordinal(e){if(e<=10&&e>=1)return"squared"===this.w.powers[e]?"second":"cubed"===this.w.powers[e]?"third":this.w.powers[e];return`${e}${e%100>=11&&e%100<=13?"th":["th","st","nd","rd"][e%10]??"th"}`}derivative(e){const{n:t,body:n,by:s,at:r,variable:i}=Lt(e),o=this.w,a=t=>this.seg(e,t),l=r?[a(`${o.comma} ${o.at}`),...this.speak(s),a(o.equals),...this.speak(r)]:[];if(i){return[...[a(1===t?o.d:`${o.d} ${2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`}`),...this.speak(n),a(o.d),...this.speak(s),a(1===t?"":2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`)],...l]}return[a(`${1===t?o.derivative:2===t?o.secondDerivative:o.nthDerivative(this.ordinal(t))} ${o.withRespectTo}`),...this.speak(s),a(o.of),...this.contents(n,"endDerivative"),...l]}integral(e){const{args:t}=e,[n,s,r,i]=t,o=this.w,a=t=>this.seg(e,t),l=t.length>=2&&"symbol"===s.type&&1===s.value.length,c=l?this.speak(s):[a(S(n)||"x")];let h=[];4===t.length?h=[r,i]:3===t.length?h=l?[r]:[s,r]:2!==t.length||l||(h=[s]);return[...2===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.to),...this.speak(h[1]),a(o.of)]:1===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(e){const{args:t}=e,[n,s,r,i]=t,o=this.w,a=t=>this.seg(e,t);let l;if(t.length>=3){if(l=[...this.speak(s),a(o.approaches),...this.speak(r)],4===t.length){const e=String(i.value??"").toLowerCase().startsWith("r");l.push(a(e?o.fromTheRight:o.fromTheLeft))}}else if(2===t.length&&"op"===s.type&&"→"===s.op)l=[...this.speak(s.args[0]),a(o.approaches),...this.speak(s.args[1])];else{if(2!==t.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const e=S(n);l=e?[a(e),a(o.approaches),...this.speak(s)]:this.speak(s)}}return this.audio&&"op"===n.type&&"/"===n.op?[a(o.limitAs),...l,a(o.of),...this.grouped(n,"endLimit",!0)]:[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(e,t,n,s,r){const{args:i}=e,[o,a,l]=i,c=this.w,h=t=>this.seg(e,t);let u;return u=3===i.length?[h(t),...this.speak(a),h(c.to),...this.speak(l),h(c.of)]:2===i.length?[h(n),...this.speak(a),h(c.of)]:[h(s)],[...u,...this.contents(o,r)]}}for(const e of[Dn,Un,Vn,Xn,Bn])Object.setPrototypeOf(e,null);function Kn(e,t={}){return Fn(e)?[]:function(e,t={}){return Hn(e,t,!1)}(Pn(e),t)}function Yn(e,t={}){return Fn(e)?"":Gn(Pn(e),t)}const es={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0.015"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function ts(e,t,n=""){const s=es[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${s.fill?`<path d="${s.fill}" fill="currentColor"/>`:`<path d="${s.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const ns=.8,ss=.2,rs=.25,is=.7,os="−",as={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},ls={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},cs={"±":"±","∪":"∪","∩":"∩",mod:"mod"},hs=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],us={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},ps=[...hs,...Object.keys(us),"ln","det"],fs={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},ds={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},ms=["int","lim","\\sumidx","\\prodidx"],gs={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},$s={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},xs=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,ys=e=>"symbol"===e?.type&&xs.test(mt[e.value]??e.value),bs=["boxed","overline","bar","underline","cancel",...Object.keys($s)],ws={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},vs=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ks=e=>+e.toFixed(3)+"em",Es=(e,t=ns,n=ss)=>({html:e,h:t,d:n});function Ms(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(ns,...t.map(e=>e.h)),d:Math.max(ss,...t.map(e=>e.d))}}function _s(e,t={}){const n=new As({...ws,...t}),s=n.render(e,{level:0}),r=`${n.p}${n.o.display?` ${n.p}-display`:""}`,i="function"==typeof n.o.mathml?function(e,t,n,s){try{return String(e(t)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${s?' display="block"':""}>`)}catch{return""}}(n.o.mathml,e,n.p,n.o.display):"",o=i?null:function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):Yn(e)}catch{return null}}(e,n.o.label),a=null!==o||i?s.html.replace(/^<span /,'<span aria-hidden="true" '):s.html;return{html:`<span class="${r}"${null===o?"":` role="math" aria-label="${vs(o)}"`}>${a}${i}</span>`,h:s.h,d:s.d}}class As{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",s=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${s}>${t}</span>`}text(e,t){const n=Es(this.el(e,vs(t)));return n.leaf={kind:e,content:vs(t)},n}bin(e){return this.text("bin",e)}rel(e){return this.text("rel",e)}punct(e){return this.text("punct",e)}word(e){return this.text("word",e)}wrap(e,t,n){let s="";void 0!==e.id&&(s+=` data-node="${e.id}"`),"op"===e.type&&(s+=` data-op="${vs(e.op)}"`);const r=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(r))"class"!==e&&"style"!==e&&/^[A-Za-z_:][\w:.-]*$/.test(e)&&(s+=` ${e}="${vs(t)}"`);const i=[r.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),o=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(r.class?[vs(r.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${i?` style="${vs(i)}"`:""}${s}>${a}</span>`,h:n.h,d:n.d}}render(e,t){return"number"===e.type?this.number(e):"string"===e.type?this.wrap(e,["text"],this.text("text",e.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===e.type?this.wrap(e,["symbol"],this.symbol(e.value)):this.operation(e,t)}number(e){return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,os)))}symbol(e){return mt[e]&&(e=mt[e]),gs[e]?this.text("ord",gs[e]):"\\+"===e||"\\-"===e?this.text("ord",e[1]):"-∞"===e?this.text("ord","−∞"):/^[A-Za-z]$/.test(e)||/^[α-ω]$/.test(e)?this.text("var",e):/^[A-Za-z]′+$/.test(e)?Es(this.el("var",vs(e[0]))+this.el("prime",vs(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?Es(this.el("ord","Δ")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:n,args:s}=e,[r,o]=s,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1,leftFactor:!1}),c=as[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),h=t=>this.wrap(e,["op",`op-${c}`],t),u=(t,n)=>wt(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(ps.includes(n)||"log"===n)return h(this.named(e,t));if(fs[n])return h(Ms(this.word(fs[n]),this.fence(this.list(s,t))));if(i(n))return h(this.custom(e,t));const p=Pt(e);if(p)return h(this.matrix(e,p,t));if(ds[n])return h(this.fence(this.list(s,t),...ds[n]));if(("|"===n||"&"===n)&&s.length>=2&&s.every(Ns)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===n?a(e):this.fence(a(e));return h(Ms(s.map((t,s)=>s?[this.text("conj","|"===n?"or":"and"),e(t)]:[e(t)]).flat()))}if(ls[n]&&2===s.length)return h(Ms(u(r,"left"),this.rel(ls[n]),u(o,"right")));if(cs[n]&&2===s.length)return h(Ms(u(r,"left"),this.bin(cs[n]),u(o,"right")));switch(n){case"+":if(xt(o)){const e=o.args[1],t=wt({op:"-"},e,"right")?this.fence(a(e)):a(e);return h(Ms(u(r,"left"),this.bin(os),this.wrap(o,["op","op-mul"],t)))}return"number"===o.type&&o.value.startsWith("-")?h(Ms(u(r,"left"),this.bin(os),this.wrap(o,["number"],this.text("num",o.value.slice(1))))):h(Ms(u(r,"left"),this.bin("+"),this.signed(o,u(o,"right"))));case"-":return h(Ms(u(r,"left"),this.bin(os),this.signed(o,u(o,"right"))));case"*":return h(this.product(e,t));case"/":return h(this.fraction(e,t));case"^":return h(this.power(e,t));case"_":{const e=yt(r)&&l(yt(r))<100;return h(this.script(e?this.fence(a(r)):a(r,{forceParens:!0}),null,t,a(o,{level:t.level+1})))}case"neg":return h(Ms(this.text("sign",os),vt(n,r)?this.fence(a(r)):a(r,{before:t.before})));case"pm":return h(Ms(this.text("sign","±"),vt(n,r)?this.fence(a(r)):a(r)));case"!":return h(Ms(vt(n,r)?this.fence(a(r)):a(r,{forceParens:!0}),this.text("ord","!")));case"\\not":return h(Ms(this.text("sign","¬"),vt(n,r)?this.fence(a(r)):a(r)));case"pmod":return h(Ms(a(r),this.fence(Ms(this.word("mod"),this.text("space",""),a(o)))));case"sqrt":return h(this.radical(a(r)));case"root":return h(this.radical(a(o),this.render(r,{level:t.level+2})));case"abs":return h(this.fence(a(r),"|","|"));case"floor":return h(this.fence(a(r),"⌊","⌋"));case"ceil":return h(this.fence(a(r),"⌈","⌉"));case"loglog":return h(Ms(this.word("ln"),this.fence(Ms(this.word("ln"),this.fence(a(r))))));case"logloglog":return h(Ms(this.word("ln"),this.fence(Ms(this.word("ln"),this.fence(Ms(this.word("ln"),this.fence(a(r))))))));case"perm":return h(this.script(this.script(Es(""),this.render(r,{level:t.level+1}),t),null,t,this.render(o,{level:t.level+1}),this.word("P")));case"comb":return h(this.fence(this.stack(a(r),a(o),!1)));case"?:":return h(this.o.cases?this.cases(e,t):Ms(a(r),this.bin("?"),a(o),this.bin(":"),a(s[2])));case"sum":case"prod":{const e={op:"sum"===n?"+":"*"},t=(t,n)=>wt(e,t,n?"right":"left")?this.fence(a(t)):a(t);return h(Ms(s.map((e,s)=>s?[this.bin("sum"===n?"+":"·"),t(e,s)]:[t(e,s)]).flat()))}case"der":return h(this.derivative(e,t));case"int":return h(this.integral(s,t));case"lim":return h(this.limit(s,t));case"\\sumidx":return h(this.bigOperator("sum",s,t));case"\\prodidx":return h(this.bigOperator("prod",s,t))}throw new Error(`Inline Math cannot draw '${n}'`)}signed(e,t){return("number"===e.type?e.value.startsWith("-"):"neg"===e.op||"pm"===e.op)&&!t.fenced?this.fence(t):t}list(e,t){return Ms(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[n,s]=e.args;if(xt(e))return Ms(this.text("sign",os),vt("neg",s)?this.fence(this.render(s,t)):this.render(s,t));const r=function(e){const[t,n]=e.args;return{left:wt(e,t,"left")&&"/"!==t.op,right:wt(e,n,"right")&&"/"!==n.op}}(e);ms.includes(n.op)&&(r.left=!0);const o=!e.written&&kt(n,s,r),a=function(e){for(;"op"===e.type;){if(ps.includes(e.op)||"log"===e.op||fs[e.op]||i(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(s),l=r.left?this.fence(this.render(n,t)):this.render(n,{...t,before:o&&!a,leftFactor:!0}),c=r.right?this.fence(this.render(s,t)):this.render(s,{...t,before:t.before});return Ms(l,o?Es(this.el(a?"fnspace":"times","")):this.bin("cross"===e.written?"×":"·"),c)}named(e,t,n=null){const{op:s,args:r}=e,i="log"===s?r[1]:r[0];let o;o=us[s]&&"power"===this.o.inverseTrig?this.script(this.word(us[s]),this.text("num","−1"),t):this.word(s),n&&(o=this.script(o,n,t)),"log"===s&&(o=this.script(o,null,t,this.render(r[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&Os(i),l=this.render(i,{...t,forceParens:!1,before:!1});return Ms(o,a?Ms(Es(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=St(e.op),s=e.args;if(bs.includes(n)&&1===s.length)return this.decorate(n,this.render(s[0],t),s[0]);return Ms(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Es(this.el("callgap","")),this.fence(this.list(s,t)))}decorate(e,t,n){switch(e){case"boxed":return Es(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return Es(this.el("cancel",t.html+ts("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return Es(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return Es(this.el("over"+(ys(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const s=ys(n);return Es(this.el("accent"+(s?" accent-low":""),this.el(`accent-mark accent-${e}`,$s[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[n,s]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&Os(n,!0)&&Os(s,!0)){const e={...t,leftFactor:!1},r=(t,n)=>"op"!==t.type||Os(t)&&(!n||"*"!==t.op||xt(t))?this.render(t,e):this.fence(this.render(t,e)),i=Ms("op"===n.type&&"neg"===n.op?this.render(n,e):r(n,!1),this.text("ord","/"),r(s,!0));return t.leftFactor?this.fence(i):i}const r=t.level>0||t.inFraction||!this.o.display?.8:1,i={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,i),this.render(s,i),!0,r)}stack(e,t,n=!0,s=1){const r=e=>1===s?e.html:this.el("scaled",e.html,`font-size:${ks(s)}`),i=n?.06:0,o=rs+i/2+.1+Math.max(ss,s*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",r(e))+this.el("denom",r(t)),`vertical-align:${ks(o)}`);return Es(a,o+Math.max(ns,s*e.h),Math.max(ns,s*t.h)+Math.max(ss,s*t.d)+.1+i/2-rs)}power(e,t){const[n,s]=e.args,r={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},i=()=>this.render(s,r);if(this.o.trigPowers&&hs.includes(n.op)&&Ls(s))return this.wrap(n,["op",`op-${n.op}`],this.named(n,t,i()));if("_"===n.op){const e=this.render(n.args[1],r);return this.wrap(n,["op","op-subscript"],this.script(this.render(n.args[0],{...t,forceParens:!0}),i(),t,e))}const o=wt(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||ps.includes(n.op)||ms.includes(n.op)?this.fence(this.render(n,t)):this.render(n,{...t,forceParens:!0});return this.script(o,i(),t)}script(e,t,n,s=null,r=null){const i=n.level>0?.8:is,o=r?Ms(e,r):e;let a=t?Math.max(.42,e.h-.38,i*t.d+.12):0,l=s?Math.max(.2,e.d-.05,i*s.h-.45):0;if(t&&s){const e=.1-(a-i*t.d-(i*s.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${ks(i)}`);if(t&&!s)return Es(e.html+this.el("sup",t.html,`font-size:${ks(i)};vertical-align:${ks(a/i)}`),Math.max(o.h,a+i*t.h),Math.max(o.d,i*t.d-a));if(s&&!t)return Es(o.html+this.el("sub",s.html,`font-size:${ks(i)};vertical-align:${ks(-l/i)}`),Math.max(o.h,i*s.h-l),Math.max(o.d,l+i*s.d));const h=a+i*t.h,u=l+i*s.d,p=this.el("subsup",c(t)+c(s),`vertical-align:${ks(a)};height:${ks(h+u)}`);return Es(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,ns)+.1+.06,s=Math.max(e.d,ss),r=n+s,i=ts("sqrt",`${this.p}-hook`,`height:${ks(r)};width:${ks(.5+.06*(r-1))};vertical-align:${ks(-s)}`);let o="";if(t){const e=.8*is;o=this.el("rootindex",t.html,`font-size:${ks(e)};vertical-align:${ks((.55*r-s)/e)}`)}return Es(this.el("sqrt",o+i+this.el("radicand",e.html)),n,s)}fence(e,t="(",n=")"){const s=Math.max(e.h,ns)+Math.max(e.d,ss),r=s>1.25,i=r?.1:0,o=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const i=n+(r?Math.min(.2,.05*(s-1)):0);return{html:ts(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${ks(i)}`),w:i+.1}}const i={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${i} delim-${t}`,""),w:"|"===e?.18:.3}},a=o(t,"l"),l=o(n,"r"),c=`padding:${ks(i)} ${ks(l.w)} ${ks(i)} ${ks(a.w)}`,h=Es(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,ns)+i,Math.max(e.d,ss)+i);return h.fenced=!0,h}derivative(e,t){const n=this.leibniz(e,t),{by:s,at:r}=Lt(e);if(!r)return n;const i=e.args[1],o=this.render({...i,args:[{...s,id:void 0},r]},{...t,level:t.level+1});return this.script(this.fence(n,"","|"),null,t,o)}leibniz(e,t){const{n:n,body:s,by:r,variable:i}=Lt(e),o={...t,level:t.level+1},a=()=>this.text("d","d"),c=()=>n>1?this.render({type:"number",value:String(n)},o):null,h={...t,inFraction:!0},u=Ms(a(),c()?this.script(this.render(r,h),c(),h):this.render(r,h)),p=e=>Ms(c()?this.script(a(),c(),h):a(),e||[]),f=t.level>0||t.inFraction||!this.o.display?.8:1;if(i)return this.stack(p(this.render(s,h)),u,!0,f);const d=yt(s)&&l(yt(s))<100,[m,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],$=d?this.fence(this.render(s,t),m,g):this.render(s,t);return Ms(this.stack(p(),u,!0,f),$)}integral(e,t){const[n,s,r,i]=e,o=e=>this.render(e,t),a=e=>e?this.render(e,{...t,level:t.level+1}):null,l=()=>this.text("var",S(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:Nt(s)?c=o(s):(c=l(),h=a(s));break;case 3:Nt(s)?(c=o(s),h=a(r)):(c=l(),h=a(s),u=a(r));break;default:c=o(s),h=a(r),u=a(i)}const p=o(n),f=Es(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Ms(this.bigSign("int",p,h,u,t),p,f)}bigSign(e,t,n,s,r){const i=!this.o.display||r.level>0,o=Math.max(i?.6:.95,Math.max(t.h-rs,t.d+rs)+.12),a=ts(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${ks(2*o)};width:${ks(i?.38:.5)};vertical-align:${ks(rs-o)}`);if(!n&&!s)return Es(a,rs+o,o-rs);const l=is,c=s||Es(""),h=n||Es(""),u=rs+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${ks(l)}`)+this.el("script lower",h.html,`font-size:${ks(l)}`),`vertical-align:${ks(u)};height:${ks(2*o)}`);return Es(a+p,rs+o,o-rs)}limit(e,t){const[n,s,r,i]=e,o={...t,level:t.level+1},a=e=>this.render(e,o),l=()=>this.rel("→");let c;switch(e.length){case 1:return Ms(this.word("lim"),Es(this.el("fnspace","")),this.body(n,t));case 2:{const e=S(n),t="number"===s.type||"symbol"===s.type&&s.value.includes("∞");c=e&&t?Ms(this.text("var",e),l(),a(s)):a(s);break}case 3:c=Ms(a(s),l(),a(r));break;default:{const e=gt(i).toLowerCase().startsWith("r")?"+":os;c=Ms(a(s),l(),this.script(a(r),this.wrap(i,["symbol"],this.text("ord",e)),o))}}return Ms(this.under(this.word("lim"),c,t),this.body(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):Es(this.el("under",e.html+this.el("script",t.html,`font-size:${ks(.7)}`)),e.h,Math.max(e.d,ss)+.05+.7*(t.h+t.d))}body(e,t){const n=yt(e);return n&&l(n)<l("*")?this.fence(this.render(e,t)):this.render(e,t)}bigOperator(e,t,n){const[s,r,i]=t,o={...n,level:n.level+1},a=r?this.render(r,o):null,l=i?this.render(i,o):null,c=this.body(s,n);if(!this.o.display||n.level>0){const t=.55,s=ts(e,`${this.p}-bigsign`,`height:${ks(2*t)};width:${ks(.8)};vertical-align:${ks(rs-t)}`);return Ms(this.script(Es(s,rs+t,t-rs),l,n,a),c)}const h=.68,u=is,p=ts(e,`${this.p}-bigsign`,`height:${ks(1.36)};width:${ks("sum"===e?1:1.05)}`),f=l?1.01+u*l.d:rs-h,d=e=>this.el("script",e.html,`font-size:${ks(u)}`),m=this.el("bigop",(l?d(l):"")+p+(a?d(a):""),`vertical-align:${ks(f)}`);return Ms(Es(m,.93+(l?.08+u*(l.h+l.d):0),h-rs+(a?.08+u*(a.h+a.d):0)),c)}matrix(e,t,n){const s=t.map(e=>e.map(e=>this.render(e,n))),r=s.map(e=>({h:Math.max(ns,...e.map(e=>e.h)),d:Math.max(ss,...e.map(e=>e.d))})),i=r.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=rs+i/2-r[0].h,a=s.map((t,n)=>{const s=t.map(e=>this.el("matrix-cell",e.html)).join(""),r=e.args[n];return r&&"op"===r.type&&"[]"===r.op?this.wrap(r,["op","op-list","matrix-row"],Es(s)).html:s}).join(""),l=t[0].length,c=Es(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${ks(o)}`),rs+i/2,i/2-rs),[h,u]=Zt[e.op]??["[","]"];return this.fence(c,h,u)}cases(e,t){const n=[];let s=e;for(;"op"===s.type&&"?:"===s.op;)n.push([this.render(s.args[1],t),Ms(this.word("if"),this.text("space",""),this.render(s.args[0],t))]),s=s.args[2];"symbol"===s.type&&"unchanged"===s.value||n.push([this.render(s,t),this.word("otherwise")]);const r=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),i=r.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),o=rs+i/2-r[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=Es(this.el("cases",a,`vertical-align:${ks(o)}`),rs+i/2,i/2-rs);return this.fence(l,"{","")}}function Os(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||Pt(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!xt(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Ss(e)||"*"===e.op&&Os(e,t)):Os(e.args[0],!0)&&("neg"===e.op||Os(e.args[1],!0)))}const qs=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],Ns=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&qs.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(Ns)),Ss=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(mt[e.value])),Ls=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[as,ls,cs,us,fs,ds,gs,$s])Object.setPrototypeOf(e,null);function zs(e){const{id:t,from:n,...s}=e;return s.args&&(s.args=s.args.map(zs)),s}const Cs=e=>O(e).join(" ");function Is(e,t){const n=new Set;Rs(e,t,n);const s=[];return N(e,e=>{n.has(e)&&s.push(e)}),s}function Rs(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>Rs(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const s=Cs(Zn(t));return void N(e,e=>{Cs(e)===s&&n.add(e)})}if(t.path){const s=Ts(e,t.path);return void(s&&n.add(s))}if(t.type){const s=Cs(t);N(e,e=>{e!==t&&Cs(e)!==s||n.add(e)})}}else N(e,(e,s)=>{t(e,s)&&n.add(e)});else N(e,e=>{e.id===t&&n.add(e)})}function Ts(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}function js(e,t){const n=[],s=e=>{if(e.id===t)return!0;if("op"!==e.type)return!1;for(let t=0;t<e.args.length;t++){if(n.push(t),s(e.args[t]))return!0;n.pop()}return!1};return s(e)?n:null}function Zs(t){let n=0;const s=t=>{"op"===t.type&&(t.args.forEach(s),o(t.op)?.arity===e&&n++),t.id=n++};return s(t),t}function Ps(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Zn(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return A(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return N(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),Zs(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Fs(e,t={}){const n=Ps(e,t);return _s(n,Ws(n,t)).html}function Ws(e,t){const{colors:n,highlight:s,scope:r,blocks:i,...o}=t,a=new Map;for(const[t,s]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(Ds(s))for(const n of Is(e,t))a.set(n,`color:${s}`);const l=new Set(void 0===s?[]:Is(e,s));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}function Ds(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}export{c as A,yt as B,It as C,ws as D,gt as E,Nt as F,mt as G,vt as H,Fn as I,jn as J,o as K,Zt as M,es as P,Ws as a,Kn as b,Cs as c,Zs as d,Fs as e,Ps as f,zs as g,S as h,O as i,Pn as j,$t as k,_s as l,Tt as m,Ts as n,Zn as o,js as p,q,Cn as r,Is as s,Yn as t,jt as u,xt as v,Pt as w,i as x,St as y,Lt as z};