@mathzetta/inlinemath 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- /* Inline Math 0.3.0 — MIT license; 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="",p="",m={[u]:"dot",[p]:"cross"},d="",f={ln:h,log:h,loglog:h,logloglog:h,sqrt:h,sqrtpow:h,pow:h,expm1:h,der:h,lim:h,int:h,round:h,fixed:h,floor:h,ceil:h,abs:h,random:h,sum:h,prod:h,"\\sumidx":h,"\\prodidx":h,perm:h,comb:h,"\\perm":h,"\\comb":h,"\\binom":h,max:h,min:h,gcd:h,mean:h,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,[u]:70,[p]:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"?:":10,"?":9,",":5},g=e=>Object.prototype.hasOwnProperty.call(f,e),b=new Set(["^","?:","?","log"]),$=["(","{","["],x=[")","}","]"];function y(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[f])Object.setPrototypeOf(e,null);const v=e=>({type:"number",value:String(e)}),w=e=>({type:"symbol",value:e}),k=(e,t)=>({type:"op",op:e,args:t}),E=['"',"'","`"];function M(e){return y(e,!0)?v(e):E.includes(e[0])?{type:"string",value:e}:w(e)}const A={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function _(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],i=[];if(e.forEach((e,s)=>{const r=A[e]??String(e),l=a(r);if(!l)return n.push({...M(r),id:s}),void i.push(1);let c=l.arity;if(c===t){const e=n.pop();if(i.pop(),c=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(c)||c<0)throw new Error(`'${r}' takes a variable number of arguments, so it must follow a count`);if(0===c&&!l.group&&!o(r))throw new Error(`'${r}' needs at least one argument`)}if(n.length<c)throw new Error(`'${r}' needs ${c} operand${1===c?"":"s"}`);const h=1+Math.max(0,...i.splice(i.length-c,c));if(h>1e3)throw new Error("Nested too deeply (more than 1000 levels)");i.push(h),n.push({...k(r,n.splice(n.length-c,c)),id:s})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function O(e,n){const i=[];return function e(s){"op"===s.type?(s.args.forEach(e),a(s.op)?.arity===t&&i.push(String(s.args.length)),n&&s.written&&(n[i.length]=s.written),i.push(s.op)):i.push(s.value)}(e),i}function q(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>q(n,t,e))}function N(e){let t="";return q(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[A])Object.setPrototypeOf(e,null);function S(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 L(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=z(n,e,s);r?(i+=t.get(e.slice(s,s+r)),s+=r):i+=e[s++]}return i}}function z(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 L(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),C(e)]);return t.delete(e),t}function C(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 T=[["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\cfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\%","%"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot",u],["\\times",p],["×",p],["·",u],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],...["","\\"].flatMap(e=>["(","{"].flatMap(t=>[2,3,4,5,6,7,8,9,10].map(n=>[`${e}log${n}${t}`,`log_{${n}}${t}`]))),["\\log_10","log_{10}"],["log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left.",d],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⅕","(1/5)"],["⅖","(2/5)"],["⅗","(3/5)"],["⅘","(4/5)"],["⅙","(1/6)"],["⅚","(5/6)"],["⅐","(1/7)"],["⅑","(1/9)"],["⅒","(1/10)"],["⊕"," \\xor "],["∞","∞"],["⋅",u],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0]];const I=e=>" "===e||"\t"===e||"\n"===e,R="({[",j=")}]";const Z={__proto__:null},F={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((e,t)=>{Z[e]=String(t)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((e,t)=>{F[e]=String(t)}),Object.assign(Z,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g","ʰ":"h","ⁱ":"i","ʲ":"j","ᵏ":"k","ˡ":"l","ᵐ":"m","ⁿ":"n","ᵒ":"o","ᵖ":"p","ʳ":"r","ˢ":"s","ᵗ":"t","ᵘ":"u","ᵛ":"v","ʷ":"w","ˣ":"x","ʸ":"y","ᶻ":"z"}),Object.assign(F,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const P=new RegExp(`[${Object.keys(Z).join("")}]+|[${Object.keys(F).join("")}]+`,"g");const W={__proto__:null,"½":"1/2","⅓":"1/3","⅔":"2/3","¼":"1/4","¾":"3/4","⅕":"1/5","⅖":"2/5","⅗":"3/5","⅘":"4/5","⅙":"1/6","⅚":"5/6","⅐":"1/7","⅛":"1/8","⅜":"3/8","⅝":"5/8","⅞":"7/8","⅑":"1/9","⅒":"1/10"},D=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys(W).join("")}])`,"g"),U=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,B=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function H(e){const t=e.replace(/^\s*(?:\\(?:text|textrm|mathrm)\s*\{\s*(?:if|for|when|where)\s*\}|\b(?:if|for|when|where)\b)\s*,?/,"").replace(/[\s,.;]+$/,"").trim();return/^(?:\\(?:text|textrm|mathrm)\s*\{\s*)?(?:otherwise|else)\s*\}?$/.test(t)?"":t}function G(e,t){const n=[];let i=0,s=0;for(let r=0;r<e.length;r++)R.includes(e[r])?i++:j.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 Q(e,t,n){let i=0;const s=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(R.includes(e[n]))i++;else if(j.includes(e[n])){if(--i<0)return-1}else if(0===i&&(s.lastIndex=n,s.test(e)))return n;return-1}function X(e,t){let n=0;for(let i=t;i<e.length;i++)if(R.includes(e[i]))n++;else if(j.includes(e[i])&&--n<0)return i;return e.length}function V(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 Y(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(R.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&&o>0&&(e=e.slice(0,t+1)+"_{"+r+"}("+s+")"+e.slice(o+1))}return e}function J(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 K(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 ee=new Set(["pmatrix","bmatrix","vmatrix"]);function te(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 ee.has(i)?i+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function ne(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 ie(e){const{lower:t,upper:n,next:i}=function(e){let t="",n="",i=0;return"_"===e[0]&&([t,i]=ne(e,0),"^"===e[i]&&([n,i]=ne(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(R.includes(e[n]))t++;else if(j.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).trim()?r(o):"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function se(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(j.includes(n[e])?i--:R.includes(n[e])&&i++,0===i)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function re(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const oe=/[A-Za-z\u0370-\u03FF]/;function ae(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 le(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function ce(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 he(e,t){if(R.includes(e[t])){let n=0;for(let i=t;i<e.length;i++)if(R.includes(e[i]))n++;else if(j.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(R.includes(e[i]))n++;else{if(j.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 ue=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const pe="strtktk",me="ABCDEFGHIJ",de=e=>pe+[...String(e)].map(e=>me[e]).join(""),fe=new RegExp(`^${pe}[${me}]+$`);function ge(e){let t="";for(let n=0;n<e.length;n++){const i=e[n];if('"'===i||"`"===i){const i=be(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=be(e,n);t+=e.slice(n,i+1),n=i}else t+=i}return t}function be(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}const $e=new RegExp(`${pe}[${me}]+|§\\d+§`,"g");function xe(e,t){return t&&0!==t.size?e.map(e=>"string"!=typeof e?e:e.replace($e,e=>{const n=t.get(e);if(void 0!==n)return n;for(let n=e.length-1;n>7;n--){const i=t.get(e.slice(0,n));if(void 0!==i)return i+e.slice(n)}return e})):e}const ye={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))"};for(const e of[ye])Object.setPrototypeOf(e,null);const ve="([{",we=")]}";function ke(e,t){let n=0;for(let i=t;i<e.length;i++)if(ve.includes(e[i]))n++;else if(we.includes(e[i])&&0===--n)return i;return-1}function Ee(e){if(!e.trim())return[];const t=[];let n=0,i=0;for(let s=0;s<e.length;s++)ve.includes(e[s])?n++:we.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 Me(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=ke(e,r);if(o<0)continue;const a=n(Ee(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 Ae=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),_e=e=>`(${e})`,Oe=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const qe={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(_e).join(" & ")})`,OR:e=>e.length&&`(${e.map(_e).join(" ∨ ")})`,NOT:e=>1===e.length&&`(!(${e[0]}))`,XOR:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,LOG:e=>2===e.length?`log_{${e[1]}}(${e[0]})`:1===e.length&&`log_{10}(${e[0]})`,ATAN2:e=>2===e.length&&`atan2(${e[1]}, ${e[0]})`,INT:e=>1===e.length&&`floor(${e[0]})`,FIXED:e=>(1===e.length||2===e.length)&&`fixed(${e[0]}, ${e[1]??2})`,"FLOOR.MATH":e=>1===e.length&&`floor(${e[0]})`,"CEILING.MATH":e=>1===e.length&&`ceil(${e[0]})`,FACT:e=>1===e.length&&`((${e[0]})!)`,COMBIN:e=>2===e.length&&`comb(${e.join(", ")})`,PERMUT:e=>2===e.length&&`perm(${e.join(", ")})`,AVERAGE:e=>`mean(${e.join(", ")})`,SUM:e=>`sum(${e.join(", ")})`,PRODUCT:e=>`prod(${e.join(", ")})`,MAX:e=>`max(${e.join(", ")})`,MIN:e=>`min(${e.join(", ")})`,MEDIAN:e=>`median(${e.join(", ")})`,"STDEV.P":e=>`stdev(${e.join(", ")})`,STDEVP:e=>`stdev(${e.join(", ")})`,CEILING:e=>(1===e.length||2===e.length&&"1"===e[1].trim())&&`ceil(${e[0]})`,RAND:e=>!e.length&&"random()",ISNUMBER:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,LOG10:e=>1===e.length&&`log_{10}(${e[0]})`};function Ne(e,t){for(let n=t,i=0;n>=0;n--)if(")"===e[n])i++;else if("("===e[n]&&0===--i)return n;return-1}function Se(e){const t="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";return e=function(e,t){const n=new RegExp(`^(?:${t})`,"u"),i=new RegExp(`(?:${t})$`,"u"),s=/[\p{L}_][\p{L}\p{N}_.]*$/u;for(let t=e.indexOf("^");t>=0;t=e.indexOf("^",t+1)){let r,o=t+1;for(;/\s/.test(e[o]??"");)o++;if("("===e[o])r=ke(e,o)+1;else{const t=n.exec(e.slice(o));r=t?o+t[0].length:0,t&&"("===e[r]&&(r=ke(e,r)+1)}if(r<=o||!/^\s*\^/.test(e.slice(r)))continue;let a,l=t;for(;l>0&&/\s/.test(e[l-1]);)l--;if(")"===e[l-1]){a=Ne(e,l-1);const t=a>0&&s.exec(e.slice(Math.max(0,a-64),a));t&&(a-=t[0].length)}else{const t=i.exec(e.slice(Math.max(0,l-64),l));a=t?l-t[0].length:-1}a<0||(e=`${e.slice(0,a)}(${e.slice(a,r)})${e.slice(r)}`,t=r+1)}return e}(e=(e=(e=e.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${t})(?=\\s*\\^)`,"gu"),"$1(-$2)"),t),Me(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>qe[t[1]]?.(e)||null)}const ze={POWER:"pow",SQRT:"sqrt",ABS:"abs",LN:"ln",EXP:"exp",FLOOR:"floor",CEIL:"ceil",CEILING:"ceil",ROUND:"round",GREATEST:"max",LEAST:"min",MOD:"mod",ATAN2:"atan2",FACTORIAL:"factorial",SIN:"sin",COS:"cos",TAN:"tan",SEC:"sec",CSC:"csc",COT:"cot",ASIN:"asin",ACOS:"acos",ATAN:"atan",SINH:"sinh",COSH:"cosh",TANH:"tanh",ASINH:"asinh",ACOSH:"acosh",ATANH:"atanh",COMB:"comb",PERM:"perm",GCD:"gcd",DERIVATIVE:"derivative",LIMIT:"limit",UNION:"union",EXPM1:"expm1",TRUNC:"trunc",SUMMATION:"sum"},Le="strtktk[A-J]+";function Ce(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${Le})\\s*\\|\\|\\s*(${Le})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${Le},\\s*${Le}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const i=ke(e,n),s=i>0&&t.exec(e.slice(n,i+1));if(!s)continue;const[,r,o]=s,a=new Map([[`${r} = TRUNC(${r})`,"ℤ"],[`${r} = TRUNC(${r}) AND ${r} > 0`,"ℕ"],[`ABS(${r}) < ∞`,"ℝ"]]).get(o.trim());a&&(e=`${e.slice(0,n)}((${r}) ∈ ${a})${e.slice(i+1)}`)}e=Me(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=Me(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})`,_e(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=>ze[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=ke(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 Te={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"},Ie={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc",union1d:"union",intersect1d:"intersection"};const Re={inf:"∞",nan:"NaN"};function je(e){return(e=(e=function(e){return e=e.replace(/(?<![\w.])sympy\.Interval\.(open|Lopen|Ropen)\s*\(/g,(e,t)=>`sympy_interval_${t}(`),e=e.replace(/(?<![\w.])sympy\.S\.(\w+)/g,(e,t)=>Fe[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>Fe[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>Pe[t]??Ze[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)=>Te[t]?`Math.${Te[t]}`:Ie[t]?Ie[t]:Re[t]??e)).replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>Re[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 Ze={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Fe={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},Pe={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",real_root:"sympy_root",det:"det",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},We={open:"()",Lopen:"(]",Ropen:"[)"};const De=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?Ee(t[1]):null},Ue=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Be=e=>De(e)??[e],He={where:e=>3===e.length&&`((${e[0]}) ? (${e[1]}) : (${e[2]}))`,logical_and:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,logical_or:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,logical_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,logical_not:e=>1===e.length&&`(!(${e[0]}))`,isin:e=>2===e.length&&`((${e[0]}) ∈ ${Oe(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${Oe(e[0])})`,isclose:e=>e.length>=2&&`((${e[0]}) ≈ (${e[1]}))`,isfinite:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,isinteger:e=>1===e.length&&`((${e[0]}) ∈ ℤ)`,factorial:e=>1===e.length&&`((${e[0]})!)`,union:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,union_:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,intersection:e=>2===e.length&&`((${e[0]}) ∩ (${e[1]}))`,sq:e=>1===e.length&&`((${e[0]})^2)`,cube:e=>1===e.length&&`((${e[0]})^3)`,fract:e=>1===e.length&&`((${e[0]}) - floor(${e[0]}))`,inversesqrt:e=>1===e.length&&`(1/sqrt(${e[0]}))`,mod:e=>2===e.length&&`((${e[0]}) \\mod (${e[1]}))`,atan:e=>2===e.length&&`atan2(${e[0]}, ${e[1]})`,exp2:e=>1===e.length&&`((2)^(${e[0]}))`,trunc:e=>1===e.length&&`((${e[0]}) < 0 ? (ceil(${e[0]})) : floor(${e[0]}))`,vec2:e=>`(${e.join(", ")})`,vec3:e=>`(${e.join(", ")})`,vec4:e=>`(${e.join(", ")})`,derivative:e=>e.length>=2&&`der(${e.join(", ")})`,sympy_rational:e=>2===e.length&&`((${e[0]})/(${e[1]}))`,sympy_value:e=>1===e.length&&`(${e[0]})`,sympy_eq:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,sympy_ne:e=>2===e.length&&`((${e[0]}) ≠ (${e[1]}))`,sympy_and:e=>e.length&&`(${e.map(_e).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(_e).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(De);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:Ue("[]"),sympy_interval_open:Ue("()"),sympy_interval_Lopen:Ue("(]"),sympy_interval_Ropen:Ue("[)"),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=Be(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&&Be(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&&Be(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:Ge("sum"),prod:Ge("prod")};function Ge(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=Ee(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]}))`}}function Qe(e){e=function(e){for(let t=e.lastIndexOf("(lambda");t>=0;t=t>0?e.lastIndexOf("(lambda",t-1):-1){const n=ke(e,t);if(n<0||"("!==e[n+1])continue;const i=ke(e,n+1),s=/^\(lambda\s+([\w\s,]+?)\s*:\s*([\s\S]*)\)$/.exec(e.slice(t,n+1));if(i<0||!s)continue;const r=s[1].split(",").map(e=>e.trim()),o=Ee(e.slice(n+2,i));if(o.length!==r.length||!r.every(e=>/^[A-Za-z_]\w*$/.test(e)))continue;const a=new Map(r.map((e,t)=>[e,o[t]])),l=s[2].replace(new RegExp(`(?<![\\w.])(${r.join("|")})(?!\\w)`,"g"),e=>`(${a.get(e)})`);if((e=e.slice(0,t)+`(${l})`+e.slice(i+1)).length>1e5)throw new Error("The expression expands too much when read")}return e}(e),e=Me(e,Ae("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=Me(e,Ae(Object.keys(He).join("|")),(e,t)=>He[t[1]](e)||null);for(let t=(e=Me(e,Ae("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=ke(e,n);let s=t;if(we.includes(e[t-1])){let n=0;for(s=t-1;s>=0;s--)if(we.includes(e[s]))n++;else if(ve.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)}) ∈ ${Oe(e.slice(s,t))})${e.slice(i+1)}`)}return e}for(const e of[qe,ze,Te,Ie,Ze,Fe,Pe,We,He,Re])Object.setPrototypeOf(e,null);const Xe=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Ve=e=>e.trim().split(/\s+/).join(String.raw`\s+`),Ye=e=>new RegExp(String.raw`(?<![\w.])${Ve(e)}(?![\w.])`,"gi"),Je=[["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","="]],Ke="[<>≤≥=≠≈]",et={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(et,null);const tt=Object.entries({sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"}).sort((e,t)=>t[0].length-e[0].length),nt=[["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","∈ ℚ"]],it=/(?<![A-Za-z])(?:is|between|exceeds|equals?|does|doesn't|least|most|than|divides|and|or|of|to|squared|cubed|twice|percent|by|over|times|plus|minus|modulo)(?![A-Za-z])/i;Je.map(([e])=>e),nt.map(([e])=>e),tt.map(([e])=>`${e} of`);const st=S([[" 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 ","→"],["===","=...="]]),rt=S([...T,...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}()]),ot=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=Se(e)),(e=(e=(e=function(e){for(let t=0;t<50;t++){let t=!0;for(const n of e.matchAll(/\bif\b/g)){const i=n.index;let s=0,r=-1,o=e.length;for(let t=i+2;t<e.length;t++)if(ve.includes(e[t]))s++;else{if(we.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(we.includes(e[t]))s++;else{if(ve.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=Qe(e=function(e){return e.includes("sorted")?Me(e,/(?<![\w.])sorted\s*\(/g,e=>{if(1!==e.length)return null;const t=e[0];for(let e=0,n=0;e<t.length;e++)if("([{".includes(t[e]))n++;else if(")]}".includes(t[e]))n--;else if(0===n&&("|"===t[e]||"&"===t[e])){const n=e=>{const t=e.trim(),n=/^set\s*\(/.exec(t);return n&&ke(t,n[0].length-1)===t.length-1?t.slice(n[0].length,-1):null},[i,s]=[n(t.slice(0,e)),n(t.slice(e+1))];return null!==i&&null!==s?`((${i}) ${"|"===t[e]?"∪":"∩"} (${s}))`:null}return null}):e}(e=je(e=Ce(e=(e=(e=function(e){for(const[t,n]of Object.entries(ye))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]?ke(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=ke(e,n),s=e.lastIndexOf("Number(",t);i<0||s<0||ke(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})"))))))).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(!it.test(e))return e;let t=e;const n=(e,n,i,s="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Ve(e)}\s+(${Xe})\s+(?:and|to)\s+(${Xe})(?:\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+(${Xe})\s+to\s+(${Xe})`,"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`(${Xe})\s+`;t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?within\s+(${Xe})\s*(%|\s+percent)?\s+of\s+(${Xe})`,"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+(${Xe})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Xe})`,"gi"),(e,t,n,i)=>`((${t}) mod (${i}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${Xe})\s+divides\s+(${Xe})`,"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 nt)t=t.replace(Ye(e),` ${n} `);t=t.replace(Ye("is not in")," ∉ ").replace(Ye("is in")," ∈ ").replace(Ye("is an element of")," ∈ ");for(const[e,n]of Je)t=t.replace(Ye(e),` ${n} `);t=t.replace(Ye("is not")," ≠ "),t=t.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let e=!0;e;){const n=t;t=t.replace(new RegExp(String.raw`(${Xe})\s*(${Ke})\s*(${Xe})\s+(and|or)\s+(${Ke})`,"gi"),"$1 $2 $3 $4 $1 $5"),e=t!==n}t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${Xe})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${Xe})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${Xe})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+power\s+of\s+(${Xe})`,"gi"),"($1)^($2)"),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+(${Object.keys(et).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,i)=>`(${t})^(${et[n.toLowerCase()]??i})`),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+(${Xe})(?![\w.])`,"gi"),"($1)^($2)");for(const[e,n]of tt)t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Ve(e)}\s+of\s+(${Xe})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${Xe})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${Xe})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${Xe})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${Xe})`,"gi"),"2*($1)"),t=t.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const s=e=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${Ve(e)}(?=\s+[\w.(\[{-])`,"gi");for(const[e,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(s(e),` ${n} `);return t}],["words",st],["spaced",function(e){e=Y(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=Q(e,n+2,"then");if(i<0)return e;const s=e.slice(n+2,i),r=Q(e,i+4,"else"),o=X(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=function(e){for(let t=e.lastIndexOf("\\sqrt");t>=0;t=t>0?e.lastIndexOf("\\sqrt",t-1):-1){let n=t+5;if(/[A-Za-z]/.test(e[n]??""))continue;for(;I(e[n]);)n++;const i=e.slice(n);let s=/^(?:§\d+§|-?(?:\d+(?:\.\d+)?|\.\d+)|-?[A-Za-zͰ-Ͽ])/.exec(i)?.[0];if(!s&&/^\\[A-Za-z]/.test(i)&&!i.startsWith("\\left")){let e=/^\\[A-Za-z]+/.exec(i)[0].length;if(/^\d\d/.exec(i.slice(e))&&/frac$/.test(i.slice(0,e)))e+=2;else{const t=/^\s*\[[^\[\]{}]*\]/.exec(i.slice(e));for(t&&(e+=t[0].length);;){let t=e;for(;I(i[t]);)t++;if("{"!==i[t])break;let n=0,s=-1;for(let e=t;e<i.length;e++)if("{"===i[e])n++;else if("}"===i[e]&&0===--n){s=e;break}if(s<0)break;e=s+1}}s=i.slice(0,e)}s&&(e=`${e.slice(0,t)}\\sqrt{${s}}${e.slice(n+s.length)}`)}return e}(function(e){return e=e.replace(D,(e,t,n)=>`(${t}+${W[n]})`),e=e.replace(U,(e,t,n,i)=>Number(n)<Number(i)&&3!==n.length?`(${t}+${n}/${i})`:e),e.replace(B,(e,t,n,i,s,r)=>{const[o,a]=[n??s,i??r];return Number(o)<Number(a)?`(${t}+\\frac{${o}}{${a}})`:e})}(function(e){return e.replace(P,e=>{const t=e[0]in Z;return`${t?"^":"_"}{${[...e].map(e=>(t?Z:F)[e]).join("")}}`})}(e))))).replace(/\(\s*\\?b?mod\s+([^()\s](?:[^()]*[^()\s])?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")));for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=V(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}const i=("^"===e[t]||/[A-Za-z}]/.test(e[t-1]??""))&&/^\\[A-Za-z]+(?![A-Za-z{\d])/.exec(e.slice(t+1));if(i){e=`${e.slice(0,t+1)}{${i[0]}}${e.slice(t+1+i[0].length)}`;continue}let s=t+1;for("-"===e[s]&&s++;s<e.length&&".0123456789".includes(e[s]);)s++;if(s===t+2&&"-"===e[t+1]&&(s=t+1),"-"===e[t+1]&&/^\s*[\^!]/.test(e.slice(s,s+8)))continue;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 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",rt],["bar",function(e){let t=0;for(let n=e.indexOf(d,t);n>=0;n=e.indexOf(d,t)){let i=0,s=-1;for(let t=n+1;t<e.length;t++)if("([{".includes(e[t]))i++;else if(")]}".includes(e[t]))i--;else if(0===i&&e.startsWith("|_",t)){s=t;break}s<0&&at(),e=`${e.slice(0,n+1)}(${e.slice(n+1,s)})${e.slice(s)}`,t=n+1}return e}],["compact",function(e){if(e=function(e){for(let t=0;t<e.length;t++){const n=t>0&&oe.test(e[t-1]);let i,s=null,r=t;if(e.startsWith("frac{",t)){const n=ae(e,t+4),i=n&&ae(e,n[1]);s=i&&ce(n[0],i[0]),s&&(r=i[1])}else if("d"===e[t]&&!n){let[n,i]=le(e,t+1),o="";if(oe.test(e[i]??"")&&"/"===e[i+1]&&(o=e[i++]),"/"===e[i]&&"d"===e[i+1]&&oe.test(e[i+2]??"")){const t=e[i+2],[,a]=le(e,i+3);s={n:n,of:o,by:t},r=a}}if(s){if(s.of)i=ue(s.of,s.by,s.n);else{const[t,n]=he(e,r);if(!t)continue;i=ue(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)+ue(e.slice(i,t+1),"x",s)+e.slice(t+1+s),t=i}return e}(e=(e=Y(e)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}"))),e.split("\\int").length>101)throw new Error("More than 100 integrals");for(let t=0;t<e.length;t++){const n=e[t],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=te(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"+K(e.slice(t+1)):"sqrt"===i(4)&&(e=e.slice(0,t-4)+"sqrt"+K(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+J(e.slice(t));else if("t"===n)"\\int"===s(3)&&(e=e.slice(0,t-3)+ie(e.slice(t+1)));else if("m"===n)"\\binom"===s(5)&&(e=e.slice(0,t-5)+"\\binom"+re(e.slice(t+1)));else if("d"===n&&"dd"===s(1)&&"("===e[t+2]){const n=se(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return(e=e.replace(/\\(?:text|textrm|textit|mathrm|mathit|mathbf|mathsf|operatorname)\{([A-Za-z])\}/g,"$1")).replace(/\\log/g,"log")}],["bars",function(e){for(let t=e.indexOf(d);t>=0;t=e.indexOf(d)){const n=at;e.startsWith("(der(",t+1)||n();const i=lt(e,t+1,"(",")"),s=lt(e,t+5,"(",")");(s<0||i!==s+1)&&n();const r=ct(e.slice(t+6,s));(r.length<2||r.length>3||!e.startsWith("|_",i+1))&&n();const o=i;let a,l;"{"===e[o+3]?(l=lt(e,o+3,"{","}"),l<0&&n(),a=e.slice(o+4,l)):(l=o+3,a=e[l]??"");const[c,h,u]=r;a.trim()||n();const p=a.includes("=")?a:`${h}=${a}`;e=`${e.slice(0,t)}der(${c},${p}${u?`,${u}`:""})${e.slice(l+1)}`}return e}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]],at=()=>{throw new Error("An evaluation bar (\\left. … \\right|_{x = a}) is read only after a derivative: \\left.\\frac{d}{dx} f\\right|_{x=a}")};function lt(e,t,n,i){let s=0;for(let r=t;r<e.length;r++)if(e[r]===n)s++;else if(e[r]===i&&0===--s)return r;return-1}function ct(e){const t=[];let n=0,i=0;for(let s=0;s<e.length;s++)"([{".includes(e[s])?n++:")]}".includes(e[s])?n--:","===e[s]&&0===n&&(t.push(e.slice(i,s)),i=s+1);return t.push(e.slice(i)),t}function ht(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=de(t.size);t.set(l,s+o+s),n+=l,i=r+1}return{text:n,strings:t}}(ge(e));let s=n.replace(/\t/g," ");t.evaluate&&(s=function(e,t,n){const i=/\\[A-Za-z]/.test(e);let s=0;for(;;){let r=e.indexOf("{{",s);if(r<0)return e;let o=!1;const a=i&&ut.test(e.slice(0,r));if(pt(e,r)||a&&"{"===e[r+2]?r+=1:o=a,!e.startsWith("{{",r)){s=r;continue}const l=mt(e,r);if(l<0)return e;let c=e.slice(r+2,l).trim();for(const[e,n]of t)c=c.split(e).join(n);try{let i=n(c);if(/^["'`]/.test(i)){const e=de(t.size);t.set(e,i),i=e}const a=e.slice(0,r).trimEnd(),h=e.slice(l+2).trimStart();/^[\d.]/.test(i)&&(/[\d.]$/.test(a)||/^[\d.]/.test(h))&&(i=`(${i})`),o&&(i=`{${i}}`),e=e.slice(0,r)+" "+i+" "+e.slice(l+2),s=r+1+i.length}catch{s=l+2}}}(s,i,t.evaluate));const r=[["strings",s]];for(const[e,t]of ot){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}}const ut=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function pt(e,t){let n=0;for(;"\\"===e[t-1-n];)n++;return n%2==1}function mt(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 dt={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 ft(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function gt(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==ft(n)}function bt(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":gt(e)?"neg":e.op}const $t=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),xt=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!$t.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,bt(t),n);function yt(e,t){const n=bt(t),i=n&&a(n)?.prec;return i?"!"===e?i<=a("!").prec:"\\not"===e?i<a("\\not").prec:i<70||_t(t)||"\\not"===n:"\\not"!==e&&_t(t)}function vt(e,t,n={}){const i=n.left?"bracket":Mt(e),s=n.right?"bracket":Et(t);return"digit"!==s&&"sign"!==s&&"word"!==i&&"word"!==s&&"other"!==i&&("frac"!==s||"digit"!==i&&"frac"!==i)}function wt(e){return 1===e.length||Boolean(dt[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function kt(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function Et(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&wt(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||gt(e)?"sign":"/"===t?"frac":a(t)?.group||kt(e)?"bracket":At(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?kt(e.args[0])?"bracket":Et(e.args[0]):["*","sum","prod","perm"].includes(t)?Et(e.args[0]):"other"}function Mt(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&wt(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||kt(e)||At(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?Mt(e.args[e.args.length-1]):"other"}function At(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function _t(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||gt(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!xt(e,e.args[0],"left")&&_t(e.args[0])}const Ot=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),qt=e=>e.slice(2);function Nt(e){const t="op"===e.args[1].type&&"="===e.args[1].op?e.args[1]:null,n=t?t.args[0]:e.args[1],i=t?t.args[1]:null;let s=1,r=e.args[0];for(;"op"===r.type&&"der"===r.op&&St(r.args[1],n);)s++,r=r.args[0];return{n:s,body:r,by:n,at:i,variable:"symbol"===r.type&&wt(r.value)}}const St=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type;for(const e of[dt])Object.setPrototypeOf(e,null);const zt={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function Lt(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(zt,e.op))return e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args:[e]);if("[]"!==e.op||!e.args.length||!e.args.every(e=>"op"===e.type&&"[]"===e.op))return null;const t=e.args[0].args.length;return!t||!e.args.every(e=>e.args.length===t)||e.args.length<2&&t<2?null:e.args.map(e=>e.args)}const Ct=Object.keys(f).filter(e=>100===f[e]&&/^[a-z]{2,}$/.test(e)),Tt=["frac"],It=[...Object.keys(dt),"pi","tau","inf","infinity","exp"],Rt="\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+/),jt=new Set([...It,...Rt,"true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),Zt=/^[a-zA-ZͰ-Ͽ]$/,Ft=new Set(["f","g","h","u","v","F","G","H"]),Pt=e=>Ct.includes(e)||Tt.includes(e),Wt=[...Ct,...Tt,...It].sort((e,t)=>t.length-e.length),Dt=[...Ct,...Tt,"pi"].sort((e,t)=>t.length-e.length);function Ut(e,t=Wt){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(Pt(e))return!0;const t=Ut(e,Dt);return t.length>1&&Pt(t[t.length-1])&&!jt.has(e)}function Ht(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=>Zt.test(e)))||1===e.length||jt.has(e)||Pt(e))return[e];var i;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return Gt(Ut(e),n);if(e.length<=2)return[...e];const s=Gt(Ut(e,Dt),n),r=s.findIndex(e=>e.length>1);if(r<0)return[e];if("pi"===s[r]&&!s.some(e=>Ct.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 Gt(e,t){const n=e[e.length-1];return t||!Ct.includes(n)?e:[...e.slice(0,-1),...n]}const Qt="§",Xt=/[A-Za-zͰ-Ͽ′]/,Vt=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 i="";const s=e=>{i&&(Vt(i)?n.push(...function(e,t,n){if((e=>fe.test(e))(e))return[e];if($.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 Ft.has(e)?[r+e]:[e];if(g(e))return[e];const n=Ht(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 Ht(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===Qt){s(o);const i=e.indexOf(Qt,t+1);if(i<0)throw new Error(`An unmatched ${Qt}`);const a=e.slice(t,i+1);n.push($.includes(e[i+1])?r+a:a),t=i;continue}if(Vt(i)&&/[0-9]/.test(o)&&g(i+o)){const{op:s,end:r}=Jt(e,t,i+o);n.push(s),i="",t=r;continue}if(Xt.test(o)&&"′"!==o&&y(i)&&(n.push(i),i=""),Xt.test(o)&&(""===i?"′"!==o:Vt(i)))i+=o;else if(/[0-9]/.test(o)&&Vt(i)&&!Bt(i))i+=o;else if(Vt(i)&&s(" "===o?e[t+1]:o),"(){}[]".includes(o))i&&n.push(...Kt(i,o)),i="",n.push(o);else if("_"!==o&&" "!==o){if(g(i+o)){const{op:s,end:r}=Jt(e,t,i+o);n.push(s),i="",t=r;continue}if(g(o)){s(o);const{op:i,end:r}=Jt(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 Jt(e,t,n){let i=t;for(;i+1<e.length&&g(n+e[i+1]);)n+=e[i+1],i++;return"!"===n&&"_"===e[i+1]&&i++,{op:n,end:i}}function Kt(e,t){if(!$.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[g(t)?t:r+t]}return y(e)?[e,"*"]:g(e)||Pt(e)||y(e[0])?[e]:[r+e]}const en=70,tn=100,nn="%mod",sn=e=>$.includes(e),rn=e=>x.includes(e),on=e=>o(e)||f[e]===tn&&"_"!==e,an=new Set(["\\comb","\\perm","comb","perm"]),ln={frac:"/","\\binom":"\\binom"},cn=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","∈","∉","true","false"]),hn={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class un{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(rn(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){this.parseOperand(),this.absorb(e,t)}absorb(e,t=!1){for(;;){const n=this.peek();if(void 0===n||rn(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:f.mod,run:()=>this.modulo()};if(e===nn)return{lbp:en,run:()=>{this.next(),this.parseExpression(en),this.emit("mod")}};if("pmod"===e)return{lbp:f.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:tn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(an.has(e))return{lbp:tn,run:()=>{this.next(),this.parseExpression(tn),this.emit(e)}};const n=f[e];if("="===e&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!on(e)&&"\\not"!==e&&!(e in ln)){const t=b.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&&!on(e)?71:en,run:()=>{this.parseExpression(en),this.emit("*")}}}startsOperand(e){return void 0===e||rn(e)||"|"===e?"|"===e:e!==nn&&(!!(sn(e)||on(e)||e in ln)||!g(e))}pipe(){if(this.absDepth>0)return null;let e=0;for(let t=this.pos;t<this.tokens.length;t++)"|"===this.tokens[t]&&e++;const t="|"===this.peek(1);return e%2==0&&!t&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:f["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(f["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(en,!0),this.emit("mod")}equals(e){this.next(),this.parseExpression(e),cn.has(this.out[this.out.length-1])&&this.questionAhead()&&this.absorb(8),this.emit("=")}questionAhead(){let e=0;for(let t=this.pos;t<this.tokens.length;t++){const n=this.tokens[t];if(sn(n))e++;else if(rn(n)){if(0===e--)return!1}else{if(0===e&&","===n)return!1;if(0===e&&"?"===n)return!0}}return!1}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const e=this.next(),t=this.tokens[this.pos-2],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(sn(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||rn(n))||sn(t)&&rn(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 ln)return this.parseScript(),this.parseScript(),this.emit(ln[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(on(e))return this.functionCall(e);if(e===nn)throw new Error("'%' is missing an operand");if(rn(e)||g(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!y(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(rn(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();rn(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(sn(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(on(e))return this.parseOperand();if(this.next(),void 0===e||rn(e)||g(e))throw new Error("Missing a sub- or superscript");this.emit(e)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const e=this.out.length;this.parseScript();const t=this.out.splice(e);this.parseExpression(f["+"],!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(f["+"],!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&&!sn(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(sn(e))return this.next(),this.bracket(e);this.parseExpression(en,!0)}}function pn(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(Ft.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:y(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)g(i)||sn(i)||rn(i)||"_"===i||o(i)||y(i)?n.push(i):n.push(...mn(i,t));return n}function mn(e,t){if("%"===e)return[nn];if(!e.includes("%"))return dn(e,t);const n=e.split("%");n.length>1&&""===n[n.length-1]&&(n.pop(),n[n.length-1]+="%");const i=[];return n.forEach((e,n)=>{n>0&&i.push(nn),""!==e&&i.push(...dn(e,t))}),i}function dn(e,t){let n=0;for(;n<e.length&&y(e.slice(0,n+1));)n++;if(0===n||n===e.length)return[e];const i=e.slice(n);return"%"===i?[e]:[e.slice(0,n),...(s=i,pn(Yt(s,t),t))];var s}for(const e of[ln,hn])Object.setPrototypeOf(e,null);const fn=new Set(["()","[]","{}","(]","[)"]),gn={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(m).map(e=>[e,"*"]))},bn=new Set(["round","fixed","der"]),$n=e=>o(e)||100===f[e];function xn(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((o,l)=>{if("∅"===o)return void n.push({list:[]});if(","===o){const e=i(o),t=i(o);return void n.push({list:[...s(t),...s(e)]})}if(fn.has(o)){const t=s(i(o));if(!t.length&&!$n(e[l+1]))throw new Error("Empty brackets");return void n.push(k(o,t))}const c=gn[o]??o,h=a(c);if(!h){if("?"===o||"abs("===o)throw new Error(`Unmatched '${o[0]}'`);return void n.push(M(o))}let u;if($n(o)&&fn.has(e[l-1])&&n[n.length-1]?.op===e[l-1])u=n.pop().args;else{let e=h.arity===t||bn.has(c)?1:h.arity;if(n.length<e)throw new Error(`'${o}' needs ${e} operand${1===e?"":"s"}`);u=n.splice(n.length-e,e).map(e=>r(e,o))}const p=function(e,t){switch(e){case"sqrt":if(2===t.length)return k("root",t);break;case"round":if(1===t.length)return k("round",[t[0],v(0)]);break;case"sum":case"prod":{const n=t[1];if("op"===n?.type&&"symbol"===n.args[0]?.type&&(3===t.length&&"="===n.op||2===t.length&&"∈"===n.op))return k("sum"===e?"\\sumidx":"\\prodidx",t);break}case"det":if(t.length>1&&t.every(e=>"op"===e.type&&"[]"===e.op))return k("det",[k("[]",t)]);break;case"fixed":if(1===t.length)return k("fixed",[t[0],v(2)]);break;case"der":if(1===t.length)return k("der",[t[0],w("x")]);if(3===t.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");const s="op"===t.type&&"="===t.op?t:null,r=s?s.args[0]:t;let o=e;for(let e=0;e<i;e++)o=k("der",[o,s&&e===i-1?s:r]);return o}(t);break;case"log":if(2===t.length&&"symbol"===t[0].type&&"e"===t[0].value)return k("ln",[t[1]]);break;case"lim":return vn(e,t),k("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?yn[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],w(t(s))]}return 3===e.length&&t(s)?[n,i,s.args[0],w(t(s))]:e}(t));case"\\:if":if(2===t.length||3===t.length)return k("?:",[t[0],t[1],t[2]??w("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return vn(e,t),k(e,t)}(c,u);m[o]&&"*"===p.op&&(p.written=m[o]),n.push(p)}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return r(n[0],"end")}const yn={"\\+":"r","\\-":"l"};function vn(e,n){const{arity:i}=a(e);if(i!==t){if(n.length!==i){throw new Error(`'${e}' takes ${i} argument${1===i?"":"s"}, not ${n.length}`)}}else if(0===n.length&&!o(e))throw new Error(`'${e}' needs at least one argument`)}for(const e of[gn,yn])Object.setPrototypeOf(e,null);const wn=new RegExp(`[${Object.keys(m).join("")}]`,"g"),kn=e=>e.replace(wn,"*"),En=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Mn=e=>/^[a-z][a-z0-9]*$/.test(e)&&g(e);function An(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=G(e.slice(t+13,n),"\\\\").map(e=>G(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=H(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 _n(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)`);if(e.includes(""))throw new Error("The character U+E000 can't be read: MathZetta uses it to hold § in strings");if((e=function(e,t,n){if(!e.includes(t))return e;const i=ge(e);let s="";for(let r=0;r<i.length;r++){const o=i[r];if('"'===o||"`"===o||"'"===o){const o=be(i,r);s+=e.slice(r,o+1).replaceAll(t,n),r=o}else s+=e[r]}return s}(e,Qt,"")).includes(Qt))throw new Error(`The character ${Qt} can't be read: MathZetta uses it to mark names`);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=new Map,r=e=>{let t=s.get(e);return void 0===t&&(t=`${Qt}${i.size}${Qt}`,i.set(t,e),s.set(e,t)),t};e=e.replace(En,(e,t)=>Mn(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,i)=>r(t)+(i?" * (":n))}return{text:e,protectedNames:i}}(An(e),t.names,[...t.values??[],...r]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=function(e,t={}){const n=void 0===t.blocks?null:t.blocks;return ht(e,{evaluate:n?e=>n(e,t.scope):void 0})}(o,{blocks:t.blocks,scope:t.scope}),p=e=>xe(xe(e,h),a).map(e=>"string"==typeof e?e.replaceAll("",Qt):e);n.mode=l,n.cleaned=kn(p([c])[0]),n.cleanSteps=u.map(([e,t])=>[e,kn(t)]);const m=Yt(c,l);n.tokens=m.map(kn);const d=p(function(e,t="plain"){return new un(pn(e,t)).parseAll().map(e=>hn[e]??e)}(m,l));n.rawPostfix=d.map(kn);const f={},g=O(xn(d),f);n.postfix=g,n.written=f,n.tree=_(g),Object.keys(f).length&&q(n.tree,e=>{f[e.id]&&(e.written=f[e.id])})}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function On(e,t={}){const n=_n(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 qn=(e,t)=>"string"==typeof e?On(e,t):function(e){if(Array.isArray(e))return _(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}(e),Nn=e=>"op"===e.type&&o(e.op)&&["vec","hat"].includes(qt(e.op)),Sn={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",dot:"dot",cross:"cross",vector:"vector",hat:"hat",at:"at",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",matrix:(e,t)=>`the ${e} by ${t} matrix`,row:e=>`row ${e}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},zn={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"},Ln=Object.fromEntries(Object.entries(dt).map(([e,t])=>[t,e]));function Cn(e,t={}){return Tn(function(e,t={}){return function(e,t,n){const i=new jn({...Sn,...t.words},{...zn,...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 Tn(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const In={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},Rn={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class jn{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=>Tn(this.speak(e))):[e.value],e,e=>Tn(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(Rn[e])return t[Rn[e]];if(Ln[e])return Ln[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)}grouped(e,t,n){return this.isCompound(e)||this.audio&&n?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[i,s]=n,r=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(r.comma),...this.listed(e)]:this.listed(e));if(In[t])return[...this.speak(i),a(r[In[t]]),...this.speak(s)];if(o(t)){if(1===n.length&&"symbol"===i.type&&"vec"===qt(t))return[a(r.vector),...this.speak(i)];if(1===n.length&&"symbol"===i.type&&"hat"===qt(t))return[...this.speak(i),a(r.hat)];const e=this.symbol(qt(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 gt(s)?[...this.leftSide(i),a(r.minus),...this.quantityIfSum(s.args[1])]:[...this.leftSide(i),a(r.plus),...this.speak(s)];case"-":return gt(s)?[...this.leftSide(i),a(r.plus),...this.speak(s.args[1])]:[...this.leftSide(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.grouped(s,"endSub","op"===s.type):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.grouped(i,"endQuantity","op"===i.type||"number"===i.type&&i.value.startsWith("-")),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):Tn(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:`${Tn(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 Lt(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=Lt(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.listed(e)]:this.listed(e))}listed(e){return this.audio?this.quantity(e):this.speak(e)}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}leftSide(e){return this.audio&&"op"===e.type&&"?:"===e.op?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,"endQuantity")]:this.speak(e)}quantityIfSum(e){return this.quantity(e)}product(e){const[t,n]=e.args,i=this.w;if(gt(e))return this.speak({...e,op:"neg",args:[n]});if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,i.degrees)];const s=this.audio&&"op"===t.type&&"/"===t.op&&!t.args.every(e=>"number"===e.type&&/^\d$|^10$/.test(e.value))?[this.seg(t,i.quantity),...this.speak(t),...this.closer(t,"endFraction")]:this.quantity(t);this.audio&&"op"===t.type&&"^"===t.op&&"number"!==t.args[1].type&&s.push(...this.closer(t.args[1],"endExponent"));const r=this.quantity(n);if(e.written&&[t,n].some(Nn))return[...s,this.seg(e,i[e.written]),...r];return Boolean(e.written)||this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||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)&&!dt[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}`)]}const r=(e,...t)=>"op"===e.type&&t.includes(e.op)&&!gt(e);return[...this.grouped(t,null,r(t,"/")),...this.isCall(t)?[s(i.comma)]:[],s(i.over),...this.grouped(n,"endFraction",r(n,"/"))]}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||"neg"===t.op||gt(t))?[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))}`)];if(!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))){const e=this.speak(n),t=e[0]&&e[0].text.startsWith(i.quantity);return[...r,s(t?i.toThePowerOf:i.toThe),...e]}return 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,at:s,variable:r}=Nt(e),o=this.w,a=t=>this.seg(e,t),l=s?[a(`${o.comma} ${o.at}`),...this.speak(i),a(o.equals),...this.speak(s)]:[];if(r){return[...[a(1===t?o.d:`${o.d} ${2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`}`),...this.speak(n),a(o.d),...this.speak(i),a(1===t?"":2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`)],...l]}return[a(`${1===t?o.derivative:2===t?o.secondDerivative:o.nthDerivative(this.ordinal(t))} ${o.withRespectTo}`),...this.speak(i),a(o.of),...this.contents(n,"endDerivative"),...l]}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(N(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=N(n);l=e?[a(e),a(o.approaches),...this.speak(i)]:this.speak(i)}}return this.audio&&"op"===n.type&&"/"===n.op?[a(o.limitAs),...l,a(o.of),...this.grouped(n,"endLimit",!0)]:[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(e,t,n,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[Sn,zn,In,Rn,Ln])Object.setPrototypeOf(e,null);function Zn(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":Cn(qn(e),t)}const Fn={"(":{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 Pn(e,t,n=""){const i=Fn[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 Wn=.8,Dn=.2,Un=.25,Bn=.7,Hn="−",Gn={"+":"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"},Qn={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Xn={"±":"±","∪":"∪","∩":"∩",mod:"mod"},Vn=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],Yn={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},Jn=[...Vn,...Object.keys(Yn),"ln","det"],Kn={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},ei={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},ti=["int","lim","\\sumidx","\\prodidx"],ni={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},ii={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},si=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,ri=e=>"symbol"===e?.type&&si.test(dt[e.value]??e.value),oi=["boxed","overline","bar","underline","cancel",...Object.keys(ii)],ai={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},li=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ci=e=>+e.toFixed(3)+"em",hi=(e,t=Wn,n=Dn)=>({html:e,h:t,d:n});function ui(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(Wn,...t.map(e=>e.h)),d:Math.max(Dn,...t.map(e=>e.d))}}function pi(e,t={}){const n=new mi({...ai,...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):Zn(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="${li(o)}"`}>${a}${r}</span>`,h:i.h,d:i.d}}class mi{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=hi(this.el(e,li(t)));return n.leaf={kind:e,content:li(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="${li(e.op)}"`);const s=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(s))"class"!==e&&"style"!==e&&/^[A-Za-z_:][\w:.-]*$/.test(e)&&(i+=` ${e}="${li(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?[li(s.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${r?` style="${li(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(/^-/,Hn)))}symbol(e){return dt[e]&&(e=dt[e]),ni[e]?this.text("ord",ni[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)?hi(this.el("var",li(e[0]))+this.el("prime",li(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?hi(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,leftFactor:!1}),l=Gn[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),h=t=>this.wrap(e,["op",`op-${l}`],t),u=(t,n)=>xt(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(Jn.includes(n)||"log"===n)return h(this.named(e,t));if(Kn[n])return h(ui(this.word(Kn[n]),this.fence(this.list(i,t))));if(o(n))return h(this.custom(e,t));const p=Lt(e);if(p)return h(this.matrix(e,p,t));if(ei[n])return h(this.fence(this.list(i,t),...ei[n]));if(("|"===n||"&"===n)&&i.length>=2&&i.every(gi)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===n?a(e):this.fence(a(e));return h(ui(i.map((t,i)=>i?[this.text("conj","|"===n?"or":"and"),e(t)]:[e(t)]).flat()))}if(Qn[n]&&2===i.length)return h(ui(u(s,"left"),this.rel(Qn[n]),u(r,"right")));if(Xn[n]&&2===i.length)return h(ui(u(s,"left"),this.bin(Xn[n]),u(r,"right")));switch(n){case"+":if(gt(r)){const e=r.args[1],t=xt({op:"-"},e,"right")?this.fence(a(e)):a(e);return h(ui(u(s,"left"),this.bin(Hn),this.wrap(r,["op","op-mul"],t)))}return"number"===r.type&&r.value.startsWith("-")?h(ui(u(s,"left"),this.bin(Hn),this.wrap(r,["number"],this.text("num",r.value.slice(1))))):h(ui(u(s,"left"),this.bin("+"),this.signed(r,u(r,"right"))));case"-":return h(ui(u(s,"left"),this.bin(Hn),this.signed(r,u(r,"right"))));case"*":return h(this.product(e,t));case"/":return h(this.fraction(e,t));case"^":return h(this.power(e,t));case"_":{const e=bt(s)&&c(bt(s))<100;return h(this.script(e?this.fence(a(s)):a(s,{forceParens:!0}),null,t,a(r,{level:t.level+1})))}case"neg":return h(ui(this.text("sign",Hn),yt(n,s)?this.fence(a(s)):a(s,{before:t.before})));case"pm":return h(ui(this.text("sign","±"),yt(n,s)?this.fence(a(s)):a(s)));case"!":return h(ui(yt(n,s)?this.fence(a(s)):a(s,{forceParens:!0}),this.text("ord","!")));case"\\not":return h(ui(this.text("sign","¬"),yt(n,s)?this.fence(a(s)):a(s)));case"pmod":return h(ui(a(s),this.fence(ui(this.word("mod"),this.text("space",""),a(r)))));case"sqrt":return h(this.radical(a(s)));case"root":return h(this.radical(a(r),this.render(s,{level:t.level+2})));case"abs":return h(this.fence(a(s),"|","|"));case"floor":return h(this.fence(a(s),"⌊","⌋"));case"ceil":return h(this.fence(a(s),"⌈","⌉"));case"loglog":return h(ui(this.word("ln"),this.fence(ui(this.word("ln"),this.fence(a(s))))));case"logloglog":return h(ui(this.word("ln"),this.fence(ui(this.word("ln"),this.fence(ui(this.word("ln"),this.fence(a(s))))))));case"perm":return h(this.script(this.script(hi(""),this.render(s,{level:t.level+1}),t),null,t,this.render(r,{level:t.level+1}),this.word("P")));case"comb":return h(this.fence(this.stack(a(s),a(r),!1)));case"?:":return h(this.o.cases?this.cases(e,t):ui(a(s),this.bin("?"),a(r),this.bin(":"),a(i[2])));case"sum":case"prod":{const e={op:"sum"===n?"+":"*"},t=(t,n)=>xt(e,t,n?"right":"left")?this.fence(a(t)):a(t);return h(ui(i.map((e,i)=>i?[this.bin("sum"===n?"+":"·"),t(e,i)]:[t(e,i)]).flat()))}case"der":return h(this.derivative(e,t));case"int":return h(this.integral(i,t));case"lim":return h(this.limit(i,t));case"\\sumidx":return h(this.bigOperator("sum",i,t));case"\\prodidx":return h(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 ui(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(gt(e))return ui(this.text("sign",Hn),yt("neg",i)?this.fence(this.render(i,t)):this.render(i,t));const s=function(e){const[t,n]=e.args;return{left:xt(e,t,"left")&&"/"!==t.op,right:xt(e,n,"right")&&"/"!==n.op}}(e);ti.includes(n.op)&&(s.left=!0);const r=!e.written&&vt(n,i,s),a=function(e){for(;"op"===e.type;){if(Jn.includes(e.op)||"log"===e.op||Kn[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,leftFactor:!0}),c=s.right?this.fence(this.render(i,t)):this.render(i,{...t,before:t.before});return ui(l,r?hi(this.el(a?"fnspace":"times","")):this.bin("cross"===e.written?"×":"·"),c)}named(e,t,n=null){const{op:i,args:s}=e,r="log"===i?s[1]:s[0];let o;o=Yn[i]&&"power"===this.o.inverseTrig?this.script(this.word(Yn[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&&di(r),l=this.render(r,{...t,forceParens:!1,before:!1});return ui(o,a?ui(hi(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=qt(e.op),i=e.args;if(oi.includes(n)&&1===i.length)return this.decorate(n,this.render(i[0],t),i[0]);return ui(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),hi(this.el("callgap","")),this.fence(this.list(i,t)))}decorate(e,t,n){switch(e){case"boxed":return hi(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return hi(this.el("cancel",t.html+Pn("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return hi(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return hi(this.el("over"+(ri(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const i=ri(n);return hi(this.el("accent"+(i?" accent-low":""),this.el(`accent-mark accent-${e}`,ii[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[n,i]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&di(n,!0)&&di(i,!0)){const e={...t,leftFactor:!1},s=(t,n)=>"op"!==t.type||di(t)&&(!n||"*"!==t.op||gt(t))?this.render(t,e):this.fence(this.render(t,e)),r=ui("op"===n.type&&"neg"===n.op?this.render(n,e):s(n,!1),this.text("ord","/"),s(i,!0));return t.leftFactor?this.fence(r):r}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:${ci(i)}`),r=n?.06:0,o=Un+r/2+.1+Math.max(Dn,i*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",s(e))+this.el("denom",s(t)),`vertical-align:${ci(o)}`);return hi(a,o+Math.max(Wn,i*e.h),Math.max(Wn,i*t.h)+Math.max(Dn,i*t.d)+.1+r/2-Un)}power(e,t){const[n,i]=e.args,s={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},r=()=>this.render(i,s);if(this.o.trigPowers&&Vn.includes(n.op)&&$i(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=xt(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||Jn.includes(n.op)||ti.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:Bn,o=s?ui(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:${ci(r)}`);if(t&&!i)return hi(e.html+this.el("sup",t.html,`font-size:${ci(r)};vertical-align:${ci(a/r)}`),Math.max(o.h,a+r*t.h),Math.max(o.d,r*t.d-a));if(i&&!t)return hi(o.html+this.el("sub",i.html,`font-size:${ci(r)};vertical-align:${ci(-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:${ci(a)};height:${ci(h+u)}`);return hi(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,Wn)+.1+.06,i=Math.max(e.d,Dn),s=n+i,r=Pn("sqrt",`${this.p}-hook`,`height:${ci(s)};width:${ci(.5+.06*(s-1))};vertical-align:${ci(-i)}`);let o="";if(t){const e=.8*Bn;o=this.el("rootindex",t.html,`font-size:${ci(e)};vertical-align:${ci((.55*s-i)/e)}`)}return hi(this.el("sqrt",o+r+this.el("radicand",e.html)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,Wn)+Math.max(e.d,Dn),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:Pn(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${ci(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:${ci(r)} ${ci(l.w)} ${ci(r)} ${ci(a.w)}`,h=hi(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,Wn)+r,Math.max(e.d,Dn)+r);return h.fenced=!0,h}derivative(e,t){const n=this.leibniz(e,t),{by:i,at:s}=Nt(e);if(!s)return n;const r=e.args[1],o=this.render({...r,args:[{...i,id:void 0},s]},{...t,level:t.level+1});return this.script(this.fence(n,"","|"),null,t,o)}leibniz(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=ui(a(),l()?this.script(this.render(s,h),l(),h):this.render(s,h)),p=e=>ui(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=bt(i)&&c(bt(i))<100,[f,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=d?this.fence(this.render(i,t),f,g):this.render(i,t);return ui(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",N(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:Ot(i)?c=o(i):(c=l(),h=a(i));break;case 3:Ot(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=hi(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return ui(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-Un,t.d+Un)+.12),a=Pn(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${ci(2*o)};width:${ci(r?.38:.5)};vertical-align:${ci(Un-o)}`);if(!n&&!i)return hi(a,Un+o,o-Un);const l=Bn,c=i||hi(""),h=n||hi(""),u=Un+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${ci(l)}`)+this.el("script lower",h.html,`font-size:${ci(l)}`),`vertical-align:${ci(u)};height:${ci(2*o)}`);return hi(a+p,Un+o,o-Un)}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 ui(this.word("lim"),hi(this.el("fnspace","")),this.body(n,t));case 2:{const e=N(n),t="number"===i.type||"symbol"===i.type&&i.value.includes("∞");c=e&&t?ui(this.text("var",e),l(),a(i)):a(i);break}case 3:c=ui(a(i),l(),a(s));break;default:{const e=ft(r).toLowerCase().startsWith("r")?"+":Hn;c=ui(a(i),l(),this.script(a(s),this.wrap(r,["symbol"],this.text("ord",e)),o))}}return ui(this.under(this.word("lim"),c,t),this.body(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):hi(this.el("under",e.html+this.el("script",t.html,`font-size:${ci(.7)}`)),e.h,Math.max(e.d,Dn)+.05+.7*(t.h+t.d))}body(e,t){const n=bt(e);return n&&c(n)<c("*")?this.fence(this.render(e,t)):this.render(e,t)}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.body(i,n);if(!this.o.display||n.level>0){const t=.55,i=Pn(e,`${this.p}-bigsign`,`height:${ci(2*t)};width:${ci(.8)};vertical-align:${ci(Un-t)}`);return ui(this.script(hi(i,Un+t,t-Un),l,n,a),c)}const h=.68,u=Bn,p=Pn(e,`${this.p}-bigsign`,`height:${ci(1.36)};width:${ci("sum"===e?1:1.05)}`),m=l?1.01+u*l.d:Un-h,d=e=>this.el("script",e.html,`font-size:${ci(u)}`),f=this.el("bigop",(l?d(l):"")+p+(a?d(a):""),`vertical-align:${ci(m)}`);return ui(hi(f,.93+(l?.08+u*(l.h+l.d):0),h-Un+(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(Wn,...e.map(e=>e.h)),d:Math.max(Dn,...e.map(e=>e.d))})),r=s.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=Un+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"],hi(i)).html:i}).join(""),l=t[0].length,c=hi(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${ci(o)}`),Un+r/2,r/2-Un),[h,u]=zt[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),ui(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=Un+r/2-s[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=hi(this.el("cases",a,`vertical-align:${ci(o)}`),Un+r/2,r/2-Un);return this.fence(l,"{","")}}function di(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||Lt(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!gt(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||bi(e)||"*"===e.op&&di(e,t)):di(e.args[0],!0)&&("neg"===e.op||di(e.args[1],!0)))}const fi=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],gi=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&fi.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(gi)),bi=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(dt[e.value])),$i=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[Gn,Qn,Xn,Yn,Kn,ei,ni,ii])Object.setPrototypeOf(e,null);const xi=e=>O(e).join(" ");function yi(e,t){const n=new Set;vi(e,t,n);const i=[];return q(e,e=>{n.has(e)&&i.push(e)}),i}function vi(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>vi(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const i=xi(On(t));return void q(e,e=>{xi(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=xi(t);q(e,e=>{e!==t&&xi(e)!==i||n.add(e)})}}else q(e,(e,i)=>{t(e,i)&&n.add(e)});else q(e,e=>{e.id===t&&n.add(e)})}function wi(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 ki(e,t={}){const{blocks:n}=t;if("string"==typeof e)return On(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return _(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return q(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),wi(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Ei(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var Mi='/*\n * Inline Math stylesheet. Everything is under .mv; colors 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 color\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, .mv-conj { 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-conj { margin: 0 0.6em; } /* x = 2 or x = 3 */\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; position: relative; padding-top: 0.14em; }\n.mv-over::before { content: \'\'; position: absolute; left: 0; right: 0; top: 0.21em; border-top: 0.06em solid currentColor; } /* metric */\n.mv-over-low::before { top: 0.48em; }\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.27em; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; } /* metric: measured over F, h, A */\n/* ˆ ˜ ˙ ¨ are spacing marks that sit high in their em: full size, pulled down onto the letter */\n.mv-accent-hat, .mv-accent-widehat, .mv-accent-tilde, .mv-accent-dot, .mv-accent-ddot { font-size: 1em; line-height: 1; top: 0.02em; }\n/* over an italic letter the mark leans with it, right of the box\'s center */\n.mv-accent:has(> .mv-var) > .mv-accent-mark { transform: translateX(0.1em); }\n/* a letter with no ascender (x, u, α; layout.js adds -low): the mark comes down to its top */\n.mv-accent-low > .mv-accent-mark { top: 0.08em; }\n.mv-accent-low > .mv-accent-hat, .mv-accent-low > .mv-accent-widehat, .mv-accent-low > .mv-accent-tilde, .mv-accent-low > .mv-accent-dot, .mv-accent-low > .mv-accent-ddot { top: 0.31em; }\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 colors) 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 math (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 Ai=Mi;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Mi,document.head.append(e)}return e.CSS=Ai,e.DEFAULTS=ai,e.layout=pi,e.numberTree=wi,e.select=yi,e.toHTML=function(e,t={}){const n=ki(e,t);return pi(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(Ei(i))for(const n of yi(e,t))a.set(n,`color:${i}`);const l=new Set(void 0===i?[]:yi(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=ki,e}({});
1
+ /* Inline Math 0.4.1 — MIT license; 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),arcsec:i(1),arccsc:i(1),arccot: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),evaluated:i(4),setbuilder: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"},"\\implies":{prec:15,assoc:"right",arity:2,fixity:"infix"},"\\iff":{prec:14,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="",p="",m={[u]:"dot",[p]:"cross"},d="",f={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,evaluated:h,setbuilder:h,arcsin:h,arccos:h,arctan:h,arcsec:h,arccsc:h,arccot:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,[u]:70,[p]:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"\\implies":15,"\\iff":14,"?:":10,"?":9,",":5},g=e=>Object.prototype.hasOwnProperty.call(f,e),b=new Set(["^","?:","?","log"]),$=["(","{","["],x=[")","}","]"];function v(e,t=!1){return"string"==typeof e&&(t?w:y).test(e)}const y=/^(?:\d+\.?\d*|\.\d+|\d*\.\d+\.\.)$/,w=/^-?(?:\d+\.?\d*|\.\d+|\d*\.\d+\.\.)$/;for(const e of[f])Object.setPrototypeOf(e,null);const k=e=>({type:"number",value:String(e)}),A=e=>({type:"symbol",value:e}),E=(e,t)=>({type:"op",op:e,args:t}),_=['"',"'","`"];function M(e){return v(e,!0)?k(e):_.includes(e[0])?{type:"string",value:e}:A(e)}const O={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function q(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],i=[];if(e.forEach((e,s)=>{const r=O[e]??String(e),l=a(r);if(!l)return n.push({...M(r),id:s}),void i.push(1);let c=l.arity;if(c===t){const e=n.pop();if(i.pop(),c=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(c)||c<0)throw new Error(`'${r}' takes a variable number of arguments, so it must follow a count`);if(0===c&&!l.group&&!o(r))throw new Error(`'${r}' needs at least one argument`)}if(n.length<c)throw new Error(`'${r}' needs ${c} operand${1===c?"":"s"}`);const h=1+Math.max(0,...i.splice(i.length-c,c));if(h>1e3)throw new Error("Nested too deeply (more than 1000 levels)");i.push(h),n.push({...E(r,n.splice(n.length-c,c)),id:s})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function z(e,n){const i=[];return function e(s){"op"===s.type?(s.args.forEach(e),a(s.op)?.arity===t&&i.push(String(s.args.length)),n&&s.written&&(n[i.length]=s.written),i.push(s.op)):i.push(s.value)}(e),i}function S(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>S(n,t,e))}function N(e){let t="";return S(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[O])Object.setPrototypeOf(e,null);function L(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 C(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=Z(n,e,s);r?(i+=t.get(e.slice(s,s+r)),s+=r):i+=e[s++]}return i}}function Z(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 C(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),j(e)]);return t.delete(e),t}function j(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 R=[["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log2","log_{2}"],["Math.log10","log_{10}"],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\cfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\%","%"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["asec(","arcsec("],["acsc(","arccsc("],["acot(","arccot("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot",u],["\\times",p],["×",p],["·",u],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],...["","\\"].flatMap(e=>["(","{"].flatMap(t=>[2,3,4,5,6,7,8,9,10].map(n=>[`${e}log${n}${t}`,`log_{${n}}${t}`]))),["\\log_10","log_{10}"],["log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\Longrightarrow"," \\implies "],["\\Rightarrow"," \\implies "],["\\implies"," \\implies "],["⇒"," \\implies "],["⟹"," \\implies "],["\\Longleftrightarrow"," \\iff "],["\\Leftrightarrow"," \\iff "],["\\iff"," \\iff "],["⇔"," \\iff "],["⟺"," \\iff "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left.",d],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⅕","(1/5)"],["⅖","(2/5)"],["⅗","(3/5)"],["⅘","(4/5)"],["⅙","(1/6)"],["⅚","(5/6)"],["⅐","(1/7)"],["⅑","(1/9)"],["⅒","(1/10)"],["⊕"," \\xor "],["∞","∞"],["⋅",u],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0]];const T=e=>" "===e||"\t"===e||"\n"===e,I="({[",F=")}]";const P="ⅆ",W=new RegExp(String.raw`(\\(?:mathrm|operatorname|text)\{d\}\s*|d)([A-Za-zα-ω](?![A-Za-z0-9])|\\(?:${"alpha|beta|gamma|delta|epsilon|varepsilon|zeta|eta|theta|vartheta|iota|kappa|lambda|mu|nu|xi|rho|sigma|tau|upsilon|phi|varphi|chi|psi|omega"})(?![A-Za-z]))`,"g");function B(e){const t=[String.raw`\left\{`,String.raw`\left\lbrace`,String.raw`\{`,String.raw`\lbrace`,"{"],n=[String.raw`\right\}`,String.raw`\right\rbrace`,String.raw`\}`,String.raw`\rbrace`,"}"],i=/\\[A-Za-z{]/.test(e);for(let s=0,r=0;s<50;s++){let s=-1,o="";for(let n=r;n<e.length&&s<0;n++){const r=t.find(t=>e.startsWith(t,n));r&&("{"===r&&(i||/[\\^_A-Za-z]$/.test(e.slice(0,n)))||("{"!==r||"{"!==e[n+1]?(s=n,o=r):n++))}if(s<0)return e;let a=0,l=null,c=null,h=-1,u=0;for(let t=s+o.length;t<e.length;t++){const s=n.find(n=>e.startsWith(n,t));if(0===a&&s&&("{"===o?"}"===s:"}"!==s)){h=t,o+="|"+s;break}if(!"([{".includes(e[t])||"{"===e[t]&&"\\"===e[t-1]?")]}".includes(e[t])&&"\\"!==e[t-1]&&a--:a++,0===a&&"?"===e[t]&&u++,0===a&&!l){const n=/^(?:\\middle\s*\||\\mid(?![A-Za-z])|:(?!=)|\|)/.exec(e.slice(t));n&&":"===n[0]&&u?u--:n&&"|"!==n[0]?l={at:t,length:n[0].length}:n&&i&&!c&&!/\\left\s*$|\\right\s*$|\\middle\s*$/.test(e.slice(0,t))&&(c={at:t,length:1})}}if(l??=c,h<0||!l){r=s+1;continue}const p=e.slice(s+o.split("|")[0].length,l.at).trim(),m=e.slice(l.at+l.length,h).trim();if(!p||!m){r=s+1;continue}const d=o.split("|")[1];e=`${e.slice(0,s)}setbuilder((${p}),(${m}))${e.slice(h+d.length)}`,r=s}return e}const D=String.raw`\\(?:[Bb]igg?|right)[lrm]?`,U=new RegExp(`(?:${D}\\s*([\\]|])|(\\]))\\s*(?=[_^])`,"g");function H(e,t){let n=t;for(;" "===e[n];)n++;if("{"===e[n]){let t=0;for(let i=n;i<e.length;i++)if("{"===e[i])t++;else if("}"===e[i]&&0===--t)return{value:e.slice(n+1,i).trim(),end:i+1};return null}const i=/^\\[A-Za-z]+/.exec(e.slice(n));return i?{value:i[0],end:n+i[0].length}:"-"===e[n]&&/\d/.test(e[n+1]??"")?{value:e.slice(n,n+2),end:n+2}:e[n]?{value:e[n],end:n+1}:null}function G(e,t){let n=t;for(;" "===e[n];)n++;const i=e[n];if("_"!==i&&"^"!==i)return null;const s=H(e,n+1);if(!s)return null;let r=s.end;for(;" "===e[r];)r++;const o="_"===i?"^":"_";if(e[r]!==o)return null;const a=H(e,r+1);return a?"_"===i?{lo:s.value,hi:a.value,end:a.end}:{lo:a.value,hi:s.value,end:a.end}:null}function Q(e,t,n){let i=0;for(let s=t-1;s>=0;s--){if(n){if("]"===e[s])i++;else if("["===e[s]){if(0===i)return{start:s,end:s+1};i--}continue}const r=e.slice(0,s+1),o=/\\right\s*[\]|)}.]$|\\[Bb]igg?r?\s*[\]|]$/.exec(r),a=/\\left\s*(?:[[(.]|\\\{)$|\\[Bb]igg?l?\s*\[$/.exec(r);if(o&&s+1<t)i++,s-=o[0].length-1;else if(a){if(0===i)return{start:s+1-a[0].length,end:s+1};i--,s-=a[0].length-1}}return null}function X(e,t){let n=0;for(let i=t-1;i>=0;i--){const t=e[i];if(")]}".includes(t))n++;else if("([{".includes(t)){if(0===n)return i+1;n--}else{if(0===n&&/[=<>&,]/.test(t))return i+1;if(0===n&&/\\(?:approx|leq?|geq?|neq?|to|quad|qquad)$/.test(e.slice(0,i+1)))return i+1}}return 0}function V(e){for(let t=0;t<50;t++){U.lastIndex=0;let t=null;for(let n=U.exec(e);n;n=U.exec(e)){const i=G(e,n.index+n[0].length);if(!i)continue;const s=Boolean(n[2]),r="|"===(n[1]??n[2]),o=Q(e,n.index,s);if((o||r&&!/^\\right/.test(n[0]))&&(!o||!/\\left\s*\|$/.test(e.slice(o.start,o.end)))){t={m:n,limits:i,opener:o};break}}if(!t)return e;const{m:n,limits:i,opener:s}=t,r=s?s.start:X(e,n.index),o=e.slice(s?s.end:r,n.index).trim(),a=/^\s*([A-Za-zα-ωΑ-Ω]|\\[A-Za-z]+)\s*=\s*([\s\S]+)$/.exec(i.lo),l=i.hi.replace(/^\s*(?:[A-Za-zα-ωΑ-Ω]|\\[A-Za-z]+)\s*=\s*/,""),c=a?`evaluated((${o}),${a[1]},${a[2]},${l})`:`evaluated((${o}),${i.lo},${l})`;e=`${e.slice(0,r)}${r>0&&/[^\s(=]/.test(e[r-1])?" ":""}${c}${e.slice(i.end)}`}return e}const Y={__proto__:null,sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot"};const J=100;const K={__proto__:null},ee={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((e,t)=>{K[e]=String(t)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((e,t)=>{ee[e]=String(t)}),Object.assign(K,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g","ʰ":"h","ⁱ":"i","ʲ":"j","ᵏ":"k","ˡ":"l","ᵐ":"m","ⁿ":"n","ᵒ":"o","ᵖ":"p","ʳ":"r","ˢ":"s","ᵗ":"t","ᵘ":"u","ᵛ":"v","ʷ":"w","ˣ":"x","ʸ":"y","ᶻ":"z"}),Object.assign(ee,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const te=new RegExp(`[${Object.keys(K).join("")}]+|[${Object.keys(ee).join("")}]+`,"g");const ne={__proto__:null,"½":"1/2","⅓":"1/3","⅔":"2/3","¼":"1/4","¾":"3/4","⅕":"1/5","⅖":"2/5","⅗":"3/5","⅘":"4/5","⅙":"1/6","⅚":"5/6","⅐":"1/7","⅛":"1/8","⅜":"3/8","⅝":"5/8","⅞":"7/8","⅑":"1/9","⅒":"1/10"},ie=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys(ne).join("")}])`,"g"),se=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,re=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function oe(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 ae(e,t){const n=[];let i=0,s=0;for(let r=0;r<e.length;r++)I.includes(e[r])?i++:F.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 le(e,t,n){let i=0;const s=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(I.includes(e[n]))i++;else if(F.includes(e[n])){if(--i<0)return-1}else if(0===i&&(s.lastIndex=n,s.test(e)))return n;return-1}function ce(e,t){let n=0;for(let i=t;i<e.length;i++)if(I.includes(e[i]))n++;else if(F.includes(e[i])&&--n<0)return i;return e.length}function he(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 ue(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(I.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&&o>0&&(e=e.slice(0,t+1)+"_{"+r+"}("+s+")"+e.slice(o+1))}return e}function pe(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 me(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 de=new Set(["pmatrix","bmatrix","vmatrix"]);function fe(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 de.has(i)?i+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function ge(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 be(e){const{lower:t,upper:n,next:i}=function(e){let t="",n="",i=0;return"_"===e[0]&&([t,i]=ge(e,0),"^"===e[i]&&([n,i]=ge(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(I.includes(e[n]))t++;else if(F.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).trim()?r(o):"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function $e(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(F.includes(n[e])?i--:I.includes(n[e])&&i++,0===i)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function xe(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const ve=/[A-Za-z\u0370-\u03FF]/;function ye(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 we(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function ke(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 Ae(e,t){if(I.includes(e[t])){let n=0;for(let i=t;i<e.length;i++)if(I.includes(e[i]))n++;else if(F.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(I.includes(e[i]))n++;else{if(F.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 Ee=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const _e="strtktk",Me="ABCDEFGHIJ",Oe=e=>_e+[...String(e)].map(e=>Me[e]).join(""),qe=new RegExp(`^${_e}[${Me}]+$`);function ze(e){let t="";for(let n=0;n<e.length;n++){const i=e[n];if('"'===i||"`"===i){const i=Se(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=Se(e,n);t+=e.slice(n,i+1),n=i}else t+=i}return t}function Se(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}const Ne=new RegExp(`${_e}[${Me}]+|§\\d+§`,"g");function Le(e,t){return t&&0!==t.size?e.map(e=>"string"!=typeof e?e:e.replace(Ne,e=>{const n=t.get(e);if(void 0!==n)return n;for(let n=e.length-1;n>7;n--){const i=t.get(e.slice(0,n));if(void 0!==i)return i+e.slice(n)}return e})):e}const Ze={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",times:"((a, b) => { const L = Array.isArray; const m = (v) => L(v) && v.length > 0 && v.every((r) => L(r) && r.length > 0 && r.length === v[0].length && !r.some(L)) && (v.length > 1 || v[0].length > 1); const l = (v) => L(v) && v.length > 0 && !v.some(L); const p = (A, B) => (A[0].length === B.length ? A.map((r) => B[0].map((_, j) => r.reduce((s, x, k) => s + x * B[k][j], 0))) : NaN); const e = (x, y) => (L(x) && L(y) ? (x.length === y.length ? x.map((t, i) => e(t, y[i])) : NaN) : L(x) ? x.map((t) => e(t, y)) : L(y) ? y.map((t) => e(x, t)) : x * y); if (m(a) && m(b)) return p(a, b); if (m(a) && l(b)) { const c = p(a, b.map((y) => [y])); return L(c) ? c.map((r) => r[0]) : c; } if (l(a) && m(b)) { const c = p([a], b); return L(c) ? c[0] : c; } return e(a, b); })",same:"((a, b) => { const s = (x, y) => (Array.isArray(x) && Array.isArray(y) ? x.length === y.length && x.every((v, i) => s(v, y[i])) : x == y); return s(a, b); })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 && Math.abs(n % 2) === 1 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))",contains:"((s, t) => { const f = (x) => (x == null ? String() : String(x)).replace(/[A-Z]/g, (c) => String.fromCharCode(c.charCodeAt(0) + 32)); return f(s).includes(f(t)); })",startswith:"((s, t) => { const f = (x) => (x == null ? String() : String(x)).replace(/[A-Z]/g, (c) => String.fromCharCode(c.charCodeAt(0) + 32)); return f(s).startsWith(f(t)); })"},Ce="lambda x: str().join(chr(ord(c) + 32) if 65 <= ord(c) <= 90 else c for c in (str() if x is None or x != x else str(int(x)) if isinstance(x, float) and x.is_integer() else str(x)))",je=`lambda s, t, f=${Ce}: f(t) in f(s)`,Re=`lambda s, t, f=${Ce}: f(s).startswith(f(t))`,Te={contains:`(${je})`,startswith:`(${Re})`},Ie={contains:`np.vectorize(${je}, otypes=[bool])`,startswith:`np.vectorize(${Re}, otypes=[bool])`};for(const e of[Ze,Te,Ie])Object.setPrototypeOf(e,null);const Fe="([{",Pe=")]}";function We(e,t){let n=0;for(let i=t;i<e.length;i++)if(Fe.includes(e[i]))n++;else if(Pe.includes(e[i])&&0===--n)return i;return-1}function Be(e){if(!e.trim())return[];const t=[];let n=0,i=0;for(let s=0;s<e.length;s++)Fe.includes(e[s])?n++:Pe.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 De(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=We(e,r);if(o<0)continue;const a=n(Be(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 Ue=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),He=e=>`(${e})`,Ge=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e,Qe=[...Object.entries(Ze),...Object.entries(Ie),...Object.entries(Te)];const Xe={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]})`,MMULT:e=>2===e.length&&`((${e[0]}) * (${e[1]}))`};function Ve(e,t){for(let n=t,i=0;n>=0;n--)if(")"===e[n])i++;else if("("===e[n]&&0===--i)return n;return-1}function Ye(e){const t="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";return e=function(e,t){const n=new RegExp(`^(?:${t})`,"u"),i=new RegExp(`(?:${t})$`,"u"),s=/[\p{L}_][\p{L}\p{N}_.]*$/u;for(let t=e.indexOf("^");t>=0;t=e.indexOf("^",t+1)){let r,o=t+1;for(;/\s/.test(e[o]??"");)o++;if("("===e[o])r=We(e,o)+1;else{const t=n.exec(e.slice(o));r=t?o+t[0].length:0,t&&"("===e[r]&&(r=We(e,r)+1)}if(r<=o||!/^\s*\^/.test(e.slice(r)))continue;let a,l=t;for(;l>0&&/\s/.test(e[l-1]);)l--;if(")"===e[l-1]){a=Ve(e,l-1);const t=a>0&&s.exec(e.slice(Math.max(0,a-64),a));t&&(a-=t[0].length)}else{const t=i.exec(e.slice(Math.max(0,l-64),l));a=t?l-t[0].length:-1}a<0||(e=`${e.slice(0,a)}(${e.slice(a,r)})${e.slice(r)}`,t=r+1)}return e}(e=(e=(e=e.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${t})(?=\\s*\\^)`,"gu"),"$1(-$2)"),t),De(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>Xe[t[1]]?.(e)||null)}const Je={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"},Ke="strtktk[A-J]+";function et(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${Ke})\\s*\\|\\|\\s*(${Ke})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${Ke},\\s*${Ke}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const i=We(e,n),s=i>0&&t.exec(e.slice(n,i+1));if(!s)continue;const[,r,o]=s,a=new Map([[`${r} = TRUNC(${r})`,"ℤ"],[`${r} = TRUNC(${r}) AND ${r} > 0`,"ℕ"],[`ABS(${r}) < ∞`,"ℝ"]]).get(o.trim());a&&(e=`${e.slice(0,n)}((${r}) ∈ ${a})${e.slice(i+1)}`)}e=De(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=De(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})`,He(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=>Je[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=We(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 tt={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"},nt={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc",union1d:"union",intersect1d:"intersection",dot:"np_times",matmul:"np_times",multiply:"np_times",array_equal:"np_equal"};const it=e=>e.replace(/(?<![\w.])set\s*\(\s*\)/g,"∅"),st={inf:"∞",nan:"NaN"};function rt(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)=>at[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>at[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>lt[t]??ot[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)=>tt[t]?`Math.${tt[t]}`:nt[t]?nt[t]:st[t]??e)).replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>st[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 ot={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},at={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},lt={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",real_root:"sympy_root",det:"det",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Implies:"sympy_implies",Equivalent:"sympy_iff",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:""},ct={open:"()",Lopen:"(]",Ropen:"[)"};const ht=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?Be(t[1]):null},ut=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,pt=e=>ht(e)??[e],mt={where:e=>3===e.length&&`((${e[0]}) ? (${e[1]}) : (${e[2]}))`,both:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,either:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,np_times:e=>2===e.length&&`((${e[0]}) * (${e[1]}))`,np_equal:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,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]}) ∈ ${Ge(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${Ge(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]}))`,radians:e=>1===e.length&&`((${e[0]})°)`,degrees:e=>1===e.length&&`((${e[0]})/°)`,mod:e=>2===e.length&&`((${e[0]}) \\mod (${e[1]}))`,atan:e=>2===e.length&&`atan2(${e[0]}, ${e[1]})`,exp2:e=>1===e.length&&`((2)^(${e[0]}))`,trunc:e=>1===e.length&&`((${e[0]}) < 0 ? (ceil(${e[0]})) : floor(${e[0]}))`,...Object.fromEntries([2,3,4].map(e=>[`mat${e}`,t=>t.length===e*e&&`[${Array.from({length:e},(n,i)=>`[${Array.from({length:e},(n,s)=>t[s*e+i]).join(", ")}]`).join(", ")}]`])),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_implies:e=>2===e.length&&`((${e[0]}) \\implies (${e[1]}))`,sympy_iff:e=>2===e.length&&`((${e[0]}) \\iff (${e[1]}))`,sympy_nor:e=>2===e.length&&`((${e[0]}) \\nor (${e[1]}))`,sympy_piecewise:e=>{const t=e.map(ht);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:ut("[]"),sympy_interval_open:ut("()"),sympy_interval_Lopen:ut("(]"),sympy_interval_Ropen:ut("[)"),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=pt(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&&pt(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&&pt(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:dt("sum"),prod:dt("prod")};function dt(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=Be(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]}))`}}function ft(e){e=function(e){for(let t=e.lastIndexOf("(lambda");t>=0;t=t>0?e.lastIndexOf("(lambda",t-1):-1){const n=We(e,t);if(n<0||"("!==e[n+1])continue;const i=We(e,n+1),s=/^\(lambda\s+([\w\s,]+?)\s*:\s*([\s\S]*)\)$/.exec(e.slice(t,n+1));if(i<0||!s)continue;const r=s[1].split(",").map(e=>e.trim()),o=Be(e.slice(n+2,i));if(o.length!==r.length||!r.every(e=>/^[A-Za-z_]\w*$/.test(e)))continue;const a=new Map(r.map((e,t)=>[e,o[t]])),l=s[2].replace(new RegExp(`(?<![\\w.])(${r.join("|")})(?!\\w)`,"g"),e=>`(${a.get(e)})`);if((e=e.slice(0,t)+`(${l})`+e.slice(i+1)).length>1e5)throw new Error("The expression expands too much when read")}return e}(e),e=De(e,Ue("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=De(e,Ue(Object.keys(mt).join("|")),(e,t)=>mt[t[1]](e)||null);for(let t=(e=De(e,Ue("float"),(e,t,n)=>{if(1!==e.length)return null;const i=/^\s*\.is_integer\(\s*\)/.exec(n);return i?[`((${e[0]}) ∈ ℤ)`,i[0].length]:`(${e[0]})`})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,i=We(e,n);let s=t;if(Pe.includes(e[t-1])){let n=0;for(s=t-1;s>=0;s--)if(Pe.includes(e[s]))n++;else if(Fe.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)}) ∈ ${Ge(e.slice(s,t))})${e.slice(i+1)}`)}return e}for(const e of[Xe,Je,tt,nt,ot,at,lt,ct,mt,st])Object.setPrototypeOf(e,null);const gt=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,bt=e=>e.trim().split(/\s+/).join(String.raw`\s+`),$t=e=>new RegExp(String.raw`(?<![\w.])${bt(e)}(?![\w.])`,"gi"),xt=[["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","="]],vt="[<>≤≥=≠≈]",yt={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(yt,null);const wt=Object.entries({sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan",arcsecant:"arcsec",arccosecant:"arccsc",arccotangent:"arccot","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"}).sort((e,t)=>t[0].length-e[0].length),kt=[["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 an integer","∈ ℤ"],["is not an integer","∉ ℤ"],["is a natural number","∈ ℕ"],["is a real number","∈ ℝ"],["is real","∈ ℝ"],["is a rational number","∈ ℚ"],["is rational","∈ ℚ"],...[["the integers","ℤ"],["the natural numbers","ℕ"],["the real numbers","ℝ"],["the rational numbers","ℚ"],["the complex numbers","ℂ"]].flatMap(([e,t])=>[[`is not in ${e}`,`∉ ${t}`],[`is in ${e}`,`∈ ${t}`]])],At=/(?<![A-Za-z])(?:is|between|exceeds|equals?|does|doesn't|least|most|than|divides|and|or|of|to|squared|cubed|twice|percent|by|over|times|plus|minus|modulo)(?![A-Za-z])/i;xt.map(([e])=>e),kt.map(([e])=>e),wt.map(([e])=>`${e} of`);const Et=L([[" And "," & "],[" Or "," ∨ "],[" Not In "," ∉ "],[" Nor "," \\nor "],[" Xor "," \\xor "],[" Nand "," \\nand "],[" In "," ∈ "],[" Mod "," \\mod "],[" % ","%"],[" Perm ","\\perm "],[" P ","\\perm",!0],[" Comb ","\\comb "],[" C ","\\comb",!0],[" choose ","\\comb "],["! ","!_"],["\\in ","∈"],["\\notin ","∉"],["\\not\\in ","∉"],["\\to ","→"],["===","=...="]]),_t=L([...R,...function(){const e=[],t=(t,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"]){e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]);for(const e of["sin","cos","tan"].includes(n)?["","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}()]),Mt=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=Ye(e)),(e=(e=(e=function(e){for(let t=0;t<50;t++){let t=!0;for(const n of e.matchAll(/\bif\b/g)){const i=n.index;let s=0,r=-1,o=e.length;for(let t=i+2;t<e.length;t++)if(Fe.includes(e[t]))s++;else{if(Pe.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(Pe.includes(e[t]))s++;else{if(Fe.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=ft(e=function(e){return e.includes("set")?it(De(e,/(?<![\w.])sorted\s*\(/g,e=>{if(1!==e.length)return null;const t=e[0];for(let e=0,n=0;e<t.length;e++)if("([{".includes(t[e]))n++;else if(")]}".includes(t[e]))n--;else if(0===n&&("|"===t[e]||"&"===t[e])){const n=e=>{const t=e.trim(),n=/^set\s*\(/.exec(t);return n&&We(t,n[0].length-1)===t.length-1?t.slice(n[0].length,-1):null},[i,s]=[n(t.slice(0,e)),n(t.slice(e+1))];return null!==i&&null!==s?`((${i}) ${"|"===t[e]?"∪":"∩"} (${s}))`:null}return null})):e}(e=rt(e=et(e=(e=(e=function(e){for(const[t,n]of Qe)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]?We(e,s):-1;if(r<0)continue;let o=e.slice(s+1,r);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="times"===t||"same"===t?Be(o):null,l="factorial"===t?`((${o})!)`:2===a?.length?`((${a[0]}) ${"times"===t?"*":"="} (${a[1]}))`:`${t}(${o})`;e=e.slice(0,i)+l+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=We(e,n),s=e.lastIndexOf("Number(",t);i<0||s<0||We(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})"))))))).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(!At.test(e))return e;let t=e;const n=(e,n,i,s="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${bt(e)}\s+(${gt})\s+(?:and|to)\s+(${gt})(?:\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+(${gt})\s+to\s+(${gt})`,"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`(${gt})\s+`;t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?within\s+(${gt})\s*(%|\s+percent)?\s+of\s+(${gt})`,"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+(${gt})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?divisible\s+by\s+(${gt})`,"gi"),(e,t,n,i)=>`((${t}) mod (${i}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${gt})\s+divides\s+(${gt})`,"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)`),t=t.replace(new RegExp(i+String.raw`is\s+(not\s+)?a\s+whole\s+number(?![\w.])`,"gi"),(e,t,n)=>n?`((${t}) ∉ ℤ ∨ (${t}) < 0)`:`((${t}) ∈ ℤ & (${t}) ≥ 0)`);for(const[e,n]of kt)t=t.replace($t(e),` ${n} `);t=t.replace($t("is not in")," ∉ ").replace($t("is in")," ∈ ").replace($t("is an element of")," ∈ ");for(const[e,n]of xt)t=t.replace($t(e),` ${n} `);t=t.replace($t("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`(${gt})\s*(${vt})\s*(${gt})\s+(and|or)\s+(${vt})`,"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+(${gt})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${gt})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${gt})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${gt})\s+to\s+the\s+power\s+of\s+(${gt})`,"gi"),"($1)^($2)"),t=t.replace(new RegExp(String.raw`(${gt})\s+to\s+the\s+(${Object.keys(yt).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,i)=>`(${t})^(${yt[n.toLowerCase()]??i})`),t=t.replace(new RegExp(String.raw`(${gt})\s+to\s+the\s+(${gt})(?![\w.])`,"gi"),"($1)^($2)");for(const[e,n]of wt)t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${bt(e)}\s+of\s+(${gt})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${gt})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${gt})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${gt})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${gt})`,"gi"),"2*($1)"),t=t.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const s=e=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${bt(e)}(?=\s+[\w.(\[{-])`,"gi");for(const[e,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(s(e),` ${n} `);return t}],["words",Et],["spaced",function(e){e=function(e){if(/\\[io]*int|∫|(?<![A-Za-z])int\(|\\partial|∂|(?<![A-Za-z])d\s*\/\s*d|frac\s*\{\s*(?:\\mathrm\s*\{\s*d\s*\}|\\operatorname\s*\{\s*d\s*\}|d)/.test(e))return e;const t=[];for(const n of e.matchAll(W)){const i=e.slice(0,n.index),s=e.slice(n.index+n[0].length),r="d"!==n[1];if(!r&&(/[A-Za-z0-9\\^_/]$|frac\s*\{$/.test(i)||/^\s*[/}]/.test(s)&&!/\{\s*$/.test(i)))continue;const o=r||/\\[,;:! ]\s*$/.test(i);t.push({m:n,strong:o})}const n=t.length>=2?t:t.filter(e=>e.strong);for(const{m:t}of n.reverse())e=e.slice(0,t.index)+P+t[2]+e.slice(t.index+t[0].length);return e}(e=function(e){return e.replace(/(?:\{\s*\}|(?<![\w}\])′]))_\s*(?:\{\s*([^{}]+?)\s*\}|([A-Za-z0-9]+?))\s*(?:\\mathrm\{([CP])\}|([CP]))\s*_\s*(?:\{\s*([^{}]+?)\s*\}|([A-Za-z0-9]))/g,(e,t,n,i,s,r,o)=>`${"C"===(i??s)?"comb":"perm"}(${t??n},${r??o})`)}(function(e){return e.replace(/(?<![A-Za-z\\])([A-Za-z])\^\s*\{?\s*\(\s*([1-9]\d*)\s*\)\s*\}?(?=\s*\()/g,(e,t,n)=>{if(n.length>3||Number(n)>J)throw new Error(`A derivative f^{(n)} is read up to n = ${J}`);return t+"′".repeat(Number(n))})}(function(e){return e.replace(/(?<![A-Za-z\\])(arc)?(sine|cosine|tangent|secant|cosecant|cotangent)(?![A-Za-z])(?=\s*\(|\s+(?:[A-Za-z](?![A-Za-z])|\d|\\))/gi,(e,t,n)=>(t?"arc":"")+Y[n.toLowerCase()])}(e=function(e){for(let t=e.lastIndexOf("\\sqrt");t>=0;t=t>0?e.lastIndexOf("\\sqrt",t-1):-1){let n=t+5;if(/[A-Za-z]/.test(e[n]??""))continue;for(;T(e[n]);)n++;const i=e.slice(n);let s=/^(?:§\d+§|-?(?:\d+(?:\.\d+)?|\.\d+)|-?[A-Za-zͰ-Ͽ])/.exec(i)?.[0];if(!s&&/^\\[A-Za-z]/.test(i)&&!i.startsWith("\\left")){let e=/^\\[A-Za-z]+/.exec(i)[0].length;if(/^\d\d/.exec(i.slice(e))&&/frac$/.test(i.slice(0,e)))e+=2;else{const t=/^\s*\[[^\[\]{}]*\]/.exec(i.slice(e));for(t&&(e+=t[0].length);;){let t=e;for(;T(i[t]);)t++;if("{"!==i[t])break;let n=0,s=-1;for(let e=t;e<i.length;e++)if("{"===i[e])n++;else if("}"===i[e]&&0===--n){s=e;break}if(s<0)break;e=s+1}}s=i.slice(0,e)}s&&(e=`${e.slice(0,t)}\\sqrt{${s}}${e.slice(n+s.length)}`)}return e}(function(e){return e=e.replace(ie,(e,t,n)=>`(${t}+${ne[n]})`),e=e.replace(se,(e,t,n,i)=>Number(n)<Number(i)&&3!==n.length?`(${t}+${n}/${i})`:e),e.replace(re,(e,t,n,i,s,r)=>{const[o,a]=[n??s,i??r];return Number(o)<Number(a)?`(${t}+\\frac{${o}}{${a}})`:e})}(function(e){return e.replace(te,e=>{const t=e[0]in K;return`${t?"^":"_"}{${[...e].map(e=>(t?K:ee)[e]).join("")}}`})}(e))))))),/\\/.test(e)||(e=B(e)),e=ue(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=le(e,n+2,"then");if(i<0)return e;const s=e.slice(n+2,i),r=le(e,i+4,"else"),o=ce(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=e.replace(/(?<![.\w=])\.\.\.(?![.\w=])/g,"⋯").replace(/∅/g,"\\{\\}"))).replace(/\(\s*\\?b?mod\s+([^()\s](?:[^()]*[^()\s])?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")));for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=he(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}const i=("^"===e[t]||/[A-Za-z}]/.test(e[t-1]??""))&&/^\\[A-Za-z]+(?![A-Za-z{\d])/.exec(e.slice(t+1));if(i){e=`${e.slice(0,t+1)}{${i[0]}}${e.slice(t+1+i[0].length)}`;continue}let s=t+1;for("-"===e[s]&&s++;s<e.length&&".0123456789".includes(e[s]);)s++;if(s===t+2&&"-"===e[t+1]&&(s=t+1),"-"===e[t+1]&&/^\s*[\^!]/.test(e.slice(s,s+8)))continue;s>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,s)+"}"+e.slice(s))}return e}],["squeeze",function(e){return(e=e.replace(/(?<![\d.])\d{1,3}(?:[ \u00A0\u202F]\d{3})+(?![\d])/g,e=>e.replace(/[ \u00A0\u202F]/g,""))).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)||/[A-Za-z\u0370-\u03FF′]/.test(i)&&/^\\[A-Za-z]/.test(e.slice(n+t.length,n+t.length+2))&&!/\\[A-Za-z]+$/.test(e.slice(0,n))||/[A-Za-z\u0370-\u03FF′]/.test(i)&&/\d/.test(s)&&!/\\[A-Za-z]+$/.test(e.slice(0,n))?" ":/\d/.test(i)&&/\d/.test(s)&&!/\\[A-Za-z]+\s*\d*$/.test(e.slice(0,n))?"*":""})}],["symbols",_t],["bar",function(e){let t=0;for(let n=e.indexOf(d,t);n>=0;n=e.indexOf(d,t)){let i=0,s=-1;for(let t=n+1;t<e.length;t++)if("([{".includes(e[t]))i++;else if(")]}".includes(e[t]))i--;else if(0===i&&e.startsWith("|_",t)){s=t;break}s<0&&Ot(),e=`${e.slice(0,n+1)}(${e.slice(n+1,s)})${e.slice(s)}`,t=n+1}return e}],["compact",function(e){if(e=function(e){for(let t=0;t<e.length;t++){const n=t>0&&ve.test(e[t-1]);let i,s=null,r=t;if(e.startsWith("frac{",t)){const n=ye(e,t+4),i=n&&ye(e,n[1]);s=i&&ke(n[0],i[0]),s&&(r=i[1])}else if("d"===e[t]&&!n){let[n,i]=we(e,t+1),o="";if(ve.test(e[i]??"")&&"/"===e[i+1]&&(o=e[i++]),"/"===e[i]&&"d"===e[i+1]&&ve.test(e[i+2]??"")){const t=e[i+2],[,a]=we(e,i+3);s={n:n,of:o,by:t},r=a}}if(s){if(s.of)i=Ee(s.of,s.by,s.n);else{const[t,n]=Ae(e,r);if(!t)continue;i=Ee(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)+Ee(e.slice(i,t+1),"x",s)+e.slice(t+1+s),t=i}return e}(e=(e=ue(e)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}"))),e.split("\\int").length>101)throw new Error("More than 100 integrals");for(let t=0;t<e.length;t++){const n=e[t],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=fe(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"+me(e.slice(t+1)):"sqrt"===i(4)&&(e=e.slice(0,t-4)+"sqrt"+me(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+pe(e.slice(t));else if("t"===n)"\\int"===s(3)&&(e=e.slice(0,t-3)+be(e.slice(t+1)));else if("m"===n)"\\binom"===s(5)&&(e=e.slice(0,t-5)+"\\binom"+xe(e.slice(t+1)));else if("d"===n&&"dd"===s(1)&&"("===e[t+2]){const n=$e(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return(e=e.replace(/\\(?:text|textrm|textit|mathrm|mathit|mathbf|mathsf|operatorname)\{([A-Za-z])\}/g,"$1")).replace(/\\log/g,"log")}],["bars",function(e){for(let t=e.indexOf(d);t>=0;t=e.indexOf(d)){const n=Ot;e.startsWith("(der(",t+1)||n();const i=qt(e,t+1,"(",")"),s=qt(e,t+5,"(",")");(s<0||i!==s+1)&&n();const r=zt(e.slice(t+6,s));(r.length<2||r.length>3||!e.startsWith("|_",i+1))&&n();const o=i;let a,l;"{"===e[o+3]?(l=qt(e,o+3,"{","}"),l<0&&n(),a=e.slice(o+4,l)):(l=o+3,a=e[l]??"");const[c,h,u]=r;a.trim()||n();const p=a.includes("=")?a:`${h}=${a}`;e=`${e.slice(0,t)}der(${c},${p}${u?`,${u}`:""})${e.slice(l+1)}`}return e}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]],Ot=()=>{throw new Error("A bar with one limit (\\left. … \\right|_{x = a}) is read only after a derivative, \\left.\\frac{d}{dx} f\\right|_{x=a}; with two, \\left. F \\right|_a^b, it is F at b minus F at a")};function qt(e,t,n,i){let s=0;for(let r=t;r<e.length;r++)if(e[r]===n)s++;else if(e[r]===i&&0===--s)return r;return-1}function zt(e){const t=[];let n=0,i=0;for(let s=0;s<e.length;s++)"([{".includes(e[s])?n++:")]}".includes(e[s])?n--:","===e[s]&&0===n&&(t.push(e.slice(i,s)),i=s+1);return t.push(e.slice(i)),t}function St(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=Oe(t.size);t.set(l,s+o+s),n+=l,i=r+1}return{text:n,strings:t}}(ze(e));let s=n.replace(/\t/g," ");t.evaluate&&(s=function(e,t,n){const i=/\\[A-Za-z]/.test(e);let s=0;for(;;){let r=e.indexOf("{{",s);if(r<0)return e;let o=!1;const a=i&&Nt.test(e.slice(0,r));if(Lt(e,r)||a&&"{"===e[r+2]?r+=1:o=a,!e.startsWith("{{",r)){s=r;continue}const l=Zt(e,r);if(l<0)return e;let c=e.slice(r+2,l).trim();for(const[e,n]of t)c=c.split(e).join(n);try{let i=n(c);if(/^["'`]/.test(i)){const e=Oe(t.size);t.set(e,i),i=e}const a=e.slice(0,r).trimEnd(),h=e.slice(l+2).trimStart();/^[\d.]/.test(i)&&(/[\d.]$/.test(a)||/^[\d.]/.test(h))&&(i=`(${i})`),o&&(i=`{${i}}`),e=e.slice(0,r)+" "+i+" "+e.slice(l+2),s=r+1+i.length}catch{s=l+2}}}(s,i,t.evaluate));const r=[["strings",s]];for(const[e,t]of Mt){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}}const Nt=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function Lt(e,t){let n=0;for(;"\\"===e[t-1-n];)n++;return n%2==1}function Zt(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 Ct={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 jt(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function Rt(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==jt(n)}function Tt(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":Rt(e)?"neg":e.op}const It=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),Ft=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!It.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,Tt(t),n);function Pt(e,t){const n=Tt(t),i=n&&a(n)?.prec;return i?"!"===e?i<=a("!").prec:"\\not"===e?i<a("\\not").prec:i<70||Qt(t)||"\\not"===n:"\\not"!==e&&Qt(t)}function Wt(e,t,n={}){const i=n.left?"bracket":Ht(e),s=n.right?"bracket":Ut(t);return"digit"!==s&&"sign"!==s&&"word"!==i&&"word"!==s&&"other"!==i&&("frac"!==s||"digit"!==i&&"frac"!==i)}function Bt(e){return 1===e.length||Boolean(Ct[e])||/^Δ.$/.test(e)||/^d[A-Za-z\u03B1-\u03C9]$/.test(e)||/^.′+$/.test(e)}function Dt(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function Ut(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&Bt(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||Rt(e)?"sign":"/"===t?"frac":a(t)?.group||Dt(e)?"bracket":Gt(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?Dt(e.args[0])?"bracket":Ut(e.args[0]):["*","sum","prod","perm"].includes(t)?Ut(e.args[0]):"other"}function Ht(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&Bt(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||Dt(e)||Gt(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?Ht(e.args[e.args.length-1]):"other"}function Gt(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function Qt(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||Rt(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!Ft(e,e.args[0],"left")&&Qt(e.args[0])}const Xt=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),Vt=e=>e.slice(2);function Yt(e){const t="op"===e.args[1].type&&"="===e.args[1].op?e.args[1]:null,n=t?t.args[0]:e.args[1],i=t?t.args[1]:null;let s=1,r=e.args[0];for(;"op"===r.type&&"der"===r.op&&Jt(r.args[1],n);)s++,r=r.args[0];return{n:s,body:r,by:n,at:i,variable:"symbol"===r.type&&Bt(r.value)}}const Jt=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type;for(const e of[Ct])Object.setPrototypeOf(e,null);const Kt={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function en(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(Kt,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 tn=Object.keys(f).filter(e=>100===f[e]&&/^[a-z]{2,}$/.test(e)),nn=["frac"],sn=[...Object.keys(Ct),"pi","tau","inf","infinity","exp"],rn="\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+/),on=new Set([...sn,...rn,"simplify","expand","factor","cancel","diff","integrate","solve","approx","limit","true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),an=/^[a-zA-ZͰ-Ͽ]$/,ln=new Set(["f","g","h","u","v","F","G","H"]),cn=e=>tn.includes(e)||nn.includes(e),hn=[...tn,...nn,...sn].sort((e,t)=>t.length-e.length),un=[...tn,...nn,"pi"].sort((e,t)=>t.length-e.length);function pn(e,t=hn){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 mn(e){if(cn(e))return!0;const t=pn(e,un);return t.length>1&&cn(t[t.length-1])&&!on.has(e)}function dn(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=>an.test(e)))||1===e.length||on.has(e)||cn(e))return[e];var i;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return fn(pn(e),n);if(e.length<=2)return[...e];const s=fn(pn(e,un),n),r=s.findIndex(e=>e.length>1);if(r<0)return[e];if("pi"===s[r]&&!s.some(e=>tn.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 fn(e,t){const n=e[e.length-1];return t||!tn.includes(n)?e:[...e.slice(0,-1),...n]}const gn="§",bn=/[A-Za-zͰ-Ͽ′]/,$n=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function xn(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let i="";const s=e=>{i&&($n(i)?n.push(...function(e,t,n){if((e=>qe.test(e))(e))return[e];if($.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 ln.has(e)?[r+e]:[e];if(g(e))return[e];const n=dn(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 dn(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===gn){s(o);const i=e.indexOf(gn,t+1);if(i<0)throw new Error(`An unmatched ${gn}`);const a=e.slice(t,i+1);n.push($.includes(e[i+1])?r+a:a),t=i;continue}if("ⅆ"===o&&/[A-Za-z\u0370-\u03FF]/.test(e[t+1]??""))i&&s(o),i="",n.push("d"+e[t+1]),t+=1;else{if($n(i)&&/[0-9]/.test(o)&&g(i+o)){const{op:s,end:r}=vn(e,t,i+o);n.push(s),i="",t=r;continue}if(bn.test(o)&&"′"!==o&&v(i)&&(n.push(i),i=""),bn.test(o)&&(""===i?"′"!==o:$n(i)))i+=o;else if(/[0-9]/.test(o)&&$n(i)&&!mn(i))i+=o;else if($n(i)&&s(" "===o?e[t+1]:o),"(){}[]".includes(o))i&&n.push(...yn(i,o)),i="",n.push(o);else if("_"!==o&&" "!==o){if(g(i+o)){const{op:s,end:r}=vn(e,t,i+o);n.push(s),i="",t=r;continue}if(g(o)){s(o);const{op:i,end:r}=vn(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 vn(e,t,n){let i=t;for(;i+1<e.length&&g(n+e[i+1]);)n+=e[i+1],i++;return"!"===n&&"_"===e[i+1]&&i++,{op:n,end:i}}function yn(e,t){if(!$.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[g(t)?t:r+t]}return v(e)?[e,"*"]:g(e)||cn(e)||v(e[0])?[e]:[r+e]}const wn=70,kn=100,An="%mod",En=/^d[A-Za-z\u0370-\u03FF]$/,_n=e=>$.includes(e),Mn=e=>x.includes(e),On=e=>o(e)||f[e]===kn&&"_"!==e,qn=new Set(["\\comb","\\perm","comb","perm"]),zn={frac:"/","\\binom":"\\binom"},Sn=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","\\implies","\\iff","∈","∉","true","false"]),Nn={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Ln{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(Mn(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){this.parseOperand(),this.absorb(e,t)}absorb(e,t=!1){for(;;){const n=this.peek();if(void 0===n||Mn(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:f.mod,run:()=>this.modulo()};if(e===An)return{lbp:wn,run:()=>{this.next(),this.parseExpression(wn),this.emit("mod")}};if("pmod"===e)return{lbp:f.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:kn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(qn.has(e))return{lbp:kn,run:()=>{this.next(),this.parseExpression(kn),this.emit(e)}};const n=f[e];if("="===e&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!On(e)&&"\\not"!==e&&!(e in zn)){const t=b.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||On(e)||En.test(e)?wn:71,run:()=>{this.parseExpression(wn),this.emit("*")}}}startsOperand(e){return void 0===e||Mn(e)||"|"===e?"|"===e:e!==An&&(!!(_n(e)||On(e)||e in zn)||!g(e))}pipe(){if(this.absDepth>0)return null;let e=0;for(let t=this.pos;t<this.tokens.length;t++)"|"===this.tokens[t]&&e++;const t="|"===this.peek(1);return e%2==0&&!t&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:f["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(f["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(wn,!0),this.emit("mod")}equals(e){this.next(),this.parseExpression(e),Sn.has(this.out[this.out.length-1])&&this.questionAhead()&&this.absorb(8),this.emit("=")}questionAhead(){let e=0;for(let t=this.pos;t<this.tokens.length;t++){const n=this.tokens[t];if(_n(n))e++;else if(Mn(n)){if(0===e--)return!1}else{if(0===e&&","===n)return!1;if(0===e&&"?"===n)return!0}}return!1}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const e=this.next(),t=this.tokens[this.pos-2],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(_n(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Mn(n))||_n(t)&&Mn(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 zn)return this.parseScript(),this.parseScript(),this.emit(zn[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(On(e))return this.functionCall(e);if(e===An)throw new Error("'%' is missing an operand");if(Mn(e)||g(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!v(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(Mn(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();Mn(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(_n(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(On(e))return this.parseOperand();if(this.next(),void 0===e||Mn(e)||g(e))throw new Error("Missing a sub- or superscript");this.emit(e)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const e=this.out.length;this.parseScript();const t=this.out.splice(e);this.parseExpression(f["+"],!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(f["+"],!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&&!_n(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(_n(e))return this.next(),this.bracket(e);this.parseExpression(wn,!0)}}function Zn(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(ln.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:v(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)g(i)||_n(i)||Mn(i)||"_"===i||o(i)||v(i)?n.push(i):n.push(...Cn(i,t));return n}function Cn(e,t){if("%"===e)return[An];if(!e.includes("%"))return jn(e,t);const n=e.split("%");n.length>1&&""===n[n.length-1]&&(n.pop(),n[n.length-1]+="%");const i=[];return n.forEach((e,n)=>{n>0&&i.push(An),""!==e&&i.push(...jn(e,t))}),i}function jn(e,t){let n=0;for(;n<e.length&&v(e.slice(0,n+1));)n++;if(0===n||n===e.length)return[e];const i=e.slice(n);return"%"===i?[e]:[e.slice(0,n),...(s=i,Zn(xn(s,t),t))];var s}for(const e of[zn,Nn])Object.setPrototypeOf(e,null);const Rn=new Set(["()","[]","{}","(]","[)"]),Tn={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(m).map(e=>[e,"*"]))},In=new Set(["round","fixed","der"]),Fn=e=>o(e)||100===f[e];function Pn(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((o,l)=>{if("∅"===o)return void n.push({list:[]});if(","===o){const e=i(o),t=i(o);return void n.push({list:[...s(t),...s(e)]})}if(Rn.has(o)){const t=s(i(o));if(!t.length&&"{}"!==o&&!Fn(e[l+1]))throw new Error("Empty brackets");return void n.push(E(o,t))}const c=Tn[o]??o,h=a(c);if(!h){if("?"===o||"abs("===o)throw new Error(`Unmatched '${o[0]}'`);return void n.push(M(o))}let u;if(Fn(o)&&Rn.has(e[l-1])&&n[n.length-1]?.op===e[l-1])u=n.pop().args;else{let e=h.arity===t||In.has(c)?1:h.arity;if(n.length<e)throw new Error(`'${o}' needs ${e} operand${1===e?"":"s"}`);u=n.splice(n.length-e,e).map(e=>r(e,o))}const p=function(e,t){switch(e){case"sqrt":if(2===t.length)return E("root",t);break;case"round":if(1===t.length)return E("round",[t[0],k(0)]);break;case"sum":case"prod":{const n=t[1];if("op"===n?.type&&"symbol"===n.args[0]?.type&&(3===t.length&&"="===n.op||2===t.length&&"∈"===n.op))return E("sum"===e?"\\sumidx":"\\prodidx",t);break}case"evaluated":if(3===t.length)return E("evaluated",[t[0],A(N(t[0])||"x"),t[1],t[2]]);break;case"det":if(t.length>1&&t.every(e=>"op"===e.type&&"[]"===e.op))return E("det",[E("[]",t)]);break;case"fixed":if(1===t.length)return E("fixed",[t[0],k(2)]);break;case"der":if(1===t.length)return E("der",[t[0],A("x")]);if(3===t.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");const s="op"===t.type&&"="===t.op?t:null,r=s?s.args[0]:t;let o=e;for(let e=0;e<i;e++)o=E("der",[o,s&&e===i-1?s:r]);return o}(t);break;case"log":if(2===t.length&&"symbol"===t[0].type&&"e"===t[0].value)return E("ln",[t[1]]);break;case"lim":return Bn(e,t),E("lim",function(e){const t=e=>{if("op"!==e.type)return null;if("^"===e.op&&"symbol"===e.args[1].type&&Wn[e.args[1].value])return{point:e.args[0],side:Wn[e.args[1].value]};const n=e.args.length?t(e.args[e.args.length-1]):null;return n&&{point:{...e,args:[...e.args.slice(0,-1),n.point]},side:n.side}},[n,i,s]=e;if(2===e.length&&"op"===i.type&&"→"===i.op){const[e,s]=i.args,r=t(s);if(r)return[n,e,r.point,A(r.side)]}const r=3===e.length&&t(s);return r?[n,i,r.point,A(r.side)]:e}(t));case"\\:if":if(2===t.length||3===t.length)return E("?:",[t[0],t[1],t[2]??A("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return Bn(e,t),E(e,t)}(c,u);m[o]&&"*"===p.op&&(p.written=m[o]),n.push(p)}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");const o=["=","<",">","≤","≥","≠","≈","≡","∈","∉"],l=n[0];return l.list&&l.list.length>1&&l.list.every(e=>"op"===e.type&&o.includes(e.op))?l.list.reduce((e,t)=>E("&",[e,t])):r(n[0],"end")}const Wn={"\\+":"r","\\-":"l"};function Bn(e,n){const{arity:i}=a(e);if(i!==t){if(n.length!==i){throw new Error(`'${e}' takes ${i} argument${1===i?"":"s"}, not ${n.length}`)}}else if(0===n.length&&!o(e))throw new Error(`'${e}' needs at least one argument`)}for(const e of[Tn,Wn])Object.setPrototypeOf(e,null);const Dn=new RegExp(`[${Object.keys(m).join("")}]`,"g"),Un=e=>e.replace(Dn,"*"),Hn=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Gn=e=>/^[a-z][a-z0-9]*$/.test(e)&&g(e);function Qn(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=ae(e.slice(t+13,n),"\\\\").map(e=>ae(e,"&")).filter(e=>e.join("").trim());let s=null;const r=/=|<|>|\\(?:le|ge|leq|geq|neq|ne|lt|gt)(?![A-Za-z])/;if(i.length>1&&i.every(e=>1===e.length&&r.test(e[0])))s=i.map(e=>`(${e[0].trim().replace(/\s*[,;.]$/,"")})`).join(" \\land "),e=e.slice(0,t)+`(${s})`+e.slice(n+11);else{for(let e=i.length-1;e>=0;e--){const t=i[e][0].trim().replace(/\s*[,;]$/,""),n=oe(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=function(e){return e=V(e),e=B(e),e=e.replace(/\\(?:[Bb]igg?)[lrm]?(?![A-Za-z])\s*/g,""),e=e.replace(/\^\s*(?:\\circ\b|\{\s*\\circ\s*\})|\\degree\b|\\textdegree\b/g,"°"),e=e.replace(/\\(?:cdots|ldots|dotsb|dotsc|dots)(?![A-Za-z])/g,"⋯"),e=e.replace(/(\d*)\.(\d*)\\overline\s*\{\s*(\d+)\s*\}/g,(e,t,n,i)=>`${t||"0"}.${n}${i}${i}..`),e=e.replace(/\\(?:emptyset|varnothing)(?![A-Za-z])/g,"\\{\\}"),e=e.replace(/\(\s*([A-Za-z])\s*\\circ\s*([A-Za-z])\s*\)\s*\(([^()]*)\)/g,"$1($2($3))"),e}(e)).replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):/[\]|]\s*_/.test(e)?V(e):e}function Xn(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)`);if(e.includes(""))throw new Error("The character U+E000 can't be read: MathZetta uses it to hold § in strings");if((e=function(e,t,n){if(!e.includes(t))return e;const i=ze(e);let s="";for(let r=0;r<i.length;r++){const o=i[r];if('"'===o||"`"===o||"'"===o){const o=Se(i,r);s+=e.slice(r,o+1).replaceAll(t,n),r=o}else s+=e[r]}return s}(e,gn,"")).includes(gn))throw new Error(`The character ${gn} can't be read: MathZetta uses it to mark names`);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=new Map,r=e=>{let t=s.get(e);return void 0===t&&(t=`${gn}${i.size}${gn}`,i.set(t,e),s.set(e,t)),t};e=e.replace(Hn,(e,t)=>Gn(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,i)=>r(t)+(i?" * (":n))}return{text:e,protectedNames:i}}(Qn(e),t.names,[...t.values??[],...r]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=function(e,t={}){const n=void 0===t.blocks?null:t.blocks;return St(e,{evaluate:n?e=>n(e,t.scope):void 0})}(o,{blocks:t.blocks,scope:t.scope}),p=e=>Le(Le(e,h),a).map(e=>"string"==typeof e?e.replaceAll("",gn):e);n.mode=l,n.cleaned=Un(p([c])[0]),n.cleanSteps=u.map(([e,t])=>[e,Un(t)]);const m=xn(c,l);n.tokens=m.map(Un);const d=p(function(e,t="plain"){return new Ln(Zn(e,t)).parseAll().map(e=>Nn[e]??e)}(m,l));n.rawPostfix=d.map(Un);const f={},g=z(Pn(d),f);n.postfix=g,n.written=f,n.tree=q(g),Object.keys(f).length&&S(n.tree,e=>{f[e.id]&&(e.written=f[e.id])})}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function Vn(e,t={}){const n=Xn(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 Yn=(e,t)=>"string"==typeof e?Vn(e,t):function(e){if(Array.isArray(e))return q(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}(e),Jn=e=>"op"===e.type&&o(e.op)&&["vec","hat"].includes(Vt(e.op)),Kn={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",implies:"implies",iff:"if and only if",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",dot:"dot",cross:"cross",vector:"vector",hat:"hat",at:"at",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",evaluatedFrom:"evaluated from",setOf:"the set of",suchThat:"such that",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",andSoOn:"dot dot dot",emptySet:"the empty set",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"]},ei={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",arcsec:"inverse secant",arccsc:"inverse cosecant",arccot:"inverse cotangent",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"},ti=Object.fromEntries(Object.entries(Ct).map(([e,t])=>[t,e]));function ni(e,t={}){return ii(function(e,t={}){return function(e,t,n){const i=new oi({...Kn,...t.words},{...ei,...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 ii(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const si={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor","\\implies":"implies","\\iff":"iff"},ri={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class oi{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=>ii(this.speak(e))):[e.value],e,e=>ii(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("⋯"===e)return t.andSoOn;if(ri[e])return t[ri[e]];if(ti[e])return ti[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;if(/^d[A-Za-z\u03B1-\u03C9]$/.test(e))return`d ${this.symbol(e[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)}grouped(e,t,n){return this.isCompound(e)||this.audio&&n?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[i,s]=n,r=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(r.comma),...this.listed(e)]:this.listed(e));if(si[t])return[...this.speak(i),a(r[si[t]]),...this.speak(s)];if(o(t)){if(1===n.length&&"symbol"===i.type&&"vec"===Vt(t))return[a(r.vector),...this.speak(i)];if(1===n.length&&"symbol"===i.type&&"hat"===Vt(t))return[...this.speak(i),a(r.hat)];const e=this.symbol(Vt(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 Rt(s)?[...this.leftSide(i),a(r.minus),...this.quantityIfSum(s.args[1])]:[...this.leftSide(i),a(r.plus),...this.speak(s)];case"-":return Rt(s)?[...this.leftSide(i),a(r.plus),...this.speak(s.args[1])]:[...this.leftSide(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.grouped(s,"endSub","op"===s.type):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.grouped(i,"endQuantity","op"===i.type||"number"===i.type&&i.value.startsWith("-")),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):ii(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:`${ii(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 en(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 n.length?[a(r.theSet),...l()]:[a(r.emptySet)];case"setbuilder":return[a(r.setOf),..."op"===n[0].type&&"∈"===n[0].op?[...this.speak(n[0].args[0]),a("in"),...this.speak(n[0].args[1])]:this.speak(n[0]),a(r.suchThat),...this.speak(n[1])];case"evaluated":return[...this.speak(n[0]),a(`${r.comma} ${r.evaluatedFrom}`),...this.speak(n[2]),a(r.to),...this.speak(n[3])];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=en(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.listed(e)]:this.listed(e))}listed(e){return this.audio?this.quantity(e):this.speak(e)}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}leftSide(e){return this.audio&&"op"===e.type&&"?:"===e.op?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,"endQuantity")]:this.speak(e)}quantityIfSum(e){return this.quantity(e)}product(e){const[t,n]=e.args,i=this.w;if(Rt(e))return this.speak({...e,op:"neg",args:[n]});if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,i.degrees)];const s=this.audio&&"op"===t.type&&"/"===t.op&&!t.args.every(e=>"number"===e.type&&/^\d$|^10$/.test(e.value))?[this.seg(t,i.quantity),...this.speak(t),...this.closer(t,"endFraction")]:this.quantity(t);this.audio&&"op"===t.type&&"^"===t.op&&"number"!==t.args[1].type&&s.push(...this.closer(t.args[1],"endExponent"));const r=this.quantity(n);if(e.written&&[t,n].some(Jn))return[...s,this.seg(e,i[e.written]),...r];return Boolean(e.written)||this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||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)&&!Ct[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}`)]}const r=(e,...t)=>"op"===e.type&&t.includes(e.op)&&!Rt(e),o=this.grouped(t,null,r(t,"/")),a=this.isCall(t)?[s(i.comma)]:[],l=this.speak(n),c=r(n,"/")||this.audio&&r(n,"*")&&l.some(e=>e.id===n.id&&e.text===i.times),h=this.isCompound(n)||this.audio&&c;return[...o,...a,s(i.over),...h?[this.seg(n,i.quantity),...l,...this.closer(n,"endFraction")]:l]}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||"neg"===t.op||Rt(t))?[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))}`)];if(!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))){const e=this.speak(n),t=e[0]&&e[0].text.startsWith(i.quantity);return[...r,s(t?i.toThePowerOf:i.toThe),...e]}return 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,at:s,variable:r}=Yt(e),o=this.w,a=t=>this.seg(e,t),l=s?[a(`${o.comma} ${o.at}`),...this.speak(i),a(o.equals),...this.speak(s)]:[];if(r){return[...[a(1===t?o.d:`${o.d} ${2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`}`),...this.speak(n),a(o.d),...this.speak(i),a(1===t?"":2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`)],...l]}return[a(`${1===t?o.derivative:2===t?o.secondDerivative:o.nthDerivative(this.ordinal(t))} ${o.withRespectTo}`),...this.speak(i),a(o.of),...this.contents(n,"endDerivative"),...l]}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(N(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=N(n);l=e?[a(e),a(o.approaches),...this.speak(i)]:this.speak(i)}}return this.audio&&"op"===n.type&&"/"===n.op?[a(o.limitAs),...l,a(o.of),...this.grouped(n,"endLimit",!0)]:[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(e,t,n,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[Kn,ei,si,ri,ti])Object.setPrototypeOf(e,null);function ai(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":ni(Yn(e),t)}const li={"(":{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"},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 ci(e,t,n=""){const i=li[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 hi=.8,ui=.2,pi=.25,mi=.7,di="−",fi={"+":"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","\\implies":"implies","\\iff":"iff","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},gi={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},bi={"±":"±","∪":"∪","∩":"∩",mod:"mod"},$i=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],xi={arcsin:"sin",arccos:"cos",arctan:"tan",arcsec:"sec",arccsc:"csc",arccot:"cot",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},vi=[...$i,...Object.keys(xi),"ln","det"],yi={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},wi={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},ki=["int","lim","\\sumidx","\\prodidx"],Ai={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},Ei={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},_i=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,Mi=e=>"symbol"===e?.type&&_i.test(Ct[e.value]??e.value),Oi=["boxed","overline","bar","underline","cancel",...Object.keys(Ei)],qi={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},zi=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Si=e=>+e.toFixed(3)+"em",Ni=(e,t=hi,n=ui)=>({html:e,h:t,d:n});function Li(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(hi,...t.map(e=>e.h)),d:Math.max(ui,...t.map(e=>e.d))}}function Zi(e,t={}){const n=new Ci({...qi,...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):ai(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="${zi(o)}"`}>${a}${r}</span>`,h:i.h,d:i.d}}class Ci{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=Ni(this.el(e,zi(t)));return n.leaf={kind:e,content:zi(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="${zi(e.op)}"`);const s=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(s))"class"!==e&&"style"!==e&&/^[A-Za-z_:][\w:.-]*$/.test(e)&&(i+=` ${e}="${zi(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?[zi(s.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${r?` style="${zi(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){const t=/^(-?\d*\.)(\d*)\.\.$/.exec(e.value);if(t){const[,n,i]=t;let s=1;for(let e=1;2*e<=i.length;e++)if(i.slice(-e)===i.slice(-2*e,-e)){s=e;break}let r=i;for(;r.endsWith(i.slice(-s))&&r.length>=s;)r=r.slice(0,-s);const o=this.text("num",(n+r).replace(/^-/,di)),a=this.text("num",i.slice(-s));return this.wrap(e,["number"],Li(o,Ni(this.el("over",a.html),a.h+.14,a.d)))}return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,di)))}symbol(e){return Ct[e]&&(e=Ct[e]),Ai[e]?this.text("ord",Ai[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)?Ni(this.el("var",zi(e[0]))+this.el("prime",zi(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?Ni(this.el("ord","Δ")+this.el("var",e[1])):/^d[A-Za-zα-ω]$/.test(e)?Ni(this.el("ord","d")+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,leftFactor:!1}),l=fi[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),h=t=>this.wrap(e,["op",`op-${l}`],t),u=(t,n)=>Ft(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(vi.includes(n)||"log"===n)return h(this.named(e,t));if(yi[n])return h(Li(this.word(yi[n]),this.fence(this.list(i,t))));if(o(n))return h(this.custom(e,t));const p=en(e);if(p)return h(this.matrix(e,p,t));if("{}"===n&&!i.length)return h(this.text("op","∅"));if(wi[n])return h(this.fence(this.list(i,t),...wi[n]));if(("|"===n||"&"===n)&&i.length>=2&&i.every(Ti)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===n?a(e):this.fence(a(e));return h(Li(i.map((t,i)=>i?[this.text("conj","|"===n?"or":"and"),e(t)]:[e(t)]).flat()))}if(gi[n]&&2===i.length)return h(Li(u(s,"left"),this.rel(gi[n]),u(r,"right")));if(bi[n]&&2===i.length)return h(Li(u(s,"left"),this.bin(bi[n]),u(r,"right")));switch(n){case"+":if(Rt(r)){const e=r.args[1],t=Ft({op:"-"},e,"right")?this.fence(a(e)):a(e);return h(Li(u(s,"left"),this.bin(di),this.wrap(r,["op","op-mul"],t)))}return"number"===r.type&&r.value.startsWith("-")?h(Li(u(s,"left"),this.bin(di),this.wrap(r,["number"],this.text("num",r.value.slice(1))))):h(Li(u(s,"left"),this.bin("+"),this.signed(r,u(r,"right"))));case"-":return h(Li(u(s,"left"),this.bin(di),this.signed(r,u(r,"right"))));case"*":return h(this.product(e,t));case"/":return h(this.fraction(e,t));case"^":return h(this.power(e,t));case"_":{const e=Tt(s)&&c(Tt(s))<100;return h(this.script(e?this.fence(a(s)):a(s,{forceParens:!0}),null,t,a(r,{level:t.level+1})))}case"neg":return h(Li(this.text("sign",di),Pt(n,s)?this.fence(a(s)):a(s,{before:t.before})));case"pm":return h(Li(this.text("sign","±"),Pt(n,s)?this.fence(a(s)):a(s)));case"!":return h(Li(Pt(n,s)?this.fence(a(s)):a(s,{forceParens:!0}),this.text("ord","!")));case"\\not":return h(Li(this.text("sign","¬"),Pt(n,s)?this.fence(a(s)):a(s)));case"pmod":return h(Li(a(s),this.fence(Li(this.word("mod"),this.text("space",""),a(r)))));case"sqrt":return h(this.radical(a(s)));case"root":return h(this.radical(a(r),this.render(s,{level:t.level+2})));case"abs":return h(this.fence(a(s),"|","|"));case"floor":return h(this.fence(a(s),"⌊","⌋"));case"ceil":return h(this.fence(a(s),"⌈","⌉"));case"loglog":return h(Li(this.word("ln"),this.fence(Li(this.word("ln"),this.fence(a(s))))));case"logloglog":return h(Li(this.word("ln"),this.fence(Li(this.word("ln"),this.fence(Li(this.word("ln"),this.fence(a(s))))))));case"perm":return h(this.script(this.script(Ni(""),this.render(s,{level:t.level+1}),t),null,t,this.render(r,{level:t.level+1}),this.word("P")));case"comb":return h(this.fence(this.stack(a(s),a(r),!1)));case"?:":return h(this.o.cases?this.cases(e,t):Li(a(s),this.bin("?"),a(r),this.bin(":"),a(i[2])));case"sum":case"prod":{const e={op:"sum"===n?"+":"*"},t=(t,n)=>Ft(e,t,n?"right":"left")?this.fence(a(t)):a(t);return h(Li(i.map((e,i)=>i?[this.bin("sum"===n?"+":"·"),t(e,i)]:[t(e,i)]).flat()))}case"setbuilder":return h(this.fence(Li(a(s),this.bin("|"),a(r)),"{","}"));case"evaluated":{const e=e=>this.render(e,{...t,level:t.level+1});return h(this.script(this.fence(a(s),"[","]"),e(i[3]),t,e(i[2])))}case"der":return h(this.derivative(e,t));case"int":return h(this.integral(i,t));case"lim":return h(this.limit(i,t));case"\\sumidx":return h(this.bigOperator("sum",i,t));case"\\prodidx":return h(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 Li(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(Rt(e))return Li(this.text("sign",di),Pt("neg",i)?this.fence(this.render(i,t)):this.render(i,t));const s=function(e){const[t,n]=e.args;return{left:Ft(e,t,"left")&&"/"!==t.op,right:Ft(e,n,"right")&&"/"!==n.op}}(e);ki.includes(n.op)&&(s.left=!0);const r=!e.written&&Wt(n,i,s),a=function(e){for(;"op"===e.type;){if(vi.includes(e.op)||"log"===e.op||yi[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,leftFactor:!0}),c=s.right?this.fence(this.render(i,t)):this.render(i,{...t,before:t.before});return Li(l,r?Ni(this.el(a?"fnspace":"times","")):this.bin("cross"===e.written?"×":"·"),c)}named(e,t,n=null){const{op:i,args:s}=e,r="log"===i?s[1]:s[0];let o;o=xi[i]&&"power"===this.o.inverseTrig?this.script(this.word(xi[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&&ji(r),l=this.render(r,{...t,forceParens:!1,before:!1});return Li(o,a?Li(Ni(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=Vt(e.op),i=e.args;if(Oi.includes(n)&&1===i.length)return this.decorate(n,this.render(i[0],t),i[0]);return Li(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Ni(this.el("callgap","")),this.fence(this.list(i,t)))}decorate(e,t,n){switch(e){case"boxed":return Ni(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return Ni(this.el("cancel",t.html+ci("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return Ni(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return Ni(this.el("over"+(Mi(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const i=Mi(n);return Ni(this.el("accent"+(i?" accent-low":""),this.el(`accent-mark accent-${e}`,Ei[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[n,i]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&ji(n,!0)&&ji(i,!0)){const e={...t,leftFactor:!1},s=(t,n)=>"op"!==t.type||ji(t)&&(!n||"*"!==t.op||Rt(t))?this.render(t,e):this.fence(this.render(t,e)),r=Li("op"===n.type&&"neg"===n.op?this.render(n,e):s(n,!1),this.text("ord","/"),s(i,!0));return t.leftFactor?this.fence(r):r}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:${Si(i)}`),r=n?.06:0,o=pi+r/2+.1+Math.max(ui,i*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",s(e))+this.el("denom",s(t)),`vertical-align:${Si(o)}`);return Ni(a,o+Math.max(hi,i*e.h),Math.max(hi,i*t.h)+Math.max(ui,i*t.d)+.1+r/2-pi)}power(e,t){const[n,i]=e.args,s={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},r=()=>this.render(i,s);if(this.o.trigPowers&&$i.includes(n.op)&&Fi(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=Ft(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||vi.includes(n.op)||ki.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:mi,o=s?Li(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:${Si(r)}`);if(t&&!i)return Ni(e.html+this.el("sup",t.html,`font-size:${Si(r)};vertical-align:${Si(a/r)}`),Math.max(o.h,a+r*t.h),Math.max(o.d,r*t.d-a));if(i&&!t)return Ni(o.html+this.el("sub",i.html,`font-size:${Si(r)};vertical-align:${Si(-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:${Si(a)};height:${Si(h+u)}`);return Ni(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,hi)+.1+.06,i=Math.max(e.d,ui),s=n+i,r=.5+.06*(s-1),o=ci("sqrt",`${this.p}-hook`,`width:${Si(r)};left:${Si(-r)}`);let a="";if(t){const e=.8*mi;a=this.el("rootindex",t.html,`font-size:${Si(e)};vertical-align:${Si((.55*s-i)/e)}`)}return Ni(this.el("sqrt",a+this.el("radicand",o+e.html,`margin-left:${Si(r+.05)}`)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,hi)+Math.max(e.d,ui),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:ci(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${Si(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");if(!s){const t=Ni(this.el("fence fence-line",a.html+e.html+l.html),Math.max(e.h,hi),Math.max(e.d,ui));return t.fenced=!0,t}const c=`padding:${Si(r)} ${Si(l.w)} ${Si(r)} ${Si(a.w)}`,h=Ni(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,hi)+r,Math.max(e.d,ui)+r);return h.fenced=!0,h}derivative(e,t){const n=this.leibniz(e,t),{by:i,at:s}=Yt(e);if(!s)return n;const r=e.args[1],o=this.render({...r,args:[{...i,id:void 0},s]},{...t,level:t.level+1});return this.script(this.fence(n,"","|"),null,t,o)}leibniz(e,t){const{n:n,body:i,by:s,variable:r}=Yt(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=Li(a(),l()?this.script(this.render(s,h),l(),h):this.render(s,h)),p=e=>Li(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=Tt(i)&&c(Tt(i))<100,[f,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=d?this.fence(this.render(i,t),f,g):this.render(i,t);return Li(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",N(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:Xt(i)?c=o(i):(c=l(),h=a(i));break;case 3:Xt(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=Ni(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Li(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-pi,t.d+pi)+.12),a=ci(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${Si(2*o)};width:${Si(r?.38:.5)};vertical-align:${Si(pi-o)}`);if(!n&&!i)return Ni(a,pi+o,o-pi);const l=mi,c=i||Ni(""),h=n||Ni(""),u=pi+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${Si(l)}`)+this.el("script lower",h.html,`font-size:${Si(l)}`),`vertical-align:${Si(u)};height:${Si(2*o)}`);return Ni(a+p,pi+o,o-pi)}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 Li(this.word("lim"),Ni(this.el("fnspace","")),this.body(n,t));case 2:{const e=N(n),t="number"===i.type||"symbol"===i.type&&i.value.includes("∞");c=e&&t?Li(this.text("var",e),l(),a(i)):a(i);break}case 3:c=Li(a(i),l(),a(s));break;default:{const e=jt(r).toLowerCase().startsWith("r")?"+":di;c=Li(a(i),l(),this.script(a(s),this.wrap(r,["symbol"],this.text("ord",e)),o))}}return Li(this.under(this.word("lim"),c,t),this.body(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):Ni(this.el("under",e.html+this.el("script",t.html,`font-size:${Si(.7)}`)),e.h,Math.max(e.d,ui)+.05+.7*(t.h+t.d))}body(e,t){const n=Tt(e);return n&&c(n)<c("*")?this.fence(this.render(e,t)):this.render(e,t)}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.body(i,n);if(!this.o.display||n.level>0){const t=.55,i=ci(e,`${this.p}-bigsign`,`height:${Si(2*t)};width:${Si(.8)};vertical-align:${Si(pi-t)}`);return Li(this.script(Ni(i,pi+t,t-pi),l,n,a),c)}const h=.68,u=mi,p=ci(e,`${this.p}-bigsign`,`height:${Si(1.36)};width:${Si("sum"===e?1:1.05)}`),m=l?1.01+u*l.d:pi-h,d=e=>this.el("script",e.html,`font-size:${Si(u)}`),f=this.el("bigop",(l?d(l):"")+p+(a?d(a):""),`vertical-align:${Si(m)}`);return Li(Ni(f,.93+(l?.08+u*(l.h+l.d):0),h-pi+(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(hi,...e.map(e=>e.h)),d:Math.max(ui,...e.map(e=>e.d))})),r=s.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=pi+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"],Ni(i)).html:i}).join(""),l=t[0].length,c=Ni(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${Si(o)}`),pi+r/2,r/2-pi),[h,u]=Kt[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),Li(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=pi+r/2-s[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=Ni(this.el("cases",a,`vertical-align:${Si(o)}`),pi+r/2,r/2-pi);return this.fence(l,"{","")}}function ji(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||en(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!Rt(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Ii(e)||"*"===e.op&&ji(e,t)):ji(e.args[0],!0)&&("neg"===e.op||ji(e.args[1],!0)))}const Ri=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],Ti=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&Ri.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(Ti)),Ii=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(Ct[e.value])),Fi=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[fi,gi,bi,xi,yi,wi,Ai,Ei])Object.setPrototypeOf(e,null);const Pi=e=>z(e).join(" ");function Wi(e,t){const n=new Set;Bi(e,t,n);const i=[];return S(e,e=>{n.has(e)&&i.push(e)}),i}function Bi(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>Bi(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const i=Pi(Vn(t));return void S(e,e=>{Pi(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=Pi(t);S(e,e=>{e!==t&&Pi(e)!==i||n.add(e)})}}else S(e,(e,i)=>{t(e,i)&&n.add(e)});else S(e,e=>{e.id===t&&n.add(e)})}function Di(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 Ui(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Vn(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return q(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return S(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),Di(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Hi(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var Gi='/*\n * Inline Math stylesheet. Everything is under .mv; colors 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 color\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, .mv-conj { 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-conj { margin: 0 0.6em; } /* x = 2 or x = 3 */\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-radicand { display: inline-block; position: relative; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n/* the hook, in the radicand\'s left margin (layout.js sets its width and that margin): from the bar\'s center\n (just below the middle of the 0.06em border above the box) to the bottom of what it holds, so the tip always meets the bar */\n.mv-hook { position: absolute; top: -0.02em; height: calc(100% + 0.02em); overflow: visible; } /* a hair below the center: never above the bar */\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/* around one line: inline, placed from the baseline like a typed bracket (0.25em below it, 0.75em above),\n not stretched over the line box, which sits higher or lower in every font; the margins keep the widths */\n.mv-fence-line > .mv-delim { position: static; display: inline-block; vertical-align: -0.25em; height: 1em; }\n.mv-fence-line > svg.mv-delim-l { margin: 0 0.07em 0 0.03em; }\n.mv-fence-line > svg.mv-delim-r { margin: 0 0.03em 0 0.07em; }\n.mv-fence-line > span.mv-delim-l { margin: 0 0.08em 0 0.06em; }\n.mv-fence-line > span.mv-delim-r { margin: 0 0.06em 0 0.08em; }\n.mv-fence-line > .mv-delim.mv-vert.mv-delim-l { margin: 0 0.11em 0 0.07em; }\n.mv-fence-line > .mv-delim.mv-vert.mv-delim-r { margin: 0 0.07em 0 0.11em; }\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; position: relative; padding-top: 0.14em; }\n.mv-over::before { content: \'\'; position: absolute; left: 0; right: 0; top: 0.21em; border-top: 0.06em solid currentColor; } /* metric */\n.mv-over-low::before { top: 0.48em; }\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.27em; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; } /* metric: measured over F, h, A */\n/* ˆ ˜ ˙ ¨ are spacing marks that sit high in their em: full size, pulled down onto the letter */\n.mv-accent-hat, .mv-accent-widehat, .mv-accent-tilde, .mv-accent-dot, .mv-accent-ddot { font-size: 1em; line-height: 1; top: 0.02em; }\n/* over an italic letter the mark leans with it, right of the box\'s center */\n.mv-accent:has(> .mv-var) > .mv-accent-mark { transform: translateX(0.1em); }\n/* a letter with no ascender (x, u, α; layout.js adds -low): the mark comes down to its top */\n.mv-accent-low > .mv-accent-mark { top: 0.08em; }\n.mv-accent-low > .mv-accent-hat, .mv-accent-low > .mv-accent-widehat, .mv-accent-low > .mv-accent-tilde, .mv-accent-low > .mv-accent-dot, .mv-accent-low > .mv-accent-ddot { top: 0.31em; }\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 colors) 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 math (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 Qi=Gi;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Gi,document.head.append(e)}return e.CSS=Qi,e.DEFAULTS=qi,e.layout=Zi,e.numberTree=Di,e.select=Wi,e.toHTML=function(e,t={}){const n=Ui(e,t);return Zi(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(Hi(i))for(const n of Wi(e,t))a.set(n,`color:${i}`);const l=new Set(void 0===i?[]:Wi(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=Ui,e}({});