@mathzetta/inlinemath 0.1.0 → 0.2.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.
Files changed (43) hide show
  1. package/README.md +64 -20
  2. package/dist/cas.external.js +2 -2
  3. package/dist/cas.js +2 -2
  4. package/dist/chunks/calculate-Cz87Lt0N.js +2 -0
  5. package/dist/chunks/draw-Bev17BJJ.js +2 -0
  6. package/dist/chunks/edit-C65xXzo8.js +2 -0
  7. package/dist/chunks/edit-M68aRA5o.js +2 -0
  8. package/dist/chunks/{html-CvuSyhzk.js → html-BimAqn7x.js} +2 -2
  9. package/dist/chunks/html-CupluJSh.js +2 -0
  10. package/dist/chunks/lite-3Fb-OHbt.js +2 -0
  11. package/dist/inlinemath-cas.external.global.min.js +2 -2
  12. package/dist/inlinemath-cas.global.min.js +2 -2
  13. package/dist/inlinemath-lite-calc.global.min.js +2 -2
  14. package/dist/inlinemath-lite.external.global.min.js +2 -2
  15. package/dist/inlinemath-lite.global.min.js +2 -2
  16. package/dist/inlinemath.css +32 -1
  17. package/dist/inlinemath.external.global.min.js +2 -2
  18. package/dist/inlinemath.external.js +2 -2
  19. package/dist/inlinemath.global.min.js +2 -2
  20. package/dist/inlinemath.js +2 -2
  21. package/dist/lite-calc.js +2 -2
  22. package/dist/lite.external.js +2 -2
  23. package/dist/lite.js +2 -2
  24. package/dist/markdown.external.js +2 -2
  25. package/dist/markdown.js +2 -2
  26. package/inlinemath.css +32 -1
  27. package/package.json +3 -3
  28. package/src/cas.js +25 -15
  29. package/src/edit.js +96 -0
  30. package/src/glyphs.js +2 -0
  31. package/src/index.d.ts +2 -2
  32. package/src/index.js +1 -1
  33. package/src/layout.js +55 -11
  34. package/src/markdown.d.ts +2 -2
  35. package/src/markdown.js +354 -39
  36. package/src/mathzetta.js +2 -1
  37. package/src/types.d.ts +77 -6
  38. package/src/variables.js +228 -0
  39. package/src/view.js +226 -6
  40. package/dist/chunks/calculate-BX9lJ7Ff.js +0 -2
  41. package/dist/chunks/draw-Cm4exbg7.js +0 -2
  42. package/dist/chunks/html-DWtfytjA.js +0 -2
  43. package/dist/chunks/lite-Bj_L6w2g.js +0 -2
