@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.
- package/README.md +64 -20
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-Cz87Lt0N.js +2 -0
- package/dist/chunks/draw-Bev17BJJ.js +2 -0
- package/dist/chunks/edit-C65xXzo8.js +2 -0
- package/dist/chunks/edit-M68aRA5o.js +2 -0
- package/dist/chunks/{html-CvuSyhzk.js → html-BimAqn7x.js} +2 -2
- package/dist/chunks/html-CupluJSh.js +2 -0
- package/dist/chunks/lite-3Fb-OHbt.js +2 -0
- package/dist/inlinemath-cas.external.global.min.js +2 -2
- package/dist/inlinemath-cas.global.min.js +2 -2
- package/dist/inlinemath-lite-calc.global.min.js +2 -2
- package/dist/inlinemath-lite.external.global.min.js +2 -2
- package/dist/inlinemath-lite.global.min.js +2 -2
- package/dist/inlinemath.css +32 -1
- package/dist/inlinemath.external.global.min.js +2 -2
- package/dist/inlinemath.external.js +2 -2
- package/dist/inlinemath.global.min.js +2 -2
- package/dist/inlinemath.js +2 -2
- package/dist/lite-calc.js +2 -2
- package/dist/lite.external.js +2 -2
- package/dist/lite.js +2 -2
- package/dist/markdown.external.js +2 -2
- package/dist/markdown.js +2 -2
- package/inlinemath.css +32 -1
- package/package.json +3 -3
- package/src/cas.js +25 -15
- package/src/edit.js +96 -0
- package/src/glyphs.js +2 -0
- package/src/index.d.ts +2 -2
- package/src/index.js +1 -1
- package/src/layout.js +55 -11
- package/src/markdown.d.ts +2 -2
- package/src/markdown.js +354 -39
- package/src/mathzetta.js +2 -1
- package/src/types.d.ts +77 -6
- package/src/variables.js +228 -0
- package/src/view.js +226 -6
- package/dist/chunks/calculate-BX9lJ7Ff.js +0 -2
- package/dist/chunks/draw-Cm4exbg7.js +0 -2
- package/dist/chunks/html-DWtfytjA.js +0 -2
- package/dist/chunks/lite-Bj_L6w2g.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
var InlineMath=function(e){"use strict";const t=-1,n={"+":{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(t),min:s(t),gcd:s(t),mean:s(t),sum:s(t),prod:s(t),int:s(t),lim:s(t),"\\sumidx":s(t),"\\prodidx":s(t),"()":r(),"[]":r(),"{}":r(),"(]":r(),"[)":r(),"=":{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 r(){return{prec:5,assoc:"left",arity:t,fixity:"none",group:!0}}const i="\\:",o=e=>"string"==typeof e&&e.startsWith(i)&&e.length>2;function a(e){return Object.prototype.hasOwnProperty.call(n,e)?n[e]:o(e)?l:void 0}const l=s(t),c=e=>a(e)?.prec;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),m=new Set(["^","?:","?","log"]),f=["(","{","["],g=[")","}","]"];function d(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[u])Object.setPrototypeOf(e,null);const $=e=>({type:"number",value:String(e)}),b=e=>({type:"symbol",value:e}),y=(e,t)=>({type:"op",op:e,args:t}),x=['"',"'","`"];function v(e){return d(e,!0)?$(e):x.includes(e[0])?{type:"string",value:e}:b(e)}const w={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function k(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],s=[];if(e.forEach((e,r)=>{const i=w[e]??String(e),o=a(i);if(!o)return n.push({...v(i),id:r}),void s.push(1);let l=o.arity;if(l===t){const e=n.pop();if(s.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(n.length<l)throw new Error(`'${i}' needs ${l} operand${1===l?"":"s"}`);const c=1+Math.max(0,...s.splice(s.length-l,l));if(c>1e3)throw new Error("Nested too deeply (more than 1000 levels)");s.push(c),n.push({...y(i,n.splice(n.length-l,l)),id:r})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function _(e){const n=[];return function e(s){"op"===s.type?(s.args.forEach(e),a(s.op)?.arity===t&&n.push(String(s.args.length)),n.push(s.op)):n.push(s.value)}(e),n}function E(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>E(n,t,e))}function M(e){let t="";return E(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[w])Object.setPrototypeOf(e,null);function A(e){const t=new Map;for(const[n,s,r]of e)if(n&&""!==n.trim()&&(t.set(n,s),!r))for(const e of O(n))t.get(e)||t.set(e,s);const n=new Map;for(const e of t.keys()){let t=n;for(let n=0;n<e.length;n++)t.has(e[n])||t.set(e[n],new Map),t=t.get(e[n]);t.end=!0}return e=>{let s="",r=0;for(;r<e.length;){const i=q(n,e,r);i?(s+=t.get(e.slice(r,r+i)),r+=i):s+=e[r++]}return s}}function q(e,t,n){let s=e,r=0;for(let e=n;e<t.length&&(s=s.get(t[e]),s);e++)s.end&&(r=e-n+1);return r}function O(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),N(e)]);return t.delete(e),t}function N(e){let t="",n=!1;for(const s of e){const e=s>="a"&&s<="z",r=s>="A"&&s<="Z";t+=!n&&e?s.toUpperCase():s,n=e||r}return t}const C="({[",L=")}]";function S(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 R(e,t){const n=[];let s=0,r=0;for(let i=0;i<e.length;i++)C.includes(e[i])?s++:L.includes(e[i])?s--:0===s&&e.startsWith(t,i)&&(n.push(e.slice(r,i)),i+=t.length-1,r=i+1);return n.push(e.slice(r)),n}function z(e,t,n){let s=0;const r=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(C.includes(e[n]))s++;else if(L.includes(e[n])){if(--s<0)return-1}else if(0===s&&(r.lastIndex=n,r.test(e)))return n;return-1}function I(e,t){let n=0;for(let s=t;s<e.length;s++)if(C.includes(e[s]))n++;else if(L.includes(e[s])&&--n<0)return s;return e.length}function T(e,t){let n=1;for(let s=t+1;s<e.length;s++)if("?"===e[s])n++;else if(":"===e[s]&&0===--n)return e.slice(0,t+1)+"("+e.slice(t+1,s)+")?:"+e.slice(s+1);return e}function Z(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(C.includes(e[t+2]))continue;const n=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(e.slice(t+2))?.[0];if(!n)continue;const s=t+2+n.length;e=e.slice(0,t+2)+"{"+n+"}"+e.slice(s)}else if("("===e[t+1]){let n=1,s=0,r="",i="",o=0;for(let a=t+2;a<e.length;a++){if(")]".includes(e[a])?n--:"([".includes(e[a])&&n++,0===n){o=a;break}1===n&&","===e[a]?s++:0===s?r+=e[a]:i+=e[a]}1===s&&(e=e.slice(0,t+1)+"_{"+i+"}("+r+")"+e.slice(o+1))}return e}function j(e){const t="⌈"===e[0]?"ceil":"floor";let n=1;for(let s=1;s<e.length;s++)if("⌊"===e[s]||"⌈"===e[s]?n++:"⌋"!==e[s]&&"⌉"!==e[s]||n--,0===n)return t+"("+e.slice(1,s)+")"+e.slice(s+1);return e}function P(e){let t=1;for(let n=0;n<e.length;n++){if(")]".includes(e[n])?t--:"([".includes(e[n])&&t++,0!==t)continue;const s=e.slice(0,n),r=e[n+1];if("{"===r||"("===r)return r+s+","+e.slice(n+2);const i=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(e.slice(n+1))?.[0]??"";return"{"+s+","+i+"}"+e.slice(n+1+i.length)}return e}function F(e){const t=e.indexOf("}"),n=e.indexOf("{");if(t<0||n>=0&&n<t)return!1;const s=e.slice(0,t);if(!s.includes("matrix"))return!1;const r=e.indexOf("\\end{"+s+"}"),i=e.indexOf("\\begin{"+s+"}",t+1);if(r<0||-1!==i&&i<r)return!1;const o=e.slice(t+1,r).trim().split("\\\\").map(e=>e.trim()).filter(e=>e.length).map(e=>"["+e.replace(/&/g,", ")+"]");return"["+o.join(", ")+"]"+e.slice(r+6+s.length)}function W(e,t){if("{"!==e[t+1])return[e[t+1],t+2];let n=1,s="";for(let r=t+2;r<e.length;r++){if("{"===e[r])n++;else if("}"===e[r]&&0===--n)return[s,r+1];s+=e[r]}return[s,e.length]}function D(e){const{lower:t,upper:n,next:s}=function(e){let t="",n="",s=0;return"_"===e[0]&&([t,s]=W(e,0),"^"===e[s]&&([n,s]=W(e,s))),{lower:t,upper:n,next:s}}(e),r=e.slice(s),i=e=>e.replace(/\\,/g,"").replace(/\\!/g,"");let o,a="",l="",c=r.indexOf("\\mathrm{d}");if(c>=0){o=r.slice(0,c);const e=/^\{([^{}]*)\}/.exec(r.slice(c+10));a=e?e[1]:r[c+10],l=r.slice(c+10+(e?e[0].length:1))}else(c=function(e){let t=0;for(let n=0;n<e.length;n++)if(C.includes(e[n]))t++;else if(L.includes(e[n]))t--;else if(0===t&&"d"===e[n]&&/[A-Za-z\u0370-\u03FF]/.test(e[n+1]??"")&&!/[A-Za-z]/.test(e[n+2]??""))return n;return-1}(r))>=0?(o=r.slice(0,c),a=r[c+1],l=r.slice(c+2)):o=r;if(!a){const e=/frac\{d([A-Za-z])\}/.exec(o);e&&(a=e[1],o=o.replace(e[0],"frac{1}"))}if(!a&&/^[A-Za-z]$/.test(t)){a=[...i(o).matchAll(/(?<![A-Za-z\\])([A-Za-z])(?![A-Za-z(])/g)].map(e=>e[1]).find(e=>e!==t&&e!==n)??"x"}let h="int("+(i(o)||"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function U(e){const t=e[0];if(!(t>="A"&&t<="Z"||t>="a"&&t<="z"||t>="α"&&t<="ω"))return!1;const n=e.slice(2);let s=1;for(let e=0;e<n.length;e++)if(L.includes(n[e])?s--:C.includes(n[e])&&s++,0===s)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function B(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const H=/[A-Za-z\u0370-\u03FF]/;function G(e,t){if("{"!==e[t])return null;let n=0;for(let s=t;s<e.length;s++)if("{"===e[s])n++;else if("}"===e[s]&&0===--n)return[e.slice(t+1,s),s+1];return null}function X(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function V(e,t){const n=e.replace(/\\mathrm\{d\}/g,"d"),s=t.replace(/\\mathrm\{d\}/g,"d"),r=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(n),i=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(s);return r&&i?{n:Number(r[1]??1),of:r[2],by:i[1]}:null}function Q(e,t){if(C.includes(e[t])){let n=0;for(let s=t;s<e.length;s++)if(C.includes(e[s]))n++;else if(L.includes(e[s])&&0===--n)return[e.slice(t,s+1),s+1];return[e.slice(t),e.length]}let n=0;for(let s=t;s<e.length;s++)if(C.includes(e[s]))n++;else{if(L.includes(e[s])&&--n<0)return[e.slice(t,s),s];if(0===n&&("="===e[s]||","===e[s]))return[e.slice(t,s),s]}return[e.slice(t),e.length]}const J=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const K="strtktk",Y="ABCDEFGHIJ",ee=e=>K+[...String(e)].map(e=>Y[e]).join("");function te(e,t){let n=!1;for(let s=t+1;s<e.length;s++)if(n)n=!1;else if("\\"===e[s])n=!0;else if(e[s]===e[t])return s;return e.length-1}function ne(e,t){if(!t||0===t.size)return e;const n=[...t].sort((e,t)=>t[0].length-e[0].length);return e.map(e=>{for(const[t,s]of n)e=e.split(t).join(s);return e})}const se={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[se])Object.setPrototypeOf(e,null);const re="([{",ie=")]}";function oe(e,t){let n=0;for(let s=t;s<e.length;s++)if(re.includes(e[s]))n++;else if(ie.includes(e[s])&&0===--n)return s;return-1}function ae(e){if(!e.trim())return[];const t=[];let n=0,s=0;for(let r=0;r<e.length;r++)re.includes(e[r])?n++:ie.includes(e[r])?n--:","===e[r]&&0===n&&(t.push(e.slice(s,r).trim()),s=r+1);return t.push(e.slice(s).trim()),t}function le(e,t,n){const s=[...e.matchAll(t)];for(let t=s.length-1;t>=0;t--){const r=s[t],i=r.index+r[0].length-1,o=oe(e,i);if(o<0)continue;const a=n(ae(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 ce=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),he=e=>`(${e})`,ue=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const pe={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(he).join(" & ")})`,OR:e=>e.length&&`(${e.map(he).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 me={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"},fe="strtktk[A-J]+";function ge(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${fe})\\s*\\|\\|\\s*(${fe})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${fe},\\s*${fe}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const s=oe(e,n),r=s>0&&t.exec(e.slice(n,s+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,n)}((${i}) ∈ ${a})${e.slice(s+1)}`)}e=le(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=le(e=function(e){for(let t=0;t<50;t++){const t=[...e.matchAll(/\bCASE\s+WHEN\b/gi)];if(!t.length)return e;const n=t[t.length-1].index,s=/\bEND\b/i.exec(e.slice(n));if(!s)return e;const r=e.slice(n+4,n+s.index).split(/\b(WHEN|THEN|ELSE)\b/i).map(e=>e.trim()),i=[];let o="null";for(let e=1;e<r.length;e+=2){const t=r[e].toUpperCase();"WHEN"===t?i.push([r[e+1],r[e+3]]):"ELSE"===t&&(o=r[e+1])}const a=i.reduceRight((e,[t,n])=>`((${t}) ? (${n}) : ${e})`,he(o));e=e.slice(0,n)+a+e.slice(n+s.index+3)}return e}(e=e.replace(/(?<![\w.])ARRAY\s*\[/g,"[")),/(?<![\w.])LOG\s*\(/g,e=>2===e.length?`log_{${e[0]}}(${e[1]})`:`log_{10}(${e[0]})`)).replace(/(?<![\w.])PI\s*\(\s*\)/g,"π")).replace(/(?<![\w.])([A-Z][A-Z0-9]*)(?=\s*\()/g,e=>me[e]??e);for(const[t,n]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let s=t.exec(e);s;s=t.exec(e)){const r=s.index+s[0].length-1,i=oe(e,r);if(i<0)break;e=`${e.slice(0,s.index)}${n} {${e.slice(r+1,i)}}${e.slice(i+1)}`,t.lastIndex=0}return e.replace(/<>/g," ≠ ")}const de={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"},$e={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 be(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)=>xe[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>xe[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>ve[t]??ye[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)=>de[t]?`Math.${de[t]}`:$e[t]?$e[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 ye={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},xe={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"},we={open:"()",Lopen:"(]",Ropen:"[)"};const ke=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?ae(t[1]):null},_e=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Ee=e=>ke(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]}) ∈ ${ue(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${ue(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(he).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(he).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(ke);return!t.length||t.some(e=>!e||2!==e.length)?null:t.reduceRight((e,[t,n])=>null===e||/^True$|^true$/.test(n.trim())&&void 0===e?`(${t})`:`((${n}) ? (${t}) : ${e??"(null)"})`,void 0)},sympy_set:e=>`{${e.join(", ")}}`,sympy_interval:_e("[]"),sympy_interval_open:_e("()"),sympy_interval_Lopen:_e("(]"),sympy_interval_Ropen:_e("[)"),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=Ee(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&&Ee(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&&Ee(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:Ae("sum"),prod:Ae("prod")};function Ae(e){return t=>{const n=1===t.length&&/^(.*?)\s+for\s+(\w+)\s+in\s+range\((.*)\)\s*$/s.exec(t[0]);if(!n)return null;const s=ae(n[3]),[r,i]=1===s.length?["0",s[0]]:s,o=/\s*\+\s*1$/.test(i)?i.replace(/\s*\+\s*1$/,""):`(${i}) - 1`;return`(\\${e}_{${n[2]}=${r}}^{${o}} (${n[1]}))`}}for(const e of[pe,me,de,$e,ye,xe,ve,we,Me])Object.setPrototypeOf(e,null);const qe=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Oe=e=>e.trim().split(/\s+/).join(String.raw`\s+`),Ne=e=>new RegExp(String.raw`(?<![\w.])${Oe(e)}(?![\w.])`,"gi"),Ce=[["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","="]],Le="[<>≤≥=≠≈]",Se=[["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 Re=A([[" 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 ","→"],["===","=...="]]),ze=A([["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,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const e of["","h"]){const s=n+e,r="arc"+n+e;e&&(t("Math."+s,s),t("\\"+s,s));for(const n of["^-1","^{-1}","-1"])t("\\"+s+n,r),t(s+n,r),e||t("Math."+s+n,r);e||t("\\a"+s,r),t("\\arc"+s,r),t("Math.a"+s,r),t("Math.arc"+s,r)}return e}()]),Ie=[["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 n=!0;n;){const s=e;n=(e=e.replace(new RegExp(`(^|[^\\p{L}\\p{N}_.)§])(${t}\\s*\\^\\s*${t})(?=\\s*\\^)`,"u"),"$1($2)"))!==s}return le(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>pe[t[1]]?.(e)||null)}(e)),e=function(e){e=le(e,ce("quad"),(e,t,n)=>{const s=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(e[0]??"");if(!s||3!==e.length)return null;const r=/^\s*\[\s*0\s*\]/.exec(n);return[`int(${s[2]}, ${s[1]}, ${e[1]}, ${e[2]})`,r?r[0].length:0]}),e=le(e,ce(Object.keys(Me).join("|")),(e,t)=>Me[t[1]](e)||null);for(let t=(e=le(e,ce("float"),(e,t,n)=>{const s=/^\s*\.is_integer\(\s*\)/.exec(n);return s&&1===e.length?[`((${e[0]}) ∈ ℤ)`,s[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,s=oe(e,n);let r=t;if(ie.includes(e[t-1])){let n=0;for(r=t-1;r>=0;r--)if(ie.includes(e[r]))n++;else if(re.includes(e[r])&&0===--n)break}else for(;r>0&&/[\w.]/.test(e[r-1]);)r--;s<0||r<0||r===t||(e=`${e.slice(0,r)}((${e.slice(n+1,s)}) ∈ ${ue(e.slice(r,t))})${e.slice(s+1)}`)}return e}(e=be(e=ge(e=(e=(e=function(e){for(const[t,n]of Object.entries(se))for(let s=e.lastIndexOf(n);s>=0;s=s>0?e.lastIndexOf(n,s-1):-1){const r=s+n.length,i="("===e[r]?oe(e,r):-1;if(i<0)continue;let o=e.slice(r+1,i);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===t?`((${o})!)`:`${t}(${o})`;e=e.slice(0,s)+a+e.slice(i+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const n=t+10-1,s=oe(e,n),r=e.lastIndexOf("Number(",t);s<0||r<0||oe(e,r+7-1)!==t||(e=e.slice(0,r)+`fixed(${e.slice(r+7,t)}, ${e.slice(n+1,s)})`+e.slice(s+1))}return e.replace(/\(\(\)=>\{let (sum|prod) = [01]; let loopCount = 0; for \(let (\w+)=(.*?);\2<=(.*?);\2\+\+\) \{if \(loopCount\+\+ > 1000000\)\{break\};\1 [+*]= (.*?);\}; return \1;\}\)\(\)/g,(e,t,n,s,r,i)=>`(\\${"sum"===t?"sum":"prod"}_{${n}=${s}}^{${r}} (${i}))`)}(e)).replace(/(?<![\w.])9e999\b/g,"∞")).replace(/(?<![\w.])(\d+(?:\.\d+)?)[eE]([+-]\d+)(?![\w.])/g,"($1*10^{$2})")))),(e=(e=(e=function(e){for(let t=0;t<50;t++){let t=!0;for(const n of e.matchAll(/\bif\b/g)){const s=n.index;let r=0,i=-1,o=e.length;for(let t=s+2;t<e.length;t++)if(re.includes(e[t]))r++;else{if(ie.includes(e[t])&&--r<0){o=t;break}if(0===r&&","===e[t]){o=t;break}if(0===r&&/^then\b/.test(e.slice(t))&&/\W/.test(e[t-1])){i=-2;break}0===r&&i<0&&/^else\b/.test(e.slice(t))&&/\W/.test(e[t-1])&&(i=t)}if(i<0)continue;r=0;let a=0;for(let t=s-1;t>=0;t--)if(ie.includes(e[t]))r++;else{if(re.includes(e[t])&&--r<0){a=t+1;break}if(0===r&&","===e[t]){a=t+1;break}}const l=e.slice(a,s).trim();if(!l)continue;const c=`((${e.slice(s+2,i).trim()}) ? (${l}) : (${e.slice(i+4,o).trim()}))`;e=e.slice(0,a)+c+e.slice(o),t=!1;break}if(t)return e}return e}(e)).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 n=(e,n,s,r="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Oe(e)}\s+(${qe})\s+(?:and|to)\s+(${qe})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(e,t,i,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[n,s];return` ${r} ${a}${t}, ${i}${l} `})};n("is not strictly between","(",")","∉"),n("is not between","[","]","∉"),n("is strictly between","(",")"),n("is between","[","]"),n("between","[","]"),t=t.replace(new RegExp(String.raw`(?<![\w.])is\s+(not\s+)?in\s+the\s+(open|closed|half-open)\s+interval\s+from\s+(${qe})\s+to\s+(${qe})`,"gi"),(e,t,n,s,r)=>{const[i,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[n.toLowerCase()];return` ${t?"∉":"∈"} ${i}${s}, ${r}${o} `});const s=String.raw`(${qe})\s+`;t=t.replace(new RegExp(s+String.raw`is\s+(not\s+)?within\s+(${qe})\s*(%|\s+percent)?\s+of\s+(${qe})`,"gi"),(e,t,n,s,r,i)=>`(abs((${t}) - (${i})) ${n?">":"≤"} ${r?`(${s})/100 * ${/^\d+(\.\d+)?$/.test(i)?i:`abs(${i})`}`:`(${s})`})`),t=t.replace(new RegExp(s+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${qe})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(s+String.raw`is\s+(not\s+)?divisible\s+by\s+(${qe})`,"gi"),(e,t,n,s)=>`((${t}) mod (${s}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${qe})\s+divides\s+(${qe})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(s+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,n,s)=>`((${t}) mod 2 ${"even"===s.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[e,n]of Se)t=t.replace(Ne(e),` ${n} `);t=t.replace(Ne("is not in")," ∉ ").replace(Ne("is in")," ∈ ").replace(Ne("is an element of")," ∈ ");for(const[e,n]of Ce)t=t.replace(Ne(e),` ${n} `);t=t.replace(Ne("is not")," ≠ "),t=t.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let e=!0;e;){const n=t;t=t.replace(new RegExp(String.raw`(${qe})\s*(${Le})\s*(${qe})\s+(and|or)\s+(${Le})`,"gi"),"$1 $2 $3 $4 $1 $5"),e=t!==n}t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${qe})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${qe})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${qe})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${qe})\s+to\s+the\s+power\s+of\s+(${qe})`,"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`(${qe})\s+to\s+the\s+(${Object.keys(r).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,s)=>`(${t})^(${r[n.toLowerCase()]??s})`),t=t.replace(new RegExp(String.raw`(${qe})\s+to\s+the\s+(${qe})(?![\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,n]of Object.entries(i).sort((e,t)=>t[0].length-e[0].length))t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Oe(e)}\s+of\s+(${qe})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${qe})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${qe})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${qe})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${qe})`,"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+)${Oe(e)}(?=\s+[\w.(\[{-])`,"gi");for(const[e,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(o(e),` ${n} `);return t}],["words",Re],["spaced",function(e){e=Z(e=function(e){for(let t=0;t<e.length;t++){const n=n=>e.slice(Math.max(0,t-n),t+1);if("t"===e[t]&&"\\text"===n(4)&&"{"===e[t+1]){let n=1,s=t+2,r="";for(;n>0&&s<e.length;)"{"===e[s]?n++:"}"===e[s]?n--:r+=e[s],s++;e=e.slice(0,t-4)+r+e.slice(s)}}return e}(e=(e=(e=function(e){for(let t=0;t<100;t++){const t=[...e.matchAll(/\bif\b/gi)];if(!t.length)return e;const n=t[t.length-1].index,s=z(e,n+2,"then");if(s<0)return e;const r=e.slice(n+2,s),i=z(e,s+4,"else"),o=I(e,i<0?s+4:i+4),a=e.slice(s+4,i<0?o:i),l=i<0?"unchanged":e.slice(i+4,o).trim();e=`${e.slice(0,n)}((${r.trim()}) ? (${a.trim()}) : (${l}))${e.slice(o)}`}return e}(e)).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=T(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}let s=t+1;for("-"===e[s]&&s++;s<e.length&&".0123456789".includes(e[s]);)s++;s===t+2&&"-"===e[t+1]&&(s=t+1),s>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,s)+"}"+e.slice(s))}return e}],["squeeze",function(e){return e.replace(/\s+/g,(t,n)=>{const s=e[n-1]??"",r=e[n+t.length]??"";return"Δ"===s?"":/[A-Za-z\u0370-\u03FF′]/.test(s)&&/[A-Za-z\u0370-\u03FF]/.test(r)?" ":""})}],["symbols",ze],["compact",function(e){e=function(e){for(let t=0;t<e.length;t++){const n=t>0&&H.test(e[t-1]);let s,r=null,i=t;if(e.startsWith("frac{",t)){const n=G(e,t+4),s=n&&G(e,n[1]);r=s&&V(n[0],s[0]),r&&(i=s[1])}else if("d"===e[t]&&!n){let[n,s]=X(e,t+1),o="";if(H.test(e[s]??"")&&"/"===e[s+1]&&(o=e[s++]),"/"===e[s]&&"d"===e[s+1]&&H.test(e[s+2]??"")){const t=e[s+2],[,a]=X(e,s+3);r={n:n,of:o,by:t},i=a}}if(r){if(r.of)s=J(r.of,r.by,r.n);else{const[t,n]=Q(e,i);if(!t)continue;s=J(t,r.by,r.n),i=n}e=e.slice(0,t)+s+e.slice(i),t+=3}}return e}(e=function(e){for(let t=e.indexOf(")′");t>=0;t=e.indexOf(")′",t+1)){let n=0,s=-1;for(let r=t;r>=0;r--)if(")"===e[r])n++;else if("("===e[r]&&0===--n){s=r;break}if(s<0)continue;for(;s>0&&/[A-Za-z\u0370-\u03FF′]/.test(e[s-1]);)s--;let r=0;for(;"′"===e[t+1+r];)r++;e=e.slice(0,s)+J(e.slice(s,t+1),"x",r)+e.slice(t+1+r),t=s}return e}(e=(e=Z(e)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}")));for(let t=0;t<e.length;t++){const n=e[t],s=n=>e.slice(Math.max(0,t-n),t),r=n=>e.slice(Math.max(0,t-n),t+1);if("{"===n){if("\\begin"===s(6)){const n=F(e.slice(t+1));n&&(e=e.slice(0,t-6)+n)}}else if("["===n)"\\sqrt"===s(5)?e=e.slice(0,t-5)+"sqrt"+P(e.slice(t+1)):"sqrt"===s(4)&&(e=e.slice(0,t-4)+"sqrt"+P(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+j(e.slice(t));else if("t"===n)"\\int"===r(3)&&(e=e.slice(0,t-3)+D(e.slice(t+1)));else if("m"===n)"\\binom"===r(5)&&(e=e.slice(0,t-5)+"\\binom"+B(e.slice(t+1)));else if("d"===n&&"dd"===r(1)&&"("===e[t+2]){const n=U(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return e.replace(/\\log/g,"log")}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]];function Te(e,t={}){if("string"!=typeof e)throw new Error("Expression must be a string");const{text:n,strings:s}=function(e){const t=new Map;let n="",s=0;for(;s<e.length;){const r=e[s];if('"'!==r&&"'"!==r&&"`"!==r){n+=e[s++];continue}let i=s+1,o="",a=!1;for(;i<e.length&&(a||e[i]!==r);)a=!a&&"\\"===e[i],o+=e[i++];const l=ee(t.size);t.set(l,r+o+r),n+=l,s=i+1}return{text:n,strings:t}}(function(e){let t="";for(let n=0;n<e.length;n++){const s=e[n];if('"'===s||"`"===s){const s=te(e,n);t+=e.slice(n,s+1),n=s}else if("'"===s)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(t[t.length-1]??""))t+="′";else{const s=te(e,n);t+=e.slice(n,s+1),n=s}else t+=s}return t}(e));let r=n.replace(/\t/g," ");t.evaluate&&(r=function(e,t,n){let s=0;for(;;){const r=e.indexOf("{{",s);if(r<0)return e;const i=Ze(e,r);if(i<0)return e;let o=e.slice(r+2,i).trim();for(const[e,n]of t)o=o.split(e).join(n);try{let a=n(o);if(/^["'`]/.test(a)){const e=ee(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),s=0}catch{s=i+2}}}(r,s,t.evaluate));const i=[["strings",r]];for(const[e,t]of Ie){if(r=t(r),r.length>1e5)throw new Error("The expression expands too much when read");i.push([e,r])}return{cleaned:r,stringMap:s,steps:i}}function Ze(e,t){let n=0;for(let s=t+2;s<e.length;s++){if(e.startsWith("}}",s)&&0===n)return s;"{"===e[s]?n++:"}"===e[s]&&n--}return-1}const je={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 Pe(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function Fe(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==Pe(n)}function We(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":Fe(e)?null:e.op}const De=(e,t,n)=>function(e,t,n){if("mod"===e&&t)return c(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const s=c(e),r=c(t);if(!s||!r)return!1;if(r!==s)return r<s;const i=a(e).assoc;return"left"===i?"right"===n:"right"===i&&"left"===n}(e.op,We(t),n);function Ue(e,t){const n=We(t),s=n&&a(n)?.prec;return!!s&&("!"===e?s<=a("!").prec:"\\not"===e?s<a("\\not").prec:s<70||Je(t)||"\\not"===n)}function Be(e,t,n={}){const s=n.left?"bracket":Ve(e),r=n.right?"bracket":Xe(t);return"digit"!==r&&"sign"!==r&&"word"!==s&&"word"!==r&&"other"!==s&&("frac"!==r||"digit"!==s&&"frac"!==s)}function He(e){return 1===e.length||Boolean(je[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function Ge(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function Xe(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||Fe(e)?"sign":"/"===t?"frac":a(t)?.group||Ge(e)?"bracket":Qe(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?Ge(e.args[0])?"bracket":Xe(e.args[0]):["*","sum","prod","perm"].includes(t)?Xe(e.args[0]):"other"}function Ve(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":a(t)?.group||Ge(e)||Qe(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?Ve(e.args[e.args.length-1]):"other"}function Qe(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function Je(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||Fe(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!De(e,e.args[0],"left")&&Je(e.args[0])}const Ke=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),Ye=e=>e.slice(2);function et(e){const t=e.args[1];let n=0,s=e;for(;"op"===s.type&&"der"===s.op&&tt(s.args[1],t);)n++,s=s.args[0];return{n:n,body:s,by:t,variable:"symbol"===s.type&&He(s.value)}}const tt=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type;for(const e of[je])Object.setPrototypeOf(e,null);const nt=Object.keys(u).filter(e=>100===u[e]&&/^[a-z]{2,}$/.test(e)),st=["frac"],rt=[...Object.keys(je),"pi","tau","inf","infinity","exp"],it="\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+/),ot=new Set([...rt,...it,"true","false","null","undefined","deg","mod","pmod","NaN","Infinity"]),at=/^[a-zA-ZͰ-Ͽ]$/,lt=new Set(["f","g","h","u","v","F","G","H"]),ct=e=>nt.includes(e)||st.includes(e),ht=[...nt,...st,...rt].sort((e,t)=>t.length-e.length),ut=[...nt,...st,"pi"].sort((e,t)=>t.length-e.length);function pt(e,t=ht){const n=[];let s=0;for(;s<e.length;){const r=t.find(t=>e.startsWith(t,s))??e[s];n.push(r),s+=r.length}return n}function mt(e){if(ct(e))return!0;const t=pt(e,ut);return t.length>1&&ct(t[t.length-1])&&!ot.has(e)}function ft(e,{mode:t="plain",followed:n=!0}={}){if(e.includes("′")&&/^[a-zA-Z′]+$/.test(e)&&!/^.′+$/.test(e))return e.match(/[a-zA-Z]′*/g);if(!((s=e).length>0&&[...s].every(e=>at.test(e)))||1===e.length||ot.has(e)||ct(e))return[e];var s;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return gt(pt(e),n);if(e.length<=2)return[...e];const r=gt(pt(e,ut),n),i=r.findIndex(e=>e.length>1);if(i<0)return[e];if("pi"===r[i]&&!r.some(e=>nt.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 gt(e,t){const n=e[e.length-1];return t||!nt.includes(n)?e:[...e.slice(0,-1),...n]}const dt="§",$t=/[A-Za-zͰ-Ͽ′]/,bt=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function yt(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let s="";const r=e=>{s&&(bt(s)?n.push(...function(e,t,n){if((e=>new RegExp(`^${K}[${Y}]+$`).test(e))(e))return[e];if(f.includes(t))return function(e,t){if(/^[a-zA-Z]′+$/.test(e))return[i+e];if("if"===e.toLowerCase())return["\\:if"];if(1===e.length)return lt.has(e)?[i+e]:[e];if(p(e))return[e];const n=ft(e,{mode:t,followed:!0});return n.length>1?n:e.length<=2?[...e]:[i+e]}(e,n);const s=void 0!==t&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(t);return ft(e,{mode:n,followed:s})}(s,e,t)):n.push(s),s="")};for(let t=0;t<e.length;t++){const o=e[t];if(o===dt){r(o);const s=e.indexOf(dt,t+1),a=e.slice(t,s+1);n.push(f.includes(e[s+1])?i+a:a),t=s;continue}if(bt(s)&&/[0-9]/.test(o)&&p(s+o)){const{op:r,end:i}=xt(e,t,s+o);n.push(r),s="",t=i;continue}if($t.test(o)&&"′"!==o&&d(s)&&(n.push(s),s=""),$t.test(o)&&(""===s?"′"!==o:bt(s)))s+=o;else if(/[0-9]/.test(o)&&bt(s)&&!mt(s))s+=o;else if(bt(s)&&r(" "===o?e[t+1]:o),"(){}[]".includes(o))s&&n.push(...vt(s,o)),s="",n.push(o);else if("_"!==o&&" "!==o){if(p(s+o)){const{op:r,end:i}=xt(e,t,s+o);n.push(r),s="",t=i;continue}if(p(o)){r(o);const{op:s,end:i}=xt(e,t,o);n.push(s),t=i;continue}s+=o}else r(e[t+1]),"_"===o&&n.push("_")}if(r(void 0),n.some(e=>/^:/.test(e)))throw new Error("Unmatched ':'");return n}function xt(e,t,n){let s=t;for(;s+1<e.length&&p(n+e[s+1]);)n+=e[s+1],s++;return"!"===n&&"_"===e[s+1]&&s++,{op:n,end:s}}function vt(e,t){if(!f.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[p(t)?t:i+t]}return d(e)?[e,"*"]:p(e)||ct(e)||d(e[0])?[e]:[i+e]}const wt=70,kt=100,_t="%mod",Et=e=>f.includes(e),Mt=e=>g.includes(e),At=e=>o(e)||u[e]===kt&&"_"!==e,qt=new Set(["\\comb","\\perm","comb","perm"]),Ot={frac:"/","\\binom":"\\binom"},Nt={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Ct{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(Mt(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){for(this.parseOperand();;){const n=this.peek();if(void 0===n||Mt(n))return;const s=this.operatorAt(n,t);if(!s||s.lbp<=e)return;s.run()}}operatorAt(e,t){if("|"===e)return this.pipe();if(","===e)return{lbp:5,run:()=>{this.next(),this.frames.length&&(this.frames[this.frames.length-1].comma=!0),this.parseExpression(5),this.emit(",")}};if("?"===e)return{lbp:9,run:()=>this.ternary()};if("mod"===e)return{lbp:u.mod,run:()=>this.modulo()};if(e===_t)return{lbp:wt,run:()=>{this.next(),this.parseExpression(wt),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:kt,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(qt.has(e))return{lbp:kt,run:()=>{this.next(),this.parseExpression(kt),this.emit(e)}};const n=u[e];if(void 0!==n&&!At(e)&&"\\not"!==e&&!(e in Ot)){const t=m.has(e)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:t&&!At(e)?71:wt,run:()=>{this.parseExpression(wt),this.emit("*")}}}startsOperand(e){return void 0===e||Mt(e)||"|"===e?"|"===e:e!==_t&&(!!(Et(e)||At(e)||e in Ot)||!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(wt,!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],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(Et(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Mt(n))||Et(t)&&Mt(n)?this.emit("\\"+e):"+"===e?this.parseExpression(75):this.negate()}if("±"===e)return this.parseExpression(75),this.emit("pm");if("!"===e||"\\not"===e)return this.parseExpression(85),this.emit("\\not");if(e in Ot)return this.parseScript(),this.parseScript(),this.emit(Ot[e]);if("log"===e)return this.logarithm();if("lim"===e&&"_"===n)return this.limit();if(("\\sumidx"===e||"\\prodidx"===e)&&"_"===n)return this.bigOperator(e);if(At(e))return this.functionCall(e);if(Mt(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(Mt(this.peek()))return void this.emit("∅",e+this.next());this.frames.push({comma:!1}),this.parseExpression(0);const{comma:n}=this.frames.pop(),s=this.peek();Mt(s)&&(this.next(),n?this.emit(e+s):t&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const e=this.peek();if(Et(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(At(e))return this.parseOperand();if(this.next(),void 0===e||Mt(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 n=this.out.splice(t);"^"===this.peek()&&(this.next(),this.parseScript(),n=[...n,...this.out.splice(t),","]),this.parseExpression(u["+"],!0),this.emit(...n,",","()",e)}functionCall(e){if(void 0===this.peek())return this.emit(e);let t=null;if("^"===this.peek()){this.next();const e=this.out.length;this.parseScript(),t=this.out.splice(e)}if(0===a(e)?.arity&&!Et(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(Et(e))return this.next(),this.bracket(e);this.parseExpression(wt,!0)}}function Lt(e,t){e=function(e){const t=[];for(let n=0;n<e.length;n++){const s=e[n],r=e=>"string"==typeof e&&/^[a-zA-Z]$/.test(e);if(lt.has(s)&&"^ { - 1 } ("===e.slice(n+1,n+7).join(" ")){t.push(i+s+"⁻¹"),n+=5;continue}const[o,a,l]=e.slice(n+1,n+4),c=r(a)?a!==s:d(a);r(s)&&"e"!==s&&"("===o&&c&&")"===l?t.push(i+s):t.push(s)}return t}(e);const n=[];for(const s of e)p(s)||Et(s)||Mt(s)||"_"===s||o(s)||d(s)?n.push(s):n.push(...St(s,t));return n}function St(e,t){const n=e=>Lt(yt(e,t),t);let s=0;for(;s<e.length&&d(e.slice(0,s+1));)s++;if(0===s){if("%"===e[0])return[_t,...n(e.slice(1))];const s=e.indexOf("%");return s>0&&s<e.length-1?[...St(e.slice(0,s),t),_t,...n(e.slice(s+1))]:[e]}const r=e.slice(s);return"%"===r[0]?1===r.length?[e]:[e.slice(0,s),_t,...n(r.slice(1))]:[e.slice(0,s),...n(r)]}for(const e of[Ot,Nt])Object.setPrototypeOf(e,null);const Rt=new Set(["()","[]","{}","(]","[)"]),zt={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠="},It=new Set(["round","fixed","der"]),Tt=e=>o(e)||100===u[e];function Zt(e){const n=[],s=e=>{if(!n.length)throw new Error(`'${e}' is missing an operand`);return n.pop()},r=e=>e.list?e.list:[e],i=(e,t)=>{if(e.list)throw new Error(`A list of values needs brackets around it (near '${t}')`);return e};if(e.forEach((l,c)=>{if("∅"===l)return void n.push({list:[]});if(","===l){const e=s(l),t=s(l);return void n.push({list:[...r(t),...r(e)]})}if(Rt.has(l)){const t=r(s(l));if(!t.length&&!Tt(e[c+1]))throw new Error("Empty brackets");return void n.push(y(l,t))}const h=zt[l]??l,u=a(h);if(!u){if("?"===l||"abs("===l)throw new Error(`Unmatched '${l[0]}'`);return void n.push(v(l))}let p;if(Tt(l)&&Rt.has(e[c-1])&&n[n.length-1]?.op===e[c-1])p=n.pop().args;else{let e=u.arity===t||It.has(h)?1:u.arity;if(n.length<e)throw new Error(`'${l}' needs ${e} operand${1===e?"":"s"}`);p=n.splice(n.length-e,e).map(e=>i(e,l))}n.push(function(e,n){switch(e){case"sqrt":if(2===n.length)return y("root",n);break;case"round":if(1===n.length)return y("round",[n[0],$(0)]);break;case"sum":case"prod":{const t=n[1];if("op"===t?.type&&"symbol"===t.args[0]?.type&&(3===n.length&&"="===t.op||2===n.length&&"∈"===t.op))return y("sum"===e?"\\sumidx":"\\prodidx",n);break}case"fixed":if(1===n.length)return y("fixed",[n[0],$(2)]);break;case"der":if(1===n.length)return y("der",[n[0],b("x")]);if(3===n.length)return function([e,t,n]){const s="number"===n.type?Number(n.value):NaN;if(!Number.isInteger(s)||s<1||s>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");let r=e;for(let e=0;e<s;e++)r=y("der",[r,t]);return r}(n);break;case"log":if("symbol"===n[0].type&&"e"===n[0].value)return y("ln",[n[1]]);break;case"lim":return y("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?{"\\+":"r","\\-":"l"}[e.args[1].value]:void 0,[n,s,r]=e;if(2===e.length&&"op"===s.type&&"→"===s.op&&t(s.args[1])){const[e,r]=s.args;return[n,e,r.args[0],b(t(r))]}return 3===e.length&&t(r)?[n,s,r.args[0],b(t(r))]:e}(n));case"\\:if":if(2===n.length||3===n.length)return y("?:",[n[0],n[1],n[2]??b("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return function(e,n){const{arity:s}=a(e);if(s===t){if(0===n.length&&!o(e))throw new Error(`'${e}' needs at least one argument`);return}if(n.length!==s){throw new Error(`'${e}' takes ${s} argument${1===s?"":"s"}, not ${n.length}`)}}(e,n),y(e,n)}(h,p))}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return i(n[0],"end")}for(const e of[zt])Object.setPrototypeOf(e,null);const jt=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Pt=e=>/^[a-z][a-z0-9]*$/.test(e)&&p(e);function Ft(e){return e.includes("\\")?(e=function(e){for(let t=0;t<50;t++){const t=e.lastIndexOf("\\begin{cases}"),n=t<0?-1:e.indexOf("\\end{cases}",t);if(n<0)return e;const s=R(e.slice(t+13,n),"\\\\").map(e=>R(e,"&")).filter(e=>e.join("").trim());let r=null;for(let e=s.length-1;e>=0;e--){const t=s[e][0].trim(),n=S(s[e].slice(1).join("&"));r=null!==r||n?`((${n||"true"}) ? (${t}) : ${r??"(unchanged)"})`:`(${t})`}e=e.slice(0,t)+(r??"")+e.slice(n+11)}return e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):e}function Wt(e,t={}){const n={original:e};try{if("string"!=typeof e)throw new Error("Expression must be a string");const s=t.maxLength??5e3;if(e.length>s)throw new Error(`Longer than ${s} characters (options.maxLength)`);const r=/^\s*=(?!=)/.test(e);r&&(e=e.replace(/("(?:[^"]|"")*")|\$(?=[A-Za-z]{0,3}\d|[A-Za-z]{1,3}\$?\d)/g,(e,t)=>t??""));const i=r?[...new Set(e.replace(/"(?:[^"]|"")*"/g,"").match(/(?<![\w.])[A-Za-z]{1,3}\d+(?::[A-Za-z]{1,3}\d+)?(?![\w.(])/g)??[])]:[],{text:o,protectedNames:a}=function(e,t=[],n=[]){const s=new Map,r=e=>{const t=`${dt}${s.size}${dt}`;return s.set(t,e),t};e=e.replace(jt,(e,t)=>Pt(t.trim())?` ${t.trim()}`:r(t.trim()));for(const n of[...t].sort((e,t)=>t.length-e.length)){const t=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${t}(?![A-Za-z0-9_])`,"g"),()=>r(n))}for(const t of[...n].sort((e,t)=>t.length-e.length)){const n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(e,n,s)=>r(t)+(s?" * (":n))}return{text:e,protectedNames:s}}(Ft(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 n=void 0===t.blocks?null:t.blocks;return Te(e,{evaluate:n?e=>n(e,t.scope):void 0})})(o,{blocks:t.blocks,scope:t.scope}),p=e=>ne(ne(e,h),a);n.mode=l,n.cleaned=p([c])[0],n.cleanSteps=u,n.tokens=yt(c,l),n.rawPostfix=p(function(e,t="plain"){return new Ct(Lt(e,t)).parseAll().map(e=>Nt[e]??e)}(n.tokens,l));const m=_(Zt(n.rawPostfix));n.postfix=m,n.tree=k(m)}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function Dt(e,t={}){const n=Wt(e,t);if(n.error)throw new Error(`Failed to parse expression "${s=e,"string"==typeof s&&s.length>80?`${s.slice(0,77)}…`:s}": ${n.error}`);var s;return n.tree}const Ut=(e,t)=>"string"==typeof e?Dt(e,t):function(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")}(e),Bt={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"]},Ht={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"},Gt=Object.fromEntries(Object.entries(je).map(([e,t])=>[t,e]));function Xt(e,t={}){return Vt(function(e,t={}){const n=new Kt({...Bt,...t.words},{...Ht,...t.names},t.say||{});return function(e){const t=[];for(const{text:n,id:s}of e){const e=n.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:s})}t.length&&(t[t.length-1].text=t[t.length-1].text.replace(/,$/,""));return t}(n.speak(e))}(e,t))}function Vt(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const Qt={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},Jt={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class Kt{constructor(e,t,n){this.w=e,this.names=t,this.say=n}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=>Vt(this.speak(e))):[e.value],e,e=>Vt(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(Jt[e])return t[Jt[e]];if(Gt[e])return Gt[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=c(e.op);return void 0!==t&&t<=50&&!a(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:n}=e,[s,r]=n,i=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(i.comma),...this.speak(e)]:this.speak(e));if(Qt[t])return[...this.speak(s),a(i[Qt[t]]),...this.speak(r)];if(o(t)){const e=this.symbol(Ye(t));return n.length?[a(`${e} ${i.of}`),...this.arguments(n)]:[a(e)]}if(this.names[t]&&!["log","round","fixed","atan2","random","expm1"].includes(t))return[a(`${this.names[t]} ${i.of}`),...this.arguments(n)];switch(t){case"+":return Fe(r)?[...this.speak(s),a(i.minus),...this.speak(r.args[1])]:[...this.speak(s),a(i.plus),...this.speak(r)];case"-":return Fe(r)?[...this.speak(s),a(i.plus),...this.speak(r.args[1])]:[...this.speak(s),a(i.minus),...this.quantityIfSum(r)];case"*":return this.product(e);case"/":return this.fraction(e);case"^":return this.power(e);case"_":return[...this.speak(s),a(i.sub),...this.speak(r)];case"neg":return this.isCompound(s)||"op"===s.type&&"neg"===s.op?[a(`${i.negative} ${i.quantity}`),...this.speak(s),a(i.comma)]:[a(i.negative),...this.speak(s)];case"pm":return[a(i.plusOrMinus),...this.speak(s)];case"!":return[...this.quantity(s),a(i.factorial)];case"\\not":return[a(i.not),...this.quantity(s)];case"sqrt":return[a(i.squareRoot),...this.speak(s),...this.pauseAfter(s)];case"root":{const e="number"===s.type?Number(s.value):NaN,t=3===e?i.cubeRoot:2===e?i.squareRoot:i.nthRoot(e?this.ordinal(e):Vt(this.speak(s))+"th");return[a(t),...this.speak(r),...this.pauseAfter(r)]}case"abs":return[a(i.absoluteValue),...this.speak(s),...this.pauseAfter(s)];case"floor":return[a(i.floor),...this.speak(s),...this.pauseAfter(s)];case"ceil":return[a(i.ceiling),...this.speak(s),...this.pauseAfter(s)];case"log":return"symbol"===s.type&&"e"===s.value?[a(`${this.names.ln} ${i.of}`),...this.argument(r)]:[a(`${i.logBase}`),...this.speak(s),a(i.of),...this.argument(r)];case"mod":return[...this.quantity(s),a(i.mod),...this.quantity(r)];case"pmod":return[...this.speak(s),a(`${i.comma} ${i.mod}`),...this.speak(r)];case"perm":return[...this.quantity(s),a(i.permute),...this.quantity(r)];case"comb":return[...this.quantity(s),a(i.choose),...this.quantity(r)];case"round":{const e=0===("number"===r.type?Number(r.value):NaN)?i.nearestWholeNumber:`${Vt(this.speak(r))} ${i.decimalPlaces}`;return[...this.speak(s),a(`${i.comma} ${i.rounded} ${e}`)]}case"fixed":return 0===("number"===r.type?Number(r.value):NaN)?[...this.speak(s),a(`${i.comma} ${i.asWholeNumber}`)]:[...this.speak(s),a(`${i.comma} ${i.writtenTo}`),...this.speak(r),a(i.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${i.of}`),...this.speak(s),a(i.over),...this.speak(r)];case"random":return[a(i.randomNumber)];case"expm1":return[a(i.eToThe),...this.speak(s),a(`${i.comma} ${i.minus} 1`)];case"?:":return[a(i.if),...this.speak(s),a(`${i.comma} ${i.then}`),...this.speak(r),a(`${i.comma} ${i.otherwise}`),...this.speak(n[2])];case"sum":return n.flatMap((e,t)=>t?[a(i.plus),...this.speak(e)]:this.speak(e));case"prod":return n.flatMap((e,t)=>t?[a(i.times),...this.quantity(e)]:this.quantity(e));case"mean":case"max":case"min":case"gcd":return[a(`${this.names[t]} ${i.of}`),...l()];case"()":return 2===n.length?[a(i.openInterval),...this.speak(s),a(i.to),...this.speak(r)]:l();case"[]":return 2===n.length?[a(i.closedInterval),...this.speak(s),a(i.to),...this.speak(r)]:[a(i.theList),...l()];case"(]":case"[)":return[a(i.halfOpenInterval),...this.speak(s),a(i.to),...this.speak(r)];case"{}":return[a(i.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,i.sumFrom,i.sumOver,i.sumOf);case"\\prodidx":return this.bigOperator(e,i.productFrom,i.productOver,i.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,n]=e.args,s=this.w;if(Fe(e))return[this.seg(e,s.negative),...this.speak(n)];if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,s.degrees)];const r=this.quantity(t),i=this.quantity(n);return this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||i[0].text.startsWith("the ")?[...r,this.seg(e,s.times),...i]:[...r,...i]}isWord(e){return"symbol"===e.type&&/^[A-Za-z]{2,}$/.test(e.value)&&!je[e.value]&&!["pi","tau"].includes(e.value)}isCall(e){return"op"===e.type&&(o(e.op)||"prefix"===a(e.op)?.fixity&&100===c(e.op))}startsWithNumber(e){let t=e;for(;"op"===t.type&&t.args.length;)t=t.args[0];return"number"===t.type}fraction(e){const[t,n]=e.args,s=this.w,r=t=>this.seg(e,t);if("number"===t.type&&"number"===n.type&&/^[1-9]$/.test(t.value)&&/^([2-9]|10)$/.test(n.value)){const e=Number(t.value),i=Number(n.value),o=2===i?1===e?s.half:s.halves:s.ordinals[i]+(1===e?"":"s");return[r(`${s.numerators[e]} ${o}`)]}return[...this.quantity(t),...this.isCall(t)?[r(s.comma)]:[],r(s.over),...this.quantity(n)]}power(e){const[t,n]=e.args,s=this.w,r=t=>this.seg(e,t),i=this.isCompound(t)||this.isCall(t)||"number"===t.type&&t.value.startsWith("-")||"op"===t.type&&"/"===t.op?[r(s.quantity),...this.speak(t),r(s.comma)]:this.speak(t);if(this.isCall(t)&&this.names[t.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===t.args.length){const e=2===Number(n.value)?s.squared:s.cubed;return[r(`${this.names[t.op]} ${e} ${s.of}`),...this.argument(t.args[0])]}if("number"===n.type&&/^(?:[1-9]|10)$/.test(n.value)){const e=Number(n.value);return 2===e||3===e?[...i,r(s.powers[e])]:[...i,r(`${s.toThe} ${s.powers[e]}`)]}if("number"===n.type&&/^\d+$/.test(n.value))return[...i,r(`${s.toThe} ${this.ordinal(Number(n.value))}`)];return!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))?[...i,r(s.toThe),...this.speak(n)]:[...i,r(s.toThePowerOf),...this.speak(n),r(s.comma)]}ordinal(e){if(e<=10&&e>=1)return"squared"===this.w.powers[e]?"second":"cubed"===this.w.powers[e]?"third":this.w.powers[e];return`${e}${e%100>=11&&e%100<=13?"th":["th","st","nd","rd"][e%10]??"th"}`}derivative(e){const{n:t,body:n,by:s,variable:r}=et(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(n),o(i.d),...this.speak(s),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(s),o(i.of),...this.speak(n),...this.pauseAfter(n)]}integral(e){const{args:t}=e,[n,s,r,i]=t,o=this.w,a=t=>this.seg(e,t),l=t.length>=2&&"symbol"===s.type&&1===s.value.length,c=l?this.speak(s):[a(M(n)||"x")];let h=[];4===t.length?h=[r,i]:3===t.length?h=l?[r]:[s,r]:2!==t.length||l||(h=[s]);return[...2===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.to),...this.speak(h[1]),a(o.of)]:1===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(e){const{args:t}=e,[n,s,r,i]=t,o=this.w,a=t=>this.seg(e,t);let l;if(t.length>=3){if(l=[...this.speak(s),a(o.approaches),...this.speak(r)],4===t.length){const e=String(i.value??"").toLowerCase().startsWith("r");l.push(a(e?o.fromTheRight:o.fromTheLeft))}}else if(2===t.length&&"op"===s.type&&"→"===s.op)l=[...this.speak(s.args[0]),a(o.approaches),...this.speak(s.args[1])];else{if(2!==t.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const e=M(n);l=e?[a(e),a(o.approaches),...this.speak(s)]:this.speak(s)}}return[a(o.limitAs),...l,a(o.of),...this.speak(n),...this.pauseAfter(n)]}bigOperator(e,t,n,s){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(n),...this.speak(o),c(l.of)]:[c(s)],[...h,...this.speak(i),...this.pauseAfter(i)]}}for(const e of[Bt,Ht,Qt,Jt,Gt])Object.setPrototypeOf(e,null);function Yt(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":Xt(Ut(e),t)}const en={"(":{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 tn(e,t,n=""){const s=en[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${s.fill?`<path d="${s.fill}" fill="currentColor"/>`:`<path d="${s.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const nn=.8,sn=.2,rn=.25,on=.7,an="−",ln={"+":"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"},cn={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},hn={"±":"±","∪":"∪","∩":"∩",mod:"mod"},un=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],pn={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},mn=[...un,...Object.keys(pn),"ln"],fn={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},gn={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},dn={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},$n={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},bn=["boxed","overline","bar","underline","cancel",...Object.keys($n)],yn={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,attributes:null,style:null},xn=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),vn=e=>+e.toFixed(3)+"em",wn=(e,t=nn,n=sn)=>({html:e,h:t,d:n});function kn(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(nn,...t.map(e=>e.h)),d:Math.max(sn,...t.map(e=>e.d))}}function _n(e,t={}){const n=new En({...yn,...t}),s=n.render(e,{level:0}),r=`${n.p}${n.o.display?` ${n.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):Yt(e)}catch{return null}}(e,n.o.label),o=null===i?s.html:s.html.replace(/^<span /,'<span aria-hidden="true" ');return{html:`<span class="${r}"${null===i?"":` role="math" aria-label="${xn(i)}"`}>${o}</span>`,h:s.h,d:s.d}}class En{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",s=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${s}>${t}</span>`}text(e,t){const n=wn(this.el(e,xn(t)));return n.leaf={kind:e,content:xn(t)},n}bin(e){return this.text("bin",e)}rel(e){return this.text("rel",e)}punct(e){return this.text("punct",e)}word(e){return this.text("word",e)}wrap(e,t,n){let s="";void 0!==e.id&&(s+=` data-node="${e.id}"`),"op"===e.type&&(s+=` data-op="${xn(e.op)}"`);const r=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(r))"class"!==e&&"style"!==e&&(s+=` ${e}="${xn(t)}"`);const i=[r.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),o=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(r.class?[r.class]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${i?` style="${xn(i)}"`:""}${s}>${a}</span>`,h:n.h,d:n.d}}render(e,t){return"number"===e.type?this.number(e):"string"===e.type?this.wrap(e,["text"],this.text("text",e.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===e.type?this.wrap(e,["symbol"],this.symbol(e.value)):this.operation(e,t)}number(e){return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,an)))}symbol(e){return je[e]&&(e=je[e]),dn[e]?this.text("ord",dn[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)?wn(this.el("var",xn(e[0]))+this.el("prime",xn(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?wn(this.el("ord","Δ")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:n,args:s}=e,[r,i]=s,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1}),l=ln[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,n)=>De(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(mn.includes(n)||"log"===n)return c(this.named(e,t));if(fn[n])return c(kn(this.word(fn[n]),this.fence(this.list(s,t))));if(o(n))return c(this.custom(e,t));if(gn[n])return c(this.fence(this.list(s,t),...gn[n]));if(cn[n]&&2===s.length)return c(kn(h(r,"left"),this.rel(cn[n]),h(i,"right")));if(hn[n]&&2===s.length)return c(kn(h(r,"left"),this.bin(hn[n]),h(i,"right")));switch(n){case"+":return Fe(i)?c(kn(h(r,"left"),this.bin(an),this.wrap(i,["op","op-mul"],this.render(i.args[1],t)))):"number"===i.type&&i.value.startsWith("-")?c(kn(h(r,"left"),this.bin(an),this.wrap(i,["number"],this.text("num",i.value.slice(1))))):c(kn(h(r,"left"),this.bin("+"),this.signed(i,h(i,"right"))));case"-":return c(kn(h(r,"left"),this.bin(an),this.signed(i,h(i,"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(i,{level:t.level+1})));case"neg":return c(kn(this.text("sign",an),Ue(n,r)?this.fence(a(r)):a(r,{before:t.before})));case"pm":return c(kn(this.text("sign","±"),Ue(n,r)?this.fence(a(r)):a(r)));case"!":return c(kn(Ue(n,r)?this.fence(a(r)):a(r,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(kn(this.text("sign","¬"),Ue(n,r)?this.fence(a(r)):a(r)));case"pmod":return c(kn(a(r),this.fence(kn(this.word("mod"),this.text("space",""),a(i)))));case"sqrt":return c(this.radical(a(r)));case"root":return c(this.radical(a(i),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(kn(this.word("ln"),this.fence(kn(this.word("ln"),this.fence(a(r))))));case"logloglog":return c(kn(this.word("ln"),this.fence(kn(this.word("ln"),this.fence(kn(this.word("ln"),this.fence(a(r))))))));case"perm":return c(this.script(this.script(wn(""),this.render(r,{level:t.level+1}),t),null,t,this.render(i,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(r),a(i),!1)));case"?:":return c(this.o.cases?this.cases(e,t):kn(a(r),this.bin("?"),a(i),this.bin(":"),a(s[2])));case"sum":return c(kn(s.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(kn(s.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(s,t));case"lim":return c(this.limit(s,t));case"\\sumidx":return c(this.bigOperator("sum",s,t));case"\\prodidx":return c(this.bigOperator("prod",s,t))}throw new Error(`Inline Math cannot draw '${n}'`)}signed(e,t){return("number"===e.type?e.value.startsWith("-"):"neg"===e.op||"pm"===e.op)&&!t.fenced?this.fence(t):t}list(e,t){return kn(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[n,s]=e.args;if(Fe(e))return kn(this.text("sign",an),this.render(s,t));const r=function(e){const[t,n]=e.args;return{left:De(e,t,"left")&&"/"!==t.op,right:De(e,n,"right")&&"/"!==n.op}}(e),i=Be(n,s,r),a=function(e){for(;"op"===e.type;){if(mn.includes(e.op)||"log"===e.op||fn[e.op]||o(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(s),l=r.left?this.fence(this.render(n,t)):this.render(n,{...t,before:i&&!a}),c=r.right?this.fence(this.render(s,t)):this.render(s,{...t,before:t.before});return kn(l,i?wn(this.el(a?"fnspace":"times","")):this.bin("·"),c)}named(e,t,n=null){const{op:s,args:r}=e,i="log"===s?r[1]:r[0];let o;o=pn[s]&&"power"===this.o.inverseTrig?this.script(this.word(pn[s]),this.text("num","−1"),t):this.word(s),n&&(o=this.script(o,n,t)),"log"===s&&(o=this.script(o,null,t,this.render(r[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&Mn(i),l=this.render(i,{...t,forceParens:!1,before:!1});return kn(o,a?kn(wn(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=Ye(e.op),s=e.args;if(bn.includes(n)&&1===s.length)return this.decorate(n,this.render(s[0],t));return kn(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),wn(this.el("callgap","")),this.fence(this.list(s,t)))}decorate(e,t){switch(e){case"boxed":return wn(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return wn(this.el("cancel",t.html),t.h,t.d);case"underline":return wn(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return wn(this.el("over",t.html),t.h+.14,t.d);default:return wn(this.el("accent",this.el("accent-mark",$n[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,s]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&Mn(n,!0)&&Mn(s,!0)){const e=e=>"op"!==e.type||Mn(e)?this.render(e,t):this.fence(this.render(e,t));return kn(e(n),this.text("ord","/"),e(s))}const r=t.level>0||t.inFraction||!this.o.display?.8:1,i={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,i),this.render(s,i),!0,r)}stack(e,t,n=!0,s=1){const r=e=>1===s?e.html:this.el("scaled",e.html,`font-size:${vn(s)}`),i=n?.06:0,o=rn+i/2+.1+Math.max(sn,s*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",r(e))+this.el("denom",r(t)),`vertical-align:${vn(o)}`);return wn(a,o+Math.max(nn,s*e.h),Math.max(nn,s*t.h)+Math.max(sn,s*t.d)+.1+i/2-rn)}power(e,t){const[n,s]=e.args,r={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1},i=()=>this.render(s,r);if(this.o.trigPowers&&un.includes(n.op)&&qn(s))return this.wrap(n,["op",`op-${n.op}`],this.named(n,t,i()));if("_"===n.op){const e=this.render(n.args[1],r);return this.wrap(n,["op","op-subscript"],this.script(this.render(n.args[0],{...t,forceParens:!0}),i(),t,e))}const o=De(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||mn.includes(n.op)?this.fence(this.render(n,t)):this.render(n,{...t,forceParens:!0});return this.script(o,i(),t)}script(e,t,n,s=null,r=null){const i=n.level>0?.8:on,o=r?kn(e,r):e;let a=t?Math.max(.42,e.h-.38,i*t.d+.12):0,l=s?Math.max(.2,e.d-.05,i*s.h-.45):0;if(t&&s){const e=.1-(a-i*t.d-(i*s.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${vn(i)}`);if(t&&!s)return wn(e.html+this.el("sup",t.html,`font-size:${vn(i)};vertical-align:${vn(a/i)}`),Math.max(o.h,a+i*t.h),Math.max(o.d,i*t.d-a));if(s&&!t)return wn(o.html+this.el("sub",s.html,`font-size:${vn(i)};vertical-align:${vn(-l/i)}`),Math.max(o.h,i*s.h-l),Math.max(o.d,l+i*s.d));const h=a+i*t.h,u=l+i*s.d,p=this.el("subsup",c(t)+c(s),`vertical-align:${vn(a)};height:${vn(h+u)}`);return wn(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,nn)+.1+.06,s=Math.max(e.d,sn),r=n+s,i=tn("sqrt",`${this.p}-hook`,`height:${vn(r)};width:${vn(.5+.06*(r-1))};vertical-align:${vn(-s)}`);let o="";if(t){const e=.8*on;o=this.el("rootindex",t.html,`font-size:${vn(e)};vertical-align:${vn((.55*r-s)/e)}`)}return wn(this.el("sqrt",o+i+this.el("radicand",e.html)),n,s)}fence(e,t="(",n=")"){const s=Math.max(e.h,nn)+Math.max(e.d,sn),r=s>1.25,i=r?.1:0,o=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const i=n+(r?Math.min(.2,.05*(s-1)):0);return{html:tn(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${vn(i)}`),w:i+.1}}const i={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${i} delim-${t}`,""),w:"|"===e?.18:.3}},a=o(t,"l"),l=o(n,"r"),c=`padding:${vn(i)} ${vn(l.w)} ${vn(i)} ${vn(a.w)}`,h=wn(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,nn)+i,Math.max(e.d,sn)+i);return h.fenced=!0,h}derivative(e,t){const{n:n,body:s,by:r,variable:i}=et(e),o={...t,level:t.level+1},a=()=>this.text("d","d"),l=()=>n>1?this.render({type:"number",value:String(n)},o):null,h={...t,inFraction:!0},u=kn(a(),l()?this.script(this.render(r,h),l(),h):this.render(r,h)),p=e=>kn(l()?this.script(a(),l(),h):a(),e||[]),m=t.level>0||t.inFraction||!this.o.display?.8:1;if(i)return this.stack(p(this.render(s,h)),u,!0,m);const f=We(s)&&c(We(s))<100,[g,d]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],$=f?this.fence(this.render(s,t),g,d):this.render(s,t);return kn(this.stack(p(),u,!0,m),$)}integral(e,t){const[n,s,r,i]=e,o=e=>this.render(e,t),a=e=>e?this.render(e,{...t,level:t.level+1}):null,l=()=>this.text("var",M(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:Ke(s)?c=o(s):(c=l(),h=a(s));break;case 3:Ke(s)?(c=o(s),h=a(r)):(c=l(),h=a(s),u=a(r));break;default:c=o(s),h=a(r),u=a(i)}const p=o(n),m=wn(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return kn(this.bigSign("int",p,h,u,t),p,m)}bigSign(e,t,n,s,r){const i=!this.o.display||r.level>0,o=Math.max(i?.6:.95,Math.max(t.h-rn,t.d+rn)+.12),a=tn(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${vn(2*o)};width:${vn(i?.38:.5)};vertical-align:${vn(rn-o)}`);if(!n&&!s)return wn(a,rn+o,o-rn);const l=on,c=s||wn(""),h=n||wn(""),u=rn+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${vn(l)}`)+this.el("script lower",h.html,`font-size:${vn(l)}`),`vertical-align:${vn(u)};height:${vn(2*o)}`);return wn(a+p,rn+o,o-rn)}limit(e,t){const[n,s,r,i]=e,o={...t,level:t.level+1},a=e=>this.render(e,o),l=()=>this.rel("→");let c;switch(e.length){case 1:return kn(this.word("lim"),wn(this.el("fnspace","")),this.render(n,t));case 2:{const e=M(n),t="number"===s.type||"symbol"===s.type&&s.value.includes("∞");c=e&&t?kn(this.text("var",e),l(),a(s)):a(s);break}case 3:c=kn(a(s),l(),a(r));break;default:{const e=Pe(i).toLowerCase().startsWith("r")?"+":an;c=kn(a(s),l(),this.script(a(r),this.wrap(i,["symbol"],this.text("ord",e)),o))}}return kn(this.under(this.word("lim"),c,t),this.render(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):wn(this.el("under",e.html+this.el("script",t.html,`font-size:${vn(.7)}`)),e.h,Math.max(e.d,sn)+.05+.7*(t.h+t.d))}bigOperator(e,t,n){const[s,r,i]=t,o={...n,level:n.level+1},a=r?this.render(r,o):null,l=i?this.render(i,o):null,c=this.render(s,n);if(!this.o.display||n.level>0){const t=.55,s=tn(e,`${this.p}-bigsign`,`height:${vn(2*t)};width:${vn(.8)};vertical-align:${vn(rn-t)}`);return kn(this.script(wn(s,rn+t,t-rn),l,n,a),c)}const h=.68,u=on,p=tn(e,`${this.p}-bigsign`,`height:${vn(1.36)};width:${vn("sum"===e?1:1.05)}`),m=l?1.01+u*l.d:rn-h,f=e=>this.el("script",e.html,`font-size:${vn(u)}`),g=this.el("bigop",(l?f(l):"")+p+(a?f(a):""),`vertical-align:${vn(m)}`);return kn(wn(g,.93+(l?.08+u*(l.h+l.d):0),h-rn+(a?.08+u*(a.h+a.d):0)),c)}cases(e,t){const n=[];let s=e;for(;"op"===s.type&&"?:"===s.op;)n.push([this.render(s.args[1],t),kn(this.word("if"),this.text("space",""),this.render(s.args[0],t))]),s=s.args[2];n.push([this.render(s,t),this.word("otherwise")]);const r=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),i=r.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),o=rn+i/2-r[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=wn(this.el("cases",a,`vertical-align:${vn(o)}`),rn+i/2,i/2-rn);return this.fence(l,"{","")}}function Mn(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&&!Fe(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||An(e)||"*"===e.op&&Mn(e,t)):Mn(e.args[0],!0)&&("neg"===e.op||Mn(e.args[1],!0)))}const An=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(je[e.value])),qn=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const On=e=>_(e).join(" ");function Nn(e,t){const n=new Set;Cn(e,t,n);const s=[];return E(e,e=>{n.has(e)&&s.push(e)}),s}function Cn(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>Cn(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const s=On(Dt(t));return void E(e,e=>{On(e)===s&&n.add(e)})}if(t.path){const s=function(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}(e,t.path);return void(s&&n.add(s))}if(t.type){const s=On(t);E(e,e=>{e!==t&&On(e)!==s||n.add(e)})}}else E(e,(e,s)=>{t(e,s)&&n.add(e)});else E(e,e=>{e.id===t&&n.add(e)})}function Ln(e){let n=0;const s=e=>{"op"===e.type&&(e.args.forEach(s),a(e.op)?.arity===t&&n++),e.id=n++};return s(e),e}function Sn(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Dt(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return k(e);if(e&&"object"==typeof e&&e.type)return void 0===e.id?Ln(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Rn(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var zn='/*\n * Inline Math stylesheet. Everything is under .mv; colours are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight colour\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; border-top: 0.06em solid currentColor; padding-top: 0.08em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; background: linear-gradient(to top right, transparent calc(50% - 0.04em), currentColor calc(50% - 0.03em), currentColor calc(50% + 0.03em), transparent calc(50% + 0.04em)); }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with maths (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n';const In=zn;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=zn,document.head.append(e)}return e.CSS=In,e.DEFAULTS=yn,e.layout=_n,e.numberTree=Ln,e.select=Nn,e.toHTML=function(e,t={}){const n=Sn(e,t);return _n(n,function(e,t){const{colors:n,highlight:s,scope:r,blocks:i,...o}=t,a=new Map;for(const[t,s]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(Rn(s))for(const n of Nn(e,t))a.set(n,`color:${s}`);const l=new Set(void 0===s?[]:Nn(e,s));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}(n,t)).html},e.treeOf=Sn,e}({});
|
|
1
|
+
/* Inline Math 0.2.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
var InlineMath=function(e){"use strict";const t=-1,n={"+":{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:i(1),abs:i(1),floor:i(1),ceil:i(1),det:i(1),ln:i(1),loglog:i(1),logloglog:i(1),expm1:i(1),sin:i(1),cos:i(1),tan:i(1),csc:i(1),sec:i(1),cot:i(1),sinh:i(1),cosh:i(1),tanh:i(1),arcsin:i(1),arccos:i(1),arctan:i(1),arcsinh:i(1),arccosh:i(1),arctanh:i(1),random:i(0),log:i(2),root:i(2),atan2:i(2),round:i(2),fixed:i(2),perm:i(2),comb:i(2),der:i(2),max:i(t),min:i(t),gcd:i(t),mean:i(t),sum:i(t),prod:i(t),int:i(t),lim:i(t),"\\sumidx":i(t),"\\prodidx":i(t),pmatrix:i(t),bmatrix:i(t),vmatrix:i(t),"()":s(),"[]":s(),"{}":s(),"(]":s(),"[)":s(),"=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"===":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"<":{prec:34,assoc:"left",arity:2,fixity:"infix"},">":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≤":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≥":{prec:34,assoc:"left",arity:2,fixity:"infix"},"∈":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∉":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∪":{prec:33,assoc:"left",arity:2,fixity:"infix"},"∩":{prec:33,assoc:"left",arity:2,fixity:"infix"},"≈":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≡":{prec:30,assoc:"left",arity:2,fixity:"infix"},pmod:{prec:2,assoc:"left",arity:2,fixity:"infix"},"→":{prec:38,assoc:"left",arity:2,fixity:"infix"},"\\not":{prec:85,assoc:"none",arity:1,fixity:"prefix"},"&":{prec:20,assoc:"left",arity:2,fixity:"infix"},"\\xor":{prec:19,assoc:"left",arity:2,fixity:"infix"},"|":{prec:18,assoc:"left",arity:2,fixity:"infix"},"\\nor":{prec:17,assoc:"left",arity:2,fixity:"infix"},"\\nand":{prec:17,assoc:"left",arity:2,fixity:"infix"},"?:":{prec:10,assoc:"right",arity:3,fixity:"infix"}};function i(e){return{prec:100,assoc:"none",arity:e,fixity:"prefix"}}function s(){return{prec:5,assoc:"left",arity:t,fixity:"none",group:!0}}const r="\\:",o=e=>"string"==typeof e&&e.startsWith(r)&&e.length>2;function a(e){return Object.prototype.hasOwnProperty.call(n,e)?n[e]:o(e)?l:void 0}const l=i(t),c=e=>a(e)?.prec;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,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,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),m=new Set(["^","?:","?","log"]),d=["(","{","["],f=[")","}","]"];function g(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[u])Object.setPrototypeOf(e,null);const b=e=>({type:"number",value:String(e)}),x=e=>({type:"symbol",value:e}),$=(e,t)=>({type:"op",op:e,args:t}),y=['"',"'","`"];function v(e){return g(e,!0)?b(e):y.includes(e[0])?{type:"string",value:e}:x(e)}const w={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function k(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],i=[];if(e.forEach((e,s)=>{const r=w[e]??String(e),o=a(r);if(!o)return n.push({...v(r),id:s}),void i.push(1);let l=o.arity;if(l===t){const e=n.pop();if(i.pop(),l=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(l)||l<0)throw new Error(`'${r}' takes a variable number of arguments, so it must follow a count`)}if(n.length<l)throw new Error(`'${r}' needs ${l} operand${1===l?"":"s"}`);const c=1+Math.max(0,...i.splice(i.length-l,l));if(c>1e3)throw new Error("Nested too deeply (more than 1000 levels)");i.push(c),n.push({...$(r,n.splice(n.length-l,l)),id:s})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function _(e){const n=[];return function e(i){"op"===i.type?(i.args.forEach(e),a(i.op)?.arity===t&&n.push(String(i.args.length)),n.push(i.op)):n.push(i.value)}(e),n}function E(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>E(n,t,e))}function M(e){let t="";return E(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[w])Object.setPrototypeOf(e,null);function A(e){const t=new Map;for(const[n,i,s]of e)if(n&&""!==n.trim()&&(t.set(n,i),!s))for(const e of q(n))t.get(e)||t.set(e,i);const n=new Map;for(const e of t.keys()){let t=n;for(let n=0;n<e.length;n++)t.has(e[n])||t.set(e[n],new Map),t=t.get(e[n]);t.end=!0}return e=>{let i="",s=0;for(;s<e.length;){const r=O(n,e,s);r?(i+=t.get(e.slice(s,s+r)),s+=r):i+=e[s++]}return i}}function O(e,t,n){let i=e,s=0;for(let e=n;e<t.length&&(i=i.get(t[e]),i);e++)i.end&&(s=e-n+1);return s}function q(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),N(e)]);return t.delete(e),t}function N(e){let t="",n=!1;for(const i of e){const e=i>="a"&&i<="z",s=i>="A"&&i<="Z";t+=!n&&e?i.toUpperCase():i,n=e||s}return t}const L="({[",S=")}]";function C(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 T(e,t){const n=[];let i=0,s=0;for(let r=0;r<e.length;r++)L.includes(e[r])?i++:S.includes(e[r])?i--:0===i&&e.startsWith(t,r)&&(n.push(e.slice(s,r)),r+=t.length-1,s=r+1);return n.push(e.slice(s)),n}function z(e,t,n){let i=0;const s=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(L.includes(e[n]))i++;else if(S.includes(e[n])){if(--i<0)return-1}else if(0===i&&(s.lastIndex=n,s.test(e)))return n;return-1}function R(e,t){let n=0;for(let i=t;i<e.length;i++)if(L.includes(e[i]))n++;else if(S.includes(e[i])&&--n<0)return i;return e.length}function I(e,t){let n=1;for(let i=t+1;i<e.length;i++)if("?"===e[i])n++;else if(":"===e[i]&&0===--n)return e.slice(0,t+1)+"("+e.slice(t+1,i)+")?:"+e.slice(i+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(L.includes(e[t+2]))continue;const n=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(e.slice(t+2))?.[0];if(!n)continue;const i=t+2+n.length;e=e.slice(0,t+2)+"{"+n+"}"+e.slice(i)}else if("("===e[t+1]){let n=1,i=0,s="",r="",o=0;for(let a=t+2;a<e.length;a++){if(")]".includes(e[a])?n--:"([".includes(e[a])&&n++,0===n){o=a;break}1===n&&","===e[a]?i++:0===i?s+=e[a]:r+=e[a]}1===i&&(e=e.slice(0,t+1)+"_{"+r+"}("+s+")"+e.slice(o+1))}return e}function Z(e){const t="⌈"===e[0]?"ceil":"floor";let n=1;for(let i=1;i<e.length;i++)if("⌊"===e[i]||"⌈"===e[i]?n++:"⌋"!==e[i]&&"⌉"!==e[i]||n--,0===n)return t+"("+e.slice(1,i)+")"+e.slice(i+1);return e}function P(e){let t=1;for(let n=0;n<e.length;n++){if(")]".includes(e[n])?t--:"([".includes(e[n])&&t++,0!==t)continue;const i=e.slice(0,n),s=e[n+1];if("{"===s||"("===s)return s+i+","+e.slice(n+2);const r=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(e.slice(n+1))?.[0]??"";return"{"+i+","+r+"}"+e.slice(n+1+r.length)}return e}const F=new Set(["pmatrix","bmatrix","vmatrix"]);function W(e){const t=e.indexOf("}"),n=e.indexOf("{");if(t<0||n>=0&&n<t)return!1;const i=e.slice(0,t);if(!i.includes("matrix"))return!1;const s=e.indexOf("\\end{"+i+"}"),r=e.indexOf("\\begin{"+i+"}",t+1);if(s<0||-1!==r&&r<s)return!1;const o=e.slice(t+1,s).trim().split("\\\\").map(e=>e.trim()).filter(e=>e.length).map(e=>"["+e.replace(/&/g,", ")+"]"),a=e.slice(s+6+i.length);return F.has(i)?i+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function D(e,t){if("{"!==e[t+1])return[e[t+1],t+2];let n=1,i="";for(let s=t+2;s<e.length;s++){if("{"===e[s])n++;else if("}"===e[s]&&0===--n)return[i,s+1];i+=e[s]}return[i,e.length]}function U(e){const{lower:t,upper:n,next:i}=function(e){let t="",n="",i=0;return"_"===e[0]&&([t,i]=D(e,0),"^"===e[i]&&([n,i]=D(e,i))),{lower:t,upper:n,next:i}}(e),s=e.slice(i),r=e=>e.replace(/\\,/g,"").replace(/\\!/g,"");let o,a="",l="",c=s.indexOf("\\mathrm{d}");if(c>=0){o=s.slice(0,c);const e=/^\{([^{}]*)\}/.exec(s.slice(c+10));a=e?e[1]:s[c+10],l=s.slice(c+10+(e?e[0].length:1))}else(c=function(e){let t=0;for(let n=0;n<e.length;n++)if(L.includes(e[n]))t++;else if(S.includes(e[n]))t--;else if(0===t&&"d"===e[n]&&/[A-Za-z\u0370-\u03FF]/.test(e[n+1]??"")&&!/[A-Za-z]/.test(e[n+2]??""))return n;return-1}(s))>=0?(o=s.slice(0,c),a=s[c+1],l=s.slice(c+2)):o=s;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=[...r(o).matchAll(/(?<![A-Za-z\\])([A-Za-z])(?![A-Za-z(])/g)].map(e=>e[1]).find(e=>e!==t&&e!==n)??"x"}let h="int("+(r(o)||"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function B(e){const t=e[0];if(!(t>="A"&&t<="Z"||t>="a"&&t<="z"||t>="α"&&t<="ω"))return!1;const n=e.slice(2);let i=1;for(let e=0;e<n.length;e++)if(S.includes(n[e])?i--:L.includes(n[e])&&i++,0===i)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function H(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const G=/[A-Za-z\u0370-\u03FF]/;function X(e,t){if("{"!==e[t])return null;let n=0;for(let i=t;i<e.length;i++)if("{"===e[i])n++;else if("}"===e[i]&&0===--n)return[e.slice(t+1,i),i+1];return null}function Q(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function V(e,t){const n=e.replace(/\\mathrm\{d\}/g,"d"),i=t.replace(/\\mathrm\{d\}/g,"d"),s=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(n),r=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(i);return s&&r?{n:Number(s[1]??1),of:s[2],by:r[1]}:null}function Y(e,t){if(L.includes(e[t])){let n=0;for(let i=t;i<e.length;i++)if(L.includes(e[i]))n++;else if(S.includes(e[i])&&0===--n)return[e.slice(t,i+1),i+1];return[e.slice(t),e.length]}let n=0;for(let i=t;i<e.length;i++)if(L.includes(e[i]))n++;else{if(S.includes(e[i])&&--n<0)return[e.slice(t,i),i];if(0===n&&("="===e[i]||","===e[i]))return[e.slice(t,i),i]}return[e.slice(t),e.length]}const J=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const K="strtktk",ee="ABCDEFGHIJ",te=e=>K+[...String(e)].map(e=>ee[e]).join("");function ne(e,t){let n=!1;for(let i=t+1;i<e.length;i++)if(n)n=!1;else if("\\"===e[i])n=!0;else if(e[i]===e[t])return i;return e.length-1}function ie(e,t){if(!t||0===t.size)return e;const n=[...t].sort((e,t)=>t[0].length-e[0].length);return e.map(e=>{for(const[t,i]of n)e=e.split(t).join(i);return e})}const se={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[se])Object.setPrototypeOf(e,null);const re="([{",oe=")]}";function ae(e,t){let n=0;for(let i=t;i<e.length;i++)if(re.includes(e[i]))n++;else if(oe.includes(e[i])&&0===--n)return i;return-1}function le(e){if(!e.trim())return[];const t=[];let n=0,i=0;for(let s=0;s<e.length;s++)re.includes(e[s])?n++:oe.includes(e[s])?n--:","===e[s]&&0===n&&(t.push(e.slice(i,s).trim()),i=s+1);return t.push(e.slice(i).trim()),t}function ce(e,t,n){const i=[...e.matchAll(t)];for(let t=i.length-1;t>=0;t--){const s=i[t],r=s.index+s[0].length-1,o=ae(e,r);if(o<0)continue;const a=n(le(e.slice(r+1,o)),s,e.slice(o+1));if(null==a)continue;const[l,c=0]=Array.isArray(a)?a:[a];if((e=e.slice(0,s.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 me={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 de={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"},fe="strtktk[A-J]+";function ge(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${fe})\\s*\\|\\|\\s*(${fe})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${fe},\\s*${fe}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const i=ae(e,n),s=i>0&&t.exec(e.slice(n,i+1));if(!s)continue;const[,r,o]=s,a={[`${r} = TRUNC(${r})`]:"ℤ",[`${r} = TRUNC(${r}) AND ${r} > 0`]:"ℕ",[`ABS(${r}) < ∞`]:"ℝ"}[o.trim()];a&&(e=`${e.slice(0,n)}((${r}) ∈ ${a})${e.slice(i+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 n=t[t.length-1].index,i=/\bEND\b/i.exec(e.slice(n));if(!i)return e;const s=e.slice(n+4,n+i.index).split(/\b(WHEN|THEN|ELSE)\b/i).map(e=>e.trim()),r=[];let o="null";for(let e=1;e<s.length;e+=2){const t=s[e].toUpperCase();"WHEN"===t?r.push([s[e+1],s[e+3]]):"ELSE"===t&&(o=s[e+1])}const a=r.reduceRight((e,[t,n])=>`((${t}) ? (${n}) : ${e})`,ue(o));e=e.slice(0,n)+a+e.slice(n+i.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=>de[e]??e);for(const[t,n]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let i=t.exec(e);i;i=t.exec(e)){const s=i.index+i[0].length-1,r=ae(e,s);if(r<0)break;e=`${e.slice(0,i.index)}${n} {${e.slice(s+1,r)}}${e.slice(r+1)}`,t.lastIndex=0}return e.replace(/<>/g," ≠ ")}const be={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"},xe={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 $e(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)=>ve[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>ve[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>we[t]??ye[t]??e)}(e=(e=(e=(e=(e=(e=(e=e.replace(/(?<![\w.])(?:np|numpy)\.random\.random\(\s*\)|(?<![\w.])random\.random\(\s*\)/g,"Math.random()")).replace(/(?<![\w.])(?:np|numpy)\.linalg\.(det|inv)\b/g,"$1")).replace(/(?<![\w.])(?:np|numpy)\.array\s*\(/g,"(")).replace(/(?<![\w.])(?:np|numpy)\.(\w+)/g,(e,t)=>be[t]?`Math.${be[t]}`:xe[t]?xe[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 ye={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},ve={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},we={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},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]}`,Me=e=>_e(e)??[e],Ae={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,n])=>null===e||/^True$|^true$/.test(n.trim())&&void 0===e?`(${t})`:`((${n}) ? (${t}) : ${e??"(null)"})`,void 0)},sympy_set:e=>`{${e.join(", ")}}`,sympy_interval: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=Me(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&&Me(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&&Me(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:Oe("sum"),prod:Oe("prod")};function Oe(e){return t=>{const n=1===t.length&&/^(.*?)\s+for\s+(\w+)\s+in\s+range\((.*)\)\s*$/s.exec(t[0]);if(!n)return null;const i=le(n[3]),[s,r]=1===i.length?["0",i[0]]:i,o=/\s*\+\s*1$/.test(r)?r.replace(/\s*\+\s*1$/,""):`(${r}) - 1`;return`(\\${e}_{${n[2]}=${s}}^{${o}} (${n[1]}))`}}for(const e of[me,de,be,xe,ye,ve,we,ke,Ae])Object.setPrototypeOf(e,null);const qe=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="[<>≤≥=≠≈]",Te=[["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=A([[" 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 ","→"],["===","=...="]]),Re=A([["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"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],["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,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const e of["","h"]){const i=n+e,s="arc"+n+e;e&&(t("Math."+i,i),t("\\"+i,i));for(const n of["^-1","^{-1}","-1"])t("\\"+i+n,s),t(i+n,s),e||t("Math."+i+n,s);e||t("\\a"+i,s),t("\\arc"+i,s),t("Math.a"+i,s),t("Math.arc"+i,s)}return e}()]),Ie=[["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 n=!0;n;){const i=e;n=(e=e.replace(new RegExp(`(^|[^\\p{L}\\p{N}_.)§])(${t}\\s*\\^\\s*${t})(?=\\s*\\^)`,"u"),"$1($2)"))!==i}return ce(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>me[t[1]]?.(e)||null)}(e)),e=function(e){e=ce(e,he("quad"),(e,t,n)=>{const i=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(e[0]??"");if(!i||3!==e.length)return null;const s=/^\s*\[\s*0\s*\]/.exec(n);return[`int(${i[2]}, ${i[1]}, ${e[1]}, ${e[2]})`,s?s[0].length:0]}),e=ce(e,he(Object.keys(Ae).join("|")),(e,t)=>Ae[t[1]](e)||null);for(let t=(e=ce(e,he("float"),(e,t,n)=>{const i=/^\s*\.is_integer\(\s*\)/.exec(n);return i&&1===e.length?[`((${e[0]}) ∈ ℤ)`,i[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,i=ae(e,n);let s=t;if(oe.includes(e[t-1])){let n=0;for(s=t-1;s>=0;s--)if(oe.includes(e[s]))n++;else if(re.includes(e[s])&&0===--n)break}else for(;s>0&&/[\w.]/.test(e[s-1]);)s--;i<0||s<0||s===t||(e=`${e.slice(0,s)}((${e.slice(n+1,i)}) ∈ ${pe(e.slice(s,t))})${e.slice(i+1)}`)}return e}(e=$e(e=ge(e=(e=(e=function(e){for(const[t,n]of Object.entries(se))for(let i=e.lastIndexOf(n);i>=0;i=i>0?e.lastIndexOf(n,i-1):-1){const s=i+n.length,r="("===e[s]?ae(e,s):-1;if(r<0)continue;let o=e.slice(s+1,r);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===t?`((${o})!)`:`${t}(${o})`;e=e.slice(0,i)+a+e.slice(r+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const n=t+10-1,i=ae(e,n),s=e.lastIndexOf("Number(",t);i<0||s<0||ae(e,s+7-1)!==t||(e=e.slice(0,s)+`fixed(${e.slice(s+7,t)}, ${e.slice(n+1,i)})`+e.slice(i+1))}return e.replace(/\(\(\)=>\{let (sum|prod) = [01]; let loopCount = 0; for \(let (\w+)=(.*?);\2<=(.*?);\2\+\+\) \{if \(loopCount\+\+ > 1000000\)\{break\};\1 [+*]= (.*?);\}; return \1;\}\)\(\)/g,(e,t,n,i,s,r)=>`(\\${"sum"===t?"sum":"prod"}_{${n}=${i}}^{${s}} (${r}))`)}(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 n of e.matchAll(/\bif\b/g)){const i=n.index;let s=0,r=-1,o=e.length;for(let t=i+2;t<e.length;t++)if(re.includes(e[t]))s++;else{if(oe.includes(e[t])&&--s<0){o=t;break}if(0===s&&","===e[t]){o=t;break}if(0===s&&/^then\b/.test(e.slice(t))&&/\W/.test(e[t-1])){r=-2;break}0===s&&r<0&&/^else\b/.test(e.slice(t))&&/\W/.test(e[t-1])&&(r=t)}if(r<0)continue;s=0;let a=0;for(let t=i-1;t>=0;t--)if(oe.includes(e[t]))s++;else{if(re.includes(e[t])&&--s<0){a=t+1;break}if(0===s&&","===e[t]){a=t+1;break}}const l=e.slice(a,i).trim();if(!l)continue;const c=`((${e.slice(i+2,r).trim()}) ? (${l}) : (${e.slice(r+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 n=(e,n,i,s="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Ne(e)}\s+(${qe})\s+(?:and|to)\s+(${qe})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(e,t,r,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[n,i];return` ${s} ${a}${t}, ${r}${l} `})};n("is not strictly between","(",")","∉"),n("is not between","[","]","∉"),n("is strictly between","(",")"),n("is between","[","]"),n("between","[","]"),t=t.replace(new RegExp(String.raw`(?<![\w.])is\s+(not\s+)?in\s+the\s+(open|closed|half-open)\s+interval\s+from\s+(${qe})\s+to\s+(${qe})`,"gi"),(e,t,n,i,s)=>{const[r,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[n.toLowerCase()];return` ${t?"∉":"∈"} ${r}${i}, ${s}${o} `});const i=String.raw`(${qe})\s+`;t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?within\s+(${qe})\s*(%|\s+percent)?\s+of\s+(${qe})`,"gi"),(e,t,n,i,s,r)=>`(abs((${t}) - (${r})) ${n?">":"≤"} ${s?`(${i})/100 * ${/^\d+(\.\d+)?$/.test(r)?r:`abs(${r})`}`:`(${i})`})`),t=t.replace(new RegExp(i+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${qe})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?divisible\s+by\s+(${qe})`,"gi"),(e,t,n,i)=>`((${t}) mod (${i}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${qe})\s+divides\s+(${qe})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,n,i)=>`((${t}) mod 2 ${"even"===i.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[e,n]of Te)t=t.replace(Le(e),` ${n} `);t=t.replace(Le("is not in")," ∉ ").replace(Le("is in")," ∈ ").replace(Le("is an element of")," ∈ ");for(const[e,n]of Se)t=t.replace(Le(e),` ${n} `);t=t.replace(Le("is not")," ≠ "),t=t.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let e=!0;e;){const n=t;t=t.replace(new RegExp(String.raw`(${qe})\s*(${Ce})\s*(${qe})\s+(and|or)\s+(${Ce})`,"gi"),"$1 $2 $3 $4 $1 $5"),e=t!==n}t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${qe})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${qe})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${qe})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${qe})\s+to\s+the\s+power\s+of\s+(${qe})`,"gi"),"($1)^($2)");const s={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`(${qe})\s+to\s+the\s+(${Object.keys(s).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,i)=>`(${t})^(${s[n.toLowerCase()]??i})`),t=t.replace(new RegExp(String.raw`(${qe})\s+to\s+the\s+(${qe})(?![\w.])`,"gi"),"($1)^($2)");const r={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,n]of Object.entries(r).sort((e,t)=>t[0].length-e[0].length))t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Ne(e)}\s+of\s+(${qe})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${qe})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${qe})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${qe})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${qe})`,"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,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(o(e),` ${n} `);return t}],["words",ze],["spaced",function(e){e=j(e=function(e){for(let t=0;t<e.length;t++){const n=n=>e.slice(Math.max(0,t-n),t+1);if("t"===e[t]&&"\\text"===n(4)&&"{"===e[t+1]){let n=1,i=t+2,s="";for(;n>0&&i<e.length;)"{"===e[i]?n++:"}"===e[i]?n--:s+=e[i],i++;e=e.slice(0,t-4)+s+e.slice(i)}}return e}(e=(e=(e=function(e){for(let t=0;t<100;t++){const t=[...e.matchAll(/\bif\b/gi)];if(!t.length)return e;const n=t[t.length-1].index,i=z(e,n+2,"then");if(i<0)return e;const s=e.slice(n+2,i),r=z(e,i+4,"else"),o=R(e,r<0?i+4:r+4),a=e.slice(i+4,r<0?o:r),l=r<0?"unchanged":e.slice(r+4,o).trim();e=`${e.slice(0,n)}((${s.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=I(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}let i=t+1;for("-"===e[i]&&i++;i<e.length&&".0123456789".includes(e[i]);)i++;i===t+2&&"-"===e[t+1]&&(i=t+1),i>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,i)+"}"+e.slice(i))}return e}],["squeeze",function(e){return e.replace(/\s+/g,(t,n)=>{const i=e[n-1]??"",s=e[n+t.length]??"";return"Δ"===i?"":/[A-Za-z\u0370-\u03FF′]/.test(i)&&/[A-Za-z\u0370-\u03FF]/.test(s)?" ":""})}],["symbols",Re],["compact",function(e){e=function(e){for(let t=0;t<e.length;t++){const n=t>0&&G.test(e[t-1]);let i,s=null,r=t;if(e.startsWith("frac{",t)){const n=X(e,t+4),i=n&&X(e,n[1]);s=i&&V(n[0],i[0]),s&&(r=i[1])}else if("d"===e[t]&&!n){let[n,i]=Q(e,t+1),o="";if(G.test(e[i]??"")&&"/"===e[i+1]&&(o=e[i++]),"/"===e[i]&&"d"===e[i+1]&&G.test(e[i+2]??"")){const t=e[i+2],[,a]=Q(e,i+3);s={n:n,of:o,by:t},r=a}}if(s){if(s.of)i=J(s.of,s.by,s.n);else{const[t,n]=Y(e,r);if(!t)continue;i=J(t,s.by,s.n),r=n}e=e.slice(0,t)+i+e.slice(r),t+=3}}return e}(e=function(e){for(let t=e.indexOf(")′");t>=0;t=e.indexOf(")′",t+1)){let n=0,i=-1;for(let s=t;s>=0;s--)if(")"===e[s])n++;else if("("===e[s]&&0===--n){i=s;break}if(i<0)continue;for(;i>0&&/[A-Za-z\u0370-\u03FF′]/.test(e[i-1]);)i--;let s=0;for(;"′"===e[t+1+s];)s++;e=e.slice(0,i)+J(e.slice(i,t+1),"x",s)+e.slice(t+1+s),t=i}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 n=e[t],i=n=>e.slice(Math.max(0,t-n),t),s=n=>e.slice(Math.max(0,t-n),t+1);if("{"===n){if("\\begin"===i(6)){const n=W(e.slice(t+1));n&&(e=e.slice(0,t-6)+n)}}else if("["===n)"\\sqrt"===i(5)?e=e.slice(0,t-5)+"sqrt"+P(e.slice(t+1)):"sqrt"===i(4)&&(e=e.slice(0,t-4)+"sqrt"+P(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+Z(e.slice(t));else if("t"===n)"\\int"===s(3)&&(e=e.slice(0,t-3)+U(e.slice(t+1)));else if("m"===n)"\\binom"===s(5)&&(e=e.slice(0,t-5)+"\\binom"+H(e.slice(t+1)));else if("d"===n&&"dd"===s(1)&&"("===e[t+2]){const n=B(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return e.replace(/\\log/g,"log")}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]];function je(e,t={}){if("string"!=typeof e)throw new Error("Expression must be a string");const{text:n,strings:i}=function(e){const t=new Map;let n="",i=0;for(;i<e.length;){const s=e[i];if('"'!==s&&"'"!==s&&"`"!==s){n+=e[i++];continue}let r=i+1,o="",a=!1;for(;r<e.length&&(a||e[r]!==s);)a=!a&&"\\"===e[r],o+=e[r++];const l=te(t.size);t.set(l,s+o+s),n+=l,i=r+1}return{text:n,strings:t}}(function(e){let t="";for(let n=0;n<e.length;n++){const i=e[n];if('"'===i||"`"===i){const i=ne(e,n);t+=e.slice(n,i+1),n=i}else if("'"===i)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(t[t.length-1]??""))t+="′";else{const i=ne(e,n);t+=e.slice(n,i+1),n=i}else t+=i}return t}(e));let s=n.replace(/\t/g," ");t.evaluate&&(s=function(e,t,n){let i=0;for(;;){const s=e.indexOf("{{",i);if(s<0)return e;const r=Ze(e,s);if(r<0)return e;let o=e.slice(s+2,r).trim();for(const[e,n]of t)o=o.split(e).join(n);try{let a=n(o);if(/^["'`]/.test(a)){const e=te(t.size);t.set(e,a),a=e}const l=e.slice(0,s).trimEnd(),c=e.slice(r+2).trimStart();/^[\d.]/.test(a)&&(/[\d.]$/.test(l)||/^[\d.]/.test(c))&&(a=`(${a})`),e=e.slice(0,s)+" "+a+" "+e.slice(r+2),i=0}catch{i=r+2}}}(s,i,t.evaluate));const r=[["strings",s]];for(const[e,t]of Ie){if(s=t(s),s.length>1e5)throw new Error("The expression expands too much when read");r.push([e,s])}return{cleaned:s,stringMap:i,steps:r}}function Ze(e,t){let n=0;for(let i=t+2;i<e.length;i++){if(e.startsWith("}}",i)&&0===n)return i;"{"===e[i]?n++:"}"===e[i]&&n--}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,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==Fe(n)}function De(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":We(e)?null:e.op}const Ue=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),Be=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!Ue.has(e.op))&&function(e,t,n){if("mod"===e&&t)return c(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const i=c(e),s=c(t);if(!i||!s)return!1;if(s!==i)return s<i;const r=a(e).assoc;return"left"===r?"right"===n:"right"===r&&"left"===n}(e.op,De(t),n);function He(e,t){const n=De(t),i=n&&a(n)?.prec;return!!i&&("!"===e?i<=a("!").prec:"\\not"===e?i<a("\\not").prec:i<70||Ke(t)||"\\not"===n)}function Ge(e,t,n={}){const i=n.left?"bracket":Ye(e),s=n.right?"bracket":Ve(t);return"digit"!==s&&"sign"!==s&&"word"!==i&&"word"!==s&&"other"!==i&&("frac"!==s||"digit"!==i&&"frac"!==i)}function Xe(e){return 1===e.length||Boolean(Pe[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function Qe(e){return"op"===e.type&&!a(e.op)?.group&&(a(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&&Xe(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||We(e)?"sign":"/"===t?"frac":a(t)?.group||Qe(e)?"bracket":Je(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?Qe(e.args[0])?"bracket":Ve(e.args[0]):["*","sum","prod","perm"].includes(t)?Ve(e.args[0]):"other"}function Ye(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&Xe(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||Qe(e)||Je(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?Ye(e.args[e.args.length-1]):"other"}function Je(e){if("op"!==e.type)return!1;const t=a(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=a(e.op);return"infix"===t?.fixity&&!Be(e,e.args[0],"left")&&Ke(e.args[0])}const et=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),tt=e=>e.slice(2);function nt(e){const t=e.args[1];let n=0,i=e;for(;"op"===i.type&&"der"===i.op&&it(i.args[1],t);)n++,i=i.args[0];return{n:n,body:i,by:t,variable:"symbol"===i.type&&Xe(i.value)}}const it=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type;for(const e of[Pe])Object.setPrototypeOf(e,null);const st={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function rt(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(st,e.op))return e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args:[e]);if("[]"!==e.op||!e.args.length||!e.args.every(e=>"op"===e.type&&"[]"===e.op))return null;const t=e.args[0].args.length;return!t||!e.args.every(e=>e.args.length===t)||e.args.length<2&&t<2?null:e.args.map(e=>e.args)}const 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","unchanged","deg","mod","pmod","NaN","Infinity"]),ut=/^[a-zA-ZͰ-Ͽ]$/,pt=new Set(["f","g","h","u","v","F","G","H"]),mt=e=>ot.includes(e)||at.includes(e),dt=[...ot,...at,...lt].sort((e,t)=>t.length-e.length),ft=[...ot,...at,"pi"].sort((e,t)=>t.length-e.length);function gt(e,t=dt){const n=[];let i=0;for(;i<e.length;){const s=t.find(t=>e.startsWith(t,i))??e[i];n.push(s),i+=s.length}return n}function bt(e){if(mt(e))return!0;const t=gt(e,ft);return t.length>1&&mt(t[t.length-1])&&!ht.has(e)}function xt(e,{mode:t="plain",followed:n=!0}={}){if(e.includes("′")&&/^[a-zA-Z′]+$/.test(e)&&!/^.′+$/.test(e))return e.match(/[a-zA-Z]′*/g);if(!((i=e).length>0&&[...i].every(e=>ut.test(e)))||1===e.length||ht.has(e)||mt(e))return[e];var i;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return $t(gt(e),n);if(e.length<=2)return[...e];const s=$t(gt(e,ft),n),r=s.findIndex(e=>e.length>1);if(r<0)return[e];if("pi"===s[r]&&!s.some(e=>ot.includes(e)))return 3===e.length?s:[e];const o=r;let a=0,l=0;for(const e of s.slice(r))a=1===e.length?a+1:0,l=Math.max(l,a);return o<=1&&l<=2?s:[e]}function $t(e,t){const n=e[e.length-1];return t||!ot.includes(n)?e:[...e.slice(0,-1),...n]}const yt="§",vt=/[A-Za-zͰ-Ͽ′]/,wt=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 n=[];let i="";const s=e=>{i&&(wt(i)?n.push(...function(e,t,n){if((e=>new RegExp(`^${K}[${ee}]+$`).test(e))(e))return[e];if(d.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 n=xt(e,{mode:t,followed:!0});return n.length>1?n:e.length<=2?[...e]:[r+e]}(e,n);const i=void 0!==t&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(t);return xt(e,{mode:n,followed:i})}(i,e,t)):n.push(i),i="")};for(let t=0;t<e.length;t++){const o=e[t];if(o===yt){s(o);const i=e.indexOf(yt,t+1),a=e.slice(t,i+1);n.push(d.includes(e[i+1])?r+a:a),t=i;continue}if(wt(i)&&/[0-9]/.test(o)&&p(i+o)){const{op:s,end:r}=_t(e,t,i+o);n.push(s),i="",t=r;continue}if(vt.test(o)&&"′"!==o&&g(i)&&(n.push(i),i=""),vt.test(o)&&(""===i?"′"!==o:wt(i)))i+=o;else if(/[0-9]/.test(o)&&wt(i)&&!bt(i))i+=o;else if(wt(i)&&s(" "===o?e[t+1]:o),"(){}[]".includes(o))i&&n.push(...Et(i,o)),i="",n.push(o);else if("_"!==o&&" "!==o){if(p(i+o)){const{op:s,end:r}=_t(e,t,i+o);n.push(s),i="",t=r;continue}if(p(o)){s(o);const{op:i,end:r}=_t(e,t,o);n.push(i),t=r;continue}i+=o}else s(e[t+1]),"_"===o&&n.push("_")}if(s(void 0),n.some(e=>/^:/.test(e)))throw new Error("Unmatched ':'");return n}function _t(e,t,n){let i=t;for(;i+1<e.length&&p(n+e[i+1]);)n+=e[i+1],i++;return"!"===n&&"_"===e[i+1]&&i++,{op:n,end:i}}function Et(e,t){if(!d.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[p(t)?t:r+t]}return g(e)?[e,"*"]:p(e)||mt(e)||g(e[0])?[e]:[r+e]}const Mt=70,At=100,Ot="%mod",qt=e=>d.includes(e),Nt=e=>f.includes(e),Lt=e=>o(e)||u[e]===At&&"_"!==e,St=new Set(["\\comb","\\perm","comb","perm"]),Ct={frac:"/","\\binom":"\\binom"},Tt={"\\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 n=this.peek();if(void 0===n||Nt(n))return;const i=this.operatorAt(n,t);if(!i||i.lbp<=e)return;i.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===Ot)return{lbp:Mt,run:()=>{this.next(),this.parseExpression(Mt),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:At,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(St.has(e))return{lbp:At,run:()=>{this.next(),this.parseExpression(At),this.emit(e)}};const n=u[e];if(void 0!==n&&!Lt(e)&&"\\not"!==e&&!(e in Ct)){const t=m.has(e)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:t&&!Lt(e)?71:Mt,run:()=>{this.parseExpression(Mt),this.emit("*")}}}startsOperand(e){return void 0===e||Nt(e)||"|"===e?"|"===e:e!==Ot&&(!!(qt(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(Mt,!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],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(qt(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Nt(n))||qt(t)&&Nt(n)?this.emit("\\"+e):"+"===e?this.parseExpression(75):this.negate()}if("±"===e)return this.parseExpression(75),this.emit("pm");if("!"===e||"\\not"===e)return this.parseExpression(85),this.emit("\\not");if(e in Ct)return this.parseScript(),this.parseScript(),this.emit(Ct[e]);if("log"===e)return this.logarithm();if("lim"===e&&"_"===n)return this.limit();if(("\\sumidx"===e||"\\prodidx"===e)&&"_"===n)return this.bigOperator(e);if(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||!g(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:n}=this.frames.pop(),i=this.peek();Nt(i)&&(this.next(),n?this.emit(e+i):t&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const e=this.peek();if(qt(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 n=this.out.splice(t);"^"===this.peek()&&(this.next(),this.parseScript(),n=[...n,...this.out.splice(t),","]),this.parseExpression(u["+"],!0),this.emit(...n,",","()",e)}functionCall(e){if(void 0===this.peek())return this.emit(e);let t=null;if("^"===this.peek()){this.next();const e=this.out.length;this.parseScript(),t=this.out.splice(e)}if(0===a(e)?.arity&&!qt(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(qt(e))return this.next(),this.bracket(e);this.parseExpression(Mt,!0)}}function Rt(e,t){e=function(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n],s=e=>"string"==typeof e&&/^[a-zA-Z]$/.test(e);if(pt.has(i)&&"^ { - 1 } ("===e.slice(n+1,n+7).join(" ")){t.push(r+i+"⁻¹"),n+=5;continue}const[o,a,l]=e.slice(n+1,n+4),c=s(a)?a!==i:g(a);s(i)&&"e"!==i&&"("===o&&c&&")"===l?t.push(r+i):t.push(i)}return t}(e);const n=[];for(const i of e)p(i)||qt(i)||Nt(i)||"_"===i||o(i)||g(i)?n.push(i):n.push(...It(i,t));return n}function It(e,t){const n=e=>Rt(kt(e,t),t);let i=0;for(;i<e.length&&g(e.slice(0,i+1));)i++;if(0===i){if("%"===e[0])return[Ot,...n(e.slice(1))];const i=e.indexOf("%");return i>0&&i<e.length-1?[...It(e.slice(0,i),t),Ot,...n(e.slice(i+1))]:[e]}const s=e.slice(i);return"%"===s[0]?1===s.length?[e]:[e.slice(0,i),Ot,...n(s.slice(1))]:[e.slice(0,i),...n(s)]}for(const e of[Ct,Tt])Object.setPrototypeOf(e,null);const jt=new Set(["()","[]","{}","(]","[)"]),Zt={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠="},Pt=new Set(["round","fixed","der"]),Ft=e=>o(e)||100===u[e];function Wt(e){const n=[],i=e=>{if(!n.length)throw new Error(`'${e}' is missing an operand`);return n.pop()},s=e=>e.list?e.list:[e],r=(e,t)=>{if(e.list)throw new Error(`A list of values needs brackets around it (near '${t}')`);return e};if(e.forEach((l,c)=>{if("∅"===l)return void n.push({list:[]});if(","===l){const e=i(l),t=i(l);return void n.push({list:[...s(t),...s(e)]})}if(jt.has(l)){const t=s(i(l));if(!t.length&&!Ft(e[c+1]))throw new Error("Empty brackets");return void n.push($(l,t))}const h=Zt[l]??l,u=a(h);if(!u){if("?"===l||"abs("===l)throw new Error(`Unmatched '${l[0]}'`);return void n.push(v(l))}let p;if(Ft(l)&&jt.has(e[c-1])&&n[n.length-1]?.op===e[c-1])p=n.pop().args;else{let e=u.arity===t||Pt.has(h)?1:u.arity;if(n.length<e)throw new Error(`'${l}' needs ${e} operand${1===e?"":"s"}`);p=n.splice(n.length-e,e).map(e=>r(e,l))}n.push(function(e,n){switch(e){case"sqrt":if(2===n.length)return $("root",n);break;case"round":if(1===n.length)return $("round",[n[0],b(0)]);break;case"sum":case"prod":{const t=n[1];if("op"===t?.type&&"symbol"===t.args[0]?.type&&(3===n.length&&"="===t.op||2===n.length&&"∈"===t.op))return $("sum"===e?"\\sumidx":"\\prodidx",n);break}case"det":if(n.length>1&&n.every(e=>"op"===e.type&&"[]"===e.op))return $("det",[$("[]",n)]);break;case"fixed":if(1===n.length)return $("fixed",[n[0],b(2)]);break;case"der":if(1===n.length)return $("der",[n[0],x("x")]);if(3===n.length)return function([e,t,n]){const i="number"===n.type?Number(n.value):NaN;if(!Number.isInteger(i)||i<1||i>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");let s=e;for(let e=0;e<i;e++)s=$("der",[s,t]);return s}(n);break;case"log":if("symbol"===n[0].type&&"e"===n[0].value)return $("ln",[n[1]]);break;case"lim":return $("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?{"\\+":"r","\\-":"l"}[e.args[1].value]:void 0,[n,i,s]=e;if(2===e.length&&"op"===i.type&&"→"===i.op&&t(i.args[1])){const[e,s]=i.args;return[n,e,s.args[0],x(t(s))]}return 3===e.length&&t(s)?[n,i,s.args[0],x(t(s))]:e}(n));case"\\:if":if(2===n.length||3===n.length)return $("?:",[n[0],n[1],n[2]??x("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return function(e,n){const{arity:i}=a(e);if(i===t){if(0===n.length&&!o(e))throw new Error(`'${e}' needs at least one argument`);return}if(n.length!==i){throw new Error(`'${e}' takes ${i} argument${1===i?"":"s"}, not ${n.length}`)}}(e,n),$(e,n)}(h,p))}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return r(n[0],"end")}for(const e of[Zt])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}"),n=t<0?-1:e.indexOf("\\end{cases}",t);if(n<0)return e;const i=T(e.slice(t+13,n),"\\\\").map(e=>T(e,"&")).filter(e=>e.join("").trim());let s=null;for(let e=i.length-1;e>=0;e--){const t=i[e][0].trim(),n=C(i[e].slice(1).join("&"));s=null!==s||n?`((${n||"true"}) ? (${t}) : ${s??"(unchanged)"})`:`(${t})`}e=e.slice(0,t)+(s??"")+e.slice(n+11)}return e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):e}function Ht(e,t={}){const n={original:e};try{if("string"!=typeof e)throw new Error("Expression must be a string");const i=t.maxLength??5e3;if(e.length>i)throw new Error(`Longer than ${i} characters (options.maxLength)`);const s=/^\s*=(?!=)/.test(e);s&&(e=e.replace(/("(?:[^"]|"")*")|\$(?=[A-Za-z]{0,3}\d|[A-Za-z]{1,3}\$?\d)/g,(e,t)=>t??""));const r=s?[...new Set(e.replace(/"(?:[^"]|"")*"/g,"").match(/(?<![\w.])[A-Za-z]{1,3}\d+(?::[A-Za-z]{1,3}\d+)?(?![\w.(])/g)??[])]:[],{text:o,protectedNames:a}=function(e,t=[],n=[]){const i=new Map,s=e=>{const t=`${yt}${i.size}${yt}`;return i.set(t,e),t};e=e.replace(Dt,(e,t)=>Ut(t.trim())?` ${t.trim()}`:s(t.trim()));for(const n of[...t].sort((e,t)=>t.length-e.length)){const t=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${t}(?![A-Za-z0-9_])`,"g"),()=>s(n))}for(const t of[...n].sort((e,t)=>t.length-e.length)){const n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(e,n,i)=>s(t)+(i?" * (":n))}return{text:e,protectedNames:i}}(Bt(e),t.names,[...t.values??[],...r]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=((e,t={})=>{const n=void 0===t.blocks?null:t.blocks;return je(e,{evaluate:n?e=>n(e,t.scope):void 0})})(o,{blocks:t.blocks,scope:t.scope}),p=e=>ie(ie(e,h),a);n.mode=l,n.cleaned=p([c])[0],n.cleanSteps=u,n.tokens=kt(c,l),n.rawPostfix=p(function(e,t="plain"){return new zt(Rt(e,t)).parseAll().map(e=>Tt[e]??e)}(n.tokens,l));const m=_(Wt(n.rawPostfix));n.postfix=m,n.tree=k(m)}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function Gt(e,t={}){const n=Ht(e,t);if(n.error)throw new Error(`Failed to parse expression "${i=e,"string"==typeof i&&i.length>80?`${i.slice(0,77)}…`:i}": ${n.error}`);var i;return n.tree}const Xt=(e,t)=>"string"==typeof e?Gt(e,t):function(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")}(e),Qt={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",matrix:(e,t)=>`the ${e} by ${t} matrix`,row:e=>`row ${e}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},Vt={sin:"sine",cos:"cosine",tan:"tangent",csc:"cosecant",sec:"secant",cot:"cotangent",sinh:"hyperbolic sine",cosh:"hyperbolic cosine",tanh:"hyperbolic tangent",arcsin:"inverse sine",arccos:"inverse cosine",arctan:"inverse tangent",arcsinh:"inverse hyperbolic sine",arccosh:"inverse hyperbolic cosine",arctanh:"inverse hyperbolic tangent",ln:"the natural log",log:"log",loglog:"the log of the log",logloglog:"the log of the log of the log",expm1:"e to the power, minus 1, of",max:"the maximum",min:"the minimum",gcd:"the greatest common divisor",mean:"the mean",det:"the determinant",atan2:"the arctangent",round:"round",fixed:"fixed",random:"random"},Yt=Object.fromEntries(Object.entries(Pe).map(([e,t])=>[t,e]));function Jt(e,t={}){return Kt(function(e,t={}){return function(e,t,n){const i=new nn({...Qt,...t.words},{...Vt,...t.names},t.say||{},n);return function(e){let t=e.length;for(;t>0&&(e[t-1].close||!e[t-1].text.replace(/,/g,"").trim());)t--;const n=[];for(const{text:i,id:s}of e.slice(0,t)){const e=i.trim();if(!e)continue;const t=e.startsWith(","),r=t?e.slice(1).trim():e;t&&n.length&&!n[n.length-1].text.endsWith(",")&&(n[n.length-1].text+=","),r&&n.push({text:r,id:s})}n.length&&(n[n.length-1].text=n[n.length-1].text.replace(/,$/,""));return n}(i.speak(e))}(e,t,!0)}(e,t))}function Kt(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const en={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},tn={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class nn{constructor(e,t,n,i=!1){this.w=e,this.names=t,this.say=n,this.audio=i}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=>Kt(this.speak(e))):[e.value],e,e=>Kt(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(tn[e])return t[tn[e]];if(Yt[e])return Yt[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=c(e.op);return void 0!==t&&t<=50&&!a(e.op).group}quantity(e,t="endQuantity"){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[i,s]=n,r=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(r.comma),...this.speak(e)]:this.speak(e));if(en[t])return[...this.speak(i),a(r[en[t]]),...this.speak(s)];if(o(t)){const e=this.symbol(tt(t));return n.length?[a(`${e} ${r.of}`),...this.arguments(n)]:[a(e)]}if(this.names[t]&&!["log","round","fixed","atan2","random","expm1"].includes(t))return[a(`${this.names[t]} ${r.of}`),...this.arguments(n)];switch(t){case"+":return We(s)?[...this.speak(i),a(r.minus),...this.speak(s.args[1])]:[...this.speak(i),a(r.plus),...this.speak(s)];case"-":return We(s)?[...this.speak(i),a(r.plus),...this.speak(s.args[1])]:[...this.speak(i),a(r.minus),...this.quantityIfSum(s)];case"*":return this.product(e);case"/":return this.fraction(e);case"^":return this.power(e);case"_":return[...this.speak(i),a(r.sub),...this.audio?this.quantity(s,"endSub"):this.speak(s)];case"neg":return this.isCompound(i)||"op"===i.type&&"neg"===i.op?[a(`${r.negative} ${r.quantity}`),...this.speak(i),...this.closer(i,"endQuantity")]:[a(r.negative),...this.speak(i)];case"pm":return[a(r.plusOrMinus),...this.speak(i)];case"!":return[...this.quantity(i),a(r.factorial)];case"\\not":return[a(r.not),...this.quantity(i)];case"sqrt":return[a(r.squareRoot),...this.contents(i,"endRoot")];case"root":{const e="number"===i.type?Number(i.value):NaN,t=3===e?r.cubeRoot:2===e?r.squareRoot:r.nthRoot(e?this.ordinal(e):Kt(this.speak(i))+"th");return[a(t),...this.contents(s,"endRoot")]}case"abs":return[a(r.absoluteValue),...this.contents(i,"endAbsoluteValue")];case"floor":return[a(r.floor),...this.contents(i,"endFloor")];case"ceil":return[a(r.ceiling),...this.contents(i,"endCeiling")];case"log":return"symbol"===i.type&&"e"===i.value?[a(`${this.names.ln} ${r.of}`),...this.argument(s)]:[a(`${r.logBase}`),...this.speak(i),a(r.of),...this.argument(s)];case"mod":return[...this.quantity(i),a(r.mod),...this.quantity(s)];case"pmod":return[...this.speak(i),a(`${r.comma} ${r.mod}`),...this.speak(s)];case"perm":return[...this.quantity(i),a(r.permute),...this.quantity(s)];case"comb":return[...this.quantity(i),a(r.choose),...this.quantity(s)];case"round":{const e=0===("number"===s.type?Number(s.value):NaN)?r.nearestWholeNumber:`${Kt(this.speak(s))} ${r.decimalPlaces}`;return[...this.speak(i),a(`${r.comma} ${r.rounded} ${e}`)]}case"fixed":return 0===("number"===s.type?Number(s.value):NaN)?[...this.speak(i),a(`${r.comma} ${r.asWholeNumber}`)]:[...this.speak(i),a(`${r.comma} ${r.writtenTo}`),...this.speak(s),a(r.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${r.of}`),...this.speak(i),a(r.over),...this.speak(s)];case"random":return[a(r.randomNumber)];case"expm1":return[a(r.eToThe),...this.speak(i),a(`${r.comma} ${r.minus} 1`)];case"?:":{const e=[a(r.if),...this.speak(i),a(`${r.comma} ${r.then}`),...this.speak(s)];return(e=>"symbol"===e.type&&"unchanged"===e.value)(n[2])?e:[...e,a(`${r.comma} ${r.otherwise}`),...this.speak(n[2])]}case"sum":return n.flatMap((e,t)=>t?[a(r.plus),...this.speak(e)]:this.speak(e));case"prod":return n.flatMap((e,t)=>t?[a(r.times),...this.quantity(e)]:this.quantity(e));case"mean":case"max":case"min":case"gcd":return[a(`${this.names[t]} ${r.of}`),...l()];case"()":return 2===n.length?[a(r.openInterval),...this.speak(i),a(r.to),...this.speak(s)]:l();case"pmatrix":case"bmatrix":return this.matrix(e);case"vmatrix":return[a(r.determinantOf),...this.matrix(e)];case"[]":return rt(e)?this.matrix(e):2===n.length?[a(r.closedInterval),...this.speak(i),a(r.to),...this.speak(s)]:[a(r.theList),...l()];case"(]":case"[)":return[a(r.halfOpenInterval),...this.speak(i),a(r.to),...this.speak(s)];case"{}":return[a(r.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,r.sumFrom,r.sumOver,r.sumOf,"endSum");case"\\prodidx":return this.bigOperator(e,r.productFrom,r.productOver,r.productOf,"endProduct")}throw new Error(`No speech for '${t}'`)}matrix(e){const t=this.w,n=rt(e),i=[this.seg(e,t.matrix(n.length,n[0].length))];return n.forEach((n,s)=>{const r=e.args[s];i.push(this.seg(e,t.comma),this.seg("op"===r.type&&"[]"===r.op?r:e,`${t.row(s+1)}:`)),n.forEach((n,s)=>i.push(...s?[this.seg(e,t.comma)]:[],...this.speak(n)))}),[...i,...this.closer(e,"endMatrix")]}arguments(e){return 1===e.length?this.argument(e[0]):e.flatMap((e,t)=>t?[{text:this.w.comma,id:e.id},...this.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,n]=e.args,i=this.w;if(We(e))return[this.seg(e,i.negative),...this.speak(n)];if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,i.degrees)];const s=this.quantity(t),r=this.quantity(n);return this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||r[0].text.startsWith("the ")?[...s,this.seg(e,i.times),...r]:[...s,...r]}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&&(o(e.op)||"prefix"===a(e.op)?.fixity&&100===c(e.op))}startsWithNumber(e){let t=e;for(;"op"===t.type&&t.args.length;)t=t.args[0];return"number"===t.type}fraction(e){const[t,n]=e.args,i=this.w,s=t=>this.seg(e,t);if("number"===t.type&&"number"===n.type&&/^[1-9]$/.test(t.value)&&/^([2-9]|10)$/.test(n.value)){const e=Number(t.value),r=Number(n.value),o=2===r?1===e?i.half:i.halves:i.ordinals[r]+(1===e?"":"s");return[s(`${i.numerators[e]} ${o}`)]}return[...this.quantity(t,null),...this.isCall(t)?[s(i.comma)]:[],s(i.over),...this.quantity(n,"endFraction")]}power(e){const[t,n]=e.args,i=this.w,s=t=>this.seg(e,t),r=this.isCompound(t)||this.isCall(t)||"number"===t.type&&t.value.startsWith("-")||"op"===t.type&&"/"===t.op||this.audio&&"op"===t.type&&"^"===t.op?[s(i.quantity),...this.speak(t),...this.closer(t,"endQuantity")]:this.speak(t);if(this.isCall(t)&&this.names[t.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===t.args.length){const e=2===Number(n.value)?i.squared:i.cubed;return[s(`${this.names[t.op]} ${e} ${i.of}`),...this.argument(t.args[0])]}if("number"===n.type&&/^(?:[1-9]|10)$/.test(n.value)){const e=Number(n.value);return 2===e||3===e?[...r,s(i.powers[e])]:[...r,s(`${i.toThe} ${i.powers[e]}`)]}if("number"===n.type&&/^\d+$/.test(n.value))return[...r,s(`${i.toThe} ${this.ordinal(Number(n.value))}`)];return!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))?[...r,s(i.toThe),...this.speak(n)]:this.audio?[...r,s(i.toThePowerOf),s(i.quantity),...this.speak(n),...this.closer(n,"endExponent")]:[...r,s(i.toThePowerOf),...this.speak(n),s(i.comma)]}ordinal(e){if(e<=10&&e>=1)return"squared"===this.w.powers[e]?"second":"cubed"===this.w.powers[e]?"third":this.w.powers[e];return`${e}${e%100>=11&&e%100<=13?"th":["th","st","nd","rd"][e%10]??"th"}`}derivative(e){const{n:t,body:n,by:i,variable:s}=nt(e),r=this.w,o=t=>this.seg(e,t);if(s){return[o(1===t?r.d:`${r.d} ${2===t?r.squared:3===t?r.cubed:`${r.toThe} ${this.ordinal(t)}`}`),...this.speak(n),o(r.d),...this.speak(i),o(1===t?"":2===t?r.squared:3===t?r.cubed:`${r.toThe} ${this.ordinal(t)}`)]}return[o(`${1===t?r.derivative:2===t?r.secondDerivative:r.nthDerivative(this.ordinal(t))} ${r.withRespectTo}`),...this.speak(i),o(r.of),...this.contents(n,"endDerivative")]}integral(e){const{args:t}=e,[n,i,s,r]=t,o=this.w,a=t=>this.seg(e,t),l=t.length>=2&&"symbol"===i.type&&1===i.value.length,c=l?this.speak(i):[a(M(n)||"x")];let h=[];4===t.length?h=[s,r]:3===t.length?h=l?[s]:[i,s]:2!==t.length||l||(h=[i]);return[...2===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.to),...this.speak(h[1]),a(o.of)]:1===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(e){const{args:t}=e,[n,i,s,r]=t,o=this.w,a=t=>this.seg(e,t);let l;if(t.length>=3){if(l=[...this.speak(i),a(o.approaches),...this.speak(s)],4===t.length){const e=String(r.value??"").toLowerCase().startsWith("r");l.push(a(e?o.fromTheRight:o.fromTheLeft))}}else if(2===t.length&&"op"===i.type&&"→"===i.op)l=[...this.speak(i.args[0]),a(o.approaches),...this.speak(i.args[1])];else{if(2!==t.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const e=M(n);l=e?[a(e),a(o.approaches),...this.speak(i)]:this.speak(i)}}return[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(e,t,n,i,s){const{args:r}=e,[o,a,l]=r,c=this.w,h=t=>this.seg(e,t);let u;return u=3===r.length?[h(t),...this.speak(a),h(c.to),...this.speak(l),h(c.of)]:2===r.length?[h(n),...this.speak(a),h(c.of)]:[h(i)],[...u,...this.contents(o,s)]}}for(const e of[Qt,Vt,en,tn,Yt])Object.setPrototypeOf(e,null);function sn(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":Jt(Xt(e),t)}const rn={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0.015"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function on(e,t,n=""){const i=rn[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${i.fill?`<path d="${i.fill}" fill="currentColor"/>`:`<path d="${i.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const an=.8,ln=.2,cn=.25,hn=.7,un="−",pn={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},mn={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},dn={"±":"±","∪":"∪","∩":"∩",mod:"mod"},fn=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],gn={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},bn=[...fn,...Object.keys(gn),"ln","det"],xn={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},$n={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},yn={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},vn={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},wn=["boxed","overline","bar","underline","cancel",...Object.keys(vn)],kn={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},_n=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),En=e=>+e.toFixed(3)+"em",Mn=(e,t=an,n=ln)=>({html:e,h:t,d:n});function An(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(an,...t.map(e=>e.h)),d:Math.max(ln,...t.map(e=>e.d))}}function On(e,t={}){const n=new qn({...kn,...t}),i=n.render(e,{level:0}),s=`${n.p}${n.o.display?` ${n.p}-display`:""}`,r="function"==typeof n.o.mathml?function(e,t,n,i){try{return String(e(t)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${i?' display="block"':""}>`)}catch{return""}}(n.o.mathml,e,n.p,n.o.display):"",o=r?null:function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):sn(e)}catch{return null}}(e,n.o.label),a=null!==o||r?i.html.replace(/^<span /,'<span aria-hidden="true" '):i.html;return{html:`<span class="${s}"${null===o?"":` role="math" aria-label="${_n(o)}"`}>${a}${r}</span>`,h:i.h,d:i.d}}class qn{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",i=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${i}>${t}</span>`}text(e,t){const n=Mn(this.el(e,_n(t)));return n.leaf={kind:e,content:_n(t)},n}bin(e){return this.text("bin",e)}rel(e){return this.text("rel",e)}punct(e){return this.text("punct",e)}word(e){return this.text("word",e)}wrap(e,t,n){let i="";void 0!==e.id&&(i+=` data-node="${e.id}"`),"op"===e.type&&(i+=` data-op="${_n(e.op)}"`);const s=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(s))"class"!==e&&"style"!==e&&(i+=` ${e}="${_n(t)}"`);const r=[s.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),o=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(s.class?[s.class]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${r?` style="${_n(r)}"`:""}${i}>${a}</span>`,h:n.h,d:n.d}}render(e,t){return"number"===e.type?this.number(e):"string"===e.type?this.wrap(e,["text"],this.text("text",e.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===e.type?this.wrap(e,["symbol"],this.symbol(e.value)):this.operation(e,t)}number(e){return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,un)))}symbol(e){return Pe[e]&&(e=Pe[e]),yn[e]?this.text("ord",yn[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)?Mn(this.el("var",_n(e[0]))+this.el("prime",_n(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?Mn(this.el("ord","Δ")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:n,args:i}=e,[s,r]=i,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1}),l=pn[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,n)=>Be(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(bn.includes(n)||"log"===n)return c(this.named(e,t));if(xn[n])return c(An(this.word(xn[n]),this.fence(this.list(i,t))));if(o(n))return c(this.custom(e,t));const u=rt(e);if(u)return c(this.matrix(e,u,t));if($n[n])return c(this.fence(this.list(i,t),...$n[n]));if(mn[n]&&2===i.length)return c(An(h(s,"left"),this.rel(mn[n]),h(r,"right")));if(dn[n]&&2===i.length)return c(An(h(s,"left"),this.bin(dn[n]),h(r,"right")));switch(n){case"+":return We(r)?c(An(h(s,"left"),this.bin(un),this.wrap(r,["op","op-mul"],this.render(r.args[1],t)))):"number"===r.type&&r.value.startsWith("-")?c(An(h(s,"left"),this.bin(un),this.wrap(r,["number"],this.text("num",r.value.slice(1))))):c(An(h(s,"left"),this.bin("+"),this.signed(r,h(r,"right"))));case"-":return c(An(h(s,"left"),this.bin(un),this.signed(r,h(r,"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(s,{forceParens:!0}),null,t,a(r,{level:t.level+1})));case"neg":return c(An(this.text("sign",un),He(n,s)?this.fence(a(s)):a(s,{before:t.before})));case"pm":return c(An(this.text("sign","±"),He(n,s)?this.fence(a(s)):a(s)));case"!":return c(An(He(n,s)?this.fence(a(s)):a(s,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(An(this.text("sign","¬"),He(n,s)?this.fence(a(s)):a(s)));case"pmod":return c(An(a(s),this.fence(An(this.word("mod"),this.text("space",""),a(r)))));case"sqrt":return c(this.radical(a(s)));case"root":return c(this.radical(a(r),this.render(s,{level:t.level+2})));case"abs":return c(this.fence(a(s),"|","|"));case"floor":return c(this.fence(a(s),"⌊","⌋"));case"ceil":return c(this.fence(a(s),"⌈","⌉"));case"loglog":return c(An(this.word("ln"),this.fence(An(this.word("ln"),this.fence(a(s))))));case"logloglog":return c(An(this.word("ln"),this.fence(An(this.word("ln"),this.fence(An(this.word("ln"),this.fence(a(s))))))));case"perm":return c(this.script(this.script(Mn(""),this.render(s,{level:t.level+1}),t),null,t,this.render(r,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(s),a(r),!1)));case"?:":return c(this.o.cases?this.cases(e,t):An(a(s),this.bin("?"),a(r),this.bin(":"),a(i[2])));case"sum":return c(An(i.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(An(i.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(i,t));case"lim":return c(this.limit(i,t));case"\\sumidx":return c(this.bigOperator("sum",i,t));case"\\prodidx":return c(this.bigOperator("prod",i,t))}throw new Error(`Inline Math cannot draw '${n}'`)}signed(e,t){return("number"===e.type?e.value.startsWith("-"):"neg"===e.op||"pm"===e.op)&&!t.fenced?this.fence(t):t}list(e,t){return An(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[n,i]=e.args;if(We(e))return An(this.text("sign",un),this.render(i,t));const s=function(e){const[t,n]=e.args;return{left:Be(e,t,"left")&&"/"!==t.op,right:Be(e,n,"right")&&"/"!==n.op}}(e),r=Ge(n,i,s),a=function(e){for(;"op"===e.type;){if(bn.includes(e.op)||"log"===e.op||xn[e.op]||o(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(i),l=s.left?this.fence(this.render(n,t)):this.render(n,{...t,before:r&&!a}),c=s.right?this.fence(this.render(i,t)):this.render(i,{...t,before:t.before});return An(l,r?Mn(this.el(a?"fnspace":"times","")):this.bin("·"),c)}named(e,t,n=null){const{op:i,args:s}=e,r="log"===i?s[1]:s[0];let o;o=gn[i]&&"power"===this.o.inverseTrig?this.script(this.word(gn[i]),this.text("num","−1"),t):this.word(i),n&&(o=this.script(o,n,t)),"log"===i&&(o=this.script(o,null,t,this.render(s[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&Nn(r),l=this.render(r,{...t,forceParens:!1,before:!1});return An(o,a?An(Mn(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=tt(e.op),i=e.args;if(wn.includes(n)&&1===i.length)return this.decorate(n,this.render(i[0],t));return An(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Mn(this.el("callgap","")),this.fence(this.list(i,t)))}decorate(e,t){switch(e){case"boxed":return Mn(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return Mn(this.el("cancel",t.html+on("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return Mn(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return Mn(this.el("over",t.html),t.h+.14,t.d);default:return Mn(this.el("accent",this.el("accent-mark",vn[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,i]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&Nn(n,!0)&&Nn(i,!0)){const e=e=>"op"!==e.type||Nn(e)?this.render(e,t):this.fence(this.render(e,t));return An(e(n),this.text("ord","/"),e(i))}const s=t.level>0||t.inFraction||!this.o.display?.8:1,r={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,r),this.render(i,r),!0,s)}stack(e,t,n=!0,i=1){const s=e=>1===i?e.html:this.el("scaled",e.html,`font-size:${En(i)}`),r=n?.06:0,o=cn+r/2+.1+Math.max(ln,i*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",s(e))+this.el("denom",s(t)),`vertical-align:${En(o)}`);return Mn(a,o+Math.max(an,i*e.h),Math.max(an,i*t.h)+Math.max(ln,i*t.d)+.1+r/2-cn)}power(e,t){const[n,i]=e.args,s={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1},r=()=>this.render(i,s);if(this.o.trigPowers&&fn.includes(n.op)&&Sn(i))return this.wrap(n,["op",`op-${n.op}`],this.named(n,t,r()));if("_"===n.op){const e=this.render(n.args[1],s);return this.wrap(n,["op","op-subscript"],this.script(this.render(n.args[0],{...t,forceParens:!0}),r(),t,e))}const o=Be(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||bn.includes(n.op)?this.fence(this.render(n,t)):this.render(n,{...t,forceParens:!0});return this.script(o,r(),t)}script(e,t,n,i=null,s=null){const r=n.level>0?.8:hn,o=s?An(e,s):e;let a=t?Math.max(.42,e.h-.38,r*t.d+.12):0,l=i?Math.max(.2,e.d-.05,r*i.h-.45):0;if(t&&i){const e=.1-(a-r*t.d-(r*i.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${En(r)}`);if(t&&!i)return Mn(e.html+this.el("sup",t.html,`font-size:${En(r)};vertical-align:${En(a/r)}`),Math.max(o.h,a+r*t.h),Math.max(o.d,r*t.d-a));if(i&&!t)return Mn(o.html+this.el("sub",i.html,`font-size:${En(r)};vertical-align:${En(-l/r)}`),Math.max(o.h,r*i.h-l),Math.max(o.d,l+r*i.d));const h=a+r*t.h,u=l+r*i.d,p=this.el("subsup",c(t)+c(i),`vertical-align:${En(a)};height:${En(h+u)}`);return Mn(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,an)+.1+.06,i=Math.max(e.d,ln),s=n+i,r=on("sqrt",`${this.p}-hook`,`height:${En(s)};width:${En(.5+.06*(s-1))};vertical-align:${En(-i)}`);let o="";if(t){const e=.8*hn;o=this.el("rootindex",t.html,`font-size:${En(e)};vertical-align:${En((.55*s-i)/e)}`)}return Mn(this.el("sqrt",o+r+this.el("radicand",e.html)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,an)+Math.max(e.d,ln),s=i>1.25,r=s?.1:0,o=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const r=n+(s?Math.min(.2,.05*(i-1)):0);return{html:on(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${En(r)}`),w:r+.1}}const r={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${r} delim-${t}`,""),w:"|"===e?.18:.3}},a=o(t,"l"),l=o(n,"r"),c=`padding:${En(r)} ${En(l.w)} ${En(r)} ${En(a.w)}`,h=Mn(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,an)+r,Math.max(e.d,ln)+r);return h.fenced=!0,h}derivative(e,t){const{n:n,body:i,by:s,variable:r}=nt(e),o={...t,level:t.level+1},a=()=>this.text("d","d"),l=()=>n>1?this.render({type:"number",value:String(n)},o):null,h={...t,inFraction:!0},u=An(a(),l()?this.script(this.render(s,h),l(),h):this.render(s,h)),p=e=>An(l()?this.script(a(),l(),h):a(),e||[]),m=t.level>0||t.inFraction||!this.o.display?.8:1;if(r)return this.stack(p(this.render(i,h)),u,!0,m);const d=De(i)&&c(De(i))<100,[f,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=d?this.fence(this.render(i,t),f,g):this.render(i,t);return An(this.stack(p(),u,!0,m),b)}integral(e,t){const[n,i,s,r]=e,o=e=>this.render(e,t),a=e=>e?this.render(e,{...t,level:t.level+1}):null,l=()=>this.text("var",M(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:et(i)?c=o(i):(c=l(),h=a(i));break;case 3:et(i)?(c=o(i),h=a(s)):(c=l(),h=a(i),u=a(s));break;default:c=o(i),h=a(s),u=a(r)}const p=o(n),m=Mn(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return An(this.bigSign("int",p,h,u,t),p,m)}bigSign(e,t,n,i,s){const r=!this.o.display||s.level>0,o=Math.max(r?.6:.95,Math.max(t.h-cn,t.d+cn)+.12),a=on(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${En(2*o)};width:${En(r?.38:.5)};vertical-align:${En(cn-o)}`);if(!n&&!i)return Mn(a,cn+o,o-cn);const l=hn,c=i||Mn(""),h=n||Mn(""),u=cn+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${En(l)}`)+this.el("script lower",h.html,`font-size:${En(l)}`),`vertical-align:${En(u)};height:${En(2*o)}`);return Mn(a+p,cn+o,o-cn)}limit(e,t){const[n,i,s,r]=e,o={...t,level:t.level+1},a=e=>this.render(e,o),l=()=>this.rel("→");let c;switch(e.length){case 1:return An(this.word("lim"),Mn(this.el("fnspace","")),this.render(n,t));case 2:{const e=M(n),t="number"===i.type||"symbol"===i.type&&i.value.includes("∞");c=e&&t?An(this.text("var",e),l(),a(i)):a(i);break}case 3:c=An(a(i),l(),a(s));break;default:{const e=Fe(r).toLowerCase().startsWith("r")?"+":un;c=An(a(i),l(),this.script(a(s),this.wrap(r,["symbol"],this.text("ord",e)),o))}}return An(this.under(this.word("lim"),c,t),this.render(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):Mn(this.el("under",e.html+this.el("script",t.html,`font-size:${En(.7)}`)),e.h,Math.max(e.d,ln)+.05+.7*(t.h+t.d))}bigOperator(e,t,n){const[i,s,r]=t,o={...n,level:n.level+1},a=s?this.render(s,o):null,l=r?this.render(r,o):null,c=this.render(i,n);if(!this.o.display||n.level>0){const t=.55,i=on(e,`${this.p}-bigsign`,`height:${En(2*t)};width:${En(.8)};vertical-align:${En(cn-t)}`);return An(this.script(Mn(i,cn+t,t-cn),l,n,a),c)}const h=.68,u=hn,p=on(e,`${this.p}-bigsign`,`height:${En(1.36)};width:${En("sum"===e?1:1.05)}`),m=l?1.01+u*l.d:cn-h,d=e=>this.el("script",e.html,`font-size:${En(u)}`),f=this.el("bigop",(l?d(l):"")+p+(a?d(a):""),`vertical-align:${En(m)}`);return An(Mn(f,.93+(l?.08+u*(l.h+l.d):0),h-cn+(a?.08+u*(a.h+a.d):0)),c)}matrix(e,t,n){const i=t.map(e=>e.map(e=>this.render(e,n))),s=i.map(e=>({h:Math.max(an,...e.map(e=>e.h)),d:Math.max(ln,...e.map(e=>e.d))})),r=s.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=cn+r/2-s[0].h,a=i.map((t,n)=>{const i=t.map(e=>this.el("matrix-cell",e.html)).join(""),s=e.args[n];return s&&"op"===s.type&&"[]"===s.op?this.wrap(s,["op","op-list","matrix-row"],Mn(i)).html:i}).join(""),l=t[0].length,c=Mn(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${En(o)}`),cn+r/2,r/2-cn),[h,u]=st[e.op]??["[","]"];return this.fence(c,h,u)}cases(e,t){const n=[];let i=e;for(;"op"===i.type&&"?:"===i.op;)n.push([this.render(i.args[1],t),An(this.word("if"),this.text("space",""),this.render(i.args[0],t))]),i=i.args[2];"symbol"===i.type&&"unchanged"===i.value||n.push([this.render(i,t),this.word("otherwise")]);const s=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),r=s.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),o=cn+r/2-s[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=Mn(this.el("cases",a,`vertical-align:${En(o)}`),cn+r/2,r/2-cn);return this.fence(l,"{","")}}function Nn(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||rt(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!We(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Ln(e)||"*"===e.op&&Nn(e,t)):Nn(e.args[0],!0)&&("neg"===e.op||Nn(e.args[1],!0)))}const Ln=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(Pe[e.value])),Sn=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const Cn=e=>_(e).join(" ");function Tn(e,t){const n=new Set;zn(e,t,n);const i=[];return E(e,e=>{n.has(e)&&i.push(e)}),i}function zn(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>zn(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const i=Cn(Gt(t));return void E(e,e=>{Cn(e)===i&&n.add(e)})}if(t.path){const i=function(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}(e,t.path);return void(i&&n.add(i))}if(t.type){const i=Cn(t);E(e,e=>{e!==t&&Cn(e)!==i||n.add(e)})}}else E(e,(e,i)=>{t(e,i)&&n.add(e)});else E(e,e=>{e.id===t&&n.add(e)})}function Rn(e){let n=0;const i=e=>{"op"===e.type&&(e.args.forEach(i),a(e.op)?.arity===t&&n++),e.id=n++};return i(e),e}function In(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Gt(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return k(e);if(e&&"object"==typeof e&&e.type)return void 0===e.id?Rn(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function jn(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var Zn='/*\n * Inline Math stylesheet. Everything is under .mv; colours are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight colour\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }\n.mv-matrix-row { display: contents; }\n.mv-matrix-cell { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; border-top: 0.06em solid currentColor; padding-top: 0.08em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; position: relative; }\n.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n/* Windows high contrast (and other forced colours) drops backgrounds and shadows: outline a highlight instead */\n@media (forced-colors: active) {\n .mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }\n}\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the box editing a part in place (view.editable, or a Markdown textbox variable) */\n.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;\n border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }\n.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }\n/* the live region a view announces steps through ({ announce: true }): read, never seen */\n.mv-sr-only, .mv-sr-math { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */\n.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }\n.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }\n/* while a part is ringed, the whole expression\'s ring steps back so the part is the one that stands out */\n.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }\n@media (forced-colors: active) {\n .mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }\n}\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with maths (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */\n.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }\n.mv-md-assign { margin: 0 0.1em; }\n.mv-md-input { font: inherit; font-size: 0.9em; }\ninput.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }\ninput.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }\ninput.mv-md-slider { vertical-align: middle; }\n.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }\n';const Pn=Zn;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Zn,document.head.append(e)}return e.CSS=Pn,e.DEFAULTS=kn,e.layout=On,e.numberTree=Rn,e.select=Tn,e.toHTML=function(e,t={}){const n=In(e,t);return On(n,function(e,t){const{colors:n,highlight:i,scope:s,blocks:r,...o}=t,a=new Map;for(const[t,i]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(jn(i))for(const n of Tn(e,t))a.set(n,`color:${i}`);const l=new Set(void 0===i?[]:Tn(e,i));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}}}(n,t)).html},e.treeOf=In,e}({});
|