@mathzetta/inlinemath 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +64 -20
  2. package/dist/cas.external.js +2 -2
  3. package/dist/cas.js +2 -2
  4. package/dist/chunks/calculate-Cz87Lt0N.js +2 -0
  5. package/dist/chunks/draw-Bev17BJJ.js +2 -0
  6. package/dist/chunks/edit-C65xXzo8.js +2 -0
  7. package/dist/chunks/edit-M68aRA5o.js +2 -0
  8. package/dist/chunks/{html-CvuSyhzk.js → html-BimAqn7x.js} +2 -2
  9. package/dist/chunks/html-CupluJSh.js +2 -0
  10. package/dist/chunks/lite-3Fb-OHbt.js +2 -0
  11. package/dist/inlinemath-cas.external.global.min.js +2 -2
  12. package/dist/inlinemath-cas.global.min.js +2 -2
  13. package/dist/inlinemath-lite-calc.global.min.js +2 -2
  14. package/dist/inlinemath-lite.external.global.min.js +2 -2
  15. package/dist/inlinemath-lite.global.min.js +2 -2
  16. package/dist/inlinemath.css +32 -1
  17. package/dist/inlinemath.external.global.min.js +2 -2
  18. package/dist/inlinemath.external.js +2 -2
  19. package/dist/inlinemath.global.min.js +2 -2
  20. package/dist/inlinemath.js +2 -2
  21. package/dist/lite-calc.js +2 -2
  22. package/dist/lite.external.js +2 -2
  23. package/dist/lite.js +2 -2
  24. package/dist/markdown.external.js +2 -2
  25. package/dist/markdown.js +2 -2
  26. package/inlinemath.css +32 -1
  27. package/package.json +3 -3
  28. package/src/cas.js +25 -15
  29. package/src/edit.js +96 -0
  30. package/src/glyphs.js +2 -0
  31. package/src/index.d.ts +2 -2
  32. package/src/index.js +1 -1
  33. package/src/layout.js +55 -11
  34. package/src/markdown.d.ts +2 -2
  35. package/src/markdown.js +354 -39
  36. package/src/mathzetta.js +2 -1
  37. package/src/types.d.ts +77 -6
  38. package/src/variables.js +228 -0
  39. package/src/view.js +226 -6
  40. package/dist/chunks/calculate-BX9lJ7Ff.js +0 -2
  41. package/dist/chunks/draw-Cm4exbg7.js +0 -2
  42. package/dist/chunks/html-DWtfytjA.js +0 -2
  43. package/dist/chunks/lite-Bj_L6w2g.js +0 -2
@@ -1,2 +1,2 @@
1
- /* Inline Math 0.1.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
2
- var InlineMath=function(e){"use strict";const t=-1,n={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt:r(1),abs:r(1),floor:r(1),ceil:r(1),ln:r(1),loglog:r(1),logloglog:r(1),expm1:r(1),sin:r(1),cos:r(1),tan:r(1),csc:r(1),sec:r(1),cot:r(1),sinh:r(1),cosh:r(1),tanh:r(1),arcsin:r(1),arccos:r(1),arctan:r(1),arcsinh:r(1),arccosh:r(1),arctanh:r(1),random:r(0),log:r(2),root:r(2),atan2:r(2),round:r(2),fixed:r(2),perm:r(2),comb:r(2),der:r(2),max:r(t),min:r(t),gcd:r(t),mean:r(t),sum:r(t),prod:r(t),int:r(t),lim:r(t),"\\sumidx":r(t),"\\prodidx":r(t),"()":i(),"[]":i(),"{}":i(),"(]":i(),"[)":i(),"=":{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 r(e){return{prec:100,assoc:"none",arity:e,fixity:"prefix"}}function i(){return{prec:5,assoc:"left",arity:t,fixity:"none",group:!0}}const s="\\:",o=e=>"string"==typeof e&&e.startsWith(s)&&e.length>2;function a(e){return Object.prototype.hasOwnProperty.call(n,e)?n[e]:o(e)?l:void 0}const l=r(t),c=e=>a(e)?.prec;const h=100,u={ln:h,log:h,loglog:h,logloglog:h,sqrt:h,sqrtpow:h,pow:h,expm1:h,der:h,lim:h,int:h,round:h,fixed:h,floor:h,ceil:h,abs:h,random:h,sum:h,prod:h,"\\sumidx":h,"\\prodidx":h,perm:h,comb:h,"\\perm":h,"\\comb":h,"\\binom":h,max:h,min:h,gcd:h,mean:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"?:":10,"?":9,",":5},p=e=>Object.prototype.hasOwnProperty.call(u,e),f=new Set(["^","?:","?","log"]),m=["(","{","["],g=[")","}","]"];function d(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[u])Object.setPrototypeOf(e,null);const b=e=>({type:"number",value:String(e)}),$=e=>({type:"symbol",value:e}),y=(e,t)=>({type:"op",op:e,args:t}),x=['"',"'","`"];function w(e){return d(e,!0)?b(e):x.includes(e[0])?{type:"string",value:e}:$(e)}const v={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function M(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],r=[];if(e.forEach((e,i)=>{const s=v[e]??String(e),o=a(s);if(!o)return n.push({...w(s),id:i}),void r.push(1);let l=o.arity;if(l===t){const e=n.pop();if(r.pop(),l=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(l)||l<0)throw new Error(`'${s}' takes a variable number of arguments, so it must follow a count`)}if(n.length<l)throw new Error(`'${s}' needs ${l} operand${1===l?"":"s"}`);const c=1+Math.max(0,...r.splice(r.length-l,l));if(c>1e3)throw new Error("Nested too deeply (more than 1000 levels)");r.push(c),n.push({...y(s,n.splice(n.length-l,l)),id:i})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function k(e){const n=[];return function e(r){"op"===r.type?(r.args.forEach(e),a(r.op)?.arity===t&&n.push(String(r.args.length)),n.push(r.op)):n.push(r.value)}(e),n}function N(e){if(Array.isArray(e))return M(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}function E(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>E(n,t,e))}function _(e){let t="";return E(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[v])Object.setPrototypeOf(e,null);const A={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 O(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function I(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==O(n)}function S(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":I(e)?null:e.op}const q=(e,t,n)=>function(e,t,n){if("mod"===e&&t)return c(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const r=c(e),i=c(t);if(!r||!i)return!1;if(i!==r)return i<r;const s=a(e).assoc;return"left"===s?"right"===n:"right"===s&&"left"===n}(e.op,S(t),n);function L(e,t){const n=S(t),r=n&&a(n)?.prec;return!!r&&("!"===e?r<=a("!").prec:"\\not"===e?r<a("\\not").prec:r<70||P(t)||"\\not"===n)}function C(e,t,n={}){const r=n.left?"bracket":j(e),i=n.right?"bracket":T(t);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function z(e){return 1===e.length||Boolean(A[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function R(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function T(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&z(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||I(e)?"sign":"/"===t?"frac":a(t)?.group||R(e)?"bracket":F(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?R(e.args[0])?"bracket":T(e.args[0]):["*","sum","prod","perm"].includes(t)?T(e.args[0]):"other"}function j(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&z(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||R(e)||F(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?j(e.args[e.args.length-1]):"other"}function F(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function P(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||I(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!q(e,e.args[0],"left")&&P(e.args[0])}const Z=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),B=e=>e.slice(2);function W(e){const t=e.args[1];let n=0,r=e;for(;"op"===r.type&&"der"===r.op&&D(r.args[1],t);)n++,r=r.args[0];return{n:n,body:r,by:t,variable:"symbol"===r.type&&z(r.value)}}const D=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,U=new Set(["<",">","≤","≥","=","≠"]);function H(e){if("op"!==e.type||!U.has(e.op)||2!==e.args.length)return null;const[t,n]=e.args;if("op"!==t.type||!U.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[H(t)??t,{type:"op",op:e.op,args:[t.args[1],n]}]}}for(const e of[A])Object.setPrototypeOf(e,null);function G(e){const t=new Map;for(const[n,r,i]of e)if(n&&""!==n.trim()&&(t.set(n,r),!i))for(const e of V(n))t.get(e)||t.set(e,r);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 r="",i=0;for(;i<e.length;){const s=X(n,e,i);s?(r+=t.get(e.slice(i,i+s)),i+=s):r+=e[i++]}return r}}function X(e,t,n){let r=e,i=0;for(let e=n;e<t.length&&(r=r.get(t[e]),r);e++)r.end&&(i=e-n+1);return i}function V(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),Q(e)]);return t.delete(e),t}function Q(e){let t="",n=!1;for(const r of e){const e=r>="a"&&r<="z",i=r>="A"&&r<="Z";t+=!n&&e?r.toUpperCase():r,n=e||i}return t}const J="({[",K=")}]";function Y(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 ee(e,t){const n=[];let r=0,i=0;for(let s=0;s<e.length;s++)J.includes(e[s])?r++:K.includes(e[s])?r--:0===r&&e.startsWith(t,s)&&(n.push(e.slice(i,s)),s+=t.length-1,i=s+1);return n.push(e.slice(i)),n}function te(e,t,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(J.includes(e[n]))r++;else if(K.includes(e[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(e)))return n;return-1}function ne(e,t){let n=0;for(let r=t;r<e.length;r++)if(J.includes(e[r]))n++;else if(K.includes(e[r])&&--n<0)return r;return e.length}function re(e,t){let n=1;for(let r=t+1;r<e.length;r++)if("?"===e[r])n++;else if(":"===e[r]&&0===--n)return e.slice(0,t+1)+"("+e.slice(t+1,r)+")?:"+e.slice(r+1);return e}function ie(e){for(let t=2;t<e.length;t++)if("g"===e[t]&&"log"===e.slice(t-2,t+1))if("_"===e[t+1]){if(J.includes(e[t+2]))continue;const n=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(e.slice(t+2))?.[0];if(!n)continue;const r=t+2+n.length;e=e.slice(0,t+2)+"{"+n+"}"+e.slice(r)}else if("("===e[t+1]){let n=1,r=0,i="",s="",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]?r++:0===r?i+=e[a]:s+=e[a]}1===r&&(e=e.slice(0,t+1)+"_{"+s+"}("+i+")"+e.slice(o+1))}return e}function se(e){const t="⌈"===e[0]?"ceil":"floor";let n=1;for(let r=1;r<e.length;r++)if("⌊"===e[r]||"⌈"===e[r]?n++:"⌋"!==e[r]&&"⌉"!==e[r]||n--,0===n)return t+"("+e.slice(1,r)+")"+e.slice(r+1);return e}function oe(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 r=e.slice(0,n),i=e[n+1];if("{"===i||"("===i)return i+r+","+e.slice(n+2);const s=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(e.slice(n+1))?.[0]??"";return"{"+r+","+s+"}"+e.slice(n+1+s.length)}return e}function ae(e){const t=e.indexOf("}"),n=e.indexOf("{");if(t<0||n>=0&&n<t)return!1;const r=e.slice(0,t);if(!r.includes("matrix"))return!1;const i=e.indexOf("\\end{"+r+"}"),s=e.indexOf("\\begin{"+r+"}",t+1);if(i<0||-1!==s&&s<i)return!1;const o=e.slice(t+1,i).trim().split("\\\\").map(e=>e.trim()).filter(e=>e.length).map(e=>"["+e.replace(/&/g,", ")+"]");return"["+o.join(", ")+"]"+e.slice(i+6+r.length)}function le(e,t){if("{"!==e[t+1])return[e[t+1],t+2];let n=1,r="";for(let i=t+2;i<e.length;i++){if("{"===e[i])n++;else if("}"===e[i]&&0===--n)return[r,i+1];r+=e[i]}return[r,e.length]}function ce(e){const{lower:t,upper:n,next:r}=function(e){let t="",n="",r=0;return"_"===e[0]&&([t,r]=le(e,0),"^"===e[r]&&([n,r]=le(e,r))),{lower:t,upper:n,next:r}}(e),i=e.slice(r),s=e=>e.replace(/\\,/g,"").replace(/\\!/g,"");let o,a="",l="",c=i.indexOf("\\mathrm{d}");if(c>=0){o=i.slice(0,c);const e=/^\{([^{}]*)\}/.exec(i.slice(c+10));a=e?e[1]:i[c+10],l=i.slice(c+10+(e?e[0].length:1))}else(c=function(e){let t=0;for(let n=0;n<e.length;n++)if(J.includes(e[n]))t++;else if(K.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}(i))>=0?(o=i.slice(0,c),a=i[c+1],l=i.slice(c+2)):o=i;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=[...s(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("+(s(o)||"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function he(e){const t=e[0];if(!(t>="A"&&t<="Z"||t>="a"&&t<="z"||t>="α"&&t<="ω"))return!1;const n=e.slice(2);let r=1;for(let e=0;e<n.length;e++)if(K.includes(n[e])?r--:J.includes(n[e])&&r++,0===r)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function ue(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const pe=/[A-Za-z\u0370-\u03FF]/;function fe(e,t){if("{"!==e[t])return null;let n=0;for(let r=t;r<e.length;r++)if("{"===e[r])n++;else if("}"===e[r]&&0===--n)return[e.slice(t+1,r),r+1];return null}function me(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function ge(e,t){const n=e.replace(/\\mathrm\{d\}/g,"d"),r=t.replace(/\\mathrm\{d\}/g,"d"),i=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(n),s=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(r);return i&&s?{n:Number(i[1]??1),of:i[2],by:s[1]}:null}function de(e,t){if(J.includes(e[t])){let n=0;for(let r=t;r<e.length;r++)if(J.includes(e[r]))n++;else if(K.includes(e[r])&&0===--n)return[e.slice(t,r+1),r+1];return[e.slice(t),e.length]}let n=0;for(let r=t;r<e.length;r++)if(J.includes(e[r]))n++;else{if(K.includes(e[r])&&--n<0)return[e.slice(t,r),r];if(0===n&&("="===e[r]||","===e[r]))return[e.slice(t,r),r]}return[e.slice(t),e.length]}const be=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const $e="strtktk",ye="ABCDEFGHIJ",xe=e=>$e+[...String(e)].map(e=>ye[e]).join("");function we(e,t){let n=!1;for(let r=t+1;r<e.length;r++)if(n)n=!1;else if("\\"===e[r])n=!0;else if(e[r]===e[t])return r;return e.length-1}function ve(e,t){if(!t||0===t.size)return e;const n=[...t].sort((e,t)=>t[0].length-e[0].length);return e.map(e=>{for(const[t,r]of n)e=e.split(t).join(r);return e})}const Me={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { let r = 1; for (let i = n - k + 1; i <= n; i++) r *= i; return r; })",comb:"((n, k) => { let r = 1; for (let i = 1; i <= k; i++) r = r * (n - k + i) / i; return r; })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})"};for(const e of[Me])Object.setPrototypeOf(e,null);const ke="([{",Ne=")]}";function Ee(e,t){let n=0;for(let r=t;r<e.length;r++)if(ke.includes(e[r]))n++;else if(Ne.includes(e[r])&&0===--n)return r;return-1}function _e(e){if(!e.trim())return[];const t=[];let n=0,r=0;for(let i=0;i<e.length;i++)ke.includes(e[i])?n++:Ne.includes(e[i])?n--:","===e[i]&&0===n&&(t.push(e.slice(r,i).trim()),r=i+1);return t.push(e.slice(r).trim()),t}function Ae(e,t,n){const r=[...e.matchAll(t)];for(let t=r.length-1;t>=0;t--){const i=r[t],s=i.index+i[0].length-1,o=Ee(e,s);if(o<0)continue;const a=n(_e(e.slice(s+1,o)),i,e.slice(o+1));if(null==a)continue;const[l,c=0]=Array.isArray(a)?a:[a];if((e=e.slice(0,i.index)+l+e.slice(o+1+c)).length>1e5)throw new Error("The expression expands too much when read")}return e}const Oe=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),Ie=e=>`(${e})`,Se=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(Ie).join(" & ")})`,OR:e=>e.length&&`(${e.map(Ie).join(" ∨ ")})`,NOT:e=>1===e.length&&`(!(${e[0]}))`,XOR:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,LOG:e=>2===e.length?`log_{${e[1]}}(${e[0]})`:1===e.length&&`log_{10}(${e[0]})`,ATAN2:e=>2===e.length&&`atan2(${e[1]}, ${e[0]})`,INT:e=>1===e.length&&`floor(${e[0]})`,FIXED:e=>(1===e.length||2===e.length)&&`fixed(${e[0]}, ${e[1]??2})`,"FLOOR.MATH":e=>1===e.length&&`floor(${e[0]})`,"CEILING.MATH":e=>1===e.length&&`ceil(${e[0]})`,FACT:e=>1===e.length&&`((${e[0]})!)`,COMBIN:e=>2===e.length&&`comb(${e.join(", ")})`,PERMUT:e=>2===e.length&&`perm(${e.join(", ")})`,AVERAGE:e=>`mean(${e.join(", ")})`,SUM:e=>`sum(${e.join(", ")})`,PRODUCT:e=>`prod(${e.join(", ")})`,MAX:e=>`max(${e.join(", ")})`,MIN:e=>`min(${e.join(", ")})`,MEDIAN:e=>`median(${e.join(", ")})`,"STDEV.P":e=>`stdev(${e.join(", ")})`,STDEVP:e=>`stdev(${e.join(", ")})`,CEILING:e=>(1===e.length||2===e.length&&"1"===e[1].trim())&&`ceil(${e[0]})`,RAND:e=>!e.length&&"random()",ISNUMBER:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,LOG10:e=>1===e.length&&`log_{10}(${e[0]})`};const Le={POWER:"pow",SQRT:"sqrt",ABS:"abs",LN:"ln",EXP:"exp",FLOOR:"floor",CEIL:"ceil",CEILING:"ceil",ROUND:"round",GREATEST:"max",LEAST:"min",MOD:"mod",ATAN2:"atan2",FACTORIAL:"factorial",SIN:"sin",COS:"cos",TAN:"tan",SEC:"sec",CSC:"csc",COT:"cot",ASIN:"asin",ACOS:"acos",ATAN:"atan",SINH:"sinh",COSH:"cosh",TANH:"tanh",ASINH:"asinh",ACOSH:"acosh",ATANH:"atanh",COMB:"comb",PERM:"perm",GCD:"gcd",DERIVATIVE:"derivative",LIMIT:"limit",UNION:"union",EXPM1:"expm1",TRUNC:"trunc",SUMMATION:"sum"},Ce="strtktk[A-J]+";function ze(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${Ce})\\s*\\|\\|\\s*(${Ce})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${Ce},\\s*${Ce}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const r=Ee(e,n),i=r>0&&t.exec(e.slice(n,r+1));if(!i)continue;const[,s,o]=i,a={[`${s} = TRUNC(${s})`]:"ℤ",[`${s} = TRUNC(${s}) AND ${s} > 0`]:"ℕ",[`ABS(${s}) < ∞`]:"ℝ"}[o.trim()];a&&(e=`${e.slice(0,n)}((${s}) ∈ ${a})${e.slice(r+1)}`)}e=Ae(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=Ae(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,r=/\bEND\b/i.exec(e.slice(n));if(!r)return e;const i=e.slice(n+4,n+r.index).split(/\b(WHEN|THEN|ELSE)\b/i).map(e=>e.trim()),s=[];let o="null";for(let e=1;e<i.length;e+=2){const t=i[e].toUpperCase();"WHEN"===t?s.push([i[e+1],i[e+3]]):"ELSE"===t&&(o=i[e+1])}const a=s.reduceRight((e,[t,n])=>`((${t}) ? (${n}) : ${e})`,Ie(o));e=e.slice(0,n)+a+e.slice(n+r.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=>Le[e]??e);for(const[t,n]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let r=t.exec(e);r;r=t.exec(e)){const i=r.index+r[0].length-1,s=Ee(e,i);if(s<0)break;e=`${e.slice(0,r.index)}${n} {${e.slice(i+1,s)}}${e.slice(s+1)}`,t.lastIndex=0}return e.replace(/<>/g," ≠ ")}const Re={sin:"sin",cos:"cos",tan:"tan",sinh:"sinh",cosh:"cosh",tanh:"tanh",arcsin:"asin",arccos:"acos",arctan:"atan",arcsinh:"asinh",arccosh:"acosh",arctanh:"atanh",arctan2:"atan2",sqrt:"sqrt",cbrt:"cbrt",exp:"exp",expm1:"expm1",log:"log",log2:"log2",log10:"log10",floor:"floor",ceil:"ceil",round:"round",power:"pow",abs:"abs",absolute:"abs",fabs:"abs",pi:"PI",e:"E",gcd:"gcd"},Te={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc"};function je(e){return e=(e=e.replace(/(?<![\w.])(?:np|numpy)\.random\.random\(\s*\)|(?<![\w.])random\.random\(\s*\)/g,"Math.random()")).replace(/(?<![\w.])(?:np|numpy)\.(\w+)/g,(e,t)=>Re[t]?`Math.${Re[t]}`:Te[t]?Te[t]:{inf:"∞",nan:"NaN"}[t]??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)=>Pe[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>Pe[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>Ze[t]??Fe[t]??e)}(e=(e=(e=e.replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>({inf:"∞",nan:"NaN"}[t]??t))).replace(/(?<![\w.])Number\.(isInteger|isFinite)\b/g,(e,t)=>t.toLowerCase())).replace(/(?<![\w.])scipy\.(?:special|integrate)\.(\w+)/g,"$1")),(e=e.replace(/\bMZ_INFINITY\b/g,"∞")).replace(/(?<![\w.])mz_(?=\w+\s*\()/g,"")}const Fe={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Pe={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},Ze={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1"},Be={open:"()",Lopen:"(]",Ropen:"[)"};const We=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?_e(t[1]):null},De=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Ue=e=>We(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]}) ∈ ${Se(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${Se(e[0])})`,isclose:e=>e.length>=2&&`((${e[0]}) ≈ (${e[1]}))`,isfinite:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,isinteger:e=>1===e.length&&`((${e[0]}) ∈ ℤ)`,factorial:e=>1===e.length&&`((${e[0]})!)`,union:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,union_:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,intersection:e=>2===e.length&&`((${e[0]}) ∩ (${e[1]}))`,sq:e=>1===e.length&&`((${e[0]})^2)`,cube:e=>1===e.length&&`((${e[0]})^3)`,fract:e=>1===e.length&&`((${e[0]}) - floor(${e[0]}))`,inversesqrt:e=>1===e.length&&`(1/sqrt(${e[0]}))`,mod:e=>2===e.length&&`((${e[0]}) \\mod (${e[1]}))`,atan:e=>2===e.length&&`atan2(${e[0]}, ${e[1]})`,exp2:e=>1===e.length&&`((2)^(${e[0]}))`,trunc:e=>1===e.length&&`((${e[0]}) - ((${e[0]}) \\mod 1))`,vec2:e=>`(${e.join(", ")})`,vec3:e=>`(${e.join(", ")})`,vec4:e=>`(${e.join(", ")})`,derivative:e=>e.length>=2&&`der(${e.join(", ")})`,sympy_rational:e=>2===e.length&&`((${e[0]})/(${e[1]}))`,sympy_value:e=>1===e.length&&`(${e[0]})`,sympy_eq:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,sympy_ne:e=>2===e.length&&`((${e[0]}) ≠ (${e[1]}))`,sympy_and:e=>e.length&&`(${e.map(Ie).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(Ie).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(We);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:De("[]"),sympy_interval_open:De("()"),sympy_interval_Lopen:De("(]"),sympy_interval_Ropen:De("[)"),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=Ue(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&&Ue(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&&Ue(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 r=_e(n[3]),[i,s]=1===r.length?["0",r[0]]:r,o=/\s*\+\s*1$/.test(s)?s.replace(/\s*\+\s*1$/,""):`(${s}) - 1`;return`(\\${e}_{${n[2]}=${i}}^{${o}} (${n[1]}))`}}for(const e of[qe,Le,Re,Te,Fe,Pe,Ze,Be,He])Object.setPrototypeOf(e,null);const Xe=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Ve=e=>e.trim().split(/\s+/).join(String.raw`\s+`),Qe=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="[<>≤≥=≠≈]",Ye=[["is non-negative","≥ 0"],["is nonnegative","≥ 0"],["is not negative","≥ 0"],["is non-positive","≤ 0"],["is nonpositive","≤ 0"],["is not positive","≤ 0"],["is positive","> 0"],["is negative","< 0"],["is non-zero","≠ 0"],["is nonzero","≠ 0"],["is not zero","≠ 0"],["is zero","= 0"],["is a whole number","∈ ℤ"],["is an integer","∈ ℤ"],["is not an integer","∉ ℤ"],["is a natural number","∈ ℕ"],["is a real number","∈ ℝ"],["is real","∈ ℝ"],["is a rational number","∈ ℚ"],["is rational","∈ ℚ"]];const et=G([[" 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 ","→"],["===","=...="]]),tt=G([["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["\\downarrow","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot","*"],["\\times","*"],["×","*"],["·","*"],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],["log2(","log_{2}("],["log3(","log_{3}("],["log4(","log_{4}("],["log5(","log_{5}("],["log6(","log_{6}("],["log7(","log_{7}("],["log8(","log_{8}("],["log9(","log_{9}("],["log10(","log_{10}("],["log_10","log_{10}"],["\\log2(","log_{2}("],["\\log3(","log_{3}("],["\\log4(","log_{4}("],["\\log5(","log_{5}("],["\\log6(","log_{6}("],["\\log7(","log_{7}("],["\\log8(","log_{8}("],["\\log9(","log_{9}("],["\\log10(","log_{10}("],["\\log_10","log_{10}"],["log2{","log_{2}{"],["log3{","log_{3}{"],["log4{","log_{4}{"],["log5{","log_{5}{"],["log6{","log_{6}{"],["log7{","log_{7}{"],["log8{","log_{8}{"],["log9{","log_{9}{"],["log10{","log_{10}{"],["\\log2{","log_{2}{"],["\\log3{","log_{3}{"],["\\log4{","log_{4}{"],["\\log5{","log_{5}{"],["\\log6{","log_{6}{"],["\\log7{","log_{7}{"],["\\log8{","log_{8}{"],["\\log9{","log_{9}{"],["\\log10{","log_{10}{"],["\\log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⊕"," \\xor "],["∞","∞"],["⋅","*"],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0],...function(){const e=[],t=(t,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const e of["","h"]){const r=n+e,i="arc"+n+e;e&&(t("Math."+r,r),t("\\"+r,r));for(const n of["^-1","^{-1}","-1"])t("\\"+r+n,i),t(r+n,i),e||t("Math."+r+n,i);e||t("\\a"+r,i),t("\\arc"+r,i),t("Math.a"+r,i),t("Math.arc"+r,i)}return e}()]),nt=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=function(e){const t="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";e=(e=(e=e.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${t})(?=\\s*\\^)`,"gu"),"$1(-$2)");for(let n=!0;n;){const r=e;n=(e=e.replace(new RegExp(`(^|[^\\p{L}\\p{N}_.)§])(${t}\\s*\\^\\s*${t})(?=\\s*\\^)`,"u"),"$1($2)"))!==r}return Ae(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>qe[t[1]]?.(e)||null)}(e)),e=function(e){e=Ae(e,Oe("quad"),(e,t,n)=>{const r=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(e[0]??"");if(!r||3!==e.length)return null;const i=/^\s*\[\s*0\s*\]/.exec(n);return[`int(${r[2]}, ${r[1]}, ${e[1]}, ${e[2]})`,i?i[0].length:0]}),e=Ae(e,Oe(Object.keys(He).join("|")),(e,t)=>He[t[1]](e)||null);for(let t=(e=Ae(e,Oe("float"),(e,t,n)=>{const r=/^\s*\.is_integer\(\s*\)/.exec(n);return r&&1===e.length?[`((${e[0]}) ∈ ℤ)`,r[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,r=Ee(e,n);let i=t;if(Ne.includes(e[t-1])){let n=0;for(i=t-1;i>=0;i--)if(Ne.includes(e[i]))n++;else if(ke.includes(e[i])&&0===--n)break}else for(;i>0&&/[\w.]/.test(e[i-1]);)i--;r<0||i<0||i===t||(e=`${e.slice(0,i)}((${e.slice(n+1,r)}) ∈ ${Se(e.slice(i,t))})${e.slice(r+1)}`)}return e}(e=je(e=ze(e=(e=(e=function(e){for(const[t,n]of Object.entries(Me))for(let r=e.lastIndexOf(n);r>=0;r=r>0?e.lastIndexOf(n,r-1):-1){const i=r+n.length,s="("===e[i]?Ee(e,i):-1;if(s<0)continue;let o=e.slice(i+1,s);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===t?`((${o})!)`:`${t}(${o})`;e=e.slice(0,r)+a+e.slice(s+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const n=t+10-1,r=Ee(e,n),i=e.lastIndexOf("Number(",t);r<0||i<0||Ee(e,i+7-1)!==t||(e=e.slice(0,i)+`fixed(${e.slice(i+7,t)}, ${e.slice(n+1,r)})`+e.slice(r+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,r,i,s)=>`(\\${"sum"===t?"sum":"prod"}_{${n}=${r}}^{${i}} (${s}))`)}(e)).replace(/(?<![\w.])9e999\b/g,"∞")).replace(/(?<![\w.])(\d+(?:\.\d+)?)[eE]([+-]\d+)(?![\w.])/g,"($1*10^{$2})")))),e=function(e){for(let t=0;t<50;t++){let t=!0;for(const n of e.matchAll(/\bif\b/g)){const r=n.index;let i=0,s=-1,o=e.length;for(let t=r+2;t<e.length;t++)if(ke.includes(e[t]))i++;else{if(Ne.includes(e[t])&&--i<0){o=t;break}if(0===i&&","===e[t]){o=t;break}if(0===i&&/^then\b/.test(e.slice(t))&&/\W/.test(e[t-1])){s=-2;break}0===i&&s<0&&/^else\b/.test(e.slice(t))&&/\W/.test(e[t-1])&&(s=t)}if(s<0)continue;i=0;let a=0;for(let t=r-1;t>=0;t--)if(Ne.includes(e[t]))i++;else{if(ke.includes(e[t])&&--i<0){a=t+1;break}if(0===i&&","===e[t]){a=t+1;break}}const l=e.slice(a,r).trim();if(!l)continue;const c=`((${e.slice(r+2,s).trim()}) ? (${l}) : (${e.slice(s+4,o).trim()}))`;e=e.slice(0,a)+c+e.slice(o),t=!1;break}if(t)return e}return e}(e),(e=(e=e.replace(/\b(?:True|TRUE)\b/g,"true").replace(/\b(?:False|FALSE)\b/g,"false").replace(/\b(?:None|NULL)\b/g,"null")).replace(/\^\^/g," \\xor ")).replace(/%(?=\s*(?:[(-]|[A-Za-z_][\w.]*\s*\())/g," \\mod ")):e}],["english",function(e){if(!/[A-Za-z]{2}/.test(e))return e;let t=e;const n=(e,n,r,i="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Ve(e)}\s+(${Xe})\s+(?:and|to)\s+(${Xe})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(e,t,s,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[n,r];return` ${i} ${a}${t}, ${s}${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,r,i)=>{const[s,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[n.toLowerCase()];return` ${t?"∉":"∈"} ${s}${r}, ${i}${o} `});const r=String.raw`(${Xe})\s+`;t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${Xe})\s*(%|\s+percent)?\s+of\s+(${Xe})`,"gi"),(e,t,n,r,i,s)=>`(abs((${t}) - (${s})) ${n?">":"≤"} ${i?`(${r})/100 * ${/^\d+(\.\d+)?$/.test(s)?s:`abs(${s})`}`:`(${r})`})`),t=t.replace(new RegExp(r+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${Xe})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Xe})`,"gi"),(e,t,n,r)=>`((${t}) mod (${r}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${Xe})\s+divides\s+(${Xe})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,n,r)=>`((${t}) mod 2 ${"even"===r.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[e,n]of Ye)t=t.replace(Qe(e),` ${n} `);t=t.replace(Qe("is not in")," ∉ ").replace(Qe("is in")," ∈ ").replace(Qe("is an element of")," ∈ ");for(const[e,n]of Je)t=t.replace(Qe(e),` ${n} `);t=t.replace(Qe("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)");const i={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+(${Object.keys(i).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,r)=>`(${t})^(${i[n.toLowerCase()]??r})`),t=t.replace(new RegExp(String.raw`(${Xe})\s+to\s+the\s+(${Xe})(?![\w.])`,"gi"),"($1)^($2)");const s={sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"};for(const[e,n]of Object.entries(s).sort((e,t)=>t[0].length-e[0].length))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 o=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(o(e),` ${n} `);return t}],["words",et],["spaced",function(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,r=te(e,n+2,"then");if(r<0)return e;const i=e.slice(n+2,r),s=te(e,r+4,"else"),o=ne(e,s<0?r+4:s+4),a=e.slice(r+4,s<0?o:s),l=s<0?"unchanged":e.slice(s+4,o).trim();e=`${e.slice(0,n)}((${i.trim()}) ? (${a.trim()}) : (${l}))${e.slice(o)}`}return e}(e),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,r=t+2,i="";for(;n>0&&r<e.length;)"{"===e[r]?n++:"}"===e[r]?n--:i+=e[r],r++;e=e.slice(0,t-4)+i+e.slice(r)}}return e}(e=(e=e.replace(/\(\s*\\?b?mod\s+([^()]+?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")),e=ie(e);for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=re(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}let r=t+1;for("-"===e[r]&&r++;r<e.length&&".0123456789".includes(e[r]);)r++;r===t+2&&"-"===e[t+1]&&(r=t+1),r>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,r)+"}"+e.slice(r))}return e}],["squeeze",function(e){return e.replace(/\s+/g,(t,n)=>{const r=e[n-1]??"",i=e[n+t.length]??"";return"Δ"===r?"":/[A-Za-z\u0370-\u03FF′]/.test(r)&&/[A-Za-z\u0370-\u03FF]/.test(i)?" ":""})}],["symbols",tt],["compact",function(e){e=function(e){for(let t=e.indexOf(")′");t>=0;t=e.indexOf(")′",t+1)){let n=0,r=-1;for(let i=t;i>=0;i--)if(")"===e[i])n++;else if("("===e[i]&&0===--n){r=i;break}if(r<0)continue;for(;r>0&&/[A-Za-z\u0370-\u03FF′]/.test(e[r-1]);)r--;let i=0;for(;"′"===e[t+1+i];)i++;e=e.slice(0,r)+be(e.slice(r,t+1),"x",i)+e.slice(t+1+i),t=r}return e}(e=(e=ie(e)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}")),e=function(e){for(let t=0;t<e.length;t++){const n=t>0&&pe.test(e[t-1]);let r,i=null,s=t;if(e.startsWith("frac{",t)){const n=fe(e,t+4),r=n&&fe(e,n[1]);i=r&&ge(n[0],r[0]),i&&(s=r[1])}else if("d"===e[t]&&!n){let[n,r]=me(e,t+1),o="";if(pe.test(e[r]??"")&&"/"===e[r+1]&&(o=e[r++]),"/"===e[r]&&"d"===e[r+1]&&pe.test(e[r+2]??"")){const t=e[r+2],[,a]=me(e,r+3);i={n:n,of:o,by:t},s=a}}if(i){if(i.of)r=be(i.of,i.by,i.n);else{const[t,n]=de(e,s);if(!t)continue;r=be(t,i.by,i.n),s=n}e=e.slice(0,t)+r+e.slice(s),t+=3}}return e}(e);for(let t=0;t<e.length;t++){const n=e[t],r=n=>e.slice(Math.max(0,t-n),t),i=n=>e.slice(Math.max(0,t-n),t+1);if("{"===n){if("\\begin"===r(6)){const n=ae(e.slice(t+1));n&&(e=e.slice(0,t-6)+n)}}else if("["===n)"\\sqrt"===r(5)?e=e.slice(0,t-5)+"sqrt"+oe(e.slice(t+1)):"sqrt"===r(4)&&(e=e.slice(0,t-4)+"sqrt"+oe(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+se(e.slice(t));else if("t"===n)"\\int"===i(3)&&(e=e.slice(0,t-3)+ce(e.slice(t+1)));else if("m"===n)"\\binom"===i(5)&&(e=e.slice(0,t-5)+"\\binom"+ue(e.slice(t+1)));else if("d"===n&&"dd"===i(1)&&"("===e[t+2]){const n=he(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return e.replace(/\\log/g,"log")}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]];function rt(e,t={}){if("string"!=typeof e)throw new Error("Expression must be a string");const{text:n,strings:r}=function(e){const t=new Map;let n="",r=0;for(;r<e.length;){const i=e[r];if('"'!==i&&"'"!==i&&"`"!==i){n+=e[r++];continue}let s=r+1,o="",a=!1;for(;s<e.length&&(a||e[s]!==i);)a=!a&&"\\"===e[s],o+=e[s++];const l=xe(t.size);t.set(l,i+o+i),n+=l,r=s+1}return{text:n,strings:t}}(function(e){let t="";for(let n=0;n<e.length;n++){const r=e[n];if('"'===r||"`"===r){const r=we(e,n);t+=e.slice(n,r+1),n=r}else if("'"===r)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(t[t.length-1]??""))t+="′";else{const r=we(e,n);t+=e.slice(n,r+1),n=r}else t+=r}return t}(e));let i=n.replace(/\t/g," ");t.evaluate&&(i=function(e,t,n){let r=0;for(;;){const i=e.indexOf("{{",r);if(i<0)return e;const s=it(e,i);if(s<0)return e;let o=e.slice(i+2,s).trim();for(const[e,n]of t)o=o.split(e).join(n);try{let a=n(o);if(/^["'`]/.test(a)){const e=xe(t.size);t.set(e,a),a=e}const l=e.slice(0,i).trimEnd(),c=e.slice(s+2).trimStart();/^[\d.]/.test(a)&&(/[\d.]$/.test(l)||/^[\d.]/.test(c))&&(a=`(${a})`),e=e.slice(0,i)+" "+a+" "+e.slice(s+2),r=0}catch{r=s+2}}}(i,r,t.evaluate));const s=[["strings",i]];for(const[e,t]of nt){if(i=t(i),i.length>1e5)throw new Error("The expression expands too much when read");s.push([e,i])}return{cleaned:i,stringMap:r,steps:s}}function it(e,t){let n=0;for(let r=t+2;r<e.length;r++){if(e.startsWith("}}",r)&&0===n)return r;"{"===e[r]?n++:"}"===e[r]&&n--}return-1}const st=Object.keys(u).filter(e=>100===u[e]&&/^[a-z]{2,}$/.test(e)),ot=["frac"],at=[...Object.keys(A),"pi","tau","inf","infinity","exp"],lt="\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+/),ct=new Set([...at,...lt,"true","false","null","undefined","deg","mod","pmod","NaN","Infinity"]),ht=/^[a-zA-ZͰ-Ͽ]$/,ut=new Set(["f","g","h","u","v","F","G","H"]),pt=e=>st.includes(e)||ot.includes(e),ft=[...st,...ot,...at].sort((e,t)=>t.length-e.length),mt=[...st,...ot,"pi"].sort((e,t)=>t.length-e.length);function gt(e,t=ft){const n=[];let r=0;for(;r<e.length;){const i=t.find(t=>e.startsWith(t,r))??e[r];n.push(i),r+=i.length}return n}function dt(e){if(pt(e))return!0;const t=gt(e,mt);return t.length>1&&pt(t[t.length-1])&&!ct.has(e)}function bt(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(!((r=e).length>0&&[...r].every(e=>ht.test(e)))||1===e.length||ct.has(e)||pt(e))return[e];var r;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return $t(gt(e),n);if(e.length<=2)return[...e];const i=$t(gt(e,mt),n),s=i.findIndex(e=>e.length>1);if(s<0)return[e];if("pi"===i[s]&&!i.some(e=>st.includes(e)))return 3===e.length?i:[e];const o=s;let a=0,l=0;for(const e of i.slice(s))a=1===e.length?a+1:0,l=Math.max(l,a);return o<=1&&l<=2?i:[e]}function $t(e,t){const n=e[e.length-1];return t||!st.includes(n)?e:[...e.slice(0,-1),...n]}const yt="§",xt=/[A-Za-zͰ-Ͽ′]/,wt=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function vt(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=e=>{r&&(wt(r)?n.push(...function(e,t,n){if((e=>new RegExp(`^${$e}[${ye}]+$`).test(e))(e))return[e];if(m.includes(t))return function(e,t){if(/^[a-zA-Z]′+$/.test(e))return[s+e];if("if"===e.toLowerCase())return["\\:if"];if(1===e.length)return ut.has(e)?[s+e]:[e];if(p(e))return[e];const n=bt(e,{mode:t,followed:!0});return n.length>1?n:e.length<=2?[...e]:[s+e]}(e,n);const r=void 0!==t&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(t);return bt(e,{mode:n,followed:r})}(r,e,t)):n.push(r),r="")};for(let t=0;t<e.length;t++){const o=e[t];if(o===yt){i(o);const r=e.indexOf(yt,t+1),a=e.slice(t,r+1);n.push(m.includes(e[r+1])?s+a:a),t=r;continue}if(wt(r)&&/[0-9]/.test(o)&&p(r+o)){const{op:i,end:s}=Mt(e,t,r+o);n.push(i),r="",t=s;continue}if(xt.test(o)&&"′"!==o&&d(r)&&(n.push(r),r=""),xt.test(o)&&(""===r?"′"!==o:wt(r)))r+=o;else if(/[0-9]/.test(o)&&wt(r)&&!dt(r))r+=o;else if(wt(r)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))r&&n.push(...kt(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(p(r+o)){const{op:i,end:s}=Mt(e,t,r+o);n.push(i),r="",t=s;continue}if(p(o)){i(o);const{op:r,end:s}=Mt(e,t,o);n.push(r),t=s;continue}r+=o}else i(e[t+1]),"_"===o&&n.push("_")}if(i(void 0),n.some(e=>/^:/.test(e)))throw new Error("Unmatched ':'");return n}function Mt(e,t,n){let r=t;for(;r+1<e.length&&p(n+e[r+1]);)n+=e[r+1],r++;return"!"===n&&"_"===e[r+1]&&r++,{op:n,end:r}}function kt(e,t){if(!m.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[p(t)?t:s+t]}return d(e)?[e,"*"]:p(e)||pt(e)||d(e[0])?[e]:[s+e]}const Nt=70,Et=100,_t="%mod",At=e=>m.includes(e),Ot=e=>g.includes(e),It=e=>o(e)||u[e]===Et&&"_"!==e,St=new Set(["\\comb","\\perm","comb","perm"]),qt={frac:"/","\\binom":"\\binom"},Lt={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Ct{constructor(e){this.tokens=e,this.pos=0,this.out=[],this.absDepth=0,this.frames=[]}peek(e=0){return this.tokens[this.pos+e]}next(){return this.tokens[this.pos++]}emit(...e){this.out.push(...e)}parseAll(){if(!this.tokens.length)throw new Error("Empty expression");this.parseExpression(0);const e=this.peek();if(void 0!==e)throw new Error(Ot(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){for(this.parseOperand();;){const n=this.peek();if(void 0===n||Ot(n))return;const r=this.operatorAt(n,t);if(!r||r.lbp<=e)return;r.run()}}operatorAt(e,t){if("|"===e)return this.pipe();if(","===e)return{lbp:5,run:()=>{this.next(),this.frames.length&&(this.frames[this.frames.length-1].comma=!0),this.parseExpression(5),this.emit(",")}};if("?"===e)return{lbp:9,run:()=>this.ternary()};if("mod"===e)return{lbp:u.mod,run:()=>this.modulo()};if(e===_t)return{lbp:Nt,run:()=>{this.next(),this.parseExpression(Nt),this.emit("mod")}};if("pmod"===e)return{lbp:u.pmod,run:()=>{this.next(),this.parseScript(),this.emit("pmod")}};if("?:"===e)return{lbp:10,run:()=>{throw new Error("Unmatched ':'")}};if("!"===e)return{lbp:90,run:()=>{this.next(),this.emit("!")}};if("_"===e)return{lbp:Et,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(St.has(e))return{lbp:Et,run:()=>{this.next(),this.parseExpression(Et),this.emit(e)}};const n=u[e];if(void 0!==n&&!It(e)&&"\\not"!==e&&!(e in qt)){const t=f.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&&!It(e)?71:Nt,run:()=>{this.parseExpression(Nt),this.emit("*")}}}startsOperand(e){return void 0===e||Ot(e)||"|"===e?"|"===e:e!==_t&&(!!(At(e)||It(e)||e in qt)||!p(e))}pipe(){if(this.absDepth>0)return null;let e=0;for(let t=this.pos;t<this.tokens.length;t++)"|"===this.tokens[t]&&e++;const t="|"===this.peek(1);return e%2==0&&!t&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:u["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(u["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(Nt,!0),this.emit("mod")}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const e=this.next(),t=this.tokens[this.pos-2],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(At(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Ot(n))||At(t)&&Ot(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 qt)return this.parseScript(),this.parseScript(),this.emit(qt[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(It(e))return this.functionCall(e);if(Ot(e)||p(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!d(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(Ot(this.peek()))return void this.emit("∅",e+this.next());this.frames.push({comma:!1}),this.parseExpression(0);const{comma:n}=this.frames.pop(),r=this.peek();Ot(r)&&(this.next(),n?this.emit(e+r):t&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const e=this.peek();if(At(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(It(e))return this.parseOperand();if(this.next(),void 0===e||Ot(e)||p(e))throw new Error("Missing a sub- or superscript");this.emit(e)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const e=this.out.length;this.parseScript();const t=this.out.splice(e);this.parseExpression(u["+"],!0),this.emit(...t,",","()","lim")}bigOperator(e){this.next();const t=this.out.length;this.parseScript();let n=this.out.splice(t);"^"===this.peek()&&(this.next(),this.parseScript(),n=[...n,...this.out.splice(t),","]),this.parseExpression(u["+"],!0),this.emit(...n,",","()",e)}functionCall(e){if(void 0===this.peek())return this.emit(e);let t=null;if("^"===this.peek()){this.next();const e=this.out.length;this.parseScript(),t=this.out.splice(e)}if(0===a(e)?.arity&&!At(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(At(e))return this.next(),this.bracket(e);this.parseExpression(Nt,!0)}}function zt(e,t){e=function(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n],i=e=>"string"==typeof e&&/^[a-zA-Z]$/.test(e);if(ut.has(r)&&"^ { - 1 } ("===e.slice(n+1,n+7).join(" ")){t.push(s+r+"⁻¹"),n+=5;continue}const[o,a,l]=e.slice(n+1,n+4),c=i(a)?a!==r:d(a);i(r)&&"e"!==r&&"("===o&&c&&")"===l?t.push(s+r):t.push(r)}return t}(e);const n=[];for(const r of e)p(r)||At(r)||Ot(r)||"_"===r||o(r)||d(r)?n.push(r):n.push(...Rt(r,t));return n}function Rt(e,t){const n=e=>zt(vt(e,t),t);let r=0;for(;r<e.length&&d(e.slice(0,r+1));)r++;if(0===r){if("%"===e[0])return[_t,...n(e.slice(1))];const r=e.indexOf("%");return r>0&&r<e.length-1?[...Rt(e.slice(0,r),t),_t,...n(e.slice(r+1))]:[e]}const i=e.slice(r);return"%"===i[0]?1===i.length?[e]:[e.slice(0,r),_t,...n(i.slice(1))]:[e.slice(0,r),...n(i)]}for(const e of[qt,Lt])Object.setPrototypeOf(e,null);const Tt=new Set(["()","[]","{}","(]","[)"]),jt={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠="},Ft=new Set(["round","fixed","der"]),Pt=e=>o(e)||100===u[e];function Zt(e){const n=[],r=e=>{if(!n.length)throw new Error(`'${e}' is missing an operand`);return n.pop()},i=e=>e.list?e.list:[e],s=(e,t)=>{if(e.list)throw new Error(`A list of values needs brackets around it (near '${t}')`);return e};if(e.forEach((l,c)=>{if("∅"===l)return void n.push({list:[]});if(","===l){const e=r(l),t=r(l);return void n.push({list:[...i(t),...i(e)]})}if(Tt.has(l)){const t=i(r(l));if(!t.length&&!Pt(e[c+1]))throw new Error("Empty brackets");return void n.push(y(l,t))}const h=jt[l]??l,u=a(h);if(!u){if("?"===l||"abs("===l)throw new Error(`Unmatched '${l[0]}'`);return void n.push(w(l))}let p;if(Pt(l)&&Tt.has(e[c-1])&&n[n.length-1]?.op===e[c-1])p=n.pop().args;else{let e=u.arity===t||Ft.has(h)?1:u.arity;if(n.length<e)throw new Error(`'${l}' needs ${e} operand${1===e?"":"s"}`);p=n.splice(n.length-e,e).map(e=>s(e,l))}n.push(function(e,n){switch(e){case"sqrt":if(2===n.length)return y("root",n);break;case"round":if(1===n.length)return y("round",[n[0],b(0)]);break;case"sum":case"prod":{const t=n[1];if("op"===t?.type&&"symbol"===t.args[0]?.type&&(3===n.length&&"="===t.op||2===n.length&&"∈"===t.op))return y("sum"===e?"\\sumidx":"\\prodidx",n);break}case"fixed":if(1===n.length)return y("fixed",[n[0],b(2)]);break;case"der":if(1===n.length)return y("der",[n[0],$("x")]);if(3===n.length)return function([e,t,n]){const r="number"===n.type?Number(n.value):NaN;if(!Number.isInteger(r)||r<1||r>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");let i=e;for(let e=0;e<r;e++)i=y("der",[i,t]);return i}(n);break;case"log":if("symbol"===n[0].type&&"e"===n[0].value)return y("ln",[n[1]]);break;case"lim":return y("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?{"\\+":"r","\\-":"l"}[e.args[1].value]:void 0,[n,r,i]=e;if(2===e.length&&"op"===r.type&&"→"===r.op&&t(r.args[1])){const[e,i]=r.args;return[n,e,i.args[0],$(t(i))]}return 3===e.length&&t(i)?[n,r,i.args[0],$(t(i))]:e}(n));case"\\:if":if(2===n.length||3===n.length)return y("?:",[n[0],n[1],n[2]??$("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return function(e,n){const{arity:r}=a(e);if(r===t){if(0===n.length&&!o(e))throw new Error(`'${e}' needs at least one argument`);return}if(n.length!==r){throw new Error(`'${e}' takes ${r} argument${1===r?"":"s"}, not ${n.length}`)}}(e,n),y(e,n)}(h,p))}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return s(n[0],"end")}for(const e of[jt])Object.setPrototypeOf(e,null);const Bt=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Wt=e=>/^[a-z][a-z0-9]*$/.test(e)&&p(e);function Dt(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 r=ee(e.slice(t+13,n),"\\\\").map(e=>ee(e,"&")).filter(e=>e.join("").trim());let i=null;for(let e=r.length-1;e>=0;e--){const t=r[e][0].trim(),n=Y(r[e].slice(1).join("&"));i=null!==i||n?`((${n||"true"}) ? (${t}) : ${i??"(unchanged)"})`:`(${t})`}e=e.slice(0,t)+(i??"")+e.slice(n+11)}return e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):e}let Ut=null;function Ht(e,t={}){const n={original:e};try{if("string"!=typeof e)throw new Error("Expression must be a string");const r=t.maxLength??5e3;if(e.length>r)throw new Error(`Longer than ${r} characters (options.maxLength)`);const i=/^\s*=(?!=)/.test(e);i&&(e=e.replace(/("(?:[^"]|"")*")|\$(?=[A-Za-z]{0,3}\d|[A-Za-z]{1,3}\$?\d)/g,(e,t)=>t??""));const s=i?[...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 r=new Map,i=e=>{const t=`${yt}${r.size}${yt}`;return r.set(t,e),t};e=e.replace(Bt,(e,t)=>Wt(t.trim())?` ${t.trim()}`:i(t.trim()));for(const n of[...t].sort((e,t)=>t.length-e.length)){const t=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${t}(?![A-Za-z0-9_])`,"g"),()=>i(n))}for(const t of[...n].sort((e,t)=>t.length-e.length)){const n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(e,n,r)=>i(t)+(r?" * (":n))}return{text:e,protectedNames:r}}(Dt(e),t.names,[...t.values??[],...s]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=((e,t={})=>{const n=void 0===t.blocks?Ut:t.blocks;return rt(e,{evaluate:n?e=>n(e,t.scope):void 0})})(o,{blocks:t.blocks,scope:t.scope}),p=e=>ve(ve(e,h),a);n.mode=l,n.cleaned=p([c])[0],n.cleanSteps=u,n.tokens=vt(c,l),n.rawPostfix=p(function(e,t="plain"){return new Ct(zt(e,t)).parseAll().map(e=>Lt[e]??e)}(n.tokens,l));const f=k(Zt(n.rawPostfix));n.postfix=f,n.tree=M(f)}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function Gt(e,t={}){const n=Ht(e,t);if(n.error)throw new Error(`Failed to parse expression "${r=e,"string"==typeof r&&r.length>80?`${r.slice(0,77)}…`:r}": ${n.error}`);var r;return n.tree}const Xt=(e,t)=>"string"==typeof e?Gt(e,t):N(e),Vt=e=>Array.isArray(e)&&0===e.length,Qt={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},Jt=(e,t)=>t?Jt(t,e%t):Math.abs(e),Kt={neg:e=>-e,pm:e=>[e,-e],"!":e=>{if(!Number.isInteger(e)||e<0)return NaN;if(e>170)return 1/0;let t=1;for(let n=2;n<=e;n++)t*=n;return t},"\\not":e=>!e,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,ln:Math.log,loglog:e=>Math.log(Math.log(e)),logloglog:e=>Math.log(Math.log(Math.log(e))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:e=>1/Math.sin(e),sec:e=>1/Math.cos(e),cot:e=>1/Math.tan(e),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},Yt={"+":(e,t)=>e+t,"-":(e,t)=>e-t,"*":(e,t)=>e*t,"/":(e,t)=>e/t,"^":(e,t)=>e**t,mod:(e,t)=>e%t,log:(e,t)=>Math.log(t)/Math.log(e),root:(e,t)=>t**(1/e),atan2:Math.atan2,round:(e,t)=>Math.round(e*10**t)/10**t,"±":(e,t)=>[e+t,e-t],fixed:(e,t)=>Number(e).toFixed(t),perm:(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t)||t<0||t>e)return NaN;let n=1;for(let r=e-t+1;r<=e&&n!==1/0;r++)n*=r;return n},comb:(e,t)=>{if(!Number.isInteger(e)||!Number.isInteger(t)||t<0||t>e)return NaN;t=Math.min(t,e-t);let n=1;for(let r=1;r<=t&&n!==1/0;r++)n=n*(e-t+r)/r;return Math.round(n)},"=":(e,t)=>e==t,"===":(e,t)=>e===t,"≠":(e,t)=>e!=t,"≠=":(e,t)=>e!==t,"≈":(e,t)=>Math.abs(e-t)<1e-9,"≡":(e,t)=>e===t,"∪":(e,t)=>[...new Set([...[].concat(e),...[].concat(t)])],"∩":(e,t)=>[].concat(e).filter(e=>[].concat(t).includes(e)),"<":(e,t)=>e<t,">":(e,t)=>e>t,"≤":(e,t)=>e<=t,"≥":(e,t)=>e>=t,"&":(e,t)=>e&&t,"|":(e,t)=>e||t,"\\xor":(e,t)=>Boolean(e)!==Boolean(t),"\\nor":(e,t)=>!(e||t),"\\nand":(e,t)=>!(e&&t)},en={max:e=>Math.max(...e),min:e=>Math.min(...e),sum:e=>e.reduce((e,t)=>e+t,0),prod:e=>e.reduce((e,t)=>e*t,1),mean:e=>e.reduce((e,t)=>e+t,0)/e.length,gcd:e=>e.reduce(Jt),"()":e=>e,"[]":e=>e,"{}":e=>e};const tn=5e6;let nn=0,rn=0;function sn(e,t){if(++nn>tn)throw new Error("Too much to work out");switch(e.type){case"number":return Number(e.value);case"string":return e.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(t,e.value))return t[e.value];if(Object.prototype.hasOwnProperty.call(Qt,e.value))return Qt[e.value];throw new Error(`No value for '${e.value}'`)}const n=H(e);if(n)return sn(n,t);const{op:r,args:i}=e;if("?:"===r)return sn(i[0],t)?sn(i[1],t):sn(i[2],t);if("∈"===r||"∉"===r)return function(e,t){const[n,r]=e.args,i=sn(n,t);let s;if("symbol"===r.type&&on[r.value])return s=on[r.value](i),"∈"===e.op?s:!s;if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[e,n]=r.args.map(e=>sn(e,t)),o="["===r.op[0]?i>=e:i>e,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const e=sn(r,t);s=Array.isArray(e)&&e.includes(i)}return"∈"===e.op?s:!s}(e,t);if("random"===r)return Math.random();if(("\\sumidx"===r||"\\prodidx"===r)&&3===i.length&&"op"===i[1].type&&"="===i[1].op&&"symbol"===i[1].args[0].type){const[e,n,s]=[i[0],i[1].args[1],i[2]],o=i[1].args[0].value,a=sn(n,t),l=sn(s,t);if(!Number.isFinite(a)||!Number.isFinite(l)||l-a>1e6)throw new Error(`Can't evaluate '${r}' over that range`);let c="\\sumidx"===r?0:1;for(let n=a;n<=l;n++){const i=sn(e,{...t,[o]:n});c="\\sumidx"===r?c+i:c*i}return c}if("pmod"===r){const[e,n]=i,r=sn(n,t);if("op"===e.type&&["≡","="].includes(e.op)){const[n,i]=e.args.map(e=>sn(e,t));return(n-i)%r===0}return sn(e,t)%r}const s=i.map(e=>sn(e,t));if(Kt[r]&&1===s.length)return Kt[r](s[0]);if(Yt[r]&&2===s.length)return Yt[r](s[0],s[1]);if(en[r])return en[r](s);throw new Error(`Can't evaluate '${r}'`)}const on={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":e=>Number.isInteger(e)&&e>0,"ℚ":Number.isFinite,"ℂ":e=>"number"==typeof e&&!Number.isNaN(e)};for(const e of[Qt,Kt,Yt,en,on])Object.setPrototypeOf(e,null);class an extends Error{}class ln extends Error{}const cn={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6};let hn=0,un=0;const pn=e=>e<0n?-e:e,fn=e=>0n===e?0:pn(e).toString(2).length;function mn(e,t){for(e=pn(e),t=pn(t);t;)[e,t]=[t,e%t];return e}function gn(e,t=1n){if(0n===t)throw new an("division by zero");t<0n&&(e=-e,t=-t);const n=mn(e,t)||1n;return{n:e/n,d:t/n}}const dn=gn(0n),bn=gn(1n),$n=(e,t)=>gn(e.n*t.d+t.n*e.d,e.d*t.d),yn=(e,t)=>gn(e.n*t.n,e.d*t.d),xn=(e,t)=>gn(e.n*t.d,e.d*t.n),wn=e=>({n:-e.n,d:e.d}),vn=(e,t)=>{const n=e.n*t.d-t.n*e.d;return n<0n?-1:n>0n?1:0},Mn=e=>{const t=e.n/e.d;return e.n<0n&&t*e.d!==e.n?t-1n:t};function kn(e){const t=fn(e.n),n=fn(e.d);if(t<1e3&&n<1e3)return Number(e.n)/Number(e.d);const r=BigInt(Math.max(t,n)-1e3),i=e.d>>r;return 0n===i?e.n<0n?-1/0:1/0:Number(e.n>>r)/Number(i)}function Nn(e){let t=String(e).trim(),n=1n;t.startsWith("-")&&(n=-1n,t=t.slice(1));const r=t.endsWith("..");r&&(t=t.slice(0,-2));let i=0;const s=t.search(/e/i);s>=0&&(i=Number(t.slice(s+1)),t=t.slice(0,s));const[o="",a=""]=t.split(".");if(!(/^\d*$/.test(o)&&/^\d*$/.test(a)&&o+a))throw new ln(`'${e}' is not a number`);let l;if(r&&a){let e=1;for(let t=1;2*t<=a.length;t++)if(a.slice(-t)===a.slice(-2*t,-t)){e=t;break}const t=a.slice(-e);let n=a;for(;n.endsWith(t);)n=n.slice(0,-e);const r=BigInt(n||"0"),i=BigInt(n+t);l=$n(gn(BigInt(o||"0")),gn(i-r,(10n**BigInt(e)-1n)*10n**BigInt(n.length)))}else l=gn(BigInt(o+a||"0"),10n**BigInt(a.length));return i&&(l=i>0?yn(l,gn(10n**BigInt(i))):xn(l,gn(10n**BigInt(-i)))),n<0n?wn(l):l}function En(e,t=0,n=0,r=null){return 0n===e.n?{kind:"x",c:dn,pi:0,e:0,root:null}:{kind:"x",c:e,pi:t,e:n,root:r}}const _n=(e,t=1n)=>En(gn(BigInt(e),BigInt(t))),An=En(bn,1),On=En(bn,0,1),In=e=>null!==e&&"object"==typeof e&&"x"===e.kind,Sn=e=>In(e)&&!e.pi&&!e.e&&!e.root,qn=e=>In(e)?0n===e.c.n:0===e,Ln=e=>Sn(e)&&1n===e.c.d?e.c.n:null,Cn=(e,t)=>Object.assign(e,{group:t}),zn=e=>({kind:"s",text:e});function Rn(e,t){return e&&t?e.n===t.n&&e.r===t.r:e===t}const Tn=(e,t)=>0===vn(e.c,t.c)&&e.pi===t.pi&&e.e===t.e&&Rn(e.root,t.root);function jn(e){if("number"==typeof e)return e;if(In(e)){let t=kn(e.c);return e.pi&&(t*=Math.PI**e.pi),e.e&&(t*=Math.E**e.e),e.root&&(t*=kn(gn(e.root.r))**(1/e.root.n)),t}if("boolean"==typeof e)return e?1:0;throw new ln("not a number")}function Fn(e,...t){if(Number.isNaN(e))throw new an("undefined");if(!Number.isFinite(e)&&t.every(Number.isFinite))throw new ln("too large to calculate");return e}const Pn=e=>"boolean"==typeof e?e:In(e)?0n!==e.c.n:"number"==typeof e?0!==e:Boolean(e);function Zn(e){if("bigint"==typeof e)return En(gn(e));if("number"==typeof e)return Number.isFinite(e)?En(Number.isInteger(e)&&Math.abs(e)<=Number.MAX_SAFE_INTEGER?gn(BigInt(e)):Nn(String(e))):e;if("boolean"==typeof e)return e;if("string"==typeof e)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(e.trim())?En(Nn(e)):kr(Gt(e),{});if(Array.isArray(e))return Cn(e.map(Zn),e.group||"()");if(In(e)||"function"==typeof e)return e;throw new ln(`can't use ${typeof e} as a value`)}function Bn(e){return Array.isArray(e)?e.map(Bn):e&&"s"===e.kind?e.text:"boolean"==typeof e?e:jn(e)}function Wn(e,t){if(e<2n)return e;const n=BigInt(t);let r=1n<<BigInt(Math.ceil(fn(e)/t));for(;;){const t=((n-1n)*r+e/r**(n-1n))/n;if(t>=r)return r;r=t}}function Dn(e,t,n,r=0,i=0){if(0n===n)return En(dn);const{coef:s,root:o}=function(e,t){let n=1n,r=t;const i=BigInt(e),s=r<10n**24n?1000000n:10000n;for(let e=2n;e<=s&&e*e<=r;e+=2n===e?1n:2n){const t=e**i;for(;r%t===0n;)r/=t,n*=e}const o=Wn(r,e);if(o**i===r&&(n*=o,r=1n),1n===r)return{coef:n,root:null};for(let t=e;t>=2;t--){if(e%t!==0)continue;const i=Wn(r,t);if(i**BigInt(t)===r)return{coef:n,root:{n:e/t,r:i}}}return{coef:n,root:{n:e,r:r}}}(t,n);return o&&1===o.n?En(yn(e,gn(s*o.r)),r,i):En(yn(e,gn(s)),r,i,o)}function Un(e,t){const n=yn(e.c,t.c);if(fn(n.n)+fn(n.d)>cn.bits)return null;const r=e.pi+t.pi,i=e.e+t.e;if(!e.root||!t.root)return En(n,r,i,e.root||t.root);const s=br(e.root.n,t.root.n);if(s>cn.rootIndex)return null;const o=e.root.r**BigInt(s/e.root.n)*t.root.r**BigInt(s/t.root.n);return fn(o)>4e3?null:Dn(n,s,o,r,i)}function Hn(e){if(0n===e.c.n)throw new an("division by zero");const t=En(xn(bn,e.c),-e.pi,-e.e);if(!e.root)return t;const{n:n,r:r}=e.root;return Un(t,Dn(gn(1n,r),n,r**BigInt(n-1)))}function Gn(e,t){if(0n===t){if(0n===e.c.n)throw new an("0^0 is undefined");return En(bn)}if(t<0n){const n=Hn(e);return n&&Gn(n,-t)}if((fn(e.c.n)+fn(e.c.d)+(e.root?fn(e.root.r):0))*Number(t)>cn.bits||t>100000n)return null;const n=gn(e.c.n**t,e.c.d**t),r=Number(t);if(!e.root)return En(n,e.pi*r,e.e*r);const{n:i,r:s}=e.root,o=s**(t/BigInt(i));return Dn(yn(n,gn(o)),i,s**(t%BigInt(i))||1n,e.pi*r,e.e*r)}function Xn(e,t,n){if(!Sn(e)||n>1000n)return null;const r=Gn(e,t);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new an("not a real number");o=!0,i=-i}const a=function(e,t){const n=e.n*e.d**BigInt(t-1);return fn(n)>4e3?null:Dn(gn(1n,e.d),t,n)}({n:i,d:s},Number(n));return a?o?En(wn(a.c),a.pi,a.e,a.root):a:null}function Vn(e){return t=>Array.isArray(t)?Cn(t.map(t=>Vn(e)(t)),t.group):e(t)}function Qn(e){const t=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new an("lists of different lengths");return Cn(n.map((e,n)=>t(e,r[n])),n.group)}return i?Cn(n.map(e=>t(e,r)),n.group):s?Cn(r.map(e=>t(n,e)),r.group):e(n,r)};return t}const Jn=Qn((e,t)=>In(e)&&In(t)&&function(e,t){if(0n===e.c.n)return t;if(0n===t.c.n)return e;if(e.pi!==t.pi||e.e!==t.e||!Rn(e.root,t.root))return null;const n=$n(e.c,t.c);return fn(n.n)+fn(n.d)>cn.bits?null:En(n,e.pi,e.e,e.root)}(e,t)||Fn(jn(e)+jn(t),jn(e),jn(t))),Kn=Vn(e=>In(e)?En(wn(e.c),e.pi,e.e,e.root):-jn(e)),Yn=(e,t)=>Jn(e,Kn(t)),er=Qn((e,t)=>In(e)&&In(t)&&Un(e,t)||Fn(jn(e)*jn(t),jn(e),jn(t))),tr=Qn((e,t)=>{if(qn(t))throw new an("division by zero");if(In(e)&&In(t)){const n=Hn(t),r=n&&Un(e,n);if(r)return r}return Fn(jn(e)/jn(t),jn(e),jn(t))}),nr=Qn((e,t)=>{if(In(e)&&Sn(t)){const{n:n,d:r}=t.c,i=1n===r?Gn(e,n):Xn(e,n,r);if(i)return i}const n=jn(e),r=jn(t);if(0===n&&0===r)throw new an("0^0 is undefined");if(0===n&&r<0)throw new an("division by zero");if(n<0&&!Number.isInteger(r))throw new an("not a real number");return Fn(n**r,n,r)});function rr(e,t){if(Sn(e)&&Sn(t))return vn(e.c,t.c);if(In(e)&&In(t)&&Tn(e,t))return 0;const n=jn(e),r=jn(t);return n===r||Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-r)<=1e-12*Math.max(1,Math.abs(n),Math.abs(r))?0:n<r?-1:1}function ir(e,t){return Array.isArray(e)||Array.isArray(t)?Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>ir(e,t[n])):e&&"s"===e.kind?Boolean(t&&"s"===t.kind&&e.text===t.text):"boolean"==typeof e||"boolean"==typeof t?e===t:0===rr(e,t)}const sr={0:()=>_n(0),2:()=>_n(1,2),3:()=>Dn(gn(1n,2n),2,2n),4:()=>Dn(gn(1n,2n),2,3n),6:()=>_n(1)};function or(e){e=(e%24+24)%24;const[t,n]=e<=6?[e,1]:e<=12?[12-e,1]:e<=18?[e-12,-1]:[24-e,-1],r=sr[t];return r?n<0?Kn(r()):r():null}const ar=e=>or(e+6),lr=(e,t)=>Math.abs(e)<1e-15&&Math.abs(t)>1e-6?0:e;function cr(e,t){const n=function(e){if(qn(e))return 0;if(!In(e)||1!==e.pi||e.e||e.root)return null;const t=yn(e.c,gn(12n));return 1n!==t.d?null:Number((t.n%24n+24n)%24n)}(t);if(null!==n){const t=or(n),r=ar(n);if(t&&r)switch(e){case"sin":return t;case"cos":return r;case"tan":return tr(t,r);case"cot":return tr(r,t);case"sec":return tr(_n(1),r);case"csc":return tr(_n(1),t)}}const r=jn(t),i=lr(Math.sin(r),r),s=lr(Math.cos(r),r),o={sin:i,cos:s,tan:i/s,cot:s/i,sec:1/s,csc:1/i}[e];if(!Number.isFinite(o)&&Number.isFinite(r))throw new an("undefined");return Fn(o)}function hr(e,t){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[e],r=t=>"arcsin"===e?or(t):"arccos"===e?ar(t):ar(t)&&!qn(ar(t))?tr(or(t),ar(t)):null;if(In(t))for(let e=n[0];e<=n[1];e++){const n=r(e);if(n&&In(n)&&Tn(n,t))return En(gn(BigInt(e),12n),1)}const i=jn(t);if("arctan"!==e&&Math.abs(i)>1)throw new an("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[e](i)}function ur(e){if(In(e)){if(0n===e.c.n)throw new an("ln 0 is undefined");if(e.c.n<0n)throw new an("not a real number");if(1n===e.c.n&&1n===e.c.d&&!e.pi&&!e.root)return _n(e.e)}const t=jn(e);if(t<=0)throw new an(0===t?"ln 0 is undefined":"not a real number");return Math.log(t)}function pr(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*pr(1-e));const t=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];let n=t[0];const r=(e-=1)+7+.5;for(let r=1;r<9;r++)n+=t[r]/(e+r);return Math.sqrt(2*Math.PI)*r**(e+.5)*Math.exp(-r)*n}function fr(e,t){const n=Ln(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null===n)throw new an(`${t} needs whole numbers`);return n}const mr=Vn(e=>Sn(e)?En(gn(Mn(e.c))):Zn(Math.floor(jn(e)))),gr=Vn(e=>Sn(e)?En(gn(-Mn(wn(e.c)))):Zn(Math.ceil(jn(e))));function dr(e,t){const n=Number(fr(t,"round"));if(Sn(e)){const t=gn(10n**BigInt(Math.abs(n))),r=n>=0?yn(e.c,t):xn(e.c,t),i=Mn($n(yn(gn(2n),gn(pn(r.n),r.d)),bn))/2n,s=gn(r.n<0n?-i:i);return En(n>=0?xn(s,t):yn(s,t))}const r=10**n;return Math.sign(jn(e))*Math.round(Math.abs(jn(e))*r)/r}const br=(e,t)=>e/$r(e,t)*t,$r=(e,t)=>t?$r(t,e%t):e,yr={pi:()=>An,"π":()=>An,tau:()=>En(gn(2n),1),"τ":()=>En(gn(2n),1),e:()=>On,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},xr={abs:e=>In(e)?En(gn(pn(e.c.n),e.c.d),e.pi,e.e,e.root):Math.abs(jn(e)),floor:mr,ceil:gr,sqrt:e=>nr(e,_n(1,2)),ln:Vn(ur),loglog:Vn(e=>ur(ur(e))),logloglog:Vn(e=>ur(ur(ur(e)))),expm1:Vn(e=>qn(e)?_n(0):Math.expm1(jn(e))),sinh:Vn(e=>qn(e)?_n(0):Math.sinh(jn(e))),cosh:Vn(e=>qn(e)?_n(1):Math.cosh(jn(e))),tanh:Vn(e=>qn(e)?_n(0):Math.tanh(jn(e))),arcsinh:Vn(e=>qn(e)?_n(0):Math.asinh(jn(e))),arccosh:Vn(e=>{const t=jn(e);if(t<1)throw new an("not a real number");return 1===t?_n(0):Math.acosh(t)}),arctanh:Vn(e=>{const t=jn(e);if(Math.abs(t)>=1)throw new an("undefined");return qn(e)?_n(0):Math.atanh(t)}),"!":Vn(function(e){const t=Ln(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null!==t){if(t<0n)throw new an("factorial of a negative number");if(t>BigInt(cn.factorial))throw new ln("too large to calculate");let e=1n;for(let n=2n;n<=t;n++)e*=n;return En(gn(e))}const n=jn(e);if(n<0&&Number.isInteger(n))throw new an("factorial of a negative number");return Fn(pr(n+1),n)}),neg:Kn,pm:e=>Cn([e,Kn(e)],"pm"),"\\not":e=>!Pn(e)};for(const e of["sin","cos","tan","csc","sec","cot"])xr[e]=Vn(t=>cr(e,t));for(const e of["arcsin","arccos","arctan"])xr[e]=Vn(t=>hr(e,t));const wr={"+":Jn,"-":Yn,"*":er,"/":tr,"^":nr,"±":(e,t)=>Cn([Jn(e,t),Yn(e,t)],"pm"),mod:Qn(function(e,t){if(qn(t))throw new an("division by zero");if(Sn(e)&&Sn(t))return En($n(e.c,wn(yn(t.c,gn(Mn(xn(e.c,t.c)))))));const n=jn(e),r=jn(t);return Fn((n%r+r)%r)}),log:Qn(function(e,t){if(In(e)&&Tn(e,On))return ur(t);const n=jn(e),r=jn(t);if(n<=0||1===n)throw new an("not a valid base");if(r<=0)throw new an(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(Sn(e)&&Sn(t))for(let n=1n;n<=12n;n++){const r=Math.round(i*Number(n));if(Math.abs(i*Number(n)-r)>1e-9)continue;const s=Gn(e,BigInt(r)),o=Gn(t,n);if(s&&o&&Tn(s,o))return En(gn(BigInt(r),n))}return i}),root:Qn((e,t)=>nr(t,tr(_n(1),e))),atan2:(e,t)=>Math.atan2(jn(e),jn(t)),round:dr,fixed:function(e,t){const n=Number(fr(t,"fixed"));if(n<0)throw new an("fixed needs 0 or more decimal places");const r=dr(e,t);if(Sn(r)){const e=r.c.n*10n**BigInt(n)/r.c.d,t=(e<0n?-e:e).toString().padStart(n+1,"0");return zn(`${e<0n?"-":""}${t.slice(0,t.length-n)}${n?"."+t.slice(-n):""}`)}return zn(Number(jn(r)).toFixed(n))},perm:function(e,t){const n=fr(e,"permutations"),r=fr(t,"permutations");if(r<0n||r>n)throw new an("undefined");if(r>BigInt(cn.terms))throw new ln("too large to calculate");let i=1n;for(let e=n-r+1n;e<=n;e++)i*=e;return En(gn(i))},comb:function(e,t){const n=fr(e,"combinations");let r=fr(t,"combinations");if(r<0n||r>n)throw new an("undefined");if(n-r<r&&(r=n-r),r>BigInt(cn.terms))throw new ln("too large to calculate");let i=1n;for(let e=1n;e<=r;e++)i=i*(n-r+e)/e;return En(gn(i))},"=":(e,t)=>ir(e,t),"===":(e,t)=>ir(e,t),"≠":(e,t)=>!ir(e,t),"≠=":(e,t)=>!ir(e,t),"≈":(e,t)=>Math.abs(jn(e)-jn(t))<=1e-9*Math.max(1,Math.abs(jn(e)),Math.abs(jn(t))),"<":(e,t)=>rr(e,t)<0,">":(e,t)=>rr(e,t)>0,"≤":(e,t)=>rr(e,t)<=0,"≥":(e,t)=>rr(e,t)>=0,"&":(e,t)=>Pn(e)&&Pn(t),"|":(e,t)=>Pn(e)||Pn(t),"\\xor":(e,t)=>Pn(e)!==Pn(t),"\\nor":(e,t)=>!(Pn(e)||Pn(t)),"\\nand":(e,t)=>!(Pn(e)&&Pn(t))},vr={sum:e=>e.reduce((e,t)=>Jn(e,t),_n(0)),prod:e=>e.reduce((e,t)=>er(e,t),_n(1)),max:e=>e.reduce((e,t)=>rr(t,e)>0?t:e),min:e=>e.reduce((e,t)=>rr(t,e)<0?t:e),mean:e=>tr(vr.sum(e),_n(e.length)),gcd:e=>En(gn(e.map(e=>fr(e,"gcd")).reduce(mn)))},Mr=["∈","∉","∪","∩","pmod","random","(]","[)"];function kr(e,t){if(++hn>cn.steps)throw new ln("too much to work out");switch(e.type){case"number":return En(Nn(e.value));case"string":return zn(e.value.slice(1,-1));case"symbol":return Nr(e.value,t)}const n=H(e);if(n)return kr(n,t);const{op:r,args:i}=e,s=e=>kr(e,t);if("?:"===r)return Pn(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(e=>"op"!==e.type))return Nr(`${i[0].value}_${i[1].value}`,t);throw new ln("subscript")}if("der"===r)return function(e,t){const[n,r]=e.args,i=_r(r);if(!i||!Object.prototype.hasOwnProperty.call(t,i))throw new ln(`a derivative needs a value for ${i||"its variable"}`);const s=jn(t[i]),o=Er(n,i,t);if(!Number.isFinite(o(s)))throw new an("undefined");const a=1e-6*Math.max(1,Math.abs(s)),l=(o(s+a)-o(s))/a,c=(o(s)-o(s-a))/a;if(!Number.isFinite(l)||!Number.isFinite(c)||Math.abs(l-c)>.001*Math.max(1,Math.abs(l)))throw new an("not differentiable here");let h=.1*Math.max(1,Math.abs(s));const u=1.4,p=[[(o(s+h)-o(s-h))/(2*h)]];let f=p[0][0],m=1/0;for(let e=1;e<12;e++){h/=u,p[e]=[(o(s+h)-o(s-h))/(2*h)];let t=u*u;for(let n=1;n<=e;n++){p[e][n]=(p[e][n-1]*t-p[e-1][n-1])/(t-1),t*=u*u;const r=Math.max(Math.abs(p[e][n]-p[e][n-1]),Math.abs(p[e][n]-p[e-1][n-1]));r<=m&&(m=r,f=p[e][n])}if(Math.abs(p[e][e]-p[e-1][e-1])>=2*m)break}if(!Number.isFinite(f))throw new an("not differentiable here");return Sr(f,m)}(e,t);if("int"===r)return function(e,t){const[n,r,i,s]=e,o=e=>e&&"symbol"===e.type&&/^[a-zA-Zʹ-Ͽ]$/.test(e.value);let a,l,c;if(4===e.length)[a,l,c]=[_r(r),i,s];else{if(3!==e.length||o(r))throw new ln("an integral needs limits to be calculated");[a,l,c]=[_(n)||"x",r,i]}let h=jn(kr(l,t)),u=jn(kr(c,t));if(h===u)return _n(0);let p=1;h>u&&([h,u]=[u,h],p=-1);const f=Er(n,a,t),{value:m,error:g}=Ar(f,h,u);return Sr(p*m,g)}(i,t);if("lim"===r)return function(e,t){const[n,r,i,s]=e;let o,a,l=0;if(2===e.length&&"op"===r.type&&"→"===r.op)[o,a]=[_r(r.args[0]),r.args[1]];else if(2===e.length)[o,a]=[_(n),r];else{if(!(e.length>=3))throw new ln("a limit needs a point");[o,a]=[_r(r),i]}if(4===e.length){const e="op"===s.type?"":String(s.value).toLowerCase();l=e.startsWith("r")||"+"===e?1:-1}if(!o)throw new ln("a limit needs a variable");const c=kr(a,t),h=jn(c),u=Er(n,o,t);let p,f;if(Number.isFinite(h))if(l)({value:p,error:f}=Ir(e=>u(h+l*e*Math.max(1,Math.abs(h)))));else{const e=Ir(e=>u(h+e*Math.max(1,Math.abs(h)))),r=Ir(e=>u(h-e*Math.max(1,Math.abs(h))));if(e.value===r.value)({value:p,error:f}=e);else{if(!(Number.isFinite(e.value)&&Number.isFinite(r.value)&&Math.abs(e.value-r.value)<=1e-6*Math.max(1,Math.abs(e.value))))throw new an("the limit does not exist");p=(e.value+r.value)/2,f=Math.max(e.error,r.error,Math.abs(e.value-r.value))}try{const e=kr(n,{...t,[o]:c});if(Math.abs(jn(e)-p)<=1e-6*Math.max(1,Math.abs(p)))return e}catch(e){if(!(e instanceof an))throw e}}else({value:p,error:f}=Ir(e=>u(Math.sign(h)/e)));return Number.isFinite(p)?Sr(p,f):p}(i,t);if("\\sumidx"===r||"\\prodidx"===r)return function(e,t,n){const[r,i,s]=t;if(t.length<3)throw new ln("a sum needs its limits");let o,a=i;"op"===i.type&&"="===i.op&&"symbol"===i.args[0].type?[o,a]=[i.args[0].value,i.args[1]]:o=_(r)||"n";const l=fr(kr(a,n),"a sum"),c=kr(s,n),h=e?Jn:er;if(c===1/0){if(!e)throw new ln("an infinite product");return function(e,t){const n=[],r=[];let i=0,s=t;for(let o=4;o<=17;o++){const a=2**o;for(;s<t+a;s++){const t=e(s);if(!Number.isFinite(t))throw new an("undefined");i+=t}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2])return Sr(i,0)}const o=r[r.length-1]-r[r.length-2],a=r[r.length-2]-r[r.length-3];if(Math.abs(o)>=.9*Math.abs(a)&&Math.abs(o)>1e-12)throw new an("the series diverges");const l=n.slice(-7).map(e=>1/e),c=r.slice(-7),h=r.slice(-8,-1),u=(e,t)=>{const n=t.slice();for(let t=1;t<e.length;t++)for(let r=0;r<e.length-t;r++)n[r]=(e[r+t]*n[r]-e[r]*n[r+1])/(e[r+t]-e[r]);return n[0]},p=u(l,c),f=u(n.slice(-8,-1).map(e=>1/e),h);return Sr(p,Math.abs(p-f))}(Er(r,o,n),Number(l))}const u=fr(c,"a sum");if(u-l+1n>BigInt(cn.terms))throw new ln("too many terms to add one by one");let p=_n(e?0:1);for(let e=l;e<=u;e++)p=h(p,kr(r,{...n,[o]:En(gn(e))}));return p}("\\sumidx"===r,i,t);if(["()","[]","{}"].includes(r))return Cn(i.map(s),r);if(Mr.includes(r))return function(e,t){const n={};for(const[e,r]of Object.entries(t))"function"!=typeof r&&(n[e]=Bn(r));try{return Zn(function(e,t={}){0===rn&&(nn=0),rn++;try{return sn(Xt(e),t)}finally{rn--}}(e,n))}catch(e){throw new ln(e.message)}}(e,t);if(r.startsWith("\\:")){const e=t[r.slice(2)];if("function"!=typeof e)throw new ln(`no function ${r.slice(2)}`);return Zn(e(...i.map(e=>Bn(s(e)))))}if(xr[r]&&1===i.length)return xr[r](s(i[0]));if(wr[r]&&2===i.length)return wr[r](s(i[0]),s(i[1]));if(vr[r])return vr[r](i.map(s));throw new ln(`can't calculate '${r}'`)}function Nr(e,t){if(Object.prototype.hasOwnProperty.call(t,e))return t[e];if(Object.prototype.hasOwnProperty.call(yr,e))return yr[e]();throw new ln(`no value for '${e}'`)}function Er(e,t,n){return r=>{try{return jn(kr(e,{...n,[t]:r}))}catch(e){if(e instanceof an)return NaN;throw e}}}const _r=e=>"symbol"===e.type?e.value:null;function Ar(e,t,n){if(t===-1/0&&n===1/0){const t=Ar(e,-1/0,0),n=Ar(e,0,1/0);return{value:t.value+n.value,error:t.error+n.error}}return n===1/0?Or(n=>e(t+n/(1-n))/((1-n)*(1-n)),0,1):t===-1/0?Or(t=>e(n-t/(1-t))/((1-t)*(1-t)),0,1):Or(e,t,n)}function Or(e,t,n){const r=(n-t)/2;let i=1,s=0,o=NaN,a=NaN,l=0;const c=i=>{const s=Math.PI/2*Math.sinh(Math.abs(i)),o=Math.exp(-2*s),a=2*r*o/(1+o),c=r*(Math.PI/2)*Math.cosh(i)*(4*o)/((1+o)*(1+o));if(0===a||0===c)return 0;const h=i>0?n-a:t+a;if(0!==i&&(h<=t||h>=n))return 0;const u=e(0===i?(t+n)/2:h);if(!Number.isFinite(u)){if(a<1e-6*r)return 0;throw new an("the integral diverges")}return Math.abs(i)>3.5&&(l=Math.max(l,Math.abs(c*u))),c*u};s=c(0);for(let e=i;e<=4;e+=i)s+=c(e)+c(-e);o=i*s;for(let e=1;e<=8;e++){i/=2;for(let e=i;e<=4;e+=2*i)s+=c(e)+c(-e);a=o,o=i*s;const t=Math.max(1,Math.abs(o));if(l>1e-8*t)throw new an("the integral diverges");if(e>=3&&Math.abs(o-a)<=1e-13*t)break}const h=Math.abs(o-a);if(!Number.isFinite(o)||h>1e-6*Math.max(1,Math.abs(o)))throw new an("the integral does not converge");return{value:o,error:h}}function Ir(e){const t=[],n=[];for(let r=0;r<30;r++){const i=.1/2**r,s=e(i);Number.isFinite(s)&&(t.push(i),n.push(s))}if(n.length<6)throw new an("undefined");const r=n.slice(1).map((e,t)=>e-n[t]).slice(-6);if(r.every(e=>Math.sign(e)===Math.sign(r[0])&&0!==e)&&Math.abs(r[5])>=.95*Math.abs(r[0])&&Math.abs(n[n.length-1])>10)return{value:Math.sign(r[0])*(1/0),error:0};const i=e=>{const r=t.slice(e,e+8),i=n.slice(e,e+8);for(let e=1;e<r.length;e++)for(let t=0;t<r.length-e;t++)i[t]=(r[t+e]*i[t]-r[t]*i[t+1])/(r[t+e]-r[t]);return i[0]};let s=null;for(let e=0;e+9<=n.length;e++){const t=i(e),n=i(e+1),r=Math.abs(t-n);Number.isFinite(t)&&(!s||r<s.error)&&(s={value:t,error:r})}const o=n[n.length-1],a=Math.abs(o-n[n.length-2]);if(!s||s.error>Math.max(a,1e-6*Math.max(1,Math.abs(o)))){if(a<=1e-6*Math.max(1,Math.abs(o)))return{value:o,error:10*a};throw new an("the limit could not be found")}return s}function Sr(e,t=0){if(!Number.isFinite(e))return e;const n=Math.max(1e-10,4*t)*Math.max(1,Math.abs(e));if(n>1e-6*Math.max(1,Math.abs(e)))return e;if(Math.abs(e)<n)return _n(0);const r=[[_n(1),1e3],[An,100],[En(bn,2),100],[On,100],...[2n,3n,5n,6n,7n].map(e=>[En(bn,0,0,{n:2,r:e}),100])];for(const[t,i]of r){const r=e/jn(t),s=qr(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*jn(t)<=n)return Un(En(s),t)}return e}function qr(e,t){if(!Number.isFinite(e)||Math.abs(e)>1e12)return null;let[n,r,i,s]=[0,1,1,0],o=e;for(let e=0;e<40;e++){const e=Math.floor(o),a=e*r+n,l=e*s+i;if(l>t)break;if([n,r,i,s]=[r,a,s,l],Math.abs(o-e)<1e-15)break;o=1/(o-e)}return s?gn(BigInt(r),BigInt(s)):null}function Lr(e,t){if("boolean"==typeof e)return String(e);if(e&&"s"===e.kind)return JSON.stringify(e.text);if(Array.isArray(e)){if("pm"===e.group&&2===e.length&&ir(e[1],Kn(e[0])))return`±${Cr(e[0],t)}`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[e.group]||"{}";return n+e.map(e=>Lr(e,t)).join(", ")+r}return"number"==typeof e?zr(e,t):t.decimal||null!==t.places?function(e,t){if(Sn(e)&&null===t.places){let n=e.c.d,r=0,i=0;for(;n%2n==0n;)n/=2n,r++;for(;n%5n==0n;)n/=5n,i++;const s=Math.max(r,i);if(1n===n&&s<=t.digits){const n=e.c.n*10n**BigInt(s)/e.c.d,r=n<0n,i=pn(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=t.maxDigits)return(r?"-":"")+Rr(o)}}return Sn(e)&&null!==t.places?Lr(dr(e,_n(t.places)),{...t,places:null,decimal:!0}):zr(jn(e),t)}(e,t):function(e,t){const{c:n}=e,r=pn(n.n);if(r.toString().length>t.maxDigits||n.d.toString().length>t.maxDigits)return function(e,t){if(!Sn(e)||1n!==e.c.d)return zr(jn(e),t);const n=pn(e.c.n).toString(),r=BigInt(n.slice(0,t.digits+1)),i=((r+5n)/10n).toString(),s=n.length-1+(i.length>t.digits?1:0),o=Rr(`${i[0]}.${i.slice(1,t.digits)}`);return`${e.c.n<0n?"-":""}${o}*10^(${s})`}(e,t);const i=(e,t)=>1===t?e:`${e}^${t}`,s=[],o=[];e.pi>0&&s.push(i("pi",e.pi));e.pi<0&&o.push(i("pi",-e.pi));e.e>0&&s.push(i("e",e.e));e.e<0&&o.push(i("e",-e.e));e.root&&s.push(2===e.root.n?`sqrt(${e.root.r})`:`root(${e.root.n}, ${e.root.r})`);1n===r&&s.length||s.unshift(r.toString());1n!==n.d&&o.unshift(n.d.toString());const a=e=>e.length>1?`(${e.join("*")})`:e[0],l=o.length?`${a(s)}/${a(o)}`:s.join("*");return(n.n<0n?"-":"")+l}(e,t)}const Cr=(e,t)=>{const n=Lr(e,t);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function zr(e,t){if(e===1/0)return"∞";if(e===-1/0)return"-∞";if(Object.is(e,-0)||0===e)return"0";if(null!==t.places&&Math.abs(e)<1e21)return e.toFixed(t.places);const n=Math.abs(e);if(n>=1e15||n<1e-6){const[n,r]=e.toExponential(t.digits-1).split("e");return`${Rr(n)}*10^(${Number(r)})`}return String(Number(e.toPrecision(t.digits)))}const Rr=e=>e.includes(".")?e.replace(/\.?0+$/,""):e;function Tr(e,t={},n={}){const r="string"==typeof e?Gt(e):N(e),i={};for(const[e,n]of Object.entries(t))i[e]=Zn(n);let s;0===un&&(hn=0),un++;try{s=kr(r,i)}finally{un--}const o={decimal:!1,places:null,digits:12,maxDigits:50,...n};void 0===o.places&&(o.places=null);const a=e=>Array.isArray(e)?e.every(a):"number"!=typeof e;return{value:Bn(s),text:Lr(s,o),exact:a(s)}}function jr(e,t={}){let n=e.trim();const r={},i=/^(~|≈)\s*(\d+)?/.exec(n);i&&(r.decimal=!0,void 0!==i[2]&&(r.places=Number(i[2])),n=n.slice(i[0].length)),/\d\.\d|\.\d/.test(n)&&(r.decimal=!0);try{const{text:e}=Tr(n,t,r);return e.startsWith('"')||/^\d+(\.\d+)?$/.test(e)?e:`(${e})`}catch(e){if(e instanceof an)return'"undefined"';if(e instanceof ln)return`(${n})`;throw e}}Ut=jr;for(const e of[cn,sr,yr,xr,wr,vr])Object.setPrototypeOf(e,null);const Fr={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},Pr={sin:"sine",cos:"cosine",tan:"tangent",csc:"cosecant",sec:"secant",cot:"cotangent",sinh:"hyperbolic sine",cosh:"hyperbolic cosine",tanh:"hyperbolic tangent",arcsin:"inverse sine",arccos:"inverse cosine",arctan:"inverse tangent",arcsinh:"inverse hyperbolic sine",arccosh:"inverse hyperbolic cosine",arctanh:"inverse hyperbolic tangent",ln:"the natural log",log:"log",loglog:"the log of the log",logloglog:"the log of the log of the log",expm1:"e to the power, minus 1, of",max:"the maximum",min:"the minimum",gcd:"the greatest common divisor",mean:"the mean",atan2:"the arctangent",round:"round",fixed:"fixed",random:"random"},Zr=Object.fromEntries(Object.entries(A).map(([e,t])=>[t,e]));function Br(e,t={}){return function(e){const t=[];for(const{text:n,id:r}of e){const e=n.trim();if(!e)continue;const i=e.startsWith(","),s=i?e.slice(1).trim():e;i&&t.length&&!t[t.length-1].text.endsWith(",")&&(t[t.length-1].text+=","),s&&t.push({text:s,id:r})}t.length&&(t[t.length-1].text=t[t.length-1].text.replace(/,$/,""));return t}(new Hr({...Fr,...t.words},{...Pr,...t.names},t.say||{}).speak(e))}function Wr(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const Dr={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},Ur={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class Hr{constructor(e,t,n){this.w=e,this.names=t,this.say=n}speak(e){const t=this.say["op"===e.type?e.op:e.type];if(t){return[{text:t("op"===e.type?e.args.map(e=>Wr(this.speak(e))):[e.value],e,e=>Wr(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(Ur[e])return t[Ur[e]];if(Zr[e])return Zr[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=c(e.op);return void 0!==t&&t<=50&&!a(e.op).group}quantity(e){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),this.seg(e,this.w.comma)]:this.speak(e)}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[r,i]=n,s=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(s.comma),...this.speak(e)]:this.speak(e));if(Dr[t])return[...this.speak(r),a(s[Dr[t]]),...this.speak(i)];if(o(t)){const e=this.symbol(B(t));return n.length?[a(`${e} ${s.of}`),...this.arguments(n)]:[a(e)]}if(this.names[t]&&!["log","round","fixed","atan2","random","expm1"].includes(t))return[a(`${this.names[t]} ${s.of}`),...this.arguments(n)];switch(t){case"+":return I(i)?[...this.speak(r),a(s.minus),...this.speak(i.args[1])]:[...this.speak(r),a(s.plus),...this.speak(i)];case"-":return I(i)?[...this.speak(r),a(s.plus),...this.speak(i.args[1])]:[...this.speak(r),a(s.minus),...this.quantityIfSum(i)];case"*":return this.product(e);case"/":return this.fraction(e);case"^":return this.power(e);case"_":return[...this.speak(r),a(s.sub),...this.speak(i)];case"neg":return this.isCompound(r)||"op"===r.type&&"neg"===r.op?[a(`${s.negative} ${s.quantity}`),...this.speak(r),a(s.comma)]:[a(s.negative),...this.speak(r)];case"pm":return[a(s.plusOrMinus),...this.speak(r)];case"!":return[...this.quantity(r),a(s.factorial)];case"\\not":return[a(s.not),...this.quantity(r)];case"sqrt":return[a(s.squareRoot),...this.speak(r),...this.pauseAfter(r)];case"root":{const e="number"===r.type?Number(r.value):NaN,t=3===e?s.cubeRoot:2===e?s.squareRoot:s.nthRoot(e?this.ordinal(e):Wr(this.speak(r))+"th");return[a(t),...this.speak(i),...this.pauseAfter(i)]}case"abs":return[a(s.absoluteValue),...this.speak(r),...this.pauseAfter(r)];case"floor":return[a(s.floor),...this.speak(r),...this.pauseAfter(r)];case"ceil":return[a(s.ceiling),...this.speak(r),...this.pauseAfter(r)];case"log":return"symbol"===r.type&&"e"===r.value?[a(`${this.names.ln} ${s.of}`),...this.argument(i)]:[a(`${s.logBase}`),...this.speak(r),a(s.of),...this.argument(i)];case"mod":return[...this.quantity(r),a(s.mod),...this.quantity(i)];case"pmod":return[...this.speak(r),a(`${s.comma} ${s.mod}`),...this.speak(i)];case"perm":return[...this.quantity(r),a(s.permute),...this.quantity(i)];case"comb":return[...this.quantity(r),a(s.choose),...this.quantity(i)];case"round":{const e=0===("number"===i.type?Number(i.value):NaN)?s.nearestWholeNumber:`${Wr(this.speak(i))} ${s.decimalPlaces}`;return[...this.speak(r),a(`${s.comma} ${s.rounded} ${e}`)]}case"fixed":return 0===("number"===i.type?Number(i.value):NaN)?[...this.speak(r),a(`${s.comma} ${s.asWholeNumber}`)]:[...this.speak(r),a(`${s.comma} ${s.writtenTo}`),...this.speak(i),a(s.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${s.of}`),...this.speak(r),a(s.over),...this.speak(i)];case"random":return[a(s.randomNumber)];case"expm1":return[a(s.eToThe),...this.speak(r),a(`${s.comma} ${s.minus} 1`)];case"?:":return[a(s.if),...this.speak(r),a(`${s.comma} ${s.then}`),...this.speak(i),a(`${s.comma} ${s.otherwise}`),...this.speak(n[2])];case"sum":return n.flatMap((e,t)=>t?[a(s.plus),...this.speak(e)]:this.speak(e));case"prod":return n.flatMap((e,t)=>t?[a(s.times),...this.quantity(e)]:this.quantity(e));case"mean":case"max":case"min":case"gcd":return[a(`${this.names[t]} ${s.of}`),...l()];case"()":return 2===n.length?[a(s.openInterval),...this.speak(r),a(s.to),...this.speak(i)]:l();case"[]":return 2===n.length?[a(s.closedInterval),...this.speak(r),a(s.to),...this.speak(i)]:[a(s.theList),...l()];case"(]":case"[)":return[a(s.halfOpenInterval),...this.speak(r),a(s.to),...this.speak(i)];case"{}":return[a(s.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,s.sumFrom,s.sumOver,s.sumOf);case"\\prodidx":return this.bigOperator(e,s.productFrom,s.productOver,s.productOf)}throw new Error(`No speech for '${t}'`)}arguments(e){return 1===e.length?this.argument(e[0]):e.flatMap((e,t)=>t?[{text:this.w.comma,id:e.id},...this.speak(e)]:this.speak(e))}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}quantityIfSum(e){return this.quantity(e)}product(e){const[t,n]=e.args,r=this.w;if(I(e))return[this.seg(e,r.negative),...this.speak(n)];if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,r.degrees)];const i=this.quantity(t),s=this.quantity(n);return this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||s[0].text.startsWith("the ")?[...i,this.seg(e,r.times),...s]:[...i,...s]}isWord(e){return"symbol"===e.type&&/^[A-Za-z]{2,}$/.test(e.value)&&!A[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,r=this.w,i=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),s=Number(n.value),o=2===s?1===e?r.half:r.halves:r.ordinals[s]+(1===e?"":"s");return[i(`${r.numerators[e]} ${o}`)]}return[...this.quantity(t),...this.isCall(t)?[i(r.comma)]:[],i(r.over),...this.quantity(n)]}power(e){const[t,n]=e.args,r=this.w,i=t=>this.seg(e,t),s=this.isCompound(t)||this.isCall(t)||"number"===t.type&&t.value.startsWith("-")||"op"===t.type&&"/"===t.op?[i(r.quantity),...this.speak(t),i(r.comma)]:this.speak(t);if(this.isCall(t)&&this.names[t.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===t.args.length){const e=2===Number(n.value)?r.squared:r.cubed;return[i(`${this.names[t.op]} ${e} ${r.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?[...s,i(r.powers[e])]:[...s,i(`${r.toThe} ${r.powers[e]}`)]}if("number"===n.type&&/^\d+$/.test(n.value))return[...s,i(`${r.toThe} ${this.ordinal(Number(n.value))}`)];return!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))?[...s,i(r.toThe),...this.speak(n)]:[...s,i(r.toThePowerOf),...this.speak(n),i(r.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:r,variable:i}=W(e),s=this.w,o=t=>this.seg(e,t);if(i){return[o(1===t?s.d:`${s.d} ${2===t?s.squared:3===t?s.cubed:`${s.toThe} ${this.ordinal(t)}`}`),...this.speak(n),o(s.d),...this.speak(r),o(1===t?"":2===t?s.squared:3===t?s.cubed:`${s.toThe} ${this.ordinal(t)}`)]}return[o(`${1===t?s.derivative:2===t?s.secondDerivative:s.nthDerivative(this.ordinal(t))} ${s.withRespectTo}`),...this.speak(r),o(s.of),...this.speak(n),...this.pauseAfter(n)]}integral(e){const{args:t}=e,[n,r,i,s]=t,o=this.w,a=t=>this.seg(e,t),l=t.length>=2&&"symbol"===r.type&&1===r.value.length,c=l?this.speak(r):[a(_(n)||"x")];let h=[];4===t.length?h=[i,s]:3===t.length?h=l?[i]:[r,i]:2!==t.length||l||(h=[r]);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,r,i,s]=t,o=this.w,a=t=>this.seg(e,t);let l;if(t.length>=3){if(l=[...this.speak(r),a(o.approaches),...this.speak(i)],4===t.length){const e=String(s.value??"").toLowerCase().startsWith("r");l.push(a(e?o.fromTheRight:o.fromTheLeft))}}else if(2===t.length&&"op"===r.type&&"→"===r.op)l=[...this.speak(r.args[0]),a(o.approaches),...this.speak(r.args[1])];else{if(2!==t.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const e=_(n);l=e?[a(e),a(o.approaches),...this.speak(r)]:this.speak(r)}}return[a(o.limitAs),...l,a(o.of),...this.speak(n),...this.pauseAfter(n)]}bigOperator(e,t,n,r){const{args:i}=e,[s,o,a]=i,l=this.w,c=t=>this.seg(e,t);let h;return h=3===i.length?[c(t),...this.speak(o),c(l.to),...this.speak(a),c(l.of)]:2===i.length?[c(n),...this.speak(o),c(l.of)]:[c(r)],[...h,...this.speak(s),...this.pauseAfter(s)]}}for(const e of[Fr,Pr,Dr,Ur,Zr])Object.setPrototypeOf(e,null);function Gr(e,t={}){return Vt(e)?"":function(e,t={}){return Wr(Br(e,t))}(Xt(e),t)}const Xr={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0.015"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function Vr(e,t,n=""){const r=Xr[e];return`<svg class="${t}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${r.fill?`<path d="${r.fill}" fill="currentColor"/>`:`<path d="${r.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const Qr=.8,Jr=.2,Kr=.25,Yr=.7,ei="−",ti={"+":"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"},ni={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},ri={"±":"±","∪":"∪","∩":"∩",mod:"mod"},ii=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],si={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},oi=[...ii,...Object.keys(si),"ln"],ai={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},li={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},ci={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},hi={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},ui=["boxed","overline","bar","underline","cancel",...Object.keys(hi)],pi={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,attributes:null,style:null},fi=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),mi=e=>+e.toFixed(3)+"em",gi=(e,t=Qr,n=Jr)=>({html:e,h:t,d:n});function di(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(Qr,...t.map(e=>e.h)),d:Math.max(Jr,...t.map(e=>e.d))}}function bi(e,t={}){const n=new $i({...pi,...t}),r=n.render(e,{level:0}),i=`${n.p}${n.o.display?` ${n.p}-display`:""}`,s=function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):Gr(e)}catch{return null}}(e,n.o.label),o=null===s?r.html:r.html.replace(/^<span /,'<span aria-hidden="true" ');return{html:`<span class="${i}"${null===s?"":` role="math" aria-label="${fi(s)}"`}>${o}</span>`,h:r.h,d:r.d}}class $i{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",r=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${r}>${t}</span>`}text(e,t){const n=gi(this.el(e,fi(t)));return n.leaf={kind:e,content:fi(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 r="";void 0!==e.id&&(r+=` data-node="${e.id}"`),"op"===e.type&&(r+=` data-op="${fi(e.op)}"`);const i=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(i))"class"!==e&&"style"!==e&&(r+=` ${e}="${fi(t)}"`);const s=[i.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(i.class?[i.class]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${s?` style="${fi(s)}"`:""}${r}>${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(/^-/,ei)))}symbol(e){return A[e]&&(e=A[e]),ci[e]?this.text("ord",ci[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)?gi(this.el("var",fi(e[0]))+this.el("prime",fi(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?gi(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:r}=e,[i,s]=r,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1}),l=ti[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,n)=>q(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(oi.includes(n)||"log"===n)return c(this.named(e,t));if(ai[n])return c(di(this.word(ai[n]),this.fence(this.list(r,t))));if(o(n))return c(this.custom(e,t));if(li[n])return c(this.fence(this.list(r,t),...li[n]));if(ni[n]&&2===r.length)return c(di(h(i,"left"),this.rel(ni[n]),h(s,"right")));if(ri[n]&&2===r.length)return c(di(h(i,"left"),this.bin(ri[n]),h(s,"right")));switch(n){case"+":return I(s)?c(di(h(i,"left"),this.bin(ei),this.wrap(s,["op","op-mul"],this.render(s.args[1],t)))):"number"===s.type&&s.value.startsWith("-")?c(di(h(i,"left"),this.bin(ei),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):c(di(h(i,"left"),this.bin("+"),this.signed(s,h(s,"right"))));case"-":return c(di(h(i,"left"),this.bin(ei),this.signed(s,h(s,"right"))));case"*":return c(this.product(e,t));case"/":return c(this.fraction(e,t));case"^":return c(this.power(e,t));case"_":return c(this.script(a(i,{forceParens:!0}),null,t,a(s,{level:t.level+1})));case"neg":return c(di(this.text("sign",ei),L(n,i)?this.fence(a(i)):a(i,{before:t.before})));case"pm":return c(di(this.text("sign","±"),L(n,i)?this.fence(a(i)):a(i)));case"!":return c(di(L(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(di(this.text("sign","¬"),L(n,i)?this.fence(a(i)):a(i)));case"pmod":return c(di(a(i),this.fence(di(this.word("mod"),this.text("space",""),a(s)))));case"sqrt":return c(this.radical(a(i)));case"root":return c(this.radical(a(s),this.render(i,{level:t.level+2})));case"abs":return c(this.fence(a(i),"|","|"));case"floor":return c(this.fence(a(i),"⌊","⌋"));case"ceil":return c(this.fence(a(i),"⌈","⌉"));case"loglog":return c(di(this.word("ln"),this.fence(di(this.word("ln"),this.fence(a(i))))));case"logloglog":return c(di(this.word("ln"),this.fence(di(this.word("ln"),this.fence(di(this.word("ln"),this.fence(a(i))))))));case"perm":return c(this.script(this.script(gi(""),this.render(i,{level:t.level+1}),t),null,t,this.render(s,{level:t.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(i),a(s),!1)));case"?:":return c(this.o.cases?this.cases(e,t):di(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":return c(di(r.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(di(r.map((e,t)=>t?[this.bin("·"),a(e)]:[a(e)]).flat()));case"der":return c(this.derivative(e,t));case"int":return c(this.integral(r,t));case"lim":return c(this.limit(r,t));case"\\sumidx":return c(this.bigOperator("sum",r,t));case"\\prodidx":return c(this.bigOperator("prod",r,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 di(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,t){const[n,r]=e.args;if(I(e))return di(this.text("sign",ei),this.render(r,t));const i=function(e){const[t,n]=e.args;return{left:q(e,t,"left")&&"/"!==t.op,right:q(e,n,"right")&&"/"!==n.op}}(e),s=C(n,r,i),a=function(e){for(;"op"===e.type;){if(oi.includes(e.op)||"log"===e.op||ai[e.op]||o(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(r),l=i.left?this.fence(this.render(n,t)):this.render(n,{...t,before:s&&!a}),c=i.right?this.fence(this.render(r,t)):this.render(r,{...t,before:t.before});return di(l,s?gi(this.el(a?"fnspace":"times","")):this.bin("·"),c)}named(e,t,n=null){const{op:r,args:i}=e,s="log"===r?i[1]:i[0];let o;o=si[r]&&"power"===this.o.inverseTrig?this.script(this.word(si[r]),this.text("num","−1"),t):this.word(r),n&&(o=this.script(o,n,t)),"log"===r&&(o=this.script(o,null,t,this.render(i[0],{level:t.level+1})));const a="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&yi(s),l=this.render(s,{...t,forceParens:!1,before:!1});return di(o,a?di(gi(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=B(e.op),r=e.args;if(ui.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],t));return di(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),gi(this.el("callgap","")),this.fence(this.list(r,t)))}decorate(e,t){switch(e){case"boxed":return gi(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return gi(this.el("cancel",t.html),t.h,t.d);case"underline":return gi(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return gi(this.el("over",t.html),t.h+.14,t.d);default:return gi(this.el("accent",this.el("accent-mark",hi[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,r]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&yi(n,!0)&&yi(r,!0)){const e=e=>"op"!==e.type||yi(e)?this.render(e,t):this.fence(this.render(e,t));return di(e(n),this.text("ord","/"),e(r))}const i=t.level>0||t.inFraction||!this.o.display?.8:1,s={...t,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,s),this.render(r,s),!0,i)}stack(e,t,n=!0,r=1){const i=e=>1===r?e.html:this.el("scaled",e.html,`font-size:${mi(r)}`),s=n?.06:0,o=Kr+s/2+.1+Math.max(Jr,r*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(e))+this.el("denom",i(t)),`vertical-align:${mi(o)}`);return gi(a,o+Math.max(Qr,r*e.h),Math.max(Qr,r*t.h)+Math.max(Jr,r*t.d)+.1+s/2-Kr)}power(e,t){const[n,r]=e.args,i={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1},s=()=>this.render(r,i);if(this.o.trigPowers&&ii.includes(n.op)&&wi(r))return this.wrap(n,["op",`op-${n.op}`],this.named(n,t,s()));if("_"===n.op){const e=this.render(n.args[1],i);return this.wrap(n,["op","op-subscript"],this.script(this.render(n.args[0],{...t,forceParens:!0}),s(),t,e))}const o=q(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||oi.includes(n.op)?this.fence(this.render(n,t)):this.render(n,{...t,forceParens:!0});return this.script(o,s(),t)}script(e,t,n,r=null,i=null){const s=n.level>0?.8:Yr,o=i?di(e,i):e;let a=t?Math.max(.42,e.h-.38,s*t.d+.12):0,l=r?Math.max(.2,e.d-.05,s*r.h-.45):0;if(t&&r){const e=.1-(a-s*t.d-(s*r.h-l));e>0&&(l+=e)}const c=e=>this.el("script",e.html,`font-size:${mi(s)}`);if(t&&!r)return gi(e.html+this.el("sup",t.html,`font-size:${mi(s)};vertical-align:${mi(a/s)}`),Math.max(o.h,a+s*t.h),Math.max(o.d,s*t.d-a));if(r&&!t)return gi(o.html+this.el("sub",r.html,`font-size:${mi(s)};vertical-align:${mi(-l/s)}`),Math.max(o.h,s*r.h-l),Math.max(o.d,l+s*r.d));const h=a+s*t.h,u=l+s*r.d,p=this.el("subsup",c(t)+c(r),`vertical-align:${mi(a)};height:${mi(h+u)}`);return gi(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,Qr)+.1+.06,r=Math.max(e.d,Jr),i=n+r,s=Vr("sqrt",`${this.p}-hook`,`height:${mi(i)};width:${mi(.5+.06*(i-1))};vertical-align:${mi(-r)}`);let o="";if(t){const e=.8*Yr;o=this.el("rootindex",t.html,`font-size:${mi(e)};vertical-align:${mi((.55*i-r)/e)}`)}return gi(this.el("sqrt",o+s+this.el("radicand",e.html)),n,r)}fence(e,t="(",n=")"){const r=Math.max(e.h,Qr)+Math.max(e.d,Jr),i=r>1.25,s=i?.1:0,o=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const s=n+(i?Math.min(.2,.05*(r-1)):0);return{html:Vr(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${mi(s)}`),w:s+.1}}const s={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${s} delim-${t}`,""),w:"|"===e?.18:.3}},a=o(t,"l"),l=o(n,"r"),c=`padding:${mi(s)} ${mi(l.w)} ${mi(s)} ${mi(a.w)}`,h=gi(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,Qr)+s,Math.max(e.d,Jr)+s);return h.fenced=!0,h}derivative(e,t){const{n:n,body:r,by:i,variable:s}=W(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=di(a(),l()?this.script(this.render(i,h),l(),h):this.render(i,h)),p=e=>di(l()?this.script(a(),l(),h):a(),e||[]),f=t.level>0||t.inFraction||!this.o.display?.8:1;if(s)return this.stack(p(this.render(r,h)),u,!0,f);const m=S(r)&&c(S(r))<100,[g,d]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=m?this.fence(this.render(r,t),g,d):this.render(r,t);return di(this.stack(p(),u,!0,f),b)}integral(e,t){const[n,r,i,s]=e,o=e=>this.render(e,t),a=e=>e?this.render(e,{...t,level:t.level+1}):null,l=()=>this.text("var",_(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:Z(r)?c=o(r):(c=l(),h=a(r));break;case 3:Z(r)?(c=o(r),h=a(i)):(c=l(),h=a(r),u=a(i));break;default:c=o(r),h=a(i),u=a(s)}const p=o(n),f=gi(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return di(this.bigSign("int",p,h,u,t),p,f)}bigSign(e,t,n,r,i){const s=!this.o.display||i.level>0,o=Math.max(s?.6:.95,Math.max(t.h-Kr,t.d+Kr)+.12),a=Vr(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${mi(2*o)};width:${mi(s?.38:.5)};vertical-align:${mi(Kr-o)}`);if(!n&&!r)return gi(a,Kr+o,o-Kr);const l=Yr,c=r||gi(""),h=n||gi(""),u=Kr+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${mi(l)}`)+this.el("script lower",h.html,`font-size:${mi(l)}`),`vertical-align:${mi(u)};height:${mi(2*o)}`);return gi(a+p,Kr+o,o-Kr)}limit(e,t){const[n,r,i,s]=e,o={...t,level:t.level+1},a=e=>this.render(e,o),l=()=>this.rel("→");let c;switch(e.length){case 1:return di(this.word("lim"),gi(this.el("fnspace","")),this.render(n,t));case 2:{const e=_(n),t="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=e&&t?di(this.text("var",e),l(),a(r)):a(r);break}case 3:c=di(a(r),l(),a(i));break;default:{const e=O(s).toLowerCase().startsWith("r")?"+":ei;c=di(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",e)),o))}}return di(this.under(this.word("lim"),c,t),this.render(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):gi(this.el("under",e.html+this.el("script",t.html,`font-size:${mi(.7)}`)),e.h,Math.max(e.d,Jr)+.05+.7*(t.h+t.d))}bigOperator(e,t,n){const[r,i,s]=t,o={...n,level:n.level+1},a=i?this.render(i,o):null,l=s?this.render(s,o):null,c=this.render(r,n);if(!this.o.display||n.level>0){const t=.55,r=Vr(e,`${this.p}-bigsign`,`height:${mi(2*t)};width:${mi(.8)};vertical-align:${mi(Kr-t)}`);return di(this.script(gi(r,Kr+t,t-Kr),l,n,a),c)}const h=.68,u=Yr,p=Vr(e,`${this.p}-bigsign`,`height:${mi(1.36)};width:${mi("sum"===e?1:1.05)}`),f=l?1.01+u*l.d:Kr-h,m=e=>this.el("script",e.html,`font-size:${mi(u)}`),g=this.el("bigop",(l?m(l):"")+p+(a?m(a):""),`vertical-align:${mi(f)}`);return di(gi(g,.93+(l?.08+u*(l.h+l.d):0),h-Kr+(a?.08+u*(a.h+a.d):0)),c)}cases(e,t){const n=[];let r=e;for(;"op"===r.type&&"?:"===r.op;)n.push([this.render(r.args[1],t),di(this.word("if"),this.text("space",""),this.render(r.args[0],t))]),r=r.args[2];n.push([this.render(r,t),this.word("otherwise")]);const i=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),s=i.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),o=Kr+s/2-i[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=gi(this.el("cases",a,`vertical-align:${mi(o)}`),Kr+s/2,s/2-Kr);return this.fence(l,"{","")}}function yi(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!I(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||xi(e)||"*"===e.op&&yi(e,t)):yi(e.args[0],!0)&&("neg"===e.op||yi(e.args[1],!0)))}const xi=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(A[e.value])),wi=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const vi=e=>k(e).join(" ");function Mi(e,t){const n=new Set;ki(e,t,n);const r=[];return E(e,e=>{n.has(e)&&r.push(e)}),r}function ki(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>ki(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const r=vi(Gt(t));return void E(e,e=>{vi(e)===r&&n.add(e)})}if(t.path){const r=Ni(e,t.path);return void(r&&n.add(r))}if(t.type){const r=vi(t);E(e,e=>{e!==t&&vi(e)!==r||n.add(e)})}}else E(e,(e,r)=>{t(e,r)&&n.add(e)});else E(e,e=>{e.id===t&&n.add(e)})}function Ni(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}function Ei(e,t){const n=[],r=e=>{if(e.id===t)return!0;if("op"!==e.type)return!1;for(let t=0;t<e.args.length;t++){if(n.push(t),r(e.args[t]))return!0;n.pop()}return!1};return r(e)?n:null}function _i(e){let n=0;const r=e=>{"op"===e.type&&(e.args.forEach(r),a(e.op)?.arity===t&&n++),e.id=n++};return r(e),e}function Ai(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Gt(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return M(e);if(e&&"object"==typeof e&&e.type)return void 0===e.id?_i(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Oi(e,t){const{colors:n,highlight:r,scope:i,blocks:s,...o}=t,a=new Map;for(const[t,r]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(Ii(r))for(const n of Mi(e,t))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:Mi(e,r));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}function Ii(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}function Si(e,t={}){return Ai(e,{...t,blocks:t.blocks??jr})}function qi(e,t={}){return function(e,t={}){const n=Ai(e,t);return bi(n,Oi(n,t)).html}(e,{...t,blocks:t.blocks??jr})}class Li{constructor(e,t,n={}){this.element=e,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.set(t)}set(e,{animate:t=!1,duration:n=600,easing:r="ease-in-out"}={}){const i=t&&this.tree?this.snapshot():null;return this.tree=Si(e,this.options),this.element.innerHTML=bi(this.tree,Oi(this.tree,this.options)).html,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),i&&this.morph(i,{duration:n,easing:r}),this}nodes(e){return Mi(this.tree,e)}elements(e){return this.nodes(e).map(e=>this.elementOf(e)).filter(Boolean)}elementOf(e){return void 0===e.id?null:this.root.querySelector(`[data-node="${e.id}"]`)}highlight(e,t=`${this.p}-hl`){return this.elements(e).forEach(e=>e.classList.add(t)),this}unhighlight(e=null,t=`${this.p}-hl`){return(null===e?this.root.querySelectorAll(`.${t}`):this.elements(e)).forEach(e=>e.classList.remove(t)),this}color(e,t){return this.elements(e).forEach(e=>{e.style.color=t||""}),this}on(e,t){const n=e=>{const n=e.target.closest?.("[data-node]");if(!n||!this.root.contains(n))return;const r=Number(n.dataset.node),i=Mi(this.tree,r)[0];t({node:i,id:r,path:Ei(this.tree,r),element:n,event:e})};return this.element.addEventListener(e,n),this.handlers.push([e,n]),this.root.classList.add(`${this.p}-clickable`),()=>this.element.removeEventListener(e,n)}segments(e={}){return function(e,t={}){return Vt(e)?[]:Br(Xt(e),t)}(this.tree,e)}showSegment(e,t=`${this.p}-hl`){return this.unhighlight(null,t),e&&void 0!==e.id&&this.highlight(e.id,t),this}snapshot(){const e=new Map,t=n=>{const r=this.elementOf(n);if(r){const t=vi(n);e.has(t)||e.set(t,[]),e.get(t).push(r.getBoundingClientRect())}"op"===n.type&&n.args.forEach(t)};return t(this.tree),e}morph(e,{duration:t,easing:n}){if("undefined"==typeof Element||!Element.prototype.animate)return;const r=i=>{const s=this.elementOf(i),o=s&&e.get(vi(i));if(o&&o.length){const e=o.shift(),r=s.getBoundingClientRect(),i=e.left-r.left,a=e.top-r.top,l=r.width?e.width/r.width:1,c=r.height?e.height/r.height:1;return void((Math.abs(i)+Math.abs(a)>.5||Math.abs(l-1)+Math.abs(c-1)>.01)&&s.animate([{transformOrigin:"0 0",transform:`translate(${i}px, ${a}px) scale(${l}, ${c})`},{transformOrigin:"0 0",transform:"none"}],{duration:t,easing:n}))}"op"===i.type?i.args.forEach(r):s&&s.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:t,easing:n})};r(this.tree)}}const Ci=new RegExp("(\\d+)","g");function zi(e,{delimiters:t=["$$","$","\\[","\\("]}={}){const n=[];let r="",i=0;const s=String(e),o=e=>0===e||"\n"===s[e-1],a=(e,t,r)=>(n.push({source:e,display:t,raw:r}),`${n.length-1}`);for(;i<s.length;){if(o(i)){const e=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(s.slice(i));if(e){const t=e[2],n=new RegExp(`\\n {0,3}${"`"===t[0]?"`":"~"}{${t.length},}[ \\t]*(?=\\n|$)`),o=s.slice(i+e[0].length),l=n.exec(`\n${o}`),c=l?o.slice(0,Math.max(0,l.index-1)):o,h=e[0].length+(l?l.index-1+l[0].length:o.length),u=s.slice(i,i+h);"math"===e[3].trim()?r+=a(c,!0,u):r+=u,i+=h;continue}}const e=s[i];if("`"===e){const e=/^`+/.exec(s.slice(i))[0],t=s.indexOf(e,i+e.length);if(t>-1){r+=s.slice(i,t+e.length),i=t+e.length;continue}r+=e,i+=e.length;continue}if("\\"===e){const e=s.slice(i,i+2),n="\\["===e?"\\]":"\\("===e?"\\)":null;if(n&&t.includes(e)){const t=s.indexOf(n,i+2);if(t>-1){r+=a(s.slice(i+2,t),"\\["===e,s.slice(i,t+2)),i=t+2;continue}}r+=e,i+=2;continue}if("$"===e)if("$"===s[i+1]&&t.includes("$$")){const e=s.indexOf("$$",i+2);if(e>-1){r+=a(s.slice(i+2,e),!0,s.slice(i,e+2)),i=e+2;continue}}else if(t.includes("$")&&s[i+1]&&!/\s/.test(s[i+1])){const e=Ri(s,i+1);if(e>-1){r+=a(s.slice(i+1,e),!1,s.slice(i,e+1)),i=e+1;continue}}r+=e,i++}return{text:r,math:n}}function Ri(e,t){for(let n=t;n<e.length;n++){const t=e[n];if("\\"!==t){if("`"===t)return-1;if("\n"===t&&/^\n[ \t]*\n/.test(e.slice(n)))return-1;if("$"===t&&!/\s/.test(e[n-1])&&!/\d/.test(e[n+1]??"")&&"$"!==e[n+1])return n}else n++}return-1}const Ti=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ji=/^\s*([A-Za-zͰ-Ͽ](?:_\{?\w+\}?)?)\s*(?::=|=)\s*([^=<>≤≥]+)$/;function Fi(e,t,n){const{source:r,display:i}=e;try{const e=qi(r,{...t.math,display:i,blocks:t.blocks,scope:n});return!1!==t.define&&function(e,t){const n=ji.exec(e);if(!n||/\{\{/.test(n[2]))return;try{const e=Tr(n[2],t);"number"!=typeof e.value&&"bigint"!=typeof e.value||(t[n[1].replace(/[{}]/g,"")]=e.exact?e.text:e.value)}catch{}}(r,n),i?`<span class="mv-md-display">${e}</span>`:`<span class="mv-md-math">${e}</span>`}catch(t){return`<span class="mv-md-error" title="${Ti(t.message)}"><code>${Ti(e.raw)}</code></span>`}}const Pi=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,Zi=e=>Pi.test(e.trim())?Ti(e.trim()):"#";function Bi(e,t,n){const r=[],i=e=>(r.push(e),`${r.length-1}`);let s=e;return s=s.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(e,t,r)=>i(`<code>${Ti(n(r.trim()))}</code>`)),s=s.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(e,t)=>i(Ti(t))),s=s.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(e,t)=>i(`<a href="${Zi(t)}">${Ti(t)}</a>`)),t.html&&(s=s.replace(/<\/?[A-Za-z][^>]*>/g,e=>i(e))),s=s.replace(/!\[([^\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,t,n,r)=>i(`<img src="${Zi(n)}" alt="${Ti(t)}"${r?` title="${Ti(r)}"`:""}>`)),s=s.replace(/\[([^\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,r,s,o)=>i(`<a href="${Zi(s)}"${o?` title="${Ti(o)}"`:""}>${Bi(r,t,n)}</a>`)),s=Ti(s),s=s.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),s=s.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),s=s.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),s=s.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),s=s.replace(/( {2,}|\\)\n/g,"<br>\n"),s.replace(/(\d+)/g,(e,t)=>r[Number(t)])}const Wi=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,Di=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,Ui=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;function Hi(e,t,n){const r=[];let i=0;const s=e=>Bi(e,t,n);for(;i<e.length;){const o=e[i];if(!o.trim()){i++;continue}const a=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(o);if(a){const t=[];for(i++;i<e.length&&!new RegExp(`^ {0,3}${"`"===a[1][0]?"`":"~"}{${a[1].length},}\\s*$`).test(e[i]);)t.push(e[i++]);i++;const s=a[2]?` class="language-${Ti(a[2])}"`:"";r.push(`<pre><code${s}>${Ti(n(t.join("\n")))}</code></pre>`);continue}const l=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/.exec(o);if(l){r.push(`<h${l[1].length}>${s(l[2])}</h${l[1].length}>`),i++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(o)){r.push("<hr>"),i++;continue}if(/^ {0,3}>/.test(o)){const s=[];for(;i<e.length&&e[i].trim()&&(/^ {0,3}>/.test(e[i])||s.length);)s.push(e[i].replace(/^ {0,3}> ?/,"")),i++;r.push(`<blockquote>\n${Hi(s,t,n)}\n</blockquote>`);continue}const c=Di.exec(o);if(c){const s=/\d/.test(c[2]),o=s?parseInt(c[2],10):1,a=[];let l=!1;for(;i<e.length;){const t=Di.exec(e[i]);if(!t||/\d/.test(t[2])!==s)break;const n=t[0].length,r=[e[i].slice(n)];for(i++;i<e.length;){const t=e[i];if(!t.trim()){const t=e[i+1];if(void 0!==t&&t.startsWith(" ".repeat(Math.min(n,4)))&&t.trim()){r.push(""),l=!0,i++;continue}void 0!==t&&Di.test(t)&&(l=!0);break}if(t.startsWith(" ".repeat(Math.min(n,4))))r.push(t.slice(Math.min(n,4)));else{if(Di.test(t)||Wi.test(t))break;r.push(t)}i++}for(a.push(r);i<e.length&&!e[i].trim()&&void 0!==e[i+1]&&Di.test(e[i+1]);)i++}const h=s?"ol":"ul",u=a.map(e=>{let r=Hi(e,t,n);return l||(r=r.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${r}</li>`});r.push(`<${h}${s&&1!==o?` start="${o}"`:""}>\n${u.join("\n")}\n</${h}>`);continue}if(o.includes("|")&&void 0!==e[i+1]&&Ui.test(e[i+1])&&e[i+1].includes("-")){const t=e=>e.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(e=>e.trim()),n=t(e[i+1]).map(e=>e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":e.startsWith(":")?"left":""),a=(e,t,r)=>`<${e}${n[r]?` style="text-align:${n[r]}"`:""}>${s(t)}</${e}>`,l=t(o);i+=2;const c=[];for(;i<e.length&&e[i].trim()&&e[i].includes("|");)c.push(t(e[i++]));r.push(`<table>\n<thead><tr>${l.map((e,t)=>a("th",e,t)).join("")}</tr></thead>\n<tbody>\n${c.map(e=>`<tr>${l.map((t,n)=>a("td",e[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(o)){const t=[];for(;i<e.length&&(/^( {4}|\t)/.test(e[i])||!e[i].trim());)t.push(e[i++].replace(/^( {4}|\t)/,""));for(;t.length&&!t[t.length-1].trim();)t.pop();r.push(`<pre><code>${Ti(n(t.join("\n")))}</code></pre>`);continue}const h=[];for(;i<e.length&&e[i].trim()&&(!h.length||!Wi.test(e[i])||/^ {0,3}[-=]+\s*$/.test(e[i]));){if(h.length&&/^ {0,3}(=+|-+)\s*$/.test(e[i])){const t="="===e[i].trim()[0]?1:2;r.push(`<h${t}>${s(h.join("\n"))}</h${t}>`),h.length=0,i++;break}h.push(e[i].replace(/^ {0,3}/,"")),i++}h.length&&r.push(`<p>${s(h.join("\n"))}</p>`)}return r.join("\n")}function Gi(e,t={},n=e=>e){return Hi(String(e).replace(/\r\n?/g,"\n").split("\n"),t,n)}function Xi(e,t={}){const{text:n,math:r}=zi(e,t),i={...t.scope??{}},s=r.map(e=>Fi(e,t,i));return(t.render?t.render(n):Gi(n,t,e=>e.replace(Ci,(e,t)=>r[Number(t)].raw))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(e,t)=>r[Number(t)].display?`<div class="mv-md-block">${s[Number(t)]}</div>`:e).replace(Ci,(e,t)=>s[Number(t)])}var Vi='/*\n * Inline Math stylesheet. Everything is under .mv; colours are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight colour\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; border-top: 0.06em solid currentColor; padding-top: 0.08em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; background: linear-gradient(to top right, transparent calc(50% - 0.04em), currentColor calc(50% - 0.03em), currentColor calc(50% + 0.03em), transparent calc(50% + 0.04em)); }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with maths (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n';const Qi=Vi;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Vi,document.head.append(e)}return e.CSS=Qi,e.DEFAULTS=pi,e.PATHS=Xr,e.View=Li,e.extractMath=zi,e.layout=bi,e.markdownToHTML=Xi,e.nodeAt=Ni,e.numberTree=_i,e.pathOf=Ei,e.render=function(e,t,n={}){return new Li(e,t,n)},e.renderMarkdown=Gi,e.renderMarkdownInto=function(e,t,n={}){return e.innerHTML=Xi(t,n),e},e.select=Mi,e.signature=vi,e.toHTML=qi,e.treeOf=Si,e}({});
1
+ /* Inline Math 0.2.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
2
+ var InlineMath=function(t){"use strict";const e=-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:r(1),abs:r(1),floor:r(1),ceil:r(1),det:r(1),ln:r(1),loglog:r(1),logloglog:r(1),expm1:r(1),sin:r(1),cos:r(1),tan:r(1),csc:r(1),sec:r(1),cot:r(1),sinh:r(1),cosh:r(1),tanh:r(1),arcsin:r(1),arccos:r(1),arctan:r(1),arcsinh:r(1),arccosh:r(1),arctanh:r(1),random:r(0),log:r(2),root:r(2),atan2:r(2),round:r(2),fixed:r(2),perm:r(2),comb:r(2),der:r(2),max:r(e),min:r(e),gcd:r(e),mean:r(e),sum:r(e),prod:r(e),int:r(e),lim:r(e),"\\sumidx":r(e),"\\prodidx":r(e),pmatrix:r(e),bmatrix:r(e),vmatrix:r(e),"()":i(),"[]":i(),"{}":i(),"(]":i(),"[)":i(),"=":{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 r(t){return{prec:100,assoc:"none",arity:t,fixity:"prefix"}}function i(){return{prec:5,assoc:"left",arity:e,fixity:"none",group:!0}}const s="\\:",o=t=>"string"==typeof t&&t.startsWith(s)&&t.length>2;function a(t){return Object.prototype.hasOwnProperty.call(n,t)?n[t]:o(t)?l:void 0}const l=r(e),c=t=>a(t)?.prec;function u(t,e,n){if("mod"===t&&e)return c(e)<=70;if("mod"===e&&["*","/"].includes(t))return!0;if("mod"===e&&["+","-","±"].includes(t))return"right"===n;const r=c(t),i=c(e);if(!r||!i)return!1;if(i!==r)return i<r;const s=a(t).assoc;return"left"===s?"right"===n:"right"===s&&"left"===n}const h=100,p={ln:h,log:h,loglog:h,logloglog:h,sqrt:h,sqrtpow:h,pow:h,expm1:h,der:h,lim:h,int:h,round:h,fixed:h,floor:h,ceil:h,abs:h,random:h,sum:h,prod:h,"\\sumidx":h,"\\prodidx":h,perm:h,comb:h,"\\perm":h,"\\comb":h,"\\binom":h,max:h,min:h,gcd:h,mean:h,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"?:":10,"?":9,",":5},m=t=>Object.prototype.hasOwnProperty.call(p,t),f=new Set(["^","?:","?","log"]),d=["(","{","["],g=[")","}","]"];function b(t,e=!1){if(!t)return!1;for(let n=0;n<t.length;n++)if(!("0123456789.".includes(t[n])||e&&0===n&&"-"===t[n]&&t.length>1))return!1;return!0}for(const t of[p])Object.setPrototypeOf(t,null);const $=t=>({type:"number",value:String(t)}),y=t=>({type:"symbol",value:t}),v=(t,e)=>({type:"op",op:t,args:e}),x=['"',"'","`"];function w(t){return b(t,!0)?$(t):x.includes(t[0])?{type:"string",value:t}:y(t)}const M={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function k(t){if(!Array.isArray(t)||0===t.length)throw new Error("Empty postfix");const n=[],r=[];if(t.forEach((t,i)=>{const s=M[t]??String(t),o=a(s);if(!o)return n.push({...w(s),id:i}),void r.push(1);let l=o.arity;if(l===e){const t=n.pop();if(r.pop(),l=t&&"number"===t.type?Number(t.value):NaN,!Number.isInteger(l)||l<0)throw new Error(`'${s}' takes a variable number of arguments, so it must follow a count`)}if(n.length<l)throw new Error(`'${s}' needs ${l} operand${1===l?"":"s"}`);const c=1+Math.max(0,...r.splice(r.length-l,l));if(c>1e3)throw new Error("Nested too deeply (more than 1000 levels)");r.push(c),n.push({...v(s,n.splice(n.length-l,l)),id:i})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function A(t){const n=[];return function t(r){"op"===r.type?(r.args.forEach(t),a(r.op)?.arity===e&&n.push(String(r.args.length)),n.push(r.op)):n.push(r.value)}(t),n}function E(t){if(Array.isArray(t))return k(t);if(t&&"object"==typeof t&&t.type)return t;throw new Error("Expected a postfix array or an expression tree")}function N(t,e,n=null){e(t,n),"op"===t.type&&t.args.forEach(n=>N(n,e,t))}function O(t){let e="";return N(t,t=>{!e&&"symbol"===t.type&&1===t.value.length&&/[a-zA-Zʹ-Ͽ]/.test(t.value)&&(e=t.value)}),e}for(const t of[M])Object.setPrototypeOf(t,null);const _={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 S(t){for(;"op"===t.type&&t.args.length;)t=t.args[0];return"op"===t.type?"":t.value}function I(t){if("*"!==t.op)return!1;const[e,n]=t.args;return"number"===e.type&&"-1"===e.value&&"-1"!==S(n)}function q(t){return"op"!==t.type||a(t.op)?.group?null:"sum"===t.op?"+":"prod"===t.op?"*":I(t)?null:t.op}const L=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),C=(t,e,n)=>("op"!==e.type||"?:"!==e.op||!L.has(t.op))&&u(t.op,q(e),n);function T(t,e){const n=q(e),r=n&&a(n)?.prec;return!!r&&("!"===t?r<=a("!").prec:"\\not"===t?r<a("\\not").prec:r<70||B(e)||"\\not"===n)}function z(t,e,n={}){const r=n.left?"bracket":P(t),i=n.right?"bracket":F(e);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function j(t){return 1===t.length||Boolean(_[t])||/^Δ.$/.test(t)||/^.′+$/.test(t)}function R(t){return"op"===t.type&&!a(t.op)?.group&&(a(t.op)?.prec??100)<70&&!["sum","prod"].includes(t.op)}function F(t){if("number"===t.type)return t.value.startsWith("-")?"sign":"digit";if("op"!==t.type)return"symbol"===t.type&&j(t.value)?"name":"word";const e=t.op;return"neg"===e||"pm"===e||I(t)?"sign":"/"===e?"frac":a(e)?.group||R(t)?"bracket":Z(t)||["der","int","lim","comb"].includes(e)?"call":["^","!","_"].includes(e)?R(t.args[0])?"bracket":F(t.args[0]):["*","sum","prod","perm"].includes(e)?F(t.args[0]):"other"}function P(t){if("number"===t.type)return"digit";if("op"!==t.type)return"symbol"===t.type&&j(t.value)?"name":"word";const e=t.op;return"/"===e?"frac":"^"===e||"_"===e?"script":a(e)?.group||R(t)||Z(t)||["der","int","lim","comb","perm"].includes(e)?"bracket":["*","neg","pm","sum","prod"].includes(e)?P(t.args[t.args.length-1]):"other"}function Z(t){if("op"!==t.type)return!1;const e=a(t.op);return"prefix"===e?.fixity&&100===e.prec}function B(t){if("number"===t.type)return t.value.startsWith("-");if("op"!==t.type)return!1;if("neg"===t.op||I(t))return!0;const e=a(t.op);return"infix"===e?.fixity&&!C(t,t.args[0],"left")&&B(t.args[0])}const W=t=>"symbol"===t.type&&1===t.value.length&&/[a-zA-Zʹ-Ͽ]/.test(t.value),D=t=>t.slice(2);function U(t){const e=t.args[1];let n=0,r=t;for(;"op"===r.type&&"der"===r.op&&H(r.args[1],e);)n++,r=r.args[0];return{n:n,body:r,by:e,variable:"symbol"===r.type&&j(r.value)}}const H=(t,e)=>t.type===e.type&&t.value===e.value&&"op"!==t.type,G=new Set(["<",">","≤","≥","=","≠"]);function V(t){if("op"!==t.type||!G.has(t.op)||2!==t.args.length)return null;const[e,n]=t.args;if("op"!==e.type||!G.has(e.op)||2!==e.args.length)return null;return{type:"op",op:"&",args:[V(e)??e,{type:"op",op:t.op,args:[e.args[1],n]}]}}for(const t of[_])Object.setPrototypeOf(t,null);const X={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function Q(t){if(!t||"op"!==t.type)return null;if(Object.prototype.hasOwnProperty.call(X,t.op))return t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args:[t]);if("[]"!==t.op||!t.args.length||!t.args.every(t=>"op"===t.type&&"[]"===t.op))return null;const e=t.args[0].args.length;return!e||!t.args.every(t=>t.args.length===e)||t.args.length<2&&e<2?null:t.args.map(t=>t.args)}function J(t){return Array.isArray(t)&&t.length>0&&t.every(e=>Array.isArray(e)&&e.length>0&&e.length===t[0].length&&!e.some(Array.isArray))}const Y=t=>Array.isArray(t)&&t.length>0&&!t.some(Array.isArray);function K(t){const e=t,n=e.make??(t=>t),r=e.size??(()=>1),i=t=>`${t.length} by ${t[0].length}`,s=(t,r)=>n(Array.from({length:t},(n,r)=>Array.from({length:t},(t,n)=>r===n?e.one():e.zero())),r);function o(t,r){return t[0].length!==r.length&&e.fail(`a ${i(t)} matrix times a ${i(r)} one`),n(t.map(t=>r[0].map((n,i)=>t.reduce((t,n,s)=>e.add(t,e.mul(n,r[s][i])),e.zero()))),t)}function a(t){const n=t.map(t=>t.slice()),i=n.length,s=n[0].length;let o=e.one(),a=0;for(let t=0;t<s&&a<i;t++){let s=-1;for(let o=a;o<i;o++)e.isZero(n[o][t])||(s<0||r(n[o][t])>r(n[s][t]))&&(s=o);if(s<0){o=e.zero();continue}s!==a&&([n[s],n[a]]=[n[a],n[s]],o=e.sub(e.zero(),o));const l=n[a][t];o=e.mul(o,l),n[a]=n[a].map(t=>e.div(t,l));for(let r=0;r<i;r++){if(r===a||e.isZero(n[r][t]))continue;const i=n[r][t];n[r]=n[r].map((t,r)=>e.sub(t,e.mul(i,n[a][r])))}a++}return a<i&&(o=e.zero()),{M:n,det:o,rank:a}}function l(t){const r=t.length;r!==t[0].length&&e.fail(`a ${i(t)} matrix has no inverse`);const o=s(r),{M:l,rank:c}=a(t.map((t,e)=>[...t,...o[e]]));return(c<r||l.some((t,n)=>e.isZero(t[n])))&&e.fail("the matrix has no inverse (its determinant is 0)"),n(l.map(t=>t.slice(r)),t)}return{identity:s,transpose:t=>n(t[0].map((e,n)=>t.map(t=>t[n])),t),times:o,det:function(t){return t.length!==t[0].length&&e.fail(`a ${i(t)} matrix has no determinant`),a(t).det},inverse:l,power:function(t,n){t.length!==t[0].length&&e.fail(`a ${i(t)} matrix has no powers`);let r=n<0n?l(t):t,a=n<0n?-n:n,c=s(t.length,t);for(;a>0n;)1n&a&&(c=o(c,r)),r=o(r,r),a>>=1n;return c},trace:t=>(t.length!==t[0].length&&e.fail(`a ${i(t)} matrix has no trace`),t.reduce((t,n,r)=>e.add(t,n[r]),e.zero())),dot:(t,n)=>(t.length!==n.length&&e.fail("vectors of different lengths"),t.reduce((t,r,i)=>e.add(t,e.mul(r,n[i])),e.zero())),cross:(t,n)=>(3===t.length&&3===n.length||e.fail("the cross product is for vectors of 3 numbers"),[e.sub(e.mul(t[1],n[2]),e.mul(t[2],n[1])),e.sub(e.mul(t[2],n[0]),e.mul(t[0],n[2])),e.sub(e.mul(t[0],n[1]),e.mul(t[1],n[0]))]),solve:function(t,e){return J(e)?o(l(t),e):o(l(t),e.map(t=>[t])).map(t=>t[0])},rank:t=>a(t).rank,rref:t=>n(a(t).M,t),timesVector:(t,e)=>o(t,e.map(t=>[t])).map(t=>t[0]),vectorTimes:(t,e)=>o([t],e)[0]}}function tt(t){const e=new Map;for(const[n,r,i]of t)if(n&&""!==n.trim()&&(e.set(n,r),!i))for(const t of nt(n))e.get(t)||e.set(t,r);const n=new Map;for(const t of e.keys()){let e=n;for(let n=0;n<t.length;n++)e.has(t[n])||e.set(t[n],new Map),e=e.get(t[n]);e.end=!0}return t=>{let r="",i=0;for(;i<t.length;){const s=et(n,t,i);s?(r+=e.get(t.slice(i,i+s)),i+=s):r+=t[i++]}return r}}function et(t,e,n){let r=t,i=0;for(let t=n;t<e.length&&(r=r.get(e[t]),r);t++)r.end&&(i=t-n+1);return i}function nt(t){const e=new Set([t.toLowerCase(),t.toUpperCase(),rt(t)]);return e.delete(t),e}function rt(t){let e="",n=!1;for(const r of t){const t=r>="a"&&r<="z",i=r>="A"&&r<="Z";e+=!n&&t?r.toUpperCase():r,n=t||i}return e}const it="({[",st=")}]";function ot(t){const e=t.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(e)?"":e}function at(t,e){const n=[];let r=0,i=0;for(let s=0;s<t.length;s++)it.includes(t[s])?r++:st.includes(t[s])?r--:0===r&&t.startsWith(e,s)&&(n.push(t.slice(i,s)),s+=e.length-1,i=s+1);return n.push(t.slice(i)),n}function lt(t,e,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=e;n<t.length;n++)if(it.includes(t[n]))r++;else if(st.includes(t[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(t)))return n;return-1}function ct(t,e){let n=0;for(let r=e;r<t.length;r++)if(it.includes(t[r]))n++;else if(st.includes(t[r])&&--n<0)return r;return t.length}function ut(t,e){let n=1;for(let r=e+1;r<t.length;r++)if("?"===t[r])n++;else if(":"===t[r]&&0===--n)return t.slice(0,e+1)+"("+t.slice(e+1,r)+")?:"+t.slice(r+1);return t}function ht(t){for(let e=2;e<t.length;e++)if("g"===t[e]&&"log"===t.slice(e-2,e+1))if("_"===t[e+1]){if(it.includes(t[e+2]))continue;const n=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(t.slice(e+2))?.[0];if(!n)continue;const r=e+2+n.length;t=t.slice(0,e+2)+"{"+n+"}"+t.slice(r)}else if("("===t[e+1]){let n=1,r=0,i="",s="",o=0;for(let a=e+2;a<t.length;a++){if(")]".includes(t[a])?n--:"([".includes(t[a])&&n++,0===n){o=a;break}1===n&&","===t[a]?r++:0===r?i+=t[a]:s+=t[a]}1===r&&(t=t.slice(0,e+1)+"_{"+s+"}("+i+")"+t.slice(o+1))}return t}function pt(t){const e="⌈"===t[0]?"ceil":"floor";let n=1;for(let r=1;r<t.length;r++)if("⌊"===t[r]||"⌈"===t[r]?n++:"⌋"!==t[r]&&"⌉"!==t[r]||n--,0===n)return e+"("+t.slice(1,r)+")"+t.slice(r+1);return t}function mt(t){let e=1;for(let n=0;n<t.length;n++){if(")]".includes(t[n])?e--:"([".includes(t[n])&&e++,0!==e)continue;const r=t.slice(0,n),i=t[n+1];if("{"===i||"("===i)return i+r+","+t.slice(n+2);const s=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(t.slice(n+1))?.[0]??"";return"{"+r+","+s+"}"+t.slice(n+1+s.length)}return t}const ft=new Set(["pmatrix","bmatrix","vmatrix"]);function dt(t){const e=t.indexOf("}"),n=t.indexOf("{");if(e<0||n>=0&&n<e)return!1;const r=t.slice(0,e);if(!r.includes("matrix"))return!1;const i=t.indexOf("\\end{"+r+"}"),s=t.indexOf("\\begin{"+r+"}",e+1);if(i<0||-1!==s&&s<i)return!1;const o=t.slice(e+1,i).trim().split("\\\\").map(t=>t.trim()).filter(t=>t.length).map(t=>"["+t.replace(/&/g,", ")+"]"),a=t.slice(i+6+r.length);return ft.has(r)?r+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function gt(t,e){if("{"!==t[e+1])return[t[e+1],e+2];let n=1,r="";for(let i=e+2;i<t.length;i++){if("{"===t[i])n++;else if("}"===t[i]&&0===--n)return[r,i+1];r+=t[i]}return[r,t.length]}function bt(t){const{lower:e,upper:n,next:r}=function(t){let e="",n="",r=0;return"_"===t[0]&&([e,r]=gt(t,0),"^"===t[r]&&([n,r]=gt(t,r))),{lower:e,upper:n,next:r}}(t),i=t.slice(r),s=t=>t.replace(/\\,/g,"").replace(/\\!/g,"");let o,a="",l="",c=i.indexOf("\\mathrm{d}");if(c>=0){o=i.slice(0,c);const t=/^\{([^{}]*)\}/.exec(i.slice(c+10));a=t?t[1]:i[c+10],l=i.slice(c+10+(t?t[0].length:1))}else(c=function(t){let e=0;for(let n=0;n<t.length;n++)if(it.includes(t[n]))e++;else if(st.includes(t[n]))e--;else if(0===e&&"d"===t[n]&&/[A-Za-z\u0370-\u03FF]/.test(t[n+1]??"")&&!/[A-Za-z]/.test(t[n+2]??""))return n;return-1}(i))>=0?(o=i.slice(0,c),a=i[c+1],l=i.slice(c+2)):o=i;if(!a){const t=/frac\{d([A-Za-z])\}/.exec(o);t&&(a=t[1],o=o.replace(t[0],"frac{1}"))}if(!a&&/^[A-Za-z]$/.test(e)){a=[...s(o).matchAll(/(?<![A-Za-z\\])([A-Za-z])(?![A-Za-z(])/g)].map(t=>t[1]).find(t=>t!==e&&t!==n)??"x"}let u="int("+(s(o)||"1");return a&&(u+=","+a),(e||n)&&(u+=","+e+","+n),u+")"+l}function $t(t){const e=t[0];if(!(e>="A"&&e<="Z"||e>="a"&&e<="z"||e>="α"&&e<="ω"))return!1;const n=t.slice(2);let r=1;for(let t=0;t<n.length;t++)if(st.includes(n[t])?r--:it.includes(n[t])&&r++,0===r)return"("+n.slice(0,t)+","+e+")"+n.slice(t+1);return!1}function yt(t){return"{"===t[0]||t.length<2?t:"{"+t[0]+"}{"+t[1]+"}"+t.slice(2)}const vt=/[A-Za-z\u0370-\u03FF]/;function xt(t,e){if("{"!==t[e])return null;let n=0;for(let r=e;r<t.length;r++)if("{"===t[r])n++;else if("}"===t[r]&&0===--n)return[t.slice(e+1,r),r+1];return null}function wt(t,e){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(t.slice(e));return n?[Number(n[1]??n[2]),e+n[0].length]:[1,e]}function Mt(t,e){const n=t.replace(/\\mathrm\{d\}/g,"d"),r=e.replace(/\\mathrm\{d\}/g,"d"),i=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(n),s=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(r);return i&&s?{n:Number(i[1]??1),of:i[2],by:s[1]}:null}function kt(t,e){if(it.includes(t[e])){let n=0;for(let r=e;r<t.length;r++)if(it.includes(t[r]))n++;else if(st.includes(t[r])&&0===--n)return[t.slice(e,r+1),r+1];return[t.slice(e),t.length]}let n=0;for(let r=e;r<t.length;r++)if(it.includes(t[r]))n++;else{if(st.includes(t[r])&&--n<0)return[t.slice(e,r),r];if(0===n&&("="===t[r]||","===t[r]))return[t.slice(e,r),r]}return[t.slice(e),t.length]}const At=(t,e,n)=>`der(${t},${e}${n>1?","+n:""})`;const Et="strtktk",Nt="ABCDEFGHIJ",Ot=t=>Et+[...String(t)].map(t=>Nt[t]).join("");function _t(t,e){let n=!1;for(let r=e+1;r<t.length;r++)if(n)n=!1;else if("\\"===t[r])n=!0;else if(t[r]===t[e])return r;return t.length-1}function St(t,e){if(!e||0===e.size)return t;const n=[...e].sort((t,e)=>e[0].length-t[0].length);return t.map(t=>{for(const[e,r]of n)t=t.split(e).join(r);return t})}const It={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { let r = 1; for (let i = n - k + 1; i <= n; i++) r *= i; return r; })",comb:"((n, k) => { let r = 1; for (let i = 1; i <= k; i++) r = r * (n - k + i) / i; return r; })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})"};for(const t of[It])Object.setPrototypeOf(t,null);const qt="([{",Lt=")]}";function Ct(t,e){let n=0;for(let r=e;r<t.length;r++)if(qt.includes(t[r]))n++;else if(Lt.includes(t[r])&&0===--n)return r;return-1}function Tt(t){if(!t.trim())return[];const e=[];let n=0,r=0;for(let i=0;i<t.length;i++)qt.includes(t[i])?n++:Lt.includes(t[i])?n--:","===t[i]&&0===n&&(e.push(t.slice(r,i).trim()),r=i+1);return e.push(t.slice(r).trim()),e}function zt(t,e,n){const r=[...t.matchAll(e)];for(let e=r.length-1;e>=0;e--){const i=r[e],s=i.index+i[0].length-1,o=Ct(t,s);if(o<0)continue;const a=n(Tt(t.slice(s+1,o)),i,t.slice(o+1));if(null==a)continue;const[l,c=0]=Array.isArray(a)?a:[a];if((t=t.slice(0,i.index)+l+t.slice(o+1+c)).length>1e5)throw new Error("The expression expands too much when read")}return t}const jt=t=>new RegExp(`(?<![\\w.])(${t})\\s*\\(`,"g"),Rt=t=>`(${t})`,Ft=t=>/^\[.*\]$/s.test(t.trim())?`{${t.trim().slice(1,-1)}}`:t;const Pt={IF:t=>t.length>=2&&`((${t[0]}) ? (${t[1]}) : (${t[2]??"false"}))`,AND:t=>t.length&&`(${t.map(Rt).join(" & ")})`,OR:t=>t.length&&`(${t.map(Rt).join(" ∨ ")})`,NOT:t=>1===t.length&&`(!(${t[0]}))`,XOR:t=>2===t.length&&`((${t[0]}) \\xor (${t[1]}))`,LOG:t=>2===t.length?`log_{${t[1]}}(${t[0]})`:1===t.length&&`log_{10}(${t[0]})`,ATAN2:t=>2===t.length&&`atan2(${t[1]}, ${t[0]})`,INT:t=>1===t.length&&`floor(${t[0]})`,FIXED:t=>(1===t.length||2===t.length)&&`fixed(${t[0]}, ${t[1]??2})`,"FLOOR.MATH":t=>1===t.length&&`floor(${t[0]})`,"CEILING.MATH":t=>1===t.length&&`ceil(${t[0]})`,FACT:t=>1===t.length&&`((${t[0]})!)`,COMBIN:t=>2===t.length&&`comb(${t.join(", ")})`,PERMUT:t=>2===t.length&&`perm(${t.join(", ")})`,AVERAGE:t=>`mean(${t.join(", ")})`,SUM:t=>`sum(${t.join(", ")})`,PRODUCT:t=>`prod(${t.join(", ")})`,MAX:t=>`max(${t.join(", ")})`,MIN:t=>`min(${t.join(", ")})`,MEDIAN:t=>`median(${t.join(", ")})`,"STDEV.P":t=>`stdev(${t.join(", ")})`,STDEVP:t=>`stdev(${t.join(", ")})`,CEILING:t=>(1===t.length||2===t.length&&"1"===t[1].trim())&&`ceil(${t[0]})`,RAND:t=>!t.length&&"random()",ISNUMBER:t=>1===t.length&&`((${t[0]}) ∈ ℝ)`,LOG10:t=>1===t.length&&`log_{10}(${t[0]})`};const Zt={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"},Bt="strtktk[A-J]+";function Wt(t){for(let e=!0;e;){const n=t;e=(t=t.replace(new RegExp(`(${Bt})\\s*\\|\\|\\s*(${Bt})`,"g"),"$1 + $2"))!==n}const e=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${Bt},\\s*${Bt}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=t.lastIndexOf("(typeof(");n>=0;n=n>0?t.lastIndexOf("(typeof(",n-1):-1){const r=Ct(t,n),i=r>0&&e.exec(t.slice(n,r+1));if(!i)continue;const[,s,o]=i,a={[`${s} = TRUNC(${s})`]:"ℤ",[`${s} = TRUNC(${s}) AND ${s} > 0`]:"ℕ",[`ABS(${s}) < ∞`]:"ℝ"}[o.trim()];a&&(t=`${t.slice(0,n)}((${s}) ∈ ${a})${t.slice(r+1)}`)}t=zt(t,/(?<![\w.])CAST\s*\(/gi,t=>{const e=1===t.length&&/^(.*)\s+AS\s+(?:REAL|FLOAT|DOUBLE(?:\s+PRECISION)?|NUMERIC|DECIMAL|INTEGER|INT)\s*$/is.exec(t[0]);return e?`(${e[1]})`:null}),t=(t=(t=zt(t=function(t){for(let e=0;e<50;e++){const e=[...t.matchAll(/\bCASE\s+WHEN\b/gi)];if(!e.length)return t;const n=e[e.length-1].index,r=/\bEND\b/i.exec(t.slice(n));if(!r)return t;const i=t.slice(n+4,n+r.index).split(/\b(WHEN|THEN|ELSE)\b/i).map(t=>t.trim()),s=[];let o="null";for(let t=1;t<i.length;t+=2){const e=i[t].toUpperCase();"WHEN"===e?s.push([i[t+1],i[t+3]]):"ELSE"===e&&(o=i[t+1])}const a=s.reduceRight((t,[e,n])=>`((${e}) ? (${n}) : ${t})`,Rt(o));t=t.slice(0,n)+a+t.slice(n+r.index+3)}return t}(t=t.replace(/(?<![\w.])ARRAY\s*\[/g,"[")),/(?<![\w.])LOG\s*\(/g,t=>2===t.length?`log_{${t[0]}}(${t[1]})`:`log_{10}(${t[0]})`)).replace(/(?<![\w.])PI\s*\(\s*\)/g,"π")).replace(/(?<![\w.])([A-Z][A-Z0-9]*)(?=\s*\()/g,t=>Zt[t]??t);for(const[e,n]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let r=e.exec(t);r;r=e.exec(t)){const i=r.index+r[0].length-1,s=Ct(t,i);if(s<0)break;t=`${t.slice(0,r.index)}${n} {${t.slice(i+1,s)}}${t.slice(s+1)}`,e.lastIndex=0}return t.replace(/<>/g," ≠ ")}const Dt={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"},Ut={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc"};function Ht(t){return t=(t=(t=(t=t.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,(t,e)=>Dt[e]?`Math.${Dt[e]}`:Ut[e]?Ut[e]:{inf:"∞",nan:"NaN"}[e]??t),t=function(t){return t=t.replace(/(?<![\w.])sympy\.Interval\.(open|Lopen|Ropen)\s*\(/g,(t,e)=>`sympy_interval_${e}(`),t=t.replace(/(?<![\w.])sympy\.S\.(\w+)/g,(t,e)=>Vt[e]??t),t=t.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(t,e)=>Vt[e]),t.replace(/(?<![\w.])sympy\.(\w+)/g,(t,e)=>Xt[e]??Gt[e]??t)}(t=(t=(t=t.replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(t,e)=>({inf:"∞",nan:"NaN"}[e]??e))).replace(/(?<![\w.])Number\.(isInteger|isFinite)\b/g,(t,e)=>e.toLowerCase())).replace(/(?<![\w.])scipy\.(?:special|integrate)\.(\w+)/g,"$1")),(t=t.replace(/\bMZ_INFINITY\b/g,"∞")).replace(/(?<![\w.])mz_(?=\w+\s*\()/g,"")}const Gt={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Vt={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},Xt={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},Qt={open:"()",Lopen:"(]",Ropen:"[)"};const Jt=t=>{const e=/^\((.*)\)$/s.exec(t.trim());return e?Tt(e[1]):null},Yt=t=>e=>2===e.length&&`${t[0]}${e[0]}, ${e[1]}${t[1]}`,Kt=t=>Jt(t)??[t],te={where:t=>3===t.length&&`((${t[0]}) ? (${t[1]}) : (${t[2]}))`,logical_and:t=>2===t.length&&`((${t[0]}) & (${t[1]}))`,logical_or:t=>2===t.length&&`((${t[0]}) ∨ (${t[1]}))`,logical_xor:t=>2===t.length&&`((${t[0]}) \\xor (${t[1]}))`,logical_not:t=>1===t.length&&`(!(${t[0]}))`,isin:t=>2===t.length&&`((${t[0]}) ∈ ${Ft(t[1])})`,contains:t=>2===t.length&&`((${t[1]}) ∈ ${Ft(t[0])})`,isclose:t=>t.length>=2&&`((${t[0]}) ≈ (${t[1]}))`,isfinite:t=>1===t.length&&`((${t[0]}) ∈ ℝ)`,isinteger:t=>1===t.length&&`((${t[0]}) ∈ ℤ)`,factorial:t=>1===t.length&&`((${t[0]})!)`,union:t=>2===t.length&&`((${t[0]}) ∪ (${t[1]}))`,union_:t=>2===t.length&&`((${t[0]}) ∪ (${t[1]}))`,intersection:t=>2===t.length&&`((${t[0]}) ∩ (${t[1]}))`,sq:t=>1===t.length&&`((${t[0]})^2)`,cube:t=>1===t.length&&`((${t[0]})^3)`,fract:t=>1===t.length&&`((${t[0]}) - floor(${t[0]}))`,inversesqrt:t=>1===t.length&&`(1/sqrt(${t[0]}))`,mod:t=>2===t.length&&`((${t[0]}) \\mod (${t[1]}))`,atan:t=>2===t.length&&`atan2(${t[0]}, ${t[1]})`,exp2:t=>1===t.length&&`((2)^(${t[0]}))`,trunc:t=>1===t.length&&`((${t[0]}) - ((${t[0]}) \\mod 1))`,vec2:t=>`(${t.join(", ")})`,vec3:t=>`(${t.join(", ")})`,vec4:t=>`(${t.join(", ")})`,derivative:t=>t.length>=2&&`der(${t.join(", ")})`,sympy_rational:t=>2===t.length&&`((${t[0]})/(${t[1]}))`,sympy_value:t=>1===t.length&&`(${t[0]})`,sympy_eq:t=>2===t.length&&`((${t[0]}) = (${t[1]}))`,sympy_ne:t=>2===t.length&&`((${t[0]}) ≠ (${t[1]}))`,sympy_and:t=>t.length&&`(${t.map(Rt).join(" & ")})`,sympy_or:t=>t.length&&`(${t.map(Rt).join(" ∨ ")})`,sympy_not:t=>1===t.length&&`(!(${t[0]}))`,sympy_xor:t=>2===t.length&&`((${t[0]}) \\xor (${t[1]}))`,sympy_nand:t=>2===t.length&&`((${t[0]}) \\nand (${t[1]}))`,sympy_nor:t=>2===t.length&&`((${t[0]}) \\nor (${t[1]}))`,sympy_piecewise:t=>{const e=t.map(Jt);return!e.length||e.some(t=>!t||2!==t.length)?null:e.reduceRight((t,[e,n])=>null===t||/^True$|^true$/.test(n.trim())&&void 0===t?`(${e})`:`((${n}) ? (${e}) : ${t??"(null)"})`,void 0)},sympy_set:t=>`{${t.join(", ")}}`,sympy_interval:Yt("[]"),sympy_interval_open:Yt("()"),sympy_interval_Lopen:Yt("(]"),sympy_interval_Ropen:Yt("[)"),sympy_contains:t=>2===t.length&&`((${t[0]}) ∈ ${t[1]})`,sympy_list_gcd:t=>1===t.length&&`gcd(${t[0].trim().replace(/^\[|\]$/g,"")})`,sympy_root:t=>2===t.length&&`root(${t[1]}, ${t[0]})`,sympy_integrate:t=>{if(2!==t.length)return null;const e=Kt(t[1]);return 3===e.length?`int(${t[0]}, ${e.join(", ")})`:1===e.length?`int(${t[0]}, ${e[0]})`:null},sympy_limit:t=>t.length>=3&&`lim(${t.slice(0,3).join(", ")}${t[3]?`, ${t[3]}`:""})`,sympy_summation:t=>{if(3===t.length&&/^\s*[A-Za-z]\w*\s*==/.test(t[1]))return`sum(${t[0]}, ${t[1].replace("==","=")}, ${t[2]})`;const e=2===t.length&&Kt(t[1]);return 3===e?.length&&`(\\sum_{${e[0]}=${e[1]}}^{${e[2]}} (${t[0]}))`},sympy_product:t=>{if(3===t.length&&/^\s*[A-Za-z]\w*\s*==/.test(t[1]))return`prod(${t[0]}, ${t[1].replace("==","=")}, ${t[2]})`;const e=2===t.length&&Kt(t[1]);return 3===e?.length&&`(\\prod_{${e[0]}=${e[1]}}^{${e[2]}} (${t[0]}))`},limit:t=>t.length>=3&&`lim(${t.join(", ")})`,summation:t=>3===t.length&&/^\s*[A-Za-z]\w*\s*==/.test(t[1])&&`sum(${t[0]}, ${t[1].replace("==","=")}, ${t[2]})`,sum:ee("sum"),prod:ee("prod")};function ee(t){return e=>{const n=1===e.length&&/^(.*?)\s+for\s+(\w+)\s+in\s+range\((.*)\)\s*$/s.exec(e[0]);if(!n)return null;const r=Tt(n[3]),[i,s]=1===r.length?["0",r[0]]:r,o=/\s*\+\s*1$/.test(s)?s.replace(/\s*\+\s*1$/,""):`(${s}) - 1`;return`(\\${t}_{${n[2]}=${i}}^{${o}} (${n[1]}))`}}for(const t of[Pt,Zt,Dt,Ut,Gt,Vt,Xt,Qt,te])Object.setPrototypeOf(t,null);const ne=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,re=t=>t.trim().split(/\s+/).join(String.raw`\s+`),ie=t=>new RegExp(String.raw`(?<![\w.])${re(t)}(?![\w.])`,"gi"),se=[["is greater than or equal to","≥"],["is more than or equal to","≥"],["is at least","≥"],["is no less than","≥"],["is not less than","≥"],["is less than or equal to","≤"],["is at most","≤"],["is no more than","≤"],["is not more than","≤"],["is not greater than","≤"],["is greater than",">"],["is more than",">"],["is bigger than",">"],["is larger than",">"],["is above",">"],["exceeds",">"],["is less than","<"],["is smaller than","<"],["is fewer than","<"],["is below","<"],["is not equal to","≠"],["does not equal","≠"],["doesn't equal","≠"],["is different from","≠"],["is approximately equal to","≈"],["is approximately","≈"],["is about","≈"],["is roughly","≈"],["is close to","≈"],["is equal to","="],["is the same as","="],["equals","="],["greater than or equal to","≥"],["less than or equal to","≤"],["at least","≥"],["at most","≤"],["greater than",">"],["more than",">"],["less than","<"],["not equal to","≠"],["equal to","="]],oe="[<>≤≥=≠≈]",ae=[["is non-negative","≥ 0"],["is nonnegative","≥ 0"],["is not negative","≥ 0"],["is non-positive","≤ 0"],["is nonpositive","≤ 0"],["is not positive","≤ 0"],["is positive","> 0"],["is negative","< 0"],["is non-zero","≠ 0"],["is nonzero","≠ 0"],["is not zero","≠ 0"],["is zero","= 0"],["is a whole number","∈ ℤ"],["is an integer","∈ ℤ"],["is not an integer","∉ ℤ"],["is a natural number","∈ ℕ"],["is a real number","∈ ℝ"],["is real","∈ ℝ"],["is a rational number","∈ ℚ"],["is rational","∈ ℚ"]];const le=tt([[" 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 ","→"],["===","=...="]]),ce=tt([["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["\\downarrow","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot","*"],["\\times","*"],["×","*"],["·","*"],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],["log2(","log_{2}("],["log3(","log_{3}("],["log4(","log_{4}("],["log5(","log_{5}("],["log6(","log_{6}("],["log7(","log_{7}("],["log8(","log_{8}("],["log9(","log_{9}("],["log10(","log_{10}("],["log_10","log_{10}"],["\\log2(","log_{2}("],["\\log3(","log_{3}("],["\\log4(","log_{4}("],["\\log5(","log_{5}("],["\\log6(","log_{6}("],["\\log7(","log_{7}("],["\\log8(","log_{8}("],["\\log9(","log_{9}("],["\\log10(","log_{10}("],["\\log_10","log_{10}"],["log2{","log_{2}{"],["log3{","log_{3}{"],["log4{","log_{4}{"],["log5{","log_{5}{"],["log6{","log_{6}{"],["log7{","log_{7}{"],["log8{","log_{8}{"],["log9{","log_{9}{"],["log10{","log_{10}{"],["\\log2{","log_{2}{"],["\\log3{","log_{3}{"],["\\log4{","log_{4}{"],["\\log5{","log_{5}{"],["\\log6{","log_{6}{"],["\\log7{","log_{7}{"],["\\log8{","log_{8}{"],["\\log9{","log_{9}{"],["\\log10{","log_{10}{"],["\\log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⊕"," \\xor "],["∞","∞"],["⋅","*"],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0],...function(){const t=[],e=(e,n)=>{t.push([e,n],[e+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(t.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const t of["","h"]){const r=n+t,i="arc"+n+t;t&&(e("Math."+r,r),e("\\"+r,r));for(const n of["^-1","^{-1}","-1"])e("\\"+r+n,i),e(r+n,i),t||e("Math."+r+n,i);t||e("\\a"+r,i),e("\\arc"+r,i),e("Math.a"+r,i),e("Math.arc"+r,i)}return t}()]),ue=[["code",function(t){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(t)?(/^\s*=(?!=)/.test(t)&&(t=function(t){const e="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";t=(t=(t=t.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${e})(?=\\s*\\^)`,"gu"),"$1(-$2)");for(let n=!0;n;){const r=t;n=(t=t.replace(new RegExp(`(^|[^\\p{L}\\p{N}_.)§])(${e}\\s*\\^\\s*${e})(?=\\s*\\^)`,"u"),"$1($2)"))!==r}return zt(t,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(t,e)=>Pt[e[1]]?.(t)||null)}(t)),t=function(t){t=zt(t,jt("quad"),(t,e,n)=>{const r=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(t[0]??"");if(!r||3!==t.length)return null;const i=/^\s*\[\s*0\s*\]/.exec(n);return[`int(${r[2]}, ${r[1]}, ${t[1]}, ${t[2]})`,i?i[0].length:0]}),t=zt(t,jt(Object.keys(te).join("|")),(t,e)=>te[e[1]](t)||null);for(let e=(t=zt(t,jt("float"),(t,e,n)=>{const r=/^\s*\.is_integer\(\s*\)/.exec(n);return r&&1===t.length?[`((${t[0]}) ∈ ℤ)`,r[0].length]:null})).lastIndexOf(".includes(");e>=0;e=e>0?t.lastIndexOf(".includes(",e-1):-1){const n=e+9,r=Ct(t,n);let i=e;if(Lt.includes(t[e-1])){let n=0;for(i=e-1;i>=0;i--)if(Lt.includes(t[i]))n++;else if(qt.includes(t[i])&&0===--n)break}else for(;i>0&&/[\w.]/.test(t[i-1]);)i--;r<0||i<0||i===e||(t=`${t.slice(0,i)}((${t.slice(n+1,r)}) ∈ ${Ft(t.slice(i,e))})${t.slice(r+1)}`)}return t}(t=Ht(t=Wt(t=(t=(t=function(t){for(const[e,n]of Object.entries(It))for(let r=t.lastIndexOf(n);r>=0;r=r>0?t.lastIndexOf(n,r-1):-1){const i=r+n.length,s="("===t[i]?Ct(t,i):-1;if(s<0)continue;let o=t.slice(i+1,s);"gcd"===e&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===e?`((${o})!)`:`${e}(${o})`;t=t.slice(0,r)+a+t.slice(s+1)}for(let e=t.lastIndexOf(").toFixed(");e>=0;e=e>0?t.lastIndexOf(").toFixed(",e-1):-1){const n=e+10-1,r=Ct(t,n),i=t.lastIndexOf("Number(",e);r<0||i<0||Ct(t,i+7-1)!==e||(t=t.slice(0,i)+`fixed(${t.slice(i+7,e)}, ${t.slice(n+1,r)})`+t.slice(r+1))}return t.replace(/\(\(\)=>\{let (sum|prod) = [01]; let loopCount = 0; for \(let (\w+)=(.*?);\2<=(.*?);\2\+\+\) \{if \(loopCount\+\+ > 1000000\)\{break\};\1 [+*]= (.*?);\}; return \1;\}\)\(\)/g,(t,e,n,r,i,s)=>`(\\${"sum"===e?"sum":"prod"}_{${n}=${r}}^{${i}} (${s}))`)}(t)).replace(/(?<![\w.])9e999\b/g,"∞")).replace(/(?<![\w.])(\d+(?:\.\d+)?)[eE]([+-]\d+)(?![\w.])/g,"($1*10^{$2})")))),t=function(t){for(let e=0;e<50;e++){let e=!0;for(const n of t.matchAll(/\bif\b/g)){const r=n.index;let i=0,s=-1,o=t.length;for(let e=r+2;e<t.length;e++)if(qt.includes(t[e]))i++;else{if(Lt.includes(t[e])&&--i<0){o=e;break}if(0===i&&","===t[e]){o=e;break}if(0===i&&/^then\b/.test(t.slice(e))&&/\W/.test(t[e-1])){s=-2;break}0===i&&s<0&&/^else\b/.test(t.slice(e))&&/\W/.test(t[e-1])&&(s=e)}if(s<0)continue;i=0;let a=0;for(let e=r-1;e>=0;e--)if(Lt.includes(t[e]))i++;else{if(qt.includes(t[e])&&--i<0){a=e+1;break}if(0===i&&","===t[e]){a=e+1;break}}const l=t.slice(a,r).trim();if(!l)continue;const c=`((${t.slice(r+2,s).trim()}) ? (${l}) : (${t.slice(s+4,o).trim()}))`;t=t.slice(0,a)+c+t.slice(o),e=!1;break}if(e)return t}return t}(t),(t=(t=t.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 ")):t}],["english",function(t){if(!/[A-Za-z]{2}/.test(t))return t;let e=t;const n=(t,n,r,i="∈")=>{e=e.replace(new RegExp(String.raw`(?<![\w.])${re(t)}\s+(${ne})\s+(?:and|to)\s+(${ne})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(t,e,s,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[n,r];return` ${i} ${a}${e}, ${s}${l} `})};n("is not strictly between","(",")","∉"),n("is not between","[","]","∉"),n("is strictly between","(",")"),n("is between","[","]"),n("between","[","]"),e=e.replace(new RegExp(String.raw`(?<![\w.])is\s+(not\s+)?in\s+the\s+(open|closed|half-open)\s+interval\s+from\s+(${ne})\s+to\s+(${ne})`,"gi"),(t,e,n,r,i)=>{const[s,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[n.toLowerCase()];return` ${e?"∉":"∈"} ${s}${r}, ${i}${o} `});const r=String.raw`(${ne})\s+`;e=e.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${ne})\s*(%|\s+percent)?\s+of\s+(${ne})`,"gi"),(t,e,n,r,i,s)=>`(abs((${e}) - (${s})) ${n?">":"≤"} ${i?`(${r})/100 * ${/^\d+(\.\d+)?$/.test(s)?s:`abs(${s})`}`:`(${r})`})`),e=e.replace(new RegExp(r+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${ne})`,"gi"),"(($1) mod ($2) = 0)"),e=e.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${ne})`,"gi"),(t,e,n,r)=>`((${e}) mod (${r}) ${n?"≠":"="} 0)`),e=e.replace(new RegExp(String.raw`(${ne})\s+divides\s+(${ne})`,"gi"),"(($2) mod ($1) = 0)"),e=e.replace(new RegExp(r+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(t,e,n,r)=>`((${e}) mod 2 ${"even"===r.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[t,n]of ae)e=e.replace(ie(t),` ${n} `);e=e.replace(ie("is not in")," ∉ ").replace(ie("is in")," ∈ ").replace(ie("is an element of")," ∈ ");for(const[t,n]of se)e=e.replace(ie(t),` ${n} `);e=e.replace(ie("is not")," ≠ "),e=e.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let t=!0;t;){const n=e;e=e.replace(new RegExp(String.raw`(${ne})\s*(${oe})\s*(${ne})\s+(and|or)\s+(${oe})`,"gi"),"$1 $2 $3 $4 $1 $5"),t=e!==n}e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${ne})`,"gi"),"abs($1)"),e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${ne})`,"gi"),"sqrt($1)"),e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${ne})`,"gi"),"root(3, $1)"),e=e.replace(new RegExp(String.raw`(${ne})\s+to\s+the\s+power\s+of\s+(${ne})`,"gi"),"($1)^($2)");const i={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};e=e.replace(new RegExp(String.raw`(${ne})\s+to\s+the\s+(${Object.keys(i).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(t,e,n,r)=>`(${e})^(${i[n.toLowerCase()]??r})`),e=e.replace(new RegExp(String.raw`(${ne})\s+to\s+the\s+(${ne})(?![\w.])`,"gi"),"($1)^($2)");const s={sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"};for(const[t,n]of Object.entries(s).sort((t,e)=>e[0].length-t[0].length))e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${re(t)}\s+of\s+(${ne})`,"gi"),`${n}($1)`);e=e.replace(new RegExp(String.raw`(${ne})\s+squared(?![\w.])`,"gi"),"($1)^2"),e=e.replace(new RegExp(String.raw`(${ne})\s+cubed(?![\w.])`,"gi"),"($1)^3"),e=e.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${ne})`,"gi"),"($1)/2"),e=e.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${ne})`,"gi"),"2*($1)"),e=e.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const o=t=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${re(t)}(?=\s+[\w.(\[{-])`,"gi");for(const[t,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])e=e.replace(o(t),` ${n} `);return e}],["words",le],["spaced",function(t){t=function(t){for(let e=0;e<100;e++){const e=[...t.matchAll(/\bif\b/gi)];if(!e.length)return t;const n=e[e.length-1].index,r=lt(t,n+2,"then");if(r<0)return t;const i=t.slice(n+2,r),s=lt(t,r+4,"else"),o=ct(t,s<0?r+4:s+4),a=t.slice(r+4,s<0?o:s),l=s<0?"unchanged":t.slice(s+4,o).trim();t=`${t.slice(0,n)}((${i.trim()}) ? (${a.trim()}) : (${l}))${t.slice(o)}`}return t}(t),t=function(t){for(let e=0;e<t.length;e++){const n=n=>t.slice(Math.max(0,e-n),e+1);if("t"===t[e]&&"\\text"===n(4)&&"{"===t[e+1]){let n=1,r=e+2,i="";for(;n>0&&r<t.length;)"{"===t[r]?n++:"}"===t[r]?n--:i+=t[r],r++;t=t.slice(0,e-4)+i+t.slice(r)}}return t}(t=(t=t.replace(/\(\s*\\?b?mod\s+([^()]+?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")),t=ht(t);for(let e=0;e<t.length-1;e++)if("?"===t[e]&&":"!==t[e+1])t=ut(t,e);else if("_"===t[e]||"^"===t[e]){const n=/^§\d+§/.exec(t.slice(e+1));if(n){t=`${t.slice(0,e+1)}{${n[0]}}${t.slice(e+1+n[0].length)}`;continue}let r=e+1;for("-"===t[r]&&r++;r<t.length&&".0123456789".includes(t[r]);)r++;r===e+2&&"-"===t[e+1]&&(r=e+1),r>e+1&&(t=t.slice(0,e+1)+"{"+t.slice(e+1,r)+"}"+t.slice(r))}return t}],["squeeze",function(t){return t.replace(/\s+/g,(e,n)=>{const r=t[n-1]??"",i=t[n+e.length]??"";return"Δ"===r?"":/[A-Za-z\u0370-\u03FF′]/.test(r)&&/[A-Za-z\u0370-\u03FF]/.test(i)?" ":""})}],["symbols",ce],["compact",function(t){t=function(t){for(let e=t.indexOf(")′");e>=0;e=t.indexOf(")′",e+1)){let n=0,r=-1;for(let i=e;i>=0;i--)if(")"===t[i])n++;else if("("===t[i]&&0===--n){r=i;break}if(r<0)continue;for(;r>0&&/[A-Za-z\u0370-\u03FF′]/.test(t[r-1]);)r--;let i=0;for(;"′"===t[e+1+i];)i++;t=t.slice(0,r)+At(t.slice(r,e+1),"x",i)+t.slice(e+1+i),e=r}return t}(t=(t=ht(t)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}")),t=function(t){for(let e=0;e<t.length;e++){const n=e>0&&vt.test(t[e-1]);let r,i=null,s=e;if(t.startsWith("frac{",e)){const n=xt(t,e+4),r=n&&xt(t,n[1]);i=r&&Mt(n[0],r[0]),i&&(s=r[1])}else if("d"===t[e]&&!n){let[n,r]=wt(t,e+1),o="";if(vt.test(t[r]??"")&&"/"===t[r+1]&&(o=t[r++]),"/"===t[r]&&"d"===t[r+1]&&vt.test(t[r+2]??"")){const e=t[r+2],[,a]=wt(t,r+3);i={n:n,of:o,by:e},s=a}}if(i){if(i.of)r=At(i.of,i.by,i.n);else{const[e,n]=kt(t,s);if(!e)continue;r=At(e,i.by,i.n),s=n}t=t.slice(0,e)+r+t.slice(s),e+=3}}return t}(t);for(let e=0;e<t.length;e++){const n=t[e],r=n=>t.slice(Math.max(0,e-n),e),i=n=>t.slice(Math.max(0,e-n),e+1);if("{"===n){if("\\begin"===r(6)){const n=dt(t.slice(e+1));n&&(t=t.slice(0,e-6)+n)}}else if("["===n)"\\sqrt"===r(5)?t=t.slice(0,e-5)+"sqrt"+mt(t.slice(e+1)):"sqrt"===r(4)&&(t=t.slice(0,e-4)+"sqrt"+mt(t.slice(e+1)));else if("⌊"===n||"⌈"===n)t=t.slice(0,e)+pt(t.slice(e));else if("t"===n)"\\int"===i(3)&&(t=t.slice(0,e-3)+bt(t.slice(e+1)));else if("m"===n)"\\binom"===i(5)&&(t=t.slice(0,e-5)+"\\binom"+yt(t.slice(e+1)));else if("d"===n&&"dd"===i(1)&&"("===t[e+2]){const n=$t(t.slice(e+1));n&&(t=t.slice(0,e-1)+"der"+n)}}return t.replace(/\\log/g,"log")}],["tidy",t=>t.replace(/ {2,}/g," ").trim()]];function he(t,e={}){if("string"!=typeof t)throw new Error("Expression must be a string");const{text:n,strings:r}=function(t){const e=new Map;let n="",r=0;for(;r<t.length;){const i=t[r];if('"'!==i&&"'"!==i&&"`"!==i){n+=t[r++];continue}let s=r+1,o="",a=!1;for(;s<t.length&&(a||t[s]!==i);)a=!a&&"\\"===t[s],o+=t[s++];const l=Ot(e.size);e.set(l,i+o+i),n+=l,r=s+1}return{text:n,strings:e}}(function(t){let e="";for(let n=0;n<t.length;n++){const r=t[n];if('"'===r||"`"===r){const r=_t(t,n);e+=t.slice(n,r+1),n=r}else if("'"===r)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(e[e.length-1]??""))e+="′";else{const r=_t(t,n);e+=t.slice(n,r+1),n=r}else e+=r}return e}(t));let i=n.replace(/\t/g," ");e.evaluate&&(i=function(t,e,n){let r=0;for(;;){const i=t.indexOf("{{",r);if(i<0)return t;const s=pe(t,i);if(s<0)return t;let o=t.slice(i+2,s).trim();for(const[t,n]of e)o=o.split(t).join(n);try{let a=n(o);if(/^["'`]/.test(a)){const t=Ot(e.size);e.set(t,a),a=t}const l=t.slice(0,i).trimEnd(),c=t.slice(s+2).trimStart();/^[\d.]/.test(a)&&(/[\d.]$/.test(l)||/^[\d.]/.test(c))&&(a=`(${a})`),t=t.slice(0,i)+" "+a+" "+t.slice(s+2),r=0}catch{r=s+2}}}(i,r,e.evaluate));const s=[["strings",i]];for(const[t,e]of ue){if(i=e(i),i.length>1e5)throw new Error("The expression expands too much when read");s.push([t,i])}return{cleaned:i,stringMap:r,steps:s}}function pe(t,e){let n=0;for(let r=e+2;r<t.length;r++){if(t.startsWith("}}",r)&&0===n)return r;"{"===t[r]?n++:"}"===t[r]&&n--}return-1}const me=Object.keys(p).filter(t=>100===p[t]&&/^[a-z]{2,}$/.test(t)),fe=["frac"],de=[...Object.keys(_),"pi","tau","inf","infinity","exp"],ge="\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+/),be=new Set([...de,...ge,"true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),$e=/^[a-zA-ZͰ-Ͽ]$/,ye=new Set(["f","g","h","u","v","F","G","H"]),ve=t=>me.includes(t)||fe.includes(t),xe=[...me,...fe,...de].sort((t,e)=>e.length-t.length),we=[...me,...fe,"pi"].sort((t,e)=>e.length-t.length);function Me(t,e=xe){const n=[];let r=0;for(;r<t.length;){const i=e.find(e=>t.startsWith(e,r))??t[r];n.push(i),r+=i.length}return n}function ke(t){if(ve(t))return!0;const e=Me(t,we);return e.length>1&&ve(e[e.length-1])&&!be.has(t)}function Ae(t,{mode:e="plain",followed:n=!0}={}){if(t.includes("′")&&/^[a-zA-Z′]+$/.test(t)&&!/^.′+$/.test(t))return t.match(/[a-zA-Z]′*/g);if(!((r=t).length>0&&[...r].every(t=>$e.test(t)))||1===t.length||be.has(t)||ve(t))return[t];var r;if("Δ"===t[0]&&2===t.length)return[t];if("latex"===e)return Ee(Me(t),n);if(t.length<=2)return[...t];const i=Ee(Me(t,we),n),s=i.findIndex(t=>t.length>1);if(s<0)return[t];if("pi"===i[s]&&!i.some(t=>me.includes(t)))return 3===t.length?i:[t];const o=s;let a=0,l=0;for(const t of i.slice(s))a=1===t.length?a+1:0,l=Math.max(l,a);return o<=1&&l<=2?i:[t]}function Ee(t,e){const n=t[t.length-1];return e||!me.includes(n)?t:[...t.slice(0,-1),...n]}const Ne="§",Oe=/[A-Za-zͰ-Ͽ′]/,_e=t=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(t);function Se(t,e="plain"){if("string"!=typeof t)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=t=>{r&&(_e(r)?n.push(...function(t,e,n){if((t=>new RegExp(`^${Et}[${Nt}]+$`).test(t))(t))return[t];if(d.includes(e))return function(t,e){if(/^[a-zA-Z]′+$/.test(t))return[s+t];if("if"===t.toLowerCase())return["\\:if"];if(1===t.length)return ye.has(t)?[s+t]:[t];if(m(t))return[t];const n=Ae(t,{mode:e,followed:!0});return n.length>1?n:t.length<=2?[...t]:[s+t]}(t,n);const r=void 0!==e&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(e);return Ae(t,{mode:n,followed:r})}(r,t,e)):n.push(r),r="")};for(let e=0;e<t.length;e++){const o=t[e];if(o===Ne){i(o);const r=t.indexOf(Ne,e+1),a=t.slice(e,r+1);n.push(d.includes(t[r+1])?s+a:a),e=r;continue}if(_e(r)&&/[0-9]/.test(o)&&m(r+o)){const{op:i,end:s}=Ie(t,e,r+o);n.push(i),r="",e=s;continue}if(Oe.test(o)&&"′"!==o&&b(r)&&(n.push(r),r=""),Oe.test(o)&&(""===r?"′"!==o:_e(r)))r+=o;else if(/[0-9]/.test(o)&&_e(r)&&!ke(r))r+=o;else if(_e(r)&&i(" "===o?t[e+1]:o),"(){}[]".includes(o))r&&n.push(...qe(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(m(r+o)){const{op:i,end:s}=Ie(t,e,r+o);n.push(i),r="",e=s;continue}if(m(o)){i(o);const{op:r,end:s}=Ie(t,e,o);n.push(r),e=s;continue}r+=o}else i(t[e+1]),"_"===o&&n.push("_")}if(i(void 0),n.some(t=>/^:/.test(t)))throw new Error("Unmatched ':'");return n}function Ie(t,e,n){let r=e;for(;r+1<t.length&&m(n+t[r+1]);)n+=t[r+1],r++;return"!"===n&&"_"===t[r+1]&&r++,{op:n,end:r}}function qe(t,e){if(!d.includes(e))return[t];if("\\"===t[0]){const e=t.slice(1);return[m(e)?e:s+e]}return b(t)?[t,"*"]:m(t)||ve(t)||b(t[0])?[t]:[s+t]}const Le=70,Ce=100,Te="%mod",ze=t=>d.includes(t),je=t=>g.includes(t),Re=t=>o(t)||p[t]===Ce&&"_"!==t,Fe=new Set(["\\comb","\\perm","comb","perm"]),Pe={frac:"/","\\binom":"\\binom"},Ze={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Be{constructor(t){this.tokens=t,this.pos=0,this.out=[],this.absDepth=0,this.frames=[]}peek(t=0){return this.tokens[this.pos+t]}next(){return this.tokens[this.pos++]}emit(...t){this.out.push(...t)}parseAll(){if(!this.tokens.length)throw new Error("Empty expression");this.parseExpression(0);const t=this.peek();if(void 0!==t)throw new Error(je(t)?`Unmatched '${t}'`:`Unexpected '${t}'`);return this.out}parseExpression(t,e=!1){for(this.parseOperand();;){const n=this.peek();if(void 0===n||je(n))return;const r=this.operatorAt(n,e);if(!r||r.lbp<=t)return;r.run()}}operatorAt(t,e){if("|"===t)return this.pipe();if(","===t)return{lbp:5,run:()=>{this.next(),this.frames.length&&(this.frames[this.frames.length-1].comma=!0),this.parseExpression(5),this.emit(",")}};if("?"===t)return{lbp:9,run:()=>this.ternary()};if("mod"===t)return{lbp:p.mod,run:()=>this.modulo()};if(t===Te)return{lbp:Le,run:()=>{this.next(),this.parseExpression(Le),this.emit("mod")}};if("pmod"===t)return{lbp:p.pmod,run:()=>{this.next(),this.parseScript(),this.emit("pmod")}};if("?:"===t)return{lbp:10,run:()=>{throw new Error("Unmatched ':'")}};if("!"===t)return{lbp:90,run:()=>{this.next(),this.emit("!")}};if("_"===t)return{lbp:Ce,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(Fe.has(t))return{lbp:Ce,run:()=>{this.next(),this.parseExpression(Ce),this.emit(t)}};const n=p[t];if(void 0!==n&&!Re(t)&&"\\not"!==t&&!(t in Pe)){const e=f.has(t)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(e),this.emit(t)}}}return this.startsOperand(t)?this.implicit(t,e):null}implicit(t,e){return{lbp:e&&!Re(t)?71:Le,run:()=>{this.parseExpression(Le),this.emit("*")}}}startsOperand(t){return void 0===t||je(t)||"|"===t?"|"===t:t!==Te&&(!!(ze(t)||Re(t)||t in Pe)||!m(t))}pipe(){if(this.absDepth>0)return null;let t=0;for(let e=this.pos;e<this.tokens.length;e++)"|"===this.tokens[e]&&t++;const e="|"===this.peek(1);return t%2==0&&!e&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:p["|"],run:()=>{this.next(),e&&t%2==0&&this.next(),this.parseExpression(p["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(Le,!0),this.emit("mod")}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const t=this.next(),e=this.tokens[this.pos-2],n=this.peek();if(void 0===t)throw new Error("An operator is missing an operand at the end");if(ze(t))return this.bracket(t,"{"===t&&("∈"===e||"∉"===e));if("|"===t)return this.absolute();if("-"===t||"+"===t){return"^"===e&&(void 0===n||je(n))||ze(e)&&je(n)?this.emit("\\"+t):"+"===t?this.parseExpression(75):this.negate()}if("±"===t)return this.parseExpression(75),this.emit("pm");if("!"===t||"\\not"===t)return this.parseExpression(85),this.emit("\\not");if(t in Pe)return this.parseScript(),this.parseScript(),this.emit(Pe[t]);if("log"===t)return this.logarithm();if("lim"===t&&"_"===n)return this.limit();if(("\\sumidx"===t||"\\prodidx"===t)&&"_"===n)return this.bigOperator(t);if(Re(t))return this.functionCall(t);if(je(t)||m(t))throw new Error(`'${t}' is missing an operand`);this.emit(t)}negate(){const t=this.out.length;this.parseExpression(75);const e=this.out.slice(t);1!==e.length||!b(e[0])&&"∞"!==e[0]?this.emit("neg"):this.out[t]="-"+e[0]}bracket(t,e=!1){if(je(this.peek()))return void this.emit("∅",t+this.next());this.frames.push({comma:!1}),this.parseExpression(0);const{comma:n}=this.frames.pop(),r=this.peek();je(r)&&(this.next(),n?this.emit(t+r):e&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const t=this.peek();if(ze(t))return this.parseOperand();if("-"===t||"+"===t)return this.parseOperand();if(Re(t))return this.parseOperand();if(this.next(),void 0===t||je(t)||m(t))throw new Error("Missing a sub- or superscript");this.emit(t)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const t=this.out.length;this.parseScript();const e=this.out.splice(t);this.parseExpression(p["+"],!0),this.emit(...e,",","()","lim")}bigOperator(t){this.next();const e=this.out.length;this.parseScript();let n=this.out.splice(e);"^"===this.peek()&&(this.next(),this.parseScript(),n=[...n,...this.out.splice(e),","]),this.parseExpression(p["+"],!0),this.emit(...n,",","()",t)}functionCall(t){if(void 0===this.peek())return this.emit(t);let e=null;if("^"===this.peek()){this.next();const t=this.out.length;this.parseScript(),e=this.out.splice(t)}if(0===a(t)?.arity&&!ze(this.peek()))return this.emit(t);this.argument(),this.emit(t),e&&this.emit(...e,"^")}argument(){const t=this.peek();if(ze(t))return this.next(),this.bracket(t);this.parseExpression(Le,!0)}}function We(t,e){t=function(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n],i=t=>"string"==typeof t&&/^[a-zA-Z]$/.test(t);if(ye.has(r)&&"^ { - 1 } ("===t.slice(n+1,n+7).join(" ")){e.push(s+r+"⁻¹"),n+=5;continue}const[o,a,l]=t.slice(n+1,n+4),c=i(a)?a!==r:b(a);i(r)&&"e"!==r&&"("===o&&c&&")"===l?e.push(s+r):e.push(r)}return e}(t);const n=[];for(const r of t)m(r)||ze(r)||je(r)||"_"===r||o(r)||b(r)?n.push(r):n.push(...De(r,e));return n}function De(t,e){const n=t=>We(Se(t,e),e);let r=0;for(;r<t.length&&b(t.slice(0,r+1));)r++;if(0===r){if("%"===t[0])return[Te,...n(t.slice(1))];const r=t.indexOf("%");return r>0&&r<t.length-1?[...De(t.slice(0,r),e),Te,...n(t.slice(r+1))]:[t]}const i=t.slice(r);return"%"===i[0]?1===i.length?[t]:[t.slice(0,r),Te,...n(i.slice(1))]:[t.slice(0,r),...n(i)]}for(const t of[Pe,Ze])Object.setPrototypeOf(t,null);const Ue=new Set(["()","[]","{}","(]","[)"]),He={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠="},Ge=new Set(["round","fixed","der"]),Ve=t=>o(t)||100===p[t];function Xe(t){const n=[],r=t=>{if(!n.length)throw new Error(`'${t}' is missing an operand`);return n.pop()},i=t=>t.list?t.list:[t],s=(t,e)=>{if(t.list)throw new Error(`A list of values needs brackets around it (near '${e}')`);return t};if(t.forEach((l,c)=>{if("∅"===l)return void n.push({list:[]});if(","===l){const t=r(l),e=r(l);return void n.push({list:[...i(e),...i(t)]})}if(Ue.has(l)){const e=i(r(l));if(!e.length&&!Ve(t[c+1]))throw new Error("Empty brackets");return void n.push(v(l,e))}const u=He[l]??l,h=a(u);if(!h){if("?"===l||"abs("===l)throw new Error(`Unmatched '${l[0]}'`);return void n.push(w(l))}let p;if(Ve(l)&&Ue.has(t[c-1])&&n[n.length-1]?.op===t[c-1])p=n.pop().args;else{let t=h.arity===e||Ge.has(u)?1:h.arity;if(n.length<t)throw new Error(`'${l}' needs ${t} operand${1===t?"":"s"}`);p=n.splice(n.length-t,t).map(t=>s(t,l))}n.push(function(t,n){switch(t){case"sqrt":if(2===n.length)return v("root",n);break;case"round":if(1===n.length)return v("round",[n[0],$(0)]);break;case"sum":case"prod":{const e=n[1];if("op"===e?.type&&"symbol"===e.args[0]?.type&&(3===n.length&&"="===e.op||2===n.length&&"∈"===e.op))return v("sum"===t?"\\sumidx":"\\prodidx",n);break}case"det":if(n.length>1&&n.every(t=>"op"===t.type&&"[]"===t.op))return v("det",[v("[]",n)]);break;case"fixed":if(1===n.length)return v("fixed",[n[0],$(2)]);break;case"der":if(1===n.length)return v("der",[n[0],y("x")]);if(3===n.length)return function([t,e,n]){const r="number"===n.type?Number(n.value):NaN;if(!Number.isInteger(r)||r<1||r>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");let i=t;for(let t=0;t<r;t++)i=v("der",[i,e]);return i}(n);break;case"log":if("symbol"===n[0].type&&"e"===n[0].value)return v("ln",[n[1]]);break;case"lim":return v("lim",function(t){const e=t=>"op"===t.type&&"^"===t.op&&"symbol"===t.args[1].type?{"\\+":"r","\\-":"l"}[t.args[1].value]:void 0,[n,r,i]=t;if(2===t.length&&"op"===r.type&&"→"===r.op&&e(r.args[1])){const[t,i]=r.args;return[n,t,i.args[0],y(e(i))]}return 3===t.length&&e(i)?[n,r,i.args[0],y(e(i))]:t}(n));case"\\:if":if(2===n.length||3===n.length)return v("?:",[n[0],n[1],n[2]??y("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return function(t,n){const{arity:r}=a(t);if(r===e){if(0===n.length&&!o(t))throw new Error(`'${t}' needs at least one argument`);return}if(n.length!==r){throw new Error(`'${t}' takes ${r} argument${1===r?"":"s"}, not ${n.length}`)}}(t,n),v(t,n)}(u,p))}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return s(n[0],"end")}for(const t of[He])Object.setPrototypeOf(t,null);const Qe=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Je=t=>/^[a-z][a-z0-9]*$/.test(t)&&m(t);function Ye(t){return t.includes("\\")?(t=function(t){for(let e=0;e<50;e++){const e=t.lastIndexOf("\\begin{cases}"),n=e<0?-1:t.indexOf("\\end{cases}",e);if(n<0)return t;const r=at(t.slice(e+13,n),"\\\\").map(t=>at(t,"&")).filter(t=>t.join("").trim());let i=null;for(let t=r.length-1;t>=0;t--){const e=r[t][0].trim(),n=ot(r[t].slice(1).join("&"));i=null!==i||n?`((${n||"true"}) ? (${e}) : ${i??"(unchanged)"})`:`(${e})`}t=t.slice(0,e)+(i??"")+t.slice(n+11)}return t}(t),t.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):t}let Ke=null;function tn(t,e={}){const n={original:t};try{if("string"!=typeof t)throw new Error("Expression must be a string");const r=e.maxLength??5e3;if(t.length>r)throw new Error(`Longer than ${r} characters (options.maxLength)`);const i=/^\s*=(?!=)/.test(t);i&&(t=t.replace(/("(?:[^"]|"")*")|\$(?=[A-Za-z]{0,3}\d|[A-Za-z]{1,3}\$?\d)/g,(t,e)=>e??""));const s=i?[...new Set(t.replace(/"(?:[^"]|"")*"/g,"").match(/(?<![\w.])[A-Za-z]{1,3}\d+(?::[A-Za-z]{1,3}\d+)?(?![\w.(])/g)??[])]:[],{text:o,protectedNames:a}=function(t,e=[],n=[]){const r=new Map,i=t=>{const e=`${Ne}${r.size}${Ne}`;return r.set(e,t),e};t=t.replace(Qe,(t,e)=>Je(e.trim())?` ${e.trim()}`:i(e.trim()));for(const n of[...e].sort((t,e)=>e.length-t.length)){const e=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t=t.replace(new RegExp(`(?<![A-Za-z_])${e}(?![A-Za-z0-9_])`,"g"),()=>i(n))}for(const e of[...n].sort((t,e)=>e.length-t.length)){const n=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t=t.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(t,n,r)=>i(e)+(r?" * (":n))}return{text:t,protectedNames:r}}(Ye(t),e.names,[...e.values??[],...s]),l=(t=>/\\[A-Za-z]/.test(t)?"latex":"plain")(o),{cleaned:c,stringMap:u,steps:h}=((t,e={})=>{const n=void 0===e.blocks?Ke:e.blocks;return he(t,{evaluate:n?t=>n(t,e.scope):void 0})})(o,{blocks:e.blocks,scope:e.scope}),p=t=>St(St(t,u),a);n.mode=l,n.cleaned=p([c])[0],n.cleanSteps=h,n.tokens=Se(c,l),n.rawPostfix=p(function(t,e="plain"){return new Be(We(t,e)).parseAll().map(t=>Ze[t]??t)}(n.tokens,l));const m=A(Xe(n.rawPostfix));n.postfix=m,n.tree=k(m)}catch(t){n.error=t instanceof RangeError?"Nested too deeply":t.message}return n}function en(t,e={}){const n=tn(t,e);if(n.error)throw new Error(`Failed to parse expression "${r=t,"string"==typeof r&&r.length>80?`${r.slice(0,77)}…`:r}": ${n.error}`);var r;return n.tree}const nn=(t,e)=>"string"==typeof t?en(t,e):E(t),rn=t=>Array.isArray(t)&&0===t.length,sn=K({add:(t,e)=>t+e,sub:(t,e)=>t-e,mul:(t,e)=>t*e,div:(t,e)=>t/e,isZero:t=>Math.abs(t)<1e-12,zero:()=>0,one:()=>1,size:Math.abs,fail:t=>{throw new Error(t)}}),on=t=>J(t)&&(t.length>1||t[0].length>1),an=t=>Y(t)&&!on(t),ln=t=>{const e=(n,r)=>{if(Array.isArray(n)&&Array.isArray(r)){if(n.length!==r.length)throw new Error("Lists of different lengths");return n.map((t,n)=>e(t,r[n]))}return Array.isArray(n)?n.map(t=>e(t,r)):Array.isArray(r)?r.map(t=>e(n,t)):t(n,r)};return e},cn=(t,e)=>on(t)&&on(e)?sn.times(t,e):on(t)&&an(e)?sn.timesVector(t,e):an(t)&&on(e)?sn.vectorTimes(t,e):ln((t,e)=>t*e)(t,e),un=t=>e=>t(e.length>1&&e.every(an)?e:e[0]),hn={det:un(sn.det),inv:un(sn.inverse),inverse:un(sn.inverse),transpose:un(sn.transpose),trace:un(sn.trace),tr:un(sn.trace),rank:un(sn.rank),rref:un(sn.rref),identity:([t])=>sn.identity(t),dot:([t,e])=>sn.dot(t,e),cross:([t,e])=>sn.cross(t,e),linsolve:([t,e])=>sn.solve(t,e)},pn=(t,e)=>t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args.map(t=>xn(t,e)):[xn(t,e)]),mn={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},fn=(t,e)=>e?fn(e,t%e):Math.abs(t),dn={neg:t=>-t,pm:t=>[t,-t],"!":t=>{if(!Number.isInteger(t)||t<0)return NaN;if(t>170)return 1/0;let e=1;for(let n=2;n<=t;n++)e*=n;return e},"\\not":t=>!t,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,det:t=>sn.det(t),ln:Math.log,loglog:t=>Math.log(Math.log(t)),logloglog:t=>Math.log(Math.log(Math.log(t))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:t=>1/Math.sin(t),sec:t=>1/Math.cos(t),cot:t=>1/Math.tan(t),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},gn={"+":(t,e)=>Array.isArray(t)||Array.isArray(e)?ln((t,e)=>t+e)(t,e):t+e,"-":(t,e)=>Array.isArray(t)||Array.isArray(e)?ln((t,e)=>t-e)(t,e):t-e,"*":cn,"/":(t,e)=>on(e)?cn(t,sn.inverse(e)):Array.isArray(t)||Array.isArray(e)?ln((t,e)=>t/e)(t,e):t/e,"^":(t,e)=>{if(!on(t))return Array.isArray(t)?ln((t,e)=>t**e)(t,e):t**e;if(!Number.isInteger(e))throw new Error("A matrix to a power that is not a whole number");return sn.power(t,BigInt(e))},mod:(t,e)=>t%e,log:(t,e)=>Math.log(e)/Math.log(t),root:(t,e)=>e**(1/t),atan2:Math.atan2,round:(t,e)=>Math.round(t*10**e)/10**e,"±":(t,e)=>[t+e,t-e],fixed:(t,e)=>Number(t).toFixed(e),perm:(t,e)=>{if(!Number.isInteger(t)||!Number.isInteger(e)||e<0||e>t)return NaN;let n=1;for(let r=t-e+1;r<=t&&n!==1/0;r++)n*=r;return n},comb:(t,e)=>{if(!Number.isInteger(t)||!Number.isInteger(e)||e<0||e>t)return NaN;e=Math.min(e,t-e);let n=1;for(let r=1;r<=e&&n!==1/0;r++)n=n*(t-e+r)/r;return Math.round(n)},"=":(t,e)=>t==e,"===":(t,e)=>t===e,"≠":(t,e)=>t!=e,"≠=":(t,e)=>t!==e,"≈":(t,e)=>Math.abs(t-e)<1e-9,"≡":(t,e)=>t===e,"∪":(t,e)=>[...new Set([...[].concat(t),...[].concat(e)])],"∩":(t,e)=>[].concat(t).filter(t=>[].concat(e).includes(t)),"<":(t,e)=>t<e,">":(t,e)=>t>e,"≤":(t,e)=>t<=e,"≥":(t,e)=>t>=e,"&":(t,e)=>t&&e,"|":(t,e)=>t||e,"\\xor":(t,e)=>Boolean(t)!==Boolean(e),"\\nor":(t,e)=>!(t||e),"\\nand":(t,e)=>!(t&&e)},bn={max:t=>Math.max(...t),min:t=>Math.min(...t),sum:t=>t.reduce((t,e)=>t+e,0),prod:t=>t.reduce((t,e)=>t*e,1),mean:t=>t.reduce((t,e)=>t+e,0)/t.length,gcd:t=>t.reduce(fn),"()":t=>t,"[]":t=>t,"{}":t=>t};const $n=5e6;let yn=0,vn=0;function xn(t,e){if(++yn>$n)throw new Error("Too much to work out");switch(t.type){case"number":return Number(t.value);case"string":return t.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(e,t.value))return e[t.value];if(Object.prototype.hasOwnProperty.call(mn,t.value))return mn[t.value];throw new Error(`No value for '${t.value}'`)}const n=V(t);if(n)return xn(n,e);const{op:r,args:i}=t;if("?:"===r)return xn(i[0],e)?xn(i[1],e):xn(i[2],e);if("∈"===r||"∉"===r)return function(t,e){const[n,r]=t.args,i=xn(n,e);let s;if("symbol"===r.type&&wn[r.value])return s=wn[r.value](i),"∈"===t.op?s:!s;if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,n]=r.args.map(t=>xn(t,e)),o="["===r.op[0]?i>=t:i>t,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const t=xn(r,e);s=Array.isArray(t)&&t.includes(i)}return"∈"===t.op?s:!s}(t,e);if("random"===r)return Math.random();if(("\\sumidx"===r||"\\prodidx"===r)&&3===i.length&&"op"===i[1].type&&"="===i[1].op&&"symbol"===i[1].args[0].type){const[t,n,s]=[i[0],i[1].args[1],i[2]],o=i[1].args[0].value,a=xn(n,e),l=xn(s,e);if(!Number.isFinite(a)||!Number.isFinite(l)||l-a>1e6)throw new Error(`Can't evaluate '${r}' over that range`);let c="\\sumidx"===r?0:1;for(let n=a;n<=l;n++){const i=xn(t,{...e,[o]:n});c="\\sumidx"===r?c+i:c*i}return c}if("pmod"===r){const[t,n]=i,r=xn(n,e);if("op"===t.type&&["≡","="].includes(t.op)){const[n,i]=t.args.map(t=>xn(t,e));return(n-i)%r===0}return xn(t,e)%r}if("pmatrix"===r||"bmatrix"===r)return pn(t,e);if("vmatrix"===r)return sn.det(pn(t,e));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(e,"T")){const t=xn(i[0],e);if(on(t))return sn.transpose(t)}const s=i.map(t=>xn(t,e));if(r.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(hn,r.slice(2)))return hn[r.slice(2)](s);if(dn[r]&&1===s.length)return dn[r](s[0]);if(gn[r]&&2===s.length)return gn[r](s[0],s[1]);if(bn[r])return bn[r](s);throw new Error(`Can't evaluate '${r}'`)}const wn={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":t=>Number.isInteger(t)&&t>0,"ℚ":Number.isFinite,"ℂ":t=>"number"==typeof t&&!Number.isNaN(t)};for(const t of[mn,dn,gn,bn,wn,hn])Object.setPrototypeOf(t,null);class Mn extends Error{}class kn extends Error{}const An={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6};let En=0,Nn=0;const On=t=>t<0n?-t:t,_n=t=>0n===t?0:On(t).toString(2).length;function Sn(t,e){for(t=On(t),e=On(e);e;)[t,e]=[e,t%e];return t}function In(t,e=1n){if(0n===e)throw new Mn("division by zero");e<0n&&(t=-t,e=-e);const n=Sn(t,e)||1n;return{n:t/n,d:e/n}}const qn=In(0n),Ln=In(1n),Cn=(t,e)=>In(t.n*e.d+e.n*t.d,t.d*e.d),Tn=(t,e)=>In(t.n*e.n,t.d*e.d),zn=(t,e)=>In(t.n*e.d,t.d*e.n),jn=t=>({n:-t.n,d:t.d}),Rn=(t,e)=>{const n=t.n*e.d-e.n*t.d;return n<0n?-1:n>0n?1:0},Fn=t=>{const e=t.n/t.d;return t.n<0n&&e*t.d!==t.n?e-1n:e};function Pn(t){const e=_n(t.n),n=_n(t.d);if(e<1e3&&n<1e3)return Number(t.n)/Number(t.d);const r=BigInt(Math.max(e,n)-1e3),i=t.d>>r;return 0n===i?t.n<0n?-1/0:1/0:Number(t.n>>r)/Number(i)}function Zn(t){let e=String(t).trim(),n=1n;e.startsWith("-")&&(n=-1n,e=e.slice(1));const r=e.endsWith("..");r&&(e=e.slice(0,-2));let i=0;const s=e.search(/e/i);s>=0&&(i=Number(e.slice(s+1)),e=e.slice(0,s));const[o="",a=""]=e.split(".");if(!(/^\d*$/.test(o)&&/^\d*$/.test(a)&&o+a))throw new kn(`'${t}' is not a number`);let l;if(r&&a){let t=1;for(let e=1;2*e<=a.length;e++)if(a.slice(-e)===a.slice(-2*e,-e)){t=e;break}const e=a.slice(-t);let n=a;for(;n.endsWith(e);)n=n.slice(0,-t);const r=BigInt(n||"0"),i=BigInt(n+e);l=Cn(In(BigInt(o||"0")),In(i-r,(10n**BigInt(t)-1n)*10n**BigInt(n.length)))}else l=In(BigInt(o+a||"0"),10n**BigInt(a.length));return i&&(l=i>0?Tn(l,In(10n**BigInt(i))):zn(l,In(10n**BigInt(-i)))),n<0n?jn(l):l}function Bn(t,e=0,n=0,r=null){return 0n===t.n?{kind:"x",c:qn,pi:0,e:0,root:null}:{kind:"x",c:t,pi:e,e:n,root:r}}const Wn=(t,e=1n)=>Bn(In(BigInt(t),BigInt(e))),Dn=Bn(Ln,1),Un=Bn(Ln,0,1),Hn=t=>null!==t&&"object"==typeof t&&"x"===t.kind,Gn=t=>Hn(t)&&!t.pi&&!t.e&&!t.root,Vn=t=>Hn(t)?0n===t.c.n:0===t,Xn=t=>Gn(t)&&1n===t.c.d?t.c.n:null,Qn=(t,e)=>Object.assign(t,{group:e}),Jn=t=>({kind:"s",text:t});function Yn(t,e){return t&&e?t.n===e.n&&t.r===e.r:t===e}const Kn=(t,e)=>0===Rn(t.c,e.c)&&t.pi===e.pi&&t.e===e.e&&Yn(t.root,e.root);function tr(t){if("number"==typeof t)return t;if(Hn(t)){let e=Pn(t.c);return t.pi&&(e*=Math.PI**t.pi),t.e&&(e*=Math.E**t.e),t.root&&(e*=Pn(In(t.root.r))**(1/t.root.n)),e}if("boolean"==typeof t)return t?1:0;throw new kn("not a number")}function er(t,...e){if(Number.isNaN(t))throw new Mn("undefined");if(!Number.isFinite(t)&&e.every(Number.isFinite))throw new kn("too large to calculate");return t}const nr=t=>"boolean"==typeof t?t:Hn(t)?0n!==t.c.n:"number"==typeof t?0!==t:Boolean(t);function rr(t){if("bigint"==typeof t)return Bn(In(t));if("number"==typeof t)return Number.isFinite(t)?Bn(Number.isInteger(t)&&Math.abs(t)<=Number.MAX_SAFE_INTEGER?In(BigInt(t)):Zn(String(t))):t;if("boolean"==typeof t)return t;if("string"==typeof t)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(t.trim())?Bn(Zn(t)):Xr(en(t),{});if(Array.isArray(t))return!t.group&&J(t)?Qn(t.map(t=>Qn(t.map(rr),"[]")),"[]"):Qn(t.map(rr),t.group||"()");if(Hn(t)||"function"==typeof t)return t;throw new kn(`can't use ${typeof t} as a value`)}function ir(t){return Array.isArray(t)?t.map(ir):t&&"s"===t.kind?t.text:"boolean"==typeof t?t:tr(t)}function sr(t,e){if(t<2n)return t;const n=BigInt(e);let r=1n<<BigInt(Math.ceil(_n(t)/e));for(;;){const e=((n-1n)*r+t/r**(n-1n))/n;if(e>=r)return r;r=e}}function or(t,e,n,r=0,i=0){if(0n===n)return Bn(qn);const{coef:s,root:o}=function(t,e){let n=1n,r=e;const i=BigInt(t),s=r<10n**24n?1000000n:10000n;for(let t=2n;t<=s&&t*t<=r;t+=2n===t?1n:2n){const e=t**i;for(;r%e===0n;)r/=e,n*=t}const o=sr(r,t);if(o**i===r&&(n*=o,r=1n),1n===r)return{coef:n,root:null};for(let e=t;e>=2;e--){if(t%e!==0)continue;const i=sr(r,e);if(i**BigInt(e)===r)return{coef:n,root:{n:t/e,r:i}}}return{coef:n,root:{n:t,r:r}}}(e,n);return o&&1===o.n?Bn(Tn(t,In(s*o.r)),r,i):Bn(Tn(t,In(s)),r,i,o)}function ar(t,e){const n=Tn(t.c,e.c);if(_n(n.n)+_n(n.d)>An.bits)return null;const r=t.pi+e.pi,i=t.e+e.e;if(!t.root||!e.root)return Bn(n,r,i,t.root||e.root);const s=Lr(t.root.n,e.root.n);if(s>An.rootIndex)return null;const o=t.root.r**BigInt(s/t.root.n)*e.root.r**BigInt(s/e.root.n);return _n(o)>4e3?null:or(n,s,o,r,i)}function lr(t){if(0n===t.c.n)throw new Mn("division by zero");const e=Bn(zn(Ln,t.c),-t.pi,-t.e);if(!t.root)return e;const{n:n,r:r}=t.root;return ar(e,or(In(1n,r),n,r**BigInt(n-1)))}function cr(t,e){if(0n===e){if(0n===t.c.n)throw new Mn("0^0 is undefined");return Bn(Ln)}if(e<0n){const n=lr(t);return n&&cr(n,-e)}if((_n(t.c.n)+_n(t.c.d)+(t.root?_n(t.root.r):0))*Number(e)>An.bits||e>100000n)return null;const n=In(t.c.n**e,t.c.d**e),r=Number(e);if(!t.root)return Bn(n,t.pi*r,t.e*r);const{n:i,r:s}=t.root,o=s**(e/BigInt(i));return or(Tn(n,In(o)),i,s**(e%BigInt(i))||1n,t.pi*r,t.e*r)}function ur(t,e,n){if(!Gn(t)||n>1000n)return null;const r=cr(t,e);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new Mn("not a real number");o=!0,i=-i}const a=function(t,e){const n=t.n*t.d**BigInt(e-1);return _n(n)>4e3?null:or(In(1n,t.d),e,n)}({n:i,d:s},Number(n));return a?o?Bn(jn(a.c),a.pi,a.e,a.root):a:null}function hr(t){return e=>Array.isArray(e)?Qn(e.map(e=>hr(t)(e)),e.group):t(e)}function pr(t){const e=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new Mn("lists of different lengths");return Qn(n.map((t,n)=>e(t,r[n])),n.group)}return i?Qn(n.map(t=>e(t,r)),n.group):s?Qn(r.map(t=>e(n,t)),r.group):t(n,r)};return e}const mr=pr((t,e)=>Hn(t)&&Hn(e)&&function(t,e){if(0n===t.c.n)return e;if(0n===e.c.n)return t;if(t.pi!==e.pi||t.e!==e.e||!Yn(t.root,e.root))return null;const n=Cn(t.c,e.c);return _n(n.n)+_n(n.d)>An.bits?null:Bn(n,t.pi,t.e,t.root)}(t,e)||er(tr(t)+tr(e),tr(t),tr(e))),fr=hr(t=>Hn(t)?Bn(jn(t.c),t.pi,t.e,t.root):-tr(t)),dr=(t,e)=>mr(t,fr(e)),gr=pr((t,e)=>Hn(t)&&Hn(e)&&ar(t,e)||er(tr(t)*tr(e),tr(t),tr(e))),br=pr((t,e)=>{if(Vn(e))throw new Mn("division by zero");if(Hn(t)&&Hn(e)){const n=lr(e),r=n&&ar(t,n);if(r)return r}return er(tr(t)/tr(e),tr(t),tr(e))}),$r=pr((t,e)=>{if(Hn(t)&&Gn(e)){const{n:n,d:r}=e.c,i=1n===r?cr(t,n):ur(t,n,r);if(i)return i}const n=tr(t),r=tr(e);if(0===n&&0===r)throw new Mn("0^0 is undefined");if(0===n&&r<0)throw new Mn("division by zero");if(n<0&&!Number.isInteger(r))throw new Mn("not a real number");return er(n**r,n,r)});function yr(t,e){if(Gn(t)&&Gn(e))return Rn(t.c,e.c);if(Hn(t)&&Hn(e)&&Kn(t,e))return 0;const n=tr(t),r=tr(e);return n===r||Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-r)<=1e-12*Math.max(1,Math.abs(n),Math.abs(r))?0:n<r?-1:1}function vr(t,e){return Array.isArray(t)||Array.isArray(e)?Array.isArray(t)&&Array.isArray(e)&&t.length===e.length&&t.every((t,n)=>vr(t,e[n])):t&&"s"===t.kind?Boolean(e&&"s"===e.kind&&t.text===e.text):"boolean"==typeof t||"boolean"==typeof e?t===e:0===yr(t,e)}const xr={0:()=>Wn(0),2:()=>Wn(1,2),3:()=>or(In(1n,2n),2,2n),4:()=>or(In(1n,2n),2,3n),6:()=>Wn(1)};function wr(t){t=(t%24+24)%24;const[e,n]=t<=6?[t,1]:t<=12?[12-t,1]:t<=18?[t-12,-1]:[24-t,-1],r=xr[e];return r?n<0?fr(r()):r():null}const Mr=t=>wr(t+6),kr=(t,e)=>Math.abs(t)<1e-15&&Math.abs(e)>1e-6?0:t;function Ar(t,e){const n=function(t){if(Vn(t))return 0;if(!Hn(t)||1!==t.pi||t.e||t.root)return null;const e=Tn(t.c,In(12n));return 1n!==e.d?null:Number((e.n%24n+24n)%24n)}(e);if(null!==n){const e=wr(n),r=Mr(n);if(e&&r)switch(t){case"sin":return e;case"cos":return r;case"tan":return br(e,r);case"cot":return br(r,e);case"sec":return br(Wn(1),r);case"csc":return br(Wn(1),e)}}const r=tr(e),i=kr(Math.sin(r),r),s=kr(Math.cos(r),r),o={sin:i,cos:s,tan:i/s,cot:s/i,sec:1/s,csc:1/i}[t];if(!Number.isFinite(o)&&Number.isFinite(r))throw new Mn("undefined");return er(o)}function Er(t,e){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[t],r=e=>"arcsin"===t?wr(e):"arccos"===t?Mr(e):Mr(e)&&!Vn(Mr(e))?br(wr(e),Mr(e)):null;if(Hn(e))for(let t=n[0];t<=n[1];t++){const n=r(t);if(n&&Hn(n)&&Kn(n,e))return Bn(In(BigInt(t),12n),1)}const i=tr(e);if("arctan"!==t&&Math.abs(i)>1)throw new Mn("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[t](i)}function Nr(t){if(Hn(t)){if(0n===t.c.n)throw new Mn("ln 0 is undefined");if(t.c.n<0n)throw new Mn("not a real number");if(1n===t.c.n&&1n===t.c.d&&!t.pi&&!t.root)return Wn(t.e)}const e=tr(t);if(e<=0)throw new Mn(0===e?"ln 0 is undefined":"not a real number");return Math.log(e)}function Or(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*Or(1-t));const e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];let n=e[0];const r=(t-=1)+7+.5;for(let r=1;r<9;r++)n+=e[r]/(t+r);return Math.sqrt(2*Math.PI)*r**(t+.5)*Math.exp(-r)*n}function _r(t,e){const n=Xn(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null===n)throw new Mn(`${e} needs whole numbers`);return n}const Sr=hr(t=>Gn(t)?Bn(In(Fn(t.c))):rr(Math.floor(tr(t)))),Ir=hr(t=>Gn(t)?Bn(In(-Fn(jn(t.c)))):rr(Math.ceil(tr(t))));function qr(t,e){const n=Number(_r(e,"round"));if(Gn(t)){const e=In(10n**BigInt(Math.abs(n))),r=n>=0?Tn(t.c,e):zn(t.c,e),i=Fn(Cn(Tn(In(2n),In(On(r.n),r.d)),Ln))/2n,s=In(r.n<0n?-i:i);return Bn(n>=0?zn(s,e):Tn(s,e))}const r=10**n;return Math.sign(tr(t))*Math.round(Math.abs(tr(t))*r)/r}const Lr=(t,e)=>t/Cr(t,e)*e,Cr=(t,e)=>e?Cr(e,t%e):t,Tr={pi:()=>Dn,"π":()=>Dn,tau:()=>Bn(In(2n),1),"τ":()=>Bn(In(2n),1),e:()=>Un,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},zr={abs:t=>Hn(t)?Bn(In(On(t.c.n),t.c.d),t.pi,t.e,t.root):Math.abs(tr(t)),floor:Sr,ceil:Ir,sqrt:t=>$r(t,Wn(1,2)),ln:hr(Nr),loglog:hr(t=>Nr(Nr(t))),logloglog:hr(t=>Nr(Nr(Nr(t)))),expm1:hr(t=>Vn(t)?Wn(0):Math.expm1(tr(t))),sinh:hr(t=>Vn(t)?Wn(0):Math.sinh(tr(t))),cosh:hr(t=>Vn(t)?Wn(1):Math.cosh(tr(t))),tanh:hr(t=>Vn(t)?Wn(0):Math.tanh(tr(t))),arcsinh:hr(t=>Vn(t)?Wn(0):Math.asinh(tr(t))),arccosh:hr(t=>{const e=tr(t);if(e<1)throw new Mn("not a real number");return 1===e?Wn(0):Math.acosh(e)}),arctanh:hr(t=>{const e=tr(t);if(Math.abs(e)>=1)throw new Mn("undefined");return Vn(t)?Wn(0):Math.atanh(e)}),"!":hr(function(t){const e=Xn(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null!==e){if(e<0n)throw new Mn("factorial of a negative number");if(e>BigInt(An.factorial))throw new kn("too large to calculate");let t=1n;for(let n=2n;n<=e;n++)t*=n;return Bn(In(t))}const n=tr(t);if(n<0&&Number.isInteger(n))throw new Mn("factorial of a negative number");return er(Or(n+1),n)}),neg:fr,pm:t=>Qn([t,fr(t)],"pm"),"\\not":t=>!nr(t),det:t=>Dr.det(t)};for(const t of["sin","cos","tan","csc","sec","cot"])zr[t]=hr(e=>Ar(t,e));for(const t of["arcsin","arccos","arctan"])zr[t]=hr(e=>Er(t,e));const jr=new Set(["pmatrix","bmatrix"]),Rr=t=>J(t)&&(jr.has(t.group)||"[]"===t.group&&t.every(t=>"[]"===t.group)&&(t.length>1||t[0].length>1)),Fr=t=>Y(t)&&!Rr(t)&&"pm"!==t.group,Pr=K({add:mr,sub:dr,mul:gr,div:br,isZero:t=>Hn(t)?0n===t.c.n:Math.abs(tr(t))<1e-12,zero:()=>Wn(0),one:()=>Wn(1),size:t=>Math.abs(tr(t)),fail:t=>{throw new Mn(t)},make:(t,e)=>Qn(t.map(t=>Qn(t,"[]")),e&&e.group?e.group:"bmatrix")}),Zr=(t,e)=>Qn(t,e&&e.group?e.group:"[]"),Br=(t,e)=>(...n)=>{const r=n.length>1&&n.every(Fr)?Qn(n.map(t=>Qn(t,"[]")),"[]"):n[0];if(n.length>1&&r===n[0])throw new kn(`${t} of more than one thing`);if(!Rr(r))throw new kn(`${t} of something that isn't a matrix`);return e(r)};function Wr(t,e){return Rr(t)&&Rr(e)?Pr.times(t,e):Rr(t)&&Fr(e)?Zr(Pr.timesVector(t,e),e):Fr(t)&&Rr(e)?Zr(Pr.vectorTimes(t,e),t):gr(t,e)}const Dr={det:Br("det",Pr.det),inv:Br("inv",Pr.inverse),inverse:Br("inverse",Pr.inverse),transpose:Br("transpose",Pr.transpose),trace:Br("trace",Pr.trace),tr:Br("tr",Pr.trace),rank:Br("rank",t=>Wn(Pr.rank(t))),rref:Br("rref",Pr.rref),identity:t=>{const e=Xn(t);if(null===e||e<1n||e>100n)throw new kn("identity(n) needs a whole number n");return Pr.identity(Number(e))},dot:(t,e)=>{if(!Fr(t)||!Fr(e))throw new kn("dot of something that isn't a vector");return Pr.dot(t,e)},cross:(t,e)=>{if(!Fr(t)||!Fr(e))throw new kn("cross of something that isn't a vector");return Zr(Pr.cross(t,e),t)},linsolve:(t,e)=>{if(!Rr(t)||!Rr(e)&&!Fr(e))throw new kn("linsolve(A, b) needs a matrix and a vector");return Rr(e)?Pr.solve(t,e):Zr(Pr.solve(t,e),e)}};function Ur(t,e){const n=t.args.map(t=>Qn("op"===t.type&&"[]"===t.op?t.args.map(e):[e(t)],"[]"));if(n.some(t=>t.length!==n[0].length))throw new Mn("rows of different lengths");return Qn(n,"vmatrix"===t.op?"bmatrix":t.op)}const Hr={"+":mr,"-":dr,"*":Wr,"/":(t,e)=>Rr(e)?Wr(t,Pr.inverse(e)):br(t,e),"^":function(t,e){if(!Rr(t))return $r(t,e);const n=Xn(e);if(null===n)throw new kn("a matrix to a power that is not a whole number");return Pr.power(t,n)},"±":(t,e)=>Qn([mr(t,e),dr(t,e)],"pm"),mod:pr(function(t,e){if(Vn(e))throw new Mn("division by zero");if(Gn(t)&&Gn(e))return Bn(Cn(t.c,jn(Tn(e.c,In(Fn(zn(t.c,e.c)))))));const n=tr(t),r=tr(e);return er((n%r+r)%r)}),log:pr(function(t,e){if(Hn(t)&&Kn(t,Un))return Nr(e);const n=tr(t),r=tr(e);if(n<=0||1===n)throw new Mn("not a valid base");if(r<=0)throw new Mn(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(Gn(t)&&Gn(e))for(let n=1n;n<=12n;n++){const r=Math.round(i*Number(n));if(Math.abs(i*Number(n)-r)>1e-9)continue;const s=cr(t,BigInt(r)),o=cr(e,n);if(s&&o&&Kn(s,o))return Bn(In(BigInt(r),n))}return i}),root:pr((t,e)=>$r(e,br(Wn(1),t))),atan2:(t,e)=>Math.atan2(tr(t),tr(e)),round:qr,fixed:function(t,e){const n=Number(_r(e,"fixed"));if(n<0)throw new Mn("fixed needs 0 or more decimal places");const r=qr(t,e);if(Gn(r)){const t=r.c.n*10n**BigInt(n)/r.c.d,e=(t<0n?-t:t).toString().padStart(n+1,"0");return Jn(`${t<0n?"-":""}${e.slice(0,e.length-n)}${n?"."+e.slice(-n):""}`)}return Jn(Number(tr(r)).toFixed(n))},perm:function(t,e){const n=_r(t,"permutations"),r=_r(e,"permutations");if(r<0n||r>n)throw new Mn("undefined");if(r>BigInt(An.terms))throw new kn("too large to calculate");let i=1n;for(let t=n-r+1n;t<=n;t++)i*=t;return Bn(In(i))},comb:function(t,e){const n=_r(t,"combinations");let r=_r(e,"combinations");if(r<0n||r>n)throw new Mn("undefined");if(n-r<r&&(r=n-r),r>BigInt(An.terms))throw new kn("too large to calculate");let i=1n;for(let t=1n;t<=r;t++)i=i*(n-r+t)/t;return Bn(In(i))},"=":(t,e)=>vr(t,e),"===":(t,e)=>vr(t,e),"≠":(t,e)=>!vr(t,e),"≠=":(t,e)=>!vr(t,e),"≈":(t,e)=>Math.abs(tr(t)-tr(e))<=1e-9*Math.max(1,Math.abs(tr(t)),Math.abs(tr(e))),"<":(t,e)=>yr(t,e)<0,">":(t,e)=>yr(t,e)>0,"≤":(t,e)=>yr(t,e)<=0,"≥":(t,e)=>yr(t,e)>=0,"&":(t,e)=>nr(t)&&nr(e),"|":(t,e)=>nr(t)||nr(e),"\\xor":(t,e)=>nr(t)!==nr(e),"\\nor":(t,e)=>!(nr(t)||nr(e)),"\\nand":(t,e)=>!(nr(t)&&nr(e))},Gr={sum:t=>t.reduce((t,e)=>mr(t,e),Wn(0)),prod:t=>t.reduce((t,e)=>gr(t,e),Wn(1)),max:t=>t.reduce((t,e)=>yr(e,t)>0?e:t),min:t=>t.reduce((t,e)=>yr(e,t)<0?e:t),mean:t=>br(Gr.sum(t),Wn(t.length)),gcd:t=>Bn(In(t.map(t=>_r(t,"gcd")).reduce(Sn)))},Vr=["∈","∉","∪","∩","pmod","random","(]","[)"];function Xr(t,e){if(++En>An.steps)throw new kn("too much to work out");switch(t.type){case"number":return Bn(Zn(t.value));case"string":return Jn(t.value.slice(1,-1));case"symbol":return Qr(t.value,e)}const n=V(t);if(n)return Xr(n,e);const{op:r,args:i}=t,s=t=>Xr(t,e);if("?:"===r)return nr(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(t=>"op"!==t.type))return Qr(`${i[0].value}_${i[1].value}`,e);throw new kn("subscript")}if("der"===r)return function(t,e){const[n,r]=t.args,i=Yr(r);if(!i||!Object.prototype.hasOwnProperty.call(e,i))throw new kn(`a derivative needs a value for ${i||"its variable"}`);const s=tr(e[i]),o=Jr(n,i,e);if(!Number.isFinite(o(s)))throw new Mn("undefined");const a=1e-6*Math.max(1,Math.abs(s)),l=(o(s+a)-o(s))/a,c=(o(s)-o(s-a))/a;if(!Number.isFinite(l)||!Number.isFinite(c)||Math.abs(l-c)>.001*Math.max(1,Math.abs(l)))throw new Mn("not differentiable here");let u=.1*Math.max(1,Math.abs(s));const h=1.4,p=[[(o(s+u)-o(s-u))/(2*u)]];let m=p[0][0],f=1/0;for(let t=1;t<12;t++){u/=h,p[t]=[(o(s+u)-o(s-u))/(2*u)];let e=h*h;for(let n=1;n<=t;n++){p[t][n]=(p[t][n-1]*e-p[t-1][n-1])/(e-1),e*=h*h;const r=Math.max(Math.abs(p[t][n]-p[t][n-1]),Math.abs(p[t][n]-p[t-1][n-1]));r<=f&&(f=r,m=p[t][n])}if(Math.abs(p[t][t]-p[t-1][t-1])>=2*f)break}if(!Number.isFinite(m))throw new Mn("not differentiable here");return ni(m,f)}(t,e);if("int"===r)return function(t,e){const[n,r,i,s]=t,o=t=>t&&"symbol"===t.type&&/^[a-zA-Zʹ-Ͽ]$/.test(t.value);let a,l,c;if(4===t.length)[a,l,c]=[Yr(r),i,s];else{if(3!==t.length||o(r))throw new kn("an integral needs limits to be calculated");[a,l,c]=[O(n)||"x",r,i]}let u=tr(Xr(l,e)),h=tr(Xr(c,e));if(u===h)return Wn(0);let p=1;u>h&&([u,h]=[h,u],p=-1);const m=Jr(n,a,e),{value:f,error:d}=Kr(m,u,h);return ni(p*f,d)}(i,e);if("lim"===r)return function(t,e){const[n,r,i,s]=t;let o,a,l=0;if(2===t.length&&"op"===r.type&&"→"===r.op)[o,a]=[Yr(r.args[0]),r.args[1]];else if(2===t.length)[o,a]=[O(n),r];else{if(!(t.length>=3))throw new kn("a limit needs a point");[o,a]=[Yr(r),i]}if(4===t.length){const t="op"===s.type?"":String(s.value).toLowerCase();l=t.startsWith("r")||"+"===t?1:-1}if(!o)throw new kn("a limit needs a variable");const c=Xr(a,e),u=tr(c),h=Jr(n,o,e);let p,m;if(Number.isFinite(u))if(l)({value:p,error:m}=ei(t=>h(u+l*t*Math.max(1,Math.abs(u)))));else{const t=ei(t=>h(u+t*Math.max(1,Math.abs(u)))),r=ei(t=>h(u-t*Math.max(1,Math.abs(u))));if(t.value===r.value)({value:p,error:m}=t);else{if(!(Number.isFinite(t.value)&&Number.isFinite(r.value)&&Math.abs(t.value-r.value)<=1e-6*Math.max(1,Math.abs(t.value))))throw new Mn("the limit does not exist");p=(t.value+r.value)/2,m=Math.max(t.error,r.error,Math.abs(t.value-r.value))}try{const t=Xr(n,{...e,[o]:c});if(Math.abs(tr(t)-p)<=1e-6*Math.max(1,Math.abs(p)))return t}catch(t){if(!(t instanceof Mn))throw t}}else({value:p,error:m}=ei(t=>h(Math.sign(u)/t)));return Number.isFinite(p)?ni(p,m):p}(i,e);if("\\sumidx"===r||"\\prodidx"===r)return function(t,e,n){const[r,i,s]=e;if(e.length<3)throw new kn("a sum needs its limits");let o,a=i;"op"===i.type&&"="===i.op&&"symbol"===i.args[0].type?[o,a]=[i.args[0].value,i.args[1]]:o=O(r)||"n";const l=_r(Xr(a,n),"a sum"),c=Xr(s,n),u=t?mr:gr;if(c===1/0){if(!t)throw new kn("an infinite product");return function(t,e){const n=[],r=[];let i=0,s=e;for(let o=4;o<=17;o++){const a=2**o;for(;s<e+a;s++){const e=t(s);if(!Number.isFinite(e))throw new Mn("undefined");i+=e}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2])return ni(i,0)}const o=r[r.length-1]-r[r.length-2],a=r[r.length-2]-r[r.length-3];if(Math.abs(o)>=.9*Math.abs(a)&&Math.abs(o)>1e-12)throw new Mn("the series diverges");const l=n.slice(-7).map(t=>1/t),c=r.slice(-7),u=r.slice(-8,-1),h=(t,e)=>{const n=e.slice();for(let e=1;e<t.length;e++)for(let r=0;r<t.length-e;r++)n[r]=(t[r+e]*n[r]-t[r]*n[r+1])/(t[r+e]-t[r]);return n[0]},p=h(l,c),m=h(n.slice(-8,-1).map(t=>1/t),u);return ni(p,Math.abs(p-m))}(Jr(r,o,n),Number(l))}const h=_r(c,"a sum");if(h-l+1n>BigInt(An.terms))throw new kn("too many terms to add one by one");let p=Wn(t?0:1);for(let t=l;t<=h;t++)p=u(p,Xr(r,{...n,[o]:Bn(In(t))}));return p}("\\sumidx"===r,i,e);if(["()","[]","{}"].includes(r))return Qn(i.map(s),r);if("pmatrix"===r||"bmatrix"===r)return Ur(t,s);if("vmatrix"===r)return Pr.det(Ur(t,s));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(e,"T")){const t=s(i[0]);if(Rr(t))return Pr.transpose(t)}if(Vr.includes(r))return function(t,e){const n={};for(const[t,r]of Object.entries(e))"function"!=typeof r&&(n[t]=ir(r));try{return rr(function(t,e={}){0===vn&&(yn=0),vn++;try{return xn(nn(t),e)}finally{vn--}}(t,n))}catch(t){throw new kn(t.message)}}(t,e);if(r.startsWith("\\:")){const t=r.slice(2);if("function"!=typeof e[t]&&Object.prototype.hasOwnProperty.call(Dr,t))return Dr[t](...i.map(s));const n=e[t];if("function"!=typeof n)throw new kn(`no function ${r.slice(2)}`);return rr(n(...i.map(t=>ir(s(t)))))}if(zr[r]&&1===i.length)return zr[r](s(i[0]));if(Hr[r]&&2===i.length)return Hr[r](s(i[0]),s(i[1]));if(Gr[r])return Gr[r](i.map(s));throw new kn(`can't calculate '${r}'`)}function Qr(t,e){if(Object.prototype.hasOwnProperty.call(e,t))return e[t];if(Object.prototype.hasOwnProperty.call(Tr,t))return Tr[t]();throw new kn(`no value for '${t}'`)}function Jr(t,e,n){return r=>{try{return tr(Xr(t,{...n,[e]:r}))}catch(t){if(t instanceof Mn)return NaN;throw t}}}const Yr=t=>"symbol"===t.type?t.value:null;function Kr(t,e,n){if(e===-1/0&&n===1/0){const e=Kr(t,-1/0,0),n=Kr(t,0,1/0);return{value:e.value+n.value,error:e.error+n.error}}return n===1/0?ti(n=>t(e+n/(1-n))/((1-n)*(1-n)),0,1):e===-1/0?ti(e=>t(n-e/(1-e))/((1-e)*(1-e)),0,1):ti(t,e,n)}function ti(t,e,n){const r=(n-e)/2;let i=1,s=0,o=NaN,a=NaN,l=0;const c=i=>{const s=Math.PI/2*Math.sinh(Math.abs(i)),o=Math.exp(-2*s),a=2*r*o/(1+o),c=r*(Math.PI/2)*Math.cosh(i)*(4*o)/((1+o)*(1+o));if(0===a||0===c)return 0;const u=i>0?n-a:e+a;if(0!==i&&(u<=e||u>=n))return 0;const h=t(0===i?(e+n)/2:u);if(!Number.isFinite(h)){if(a<1e-6*r)return 0;throw new Mn("the integral diverges")}return Math.abs(i)>3.5&&(l=Math.max(l,Math.abs(c*h))),c*h};s=c(0);for(let t=i;t<=4;t+=i)s+=c(t)+c(-t);o=i*s;for(let t=1;t<=8;t++){i/=2;for(let t=i;t<=4;t+=2*i)s+=c(t)+c(-t);a=o,o=i*s;const e=Math.max(1,Math.abs(o));if(l>1e-8*e)throw new Mn("the integral diverges");if(t>=3&&Math.abs(o-a)<=1e-13*e)break}const u=Math.abs(o-a);if(!Number.isFinite(o)||u>1e-6*Math.max(1,Math.abs(o)))throw new Mn("the integral does not converge");return{value:o,error:u}}function ei(t){const e=[],n=[];for(let r=0;r<30;r++){const i=.1/2**r,s=t(i);Number.isFinite(s)&&(e.push(i),n.push(s))}if(n.length<6)throw new Mn("undefined");const r=n.slice(1).map((t,e)=>t-n[e]).slice(-6);if(r.every(t=>Math.sign(t)===Math.sign(r[0])&&0!==t)&&Math.abs(r[5])>=.95*Math.abs(r[0])&&Math.abs(n[n.length-1])>10)return{value:Math.sign(r[0])*(1/0),error:0};const i=t=>{const r=e.slice(t,t+8),i=n.slice(t,t+8);for(let t=1;t<r.length;t++)for(let e=0;e<r.length-t;e++)i[e]=(r[e+t]*i[e]-r[e]*i[e+1])/(r[e+t]-r[e]);return i[0]};let s=null;for(let t=0;t+9<=n.length;t++){const e=i(t),n=i(t+1),r=Math.abs(e-n);Number.isFinite(e)&&(!s||r<s.error)&&(s={value:e,error:r})}const o=n[n.length-1],a=Math.abs(o-n[n.length-2]);if(!s||s.error>Math.max(a,1e-6*Math.max(1,Math.abs(o)))){if(a<=1e-6*Math.max(1,Math.abs(o)))return{value:o,error:10*a};throw new Mn("the limit could not be found")}return s}function ni(t,e=0){if(!Number.isFinite(t))return t;const n=Math.max(1e-10,4*e)*Math.max(1,Math.abs(t));if(n>1e-6*Math.max(1,Math.abs(t)))return t;if(Math.abs(t)<n)return Wn(0);const r=[[Wn(1),1e3],[Dn,100],[Bn(Ln,2),100],[Un,100],...[2n,3n,5n,6n,7n].map(t=>[Bn(Ln,0,0,{n:2,r:t}),100])];for(const[e,i]of r){const r=t/tr(e),s=ri(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*tr(e)<=n)return ar(Bn(s),e)}return t}function ri(t,e){if(!Number.isFinite(t)||Math.abs(t)>1e12)return null;let[n,r,i,s]=[0,1,1,0],o=t;for(let t=0;t<40;t++){const t=Math.floor(o),a=t*r+n,l=t*s+i;if(l>e)break;if([n,r,i,s]=[r,a,s,l],Math.abs(o-t)<1e-15)break;o=1/(o-t)}return s?In(BigInt(r),BigInt(s)):null}function ii(t,e){if("boolean"==typeof t)return String(t);if(t&&"s"===t.kind)return JSON.stringify(t.text);if(Array.isArray(t)){if("pm"===t.group&&2===t.length&&vr(t[1],fr(t[0])))return`±${si(t[0],e)}`;if(jr.has(t.group)&&J(t))return`${t.group}(${t.map(t=>`[${t.map(t=>ii(t,e)).join(", ")}]`).join(", ")})`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[t.group]||"{}";return n+t.map(t=>ii(t,e)).join(", ")+r}return"number"==typeof t?oi(t,e):e.decimal||null!==e.places?function(t,e){if(Gn(t)&&null===e.places){let n=t.c.d,r=0,i=0;for(;n%2n==0n;)n/=2n,r++;for(;n%5n==0n;)n/=5n,i++;const s=Math.max(r,i);if(1n===n&&s<=e.digits){const n=t.c.n*10n**BigInt(s)/t.c.d,r=n<0n,i=On(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=e.maxDigits)return(r?"-":"")+ai(o)}}return Gn(t)&&null!==e.places?ii(qr(t,Wn(e.places)),{...e,places:null,decimal:!0}):oi(tr(t),e)}(t,e):function(t,e){const{c:n}=t,r=On(n.n);if(r.toString().length>e.maxDigits||n.d.toString().length>e.maxDigits)return function(t,e){if(!Gn(t)||1n!==t.c.d)return oi(tr(t),e);const n=On(t.c.n).toString(),r=BigInt(n.slice(0,e.digits+1)),i=((r+5n)/10n).toString(),s=n.length-1+(i.length>e.digits?1:0),o=ai(`${i[0]}.${i.slice(1,e.digits)}`);return`${t.c.n<0n?"-":""}${o}*10^(${s})`}(t,e);const i=(t,e)=>1===e?t:`${t}^${e}`,s=[],o=[];t.pi>0&&s.push(i("pi",t.pi));t.pi<0&&o.push(i("pi",-t.pi));t.e>0&&s.push(i("e",t.e));t.e<0&&o.push(i("e",-t.e));t.root&&s.push(2===t.root.n?`sqrt(${t.root.r})`:`root(${t.root.n}, ${t.root.r})`);1n===r&&s.length||s.unshift(r.toString());1n!==n.d&&o.unshift(n.d.toString());const a=t=>t.length>1?`(${t.join("*")})`:t[0],l=o.length?`${a(s)}/${a(o)}`:s.join("*");return(n.n<0n?"-":"")+l}(t,e)}const si=(t,e)=>{const n=ii(t,e);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function oi(t,e){if(t===1/0)return"∞";if(t===-1/0)return"-∞";if(Object.is(t,-0)||0===t)return"0";if(null!==e.places&&Math.abs(t)<1e21)return t.toFixed(e.places);const n=Math.abs(t);if(n>=1e15||n<1e-6){const[n,r]=t.toExponential(e.digits-1).split("e");return`${ai(n)}*10^(${Number(r)})`}return String(Number(t.toPrecision(e.digits)))}const ai=t=>t.includes(".")?t.replace(/\.?0+$/,""):t;function li(t,e={},n={}){const r="string"==typeof t?en(t):E(t),i={};for(const[t,n]of Object.entries(e))i[t]=rr(n);let s;0===Nn&&(En=0),Nn++;try{s=Xr(r,i)}finally{Nn--}const o={decimal:!1,places:null,digits:12,maxDigits:50,...n};void 0===o.places&&(o.places=null);const a=t=>Array.isArray(t)?t.every(a):"number"!=typeof t;return{value:ir(s),text:ii(s,o),exact:a(s)}}function ci(t,e={}){let n=t.trim();const r={},i=/^(~|≈)\s*(\d+)?/.exec(n);i&&(r.decimal=!0,void 0!==i[2]&&(r.places=Number(i[2])),n=n.slice(i[0].length)),/\d\.\d|\.\d/.test(n)&&(r.decimal=!0);try{const{text:t}=li(n,e,r);return t.startsWith('"')||/^\d+(\.\d+)?$/.test(t)?t:`(${t})`}catch(t){if(t instanceof Mn)return'"undefined"';if(t instanceof kn)return`(${n})`;throw t}}Ke=ci;for(const t of[An,xr,Tr,zr,Hr,Gr])Object.setPrototypeOf(t,null);Object.setPrototypeOf(Dr,null);const ui={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:t=>`the ${t} 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:t=>`the ${t} 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:(t,e)=>`the ${t} by ${e} matrix`,row:t=>`row ${t}`,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"]},hi={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"},pi=Object.fromEntries(Object.entries(_).map(([t,e])=>[e,t]));function mi(t,e={}){return di(function(t,e={}){return fi(t,e,!0)}(t,e))}function fi(t,e,n){return function(t){let e=t.length;for(;e>0&&(t[e-1].close||!t[e-1].text.replace(/,/g,"").trim());)e--;const n=[];for(const{text:r,id:i}of t.slice(0,e)){const t=r.trim();if(!t)continue;const e=t.startsWith(","),s=e?t.slice(1).trim():t;e&&n.length&&!n[n.length-1].text.endsWith(",")&&(n[n.length-1].text+=","),s&&n.push({text:s,id:i})}n.length&&(n[n.length-1].text=n[n.length-1].text.replace(/,$/,""));return n}(new $i({...ui,...e.words},{...hi,...e.names},e.say||{},n).speak(t))}function di(t){return t.map(t=>t.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const gi={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},bi={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class $i{constructor(t,e,n,r=!1){this.w=t,this.names=e,this.say=n,this.audio=r}speak(t){const e=this.say["op"===t.type?t.op:t.type];if(e){return[{text:e("op"===t.type?t.args.map(t=>di(this.speak(t))):[t.value],t,t=>di(this.speak(t))),id:t.id}]}return"number"===t.type?[this.seg(t,this.number(t.value))]:"string"===t.type?[this.seg(t,t.value.slice(1,-1))]:"symbol"===t.type?[this.seg(t,this.symbol(t.value))]:this.operation(t)}seg(t,e){return{text:e,id:t.id}}number(t){const e=this.w;return t.endsWith("..")?`${t.replace(/\.+$/,"")} ${e.repeating}`:t.startsWith("-")?`${e.negative} ${t.slice(1)}`:t}symbol(t){const e=this.w;if("∞"===t)return e.infinity;if("-∞"===t)return`${e.negative} ${e.infinity}`;if("pi"===t||"π"===t)return e.pi;if("tau"===t||"τ"===t)return"tau";if("\\+"===t)return e.plus;if("\\-"===t)return e.minus;if("°"===t)return e.degrees;if(bi[t])return e[bi[t]];if(pi[t])return pi[t].toLowerCase();if(/^Δ.+$/.test(t))return`${e.delta} ${this.symbol(t.slice(1))}`;const n=/′+$/.exec(t);return n?`${this.symbol(t.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:t.endsWith("⁻¹")?`${this.symbol(t.slice(0,-2))} ${e.inverse}`:t}primes(t){const e=this.w;return[e.prime,e.doublePrime,e.triplePrime][t-1]??`${t} ${e.prime}`}isCompound(t){if("op"!==t.type)return!1;if("sum"===t.op||"?:"===t.op)return!0;const e=c(t.op);return void 0!==e&&e<=50&&!a(t.op).group}quantity(t,e="endQuantity"){return this.isCompound(t)?[this.seg(t,this.w.quantity),...this.speak(t),...this.closer(t,e)]:this.speak(t)}closer(t,e){const n=this.seg(t,this.w.comma);return this.audio&&e?[n,{text:this.w[e],id:t.id,close:!0},n]:[n]}contents(t,e){return this.audio&&this.isCompound(t)?this.quantity(t,e):[...this.speak(t),...this.pauseAfter(t)]}argument(t){return this.quantity(t)}operation(t){const{op:e,args:n}=t,[r,i]=n,s=this.w,a=e=>this.seg(t,e),l=()=>n.flatMap((t,e)=>e?[a(s.comma),...this.speak(t)]:this.speak(t));if(gi[e])return[...this.speak(r),a(s[gi[e]]),...this.speak(i)];if(o(e)){const t=this.symbol(D(e));return n.length?[a(`${t} ${s.of}`),...this.arguments(n)]:[a(t)]}if(this.names[e]&&!["log","round","fixed","atan2","random","expm1"].includes(e))return[a(`${this.names[e]} ${s.of}`),...this.arguments(n)];switch(e){case"+":return I(i)?[...this.speak(r),a(s.minus),...this.speak(i.args[1])]:[...this.speak(r),a(s.plus),...this.speak(i)];case"-":return I(i)?[...this.speak(r),a(s.plus),...this.speak(i.args[1])]:[...this.speak(r),a(s.minus),...this.quantityIfSum(i)];case"*":return this.product(t);case"/":return this.fraction(t);case"^":return this.power(t);case"_":return[...this.speak(r),a(s.sub),...this.audio?this.quantity(i,"endSub"):this.speak(i)];case"neg":return this.isCompound(r)||"op"===r.type&&"neg"===r.op?[a(`${s.negative} ${s.quantity}`),...this.speak(r),...this.closer(r,"endQuantity")]:[a(s.negative),...this.speak(r)];case"pm":return[a(s.plusOrMinus),...this.speak(r)];case"!":return[...this.quantity(r),a(s.factorial)];case"\\not":return[a(s.not),...this.quantity(r)];case"sqrt":return[a(s.squareRoot),...this.contents(r,"endRoot")];case"root":{const t="number"===r.type?Number(r.value):NaN,e=3===t?s.cubeRoot:2===t?s.squareRoot:s.nthRoot(t?this.ordinal(t):di(this.speak(r))+"th");return[a(e),...this.contents(i,"endRoot")]}case"abs":return[a(s.absoluteValue),...this.contents(r,"endAbsoluteValue")];case"floor":return[a(s.floor),...this.contents(r,"endFloor")];case"ceil":return[a(s.ceiling),...this.contents(r,"endCeiling")];case"log":return"symbol"===r.type&&"e"===r.value?[a(`${this.names.ln} ${s.of}`),...this.argument(i)]:[a(`${s.logBase}`),...this.speak(r),a(s.of),...this.argument(i)];case"mod":return[...this.quantity(r),a(s.mod),...this.quantity(i)];case"pmod":return[...this.speak(r),a(`${s.comma} ${s.mod}`),...this.speak(i)];case"perm":return[...this.quantity(r),a(s.permute),...this.quantity(i)];case"comb":return[...this.quantity(r),a(s.choose),...this.quantity(i)];case"round":{const t=0===("number"===i.type?Number(i.value):NaN)?s.nearestWholeNumber:`${di(this.speak(i))} ${s.decimalPlaces}`;return[...this.speak(r),a(`${s.comma} ${s.rounded} ${t}`)]}case"fixed":return 0===("number"===i.type?Number(i.value):NaN)?[...this.speak(r),a(`${s.comma} ${s.asWholeNumber}`)]:[...this.speak(r),a(`${s.comma} ${s.writtenTo}`),...this.speak(i),a(s.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${s.of}`),...this.speak(r),a(s.over),...this.speak(i)];case"random":return[a(s.randomNumber)];case"expm1":return[a(s.eToThe),...this.speak(r),a(`${s.comma} ${s.minus} 1`)];case"?:":{const t=[a(s.if),...this.speak(r),a(`${s.comma} ${s.then}`),...this.speak(i)];return(t=>"symbol"===t.type&&"unchanged"===t.value)(n[2])?t:[...t,a(`${s.comma} ${s.otherwise}`),...this.speak(n[2])]}case"sum":return n.flatMap((t,e)=>e?[a(s.plus),...this.speak(t)]:this.speak(t));case"prod":return n.flatMap((t,e)=>e?[a(s.times),...this.quantity(t)]:this.quantity(t));case"mean":case"max":case"min":case"gcd":return[a(`${this.names[e]} ${s.of}`),...l()];case"()":return 2===n.length?[a(s.openInterval),...this.speak(r),a(s.to),...this.speak(i)]:l();case"pmatrix":case"bmatrix":return this.matrix(t);case"vmatrix":return[a(s.determinantOf),...this.matrix(t)];case"[]":return Q(t)?this.matrix(t):2===n.length?[a(s.closedInterval),...this.speak(r),a(s.to),...this.speak(i)]:[a(s.theList),...l()];case"(]":case"[)":return[a(s.halfOpenInterval),...this.speak(r),a(s.to),...this.speak(i)];case"{}":return[a(s.theSet),...l()];case"der":return this.derivative(t);case"int":return this.integral(t);case"lim":return this.limit(t);case"\\sumidx":return this.bigOperator(t,s.sumFrom,s.sumOver,s.sumOf,"endSum");case"\\prodidx":return this.bigOperator(t,s.productFrom,s.productOver,s.productOf,"endProduct")}throw new Error(`No speech for '${e}'`)}matrix(t){const e=this.w,n=Q(t),r=[this.seg(t,e.matrix(n.length,n[0].length))];return n.forEach((n,i)=>{const s=t.args[i];r.push(this.seg(t,e.comma),this.seg("op"===s.type&&"[]"===s.op?s:t,`${e.row(i+1)}:`)),n.forEach((n,i)=>r.push(...i?[this.seg(t,e.comma)]:[],...this.speak(n)))}),[...r,...this.closer(t,"endMatrix")]}arguments(t){return 1===t.length?this.argument(t[0]):t.flatMap((t,e)=>e?[{text:this.w.comma,id:t.id},...this.speak(t)]:this.speak(t))}pauseAfter(t){return this.isCompound(t)?[this.seg(t,this.w.comma)]:[]}quantityIfSum(t){return this.quantity(t)}product(t){const[e,n]=t.args,r=this.w;if(I(t))return[this.seg(t,r.negative),...this.speak(n)];if("symbol"===n.type&&"°"===n.value)return[...this.speak(e),this.seg(t,r.degrees)];const i=this.quantity(e),s=this.quantity(n);return this.isCompound(e)||this.isCompound(n)||this.isWord(e)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(e)||s[0].text.startsWith("the ")?[...i,this.seg(t,r.times),...s]:[...i,...s]}isWord(t){return"symbol"===t.type&&/^[A-Za-z]{2,}$/.test(t.value)&&!_[t.value]&&!["pi","tau"].includes(t.value)}isCall(t){return"op"===t.type&&(o(t.op)||"prefix"===a(t.op)?.fixity&&100===c(t.op))}startsWithNumber(t){let e=t;for(;"op"===e.type&&e.args.length;)e=e.args[0];return"number"===e.type}fraction(t){const[e,n]=t.args,r=this.w,i=e=>this.seg(t,e);if("number"===e.type&&"number"===n.type&&/^[1-9]$/.test(e.value)&&/^([2-9]|10)$/.test(n.value)){const t=Number(e.value),s=Number(n.value),o=2===s?1===t?r.half:r.halves:r.ordinals[s]+(1===t?"":"s");return[i(`${r.numerators[t]} ${o}`)]}return[...this.quantity(e,null),...this.isCall(e)?[i(r.comma)]:[],i(r.over),...this.quantity(n,"endFraction")]}power(t){const[e,n]=t.args,r=this.w,i=e=>this.seg(t,e),s=this.isCompound(e)||this.isCall(e)||"number"===e.type&&e.value.startsWith("-")||"op"===e.type&&"/"===e.op||this.audio&&"op"===e.type&&"^"===e.op?[i(r.quantity),...this.speak(e),...this.closer(e,"endQuantity")]:this.speak(e);if(this.isCall(e)&&this.names[e.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===e.args.length){const t=2===Number(n.value)?r.squared:r.cubed;return[i(`${this.names[e.op]} ${t} ${r.of}`),...this.argument(e.args[0])]}if("number"===n.type&&/^(?:[1-9]|10)$/.test(n.value)){const t=Number(n.value);return 2===t||3===t?[...s,i(r.powers[t])]:[...s,i(`${r.toThe} ${r.powers[t]}`)]}if("number"===n.type&&/^\d+$/.test(n.value))return[...s,i(`${r.toThe} ${this.ordinal(Number(n.value))}`)];return!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))?[...s,i(r.toThe),...this.speak(n)]:this.audio?[...s,i(r.toThePowerOf),i(r.quantity),...this.speak(n),...this.closer(n,"endExponent")]:[...s,i(r.toThePowerOf),...this.speak(n),i(r.comma)]}ordinal(t){if(t<=10&&t>=1)return"squared"===this.w.powers[t]?"second":"cubed"===this.w.powers[t]?"third":this.w.powers[t];return`${t}${t%100>=11&&t%100<=13?"th":["th","st","nd","rd"][t%10]??"th"}`}derivative(t){const{n:e,body:n,by:r,variable:i}=U(t),s=this.w,o=e=>this.seg(t,e);if(i){return[o(1===e?s.d:`${s.d} ${2===e?s.squared:3===e?s.cubed:`${s.toThe} ${this.ordinal(e)}`}`),...this.speak(n),o(s.d),...this.speak(r),o(1===e?"":2===e?s.squared:3===e?s.cubed:`${s.toThe} ${this.ordinal(e)}`)]}return[o(`${1===e?s.derivative:2===e?s.secondDerivative:s.nthDerivative(this.ordinal(e))} ${s.withRespectTo}`),...this.speak(r),o(s.of),...this.contents(n,"endDerivative")]}integral(t){const{args:e}=t,[n,r,i,s]=e,o=this.w,a=e=>this.seg(t,e),l=e.length>=2&&"symbol"===r.type&&1===r.value.length,c=l?this.speak(r):[a(O(n)||"x")];let u=[];4===e.length?u=[i,s]:3===e.length?u=l?[i]:[r,i]:2!==e.length||l||(u=[r]);return[...2===u.length?[a(o.integralFrom),...this.speak(u[0]),a(o.to),...this.speak(u[1]),a(o.of)]:1===u.length?[a(o.integralFrom),...this.speak(u[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(t){const{args:e}=t,[n,r,i,s]=e,o=this.w,a=e=>this.seg(t,e);let l;if(e.length>=3){if(l=[...this.speak(r),a(o.approaches),...this.speak(i)],4===e.length){const t=String(s.value??"").toLowerCase().startsWith("r");l.push(a(t?o.fromTheRight:o.fromTheLeft))}}else if(2===e.length&&"op"===r.type&&"→"===r.op)l=[...this.speak(r.args[0]),a(o.approaches),...this.speak(r.args[1])];else{if(2!==e.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const t=O(n);l=t?[a(t),a(o.approaches),...this.speak(r)]:this.speak(r)}}return[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(t,e,n,r,i){const{args:s}=t,[o,a,l]=s,c=this.w,u=e=>this.seg(t,e);let h;return h=3===s.length?[u(e),...this.speak(a),u(c.to),...this.speak(l),u(c.of)]:2===s.length?[u(n),...this.speak(a),u(c.of)]:[u(r)],[...h,...this.contents(o,i)]}}for(const t of[ui,hi,gi,bi,pi])Object.setPrototypeOf(t,null);function yi(t,e={}){return rn(t)?[]:function(t,e={}){return fi(t,e,!1)}(nn(t),e)}function vi(t,e={}){return rn(t)?"":mi(nn(t),e)}const xi={"(":{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 wi(t,e,n=""){const r=xi[t];return`<svg class="${e}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${r.fill?`<path d="${r.fill}" fill="currentColor"/>`:`<path d="${r.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const Mi=.8,ki=.2,Ai=.25,Ei=.7,Ni="−",Oi={"+":"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"},_i={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Si={"±":"±","∪":"∪","∩":"∩",mod:"mod"},Ii=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],qi={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},Li=[...Ii,...Object.keys(qi),"ln","det"],Ci={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},Ti={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},zi={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},ji={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},Ri=["boxed","overline","bar","underline","cancel",...Object.keys(ji)],Fi={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},Pi=t=>String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),Zi=t=>+t.toFixed(3)+"em",Bi=(t,e=Mi,n=ki)=>({html:t,h:e,d:n});function Wi(...t){const e=t.flat().filter(Boolean);return{html:e.map(t=>t.html).join(""),h:Math.max(Mi,...e.map(t=>t.h)),d:Math.max(ki,...e.map(t=>t.d))}}function Di(t,e={}){const n=new Ui({...Fi,...e}),r=n.render(t,{level:0}),i=`${n.p}${n.o.display?` ${n.p}-display`:""}`,s="function"==typeof n.o.mathml?function(t,e,n,r){try{return String(t(e)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${r?' display="block"':""}>`)}catch{return""}}(n.o.mathml,t,n.p,n.o.display):"",o=s?null:function(t,e){if(!1===e||null===e)return null;if("string"==typeof e)return e;try{return"function"==typeof e?e(t):vi(t)}catch{return null}}(t,n.o.label),a=null!==o||s?r.html.replace(/^<span /,'<span aria-hidden="true" '):r.html;return{html:`<span class="${i}"${null===o?"":` role="math" aria-label="${Pi(o)}"`}>${a}${s}</span>`,h:r.h,d:r.d}}class Ui{constructor(t){this.o=t,this.p=t.prefix}el(t,e,n="",r=""){return`<span class="${t.split(" ").map(t=>`${this.p}-${t}`).join(" ")}"${n?` style="${n}"`:""}${r}>${e}</span>`}text(t,e){const n=Bi(this.el(t,Pi(e)));return n.leaf={kind:t,content:Pi(e)},n}bin(t){return this.text("bin",t)}rel(t){return this.text("rel",t)}punct(t){return this.text("punct",t)}word(t){return this.text("word",t)}wrap(t,e,n){let r="";void 0!==t.id&&(r+=` data-node="${t.id}"`),"op"===t.type&&(r+=` data-op="${Pi(t.op)}"`);const i=this.o.attributes&&this.o.attributes(t)||{};for(const[t,e]of Object.entries(i))"class"!==t&&"style"!==t&&(r+=` ${t}="${Pi(e)}"`);const s=[i.style,this.o.style&&this.o.style(t)].filter(Boolean).join(";"),o=(n.leaf?["n",...e,n.leaf.kind]:["n",...e]).map(t=>`${this.p}-${t}`).concat(i.class?[i.class]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${s?` style="${Pi(s)}"`:""}${r}>${a}</span>`,h:n.h,d:n.d}}render(t,e){return"number"===t.type?this.number(t):"string"===t.type?this.wrap(t,["text"],this.text("text",t.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===t.type?this.wrap(t,["symbol"],this.symbol(t.value)):this.operation(t,e)}number(t){return this.wrap(t,["number"],this.text("num",t.value.replace(/^-/,Ni)))}symbol(t){return _[t]&&(t=_[t]),zi[t]?this.text("ord",zi[t]):"\\+"===t||"\\-"===t?this.text("ord",t[1]):"-∞"===t?this.text("ord","−∞"):/^[A-Za-z]$/.test(t)||/^[α-ω]$/.test(t)?this.text("var",t):/^[A-Za-z]′+$/.test(t)?Bi(this.el("var",Pi(t[0]))+this.el("prime",Pi(t.slice(1)))):/^Δ[A-Za-z]$/.test(t)?Bi(this.el("ord","Δ")+this.el("var",t[1])):t.endsWith("⁻¹")?this.script(this.symbol(t.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(t)?this.text("name",t.slice(1)):/^[A-Za-z]{2,}$/.test(t)?this.text("name",t):this.text("ord",t)}operation(t,e){const{op:n,args:r}=t,[i,s]=r,a=(t,n={})=>this.render(t,{...e,...n,forceParens:n.forceParens||!1,before:n.before||!1}),l=Oi[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),c=e=>this.wrap(t,["op",`op-${l}`],e),u=(e,n)=>C(t,e,n)&&"/"!==e.op?this.fence(a(e)):a(e);if(Li.includes(n)||"log"===n)return c(this.named(t,e));if(Ci[n])return c(Wi(this.word(Ci[n]),this.fence(this.list(r,e))));if(o(n))return c(this.custom(t,e));const h=Q(t);if(h)return c(this.matrix(t,h,e));if(Ti[n])return c(this.fence(this.list(r,e),...Ti[n]));if(_i[n]&&2===r.length)return c(Wi(u(i,"left"),this.rel(_i[n]),u(s,"right")));if(Si[n]&&2===r.length)return c(Wi(u(i,"left"),this.bin(Si[n]),u(s,"right")));switch(n){case"+":return I(s)?c(Wi(u(i,"left"),this.bin(Ni),this.wrap(s,["op","op-mul"],this.render(s.args[1],e)))):"number"===s.type&&s.value.startsWith("-")?c(Wi(u(i,"left"),this.bin(Ni),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):c(Wi(u(i,"left"),this.bin("+"),this.signed(s,u(s,"right"))));case"-":return c(Wi(u(i,"left"),this.bin(Ni),this.signed(s,u(s,"right"))));case"*":return c(this.product(t,e));case"/":return c(this.fraction(t,e));case"^":return c(this.power(t,e));case"_":return c(this.script(a(i,{forceParens:!0}),null,e,a(s,{level:e.level+1})));case"neg":return c(Wi(this.text("sign",Ni),T(n,i)?this.fence(a(i)):a(i,{before:e.before})));case"pm":return c(Wi(this.text("sign","±"),T(n,i)?this.fence(a(i)):a(i)));case"!":return c(Wi(T(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(Wi(this.text("sign","¬"),T(n,i)?this.fence(a(i)):a(i)));case"pmod":return c(Wi(a(i),this.fence(Wi(this.word("mod"),this.text("space",""),a(s)))));case"sqrt":return c(this.radical(a(i)));case"root":return c(this.radical(a(s),this.render(i,{level:e.level+2})));case"abs":return c(this.fence(a(i),"|","|"));case"floor":return c(this.fence(a(i),"⌊","⌋"));case"ceil":return c(this.fence(a(i),"⌈","⌉"));case"loglog":return c(Wi(this.word("ln"),this.fence(Wi(this.word("ln"),this.fence(a(i))))));case"logloglog":return c(Wi(this.word("ln"),this.fence(Wi(this.word("ln"),this.fence(Wi(this.word("ln"),this.fence(a(i))))))));case"perm":return c(this.script(this.script(Bi(""),this.render(i,{level:e.level+1}),e),null,e,this.render(s,{level:e.level+1}),this.word("P")));case"comb":return c(this.fence(this.stack(a(i),a(s),!1)));case"?:":return c(this.o.cases?this.cases(t,e):Wi(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":return c(Wi(r.map((t,e)=>e?[this.bin("+"),a(t)]:[a(t)]).flat()));case"prod":return c(Wi(r.map((t,e)=>e?[this.bin("·"),a(t)]:[a(t)]).flat()));case"der":return c(this.derivative(t,e));case"int":return c(this.integral(r,e));case"lim":return c(this.limit(r,e));case"\\sumidx":return c(this.bigOperator("sum",r,e));case"\\prodidx":return c(this.bigOperator("prod",r,e))}throw new Error(`Inline Math cannot draw '${n}'`)}signed(t,e){return("number"===t.type?t.value.startsWith("-"):"neg"===t.op||"pm"===t.op)&&!e.fenced?this.fence(e):e}list(t,e){return Wi(t.map((t,n)=>n?[this.punct(","),this.render(t,e)]:[this.render(t,e)]).flat())}product(t,e){const[n,r]=t.args;if(I(t))return Wi(this.text("sign",Ni),this.render(r,e));const i=function(t){const[e,n]=t.args;return{left:C(t,e,"left")&&"/"!==e.op,right:C(t,n,"right")&&"/"!==n.op}}(t),s=z(n,r,i),a=function(t){for(;"op"===t.type;){if(Li.includes(t.op)||"log"===t.op||Ci[t.op]||o(t.op))return!0;if("^"!==t.op&&"*"!==t.op)return!1;t=t.args[0]}return!1}(r),l=i.left?this.fence(this.render(n,e)):this.render(n,{...e,before:s&&!a}),c=i.right?this.fence(this.render(r,e)):this.render(r,{...e,before:e.before});return Wi(l,s?Bi(this.el(a?"fnspace":"times","")):this.bin("·"),c)}named(t,e,n=null){const{op:r,args:i}=t,s="log"===r?i[1]:i[0];let o;o=qi[r]&&"power"===this.o.inverseTrig?this.script(this.word(qi[r]),this.text("num","−1"),e):this.word(r),n&&(o=this.script(o,n,e)),"log"===r&&(o=this.script(o,null,e,this.render(i[0],{level:e.level+1})));const a="auto"===this.o.fnParens&&!e.forceParens&&!e.before&&Hi(s),l=this.render(s,{...e,forceParens:!1,before:!1});return Wi(o,a?Wi(Bi(this.el("fnspace","")),l):this.fence(l))}custom(t,e){const n=D(t.op),r=t.args;if(Ri.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],e));return Wi(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Bi(this.el("callgap","")),this.fence(this.list(r,e)))}decorate(t,e){switch(t){case"boxed":return Bi(this.el("boxed",e.html),e.h+.22,e.d+.22);case"cancel":return Bi(this.el("cancel",e.html+wi("cancel",`${this.p}-cancel-line`)),e.h,e.d);case"underline":return Bi(this.el("underline",e.html),e.h,e.d+.12);case"overline":case"bar":return Bi(this.el("over",e.html),e.h+.14,e.d);default:return Bi(this.el("accent",this.el("accent-mark",ji[t])+e.html),e.h+.3,e.d)}}fraction(t,e){const[n,r]=t.args;if(e.level>0&&"slash"===this.o.scriptFractions&&Hi(n,!0)&&Hi(r,!0)){const t=t=>"op"!==t.type||Hi(t)?this.render(t,e):this.fence(this.render(t,e));return Wi(t(n),this.text("ord","/"),t(r))}const i=e.level>0||e.inFraction||!this.o.display?.8:1,s={...e,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,s),this.render(r,s),!0,i)}stack(t,e,n=!0,r=1){const i=t=>1===r?t.html:this.el("scaled",t.html,`font-size:${Zi(r)}`),s=n?.06:0,o=Ai+s/2+.1+Math.max(ki,r*t.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(t))+this.el("denom",i(e)),`vertical-align:${Zi(o)}`);return Bi(a,o+Math.max(Mi,r*t.h),Math.max(Mi,r*e.h)+Math.max(ki,r*e.d)+.1+s/2-Ai)}power(t,e){const[n,r]=t.args,i={...e,level:e.level+1,forceParens:!1,before:!1,inFraction:!1},s=()=>this.render(r,i);if(this.o.trigPowers&&Ii.includes(n.op)&&Vi(r))return this.wrap(n,["op",`op-${n.op}`],this.named(n,e,s()));if("_"===n.op){const t=this.render(n.args[1],i);return this.wrap(n,["op","op-subscript"],this.script(this.render(n.args[0],{...e,forceParens:!0}),s(),e,t))}const o=C(t,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||Li.includes(n.op)?this.fence(this.render(n,e)):this.render(n,{...e,forceParens:!0});return this.script(o,s(),e)}script(t,e,n,r=null,i=null){const s=n.level>0?.8:Ei,o=i?Wi(t,i):t;let a=e?Math.max(.42,t.h-.38,s*e.d+.12):0,l=r?Math.max(.2,t.d-.05,s*r.h-.45):0;if(e&&r){const t=.1-(a-s*e.d-(s*r.h-l));t>0&&(l+=t)}const c=t=>this.el("script",t.html,`font-size:${Zi(s)}`);if(e&&!r)return Bi(t.html+this.el("sup",e.html,`font-size:${Zi(s)};vertical-align:${Zi(a/s)}`),Math.max(o.h,a+s*e.h),Math.max(o.d,s*e.d-a));if(r&&!e)return Bi(o.html+this.el("sub",r.html,`font-size:${Zi(s)};vertical-align:${Zi(-l/s)}`),Math.max(o.h,s*r.h-l),Math.max(o.d,l+s*r.d));const u=a+s*e.h,h=l+s*r.d,p=this.el("subsup",c(e)+c(r),`vertical-align:${Zi(a)};height:${Zi(u+h)}`);return Bi(o.html+p,Math.max(o.h,u),Math.max(o.d,h))}radical(t,e=null){const n=Math.max(t.h,Mi)+.1+.06,r=Math.max(t.d,ki),i=n+r,s=wi("sqrt",`${this.p}-hook`,`height:${Zi(i)};width:${Zi(.5+.06*(i-1))};vertical-align:${Zi(-r)}`);let o="";if(e){const t=.8*Ei;o=this.el("rootindex",e.html,`font-size:${Zi(t)};vertical-align:${Zi((.55*i-r)/t)}`)}return Bi(this.el("sqrt",o+s+this.el("radicand",t.html)),n,r)}fence(t,e="(",n=")"){const r=Math.max(t.h,Mi)+Math.max(t.d,ki),i=r>1.25,s=i?.1:0,o=(t,e)=>{if(!t)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[t];if(n){const s=n+(i?Math.min(.2,.05*(r-1)):0);return{html:wi(t,`${this.p}-delim ${this.p}-delim-${e}`,`width:${Zi(s)}`),w:s+.1}}const s={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[t];return{html:this.el(`delim ${s} delim-${e}`,""),w:"|"===t?.18:.3}},a=o(e,"l"),l=o(n,"r"),c=`padding:${Zi(s)} ${Zi(l.w)} ${Zi(s)} ${Zi(a.w)}`,u=Bi(this.el("fence",a.html+t.html+l.html,c),Math.max(t.h,Mi)+s,Math.max(t.d,ki)+s);return u.fenced=!0,u}derivative(t,e){const{n:n,body:r,by:i,variable:s}=U(t),o={...e,level:e.level+1},a=()=>this.text("d","d"),l=()=>n>1?this.render({type:"number",value:String(n)},o):null,u={...e,inFraction:!0},h=Wi(a(),l()?this.script(this.render(i,u),l(),u):this.render(i,u)),p=t=>Wi(l()?this.script(a(),l(),u):a(),t||[]),m=e.level>0||e.inFraction||!this.o.display?.8:1;if(s)return this.stack(p(this.render(r,u)),h,!0,m);const f=q(r)&&c(q(r))<100,[d,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=f?this.fence(this.render(r,e),d,g):this.render(r,e);return Wi(this.stack(p(),h,!0,m),b)}integral(t,e){const[n,r,i,s]=t,o=t=>this.render(t,e),a=t=>t?this.render(t,{...e,level:e.level+1}):null,l=()=>this.text("var",O(n)||"x");let c,u=null,h=null;switch(t.length){case 1:c=l();break;case 2:W(r)?c=o(r):(c=l(),u=a(r));break;case 3:W(r)?(c=o(r),u=a(i)):(c=l(),u=a(r),h=a(i));break;default:c=o(r),u=a(i),h=a(s)}const p=o(n),m=Bi(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Wi(this.bigSign("int",p,u,h,e),p,m)}bigSign(t,e,n,r,i){const s=!this.o.display||i.level>0,o=Math.max(s?.6:.95,Math.max(e.h-Ai,e.d+Ai)+.12),a=wi(t,`${this.p}-bigsign ${this.p}-${t}sign`,`height:${Zi(2*o)};width:${Zi(s?.38:.5)};vertical-align:${Zi(Ai-o)}`);if(!n&&!r)return Bi(a,Ai+o,o-Ai);const l=Ei,c=r||Bi(""),u=n||Bi(""),h=Ai+o-l*c.h;u.d;const p=this.el("limits",this.el("script",c.html,`font-size:${Zi(l)}`)+this.el("script lower",u.html,`font-size:${Zi(l)}`),`vertical-align:${Zi(h)};height:${Zi(2*o)}`);return Bi(a+p,Ai+o,o-Ai)}limit(t,e){const[n,r,i,s]=t,o={...e,level:e.level+1},a=t=>this.render(t,o),l=()=>this.rel("→");let c;switch(t.length){case 1:return Wi(this.word("lim"),Bi(this.el("fnspace","")),this.render(n,e));case 2:{const t=O(n),e="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=t&&e?Wi(this.text("var",t),l(),a(r)):a(r);break}case 3:c=Wi(a(r),l(),a(i));break;default:{const t=S(s).toLowerCase().startsWith("r")?"+":Ni;c=Wi(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",t)),o))}}return Wi(this.under(this.word("lim"),c,e),this.render(n,e))}under(t,e,n){return!this.o.display||n.level>0?this.script(t,null,n,e):Bi(this.el("under",t.html+this.el("script",e.html,`font-size:${Zi(.7)}`)),t.h,Math.max(t.d,ki)+.05+.7*(e.h+e.d))}bigOperator(t,e,n){const[r,i,s]=e,o={...n,level:n.level+1},a=i?this.render(i,o):null,l=s?this.render(s,o):null,c=this.render(r,n);if(!this.o.display||n.level>0){const e=.55,r=wi(t,`${this.p}-bigsign`,`height:${Zi(2*e)};width:${Zi(.8)};vertical-align:${Zi(Ai-e)}`);return Wi(this.script(Bi(r,Ai+e,e-Ai),l,n,a),c)}const u=.68,h=Ei,p=wi(t,`${this.p}-bigsign`,`height:${Zi(1.36)};width:${Zi("sum"===t?1:1.05)}`),m=l?1.01+h*l.d:Ai-u,f=t=>this.el("script",t.html,`font-size:${Zi(h)}`),d=this.el("bigop",(l?f(l):"")+p+(a?f(a):""),`vertical-align:${Zi(m)}`);return Wi(Bi(d,.93+(l?.08+h*(l.h+l.d):0),u-Ai+(a?.08+h*(a.h+a.d):0)),c)}matrix(t,e,n){const r=e.map(t=>t.map(t=>this.render(t,n))),i=r.map(t=>({h:Math.max(Mi,...t.map(t=>t.h)),d:Math.max(ki,...t.map(t=>t.d))})),s=i.reduce((t,e)=>t+e.h+e.d,0)+.3*(e.length-1),o=Ai+s/2-i[0].h,a=r.map((e,n)=>{const r=e.map(t=>this.el("matrix-cell",t.html)).join(""),i=t.args[n];return i&&"op"===i.type&&"[]"===i.op?this.wrap(i,["op","op-list","matrix-row"],Bi(r)).html:r}).join(""),l=e[0].length,c=Bi(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${Zi(o)}`),Ai+s/2,s/2-Ai),[u,h]=X[t.op]??["[","]"];return this.fence(c,u,h)}cases(t,e){const n=[];let r=t;for(;"op"===r.type&&"?:"===r.op;)n.push([this.render(r.args[1],e),Wi(this.word("if"),this.text("space",""),this.render(r.args[0],e))]),r=r.args[2];"symbol"===r.type&&"unchanged"===r.value||n.push([this.render(r,e),this.word("otherwise")]);const i=n.map(([t,e])=>({h:Math.max(t.h,e.h),d:Math.max(t.d,e.d)})),s=i.reduce((t,e)=>t+e.h+e.d,0)+.25*(n.length-1),o=Ai+s/2-i[0].h,a=n.map(([t,e])=>this.el("case-value",t.html)+this.el("case-cond",e.html)).join(""),l=Bi(this.el("cases",a,`vertical-align:${Zi(o)}`),Ai+s/2,s/2-Ai);return this.fence(l,"{","")}}function Hi(t,e=!1){return"number"===t.type?!t.value.startsWith("-")||e:"symbol"===t.type||"op"===t.type&&("abs"===t.op||Q(t)?!e:!e||"neg"!==t.op&&"^"!==t.op?"*"===t.op&&!I(t)&&t.args.every(t=>"number"===t.type&&!t.value.startsWith("-")||Gi(t)||"*"===t.op&&Hi(t,e)):Hi(t.args[0],!0)&&("neg"===t.op||Hi(t.args[1],!0)))}const Gi=t=>"symbol"===t.type&&(1===t.value.length||/^[α-ωΑ-Ω]$/.test(t.value)||Boolean(_[t.value])),Vi=t=>"number"===t.type&&/^[1-9]\d*$/.test(t.value)&&Number(t.value)<10;const Xi=t=>A(t).join(" ");function Qi(t,e){const n=new Set;Ji(t,e,n);const r=[];return N(t,t=>{n.has(t)&&r.push(t)}),r}function Ji(t,e,n){if(null!=e)if(Array.isArray(e))e.forEach(e=>Ji(t,e,n));else if("number"!=typeof e)if("function"!=typeof e){if("string"==typeof e){const r=Xi(en(e));return void N(t,t=>{Xi(t)===r&&n.add(t)})}if(e.path){const r=Yi(t,e.path);return void(r&&n.add(r))}if(e.type){const r=Xi(e);N(t,t=>{t!==e&&Xi(t)!==r||n.add(t)})}}else N(t,(t,r)=>{e(t,r)&&n.add(t)});else N(t,t=>{t.id===e&&n.add(t)})}function Yi(t,e){let n=t;for(const t of e){if("op"!==n.type||!n.args[t])return null;n=n.args[t]}return n}function Ki(t,e){const n=[],r=t=>{if(t.id===e)return!0;if("op"!==t.type)return!1;for(let e=0;e<t.args.length;e++){if(n.push(e),r(t.args[e]))return!0;n.pop()}return!1};return r(t)?n:null}function ts(t){let n=0;const r=t=>{"op"===t.type&&(t.args.forEach(r),a(t.op)?.arity===e&&n++),t.id=n++};return r(t),t}function es(t,e={}){const{blocks:n}=e;if("string"==typeof t)return en(t,n?{blocks:t=>n(t,e.scope)}:{});if(Array.isArray(t))return k(t);if(t&&"object"==typeof t&&t.type)return void 0===t.id?ts(structuredClone(t)):t;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function ns(t,e){const{colors:n,highlight:r,scope:i,blocks:s,...o}=e,a=new Map;for(const[e,r]of function(t){return t?Array.isArray(t)?t:Object.entries(t).map(([t,e])=>[/^\d+$/.test(t)?Number(t):t,e]):[]}(n))if(rs(r))for(const n of Qi(t,e))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:Qi(t,r));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:t=>[a.get(t),o.style&&o.style(t)].filter(Boolean).join(";"),attributes:t=>{const e={...o.attributes?o.attributes(t):{}};return l.has(t)&&(e.class=[e.class,`${c}-hl`].filter(Boolean).join(" ")),e}}}function rs(t){return"string"==typeof t&&/^[#\w\s.,%()/+-]+$/.test(t)&&!/url\s*\(|expression/i.test(t)}function is(t,e={}){return es(t,{...e,blocks:e.blocks??ci})}function ss(t,e={}){return function(t,e={}){const n=es(t,e);return Di(n,ns(n,e)).html}(t,{...e,blocks:e.blocks??ci})}const os=Symbol.for("inlinemath.expressions"),as=new Set(["symbol","number"]);function ls(t){return t?"symbol"===t.type?t.value:"op"===t.type&&"_"===t.op&&2===t.args.length&&"symbol"===t.args[0].type&&as.has(t.args[1].type)?`${t.args[0].value}_${t.args[1].value}`:null:null}function cs(t){const{id:e,from:n,...r}=t;return r.args&&(r.args=r.args.map(cs)),r}function us(t){const{id:e,...n}=t;return n.args&&(n.args=n.args.map(us)),n}function hs(t,e){const n=(t,r)=>{if(!r&&void 0!==t.from)return e(t.from);const{id:i,from:s,...o}=t;return o.args&&(o.args=o.args.map(t=>n(t,!1))),o};return n(t,!0)}function ps(t,e){let n=!1;const r=new Set,i=t=>{const s=ls(t);if(null!==s){if(!r.has(s)){const t=e(s);if(t){n=!0,r.add(s);const e={...i(cs(t)),from:s};return r.delete(s),e}}return t}return t.args?{...t,args:t.args.map(i)}:t},s=i(t);return{tree:n?us(s):t,changed:n}}const ms="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",fs=new RegExp(`^(${ms})\\s*\\.\\.\\s*(${ms})(?:\\s+step\\s+(${ms}))?(?:\\s*=\\s*(${ms}))?$`);function ds(t){const e=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(t);if(!e||/\]\s*,\s*\[/.test(e[1]))return null;const n=e[1].trim(),r=fs.exec(n);if(r){const t=Number(r[1]),e=Number(r[2]);if(!(e>t))return null;const n=void 0!==r[3]?Number(r[3]):Number.isInteger(t)&&Number.isInteger(e)?1:(e-t)/100;if(!(n>0))return null;const i=void 0!==r[4]?Math.min(e,Math.max(t,Number(r[4]))):t;return{kind:"slider",min:t,max:e,step:n,default:String(i)}}if(n.includes("|")){const t=n.split("|").map(t=>t.trim()).filter(Boolean);if(t.length)return{kind:"dropdown",options:t,default:t[0]}}return{kind:"textbox",default:n}}const gs=Symbol("set on the page");class bs{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(t){const e=new Map;for(const[n,r]of this.owners)if(n!==t)for(const[t,n]of r)e.delete(t),e.set(t,n);return e}textOf(t){const e=this.chosen.get(t.name);return e&&e.key===t.key?e.text:t.text}get(t){const e=this.definitions().get(t);return e?this.textOf(e):void 0}names(){return[...this.definitions().keys()]}set(t,e){e=String(e);const n=this.definitions().get(t);if(n&&n.input){const r=this.chosen.get(t);if(r&&r.key===n.key&&r.text===e)return this;this.chosen.set(t,{key:n.key,text:e})}else{const n=new Map(this.owners.get(gs));n.set(t,{name:t,text:e,key:`page:${e}`,input:null}),this.owners.delete(gs),this.owners.set(gs,n)}return this.notify(null,t),this}clear(t){return void 0===t?(this.owners.clear(),this.chosen.clear()):(this.owners.get(gs)?.delete(t),this.chosen.delete(t)),this.notify(null,t),this}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}own(t,e){const n=this.owners.get(t);var r,i;(r=n,i=e,(r?.size??0)===(i?.size??0)&&[...r??[]].every(([t,e])=>i?.get(t)?.key===e.key))?e&&this.owners.set(t,e):(e&&e.size?this.owners.set(t,e):this.owners.delete(t),this.notify(t))}notify(t,e){for(const n of[...this.listeners])n(t,e)}}function $s(){return new bs}const ys=$s();function vs(t,e,n){const r=(t,i)=>i===e.length?n:{...t,args:t.args.map((t,n)=>n===e[i]?r(t,i+1):t)};return cs(r(t,0))}function xs(t,e,{parse:n,commit:r,cancel:i,label:s="Edit"}){const o=t.ownerDocument;if(!o||!o.body)return null;const a=o.defaultView,l=t.getBoundingClientRect(),c=o.createElement("input");c.type="text",c.className="mv-edit",c.value=e,c.spellcheck=!1,c.autocomplete="off",c.setAttribute("aria-label",s);const u=()=>{c.style.width=`${Math.max(4,c.value.length+2)}ch`},h=a.getComputedStyle(t);Object.assign(c.style,{position:"absolute",left:`${l.left+a.scrollX}px`,top:`${l.top+a.scrollY+l.height/2}px`,minWidth:`${Math.max(l.width,32)}px`,fontSize:h.fontSize}),u(),o.body.appendChild(c),a.getSelection?.()?.removeAllRanges(),c.focus(),c.select();let p=!1;const m=()=>{p=!0,c.remove()},f=t=>{if(p)return!0;if(!t||c.value===e)return m(),i&&i(),!0;let s;try{s=n(c.value)}catch(t){return c.setAttribute("aria-invalid","true"),c.title=t.message,!1}return m(),r(s,c.value),!0};return c.addEventListener("keydown",t=>{t.stopPropagation(),"Enter"===t.key&&(t.preventDefault(),f(!0)),"Escape"===t.key&&(t.preventDefault(),f(!1))}),c.addEventListener("input",()=>{u(),c.removeAttribute("aria-invalid"),c.removeAttribute("title")}),c.addEventListener("blur",()=>{f(!0)||f(!1)}),c}class ws{constructor(t,e,n={}){this.element=t,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=Ms(t,n.announce,this.p),this.set(e)}set(t,{animate:e=!1,duration:n=600,easing:r="ease-in-out"}={}){const i=ks(e)&&this.tree?this.snapshot():null,s=void 0!==this.tree;return this.tree=is(t,this.options),this.element.innerHTML=Di(this.tree,ns(this.tree,this.options)).html,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),i&&this.morph(i,{duration:n,easing:r}),s&&this.live&&this.announce(this.spoken()),this}spoken(){const t=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(t)return t;try{return vi(this.tree)}catch{return""}}announce(t){return this.say(this.live,t)}say(t,e){if(!t)return this;t.textContent="";const n=()=>{t.textContent=e};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(n)):setTimeout(n,50),this}nodes(t){return Qi(this.tree,t)}elements(t){return this.nodes(t).map(t=>this.elementOf(t)).filter(Boolean)}elementOf(t){return void 0===t.id?null:this.root.querySelector(`[data-node="${t.id}"]`)}highlight(t,e=`${this.p}-hl`){return this.elements(t).forEach(t=>t.classList.add(e)),this}unhighlight(t=null,e=`${this.p}-hl`){return(null===t?this.root.querySelectorAll(`.${e}`):this.elements(t)).forEach(t=>t.classList.remove(e)),this}color(t,e){return this.elements(t).forEach(t=>{t.style.color=e||""}),this}on(t,e){const n=t=>{const n=t.target.closest?.("[data-node]");if(!n||!this.root.contains(n))return;const r=Number(n.dataset.node),i=Qi(this.tree,r)[0];e({node:i,id:r,path:Ki(this.tree,r),element:n,event:t})};return this.element.addEventListener(t,n),this.handlers.push([t,n]),this.root.classList.add(`${this.p}-clickable`),"click"===t&&(this.clicks.push(e),this.keyboard()),()=>{this.element.removeEventListener(t,n),this.clicks=this.clicks.filter(t=>t!==e)}}editable({toText:t,onEdit:e}={}){if("function"!=typeof t)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:t,onEdit:e},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.element.addEventListener("dblclick",t=>{const e=t.target.closest?.("[data-node]");e&&this.root.contains(e)&&(t.preventDefault(),this.edit(Qi(this.tree,Number(e.dataset.node))[0]))})),this}edit(t=this.tree,{returnFocus:e=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const n="object"==typeof t&&t&&t.type?t:this.nodes(t)[0];if(!n)return null;const r=Ki(this.tree,n.id)||[],i=this.elementOf(n)||this.root;let s="Edit";try{s=`Edit ${vi(n)}`}catch{}const o=()=>{e&&this.root.focus&&this.root.focus()};return xs(i,this.editing.toText(n),{label:s,parse:t=>is(t,this.options),commit:(t,n)=>{this.set(vs(this.tree,r,t),{animate:!0});const i=Yi(this.tree,r);e&&i&&this.focusPart(i===this.tree?null:i),o(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:r,part:n})},cancel:o})}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||Ms(this.element,!0,this.p),this.element.addEventListener("keydown",t=>this.key(t)))}key(t){if(!this.root||!this.root.contains(t.target))return;const e=this.active;let n;switch(t.key){case"ArrowDown":n=e?this.partsOf(e)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":n=e?this.outerOf(e):void 0;break;case"ArrowRight":n=e?this.neighbour(e,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":n=e?this.neighbour(e,-1):void 0;break;case"Home":case"Escape":n=null;break;case"F2":if(!this.editing)return;return t.preventDefault(),void this.edit(e||this.tree,{returnFocus:!0});case"Enter":case" ":{t.preventDefault();const n=e||this.tree,r=this.elementOf(n)||this.root,i={node:n,id:n.id,path:Ki(this.tree,n.id),element:r,event:t};for(const t of this.clicks)t(i);return}default:return}t.preventDefault(),void 0!==n&&this.focusPart(n)}focusPart(t){const e=`${this.p}-focus`;this.root.querySelectorAll(`.${e}`).forEach(t=>t.classList.remove(e)),this.active=t;const n=t&&this.elementOf(t);n&&n.classList.add(e);let r="";try{r=t?vi(t):this.spoken()}catch{r=""}return this.say(this.partsLive,r),this}partsOf(t){const e=[],n=t=>{this.elementOf(t)?e.push(t):"op"===t.type&&t.args.forEach(n)};return t&&"op"===t.type&&t.args.forEach(n),e}outerOf(t){const e=Ki(this.tree,t.id);for(let t=e?e.length-1:-1;t>0;t--){const n=Yi(this.tree,e.slice(0,t));if(n&&this.elementOf(n))return n}return null}neighbour(t,e){const n=this.partsOf(this.outerOf(t)||this.tree),r=n.indexOf(t);return r<0?void 0:n[r+e]}segments(t={}){return yi(this.tree,t)}showSegment(t,e=`${this.p}-hl`){return this.unhighlight(null,e),t&&void 0!==t.id&&this.highlight(t.id,e),this}snapshot(){const t=new Map,e=n=>{const r=this.elementOf(n);if(r){const e=Xi(n);t.has(e)||t.set(e,[]),t.get(e).push(r.getBoundingClientRect())}"op"===n.type&&n.args.forEach(e)};return e(this.tree),t}morph(t,{duration:e,easing:n}){if("undefined"==typeof Element||!Element.prototype.animate)return;const r=i=>{const s=this.elementOf(i),o=s&&t.get(Xi(i));if(o&&o.length){const t=o.shift(),r=s.getBoundingClientRect(),i=t.left-r.left,a=t.top-r.top,l=r.width?t.width/r.width:1,c=r.height?t.height/r.height:1;return void((Math.abs(i)+Math.abs(a)>.5||Math.abs(l-1)+Math.abs(c-1)>.01)&&s.animate([{transformOrigin:"0 0",transform:`translate(${i}px, ${a}px) scale(${l}, ${c})`},{transformOrigin:"0 0",transform:"none"}],{duration:e,easing:n}))}"op"===i.type?i.args.forEach(r):s&&s.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:e,easing:n})};r(this.tree)}}function Ms(t,e,n){if(!e)return null;if("object"==typeof e&&1===e.nodeType)return e;if("undefined"==typeof document||!t.insertAdjacentElement)return null;const r=document.createElement("span");return r.className=`${n}-sr-only`,r.setAttribute("aria-live","polite"),r.setAttribute("aria-atomic","true"),t.insertAdjacentElement("afterend",r),r}function ks(t){return!!t&&("always"===t||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}const As=new RegExp("(\\d+)","g");function Es(t,{delimiters:e=["$$","$","\\[","\\("]}={}){const n=[];let r="",i=0;const s=String(t),o=t=>0===t||"\n"===s[t-1],a=(t,e,r)=>(n.push({source:t,display:e,raw:r,start:i,end:i+r.length}),`${n.length-1}`);for(;i<s.length;){if(o(i)){const t=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(s.slice(i));if(t){const e=t[2],n=new RegExp(`\\n {0,3}${"`"===e[0]?"`":"~"}{${e.length},}[ \\t]*(?=\\n|$)`),o=s.slice(i+t[0].length),l=n.exec(`\n${o}`),c=l?o.slice(0,Math.max(0,l.index-1)):o,u=t[0].length+(l?l.index-1+l[0].length:o.length),h=s.slice(i,i+u);"math"===t[3].trim()?r+=a(c,!0,h):r+=h,i+=u;continue}}const t=s[i];if("`"===t){const t=/^`+/.exec(s.slice(i))[0],e=s.indexOf(t,i+t.length);if(e>-1){r+=s.slice(i,e+t.length),i=e+t.length;continue}r+=t,i+=t.length;continue}if("\\"===t){const t=s.slice(i,i+2),n="\\["===t?"\\]":"\\("===t?"\\)":null;if(n&&e.includes(t)){const e=s.indexOf(n,i+2);if(e>-1){r+=a(s.slice(i+2,e),"\\["===t,s.slice(i,e+2)),i=e+2;continue}}r+=t,i+=2;continue}if("$"===t)if("$"===s[i+1]&&e.includes("$$")){const t=s.indexOf("$$",i+2);if(t>-1){r+=a(s.slice(i+2,t),!0,s.slice(i,t+2)),i=t+2;continue}}else if(e.includes("$")&&s[i+1]&&!/\s/.test(s[i+1])){const t=Ns(s,i+1);if(t>-1){r+=a(s.slice(i+1,t),!1,s.slice(i,t+1)),i=t+1;continue}}r+=t,i++}return{text:r,math:n}}function Ns(t,e){for(let n=e;n<t.length;n++){const e=t[n];if("\\"!==e){if("`"===e)return-1;if("\n"===e&&/^\n[ \t]*\n/.test(t.slice(n)))return-1;if("$"===e&&!/\s/.test(t[n-1])&&!/\d/.test(t[n+1]??"")&&"$"!==t[n+1])return n}else n++}return-1}const Os=t=>String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),_s=/^\s*([A-Za-z\u0370-\u03ff](?:_\{?\w+\}?)?)\s*=\s*([^=<>≤≥]+)$/;function Ss(t,e,n,r){const{text:i,math:s}=Es(t,e),o=n?n.definitions(r):new Map,a=t=>n?n.textOf(t):t.text,l={...e.scope??{}},c={},u=new Map,h=new Set,p=[],m=()=>{for(const t of Object.keys(c))delete c[t];Object.assign(c,l);for(const t of o.keys())delete c[t];let t=[...o.values()];for(;t.length;){const e=t.filter(t=>{try{const e=li(a(t),c);if("number"==typeof e.value||"bigint"==typeof e.value||Array.isArray(e.value))return c[t.name]=e.exact?e.text:e.value,!1}catch{}return!0});if(e.length===t.length)break;t=e}const e={},n=f({});for(const t of o.keys()){const r=n(t);if(r)try{e[t]=A(ps(r,e=>e===t?null:n(e)).tree)}catch{}}c[os]=e},f=t=>{const e=new Map;return n=>{const r=o.get(n);if(!r)return null;if(!e.has(n)){let i=null;try{i=is(a(r),t)}catch{}e.set(n,i)}return e.get(n)}};m();const d=s.map((t,n)=>{const{source:r,display:i}=t,s=i?"mv-md-display":"mv-md-math",d=(t,e="")=>`<span class="${s}${e}" data-mv-md="${n}">${t}</span>`;try{const s={...e.math,display:i,blocks:e.blocks,scope:c},g=function(t){let e=t.trim();const n=e.startsWith("_");n&&(e=e.slice(1).trimStart());let r=e.indexOf(":="),i=2;r<0&&n&&(r=e.search(/(?<![<>!≤≥=])=(?!=)/),i=1);const s=n?{error:"a hidden $_…$ saves a variable: $_A := 2+2$"}:null;if(r<=0)return s;const o=e.slice(0,r).trim(),a=e.slice(r+i).trim();let l=null;try{l=/\{\{/.test(o)?null:ls(is(o))}catch{}return null!==l&&a?{hidden:n,lhs:o,name:l,rhs:a,input:ds(a)}:s}(r);if(g&&g.error)throw new Error(g.error);if(g){const{name:e,input:r,hidden:i}=g,l=r?{name:e,text:r.default,input:r,key:`input:${JSON.stringify(r)}`}:{name:e,text:g.rhs,input:null,key:`expr:${g.rhs}`,start:t.start,end:t.end};let c="";if(r){const t=function(t,e){const{input:n,name:r}=t,i=`class="mv-md-input mv-md-${n.kind}" data-mv-var="${Os(r)}" aria-label="${Os(r)}"`;if("dropdown"===n.kind)return`<select ${i}>${n.options.map(t=>`<option value="${Os(t)}"${t===e?" selected":""}>${Os(t)}</option>`).join("")}</select>`;return"slider"===n.kind?`<input type="range" ${i} min="${n.min}" max="${n.max}" step="${n.step}" value="${Os(e)}"><output class="mv-md-output" data-mv-out="${Os(r)}">${Os(e)}</output>`:`<input type="text" ${i} value="${Os(e)}" size="${Math.max(4,e.length+1)}" spellcheck="false" autocomplete="off">`}(l,a(l));c=i?t:`${ss(g.lhs,s)}<span class="mv-md-assign" aria-hidden="true">≔</span>${t}`,h.add(n)}else{const t=ps(is(g.rhs,s),f(s)).tree;if(!i){const e=ts({type:"op",op:"=",args:[cs(is(g.lhs)),void 0===t.id?t:cs(t)]});p[n]=e,c=function(t){return t.replace('<span class="mv-rel">=</span>','<span class="mv-rel mv-rel-def">≔</span>').replace(/(aria-label="[^"]*?) equals /,"$1 is defined as ").replace("<mo>=</mo>","<mo>≔</mo>")}(ss(e,s))}}return o.delete(e),o.set(e,l),u.set(e,l),m(),i&&!r?"":d(c,r?" mv-md-input-def":"")}const{tree:b,changed:$}=ps(is(r,s),f(s));$&&ts(b),p[n]=b;const y=ss(b,s);return!$&&!1!==e.define&&function(t,e,n){const r=_s.exec(t);if(!r||/\{\{/.test(r[2]))return!1;const i=r[1].replace(/[{}]/g,"");if(n.has(i))return!1;try{const t=li(r[2],e);if("number"==typeof t.value||"bigint"==typeof t.value||Array.isArray(t.value))return e[i]=t.exact?t.text:t.value,!0}catch{}return!1}(r,l,o)&&m(),d(y)}catch(e){return`<span class="mv-md-error" data-mv-md="${n}" title="${Os(e.message)}"><code>${Os(t.raw)}</code></span>`}});return{text:i,math:s,drawn:d,defs:u,inputs:h,trees:p}}const Is=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,qs=t=>Is.test(t.trim())?Os(t.trim()):"#";function Ls(t,e,n){const r=[],i=t=>(r.push(t),`${r.length-1}`);let s=t;return s=s.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(t,e,r)=>i(`<code>${Os(n(r.trim()))}</code>`)),s=s.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(t,e)=>i(Os(e))),s=s.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(t,e)=>i(`<a href="${qs(e)}">${Os(e)}</a>`)),e.html&&(s=s.replace(/<\/?[A-Za-z][^>]*>/g,t=>i(t))),s=s.replace(/!\[([^\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(t,e,n,r)=>i(`<img src="${qs(n)}" alt="${Os(e)}"${r?` title="${Os(r)}"`:""}>`)),s=s.replace(/\[([^\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(t,r,s,o)=>i(`<a href="${qs(s)}"${o?` title="${Os(o)}"`:""}>${Ls(r,e,n)}</a>`)),s=Os(s),s=s.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),s=s.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),s=s.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),s=s.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),s=s.replace(/( {2,}|\\)\n/g,"<br>\n"),s.replace(/(\d+)/g,(t,e)=>r[Number(e)])}const Cs=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,Ts=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,zs=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/;function js(t,e,n){const r=[];let i=0;const s=t=>Ls(t,e,n);for(;i<t.length;){const o=t[i];if(!o.trim()){i++;continue}const a=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(o);if(a){const e=[];for(i++;i<t.length&&!new RegExp(`^ {0,3}${"`"===a[1][0]?"`":"~"}{${a[1].length},}\\s*$`).test(t[i]);)e.push(t[i++]);i++;const s=a[2]?` class="language-${Os(a[2])}"`:"";r.push(`<pre><code${s}>${Os(n(e.join("\n")))}</code></pre>`);continue}const l=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/.exec(o);if(l){r.push(`<h${l[1].length}>${s(l[2])}</h${l[1].length}>`),i++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(o)){r.push("<hr>"),i++;continue}if(/^ {0,3}>/.test(o)){const s=[];for(;i<t.length&&t[i].trim()&&(/^ {0,3}>/.test(t[i])||s.length);)s.push(t[i].replace(/^ {0,3}> ?/,"")),i++;r.push(`<blockquote>\n${js(s,e,n)}\n</blockquote>`);continue}const c=Ts.exec(o);if(c){const s=/\d/.test(c[2]),o=s?parseInt(c[2],10):1,a=[];let l=!1;for(;i<t.length;){const e=Ts.exec(t[i]);if(!e||/\d/.test(e[2])!==s)break;const n=e[0].length,r=[t[i].slice(n)];for(i++;i<t.length;){const e=t[i];if(!e.trim()){const e=t[i+1];if(void 0!==e&&e.startsWith(" ".repeat(Math.min(n,4)))&&e.trim()){r.push(""),l=!0,i++;continue}void 0!==e&&Ts.test(e)&&(l=!0);break}if(e.startsWith(" ".repeat(Math.min(n,4))))r.push(e.slice(Math.min(n,4)));else{if(Ts.test(e)||Cs.test(e))break;r.push(e)}i++}for(a.push(r);i<t.length&&!t[i].trim()&&void 0!==t[i+1]&&Ts.test(t[i+1]);)i++}const u=s?"ol":"ul",h=a.map(t=>{let r=js(t,e,n);return l||(r=r.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${r}</li>`});r.push(`<${u}${s&&1!==o?` start="${o}"`:""}>\n${h.join("\n")}\n</${u}>`);continue}if(o.includes("|")&&void 0!==t[i+1]&&zs.test(t[i+1])&&t[i+1].includes("-")){const e=t=>t.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(t=>t.trim()),n=e(t[i+1]).map(t=>t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":t.startsWith(":")?"left":""),a=(t,e,r)=>`<${t}${n[r]?` style="text-align:${n[r]}"`:""}>${s(e)}</${t}>`,l=e(o);i+=2;const c=[];for(;i<t.length&&t[i].trim()&&t[i].includes("|");)c.push(e(t[i++]));r.push(`<table>\n<thead><tr>${l.map((t,e)=>a("th",t,e)).join("")}</tr></thead>\n<tbody>\n${c.map(t=>`<tr>${l.map((e,n)=>a("td",t[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(o)){const e=[];for(;i<t.length&&(/^( {4}|\t)/.test(t[i])||!t[i].trim());)e.push(t[i++].replace(/^( {4}|\t)/,""));for(;e.length&&!e[e.length-1].trim();)e.pop();r.push(`<pre><code>${Os(n(e.join("\n")))}</code></pre>`);continue}const u=[];for(;i<t.length&&t[i].trim()&&(!u.length||!Cs.test(t[i])||/^ {0,3}[-=]+\s*$/.test(t[i]));){if(u.length&&/^ {0,3}(=+|-+)\s*$/.test(t[i])){const e="="===t[i].trim()[0]?1:2;r.push(`<h${e}>${s(u.join("\n"))}</h${e}>`),u.length=0,i++;break}u.push(t[i].replace(/^ {0,3}/,"")),i++}u.length&&r.push(`<p>${s(u.join("\n"))}</p>`)}return r.join("\n")}function Rs(t,e={},n=t=>t){return js(String(t).replace(/\r\n?/g,"\n").split("\n"),e,n)}function Fs({text:t,math:e,drawn:n},r){return(r.render?r.render(t):Rs(t,r,t=>t.replace(As,(t,n)=>e[Number(n)].raw))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(t,r)=>e[Number(r)].display&&n[Number(r)]?`<div class="mv-md-block">${n[Number(r)]}</div>`:t).replace(As,(t,e)=>n[Number(e)]).replace(/<p>\s*<\/p>\n?/g,"")}const Ps=new WeakMap,Zs=new Set;function Bs(){for(const t of Zs)t.connected()&&!t.element.isConnected&&t.stop(!0)}function Ws(t){const e=t=>function(t){if(t.length>1e6)throw new Error("The output would be too long");return t}("op"===t.type?function(t,e){const{op:n,args:r}=t,[i,s]=r,a=(t,r)=>u(n,q(t),r)?`(${e(t)})`:e(t),l=()=>r.map(e).join(", "),c=t=>T(n,t)?`(${e(t)})`:e(t);if("*"===n&&I(t))return"-"+e(s);if("+"===n&&I(s))return`${a(i,"left")} ${e(s)}`;if("-"===n&&I(s))return`${a(i,"left")} + ${e(s).slice(1)}`;if("^"===n){const t=a(i,"left");return`${t.startsWith("-")?`(${t})`:t}^${a(s,"right")}`}if(Ds[n])return`${a(i,"left")} ${Ds[n]} ${a(s,"right")}`;if(X[n])return`${n}(${Q(t).map(t=>`[${t.map(e).join(", ")}]`).join(", ")})`;if(Us[n])return Us[n][0]+l()+Us[n][1];if(o(n))return`${D(n)}(${l()})`;switch(n){case"neg":return"-"+c(i);case"pmod":return`${e(i)} (mod ${e(s)})`;case"pm":return"±"+c(i);case"!":return c(i)+"!";case"\\not":return"¬"+c(i);case"sqrt":return`√(${e(i)})`;case"root":{const t="number"===i.type?{3:"∛",4:"∜"}[i.value]:null;return t?`${t}(${e(s)})`:`root(${e(i)}, ${e(s)})`}case"abs":return`|${e(i)}|`;case"floor":return`⌊${e(i)}⌋`;case"ceil":return`⌈${e(i)}⌉`;case"log":return`log_${"op"===i.type?`(${e(i)})`:e(i)}(${e(s)})`;case"loglog":return`ln(ln(${e(i)}))`;case"logloglog":return`ln(ln(ln(${e(i)})))`;case"perm":return`perm(${e(i)}, ${e(s)})`;case"comb":return`comb(${e(i)}, ${e(s)})`;case"_":return`${e(i)}_${e(s)}`;case"?:":return`${e(i)} ? ${e(s)} : ${e(r[2])}`;case"sum":return r.map(e).join(" + ");case"prod":return r.map(e).join(" * ");case"der":{const{n:n,body:r,by:i,variable:s}=U(t),o=n>1?`^${n}`:"";return s?`d${o}${e(r)}/d${e(i)}${o}`:`d${o}/d${e(i)}${o}(${e(r)})`}case"int":return function(t,e){const[n,r,i,s]=t,o=t.length>=2&&W(r)?e(r):O(n)||"x",a=`${e(n)} d${o}`;switch(t.length){case 1:return`∫ ${a}`;case 2:return W(r)?`∫ ${a}`:`∫[${e(r)}] ${a}`;case 3:return W(r)?`∫[${e(i)}] ${a}`:`∫[${e(r)}, ${e(i)}] ${a}`;default:return`∫[${e(i)}, ${e(s)}] ${a}`}}(r,e);case"lim":return function(t,e){const[n,r,i,s]=t;switch(t.length){case 1:return`lim ${e(n)}`;case 2:return`lim[${e(r)}] ${e(n)}`;case 3:return`lim[${e(r)}→${e(i)}] ${e(n)}`;default:{const t=S(s).toLowerCase().startsWith("r")?"⁺":"⁻";return`lim[${e(r)}→${e(i)}${t}] ${e(n)}`}}}(r,e);case"\\sumidx":return Hs("∑",r,e);case"\\prodidx":return Hs("∏",r,e)}return`${n}(${l()})`}(t,e):function(t){const e=t.value;return"symbol"!==t.type?e:_[e]?_[e]:"\\+"===e||"\\-"===e?e[1]:e}(t));return e(t)}const Ds={"+":"+","-":"-","*":"*","/":"/","^":"^",mod:"mod","±":"±","=":"=","===":"===","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","∪":"∪","∩":"∩","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Us={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]};function Hs(t,e,n){const[r,i,s]=e,o="∑"===t?"sum":"prod";return 3===e.length&&"op"===i.type&&"="===i.op?`${o}(${n(r)}, ${n(i)}, ${n(s)})`:2===e.length&&"op"===i.type&&"∈"===i.op?`${o}(${n(r)}, ${n(i)})`:1===e.length?`${t} ${n(r)}`:2===e.length?`${t}[${n(i)}] ${n(r)}`:`${t}[${n(i)}, ${n(s)}] ${n(r)}`}for(const t of[Ds,Us])Object.setPrototypeOf(t,null);var Gs='/*\n * Inline Math stylesheet. Everything is under .mv; colours are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight colour\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }\n.mv-matrix-row { display: contents; }\n.mv-matrix-cell { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; border-top: 0.06em solid currentColor; padding-top: 0.08em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; position: relative; }\n.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n/* Windows high contrast (and other forced colours) drops backgrounds and shadows: outline a highlight instead */\n@media (forced-colors: active) {\n .mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }\n}\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the box editing a part in place (view.editable, or a Markdown textbox variable) */\n.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;\n border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }\n.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }\n/* the live region a view announces steps through ({ announce: true }): read, never seen */\n.mv-sr-only, .mv-sr-math { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */\n.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }\n.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }\n/* while a part is ringed, the whole expression\'s ring steps back so the part is the one that stands out */\n.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }\n@media (forced-colors: active) {\n .mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }\n}\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with maths (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */\n.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }\n.mv-md-assign { margin: 0 0.1em; }\n.mv-md-input { font: inherit; font-size: 0.9em; }\ninput.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }\ninput.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }\ninput.mv-md-slider { vertical-align: middle; }\n.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }\n';const Vs=Gs;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const t=document.createElement("style");t.id="inlinemath-css",t.textContent=Gs,document.head.append(t)}return t.CSS=Vs,t.DEFAULTS=Fi,t.PATHS=xi,t.View=ws,t.createVariables=$s,t.extractMath=Es,t.layout=Di,t.markdownToHTML=function(t,e={}){return Fs(Ss(t,e,e.variables||null),e)},t.nodeAt=Yi,t.numberTree=ts,t.pathOf=Ki,t.render=function(t,e,n={}){return new ws(t,e,n)},t.renderMarkdown=Rs,t.renderMarkdownInto=function(t,e,n={}){const r=void 0===n.variables?ys:n.variables||null;Bs();const i=Ps.get(t);i&&i.stop(i.store!==r);let s=Ss(e,n,r,t);if(t.innerHTML=Fs(s,n),!r)return Ps.delete(t),t;r.own(t,s.defs);let o=t.isConnected;const a=e=>{const i=e.target,s=i&&i.dataset&&i.dataset.mvVar;if(void 0!==s&&t.contains(i)){if("text"===i.type)try{is(i.value,{blocks:n.blocks,scope:{}}),i.removeAttribute("aria-invalid")}catch{return void i.setAttribute("aria-invalid","true")}r.set(s,i.value)}},l=i=>{const o=i.target.closest?.("[data-node]"),a=o&&o.closest("[data-mv-md]");if(!a||!t.contains(a))return;const l=Number(a.dataset.mvMd),c=s.trees[l];if(!c)return;const u=Number(o.dataset.node),h=Ki(c,u)||[];let p=null;for(let t=h.length;t>=0&&!p;t--){const e=Yi(c,h.slice(0,t));e&&void 0!==e.from&&(p={node:e,depth:t})}const m=p&&r.definitions().get(p.node.from);if(m&&m.input&&"textbox"===m.input.kind){i.preventDefault();const e=m.name,s=t.ownerDocument.querySelector(`[data-mv-var="${CSS.escape(e)}"]`),a=n.editable&&n.editable.toText;if(!a)return void(s&&(s.focus(),s.select()));const l=t=>is(t),u=Yi(c,h);return void xs(o,a(hs(u,l)),{label:`Edit ${e}`,parse:t=>is(t,{blocks:n.blocks}),commit:t=>{const n=vs(hs(p.node,l),h.slice(p.depth),t);r.set(e,a(n))}})}const f=m&&s.defs.get(m.name),d=f&&f.key===m.key&&void 0!==f.start?{...s.math[l],start:f.start,end:f.end,raw:e.slice(f.start,f.end)}:s.math[l];t.dispatchEvent(new CustomEvent("inlinemath:select",{bubbles:!0,detail:{index:l,start:d.start,end:d.end,raw:d.raw,source:d.source,id:u,path:h}}))};t.addEventListener("input",a),t.addEventListener("change",a),t.addEventListener("dblclick",l);const c=r.subscribe(i=>{i!==t&&(t.isConnected?(o=!0,Bs(),(()=>{const i=Ss(e,n,r,t);i.drawn.forEach((e,n)=>{if(e===s.drawn[n]||i.inputs.has(n))return;const r=t.querySelector(`[data-mv-md="${n}"]`);r&&(r.outerHTML=e)});for(const e of t.querySelectorAll("[data-mv-var], [data-mv-out]")){const t=i.defs.get(e.dataset.mvVar??e.dataset.mvOut);if(!t)continue;const n=r.textOf(t);void 0!==e.dataset.mvOut?e.textContent=n:e.value!==n&&e!==e.ownerDocument?.activeElement&&(e.value=n)}s=i})()):o&&u(!0))});function u(e){c(),t.removeEventListener("input",a),t.removeEventListener("change",a),t.removeEventListener("dblclick",l),Zs.delete(h),Ps.delete(t),e&&r.own(t,null)}const h={element:t,store:r,stop:u,connected:()=>o};return Zs.add(h),Ps.set(t,h),t},t.select=Qi,t.shouldAnimate=ks,t.signature=Xi,t.toHTML=ss,t.toText=function(t){return rn(t)?"":Ws(nn(t))},t.treeOf=is,t.variables=ys,t}({});