@mathzetta/inlinemath 0.0.0-stage → 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 (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +326 -2
  3. package/dist/cas.external.js +2 -0
  4. package/dist/cas.js +2 -0
  5. package/dist/chunks/calculate-Cz87Lt0N.js +2 -0
  6. package/dist/chunks/draw-Bev17BJJ.js +2 -0
  7. package/dist/chunks/edit-C65xXzo8.js +2 -0
  8. package/dist/chunks/edit-M68aRA5o.js +2 -0
  9. package/dist/chunks/html-BimAqn7x.js +2 -0
  10. package/dist/chunks/html-CupluJSh.js +2 -0
  11. package/dist/chunks/lite-3Fb-OHbt.js +2 -0
  12. package/dist/fonts/GUST-FONT-LICENSE.txt +30 -0
  13. package/dist/fonts/fonts.css +17 -0
  14. package/dist/fonts/lmroman12-italic.woff2 +0 -0
  15. package/dist/fonts/lmroman12-regular.woff2 +0 -0
  16. package/dist/inlinemath-cas.external.global.min.js +2 -0
  17. package/dist/inlinemath-cas.global.min.js +2 -0
  18. package/dist/inlinemath-lite-calc.global.min.js +2 -0
  19. package/dist/inlinemath-lite.external.global.min.js +2 -0
  20. package/dist/inlinemath-lite.global.min.js +2 -0
  21. package/dist/inlinemath.css +158 -0
  22. package/dist/inlinemath.external.global.min.js +2 -0
  23. package/dist/inlinemath.external.js +2 -0
  24. package/dist/inlinemath.global.min.js +2 -0
  25. package/dist/inlinemath.js +2 -0
  26. package/dist/lite-calc.js +2 -0
  27. package/dist/lite.external.js +2 -0
  28. package/dist/lite.js +2 -0
  29. package/dist/markdown.external.js +2 -0
  30. package/dist/markdown.js +2 -0
  31. package/fonts/GUST-FONT-LICENSE.txt +30 -0
  32. package/fonts/fonts.css +17 -0
  33. package/fonts/lmroman12-italic.woff2 +0 -0
  34. package/fonts/lmroman12-regular.woff2 +0 -0
  35. package/inlinemath.css +158 -0
  36. package/package.json +95 -4
  37. package/src/calculator.js +6 -0
  38. package/src/cas.d.ts +3 -0
  39. package/src/cas.js +149 -0
  40. package/src/draw.js +72 -0
  41. package/src/edit.js +96 -0
  42. package/src/glyphs.js +40 -0
  43. package/src/html.js +32 -0
  44. package/src/index.d.ts +3 -0
  45. package/src/index.js +17 -0
  46. package/src/layout.js +649 -0
  47. package/src/lite-calc.d.ts +3 -0
  48. package/src/lite-calc.js +15 -0
  49. package/src/lite.d.ts +3 -0
  50. package/src/lite.js +18 -0
  51. package/src/markdown.d.ts +3 -0
  52. package/src/markdown.js +676 -0
  53. package/src/mathzetta.js +18 -0
  54. package/src/select.js +108 -0
  55. package/src/types.d.ts +204 -0
  56. package/src/variables.js +228 -0
  57. package/src/view.js +382 -0
@@ -0,0 +1,2 @@
1
+ /* Inline Math 0.2.0 — MIT licence; includes mathzetta (and @mathzetta/cas, for the CAS) */
2
+ var InlineMath=function(e){"use strict";const t=-1,n={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt: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(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),pmatrix:r(t),bmatrix:r(t),vmatrix: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,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"?:":10,"?":9,",":5},p=e=>Object.prototype.hasOwnProperty.call(u,e),m=new Set(["^","?:","?","log"]),f=["(","{","["],d=[")","}","]"];function g(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[u])Object.setPrototypeOf(e,null);const b=e=>({type:"number",value:String(e)}),y=e=>({type:"symbol",value:e}),x=(e,t)=>({type:"op",op:e,args:t}),v=['"',"'","`"];function w(e){return g(e,!0)?b(e):v.includes(e[0])?{type:"string",value:e}:y(e)}const $={"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=$[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({...x(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 A(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 N(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>N(n,t,e))}function E(e){let t="";return N(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[$])Object.setPrototypeOf(e,null);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 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 q(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":I(e)?null:e.op}const S=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),z=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!S.has(e.op))&&function(e,t,n){if("mod"===e&&t)return c(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const 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,q(t),n);function L(e,t){const n=q(t),r=n&&a(n)?.prec;return!!r&&("!"===e?r<=a("!").prec:"\\not"===e?r<a("\\not").prec:r<70||Z(t)||"\\not"===n)}function C(e,t,n={}){const r=n.left?"bracket":F(e),i=n.right?"bracket":R(t);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function T(e){return 1===e.length||Boolean(_[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function j(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function R(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&T(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||I(e)?"sign":"/"===t?"frac":a(t)?.group||j(e)?"bracket":P(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?j(e.args[0])?"bracket":R(e.args[0]):["*","sum","prod","perm"].includes(t)?R(e.args[0]):"other"}function F(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&T(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||j(e)||P(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?F(e.args[e.args.length-1]):"other"}function P(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function Z(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&&!z(e,e.args[0],"left")&&Z(e.args[0])}const B=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),W=e=>e.slice(2);function D(e){const t=e.args[1];let n=0,r=e;for(;"op"===r.type&&"der"===r.op&&U(r.args[1],t);)n++,r=r.args[0];return{n:n,body:r,by:t,variable:"symbol"===r.type&&T(r.value)}}const U=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,H=new Set(["<",">","≤","≥","=","≠"]);function G(e){if("op"!==e.type||!H.has(e.op)||2!==e.args.length)return null;const[t,n]=e.args;if("op"!==t.type||!H.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[G(t)??t,{type:"op",op:e.op,args:[t.args[1],n]}]}}for(const e of[_])Object.setPrototypeOf(e,null);const V={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function X(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(V,e.op))return e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args:[e]);if("[]"!==e.op||!e.args.length||!e.args.every(e=>"op"===e.type&&"[]"===e.op))return null;const t=e.args[0].args.length;return!t||!e.args.every(e=>e.args.length===t)||e.args.length<2&&t<2?null:e.args.map(e=>e.args)}function Q(e){return Array.isArray(e)&&e.length>0&&e.every(t=>Array.isArray(t)&&t.length>0&&t.length===e[0].length&&!t.some(Array.isArray))}const J=e=>Array.isArray(e)&&e.length>0&&!e.some(Array.isArray);function Y(e){const t=e,n=t.make??(e=>e),r=t.size??(()=>1),i=e=>`${e.length} by ${e[0].length}`,s=(e,r)=>n(Array.from({length:e},(n,r)=>Array.from({length:e},(e,n)=>r===n?t.one():t.zero())),r);function o(e,r){return e[0].length!==r.length&&t.fail(`a ${i(e)} matrix times a ${i(r)} one`),n(e.map(e=>r[0].map((n,i)=>e.reduce((e,n,s)=>t.add(e,t.mul(n,r[s][i])),t.zero()))),e)}function a(e){const n=e.map(e=>e.slice()),i=n.length,s=n[0].length;let o=t.one(),a=0;for(let e=0;e<s&&a<i;e++){let s=-1;for(let o=a;o<i;o++)t.isZero(n[o][e])||(s<0||r(n[o][e])>r(n[s][e]))&&(s=o);if(s<0){o=t.zero();continue}s!==a&&([n[s],n[a]]=[n[a],n[s]],o=t.sub(t.zero(),o));const l=n[a][e];o=t.mul(o,l),n[a]=n[a].map(e=>t.div(e,l));for(let r=0;r<i;r++){if(r===a||t.isZero(n[r][e]))continue;const i=n[r][e];n[r]=n[r].map((e,r)=>t.sub(e,t.mul(i,n[a][r])))}a++}return a<i&&(o=t.zero()),{M:n,det:o,rank:a}}function l(e){const r=e.length;r!==e[0].length&&t.fail(`a ${i(e)} matrix has no inverse`);const o=s(r),{M:l,rank:c}=a(e.map((e,t)=>[...e,...o[t]]));return(c<r||l.some((e,n)=>t.isZero(e[n])))&&t.fail("the matrix has no inverse (its determinant is 0)"),n(l.map(e=>e.slice(r)),e)}return{identity:s,transpose:e=>n(e[0].map((t,n)=>e.map(e=>e[n])),e),times:o,det:function(e){return e.length!==e[0].length&&t.fail(`a ${i(e)} matrix has no determinant`),a(e).det},inverse:l,power:function(e,n){e.length!==e[0].length&&t.fail(`a ${i(e)} matrix has no powers`);let r=n<0n?l(e):e,a=n<0n?-n:n,c=s(e.length,e);for(;a>0n;)1n&a&&(c=o(c,r)),r=o(r,r),a>>=1n;return c},trace:e=>(e.length!==e[0].length&&t.fail(`a ${i(e)} matrix has no trace`),e.reduce((e,n,r)=>t.add(e,n[r]),t.zero())),dot:(e,n)=>(e.length!==n.length&&t.fail("vectors of different lengths"),e.reduce((e,r,i)=>t.add(e,t.mul(r,n[i])),t.zero())),cross:(e,n)=>(3===e.length&&3===n.length||t.fail("the cross product is for vectors of 3 numbers"),[t.sub(t.mul(e[1],n[2]),t.mul(e[2],n[1])),t.sub(t.mul(e[2],n[0]),t.mul(e[0],n[2])),t.sub(t.mul(e[0],n[1]),t.mul(e[1],n[0]))]),solve:function(e,t){return Q(t)?o(l(e),t):o(l(e),t.map(e=>[e])).map(e=>e[0])},rank:e=>a(e).rank,rref:e=>n(a(e).M,e),timesVector:(e,t)=>o(e,t.map(e=>[e])).map(e=>e[0]),vectorTimes:(e,t)=>o([e],t)[0]}}function K(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 te(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=ee(n,e,i);s?(r+=t.get(e.slice(i,i+s)),i+=s):r+=e[i++]}return r}}function ee(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 te(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),ne(e)]);return t.delete(e),t}function ne(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 re="({[",ie=")}]";function se(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 oe(e,t){const n=[];let r=0,i=0;for(let s=0;s<e.length;s++)re.includes(e[s])?r++:ie.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 ae(e,t,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(re.includes(e[n]))r++;else if(ie.includes(e[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(e)))return n;return-1}function le(e,t){let n=0;for(let r=t;r<e.length;r++)if(re.includes(e[r]))n++;else if(ie.includes(e[r])&&--n<0)return r;return e.length}function ce(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 he(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(re.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 ue(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 pe(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}const me=new Set(["pmatrix","bmatrix","vmatrix"]);function fe(e){const t=e.indexOf("}"),n=e.indexOf("{");if(t<0||n>=0&&n<t)return!1;const 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,", ")+"]"),a=e.slice(i+6+r.length);return me.has(r)?r+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function de(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 ge(e){const{lower:t,upper:n,next:r}=function(e){let t="",n="",r=0;return"_"===e[0]&&([t,r]=de(e,0),"^"===e[r]&&([n,r]=de(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(re.includes(e[n]))t++;else if(ie.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 be(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(ie.includes(n[e])?r--:re.includes(n[e])&&r++,0===r)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function ye(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const xe=/[A-Za-z\u0370-\u03FF]/;function ve(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 we(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function $e(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 Me(e,t){if(re.includes(e[t])){let n=0;for(let r=t;r<e.length;r++)if(re.includes(e[r]))n++;else if(ie.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(re.includes(e[r]))n++;else{if(ie.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 ke=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const Ae="strtktk",Ne="ABCDEFGHIJ",Ee=e=>Ae+[...String(e)].map(e=>Ne[e]).join("");function _e(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 Oe(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 Ie={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[Ie])Object.setPrototypeOf(e,null);const qe="([{",Se=")]}";function ze(e,t){let n=0;for(let r=t;r<e.length;r++)if(qe.includes(e[r]))n++;else if(Se.includes(e[r])&&0===--n)return r;return-1}function Le(e){if(!e.trim())return[];const t=[];let n=0,r=0;for(let i=0;i<e.length;i++)qe.includes(e[i])?n++:Se.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 Ce(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=ze(e,s);if(o<0)continue;const a=n(Le(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 Te=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),je=e=>`(${e})`,Re=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const Fe={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(je).join(" & ")})`,OR:e=>e.length&&`(${e.map(je).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 Pe={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"},Ze="strtktk[A-J]+";function Be(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${Ze})\\s*\\|\\|\\s*(${Ze})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${Ze},\\s*${Ze}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const r=ze(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=Ce(e,/(?<![\w.])CAST\s*\(/gi,e=>{const t=1===e.length&&/^(.*)\s+AS\s+(?:REAL|FLOAT|DOUBLE(?:\s+PRECISION)?|NUMERIC|DECIMAL|INTEGER|INT)\s*$/is.exec(e[0]);return t?`(${t[1]})`:null}),e=(e=(e=Ce(e=function(e){for(let t=0;t<50;t++){const t=[...e.matchAll(/\bCASE\s+WHEN\b/gi)];if(!t.length)return e;const n=t[t.length-1].index,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})`,je(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=>Pe[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=ze(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 We={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"},De={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 Ue(e){return e=(e=(e=(e=e.replace(/(?<![\w.])(?:np|numpy)\.random\.random\(\s*\)|(?<![\w.])random\.random\(\s*\)/g,"Math.random()")).replace(/(?<![\w.])(?:np|numpy)\.linalg\.(det|inv)\b/g,"$1")).replace(/(?<![\w.])(?:np|numpy)\.array\s*\(/g,"(")).replace(/(?<![\w.])(?:np|numpy)\.(\w+)/g,(e,t)=>We[t]?`Math.${We[t]}`:De[t]?De[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)=>Ge[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>Ge[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>Ve[t]??He[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 He={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Ge={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},Ve={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},Xe={open:"()",Lopen:"(]",Ropen:"[)"};const Qe=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?Le(t[1]):null},Je=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Ye=e=>Qe(e)??[e],Ke={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]}) ∈ ${Re(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${Re(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(je).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(je).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(Qe);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:Je("[]"),sympy_interval_open:Je("()"),sympy_interval_Lopen:Je("(]"),sympy_interval_Ropen:Je("[)"),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=Ye(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&&Ye(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&&Ye(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:et("sum"),prod:et("prod")};function et(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=Le(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[Fe,Pe,We,De,He,Ge,Ve,Xe,Ke])Object.setPrototypeOf(e,null);const tt=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,nt=e=>e.trim().split(/\s+/).join(String.raw`\s+`),rt=e=>new RegExp(String.raw`(?<![\w.])${nt(e)}(?![\w.])`,"gi"),it=[["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","="]],st="[<>≤≥=≠≈]",ot=[["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 at=K([[" 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 ","→"],["===","=...="]]),lt=K([["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["\\downarrow","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot","*"],["\\times","*"],["×","*"],["·","*"],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],["log2(","log_{2}("],["log3(","log_{3}("],["log4(","log_{4}("],["log5(","log_{5}("],["log6(","log_{6}("],["log7(","log_{7}("],["log8(","log_{8}("],["log9(","log_{9}("],["log10(","log_{10}("],["log_10","log_{10}"],["\\log2(","log_{2}("],["\\log3(","log_{3}("],["\\log4(","log_{4}("],["\\log5(","log_{5}("],["\\log6(","log_{6}("],["\\log7(","log_{7}("],["\\log8(","log_{8}("],["\\log9(","log_{9}("],["\\log10(","log_{10}("],["\\log_10","log_{10}"],["log2{","log_{2}{"],["log3{","log_{3}{"],["log4{","log_{4}{"],["log5{","log_{5}{"],["log6{","log_{6}{"],["log7{","log_{7}{"],["log8{","log_{8}{"],["log9{","log_{9}{"],["log10{","log_{10}{"],["\\log2{","log_{2}{"],["\\log3{","log_{3}{"],["\\log4{","log_{4}{"],["\\log5{","log_{5}{"],["\\log6{","log_{6}{"],["\\log7{","log_{7}{"],["\\log8{","log_{8}{"],["\\log9{","log_{9}{"],["\\log10{","log_{10}{"],["\\log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⊕"," \\xor "],["∞","∞"],["⋅","*"],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0],...function(){const e=[],t=(t,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const e of["","h"]){const 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}()]),ct=[["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 Ce(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>Fe[t[1]]?.(e)||null)}(e)),e=function(e){e=Ce(e,Te("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=Ce(e,Te(Object.keys(Ke).join("|")),(e,t)=>Ke[t[1]](e)||null);for(let t=(e=Ce(e,Te("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=ze(e,n);let i=t;if(Se.includes(e[t-1])){let n=0;for(i=t-1;i>=0;i--)if(Se.includes(e[i]))n++;else if(qe.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)}) ∈ ${Re(e.slice(i,t))})${e.slice(r+1)}`)}return e}(e=Ue(e=Be(e=(e=(e=function(e){for(const[t,n]of Object.entries(Ie))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]?ze(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=ze(e,n),i=e.lastIndexOf("Number(",t);r<0||i<0||ze(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(qe.includes(e[t]))i++;else{if(Se.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(Se.includes(e[t]))i++;else{if(qe.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.])${nt(e)}\s+(${tt})\s+(?:and|to)\s+(${tt})(?:\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+(${tt})\s+to\s+(${tt})`,"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`(${tt})\s+`;t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${tt})\s*(%|\s+percent)?\s+of\s+(${tt})`,"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+(${tt})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${tt})`,"gi"),(e,t,n,r)=>`((${t}) mod (${r}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${tt})\s+divides\s+(${tt})`,"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 ot)t=t.replace(rt(e),` ${n} `);t=t.replace(rt("is not in")," ∉ ").replace(rt("is in")," ∈ ").replace(rt("is an element of")," ∈ ");for(const[e,n]of it)t=t.replace(rt(e),` ${n} `);t=t.replace(rt("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`(${tt})\s*(${st})\s*(${tt})\s+(and|or)\s+(${st})`,"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+(${tt})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${tt})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${tt})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${tt})\s+to\s+the\s+power\s+of\s+(${tt})`,"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`(${tt})\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`(${tt})\s+to\s+the\s+(${tt})(?![\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+)?${nt(e)}\s+of\s+(${tt})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${tt})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${tt})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${tt})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${tt})`,"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+)${nt(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",at],["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=ae(e,n+2,"then");if(r<0)return e;const i=e.slice(n+2,r),s=ae(e,r+4,"else"),o=le(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=he(e);for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=ce(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",lt],["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)+ke(e.slice(r,t+1),"x",i)+e.slice(t+1+i),t=r}return e}(e=(e=he(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&&xe.test(e[t-1]);let r,i=null,s=t;if(e.startsWith("frac{",t)){const n=ve(e,t+4),r=n&&ve(e,n[1]);i=r&&$e(n[0],r[0]),i&&(s=r[1])}else if("d"===e[t]&&!n){let[n,r]=we(e,t+1),o="";if(xe.test(e[r]??"")&&"/"===e[r+1]&&(o=e[r++]),"/"===e[r]&&"d"===e[r+1]&&xe.test(e[r+2]??"")){const t=e[r+2],[,a]=we(e,r+3);i={n:n,of:o,by:t},s=a}}if(i){if(i.of)r=ke(i.of,i.by,i.n);else{const[t,n]=Me(e,s);if(!t)continue;r=ke(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=fe(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"+pe(e.slice(t+1)):"sqrt"===r(4)&&(e=e.slice(0,t-4)+"sqrt"+pe(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+ue(e.slice(t));else if("t"===n)"\\int"===i(3)&&(e=e.slice(0,t-3)+ge(e.slice(t+1)));else if("m"===n)"\\binom"===i(5)&&(e=e.slice(0,t-5)+"\\binom"+ye(e.slice(t+1)));else if("d"===n&&"dd"===i(1)&&"("===e[t+2]){const n=be(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 ht(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=Ee(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=_e(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=_e(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=ut(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=Ee(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 ct){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 ut(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 pt=Object.keys(u).filter(e=>100===u[e]&&/^[a-z]{2,}$/.test(e)),mt=["frac"],ft=[...Object.keys(_),"pi","tau","inf","infinity","exp"],dt="\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+/),gt=new Set([...ft,...dt,"true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),bt=/^[a-zA-ZͰ-Ͽ]$/,yt=new Set(["f","g","h","u","v","F","G","H"]),xt=e=>pt.includes(e)||mt.includes(e),vt=[...pt,...mt,...ft].sort((e,t)=>t.length-e.length),wt=[...pt,...mt,"pi"].sort((e,t)=>t.length-e.length);function $t(e,t=vt){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 Mt(e){if(xt(e))return!0;const t=$t(e,wt);return t.length>1&&xt(t[t.length-1])&&!gt.has(e)}function kt(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=>bt.test(e)))||1===e.length||gt.has(e)||xt(e))return[e];var r;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return At($t(e),n);if(e.length<=2)return[...e];const i=At($t(e,wt),n),s=i.findIndex(e=>e.length>1);if(s<0)return[e];if("pi"===i[s]&&!i.some(e=>pt.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 At(e,t){const n=e[e.length-1];return t||!pt.includes(n)?e:[...e.slice(0,-1),...n]}const Nt="§",Et=/[A-Za-zͰ-Ͽ′]/,_t=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function Ot(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=e=>{r&&(_t(r)?n.push(...function(e,t,n){if((e=>new RegExp(`^${Ae}[${Ne}]+$`).test(e))(e))return[e];if(f.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 yt.has(e)?[s+e]:[e];if(p(e))return[e];const n=kt(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 kt(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===Nt){i(o);const r=e.indexOf(Nt,t+1),a=e.slice(t,r+1);n.push(f.includes(e[r+1])?s+a:a),t=r;continue}if(_t(r)&&/[0-9]/.test(o)&&p(r+o)){const{op:i,end:s}=It(e,t,r+o);n.push(i),r="",t=s;continue}if(Et.test(o)&&"′"!==o&&g(r)&&(n.push(r),r=""),Et.test(o)&&(""===r?"′"!==o:_t(r)))r+=o;else if(/[0-9]/.test(o)&&_t(r)&&!Mt(r))r+=o;else if(_t(r)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))r&&n.push(...qt(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(p(r+o)){const{op:i,end:s}=It(e,t,r+o);n.push(i),r="",t=s;continue}if(p(o)){i(o);const{op:r,end:s}=It(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 It(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 qt(e,t){if(!f.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[p(t)?t:s+t]}return g(e)?[e,"*"]:p(e)||xt(e)||g(e[0])?[e]:[s+e]}const St=70,zt=100,Lt="%mod",Ct=e=>f.includes(e),Tt=e=>d.includes(e),jt=e=>o(e)||u[e]===zt&&"_"!==e,Rt=new Set(["\\comb","\\perm","comb","perm"]),Ft={frac:"/","\\binom":"\\binom"},Pt={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Zt{constructor(e){this.tokens=e,this.pos=0,this.out=[],this.absDepth=0,this.frames=[]}peek(e=0){return this.tokens[this.pos+e]}next(){return this.tokens[this.pos++]}emit(...e){this.out.push(...e)}parseAll(){if(!this.tokens.length)throw new Error("Empty expression");this.parseExpression(0);const e=this.peek();if(void 0!==e)throw new Error(Tt(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){for(this.parseOperand();;){const n=this.peek();if(void 0===n||Tt(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===Lt)return{lbp:St,run:()=>{this.next(),this.parseExpression(St),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:zt,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(Rt.has(e))return{lbp:zt,run:()=>{this.next(),this.parseExpression(zt),this.emit(e)}};const n=u[e];if(void 0!==n&&!jt(e)&&"\\not"!==e&&!(e in Ft)){const t=m.has(e)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:t&&!jt(e)?71:St,run:()=>{this.parseExpression(St),this.emit("*")}}}startsOperand(e){return void 0===e||Tt(e)||"|"===e?"|"===e:e!==Lt&&(!!(Ct(e)||jt(e)||e in Ft)||!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(St,!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(Ct(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Tt(n))||Ct(t)&&Tt(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 Ft)return this.parseScript(),this.parseScript(),this.emit(Ft[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(jt(e))return this.functionCall(e);if(Tt(e)||p(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!g(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(Tt(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();Tt(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(Ct(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(jt(e))return this.parseOperand();if(this.next(),void 0===e||Tt(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&&!Ct(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(Ct(e))return this.next(),this.bracket(e);this.parseExpression(St,!0)}}function Bt(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(yt.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:g(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)||Ct(r)||Tt(r)||"_"===r||o(r)||g(r)?n.push(r):n.push(...Wt(r,t));return n}function Wt(e,t){const n=e=>Bt(Ot(e,t),t);let r=0;for(;r<e.length&&g(e.slice(0,r+1));)r++;if(0===r){if("%"===e[0])return[Lt,...n(e.slice(1))];const r=e.indexOf("%");return r>0&&r<e.length-1?[...Wt(e.slice(0,r),t),Lt,...n(e.slice(r+1))]:[e]}const i=e.slice(r);return"%"===i[0]?1===i.length?[e]:[e.slice(0,r),Lt,...n(i.slice(1))]:[e.slice(0,r),...n(i)]}for(const e of[Ft,Pt])Object.setPrototypeOf(e,null);const Dt=new Set(["()","[]","{}","(]","[)"]),Ut={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠="},Ht=new Set(["round","fixed","der"]),Gt=e=>o(e)||100===u[e];function Vt(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(Dt.has(l)){const t=i(r(l));if(!t.length&&!Gt(e[c+1]))throw new Error("Empty brackets");return void n.push(x(l,t))}const h=Ut[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(Gt(l)&&Dt.has(e[c-1])&&n[n.length-1]?.op===e[c-1])p=n.pop().args;else{let e=u.arity===t||Ht.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 x("root",n);break;case"round":if(1===n.length)return x("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 x("sum"===e?"\\sumidx":"\\prodidx",n);break}case"det":if(n.length>1&&n.every(e=>"op"===e.type&&"[]"===e.op))return x("det",[x("[]",n)]);break;case"fixed":if(1===n.length)return x("fixed",[n[0],b(2)]);break;case"der":if(1===n.length)return x("der",[n[0],y("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=x("der",[i,t]);return i}(n);break;case"log":if("symbol"===n[0].type&&"e"===n[0].value)return x("ln",[n[1]]);break;case"lim":return x("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?{"\\+":"r","\\-":"l"}[e.args[1].value]:void 0,[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],y(t(i))]}return 3===e.length&&t(i)?[n,r,i.args[0],y(t(i))]:e}(n));case"\\:if":if(2===n.length||3===n.length)return x("?:",[n[0],n[1],n[2]??y("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),x(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[Ut])Object.setPrototypeOf(e,null);const Xt=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Qt=e=>/^[a-z][a-z0-9]*$/.test(e)&&p(e);function Jt(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=oe(e.slice(t+13,n),"\\\\").map(e=>oe(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=se(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 Yt=null;function Kt(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=`${Nt}${r.size}${Nt}`;return r.set(t,e),t};e=e.replace(Xt,(e,t)=>Qt(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}}(Jt(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?Yt:t.blocks;return ht(e,{evaluate:n?e=>n(e,t.scope):void 0})})(o,{blocks:t.blocks,scope:t.scope}),p=e=>Oe(Oe(e,h),a);n.mode=l,n.cleaned=p([c])[0],n.cleanSteps=u,n.tokens=Ot(c,l),n.rawPostfix=p(function(e,t="plain"){return new Zt(Bt(e,t)).parseAll().map(e=>Pt[e]??e)}(n.tokens,l));const m=k(Vt(n.rawPostfix));n.postfix=m,n.tree=M(m)}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function en(e,t={}){const n=Kt(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 tn=(e,t)=>"string"==typeof e?en(e,t):A(e),nn=Y({add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>e/t,isZero:e=>Math.abs(e)<1e-12,zero:()=>0,one:()=>1,size:Math.abs,fail:e=>{throw new Error(e)}}),rn=e=>Q(e)&&(e.length>1||e[0].length>1),sn=e=>J(e)&&!rn(e),on=e=>{const t=(n,r)=>{if(Array.isArray(n)&&Array.isArray(r)){if(n.length!==r.length)throw new Error("Lists of different lengths");return n.map((e,n)=>t(e,r[n]))}return Array.isArray(n)?n.map(e=>t(e,r)):Array.isArray(r)?r.map(e=>t(n,e)):e(n,r)};return t},an=(e,t)=>rn(e)&&rn(t)?nn.times(e,t):rn(e)&&sn(t)?nn.timesVector(e,t):sn(e)&&rn(t)?nn.vectorTimes(e,t):on((e,t)=>e*t)(e,t),ln=e=>t=>e(t.length>1&&t.every(sn)?t:t[0]),cn={det:ln(nn.det),inv:ln(nn.inverse),inverse:ln(nn.inverse),transpose:ln(nn.transpose),trace:ln(nn.trace),tr:ln(nn.trace),rank:ln(nn.rank),rref:ln(nn.rref),identity:([e])=>nn.identity(e),dot:([e,t])=>nn.dot(e,t),cross:([e,t])=>nn.cross(e,t),linsolve:([e,t])=>nn.solve(e,t)},hn=(e,t)=>e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args.map(e=>xn(e,t)):[xn(e,t)]),un={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},pn=(e,t)=>t?pn(t,e%t):Math.abs(e),mn={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,det:e=>nn.det(e),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},fn={"+":(e,t)=>Array.isArray(e)||Array.isArray(t)?on((e,t)=>e+t)(e,t):e+t,"-":(e,t)=>Array.isArray(e)||Array.isArray(t)?on((e,t)=>e-t)(e,t):e-t,"*":an,"/":(e,t)=>rn(t)?an(e,nn.inverse(t)):Array.isArray(e)||Array.isArray(t)?on((e,t)=>e/t)(e,t):e/t,"^":(e,t)=>{if(!rn(e))return Array.isArray(e)?on((e,t)=>e**t)(e,t):e**t;if(!Number.isInteger(t))throw new Error("A matrix to a power that is not a whole number");return nn.power(e,BigInt(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)},dn={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(pn),"()":e=>e,"[]":e=>e,"{}":e=>e};const gn=5e6;let bn=0,yn=0;function xn(e,t){if(++bn>gn)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(un,e.value))return un[e.value];throw new Error(`No value for '${e.value}'`)}const n=G(e);if(n)return xn(n,t);const{op:r,args:i}=e;if("?:"===r)return xn(i[0],t)?xn(i[1],t):xn(i[2],t);if("∈"===r||"∉"===r)return function(e,t){const[n,r]=e.args,i=xn(n,t);let s;if("symbol"===r.type&&vn[r.value])return s=vn[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=>xn(e,t)),o="["===r.op[0]?i>=e:i>e,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const e=xn(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=xn(n,t),l=xn(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=xn(e,{...t,[o]:n});c="\\sumidx"===r?c+i:c*i}return c}if("pmod"===r){const[e,n]=i,r=xn(n,t);if("op"===e.type&&["≡","="].includes(e.op)){const[n,i]=e.args.map(e=>xn(e,t));return(n-i)%r===0}return xn(e,t)%r}if("pmatrix"===r||"bmatrix"===r)return hn(e,t);if("vmatrix"===r)return nn.det(hn(e,t));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=xn(i[0],t);if(rn(e))return nn.transpose(e)}const s=i.map(e=>xn(e,t));if(r.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(cn,r.slice(2)))return cn[r.slice(2)](s);if(mn[r]&&1===s.length)return mn[r](s[0]);if(fn[r]&&2===s.length)return fn[r](s[0],s[1]);if(dn[r])return dn[r](s);throw new Error(`Can't evaluate '${r}'`)}const vn={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":e=>Number.isInteger(e)&&e>0,"ℚ":Number.isFinite,"ℂ":e=>"number"==typeof e&&!Number.isNaN(e)};for(const e of[un,mn,fn,dn,vn,cn])Object.setPrototypeOf(e,null);class wn extends Error{}class $n extends Error{}const Mn={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6};let kn=0,An=0;const Nn=e=>e<0n?-e:e,En=e=>0n===e?0:Nn(e).toString(2).length;function _n(e,t){for(e=Nn(e),t=Nn(t);t;)[e,t]=[t,e%t];return e}function On(e,t=1n){if(0n===t)throw new wn("division by zero");t<0n&&(e=-e,t=-t);const n=_n(e,t)||1n;return{n:e/n,d:t/n}}const In=On(0n),qn=On(1n),Sn=(e,t)=>On(e.n*t.d+t.n*e.d,e.d*t.d),zn=(e,t)=>On(e.n*t.n,e.d*t.d),Ln=(e,t)=>On(e.n*t.d,e.d*t.n),Cn=e=>({n:-e.n,d:e.d}),Tn=(e,t)=>{const n=e.n*t.d-t.n*e.d;return n<0n?-1:n>0n?1:0},jn=e=>{const t=e.n/e.d;return e.n<0n&&t*e.d!==e.n?t-1n:t};function Rn(e){const t=En(e.n),n=En(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 Fn(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 $n(`'${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=Sn(On(BigInt(o||"0")),On(i-r,(10n**BigInt(e)-1n)*10n**BigInt(n.length)))}else l=On(BigInt(o+a||"0"),10n**BigInt(a.length));return i&&(l=i>0?zn(l,On(10n**BigInt(i))):Ln(l,On(10n**BigInt(-i)))),n<0n?Cn(l):l}function Pn(e,t=0,n=0,r=null){return 0n===e.n?{kind:"x",c:In,pi:0,e:0,root:null}:{kind:"x",c:e,pi:t,e:n,root:r}}const Zn=(e,t=1n)=>Pn(On(BigInt(e),BigInt(t))),Bn=Pn(qn,1),Wn=Pn(qn,0,1),Dn=e=>null!==e&&"object"==typeof e&&"x"===e.kind,Un=e=>Dn(e)&&!e.pi&&!e.e&&!e.root,Hn=e=>Dn(e)?0n===e.c.n:0===e,Gn=e=>Un(e)&&1n===e.c.d?e.c.n:null,Vn=(e,t)=>Object.assign(e,{group:t}),Xn=e=>({kind:"s",text:e});function Qn(e,t){return e&&t?e.n===t.n&&e.r===t.r:e===t}const Jn=(e,t)=>0===Tn(e.c,t.c)&&e.pi===t.pi&&e.e===t.e&&Qn(e.root,t.root);function Yn(e){if("number"==typeof e)return e;if(Dn(e)){let t=Rn(e.c);return e.pi&&(t*=Math.PI**e.pi),e.e&&(t*=Math.E**e.e),e.root&&(t*=Rn(On(e.root.r))**(1/e.root.n)),t}if("boolean"==typeof e)return e?1:0;throw new $n("not a number")}function Kn(e,...t){if(Number.isNaN(e))throw new wn("undefined");if(!Number.isFinite(e)&&t.every(Number.isFinite))throw new $n("too large to calculate");return e}const er=e=>"boolean"==typeof e?e:Dn(e)?0n!==e.c.n:"number"==typeof e?0!==e:Boolean(e);function tr(e){if("bigint"==typeof e)return Pn(On(e));if("number"==typeof e)return Number.isFinite(e)?Pn(Number.isInteger(e)&&Math.abs(e)<=Number.MAX_SAFE_INTEGER?On(BigInt(e)):Fn(String(e))):e;if("boolean"==typeof e)return e;if("string"==typeof e)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(e.trim())?Pn(Fn(e)):Gr(en(e),{});if(Array.isArray(e))return!e.group&&Q(e)?Vn(e.map(e=>Vn(e.map(tr),"[]")),"[]"):Vn(e.map(tr),e.group||"()");if(Dn(e)||"function"==typeof e)return e;throw new $n(`can't use ${typeof e} as a value`)}function nr(e){return Array.isArray(e)?e.map(nr):e&&"s"===e.kind?e.text:"boolean"==typeof e?e:Yn(e)}function rr(e,t){if(e<2n)return e;const n=BigInt(t);let r=1n<<BigInt(Math.ceil(En(e)/t));for(;;){const t=((n-1n)*r+e/r**(n-1n))/n;if(t>=r)return r;r=t}}function ir(e,t,n,r=0,i=0){if(0n===n)return Pn(In);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=rr(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=rr(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?Pn(zn(e,On(s*o.r)),r,i):Pn(zn(e,On(s)),r,i,o)}function sr(e,t){const n=zn(e.c,t.c);if(En(n.n)+En(n.d)>Mn.bits)return null;const r=e.pi+t.pi,i=e.e+t.e;if(!e.root||!t.root)return Pn(n,r,i,e.root||t.root);const s=qr(e.root.n,t.root.n);if(s>Mn.rootIndex)return null;const o=e.root.r**BigInt(s/e.root.n)*t.root.r**BigInt(s/t.root.n);return En(o)>4e3?null:ir(n,s,o,r,i)}function or(e){if(0n===e.c.n)throw new wn("division by zero");const t=Pn(Ln(qn,e.c),-e.pi,-e.e);if(!e.root)return t;const{n:n,r:r}=e.root;return sr(t,ir(On(1n,r),n,r**BigInt(n-1)))}function ar(e,t){if(0n===t){if(0n===e.c.n)throw new wn("0^0 is undefined");return Pn(qn)}if(t<0n){const n=or(e);return n&&ar(n,-t)}if((En(e.c.n)+En(e.c.d)+(e.root?En(e.root.r):0))*Number(t)>Mn.bits||t>100000n)return null;const n=On(e.c.n**t,e.c.d**t),r=Number(t);if(!e.root)return Pn(n,e.pi*r,e.e*r);const{n:i,r:s}=e.root,o=s**(t/BigInt(i));return ir(zn(n,On(o)),i,s**(t%BigInt(i))||1n,e.pi*r,e.e*r)}function lr(e,t,n){if(!Un(e)||n>1000n)return null;const r=ar(e,t);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new wn("not a real number");o=!0,i=-i}const a=function(e,t){const n=e.n*e.d**BigInt(t-1);return En(n)>4e3?null:ir(On(1n,e.d),t,n)}({n:i,d:s},Number(n));return a?o?Pn(Cn(a.c),a.pi,a.e,a.root):a:null}function cr(e){return t=>Array.isArray(t)?Vn(t.map(t=>cr(e)(t)),t.group):e(t)}function hr(e){const t=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new wn("lists of different lengths");return Vn(n.map((e,n)=>t(e,r[n])),n.group)}return i?Vn(n.map(e=>t(e,r)),n.group):s?Vn(r.map(e=>t(n,e)),r.group):e(n,r)};return t}const ur=hr((e,t)=>Dn(e)&&Dn(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||!Qn(e.root,t.root))return null;const n=Sn(e.c,t.c);return En(n.n)+En(n.d)>Mn.bits?null:Pn(n,e.pi,e.e,e.root)}(e,t)||Kn(Yn(e)+Yn(t),Yn(e),Yn(t))),pr=cr(e=>Dn(e)?Pn(Cn(e.c),e.pi,e.e,e.root):-Yn(e)),mr=(e,t)=>ur(e,pr(t)),fr=hr((e,t)=>Dn(e)&&Dn(t)&&sr(e,t)||Kn(Yn(e)*Yn(t),Yn(e),Yn(t))),dr=hr((e,t)=>{if(Hn(t))throw new wn("division by zero");if(Dn(e)&&Dn(t)){const n=or(t),r=n&&sr(e,n);if(r)return r}return Kn(Yn(e)/Yn(t),Yn(e),Yn(t))}),gr=hr((e,t)=>{if(Dn(e)&&Un(t)){const{n:n,d:r}=t.c,i=1n===r?ar(e,n):lr(e,n,r);if(i)return i}const n=Yn(e),r=Yn(t);if(0===n&&0===r)throw new wn("0^0 is undefined");if(0===n&&r<0)throw new wn("division by zero");if(n<0&&!Number.isInteger(r))throw new wn("not a real number");return Kn(n**r,n,r)});function br(e,t){if(Un(e)&&Un(t))return Tn(e.c,t.c);if(Dn(e)&&Dn(t)&&Jn(e,t))return 0;const n=Yn(e),r=Yn(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 yr(e,t){return Array.isArray(e)||Array.isArray(t)?Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>yr(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===br(e,t)}const xr={0:()=>Zn(0),2:()=>Zn(1,2),3:()=>ir(On(1n,2n),2,2n),4:()=>ir(On(1n,2n),2,3n),6:()=>Zn(1)};function vr(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=xr[t];return r?n<0?pr(r()):r():null}const wr=e=>vr(e+6),$r=(e,t)=>Math.abs(e)<1e-15&&Math.abs(t)>1e-6?0:e;function Mr(e,t){const n=function(e){if(Hn(e))return 0;if(!Dn(e)||1!==e.pi||e.e||e.root)return null;const t=zn(e.c,On(12n));return 1n!==t.d?null:Number((t.n%24n+24n)%24n)}(t);if(null!==n){const t=vr(n),r=wr(n);if(t&&r)switch(e){case"sin":return t;case"cos":return r;case"tan":return dr(t,r);case"cot":return dr(r,t);case"sec":return dr(Zn(1),r);case"csc":return dr(Zn(1),t)}}const r=Yn(t),i=$r(Math.sin(r),r),s=$r(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 wn("undefined");return Kn(o)}function kr(e,t){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[e],r=t=>"arcsin"===e?vr(t):"arccos"===e?wr(t):wr(t)&&!Hn(wr(t))?dr(vr(t),wr(t)):null;if(Dn(t))for(let e=n[0];e<=n[1];e++){const n=r(e);if(n&&Dn(n)&&Jn(n,t))return Pn(On(BigInt(e),12n),1)}const i=Yn(t);if("arctan"!==e&&Math.abs(i)>1)throw new wn("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[e](i)}function Ar(e){if(Dn(e)){if(0n===e.c.n)throw new wn("ln 0 is undefined");if(e.c.n<0n)throw new wn("not a real number");if(1n===e.c.n&&1n===e.c.d&&!e.pi&&!e.root)return Zn(e.e)}const t=Yn(e);if(t<=0)throw new wn(0===t?"ln 0 is undefined":"not a real number");return Math.log(t)}function Nr(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*Nr(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 Er(e,t){const n=Gn(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null===n)throw new wn(`${t} needs whole numbers`);return n}const _r=cr(e=>Un(e)?Pn(On(jn(e.c))):tr(Math.floor(Yn(e)))),Or=cr(e=>Un(e)?Pn(On(-jn(Cn(e.c)))):tr(Math.ceil(Yn(e))));function Ir(e,t){const n=Number(Er(t,"round"));if(Un(e)){const t=On(10n**BigInt(Math.abs(n))),r=n>=0?zn(e.c,t):Ln(e.c,t),i=jn(Sn(zn(On(2n),On(Nn(r.n),r.d)),qn))/2n,s=On(r.n<0n?-i:i);return Pn(n>=0?Ln(s,t):zn(s,t))}const r=10**n;return Math.sign(Yn(e))*Math.round(Math.abs(Yn(e))*r)/r}const qr=(e,t)=>e/Sr(e,t)*t,Sr=(e,t)=>t?Sr(t,e%t):e,zr={pi:()=>Bn,"π":()=>Bn,tau:()=>Pn(On(2n),1),"τ":()=>Pn(On(2n),1),e:()=>Wn,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},Lr={abs:e=>Dn(e)?Pn(On(Nn(e.c.n),e.c.d),e.pi,e.e,e.root):Math.abs(Yn(e)),floor:_r,ceil:Or,sqrt:e=>gr(e,Zn(1,2)),ln:cr(Ar),loglog:cr(e=>Ar(Ar(e))),logloglog:cr(e=>Ar(Ar(Ar(e)))),expm1:cr(e=>Hn(e)?Zn(0):Math.expm1(Yn(e))),sinh:cr(e=>Hn(e)?Zn(0):Math.sinh(Yn(e))),cosh:cr(e=>Hn(e)?Zn(1):Math.cosh(Yn(e))),tanh:cr(e=>Hn(e)?Zn(0):Math.tanh(Yn(e))),arcsinh:cr(e=>Hn(e)?Zn(0):Math.asinh(Yn(e))),arccosh:cr(e=>{const t=Yn(e);if(t<1)throw new wn("not a real number");return 1===t?Zn(0):Math.acosh(t)}),arctanh:cr(e=>{const t=Yn(e);if(Math.abs(t)>=1)throw new wn("undefined");return Hn(e)?Zn(0):Math.atanh(t)}),"!":cr(function(e){const t=Gn(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null!==t){if(t<0n)throw new wn("factorial of a negative number");if(t>BigInt(Mn.factorial))throw new $n("too large to calculate");let e=1n;for(let n=2n;n<=t;n++)e*=n;return Pn(On(e))}const n=Yn(e);if(n<0&&Number.isInteger(n))throw new wn("factorial of a negative number");return Kn(Nr(n+1),n)}),neg:pr,pm:e=>Vn([e,pr(e)],"pm"),"\\not":e=>!er(e),det:e=>Br.det(e)};for(const e of["sin","cos","tan","csc","sec","cot"])Lr[e]=cr(t=>Mr(e,t));for(const e of["arcsin","arccos","arctan"])Lr[e]=cr(t=>kr(e,t));const Cr=new Set(["pmatrix","bmatrix"]),Tr=e=>Q(e)&&(Cr.has(e.group)||"[]"===e.group&&e.every(e=>"[]"===e.group)&&(e.length>1||e[0].length>1)),jr=e=>J(e)&&!Tr(e)&&"pm"!==e.group,Rr=Y({add:ur,sub:mr,mul:fr,div:dr,isZero:e=>Dn(e)?0n===e.c.n:Math.abs(Yn(e))<1e-12,zero:()=>Zn(0),one:()=>Zn(1),size:e=>Math.abs(Yn(e)),fail:e=>{throw new wn(e)},make:(e,t)=>Vn(e.map(e=>Vn(e,"[]")),t&&t.group?t.group:"bmatrix")}),Fr=(e,t)=>Vn(e,t&&t.group?t.group:"[]"),Pr=(e,t)=>(...n)=>{const r=n.length>1&&n.every(jr)?Vn(n.map(e=>Vn(e,"[]")),"[]"):n[0];if(n.length>1&&r===n[0])throw new $n(`${e} of more than one thing`);if(!Tr(r))throw new $n(`${e} of something that isn't a matrix`);return t(r)};function Zr(e,t){return Tr(e)&&Tr(t)?Rr.times(e,t):Tr(e)&&jr(t)?Fr(Rr.timesVector(e,t),t):jr(e)&&Tr(t)?Fr(Rr.vectorTimes(e,t),e):fr(e,t)}const Br={det:Pr("det",Rr.det),inv:Pr("inv",Rr.inverse),inverse:Pr("inverse",Rr.inverse),transpose:Pr("transpose",Rr.transpose),trace:Pr("trace",Rr.trace),tr:Pr("tr",Rr.trace),rank:Pr("rank",e=>Zn(Rr.rank(e))),rref:Pr("rref",Rr.rref),identity:e=>{const t=Gn(e);if(null===t||t<1n||t>100n)throw new $n("identity(n) needs a whole number n");return Rr.identity(Number(t))},dot:(e,t)=>{if(!jr(e)||!jr(t))throw new $n("dot of something that isn't a vector");return Rr.dot(e,t)},cross:(e,t)=>{if(!jr(e)||!jr(t))throw new $n("cross of something that isn't a vector");return Fr(Rr.cross(e,t),e)},linsolve:(e,t)=>{if(!Tr(e)||!Tr(t)&&!jr(t))throw new $n("linsolve(A, b) needs a matrix and a vector");return Tr(t)?Rr.solve(e,t):Fr(Rr.solve(e,t),t)}};function Wr(e,t){const n=e.args.map(e=>Vn("op"===e.type&&"[]"===e.op?e.args.map(t):[t(e)],"[]"));if(n.some(e=>e.length!==n[0].length))throw new wn("rows of different lengths");return Vn(n,"vmatrix"===e.op?"bmatrix":e.op)}const Dr={"+":ur,"-":mr,"*":Zr,"/":(e,t)=>Tr(t)?Zr(e,Rr.inverse(t)):dr(e,t),"^":function(e,t){if(!Tr(e))return gr(e,t);const n=Gn(t);if(null===n)throw new $n("a matrix to a power that is not a whole number");return Rr.power(e,n)},"±":(e,t)=>Vn([ur(e,t),mr(e,t)],"pm"),mod:hr(function(e,t){if(Hn(t))throw new wn("division by zero");if(Un(e)&&Un(t))return Pn(Sn(e.c,Cn(zn(t.c,On(jn(Ln(e.c,t.c)))))));const n=Yn(e),r=Yn(t);return Kn((n%r+r)%r)}),log:hr(function(e,t){if(Dn(e)&&Jn(e,Wn))return Ar(t);const n=Yn(e),r=Yn(t);if(n<=0||1===n)throw new wn("not a valid base");if(r<=0)throw new wn(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(Un(e)&&Un(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=ar(e,BigInt(r)),o=ar(t,n);if(s&&o&&Jn(s,o))return Pn(On(BigInt(r),n))}return i}),root:hr((e,t)=>gr(t,dr(Zn(1),e))),atan2:(e,t)=>Math.atan2(Yn(e),Yn(t)),round:Ir,fixed:function(e,t){const n=Number(Er(t,"fixed"));if(n<0)throw new wn("fixed needs 0 or more decimal places");const r=Ir(e,t);if(Un(r)){const e=r.c.n*10n**BigInt(n)/r.c.d,t=(e<0n?-e:e).toString().padStart(n+1,"0");return Xn(`${e<0n?"-":""}${t.slice(0,t.length-n)}${n?"."+t.slice(-n):""}`)}return Xn(Number(Yn(r)).toFixed(n))},perm:function(e,t){const n=Er(e,"permutations"),r=Er(t,"permutations");if(r<0n||r>n)throw new wn("undefined");if(r>BigInt(Mn.terms))throw new $n("too large to calculate");let i=1n;for(let e=n-r+1n;e<=n;e++)i*=e;return Pn(On(i))},comb:function(e,t){const n=Er(e,"combinations");let r=Er(t,"combinations");if(r<0n||r>n)throw new wn("undefined");if(n-r<r&&(r=n-r),r>BigInt(Mn.terms))throw new $n("too large to calculate");let i=1n;for(let e=1n;e<=r;e++)i=i*(n-r+e)/e;return Pn(On(i))},"=":(e,t)=>yr(e,t),"===":(e,t)=>yr(e,t),"≠":(e,t)=>!yr(e,t),"≠=":(e,t)=>!yr(e,t),"≈":(e,t)=>Math.abs(Yn(e)-Yn(t))<=1e-9*Math.max(1,Math.abs(Yn(e)),Math.abs(Yn(t))),"<":(e,t)=>br(e,t)<0,">":(e,t)=>br(e,t)>0,"≤":(e,t)=>br(e,t)<=0,"≥":(e,t)=>br(e,t)>=0,"&":(e,t)=>er(e)&&er(t),"|":(e,t)=>er(e)||er(t),"\\xor":(e,t)=>er(e)!==er(t),"\\nor":(e,t)=>!(er(e)||er(t)),"\\nand":(e,t)=>!(er(e)&&er(t))},Ur={sum:e=>e.reduce((e,t)=>ur(e,t),Zn(0)),prod:e=>e.reduce((e,t)=>fr(e,t),Zn(1)),max:e=>e.reduce((e,t)=>br(t,e)>0?t:e),min:e=>e.reduce((e,t)=>br(t,e)<0?t:e),mean:e=>dr(Ur.sum(e),Zn(e.length)),gcd:e=>Pn(On(e.map(e=>Er(e,"gcd")).reduce(_n)))},Hr=["∈","∉","∪","∩","pmod","random","(]","[)"];function Gr(e,t){if(++kn>Mn.steps)throw new $n("too much to work out");switch(e.type){case"number":return Pn(Fn(e.value));case"string":return Xn(e.value.slice(1,-1));case"symbol":return Vr(e.value,t)}const n=G(e);if(n)return Gr(n,t);const{op:r,args:i}=e,s=e=>Gr(e,t);if("?:"===r)return er(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(e=>"op"!==e.type))return Vr(`${i[0].value}_${i[1].value}`,t);throw new $n("subscript")}if("der"===r)return function(e,t){const[n,r]=e.args,i=Qr(r);if(!i||!Object.prototype.hasOwnProperty.call(t,i))throw new $n(`a derivative needs a value for ${i||"its variable"}`);const s=Yn(t[i]),o=Xr(n,i,t);if(!Number.isFinite(o(s)))throw new wn("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 wn("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 m=p[0][0],f=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<=f&&(f=r,m=p[e][n])}if(Math.abs(p[e][e]-p[e-1][e-1])>=2*f)break}if(!Number.isFinite(m))throw new wn("not differentiable here");return ei(m,f)}(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]=[Qr(r),i,s];else{if(3!==e.length||o(r))throw new $n("an integral needs limits to be calculated");[a,l,c]=[E(n)||"x",r,i]}let h=Yn(Gr(l,t)),u=Yn(Gr(c,t));if(h===u)return Zn(0);let p=1;h>u&&([h,u]=[u,h],p=-1);const m=Xr(n,a,t),{value:f,error:d}=Jr(m,h,u);return ei(p*f,d)}(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]=[Qr(r.args[0]),r.args[1]];else if(2===e.length)[o,a]=[E(n),r];else{if(!(e.length>=3))throw new $n("a limit needs a point");[o,a]=[Qr(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 $n("a limit needs a variable");const c=Gr(a,t),h=Yn(c),u=Xr(n,o,t);let p,m;if(Number.isFinite(h))if(l)({value:p,error:m}=Kr(e=>u(h+l*e*Math.max(1,Math.abs(h)))));else{const e=Kr(e=>u(h+e*Math.max(1,Math.abs(h)))),r=Kr(e=>u(h-e*Math.max(1,Math.abs(h))));if(e.value===r.value)({value:p,error:m}=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 wn("the limit does not exist");p=(e.value+r.value)/2,m=Math.max(e.error,r.error,Math.abs(e.value-r.value))}try{const e=Gr(n,{...t,[o]:c});if(Math.abs(Yn(e)-p)<=1e-6*Math.max(1,Math.abs(p)))return e}catch(e){if(!(e instanceof wn))throw e}}else({value:p,error:m}=Kr(e=>u(Math.sign(h)/e)));return Number.isFinite(p)?ei(p,m):p}(i,t);if("\\sumidx"===r||"\\prodidx"===r)return function(e,t,n){const[r,i,s]=t;if(t.length<3)throw new $n("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=E(r)||"n";const l=Er(Gr(a,n),"a sum"),c=Gr(s,n),h=e?ur:fr;if(c===1/0){if(!e)throw new $n("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 wn("undefined");i+=t}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2])return ei(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 wn("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),m=u(n.slice(-8,-1).map(e=>1/e),h);return ei(p,Math.abs(p-m))}(Xr(r,o,n),Number(l))}const u=Er(c,"a sum");if(u-l+1n>BigInt(Mn.terms))throw new $n("too many terms to add one by one");let p=Zn(e?0:1);for(let e=l;e<=u;e++)p=h(p,Gr(r,{...n,[o]:Pn(On(e))}));return p}("\\sumidx"===r,i,t);if(["()","[]","{}"].includes(r))return Vn(i.map(s),r);if("pmatrix"===r||"bmatrix"===r)return Wr(e,s);if("vmatrix"===r)return Rr.det(Wr(e,s));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=s(i[0]);if(Tr(e))return Rr.transpose(e)}if(Hr.includes(r))return function(e,t){const n={};for(const[e,r]of Object.entries(t))"function"!=typeof r&&(n[e]=nr(r));try{return tr(function(e,t={}){0===yn&&(bn=0),yn++;try{return xn(tn(e),t)}finally{yn--}}(e,n))}catch(e){throw new $n(e.message)}}(e,t);if(r.startsWith("\\:")){const e=r.slice(2);if("function"!=typeof t[e]&&Object.prototype.hasOwnProperty.call(Br,e))return Br[e](...i.map(s));const n=t[e];if("function"!=typeof n)throw new $n(`no function ${r.slice(2)}`);return tr(n(...i.map(e=>nr(s(e)))))}if(Lr[r]&&1===i.length)return Lr[r](s(i[0]));if(Dr[r]&&2===i.length)return Dr[r](s(i[0]),s(i[1]));if(Ur[r])return Ur[r](i.map(s));throw new $n(`can't calculate '${r}'`)}function Vr(e,t){if(Object.prototype.hasOwnProperty.call(t,e))return t[e];if(Object.prototype.hasOwnProperty.call(zr,e))return zr[e]();throw new $n(`no value for '${e}'`)}function Xr(e,t,n){return r=>{try{return Yn(Gr(e,{...n,[t]:r}))}catch(e){if(e instanceof wn)return NaN;throw e}}}const Qr=e=>"symbol"===e.type?e.value:null;function Jr(e,t,n){if(t===-1/0&&n===1/0){const t=Jr(e,-1/0,0),n=Jr(e,0,1/0);return{value:t.value+n.value,error:t.error+n.error}}return n===1/0?Yr(n=>e(t+n/(1-n))/((1-n)*(1-n)),0,1):t===-1/0?Yr(t=>e(n-t/(1-t))/((1-t)*(1-t)),0,1):Yr(e,t,n)}function Yr(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 wn("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 wn("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 wn("the integral does not converge");return{value:o,error:h}}function Kr(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 wn("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 wn("the limit could not be found")}return s}function ei(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 Zn(0);const r=[[Zn(1),1e3],[Bn,100],[Pn(qn,2),100],[Wn,100],...[2n,3n,5n,6n,7n].map(e=>[Pn(qn,0,0,{n:2,r:e}),100])];for(const[t,i]of r){const r=e/Yn(t),s=ti(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*Yn(t)<=n)return sr(Pn(s),t)}return e}function ti(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?On(BigInt(r),BigInt(s)):null}function ni(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&&yr(e[1],pr(e[0])))return`±${ri(e[0],t)}`;if(Cr.has(e.group)&&Q(e))return`${e.group}(${e.map(e=>`[${e.map(e=>ni(e,t)).join(", ")}]`).join(", ")})`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[e.group]||"{}";return n+e.map(e=>ni(e,t)).join(", ")+r}return"number"==typeof e?ii(e,t):t.decimal||null!==t.places?function(e,t){if(Un(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=Nn(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=t.maxDigits)return(r?"-":"")+si(o)}}return Un(e)&&null!==t.places?ni(Ir(e,Zn(t.places)),{...t,places:null,decimal:!0}):ii(Yn(e),t)}(e,t):function(e,t){const{c:n}=e,r=Nn(n.n);if(r.toString().length>t.maxDigits||n.d.toString().length>t.maxDigits)return function(e,t){if(!Un(e)||1n!==e.c.d)return ii(Yn(e),t);const n=Nn(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=si(`${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 ri=(e,t)=>{const n=ni(e,t);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function ii(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`${si(n)}*10^(${Number(r)})`}return String(Number(e.toPrecision(t.digits)))}const si=e=>e.includes(".")?e.replace(/\.?0+$/,""):e;function oi(e,t={},n={}){const r="string"==typeof e?en(e):A(e),i={};for(const[e,n]of Object.entries(t))i[e]=tr(n);let s;0===An&&(kn=0),An++;try{s=Gr(r,i)}finally{An--}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:nr(s),text:ni(s,o),exact:a(s)}}function ai(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}=oi(n,t,r);return e.startsWith('"')||/^\d+(\.\d+)?$/.test(e)?e:`(${e})`}catch(e){if(e instanceof wn)return'"undefined"';if(e instanceof $n)return`(${n})`;throw e}}Yt=ai;for(const e of[Mn,xr,zr,Lr,Dr,Ur])Object.setPrototypeOf(e,null);Object.setPrototypeOf(Br,null);const li={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",matrix:(e,t)=>`the ${e} by ${t} matrix`,row:e=>`row ${e}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},ci={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"},hi=Object.fromEntries(Object.entries(_).map(([e,t])=>[t,e]));function ui(e,t={}){return pi(function(e,t={}){return function(e,t,n){const r=new di({...li,...t.words},{...ci,...t.names},t.say||{},n);return function(e){let t=e.length;for(;t>0&&(e[t-1].close||!e[t-1].text.replace(/,/g,"").trim());)t--;const n=[];for(const{text:r,id:i}of e.slice(0,t)){const e=r.trim();if(!e)continue;const t=e.startsWith(","),s=t?e.slice(1).trim():e;t&&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}(r.speak(e))}(e,t,!0)}(e,t))}function pi(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const mi={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},fi={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class di{constructor(e,t,n,r=!1){this.w=e,this.names=t,this.say=n,this.audio=r}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=>pi(this.speak(e))):[e.value],e,e=>pi(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(fi[e])return t[fi[e]];if(hi[e])return hi[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=c(e.op);return void 0!==t&&t<=50&&!a(e.op).group}quantity(e,t="endQuantity"){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[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(mi[t])return[...this.speak(r),a(s[mi[t]]),...this.speak(i)];if(o(t)){const e=this.symbol(W(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.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 e="number"===r.type?Number(r.value):NaN,t=3===e?s.cubeRoot:2===e?s.squareRoot:s.nthRoot(e?this.ordinal(e):pi(this.speak(r))+"th");return[a(t),...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 e=0===("number"===i.type?Number(i.value):NaN)?s.nearestWholeNumber:`${pi(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"?:":{const e=[a(s.if),...this.speak(r),a(`${s.comma} ${s.then}`),...this.speak(i)];return(e=>"symbol"===e.type&&"unchanged"===e.value)(n[2])?e:[...e,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"pmatrix":case"bmatrix":return this.matrix(e);case"vmatrix":return[a(s.determinantOf),...this.matrix(e)];case"[]":return X(e)?this.matrix(e):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,"endSum");case"\\prodidx":return this.bigOperator(e,s.productFrom,s.productOver,s.productOf,"endProduct")}throw new Error(`No speech for '${t}'`)}matrix(e){const t=this.w,n=X(e),r=[this.seg(e,t.matrix(n.length,n[0].length))];return n.forEach((n,i)=>{const s=e.args[i];r.push(this.seg(e,t.comma),this.seg("op"===s.type&&"[]"===s.op?s:e,`${t.row(i+1)}:`)),n.forEach((n,i)=>r.push(...i?[this.seg(e,t.comma)]:[],...this.speak(n)))}),[...r,...this.closer(e,"endMatrix")]}arguments(e){return 1===e.length?this.argument(e[0]):e.flatMap((e,t)=>t?[{text:this.w.comma,id:e.id},...this.speak(e)]:this.speak(e))}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}quantityIfSum(e){return this.quantity(e)}product(e){const[t,n]=e.args,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)&&!_[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,null),...this.isCall(t)?[i(r.comma)]:[],i(r.over),...this.quantity(n,"endFraction")]}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||this.audio&&"op"===t.type&&"^"===t.op?[i(r.quantity),...this.speak(t),...this.closer(t,"endQuantity")]:this.speak(t);if(this.isCall(t)&&this.names[t.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===t.args.length){const e=2===Number(n.value)?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)]: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(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}=D(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.contents(n,"endDerivative")]}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(E(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=E(n);l=e?[a(e),a(o.approaches),...this.speak(r)]:this.speak(r)}}return[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(e,t,n,r,i){const{args:s}=e,[o,a,l]=s,c=this.w,h=t=>this.seg(e,t);let u;return u=3===s.length?[h(t),...this.speak(a),h(c.to),...this.speak(l),h(c.of)]:2===s.length?[h(n),...this.speak(a),h(c.of)]:[h(r)],[...u,...this.contents(o,i)]}}for(const e of[li,ci,mi,fi,hi])Object.setPrototypeOf(e,null);function gi(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":ui(tn(e),t)}const bi={"(":{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 yi(e,t,n=""){const r=bi[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 xi=.8,vi=.2,wi=.25,$i=.7,Mi="−",ki={"+":"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"},Ai={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Ni={"±":"±","∪":"∪","∩":"∩",mod:"mod"},Ei=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],_i={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},Oi=[...Ei,...Object.keys(_i),"ln","det"],Ii={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},qi={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},Si={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},zi={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},Li=["boxed","overline","bar","underline","cancel",...Object.keys(zi)],Ci={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},Ti=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),ji=e=>+e.toFixed(3)+"em",Ri=(e,t=xi,n=vi)=>({html:e,h:t,d:n});function Fi(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(xi,...t.map(e=>e.h)),d:Math.max(vi,...t.map(e=>e.d))}}function Pi(e,t={}){const n=new Zi({...Ci,...t}),r=n.render(e,{level:0}),i=`${n.p}${n.o.display?` ${n.p}-display`:""}`,s="function"==typeof n.o.mathml?function(e,t,n,r){try{return String(e(t)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${r?' display="block"':""}>`)}catch{return""}}(n.o.mathml,e,n.p,n.o.display):"",o=s?null:function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):gi(e)}catch{return null}}(e,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="${Ti(o)}"`}>${a}${s}</span>`,h:r.h,d:r.d}}class Zi{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=Ri(this.el(e,Ti(t)));return n.leaf={kind:e,content:Ti(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="${Ti(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}="${Ti(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="${Ti(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(/^-/,Mi)))}symbol(e){return _[e]&&(e=_[e]),Si[e]?this.text("ord",Si[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)?Ri(this.el("var",Ti(e[0]))+this.el("prime",Ti(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?Ri(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=ki[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),c=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,n)=>z(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(Oi.includes(n)||"log"===n)return c(this.named(e,t));if(Ii[n])return c(Fi(this.word(Ii[n]),this.fence(this.list(r,t))));if(o(n))return c(this.custom(e,t));const u=X(e);if(u)return c(this.matrix(e,u,t));if(qi[n])return c(this.fence(this.list(r,t),...qi[n]));if(Ai[n]&&2===r.length)return c(Fi(h(i,"left"),this.rel(Ai[n]),h(s,"right")));if(Ni[n]&&2===r.length)return c(Fi(h(i,"left"),this.bin(Ni[n]),h(s,"right")));switch(n){case"+":return I(s)?c(Fi(h(i,"left"),this.bin(Mi),this.wrap(s,["op","op-mul"],this.render(s.args[1],t)))):"number"===s.type&&s.value.startsWith("-")?c(Fi(h(i,"left"),this.bin(Mi),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):c(Fi(h(i,"left"),this.bin("+"),this.signed(s,h(s,"right"))));case"-":return c(Fi(h(i,"left"),this.bin(Mi),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(Fi(this.text("sign",Mi),L(n,i)?this.fence(a(i)):a(i,{before:t.before})));case"pm":return c(Fi(this.text("sign","±"),L(n,i)?this.fence(a(i)):a(i)));case"!":return c(Fi(L(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return c(Fi(this.text("sign","¬"),L(n,i)?this.fence(a(i)):a(i)));case"pmod":return c(Fi(a(i),this.fence(Fi(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(Fi(this.word("ln"),this.fence(Fi(this.word("ln"),this.fence(a(i))))));case"logloglog":return c(Fi(this.word("ln"),this.fence(Fi(this.word("ln"),this.fence(Fi(this.word("ln"),this.fence(a(i))))))));case"perm":return c(this.script(this.script(Ri(""),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):Fi(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":return c(Fi(r.map((e,t)=>t?[this.bin("+"),a(e)]:[a(e)]).flat()));case"prod":return c(Fi(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 Fi(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 Fi(this.text("sign",Mi),this.render(r,t));const i=function(e){const[t,n]=e.args;return{left:z(e,t,"left")&&"/"!==t.op,right:z(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||Ii[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 Fi(l,s?Ri(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=_i[r]&&"power"===this.o.inverseTrig?this.script(this.word(_i[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&&Bi(s),l=this.render(s,{...t,forceParens:!1,before:!1});return Fi(o,a?Fi(Ri(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=W(e.op),r=e.args;if(Li.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],t));return Fi(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Ri(this.el("callgap","")),this.fence(this.list(r,t)))}decorate(e,t){switch(e){case"boxed":return Ri(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return Ri(this.el("cancel",t.html+yi("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return Ri(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return Ri(this.el("over",t.html),t.h+.14,t.d);default:return Ri(this.el("accent",this.el("accent-mark",zi[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,r]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&Bi(n,!0)&&Bi(r,!0)){const e=e=>"op"!==e.type||Bi(e)?this.render(e,t):this.fence(this.render(e,t));return Fi(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:${ji(r)}`),s=n?.06:0,o=wi+s/2+.1+Math.max(vi,r*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(e))+this.el("denom",i(t)),`vertical-align:${ji(o)}`);return Ri(a,o+Math.max(xi,r*e.h),Math.max(xi,r*t.h)+Math.max(vi,r*t.d)+.1+s/2-wi)}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&&Ei.includes(n.op)&&Di(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=z(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:$i,o=i?Fi(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:${ji(s)}`);if(t&&!r)return Ri(e.html+this.el("sup",t.html,`font-size:${ji(s)};vertical-align:${ji(a/s)}`),Math.max(o.h,a+s*t.h),Math.max(o.d,s*t.d-a));if(r&&!t)return Ri(o.html+this.el("sub",r.html,`font-size:${ji(s)};vertical-align:${ji(-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:${ji(a)};height:${ji(h+u)}`);return Ri(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,xi)+.1+.06,r=Math.max(e.d,vi),i=n+r,s=yi("sqrt",`${this.p}-hook`,`height:${ji(i)};width:${ji(.5+.06*(i-1))};vertical-align:${ji(-r)}`);let o="";if(t){const e=.8*$i;o=this.el("rootindex",t.html,`font-size:${ji(e)};vertical-align:${ji((.55*i-r)/e)}`)}return Ri(this.el("sqrt",o+s+this.el("radicand",e.html)),n,r)}fence(e,t="(",n=")"){const r=Math.max(e.h,xi)+Math.max(e.d,vi),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:yi(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${ji(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:${ji(s)} ${ji(l.w)} ${ji(s)} ${ji(a.w)}`,h=Ri(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,xi)+s,Math.max(e.d,vi)+s);return h.fenced=!0,h}derivative(e,t){const{n:n,body:r,by:i,variable:s}=D(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=Fi(a(),l()?this.script(this.render(i,h),l(),h):this.render(i,h)),p=e=>Fi(l()?this.script(a(),l(),h):a(),e||[]),m=t.level>0||t.inFraction||!this.o.display?.8:1;if(s)return this.stack(p(this.render(r,h)),u,!0,m);const f=q(r)&&c(q(r))<100,[d,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=f?this.fence(this.render(r,t),d,g):this.render(r,t);return Fi(this.stack(p(),u,!0,m),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",E(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:B(r)?c=o(r):(c=l(),h=a(r));break;case 3:B(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),m=Ri(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Fi(this.bigSign("int",p,h,u,t),p,m)}bigSign(e,t,n,r,i){const s=!this.o.display||i.level>0,o=Math.max(s?.6:.95,Math.max(t.h-wi,t.d+wi)+.12),a=yi(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${ji(2*o)};width:${ji(s?.38:.5)};vertical-align:${ji(wi-o)}`);if(!n&&!r)return Ri(a,wi+o,o-wi);const l=$i,c=r||Ri(""),h=n||Ri(""),u=wi+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${ji(l)}`)+this.el("script lower",h.html,`font-size:${ji(l)}`),`vertical-align:${ji(u)};height:${ji(2*o)}`);return Ri(a+p,wi+o,o-wi)}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 Fi(this.word("lim"),Ri(this.el("fnspace","")),this.render(n,t));case 2:{const e=E(n),t="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=e&&t?Fi(this.text("var",e),l(),a(r)):a(r);break}case 3:c=Fi(a(r),l(),a(i));break;default:{const e=O(s).toLowerCase().startsWith("r")?"+":Mi;c=Fi(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",e)),o))}}return Fi(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):Ri(this.el("under",e.html+this.el("script",t.html,`font-size:${ji(.7)}`)),e.h,Math.max(e.d,vi)+.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=yi(e,`${this.p}-bigsign`,`height:${ji(2*t)};width:${ji(.8)};vertical-align:${ji(wi-t)}`);return Fi(this.script(Ri(r,wi+t,t-wi),l,n,a),c)}const h=.68,u=$i,p=yi(e,`${this.p}-bigsign`,`height:${ji(1.36)};width:${ji("sum"===e?1:1.05)}`),m=l?1.01+u*l.d:wi-h,f=e=>this.el("script",e.html,`font-size:${ji(u)}`),d=this.el("bigop",(l?f(l):"")+p+(a?f(a):""),`vertical-align:${ji(m)}`);return Fi(Ri(d,.93+(l?.08+u*(l.h+l.d):0),h-wi+(a?.08+u*(a.h+a.d):0)),c)}matrix(e,t,n){const r=t.map(e=>e.map(e=>this.render(e,n))),i=r.map(e=>({h:Math.max(xi,...e.map(e=>e.h)),d:Math.max(vi,...e.map(e=>e.d))})),s=i.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=wi+s/2-i[0].h,a=r.map((t,n)=>{const r=t.map(e=>this.el("matrix-cell",e.html)).join(""),i=e.args[n];return i&&"op"===i.type&&"[]"===i.op?this.wrap(i,["op","op-list","matrix-row"],Ri(r)).html:r}).join(""),l=t[0].length,c=Ri(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${ji(o)}`),wi+s/2,s/2-wi),[h,u]=V[e.op]??["[","]"];return this.fence(c,h,u)}cases(e,t){const n=[];let r=e;for(;"op"===r.type&&"?:"===r.op;)n.push([this.render(r.args[1],t),Fi(this.word("if"),this.text("space",""),this.render(r.args[0],t))]),r=r.args[2];"symbol"===r.type&&"unchanged"===r.value||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=wi+s/2-i[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=Ri(this.el("cases",a,`vertical-align:${ji(o)}`),wi+s/2,s/2-wi);return this.fence(l,"{","")}}function Bi(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||X(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!I(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Wi(e)||"*"===e.op&&Bi(e,t)):Bi(e.args[0],!0)&&("neg"===e.op||Bi(e.args[1],!0)))}const Wi=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(_[e.value])),Di=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const Ui=e=>k(e).join(" ");function Hi(e,t){const n=new Set;Gi(e,t,n);const r=[];return N(e,e=>{n.has(e)&&r.push(e)}),r}function Gi(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>Gi(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const r=Ui(en(t));return void N(e,e=>{Ui(e)===r&&n.add(e)})}if(t.path){const r=function(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}(e,t.path);return void(r&&n.add(r))}if(t.type){const r=Ui(t);N(e,e=>{e!==t&&Ui(e)!==r||n.add(e)})}}else N(e,(e,r)=>{t(e,r)&&n.add(e)});else N(e,e=>{e.id===t&&n.add(e)})}function Vi(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 Xi(e,t={}){const{blocks:n}=t;if("string"==typeof e)return en(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?Vi(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Qi(e,t={}){const n=Xi(e,t);return Pi(n,function(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(Ji(r))for(const n of Hi(e,t))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:Hi(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}}}(n,t)).html}function Ji(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var Yi='/*\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 Ki=Yi;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Yi,document.head.append(e)}return e.CSS=Ki,e.DEFAULTS=Ci,e.calculate=oi,e.calculateBlock=ai,e.layout=Pi,e.numberTree=Vi,e.select=Hi,e.toHTML=(e,t={})=>Qi(e,{...t,blocks:t.blocks??ai}),e.treeOf=(e,t={})=>Xi(e,{...t,blocks:t.blocks??ai}),e}({});
@@ -0,0 +1,2 @@
1
+ /* Inline Math 0.2.0 — MIT licence; MathZetta not included: load a MathZetta <script> (mathzetta.min.js or mathzetta.maths-display.min.js) first */
2
+ var InlineMath=function(e,t,n){"use strict";const i={"(":{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 r(e,t,n=""){const r=i[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 s=.8,a=.2,l=.25,o=.7,m="−",h={"+":"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"},c={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},d={"±":"±","∪":"∪","∩":"∩",mod:"mod"},p=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],u={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},f=[...p,...Object.keys(u),"ln","det"],v={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},g={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},b={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},x={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},y=["boxed","overline","bar","underline","cancel",...Object.keys(x)],w={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},$=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;"),k=e=>+e.toFixed(3)+"em",M=(e,t=s,n=a)=>({html:e,h:t,d:n});function L(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(s,...t.map(e=>e.h)),d:Math.max(a,...t.map(e=>e.d))}}function C(e,t={}){const i=new z({...w,...t}),r=i.render(e,{level:0}),s=`${i.p}${i.o.display?` ${i.p}-display`:""}`,a="function"==typeof i.o.mathml?function(e,t,n,i){try{return String(e(t)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${i?' display="block"':""}>`)}catch{return""}}(i.o.mathml,e,i.p,i.o.display):"",l=a?null:function(e,t){if(!1===t||null===t)return null;if("string"==typeof t)return t;try{return"function"==typeof t?t(e):n.toAudioSpeech(e)}catch{return null}}(e,i.o.label),o=null!==l||a?r.html.replace(/^<span /,'<span aria-hidden="true" '):r.html;return{html:`<span class="${s}"${null===l?"":` role="math" aria-label="${$(l)}"`}>${o}${a}</span>`,h:r.h,d:r.d}}class z{constructor(e){this.o=e,this.p=e.prefix}el(e,t,n="",i=""){return`<span class="${e.split(" ").map(e=>`${this.p}-${e}`).join(" ")}"${n?` style="${n}"`:""}${i}>${t}</span>`}text(e,t){const n=M(this.el(e,$(t)));return n.leaf={kind:e,content:$(t)},n}bin(e){return this.text("bin",e)}rel(e){return this.text("rel",e)}punct(e){return this.text("punct",e)}word(e){return this.text("word",e)}wrap(e,t,n){let i="";void 0!==e.id&&(i+=` data-node="${e.id}"`),"op"===e.type&&(i+=` data-op="${$(e.op)}"`);const r=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(r))"class"!==e&&"style"!==e&&(i+=` ${e}="${$(t)}"`);const s=[r.style,this.o.style&&this.o.style(e)].filter(Boolean).join(";"),a=(n.leaf?["n",...t,n.leaf.kind]:["n",...t]).map(e=>`${this.p}-${e}`).concat(r.class?[r.class]:[]).join(" "),l=n.leaf?n.leaf.content:n.html;return{html:`<span class="${a}"${s?` style="${$(s)}"`:""}${i}>${l}</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(/^-/,m)))}symbol(e){return t.GREEK[e]&&(e=t.GREEK[e]),b[e]?this.text("ord",b[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)?M(this.el("var",$(e[0]))+this.el("prime",$(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?M(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,n){const{op:i,args:r}=e,[s,a]=r,l=(e,t={})=>this.render(e,{...n,...t,forceParens:t.forceParens||!1,before:t.before||!1}),o=h[i]??(/^[a-z0-9]+$/i.test(i)?i:"other"),p=t=>this.wrap(e,["op",`op-${o}`],t),u=(n,i)=>t.needsBrackets(e,n,i)&&"/"!==n.op?this.fence(l(n)):l(n);if(f.includes(i)||"log"===i)return p(this.named(e,n));if(v[i])return p(L(this.word(v[i]),this.fence(this.list(r,n))));if(t.isCustomFunction(i))return p(this.custom(e,n));const b=t.matrixRows(e);if(b)return p(this.matrix(e,b,n));if(g[i])return p(this.fence(this.list(r,n),...g[i]));if(c[i]&&2===r.length)return p(L(u(s,"left"),this.rel(c[i]),u(a,"right")));if(d[i]&&2===r.length)return p(L(u(s,"left"),this.bin(d[i]),u(a,"right")));switch(i){case"+":return t.isMinusOneTimes(a)?p(L(u(s,"left"),this.bin(m),this.wrap(a,["op","op-mul"],this.render(a.args[1],n)))):"number"===a.type&&a.value.startsWith("-")?p(L(u(s,"left"),this.bin(m),this.wrap(a,["number"],this.text("num",a.value.slice(1))))):p(L(u(s,"left"),this.bin("+"),this.signed(a,u(a,"right"))));case"-":return p(L(u(s,"left"),this.bin(m),this.signed(a,u(a,"right"))));case"*":return p(this.product(e,n));case"/":return p(this.fraction(e,n));case"^":return p(this.power(e,n));case"_":return p(this.script(l(s,{forceParens:!0}),null,n,l(a,{level:n.level+1})));case"neg":return p(L(this.text("sign",m),t.unaryNeedsBrackets(i,s)?this.fence(l(s)):l(s,{before:n.before})));case"pm":return p(L(this.text("sign","±"),t.unaryNeedsBrackets(i,s)?this.fence(l(s)):l(s)));case"!":return p(L(t.unaryNeedsBrackets(i,s)?this.fence(l(s)):l(s,{forceParens:!0}),this.text("ord","!")));case"\\not":return p(L(this.text("sign","¬"),t.unaryNeedsBrackets(i,s)?this.fence(l(s)):l(s)));case"pmod":return p(L(l(s),this.fence(L(this.word("mod"),this.text("space",""),l(a)))));case"sqrt":return p(this.radical(l(s)));case"root":return p(this.radical(l(a),this.render(s,{level:n.level+2})));case"abs":return p(this.fence(l(s),"|","|"));case"floor":return p(this.fence(l(s),"⌊","⌋"));case"ceil":return p(this.fence(l(s),"⌈","⌉"));case"loglog":return p(L(this.word("ln"),this.fence(L(this.word("ln"),this.fence(l(s))))));case"logloglog":return p(L(this.word("ln"),this.fence(L(this.word("ln"),this.fence(L(this.word("ln"),this.fence(l(s))))))));case"perm":return p(this.script(this.script(M(""),this.render(s,{level:n.level+1}),n),null,n,this.render(a,{level:n.level+1}),this.word("P")));case"comb":return p(this.fence(this.stack(l(s),l(a),!1)));case"?:":return p(this.o.cases?this.cases(e,n):L(l(s),this.bin("?"),l(a),this.bin(":"),l(r[2])));case"sum":return p(L(r.map((e,t)=>t?[this.bin("+"),l(e)]:[l(e)]).flat()));case"prod":return p(L(r.map((e,t)=>t?[this.bin("·"),l(e)]:[l(e)]).flat()));case"der":return p(this.derivative(e,n));case"int":return p(this.integral(r,n));case"lim":return p(this.limit(r,n));case"\\sumidx":return p(this.bigOperator("sum",r,n));case"\\prodidx":return p(this.bigOperator("prod",r,n))}throw new Error(`Inline Math cannot draw '${i}'`)}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 L(e.map((e,n)=>n?[this.punct(","),this.render(e,t)]:[this.render(e,t)]).flat())}product(e,n){const[i,r]=e.args;if(t.isMinusOneTimes(e))return L(this.text("sign",m),this.render(r,n));const s=t.bracketedSides(e),a=t.isImplicitProduct(i,r,s),l=function(e){for(;"op"===e.type;){if(f.includes(e.op)||"log"===e.op||v[e.op]||t.isCustomFunction(e.op))return!0;if("^"!==e.op&&"*"!==e.op)return!1;e=e.args[0]}return!1}(r),o=s.left?this.fence(this.render(i,n)):this.render(i,{...n,before:a&&!l}),h=s.right?this.fence(this.render(r,n)):this.render(r,{...n,before:n.before});return L(o,a?M(this.el(l?"fnspace":"times","")):this.bin("·"),h)}named(e,t,n=null){const{op:i,args:r}=e,s="log"===i?r[1]:r[0];let a;a=u[i]&&"power"===this.o.inverseTrig?this.script(this.word(u[i]),this.text("num","−1"),t):this.word(i),n&&(a=this.script(a,n,t)),"log"===i&&(a=this.script(a,null,t,this.render(r[0],{level:t.level+1})));const l="auto"===this.o.fnParens&&!t.forceParens&&!t.before&&A(s),o=this.render(s,{...t,forceParens:!1,before:!1});return L(a,l?L(M(this.el("fnspace","")),o):this.fence(o))}custom(e,n){const i=t.customName(e.op),r=e.args;if(y.includes(i)&&1===r.length)return this.decorate(i,this.render(r[0],n));return L(/^[A-Za-z]′*(⁻¹)?$/.test(i)?this.symbol(i):this.word(i),M(this.el("callgap","")),this.fence(this.list(r,n)))}decorate(e,t){switch(e){case"boxed":return M(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return M(this.el("cancel",t.html+r("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return M(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return M(this.el("over",t.html),t.h+.14,t.d);default:return M(this.el("accent",this.el("accent-mark",x[e])+t.html),t.h+.3,t.d)}}fraction(e,t){const[n,i]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&A(n,!0)&&A(i,!0)){const e=e=>"op"!==e.type||A(e)?this.render(e,t):this.fence(this.render(e,t));return L(e(n),this.text("ord","/"),e(i))}const r=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(i,s),!0,r)}stack(e,t,n=!0,i=1){const r=e=>1===i?e.html:this.el("scaled",e.html,`font-size:${k(i)}`),o=n?.06:0,m=l+o/2+.1+Math.max(a,i*e.d),h=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",r(e))+this.el("denom",r(t)),`vertical-align:${k(m)}`);return M(h,m+Math.max(s,i*e.h),Math.max(s,i*t.h)+Math.max(a,i*t.d)+.1+o/2-l)}power(e,n){const[i,r]=e.args,s={...n,level:n.level+1,forceParens:!1,before:!1,inFraction:!1},a=()=>this.render(r,s);if(this.o.trigPowers&&p.includes(i.op)&&j(r))return this.wrap(i,["op",`op-${i.op}`],this.named(i,n,a()));if("_"===i.op){const e=this.render(i.args[1],s);return this.wrap(i,["op","op-subscript"],this.script(this.render(i.args[0],{...n,forceParens:!0}),a(),n,e))}const l=t.needsBrackets(e,i,"left")||"number"===i.type&&i.value.startsWith("-")||"/"===i.op||f.includes(i.op)?this.fence(this.render(i,n)):this.render(i,{...n,forceParens:!0});return this.script(l,a(),n)}script(e,t,n,i=null,r=null){const s=n.level>0?.8:o,a=r?L(e,r):e;let l=t?Math.max(.42,e.h-.38,s*t.d+.12):0,m=i?Math.max(.2,e.d-.05,s*i.h-.45):0;if(t&&i){const e=.1-(l-s*t.d-(s*i.h-m));e>0&&(m+=e)}const h=e=>this.el("script",e.html,`font-size:${k(s)}`);if(t&&!i)return M(e.html+this.el("sup",t.html,`font-size:${k(s)};vertical-align:${k(l/s)}`),Math.max(a.h,l+s*t.h),Math.max(a.d,s*t.d-l));if(i&&!t)return M(a.html+this.el("sub",i.html,`font-size:${k(s)};vertical-align:${k(-m/s)}`),Math.max(a.h,s*i.h-m),Math.max(a.d,m+s*i.d));const c=l+s*t.h,d=m+s*i.d,p=this.el("subsup",h(t)+h(i),`vertical-align:${k(l)};height:${k(c+d)}`);return M(a.html+p,Math.max(a.h,c),Math.max(a.d,d))}radical(e,t=null){const n=Math.max(e.h,s)+.1+.06,i=Math.max(e.d,a),l=n+i,m=r("sqrt",`${this.p}-hook`,`height:${k(l)};width:${k(.5+.06*(l-1))};vertical-align:${k(-i)}`);let h="";if(t){const e=.8*o;h=this.el("rootindex",t.html,`font-size:${k(e)};vertical-align:${k((.55*l-i)/e)}`)}return M(this.el("sqrt",h+m+this.el("radicand",e.html)),n,i)}fence(e,t="(",n=")"){const i=Math.max(e.h,s)+Math.max(e.d,a),l=i>1.25,o=l?.1:0,m=(e,t)=>{if(!e)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[e];if(n){const s=n+(l?Math.min(.2,.05*(i-1)):0);return{html:r(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${k(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}},h=m(t,"l"),c=m(n,"r"),d=`padding:${k(o)} ${k(c.w)} ${k(o)} ${k(h.w)}`,p=M(this.el("fence",h.html+e.html+c.html,d),Math.max(e.h,s)+o,Math.max(e.d,a)+o);return p.fenced=!0,p}derivative(e,n){const{n:i,body:r,by:s,variable:a}=t.derivativeOrder(e),l={...n,level:n.level+1},o=()=>this.text("d","d"),m=()=>i>1?this.render({type:"number",value:String(i)},l):null,h={...n,inFraction:!0},c=L(o(),m()?this.script(this.render(s,h),m(),h):this.render(s,h)),d=e=>L(m()?this.script(o(),m(),h):o(),e||[]),p=n.level>0||n.inFraction||!this.o.display?.8:1;if(a)return this.stack(d(this.render(r,h)),c,!0,p);const u=t.bracketOp(r)&&t.precedenceOf(t.bracketOp(r))<100,[f,v]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],g=u?this.fence(this.render(r,n),f,v):this.render(r,n);return L(this.stack(d(),c,!0,p),g)}integral(e,n){const[i,r,s,a]=e,l=e=>this.render(e,n),o=e=>e?this.render(e,{...n,level:n.level+1}):null,m=()=>this.text("var",t.firstVariable(i)||"x");let h,c=null,d=null;switch(e.length){case 1:h=m();break;case 2:t.isVariable(r)?h=l(r):(h=m(),c=o(r));break;case 3:t.isVariable(r)?(h=l(r),c=o(s)):(h=m(),c=o(r),d=o(s));break;default:h=l(r),c=o(s),d=o(a)}const p=l(i),u=M(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return L(this.bigSign("int",p,c,d,n),p,u)}bigSign(e,t,n,i,s){const a=!this.o.display||s.level>0,m=Math.max(a?.6:.95,Math.max(t.h-l,t.d+l)+.12),h=r(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${k(2*m)};width:${k(a?.38:.5)};vertical-align:${k(l-m)}`);if(!n&&!i)return M(h,l+m,m-l);const c=o,d=i||M(""),p=n||M(""),u=l+m-c*d.h;p.d;const f=this.el("limits",this.el("script",d.html,`font-size:${k(c)}`)+this.el("script lower",p.html,`font-size:${k(c)}`),`vertical-align:${k(u)};height:${k(2*m)}`);return M(h+f,l+m,m-l)}limit(e,n){const[i,r,s,a]=e,l={...n,level:n.level+1},o=e=>this.render(e,l),h=()=>this.rel("→");let c;switch(e.length){case 1:return L(this.word("lim"),M(this.el("fnspace","")),this.render(i,n));case 2:{const e=t.firstVariable(i),n="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=e&&n?L(this.text("var",e),h(),o(r)):o(r);break}case 3:c=L(o(r),h(),o(s));break;default:{const e=t.firstLeaf(a).toLowerCase().startsWith("r")?"+":m;c=L(o(r),h(),this.script(o(s),this.wrap(a,["symbol"],this.text("ord",e)),l))}}return L(this.under(this.word("lim"),c,n),this.render(i,n))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):M(this.el("under",e.html+this.el("script",t.html,`font-size:${k(.7)}`)),e.h,Math.max(e.d,a)+.05+.7*(t.h+t.d))}bigOperator(e,t,n){const[i,s,a]=t,m={...n,level:n.level+1},h=s?this.render(s,m):null,c=a?this.render(a,m):null,d=this.render(i,n);if(!this.o.display||n.level>0){const t=.55,i=r(e,`${this.p}-bigsign`,`height:${k(2*t)};width:${k(.8)};vertical-align:${k(l-t)}`);return L(this.script(M(i,l+t,t-l),c,n,h),d)}const p=.68,u=o,f=r(e,`${this.p}-bigsign`,`height:${k(1.36)};width:${k("sum"===e?1:1.05)}`),v=c?1.01+u*c.d:l-p,g=e=>this.el("script",e.html,`font-size:${k(u)}`),b=this.el("bigop",(c?g(c):"")+f+(h?g(h):""),`vertical-align:${k(v)}`);return L(M(b,.93+(c?.08+u*(c.h+c.d):0),p-l+(h?.08+u*(h.h+h.d):0)),d)}matrix(e,n,i){const r=n.map(e=>e.map(e=>this.render(e,i))),o=r.map(e=>({h:Math.max(s,...e.map(e=>e.h)),d:Math.max(a,...e.map(e=>e.d))})),m=o.reduce((e,t)=>e+t.h+t.d,0)+.3*(n.length-1),h=l+m/2-o[0].h,c=r.map((t,n)=>{const i=t.map(e=>this.el("matrix-cell",e.html)).join(""),r=e.args[n];return r&&"op"===r.type&&"[]"===r.op?this.wrap(r,["op","op-list","matrix-row"],M(i)).html:i}).join(""),d=n[0].length,p=M(this.el("matrix",c,`grid-template-columns:repeat(${d},auto);vertical-align:${k(h)}`),l+m/2,m/2-l),[u,f]=t.MATRICES[e.op]??["[","]"];return this.fence(p,u,f)}cases(e,t){const n=[];let i=e;for(;"op"===i.type&&"?:"===i.op;)n.push([this.render(i.args[1],t),L(this.word("if"),this.text("space",""),this.render(i.args[0],t))]),i=i.args[2];"symbol"===i.type&&"unchanged"===i.value||n.push([this.render(i,t),this.word("otherwise")]);const r=n.map(([e,t])=>({h:Math.max(e.h,t.h),d:Math.max(e.d,t.d)})),s=r.reduce((e,t)=>e+t.h+t.d,0)+.25*(n.length-1),a=l+s/2-r[0].h,o=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),m=M(this.el("cases",o,`vertical-align:${k(a)}`),l+s/2,s/2-l);return this.fence(m,"{","")}}function A(e,n=!1){return"number"===e.type?!e.value.startsWith("-")||n:"symbol"===e.type||"op"===e.type&&("abs"===e.op||t.matrixRows(e)?!n:!n||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!t.isMinusOneTimes(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||T(e)||"*"===e.op&&A(e,n)):A(e.args[0],!0)&&("neg"===e.op||A(e.args[1],!0)))}const T=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(t.GREEK[e.value])),j=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;const P=e=>t.toPostfix(e).join(" ");function B(e,n){const i=new Set;E(e,n,i);const r=[];return t.walk(e,e=>{i.has(e)&&r.push(e)}),r}function E(e,n,i){if(null!=n)if(Array.isArray(n))n.forEach(t=>E(e,t,i));else if("number"!=typeof n)if("function"!=typeof n){if("string"==typeof n){const r=P(t.parseTree(n));return void t.walk(e,e=>{P(e)===r&&i.add(e)})}if(n.path){const t=function(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}(e,n.path);return void(t&&i.add(t))}if(n.type){const r=P(n);t.walk(e,e=>{e!==n&&P(e)!==r||i.add(e)})}}else t.walk(e,(e,t)=>{n(e,t)&&i.add(e)});else t.walk(e,e=>{e.id===n&&i.add(e)})}function O(e){let n=0;const i=e=>{"op"===e.type&&(e.args.forEach(i),t.operator(e.op)?.arity===t.VARIADIC&&n++),e.id=n++};return i(e),e}function Z(e,n={}){const{blocks:i}=n;if("string"==typeof e)return t.parseTree(e,i?{blocks:e=>i(e,n.scope)}:{});if(Array.isArray(e))return t.fromPostfix(e);if(e&&"object"==typeof e&&e.type)return void 0===e.id?O(structuredClone(e)):e;throw new Error("Inline Math needs an expression, standard postfix or a tree")}function S(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var q='/*\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 F=q;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=q,document.head.append(e)}return e.CSS=F,e.DEFAULTS=w,e.layout=C,e.numberTree=O,e.select=B,e.toHTML=function(e,t={}){const n=Z(e,t);return C(n,function(e,t){const{colors:n,highlight:i,scope:r,blocks:s,...a}=t,l=new Map;for(const[t,i]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(S(i))for(const n of B(e,t))l.set(n,`color:${i}`);const o=new Set(void 0===i?[]:B(e,i));if(!l.size&&!o.size)return a;const m=a.prefix||"mv";return{...a,style:e=>[l.get(e),a.style&&a.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...a.attributes?a.attributes(e):{}};return o.has(e)&&(t.class=[t.class,`${m}-hl`].filter(Boolean).join(" ")),t}}}(n,t)).html},e.treeOf=Z,e}({},MathZetta,MathZetta);