@@ -1,2 +0,0 @@
1
- /* Inline Math 0.1.0 — MIT licence; 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:s(1),abs:s(1),floor:s(1),ceil:s(1),ln:s(1),loglog:s(1),logloglog:s(1),expm1:s(1),sin:s(1),cos:s(1),tan:s(1),csc:s(1),sec:s(1),cot:s(1),sinh:s(1),cosh:s(1),tanh:s(1),arcsin:s(1),arccos:s(1),arctan:s(1),arcsinh:s(1),arccosh:s(1),arctanh:s(1),random:s(0),log:s(2),root:s(2),atan2:s(2),round:s(2),fixed:s(2),perm:s(2),comb:s(2),der:s(2),max:s(e),min:s(e),gcd:s(e),mean:s(e),sum:s(e),prod:s(e),int:s(e),lim:s(e),"\\sumidx":s(e),"\\prodidx":s(e),"()":n(),"[]":n(),"{}":n(),"(]":n(),"[)":n(),"=":{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 s(e){return{prec:100,assoc:"none",arity:e,fixity:"prefix"}}function n(){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=s(e),l=e=>o(e)?.prec;function c(e,t,s){if("mod"===e&&t)return l(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===s;const n=l(e),r=l(t);if(!n||!r)return!1;if(r!==n)return r<n;const i=o(e).assoc;return"left"===i?"right"===s:"right"===i&&"left"===s}const h=100,u={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,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,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},p=e=>Object.prototype.hasOwnProperty.call(u,e),f=new Set(["^","?:","?","log"]),g=["(","{","["],m=[")","}","]"];function d(e,t=!1){if(!e)return!1;for(let s=0;s<e.length;s++)if(!("0123456789.".includes(e[s])||t&&0===s&&"-"===e[s]&&e.length>1))return!1;return!0}for(const e of[u])Object.setPrototypeOf(e,null);const $=e=>({type:"number",value:String(e)}),y=e=>({type:"symbol",value:e}),x=(e,t)=>({type:"op",op:e,args:t}),b=['"',"'","`"];function w(e){return d(e,!0)?$(e):b.includes(e[0])?{type:"string",value:e}:y(e)}const v={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function k(t){if(!Array.isArray(t)||0===t.length)throw new Error("Empty postfix");const s=[],n=[];if(t.forEach((t,r)=>{const i=v[t]??String(t),a=o(i);if(!a)return s.push({...w(i),id:r}),void n.push(1);let l=a.arity;if(l===e){const e=s.pop();if(n.pop(),l=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(l)||l<0)throw new Error(`'${i}' takes a variable number of arguments, so it must follow a count`)}if(s.length<l)throw new Error(`'${i}' needs ${l} operand${1===l?"":"s"}`);const c=1+Math.max(0,...n.splice(n.length-l,l));if(c>1e3)throw new Error("Nested too deeply (more than 1000 levels)");n.push(c),s.push({...x(i,s.splice(s.length-l,l)),id:r})}),1!==s.length)throw new Error(`Postfix leaves ${s.length} values instead of 1`);return s[0]}function _(t){const s=[];return function t(n){"op"===n.type?(n.args.forEach(t),o(n.op)?.arity===e&&s.push(String(n.args.length)),s.push(n.op)):s.push(n.value)}(t),s}function E(e){if(Array.isArray(e))return k(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}function A(e,t,s=null){t(e,s),"op"===e.type&&e.args.forEach(s=>A(s,t,e))}function M(e){let t="";return A(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[v])Object.setPrototypeOf(e,null);function q(e){const t=new Map;for(const[s,n,r]of e)if(s&&""!==s.trim()&&(t.set(s,n),!r))for(const e of N(s))t.get(e)||t.set(e,n);const s=new Map;for(const e of t.keys()){let t=s;for(let s=0;s<e.length;s++)t.has(e[s])||t.set(e[s],new Map),t=t.get(e[s]);t.end=!0}return e=>{let n="",r=0;for(;r<e.length;){const i=O(s,e,r);i?(n+=t.get(e.slice(r,r+i)),r+=i):n+=e[r++]}return n}}function O(e,t,s){let n=e,r=0;for(let e=s;e<t.length&&(n=n.get(t[e]),n);e++)n.end&&(r=e-s+1);return r}function N(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),L(e)]);return t.delete(e),t}function L(e){let t="",s=!1;for(const n of e){const e=n>="a"&&n<="z",r=n>="A"&&n<="Z";t+=!s&&e?n.toUpperCase():n,s=e||r}return t}const S="({[",C=")}]";function R(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 z(e,t){const s=[];let n=0,r=0;for(let i=0;i<e.length;i++)S.includes(e[i])?n++:C.includes(e[i])?n--:0===n&&e.startsWith(t,i)&&(s.push(e.slice(r,i)),i+=t.length-1,r=i+1);return s.push(e.slice(r)),s}function I(e,t,s){let n=0;const r=new RegExp(`\\b${s}\\b`,"iy");for(let s=t;s<e.length;s++)if(S.includes(e[s]))n++;else if(C.includes(e[s])){if(--n<0)return-1}else if(0===n&&(r.lastIndex=s,r.test(e)))return s;return-1}function T(e,t){let s=0;for(let n=t;n<e.length;n++)if(S.includes(e[n]))s++;else if(C.includes(e[n])&&--s<0)return n;return e.length}function Z(e,t){let s=1;for(let n=t+1;n<e.length;n++)if("?"===e[n])s++;else if(":"===e[n]&&0===--s)return e.slice(0,t+1)+"("+e.slice(t+1,n)+")?:"+e.slice(n+1);return e}function j(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(S.includes(e[t+2]))continue;const s=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(e.slice(t+2))?.[0];if(!s)continue;const n=t+2+s.length;e=e.slice(0,t+2)+"{"+s+"}"+e.slice(n)}else if("("===e[t+1]){let s=1,n=0,r="",i="",o=0;for(let a=t+2;a<e.length;a++){if(")]".includes(e[a])?s--:"([".includes(e[a])&&s++,0===s){o=a;break}1===s&&","===e[a]?n++:0===n?r+=e[a]:i+=e[a]}1===n&&(e=e.slice(0,t+1)+"_{"+i+"}("+r+")"+e.slice(o+1))}return e}function P(e){const t="⌈"===e[0]?"ceil":"floor";let s=1;for(let n=1;n<e.length;n++)if("⌊"===e[n]||"⌈"===e[n]?s++:"⌋"!==e[n]&&"⌉"!==e[n]||s--,0===s)return t+"("+e.slice(1,n)+")"+e.slice(n+1);return e}function F(e){let t=1;for(let s=0;s<e.length;s++){if(")]".includes(e[s])?t--:"([".includes(e[s])&&t++,0!==t)continue;const n=e.slice(0,s),r=e[s+1];if("{"===r||"("===r)return r+n+","+e.slice(s+2);const i=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(e.slice(s+1))?.[0]??"";return"{"+n+","+i+"}"+e.slice(s+1+i.length)}return e}function W(e){const t=e.indexOf("}"),s=e.indexOf("{");if(t<0||s>=0&&s<t)return!1;const n=e.slice(0,t);if(!n.includes("matrix"))return!1;const r=e.indexOf("\\end{"+n+"}"),i=e.indexOf("\\begin{"+n+"}",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,", ")+"]");return"["+o.join(", ")+"]"+e.slice(r+6+n.length)}function D(e,t){if("{"!==e[t+1])return[e[t+1],t+2];let s=1,n="";for(let r=t+2;r<e.length;r++){if("{"===e[r])s++;else if("}"===e[r]&&0===--s)return[n,r+1];n+=e[r]}return[n,e.length]}function U(e){const{lower:t,upper:s,next:n}=function(e){let t="",s="",n=0;return"_"===e[0]&&([t,n]=D(e,0),"^"===e[n]&&([s,n]=D(e,n))),{lower:t,upper:s,next:n}}(e),r=e.slice(n),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 s=0;s<e.length;s++)if(S.includes(e[s]))t++;else if(C.includes(e[s]))t--;else if(0===t&&"d"===e[s]&&/[A-Za-z\u0370-\u03FF]/.test(e[s+1]??"")&&!/[A-Za-z]/.test(e[s+2]??""))return s;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!==s)??"x"}let h="int("+(i(o)||"1");return a&&(h+=","+a),(t||s)&&(h+=","+t+","+s),h+")"+l}function B(e){const t=e[0];if(!(t>="A"&&t<="Z"||t>="a"&&t<="z"||t>="α"&&t<="ω"))return!1;const s=e.slice(2);let n=1;for(let e=0;e<s.length;e++)if(C.includes(s[e])?n--:S.includes(s[e])&&n++,0===n)return"("+s.slice(0,e)+","+t+")"+s.slice(e+1);return!1}function G(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const H=/[A-Za-z\u0370-\u03FF]/;function X(e,t){if("{"!==e[t])return null;let s=0;for(let n=t;n<e.length;n++)if("{"===e[n])s++;else if("}"===e[n]&&0===--s)return[e.slice(t+1,n),n+1];return null}function V(e,t){const s=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return s?[Number(s[1]??s[2]),t+s[0].length]:[1,t]}function Q(e,t){const s=e.replace(/\\mathrm\{d\}/g,"d"),n=t.replace(/\\mathrm\{d\}/g,"d"),r=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(s),i=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(n);return r&&i?{n:Number(r[1]??1),of:r[2],by:i[1]}:null}function J(e,t){if(S.includes(e[t])){let s=0;for(let n=t;n<e.length;n++)if(S.includes(e[n]))s++;else if(C.includes(e[n])&&0===--s)return[e.slice(t,n+1),n+1];return[e.slice(t),e.length]}let s=0;for(let n=t;n<e.length;n++)if(S.includes(e[n]))s++;else{if(C.includes(e[n])&&--s<0)return[e.slice(t,n),n];if(0===s&&("="===e[n]||","===e[n]))return[e.slice(t,n),n]}return[e.slice(t),e.length]}const K=(e,t,s)=>`der(${e},${t}${s>1?","+s:""})`;const Y="strtktk",ee="ABCDEFGHIJ",te=e=>Y+[...String(e)].map(e=>ee[e]).join("");function se(e,t){let s=!1;for(let n=t+1;n<e.length;n++)if(s)s=!1;else if("\\"===e[n])s=!0;else if(e[n]===e[t])return n;return e.length-1}function ne(e,t){if(!t||0===t.size)return e;const s=[...t].sort((e,t)=>t[0].length-e[0].length);return e.map(e=>{for(const[t,n]of s)e=e.split(t).join(n);return e})}const re={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { let r = 1; for (let i = n - k + 1; i <= n; i++) r *= i; return r; })",comb:"((n, k) => { let r = 1; for (let i = 1; i <= k; i++) r = r * (n - k + i) / i; return r; })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})"};for(const e of[re])Object.setPrototypeOf(e,null);const ie="([{",oe=")]}";function ae(e,t){let s=0;for(let n=t;n<e.length;n++)if(ie.includes(e[n]))s++;else if(oe.includes(e[n])&&0===--s)return n;return-1}function le(e){if(!e.trim())return[];const t=[];let s=0,n=0;for(let r=0;r<e.length;r++)ie.includes(e[r])?s++:oe.includes(e[r])?s--:","===e[r]&&0===s&&(t.push(e.slice(n,r).trim()),n=r+1);return t.push(e.slice(n).trim()),t}function ce(e,t,s){const n=[...e.matchAll(t)];for(let t=n.length-1;t>=0;t--){const r=n[t],i=r.index+r[0].length-1,o=ae(e,i);if(o<0)continue;const a=s(le(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 he=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),ue=e=>`(${e})`,pe=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const fe={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(ue).join(" & ")})`,OR:e=>e.length&&`(${e.map(ue).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]})`};const ge={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"},me="strtktk[A-J]+";function de(e){for(let t=!0;t;){const s=e;t=(e=e.replace(new RegExp(`(${me})\\s*\\|\\|\\s*(${me})`,"g"),"$1 + $2"))!==s}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${me},\\s*${me}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let s=e.lastIndexOf("(typeof(");s>=0;s=s>0?e.lastIndexOf("(typeof(",s-1):-1){const n=ae(e,s),r=n>0&&t.exec(e.slice(s,n+1));if(!r)continue;const[,i,o]=r,a={[`${i} = TRUNC(${i})`]:"ℤ",[`${i} = TRUNC(${i}) AND ${i} > 0`]:"ℕ",[`ABS(${i}) < ∞`]:"ℝ"}[o.trim()];a&&(e=`${e.slice(0,s)}((${i}) ∈ ${a})${e.slice(n+1)}`)}e=ce(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=ce(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 s=t[t.length-1].index,n=/\bEND\b/i.exec(e.slice(s));if(!n)return e;const r=e.slice(s+4,s+n.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,s])=>`((${t}) ? (${s}) : ${e})`,ue(o));e=e.slice(0,s)+a+e.slice(s+n.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=>ge[e]??e);for(const[t,s]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let n=t.exec(e);n;n=t.exec(e)){const r=n.index+n[0].length-1,i=ae(e,r);if(i<0)break;e=`${e.slice(0,n.index)}${s} {${e.slice(r+1,i)}}${e.slice(i+1)}`,t.lastIndex=0}return e.replace(/<>/g," ≠ ")}const $e={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"},ye={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"};function xe(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)=>we[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>we[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>ve[t]??be[t]??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)\.(\w+)/g,(e,t)=>$e[t]?`Math.${$e[t]}`:ye[t]?ye[t]:{inf:"∞",nan:"NaN"}[t]??e)).replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>({inf:"∞",nan:"NaN"}[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 be={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},we={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},ve={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",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"},ke={open:"()",Lopen:"(]",Ropen:"[)"};const _e=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?le(t[1]):null},Ee=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Ae=e=>_e(e)??[e],Me={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]}) ∈ ${pe(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${pe(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]}) - ((${e[0]}) \\mod 1))`,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(ue).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(ue).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(_e);return!t.length||t.some(e=>!e||2!==e.length)?null:t.reduceRight((e,[t,s])=>null===e||/^True$|^true$/.test(s.trim())&&void 0===e?`(${t})`:`((${s}) ? (${t}) : ${e??"(null)"})`,void 0)},sympy_set:e=>`{${e.join(", ")}}`,sympy_interval:Ee("[]"),sympy_interval_open:Ee("()"),sympy_interval_Lopen:Ee("(]"),sympy_interval_Ropen:Ee("[)"),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=Ae(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&&Ae(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&&Ae(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 s=1===t.length&&/^(.*?)\s+for\s+(\w+)\s+in\s+range\((.*)\)\s*$/s.exec(t[0]);if(!s)return null;const n=le(s[3]),[r,i]=1===n.length?["0",n[0]]:n,o=/\s*\+\s*1$/.test(i)?i.replace(/\s*\+\s*1$/,""):`(${i}) - 1`;return`(\\${e}_{${s[2]}=${r}}^{${o}} (${s[1]}))`}}for(const e of[fe,ge,$e,ye,be,we,ve,ke,Me])Object.setPrototypeOf(e,null);const Oe=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Ne=e=>e.trim().split(/\s+/).join(String.raw`\s+`),Le=e=>new RegExp(String.raw`(?<![\w.])${Ne(e)}(?![\w.])`,"gi"),Se=[["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","="]],Ce="[<>≤≥=≠≈]",Re=[["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","∈ ℚ"]];const ze=q([[" 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 ","→"],["===","=...="]]),Ie=q([["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"],["\\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"],["\\downarrow","\\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","*"],["\\times","*"],["×","*"],["·","*"],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],["log2(","log_{2}("],["log3(","log_{3}("],["log4(","log_{4}("],["log5(","log_{5}("],["log6(","log_{6}("],["log7(","log_{7}("],["log8(","log_{8}("],["log9(","log_{9}("],["log10(","log_{10}("],["log_10","log_{10}"],["\\log2(","log_{2}("],["\\log3(","log_{3}("],["\\log4(","log_{4}("],["\\log5(","log_{5}("],["\\log6(","log_{6}("],["\\log7(","log_{7}("],["\\log8(","log_{8}("],["\\log9(","log_{9}("],["\\log10(","log_{10}("],["\\log_10","log_{10}"],["log2{","log_{2}{"],["log3{","log_{3}{"],["log4{","log_{4}{"],["log5{","log_{5}{"],["log6{","log_{6}{"],["log7{","log_{7}{"],["log8{","log_{8}{"],["log9{","log_{9}{"],["log10{","log_{10}{"],["\\log2{","log_{2}{"],["\\log3{","log_{3}{"],["\\log4{","log_{4}{"],["\\log5{","log_{5}{"],["\\log6{","log_{6}{"],["\\log7{","log_{7}{"],["\\log8{","log_{8}{"],["\\log9{","log_{9}{"],["\\log10{","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|","|"],["\\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)"],["⊕"," \\xor "],["∞","∞"],["⋅","*"],["−","-"],["\\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],...function(){const e=[],t=(t,s)=>{e.push([t,s],[t+"(",s+"("])};for(const s of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+s+"(",s+"("],["\\"+s+"(",s+"("],["\\"+s,s]),["sin","cos","tan"].includes(s))for(const e of["","h"]){const n=s+e,r="arc"+s+e;e&&(t("Math."+n,n),t("\\"+n,n));for(const s of["^-1","^{-1}","-1"])t("\\"+n+s,r),t(n+s,r),e||t("Math."+n+s,r);e||t("\\a"+n,r),t("\\arc"+n,r),t("Math.a"+n,r),t("Math.arc"+n,r)}return e}()]),Te=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=function(e){const t="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";e=(e=(e=e.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${t})(?=\\s*\\^)`,"gu"),"$1(-$2)");for(let s=!0;s;){const n=e;s=(e=e.replace(new RegExp(`(^|[^\\p{L}\\p{N}_.)§])(${t}\\s*\\^\\s*${t})(?=\\s*\\^)`,"u"),"$1($2)"))!==n}return ce(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>fe[t[1]]?.(e)||null)}(e)),e=function(e){e=ce(e,he("quad"),(e,t,s)=>{const n=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(e[0]??"");if(!n||3!==e.length)return null;const r=/^\s*\[\s*0\s*\]/.exec(s);return[`int(${n[2]}, ${n[1]}, ${e[1]}, ${e[2]})`,r?r[0].length:0]}),e=ce(e,he(Object.keys(Me).join("|")),(e,t)=>Me[t[1]](e)||null);for(let t=(e=ce(e,he("float"),(e,t,s)=>{const n=/^\s*\.is_integer\(\s*\)/.exec(s);return n&&1===e.length?[`((${e[0]}) ∈ ℤ)`,n[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const s=t+9,n=ae(e,s);let r=t;if(oe.includes(e[t-1])){let s=0;for(r=t-1;r>=0;r--)if(oe.includes(e[r]))s++;else if(ie.includes(e[r])&&0===--s)break}else for(;r>0&&/[\w.]/.test(e[r-1]);)r--;n<0||r<0||r===t||(e=`${e.slice(0,r)}((${e.slice(s+1,n)}) ∈ ${pe(e.slice(r,t))})${e.slice(n+1)}`)}return e}(e=xe(e=de(e=(e=(e=function(e){for(const[t,s]of Object.entries(re))for(let n=e.lastIndexOf(s);n>=0;n=n>0?e.lastIndexOf(s,n-1):-1){const r=n+s.length,i="("===e[r]?ae(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,n)+a+e.slice(i+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const s=t+10-1,n=ae(e,s),r=e.lastIndexOf("Number(",t);n<0||r<0||ae(e,r+7-1)!==t||(e=e.slice(0,r)+`fixed(${e.slice(r+7,t)}, ${e.slice(s+1,n)})`+e.slice(n+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,s,n,r,i)=>`(\\${"sum"===t?"sum":"prod"}_{${s}=${n}}^{${r}} (${i}))`)}(e)).replace(/(?<![\w.])9e999\b/g,"∞")).replace(/(?<![\w.])(\d+(?:\.\d+)?)[eE]([+-]\d+)(?![\w.])/g,"($1*10^{$2})")))),(e=(e=(e=function(e){for(let t=0;t<50;t++){let t=!0;for(const s of e.matchAll(/\bif\b/g)){const n=s.index;let r=0,i=-1,o=e.length;for(let t=n+2;t<e.length;t++)if(ie.includes(e[t]))r++;else{if(oe.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=n-1;t>=0;t--)if(oe.includes(e[t]))r++;else{if(ie.includes(e[t])&&--r<0){a=t+1;break}if(0===r&&","===e[t]){a=t+1;break}}const l=e.slice(a,n).trim();if(!l)continue;const c=`((${e.slice(n+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)).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(!/[A-Za-z]{2}/.test(e))return e;let t=e;const s=(e,s,n,r="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Ne(e)}\s+(${Oe})\s+(?:and|to)\s+(${Oe})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(e,t,i,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[s,n];return` ${r} ${a}${t}, ${i}${l} `})};s("is not strictly between","(",")","∉"),s("is not between","[","]","∉"),s("is strictly between","(",")"),s("is between","[","]"),s("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+(${Oe})\s+to\s+(${Oe})`,"gi"),(e,t,s,n,r)=>{const[i,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[s.toLowerCase()];return` ${t?"∉":"∈"} ${i}${n}, ${r}${o} `});const n=String.raw`(${Oe})\s+`;t=t.replace(new RegExp(n+String.raw`is\s+(not\s+)?within\s+(${Oe})\s*(%|\s+percent)?\s+of\s+(${Oe})`,"gi"),(e,t,s,n,r,i)=>`(abs((${t}) - (${i})) ${s?">":"≤"} ${r?`(${n})/100 * ${/^\d+(\.\d+)?$/.test(i)?i:`abs(${i})`}`:`(${n})`})`),t=t.replace(new RegExp(n+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${Oe})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(n+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Oe})`,"gi"),(e,t,s,n)=>`((${t}) mod (${n}) ${s?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${Oe})\s+divides\s+(${Oe})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(n+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,s,n)=>`((${t}) mod 2 ${"even"===n.toLowerCase()!==Boolean(s)?"=":"≠"} 0)`);for(const[e,s]of Re)t=t.replace(Le(e),` ${s} `);t=t.replace(Le("is not in")," ∉ ").replace(Le("is in")," ∈ ").replace(Le("is an element of")," ∈ ");for(const[e,s]of Se)t=t.replace(Le(e),` ${s} `);t=t.replace(Le("is not")," ≠ "),t=t.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let e=!0;e;){const s=t;t=t.replace(new RegExp(String.raw`(${Oe})\s*(${Ce})\s*(${Oe})\s+(and|or)\s+(${Ce})`,"gi"),"$1 $2 $3 $4 $1 $5"),e=t!==s}t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${Oe})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${Oe})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${Oe})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${Oe})\s+to\s+the\s+power\s+of\s+(${Oe})`,"gi"),"($1)^($2)");const r={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};t=t.replace(new RegExp(String.raw`(${Oe})\s+to\s+the\s+(${Object.keys(r).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,s,n)=>`(${t})^(${r[s.toLowerCase()]??n})`),t=t.replace(new RegExp(String.raw`(${Oe})\s+to\s+the\s+(${Oe})(?![\w.])`,"gi"),"($1)^($2)");const i={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"};for(const[e,s]of Object.entries(i).sort((e,t)=>t[0].length-e[0].length))t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Ne(e)}\s+of\s+(${Oe})`,"gi"),`${s}($1)`);t=t.replace(new RegExp(String.raw`(${Oe})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${Oe})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${Oe})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${Oe})`,"gi"),"2*($1)"),t=t.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const o=e=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${Ne(e)}(?=\s+[\w.(\[{-])`,"gi");for(const[e,s]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(o(e),` ${s} `);return t}],["words",ze],["spaced",function(e){e=j(e=function(e){for(let t=0;t<e.length;t++){const s=s=>e.slice(Math.max(0,t-s),t+1);if("t"===e[t]&&"\\text"===s(4)&&"{"===e[t+1]){let s=1,n=t+2,r="";for(;s>0&&n<e.length;)"{"===e[n]?s++:"}"===e[n]?s--:r+=e[n],n++;e=e.slice(0,t-4)+r+e.slice(n)}}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 s=t[t.length-1].index,n=I(e,s+2,"then");if(n<0)return e;const r=e.slice(s+2,n),i=I(e,n+4,"else"),o=T(e,i<0?n+4:i+4),a=e.slice(n+4,i<0?o:i),l=i<0?"unchanged":e.slice(i+4,o).trim();e=`${e.slice(0,s)}((${r.trim()}) ? (${a.trim()}) : (${l}))${e.slice(o)}`}return e}(e)).replace(/\(\s*\\?b?mod\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=Z(e,t);else if("_"===e[t]||"^"===e[t]){const s=/^§\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 n=t+1;for("-"===e[n]&&n++;n<e.length&&".0123456789".includes(e[n]);)n++;n===t+2&&"-"===e[t+1]&&(n=t+1),n>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,n)+"}"+e.slice(n))}return e}],["squeeze",function(e){return e.replace(/\s+/g,(t,s)=>{const n=e[s-1]??"",r=e[s+t.length]??"";return"Δ"===n?"":/[A-Za-z\u0370-\u03FF′]/.test(n)&&/[A-Za-z\u0370-\u03FF]/.test(r)?" ":""})}],["symbols",Ie],["compact",function(e){e=function(e){for(let t=0;t<e.length;t++){const s=t>0&&H.test(e[t-1]);let n,r=null,i=t;if(e.startsWith("frac{",t)){const s=X(e,t+4),n=s&&X(e,s[1]);r=n&&Q(s[0],n[0]),r&&(i=n[1])}else if("d"===e[t]&&!s){let[s,n]=V(e,t+1),o="";if(H.test(e[n]??"")&&"/"===e[n+1]&&(o=e[n++]),"/"===e[n]&&"d"===e[n+1]&&H.test(e[n+2]??"")){const t=e[n+2],[,a]=V(e,n+3);r={n:s,of:o,by:t},i=a}}if(r){if(r.of)n=K(r.of,r.by,r.n);else{const[t,s]=J(e,i);if(!t)continue;n=K(t,r.by,r.n),i=s}e=e.slice(0,t)+n+e.slice(i),t+=3}}return e}(e=function(e){for(let t=e.indexOf(")′");t>=0;t=e.indexOf(")′",t+1)){let s=0,n=-1;for(let r=t;r>=0;r--)if(")"===e[r])s++;else if("("===e[r]&&0===--s){n=r;break}if(n<0)continue;for(;n>0&&/[A-Za-z\u0370-\u03FF′]/.test(e[n-1]);)n--;let r=0;for(;"′"===e[t+1+r];)r++;e=e.slice(0,n)+K(e.slice(n,t+1),"x",r)+e.slice(t+1+r),t=n}return e}(e=(e=j(e)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}")));for(let t=0;t<e.length;t++){const s=e[t],n=s=>e.slice(Math.max(0,t-s),t),r=s=>e.slice(Math.max(0,t-s),t+1);if("{"===s){if("\\begin"===n(6)){const s=W(e.slice(t+1));s&&(e=e.slice(0,t-6)+s)}}else if("["===s)"\\sqrt"===n(5)?e=e.slice(0,t-5)+"sqrt"+F(e.slice(t+1)):"sqrt"===n(4)&&(e=e.slice(0,t-4)+"sqrt"+F(e.slice(t+1)));else if("⌊"===s||"⌈"===s)e=e.slice(0,t)+P(e.slice(t));else if("t"===s)"\\int"===r(3)&&(e=e.slice(0,t-3)+U(e.slice(t+1)));else if("m"===s)"\\binom"===r(5)&&(e=e.slice(0,t-5)+"\\binom"+G(e.slice(t+1)));else if("d"===s&&"dd"===r(1)&&"("===e[t+2]){const s=B(e.slice(t+1));s&&(e=e.slice(0,t-1)+"der"+s)}}return e.replace(/\\log/g,"log")}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]];function Ze(e,t={}){if("string"!=typeof e)throw new Error("Expression must be a string");const{text:s,strings:n}=function(e){const t=new Map;let s="",n=0;for(;n<e.length;){const r=e[n];if('"'!==r&&"'"!==r&&"`"!==r){s+=e[n++];continue}let i=n+1,o="",a=!1;for(;i<e.length&&(a||e[i]!==r);)a=!a&&"\\"===e[i],o+=e[i++];const l=te(t.size);t.set(l,r+o+r),s+=l,n=i+1}return{text:s,strings:t}}(function(e){let t="";for(let s=0;s<e.length;s++){const n=e[s];if('"'===n||"`"===n){const n=se(e,s);t+=e.slice(s,n+1),s=n}else if("'"===n)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(t[t.length-1]??""))t+="′";else{const n=se(e,s);t+=e.slice(s,n+1),s=n}else t+=n}return t}(e));let r=s.replace(/\t/g," ");t.evaluate&&(r=function(e,t,s){let n=0;for(;;){const r=e.indexOf("{{",n);if(r<0)return e;const i=je(e,r);if(i<0)return e;let o=e.slice(r+2,i).trim();for(const[e,s]of t)o=o.split(e).join(s);try{let a=s(o);if(/^["'`]/.test(a)){const e=te(t.size);t.set(e,a),a=e}const l=e.slice(0,r).trimEnd(),c=e.slice(i+2).trimStart();/^[\d.]/.test(a)&&(/[\d.]$/.test(l)||/^[\d.]/.test(c))&&(a=`(${a})`),e=e.slice(0,r)+" "+a+" "+e.slice(i+2),n=0}catch{n=i+2}}}(r,n,t.evaluate));const i=[["strings",r]];for(const[e,t]of Te){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:n,steps:i}}function je(e,t){let s=0;for(let n=t+2;n<e.length;n++){if(e.startsWith("}}",n)&&0===s)return n;"{"===e[n]?s++:"}"===e[n]&&s--}return-1}const Pe={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 Fe(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function We(e){if("*"!==e.op)return!1;const[t,s]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==Fe(s)}function De(e){return"op"!==e.type||o(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":We(e)?null:e.op}const Ue=(e,t,s)=>c(e.op,De(t),s);function Be(e,t){const s=De(t),n=s&&o(s)?.prec;return!!n&&("!"===e?n<=o("!").prec:"\\not"===e?n<o("\\not").prec:n<70||Ke(t)||"\\not"===s)}function Ge(e,t,s={}){const n=s.left?"bracket":Qe(e),r=s.right?"bracket":Ve(t);return"digit"!==r&&"sign"!==r&&"word"!==n&&"word"!==r&&"other"!==n&&("frac"!==r||"digit"!==n&&"frac"!==n)}function He(e){return 1===e.length||Boolean(Pe[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function Xe(e){return"op"===e.type&&!o(e.op)?.group&&(o(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function Ve(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&He(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||We(e)?"sign":"/"===t?"frac":o(t)?.group||Xe(e)?"bracket":Je(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?Xe(e.args[0])?"bracket":Ve(e.args[0]):["*","sum","prod","perm"].includes(t)?Ve(e.args[0]):"other"}function Qe(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&He(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":o(t)?.group||Xe(e)||Je(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?Qe(e.args[e.args.length-1]):"other"}function Je(e){if("op"!==e.type)return!1;const t=o(e.op);return"prefix"===t?.fixity&&100===t.prec}function Ke(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||We(e))return!0;const t=o(e.op);return"infix"===t?.fixity&&!Ue(e,e.args[0],"left")&&Ke(e.args[0])}const Ye=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),et=e=>e.slice(2);function tt(e){const t=e.args[1];let s=0,n=e;for(;"op"===n.type&&"der"===n.op&&st(n.args[1],t);)s++,n=n.args[0];return{n:s,body:n,by:t,variable:"symbol"===n.type&&He(n.value)}}const st=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,nt=new Set(["<",">","≤","≥","=","≠"]);function rt(e){if("op"!==e.type||!nt.has(e.op)||2!==e.args.length)return null;const[t,s]=e.args;if("op"!==t.type||!nt.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[rt(t)??t,{type:"op",op:e.op,args:[t.args[1],s]}]}}for(const e of[Pe])Object.setPrototypeOf(e,null);function it(e){if(e.length>1e6)throw new Error("The output would be too long");return e}const ot=Object.keys(u).filter(e=>100===u[e]&&/^[a-z]{2,}$/.test(e)),at=["frac"],lt=[...Object.keys(Pe),"pi","tau","inf","infinity","exp"],ct="\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+/),ht=new Set([...lt,...ct,"true","false","null","undefined","deg","mod","pmod","NaN","Infinity"]),ut=/^[a-zA-ZͰ-Ͽ]$/,pt=new Set(["f","g","h","u","v","F","G","H"]),ft=e=>ot.includes(e)||at.includes(e),gt=[...ot,...at,...lt].sort((e,t)=>t.length-e.length),mt=[...ot,...at,"pi"].sort((e,t)=>t.length-e.length);function dt(e,t=gt){const s=[];let n=0;for(;n<e.length;){const r=t.find(t=>e.startsWith(t,n))??e[n];s.push(r),n+=r.length}return s}function $t(e){if(ft(e))return!0;const t=dt(e,mt);return t.length>1&&ft(t[t.length-1])&&!ht.has(e)}function yt(e,{mode:t="plain",followed:s=!0}={}){if(e.includes("′")&&/^[a-zA-Z′]+$/.test(e)&&!/^.′+$/.test(e))return e.match(/[a-zA-Z]′*/g);if(!((n=e).length>0&&[...n].every(e=>ut.test(e)))||1===e.length||ht.has(e)||ft(e))return[e];var n;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return xt(dt(e),s);if(e.length<=2)return[...e];const r=xt(dt(e,mt),s),i=r.findIndex(e=>e.length>1);if(i<0)return[e];if("pi"===r[i]&&!r.some(e=>ot.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 xt(e,t){const s=e[e.length-1];return t||!ot.includes(s)?e:[...e.slice(0,-1),...s]}const bt="§",wt=/[A-Za-zͰ-Ͽ′]/,vt=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function kt(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const s=[];let n="";const i=e=>{n&&(vt(n)?s.push(...function(e,t,s){if((e=>new RegExp(`^${Y}[${ee}]+$`).test(e))(e))return[e];if(g.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 pt.has(e)?[r+e]:[e];if(p(e))return[e];const s=yt(e,{mode:t,followed:!0});return s.length>1?s:e.length<=2?[...e]:[r+e]}(e,s);const n=void 0!==t&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(t);return yt(e,{mode:s,followed:n})}(n,e,t)):s.push(n),n="")};for(let t=0;t<e.length;t++){const o=e[t];if(o===bt){i(o);const n=e.indexOf(bt,t+1),a=e.slice(t,n+1);s.push(g.includes(e[n+1])?r+a:a),t=n;continue}if(vt(n)&&/[0-9]/.test(o)&&p(n+o)){const{op:r,end:i}=_t(e,t,n+o);s.push(r),n="",t=i;continue}if(wt.test(o)&&"′"!==o&&d(n)&&(s.push(n),n=""),wt.test(o)&&(""===n?"′"!==o:vt(n)))n+=o;else if(/[0-9]/.test(o)&&vt(n)&&!$t(n))n+=o;else if(vt(n)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))n&&s.push(...Et(n,o)),n="",s.push(o);else if("_"!==o&&" "!==o){if(p(n+o)){const{op:r,end:i}=_t(e,t,n+o);s.push(r),n="",t=i;continue}if(p(o)){i(o);const{op:n,end:r}=_t(e,t,o);s.push(n),t=r;continue}n+=o}else i(e[t+1]),"_"===o&&s.push("_")}if(i(void 0),s.some(e=>/^:/.test(e)))throw new Error("Unmatched ':'");return s}function _t(e,t,s){let n=t;for(;n+1<e.length&&p(s+e[n+1]);)s+=e[n+1],n++;return"!"===s&&"_"===e[n+1]&&n++,{op:s,end:n}}function Et(e,t){if(!g.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[p(t)?t:r+t]}return d(e)?[e,"*"]:p(e)||ft(e)||d(e[0])?[e]:[r+e]}const At=70,Mt=100,qt="%mod",Ot=e=>g.includes(e),Nt=e=>m.includes(e),Lt=e=>i(e)||u[e]===Mt&&"_"!==e,St=new Set(["\\comb","\\perm","comb","perm"]),Ct={frac:"/","\\binom":"\\binom"},Rt={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class zt{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(Nt(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){for(this.parseOperand();;){const s=this.peek();if(void 0===s||Nt(s))return;const n=this.operatorAt(s,t);if(!n||n.lbp<=e)return;n.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:u.mod,run:()=>this.modulo()};if(e===qt)return{lbp:At,run:()=>{this.next(),this.parseExpression(At),this.emit("mod")}};if("pmod"===e)return{lbp:u.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:Mt,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(St.has(e))return{lbp:Mt,run:()=>{this.next(),this.parseExpression(Mt),this.emit(e)}};const s=u[e];if(void 0!==s&&!Lt(e)&&"\\not"!==e&&!(e in Ct)){const t=f.has(e)?s-1:s;return{lbp:s,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:t&&!Lt(e)?71:At,run:()=>{this.parseExpression(At),this.emit("*")}}}startsOperand(e){return void 0===e||Nt(e)||"|"===e?"|"===e:e!==qt&&(!!(Ot(e)||Lt(e)||e in Ct)||!p(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:u["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(u["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(At,!0),this.emit("mod")}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],s=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(Ot(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===s||Nt(s))||Ot(t)&&Nt(s)?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 Ct)return this.parseScript(),this.parseScript(),this.emit(Ct[e]);if("log"===e)return this.logarithm();if("lim"===e&&"_"===s)return this.limit();if(("\\sumidx"===e||"\\prodidx"===e)&&"_"===s)return this.bigOperator(e);if(Lt(e))return this.functionCall(e);if(Nt(e)||p(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||!d(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(Nt(this.peek()))return void this.emit("∅",e+this.next());this.frames.push({comma:!1}),this.parseExpression(0);const{comma:s}=this.frames.pop(),n=this.peek();Nt(n)&&(this.next(),s?this.emit(e+n):t&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const e=this.peek();if(Ot(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(Lt(e))return this.parseOperand();if(this.next(),void 0===e||Nt(e)||p(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(u["+"],!0),this.emit(...t,",","()","lim")}bigOperator(e){this.next();const t=this.out.length;this.parseScript();let s=this.out.splice(t);"^"===this.peek()&&(this.next(),this.parseScript(),s=[...s,...this.out.splice(t),","]),this.parseExpression(u["+"],!0),this.emit(...s,",","()",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&&!Ot(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(Ot(e))return this.next(),this.bracket(e);this.parseExpression(At,!0)}}function It(e,t){e=function(e){const t=[];for(let s=0;s<e.length;s++){const n=e[s],i=e=>"string"==typeof e&&/^[a-zA-Z]$/.test(e);if(pt.has(n)&&"^ { - 1 } ("===e.slice(s+1,s+7).join(" ")){t.push(r+n+"⁻¹"),s+=5;continue}const[o,a,l]=e.slice(s+1,s+4),c=i(a)?a!==n:d(a);i(n)&&"e"!==n&&"("===o&&c&&")"===l?t.push(r+n):t.push(n)}return t}(e);const s=[];for(const n of e)p(n)||Ot(n)||Nt(n)||"_"===n||i(n)||d(n)?s.push(n):s.push(...Tt(n,t));return s}function Tt(e,t){const s=e=>It(kt(e,t),t);let n=0;for(;n<e.length&&d(e.slice(0,n+1));)n++;if(0===n){if("%"===e[0])return[qt,...s(e.slice(1))];const n=e.indexOf("%");return n>0&&n<e.length-1?[...Tt(e.slice(0,n),t),qt,...s(e.slice(n+1))]:[e]}const r=e.slice(n);return"%"===r[0]?1===r.length?[e]:[e.slice(0,n),qt,...s(r.slice(1))]:[e.slice(0,n),...s(r)]}for(const e of[Ct,Rt])Object.setPrototypeOf(e,null);const Zt=new Set(["()","[]","{}","(]","[)"]),jt={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠="},Pt=new Set(["round","fixed","der"]),Ft=e=>i(e)||100===u[e];function Wt(t){const s=[],n=e=>{if(!s.length)throw new Error(`'${e}' is missing an operand`);return s.pop()},r=e=>e.list?e.list:[e],a=(e,t)=>{if(e.list)throw new Error(`A list of values needs brackets around it (near '${t}')`);return e};if(t.forEach((l,c)=>{if("∅"===l)return void s.push({list:[]});if(","===l){const e=n(l),t=n(l);return void s.push({list:[...r(t),...r(e)]})}if(Zt.has(l)){const e=r(n(l));if(!e.length&&!Ft(t[c+1]))throw new Error("Empty brackets");return void s.push(x(l,e))}const h=jt[l]??l,u=o(h);if(!u){if("?"===l||"abs("===l)throw new Error(`Unmatched '${l[0]}'`);return void s.push(w(l))}let p;if(Ft(l)&&Zt.has(t[c-1])&&s[s.length-1]?.op===t[c-1])p=s.pop().args;else{let t=u.arity===e||Pt.has(h)?1:u.arity;if(s.length<t)throw new Error(`'${l}' needs ${t} operand${1===t?"":"s"}`);p=s.splice(s.length-t,t).map(e=>a(e,l))}s.push(function(t,s){switch(t){case"sqrt":if(2===s.length)return x("root",s);break;case"round":if(1===s.length)return x("round",[s[0],$(0)]);break;case"sum":case"prod":{const e=s[1];if("op"===e?.type&&"symbol"===e.args[0]?.type&&(3===s.length&&"="===e.op||2===s.length&&"∈"===e.op))return x("sum"===t?"\\sumidx":"\\prodidx",s);break}case"fixed":if(1===s.length)return x("fixed",[s[0],$(2)]);break;case"der":if(1===s.length)return x("der",[s[0],y("x")]);if(3===s.length)return function([e,t,s]){const n="number"===s.type?Number(s.value):NaN;if(!Number.isInteger(n)||n<1||n>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");let r=e;for(let e=0;e<n;e++)r=x("der",[r,t]);return r}(s);break;case"log":if("symbol"===s[0].type&&"e"===s[0].value)return x("ln",[s[1]]);break;case"lim":return x("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?{"\\+":"r","\\-":"l"}[e.args[1].value]:void 0,[s,n,r]=e;if(2===e.length&&"op"===n.type&&"→"===n.op&&t(n.args[1])){const[e,r]=n.args;return[s,e,r.args[0],y(t(r))]}return 3===e.length&&t(r)?[s,n,r.args[0],y(t(r))]:e}(s));case"\\:if":if(2===s.length||3===s.length)return x("?:",[s[0],s[1],s[2]??y("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return function(t,s){const{arity:n}=o(t);if(n===e){if(0===s.length&&!i(t))throw new Error(`'${t}' needs at least one argument`);return}if(s.length!==n){throw new Error(`'${t}' takes ${n} argument${1===n?"":"s"}, not ${s.length}`)}}(t,s),x(t,s)}(h,p))}),1!==s.length)throw new Error(s.length?"Some values are not connected by an operator":"Empty expression");return a(s[0],"end")}for(const e of[jt])Object.setPrototypeOf(e,null);const Dt=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Ut=e=>/^[a-z][a-z0-9]*$/.test(e)&&p(e);function Bt(e){return e.includes("\\")?(e=function(e){for(let t=0;t<50;t++){const t=e.lastIndexOf("\\begin{cases}"),s=t<0?-1:e.indexOf("\\end{cases}",t);if(s<0)return e;const n=z(e.slice(t+13,s),"\\\\").map(e=>z(e,"&")).filter(e=>e.join("").trim());let r=null;for(let e=n.length-1;e>=0;e--){const t=n[e][0].trim(),s=R(n[e].slice(1).join("&"));r=null!==r||s?`((${s||"true"}) ? (${t}) : ${r??"(unchanged)"})`:`(${t})`}e=e.slice(0,t)+(r??"")+e.slice(s+11)}return e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):e}function Gt(e){Ht=e}let Ht=null;function Xt(e,t={}){const s={original:e};try{if("string"!=typeof e)throw new Error("Expression must be a string");const n=t.maxLength??5e3;if(e.length>n)throw new Error(`Longer than ${n} characters (options.maxLength)`);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=[],s=[]){const n=new Map,r=e=>{const t=`${bt}${n.size}${bt}`;return n.set(t,e),t};e=e.replace(Dt,(e,t)=>Ut(t.trim())?` ${t.trim()}`:r(t.trim()));for(const s of[...t].sort((e,t)=>t.length-e.length)){const t=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${t}(?![A-Za-z0-9_])`,"g"),()=>r(s))}for(const t of[...s].sort((e,t)=>t.length-e.length)){const s=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${s}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(e,s,n)=>r(t)+(n?" * (":s))}return{text:e,protectedNames:n}}(Bt(e),t.names,[...t.values??[],...i]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=((e,t={})=>{const s=void 0===t.blocks?Ht:t.blocks;return Ze(e,{evaluate:s?e=>s(e,t.scope):void 0})})(o,{blocks:t.blocks,scope:t.scope}),p=e=>ne(ne(e,h),a);s.mode=l,s.cleaned=p([c])[0],s.cleanSteps=u,s.tokens=kt(c,l),s.rawPostfix=p(function(e,t="plain"){return new zt(It(e,t)).parseAll().map(e=>Rt[e]??e)}(s.tokens,l));const f=_(Wt(s.rawPostfix));s.postfix=f,s.tree=k(f)}catch(e){s.error=e instanceof RangeError?"Nested too deeply":e.message}return s}const Vt=e=>"string"==typeof e&&e.length>80?`${e.slice(0,77)}…`:e;function Qt(e,t={}){const s=Xt(e,t);if(t.keepIntermediateSteps)return s;if(!s.error)return s.postfix;if(t.allowUnvalidated&&s.rawPostfix)return s.rawPostfix;throw new Error(`Failed to parse expression "${Vt(e)}": ${s.error}`)}function Jt(e,t={}){const s=Xt(e,t);if(s.error)throw new Error(`Failed to parse expression "${Vt(e)}": ${s.error}`);return s.tree}const Kt=(e,t)=>"string"==typeof e?Jt(e,t):E(e),Yt=e=>Array.isArray(e)&&0===e.length,es={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",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",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",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"]},ts={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",atan2:"the arctangent",round:"round",fixed:"fixed",random:"random"},ss=Object.fromEntries(Object.entries(Pe).map(([e,t])=>[t,e]));function ns(e,t={}){return function(e){const t=[];for(const{text:s,id:n}of e){const e=s.trim();if(!e)continue;const r=e.startsWith(","),i=r?e.slice(1).trim():e;r&&t.length&&!t[t.length-1].text.endsWith(",")&&(t[t.length-1].text+=","),i&&t.push({text:i,id:n})}t.length&&(t[t.length-1].text=t[t.length-1].text.replace(/,$/,""));return t}(new as({...es,...t.words},{...ts,...t.names},t.say||{}).speak(e))}function rs(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const is={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},os={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class as{constructor(e,t,s){this.w=e,this.names=t,this.say=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=>rs(this.speak(e))):[e.value],e,e=>rs(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(os[e])return t[os[e]];if(ss[e])return ss[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const s=/′+$/.exec(e);return s?`${this.symbol(e.slice(0,-s[0].length))} ${this.primes(s[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){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),this.seg(e,this.w.comma)]:this.speak(e)}argument(e){return this.quantity(e)}operation(e){const{op:t,args:s}=e,[n,r]=s,o=this.w,a=t=>this.seg(e,t),l=()=>s.flatMap((e,t)=>t?[a(o.comma),...this.speak(e)]:this.speak(e));if(is[t])return[...this.speak(n),a(o[is[t]]),...this.speak(r)];if(i(t)){const e=this.symbol(et(t));return s.length?[a(`${e} ${o.of}`),...this.arguments(s)]:[a(e)]}if(this.names[t]&&!["log","round","fixed","atan2","random","expm1"].includes(t))return[a(`${this.names[t]} ${o.of}`),...this.arguments(s)];switch(t){case"+":return We(r)?[...this.speak(n),a(o.minus),...this.speak(r.args[1])]:[...this.speak(n),a(o.plus),...this.speak(r)];case"-":return We(r)?[...this.speak(n),a(o.plus),...this.speak(r.args[1])]:[...this.speak(n),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(n),a(o.sub),...this.speak(r)];case"neg":return this.isCompound(n)||"op"===n.type&&"neg"===n.op?[a(`${o.negative} ${o.quantity}`),...this.speak(n),a(o.comma)]:[a(o.negative),...this.speak(n)];case"pm":return[a(o.plusOrMinus),...this.speak(n)];case"!":return[...this.quantity(n),a(o.factorial)];case"\\not":return[a(o.not),...this.quantity(n)];case"sqrt":return[a(o.squareRoot),...this.speak(n),...this.pauseAfter(n)];case"root":{const e="number"===n.type?Number(n.value):NaN,t=3===e?o.cubeRoot:2===e?o.squareRoot:o.nthRoot(e?this.ordinal(e):rs(this.speak(n))+"th");return[a(t),...this.speak(r),...this.pauseAfter(r)]}case"abs":return[a(o.absoluteValue),...this.speak(n),...this.pauseAfter(n)];case"floor":return[a(o.floor),...this.speak(n),...this.pauseAfter(n)];case"ceil":return[a(o.ceiling),...this.speak(n),...this.pauseAfter(n)];case"log":return"symbol"===n.type&&"e"===n.value?[a(`${this.names.ln} ${o.of}`),...this.argument(r)]:[a(`${o.logBase}`),...this.speak(n),a(o.of),...this.argument(r)];case"mod":return[...this.quantity(n),a(o.mod),...this.quantity(r)];case"pmod":return[...this.speak(n),a(`${o.comma} ${o.mod}`),...this.speak(r)];case"perm":return[...this.quantity(n),a(o.permute),...this.quantity(r)];case"comb":return[...this.quantity(n),a(o.choose),...this.quantity(r)];case"round":{const e=0===("number"===r.type?Number(r.value):NaN)?o.nearestWholeNumber:`${rs(this.speak(r))} ${o.decimalPlaces}`;return[...this.speak(n),a(`${o.comma} ${o.rounded} ${e}`)]}case"fixed":return 0===("number"===r.type?Number(r.value):NaN)?[...this.speak(n),a(`${o.comma} ${o.asWholeNumber}`)]:[...this.speak(n),a(`${o.comma} ${o.writtenTo}`),...this.speak(r),a(o.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${o.of}`),...this.speak(n),a(o.over),...this.speak(r)];case"random":return[a(o.randomNumber)];case"expm1":return[a(o.eToThe),...this.speak(n),a(`${o.comma} ${o.minus} 1`)];case"?:":return[a(o.if),...this.speak(n),a(`${o.comma} ${o.then}`),...this.speak(r),a(`${o.comma} ${o.otherwise}`),...this.speak(s[2])];case"sum":return s.flatMap((e,t)=>t?[a(o.plus),...this.speak(e)]:this.speak(e));case"prod":return s.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===s.length?[a(o.openInterval),...this.speak(n),a(o.to),...this.speak(r)]:l();case"[]":return 2===s.length?[a(o.closedInterval),...this.speak(n),a(o.to),...this.speak(r)]:[a(o.theList),...l()];case"(]":case"[)":return[a(o.halfOpenInterval),...this.speak(n),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);case"\\prodidx":return this.bigOperator(e,o.productFrom,o.productOver,o.productOf)}throw new Error(`No speech for '${t}'`)}arguments(e){return 1===e.length?this.argument(e[0]):e.flatMap((e,t)=>t?[{text:this.w.comma,id:e.id},...this.speak(e)]:this.speak(e))}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}quantityIfSum(e){return this.quantity(e)}product(e){const[t,s]=e.args,n=this.w;if(We(e))return[this.seg(e,n.negative),...this.speak(s)];if("symbol"===s.type&&"°"===s.value)return[...this.speak(t),this.seg(e,n.degrees)];const r=this.quantity(t),i=this.quantity(s);return this.isCompound(t)||this.isCompound(s)||this.isWord(t)||this.isWord(s)||this.startsWithNumber(s)||"op"===s.type&&"/"===s.op||this.isCall(t)||i[0].text.startsWith("the ")?[...r,this.seg(e,n.times),...i]:[...r,...i]}isWord(e){return"symbol"===e.type&&/^[A-Za-z]{2,}$/.test(e.value)&&!Pe[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,s]=e.args,n=this.w,r=t=>this.seg(e,t);if("number"===t.type&&"number"===s.type&&/^[1-9]$/.test(t.value)&&/^([2-9]|10)$/.test(s.value)){const e=Number(t.value),i=Number(s.value),o=2===i?1===e?n.half:n.halves:n.ordinals[i]+(1===e?"":"s");return[r(`${n.numerators[e]} ${o}`)]}return[...this.quantity(t),...this.isCall(t)?[r(n.comma)]:[],r(n.over),...this.quantity(s)]}power(e){const[t,s]=e.args,n=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?[r(n.quantity),...this.speak(t),r(n.comma)]:this.speak(t);if(this.isCall(t)&&this.names[t.op]&&"number"===s.type&&/^[2-3]$/.test(s.value)&&1===t.args.length){const e=2===Number(s.value)?n.squared:n.cubed;return[r(`${this.names[t.op]} ${e} ${n.of}`),...this.argument(t.args[0])]}if("number"===s.type&&/^(?:[1-9]|10)$/.test(s.value)){const e=Number(s.value);return 2===e||3===e?[...i,r(n.powers[e])]:[...i,r(`${n.toThe} ${n.powers[e]}`)]}if("number"===s.type&&/^\d+$/.test(s.value))return[...i,r(`${n.toThe} ${this.ordinal(Number(s.value))}`)];return!(this.isCompound(s)||"op"===s.type&&"/"===s.op&&this.isCompound(s.args[0]))?[...i,r(n.toThe),...this.speak(s)]:[...i,r(n.toThePowerOf),...this.speak(s),r(n.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:s,by:n,variable:r}=tt(e),i=this.w,o=t=>this.seg(e,t);if(r){return[o(1===t?i.d:`${i.d} ${2===t?i.squared:3===t?i.cubed:`${i.toThe} ${this.ordinal(t)}`}`),...this.speak(s),o(i.d),...this.speak(n),o(1===t?"":2===t?i.squared:3===t?i.cubed:`${i.toThe} ${this.ordinal(t)}`)]}return[o(`${1===t?i.derivative:2===t?i.secondDerivative:i.nthDerivative(this.ordinal(t))} ${i.withRespectTo}`),...this.speak(n),o(i.of),...this.speak(s),...this.pauseAfter(s)]}integral(e){const{args:t}=e,[s,n,r,i]=t,o=this.w,a=t=>this.seg(e,t),l=t.length>=2&&"symbol"===n.type&&1===n.value.length,c=l?this.speak(n):[a(M(s)||"x")];let h=[];4===t.length?h=[r,i]:3===t.length?h=l?[r]:[n,r]:2!==t.length||l||(h=[n]);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(s),a(`${o.comma} ${o.d}`),...c]}limit(e){const{args:t}=e,[s,n,r,i]=t,o=this.w,a=t=>this.seg(e,t);let l;if(t.length>=3){if(l=[...this.speak(n),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"===n.type&&"→"===n.op)l=[...this.speak(n.args[0]),a(o.approaches),...this.speak(n.args[1])];else{if(2!==t.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(s)];{const e=M(s);l=e?[a(e),a(o.approaches),...this.speak(n)]:this.speak(n)}}return[a(o.limitAs),...l,a(o.of),...this.speak(s),...this.pauseAfter(s)]}bigOperator(e,t,s,n){const{args:r}=e,[i,o,a]=r,l=this.w,c=t=>this.seg(e,t);let h;return h=3===r.length?[c(t),...this.speak(o),c(l.to),...this.speak(a),c(l.of)]:2===r.length?[c(s),...this.speak(o),c(l.of)]:[c(n)],[...h,...this.speak(i),...this.pauseAfter(i)]}}for(const e of[es,ts,is,os,ss])Object.setPrototypeOf(e,null);function ls(e,t={}){return Yt(e)?"":function(e,t={}){return rs(ns(e,t))}(Kt(e),t)}function cs(e,t={}){return Yt(e)?[]:ns(Kt(e),t)}const hs={"(":{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"},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 us(e,t,s=""){const n=hs[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${s?` style="${s}"`:""}>${n.fill?`<path d="${n.fill}" fill="currentColor"/>`:`<path d="${n.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const ps=.8,fs=.2,gs=.25,ms=.7,ds="−",$s={"+":"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"},ys={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},xs={"±":"±","∪":"∪","∩":"∩",mod:"mod"},bs=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],ws={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},vs=[...bs,...Object.keys(ws),"ln"],ks={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},_s={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},Es={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},As={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},Ms=["boxed","overline","bar","underline","cancel",...Object.keys(As)],qs={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,attributes:null,style:null},Os=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Ns=e=>+e.toFixed(3)+"em",Ls=(e,t=ps,s=fs)=>({html:e,h:t,d:s});function Ss(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(ps,...t.map(e=>e.h)),d:Math.max(fs,...t.map(e=>e.d))}}function Cs(e,t={}){const s=new Rs({...qs,...t}),n=s.render(e,{level:0}),r=`${s.p}${s.o.display?` ${s.p}-display`:""}`,i=function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):ls(e)}catch{return null}}(e,s.o.label),o=null===i?n.html:n.html.replace(/^<span /,'<span aria-hidden="true" ');return{html:`<span class="${r}"${null===i?"":` role="math" aria-label="${Os(i)}"`}>${o}</span>`,h:n.h,d:n.d}}class Rs{constructor(e){this.o=e,this.p=e.prefix}el(e,t,s="",n=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${s?` style="${s}"`:""}${n}>${t}</span>`}text(e,t){const s=Ls(this.el(e,Os(t)));return s.leaf={kind:e,content:Os(t)},s}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,s){let n="";void 0!==e.id&&(n+=` data-node="${e.id}"`),"op"===e.type&&(n+=` data-op="${Os(e.op)}"`);const r=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(r))"class"!==e&&"style"!==e&&(n+=` ${e}="${Os(t)}"`);const i=[r.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),o=(s.leaf?["n",...t,s.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(r.class?[r.class]:[]).join(" "),a=s.leaf?s.leaf.content:s.html;return{html:`<span class="${o}"${i?` style="${Os(i)}"`:""}${n}>${a}</span>`,h:s.h,d:s.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(/^-/,ds)))}symbol(e){return Pe[e]&&(e=Pe[e]),Es[e]?this.text("ord",Es[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)?Ls(this.el("var",Os(e[0]))+this.el("prime",Os(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?Ls(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:s,args:n}=e,[r,o]=n,a=(e,s={})=>this.render(e,{...t,...s,forceParens:s.forceParens||!1,before:s.before||!1}),l=$s[s]??(/^[a-z0-9]+$/i.test(s)?s:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,s)=>Ue(e,t,s)&&"/"!==t.op?this.fence(a(t)):a(t);if(vs.includes(s)||"log"===s)return c(this.named(e,t));if(ks[s])return c(Ss(this.word(ks[s]),this.fence(this.list(n,t))));if(i(s))return c(this.custom(e,t));if(_s[s])return c(this.fence(this.list(n,t),..._s[s]));if(ys[s]&&2===n.length)return c(Ss(h(r,"left"),this.rel(ys[s]),h(o,"right")));if(xs[s]&&2===n.length)return c(Ss(h(r,"left"),this.bin(xs[s]),h(o,"right")));switch(s){case"+":return We(o)?c(Ss(h(r,"left"),this.bin(ds),this.wrap(o,["op","op-mul"],this.render(o.args[1],t)))):"number"===o.type&&o.value.startsWith("-")?c(Ss(h(r,"left"),this.bin(ds),this.wrap(o,["number"],this.text("num",o.value.slice(1))))):c(Ss(h(r,"left"),this.bin("+"),this.signed(o,h(o,"right"))));case"-":return c(Ss(h(r,"left"),this.bin(ds),this.signed(o,h(o,"right"))));case"*":return c(this.product(e,t));case"/":return c(this.fraction(e,t));case"^":return c(this.power(e,t));case"_":return c(this.script(a(r,{forceParens:!0}),null,t,a(o,{level:t.level+1})));case"neg":return c(Ss(this.text("sign",ds),Be(s,r)?this.fence(a(r)):a(r,{before:t.before})));case"pm":return c(Ss(this.text("sign","±"),Be(s,r)?this.fence(a(r)):a(r)));case"!":return c(Ss(Be(s,r)?this.fence(a(r)):a(r,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(Ss(this.text("sign","¬"),Be(s,r)?this.fence(a(r)):a(r)));case"pmod":return c(Ss(a(r),this.fence(Ss(this.word("mod"),this.text("space",""),a(o)))));case"sqrt":return c(this.radical(a(r)));case"root":return c(this.radical(a(o),this.render(r,{level:t.level+2})));case"abs":return c(this.fence(a(r),"|","|"));case"floor":return c(this.fence(a(r),"⌊","⌋"));case"ceil":return c(this.fence(a(r),"⌈","⌉"));case"loglog":return c(Ss(this.word("ln"),this.fence(Ss(this.word("ln"),this.fence(a(r))))));case"logloglog":return c(Ss(this.word("ln"),this.fence(Ss(this.word("ln"),this.fence(Ss(this.word("ln"),this.fence(a(r))))))));case"perm":return c(this.script(this.script(Ls(""),this.render(r,{level:t.level+1}),t),null,t,this.render(o,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(r),a(o),!1)));case"?:":return c(this.o.cases?this.cases(e,t):Ss(a(r),this.bin("?"),a(o),this.bin(":"),a(n[2])));case"sum":return c(Ss(n.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(Ss(n.map((e,t)=>t?[this.bin("·"),a(e)]:[a(e)]).flat()));case"der":return c(this.derivative(e,t));case"int":return c(this.integral(n,t));case"lim":return c(this.limit(n,t));case"\\sumidx":return c(this.bigOperator("sum",n,t));case"\\prodidx":return c(this.bigOperator("prod",n,t))}throw new Error(`Inline Math cannot draw '${s}'`)}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 Ss(e.map((e,s)=>s?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[s,n]=e.args;if(We(e))return Ss(this.text("sign",ds),this.render(n,t));const r=function(e){const[t,s]=e.args;return{left:Ue(e,t,"left")&&"/"!==t.op,right:Ue(e,s,"right")&&"/"!==s.op}}(e),o=Ge(s,n,r),a=function(e){for(;"op"===e.type;){if(vs.includes(e.op)||"log"===e.op||ks[e.op]||i(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(n),l=r.left?this.fence(this.render(s,t)):this.render(s,{...t,before:o&&!a}),c=r.right?this.fence(this.render(n,t)):this.render(n,{...t,before:t.before});return Ss(l,o?Ls(this.el(a?"fnspace":"times","")):this.bin("·"),c)}named(e,t,s=null){const{op:n,args:r}=e,i="log"===n?r[1]:r[0];let o;o=ws[n]&&"power"===this.o.inverseTrig?this.script(this.word(ws[n]),this.text("num","−1"),t):this.word(n),s&&(o=this.script(o,s,t)),"log"===n&&(o=this.script(o,null,t,this.render(r[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&zs(i),l=this.render(i,{...t,forceParens:!1,before:!1});return Ss(o,a?Ss(Ls(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const s=et(e.op),n=e.args;if(Ms.includes(s)&&1===n.length)return this.decorate(s,this.render(n[0],t));return Ss(/^[A-Za-z]′*(⁻¹)?$/.test(s)?this.symbol(s):this.word(s),Ls(this.el("callgap","")),this.fence(this.list(n,t)))}decorate(e,t){switch(e){case"boxed":return Ls(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return Ls(this.el("cancel",t.html),t.h,t.d);case"underline":return Ls(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return Ls(this.el("over",t.html),t.h+.14,t.d);default:return Ls(this.el("accent",this.el("accent-mark",As[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[s,n]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&zs(s,!0)&&zs(n,!0)){const e=e=>"op"!==e.type||zs(e)?this.render(e,t):this.fence(this.render(e,t));return Ss(e(s),this.text("ord","/"),e(n))}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(s,i),this.render(n,i),!0,r)}stack(e,t,s=!0,n=1){const r=e=>1===n?e.html:this.el("scaled",e.html,`font-size:${Ns(n)}`),i=s?.06:0,o=gs+i/2+.1+Math.max(fs,n*e.d),a=this.el("frac"+(s?"":" frac-nobar"),this.el("numer",r(e))+this.el("denom",r(t)),`vertical-align:${Ns(o)}`);return Ls(a,o+Math.max(ps,n*e.h),Math.max(ps,n*t.h)+Math.max(fs,n*t.d)+.1+i/2-gs)}power(e,t){const[s,n]=e.args,r={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1},i=()=>this.render(n,r);if(this.o.trigPowers&&bs.includes(s.op)&&Ts(n))return this.wrap(s,["op",`op-${s.op}`],this.named(s,t,i()));if("_"===s.op){const e=this.render(s.args[1],r);return this.wrap(s,["op","op-subscript"],this.script(this.render(s.args[0],{...t,forceParens:!0}),i(),t,e))}const o=Ue(e,s,"left")||"number"===s.type&&s.value.startsWith("-")||"/"===s.op||vs.includes(s.op)?this.fence(this.render(s,t)):this.render(s,{...t,forceParens:!0});return this.script(o,i(),t)}script(e,t,s,n=null,r=null){const i=s.level>0?.8:ms,o=r?Ss(e,r):e;let a=t?Math.max(.42,e.h-.38,i*t.d+.12):0,l=n?Math.max(.2,e.d-.05,i*n.h-.45):0;if(t&&n){const e=.1-(a-i*t.d-(i*n.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${Ns(i)}`);if(t&&!n)return Ls(e.html+this.el("sup",t.html,`font-size:${Ns(i)};vertical-align:${Ns(a/i)}`),Math.max(o.h,a+i*t.h),Math.max(o.d,i*t.d-a));if(n&&!t)return Ls(o.html+this.el("sub",n.html,`font-size:${Ns(i)};vertical-align:${Ns(-l/i)}`),Math.max(o.h,i*n.h-l),Math.max(o.d,l+i*n.d));const h=a+i*t.h,u=l+i*n.d,p=this.el("subsup",c(t)+c(n),`vertical-align:${Ns(a)};height:${Ns(h+u)}`);return Ls(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const s=Math.max(e.h,ps)+.1+.06,n=Math.max(e.d,fs),r=s+n,i=us("sqrt",`${this.p}-hook`,`height:${Ns(r)};width:${Ns(.5+.06*(r-1))};vertical-align:${Ns(-n)}`);let o="";if(t){const e=.8*ms;o=this.el("rootindex",t.html,`font-size:${Ns(e)};vertical-align:${Ns((.55*r-n)/e)}`)}return Ls(this.el("sqrt",o+i+this.el("radicand",e.html)),s,n)}fence(e,t="(",s=")"){const n=Math.max(e.h,ps)+Math.max(e.d,fs),r=n>1.25,i=r?.1:0,o=(e,t)=>{if(!e)return{html:"",w:0};const s={"(":.26,")":.26,"{":.36,"}":.36}[e];if(s){const i=s+(r?Math.min(.2,.05*(n-1)):0);return{html:us(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${Ns(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(s,"r"),c=`padding:${Ns(i)} ${Ns(l.w)} ${Ns(i)} ${Ns(a.w)}`,h=Ls(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,ps)+i,Math.max(e.d,fs)+i);return h.fenced=!0,h}derivative(e,t){const{n:s,body:n,by:r,variable:i}=tt(e),o={...t,level:t.level+1},a=()=>this.text("d","d"),c=()=>s>1?this.render({type:"number",value:String(s)},o):null,h={...t,inFraction:!0},u=Ss(a(),c()?this.script(this.render(r,h),c(),h):this.render(r,h)),p=e=>Ss(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(n,h)),u,!0,f);const g=De(n)&&l(De(n))<100,[m,d]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],$=g?this.fence(this.render(n,t),m,d):this.render(n,t);return Ss(this.stack(p(),u,!0,f),$)}integral(e,t){const[s,n,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",M(s)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:Ye(n)?c=o(n):(c=l(),h=a(n));break;case 3:Ye(n)?(c=o(n),h=a(r)):(c=l(),h=a(n),u=a(r));break;default:c=o(n),h=a(r),u=a(i)}const p=o(s),f=Ls(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Ss(this.bigSign("int",p,h,u,t),p,f)}bigSign(e,t,s,n,r){const i=!this.o.display||r.level>0,o=Math.max(i?.6:.95,Math.max(t.h-gs,t.d+gs)+.12),a=us(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${Ns(2*o)};width:${Ns(i?.38:.5)};vertical-align:${Ns(gs-o)}`);if(!s&&!n)return Ls(a,gs+o,o-gs);const l=ms,c=n||Ls(""),h=s||Ls(""),u=gs+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${Ns(l)}`)+this.el("script lower",h.html,`font-size:${Ns(l)}`),`vertical-align:${Ns(u)};height:${Ns(2*o)}`);return Ls(a+p,gs+o,o-gs)}limit(e,t){const[s,n,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 Ss(this.word("lim"),Ls(this.el("fnspace","")),this.render(s,t));case 2:{const e=M(s),t="number"===n.type||"symbol"===n.type&&n.value.includes("∞");c=e&&t?Ss(this.text("var",e),l(),a(n)):a(n);break}case 3:c=Ss(a(n),l(),a(r));break;default:{const e=Fe(i).toLowerCase().startsWith("r")?"+":ds;c=Ss(a(n),l(),this.script(a(r),this.wrap(i,["symbol"],this.text("ord",e)),o))}}return Ss(this.under(this.word("lim"),c,t),this.render(s,t))}under(e,t,s){return!this.o.display||s.level>0?this.script(e,null,s,t):Ls(this.el("under",e.html+this.el("script",t.html,`font-size:${Ns(.7)}`)),e.h,Math.max(e.d,fs)+.05+.7*(t.h+t.d))}bigOperator(e,t,s){const[n,r,i]=t,o={...s,level:s.level+1},a=r?this.render(r,o):null,l=i?this.render(i,o):null,c=this.render(n,s);if(!this.o.display||s.level>0){const t=.55,n=us(e,`${this.p}-bigsign`,`height:${Ns(2*t)};width:${Ns(.8)};vertical-align:${Ns(gs-t)}`);return Ss(this.script(Ls(n,gs+t,t-gs),l,s,a),c)}const h=.68,u=ms,p=us(e,`${this.p}-bigsign`,`height:${Ns(1.36)};width:${Ns("sum"===e?1:1.05)}`),f=l?1.01+u*l.d:gs-h,g=e=>this.el("script",e.html,`font-size:${Ns(u)}`),m=this.el("bigop",(l?g(l):"")+p+(a?g(a):""),`vertical-align:${Ns(f)}`);return Ss(Ls(m,.93+(l?.08+u*(l.h+l.d):0),h-gs+(a?.08+u*(a.h+a.d):0)),c)}cases(e,t){const s=[];let n=e;for(;"op"===n.type&&"?:"===n.op;)s.push([this.render(n.args[1],t),Ss(this.word("if"),this.text("space",""),this.render(n.args[0],t))]),n=n.args[2];s.push([this.render(n,t),this.word("otherwise")]);const r=s.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*(s.length-1),o=gs+i/2-r[0].h,a=s.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=Ls(this.el("cases",a,`vertical-align:${Ns(o)}`),gs+i/2,i/2-gs);return this.fence(l,"{","")}}function zs(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!We(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Is(e)||"*"===e.op&&zs(e,t)):zs(e.args[0],!0)&&("neg"===e.op||zs(e.args[1],!0)))}const Is=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(Pe[e.value])),Ts=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const Zs=e=>_(e).join(" ");function js(e,t){const s=new Set;Ps(e,t,s);const n=[];return A(e,e=>{s.has(e)&&n.push(e)}),n}function Ps(e,t,s){if(null!=t)if(Array.isArray(t))t.forEach(t=>Ps(e,t,s));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const n=Zs(Jt(t));return void A(e,e=>{Zs(e)===n&&s.add(e)})}if(t.path){const n=Fs(e,t.path);return void(n&&s.add(n))}if(t.type){const n=Zs(t);A(e,e=>{e!==t&&Zs(e)!==n||s.add(e)})}}else A(e,(e,n)=>{t(e,n)&&s.add(e)});else A(e,e=>{e.id===t&&s.add(e)})}function Fs(e,t){let s=e;for(const e of t){if("op"!==s.type||!s.args[e])return null;s=s.args[e]}return s}function Ws(e,t){const s=[],n=e=>{if(e.id===t)return!0;if("op"!==e.type)return!1;for(let t=0;t<e.args.length;t++){if(s.push(t),n(e.args[t]))return!0;s.pop()}return!1};return n(e)?s:null}function Ds(t){let s=0;const n=t=>{"op"===t.type&&(t.args.forEach(n),o(t.op)?.arity===e&&s++),t.id=s++};return n(t),t}function Us(e,t={}){const{blocks:s}=t;if("string"==typeof e)return Jt(e,s?{blocks:e=>s(e,t.scope)}:{});if(Array.isArray(e))return k(e);if(e&&"object"==typeof e&&e.type)return void 0===e.id?Ds(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Bs(e,t={}){const s=Us(e,t);return Cs(s,Gs(s,t)).html}function Gs(e,t){const{colors:s,highlight:n,scope:r,blocks:i,...o}=t,a=new Map;for(const[t,n]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(s))if(Hs(n))for(const s of js(e,t))a.set(s,`color:${n}`);const l=new Set(void 0===n?[]:js(e,n));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 Hs(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}export{Yt as A,Qt as B,o as C,qs as D,Pe as G,hs as P,Gs as a,Zs as b,Ds as c,Bs as d,Us as e,Kt as f,rt as g,Jt as h,M as i,E as j,Gt as k,Cs as l,it as m,Fs as n,We as o,Ws as p,i as q,et as r,js as s,cs as t,tt as u,c as v,De as w,Fe as x,Ye as y,Be as z};