@mathzetta/inlinemath 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-HWNd7HTQ.js +2 -0
- package/dist/chunks/draw-SJQZoo2a.js +2 -0
- package/dist/chunks/{edit-CTMRUElt.js → edit-BPcpKq9t.js} +2 -2
- package/dist/chunks/{edit-D2RO7fg0.js → edit-lks88rjH.js} +2 -2
- package/dist/chunks/{html-1wCO6EpZ.js → html-CzXOU7ql.js} +2 -2
- package/dist/chunks/html-hyetRykq.js +2 -0
- package/dist/chunks/lite-OfhVrBim.js +2 -0
- package/dist/inlinemath-cas.external.global.min.js +2 -2
- package/dist/inlinemath-cas.global.min.js +2 -2
- package/dist/inlinemath-lite-calc.global.min.js +2 -2
- package/dist/inlinemath-lite.external.global.min.js +2 -2
- package/dist/inlinemath-lite.global.min.js +2 -2
- package/dist/inlinemath.css +13 -2
- package/dist/inlinemath.external.global.min.js +2 -2
- package/dist/inlinemath.external.js +2 -2
- package/dist/inlinemath.global.min.js +2 -2
- package/dist/inlinemath.js +2 -2
- package/dist/lite-calc.js +2 -2
- package/dist/lite.external.js +2 -2
- package/dist/lite.js +2 -2
- package/dist/markdown.external.js +2 -2
- package/dist/markdown.js +2 -2
- package/inlinemath.css +13 -2
- package/package.json +5 -5
- package/src/cas.js +57 -10
- package/src/glyphs.js +3 -2
- package/src/layout.js +35 -5
- package/dist/chunks/calculate-BGMEvf3f.js +0 -2
- package/dist/chunks/draw-q86mDDWm.js +0 -2
- package/dist/chunks/html-D5QiXGXD.js +0 -2
- package/dist/chunks/lite-Bo8THzyq.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
var InlineMath=function(t){"use strict";const e=-1,n={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt:r(1),abs:r(1),floor:r(1),ceil:r(1),det:r(1),ln:r(1),loglog:r(1),logloglog:r(1),expm1:r(1),sin:r(1),cos:r(1),tan:r(1),csc:r(1),sec:r(1),cot:r(1),sinh:r(1),cosh:r(1),tanh:r(1),arcsin:r(1),arccos:r(1),arctan:r(1),arcsinh:r(1),arccosh:r(1),arctanh:r(1),random:r(0),log:r(2),root:r(2),atan2:r(2),round:r(2),fixed:r(2),perm:r(2),comb:r(2),der:r(2),max:r(e),min:r(e),gcd:r(e),mean:r(e),sum:r(e),prod:r(e),int:r(e),lim:r(e),"\\sumidx":r(e),"\\prodidx":r(e),pmatrix:r(e),bmatrix:r(e),vmatrix:r(e),"()":i(),"[]":i(),"{}":i(),"(]":i(),"[)":i(),"=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"===":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"<":{prec:34,assoc:"left",arity:2,fixity:"infix"},">":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≤":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≥":{prec:34,assoc:"left",arity:2,fixity:"infix"},"∈":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∉":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∪":{prec:33,assoc:"left",arity:2,fixity:"infix"},"∩":{prec:33,assoc:"left",arity:2,fixity:"infix"},"≈":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≡":{prec:30,assoc:"left",arity:2,fixity:"infix"},pmod:{prec:2,assoc:"left",arity:2,fixity:"infix"},"→":{prec:38,assoc:"left",arity:2,fixity:"infix"},"\\not":{prec:85,assoc:"none",arity:1,fixity:"prefix"},"&":{prec:20,assoc:"left",arity:2,fixity:"infix"},"\\xor":{prec:19,assoc:"left",arity:2,fixity:"infix"},"|":{prec:18,assoc:"left",arity:2,fixity:"infix"},"\\nor":{prec:17,assoc:"left",arity:2,fixity:"infix"},"\\nand":{prec:17,assoc:"left",arity:2,fixity:"infix"},"?:":{prec:10,assoc:"right",arity:3,fixity:"infix"}};function r(t){return{prec:100,assoc:"none",arity:t,fixity:"prefix"}}function i(){return{prec:5,assoc:"left",arity:e,fixity:"none",group:!0}}const s="\\:",o=t=>"string"==typeof t&&t.startsWith(s)&&t.length>2;function a(t){return Object.prototype.hasOwnProperty.call(n,t)?n[t]:o(t)?l:void 0}const l=r(e),c=t=>a(t)?.prec;function u(t,e,n){if("mod"===t&&e)return c(e)<=70;if("mod"===e&&["*","/"].includes(t))return!0;if("mod"===e&&["+","-","±"].includes(t))return"right"===n;const r=c(t),i=c(e);if(!r||!i)return!1;if(i!==r)return i<r;const s=a(t).assoc;return"left"===s?"right"===n:"right"===s&&"left"===n}const h=100,p="",f="",m={[p]:"dot",[f]:"cross"},d="",g={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,[p]:70,[f]: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},b=t=>Object.prototype.hasOwnProperty.call(g,t),$=new Set(["^","?:","?","log"]),y=["(","{","["],v=[")","}","]"];function w(t,e=!1){if(!t)return!1;for(let n=0;n<t.length;n++)if(!("0123456789.".includes(t[n])||e&&0===n&&"-"===t[n]&&t.length>1))return!1;return!0}for(const t of[g])Object.setPrototypeOf(t,null);const x=t=>({type:"number",value:String(t)}),M=t=>({type:"symbol",value:t}),k=(t,e)=>({type:"op",op:t,args:e}),E=['"',"'","`"];function A(t){return w(t,!0)?x(t):E.includes(t[0])?{type:"string",value:t}:M(t)}const N={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function O(t){if(!Array.isArray(t)||0===t.length)throw new Error("Empty postfix");const n=[],r=[];if(t.forEach((t,i)=>{const s=N[t]??String(t),l=a(s);if(!l)return n.push({...A(s),id:i}),void r.push(1);let c=l.arity;if(c===e){const t=n.pop();if(r.pop(),c=t&&"number"===t.type?Number(t.value):NaN,!Number.isInteger(c)||c<0)throw new Error(`'${s}' takes a variable number of arguments, so it must follow a count`);if(0===c&&!l.group&&!o(s))throw new Error(`'${s}' needs at least one argument`)}if(n.length<c)throw new Error(`'${s}' needs ${c} operand${1===c?"":"s"}`);const u=1+Math.max(0,...r.splice(r.length-c,c));if(u>1e3)throw new Error("Nested too deeply (more than 1000 levels)");r.push(u),n.push({...k(s,n.splice(n.length-c,c)),id:i})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function S(t,n){const r=[];return function t(i){"op"===i.type?(i.args.forEach(t),a(i.op)?.arity===e&&r.push(String(i.args.length)),n&&i.written&&(n[r.length]=i.written),r.push(i.op)):r.push(i.value)}(t),r}function _(t){if(Array.isArray(t))return O(t);if(t&&"object"==typeof t&&t.type)return t;throw new Error("Expected a postfix array or an expression tree")}function I(t,e,n=null){e(t,n),"op"===t.type&&t.args.forEach(n=>I(n,e,t))}function q(t){let e="";return I(t,t=>{!e&&"symbol"===t.type&&1===t.value.length&&/[a-zA-Zʹ-Ͽ]/.test(t.value)&&(e=t.value)}),e}for(const t of[N])Object.setPrototypeOf(t,null);const L={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 z(t){for(;"op"===t.type&&t.args.length;)t=t.args[0];return"op"===t.type?"":t.value}function j(t){const e="string"==typeof t&&/^(-?)(\d*)(?:\.(\d*))?%$/.exec(t);if(!e||!e[2]&&!e[3])return null;const n=(e[2]||"0").padStart(3,"0")+(e[3]??""),r=n.length-(e[3]??"").length-2,i=`${n.slice(0,r).replace(/^0+(?=\d)/,"")}.${n.slice(r)}`.replace(/\.?0+$/,"");return e[1]+(""===i?"0":i)}function T(t){if("*"!==t.op)return!1;const[e,n]=t.args;return"number"===e.type&&"-1"===e.value&&"-1"!==z(n)}function C(t){return"op"!==t.type||a(t.op)?.group?null:"sum"===t.op?"+":"prod"===t.op?"*":T(t)?"neg":t.op}const F=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),R=(t,e,n)=>("op"!==e.type||"?:"!==e.op||!F.has(t.op))&&u(t.op,C(e),n);function P(t,e){const n=C(e),r=n&&a(n)?.prec;return r?"!"===t?r<=a("!").prec:"\\not"===t?r<a("\\not").prec:r<70||G(e)||"\\not"===n:"\\not"!==t&&G(e)}function Z(t,e,n={}){const r=n.left?"bracket":U(t),i=n.right?"bracket":D(e);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function B(t){return 1===t.length||Boolean(L[t])||/^Δ.$/.test(t)||/^.′+$/.test(t)}function W(t){return"op"===t.type&&!a(t.op)?.group&&(a(t.op)?.prec??100)<70&&!["sum","prod"].includes(t.op)}function D(t){if("number"===t.type)return t.value.startsWith("-")?"sign":"digit";if("op"!==t.type)return"symbol"===t.type&&B(t.value)?"name":"word";const e=t.op;return"neg"===e||"pm"===e||T(t)?"sign":"/"===e?"frac":a(e)?.group||W(t)?"bracket":H(t)||["der","int","lim","comb"].includes(e)?"call":["^","!","_"].includes(e)?W(t.args[0])?"bracket":D(t.args[0]):["*","sum","prod","perm"].includes(e)?D(t.args[0]):"other"}function U(t){if("number"===t.type)return"digit";if("op"!==t.type)return"symbol"===t.type&&B(t.value)?"name":"word";const e=t.op;return"/"===e?"frac":"^"===e||"_"===e?"script":a(e)?.group||W(t)||H(t)||["der","int","lim","comb","perm"].includes(e)?"bracket":["*","neg","pm","sum","prod"].includes(e)?U(t.args[t.args.length-1]):"other"}function H(t){if("op"!==t.type)return!1;const e=a(t.op);return"prefix"===e?.fixity&&100===e.prec}function G(t){if("number"===t.type)return t.value.startsWith("-");if("op"!==t.type)return!1;if("neg"===t.op||T(t))return!0;const e=a(t.op);return"infix"===e?.fixity&&!R(t,t.args[0],"left")&&G(t.args[0])}const V=t=>"symbol"===t.type&&1===t.value.length&&/[a-zA-Zʹ-Ͽ]/.test(t.value),X=t=>t.slice(2);function Q(t){const e="op"===t.args[1].type&&"="===t.args[1].op?t.args[1]:null,n=e?e.args[0]:t.args[1],r=e?e.args[1]:null;let i=1,s=t.args[0];for(;"op"===s.type&&"der"===s.op&&J(s.args[1],n);)i++,s=s.args[0];return{n:i,body:s,by:n,at:r,variable:"symbol"===s.type&&B(s.value)}}const J=(t,e)=>t.type===e.type&&t.value===e.value&&"op"!==t.type,Y=new Set(["<",">","≤","≥","=","===","≠","≠=","&","|","\\not","\\xor","\\nand","\\nor","∈","∉","≈","≡"]);function K(t){return"op"===t.type&&(!!("="===t.op&&(e=t.args[1],"op"===e.type&&Y.has(e.op)||"symbol"===e.type&&("true"===e.value||"false"===e.value)))||t.args.some(K));var e}const tt=new Set(["<",">","≤","≥","=","≠"]);function et(t){if("op"!==t.type||!tt.has(t.op)||2!==t.args.length)return null;const[e,n]=t.args;if("op"!==e.type||!tt.has(e.op)||2!==e.args.length)return null;return{type:"op",op:"&",args:[et(e)??e,{type:"op",op:t.op,args:[e.args[1],n]}]}}for(const t of[L])Object.setPrototypeOf(t,null);const nt={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function rt(t){if(!t||"op"!==t.type)return null;if(Object.prototype.hasOwnProperty.call(nt,t.op))return t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args:[t]);if("[]"!==t.op||!t.args.length||!t.args.every(t=>"op"===t.type&&"[]"===t.op))return null;const e=t.args[0].args.length;return!e||!t.args.every(t=>t.args.length===e)||t.args.length<2&&e<2?null:t.args.map(t=>t.args)}function it(t){return Array.isArray(t)&&t.length>0&&t.every(e=>Array.isArray(e)&&e.length>0&&e.length===t[0].length&&!e.some(Array.isArray))}const st=t=>Array.isArray(t)&&t.length>0&&!t.some(Array.isArray);function ot(t){const e=t,n=e.make??(t=>t),r=e.size??(()=>1),i=e.charge??(()=>{}),s=t=>`${t.length} by ${t[0].length}`,o=(t,r)=>n(Array.from({length:t},(n,r)=>Array.from({length:t},(t,n)=>r===n?e.one():e.zero())),r);function a(t,r){return t[0].length!==r.length&&e.fail(`a ${s(t)} matrix times a ${s(r)} one`),i(t.length*r.length*r[0].length),n(t.map(t=>r[0].map((n,i)=>t.reduce((t,n,s)=>e.add(t,e.mul(n,r[s][i])),e.zero()))),t)}function l(t){const n=t.map(t=>t.slice()),s=n.length,o=n[0].length;i(s*s*o);let a=e.one(),l=0;for(let t=0;t<o&&l<s;t++){let i=-1;for(let o=l;o<s;o++)e.isZero(n[o][t])||(i<0||r(n[o][t])>r(n[i][t]))&&(i=o);if(i<0){a=e.zero();continue}i!==l&&([n[i],n[l]]=[n[l],n[i]],a=e.sub(e.zero(),a));const o=n[l][t];a=e.mul(a,o),n[l]=n[l].map(t=>e.div(t,o));for(let r=0;r<s;r++){if(r===l||e.isZero(n[r][t]))continue;const i=n[r][t];n[r]=n[r].map((t,r)=>e.sub(t,e.mul(i,n[l][r])))}l++}return l<s&&(a=e.zero()),{M:n,det:a,rank:l}}function c(t){const r=t.length;r!==t[0].length&&e.fail(`a ${s(t)} matrix has no inverse`);const i=o(r),{M:a,rank:c}=l(t.map((t,e)=>[...t,...i[e]]));return(c<r||a.some((t,n)=>e.isZero(t[n])))&&e.fail("the matrix has no inverse (its determinant is 0)"),n(a.map(t=>t.slice(r)),t)}return{identity:o,transpose:t=>n(t[0].map((e,n)=>t.map(t=>t[n])),t),times:a,det:function(t){return t.length!==t[0].length&&e.fail(`a ${s(t)} matrix has no determinant`),l(t).det},inverse:c,power:function(t,n){t.length!==t[0].length&&e.fail(`a ${s(t)} matrix has no powers`);let r=n<0n?c(t):t,i=n<0n?-n:n,l=o(t.length,t);for(;i>0n;)1n&i&&(l=a(l,r)),r=a(r,r),i>>=1n;return l},trace:t=>(t.length!==t[0].length&&e.fail(`a ${s(t)} matrix has no trace`),t.reduce((t,n,r)=>e.add(t,n[r]),e.zero())),dot:(t,n)=>(t.length!==n.length&&e.fail("vectors of different lengths"),t.reduce((t,r,i)=>e.add(t,e.mul(r,n[i])),e.zero())),cross:(t,n)=>(3===t.length&&3===n.length||e.fail("the cross product is for vectors of 3 numbers"),[e.sub(e.mul(t[1],n[2]),e.mul(t[2],n[1])),e.sub(e.mul(t[2],n[0]),e.mul(t[0],n[2])),e.sub(e.mul(t[0],n[1]),e.mul(t[1],n[0]))]),solve:function(t,e){return it(e)?a(c(t),e):a(c(t),e.map(t=>[t])).map(t=>t[0])},rank:t=>l(t).rank,rref:t=>n(l(t).M,t),timesVector:(t,e)=>a(t,e.map(t=>[t])).map(t=>t[0]),vectorTimes:(t,e)=>a([t],e)[0]}}function at(t){const e=new Map;for(const[n,r,i]of t)if(n&&""!==n.trim()&&(e.set(n,r),!i))for(const t of ct(n))e.get(t)||e.set(t,r);const n=new Map;for(const t of e.keys()){let e=n;for(let n=0;n<t.length;n++)e.has(t[n])||e.set(t[n],new Map),e=e.get(t[n]);e.end=!0}return t=>{let r="",i=0;for(;i<t.length;){const s=lt(n,t,i);s?(r+=e.get(t.slice(i,i+s)),i+=s):r+=t[i++]}return r}}function lt(t,e,n){let r=t,i=0;for(let t=n;t<e.length&&(r=r.get(e[t]),r);t++)r.end&&(i=t-n+1);return i}function ct(t){const e=new Set([t.toLowerCase(),t.toUpperCase(),ut(t)]);return e.delete(t),e}function ut(t){let e="",n=!1;for(const r of t){const t=r>="a"&&r<="z",i=r>="A"&&r<="Z";e+=!n&&t?r.toUpperCase():r,n=t||i}return e}const ht=[["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\cfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\%","%"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot",p],["\\times",f],["×",f],["·",p],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],...["","\\"].flatMap(t=>["(","{"].flatMap(e=>[2,3,4,5,6,7,8,9,10].map(n=>[`${t}log${n}${e}`,`log_{${n}}${e}`]))),["\\log_10","log_{10}"],["log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left.",d],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⅕","(1/5)"],["⅖","(2/5)"],["⅗","(3/5)"],["⅘","(4/5)"],["⅙","(1/6)"],["⅚","(5/6)"],["⅐","(1/7)"],["⅑","(1/9)"],["⅒","(1/10)"],["⊕"," \\xor "],["∞","∞"],["⋅",p],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0]];const pt=t=>" "===t||"\t"===t||"\n"===t,ft="({[",mt=")}]";const dt={__proto__:null},gt={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((t,e)=>{dt[t]=String(e)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((t,e)=>{gt[t]=String(e)}),Object.assign(dt,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g","ʰ":"h","ⁱ":"i","ʲ":"j","ᵏ":"k","ˡ":"l","ᵐ":"m","ⁿ":"n","ᵒ":"o","ᵖ":"p","ʳ":"r","ˢ":"s","ᵗ":"t","ᵘ":"u","ᵛ":"v","ʷ":"w","ˣ":"x","ʸ":"y","ᶻ":"z"}),Object.assign(gt,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const bt=new RegExp(`[${Object.keys(dt).join("")}]+|[${Object.keys(gt).join("")}]+`,"g");const $t={__proto__:null,"½":"1/2","⅓":"1/3","⅔":"2/3","¼":"1/4","¾":"3/4","⅕":"1/5","⅖":"2/5","⅗":"3/5","⅘":"4/5","⅙":"1/6","⅚":"5/6","⅐":"1/7","⅛":"1/8","⅜":"3/8","⅝":"5/8","⅞":"7/8","⅑":"1/9","⅒":"1/10"},yt=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys($t).join("")}])`,"g"),vt=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,wt=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function xt(t){const e=t.replace(/^\s*(?:\\(?:text|textrm|mathrm)\s*\{\s*(?:if|for|when|where)\s*\}|\b(?:if|for|when|where)\b)\s*,?/,"").replace(/[\s,.;]+$/,"").trim();return/^(?:\\(?:text|textrm|mathrm)\s*\{\s*)?(?:otherwise|else)\s*\}?$/.test(e)?"":e}function Mt(t,e){const n=[];let r=0,i=0;for(let s=0;s<t.length;s++)ft.includes(t[s])?r++:mt.includes(t[s])?r--:0===r&&t.startsWith(e,s)&&(n.push(t.slice(i,s)),s+=e.length-1,i=s+1);return n.push(t.slice(i)),n}function kt(t,e,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=e;n<t.length;n++)if(ft.includes(t[n]))r++;else if(mt.includes(t[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(t)))return n;return-1}function Et(t,e){let n=0;for(let r=e;r<t.length;r++)if(ft.includes(t[r]))n++;else if(mt.includes(t[r])&&--n<0)return r;return t.length}function At(t,e){let n=1;for(let r=e+1;r<t.length;r++)if("?"===t[r])n++;else if(":"===t[r]&&0===--n)return t.slice(0,e+1)+"("+t.slice(e+1,r)+")?:"+t.slice(r+1);return t}function Nt(t){for(let e=2;e<t.length;e++)if("g"===t[e]&&"log"===t.slice(e-2,e+1))if("_"===t[e+1]){if(ft.includes(t[e+2]))continue;const n=/^(?:\d+(?:\.\d+)?|[A-Za-z\u0370-\u03FF])/.exec(t.slice(e+2))?.[0];if(!n)continue;const r=e+2+n.length;t=t.slice(0,e+2)+"{"+n+"}"+t.slice(r)}else if("("===t[e+1]){let n=1,r=0,i="",s="",o=0;for(let a=e+2;a<t.length;a++){if(")]".includes(t[a])?n--:"([".includes(t[a])&&n++,0===n){o=a;break}1===n&&","===t[a]?r++:0===r?i+=t[a]:s+=t[a]}1===r&&o>0&&(t=t.slice(0,e+1)+"_{"+s+"}("+i+")"+t.slice(o+1))}return t}function Ot(t){const e="⌈"===t[0]?"ceil":"floor";let n=1;for(let r=1;r<t.length;r++)if("⌊"===t[r]||"⌈"===t[r]?n++:"⌋"!==t[r]&&"⌉"!==t[r]||n--,0===n)return e+"("+t.slice(1,r)+")"+t.slice(r+1);return t}function St(t){let e=1;for(let n=0;n<t.length;n++){if(")]".includes(t[n])?e--:"([".includes(t[n])&&e++,0!==e)continue;const r=t.slice(0,n),i=t[n+1];if("{"===i||"("===i)return i+r+","+t.slice(n+2);const s=/^[A-Za-z0-9.\u0370-\u03FF]+/.exec(t.slice(n+1))?.[0]??"";return"{"+r+","+s+"}"+t.slice(n+1+s.length)}return t}const _t=new Set(["pmatrix","bmatrix","vmatrix"]);function It(t){const e=t.indexOf("}"),n=t.indexOf("{");if(e<0||n>=0&&n<e)return!1;const r=t.slice(0,e);if(!r.includes("matrix"))return!1;const i=t.indexOf("\\end{"+r+"}"),s=t.indexOf("\\begin{"+r+"}",e+1);if(i<0||-1!==s&&s<i)return!1;const o=t.slice(e+1,i).trim().split("\\\\").map(t=>t.trim()).filter(t=>t.length).map(t=>"["+t.replace(/&/g,", ")+"]"),a=t.slice(i+6+r.length);return _t.has(r)?r+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function qt(t,e){if("{"!==t[e+1])return[t[e+1],e+2];let n=1,r="";for(let i=e+2;i<t.length;i++){if("{"===t[i])n++;else if("}"===t[i]&&0===--n)return[r,i+1];r+=t[i]}return[r,t.length]}function Lt(t){const{lower:e,upper:n,next:r}=function(t){let e="",n="",r=0;return"_"===t[0]&&([e,r]=qt(t,0),"^"===t[r]&&([n,r]=qt(t,r))),{lower:e,upper:n,next:r}}(t),i=t.slice(r),s=t=>t.replace(/\\,/g,"").replace(/\\!/g,"");let o,a="",l="",c=i.indexOf("\\mathrm{d}");if(c>=0){o=i.slice(0,c);const t=/^\{([^{}]*)\}/.exec(i.slice(c+10));a=t?t[1]:i[c+10],l=i.slice(c+10+(t?t[0].length:1))}else(c=function(t){let e=0;for(let n=0;n<t.length;n++)if(ft.includes(t[n]))e++;else if(mt.includes(t[n]))e--;else if(0===e&&"d"===t[n]&&/[A-Za-z\u0370-\u03FF]/.test(t[n+1]??"")&&!/[A-Za-z]/.test(t[n+2]??""))return n;return-1}(i))>=0?(o=i.slice(0,c),a=i[c+1],l=i.slice(c+2)):o=i;if(!a){const t=/frac\{d([A-Za-z])\}/.exec(o);t&&(a=t[1],o=o.replace(t[0],"frac{1}"))}if(!a&&/^[A-Za-z]$/.test(e)){a=[...s(o).matchAll(/(?<![A-Za-z\\])([A-Za-z])(?![A-Za-z(])/g)].map(t=>t[1]).find(t=>t!==e&&t!==n)??"x"}let u="int("+(s(o).trim()?s(o):"1");return a&&(u+=","+a),(e||n)&&(u+=","+e+","+n),u+")"+l}function zt(t){const e=t[0];if(!(e>="A"&&e<="Z"||e>="a"&&e<="z"||e>="α"&&e<="ω"))return!1;const n=t.slice(2);let r=1;for(let t=0;t<n.length;t++)if(mt.includes(n[t])?r--:ft.includes(n[t])&&r++,0===r)return"("+n.slice(0,t)+","+e+")"+n.slice(t+1);return!1}function jt(t){return"{"===t[0]||t.length<2?t:"{"+t[0]+"}{"+t[1]+"}"+t.slice(2)}const Tt=/[A-Za-z\u0370-\u03FF]/;function Ct(t,e){if("{"!==t[e])return null;let n=0;for(let r=e;r<t.length;r++)if("{"===t[r])n++;else if("}"===t[r]&&0===--n)return[t.slice(e+1,r),r+1];return null}function Ft(t,e){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(t.slice(e));return n?[Number(n[1]??n[2]),e+n[0].length]:[1,e]}function Rt(t,e){const n=t.replace(/\\mathrm\{d\}/g,"d"),r=e.replace(/\\mathrm\{d\}/g,"d"),i=/^d(?:\^\{?(\d+)\}?)?([A-Za-z\u0370-\u03FF]?)$/.exec(n),s=/^d([A-Za-z\u0370-\u03FF])(?:\^\{?(\d+)\}?)?$/.exec(r);return i&&s?{n:Number(i[1]??1),of:i[2],by:s[1]}:null}function Pt(t,e){if(ft.includes(t[e])){let n=0;for(let r=e;r<t.length;r++)if(ft.includes(t[r]))n++;else if(mt.includes(t[r])&&0===--n)return[t.slice(e,r+1),r+1];return[t.slice(e),t.length]}let n=0;for(let r=e;r<t.length;r++)if(ft.includes(t[r]))n++;else{if(mt.includes(t[r])&&--n<0)return[t.slice(e,r),r];if(0===n&&("="===t[r]||","===t[r]))return[t.slice(e,r),r]}return[t.slice(e),t.length]}const Zt=(t,e,n)=>`der(${t},${e}${n>1?","+n:""})`;const Bt="strtktk",Wt="ABCDEFGHIJ",Dt=t=>Bt+[...String(t)].map(t=>Wt[t]).join(""),Ut=new RegExp(`^${Bt}[${Wt}]+$`);function Ht(t){let e="";for(let n=0;n<t.length;n++){const r=t[n];if('"'===r||"`"===r){const r=Gt(t,n);e+=t.slice(n,r+1),n=r}else if("'"===r)if(/[A-Za-z0-9)\]′\u0370-\u03FF]/.test(e[e.length-1]??""))e+="′";else{const r=Gt(t,n);e+=t.slice(n,r+1),n=r}else e+=r}return e}function Gt(t,e){let n=!1;for(let r=e+1;r<t.length;r++)if(n)n=!1;else if("\\"===t[r])n=!0;else if(t[r]===t[e])return r;return t.length-1}const Vt=new RegExp(`${Bt}[${Wt}]+|§\\d+§`,"g");function Xt(t,e){return e&&0!==e.size?t.map(t=>"string"!=typeof t?t:t.replace(Vt,t=>{const n=e.get(t);if(void 0!==n)return n;for(let n=t.length-1;n>7;n--){const r=e.get(t.slice(0,n));if(void 0!==r)return r+t.slice(n)}return t})):t}const Qt={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))"};for(const t of[Qt])Object.setPrototypeOf(t,null);const Jt="([{",Yt=")]}";function Kt(t,e){let n=0;for(let r=e;r<t.length;r++)if(Jt.includes(t[r]))n++;else if(Yt.includes(t[r])&&0===--n)return r;return-1}function te(t){if(!t.trim())return[];const e=[];let n=0,r=0;for(let i=0;i<t.length;i++)Jt.includes(t[i])?n++:Yt.includes(t[i])?n--:","===t[i]&&0===n&&(e.push(t.slice(r,i).trim()),r=i+1);return e.push(t.slice(r).trim()),e}function ee(t,e,n){const r=[...t.matchAll(e)];for(let e=r.length-1;e>=0;e--){const i=r[e],s=i.index+i[0].length-1,o=Kt(t,s);if(o<0)continue;const a=n(te(t.slice(s+1,o)),i,t.slice(o+1));if(null==a)continue;const[l,c=0]=Array.isArray(a)?a:[a];if((t=t.slice(0,i.index)+l+t.slice(o+1+c)).length>1e5)throw new Error("The expression expands too much when read")}return t}const ne=t=>new RegExp(`(?<![\\w.])(${t})\\s*\\(`,"g"),re=t=>`(${t})`,ie=t=>/^\[.*\]$/s.test(t.trim())?`{${t.trim().slice(1,-1)}}`:t;const se={IF:t=>t.length>=2&&`((${t[0]}) ? (${t[1]}) : (${t[2]??"false"}))`,AND:t=>t.length&&`(${t.map(re).join(" & ")})`,OR:t=>t.length&&`(${t.map(re).join(" ∨ ")})`,NOT:t=>1===t.length&&`(!(${t[0]}))`,XOR:t=>2===t.length&&`((${t[0]}) \\xor (${t[1]}))`,LOG:t=>2===t.length?`log_{${t[1]}}(${t[0]})`:1===t.length&&`log_{10}(${t[0]})`,ATAN2:t=>2===t.length&&`atan2(${t[1]}, ${t[0]})`,INT:t=>1===t.length&&`floor(${t[0]})`,FIXED:t=>(1===t.length||2===t.length)&&`fixed(${t[0]}, ${t[1]??2})`,"FLOOR.MATH":t=>1===t.length&&`floor(${t[0]})`,"CEILING.MATH":t=>1===t.length&&`ceil(${t[0]})`,FACT:t=>1===t.length&&`((${t[0]})!)`,COMBIN:t=>2===t.length&&`comb(${t.join(", ")})`,PERMUT:t=>2===t.length&&`perm(${t.join(", ")})`,AVERAGE:t=>`mean(${t.join(", ")})`,SUM:t=>`sum(${t.join(", ")})`,PRODUCT:t=>`prod(${t.join(", ")})`,MAX:t=>`max(${t.join(", ")})`,MIN:t=>`min(${t.join(", ")})`,MEDIAN:t=>`median(${t.join(", ")})`,"STDEV.P":t=>`stdev(${t.join(", ")})`,STDEVP:t=>`stdev(${t.join(", ")})`,CEILING:t=>(1===t.length||2===t.length&&"1"===t[1].trim())&&`ceil(${t[0]})`,RAND:t=>!t.length&&"random()",ISNUMBER:t=>1===t.length&&`((${t[0]}) ∈ ℝ)`,LOG10:t=>1===t.length&&`log_{10}(${t[0]})`};function oe(t,e){for(let n=e,r=0;n>=0;n--)if(")"===t[n])r++;else if("("===t[n]&&0===--r)return n;return-1}function ae(t){const e="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";return t=function(t,e){const n=new RegExp(`^(?:${e})`,"u"),r=new RegExp(`(?:${e})$`,"u"),i=/[\p{L}_][\p{L}\p{N}_.]*$/u;for(let e=t.indexOf("^");e>=0;e=t.indexOf("^",e+1)){let s,o=e+1;for(;/\s/.test(t[o]??"");)o++;if("("===t[o])s=Kt(t,o)+1;else{const e=n.exec(t.slice(o));s=e?o+e[0].length:0,e&&"("===t[s]&&(s=Kt(t,s)+1)}if(s<=o||!/^\s*\^/.test(t.slice(s)))continue;let a,l=e;for(;l>0&&/\s/.test(t[l-1]);)l--;if(")"===t[l-1]){a=oe(t,l-1);const e=a>0&&i.exec(t.slice(Math.max(0,a-64),a));e&&(a-=e[0].length)}else{const e=r.exec(t.slice(Math.max(0,l-64),l));a=e?l-e[0].length:-1}a<0||(t=`${t.slice(0,a)}(${t.slice(a,s)})${t.slice(s)}`,e=s+1)}return t}(t=(t=(t=t.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${e})(?=\\s*\\^)`,"gu"),"$1(-$2)"),e),ee(t,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(t,e)=>se[e[1]]?.(t)||null)}const le={POWER:"pow",SQRT:"sqrt",ABS:"abs",LN:"ln",EXP:"exp",FLOOR:"floor",CEIL:"ceil",CEILING:"ceil",ROUND:"round",GREATEST:"max",LEAST:"min",MOD:"mod",ATAN2:"atan2",FACTORIAL:"factorial",SIN:"sin",COS:"cos",TAN:"tan",SEC:"sec",CSC:"csc",COT:"cot",ASIN:"asin",ACOS:"acos",ATAN:"atan",SINH:"sinh",COSH:"cosh",TANH:"tanh",ASINH:"asinh",ACOSH:"acosh",ATANH:"atanh",COMB:"comb",PERM:"perm",GCD:"gcd",DERIVATIVE:"derivative",LIMIT:"limit",UNION:"union",EXPM1:"expm1",TRUNC:"trunc",SUMMATION:"sum"},ce="strtktk[A-J]+";function ue(t){for(let e=!0;e;){const n=t;e=(t=t.replace(new RegExp(`(${ce})\\s*\\|\\|\\s*(${ce})`,"g"),"$1 + $2"))!==n}const e=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${ce},\\s*${ce}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=t.lastIndexOf("(typeof(");n>=0;n=n>0?t.lastIndexOf("(typeof(",n-1):-1){const r=Kt(t,n),i=r>0&&e.exec(t.slice(n,r+1));if(!i)continue;const[,s,o]=i,a=new Map([[`${s} = TRUNC(${s})`,"ℤ"],[`${s} = TRUNC(${s}) AND ${s} > 0`,"ℕ"],[`ABS(${s}) < ∞`,"ℝ"]]).get(o.trim());a&&(t=`${t.slice(0,n)}((${s}) ∈ ${a})${t.slice(r+1)}`)}t=ee(t,/(?<![\w.])CAST\s*\(/gi,t=>{const e=1===t.length&&/^(.*)\s+AS\s+(?:REAL|FLOAT|DOUBLE(?:\s+PRECISION)?|NUMERIC|DECIMAL|INTEGER|INT)\s*$/is.exec(t[0]);return e?`(${e[1]})`:null}),t=(t=(t=ee(t=function(t){for(let e=0;e<50;e++){const e=[...t.matchAll(/\bCASE\s+WHEN\b/gi)];if(!e.length)return t;const n=e[e.length-1].index,r=/\bEND\b/i.exec(t.slice(n));if(!r)return t;const i=t.slice(n+4,n+r.index).split(/\b(WHEN|THEN|ELSE)\b/i).map(t=>t.trim()),s=[];let o="null";for(let t=1;t<i.length;t+=2){const e=i[t].toUpperCase();"WHEN"===e?s.push([i[t+1],i[t+3]]):"ELSE"===e&&(o=i[t+1])}const a=s.reduceRight((t,[e,n])=>`((${e}) ? (${n}) : ${t})`,re(o));t=t.slice(0,n)+a+t.slice(n+r.index+3)}return t}(t=t.replace(/(?<![\w.])ARRAY\s*\[/g,"[")),/(?<![\w.])LOG\s*\(/g,t=>2===t.length?`log_{${t[0]}}(${t[1]})`:`log_{10}(${t[0]})`)).replace(/(?<![\w.])PI\s*\(\s*\)/g,"π")).replace(/(?<![\w.])([A-Z][A-Z0-9]*)(?=\s*\()/g,t=>le[t]??t);for(const[e,n]of[[/\bNOT\s+IN\s*\(/g,"∉"],[/\bIN\s*\(/g,"∈"]])for(let r=e.exec(t);r;r=e.exec(t)){const i=r.index+r[0].length-1,s=Kt(t,i);if(s<0)break;t=`${t.slice(0,r.index)}${n} {${t.slice(i+1,s)}}${t.slice(s+1)}`,e.lastIndex=0}return t.replace(/<>/g," ≠ ")}const he={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"},pe={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc",union1d:"union",intersect1d:"intersection"};const fe={inf:"∞",nan:"NaN"};function me(t){return t=(t=(t=(t=t.replace(/(?<![\w.])(?:np|numpy)\.random\.random\(\s*\)|(?<![\w.])random\.random\(\s*\)/g,"Math.random()")).replace(/(?<![\w.])(?:np|numpy)\.linalg\.(det|inv)\b/g,"$1")).replace(/(?<![\w.])(?:np|numpy)\.array\s*\(/g,"(")).replace(/(?<![\w.])(?:np|numpy)\.(\w+)/g,(t,e)=>he[e]?`Math.${he[e]}`:pe[e]?pe[e]:fe[e]??t),t=function(t){return t=t.replace(/(?<![\w.])sympy\.Interval\.(open|Lopen|Ropen)\s*\(/g,(t,e)=>`sympy_interval_${e}(`),t=t.replace(/(?<![\w.])sympy\.S\.(\w+)/g,(t,e)=>ge[e]??t),t=t.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(t,e)=>ge[e]),t.replace(/(?<![\w.])sympy\.(\w+)/g,(t,e)=>be[e]??de[e]??t)}(t=(t=(t=t.replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(t,e)=>fe[e]??e)).replace(/(?<![\w.])Number\.(isInteger|isFinite)\b/g,(t,e)=>e.toLowerCase())).replace(/(?<![\w.])scipy\.(?:special|integrate)\.(\w+)/g,"$1")),(t=t.replace(/\bMZ_INFINITY\b/g,"∞")).replace(/(?<![\w.])mz_(?=\w+\s*\()/g,"")}const de={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},ge={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},be={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",real_root:"sympy_root",det:"det",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},$e={open:"()",Lopen:"(]",Ropen:"[)"};const ye=t=>{const e=/^\((.*)\)$/s.exec(t.trim());return e?te(e[1]):null},ve=t=>e=>2===e.length&&`${t[0]}${e[0]}, ${e[1]}${t[1]}`,we=t=>ye(t)??[t],xe={where:t=>3===t.length&&`((${t[0]}) ? (${t[1]}) : (${t[2]}))`,logical_and:t=>2===t.length&&`((${t[0]}) & (${t[1]}))`,logical_or:t=>2===t.length&&`((${t[0]}) ∨ (${t[1]}))`,logical_xor:t=>2===t.length&&`((${t[0]}) \\xor (${t[1]}))`,logical_not:t=>1===t.length&&`(!(${t[0]}))`,isin:t=>2===t.length&&`((${t[0]}) ∈ ${ie(t[1])})`,contains:t=>2===t.length&&`((${t[1]}) ∈ ${ie(t[0])})`,isclose:t=>t.length>=2&&`((${t[0]}) ≈ (${t[1]}))`,isfinite:t=>1===t.length&&`((${t[0]}) ∈ ℝ)`,isinteger:t=>1===t.length&&`((${t[0]}) ∈ ℤ)`,factorial:t=>1===t.length&&`((${t[0]})!)`,union:t=>2===t.length&&`((${t[0]}) ∪ (${t[1]}))`,union_:t=>2===t.length&&`((${t[0]}) ∪ (${t[1]}))`,intersection:t=>2===t.length&&`((${t[0]}) ∩ (${t[1]}))`,sq:t=>1===t.length&&`((${t[0]})^2)`,cube:t=>1===t.length&&`((${t[0]})^3)`,fract:t=>1===t.length&&`((${t[0]}) - floor(${t[0]}))`,inversesqrt:t=>1===t.length&&`(1/sqrt(${t[0]}))`,mod:t=>2===t.length&&`((${t[0]}) \\mod (${t[1]}))`,atan:t=>2===t.length&&`atan2(${t[0]}, ${t[1]})`,exp2:t=>1===t.length&&`((2)^(${t[0]}))`,trunc:t=>1===t.length&&`((${t[0]}) < 0 ? (ceil(${t[0]})) : floor(${t[0]}))`,vec2:t=>`(${t.join(", ")})`,vec3:t=>`(${t.join(", ")})`,vec4:t=>`(${t.join(", ")})`,derivative:t=>t.length>=2&&`der(${t.join(", ")})`,sympy_rational:t=>2===t.length&&`((${t[0]})/(${t[1]}))`,sympy_value:t=>1===t.length&&`(${t[0]})`,sympy_eq:t=>2===t.length&&`((${t[0]}) = (${t[1]}))`,sympy_ne:t=>2===t.length&&`((${t[0]}) ≠ (${t[1]}))`,sympy_and:t=>t.length&&`(${t.map(re).join(" & ")})`,sympy_or:t=>t.length&&`(${t.map(re).join(" ∨ ")})`,sympy_not:t=>1===t.length&&`(!(${t[0]}))`,sympy_xor:t=>2===t.length&&`((${t[0]}) \\xor (${t[1]}))`,sympy_nand:t=>2===t.length&&`((${t[0]}) \\nand (${t[1]}))`,sympy_nor:t=>2===t.length&&`((${t[0]}) \\nor (${t[1]}))`,sympy_piecewise:t=>{const e=t.map(ye);return!e.length||e.some(t=>!t||2!==t.length)?null:e.reduceRight((t,[e,n])=>null===t||/^True$|^true$/.test(n.trim())&&void 0===t?`(${e})`:`((${n}) ? (${e}) : ${t??"(null)"})`,void 0)},sympy_set:t=>`{${t.join(", ")}}`,sympy_interval:ve("[]"),sympy_interval_open:ve("()"),sympy_interval_Lopen:ve("(]"),sympy_interval_Ropen:ve("[)"),sympy_contains:t=>2===t.length&&`((${t[0]}) ∈ ${t[1]})`,sympy_list_gcd:t=>1===t.length&&`gcd(${t[0].trim().replace(/^\[|\]$/g,"")})`,sympy_root:t=>2===t.length&&`root(${t[1]}, ${t[0]})`,sympy_integrate:t=>{if(2!==t.length)return null;const e=we(t[1]);return 3===e.length?`int(${t[0]}, ${e.join(", ")})`:1===e.length?`int(${t[0]}, ${e[0]})`:null},sympy_limit:t=>t.length>=3&&`lim(${t.slice(0,3).join(", ")}${t[3]?`, ${t[3]}`:""})`,sympy_summation:t=>{if(3===t.length&&/^\s*[A-Za-z]\w*\s*==/.test(t[1]))return`sum(${t[0]}, ${t[1].replace("==","=")}, ${t[2]})`;const e=2===t.length&&we(t[1]);return 3===e?.length&&`(\\sum_{${e[0]}=${e[1]}}^{${e[2]}} (${t[0]}))`},sympy_product:t=>{if(3===t.length&&/^\s*[A-Za-z]\w*\s*==/.test(t[1]))return`prod(${t[0]}, ${t[1].replace("==","=")}, ${t[2]})`;const e=2===t.length&&we(t[1]);return 3===e?.length&&`(\\prod_{${e[0]}=${e[1]}}^{${e[2]}} (${t[0]}))`},limit:t=>t.length>=3&&`lim(${t.join(", ")})`,summation:t=>3===t.length&&/^\s*[A-Za-z]\w*\s*==/.test(t[1])&&`sum(${t[0]}, ${t[1].replace("==","=")}, ${t[2]})`,sum:Me("sum"),prod:Me("prod")};function Me(t){return e=>{const n=1===e.length&&/^(.*?)\s+for\s+(\w+)\s+in\s+range\((.*)\)\s*$/s.exec(e[0]);if(!n)return null;const r=te(n[3]),[i,s]=1===r.length?["0",r[0]]:r,o=/\s*\+\s*1$/.test(s)?s.replace(/\s*\+\s*1$/,""):`(${s}) - 1`;return`(\\${t}_{${n[2]}=${i}}^{${o}} (${n[1]}))`}}function ke(t){t=function(t){for(let e=t.lastIndexOf("(lambda");e>=0;e=e>0?t.lastIndexOf("(lambda",e-1):-1){const n=Kt(t,e);if(n<0||"("!==t[n+1])continue;const r=Kt(t,n+1),i=/^\(lambda\s+([\w\s,]+?)\s*:\s*([\s\S]*)\)$/.exec(t.slice(e,n+1));if(r<0||!i)continue;const s=i[1].split(",").map(t=>t.trim()),o=te(t.slice(n+2,r));if(o.length!==s.length||!s.every(t=>/^[A-Za-z_]\w*$/.test(t)))continue;const a=new Map(s.map((t,e)=>[t,o[e]])),l=i[2].replace(new RegExp(`(?<![\\w.])(${s.join("|")})(?!\\w)`,"g"),t=>`(${a.get(t)})`);if((t=t.slice(0,e)+`(${l})`+t.slice(r+1)).length>1e5)throw new Error("The expression expands too much when read")}return t}(t),t=ee(t,ne("quad"),(t,e,n)=>{const r=/^lambda\s+(\w+)\s*:\s*(.*)$/s.exec(t[0]??"");if(!r||3!==t.length)return null;const i=/^\s*\[\s*0\s*\]/.exec(n);return[`int(${r[2]}, ${r[1]}, ${t[1]}, ${t[2]})`,i?i[0].length:0]}),t=ee(t,ne(Object.keys(xe).join("|")),(t,e)=>xe[e[1]](t)||null);for(let e=(t=ee(t,ne("float"),(t,e,n)=>{const r=/^\s*\.is_integer\(\s*\)/.exec(n);return r&&1===t.length?[`((${t[0]}) ∈ ℤ)`,r[0].length]:null})).lastIndexOf(".includes(");e>=0;e=e>0?t.lastIndexOf(".includes(",e-1):-1){const n=e+9,r=Kt(t,n);let i=e;if(Yt.includes(t[e-1])){let n=0;for(i=e-1;i>=0;i--)if(Yt.includes(t[i]))n++;else if(Jt.includes(t[i])&&0===--n)break}else for(;i>0&&/[\w.]/.test(t[i-1]);)i--;r<0||i<0||i===e||(t=`${t.slice(0,i)}((${t.slice(n+1,r)}) ∈ ${ie(t.slice(i,e))})${t.slice(r+1)}`)}return t}for(const t of[se,le,he,pe,de,ge,be,$e,xe,fe])Object.setPrototypeOf(t,null);const Ee=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Ae=t=>t.trim().split(/\s+/).join(String.raw`\s+`),Ne=t=>new RegExp(String.raw`(?<![\w.])${Ae(t)}(?![\w.])`,"gi"),Oe=[["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","="]],Se="[<>≤≥=≠≈]",_e={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(_e,null);const Ie=Object.entries({sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"}).sort((t,e)=>e[0].length-t[0].length),qe=[["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","∈ ℚ"]],Le=/(?<![A-Za-z])(?:is|between|exceeds|equals?|does|doesn't|least|most|than|divides|and|or|of|to|squared|cubed|twice|percent|by|over|times|plus|minus|modulo)(?![A-Za-z])/i;Oe.map(([t])=>t),qe.map(([t])=>t),Ie.map(([t])=>`${t} of`);const ze=at([[" 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 ","→"],["===","=...="]]),je=at([...ht,...function(){const t=[],e=(e,n)=>{t.push([e,n],[e+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(t.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const t of["","h"]){const r=n+t,i="arc"+n+t;t&&(e("Math."+r,r),e("\\"+r,r));for(const n of["^-1","^{-1}","-1"])e("\\"+r+n,i),e(r+n,i),t||e("Math."+r+n,i);t||e("\\a"+r,i),e("\\arc"+r,i),e("Math.a"+r,i),e("Math.arc"+r,i)}return t}()]),Te=[["code",function(t){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(t)?(/^\s*=(?!=)/.test(t)&&(t=ae(t)),t=function(t){return t.includes("sorted")?ee(t,/(?<![\w.])sorted\s*\(/g,t=>{if(1!==t.length)return null;const e=t[0];for(let t=0,n=0;t<e.length;t++)if("([{".includes(e[t]))n++;else if(")]}".includes(e[t]))n--;else if(0===n&&("|"===e[t]||"&"===e[t])){const n=t=>{const e=t.trim(),n=/^set\s*\(/.exec(e);return n&&Kt(e,n[0].length-1)===e.length-1?e.slice(n[0].length,-1):null},[r,i]=[n(e.slice(0,t)),n(e.slice(t+1))];return null!==r&&null!==i?`((${r}) ${"|"===e[t]?"∪":"∩"} (${i}))`:null}return null}):t}(t=me(t=ue(t=(t=(t=function(t){for(const[e,n]of Object.entries(Qt))for(let r=t.lastIndexOf(n);r>=0;r=r>0?t.lastIndexOf(n,r-1):-1){const i=r+n.length,s="("===t[i]?Kt(t,i):-1;if(s<0)continue;let o=t.slice(i+1,s);"gcd"===e&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===e?`((${o})!)`:`${e}(${o})`;t=t.slice(0,r)+a+t.slice(s+1)}for(let e=t.lastIndexOf(").toFixed(");e>=0;e=e>0?t.lastIndexOf(").toFixed(",e-1):-1){const n=e+10-1,r=Kt(t,n),i=t.lastIndexOf("Number(",e);r<0||i<0||Kt(t,i+7-1)!==e||(t=t.slice(0,i)+`fixed(${t.slice(i+7,e)}, ${t.slice(n+1,r)})`+t.slice(r+1))}return t.replace(/\(\(\)=>\{let (sum|prod) = [01]; let loopCount = 0; for \(let (\w+)=(.*?);\2<=(.*?);\2\+\+\) \{if \(loopCount\+\+ > 1000000\)\{break\};\1 [+*]= (.*?);\}; return \1;\}\)\(\)/g,(t,e,n,r,i,s)=>`(\\${"sum"===e?"sum":"prod"}_{${n}=${r}}^{${i}} (${s}))`)}(t)).replace(/(?<![\w.])9e999\b/g,"∞")).replace(/(?<![\w.])(\d+(?:\.\d+)?)[eE]([+-]?\d+)(?![\w.])/g,"($1*10^{$2})")))),t=function(t){for(let e=0;e<50;e++){let e=!0;for(const n of t.matchAll(/\bif\b/g)){const r=n.index;let i=0,s=-1,o=t.length;for(let e=r+2;e<t.length;e++)if(Jt.includes(t[e]))i++;else{if(Yt.includes(t[e])&&--i<0){o=e;break}if(0===i&&","===t[e]){o=e;break}if(0===i&&/^then\b/.test(t.slice(e))&&/\W/.test(t[e-1])){s=-2;break}0===i&&s<0&&/^else\b/.test(t.slice(e))&&/\W/.test(t[e-1])&&(s=e)}if(s<0)continue;i=0;let a=0;for(let e=r-1;e>=0;e--)if(Yt.includes(t[e]))i++;else{if(Jt.includes(t[e])&&--i<0){a=e+1;break}if(0===i&&","===t[e]){a=e+1;break}}const l=t.slice(a,r).trim();if(!l)continue;const c=`((${t.slice(r+2,s).trim()}) ? (${l}) : (${t.slice(s+4,o).trim()}))`;t=t.slice(0,a)+c+t.slice(o),e=!1;break}if(e)return t}return t}(t=ke(t)),(t=(t=t.replace(/\b(?:True|TRUE)\b/g,"true").replace(/\b(?:False|FALSE)\b/g,"false").replace(/\b(?:None|NULL)\b/g,"null")).replace(/\^\^/g," \\xor ")).replace(/%(?=\s*(?:[(-]|[A-Za-z_][\w.]*\s*\())/g," \\mod ")):t}],["english",function(t){if(!Le.test(t))return t;let e=t;const n=(t,n,r,i="∈")=>{e=e.replace(new RegExp(String.raw`(?<![\w.])${Ae(t)}\s+(${Ee})\s+(?:and|to)\s+(${Ee})(?:\s+(inclusive|exclusive))?(?![\w.])`,"gi"),(t,e,s,o)=>{const[a,l]="exclusive"===o?.toLowerCase()?["(",")"]:"inclusive"===o?.toLowerCase()?["[","]"]:[n,r];return` ${i} ${a}${e}, ${s}${l} `})};n("is not strictly between","(",")","∉"),n("is not between","[","]","∉"),n("is strictly between","(",")"),n("is between","[","]"),n("between","[","]"),e=e.replace(new RegExp(String.raw`(?<![\w.])is\s+(not\s+)?in\s+the\s+(open|closed|half-open)\s+interval\s+from\s+(${Ee})\s+to\s+(${Ee})`,"gi"),(t,e,n,r,i)=>{const[s,o]={open:["(",")"],closed:["[","]"],"half-open":["[",")"]}[n.toLowerCase()];return` ${e?"∉":"∈"} ${s}${r}, ${i}${o} `});const r=String.raw`(${Ee})\s+`;e=e.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${Ee})\s*(%|\s+percent)?\s+of\s+(${Ee})`,"gi"),(t,e,n,r,i,s)=>`(abs((${e}) - (${s})) ${n?">":"≤"} ${i?`(${r})/100 * ${/^\d+(\.\d+)?$/.test(s)?s:`abs(${s})`}`:`(${r})`})`),e=e.replace(new RegExp(r+String.raw`is\s+(?:a\s+)?multiple\s+of\s+(${Ee})`,"gi"),"(($1) mod ($2) = 0)"),e=e.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Ee})`,"gi"),(t,e,n,r)=>`((${e}) mod (${r}) ${n?"≠":"="} 0)`),e=e.replace(new RegExp(String.raw`(${Ee})\s+divides\s+(${Ee})`,"gi"),"(($2) mod ($1) = 0)"),e=e.replace(new RegExp(r+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(t,e,n,r)=>`((${e}) mod 2 ${"even"===r.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[t,n]of qe)e=e.replace(Ne(t),` ${n} `);e=e.replace(Ne("is not in")," ∉ ").replace(Ne("is in")," ∈ ").replace(Ne("is an element of")," ∈ ");for(const[t,n]of Oe)e=e.replace(Ne(t),` ${n} `);e=e.replace(Ne("is not")," ≠ "),e=e.replace(/(?<=[\w.)\]}′]\s+)is(?=\s+[\w.(\[{-])/gi," = ");for(let t=!0;t;){const n=e;e=e.replace(new RegExp(String.raw`(${Ee})\s*(${Se})\s*(${Ee})\s+(and|or)\s+(${Se})`,"gi"),"$1 $2 $3 $4 $1 $5"),t=e!==n}e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?absolute\s+value\s+of\s+(${Ee})`,"gi"),"abs($1)"),e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${Ee})`,"gi"),"sqrt($1)"),e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${Ee})`,"gi"),"root(3, $1)"),e=e.replace(new RegExp(String.raw`(${Ee})\s+to\s+the\s+power\s+of\s+(${Ee})`,"gi"),"($1)^($2)"),e=e.replace(new RegExp(String.raw`(${Ee})\s+to\s+the\s+(${Object.keys(_e).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(t,e,n,r)=>`(${e})^(${_e[n.toLowerCase()]??r})`),e=e.replace(new RegExp(String.raw`(${Ee})\s+to\s+the\s+(${Ee})(?![\w.])`,"gi"),"($1)^($2)");for(const[t,n]of Ie)e=e.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Ae(t)}\s+of\s+(${Ee})`,"gi"),`${n}($1)`);e=e.replace(new RegExp(String.raw`(${Ee})\s+squared(?![\w.])`,"gi"),"($1)^2"),e=e.replace(new RegExp(String.raw`(${Ee})\s+cubed(?![\w.])`,"gi"),"($1)^3"),e=e.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${Ee})`,"gi"),"($1)/2"),e=e.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${Ee})`,"gi"),"2*($1)"),e=e.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const i=t=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${Ae(t)}(?=\s+[\w.(\[{-])`,"gi");for(const[t,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])e=e.replace(i(t),` ${n} `);return e}],["words",ze],["spaced",function(t){t=function(t){for(let e=t.lastIndexOf("\\sqrt");e>=0;e=e>0?t.lastIndexOf("\\sqrt",e-1):-1){let n=e+5;if(/[A-Za-z]/.test(t[n]??""))continue;for(;pt(t[n]);)n++;const r=t.slice(n);let i=/^(?:§\d+§|-?(?:\d+(?:\.\d+)?|\.\d+)|-?[A-Za-zͰ-Ͽ])/.exec(r)?.[0];if(!i&&/^\\[A-Za-z]/.test(r)&&!r.startsWith("\\left")){let t=/^\\[A-Za-z]+/.exec(r)[0].length;if(/^\d\d/.exec(r.slice(t))&&/frac$/.test(r.slice(0,t)))t+=2;else{const e=/^\s*\[[^\[\]{}]*\]/.exec(r.slice(t));for(e&&(t+=e[0].length);;){let e=t;for(;pt(r[e]);)e++;if("{"!==r[e])break;let n=0,i=-1;for(let t=e;t<r.length;t++)if("{"===r[t])n++;else if("}"===r[t]&&0===--n){i=t;break}if(i<0)break;t=i+1}}i=r.slice(0,t)}i&&(t=`${t.slice(0,e)}\\sqrt{${i}}${t.slice(n+i.length)}`)}return t}(function(t){return t=t.replace(yt,(t,e,n)=>`(${e}+${$t[n]})`),t=t.replace(vt,(t,e,n,r)=>Number(n)<Number(r)&&3!==n.length?`(${e}+${n}/${r})`:t),t.replace(wt,(t,e,n,r,i,s)=>{const[o,a]=[n??i,r??s];return Number(o)<Number(a)?`(${e}+\\frac{${o}}{${a}})`:t})}(function(t){return t.replace(bt,t=>{const e=t[0]in dt;return`${e?"^":"_"}{${[...t].map(t=>(e?dt:gt)[t]).join("")}}`})}(t))),t=function(t){for(let e=0;e<100;e++){const e=[...t.matchAll(/\bif\b/gi)];if(!e.length)return t;const n=e[e.length-1].index,r=kt(t,n+2,"then");if(r<0)return t;const i=t.slice(n+2,r),s=kt(t,r+4,"else"),o=Et(t,s<0?r+4:s+4),a=t.slice(r+4,s<0?o:s),l=s<0?"unchanged":t.slice(s+4,o).trim();t=`${t.slice(0,n)}((${i.trim()}) ? (${a.trim()}) : (${l}))${t.slice(o)}`}return t}(t),t=function(t){for(let e=0;e<t.length;e++){const n=n=>t.slice(Math.max(0,e-n),e+1);if("t"===t[e]&&"\\text"===n(4)&&"{"===t[e+1]){let n=1,r=e+2,i="";for(;n>0&&r<t.length;)"{"===t[r]?n++:"}"===t[r]?n--:i+=t[r],r++;t=t.slice(0,e-4)+i+t.slice(r)}}return t}(t=(t=t.replace(/\(\s*\\?b?mod\s+([^()\s](?:[^()]*[^()\s])?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")),t=Nt(t);for(let e=0;e<t.length-1;e++)if("?"===t[e]&&":"!==t[e+1])t=At(t,e);else if("_"===t[e]||"^"===t[e]){const n=/^§\d+§/.exec(t.slice(e+1));if(n){t=`${t.slice(0,e+1)}{${n[0]}}${t.slice(e+1+n[0].length)}`;continue}const r=("^"===t[e]||/[A-Za-z}]/.test(t[e-1]??""))&&/^\\[A-Za-z]+(?![A-Za-z{\d])/.exec(t.slice(e+1));if(r){t=`${t.slice(0,e+1)}{${r[0]}}${t.slice(e+1+r[0].length)}`;continue}let i=e+1;for("-"===t[i]&&i++;i<t.length&&".0123456789".includes(t[i]);)i++;if(i===e+2&&"-"===t[e+1]&&(i=e+1),"-"===t[e+1]&&/^\s*[\^!]/.test(t.slice(i,i+8)))continue;i>e+1&&(t=t.slice(0,e+1)+"{"+t.slice(e+1,i)+"}"+t.slice(i))}return t}],["squeeze",function(t){return t.replace(/\s+/g,(e,n)=>{const r=t[n-1]??"",i=t[n+e.length]??"";return"Δ"===r?"":/[A-Za-z\u0370-\u03FF′]/.test(r)&&/[A-Za-z\u0370-\u03FF]/.test(i)?" ":""})}],["symbols",je],["bar",function(t){let e=0;for(let n=t.indexOf(d,e);n>=0;n=t.indexOf(d,e)){let r=0,i=-1;for(let e=n+1;e<t.length;e++)if("([{".includes(t[e]))r++;else if(")]}".includes(t[e]))r--;else if(0===r&&t.startsWith("|_",e)){i=e;break}i<0&&Ce(),t=`${t.slice(0,n+1)}(${t.slice(n+1,i)})${t.slice(i)}`,e=n+1}return t}],["compact",function(t){if(t=function(t){for(let e=t.indexOf(")′");e>=0;e=t.indexOf(")′",e+1)){let n=0,r=-1;for(let i=e;i>=0;i--)if(")"===t[i])n++;else if("("===t[i]&&0===--n){r=i;break}if(r<0)continue;for(;r>0&&/[A-Za-z\u0370-\u03FF′]/.test(t[r-1]);)r--;let i=0;for(;"′"===t[e+1+i];)i++;t=t.slice(0,r)+Zt(t.slice(r,e+1),"x",i)+t.slice(e+1+i),e=r}return t}(t=(t=Nt(t)).replace(/(?<![A-Za-z])frac(\d)(\d)/g,"frac{$1}{$2}")),t=function(t){for(let e=0;e<t.length;e++){const n=e>0&&Tt.test(t[e-1]);let r,i=null,s=e;if(t.startsWith("frac{",e)){const n=Ct(t,e+4),r=n&&Ct(t,n[1]);i=r&&Rt(n[0],r[0]),i&&(s=r[1])}else if("d"===t[e]&&!n){let[n,r]=Ft(t,e+1),o="";if(Tt.test(t[r]??"")&&"/"===t[r+1]&&(o=t[r++]),"/"===t[r]&&"d"===t[r+1]&&Tt.test(t[r+2]??"")){const e=t[r+2],[,a]=Ft(t,r+3);i={n:n,of:o,by:e},s=a}}if(i){if(i.of)r=Zt(i.of,i.by,i.n);else{const[e,n]=Pt(t,s);if(!e)continue;r=Zt(e,i.by,i.n),s=n}t=t.slice(0,e)+r+t.slice(s),e+=3}}return t}(t),t.split("\\int").length>101)throw new Error("More than 100 integrals");for(let e=0;e<t.length;e++){const n=t[e],r=n=>t.slice(Math.max(0,e-n),e),i=n=>t.slice(Math.max(0,e-n),e+1);if("{"===n){if("\\begin"===r(6)){const n=It(t.slice(e+1));n&&(t=t.slice(0,e-6)+n)}}else if("["===n)"\\sqrt"===r(5)?t=t.slice(0,e-5)+"sqrt"+St(t.slice(e+1)):"sqrt"===r(4)&&(t=t.slice(0,e-4)+"sqrt"+St(t.slice(e+1)));else if("⌊"===n||"⌈"===n)t=t.slice(0,e)+Ot(t.slice(e));else if("t"===n)"\\int"===i(3)&&(t=t.slice(0,e-3)+Lt(t.slice(e+1)));else if("m"===n)"\\binom"===i(5)&&(t=t.slice(0,e-5)+"\\binom"+jt(t.slice(e+1)));else if("d"===n&&"dd"===i(1)&&"("===t[e+2]){const n=zt(t.slice(e+1));n&&(t=t.slice(0,e-1)+"der"+n)}}return(t=t.replace(/\\(?:text|textrm|textit|mathrm|mathit|mathbf|mathsf|operatorname)\{([A-Za-z])\}/g,"$1")).replace(/\\log/g,"log")}],["bars",function(t){for(let e=t.indexOf(d);e>=0;e=t.indexOf(d)){const n=Ce;t.startsWith("(der(",e+1)||n();const r=Fe(t,e+1,"(",")"),i=Fe(t,e+5,"(",")");(i<0||r!==i+1)&&n();const s=Re(t.slice(e+6,i));(s.length<2||s.length>3||!t.startsWith("|_",r+1))&&n();const o=r;let a,l;"{"===t[o+3]?(l=Fe(t,o+3,"{","}"),l<0&&n(),a=t.slice(o+4,l)):(l=o+3,a=t[l]??"");const[c,u,h]=s;a.trim()||n();const p=a.includes("=")?a:`${u}=${a}`;t=`${t.slice(0,e)}der(${c},${p}${h?`,${h}`:""})${t.slice(l+1)}`}return t}],["tidy",t=>t.replace(/ {2,}/g," ").trim()]],Ce=()=>{throw new Error("An evaluation bar (\\left. … \\right|_{x = a}) is read only after a derivative: \\left.\\frac{d}{dx} f\\right|_{x=a}")};function Fe(t,e,n,r){let i=0;for(let s=e;s<t.length;s++)if(t[s]===n)i++;else if(t[s]===r&&0===--i)return s;return-1}function Re(t){const e=[];let n=0,r=0;for(let i=0;i<t.length;i++)"([{".includes(t[i])?n++:")]}".includes(t[i])?n--:","===t[i]&&0===n&&(e.push(t.slice(r,i)),r=i+1);return e.push(t.slice(r)),e}function Pe(t,e={}){if("string"!=typeof t)throw new Error("Expression must be a string");const{text:n,strings:r}=function(t){const e=new Map;let n="",r=0;for(;r<t.length;){const i=t[r];if('"'!==i&&"'"!==i&&"`"!==i){n+=t[r++];continue}let s=r+1,o="",a=!1;for(;s<t.length&&(a||t[s]!==i);)a=!a&&"\\"===t[s],o+=t[s++];const l=Dt(e.size);e.set(l,i+o+i),n+=l,r=s+1}return{text:n,strings:e}}(Ht(t));let i=n.replace(/\t/g," ");e.evaluate&&(i=function(t,e,n){const r=/\\[A-Za-z]/.test(t);let i=0;for(;;){let s=t.indexOf("{{",i);if(s<0)return t;let o=!1;const a=r&&Ze.test(t.slice(0,s));if(Be(t,s)||a&&"{"===t[s+2]?s+=1:o=a,!t.startsWith("{{",s)){i=s;continue}const l=We(t,s);if(l<0)return t;let c=t.slice(s+2,l).trim();for(const[t,n]of e)c=c.split(t).join(n);try{let r=n(c);if(/^["'`]/.test(r)){const t=Dt(e.size);e.set(t,r),r=t}const a=t.slice(0,s).trimEnd(),u=t.slice(l+2).trimStart();/^[\d.]/.test(r)&&(/[\d.]$/.test(a)||/^[\d.]/.test(u))&&(r=`(${r})`),o&&(r=`{${r}}`),t=t.slice(0,s)+" "+r+" "+t.slice(l+2),i=s+1+r.length}catch{i=l+2}}}(i,r,e.evaluate));const s=[["strings",i]];for(const[t,e]of Te){if(i=e(i),i.length>1e5)throw new Error("The expression expands too much when read");s.push([t,i])}return{cleaned:i,stringMap:r,steps:s}}const Ze=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function Be(t,e){let n=0;for(;"\\"===t[e-1-n];)n++;return n%2==1}function We(t,e){let n=0;for(let r=e+2;r<t.length;r++){if(t.startsWith("}}",r)&&0===n)return r;"{"===t[r]?n++:"}"===t[r]&&n--}return-1}const De=Object.keys(g).filter(t=>100===g[t]&&/^[a-z]{2,}$/.test(t)),Ue=["frac"],He=[...Object.keys(L),"pi","tau","inf","infinity","exp"],Ge="\n cost costs coast cosine cosines cosy sine sines since sincere sinus single\n tank tanks tango stand stank\n point points print prints paint paints pint pints mint hint hints lint tint saint faint joint into\n spin spine pipe pipes pine pines pick picks pink pity pie pies pilot pivot pixel pizza piano\n order orders under wonder border render older elder ladder cider rider wider bidder\n logic logo logs blog clog login slog\n model models mode modes modal modest modern module modules\n limb limbs slim lime limo limit limits climb\n maxi minute minutes mince mind mine mines\n sums sumo summit rounds floors ceils means meant sect sects secs expo kiln\n meta metal metals taxi must mute muse nut nuts\n".trim().split(/\s+/),Ve=new Set([...He,...Ge,"true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),Xe=/^[a-zA-ZͰ-Ͽ]$/,Qe=new Set(["f","g","h","u","v","F","G","H"]),Je=t=>De.includes(t)||Ue.includes(t),Ye=[...De,...Ue,...He].sort((t,e)=>e.length-t.length),Ke=[...De,...Ue,"pi"].sort((t,e)=>e.length-t.length);function tn(t,e=Ye){const n=[];let r=0;for(;r<t.length;){const i=e.find(e=>t.startsWith(e,r))??t[r];n.push(i),r+=i.length}return n}function en(t){if(Je(t))return!0;const e=tn(t,Ke);return e.length>1&&Je(e[e.length-1])&&!Ve.has(t)}function nn(t,{mode:e="plain",followed:n=!0}={}){if(t.includes("′")&&/^[a-zA-Z′]+$/.test(t)&&!/^.′+$/.test(t))return t.match(/[a-zA-Z]′*/g);if(!((r=t).length>0&&[...r].every(t=>Xe.test(t)))||1===t.length||Ve.has(t)||Je(t))return[t];var r;if("Δ"===t[0]&&2===t.length)return[t];if("latex"===e)return rn(tn(t),n);if(t.length<=2)return[...t];const i=rn(tn(t,Ke),n),s=i.findIndex(t=>t.length>1);if(s<0)return[t];if("pi"===i[s]&&!i.some(t=>De.includes(t)))return 3===t.length?i:[t];const o=s;let a=0,l=0;for(const t of i.slice(s))a=1===t.length?a+1:0,l=Math.max(l,a);return o<=1&&l<=2?i:[t]}function rn(t,e){const n=t[t.length-1];return e||!De.includes(n)?t:[...t.slice(0,-1),...n]}const sn="§",on=/[A-Za-zͰ-Ͽ′]/,an=t=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(t);function ln(t,e="plain"){if("string"!=typeof t)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=t=>{r&&(an(r)?n.push(...function(t,e,n){if((t=>Ut.test(t))(t))return[t];if(y.includes(e))return function(t,e){if(/^[a-zA-Z]′+$/.test(t))return[s+t];if("if"===t.toLowerCase())return["\\:if"];if(1===t.length)return Qe.has(t)?[s+t]:[t];if(b(t))return[t];const n=nn(t,{mode:e,followed:!0});return n.length>1?n:t.length<=2?[...t]:[s+t]}(t,n);const r=void 0!==e&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(e);return nn(t,{mode:n,followed:r})}(r,t,e)):n.push(r),r="")};for(let e=0;e<t.length;e++){const o=t[e];if(o===sn){i(o);const r=t.indexOf(sn,e+1);if(r<0)throw new Error(`An unmatched ${sn}`);const a=t.slice(e,r+1);n.push(y.includes(t[r+1])?s+a:a),e=r;continue}if(an(r)&&/[0-9]/.test(o)&&b(r+o)){const{op:i,end:s}=cn(t,e,r+o);n.push(i),r="",e=s;continue}if(on.test(o)&&"′"!==o&&w(r)&&(n.push(r),r=""),on.test(o)&&(""===r?"′"!==o:an(r)))r+=o;else if(/[0-9]/.test(o)&&an(r)&&!en(r))r+=o;else if(an(r)&&i(" "===o?t[e+1]:o),"(){}[]".includes(o))r&&n.push(...un(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(b(r+o)){const{op:i,end:s}=cn(t,e,r+o);n.push(i),r="",e=s;continue}if(b(o)){i(o);const{op:r,end:s}=cn(t,e,o);n.push(r),e=s;continue}r+=o}else i(t[e+1]),"_"===o&&n.push("_")}if(i(void 0),n.some(t=>/^:/.test(t)))throw new Error("Unmatched ':'");return n}function cn(t,e,n){let r=e;for(;r+1<t.length&&b(n+t[r+1]);)n+=t[r+1],r++;return"!"===n&&"_"===t[r+1]&&r++,{op:n,end:r}}function un(t,e){if(!y.includes(e))return[t];if("\\"===t[0]){const e=t.slice(1);return[b(e)?e:s+e]}return w(t)?[t,"*"]:b(t)||Je(t)||w(t[0])?[t]:[s+t]}const hn=70,pn=100,fn="%mod",mn=t=>y.includes(t),dn=t=>v.includes(t),gn=t=>o(t)||g[t]===pn&&"_"!==t,bn=new Set(["\\comb","\\perm","comb","perm"]),$n={frac:"/","\\binom":"\\binom"},yn=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","∈","∉","true","false"]),vn={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class wn{constructor(t){this.tokens=t,this.pos=0,this.out=[],this.absDepth=0,this.frames=[]}peek(t=0){return this.tokens[this.pos+t]}next(){return this.tokens[this.pos++]}emit(...t){this.out.push(...t)}parseAll(){if(!this.tokens.length)throw new Error("Empty expression");this.parseExpression(0);const t=this.peek();if(void 0!==t)throw new Error(dn(t)?`Unmatched '${t}'`:`Unexpected '${t}'`);return this.out}parseExpression(t,e=!1){this.parseOperand(),this.absorb(t,e)}absorb(t,e=!1){for(;;){const n=this.peek();if(void 0===n||dn(n))return;const r=this.operatorAt(n,e);if(!r||r.lbp<=t)return;r.run()}}operatorAt(t,e){if("|"===t)return this.pipe();if(","===t)return{lbp:5,run:()=>{this.next(),this.frames.length&&(this.frames[this.frames.length-1].comma=!0),this.parseExpression(5),this.emit(",")}};if("?"===t)return{lbp:9,run:()=>this.ternary()};if("mod"===t)return{lbp:g.mod,run:()=>this.modulo()};if(t===fn)return{lbp:hn,run:()=>{this.next(),this.parseExpression(hn),this.emit("mod")}};if("pmod"===t)return{lbp:g.pmod,run:()=>{this.next(),this.parseScript(),this.emit("pmod")}};if("?:"===t)return{lbp:10,run:()=>{throw new Error("Unmatched ':'")}};if("!"===t)return{lbp:90,run:()=>{this.next(),this.emit("!")}};if("_"===t)return{lbp:pn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(bn.has(t))return{lbp:pn,run:()=>{this.next(),this.parseExpression(pn),this.emit(t)}};const n=g[t];if("="===t&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!gn(t)&&"\\not"!==t&&!(t in $n)){const e=$.has(t)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(e),this.emit(t)}}}return this.startsOperand(t)?this.implicit(t,e):null}implicit(t,e){return{lbp:e&&!gn(t)?71:hn,run:()=>{this.parseExpression(hn),this.emit("*")}}}startsOperand(t){return void 0===t||dn(t)||"|"===t?"|"===t:t!==fn&&(!!(mn(t)||gn(t)||t in $n)||!b(t))}pipe(){if(this.absDepth>0)return null;let t=0;for(let e=this.pos;e<this.tokens.length;e++)"|"===this.tokens[e]&&t++;const e="|"===this.peek(1);return t%2==0&&!e&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:g["|"],run:()=>{this.next(),e&&t%2==0&&this.next(),this.parseExpression(g["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(hn,!0),this.emit("mod")}equals(t){this.next(),this.parseExpression(t),yn.has(this.out[this.out.length-1])&&this.questionAhead()&&this.absorb(8),this.emit("=")}questionAhead(){let t=0;for(let e=this.pos;e<this.tokens.length;e++){const n=this.tokens[e];if(mn(n))t++;else if(dn(n)){if(0===t--)return!1}else{if(0===t&&","===n)return!1;if(0===t&&"?"===n)return!0}}return!1}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const t=this.next(),e=this.tokens[this.pos-2],n=this.peek();if(void 0===t)throw new Error("An operator is missing an operand at the end");if(mn(t))return this.bracket(t,"{"===t&&("∈"===e||"∉"===e));if("|"===t)return this.absolute();if("-"===t||"+"===t){return"^"===e&&(void 0===n||dn(n))||mn(e)&&dn(n)?this.emit("\\"+t):"+"===t?this.parseExpression(75):this.negate()}if("±"===t)return this.parseExpression(75),this.emit("pm");if("!"===t||"\\not"===t)return this.parseExpression(85),this.emit("\\not");if(t in $n)return this.parseScript(),this.parseScript(),this.emit($n[t]);if("log"===t)return this.logarithm();if("lim"===t&&"_"===n)return this.limit();if(("\\sumidx"===t||"\\prodidx"===t)&&"_"===n)return this.bigOperator(t);if(gn(t))return this.functionCall(t);if(t===fn)throw new Error("'%' is missing an operand");if(dn(t)||b(t))throw new Error(`'${t}' is missing an operand`);this.emit(t)}negate(){const t=this.out.length;this.parseExpression(75);const e=this.out.slice(t);1!==e.length||!w(e[0])&&"∞"!==e[0]?this.emit("neg"):this.out[t]="-"+e[0]}bracket(t,e=!1){if(dn(this.peek()))return void this.emit("∅",t+this.next());this.frames.push({comma:!1}),this.parseExpression(0);const{comma:n}=this.frames.pop(),r=this.peek();dn(r)&&(this.next(),n?this.emit(t+r):e&&this.emit("{}"))}absolute(){this.absDepth++,this.parseExpression(0),this.absDepth--,"|"===this.peek()&&this.next(),this.emit("abs")}parseScript(){const t=this.peek();if(mn(t))return this.parseOperand();if("-"===t||"+"===t)return this.parseOperand();if(gn(t))return this.parseOperand();if(this.next(),void 0===t||dn(t)||b(t))throw new Error("Missing a sub- or superscript");this.emit(t)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const t=this.out.length;this.parseScript();const e=this.out.splice(t);this.parseExpression(g["+"],!0),this.emit(...e,",","()","lim")}bigOperator(t){this.next();const e=this.out.length;this.parseScript();let n=this.out.splice(e);"^"===this.peek()&&(this.next(),this.parseScript(),n=[...n,...this.out.splice(e),","]),this.parseExpression(g["+"],!0),this.emit(...n,",","()",t)}functionCall(t){if(void 0===this.peek())return this.emit(t);let e=null;if("^"===this.peek()){this.next();const t=this.out.length;this.parseScript(),e=this.out.splice(t)}if(0===a(t)?.arity&&!mn(this.peek()))return this.emit(t);this.argument(),this.emit(t),e&&this.emit(...e,"^")}argument(){const t=this.peek();if(mn(t))return this.next(),this.bracket(t);this.parseExpression(hn,!0)}}function xn(t,e){t=function(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n],i=t=>"string"==typeof t&&/^[a-zA-Z]$/.test(t);if(Qe.has(r)&&"^ { - 1 } ("===t.slice(n+1,n+7).join(" ")){e.push(s+r+"⁻¹"),n+=5;continue}const[o,a,l]=t.slice(n+1,n+4),c=i(a)?a!==r:w(a);i(r)&&"e"!==r&&"("===o&&c&&")"===l?e.push(s+r):e.push(r)}return e}(t);const n=[];for(const r of t)b(r)||mn(r)||dn(r)||"_"===r||o(r)||w(r)?n.push(r):n.push(...Mn(r,e));return n}function Mn(t,e){if("%"===t)return[fn];if(!t.includes("%"))return kn(t,e);const n=t.split("%");n.length>1&&""===n[n.length-1]&&(n.pop(),n[n.length-1]+="%");const r=[];return n.forEach((t,n)=>{n>0&&r.push(fn),""!==t&&r.push(...kn(t,e))}),r}function kn(t,e){let n=0;for(;n<t.length&&w(t.slice(0,n+1));)n++;if(0===n||n===t.length)return[t];const r=t.slice(n);return"%"===r?[t]:[t.slice(0,n),...(i=r,xn(ln(i,e),e))];var i}for(const t of[$n,vn])Object.setPrototypeOf(t,null);const En=new Set(["()","[]","{}","(]","[)"]),An={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(m).map(t=>[t,"*"]))},Nn=new Set(["round","fixed","der"]),On=t=>o(t)||100===g[t];function Sn(t){const n=[],r=t=>{if(!n.length)throw new Error(`'${t}' is missing an operand`);return n.pop()},i=t=>t.list?t.list:[t],s=(t,e)=>{if(t.list)throw new Error(`A list of values needs brackets around it (near '${e}')`);return t};if(t.forEach((o,l)=>{if("∅"===o)return void n.push({list:[]});if(","===o){const t=r(o),e=r(o);return void n.push({list:[...i(e),...i(t)]})}if(En.has(o)){const e=i(r(o));if(!e.length&&!On(t[l+1]))throw new Error("Empty brackets");return void n.push(k(o,e))}const c=An[o]??o,u=a(c);if(!u){if("?"===o||"abs("===o)throw new Error(`Unmatched '${o[0]}'`);return void n.push(A(o))}let h;if(On(o)&&En.has(t[l-1])&&n[n.length-1]?.op===t[l-1])h=n.pop().args;else{let t=u.arity===e||Nn.has(c)?1:u.arity;if(n.length<t)throw new Error(`'${o}' needs ${t} operand${1===t?"":"s"}`);h=n.splice(n.length-t,t).map(t=>s(t,o))}const p=function(t,e){switch(t){case"sqrt":if(2===e.length)return k("root",e);break;case"round":if(1===e.length)return k("round",[e[0],x(0)]);break;case"sum":case"prod":{const n=e[1];if("op"===n?.type&&"symbol"===n.args[0]?.type&&(3===e.length&&"="===n.op||2===e.length&&"∈"===n.op))return k("sum"===t?"\\sumidx":"\\prodidx",e);break}case"det":if(e.length>1&&e.every(t=>"op"===t.type&&"[]"===t.op))return k("det",[k("[]",e)]);break;case"fixed":if(1===e.length)return k("fixed",[e[0],x(2)]);break;case"der":if(1===e.length)return k("der",[e[0],M("x")]);if(3===e.length)return function([t,e,n]){const r="number"===n.type?Number(n.value):NaN;if(!Number.isInteger(r)||r<1||r>20)throw new Error("der(f, x, n) needs n to be a whole number from 1 to 20");const i="op"===e.type&&"="===e.op?e:null,s=i?i.args[0]:e;let o=t;for(let t=0;t<r;t++)o=k("der",[o,i&&t===r-1?i:s]);return o}(e);break;case"log":if(2===e.length&&"symbol"===e[0].type&&"e"===e[0].value)return k("ln",[e[1]]);break;case"lim":return In(t,e),k("lim",function(t){const e=t=>"op"===t.type&&"^"===t.op&&"symbol"===t.args[1].type?_n[t.args[1].value]:void 0,[n,r,i]=t;if(2===t.length&&"op"===r.type&&"→"===r.op&&e(r.args[1])){const[t,i]=r.args;return[n,t,i.args[0],M(e(i))]}return 3===t.length&&e(i)?[n,r,i.args[0],M(e(i))]:t}(e));case"\\:if":if(2===e.length||3===e.length)return k("?:",[e[0],e[1],e[2]??M("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return In(t,e),k(t,e)}(c,h);m[o]&&"*"===p.op&&(p.written=m[o]),n.push(p)}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return s(n[0],"end")}const _n={"\\+":"r","\\-":"l"};function In(t,n){const{arity:r}=a(t);if(r!==e){if(n.length!==r){throw new Error(`'${t}' takes ${r} argument${1===r?"":"s"}, not ${n.length}`)}}else if(0===n.length&&!o(t))throw new Error(`'${t}' needs at least one argument`)}for(const t of[An,_n])Object.setPrototypeOf(t,null);const qn=new RegExp(`[${Object.keys(m).join("")}]`,"g"),Ln=t=>t.replace(qn,"*"),zn=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const jn=t=>/^[a-z][a-z0-9]*$/.test(t)&&b(t);function Tn(t){return t.includes("\\")?(t=function(t){for(let e=0;e<50;e++){const e=t.lastIndexOf("\\begin{cases}"),n=e<0?-1:t.indexOf("\\end{cases}",e);if(n<0)return t;const r=Mt(t.slice(e+13,n),"\\\\").map(t=>Mt(t,"&")).filter(t=>t.join("").trim());let i=null;for(let t=r.length-1;t>=0;t--){const e=r[t][0].trim(),n=xt(r[t].slice(1).join("&"));i=null!==i||n?`((${n||"true"}) ? (${e}) : ${i??"(unchanged)"})`:`(${e})`}t=t.slice(0,e)+(i??"")+t.slice(n+11)}return t}(t),t.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):t}let Cn=null;function Fn(t,e={}){const n={original:t};try{if("string"!=typeof t)throw new Error("Expression must be a string");const r=e.maxLength??5e3;if(t.length>r)throw new Error(`Longer than ${r} characters (options.maxLength)`);if(t.includes(""))throw new Error("The character U+E000 can't be read: MathZetta uses it to hold § in strings");if((t=function(t,e,n){if(!t.includes(e))return t;const r=Ht(t);let i="";for(let s=0;s<r.length;s++){const o=r[s];if('"'===o||"`"===o||"'"===o){const o=Gt(r,s);i+=t.slice(s,o+1).replaceAll(e,n),s=o}else i+=t[s]}return i}(t,sn,"")).includes(sn))throw new Error(`The character ${sn} can't be read: MathZetta uses it to mark names`);const i=/^\s*=(?!=)/.test(t);i&&(t=t.replace(/("(?:[^"]|"")*")|\$(?=[A-Za-z]{0,3}\d|[A-Za-z]{1,3}\$?\d)/g,(t,e)=>e??""));const s=i?[...new Set(t.replace(/"(?:[^"]|"")*"/g,"").match(/(?<![\w.])[A-Za-z]{1,3}\d+(?::[A-Za-z]{1,3}\d+)?(?![\w.(])/g)??[])]:[],{text:o,protectedNames:a}=function(t,e=[],n=[]){const r=new Map,i=new Map,s=t=>{let e=i.get(t);return void 0===e&&(e=`${sn}${r.size}${sn}`,r.set(e,t),i.set(t,e)),e};t=t.replace(zn,(t,e)=>jn(e.trim())?` ${e.trim()}`:s(e.trim()));for(const n of[...e].sort((t,e)=>e.length-t.length)){const e=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t=t.replace(new RegExp(`(?<![A-Za-z_])${e}(?![A-Za-z0-9_])`,"g"),()=>s(n))}for(const e of[...n].sort((t,e)=>e.length-t.length)){const n=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t=t.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(t,n,r)=>s(e)+(r?" * (":n))}return{text:t,protectedNames:r}}(Tn(t),e.names,[...e.values??[],...s]),l=(t=>/\\[A-Za-z]/.test(t)?"latex":"plain")(o),{cleaned:c,stringMap:u,steps:h}=function(t,e={}){const n=void 0===e.blocks?Cn:e.blocks;return Pe(t,{evaluate:n?t=>n(t,e.scope):void 0})}(o,{blocks:e.blocks,scope:e.scope}),p=t=>Xt(Xt(t,u),a).map(t=>"string"==typeof t?t.replaceAll("",sn):t);n.mode=l,n.cleaned=Ln(p([c])[0]),n.cleanSteps=h.map(([t,e])=>[t,Ln(e)]);const f=ln(c,l);n.tokens=f.map(Ln);const m=p(function(t,e="plain"){return new wn(xn(t,e)).parseAll().map(t=>vn[t]??t)}(f,l));n.rawPostfix=m.map(Ln);const d={},g=S(Sn(m),d);n.postfix=g,n.written=d,n.tree=O(g),Object.keys(d).length&&I(n.tree,t=>{d[t.id]&&(t.written=d[t.id])})}catch(t){n.error=t instanceof RangeError?"Nested too deeply":t.message}return n}function Rn(t,e={}){const n=Fn(t,e);if(n.error)throw new Error(`Failed to parse expression "${r=t,"string"==typeof r&&r.length>80?`${r.slice(0,77)}…`:r}": ${n.error}`);var r;return n.tree}const Pn=(t,e)=>"string"==typeof t?Rn(t,e):_(t),Zn=t=>Array.isArray(t)&&0===t.length,Bn=ot({add:(t,e)=>t+e,sub:(t,e)=>t-e,mul:(t,e)=>t*e,div:(t,e)=>t/e,isZero:t=>Math.abs(t)<1e-12,zero:()=>0,one:()=>1,size:Math.abs,charge:t=>{if(sr+=t/16,sr>ir)throw new Error("Too much to work out")},fail:t=>{throw new Error(t)}}),Wn=t=>it(t)&&(t.length>1||t[0].length>1),Dn=t=>st(t)&&!Wn(t),Un=t=>{const e=(n,r)=>{if(Array.isArray(n)&&Array.isArray(r)){if(n.length!==r.length)throw new Error("Lists of different lengths");return n.map((t,n)=>e(t,r[n]))}return Array.isArray(n)?n.map(t=>e(t,r)):Array.isArray(r)?r.map(t=>e(n,t)):t(n,r)};return e},Hn=(t,e)=>Wn(t)&&Wn(e)?Bn.times(t,e):Wn(t)&&Dn(e)?Bn.timesVector(t,e):Dn(t)&&Wn(e)?Bn.vectorTimes(t,e):Un((t,e)=>t*e)(t,e),Gn=(t,e)=>n=>{const r=n.length>1&&n.every(Dn)?n:n[0];if(!it(r))throw new Error(`${e}() needs a matrix`);return t(r)},Vn=(t,e)=>([n,r])=>{if(!st(n)||!st(r))throw new Error(`${e}() needs two lists`);return t(n,r)},Xn={det:Gn(Bn.det,"det"),inv:Gn(Bn.inverse,"inv"),inverse:Gn(Bn.inverse,"inverse"),transpose:Gn(Bn.transpose,"transpose"),trace:Gn(Bn.trace,"trace"),tr:Gn(Bn.trace,"tr"),rank:Gn(Bn.rank,"rank"),rref:Gn(Bn.rref,"rref"),identity:([t])=>{if(!Number.isInteger(t)||t<1||t>100)throw new Error("identity(n) takes a whole number from 1 to 100");return Bn.identity(t)},dot:Vn(Bn.dot,"dot"),cross:Vn(Bn.cross,"cross"),linsolve:([t,e])=>{if(!it(t)||!Array.isArray(e))throw new Error("linsolve() needs a matrix and a list");return Bn.solve(t,e)}},Qn=(t,e)=>t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args.map(t=>ar(t,e)):[ar(t,e)]),Jn={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},Yn=(t,e)=>e?Yn(e,t%e):Math.abs(t),Kn=(t,e)=>(t%e+e)%e,tr=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((t,n)=>tr(t,e[n])):t==e,er={neg:t=>-t,pm:t=>[t,-t],"!":t=>{if(!Number.isInteger(t)||t<0)return NaN;if(t>170)return 1/0;let e=1;for(let n=2;n<=t;n++)e*=n;return e},"\\not":t=>!t,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,det:t=>Xn.det([t]),ln:Math.log,loglog:t=>Math.log(Math.log(t)),logloglog:t=>Math.log(Math.log(Math.log(t))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:t=>1/Math.sin(t),sec:t=>1/Math.cos(t),cot:t=>1/Math.tan(t),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},nr={"+":(t,e)=>Array.isArray(t)||Array.isArray(e)?Un((t,e)=>t+e)(t,e):t+e,"-":(t,e)=>Array.isArray(t)||Array.isArray(e)?Un((t,e)=>t-e)(t,e):t-e,"*":Hn,"/":(t,e)=>Wn(e)?Hn(t,Bn.inverse(e)):Array.isArray(t)||Array.isArray(e)?Un((t,e)=>t/e)(t,e):t/e,"^":(t,e)=>{if(!Wn(t))return Array.isArray(t)?Un((t,e)=>t**e)(t,e):t**e;if(!Number.isInteger(e))throw new Error("A matrix to a power that is not a whole number");return Bn.power(t,BigInt(e))},mod:Kn,log:(t,e)=>Math.log(e)/Math.log(t),root:(t,e)=>e<0&&Number.isInteger(t)&&t%2!=0?-((-e)**(1/t)):e**(1/t),atan2:Math.atan2,round:(t,e)=>(t=>Math.sign(t)*Math.round(Math.abs(t)))(t*10**e)/10**e,"±":(t,e)=>[t+e,t-e],fixed:(t,e)=>{const n=Math.trunc(e);if(!(n>=0&&n<=100))throw new Error("fixed() takes 0 to 100 decimals");return Number(t).toFixed(n)},perm:(t,e)=>{if(!Number.isInteger(t)||!Number.isInteger(e)||e<0||e>t)return NaN;let n=1;for(let r=t-e+1;r<=t&&n!==1/0;r++)n*=r;return n},comb:(t,e)=>{if(!Number.isInteger(t)||!Number.isInteger(e)||e<0||e>t)return NaN;e=Math.min(e,t-e);let n=1;for(let r=1;r<=e&&n!==1/0;r++)n=n*(t-e+r)/r;return Math.round(n)},"=":tr,"===":(t,e)=>t===e,"≠":(t,e)=>!tr(t,e),"≠=":(t,e)=>t!==e,"≈":(t,e)=>Math.abs(t-e)<1e-9,"≡":(t,e)=>t===e,"∪":(t,e)=>[...new Set([...[].concat(t),...[].concat(e)])],"∩":(t,e)=>[].concat(t).filter(t=>[].concat(e).includes(t)),"<":(t,e)=>t<e,">":(t,e)=>t>e,"≤":(t,e)=>t<=e,"≥":(t,e)=>t>=e,"&":(t,e)=>t&&e,"|":(t,e)=>t||e,"\\xor":(t,e)=>Boolean(t)!==Boolean(e),"\\nor":(t,e)=>!(t||e),"\\nand":(t,e)=>!(t&&e)},rr={max:t=>Math.max(...t),min:t=>Math.min(...t),sum:t=>t.reduce((t,e)=>t+e,0),prod:t=>t.reduce((t,e)=>t*e,1),mean:t=>t.reduce((t,e)=>t+e,0)/t.length,gcd:t=>t.reduce(Yn,0),"()":t=>t,"[]":t=>t,"{}":t=>t};const ir=5e6;let sr=0,or=0;function ar(t,e){if(++sr>ir)throw new Error("Too much to work out");switch(t.type){case"number":return Number(t.value);case"string":return t.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(e,t.value))return e[t.value];if(Object.prototype.hasOwnProperty.call(Jn,t.value))return Jn[t.value];if(j(t.value))return Number(j(t.value));throw new Error(`No value for '${t.value}'`)}const n=et(t);if(n)return ar(n,e);const{op:r,args:i}=t;if("?:"===r)return ar(i[0],e)?ar(i[1],e):ar(i[2],e);if("∈"===r||"∉"===r)return function(t,e){const[n,r]=t.args,i=ar(n,e);let s;if("symbol"===r.type&&lr[r.value])return s=lr[r.value](i),"∈"===t.op?s:!s;if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,n]=r.args.map(t=>ar(t,e)),o="["===r.op[0]?i>=t:i>t,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const t=ar(r,e);s=Array.isArray(t)&&t.includes(i)}return"∈"===t.op?s:!s}(t,e);if("random"===r)return Math.random();if(("\\sumidx"===r||"\\prodidx"===r)&&3===i.length){const t="op"===i[1].type&&"="===i[1].op&&"symbol"===i[1].args[0].type,[n,s,o]=[i[0],t?i[1].args[1]:i[1],i[2]],a=t?i[1].args[0].value:q(n);if(!a)throw new Error(`Can't evaluate '${r}' without an index`);const l=ar(s,e),c=ar(o,e);if(!Number.isFinite(l)||!Number.isFinite(c)||c-l>1e6||Math.abs(l)>Number.MAX_SAFE_INTEGER||Math.abs(c)>Number.MAX_SAFE_INTEGER)throw new Error(`Can't evaluate '${r}' over that range`);let u="\\sumidx"===r?0:1;for(let t=l;t<=c;t++){const i=ar(n,{...e,[a]:t});u="\\sumidx"===r?u+i:u*i}return u}if("pmod"===r){const[t,n]=i,r=ar(n,e);if("op"===t.type&&["≡","="].includes(t.op)){const[n,i]=t.args.map(t=>ar(t,e));return(n-i)%r===0}return Kn(ar(t,e),r)}if("pmatrix"===r||"bmatrix"===r)return Qn(t,e);if("vmatrix"===r)return Bn.det(Qn(t,e));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(e,"T")){const t=ar(i[0],e);if(Wn(t))return Bn.transpose(t)}const s=i.map(t=>ar(t,e));if(r.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(Xn,r.slice(2)))return Xn[r.slice(2)](s);if(er[r]&&1===s.length)return er[r](s[0]);if(nr[r]&&2===s.length)return nr[r](s[0],s[1]);if(rr[r])return rr[r](s);throw new Error(`Can't evaluate '${r}'`)}const lr={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":t=>Number.isInteger(t)&&t>0,"ℚ":Number.isFinite,"ℂ":t=>"number"==typeof t&&!Number.isNaN(t)};for(const t of[Jn,er,nr,rr,lr,Xn])Object.setPrototypeOf(t,null);class cr extends Error{}class ur extends Error{}const hr={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let pr=0;function fr(t){if(pr+=t,pr>hr.steps)throw new ur("too much to work out")}const mr=(t,e)=>fr(Number(t)*(e/64)/128);let dr=0;const gr=t=>t<0n?-t:t,br=0xFFFFFFFFFFFFn,$r=t=>0n===t?0:gr(t).toString(2).length;function yr(t,e){for(t=gr(t),e=gr(e);e;)[t,e]=[e,t%e];return t}function vr(t,e=1n){if(0n===e)throw new cr("division by zero");if(e<0n&&(t=-t,e=-e),e>br&&(t>br||-t>br)){const n=Math.min(t.toString(16).length-(t<0n?1:0),e.toString(16).length)/16;if(pr+=1+n*n/2,pr>hr.steps)throw new ur("too much to work out")}const n=yr(t,e)||1n;return{n:t/n,d:e/n}}const wr=vr(0n),xr=vr(1n),Mr=(t,e)=>vr(t.n*e.d+e.n*t.d,t.d*e.d),kr=(t,e)=>vr(t.n*e.n,t.d*e.d),Er=(t,e)=>vr(t.n*e.d,t.d*e.n),Ar=t=>({n:-t.n,d:t.d}),Nr=(t,e)=>{const n=t.n*e.d-e.n*t.d;return n<0n?-1:n>0n?1:0},Or=t=>{const e=t.n/t.d;return t.n<0n&&e*t.d!==t.n?e-1n:e};function Sr(t){if(t.n<0n)return-Sr(Ar(t));const e=$r(t.n),n=$r(t.d);if(e<1e3&&n<1e3)return Number(t.n)/Number(t.d);const r=BigInt(Math.max(e,n)-1e3),i=t.d>>r;return 0n===i?t.n<0n?-1/0:1/0:Number(t.n>>r)/Number(i)}function _r(t){let e=String(t).trim(),n=1n;e.startsWith("-")&&(n=-1n,e=e.slice(1));const r=e.endsWith("..");r&&(e=e.slice(0,-2));let i=0;const s=e.search(/e/i);s>=0&&(i=Number(e.slice(s+1)),e=e.slice(0,s));const[o="",a=""]=e.split(".");if(!(/^\d*$/.test(o)&&/^\d*$/.test(a)&&o+a))throw new ur(`'${t}' is not a number`);let l;if(r&&a){let t=1;for(let e=1;2*e<=a.length;e++)if(a.slice(-e)===a.slice(-2*e,-e)){t=e;break}const e=a.slice(-t);let n=a;for(;n.endsWith(e);)n=n.slice(0,-t);const r=BigInt(n||"0"),i=BigInt(n+e);l=Mr(vr(BigInt(o||"0")),vr(i-r,(10n**BigInt(t)-1n)*10n**BigInt(n.length)))}else l=vr(BigInt(o+a||"0"),10n**BigInt(a.length));if(Math.abs(i)>hr.bits/3)throw new ur("too large to calculate");return i&&(l=i>0?kr(l,vr(10n**BigInt(i))):Er(l,vr(10n**BigInt(-i)))),n<0n?Ar(l):l}function Ir(t,e=0,n=0,r=null){return 0n===t.n?{kind:"x",c:wr,pi:0,e:0,root:null}:{kind:"x",c:t,pi:e,e:n,root:r}}const qr=(t,e=1n)=>Ir(vr(BigInt(t),BigInt(e))),Lr=Ir(xr,1),zr=Ir(xr,0,1),jr=t=>null!==t&&"object"==typeof t&&"x"===t.kind,Tr=t=>jr(t)&&!t.pi&&!t.e&&!t.root,Cr=t=>jr(t)?0n===t.c.n:0===t,Fr=t=>Tr(t)&&1n===t.c.d?t.c.n:null,Rr=(t,e)=>Object.assign(t,{group:e}),Pr=t=>({kind:"s",text:t});function Zr(t,e){return t&&e?t.n===e.n&&t.r===e.r:t===e}const Br=(t,e)=>0===Nr(t.c,e.c)&&t.pi===e.pi&&t.e===e.e&&Zr(t.root,e.root);function Wr(t){const e=Math.max(0,$r(t)-60);return e+Math.log2(Number(t>>BigInt(e)))}function Dr(t){if("number"==typeof t)return t;if(jr(t)){let e=Sr(t.c);if(t.pi&&(e*=Math.PI**t.pi),t.e&&(e*=Math.E**t.e),t.root){const n=function(t,e){const n=Number(t);return Number.isFinite(n)?n**(1/e):2**(Wr(t)/e)}(t.root.r,t.root.n);if(!(0n===t.c.n||0!==e&&Number.isFinite(e)&&Number.isFinite(n))){const e=Wr(t.c.n<0n?-t.c.n:t.c.n)-Wr(t.c.d)+Wr(t.root.r)/t.root.n+t.pi*Math.log2(Math.PI)+t.e*Math.LOG2E;return(t.c.n<0n?-1:1)*2**e}e*=n}return e}if("boolean"==typeof t)return t?1:0;throw new ur("not a number")}function Ur(t,...e){if(Number.isNaN(t))throw new cr("undefined");if(!Number.isFinite(t)&&e.every(Number.isFinite))throw new ur("too large to calculate");return t}const Hr=t=>"boolean"==typeof t?t:jr(t)?0n!==t.c.n:"number"==typeof t?0!==t:Boolean(t);function Gr(t){if("bigint"==typeof t)return Ir(vr(t));if("number"==typeof t)return Number.isFinite(t)?Ir(Number.isInteger(t)&&Math.abs(t)<=Number.MAX_SAFE_INTEGER?vr(BigInt(t)):_r(String(t))):t;if("boolean"==typeof t)return t;if("string"==typeof t)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(t.trim())?Ir(_r(t)):Bi(Rn(t),{});if(Array.isArray(t))return!t.group&&it(t)?Rr(t.map(t=>Rr(t.map(Gr),"[]")),"[]"):Rr(t.map(Gr),t.group||"()");if(jr(t)||"function"==typeof t)return t;throw new ur(`can't use ${typeof t} as a value`)}function Vr(t){return Array.isArray(t)?t.map(Vr):t&&"s"===t.kind?t.text:"boolean"==typeof t?t:Dr(t)}function Xr(t,e){if(t<2n)return t;const n=BigInt(e);let r=1n<<BigInt(Math.ceil($r(t)/e));for(;;){const e=((n-1n)*r+t/r**(n-1n))/n;if(e>=r)return r;r=e}}function Qr(t,e,n,r=0,i=0){if(0n===n)return Ir(wr);const{coef:s,root:o}=function(t,e){let n=1n,r=e;const i=BigInt(t),s=r<10n**24n?1000000n:10000n;let o=0;for(let t=2n;t<=s&&t*t<=r;t+=2n===t?1n:2n){const e=t**i;for(;r%e===0n;)r/=e,n*=t;o++}pr+=o/4;const a=Xr(r,t);if(a**i===r&&(n*=a,r=1n),1n===r)return{coef:n,root:null};for(let e=t;e>=2;e--){if(t%e!==0)continue;const i=Xr(r,e);if(i**BigInt(e)===r)return{coef:n,root:{n:t/e,r:i}}}return{coef:n,root:{n:t,r:r}}}(e,n);return o&&1===o.n?Ir(kr(t,vr(s*o.r)),r,i):Ir(kr(t,vr(s)),r,i,o)}function Jr(t,e){const n=kr(t.c,e.c);if($r(n.n)+$r(n.d)>hr.bits)return null;const r=t.pi+e.pi,i=t.e+e.e;if(!t.root||!e.root)return Ir(n,r,i,t.root||e.root);const s=Ai(t.root.n,e.root.n);if(s>hr.rootIndex)return null;const o=t.root.r**BigInt(s/t.root.n)*e.root.r**BigInt(s/e.root.n);return $r(o)>4e3?null:Qr(n,s,o,r,i)}function Yr(t){if(0n===t.c.n)throw new cr("division by zero");const e=Ir(Er(xr,t.c),-t.pi,-t.e);if(!t.root)return e;const{n:n,r:r}=t.root;return $r(r)*(n-1)>4e3?null:Jr(e,Qr(vr(1n,r),n,r**BigInt(n-1)))}function Kr(t,e){if(0n===e){if(0n===t.c.n)throw new cr("0^0 is undefined");return Ir(xr)}if(e<0n){const n=Yr(t);return n&&Kr(n,-e)}if(($r(t.c.n)+$r(t.c.d)+(t.root?$r(t.root.r):0))*Number(e)>hr.bits||e>100000n)return null;const n=vr(t.c.n**e,t.c.d**e),r=Number(e);if(!t.root)return Ir(n,t.pi*r,t.e*r);const{n:i,r:s}=t.root,o=s**(e/BigInt(i));return Qr(kr(n,vr(o)),i,s**(e%BigInt(i))||1n,t.pi*r,t.e*r)}function ti(t,e,n){if(!Tr(t)||n>1000n)return null;const r=Kr(t,e);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new cr("not a real number");o=!0,i=-i}const a=function(t,e){const n=t.n*t.d**BigInt(e-1);return $r(n)>4e3?null:Qr(vr(1n,t.d),e,n)}({n:i,d:s},Number(n));return a?o?Ir(Ar(a.c),a.pi,a.e,a.root):a:null}function ei(t){return e=>Array.isArray(e)?Rr(e.map(e=>ei(t)(e)),e.group):t(e)}function ni(t){const e=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new cr("lists of different lengths");return Rr(n.map((t,n)=>e(t,r[n])),n.group)}return i?Rr(n.map(t=>e(t,r)),n.group):s?Rr(r.map(t=>e(n,t)),r.group):t(n,r)};return e}const ri=ni((t,e)=>jr(t)&&jr(e)&&function(t,e){if(0n===t.c.n)return e;if(0n===e.c.n)return t;if(t.pi!==e.pi||t.e!==e.e||!Zr(t.root,e.root))return null;const n=Mr(t.c,e.c);return $r(n.n)+$r(n.d)>hr.bits?null:Ir(n,t.pi,t.e,t.root)}(t,e)||Ur(Dr(t)+Dr(e),Dr(t),Dr(e))),ii=ei(t=>jr(t)?Ir(Ar(t.c),t.pi,t.e,t.root):-Dr(t)),si=(t,e)=>ri(t,ii(e)),oi=ni((t,e)=>jr(t)&&jr(e)&&Jr(t,e)||Ur(Dr(t)*Dr(e),Dr(t),Dr(e))),ai=ni((t,e)=>{if(Cr(e))throw new cr("division by zero");if(jr(t)&&jr(e)){const n=Yr(e),r=n&&Jr(t,n);if(r)return r}return Ur(Dr(t)/Dr(e),Dr(t),Dr(e))}),li=ni((t,e)=>{if(jr(t)&&Tr(e)){const{n:n,d:r}=e.c,i=1n===r?Kr(t,n):ti(t,n,r);if(i)return i}const n=Dr(t),r=Dr(e);if(0===n&&0===r)throw new cr("0^0 is undefined");if(0===n&&r<0)throw new cr("division by zero");if(n<0&&!Number.isInteger(r))throw new cr("not a real number");const i=n**r;if(0===i&&0!==n)throw new ur("too small to calculate");return Ur(i,n,r)});function ci(t,e){if(Tr(t)&&Tr(e))return Nr(t.c,e.c);if(jr(t)&&jr(e)&&Br(t,e))return 0;const n=Dr(t),r=Dr(e);if(n===r)return 0;const i=jr(t)&&jr(e)?Math.max(Math.abs(n),Math.abs(r)):Math.max(1,Math.abs(n),Math.abs(r));return Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-r)<=1e-12*i?0:n<r?-1:1}function ui(t,e){return Array.isArray(t)||Array.isArray(e)?Array.isArray(t)&&Array.isArray(e)&&t.length===e.length&&t.every((t,n)=>ui(t,e[n])):t&&"s"===t.kind||e&&"s"===e.kind?Boolean(t&&"s"===t.kind&&e&&"s"===e.kind&&t.text===e.text):"boolean"==typeof t||"boolean"==typeof e?t===e:0===ci(t,e)}const hi={0:()=>qr(0),2:()=>qr(1,2),3:()=>Qr(vr(1n,2n),2,2n),4:()=>Qr(vr(1n,2n),2,3n),6:()=>qr(1)};function pi(t){t=(t%24+24)%24;const[e,n]=t<=6?[t,1]:t<=12?[12-t,1]:t<=18?[t-12,-1]:[24-t,-1],r=hi[e];return r?n<0?ii(r()):r():null}const fi=t=>pi(t+6),mi=(t,e)=>Math.abs(t)<1e-15&&Math.abs(e)>1e-6?0:t;function di(t,e){const n=function(t){if(Cr(t))return 0;if(!jr(t)||1!==t.pi||t.e||t.root)return null;const e=kr(t.c,vr(12n));return 1n!==e.d?null:Number((e.n%24n+24n)%24n)}(e);if(null!==n){const e=pi(n),r=fi(n);if(e&&r)switch(t){case"sin":return e;case"cos":return r;case"tan":return ai(e,r);case"cot":return ai(r,e);case"sec":return ai(qr(1),r);case"csc":return ai(qr(1),e)}}const r=Dr(e),i=mi(Math.sin(r),r),s=mi(Math.cos(r),r),o={sin:i,cos:s,tan:i/s,cot:s/i,sec:1/s,csc:1/i}[t];if(!Number.isFinite(o)&&Number.isFinite(r))throw new cr("undefined");return Ur(o)}function gi(t,e){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[t],r=e=>"arcsin"===t?pi(e):"arccos"===t?fi(e):fi(e)&&!Cr(fi(e))?ai(pi(e),fi(e)):null;if(jr(e))for(let t=n[0];t<=n[1];t++){const n=r(t);if(n&&jr(n)&&Br(n,e))return Ir(vr(BigInt(t),12n),1)}const i=Dr(e);if("arctan"!==t&&Math.abs(i)>1)throw new cr("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[t](i)}function bi(t){if(jr(t)){if(0n===t.c.n)throw new cr("ln 0 is undefined");if(t.c.n<0n)throw new cr("not a real number");if(1n===t.c.n&&1n===t.c.d&&!t.pi&&!t.root)return qr(t.e)}const e=Dr(t);if(e<=0)throw new cr(0===e?"ln 0 is undefined":"not a real number");return Math.log(e)}function $i(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*$i(1-t));const e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];let n=e[0];const r=(t-=1)+7+.5;for(let r=1;r<9;r++)n+=e[r]/(t+r);return Math.sqrt(2*Math.PI)*r**(t+.5)*Math.exp(-r)*n}function yi(t,e){const n=Fr(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null===n)throw new cr(`${e} needs whole numbers`);return n}const vi=(t,e)=>Number(e)*$r(t)>hr.bits;const wi=ei(t=>Tr(t)?Ir(vr(Or(t.c))):Gr(Math.floor(Dr(t)))),xi=ei(t=>Tr(t)?Ir(vr(-Or(Ar(t.c)))):Gr(Math.ceil(Dr(t))));function Mi(t,e){const n=Number(yi(e,"round"));if(Math.abs(n)>hr.places)throw new ur("too many decimal places");if(Tr(t)){const e=vr(10n**BigInt(Math.abs(n))),r=n>=0?kr(t.c,e):Er(t.c,e),i=Or(Mr(kr(vr(2n),vr(gr(r.n),r.d)),xr))/2n,s=vr(r.n<0n?-i:i);return Ir(n>=0?Er(s,e):kr(s,e))}if(n>15)return Dr(t);const r=10**n;return 0===r?0:Math.sign(Dr(t))*Math.round(Math.abs(Dr(t))*r)/r}const ki=(t,e)=>t.toFixed(Math.min(e,100))+(e>100?"0".repeat(e-100):"");function Ei(t,e){if(Cr(e))throw new cr("division by zero");if(Tr(t)&&Tr(e))return Ir(Mr(t.c,Ar(kr(e.c,vr(Or(Er(t.c,e.c)))))));const n=Dr(t),r=Dr(e);return Ur((n%r+r)%r)}const Ai=(t,e)=>t/Ni(t,e)*e,Ni=(t,e)=>e?Ni(e,t%e):t,Oi={pi:()=>Lr,"π":()=>Lr,tau:()=>Ir(vr(2n),1),"τ":()=>Ir(vr(2n),1),e:()=>zr,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},Si={abs:t=>jr(t)?Ir(vr(gr(t.c.n),t.c.d),t.pi,t.e,t.root):Math.abs(Dr(t)),floor:wi,ceil:xi,sqrt:t=>li(t,qr(1,2)),ln:ei(bi),loglog:ei(t=>bi(bi(t))),logloglog:ei(t=>bi(bi(bi(t)))),expm1:ei(t=>Cr(t)?qr(0):Math.expm1(Dr(t))),sinh:ei(t=>Cr(t)?qr(0):Math.sinh(Dr(t))),cosh:ei(t=>Cr(t)?qr(1):Math.cosh(Dr(t))),tanh:ei(t=>Cr(t)?qr(0):Math.tanh(Dr(t))),arcsinh:ei(t=>Cr(t)?qr(0):Math.asinh(Dr(t))),arccosh:ei(t=>{const e=Dr(t);if(e<1)throw new cr("not a real number");return 1===e?qr(0):Math.acosh(e)}),arctanh:ei(t=>{const e=Dr(t);if(Math.abs(e)>=1)throw new cr("undefined");return Cr(t)?qr(0):Math.atanh(e)}),"!":ei(function(t){const e=Fr(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null!==e){if(e<0n)throw new cr("factorial of a negative number");if(e>BigInt(hr.factorial))throw new ur("too large to calculate");mr(e,Number(e)*Math.log2(Number(e)+1));let t=1n;for(let n=2n;n<=e;n++)t*=n;return Ir(vr(t))}const n=Dr(t);if(n<0&&Number.isInteger(n))throw new cr("factorial of a negative number");return Ur($i(n+1),n)}),neg:ii,pm:t=>Rr([t,ii(t)],"pm"),"\\not":t=>!Hr(t),det:t=>Ci.det(t)};for(const t of["sin","cos","tan","csc","sec","cot"])Si[t]=ei(e=>di(t,e));for(const t of["arcsin","arccos","arctan"])Si[t]=ei(e=>gi(t,e));const _i=new Set(["pmatrix","bmatrix"]),Ii=t=>it(t)&&(_i.has(t.group)||"[]"===t.group&&t.every(t=>"[]"===t.group)&&(t.length>1||t[0].length>1)),qi=t=>st(t)&&!Ii(t)&&"pm"!==t.group,Li=ot({add:ri,sub:si,mul:oi,div:ai,charge:fr,isZero:t=>jr(t)?0n===t.c.n:Math.abs(Dr(t))<1e-12,zero:()=>qr(0),one:()=>qr(1),size:t=>Math.abs(Dr(t)),fail:t=>{throw new cr(t)},make:(t,e)=>Rr(t.map(t=>Rr(t,"[]")),e&&e.group?e.group:"bmatrix")}),zi=(t,e)=>Rr(t,e&&e.group?e.group:"[]"),ji=(t,e)=>(...n)=>{const r=n.length>1&&n.every(qi)?Rr(n.map(t=>Rr(t,"[]")),"[]"):n[0];if(n.length>1&&r===n[0])throw new ur(`${t} of more than one thing`);if(!Ii(r))throw new ur(`${t} of something that isn't a matrix`);return e(r)};function Ti(t,e){return Ii(t)&&Ii(e)?Li.times(t,e):Ii(t)&&qi(e)?zi(Li.timesVector(t,e),e):qi(t)&&Ii(e)?zi(Li.vectorTimes(t,e),t):oi(t,e)}const Ci={det:ji("det",Li.det),inv:ji("inv",Li.inverse),inverse:ji("inverse",Li.inverse),transpose:ji("transpose",Li.transpose),trace:ji("trace",Li.trace),tr:ji("tr",Li.trace),rank:ji("rank",t=>qr(Li.rank(t))),rref:ji("rref",Li.rref),identity:t=>{const e=Fr(t);if(null===e||e<1n||e>100n)throw new ur("identity(n) needs a whole number n");return Li.identity(Number(e))},dot:(t,e)=>{if(!qi(t)||!qi(e))throw new ur("dot of something that isn't a vector");return Li.dot(t,e)},cross:(t,e)=>{if(!qi(t)||!qi(e))throw new ur("cross of something that isn't a vector");return zi(Li.cross(t,e),t)},linsolve:(t,e)=>{if(!Ii(t)||!Ii(e)&&!qi(e))throw new ur("linsolve(A, b) needs a matrix and a vector");return Ii(e)?Li.solve(t,e):zi(Li.solve(t,e),e)}};function Fi(t,e){const n=t.args.map(t=>Rr("op"===t.type&&"[]"===t.op?t.args.map(e):[e(t)],"[]"));if(n.some(t=>t.length!==n[0].length))throw new cr("rows of different lengths");return Rr(n,"vmatrix"===t.op?"bmatrix":t.op)}const Ri={"+":ri,"-":si,"*":Ti,"/":(t,e)=>Ii(e)?Ti(t,Li.inverse(e)):ai(t,e),"^":function(t,e){if(!Ii(t))return li(t,e);const n=Fr(e);if(null===n)throw new ur("a matrix to a power that is not a whole number");return Li.power(t,n)},"±":(t,e)=>Rr([ri(t,e),si(t,e)],"pm"),mod:ni(Ei),log:ni(function(t,e){if(jr(t)&&Br(t,zr))return bi(e);const n=Dr(t),r=Dr(e);if(n<=0||1===n)throw new cr("not a valid base");if(r<=0)throw new cr(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(Tr(t)&&Tr(e))for(let n=1n;n<=12n;n++){const r=Math.round(i*Number(n));if(Math.abs(i*Number(n)-r)>1e-9)continue;const s=Kr(t,BigInt(r)),o=Kr(e,n);if(s&&o&&Br(s,o))return Ir(vr(BigInt(r),n))}return i}),root:ni((t,e)=>li(e,ai(qr(1),t))),atan2:(t,e)=>Math.atan2(Dr(t),Dr(e)),round:Mi,fixed:function(t,e){const n=Number(yi(e,"fixed"));if(n<0)throw new cr("fixed needs 0 or more decimal places");const r=Mi(t,e);if(Tr(r)){const t=r.c.n*10n**BigInt(n)/r.c.d,e=(t<0n?-t:t).toString().padStart(n+1,"0");return Pr(`${t<0n?"-":""}${e.slice(0,e.length-n)}${n?"."+e.slice(-n):""}`)}return Pr(ki(Dr(r),n))},perm:function(t,e){const n=yi(t,"permutations"),r=yi(e,"permutations");if(r<0n||r>n)throw new cr("undefined");if(r>BigInt(hr.terms)||vi(n,r))throw new ur("too large to calculate");mr(r,Number(r)*$r(n));let i=1n;for(let t=n-r+1n;t<=n;t++)i*=t;return Ir(vr(i))},comb:function(t,e){const n=yi(t,"combinations");let r=yi(e,"combinations");if(r<0n||r>n)throw new cr("undefined");if(n-r<r&&(r=n-r),r>BigInt(hr.terms)||vi(n,r))throw new ur("too large to calculate");mr(2n*r,Number(r)*$r(n));let i=1n;for(let t=1n;t<=r;t++)i=i*(n-r+t)/t;return Ir(vr(i))},"=":(t,e)=>ui(t,e),"===":(t,e)=>ui(t,e),"≠":(t,e)=>!ui(t,e),"≠=":(t,e)=>!ui(t,e),"≈":(t,e)=>Math.abs(Dr(t)-Dr(e))<=1e-9*Math.max(1,Math.abs(Dr(t)),Math.abs(Dr(e))),"<":(t,e)=>ci(t,e)<0,">":(t,e)=>ci(t,e)>0,"≤":(t,e)=>ci(t,e)<=0,"≥":(t,e)=>ci(t,e)>=0,"&":(t,e)=>Hr(t)&&Hr(e),"|":(t,e)=>Hr(t)||Hr(e),"\\xor":(t,e)=>Hr(t)!==Hr(e),"\\nor":(t,e)=>!(Hr(t)||Hr(e)),"\\nand":(t,e)=>!(Hr(t)&&Hr(e))},Pi={sum:t=>t.reduce((t,e)=>ri(t,e),qr(0)),prod:t=>t.reduce((t,e)=>oi(t,e),qr(1)),max:t=>t.reduce((t,e)=>ci(e,t)>0?e:t),min:t=>t.reduce((t,e)=>ci(e,t)<0?e:t),mean:t=>ai(Pi.sum(t),qr(t.length)),gcd:t=>Ir(vr(t.map(t=>yi(t,"gcd")).reduce(yr)))},Zi=["∈","∉","∪","∩","pmod","random","(]","[)"];function Bi(t,e){if(++pr>hr.steps)throw new ur("too much to work out");switch(t.type){case"number":return Ir(_r(t.value));case"string":return Pr(t.value.slice(1,-1));case"symbol":return Wi(t.value,e)}const n=et(t);if(n)return Bi(n,e);const{op:r,args:i}=t,s=t=>Bi(t,e);if("?:"===r)return Hr(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(t=>"op"!==t.type))return Wi(`${i[0].value}_${i[1].value}`,e);throw new ur("subscript")}if("der"===r)return function(t,e){const[n,r]=t.args;if("op"===r.type&&"="===r.op){const t=Gi(r.args[0]);if(!t)throw new ur("a derivative at a point names its variable: der(f, x = a)");return Vi(n,t,Dr(Bi(r.args[1],e)),e)}const i=Gi(r);if(!i||!e[Di]?.has(i))throw new ur(`a derivative needs a point: der(f, ${i||"x"} = a)`);return Vi(n,i,Dr(e[i]),e)}(t,e);if("int"===r)return function(t,e){const[n,r,i,s]=t,o=t=>t&&"symbol"===t.type&&/^[a-zA-Zʹ-Ͽ]$/.test(t.value);let a,l,c;if(4===t.length)[a,l,c]=[Gi(r),i,s];else{if(3!==t.length||o(r))throw new ur("an integral needs limits to be calculated");[a,l,c]=[q(n)||"x",r,i]}let u=Dr(Bi(l,e)),h=Dr(Bi(c,e));if(u===h)return qr(0);let p=1;u>h&&([u,h]=[h,u],p=-1);const f=Hi(n,a,e),{value:m,error:d}=Xi(f,u,h);return ts(p*m,d)}(i,e);if("lim"===r)return function(t,e){const[n,r,i,s]=t;let o,a,l=0;if(2===t.length&&"op"===r.type&&"→"===r.op)[o,a]=[Gi(r.args[0]),r.args[1]];else if(2===t.length)[o,a]=[q(n),r];else{if(!(t.length>=3))throw new ur("a limit needs a point");[o,a]=[Gi(r),i]}if(4===t.length){const t="op"===s.type?"":String(s.value).toLowerCase();l=t.startsWith("r")||"+"===t?1:-1}if(!o)throw new ur("a limit needs a variable");const c=Bi(a,e),u=Dr(c),h=Hi(n,o,e);let p,f;if(Number.isFinite(u))if(l){({value:p,error:f}=Ji(t=>h(u+l*t*Math.max(1,Math.abs(u)))));try{const t=Bi(n,Ui(e,o,c));if(Math.abs(Dr(t)-p)<=Math.max(f,1e-6*Math.max(1,Math.abs(p))))return t}catch(t){if(!(t instanceof cr))throw t}}else{const t=Ji(t=>h(u+t*Math.max(1,Math.abs(u)))),r=Ji(t=>h(u-t*Math.max(1,Math.abs(u))));if(t.value===r.value)({value:p,error:f}=t);else{if(!(Number.isFinite(t.value)&&Number.isFinite(r.value)&&Math.abs(t.value-r.value)<=1e-6*Math.max(1,Math.abs(t.value))))throw new cr("the limit does not exist");p=(t.value+r.value)/2,f=Math.max(t.error,r.error,Math.abs(t.value-r.value))}try{const t=Bi(n,Ui(e,o,c));if(Math.abs(Dr(t)-p)<=1e-6*Math.max(1,Math.abs(p)))return t}catch(t){if(!(t instanceof cr))throw t}}else({value:p,error:f}=Ji(t=>h(Math.sign(u)/t)));return Number.isFinite(p)?ts(p,f):p}(i,e);if("\\sumidx"===r||"\\prodidx"===r)return function(t,e,n){const[r,i,s]=e;if(e.length<3)throw new ur("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=q(r)||"n";const l=yi(Bi(a,n),"a sum"),c=Bi(s,n),u=t?ri:oi;if(c===1/0){if(!t)throw new ur("an infinite product");return function(t,e){const n=[],r=[];let i=0,s=e;for(let o=4;o<=17;o++){const a=2**o;for(;s<e+a;s++){const e=t(s);if(!Number.isFinite(e))throw new cr("undefined");i+=e}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2]&&!Ki(t,e,s))return ts(i,0)}if(Ki(t,e,s))throw new cr("the series diverges");const o=r[r.length-1]-r[r.length-2],a=r[r.length-2]-r[r.length-3],l=r[r.length-3]-r[r.length-4],c=o/a;if(Math.abs(o)>1e-12&&c>=.999&&a/l>=.999)throw new cr("the series diverges");if(Math.abs(o)>1e-6*Math.max(1,Math.abs(i))&&c>=.9)throw new ur("the series grows too slowly to tell whether it has a sum");const u=n.slice(-7).map(t=>1/t),h=r.slice(-7),p=r.slice(-8,-1),f=(t,e)=>{const n=e.slice();for(let e=1;e<t.length;e++)for(let r=0;r<t.length-e;r++)n[r]=(t[r+e]*n[r]-t[r]*n[r+1])/(t[r+e]-t[r]);return n[0]},m=f(u,h),d=f(n.slice(-8,-1).map(t=>1/t),p);return ts(m,Math.abs(m-d))}(Hi(r,o,n),Number(l))}const h=yi(c,"a sum");if(h-l+1n>BigInt(hr.terms))throw new ur("too many terms to add one by one");let p=qr(t?0:1);for(let t=l;t<=h;t++)p=u(p,Bi(r,Ui(n,o,Ir(vr(t)))));return p}("\\sumidx"===r,i,e);if(["()","[]","{}"].includes(r))return Rr(i.map(s),r);if("pmatrix"===r||"bmatrix"===r)return Fi(t,s);if("vmatrix"===r)return Li.det(Fi(t,s));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(e,"T")){const t=s(i[0]);if(Ii(t))return Li.transpose(t)}if("pmod"===r)return function([t,e],n){const r=n(e);return"op"===t.type&&["≡","="].includes(t.op)&&2===t.args.length?Cr(Ei(si(n(t.args[0]),n(t.args[1])),r)):Ei(n(t),r)}(i,s);if("∈"===r||"∉"===r){const e=function(t,e){const[n,r]=t.args,i=e(n);let s;if("symbol"===r.type&&["ℤ","ℕ","ℚ","ℝ"].includes(r.value)&&jr(i))s="ℝ"===r.value||("ℚ"===r.value?Tr(i):Tr(i)&&1n===i.c.d&&("ℤ"===r.value||i.c.n>0n));else if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,n]=r.args.map(e),o=ci(i,t),a=ci(i,n);s=("["===r.op[0]?o>=0:o>0)&&("]"===r.op[1]?a<=0:a<0)}else{if("op"!==r.type||"{}"!==r.op)return;s=r.args.some(t=>ui(i,e(t)))}return"∈"===t.op?s:!s}(t,s);if(void 0!==e)return e}if(Zi.includes(r))return function(t,e){const n={};for(const[t,r]of Object.entries(e))"function"!=typeof r&&(n[t]=Vr(r));try{return Gr(function(t,e={}){0===or&&(sr=0),or++;try{return ar(Pn(t),e)}finally{or--}}(t,n))}catch(t){throw new ur(t.message)}}(t,e);if(r.startsWith("\\:")){const t=r.slice(2),n=Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if("function"!=typeof n&&Object.prototype.hasOwnProperty.call(Ci,t))return Ci[t](...i.map(s));if("function"!=typeof n)throw new ur(`no function ${r.slice(2)}`);return Gr(n(...i.map(t=>Vr(s(t)))))}if(Si[r]&&1===i.length)return Si[r](s(i[0]));if(Ri[r]&&2===i.length)return Ri[r](s(i[0]),s(i[1]));if(Pi[r])return Pi[r](i.map(s));throw new ur(`can't calculate '${r}'`)}function Wi(t,e){if(Object.prototype.hasOwnProperty.call(e,t))return e[t];if(Object.prototype.hasOwnProperty.call(Oi,t))return Oi[t]();if(j(t))return Ir(_r(j(t)));throw new ur(`no value for '${t}'`)}const Di=Symbol("bound"),Ui=(t,e,n)=>({...t,[e]:n,[Di]:new Set([...t[Di]??[],e])});function Hi(t,e,n){return r=>{try{return Dr(Bi(t,Ui(n,e,r)))}catch(t){if(t instanceof cr)return NaN;throw t}}}const Gi=t=>"symbol"===t.type?t.value:null;function Vi(t,e,n,r){const i=Hi(t,e,r);if(!Number.isFinite(i(n)))throw new cr("undefined");const s=1e-6*Math.max(1,Math.abs(n)),o=(i(n+s)-i(n))/s,a=(i(n)-i(n-s))/s;if(!Number.isFinite(o)||!Number.isFinite(a)||Math.abs(o-a)>.001*Math.max(1,Math.abs(o)))throw new cr("not differentiable here");let l=.1*Math.max(1,Math.abs(n));const c=1.4,u=[[(i(n+l)-i(n-l))/(2*l)]];let h=u[0][0],p=1/0;for(let t=1;t<12;t++){l/=c,u[t]=[(i(n+l)-i(n-l))/(2*l)];let e=c*c;for(let n=1;n<=t;n++){u[t][n]=(u[t][n-1]*e-u[t-1][n-1])/(e-1),e*=c*c;const r=Math.max(Math.abs(u[t][n]-u[t][n-1]),Math.abs(u[t][n]-u[t-1][n-1]));r<=p&&(p=r,h=u[t][n])}if(Math.abs(u[t][t]-u[t-1][t-1])>=2*p)break}if(!Number.isFinite(h))throw new cr("not differentiable here");return ts(h,p)}function Xi(t,e,n){if(e===-1/0&&n===1/0){const e=Xi(t,-1/0,0),n=Xi(t,0,1/0);return{value:e.value+n.value,error:e.error+n.error}}return n===1/0?Qi(n=>t(e+n/(1-n))/((1-n)*(1-n)),0,1):e===-1/0?Qi(e=>t(n-e/(1-e))/((1-e)*(1-e)),0,1):Qi(t,e,n)}function Qi(t,e,n,r=0){try{return function(t,e,n){const r=(n-e)/2,i=4;let s=1,o=0,a=NaN,l=NaN,c=0;const u=s=>{const o=Math.PI/2*Math.sinh(Math.abs(s)),a=Math.exp(-2*o),l=2*r*a/(1+a),u=r*(Math.PI/2)*Math.cosh(s)*(4*a)/((1+a)*(1+a));if(0===l||0===u)return 0;const h=s>0?n-l:e+l;if(0!==s&&(h<=e||h>=n))return 0;const p=t(0===s?(e+n)/2:h);if(!Number.isFinite(p)){if(l<1e-6*r)return 0;throw new cr("the integral diverges")}return Math.abs(s)>i-.5&&(c=Math.max(c,Math.abs(u*p))),u*p};o=u(0);for(let t=s;t<=i;t+=s)o+=u(t)+u(-t);a=s*o;for(let t=1;t<=8;t++){s/=2;for(let t=s;t<=i;t+=2*s)o+=u(t)+u(-t);l=a,a=s*o;const e=Math.max(1,Math.abs(a));if(c>1e-8*e)throw new cr("the integral diverges");if(t>=3&&Math.abs(a-l)<=1e-13*e)break}const h=Math.abs(a-l);if(!Number.isFinite(a)||h>1e-6*Math.max(1,Math.abs(a)))throw new cr("the integral does not converge");return{value:a,error:h}}(t,e,n)}catch(t){if(!(t instanceof cr)||"the integral does not converge"!==t.message||r>=10)throw t}const i=(e+n)/2,s=Qi(t,e,i,r+1),o=Qi(t,i,n,r+1);return{value:s.value+o.value,error:s.error+o.error}}function Ji(t){const e=Yi(t),n=Yi(e=>t(.7548776662466927*e));if(e.value===n.value)return e;if(!Number.isFinite(e.value)||!Number.isFinite(n.value))throw new cr("the limit does not exist");const r=Math.max(1,Math.abs(e.value)),i=Math.max(e.error,n.error,1e-6*r);if(i>.001*r)throw new cr("the limit could not be found");if(Math.abs(e.value-n.value)<=i)return e;throw new cr("the limit does not exist")}function Yi(t){const e=[],n=[];for(let r=0;r<30;r++){const i=.1/2**r,s=t(i);Number.isFinite(s)&&(e.push(i),n.push(s))}if(n.length<6)throw new cr("undefined");const r=n.slice(1).map((t,e)=>t-n[e]).slice(-6);if(r.every(t=>Math.sign(t)===Math.sign(r[0])&&0!==t)&&Math.abs(r[5])>=.95*Math.abs(r[0])&&Math.abs(n[n.length-1])>10)return{value:Math.sign(r[0])*(1/0),error:0};const i=t=>{const r=e.slice(t,t+8),i=n.slice(t,t+8);for(let t=1;t<r.length;t++)for(let e=0;e<r.length-t;e++)i[e]=(r[e+t]*i[e]-r[e]*i[e+1])/(r[e+t]-r[e]);return i[0]};let s=null;for(let t=0;t+9<=n.length;t++){const e=i(t),n=i(t+1),r=Math.abs(e-n);Number.isFinite(e)&&(!s||r<s.error)&&(s={value:e,error:r})}const o=t=>{const e=n[t+1]-n[t],r=n[t+2]-n[t+1];return r===e?n[t+2]:n[t+2]-r*r/(r-e)},a=t=>(n[t+2]-n[t+1])/(n[t+1]-n[t]),l=t=>[t,t+1].every(t=>a(t)>0&&a(t)<.95)&&Math.abs(a(t)-a(t+1))<.05;for(let t=0;t+3<n.length;t++){if(!l(t))continue;const e=o(t),n=Math.abs(e-o(t+1));Number.isFinite(e)&&(!s||n<s.error)&&(s={value:e,error:n})}const c=n[n.length-1],u=Math.abs(c-n[n.length-2]);if(!s||s.error>Math.max(u,1e-6*Math.max(1,Math.abs(c)))){if(u<=1e-6*Math.max(1,Math.abs(c)))return{value:c,error:10*u};throw new cr("the limit could not be found")}return s}function Ki(t,e,n){const r=e=>Math.max(...Array.from({length:8},(n,r)=>Math.abs(t(e+r)))),i=r(n);return i>1e-12&&i>=.5*r(e+Math.floor((n-e)/16))}function ts(t,e=0){if(!Number.isFinite(t))return t;const n=Math.max(1e-10,4*e)*Math.max(1,Math.abs(t));if(n>1e-6*Math.max(1,Math.abs(t)))return function(t,e){if(!(e>0)||0===t)return t;const n=Math.floor(-Math.log10(e/Math.abs(t)));return n>=15?t:Number(t.toPrecision(Math.max(1,n)))}(t,e);if(Math.abs(t)<=Math.max(4*e,1e-15))return qr(0);if(Math.abs(t)<1e-10)return t;const r=[[qr(1),1e3],[Lr,100],[Ir(xr,2),100],[zr,100],...[2n,3n,5n,6n,7n].map(t=>[Ir(xr,0,0,{n:2,r:t}),100])];for(const[e,i]of r){const r=t/Dr(e),s=es(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*Dr(e)<=n)return Jr(Ir(s),e)}return t}function es(t,e){if(!Number.isFinite(t)||Math.abs(t)>1e12)return null;let[n,r,i,s]=[0,1,1,0],o=t;for(let t=0;t<40;t++){const t=Math.floor(o),a=t*r+n,l=t*s+i;if(l>e)break;if([n,r,i,s]=[r,a,s,l],Math.abs(o-t)<1e-15)break;o=1/(o-t)}return s?vr(BigInt(r),BigInt(s)):null}function ns(t,e){if("boolean"==typeof t)return String(t);if(t&&"s"===t.kind)return JSON.stringify(t.text);if(Array.isArray(t)){if("pm"===t.group&&2===t.length&&ui(t[1],ii(t[0])))return`±${rs(t[0],e)}`;if(_i.has(t.group)&&it(t))return`${t.group}(${t.map(t=>`[${t.map(t=>ns(t,e)).join(", ")}]`).join(", ")})`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[t.group]||"{}";return n+t.map(t=>ns(t,e)).join(", ")+r}return"number"==typeof t?is(t,e):e.decimal||null!==e.places?function(t,e){if(Tr(t)&&null===e.places){let n=t.c.d,r=0,i=0;for(;n%2n==0n;)n/=2n,r++;for(;n%5n==0n;)n/=5n,i++;const s=Math.max(r,i);if(1n===n&&s<=e.digits){const n=t.c.n*10n**BigInt(s)/t.c.d,r=n<0n,i=gr(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=e.maxDigits)return(r?"-":"")+ss(o)}}return Tr(t)&&null!==e.places?ns(Mi(t,qr(e.places)),{...e,places:null,decimal:!0}):is(Dr(t),e)}(t,e):function(t,e){const{c:n}=t,r=gr(n.n);if(r.toString().length>e.maxDigits||n.d.toString().length>e.maxDigits)return function(t,e){if(!Tr(t))return is(Dr(t),e);if(1n!==t.c.d){const n=Dr(t);if(0!==n&&Number.isFinite(n))return is(n,e);const r=gr(t.c.n),i=t.c.d,s=e.digits+1-(r.toString().length-i.toString().length),o=(s>=0?r*10n**BigInt(s)/i:r/(i*10n**BigInt(-s))).toString(),a=((BigInt(o.slice(0,e.digits+1))+5n)/10n).toString(),l=o.length-1-s+(a.length>e.digits?1:0),c=ss(`${a[0]}.${a.slice(1,e.digits)}`);return`${t.c.n<0n?"-":""}${c}*10^(${l})`}const n=gr(t.c.n).toString(),r=BigInt(n.slice(0,e.digits+1)),i=((r+5n)/10n).toString(),s=n.length-1+(i.length>e.digits?1:0),o=ss(`${i[0]}.${i.slice(1,e.digits)}`);return`${t.c.n<0n?"-":""}${o}*10^(${s})`}(t,e);const i=(t,e)=>1===e?t:`${t}^${e}`,s=[],o=[];t.pi>0&&s.push(i("pi",t.pi));t.pi<0&&o.push(i("pi",-t.pi));t.e>0&&s.push(i("e",t.e));t.e<0&&o.push(i("e",-t.e));t.root&&s.push(2===t.root.n?`sqrt(${t.root.r})`:`root(${t.root.n}, ${t.root.r})`);1n===r&&s.length||s.unshift(r.toString());1n!==n.d&&o.unshift(n.d.toString());const a=t=>t.length>1?`(${t.join("*")})`:t[0],l=o.length?`${a(s)}/${a(o)}`:s.join("*");return(n.n<0n?"-":"")+l}(t,e)}const rs=(t,e)=>{const n=ns(t,e);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function is(t,e){if(t===1/0)return"∞";if(t===-1/0)return"-∞";if(Object.is(t,-0)||0===t)return"0";if(null!==e.places&&Math.abs(t)<1e21)return ki(t,e.places);const n=Math.abs(t);if(n>=1e15||n<1e-6){const[n,r]=t.toExponential(e.digits-1).split("e");return`${ss(n)}*10^(${Number(r)})`}return String(Number(t.toPrecision(e.digits)))}const ss=t=>t.includes(".")?t.replace(/\.?0+$/,""):t;function os(t,e={},n={}){0===dr&&(pr=0);const r="string"==typeof t?Rn(t):_(t),i={};for(const[t,n]of Object.entries(e))i[t]=Gr(n);let s;dr++;try{s=Bi(r,i)}finally{dr--}const o={decimal:!1,places:null,digits:12,maxDigits:50,...n};if(void 0===o.places&&(o.places=null),null!==o.places&&!(Number.isInteger(o.places)&&o.places>=0&&o.places<=hr.places))throw new ur(`places is a whole number from 0 to ${hr.places}`);const a=t=>Array.isArray(t)?t.every(a):"number"!=typeof t;return{value:Vr(s),text:ns(s,o),exact:a(s)}}function as(t,e={}){let n=t.trim();const r={},i=/^(~|≈)\s*(\d+)?/.exec(n);i&&(r.decimal=!0,void 0!==i[2]&&(r.places=Number(i[2])),n=n.slice(i[0].length)),/\d\.\d|\.\d/.test(n)&&(r.decimal=!0);try{const{text:t}=os(n,e,r);return t.startsWith('"')||/^\d+(\.\d+)?$/.test(t)?t:`(${t})`}catch(t){if(t instanceof cr)return'"undefined"';if(t instanceof ur)return`(${n})`;throw t}}Cn=as;for(const t of[hr,hi,Oi,Si,Ri,Pi])Object.setPrototypeOf(t,null);Object.setPrototypeOf(Ci,null);const ls=t=>"op"===t.type&&o(t.op)&&["vec","hat"].includes(X(t.op)),cs={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",dot:"dot",cross:"cross",vector:"vector",hat:"hat",at:"at",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:t=>`the ${t} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:t=>`the ${t} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",matrix:(t,e)=>`the ${t} by ${e} matrix`,row:t=>`row ${t}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},us={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"},hs=Object.fromEntries(Object.entries(L).map(([t,e])=>[e,t]));function ps(t,e={}){return ms(function(t,e={}){return fs(t,e,!0)}(t,e))}function fs(t,e,n){return function(t){let e=t.length;for(;e>0&&(t[e-1].close||!t[e-1].text.replace(/,/g,"").trim());)e--;const n=[];for(const{text:r,id:i}of t.slice(0,e)){const t=r.trim();if(!t)continue;const e=t.startsWith(","),s=e?t.slice(1).trim():t;e&&n.length&&!n[n.length-1].text.endsWith(",")&&(n[n.length-1].text+=","),s&&n.push({text:s,id:i})}n.length&&(n[n.length-1].text=n[n.length-1].text.replace(/,$/,""));return n}(new bs({...cs,...e.words},{...us,...e.names},e.say||{},n).speak(t))}function ms(t){return t.map(t=>t.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const ds={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},gs={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class bs{constructor(t,e,n,r=!1){this.w=t,this.names=e,this.say=n,this.audio=r}speak(t){const e=this.say["op"===t.type?t.op:t.type];if(e){return[{text:e("op"===t.type?t.args.map(t=>ms(this.speak(t))):[t.value],t,t=>ms(this.speak(t))),id:t.id}]}return"number"===t.type?[this.seg(t,this.number(t.value))]:"string"===t.type?[this.seg(t,t.value.slice(1,-1))]:"symbol"===t.type?[this.seg(t,this.symbol(t.value))]:this.operation(t)}seg(t,e){return{text:e,id:t.id}}number(t){const e=this.w;return t.endsWith("..")?`${t.replace(/\.+$/,"")} ${e.repeating}`:t.startsWith("-")?`${e.negative} ${t.slice(1)}`:t}symbol(t){const e=this.w;if("∞"===t)return e.infinity;if("-∞"===t)return`${e.negative} ${e.infinity}`;if("pi"===t||"π"===t)return e.pi;if("tau"===t||"τ"===t)return"tau";if("\\+"===t)return e.plus;if("\\-"===t)return e.minus;if("°"===t)return e.degrees;if(gs[t])return e[gs[t]];if(hs[t])return hs[t].toLowerCase();if(/^Δ.+$/.test(t))return`${e.delta} ${this.symbol(t.slice(1))}`;const n=/′+$/.exec(t);return n?`${this.symbol(t.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:t.endsWith("⁻¹")?`${this.symbol(t.slice(0,-2))} ${e.inverse}`:t}primes(t){const e=this.w;return[e.prime,e.doublePrime,e.triplePrime][t-1]??`${t} ${e.prime}`}isCompound(t){if("op"!==t.type)return!1;if("sum"===t.op||"?:"===t.op)return!0;const e=c(t.op);return void 0!==e&&e<=50&&!a(t.op).group}quantity(t,e="endQuantity"){return this.isCompound(t)?[this.seg(t,this.w.quantity),...this.speak(t),...this.closer(t,e)]:this.speak(t)}grouped(t,e,n){return this.isCompound(t)||this.audio&&n?[this.seg(t,this.w.quantity),...this.speak(t),...this.closer(t,e)]:this.speak(t)}closer(t,e){const n=this.seg(t,this.w.comma);return this.audio&&e?[n,{text:this.w[e],id:t.id,close:!0},n]:[n]}contents(t,e){return this.audio&&this.isCompound(t)?this.quantity(t,e):[...this.speak(t),...this.pauseAfter(t)]}argument(t){return this.quantity(t)}operation(t){const{op:e,args:n}=t,[r,i]=n,s=this.w,a=e=>this.seg(t,e),l=()=>n.flatMap((t,e)=>e?[a(s.comma),...this.listed(t)]:this.listed(t));if(ds[e])return[...this.speak(r),a(s[ds[e]]),...this.speak(i)];if(o(e)){if(1===n.length&&"symbol"===r.type&&"vec"===X(e))return[a(s.vector),...this.speak(r)];if(1===n.length&&"symbol"===r.type&&"hat"===X(e))return[...this.speak(r),a(s.hat)];const t=this.symbol(X(e));return n.length?[a(`${t} ${s.of}`),...this.arguments(n)]:[a(t)]}if(this.names[e]&&!["log","round","fixed","atan2","random","expm1"].includes(e))return[a(`${this.names[e]} ${s.of}`),...this.arguments(n)];switch(e){case"+":return T(i)?[...this.leftSide(r),a(s.minus),...this.quantityIfSum(i.args[1])]:[...this.leftSide(r),a(s.plus),...this.speak(i)];case"-":return T(i)?[...this.leftSide(r),a(s.plus),...this.speak(i.args[1])]:[...this.leftSide(r),a(s.minus),...this.quantityIfSum(i)];case"*":return this.product(t);case"/":return this.fraction(t);case"^":return this.power(t);case"_":return[...this.speak(r),a(s.sub),...this.audio?this.grouped(i,"endSub","op"===i.type):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.grouped(r,"endQuantity","op"===r.type||"number"===r.type&&r.value.startsWith("-")),a(s.factorial)];case"\\not":return[a(s.not),...this.quantity(r)];case"sqrt":return[a(s.squareRoot),...this.contents(r,"endRoot")];case"root":{const t="number"===r.type?Number(r.value):NaN,e=3===t?s.cubeRoot:2===t?s.squareRoot:s.nthRoot(t?this.ordinal(t):ms(this.speak(r))+"th");return[a(e),...this.contents(i,"endRoot")]}case"abs":return[a(s.absoluteValue),...this.contents(r,"endAbsoluteValue")];case"floor":return[a(s.floor),...this.contents(r,"endFloor")];case"ceil":return[a(s.ceiling),...this.contents(r,"endCeiling")];case"log":return"symbol"===r.type&&"e"===r.value?[a(`${this.names.ln} ${s.of}`),...this.argument(i)]:[a(`${s.logBase}`),...this.speak(r),a(s.of),...this.argument(i)];case"mod":return[...this.quantity(r),a(s.mod),...this.quantity(i)];case"pmod":return[...this.speak(r),a(`${s.comma} ${s.mod}`),...this.speak(i)];case"perm":return[...this.quantity(r),a(s.permute),...this.quantity(i)];case"comb":return[...this.quantity(r),a(s.choose),...this.quantity(i)];case"round":{const t=0===("number"===i.type?Number(i.value):NaN)?s.nearestWholeNumber:`${ms(this.speak(i))} ${s.decimalPlaces}`;return[...this.speak(r),a(`${s.comma} ${s.rounded} ${t}`)]}case"fixed":return 0===("number"===i.type?Number(i.value):NaN)?[...this.speak(r),a(`${s.comma} ${s.asWholeNumber}`)]:[...this.speak(r),a(`${s.comma} ${s.writtenTo}`),...this.speak(i),a(s.decimalPlaces)];case"atan2":return[a(`${this.names.atan2} ${s.of}`),...this.speak(r),a(s.over),...this.speak(i)];case"random":return[a(s.randomNumber)];case"expm1":return[a(s.eToThe),...this.speak(r),a(`${s.comma} ${s.minus} 1`)];case"?:":{const t=[a(s.if),...this.speak(r),a(`${s.comma} ${s.then}`),...this.speak(i)];return(t=>"symbol"===t.type&&"unchanged"===t.value)(n[2])?t:[...t,a(`${s.comma} ${s.otherwise}`),...this.speak(n[2])]}case"sum":return n.flatMap((t,e)=>e?[a(s.plus),...this.speak(t)]:this.speak(t));case"prod":return n.flatMap((t,e)=>e?[a(s.times),...this.quantity(t)]:this.quantity(t));case"mean":case"max":case"min":case"gcd":return[a(`${this.names[e]} ${s.of}`),...l()];case"()":return 2===n.length?[a(s.openInterval),...this.speak(r),a(s.to),...this.speak(i)]:l();case"pmatrix":case"bmatrix":return this.matrix(t);case"vmatrix":return[a(s.determinantOf),...this.matrix(t)];case"[]":return rt(t)?this.matrix(t):2===n.length?[a(s.closedInterval),...this.speak(r),a(s.to),...this.speak(i)]:[a(s.theList),...l()];case"(]":case"[)":return[a(s.halfOpenInterval),...this.speak(r),a(s.to),...this.speak(i)];case"{}":return[a(s.theSet),...l()];case"der":return this.derivative(t);case"int":return this.integral(t);case"lim":return this.limit(t);case"\\sumidx":return this.bigOperator(t,s.sumFrom,s.sumOver,s.sumOf,"endSum");case"\\prodidx":return this.bigOperator(t,s.productFrom,s.productOver,s.productOf,"endProduct")}throw new Error(`No speech for '${e}'`)}matrix(t){const e=this.w,n=rt(t),r=[this.seg(t,e.matrix(n.length,n[0].length))];return n.forEach((n,i)=>{const s=t.args[i];r.push(this.seg(t,e.comma),this.seg("op"===s.type&&"[]"===s.op?s:t,`${e.row(i+1)}:`)),n.forEach((n,i)=>r.push(...i?[this.seg(t,e.comma)]:[],...this.speak(n)))}),[...r,...this.closer(t,"endMatrix")]}arguments(t){return 1===t.length?this.argument(t[0]):t.flatMap((t,e)=>e?[{text:this.w.comma,id:t.id},...this.listed(t)]:this.listed(t))}listed(t){return this.audio?this.quantity(t):this.speak(t)}pauseAfter(t){return this.isCompound(t)?[this.seg(t,this.w.comma)]:[]}leftSide(t){return this.audio&&"op"===t.type&&"?:"===t.op?[this.seg(t,this.w.quantity),...this.speak(t),...this.closer(t,"endQuantity")]:this.speak(t)}quantityIfSum(t){return this.quantity(t)}product(t){const[e,n]=t.args,r=this.w;if(T(t))return this.speak({...t,op:"neg",args:[n]});if("symbol"===n.type&&"°"===n.value)return[...this.speak(e),this.seg(t,r.degrees)];const i=this.audio&&"op"===e.type&&"/"===e.op&&!e.args.every(t=>"number"===t.type&&/^\d$|^10$/.test(t.value))?[this.seg(e,r.quantity),...this.speak(e),...this.closer(e,"endFraction")]:this.quantity(e);this.audio&&"op"===e.type&&"^"===e.op&&"number"!==e.args[1].type&&i.push(...this.closer(e.args[1],"endExponent"));const s=this.quantity(n);if(t.written&&[e,n].some(ls))return[...i,this.seg(t,r[t.written]),...s];return Boolean(t.written)||this.isCompound(e)||this.isCompound(n)||this.isWord(e)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(e)||s[0].text.startsWith("the ")?[...i,this.seg(t,r.times),...s]:[...i,...s]}isWord(t){return"symbol"===t.type&&/^[A-Za-z]{2,}$/.test(t.value)&&!L[t.value]&&!["pi","tau"].includes(t.value)}isCall(t){return"op"===t.type&&(o(t.op)||"prefix"===a(t.op)?.fixity&&100===c(t.op))}startsWithNumber(t){let e=t;for(;"op"===e.type&&e.args.length;)e=e.args[0];return"number"===e.type}fraction(t){const[e,n]=t.args,r=this.w,i=e=>this.seg(t,e);if("number"===e.type&&"number"===n.type&&/^[1-9]$/.test(e.value)&&/^([2-9]|10)$/.test(n.value)){const t=Number(e.value),s=Number(n.value),o=2===s?1===t?r.half:r.halves:r.ordinals[s]+(1===t?"":"s");return[i(`${r.numerators[t]} ${o}`)]}const s=(t,...e)=>"op"===t.type&&e.includes(t.op)&&!T(t);return[...this.grouped(e,null,s(e,"/")),...this.isCall(e)?[i(r.comma)]:[],i(r.over),...this.grouped(n,"endFraction",s(n,"/"))]}power(t){const[e,n]=t.args,r=this.w,i=e=>this.seg(t,e),s=this.isCompound(e)||this.isCall(e)||"number"===e.type&&e.value.startsWith("-")||"op"===e.type&&"/"===e.op||this.audio&&"op"===e.type&&("^"===e.op||"neg"===e.op||T(e))?[i(r.quantity),...this.speak(e),...this.closer(e,"endQuantity")]:this.speak(e);if(this.isCall(e)&&this.names[e.op]&&"number"===n.type&&/^[2-3]$/.test(n.value)&&1===e.args.length){const t=2===Number(n.value)?r.squared:r.cubed;return[i(`${this.names[e.op]} ${t} ${r.of}`),...this.argument(e.args[0])]}if("number"===n.type&&/^(?:[1-9]|10)$/.test(n.value)){const t=Number(n.value);return 2===t||3===t?[...s,i(r.powers[t])]:[...s,i(`${r.toThe} ${r.powers[t]}`)]}if("number"===n.type&&/^\d+$/.test(n.value))return[...s,i(`${r.toThe} ${this.ordinal(Number(n.value))}`)];if(!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))){const t=this.speak(n),e=t[0]&&t[0].text.startsWith(r.quantity);return[...s,i(e?r.toThePowerOf:r.toThe),...t]}return this.audio?[...s,i(r.toThePowerOf),i(r.quantity),...this.speak(n),...this.closer(n,"endExponent")]:[...s,i(r.toThePowerOf),...this.speak(n),i(r.comma)]}ordinal(t){if(t<=10&&t>=1)return"squared"===this.w.powers[t]?"second":"cubed"===this.w.powers[t]?"third":this.w.powers[t];return`${t}${t%100>=11&&t%100<=13?"th":["th","st","nd","rd"][t%10]??"th"}`}derivative(t){const{n:e,body:n,by:r,at:i,variable:s}=Q(t),o=this.w,a=e=>this.seg(t,e),l=i?[a(`${o.comma} ${o.at}`),...this.speak(r),a(o.equals),...this.speak(i)]:[];if(s){return[...[a(1===e?o.d:`${o.d} ${2===e?o.squared:3===e?o.cubed:`${o.toThe} ${this.ordinal(e)}`}`),...this.speak(n),a(o.d),...this.speak(r),a(1===e?"":2===e?o.squared:3===e?o.cubed:`${o.toThe} ${this.ordinal(e)}`)],...l]}return[a(`${1===e?o.derivative:2===e?o.secondDerivative:o.nthDerivative(this.ordinal(e))} ${o.withRespectTo}`),...this.speak(r),a(o.of),...this.contents(n,"endDerivative"),...l]}integral(t){const{args:e}=t,[n,r,i,s]=e,o=this.w,a=e=>this.seg(t,e),l=e.length>=2&&"symbol"===r.type&&1===r.value.length,c=l?this.speak(r):[a(q(n)||"x")];let u=[];4===e.length?u=[i,s]:3===e.length?u=l?[i]:[r,i]:2!==e.length||l||(u=[r]);return[...2===u.length?[a(o.integralFrom),...this.speak(u[0]),a(o.to),...this.speak(u[1]),a(o.of)]:1===u.length?[a(o.integralFrom),...this.speak(u[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(t){const{args:e}=t,[n,r,i,s]=e,o=this.w,a=e=>this.seg(t,e);let l;if(e.length>=3){if(l=[...this.speak(r),a(o.approaches),...this.speak(i)],4===e.length){const t=String(s.value??"").toLowerCase().startsWith("r");l.push(a(t?o.fromTheRight:o.fromTheLeft))}}else if(2===e.length&&"op"===r.type&&"→"===r.op)l=[...this.speak(r.args[0]),a(o.approaches),...this.speak(r.args[1])];else{if(2!==e.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const t=q(n);l=t?[a(t),a(o.approaches),...this.speak(r)]:this.speak(r)}}return this.audio&&"op"===n.type&&"/"===n.op?[a(o.limitAs),...l,a(o.of),...this.grouped(n,"endLimit",!0)]:[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(t,e,n,r,i){const{args:s}=t,[o,a,l]=s,c=this.w,u=e=>this.seg(t,e);let h;return h=3===s.length?[u(e),...this.speak(a),u(c.to),...this.speak(l),u(c.of)]:2===s.length?[u(n),...this.speak(a),u(c.of)]:[u(r)],[...h,...this.contents(o,i)]}}for(const t of[cs,us,ds,gs,hs])Object.setPrototypeOf(t,null);function $s(t,e={}){return Zn(t)?[]:function(t,e={}){return fs(t,e,!1)}(Pn(t),e)}function ys(t,e={}){return Zn(t)?"":ps(Pn(t),e)}const vs={"(":{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 ws(t,e,n=""){const r=vs[t];return`<svg class="${e}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${n?` style="${n}"`:""}>${r.fill?`<path d="${r.fill}" fill="currentColor"/>`:`<path d="${r.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const xs=.8,Ms=.2,ks=.25,Es=.7,As="−",Ns={"+":"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"},Os={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Ss={"±":"±","∪":"∪","∩":"∩",mod:"mod"},_s=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],Is={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},qs=[..._s,...Object.keys(Is),"ln","det"],Ls={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},zs={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},js=["int","lim","\\sumidx","\\prodidx"],Ts={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},Cs={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},Fs=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,Rs=t=>"symbol"===t?.type&&Fs.test(L[t.value]??t.value),Ps=["boxed","overline","bar","underline","cancel",...Object.keys(Cs)],Zs={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},Bs=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Ws=t=>+t.toFixed(3)+"em",Ds=(t,e=xs,n=Ms)=>({html:t,h:e,d:n});function Us(...t){const e=t.flat().filter(Boolean);return{html:e.map(t=>t.html).join(""),h:Math.max(xs,...e.map(t=>t.h)),d:Math.max(Ms,...e.map(t=>t.d))}}function Hs(t,e={}){const n=new Gs({...Zs,...e}),r=n.render(t,{level:0}),i=`${n.p}${n.o.display?` ${n.p}-display`:""}`,s="function"==typeof n.o.mathml?function(t,e,n,r){try{return String(t(e)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${n}-sr-math"${r?' display="block"':""}>`)}catch{return""}}(n.o.mathml,t,n.p,n.o.display):"",o=s?null:function(t,e){if(!1===e||null===e)return null;if("string"==typeof e)return e;try{return"function"==typeof e?e(t):ys(t)}catch{return null}}(t,n.o.label),a=null!==o||s?r.html.replace(/^<span /,'<span aria-hidden="true" '):r.html;return{html:`<span class="${i}"${null===o?"":` role="math" aria-label="${Bs(o)}"`}>${a}${s}</span>`,h:r.h,d:r.d}}class Gs{constructor(t){this.o=t,this.p=t.prefix}el(t,e,n="",r=""){return`<span class="${t.split(" ").map(t=>`${this.p}-${t}`).join(" ")}"${n?` style="${n}"`:""}${r}>${e}</span>`}text(t,e){const n=Ds(this.el(t,Bs(e)));return n.leaf={kind:t,content:Bs(e)},n}bin(t){return this.text("bin",t)}rel(t){return this.text("rel",t)}punct(t){return this.text("punct",t)}word(t){return this.text("word",t)}wrap(t,e,n){let r="";void 0!==t.id&&(r+=` data-node="${t.id}"`),"op"===t.type&&(r+=` data-op="${Bs(t.op)}"`);const i=this.o.attributes&&this.o.attributes(t)||{};for(const[t,e]of Object.entries(i))"class"!==t&&"style"!==t&&/^[A-Za-z_:][\w:.-]*$/.test(t)&&(r+=` ${t}="${Bs(e)}"`);const s=[i.style,this.o.style&&this.o.style(t)].filter(Boolean).join(";"),o=(n.leaf?["n",...e,n.leaf.kind]:["n",...e]).map(t=>`${this.p}-${t}`).concat(i.class?[Bs(i.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${s?` style="${Bs(s)}"`:""}${r}>${a}</span>`,h:n.h,d:n.d}}render(t,e){return"number"===t.type?this.number(t):"string"===t.type?this.wrap(t,["text"],this.text("text",t.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===t.type?this.wrap(t,["symbol"],this.symbol(t.value)):this.operation(t,e)}number(t){return this.wrap(t,["number"],this.text("num",t.value.replace(/^-/,As)))}symbol(t){return L[t]&&(t=L[t]),Ts[t]?this.text("ord",Ts[t]):"\\+"===t||"\\-"===t?this.text("ord",t[1]):"-∞"===t?this.text("ord","−∞"):/^[A-Za-z]$/.test(t)||/^[α-ω]$/.test(t)?this.text("var",t):/^[A-Za-z]′+$/.test(t)?Ds(this.el("var",Bs(t[0]))+this.el("prime",Bs(t.slice(1)))):/^Δ[A-Za-z]$/.test(t)?Ds(this.el("ord","Δ")+this.el("var",t[1])):t.endsWith("⁻¹")?this.script(this.symbol(t.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(t)?this.text("name",t.slice(1)):/^[A-Za-z]{2,}$/.test(t)?this.text("name",t):this.text("ord",t)}operation(t,e){const{op:n,args:r}=t,[i,s]=r,a=(t,n={})=>this.render(t,{...e,...n,forceParens:n.forceParens||!1,before:n.before||!1,leftFactor:!1}),l=Ns[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),u=e=>this.wrap(t,["op",`op-${l}`],e),h=(e,n)=>R(t,e,n)&&"/"!==e.op?this.fence(a(e)):a(e);if(qs.includes(n)||"log"===n)return u(this.named(t,e));if(Ls[n])return u(Us(this.word(Ls[n]),this.fence(this.list(r,e))));if(o(n))return u(this.custom(t,e));const p=rt(t);if(p)return u(this.matrix(t,p,e));if(zs[n])return u(this.fence(this.list(r,e),...zs[n]));if(("|"===n||"&"===n)&&r.length>=2&&r.every(Qs)){const t=t=>"|"!==t.op&&"&"!==t.op||t.op===n?a(t):this.fence(a(t));return u(Us(r.map((e,r)=>r?[this.text("conj","|"===n?"or":"and"),t(e)]:[t(e)]).flat()))}if(Os[n]&&2===r.length)return u(Us(h(i,"left"),this.rel(Os[n]),h(s,"right")));if(Ss[n]&&2===r.length)return u(Us(h(i,"left"),this.bin(Ss[n]),h(s,"right")));switch(n){case"+":if(T(s)){const t=s.args[1],e=R({op:"-"},t,"right")?this.fence(a(t)):a(t);return u(Us(h(i,"left"),this.bin(As),this.wrap(s,["op","op-mul"],e)))}return"number"===s.type&&s.value.startsWith("-")?u(Us(h(i,"left"),this.bin(As),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):u(Us(h(i,"left"),this.bin("+"),this.signed(s,h(s,"right"))));case"-":return u(Us(h(i,"left"),this.bin(As),this.signed(s,h(s,"right"))));case"*":return u(this.product(t,e));case"/":return u(this.fraction(t,e));case"^":return u(this.power(t,e));case"_":{const t=C(i)&&c(C(i))<100;return u(this.script(t?this.fence(a(i)):a(i,{forceParens:!0}),null,e,a(s,{level:e.level+1})))}case"neg":return u(Us(this.text("sign",As),P(n,i)?this.fence(a(i)):a(i,{before:e.before})));case"pm":return u(Us(this.text("sign","±"),P(n,i)?this.fence(a(i)):a(i)));case"!":return u(Us(P(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return u(Us(this.text("sign","¬"),P(n,i)?this.fence(a(i)):a(i)));case"pmod":return u(Us(a(i),this.fence(Us(this.word("mod"),this.text("space",""),a(s)))));case"sqrt":return u(this.radical(a(i)));case"root":return u(this.radical(a(s),this.render(i,{level:e.level+2})));case"abs":return u(this.fence(a(i),"|","|"));case"floor":return u(this.fence(a(i),"⌊","⌋"));case"ceil":return u(this.fence(a(i),"⌈","⌉"));case"loglog":return u(Us(this.word("ln"),this.fence(Us(this.word("ln"),this.fence(a(i))))));case"logloglog":return u(Us(this.word("ln"),this.fence(Us(this.word("ln"),this.fence(Us(this.word("ln"),this.fence(a(i))))))));case"perm":return u(this.script(this.script(Ds(""),this.render(i,{level:e.level+1}),e),null,e,this.render(s,{level:e.level+1}),this.word("P")));case"comb":return u(this.fence(this.stack(a(i),a(s),!1)));case"?:":return u(this.o.cases?this.cases(t,e):Us(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":case"prod":{const t={op:"sum"===n?"+":"*"},e=(e,n)=>R(t,e,n?"right":"left")?this.fence(a(e)):a(e);return u(Us(r.map((t,r)=>r?[this.bin("sum"===n?"+":"·"),e(t,r)]:[e(t,r)]).flat()))}case"der":return u(this.derivative(t,e));case"int":return u(this.integral(r,e));case"lim":return u(this.limit(r,e));case"\\sumidx":return u(this.bigOperator("sum",r,e));case"\\prodidx":return u(this.bigOperator("prod",r,e))}throw new Error(`Inline Math cannot draw '${n}'`)}signed(t,e){return("number"===t.type?t.value.startsWith("-"):"neg"===t.op||"pm"===t.op)&&!e.fenced?this.fence(e):e}list(t,e){return Us(t.map((t,n)=>n?[this.punct(","),this.render(t,e)]:[this.render(t,e)]).flat())}product(t,e){const[n,r]=t.args;if(T(t))return Us(this.text("sign",As),P("neg",r)?this.fence(this.render(r,e)):this.render(r,e));const i=function(t){const[e,n]=t.args;return{left:R(t,e,"left")&&"/"!==e.op,right:R(t,n,"right")&&"/"!==n.op}}(t);js.includes(n.op)&&(i.left=!0);const s=!t.written&&Z(n,r,i),a=function(t){for(;"op"===t.type;){if(qs.includes(t.op)||"log"===t.op||Ls[t.op]||o(t.op))return!0;if("^"!==t.op&&"*"!==t.op)return!1;t=t.args[0]}return!1}(r),l=i.left?this.fence(this.render(n,e)):this.render(n,{...e,before:s&&!a,leftFactor:!0}),c=i.right?this.fence(this.render(r,e)):this.render(r,{...e,before:e.before});return Us(l,s?Ds(this.el(a?"fnspace":"times","")):this.bin("cross"===t.written?"×":"·"),c)}named(t,e,n=null){const{op:r,args:i}=t,s="log"===r?i[1]:i[0];let o;o=Is[r]&&"power"===this.o.inverseTrig?this.script(this.word(Is[r]),this.text("num","−1"),e):this.word(r),n&&(o=this.script(o,n,e)),"log"===r&&(o=this.script(o,null,e,this.render(i[0],{level:e.level+1})));const a="auto"===this.o.fnParens&&!e.forceParens&&!e.before&&Vs(s),l=this.render(s,{...e,forceParens:!1,before:!1});return Us(o,a?Us(Ds(this.el("fnspace","")),l):this.fence(l))}custom(t,e){const n=X(t.op),r=t.args;if(Ps.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],e),r[0]);return Us(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Ds(this.el("callgap","")),this.fence(this.list(r,e)))}decorate(t,e,n){switch(t){case"boxed":return Ds(this.el("boxed",e.html),e.h+.22,e.d+.22);case"cancel":return Ds(this.el("cancel",e.html+ws("cancel",`${this.p}-cancel-line`)),e.h,e.d);case"underline":return Ds(this.el("underline",e.html),e.h,e.d+.12);case"overline":case"bar":return Ds(this.el("over"+(Rs(n)?" over-low":""),e.html),e.h+.14,e.d);default:{const r=Rs(n);return Ds(this.el("accent"+(r?" accent-low":""),this.el(`accent-mark accent-${t}`,Cs[t])+e.html),e.h+.3,e.d)}}}fraction(t,e){const[n,r]=t.args;if(e.level>0&&"slash"===this.o.scriptFractions&&Vs(n,!0)&&Vs(r,!0)){const t={...e,leftFactor:!1},i=(e,n)=>"op"!==e.type||Vs(e)&&(!n||"*"!==e.op||T(e))?this.render(e,t):this.fence(this.render(e,t)),s=Us("op"===n.type&&"neg"===n.op?this.render(n,t):i(n,!1),this.text("ord","/"),i(r,!0));return e.leftFactor?this.fence(s):s}const i=e.level>0||e.inFraction||!this.o.display?.8:1,s={...e,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(n,s),this.render(r,s),!0,i)}stack(t,e,n=!0,r=1){const i=t=>1===r?t.html:this.el("scaled",t.html,`font-size:${Ws(r)}`),s=n?.06:0,o=ks+s/2+.1+Math.max(Ms,r*t.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(t))+this.el("denom",i(e)),`vertical-align:${Ws(o)}`);return Ds(a,o+Math.max(xs,r*t.h),Math.max(xs,r*e.h)+Math.max(Ms,r*e.d)+.1+s/2-ks)}power(t,e){const[n,r]=t.args,i={...e,level:e.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},s=()=>this.render(r,i);if(this.o.trigPowers&&_s.includes(n.op)&&Ys(r))return this.wrap(n,["op",`op-${n.op}`],this.named(n,e,s()));if("_"===n.op){const t=this.render(n.args[1],i);return this.wrap(n,["op","op-subscript"],this.script(this.render(n.args[0],{...e,forceParens:!0}),s(),e,t))}const o=R(t,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||qs.includes(n.op)||js.includes(n.op)?this.fence(this.render(n,e)):this.render(n,{...e,forceParens:!0});return this.script(o,s(),e)}script(t,e,n,r=null,i=null){const s=n.level>0?.8:Es,o=i?Us(t,i):t;let a=e?Math.max(.42,t.h-.38,s*e.d+.12):0,l=r?Math.max(.2,t.d-.05,s*r.h-.45):0;if(e&&r){const t=.1-(a-s*e.d-(s*r.h-l));t>0&&(l+=t)}const c=t=>this.el("script",t.html,`font-size:${Ws(s)}`);if(e&&!r)return Ds(t.html+this.el("sup",e.html,`font-size:${Ws(s)};vertical-align:${Ws(a/s)}`),Math.max(o.h,a+s*e.h),Math.max(o.d,s*e.d-a));if(r&&!e)return Ds(o.html+this.el("sub",r.html,`font-size:${Ws(s)};vertical-align:${Ws(-l/s)}`),Math.max(o.h,s*r.h-l),Math.max(o.d,l+s*r.d));const u=a+s*e.h,h=l+s*r.d,p=this.el("subsup",c(e)+c(r),`vertical-align:${Ws(a)};height:${Ws(u+h)}`);return Ds(o.html+p,Math.max(o.h,u),Math.max(o.d,h))}radical(t,e=null){const n=Math.max(t.h,xs)+.1+.06,r=Math.max(t.d,Ms),i=n+r,s=ws("sqrt",`${this.p}-hook`,`height:${Ws(i)};width:${Ws(.5+.06*(i-1))};vertical-align:${Ws(-r)}`);let o="";if(e){const t=.8*Es;o=this.el("rootindex",e.html,`font-size:${Ws(t)};vertical-align:${Ws((.55*i-r)/t)}`)}return Ds(this.el("sqrt",o+s+this.el("radicand",t.html)),n,r)}fence(t,e="(",n=")"){const r=Math.max(t.h,xs)+Math.max(t.d,Ms),i=r>1.25,s=i?.1:0,o=(t,e)=>{if(!t)return{html:"",w:0};const n={"(":.26,")":.26,"{":.36,"}":.36}[t];if(n){const s=n+(i?Math.min(.2,.05*(r-1)):0);return{html:ws(t,`${this.p}-delim ${this.p}-delim-${e}`,`width:${Ws(s)}`),w:s+.1}}const s={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[t];return{html:this.el(`delim ${s} delim-${e}`,""),w:"|"===t?.18:.3}},a=o(e,"l"),l=o(n,"r"),c=`padding:${Ws(s)} ${Ws(l.w)} ${Ws(s)} ${Ws(a.w)}`,u=Ds(this.el("fence",a.html+t.html+l.html,c),Math.max(t.h,xs)+s,Math.max(t.d,Ms)+s);return u.fenced=!0,u}derivative(t,e){const n=this.leibniz(t,e),{by:r,at:i}=Q(t);if(!i)return n;const s=t.args[1],o=this.render({...s,args:[{...r,id:void 0},i]},{...e,level:e.level+1});return this.script(this.fence(n,"","|"),null,e,o)}leibniz(t,e){const{n:n,body:r,by:i,variable:s}=Q(t),o={...e,level:e.level+1},a=()=>this.text("d","d"),l=()=>n>1?this.render({type:"number",value:String(n)},o):null,u={...e,inFraction:!0},h=Us(a(),l()?this.script(this.render(i,u),l(),u):this.render(i,u)),p=t=>Us(l()?this.script(a(),l(),u):a(),t||[]),f=e.level>0||e.inFraction||!this.o.display?.8:1;if(s)return this.stack(p(this.render(r,u)),h,!0,f);const m=C(r)&&c(C(r))<100,[d,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=m?this.fence(this.render(r,e),d,g):this.render(r,e);return Us(this.stack(p(),h,!0,f),b)}integral(t,e){const[n,r,i,s]=t,o=t=>this.render(t,e),a=t=>t?this.render(t,{...e,level:e.level+1}):null,l=()=>this.text("var",q(n)||"x");let c,u=null,h=null;switch(t.length){case 1:c=l();break;case 2:V(r)?c=o(r):(c=l(),u=a(r));break;case 3:V(r)?(c=o(r),u=a(i)):(c=l(),u=a(r),h=a(i));break;default:c=o(r),u=a(i),h=a(s)}const p=o(n),f=Ds(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Us(this.bigSign("int",p,u,h,e),p,f)}bigSign(t,e,n,r,i){const s=!this.o.display||i.level>0,o=Math.max(s?.6:.95,Math.max(e.h-ks,e.d+ks)+.12),a=ws(t,`${this.p}-bigsign ${this.p}-${t}sign`,`height:${Ws(2*o)};width:${Ws(s?.38:.5)};vertical-align:${Ws(ks-o)}`);if(!n&&!r)return Ds(a,ks+o,o-ks);const l=Es,c=r||Ds(""),u=n||Ds(""),h=ks+o-l*c.h;u.d;const p=this.el("limits",this.el("script",c.html,`font-size:${Ws(l)}`)+this.el("script lower",u.html,`font-size:${Ws(l)}`),`vertical-align:${Ws(h)};height:${Ws(2*o)}`);return Ds(a+p,ks+o,o-ks)}limit(t,e){const[n,r,i,s]=t,o={...e,level:e.level+1},a=t=>this.render(t,o),l=()=>this.rel("→");let c;switch(t.length){case 1:return Us(this.word("lim"),Ds(this.el("fnspace","")),this.body(n,e));case 2:{const t=q(n),e="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=t&&e?Us(this.text("var",t),l(),a(r)):a(r);break}case 3:c=Us(a(r),l(),a(i));break;default:{const t=z(s).toLowerCase().startsWith("r")?"+":As;c=Us(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",t)),o))}}return Us(this.under(this.word("lim"),c,e),this.body(n,e))}under(t,e,n){return!this.o.display||n.level>0?this.script(t,null,n,e):Ds(this.el("under",t.html+this.el("script",e.html,`font-size:${Ws(.7)}`)),t.h,Math.max(t.d,Ms)+.05+.7*(e.h+e.d))}body(t,e){const n=C(t);return n&&c(n)<c("*")?this.fence(this.render(t,e)):this.render(t,e)}bigOperator(t,e,n){const[r,i,s]=e,o={...n,level:n.level+1},a=i?this.render(i,o):null,l=s?this.render(s,o):null,c=this.body(r,n);if(!this.o.display||n.level>0){const e=.55,r=ws(t,`${this.p}-bigsign`,`height:${Ws(2*e)};width:${Ws(.8)};vertical-align:${Ws(ks-e)}`);return Us(this.script(Ds(r,ks+e,e-ks),l,n,a),c)}const u=.68,h=Es,p=ws(t,`${this.p}-bigsign`,`height:${Ws(1.36)};width:${Ws("sum"===t?1:1.05)}`),f=l?1.01+h*l.d:ks-u,m=t=>this.el("script",t.html,`font-size:${Ws(h)}`),d=this.el("bigop",(l?m(l):"")+p+(a?m(a):""),`vertical-align:${Ws(f)}`);return Us(Ds(d,.93+(l?.08+h*(l.h+l.d):0),u-ks+(a?.08+h*(a.h+a.d):0)),c)}matrix(t,e,n){const r=e.map(t=>t.map(t=>this.render(t,n))),i=r.map(t=>({h:Math.max(xs,...t.map(t=>t.h)),d:Math.max(Ms,...t.map(t=>t.d))})),s=i.reduce((t,e)=>t+e.h+e.d,0)+.3*(e.length-1),o=ks+s/2-i[0].h,a=r.map((e,n)=>{const r=e.map(t=>this.el("matrix-cell",t.html)).join(""),i=t.args[n];return i&&"op"===i.type&&"[]"===i.op?this.wrap(i,["op","op-list","matrix-row"],Ds(r)).html:r}).join(""),l=e[0].length,c=Ds(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${Ws(o)}`),ks+s/2,s/2-ks),[u,h]=nt[t.op]??["[","]"];return this.fence(c,u,h)}cases(t,e){const n=[];let r=t;for(;"op"===r.type&&"?:"===r.op;)n.push([this.render(r.args[1],e),Us(this.word("if"),this.text("space",""),this.render(r.args[0],e))]),r=r.args[2];"symbol"===r.type&&"unchanged"===r.value||n.push([this.render(r,e),this.word("otherwise")]);const i=n.map(([t,e])=>({h:Math.max(t.h,e.h),d:Math.max(t.d,e.d)})),s=i.reduce((t,e)=>t+e.h+e.d,0)+.25*(n.length-1),o=ks+s/2-i[0].h,a=n.map(([t,e])=>this.el("case-value",t.html)+this.el("case-cond",e.html)).join(""),l=Ds(this.el("cases",a,`vertical-align:${Ws(o)}`),ks+s/2,s/2-ks);return this.fence(l,"{","")}}function Vs(t,e=!1){return"number"===t.type?!t.value.startsWith("-")||e:"symbol"===t.type||"op"===t.type&&("abs"===t.op||rt(t)?!e:!e||"neg"!==t.op&&"^"!==t.op?"*"===t.op&&!T(t)&&t.args.every(t=>"number"===t.type&&!t.value.startsWith("-")||Js(t)||"*"===t.op&&Vs(t,e)):Vs(t.args[0],!0)&&("neg"===t.op||Vs(t.args[1],!0)))}const Xs=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],Qs=t=>"op"===t.type&&t.args.length>=2&&(2===t.args.length&&Xs.includes(t.op)||("|"===t.op||"&"===t.op)&&t.args.every(Qs)),Js=t=>"symbol"===t.type&&(1===t.value.length||/^[α-ωΑ-Ω]$/.test(t.value)||Boolean(L[t.value])),Ys=t=>"number"===t.type&&/^[1-9]\d*$/.test(t.value)&&Number(t.value)<10;for(const t of[Ns,Os,Ss,Is,Ls,zs,Ts,Cs])Object.setPrototypeOf(t,null);function Ks(t){const{id:e,from:n,...r}=t;return r.args&&(r.args=r.args.map(Ks)),r}const to=t=>S(t).join(" ");function eo(t,e){const n=new Set;no(t,e,n);const r=[];return I(t,t=>{n.has(t)&&r.push(t)}),r}function no(t,e,n){if(null!=e)if(Array.isArray(e))e.forEach(e=>no(t,e,n));else if("number"!=typeof e)if("function"!=typeof e){if("string"==typeof e){const r=to(Rn(e));return void I(t,t=>{to(t)===r&&n.add(t)})}if(e.path){const r=ro(t,e.path);return void(r&&n.add(r))}if(e.type){const r=to(e);I(t,t=>{t!==e&&to(t)!==r||n.add(t)})}}else I(t,(t,r)=>{e(t,r)&&n.add(t)});else I(t,t=>{t.id===e&&n.add(t)})}function ro(t,e){let n=t;for(const t of e){if("op"!==n.type||!n.args[t])return null;n=n.args[t]}return n}function io(t,e){const n=[],r=t=>{if(t.id===e)return!0;if("op"!==t.type)return!1;for(let e=0;e<t.args.length;e++){if(n.push(e),r(t.args[e]))return!0;n.pop()}return!1};return r(t)?n:null}function so(t){let n=0;const r=t=>{"op"===t.type&&(t.args.forEach(r),a(t.op)?.arity===e&&n++),t.id=n++};return r(t),t}function oo(t,e={}){const{blocks:n}=e;if("string"==typeof t)return Rn(t,n?{blocks:t=>n(t,e.scope)}:{});if(Array.isArray(t))return O(t);if(t&&"object"==typeof t&&t.type){if(void 0!==t.id)return t;const e=structuredClone(t);return I(e,t=>{"op"!==t.type&&void 0!==t.value&&(t.value=String(t.value))}),so(e)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function ao(t,e){const{colors:n,highlight:r,scope:i,blocks:s,...o}=e,a=new Map;for(const[e,r]of function(t){return t?Array.isArray(t)?t:Object.entries(t).map(([t,e])=>[/^\d+$/.test(t)?Number(t):t,e]):[]}(n))if(lo(r))for(const n of eo(t,e))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:eo(t,r));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:t=>[a.get(t),o.style&&o.style(t)].filter(Boolean).join(";"),attributes:t=>{const e={...o.attributes?o.attributes(t):{}};return l.has(t)&&(e.class=[e.class,`${c}-hl`].filter(Boolean).join(" ")),e}}}function lo(t){return"string"==typeof t&&/^[#\w\s.,%()/+-]+$/.test(t)&&!/url\s*\(|expression/i.test(t)}function co(t,e={}){return oo(t,{...e,blocks:e.blocks??as})}function uo(t,e={}){return function(t,e={}){const n=oo(t,e);return Hs(n,ao(n,e)).html}(t,{...e,blocks:e.blocks??as})}function ho(t,e,n){const r=(t,i)=>i===e.length?n:{...t,args:t.args.map((t,n)=>n===e[i]?r(t,i+1):t)};return Ks(r(t,0))}function po(t,e,{parse:n,commit:r,cancel:i,label:s="Edit",prefix:o="mv"}){const a=t.ownerDocument;if(!a||!a.body)return null;const l=a.defaultView,c=t.getBoundingClientRect(),u=a.createElement("input");u.type="text",u.className=`${o}-edit`,u.value=e,u.spellcheck=!1,u.autocomplete="off",u.setAttribute("aria-label",s);const h=()=>{u.style.width=`${Math.max(4,u.value.length+2)}ch`},p=l.getComputedStyle(t);Object.assign(u.style,{position:"absolute",left:`${c.left+l.scrollX}px`,top:`${c.top+l.scrollY+c.height/2}px`,minWidth:`${Math.max(c.width,32)}px`,fontSize:p.fontSize}),h(),a.body.appendChild(u),l.getSelection?.()?.removeAllRanges(),u.focus(),u.select();let f=!1;const m=()=>{f=!0,u.remove()};u.cancelEdit=()=>{f||(m(),i&&i())};const d=t=>{if(f)return!0;if(!t||u.value===e)return m(),i&&i(),!0;let s;try{s=n(u.value)}catch(t){return u.setAttribute("aria-invalid","true"),u.title=t.message,!1}return m(),r(s,u.value),!0};return u.addEventListener("keydown",t=>{t.stopPropagation(),"Enter"===t.key&&(t.preventDefault(),d(!0)),"Escape"===t.key&&(t.preventDefault(),d(!1))}),u.addEventListener("input",()=>{h(),u.removeAttribute("aria-invalid"),u.removeAttribute("title")}),u.addEventListener("blur",()=>{d(!0)||d(!1)}),u}class fo{constructor(t,e,n={}){this.element=t,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=mo(t,n.announce,this.p),this.set(e)}set(t,{animate:e=!1,duration:n=600,easing:r="ease-in-out"}={}){const i=co(t,this.options),{html:s}=Hs(i,ao(i,this.options));if(this.editor){const t=this.editor;this.editor=null,t.cancelEdit?.()}const o=go(e)&&this.tree?this.snapshot():null,a=void 0!==this.tree;return this.tree=i,this.element.innerHTML=s,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),o&&this.morph(o,{duration:n,easing:r}),a&&this.live&&this.announce(this.spoken()),this}spoken(){const t=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(t)return t;try{return ys(this.tree)}catch{return""}}announce(t){return this.say(this.live,t)}say(t,e){if(!t)return this;t.textContent="";const n=()=>{t.textContent=e};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(n)):setTimeout(n,50),this}nodes(t){return eo(this.tree,t)}elements(t){return this.nodes(t).map(t=>this.elementOf(t)).filter(Boolean)}elementOf(t){return void 0===t.id?null:this.root.querySelector(`[data-node="${t.id}"]`)}highlight(t,e=`${this.p}-hl`){return this.elements(t).forEach(t=>t.classList.add(e)),this}unhighlight(t=null,e=`${this.p}-hl`){return(null===t?this.root.querySelectorAll(`.${e}`):this.elements(t)).forEach(t=>t.classList.remove(e)),this}color(t,e){return this.elements(t).forEach(t=>{t.style.color=e||""}),this}on(t,e){const n=t=>{const n=t.target.closest?.("[data-node]");if(!n||!this.root.contains(n))return;const r=Number(n.dataset.node),i=eo(this.tree,r)[0];e({node:i,id:r,path:io(this.tree,r),element:n,event:t})};this.element.addEventListener(t,n);const r=[t,n];return this.handlers.push(r),this.root.classList.add(`${this.p}-clickable`),"click"===t&&(this.clicks.push(e),this.keyboard()),()=>{this.element.removeEventListener(t,n),this.clicks=this.clicks.filter(t=>t!==e),this.handlers=this.handlers.filter(t=>t!==r),!this.handlers.length&&this.root&&this.root.classList.remove(`${this.p}-clickable`)}}destroy(){if(this.editor){const t=this.editor;this.editor=null,t.cancelEdit?.()}for(const[t,e]of this.handlers)this.element.removeEventListener(t,e);this.handlers=[],this.clicks=[],this.keyListener&&this.element.removeEventListener("keydown",this.keyListener),this.editListener&&this.element.removeEventListener("dblclick",this.editListener),this.keyListener=this.editListener=null,this.keysOn=this.editOn=!1;for(const t of new Set([this.live,this.partsLive]))t&&"view"===t.dataset?.mvMadeBy&&t.remove();return this.live=this.partsLive=null,this}editable({toText:t,onEdit:e}={}){if("function"!=typeof t)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:t,onEdit:e},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.editListener=t=>{const e=t.target.closest?.("[data-node]");e&&this.root.contains(e)&&(t.preventDefault(),this.edit(eo(this.tree,Number(e.dataset.node))[0]))},this.element.addEventListener("dblclick",this.editListener)),this}edit(t=this.tree,{returnFocus:e=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const n="object"==typeof t&&t&&t.type?t:this.nodes(t)[0];if(!n)return null;const r=io(this.tree,n.id)||[],i=this.elementOf(n)||this.root;let s="Edit";try{s=`Edit ${ys(n)}`}catch{}const o=()=>{e&&this.root.focus&&this.root.focus()};return this.editor=po(i,this.editing.toText(n),{label:s,prefix:this.p,parse:t=>co(t,this.options),commit:(t,n)=>{this.set(ho(this.tree,r,t),{animate:!0});const i=ro(this.tree,r);e&&i&&this.focusPart(i===this.tree?null:i),o(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:r,part:n})},cancel:o}),this.editor}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||mo(this.element,!0,this.p),this.keyListener=t=>this.key(t),this.element.addEventListener("keydown",this.keyListener))}key(t){if(!this.root||!this.root.contains(t.target))return;const e=this.active;let n;switch(t.key){case"ArrowDown":n=e?this.partsOf(e)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":n=e?this.outerOf(e):void 0;break;case"ArrowRight":n=e?this.neighbor(e,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":n=e?this.neighbor(e,-1):void 0;break;case"Home":case"Escape":n=null;break;case"F2":if(!this.editing)return;return t.preventDefault(),void this.edit(e||this.tree,{returnFocus:!0});case"Enter":case" ":{t.preventDefault();const n=e||this.tree,r=this.elementOf(n)||this.root,i={node:n,id:n.id,path:io(this.tree,n.id),element:r,event:t};for(const t of this.clicks)t(i);return}default:return}t.preventDefault(),void 0!==n&&this.focusPart(n)}focusPart(t){const e=`${this.p}-focus`;this.root.querySelectorAll(`.${e}`).forEach(t=>t.classList.remove(e)),this.active=t;const n=t&&this.elementOf(t);n&&n.classList.add(e);let r="";try{r=t?ys(t):this.spoken()}catch{r=""}return this.say(this.partsLive,r),this}partsOf(t){const e=[],n=t=>{this.elementOf(t)?e.push(t):"op"===t.type&&t.args.forEach(n)};return t&&"op"===t.type&&t.args.forEach(n),e}outerOf(t){const e=io(this.tree,t.id);for(let t=e?e.length-1:-1;t>0;t--){const n=ro(this.tree,e.slice(0,t));if(n&&this.elementOf(n))return n}return null}neighbor(t,e){const n=this.partsOf(this.outerOf(t)||this.tree),r=n.indexOf(t);return r<0?void 0:n[r+e]}segments(t={}){return $s(this.tree,t)}showSegment(t,e=`${this.p}-hl`){return this.unhighlight(null,e),t&&void 0!==t.id&&this.highlight(t.id,e),this}snapshot(){const t=new Map,e=n=>{const r=this.elementOf(n);if(r){const e=to(n);t.has(e)||t.set(e,[]),t.get(e).push({rect:r.getBoundingClientRect(),node:n,sig:e})}"op"===n.type&&n.args.forEach(e)};return e(this.tree),t}morph(t,{duration:e,easing:n}){if("undefined"==typeof Element||!Element.prototype.animate)return;const r=e=>{if("op"===e.type)for(const n of e.args){const e=t.get(to(n)),i=e?e.findIndex(t=>t.node===n):-1;i>-1&&e.splice(i,1),r(n)}},i=s=>{const o=this.elementOf(s),a=o&&t.get(to(s));if(a&&a.length){const{rect:t,node:i}=a.shift();r(i);const s=o.getBoundingClientRect(),l=t.left-s.left,c=t.top-s.top,u=s.width?t.width/s.width:1,h=s.height?t.height/s.height:1;return void((Math.abs(l)+Math.abs(c)>.5||Math.abs(u-1)+Math.abs(h-1)>.01)&&o.animate([{transformOrigin:"0 0",transform:`translate(${l}px, ${c}px) scale(${u}, ${h})`},{transformOrigin:"0 0",transform:"none"}],{duration:e,easing:n}))}"op"===s.type?s.args.forEach(i):o&&o.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:e,easing:n})};i(this.tree)}}function mo(t,e,n){if(!e)return null;if("object"==typeof e&&1===e.nodeType)return e;if("undefined"==typeof document||!t.insertAdjacentElement)return null;const r=t.nextElementSibling;if(r&&"view"===r.dataset?.mvMadeBy&&r.classList.contains(`${n}-sr-only`))return r;const i=document.createElement("span");return i.dataset.mvMadeBy="view",i.className=`${n}-sr-only`,i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),t.insertAdjacentElement("afterend",i),i}function go(t){return!!t&&("always"===t||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}const bo=Symbol.for("inlinemath.expressions"),$o=new Set(["symbol","number"]);function yo(t){return t?"symbol"===t.type?t.value:"op"===t.type&&"_"===t.op&&2===t.args.length&&"symbol"===t.args[0].type&&$o.has(t.args[1].type)?`${t.args[0].value}_${t.args[1].value}`:null:null}function vo(t){const{id:e,...n}=t;return n.args&&(n.args=n.args.map(vo)),n}function wo(t,e){const n=(t,r)=>{if(!r&&void 0!==t.from)return e(t.from);const{id:i,from:s,...o}=t;return o.args&&(o.args=o.args.map(t=>n(t,!1))),o};return n(t,!0)}const xo=new Set;function Mo(t,e){let n=!1;const r=new Set,i=(t,s=xo)=>{const o=yo(t);if(null!==o){if(!r.has(o)&&!s.has(o)){const t=e(o);if(t){n=!0,r.add(o);const e={...i(Ks(t)),from:o};return r.delete(o),e}}return t}if(t.args){const e=function(t){const[e,n]=t.args,r=t=>t&&"symbol"===t.type?t.value:null;switch(t.op){case"der":return"="===n?.op?r(n.args[0])&&{name:r(n.args[0]),where:t=>0===t,index:1}:r(n)&&{name:r(n),where:t=>t<=1};case"int":{const i=r(n)??(3===t.args.length||1===t.args.length?q(e)||"x":null);return i&&{name:i,where:t=>0===t||1===t&&r(n)===i}}case"lim":return"→"===n?.op&&r(n.args[0])&&{name:r(n.args[0]),where:t=>0===t,index:1};case"\\sumidx":case"\\prodidx":return("="===n?.op||"∈"===n?.op)&&r(n.args[0])&&{name:r(n.args[0]),where:t=>0===t,index:1};default:return null}}(t);if(!e)return{...t,args:t.args.map(t=>i(t,s))};const n=new Set([...s,e.name]);return{...t,args:t.args.map((t,r)=>r===e.index?{...t,args:t.args.map((t,e)=>i(t,0===e?n:s))}:i(t,e.where(r)?n:s))}}return t},s=i(t);return{tree:n?vo(s):t,changed:n}}const ko="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",Eo=new RegExp(`^(${ko})\\s*\\.\\.\\s*(${ko})(?:\\s+step\\s+(${ko}))?(?:\\s*=\\s*(${ko}))?$`);function Ao(t){const e=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(t);if(!e||/\]\s*,\s*\[/.test(e[1]))return null;const n=e[1].trim(),r=Eo.exec(n);if(r){const t=Number(r[1]),e=Number(r[2]);if(!(e>t))return null;const n=void 0!==r[3]?Number(r[3]):Number.isInteger(t)&&Number.isInteger(e)?1:(e-t)/100;if(!(n>0))return null;const i=void 0!==r[4]?Math.min(e,Math.max(t,Number(r[4]))):t;return{kind:"slider",min:t,max:e,step:n,default:String(i)}}if(n.includes("|")){const t=n.split("|").map(t=>t.trim()).filter(Boolean);if(t.length)return{kind:"dropdown",options:t,default:t[0]}}return{kind:"textbox",default:n}}const No=Symbol("set on the page");class Oo{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(t){const e=new Map;for(const[n,r]of this.owners)if(n!==t)for(const[t,n]of r)e.delete(t),e.set(t,n);return e}textOf(t){const e=this.chosen.get(t.name);return e&&e.key===t.key?e.text:t.text}get(t){const e=this.definitions().get(t);return e?this.textOf(e):void 0}names(){return[...this.definitions().keys()]}set(t,e){e=String(e);const n=this.definitions().get(t);if(n&&n.input){const r=this.chosen.get(t);if(r&&r.key===n.key&&r.text===e)return this;this.chosen.set(t,{key:n.key,text:e})}else{const n=new Map(this.owners.get(No));n.set(t,{name:t,text:e,key:`page:${e}`,input:null}),this.owners.delete(No),this.owners.set(No,n)}return this.notify(null,t),this}clear(t){return void 0===t?(this.owners.clear(),this.chosen.clear()):(this.owners.get(No)?.delete(t),this.chosen.delete(t)),this.notify(null,t),this}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}own(t,e){const n=this.owners.get(t);var r,i;(r=n,i=e,(r?.size??0)===(i?.size??0)&&[...r??[]].every(([t,e])=>i?.get(t)?.key===e.key))?e&&this.owners.set(t,e):(e&&e.size?this.owners.set(t,e):this.owners.delete(t),this.notify(t))}notify(t,e){for(const n of[...this.listeners])n(t,e)}}function So(){return new Oo}const _o=So(),Io=new RegExp("(\\d+)","g");function qo(t,{delimiters:e=["$$","$","\\[","\\("]}={}){const n=[];let r="",i=0;const s=String(t).replace(/[\uE000-\uE003]/g,"�"),o=t=>0===t||"\n"===s[t-1],a=function(t){const e=new Map,n=t=>/^( {4}|\t)/.test(t);let r=0,i=!0,s=!1,o=-1;for(const a of t.split("\n")){const t=!a.trim();o>-1&&!t&&!n(a)&&(e.set(o,r-1),o=-1),o<0&&!t&&n(a)&&i&&!s&&(o=r),t||n(a)||(s=Bo.test(a)||s&&/^\s/.test(a)),i=t,r+=a.length+1}o>-1&&e.set(o,t.length);return e}(s);let l=-1;const c=new Set,u=(t,e,r)=>(n.push({source:t,display:e,raw:r,start:i,end:i+r.length}),`${n.length-1}`);for(;i<s.length;){if(a.has(i)){r+=s.slice(i,a.get(i)),i=a.get(i);continue}if(o(i)){const t=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(s.slice(i));if(t){const e=t[2],n=new RegExp(`\\n {0,3}${"`"===e[0]?"`":"~"}{${e.length},}[ \\t]*(?=\\n|$)`),o=s.slice(i+t[0].length),a=n.exec(`\n${o}`),l=a?o.slice(0,Math.max(0,a.index-1)):o,c=t[0].length+(a?a.index-1+a[0].length:o.length),h=s.slice(i,i+c);"math"===t[3].trim()?r+=u(l,!0,h):r+=h,i+=c;continue}}const t=s[i];if("`"===t){const t=/^`+/.exec(s.slice(i))[0],e=s.indexOf(t,i+t.length);if(e>-1){r+=s.slice(i,e+t.length),i=e+t.length;continue}r+=t,i+=t.length;continue}if("\\"===t){const t=s.slice(i,i+2),n="\\["===t?"\\]":"\\("===t?"\\)":null;if(n&&e.includes(t)){const e=c.has(n)?-1:s.indexOf(n,i+2);if(e<0&&c.add(n),e>-1){r+=u(s.slice(i+2,e),"\\["===t,s.slice(i,e+2)),i=e+2;continue}}r+=t,i+=2;continue}if("$"===t)if("$"===s[i+1]&&e.includes("$$")){const t=s.indexOf("$$",i+2);if(t>-1){r+=u(s.slice(i+2,t),!0,s.slice(i,t+2)),i=t+2;continue}}else if(e.includes("$")&&s[i+1]&&!/\s/.test(s[i+1])&&i+1>=l){const{end:t,stop:e}=Lo(s,i+1);if(t>-1){r+=u(s.slice(i+1,t),!1,s.slice(i,t+1)),i=t+1;continue}l=e}r+=t,i++}return{text:r,math:n}}function Lo(t,e){for(let n=e;n<t.length;n++){const e=t[n];if("\\"!==e){if("`"===e)return{end:-1,stop:n};if("\n"===e&&/^\n[ \t]*\n/.test(t.slice(n,n+64)))return{end:-1,stop:n};if("$"===e&&!/\s/.test(t[n-1])&&!/\d/.test(t[n+1]??"")&&"$"!==t[n+1])return{end:n,stop:n}}else n++}return{end:-1,stop:t.length}}const zo=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),jo=/^\s*([A-Za-z\u0370-\u03ff](?:_\{?\w+\}?)?)\s*=\s*([^=<>≤≥]+)$/;function To(t,e,n,r){const{text:i,math:s}=qo(t,e),o=n?n.definitions(r):new Map,a=t=>n?n.textOf(t):t.text,l={...e.scope??{}},c={},u=new Map,h=new Set,p=[],f=t=>{const e=new Map;return n=>{const r=o.get(n);if(!r)return null;if(!e.has(n)){let i=null;try{i=co(a(r),t)}catch{}e.set(n,i)}return e.get(n)}};let m=!0;const d=s.map((t,n)=>{const{source:r,display:i}=t;m&&r.includes("{{")&&((()=>{for(const t of Object.keys(c))delete c[t];Object.assign(c,l);for(const t of o.keys())delete c[t];let t=[...o.values()];for(;t.length;){const e=t.filter(t=>{try{const e=os(a(t),c);if("number"==typeof e.value||"bigint"==typeof e.value||Array.isArray(e.value))return c[t.name]=e.exact?e.text:e.value,!1}catch{}return!0});if(e.length===t.length)break;t=e}const e={},n=f({});for(const t of o.keys()){const r=n(t);if(r)try{e[t]=S(Mo(r,e=>e===t?null:n(e)).tree)}catch{}}c[bo]=e})(),m=!1);const s=i?"mv-md-display":"mv-md-math",d=(t,e="")=>`<span class="${s}${e}" data-mv-md="${n}">${t}</span>`;try{const s={...e.math,display:i,blocks:e.blocks,scope:c},g=function(t){let e=t.trim();const n=e.startsWith("_");n&&(e=e.slice(1).trimStart());let r=e.indexOf(":="),i=2;r<0&&n&&(r=e.search(/(?<![<>!≤≥=])=(?!=)/),i=1);const s=n?{error:"a hidden $_…$ saves a variable: $_A := 2+2$"}:null;if(r<=0)return s;const o=e.slice(0,r).trim(),a=e.slice(r+i).trim();let l=null;try{l=/\{\{/.test(o)?null:yo(co(o))}catch{}return null!==l&&a?{hidden:n,lhs:o,name:l,rhs:a,input:Ao(a)}:s}(r);if(g&&g.error)throw new Error(g.error);if(g){const{name:e,input:r,hidden:i}=g,l=r?{name:e,text:r.default,input:r,key:`input:${JSON.stringify(r)}`}:{name:e,text:g.rhs,input:null,key:`expr:${g.rhs}`,start:t.start,end:t.end};let c="";if(r){const t=function(t,e){const{input:n,name:r}=t,i=`class="mv-md-input mv-md-${n.kind}" data-mv-var="${zo(r)}" aria-label="${zo(r)}"`;if("dropdown"===n.kind)return`<select ${i}>${n.options.map(t=>`<option value="${zo(t)}"${t===e?" selected":""}>${zo(t)}</option>`).join("")}</select>`;return"slider"===n.kind?`<input type="range" ${i} min="${n.min}" max="${n.max}" step="${n.step}" value="${zo(e)}"><output class="mv-md-output" data-mv-out="${zo(r)}">${zo(e)}</output>`:`<input type="text" ${i} value="${zo(e)}" size="${Math.max(4,e.length+1)}" spellcheck="false" autocomplete="off">`}(l,a(l));c=i?t:`${uo(g.lhs,s)}<span class="mv-md-assign" aria-hidden="true">≔</span>${t}`,h.add(n)}else{const t=Mo(co(g.rhs,s),f(s)).tree;if(!i){const e=so({type:"op",op:"=",args:[Ks(co(g.lhs)),void 0===t.id?t:Ks(t)]});p[n]=e,c=function(t,e="mv"){return t.replace(`<span class="${e}-rel">=</span>`,`<span class="${e}-rel ${e}-rel-def">≔</span>`).replace(/(aria-label="[^"]*?) equals /,"$1 is defined as ").replace("<mo>=</mo>","<mo>≔</mo>")}(uo(e,s),s.prefix)}}return o.delete(e),o.set(e,l),u.set(e,l),m=!0,i&&!r?"":d(c,r?" mv-md-input-def":"")}const{tree:b,changed:$}=Mo(co(r,s),f(s));$&&so(b),p[n]=b;const y=uo(b,s);return!$&&!1!==e.define&&function(t,e,n){const r=jo.exec(t);if(!r||/\{\{/.test(r[2]))return!1;const i=r[1].replace(/[{}]/g,"");if(n.has(i))return!1;try{const t=os(r[2],e);if("number"==typeof t.value||"bigint"==typeof t.value||Array.isArray(t.value))return e[i]=t.exact?t.text:t.value,!0}catch{}return!1}(r,l,o)&&(m=!0),d(y)}catch(e){return`<span class="mv-md-error" data-mv-md="${n}" title="${zo(e.message)}"><code>${zo(t.raw)}</code></span>`}});return{text:i,math:s,drawn:d,defs:u,inputs:h,trees:p}}const Co=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,Fo=t=>Co.test(t.trim())?zo(t.trim()):"#",Ro=/\uE002(\d+)\uE003/g;function Po(t,e,n,r=[]){const i=t=>(r.push(t),`${r.length-1}`),s=t=>(t=>t.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"))(n(t).replace(Ro,(t,e)=>(r[Number(e)]??"").replace(/<[^>]*>/g,"")));let o=t;o=o.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(t,e,r)=>i(`<code>${zo(n(r.trim()))}</code>`)),o=o.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(t,e)=>i(zo(e))),o=o.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(t,e)=>i(`<a href="${Fo(e)}">${zo(e)}</a>`)),e.html&&(o=o.replace(/<\/?[A-Za-z][^>]*>/g,t=>i(t))),o=o.replace(/!\[([^\[\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(t,e,n,r)=>i(`<img src="${Fo(s(n))}" alt="${zo(s(e))}"${r?` title="${zo(s(r))}"`:""}>`)),o=o.replace(/\[([^\[\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(t,o,a,l)=>i(`<a href="${Fo(s(a))}"${l?` title="${zo(s(l))}"`:""}>${Po(o,e,n,r)}</a>`)),o=o.replace(/&(?!#\d{1,7};|#x[0-9a-f]{1,6};|[a-z][a-z0-9]{1,31};)/gi,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),o=o.replace(/(\*\*\*|___)(?=\S)([\s\S]*?\S)\1/g,"<strong><em>$2</em></strong>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*\*|__)(?![*_])([\s\S]*?\S)(\*|_)(?![*_])/g,"<em><strong>$2</strong>$4</em>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*|_)(?![*_])([\s\S]*?\S)(\*\*|__)(?![*_])/g,"<strong><em>$2</em>$4</strong>"),o=o.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),o=o.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),o=o.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),o=o.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),o=o.replace(/( {2,}|\\)\n/g,"<br>\n");for(let t=0;t<8&&/\uE002\d+\uE003/.test(o);t++)o=o.replace(Ro,(t,e)=>r[Number(e)]??"");return o}const Zo=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,Bo=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,Wo=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,Do=t=>Zo.test(t)&&!/^ {0,3}[-=]+\s*$/.test(t)&&!/^ {0,3}(?!1[.)])\d{1,9}[.)]\s/.test(t);function Uo(t){const e=t.trim();let n=e.length;for(;n>0&&"#"===e[n-1];)n--;return n===e.length?e:0===n?"":/[ \t]/.test(e[n-1])?e.slice(0,n).trimEnd():e}function Ho(t,e,n,r=0){const i=[];let s=0;const o=t=>Po(t,e,n);if(r>100)return`<p>${o(t.join("\n"))}</p>`;for(;s<t.length;){const a=t[s];if(!a.trim()){s++;continue}const l=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(a);if(l){const e=[];for(s++;s<t.length&&!new RegExp(`^ {0,3}${"`"===l[1][0]?"`":"~"}{${l[1].length},}\\s*$`).test(t[s]);)e.push(t[s++]);s++;const r=l[2]?` class="language-${zo(l[2])}"`:"";i.push(`<pre><code${r}>${zo(n(e.join("\n")))}</code></pre>`);continue}const c=/^ {0,3}(#{1,6})[ \t]+/.exec(a);if(c){i.push(`<h${c[1].length}>${o(Uo(a.slice(c[0].length)))}</h${c[1].length}>`),s++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(a)){i.push("<hr>"),s++;continue}if(/^ {0,3}>/.test(a)){const o=[];for(;s<t.length&&t[s].trim()&&(/^ {0,3}>/.test(t[s])||o.length);)o.push(t[s].replace(/^ {0,3}> ?/,"")),s++;i.push(`<blockquote>\n${Ho(o,e,n,r+1)}\n</blockquote>`);continue}const u=Bo.exec(a);if(u){const o=/\d/.test(u[2]),a=o?parseInt(u[2],10):1,l=[];let c=!1;for(;s<t.length;){const e=Bo.exec(t[s]);if(!e||/\d/.test(e[2])!==o)break;const n=e[0].length,r=[t[s].slice(n)];for(s++;s<t.length;){const e=t[s];if(!e.trim()){const e=t[s+1];if(void 0!==e&&e.startsWith(" ".repeat(Math.min(n,4)))&&e.trim()){r.push(""),c=!0,s++;continue}void 0!==e&&Bo.test(e)&&(c=!0);break}if(e.startsWith(" ".repeat(Math.min(n,4))))r.push(e.slice(Math.min(n,4)));else{if(Bo.test(e)||Zo.test(e))break;r.push(e)}s++}for(l.push(r);s<t.length&&!t[s].trim()&&void 0!==t[s+1]&&Bo.test(t[s+1]);)s++}const h=o?"ol":"ul",p=l.map(t=>{let i=Ho(t,e,n,r+1);return c||(i=i.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${i}</li>`});i.push(`<${h}${o&&1!==a?` start="${a}"`:""}>\n${p.join("\n")}\n</${h}>`);continue}if(a.includes("|")&&void 0!==t[s+1]&&Wo.test(t[s+1])&&t[s+1].includes("-")){const e=t=>t.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(t=>t.trim()),n=e(t[s+1]).map(t=>t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":t.startsWith(":")?"left":""),r=(t,e,r)=>`<${t}${n[r]?` style="text-align:${n[r]}"`:""}>${o(e)}</${t}>`,l=e(a);s+=2;const c=[];for(;s<t.length&&t[s].trim()&&t[s].includes("|");)c.push(e(t[s++]));i.push(`<table>\n<thead><tr>${l.map((t,e)=>r("th",t,e)).join("")}</tr></thead>\n<tbody>\n${c.map(t=>`<tr>${l.map((e,n)=>r("td",t[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(a)){const e=[];for(;s<t.length&&(/^( {4}|\t)/.test(t[s])||!t[s].trim());)e.push(t[s++].replace(/^( {4}|\t)/,""));for(;e.length&&!e[e.length-1].trim();)e.pop();i.push(`<pre><code>${zo(n(e.join("\n")))}</code></pre>`);continue}const h=[];for(;s<t.length&&t[s].trim()&&(!h.length||!Do(t[s]));){if(h.length&&/^ {0,3}(=+|-+)\s*$/.test(t[s])){const e="="===t[s].trim()[0]?1:2;i.push(`<h${e}>${o(h.join("\n"))}</h${e}>`),h.length=0,s++;break}h.push(t[s].replace(/^ {0,3}/,"")),s++}h.length&&i.push(`<p>${o(h.join("\n"))}</p>`)}return i.join("\n")}function Go(t,e={},n=t=>t){return Ho(String(t).replace(/\r\n?/g,"\n").replace(/[\uE002\uE003]/g,"�").split("\n"),e,n)}function Vo({text:t,math:e,drawn:n},r){return(r.render?r.render(t):Go(t,r,t=>t.replace(Io,(t,n)=>e[Number(n)]?.raw??""))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(t,r)=>e[Number(r)].display&&n[Number(r)]?`<div class="mv-md-block">${n[Number(r)]}</div>`:t).replace(Io,(t,e)=>n[Number(e)]??"").replace(/<p>\s*<\/p>\n?/g,"")}const Xo=new WeakMap,Qo=new Set;function Jo(){for(const t of Qo)t.connected()&&!t.element.isConnected&&t.stop(!0)}function Yo(t){const e=t=>function(t){if(t.length>1e6)throw new Error("The output would be too long");return t}("op"===t.type?ea(t,e):function(t){const e=t.value;return"symbol"!==t.type?e:L[e]?L[e]:"\\+"===e||"\\-"===e?e[1]:e}(t));return e(t)}const Ko={"+":"+","-":"-","*":"*","/":"/","^":"^",mod:"mod","±":"±","=":"=","===":"===","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","∪":"∪","∩":"∩","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},ta={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]};function ea(t,e){const{op:n,args:r}=t,[i,s]=r,a=(t,r)=>u(n,C(t),r)?`(${e(t)})`:e(t),l=()=>r.map(e).join(", "),c=t=>P(n,t)?`(${e(t)})`:e(t);if("*"===n&&T(t))return ea({...t,op:"neg",args:[s]},e);if("+"===n&&T(s))return ea({...t,op:"-",args:[i,s.args[1]]},e);if("-"===n&&T(s))return ea({...t,op:"+",args:[i,s.args[1]]},e);if("^"===n){const t=a(i,"left");return`${t.startsWith("-")?`(${t})`:t}^${a(s,"right")}`}if("*"===n&&t.written)return`${a(i,"left")} ${"cross"===t.written?"×":"·"} ${a(s,"right")}`;if(Ko[n])return`${a(i,"left")} ${Ko[n]} ${a(s,"right")}`;if(nt[n])return`${n}(${rt(t).map(t=>`[${t.map(e).join(", ")}]`).join(", ")})`;if(ta[n])return ta[n][0]+l()+ta[n][1];if(o(n))return`${X(n)}(${l()})`;switch(n){case"neg":return"-"+c(i);case"pmod":return`${e(i)} (mod ${e(s)})`;case"pm":return"±"+c(i);case"!":return c(i)+"!";case"\\not":return"¬"+c(i);case"sqrt":return`√(${e(i)})`;case"root":{const t="number"===i.type?{3:"∛",4:"∜"}[i.value]:null;return t?`${t}(${e(s)})`:`root(${e(i)}, ${e(s)})`}case"abs":return`|${e(i)}|`;case"floor":return`⌊${e(i)}⌋`;case"ceil":return`⌈${e(i)}⌉`;case"log":return`log_${"op"===i.type?`(${e(i)})`:e(i)}(${e(s)})`;case"loglog":return`ln(ln(${e(i)}))`;case"logloglog":return`ln(ln(ln(${e(i)})))`;case"perm":return`perm(${e(i)}, ${e(s)})`;case"comb":return`comb(${e(i)}, ${e(s)})`;case"_":return`${e(i)}_${e(s)}`;case"?:":return`${K(i)?`(${e(i)})`:e(i)} ? ${e(s)} : ${e(r[2])}`;case"sum":return r.map((t,n)=>u("+",C(t),n?"right":"left")?`(${e(t)})`:e(t)).join(" + ");case"prod":return r.map((t,n)=>u("*",C(t),n?"right":"left")?`(${e(t)})`:e(t)).join(" * ");case"der":{const{n:n,body:r,by:i,at:s,variable:o}=Q(t);if(s)return`der(${e(r)}, ${e(i)} = ${e(s)}${n>1?`, ${n}`:""})`;const a=n>1?`^${n}`:"";return o?`d${a}${e(r)}/d${e(i)}${a}`:`d${a}/d${e(i)}${a}(${e(r)})`}case"int":return function(t,e){const[n,r,i,s]=t,o=t.length>=2&&V(r)?e(r):q(n)||"x",a=`${e(n)} d${o}`;return 1===t.length||2===t.length&&V(r)?`∫ ${a}`:`int(${t.map(e).join(", ")})`}(r,e);case"lim":return function(t,e){const[n,r,i,s]=t;return 4===t.length?`lim(${e(n)}, ${e(r)}, ${e(i)}, ${z(s).toLowerCase().startsWith("r")?"r":"l"})`:`lim(${t.map(e).join(", ")})`}(r,e);case"\\sumidx":return na("∑",r,e);case"\\prodidx":return na("∏",r,e)}return`${n}(${l()})`}function na(t,e,n){const[r,i,s]=e,o="∑"===t?"sum":"prod";if(3===e.length&&"op"===i.type&&"="===i.op)return`${o}(${n(r)}, ${n(i)}, ${n(s)})`;if(2===e.length&&"op"===i.type&&"∈"===i.op)return`${o}(${n(r)}, ${n(i)})`;const a=q(r);return 3===e.length&&a?`${o}(${n(r)}, ${a} = ${n(i)}, ${n(s)})`:1===e.length?`${t} ${n(r)}`:2===e.length?`${t}[${n(i)}] ${n(r)}`:`${t}[${n(i)}, ${n(s)}] ${n(r)}`}for(const t of[Ko,ta])Object.setPrototypeOf(t,null);var ra='/*\n * Inline Math stylesheet. Everything is under .mv; colors are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight color\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d, .mv-conj { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-conj { margin: 0 0.6em; } /* x = 2 or x = 3 */\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-hook { display: inline-block; overflow: visible; margin-left: 0.05em; }\n.mv-radicand { display: inline-block; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }\n.mv-matrix-row { display: contents; }\n.mv-matrix-cell { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; position: relative; padding-top: 0.14em; }\n.mv-over::before { content: \'\'; position: absolute; left: 0; right: 0; top: 0.21em; border-top: 0.06em solid currentColor; } /* metric */\n.mv-over-low::before { top: 0.48em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; position: relative; }\n.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: -0.27em; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; } /* metric: measured over F, h, A */\n/* ˆ ˜ ˙ ¨ are spacing marks that sit high in their em: full size, pulled down onto the letter */\n.mv-accent-hat, .mv-accent-widehat, .mv-accent-tilde, .mv-accent-dot, .mv-accent-ddot { font-size: 1em; line-height: 1; top: 0.02em; }\n/* over an italic letter the mark leans with it, right of the box\'s center */\n.mv-accent:has(> .mv-var) > .mv-accent-mark { transform: translateX(0.1em); }\n/* a letter with no ascender (x, u, α; layout.js adds -low): the mark comes down to its top */\n.mv-accent-low > .mv-accent-mark { top: 0.08em; }\n.mv-accent-low > .mv-accent-hat, .mv-accent-low > .mv-accent-widehat, .mv-accent-low > .mv-accent-tilde, .mv-accent-low > .mv-accent-dot, .mv-accent-low > .mv-accent-ddot { top: 0.31em; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n/* Windows high contrast (and other forced colors) drops backgrounds and shadows: outline a highlight instead */\n@media (forced-colors: active) {\n .mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }\n}\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the box editing a part in place (view.editable, or a Markdown textbox variable) */\n.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;\n border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }\n.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }\n/* the live region a view announces steps through ({ announce: true }): read, never seen */\n.mv-sr-only, .mv-sr-math { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */\n.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }\n.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }\n/* while a part is ringed, the whole expression\'s ring steps back so the part is the one that stands out */\n.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }\n@media (forced-colors: active) {\n .mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }\n}\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with math (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */\n.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }\n.mv-md-assign { margin: 0 0.1em; }\n.mv-md-input { font: inherit; font-size: 0.9em; }\ninput.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }\ninput.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }\ninput.mv-md-slider { vertical-align: middle; }\n.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }\n';const ia=ra;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const t=document.createElement("style");t.id="inlinemath-css",t.textContent=ra,document.head.append(t)}return t.CSS=ia,t.DEFAULTS=Zs,t.PATHS=vs,t.View=fo,t.createVariables=So,t.extractMath=qo,t.layout=Hs,t.markdownToHTML=function(t,e={}){return Vo(To(t,e,e.variables||null),e)},t.nodeAt=ro,t.numberTree=so,t.pathOf=io,t.render=function(t,e,n={}){return new fo(t,e,n)},t.renderMarkdown=Go,t.renderMarkdownInto=function(t,e,n={}){const r=void 0===n.variables?_o:n.variables||null;Jo();const i=Xo.get(t);i&&i.stop(i.store!==r);let s=To(e,n,r,t);if(t.innerHTML=Vo(s,n),!r)return Xo.delete(t),t;r.own(t,s.defs);let o=t.isConnected;const a=e=>{const i=e.target,s=i&&i.dataset&&i.dataset.mvVar;if(void 0!==s&&t.contains(i)){if("text"===i.type)try{co(i.value,{blocks:n.blocks,scope:{}}),i.removeAttribute("aria-invalid")}catch{return void i.setAttribute("aria-invalid","true")}r.set(s,i.value)}},l=i=>{const o=i.target.closest?.("[data-node]"),a=o&&o.closest("[data-mv-md]");if(!a||!t.contains(a))return;const l=Number(a.dataset.mvMd),c=s.trees[l];if(!c)return;const u=Number(o.dataset.node),h=io(c,u)||[];let p=null;for(let t=h.length;t>=0&&!p;t--){const e=ro(c,h.slice(0,t));e&&void 0!==e.from&&(p={node:e,depth:t})}const f=p&&r.definitions().get(p.node.from);if(f&&f.input&&"textbox"===f.input.kind){i.preventDefault();const e=f.name,s=t.ownerDocument.querySelector(`[data-mv-var="${CSS.escape(e)}"]`),a=n.editable&&n.editable.toText;if(!a)return void(s&&(s.focus(),s.select()));const l=t=>co(t),u=ro(c,h);return void po(o,a(wo(u,l)),{label:`Edit ${e}`,parse:t=>co(t,{blocks:n.blocks}),commit:t=>{const n=ho(wo(p.node,l),h.slice(p.depth),t);r.set(e,a(n))}})}const m=f&&s.defs.get(f.name),d=m&&m.key===f.key&&void 0!==m.start?{...s.math[l],start:m.start,end:m.end,raw:e.slice(m.start,m.end)}:s.math[l];t.dispatchEvent(new CustomEvent("inlinemath:select",{bubbles:!0,detail:{index:l,start:d.start,end:d.end,raw:d.raw,source:d.source,id:u,path:h}}))};t.addEventListener("input",a),t.addEventListener("change",a),t.addEventListener("dblclick",l);const c=r.subscribe(i=>{i!==t&&(t.isConnected?(o=!0,Jo(),(()=>{const i=To(e,n,r,t);i.drawn.forEach((e,n)=>{if(e===s.drawn[n]||i.inputs.has(n))return;const r=t.querySelector(`[data-mv-md="${n}"]`);r&&(r.outerHTML=e)});for(const e of t.querySelectorAll("[data-mv-var], [data-mv-out]")){const t=i.defs.get(e.dataset.mvVar??e.dataset.mvOut);if(!t)continue;const n=r.textOf(t);void 0!==e.dataset.mvOut?e.textContent=n:e.value!==n&&e!==e.ownerDocument?.activeElement&&(e.value=n)}s=i})()):o&&u(!0))});function u(e){c(),t.removeEventListener("input",a),t.removeEventListener("change",a),t.removeEventListener("dblclick",l),Qo.delete(h),Xo.delete(t),e&&r.own(t,null)}const h={element:t,store:r,stop:u,connected:()=>o};return Qo.add(h),Xo.set(t,h),t},t.select=eo,t.shouldAnimate=go,t.signature=to,t.toHTML=uo,t.toText=function(t){return Zn(t)?"":Yo(Pn(t))},t.treeOf=co,t.variables=_o,t}({});
|
|
1
|
+
/* Inline Math 0.4.1 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
var InlineMath=function(e){"use strict";const t=-1,n={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt: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),arcsec:r(1),arccsc:r(1),arccot: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),evaluated:r(4),setbuilder: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"},"\\implies":{prec:15,assoc:"right",arity:2,fixity:"infix"},"\\iff":{prec:14,assoc:"left",arity:2,fixity:"infix"},"?:":{prec:10,assoc:"right",arity:3,fixity:"infix"}};function 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;function u(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}const h=100,p="",f="",m={[p]:"dot",[f]:"cross"},d="",g={ln:h,log:h,loglog:h,logloglog:h,sqrt:h,sqrtpow:h,pow:h,expm1:h,der:h,lim:h,int:h,round:h,fixed:h,floor:h,ceil:h,abs:h,random:h,sum:h,prod:h,"\\sumidx":h,"\\prodidx":h,perm:h,comb:h,"\\perm":h,"\\comb":h,"\\binom":h,max:h,min:h,gcd:h,mean:h,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,evaluated:h,setbuilder:h,arcsin:h,arccos:h,arctan:h,arcsec:h,arccsc:h,arccot:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,[p]:70,[f]:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"\\implies":15,"\\iff":14,"?:":10,"?":9,",":5},b=e=>Object.prototype.hasOwnProperty.call(g,e),$=new Set(["^","?:","?","log"]),y=["(","{","["],v=[")","}","]"];function w(e,t=!1){return"string"==typeof e&&(t?M:x).test(e)}const x=/^(?:\d+\.?\d*|\.\d+|\d*\.\d+\.\.)$/,M=/^-?(?:\d+\.?\d*|\.\d+|\d*\.\d+\.\.)$/;for(const e of[g])Object.setPrototypeOf(e,null);const k=e=>({type:"number",value:String(e)}),A=e=>({type:"symbol",value:e}),E=(e,t)=>({type:"op",op:e,args:t}),N=['"',"'","`"];function _(e){return w(e,!0)?k(e):N.includes(e[0])?{type:"string",value:e}:A(e)}const S={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function O(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],r=[];if(e.forEach((e,i)=>{const s=S[e]??String(e),l=a(s);if(!l)return n.push({..._(s),id:i}),void r.push(1);let c=l.arity;if(c===t){const e=n.pop();if(r.pop(),c=e&&"number"===e.type?Number(e.value):NaN,!Number.isInteger(c)||c<0)throw new Error(`'${s}' takes a variable number of arguments, so it must follow a count`);if(0===c&&!l.group&&!o(s))throw new Error(`'${s}' needs at least one argument`)}if(n.length<c)throw new Error(`'${s}' needs ${c} operand${1===c?"":"s"}`);const u=1+Math.max(0,...r.splice(r.length-c,c));if(u>1e3)throw new Error("Nested too deeply (more than 1000 levels)");r.push(u),n.push({...E(s,n.splice(n.length-c,c)),id:i})}),1!==n.length)throw new Error(`Postfix leaves ${n.length} values instead of 1`);return n[0]}function z(e,n){const r=[];return function e(i){"op"===i.type?(i.args.forEach(e),a(i.op)?.arity===t&&r.push(String(i.args.length)),n&&i.written&&(n[r.length]=i.written),r.push(i.op)):r.push(i.value)}(e),r}function I(e){if(Array.isArray(e))return O(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}function L(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>L(n,t,e))}function q(e){let t="";return L(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[S])Object.setPrototypeOf(e,null);const j={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 C(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function F(e,t,n){const r=e=>"symbol"===e.type?e.value===t?n:e:"op"!==e.type?e:Z.has(e.op)&&function(e,t){if("setbuilder"===e.op){const n=e.args[0];return("symbol"===n.type?n.value:n.args?.[0]?.value)===t}const n=e.args[1];return"symbol"===n?.type?n.value===t:"op"===n?.type&&["=","→"].includes(n.op)&&"symbol"===n.args[0]?.type&&n.args[0].value===t}(e,t)?{...e,id:void 0,args:e.args.map((t,n)=>function(e,t,n,r){if("setbuilder"===e)return 0===n&&"op"===t.type&&"∈"===t.op?{...t,id:void 0,args:[t.args[0],r(t.args[1])]}:t;if(0===n)return t;if(1===n)return"op"!==t.type||"="!==t.op&&"→"!==t.op?t:{...t,id:void 0,args:[t.args[0],...t.args.slice(1).map(r)]};return r(t)}(e.op,t,n,r))}:{...e,id:void 0,args:e.args.map(r)};return r(e)}const Z=new Set(["der","int","lim","\\sumidx","\\prodidx","evaluated","setbuilder"]);function T(e){if("op"!==e.type||"∈"!==e.op&&"∉"!==e.op)return null;const[t,n]=e.args;if("op"!==n.type||"setbuilder"!==n.op)return null;let[r,i]=n.args,s=null;if("op"===r.type&&"∈"===r.op&&"symbol"===r.args[0].type&&([r,s]=r.args),"symbol"!==r.type)return null;const o=F(i,r.value,t),a=s?{type:"op",op:"&",args:[{type:"op",op:"∈",args:[t,s]},o]}:o;return"∉"===e.op?{type:"op",op:"\\not",args:[a]}:a}function R(e){const t="string"==typeof e&&/^(-?)(\d*)(?:\.(\d*))?%$/.exec(e);if(!t||!t[2]&&!t[3])return null;const n=(t[2]||"0").padStart(3,"0")+(t[3]??""),r=n.length-(t[3]??"").length-2,i=`${n.slice(0,r).replace(/^0+(?=\d)/,"")}.${n.slice(r)}`.replace(/\.?0+$/,"");return t[1]+(""===i?"0":i)}function P(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==C(n)}function B(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":P(e)?"neg":e.op}const W=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),D=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!W.has(e.op))&&u(e.op,B(t),n);function U(e,t){const n=B(t),r=n&&a(n)?.prec;return r?"!"===e?r<=a("!").prec:"\\not"===e?r<a("\\not").prec:r<70||Y(t)||"\\not"===n:"\\not"!==e&&Y(t)}function H(e,t,n={}){const r=n.left?"bracket":Q(e),i=n.right?"bracket":X(t);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function G(e){return 1===e.length||Boolean(j[e])||/^Δ.$/.test(e)||/^d[A-Za-z\u03B1-\u03C9]$/.test(e)||/^.′+$/.test(e)}function V(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function X(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&G(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||P(e)?"sign":"/"===t?"frac":a(t)?.group||V(e)?"bracket":J(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?V(e.args[0])?"bracket":X(e.args[0]):["*","sum","prod","perm"].includes(t)?X(e.args[0]):"other"}function Q(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&G(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||V(e)||J(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?Q(e.args[e.args.length-1]):"other"}function J(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function Y(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||P(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!D(e,e.args[0],"left")&&Y(e.args[0])}const K=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),ee=e=>e.slice(2),te=new Set(["{}","()","[]","(]","[)","setbuilder","∪","∩"]);const ne=e=>"string"==typeof e&&e.startsWith("\\:")&&"startswith"===e.slice(2).toLowerCase(),re=e=>(null==e?"":String(e)).replace(/[A-Z]/g,e=>String.fromCharCode(e.charCodeAt(0)+32));function ie(e){const t="op"===e.args[1].type&&"="===e.args[1].op?e.args[1]:null,n=t?t.args[0]:e.args[1],r=t?t.args[1]:null;let i=1,s=e.args[0];for(;"op"===s.type&&"der"===s.op&&se(s.args[1],n);)i++,s=s.args[0];return{n:i,body:s,by:n,at:r,variable:"symbol"===s.type&&G(s.value)}}const se=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,oe=new Set(["<",">","≤","≥","=","===","≠","≠=","&","|","\\not","\\xor","\\nand","\\nor","\\implies","\\iff","∈","∉","≈","≡"]);function ae(e){return"op"===e.type&&(!!("="===e.op&&(t=e.args[1],"op"===t.type&&oe.has(t.op)||"symbol"===t.type&&("true"===t.value||"false"===t.value)))||e.args.some(ae));var t}const le=new Set(["<",">","≤","≥","=","≠"]);function ce(e){if("op"!==e.type||!le.has(e.op)||2!==e.args.length)return null;const[t,n]=e.args;if("op"!==t.type||!le.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[ce(t)??t,{type:"op",op:e.op,args:[t.args[1],n]}]}}for(const e of[j])Object.setPrototypeOf(e,null);const ue={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function he(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(ue,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 pe(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 fe=e=>Array.isArray(e)&&e.length>0&&!e.some(Array.isArray);function me(e){const t=e,n=t.make??(e=>e),r=t.size??(()=>1),i=t.charge??(()=>{}),s=e=>`${e.length} by ${e[0].length}`,o=(e,r)=>n(Array.from({length:e},(n,r)=>Array.from({length:e},(e,n)=>r===n?t.one():t.zero())),r);function a(e,r){return e[0].length!==r.length&&t.fail(`a ${s(e)} matrix times a ${s(r)} one`),i(e.length*r.length*r[0].length),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 l(e){const n=e.map(e=>e.slice()),s=n.length,o=n[0].length;i(s*s*o);let a=t.one(),l=0;for(let e=0;e<o&&l<s;e++){let i=-1;for(let o=l;o<s;o++)t.isZero(n[o][e])||(i<0||r(n[o][e])>r(n[i][e]))&&(i=o);if(i<0){a=t.zero();continue}i!==l&&([n[i],n[l]]=[n[l],n[i]],a=t.sub(t.zero(),a));const o=n[l][e];a=t.mul(a,o),n[l]=n[l].map(e=>t.div(e,o));for(let r=0;r<s;r++){if(r===l||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[l][r])))}l++}return l<s&&(a=t.zero()),{M:n,det:a,rank:l}}function c(e){const r=e.length;r!==e[0].length&&t.fail(`a ${s(e)} matrix has no inverse`);const i=o(r),{M:a,rank:c}=l(e.map((e,t)=>[...e,...i[t]]));return(c<r||a.some((e,n)=>t.isZero(e[n])))&&t.fail("the matrix has no inverse (its determinant is 0)"),n(a.map(e=>e.slice(r)),e)}return{identity:o,transpose:e=>n(e[0].map((t,n)=>e.map(e=>e[n])),e),times:a,det:function(e){return e.length!==e[0].length&&t.fail(`a ${s(e)} matrix has no determinant`),l(e).det},inverse:c,power:function(e,n){e.length!==e[0].length&&t.fail(`a ${s(e)} matrix has no powers`);let r=n<0n?c(e):e,i=n<0n?-n:n,l=o(e.length,e);for(;i>0n;)1n&i&&(l=a(l,r)),r=a(r,r),i>>=1n;return l},trace:e=>(e.length!==e[0].length&&t.fail(`a ${s(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 pe(t)?a(c(e),t):a(c(e),t.map(e=>[e])).map(e=>e[0])},rank:e=>l(e).rank,rref:e=>n(l(e).M,e),timesVector:(e,t)=>a(e,t.map(e=>[e])).map(e=>e[0]),vectorTimes:(e,t)=>a([e],t)[0]}}function de(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 be(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=ge(n,e,i);s?(r+=t.get(e.slice(i,i+s)),i+=s):r+=e[i++]}return r}}function ge(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 be(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),$e(e)]);return t.delete(e),t}function $e(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 ye=[["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log2","log_{2}"],["Math.log10","log_{10}"],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\cfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\%","%"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["asec(","arcsec("],["acsc(","arccsc("],["acot(","arccot("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot",p],["\\times",f],["×",f],["·",p],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],...["","\\"].flatMap(e=>["(","{"].flatMap(t=>[2,3,4,5,6,7,8,9,10].map(n=>[`${e}log${n}${t}`,`log_{${n}}${t}`]))),["\\log_10","log_{10}"],["log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\Longrightarrow"," \\implies "],["\\Rightarrow"," \\implies "],["\\implies"," \\implies "],["⇒"," \\implies "],["⟹"," \\implies "],["\\Longleftrightarrow"," \\iff "],["\\Leftrightarrow"," \\iff "],["\\iff"," \\iff "],["⇔"," \\iff "],["⟺"," \\iff "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left.",d],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⅕","(1/5)"],["⅖","(2/5)"],["⅗","(3/5)"],["⅘","(4/5)"],["⅙","(1/6)"],["⅚","(5/6)"],["⅐","(1/7)"],["⅑","(1/9)"],["⅒","(1/10)"],["⊕"," \\xor "],["∞","∞"],["⋅",p],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0]];const ve=e=>" "===e||"\t"===e||"\n"===e,we="({[",xe=")}]";const Me="ⅆ",ke=new RegExp(String.raw`(\\(?:mathrm|operatorname|text)\{d\}\s*|d)([A-Za-zα-ω](?![A-Za-z0-9])|\\(?:${"alpha|beta|gamma|delta|epsilon|varepsilon|zeta|eta|theta|vartheta|iota|kappa|lambda|mu|nu|xi|rho|sigma|tau|upsilon|phi|varphi|chi|psi|omega"})(?![A-Za-z]))`,"g");function Ae(e){const t=[String.raw`\left\{`,String.raw`\left\lbrace`,String.raw`\{`,String.raw`\lbrace`,"{"],n=[String.raw`\right\}`,String.raw`\right\rbrace`,String.raw`\}`,String.raw`\rbrace`,"}"],r=/\\[A-Za-z{]/.test(e);for(let i=0,s=0;i<50;i++){let i=-1,o="";for(let n=s;n<e.length&&i<0;n++){const s=t.find(t=>e.startsWith(t,n));s&&("{"===s&&(r||/[\\^_A-Za-z]$/.test(e.slice(0,n)))||("{"!==s||"{"!==e[n+1]?(i=n,o=s):n++))}if(i<0)return e;let a=0,l=null,c=null,u=-1,h=0;for(let t=i+o.length;t<e.length;t++){const i=n.find(n=>e.startsWith(n,t));if(0===a&&i&&("{"===o?"}"===i:"}"!==i)){u=t,o+="|"+i;break}if(!"([{".includes(e[t])||"{"===e[t]&&"\\"===e[t-1]?")]}".includes(e[t])&&"\\"!==e[t-1]&&a--:a++,0===a&&"?"===e[t]&&h++,0===a&&!l){const n=/^(?:\\middle\s*\||\\mid(?![A-Za-z])|:(?!=)|\|)/.exec(e.slice(t));n&&":"===n[0]&&h?h--:n&&"|"!==n[0]?l={at:t,length:n[0].length}:n&&r&&!c&&!/\\left\s*$|\\right\s*$|\\middle\s*$/.test(e.slice(0,t))&&(c={at:t,length:1})}}if(l??=c,u<0||!l){s=i+1;continue}const p=e.slice(i+o.split("|")[0].length,l.at).trim(),f=e.slice(l.at+l.length,u).trim();if(!p||!f){s=i+1;continue}const m=o.split("|")[1];e=`${e.slice(0,i)}setbuilder((${p}),(${f}))${e.slice(u+m.length)}`,s=i}return e}const Ee=String.raw`\\(?:[Bb]igg?|right)[lrm]?`,Ne=new RegExp(`(?:${Ee}\\s*([\\]|])|(\\]))\\s*(?=[_^])`,"g");function _e(e,t){let n=t;for(;" "===e[n];)n++;if("{"===e[n]){let t=0;for(let r=n;r<e.length;r++)if("{"===e[r])t++;else if("}"===e[r]&&0===--t)return{value:e.slice(n+1,r).trim(),end:r+1};return null}const r=/^\\[A-Za-z]+/.exec(e.slice(n));return r?{value:r[0],end:n+r[0].length}:"-"===e[n]&&/\d/.test(e[n+1]??"")?{value:e.slice(n,n+2),end:n+2}:e[n]?{value:e[n],end:n+1}:null}function Se(e,t){let n=t;for(;" "===e[n];)n++;const r=e[n];if("_"!==r&&"^"!==r)return null;const i=_e(e,n+1);if(!i)return null;let s=i.end;for(;" "===e[s];)s++;const o="_"===r?"^":"_";if(e[s]!==o)return null;const a=_e(e,s+1);return a?"_"===r?{lo:i.value,hi:a.value,end:a.end}:{lo:a.value,hi:i.value,end:a.end}:null}function Oe(e,t,n){let r=0;for(let i=t-1;i>=0;i--){if(n){if("]"===e[i])r++;else if("["===e[i]){if(0===r)return{start:i,end:i+1};r--}continue}const s=e.slice(0,i+1),o=/\\right\s*[\]|)}.]$|\\[Bb]igg?r?\s*[\]|]$/.exec(s),a=/\\left\s*(?:[[(.]|\\\{)$|\\[Bb]igg?l?\s*\[$/.exec(s);if(o&&i+1<t)r++,i-=o[0].length-1;else if(a){if(0===r)return{start:i+1-a[0].length,end:i+1};r--,i-=a[0].length-1}}return null}function ze(e,t){let n=0;for(let r=t-1;r>=0;r--){const t=e[r];if(")]}".includes(t))n++;else if("([{".includes(t)){if(0===n)return r+1;n--}else{if(0===n&&/[=<>&,]/.test(t))return r+1;if(0===n&&/\\(?:approx|leq?|geq?|neq?|to|quad|qquad)$/.test(e.slice(0,r+1)))return r+1}}return 0}function Ie(e){for(let t=0;t<50;t++){Ne.lastIndex=0;let t=null;for(let n=Ne.exec(e);n;n=Ne.exec(e)){const r=Se(e,n.index+n[0].length);if(!r)continue;const i=Boolean(n[2]),s="|"===(n[1]??n[2]),o=Oe(e,n.index,i);if((o||s&&!/^\\right/.test(n[0]))&&(!o||!/\\left\s*\|$/.test(e.slice(o.start,o.end)))){t={m:n,limits:r,opener:o};break}}if(!t)return e;const{m:n,limits:r,opener:i}=t,s=i?i.start:ze(e,n.index),o=e.slice(i?i.end:s,n.index).trim(),a=/^\s*([A-Za-zα-ωΑ-Ω]|\\[A-Za-z]+)\s*=\s*([\s\S]+)$/.exec(r.lo),l=r.hi.replace(/^\s*(?:[A-Za-zα-ωΑ-Ω]|\\[A-Za-z]+)\s*=\s*/,""),c=a?`evaluated((${o}),${a[1]},${a[2]},${l})`:`evaluated((${o}),${r.lo},${l})`;e=`${e.slice(0,s)}${s>0&&/[^\s(=]/.test(e[s-1])?" ":""}${c}${e.slice(r.end)}`}return e}const Le={__proto__:null,sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot"};const qe=100;const je={__proto__:null},Ce={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((e,t)=>{je[e]=String(t)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((e,t)=>{Ce[e]=String(t)}),Object.assign(je,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g","ʰ":"h","ⁱ":"i","ʲ":"j","ᵏ":"k","ˡ":"l","ᵐ":"m","ⁿ":"n","ᵒ":"o","ᵖ":"p","ʳ":"r","ˢ":"s","ᵗ":"t","ᵘ":"u","ᵛ":"v","ʷ":"w","ˣ":"x","ʸ":"y","ᶻ":"z"}),Object.assign(Ce,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const Fe=new RegExp(`[${Object.keys(je).join("")}]+|[${Object.keys(Ce).join("")}]+`,"g");const Ze={__proto__:null,"½":"1/2","⅓":"1/3","⅔":"2/3","¼":"1/4","¾":"3/4","⅕":"1/5","⅖":"2/5","⅗":"3/5","⅘":"4/5","⅙":"1/6","⅚":"5/6","⅐":"1/7","⅛":"1/8","⅜":"3/8","⅝":"5/8","⅞":"7/8","⅑":"1/9","⅒":"1/10"},Te=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys(Ze).join("")}])`,"g"),Re=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,Pe=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function Be(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 We(e,t){const n=[];let r=0,i=0;for(let s=0;s<e.length;s++)we.includes(e[s])?r++:xe.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 De(e,t,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(we.includes(e[n]))r++;else if(xe.includes(e[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(e)))return n;return-1}function Ue(e,t){let n=0;for(let r=t;r<e.length;r++)if(we.includes(e[r]))n++;else if(xe.includes(e[r])&&--n<0)return r;return e.length}function He(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 Ge(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(we.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&&o>0&&(e=e.slice(0,t+1)+"_{"+s+"}("+i+")"+e.slice(o+1))}return e}function Ve(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 Xe(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 Qe=new Set(["pmatrix","bmatrix","vmatrix"]);function Je(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 Qe.has(r)?r+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function Ye(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 Ke(e){const{lower:t,upper:n,next:r}=function(e){let t="",n="",r=0;return"_"===e[0]&&([t,r]=Ye(e,0),"^"===e[r]&&([n,r]=Ye(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(we.includes(e[n]))t++;else if(xe.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 u="int("+(s(o).trim()?s(o):"1");return a&&(u+=","+a),(t||n)&&(u+=","+t+","+n),u+")"+l}function et(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(xe.includes(n[e])?r--:we.includes(n[e])&&r++,0===r)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function tt(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const nt=/[A-Za-z\u0370-\u03FF]/;function rt(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 it(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function st(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 ot(e,t){if(we.includes(e[t])){let n=0;for(let r=t;r<e.length;r++)if(we.includes(e[r]))n++;else if(xe.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(we.includes(e[r]))n++;else{if(xe.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 at=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const lt="strtktk",ct="ABCDEFGHIJ",ut=e=>lt+[...String(e)].map(e=>ct[e]).join(""),ht=new RegExp(`^${lt}[${ct}]+$`);function pt(e){let t="";for(let n=0;n<e.length;n++){const r=e[n];if('"'===r||"`"===r){const r=ft(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=ft(e,n);t+=e.slice(n,r+1),n=r}else t+=r}return t}function ft(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}const mt=new RegExp(`${lt}[${ct}]+|§\\d+§`,"g");function dt(e,t){return t&&0!==t.size?e.map(e=>"string"!=typeof e?e:e.replace(mt,e=>{const n=t.get(e);if(void 0!==n)return n;for(let n=e.length-1;n>7;n--){const r=t.get(e.slice(0,n));if(void 0!==r)return r+e.slice(n)}return e})):e}const gt={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",times:"((a, b) => { const L = Array.isArray; const m = (v) => L(v) && v.length > 0 && v.every((r) => L(r) && r.length > 0 && r.length === v[0].length && !r.some(L)) && (v.length > 1 || v[0].length > 1); const l = (v) => L(v) && v.length > 0 && !v.some(L); const p = (A, B) => (A[0].length === B.length ? A.map((r) => B[0].map((_, j) => r.reduce((s, x, k) => s + x * B[k][j], 0))) : NaN); const e = (x, y) => (L(x) && L(y) ? (x.length === y.length ? x.map((t, i) => e(t, y[i])) : NaN) : L(x) ? x.map((t) => e(t, y)) : L(y) ? y.map((t) => e(x, t)) : x * y); if (m(a) && m(b)) return p(a, b); if (m(a) && l(b)) { const c = p(a, b.map((y) => [y])); return L(c) ? c.map((r) => r[0]) : c; } if (l(a) && m(b)) { const c = p([a], b); return L(c) ? c[0] : c; } return e(a, b); })",same:"((a, b) => { const s = (x, y) => (Array.isArray(x) && Array.isArray(y) ? x.length === y.length && x.every((v, i) => s(v, y[i])) : x == y); return s(a, b); })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 && Math.abs(n % 2) === 1 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))",contains:"((s, t) => { const f = (x) => (x == null ? String() : String(x)).replace(/[A-Z]/g, (c) => String.fromCharCode(c.charCodeAt(0) + 32)); return f(s).includes(f(t)); })",startswith:"((s, t) => { const f = (x) => (x == null ? String() : String(x)).replace(/[A-Z]/g, (c) => String.fromCharCode(c.charCodeAt(0) + 32)); return f(s).startsWith(f(t)); })"},bt="lambda x: str().join(chr(ord(c) + 32) if 65 <= ord(c) <= 90 else c for c in (str() if x is None or x != x else str(int(x)) if isinstance(x, float) and x.is_integer() else str(x)))",$t=`lambda s, t, f=${bt}: f(t) in f(s)`,yt=`lambda s, t, f=${bt}: f(s).startswith(f(t))`,vt={contains:`(${$t})`,startswith:`(${yt})`},wt={contains:`np.vectorize(${$t}, otypes=[bool])`,startswith:`np.vectorize(${yt}, otypes=[bool])`};for(const e of[gt,vt,wt])Object.setPrototypeOf(e,null);const xt="([{",Mt=")]}";function kt(e,t){let n=0;for(let r=t;r<e.length;r++)if(xt.includes(e[r]))n++;else if(Mt.includes(e[r])&&0===--n)return r;return-1}function At(e){if(!e.trim())return[];const t=[];let n=0,r=0;for(let i=0;i<e.length;i++)xt.includes(e[i])?n++:Mt.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 Et(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=kt(e,s);if(o<0)continue;const a=n(At(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 Nt=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),_t=e=>`(${e})`,St=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e,Ot=[...Object.entries(gt),...Object.entries(wt),...Object.entries(vt)];const zt={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(_t).join(" & ")})`,OR:e=>e.length&&`(${e.map(_t).join(" ∨ ")})`,NOT:e=>1===e.length&&`(!(${e[0]}))`,XOR:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,LOG:e=>2===e.length?`log_{${e[1]}}(${e[0]})`:1===e.length&&`log_{10}(${e[0]})`,ATAN2:e=>2===e.length&&`atan2(${e[1]}, ${e[0]})`,INT:e=>1===e.length&&`floor(${e[0]})`,FIXED:e=>(1===e.length||2===e.length)&&`fixed(${e[0]}, ${e[1]??2})`,"FLOOR.MATH":e=>1===e.length&&`floor(${e[0]})`,"CEILING.MATH":e=>1===e.length&&`ceil(${e[0]})`,FACT:e=>1===e.length&&`((${e[0]})!)`,COMBIN:e=>2===e.length&&`comb(${e.join(", ")})`,PERMUT:e=>2===e.length&&`perm(${e.join(", ")})`,AVERAGE:e=>`mean(${e.join(", ")})`,SUM:e=>`sum(${e.join(", ")})`,PRODUCT:e=>`prod(${e.join(", ")})`,MAX:e=>`max(${e.join(", ")})`,MIN:e=>`min(${e.join(", ")})`,MEDIAN:e=>`median(${e.join(", ")})`,"STDEV.P":e=>`stdev(${e.join(", ")})`,STDEVP:e=>`stdev(${e.join(", ")})`,CEILING:e=>(1===e.length||2===e.length&&"1"===e[1].trim())&&`ceil(${e[0]})`,RAND:e=>!e.length&&"random()",ISNUMBER:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,LOG10:e=>1===e.length&&`log_{10}(${e[0]})`,MMULT:e=>2===e.length&&`((${e[0]}) * (${e[1]}))`};function It(e,t){for(let n=t,r=0;n>=0;n--)if(")"===e[n])r++;else if("("===e[n]&&0===--r)return n;return-1}function Lt(e){const t="(?:[\\p{L}_][\\p{L}\\p{N}_.]*|\\d+(?:\\.\\d+)?|§\\d+§)";return e=function(e,t){const n=new RegExp(`^(?:${t})`,"u"),r=new RegExp(`(?:${t})$`,"u"),i=/[\p{L}_][\p{L}\p{N}_.]*$/u;for(let t=e.indexOf("^");t>=0;t=e.indexOf("^",t+1)){let s,o=t+1;for(;/\s/.test(e[o]??"");)o++;if("("===e[o])s=kt(e,o)+1;else{const t=n.exec(e.slice(o));s=t?o+t[0].length:0,t&&"("===e[s]&&(s=kt(e,s)+1)}if(s<=o||!/^\s*\^/.test(e.slice(s)))continue;let a,l=t;for(;l>0&&/\s/.test(e[l-1]);)l--;if(")"===e[l-1]){a=It(e,l-1);const t=a>0&&i.exec(e.slice(Math.max(0,a-64),a));t&&(a-=t[0].length)}else{const t=r.exec(e.slice(Math.max(0,l-64),l));a=t?l-t[0].length:-1}a<0||(e=`${e.slice(0,a)}(${e.slice(a,s)})${e.slice(s)}`,t=s+1)}return e}(e=(e=(e=e.replace(/^\s*=/,"").replace(/(?<![\w.])_xlfn\./g,"")).replace(/&/g,"+")).replace(new RegExp(`(^|[(,=<>*/+^-]\\s*)-\\s*(${t})(?=\\s*\\^)`,"gu"),"$1(-$2)"),t),Et(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>zt[t[1]]?.(e)||null)}const qt={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"},jt="strtktk[A-J]+";function Ct(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${jt})\\s*\\|\\|\\s*(${jt})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${jt},\\s*${jt}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const r=kt(e,n),i=r>0&&t.exec(e.slice(n,r+1));if(!i)continue;const[,s,o]=i,a=new Map([[`${s} = TRUNC(${s})`,"ℤ"],[`${s} = TRUNC(${s}) AND ${s} > 0`,"ℕ"],[`ABS(${s}) < ∞`,"ℝ"]]).get(o.trim());a&&(e=`${e.slice(0,n)}((${s}) ∈ ${a})${e.slice(r+1)}`)}e=Et(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=Et(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})`,_t(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=>qt[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=kt(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 Ft={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"},Zt={maximum:"max",minimum:"min",nanmax:"max",nanmin:"min",nansum:"sum",nanprod:"prod",nanmean:"mean",nanmedian:"median",nanstd:"stdev",mod:"mod",fmod:"mod",where:"where",isin:"isin",isclose:"isclose",isfinite:"isfinite",logical_and:"logical_and",logical_or:"logical_or",logical_not:"logical_not",logical_xor:"logical_xor",prod:"prod",sum:"sum",trunc:"trunc",union1d:"union",intersect1d:"intersection",dot:"np_times",matmul:"np_times",multiply:"np_times",array_equal:"np_equal"};const Tt=e=>e.replace(/(?<![\w.])set\s*\(\s*\)/g,"∅"),Rt={inf:"∞",nan:"NaN"};function Pt(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)=>Ft[t]?`Math.${Ft[t]}`:Zt[t]?Zt[t]:Rt[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)=>Wt[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>Wt[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>Dt[t]??Bt[t]??e)}(e=(e=(e=e.replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>Rt[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 Bt={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Wt={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},Dt={sqrt:"Math.sqrt",exp:"Math.exp",sin:"Math.sin",cos:"Math.cos",tan:"Math.tan",sinh:"Math.sinh",cosh:"Math.cosh",tanh:"Math.tanh",asin:"Math.asin",acos:"Math.acos",atan:"Math.atan",asinh:"Math.asinh",acosh:"Math.acosh",atanh:"Math.atanh",atan2:"atan2",csc:"csc",sec:"sec",cot:"cot",log:"log",Abs:"abs",floor:"floor",ceiling:"ceil",Max:"max",Min:"min",factorial:"factorial",binomial:"comb",ff:"perm",gcd:"gcd",gcd_list:"sympy_list_gcd",Mod:"mod",root:"sympy_root",real_root:"sympy_root",det:"det",Rational:"sympy_rational",Integer:"sympy_value",Float:"sympy_value",Eq:"sympy_eq",Ne:"sympy_ne",And:"sympy_and",Or:"sympy_or",Not:"sympy_not",Xor:"sympy_xor",Nand:"sympy_nand",Nor:"sympy_nor",Implies:"sympy_implies",Equivalent:"sympy_iff",Piecewise:"sympy_piecewise",FiniteSet:"sympy_set",Interval:"sympy_interval",Contains:"sympy_contains",Union:"union",Intersection:"intersection",diff:"derivative",integrate:"sympy_integrate",limit:"sympy_limit",summation:"sympy_summation",product:"sympy_product",expm1:"expm1",Matrix:""},Ut={open:"()",Lopen:"(]",Ropen:"[)"};const Ht=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?At(t[1]):null},Gt=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,Vt=e=>Ht(e)??[e],Xt={where:e=>3===e.length&&`((${e[0]}) ? (${e[1]}) : (${e[2]}))`,both:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,either:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,np_times:e=>2===e.length&&`((${e[0]}) * (${e[1]}))`,np_equal:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,logical_and:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,logical_or:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,logical_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,logical_not:e=>1===e.length&&`(!(${e[0]}))`,isin:e=>2===e.length&&`((${e[0]}) ∈ ${St(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${St(e[0])})`,isclose:e=>e.length>=2&&`((${e[0]}) ≈ (${e[1]}))`,isfinite:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,isinteger:e=>1===e.length&&`((${e[0]}) ∈ ℤ)`,factorial:e=>1===e.length&&`((${e[0]})!)`,union:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,union_:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,intersection:e=>2===e.length&&`((${e[0]}) ∩ (${e[1]}))`,sq:e=>1===e.length&&`((${e[0]})^2)`,cube:e=>1===e.length&&`((${e[0]})^3)`,fract:e=>1===e.length&&`((${e[0]}) - floor(${e[0]}))`,inversesqrt:e=>1===e.length&&`(1/sqrt(${e[0]}))`,radians:e=>1===e.length&&`((${e[0]})°)`,degrees:e=>1===e.length&&`((${e[0]})/°)`,mod:e=>2===e.length&&`((${e[0]}) \\mod (${e[1]}))`,atan:e=>2===e.length&&`atan2(${e[0]}, ${e[1]})`,exp2:e=>1===e.length&&`((2)^(${e[0]}))`,trunc:e=>1===e.length&&`((${e[0]}) < 0 ? (ceil(${e[0]})) : floor(${e[0]}))`,...Object.fromEntries([2,3,4].map(e=>[`mat${e}`,t=>t.length===e*e&&`[${Array.from({length:e},(n,r)=>`[${Array.from({length:e},(n,i)=>t[i*e+r]).join(", ")}]`).join(", ")}]`])),vec2:e=>`(${e.join(", ")})`,vec3:e=>`(${e.join(", ")})`,vec4:e=>`(${e.join(", ")})`,derivative:e=>e.length>=2&&`der(${e.join(", ")})`,sympy_rational:e=>2===e.length&&`((${e[0]})/(${e[1]}))`,sympy_value:e=>1===e.length&&`(${e[0]})`,sympy_eq:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,sympy_ne:e=>2===e.length&&`((${e[0]}) ≠ (${e[1]}))`,sympy_and:e=>e.length&&`(${e.map(_t).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(_t).join(" ∨ ")})`,sympy_not:e=>1===e.length&&`(!(${e[0]}))`,sympy_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,sympy_nand:e=>2===e.length&&`((${e[0]}) \\nand (${e[1]}))`,sympy_implies:e=>2===e.length&&`((${e[0]}) \\implies (${e[1]}))`,sympy_iff:e=>2===e.length&&`((${e[0]}) \\iff (${e[1]}))`,sympy_nor:e=>2===e.length&&`((${e[0]}) \\nor (${e[1]}))`,sympy_piecewise:e=>{const t=e.map(Ht);return!t.length||t.some(e=>!e||2!==e.length)?null:t.reduceRight((e,[t,n])=>null===e||/^True$|^true$/.test(n.trim())&&void 0===e?`(${t})`:`((${n}) ? (${t}) : ${e??"(null)"})`,void 0)},sympy_set:e=>`{${e.join(", ")}}`,sympy_interval:Gt("[]"),sympy_interval_open:Gt("()"),sympy_interval_Lopen:Gt("(]"),sympy_interval_Ropen:Gt("[)"),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=Vt(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&&Vt(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&&Vt(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:Qt("sum"),prod:Qt("prod")};function Qt(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=At(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]}))`}}function Jt(e){e=function(e){for(let t=e.lastIndexOf("(lambda");t>=0;t=t>0?e.lastIndexOf("(lambda",t-1):-1){const n=kt(e,t);if(n<0||"("!==e[n+1])continue;const r=kt(e,n+1),i=/^\(lambda\s+([\w\s,]+?)\s*:\s*([\s\S]*)\)$/.exec(e.slice(t,n+1));if(r<0||!i)continue;const s=i[1].split(",").map(e=>e.trim()),o=At(e.slice(n+2,r));if(o.length!==s.length||!s.every(e=>/^[A-Za-z_]\w*$/.test(e)))continue;const a=new Map(s.map((e,t)=>[e,o[t]])),l=i[2].replace(new RegExp(`(?<![\\w.])(${s.join("|")})(?!\\w)`,"g"),e=>`(${a.get(e)})`);if((e=e.slice(0,t)+`(${l})`+e.slice(r+1)).length>1e5)throw new Error("The expression expands too much when read")}return e}(e),e=Et(e,Nt("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=Et(e,Nt(Object.keys(Xt).join("|")),(e,t)=>Xt[t[1]](e)||null);for(let t=(e=Et(e,Nt("float"),(e,t,n)=>{if(1!==e.length)return null;const r=/^\s*\.is_integer\(\s*\)/.exec(n);return r?[`((${e[0]}) ∈ ℤ)`,r[0].length]:`(${e[0]})`})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,r=kt(e,n);let i=t;if(Mt.includes(e[t-1])){let n=0;for(i=t-1;i>=0;i--)if(Mt.includes(e[i]))n++;else if(xt.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)}) ∈ ${St(e.slice(i,t))})${e.slice(r+1)}`)}return e}for(const e of[zt,qt,Ft,Zt,Bt,Wt,Dt,Ut,Xt,Rt])Object.setPrototypeOf(e,null);const Yt=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Kt=e=>e.trim().split(/\s+/).join(String.raw`\s+`),en=e=>new RegExp(String.raw`(?<![\w.])${Kt(e)}(?![\w.])`,"gi"),tn=[["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","="]],nn="[<>≤≥=≠≈]",rn={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(rn,null);const sn=Object.entries({sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan",arcsecant:"arcsec",arccosecant:"arccsc",arccotangent:"arccot","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"}).sort((e,t)=>t[0].length-e[0].length),on=[["is non-negative","≥ 0"],["is nonnegative","≥ 0"],["is not negative","≥ 0"],["is non-positive","≤ 0"],["is nonpositive","≤ 0"],["is not positive","≤ 0"],["is positive","> 0"],["is negative","< 0"],["is non-zero","≠ 0"],["is nonzero","≠ 0"],["is not zero","≠ 0"],["is zero","= 0"],["is an integer","∈ ℤ"],["is not an integer","∉ ℤ"],["is a natural number","∈ ℕ"],["is a real number","∈ ℝ"],["is real","∈ ℝ"],["is a rational number","∈ ℚ"],["is rational","∈ ℚ"],...[["the integers","ℤ"],["the natural numbers","ℕ"],["the real numbers","ℝ"],["the rational numbers","ℚ"],["the complex numbers","ℂ"]].flatMap(([e,t])=>[[`is not in ${e}`,`∉ ${t}`],[`is in ${e}`,`∈ ${t}`]])],an=/(?<![A-Za-z])(?:is|between|exceeds|equals?|does|doesn't|least|most|than|divides|and|or|of|to|squared|cubed|twice|percent|by|over|times|plus|minus|modulo)(?![A-Za-z])/i;tn.map(([e])=>e),on.map(([e])=>e),sn.map(([e])=>`${e} of`);const ln=de([[" 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 ","→"],["===","=...="]]),cn=de([...ye,...function(){const e=[],t=(t,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"]){e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]);for(const e of["sin","cos","tan"].includes(n)?["","h"]:[""]){const 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}()]),un=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=Lt(e)),e=function(e){return e.includes("set")?Tt(Et(e,/(?<![\w.])sorted\s*\(/g,e=>{if(1!==e.length)return null;const t=e[0];for(let e=0,n=0;e<t.length;e++)if("([{".includes(t[e]))n++;else if(")]}".includes(t[e]))n--;else if(0===n&&("|"===t[e]||"&"===t[e])){const n=e=>{const t=e.trim(),n=/^set\s*\(/.exec(t);return n&&kt(t,n[0].length-1)===t.length-1?t.slice(n[0].length,-1):null},[r,i]=[n(t.slice(0,e)),n(t.slice(e+1))];return null!==r&&null!==i?`((${r}) ${"|"===t[e]?"∪":"∩"} (${i}))`:null}return null})):e}(e=Pt(e=Ct(e=(e=(e=function(e){for(const[t,n]of Ot)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]?kt(e,i):-1;if(s<0)continue;let o=e.slice(i+1,s);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="times"===t||"same"===t?At(o):null,l="factorial"===t?`((${o})!)`:2===a?.length?`((${a[0]}) ${"times"===t?"*":"="} (${a[1]}))`:`${t}(${o})`;e=e.slice(0,r)+l+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=kt(e,n),i=e.lastIndexOf("Number(",t);r<0||i<0||kt(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(xt.includes(e[t]))i++;else{if(Mt.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(Mt.includes(e[t]))i++;else{if(xt.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=Jt(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(!an.test(e))return e;let t=e;const n=(e,n,r,i="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Kt(e)}\s+(${Yt})\s+(?:and|to)\s+(${Yt})(?:\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+(${Yt})\s+to\s+(${Yt})`,"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`(${Yt})\s+`;t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${Yt})\s*(%|\s+percent)?\s+of\s+(${Yt})`,"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+(${Yt})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Yt})`,"gi"),(e,t,n,r)=>`((${t}) mod (${r}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${Yt})\s+divides\s+(${Yt})`,"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)`),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?a\s+whole\s+number(?![\w.])`,"gi"),(e,t,n)=>n?`((${t}) ∉ ℤ ∨ (${t}) < 0)`:`((${t}) ∈ ℤ & (${t}) ≥ 0)`);for(const[e,n]of on)t=t.replace(en(e),` ${n} `);t=t.replace(en("is not in")," ∉ ").replace(en("is in")," ∈ ").replace(en("is an element of")," ∈ ");for(const[e,n]of tn)t=t.replace(en(e),` ${n} `);t=t.replace(en("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`(${Yt})\s*(${nn})\s*(${Yt})\s+(and|or)\s+(${nn})`,"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+(${Yt})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${Yt})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${Yt})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${Yt})\s+to\s+the\s+power\s+of\s+(${Yt})`,"gi"),"($1)^($2)"),t=t.replace(new RegExp(String.raw`(${Yt})\s+to\s+the\s+(${Object.keys(rn).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,r)=>`(${t})^(${rn[n.toLowerCase()]??r})`),t=t.replace(new RegExp(String.raw`(${Yt})\s+to\s+the\s+(${Yt})(?![\w.])`,"gi"),"($1)^($2)");for(const[e,n]of sn)t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Kt(e)}\s+of\s+(${Yt})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${Yt})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${Yt})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${Yt})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${Yt})`,"gi"),"2*($1)"),t=t.replace(new RegExp(String.raw`(\d+(?:\.\d+)?)\s+percent(?![\w.])`,"gi"),"$1%");const i=e=>new RegExp(String.raw`(?<=[\w.′)\]}]\s+)${Kt(e)}(?=\s+[\w.(\[{-])`,"gi");for(const[e,n]of[["divided by","/"],["over","/"],["multiplied by","*"],["times","*"],["plus","+"],["minus","-"],["modulo","mod"]])t=t.replace(i(e),` ${n} `);return t}],["words",ln],["spaced",function(e){e=function(e){for(let t=e.lastIndexOf("\\sqrt");t>=0;t=t>0?e.lastIndexOf("\\sqrt",t-1):-1){let n=t+5;if(/[A-Za-z]/.test(e[n]??""))continue;for(;ve(e[n]);)n++;const r=e.slice(n);let i=/^(?:§\d+§|-?(?:\d+(?:\.\d+)?|\.\d+)|-?[A-Za-zͰ-Ͽ])/.exec(r)?.[0];if(!i&&/^\\[A-Za-z]/.test(r)&&!r.startsWith("\\left")){let e=/^\\[A-Za-z]+/.exec(r)[0].length;if(/^\d\d/.exec(r.slice(e))&&/frac$/.test(r.slice(0,e)))e+=2;else{const t=/^\s*\[[^\[\]{}]*\]/.exec(r.slice(e));for(t&&(e+=t[0].length);;){let t=e;for(;ve(r[t]);)t++;if("{"!==r[t])break;let n=0,i=-1;for(let e=t;e<r.length;e++)if("{"===r[e])n++;else if("}"===r[e]&&0===--n){i=e;break}if(i<0)break;e=i+1}}i=r.slice(0,e)}i&&(e=`${e.slice(0,t)}\\sqrt{${i}}${e.slice(n+i.length)}`)}return e}(function(e){return e=e.replace(Te,(e,t,n)=>`(${t}+${Ze[n]})`),e=e.replace(Re,(e,t,n,r)=>Number(n)<Number(r)&&3!==n.length?`(${t}+${n}/${r})`:e),e.replace(Pe,(e,t,n,r,i,s)=>{const[o,a]=[n??i,r??s];return Number(o)<Number(a)?`(${t}+\\frac{${o}}{${a}})`:e})}(function(e){return e.replace(Fe,e=>{const t=e[0]in je;return`${t?"^":"_"}{${[...e].map(e=>(t?je:Ce)[e]).join("")}}`})}(e))),e=function(e){if(/\\[io]*int|∫|(?<![A-Za-z])int\(|\\partial|∂|(?<![A-Za-z])d\s*\/\s*d|frac\s*\{\s*(?:\\mathrm\s*\{\s*d\s*\}|\\operatorname\s*\{\s*d\s*\}|d)/.test(e))return e;const t=[];for(const n of e.matchAll(ke)){const r=e.slice(0,n.index),i=e.slice(n.index+n[0].length),s="d"!==n[1];if(!s&&(/[A-Za-z0-9\\^_/]$|frac\s*\{$/.test(r)||/^\s*[/}]/.test(i)&&!/\{\s*$/.test(r)))continue;const o=s||/\\[,;:! ]\s*$/.test(r);t.push({m:n,strong:o})}const n=t.length>=2?t:t.filter(e=>e.strong);for(const{m:t}of n.reverse())e=e.slice(0,t.index)+Me+t[2]+e.slice(t.index+t[0].length);return e}(e=function(e){return e.replace(/(?:\{\s*\}|(?<![\w}\])′]))_\s*(?:\{\s*([^{}]+?)\s*\}|([A-Za-z0-9]+?))\s*(?:\\mathrm\{([CP])\}|([CP]))\s*_\s*(?:\{\s*([^{}]+?)\s*\}|([A-Za-z0-9]))/g,(e,t,n,r,i,s,o)=>`${"C"===(r??i)?"comb":"perm"}(${t??n},${s??o})`)}(function(e){return e.replace(/(?<![A-Za-z\\])([A-Za-z])\^\s*\{?\s*\(\s*([1-9]\d*)\s*\)\s*\}?(?=\s*\()/g,(e,t,n)=>{if(n.length>3||Number(n)>qe)throw new Error(`A derivative f^{(n)} is read up to n = ${qe}`);return t+"′".repeat(Number(n))})}(function(e){return e.replace(/(?<![A-Za-z\\])(arc)?(sine|cosine|tangent|secant|cosecant|cotangent)(?![A-Za-z])(?=\s*\(|\s+(?:[A-Za-z](?![A-Za-z])|\d|\\))/gi,(e,t,n)=>(t?"arc":"")+Le[n.toLowerCase()])}(e)))),/\\/.test(e)||(e=Ae(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=De(e,n+2,"then");if(r<0)return e;const i=e.slice(n+2,r),s=De(e,r+4,"else"),o=Ue(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.replace(/(?<![.\w=])\.\.\.(?![.\w=])/g,"⋯").replace(/∅/g,"\\{\\}")),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](?:[^()]*[^()\s])?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")),e=Ge(e);for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=He(e,t);else if("_"===e[t]||"^"===e[t]){const n=/^§\d+§/.exec(e.slice(t+1));if(n){e=`${e.slice(0,t+1)}{${n[0]}}${e.slice(t+1+n[0].length)}`;continue}const r=("^"===e[t]||/[A-Za-z}]/.test(e[t-1]??""))&&/^\\[A-Za-z]+(?![A-Za-z{\d])/.exec(e.slice(t+1));if(r){e=`${e.slice(0,t+1)}{${r[0]}}${e.slice(t+1+r[0].length)}`;continue}let i=t+1;for("-"===e[i]&&i++;i<e.length&&".0123456789".includes(e[i]);)i++;if(i===t+2&&"-"===e[t+1]&&(i=t+1),"-"===e[t+1]&&/^\s*[\^!]/.test(e.slice(i,i+8)))continue;i>t+1&&(e=e.slice(0,t+1)+"{"+e.slice(t+1,i)+"}"+e.slice(i))}return e}],["squeeze",function(e){return(e=e.replace(/(?<![\d.])\d{1,3}(?:[ \u00A0\u202F]\d{3})+(?![\d])/g,e=>e.replace(/[ \u00A0\u202F]/g,""))).replace(/\s+/g,(t,n)=>{const 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)||/[A-Za-z\u0370-\u03FF′]/.test(r)&&/^\\[A-Za-z]/.test(e.slice(n+t.length,n+t.length+2))&&!/\\[A-Za-z]+$/.test(e.slice(0,n))||/[A-Za-z\u0370-\u03FF′]/.test(r)&&/\d/.test(i)&&!/\\[A-Za-z]+$/.test(e.slice(0,n))?" ":/\d/.test(r)&&/\d/.test(i)&&!/\\[A-Za-z]+\s*\d*$/.test(e.slice(0,n))?"*":""})}],["symbols",cn],["bar",function(e){let t=0;for(let n=e.indexOf(d,t);n>=0;n=e.indexOf(d,t)){let r=0,i=-1;for(let t=n+1;t<e.length;t++)if("([{".includes(e[t]))r++;else if(")]}".includes(e[t]))r--;else if(0===r&&e.startsWith("|_",t)){i=t;break}i<0&&hn(),e=`${e.slice(0,n+1)}(${e.slice(n+1,i)})${e.slice(i)}`,t=n+1}return e}],["compact",function(e){if(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)+at(e.slice(r,t+1),"x",i)+e.slice(t+1+i),t=r}return e}(e=(e=Ge(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&&nt.test(e[t-1]);let r,i=null,s=t;if(e.startsWith("frac{",t)){const n=rt(e,t+4),r=n&&rt(e,n[1]);i=r&&st(n[0],r[0]),i&&(s=r[1])}else if("d"===e[t]&&!n){let[n,r]=it(e,t+1),o="";if(nt.test(e[r]??"")&&"/"===e[r+1]&&(o=e[r++]),"/"===e[r]&&"d"===e[r+1]&&nt.test(e[r+2]??"")){const t=e[r+2],[,a]=it(e,r+3);i={n:n,of:o,by:t},s=a}}if(i){if(i.of)r=at(i.of,i.by,i.n);else{const[t,n]=ot(e,s);if(!t)continue;r=at(t,i.by,i.n),s=n}e=e.slice(0,t)+r+e.slice(s),t+=3}}return e}(e),e.split("\\int").length>101)throw new Error("More than 100 integrals");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=Je(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"+Xe(e.slice(t+1)):"sqrt"===r(4)&&(e=e.slice(0,t-4)+"sqrt"+Xe(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+Ve(e.slice(t));else if("t"===n)"\\int"===i(3)&&(e=e.slice(0,t-3)+Ke(e.slice(t+1)));else if("m"===n)"\\binom"===i(5)&&(e=e.slice(0,t-5)+"\\binom"+tt(e.slice(t+1)));else if("d"===n&&"dd"===i(1)&&"("===e[t+2]){const n=et(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return(e=e.replace(/\\(?:text|textrm|textit|mathrm|mathit|mathbf|mathsf|operatorname)\{([A-Za-z])\}/g,"$1")).replace(/\\log/g,"log")}],["bars",function(e){for(let t=e.indexOf(d);t>=0;t=e.indexOf(d)){const n=hn;e.startsWith("(der(",t+1)||n();const r=pn(e,t+1,"(",")"),i=pn(e,t+5,"(",")");(i<0||r!==i+1)&&n();const s=fn(e.slice(t+6,i));(s.length<2||s.length>3||!e.startsWith("|_",r+1))&&n();const o=r;let a,l;"{"===e[o+3]?(l=pn(e,o+3,"{","}"),l<0&&n(),a=e.slice(o+4,l)):(l=o+3,a=e[l]??"");const[c,u,h]=s;a.trim()||n();const p=a.includes("=")?a:`${u}=${a}`;e=`${e.slice(0,t)}der(${c},${p}${h?`,${h}`:""})${e.slice(l+1)}`}return e}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]],hn=()=>{throw new Error("A bar with one limit (\\left. … \\right|_{x = a}) is read only after a derivative, \\left.\\frac{d}{dx} f\\right|_{x=a}; with two, \\left. F \\right|_a^b, it is F at b minus F at a")};function pn(e,t,n,r){let i=0;for(let s=t;s<e.length;s++)if(e[s]===n)i++;else if(e[s]===r&&0===--i)return s;return-1}function fn(e){const t=[];let n=0,r=0;for(let i=0;i<e.length;i++)"([{".includes(e[i])?n++:")]}".includes(e[i])?n--:","===e[i]&&0===n&&(t.push(e.slice(r,i)),r=i+1);return t.push(e.slice(r)),t}function mn(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=ut(t.size);t.set(l,i+o+i),n+=l,r=s+1}return{text:n,strings:t}}(pt(e));let i=n.replace(/\t/g," ");t.evaluate&&(i=function(e,t,n){const r=/\\[A-Za-z]/.test(e);let i=0;for(;;){let s=e.indexOf("{{",i);if(s<0)return e;let o=!1;const a=r&&dn.test(e.slice(0,s));if(gn(e,s)||a&&"{"===e[s+2]?s+=1:o=a,!e.startsWith("{{",s)){i=s;continue}const l=bn(e,s);if(l<0)return e;let c=e.slice(s+2,l).trim();for(const[e,n]of t)c=c.split(e).join(n);try{let r=n(c);if(/^["'`]/.test(r)){const e=ut(t.size);t.set(e,r),r=e}const a=e.slice(0,s).trimEnd(),u=e.slice(l+2).trimStart();/^[\d.]/.test(r)&&(/[\d.]$/.test(a)||/^[\d.]/.test(u))&&(r=`(${r})`),o&&(r=`{${r}}`),e=e.slice(0,s)+" "+r+" "+e.slice(l+2),i=s+1+r.length}catch{i=l+2}}}(i,r,t.evaluate));const s=[["strings",i]];for(const[e,t]of un){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}}const dn=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function gn(e,t){let n=0;for(;"\\"===e[t-1-n];)n++;return n%2==1}function bn(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 $n=Object.keys(g).filter(e=>100===g[e]&&/^[a-z]{2,}$/.test(e)),yn=["frac"],vn=[...Object.keys(j),"pi","tau","inf","infinity","exp"],wn="\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+/),xn=new Set([...vn,...wn,"simplify","expand","factor","cancel","diff","integrate","solve","approx","limit","true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),Mn=/^[a-zA-ZͰ-Ͽ]$/,kn=new Set(["f","g","h","u","v","F","G","H"]),An=e=>$n.includes(e)||yn.includes(e),En=[...$n,...yn,...vn].sort((e,t)=>t.length-e.length),Nn=[...$n,...yn,"pi"].sort((e,t)=>t.length-e.length);function _n(e,t=En){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 Sn(e){if(An(e))return!0;const t=_n(e,Nn);return t.length>1&&An(t[t.length-1])&&!xn.has(e)}function On(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=>Mn.test(e)))||1===e.length||xn.has(e)||An(e))return[e];var r;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return zn(_n(e),n);if(e.length<=2)return[...e];const i=zn(_n(e,Nn),n),s=i.findIndex(e=>e.length>1);if(s<0)return[e];if("pi"===i[s]&&!i.some(e=>$n.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 zn(e,t){const n=e[e.length-1];return t||!$n.includes(n)?e:[...e.slice(0,-1),...n]}const In="§",Ln=/[A-Za-zͰ-Ͽ′]/,qn=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function jn(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=e=>{r&&(qn(r)?n.push(...function(e,t,n){if((e=>ht.test(e))(e))return[e];if(y.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 kn.has(e)?[s+e]:[e];if(b(e))return[e];const n=On(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 On(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===In){i(o);const r=e.indexOf(In,t+1);if(r<0)throw new Error(`An unmatched ${In}`);const a=e.slice(t,r+1);n.push(y.includes(e[r+1])?s+a:a),t=r;continue}if("ⅆ"===o&&/[A-Za-z\u0370-\u03FF]/.test(e[t+1]??""))r&&i(o),r="",n.push("d"+e[t+1]),t+=1;else{if(qn(r)&&/[0-9]/.test(o)&&b(r+o)){const{op:i,end:s}=Cn(e,t,r+o);n.push(i),r="",t=s;continue}if(Ln.test(o)&&"′"!==o&&w(r)&&(n.push(r),r=""),Ln.test(o)&&(""===r?"′"!==o:qn(r)))r+=o;else if(/[0-9]/.test(o)&&qn(r)&&!Sn(r))r+=o;else if(qn(r)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))r&&n.push(...Fn(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(b(r+o)){const{op:i,end:s}=Cn(e,t,r+o);n.push(i),r="",t=s;continue}if(b(o)){i(o);const{op:r,end:s}=Cn(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 Cn(e,t,n){let r=t;for(;r+1<e.length&&b(n+e[r+1]);)n+=e[r+1],r++;return"!"===n&&"_"===e[r+1]&&r++,{op:n,end:r}}function Fn(e,t){if(!y.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[b(t)?t:s+t]}return w(e)?[e,"*"]:b(e)||An(e)||w(e[0])?[e]:[s+e]}const Zn=70,Tn=100,Rn="%mod",Pn=/^d[A-Za-z\u0370-\u03FF]$/,Bn=e=>y.includes(e),Wn=e=>v.includes(e),Dn=e=>o(e)||g[e]===Tn&&"_"!==e,Un=new Set(["\\comb","\\perm","comb","perm"]),Hn={frac:"/","\\binom":"\\binom"},Gn=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","\\implies","\\iff","∈","∉","true","false"]),Vn={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Xn{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(Wn(e)?`Unmatched '${e}'`:`Unexpected '${e}'`);return this.out}parseExpression(e,t=!1){this.parseOperand(),this.absorb(e,t)}absorb(e,t=!1){for(;;){const n=this.peek();if(void 0===n||Wn(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:g.mod,run:()=>this.modulo()};if(e===Rn)return{lbp:Zn,run:()=>{this.next(),this.parseExpression(Zn),this.emit("mod")}};if("pmod"===e)return{lbp:g.pmod,run:()=>{this.next(),this.parseScript(),this.emit("pmod")}};if("?:"===e)return{lbp:10,run:()=>{throw new Error("Unmatched ':'")}};if("!"===e)return{lbp:90,run:()=>{this.next(),this.emit("!")}};if("_"===e)return{lbp:Tn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(Un.has(e))return{lbp:Tn,run:()=>{this.next(),this.parseExpression(Tn),this.emit(e)}};const n=g[e];if("="===e&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!Dn(e)&&"\\not"!==e&&!(e in Hn)){const t=$.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||Dn(e)||Pn.test(e)?Zn:71,run:()=>{this.parseExpression(Zn),this.emit("*")}}}startsOperand(e){return void 0===e||Wn(e)||"|"===e?"|"===e:e!==Rn&&(!!(Bn(e)||Dn(e)||e in Hn)||!b(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:g["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(g["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(Zn,!0),this.emit("mod")}equals(e){this.next(),this.parseExpression(e),Gn.has(this.out[this.out.length-1])&&this.questionAhead()&&this.absorb(8),this.emit("=")}questionAhead(){let e=0;for(let t=this.pos;t<this.tokens.length;t++){const n=this.tokens[t];if(Bn(n))e++;else if(Wn(n)){if(0===e--)return!1}else{if(0===e&&","===n)return!1;if(0===e&&"?"===n)return!0}}return!1}ternary(){if(this.next(),this.parseExpression(10),"?:"!==this.next())throw new Error("Unmatched '?'");this.parseExpression(8),this.emit("?:")}parseOperand(){const e=this.next(),t=this.tokens[this.pos-2],n=this.peek();if(void 0===e)throw new Error("An operator is missing an operand at the end");if(Bn(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Wn(n))||Bn(t)&&Wn(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 Hn)return this.parseScript(),this.parseScript(),this.emit(Hn[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(Dn(e))return this.functionCall(e);if(e===Rn)throw new Error("'%' is missing an operand");if(Wn(e)||b(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||!w(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(Wn(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();Wn(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(Bn(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(Dn(e))return this.parseOperand();if(this.next(),void 0===e||Wn(e)||b(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(g["+"],!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(g["+"],!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&&!Bn(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(Bn(e))return this.next(),this.bracket(e);this.parseExpression(Zn,!0)}}function Qn(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(kn.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:w(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)b(r)||Bn(r)||Wn(r)||"_"===r||o(r)||w(r)?n.push(r):n.push(...Jn(r,t));return n}function Jn(e,t){if("%"===e)return[Rn];if(!e.includes("%"))return Yn(e,t);const n=e.split("%");n.length>1&&""===n[n.length-1]&&(n.pop(),n[n.length-1]+="%");const r=[];return n.forEach((e,n)=>{n>0&&r.push(Rn),""!==e&&r.push(...Yn(e,t))}),r}function Yn(e,t){let n=0;for(;n<e.length&&w(e.slice(0,n+1));)n++;if(0===n||n===e.length)return[e];const r=e.slice(n);return"%"===r?[e]:[e.slice(0,n),...(i=r,Qn(jn(i,t),t))];var i}for(const e of[Hn,Vn])Object.setPrototypeOf(e,null);const Kn=new Set(["()","[]","{}","(]","[)"]),er={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(m).map(e=>[e,"*"]))},tr=new Set(["round","fixed","der"]),nr=e=>o(e)||100===g[e];function rr(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((o,l)=>{if("∅"===o)return void n.push({list:[]});if(","===o){const e=r(o),t=r(o);return void n.push({list:[...i(t),...i(e)]})}if(Kn.has(o)){const t=i(r(o));if(!t.length&&"{}"!==o&&!nr(e[l+1]))throw new Error("Empty brackets");return void n.push(E(o,t))}const c=er[o]??o,u=a(c);if(!u){if("?"===o||"abs("===o)throw new Error(`Unmatched '${o[0]}'`);return void n.push(_(o))}let h;if(nr(o)&&Kn.has(e[l-1])&&n[n.length-1]?.op===e[l-1])h=n.pop().args;else{let e=u.arity===t||tr.has(c)?1:u.arity;if(n.length<e)throw new Error(`'${o}' needs ${e} operand${1===e?"":"s"}`);h=n.splice(n.length-e,e).map(e=>s(e,o))}const p=function(e,t){switch(e){case"sqrt":if(2===t.length)return E("root",t);break;case"round":if(1===t.length)return E("round",[t[0],k(0)]);break;case"sum":case"prod":{const n=t[1];if("op"===n?.type&&"symbol"===n.args[0]?.type&&(3===t.length&&"="===n.op||2===t.length&&"∈"===n.op))return E("sum"===e?"\\sumidx":"\\prodidx",t);break}case"evaluated":if(3===t.length)return E("evaluated",[t[0],A(q(t[0])||"x"),t[1],t[2]]);break;case"det":if(t.length>1&&t.every(e=>"op"===e.type&&"[]"===e.op))return E("det",[E("[]",t)]);break;case"fixed":if(1===t.length)return E("fixed",[t[0],k(2)]);break;case"der":if(1===t.length)return E("der",[t[0],A("x")]);if(3===t.length)return function([e,t,n]){const 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");const i="op"===t.type&&"="===t.op?t:null,s=i?i.args[0]:t;let o=e;for(let e=0;e<r;e++)o=E("der",[o,i&&e===r-1?i:s]);return o}(t);break;case"log":if(2===t.length&&"symbol"===t[0].type&&"e"===t[0].value)return E("ln",[t[1]]);break;case"lim":return sr(e,t),E("lim",function(e){const t=e=>{if("op"!==e.type)return null;if("^"===e.op&&"symbol"===e.args[1].type&&ir[e.args[1].value])return{point:e.args[0],side:ir[e.args[1].value]};const n=e.args.length?t(e.args[e.args.length-1]):null;return n&&{point:{...e,args:[...e.args.slice(0,-1),n.point]},side:n.side}},[n,r,i]=e;if(2===e.length&&"op"===r.type&&"→"===r.op){const[e,i]=r.args,s=t(i);if(s)return[n,e,s.point,A(s.side)]}const s=3===e.length&&t(i);return s?[n,r,s.point,A(s.side)]:e}(t));case"\\:if":if(2===t.length||3===t.length)return E("?:",[t[0],t[1],t[2]??A("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return sr(e,t),E(e,t)}(c,h);m[o]&&"*"===p.op&&(p.written=m[o]),n.push(p)}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");const o=["=","<",">","≤","≥","≠","≈","≡","∈","∉"],l=n[0];return l.list&&l.list.length>1&&l.list.every(e=>"op"===e.type&&o.includes(e.op))?l.list.reduce((e,t)=>E("&",[e,t])):s(n[0],"end")}const ir={"\\+":"r","\\-":"l"};function sr(e,n){const{arity:r}=a(e);if(r!==t){if(n.length!==r){throw new Error(`'${e}' takes ${r} argument${1===r?"":"s"}, not ${n.length}`)}}else if(0===n.length&&!o(e))throw new Error(`'${e}' needs at least one argument`)}for(const e of[er,ir])Object.setPrototypeOf(e,null);const or=new RegExp(`[${Object.keys(m).join("")}]`,"g"),ar=e=>e.replace(or,"*"),lr=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const cr=e=>/^[a-z][a-z0-9]*$/.test(e)&&b(e);function ur(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=We(e.slice(t+13,n),"\\\\").map(e=>We(e,"&")).filter(e=>e.join("").trim());let i=null;const s=/=|<|>|\\(?:le|ge|leq|geq|neq|ne|lt|gt)(?![A-Za-z])/;if(r.length>1&&r.every(e=>1===e.length&&s.test(e[0])))i=r.map(e=>`(${e[0].trim().replace(/\s*[,;.]$/,"")})`).join(" \\land "),e=e.slice(0,t)+`(${i})`+e.slice(n+11);else{for(let e=r.length-1;e>=0;e--){const t=r[e][0].trim().replace(/\s*[,;]$/,""),n=Be(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=function(e){return e=Ie(e),e=Ae(e),e=e.replace(/\\(?:[Bb]igg?)[lrm]?(?![A-Za-z])\s*/g,""),e=e.replace(/\^\s*(?:\\circ\b|\{\s*\\circ\s*\})|\\degree\b|\\textdegree\b/g,"°"),e=e.replace(/\\(?:cdots|ldots|dotsb|dotsc|dots)(?![A-Za-z])/g,"⋯"),e=e.replace(/(\d*)\.(\d*)\\overline\s*\{\s*(\d+)\s*\}/g,(e,t,n,r)=>`${t||"0"}.${n}${r}${r}..`),e=e.replace(/\\(?:emptyset|varnothing)(?![A-Za-z])/g,"\\{\\}"),e=e.replace(/\(\s*([A-Za-z])\s*\\circ\s*([A-Za-z])\s*\)\s*\(([^()]*)\)/g,"$1($2($3))"),e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):/[\]|]\s*_/.test(e)?Ie(e):e}let hr=null;function pr(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)`);if(e.includes(""))throw new Error("The character U+E000 can't be read: MathZetta uses it to hold § in strings");if((e=function(e,t,n){if(!e.includes(t))return e;const r=pt(e);let i="";for(let s=0;s<r.length;s++){const o=r[s];if('"'===o||"`"===o||"'"===o){const o=ft(r,s);i+=e.slice(s,o+1).replaceAll(t,n),s=o}else i+=e[s]}return i}(e,In,"")).includes(In))throw new Error(`The character ${In} can't be read: MathZetta uses it to mark names`);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=new Map,s=e=>{let t=i.get(e);return void 0===t&&(t=`${In}${r.size}${In}`,r.set(t,e),i.set(e,t)),t};e=e.replace(lr,(e,t)=>cr(t.trim())?` ${t.trim()}`:s(t.trim()));for(const n of[...t].sort((e,t)=>t.length-e.length)){const t=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${t}(?![A-Za-z0-9_])`,"g"),()=>s(n))}for(const t of[...n].sort((e,t)=>t.length-e.length)){const n=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`(?<![A-Za-z_])${n}(?![A-Za-z0-9_])(\\s*)(\\(?)`,"g"),(e,n,r)=>s(t)+(r?" * (":n))}return{text:e,protectedNames:r}}(ur(e),t.names,[...t.values??[],...s]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:u,steps:h}=function(e,t={}){const n=void 0===t.blocks?hr:t.blocks;return mn(e,{evaluate:n?e=>n(e,t.scope):void 0})}(o,{blocks:t.blocks,scope:t.scope}),p=e=>dt(dt(e,u),a).map(e=>"string"==typeof e?e.replaceAll("",In):e);n.mode=l,n.cleaned=ar(p([c])[0]),n.cleanSteps=h.map(([e,t])=>[e,ar(t)]);const f=jn(c,l);n.tokens=f.map(ar);const m=p(function(e,t="plain"){return new Xn(Qn(e,t)).parseAll().map(e=>Vn[e]??e)}(f,l));n.rawPostfix=m.map(ar);const d={},g=z(rr(m),d);n.postfix=g,n.written=d,n.tree=O(g),Object.keys(d).length&&L(n.tree,e=>{d[e.id]&&(e.written=d[e.id])})}catch(e){n.error=e instanceof RangeError?"Nested too deeply":e.message}return n}function fr(e,t={}){const n=pr(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 mr=(e,t)=>"string"==typeof e?fr(e,t):I(e),dr=e=>Array.isArray(e)&&0===e.length,gr=me({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,charge:e=>{if(Lr+=e/16,Lr>Ir)throw new Error("Too much to work out")},fail:e=>{throw new Error(e)}}),br=e=>pe(e)&&(e.length>1||e[0].length>1),$r=e=>fe(e)&&!br(e),yr=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},vr=(e,t)=>br(e)&&br(t)?gr.times(e,t):br(e)&&$r(t)?gr.timesVector(e,t):$r(e)&&br(t)?gr.vectorTimes(e,t):yr((e,t)=>e*t)(e,t),wr=(e,t)=>n=>{const r=n.length>1&&n.every($r)?n:n[0];if(!pe(r))throw new Error(`${t}() needs a matrix`);return e(r)},xr=(e,t)=>([n,r])=>{if(!fe(n)||!fe(r))throw new Error(`${t}() needs two lists`);return e(n,r)},Mr={det:wr(gr.det,"det"),inv:wr(gr.inverse,"inv"),inverse:wr(gr.inverse,"inverse"),transpose:wr(gr.transpose,"transpose"),trace:wr(gr.trace,"trace"),tr:wr(gr.trace,"tr"),rank:wr(gr.rank,"rank"),rref:wr(gr.rref,"rref"),identity:([e])=>{if(!Number.isInteger(e)||e<1||e>100)throw new Error("identity(n) takes a whole number from 1 to 100");return gr.identity(e)},dot:xr(gr.dot,"dot"),cross:xr(gr.cross,"cross"),linsolve:([e,t])=>{if(!pe(e)||!Array.isArray(t))throw new Error("linsolve() needs a matrix and a list");return gr.solve(e,t)}},kr=(e,t)=>e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args.map(e=>jr(e,t)):[jr(e,t)]),Ar={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1,"°":Math.PI/180},Er=(e,t)=>t?Er(t,e%t):Math.abs(e),Nr=(e,t)=>(e%t+t)%t,_r=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>_r(e,t[n])):e==t,Sr={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=>Mr.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,arcsec:e=>Math.acos(1/e),arccsc:e=>Math.asin(1/e),arccot:e=>Math.PI/2-Math.atan(e),arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},Or={"+":(e,t)=>Array.isArray(e)||Array.isArray(t)?yr((e,t)=>e+t)(e,t):e+t,"-":(e,t)=>Array.isArray(e)||Array.isArray(t)?yr((e,t)=>e-t)(e,t):e-t,"*":vr,"/":(e,t)=>br(t)?vr(e,gr.inverse(t)):Array.isArray(e)||Array.isArray(t)?yr((e,t)=>e/t)(e,t):e/t,"^":(e,t)=>{if(!br(e))return Array.isArray(e)?yr((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 gr.power(e,BigInt(t))},mod:Nr,log:(e,t)=>Math.log(t)/Math.log(e),root:(e,t)=>t<0&&Number.isInteger(e)&&e%2!=0?-((-t)**(1/e)):t**(1/e),atan2:Math.atan2,round:(e,t)=>(e=>Math.sign(e)*Math.round(Math.abs(e)))(e*10**t)/10**t,"±":(e,t)=>[e+t,e-t],fixed:(e,t)=>{const n=Math.trunc(t);if(!(n>=0&&n<=100))throw new Error("fixed() takes 0 to 100 decimals");return Number(e).toFixed(n)},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)},"=":_r,"===":(e,t)=>e===t,"≠":(e,t)=>!_r(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),"\\implies":(e,t)=>!e||Boolean(t),"\\iff":(e,t)=>Boolean(e)===Boolean(t)},zr={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(Er,0),"()":e=>e,"[]":e=>e,"{}":e=>e};const Ir=5e6;let Lr=0,qr=0;function jr(e,t){if(++Lr>Ir)throw new Error("Too much to work out");switch(e.type){case"number":return e.value.endsWith("..")?Number(function(e){const t=function(e){const t=/^(-?)(\d*)\.(\d+)\.\.$/.exec(e);if(!t)return null;const[,n,r,i]=t;let s=1;for(let e=1;2*e<=i.length;e++)if(i.slice(-e)===i.slice(-2*e,-e)){s=e;break}const o=i.slice(-s);let a=i;for(;a.endsWith(o);)a=a.slice(0,-s);return{sign:n,whole:r||"0",prefix:a,block:o}}(e);if(!t)return e.replace(/\.+$/,"");const{sign:n,whole:r,prefix:i,block:s}=t;return`${n}${r}.${(i+s.repeat(Math.ceil(20/s.length)+1)).slice(0,Math.max(i.length+s.length,17))}`}(e.value)):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(Ar,e.value))return Ar[e.value];if(R(e.value))return Number(R(e.value));throw new Error(`No value for '${e.value}'`)}const n=ce(e);if(n)return jr(n,t);const{op:r,args:i}=e;if("?:"===r)return jr(i[0],t)?jr(i[1],t):jr(i[2],t);if("setbuilder"===r)throw new Error("A set described by a condition has no list of values (test membership in it: y ∈ {x | P})");if(("∈"===r||"∉"===r)&&T(e))return jr(T(e),t);if("∈"===r||"∉"===r){const n=function(e){if("op"!==e.type||"∈"!==e.op&&"∉"!==e.op||2!==e.args.length)return null;const[t,n]=e.args;return"string"===n.type||e.textSearch?{text:t,within:n}:"string"!==t.type||("op"===n.type?te.has(n.op):"symbol"===n.type&&/^[ℝℤℕℚℂ∅]$/u.test(n.value))?null:{text:t,within:n}}(e);if(n){const e=jr(n.within,t);if(!Array.isArray(e))return re(e).includes(re(jr(n.text,t)))===("∈"===r)}else if("symbol"===i[1].type&&t&&Object.prototype.hasOwnProperty.call(t,i[1].value)){const e=jr(i[1],t);if("string"==typeof e)return re(e).includes(re(jr(i[0],t)))===("∈"===r)}return function(e,t){const[n,r]=e.args,i=jr(n,t);let s;if("symbol"===r.type&&Cr[r.value])return s=Cr[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=>jr(e,t)),o="["===r.op[0]?i>=e:i>e,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const e=jr(r,t);s=Array.isArray(e)&&e.includes(i)}return"∈"===e.op?s:!s}(e,t)}if(ne(r)){const[n,r]=function(e){if(2!==e.args.length)throw new Error('startswith takes a value and the text it starts with: startswith(name, "Mc")');return e.args}(e).map(e=>jr(e,t));return re(n).startsWith(re(r))}if("random"===r)return Math.random();if("evaluated"===r){const[e,n,r,s]=i,o=r=>jr(e,{...t,[n.value]:jr(r,t)});return o(s)-o(r)}if(("\\sumidx"===r||"\\prodidx"===r)&&3===i.length){const e="op"===i[1].type&&"="===i[1].op&&"symbol"===i[1].args[0].type,[n,s,o]=[i[0],e?i[1].args[1]:i[1],i[2]],a=e?i[1].args[0].value:q(n);if(!a)throw new Error(`Can't evaluate '${r}' without an index`);const l=jr(s,t),c=jr(o,t);if(!Number.isFinite(l)||!Number.isFinite(c)||c-l>1e6||Math.abs(l)>Number.MAX_SAFE_INTEGER||Math.abs(c)>Number.MAX_SAFE_INTEGER)throw new Error(`Can't evaluate '${r}' over that range`);let u="\\sumidx"===r?0:1;for(let e=l;e<=c;e++){const i=jr(n,{...t,[a]:e});u="\\sumidx"===r?u+i:u*i}return u}if("pmod"===r){const[e,n]=i,r=jr(n,t);if("op"===e.type&&["≡","="].includes(e.op)){const[n,i]=e.args.map(e=>jr(e,t));return(n-i)%r===0}return Nr(jr(e,t),r)}if("pmatrix"===r||"bmatrix"===r)return kr(e,t);if("vmatrix"===r)return gr.det(kr(e,t));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=jr(i[0],t);if(br(e))return gr.transpose(e)}const s=i.map(e=>jr(e,t));if(r.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(Mr,r.slice(2)))return Mr[r.slice(2)](s);if(Sr[r]&&1===s.length)return Sr[r](s[0]);if(Or[r]&&2===s.length)return Or[r](s[0],s[1]);if(zr[r])return zr[r](s);throw new Error(`Can't evaluate '${r}'`)}const Cr={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":e=>Number.isInteger(e)&&e>0,"ℚ":Number.isFinite,"ℂ":e=>"number"==typeof e&&!Number.isNaN(e)};for(const e of[Ar,Sr,Or,zr,Cr,Mr])Object.setPrototypeOf(e,null);class Fr extends Error{}class Zr extends Error{}class Tr extends Zr{}const Rr={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let Pr=0;function Br(e){if(Pr+=e,Pr>Rr.steps)throw new Zr("too much to work out")}const Wr=(e,t)=>Br(Number(e)*(t/64)/128);let Dr=0;const Ur=e=>e<0n?-e:e,Hr=0xFFFFFFFFFFFFn,Gr=e=>0n===e?0:Ur(e).toString(2).length;function Vr(e,t){for(e=Ur(e),t=Ur(t);t;)[e,t]=[t,e%t];return e}function Xr(e,t=1n){if(0n===t)throw new Fr("division by zero");if(t<0n&&(e=-e,t=-t),t>Hr&&(e>Hr||-e>Hr)){const n=Math.min(e.toString(16).length-(e<0n?1:0),t.toString(16).length)/16;if(Pr+=1+n*n/2,Pr>Rr.steps)throw new Zr("too much to work out")}const n=Vr(e,t)||1n;return{n:e/n,d:t/n}}const Qr=Xr(0n),Jr=Xr(1n),Yr=(e,t)=>Xr(e.n*t.d+t.n*e.d,e.d*t.d),Kr=(e,t)=>Xr(e.n*t.n,e.d*t.d),ei=(e,t)=>Xr(e.n*t.d,e.d*t.n),ti=e=>({n:-e.n,d:e.d}),ni=(e,t)=>{const n=e.n*t.d-t.n*e.d;return n<0n?-1:n>0n?1:0},ri=e=>{const t=e.n/e.d;return e.n<0n&&t*e.d!==e.n?t-1n:t};function ii(e){if(e.n<0n)return-ii(ti(e));const t=Gr(e.n),n=Gr(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 si(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 Zr(`'${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=Yr(Xr(BigInt(o||"0")),Xr(i-r,(10n**BigInt(e)-1n)*10n**BigInt(n.length)))}else l=Xr(BigInt(o+a||"0"),10n**BigInt(a.length));if(Math.abs(i)>Rr.bits/3)throw new Zr("too large to calculate");return i&&(l=i>0?Kr(l,Xr(10n**BigInt(i))):ei(l,Xr(10n**BigInt(-i)))),n<0n?ti(l):l}function oi(e,t=0,n=0,r=null){return 0n===e.n?{kind:"x",c:Qr,pi:0,e:0,root:null}:{kind:"x",c:e,pi:t,e:n,root:r}}const ai=(e,t=1n)=>oi(Xr(BigInt(e),BigInt(t))),li=oi(Jr,1),ci=oi(Jr,0,1),ui=e=>null!==e&&"object"==typeof e&&"x"===e.kind,hi=e=>ui(e)&&!e.pi&&!e.e&&!e.root,pi=e=>ui(e)?0n===e.c.n:0===e,fi=e=>hi(e)&&1n===e.c.d?e.c.n:null,mi=(e,t)=>Object.assign(e,{group:t}),di=e=>({kind:"s",text:e});function gi(e,t){return e&&t?e.n===t.n&&e.r===t.r:e===t}const bi=(e,t)=>0===ni(e.c,t.c)&&e.pi===t.pi&&e.e===t.e&&gi(e.root,t.root);function $i(e){const t=Math.max(0,Gr(e)-60);return t+Math.log2(Number(e>>BigInt(t)))}function yi(e){if("number"==typeof e)return e;if(Ui(e)&&Yi(e),ui(e)){let t=ii(e.c);if(e.pi&&(t*=Math.PI**e.pi),e.e&&(t*=Math.E**e.e),e.root){const n=function(e,t){const n=Number(e);return Number.isFinite(n)?n**(1/t):2**($i(e)/t)}(e.root.r,e.root.n);if(!(0n===e.c.n||0!==t&&Number.isFinite(t)&&Number.isFinite(n))){const t=$i(e.c.n<0n?-e.c.n:e.c.n)-$i(e.c.d)+$i(e.root.r)/e.root.n+e.pi*Math.log2(Math.PI)+e.e*Math.LOG2E;return(e.c.n<0n?-1:1)*2**t}t*=n}return t}if("boolean"==typeof e)return e?1:0;throw new Zr("not a number")}function vi(e,...t){if(Number.isNaN(e))throw new Fr("undefined");if(!Number.isFinite(e)&&t.every(Number.isFinite))throw new Zr("too large to calculate");return e}const wi=e=>"boolean"==typeof e?e:ui(e)?0n!==e.c.n:"number"==typeof e?0!==e:Boolean(e);function xi(e){if("bigint"==typeof e)return oi(Xr(e));if("number"==typeof e)return Number.isFinite(e)?oi(Number.isInteger(e)&&Math.abs(e)<=Number.MAX_SAFE_INTEGER?Xr(BigInt(e)):si(String(e))):e;if("boolean"==typeof e)return e;if("string"==typeof e)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(e.trim())?oi(si(e)):Vs(fr(e),{});if(Array.isArray(e))return!e.group&&pe(e)?mi(e.map(e=>mi(e.map(xi),"[]")),"[]"):mi(e.map(xi),e.group||"()");if(ui(e)||"function"==typeof e)return e;throw new Zr(`can't use ${typeof e} as a value`)}function Mi(e){if(Array.isArray(e))return e.map(Mi);if(Hi(e)){const{re:t,im:n}=Ki(e);return{re:yi(t),im:yi(n)}}return Ui(e)?uo(e,{decimal:!1,places:null,digits:12,maxDigits:50}):e&&"s"===e.kind?e.text:"boolean"==typeof e?e:yi(e)}function ki(e,t){if(e<2n)return e;const n=BigInt(t);let r=1n<<BigInt(Math.ceil(Gr(e)/t));for(;;){const t=((n-1n)*r+e/r**(n-1n))/n;if(t>=r)return r;r=t}}function Ai(e,t,n,r=0,i=0){if(0n===n)return oi(Qr);const{coef:s,root:o}=function(e,t){let n=1n,r=t;const i=BigInt(e),s=r<10n**24n?1000000n:10000n;let o=0;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;o++}Pr+=o/4;const a=ki(r,e);if(a**i===r&&(n*=a,r=1n),1n===r)return{coef:n,root:null};for(let t=e;t>=2;t--){if(e%t!==0)continue;const i=ki(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?oi(Kr(e,Xr(s*o.r)),r,i):oi(Kr(e,Xr(s)),r,i,o)}function Ei(e,t){const n=Kr(e.c,t.c);if(Gr(n.n)+Gr(n.d)>Rr.bits)return null;const r=e.pi+t.pi,i=e.e+t.e;if(!e.root||!t.root)return oi(n,r,i,e.root||t.root);const s=Os(e.root.n,t.root.n);if(s>Rr.rootIndex)return null;const o=e.root.r**BigInt(s/e.root.n)*t.root.r**BigInt(s/t.root.n);return Gr(o)>4e3?null:Ai(n,s,o,r,i)}function Ni(e){if(0n===e.c.n)throw new Fr("division by zero");const t=oi(ei(Jr,e.c),-e.pi,-e.e);if(!e.root)return t;const{n:n,r:r}=e.root;return Gr(r)*(n-1)>4e3?null:Ei(t,Ai(Xr(1n,r),n,r**BigInt(n-1)))}function _i(e,t){if(0n===t){if(0n===e.c.n)throw new Fr("0^0 is undefined");return oi(Jr)}if(t<0n){const n=Ni(e);return n&&_i(n,-t)}if((Gr(e.c.n)+Gr(e.c.d)+(e.root?Gr(e.root.r):0))*Number(t)>Rr.bits||t>100000n)return null;const n=Xr(e.c.n**t,e.c.d**t),r=Number(t);if(!e.root)return oi(n,e.pi*r,e.e*r);const{n:i,r:s}=e.root,o=s**(t/BigInt(i));return Ai(Kr(n,Xr(o)),i,s**(t%BigInt(i))||1n,e.pi*r,e.e*r)}function Si(e,t,n){if(!hi(e)||n>1000n)return null;const r=_i(e,t);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new Fr("not a real number");o=!0,i=-i}const a=function(e,t){const n=e.n*e.d**BigInt(t-1);return Gr(n)>4e3?null:Ai(Xr(1n,e.d),t,n)}({n:i,d:s},Number(n));return a?o?oi(ti(a.c),a.pi,a.e,a.root):a:null}function Oi(e){return t=>Array.isArray(t)?mi(t.map(t=>Oi(e)(t)),t.group):e(t)}function zi(e){const t=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new Fr("lists of different lengths");return mi(n.map((e,n)=>t(e,r[n])),n.group)}return i?mi(n.map(e=>t(e,r)),n.group):s?mi(r.map(e=>t(n,e)),r.group):e(n,r)};return t}const Ii=(e,t)=>ui(e)&&ui(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||!gi(e.root,t.root))return null;const n=Yr(e.c,t.c);return Gr(n.n)+Gr(n.d)>Rr.bits?null:oi(n,e.pi,e.e,e.root)}(e,t)||vi(yi(e)+yi(t),yi(e),yi(t)),Li=e=>ui(e)?oi(ti(e.c),e.pi,e.e,e.root):-yi(e),qi=(e,t)=>ui(e)&&ui(t)&&Ei(e,t)||vi(yi(e)*yi(t),yi(e),yi(t)),ji=zi((e,t)=>Ui(e)||Ui(t)?ls(e,t):Ii(e,t)),Ci=Oi(e=>Ui(e)?cs(e):Li(e)),Fi=(e,t)=>ji(e,Ci(t)),Zi=zi((e,t)=>Ui(e)||Ui(t)?hs(e,t):qi(e,t)),Ti=zi((e,t)=>Ui(e)||Ui(t)?function(e,t){if(!Ui(t)){if(pi(t))throw new Fr("division by zero");return Xi(Qi(e).map(e=>({vars:e.vars,re:Ri(e.re,t),im:Ri(e.im,t)})))}if(Hi(t))return hs(e,es(ns(Ki(t))));const n=function(e,t){const n=new Set(t.flatMap(e=>e.vars.map(([e])=>e)));if(1!==n.size)return null;const[r]=n,i=e=>e.vars.find(([e])=>e===r)?.[1]??0,s=t.reduce((e,t)=>i(t)>i(e)?t:e),o=i(s);if(1!==s.vars.length)return null;let a=e;const l=[];for(let e=0;e<1e3&&a.length;e++){const e=a.reduce((e,t)=>i(t)>i(e)?t:e);if(i(e)<o)return null;const n={vars:us(e.vars,[[r,-o]]),...ts(e,ns(s))};l.push(n);const c=ls(Xi(a),cs(hs(Xi([n]),Xi(t))));a=pi(c)?[]:Qi(c)}return a.length?null:Xi(l)}(Qi(e),[...t.terms.values()]);if(null===n)throw new Zr(`no value for '${Ji(t)}'`);return n}(e,t):Ri(e,t));function Ri(e,t){if(pi(t))throw new Fr("division by zero");if(ui(e)&&ui(t)){const n=Ni(t),r=n&&Ei(e,n);if(r)return r}return vi(yi(e)/yi(t),yi(e),yi(t))}const Pi=zi((e,t)=>{if(Ui(e)||Ui(t))return function(e,t){if(Ui(t)){Hi(t)||Yi(t),Ui(e)&&!Hi(e)&&Yi(e);const n=Ki(t);return ui(e)&&bi(e,ci)?ss(n):ss(ts(n,os(Ki(e))))}const n=fi(t);if(null!==n)return n>=0n?ps(e,n):(Hi(e)||Yi(e),ps(es(ns(Ki(e))),-n));Hi(e)||Yi(e);return as(Ki(e),t)}(e,t);try{return Bi(e,t)}catch(n){if(Wi&&n instanceof Fr&&"not a real number"===n.message)return as({re:e,im:ai(0)},t);throw n}});function Bi(e,t){if(ui(e)&&hi(t)){const{n:n,d:r}=t.c,i=1n===r?_i(e,n):Si(e,n,r);if(i)return i}const n=yi(e),r=yi(t);if(0===n&&0===r)throw new Fr("0^0 is undefined");if(0===n&&r<0)throw new Fr("division by zero");if(n<0&&!Number.isInteger(r))throw new Fr("not a real number");const i=n**r;if(0===i&&0!==n)throw new Tr("too small to calculate");return vi(i,n,r)}let Wi=!1;const Di=5e3,Ui=e=>null!==e&&"object"==typeof e&&"p"===e.kind,Hi=e=>Ui(e)&&1===e.terms.size&&e.terms.has(""),Gi=()=>Xi([{vars:[],re:ai(0),im:ai(1)}]),Vi=e=>e.map(([e,t])=>1===t?e:`${e}^${t}`).join("*");function Xi(e){const t=new Map;for(const n of e){const e=Vi(n.vars),r=t.get(e);t.set(e,r?{vars:n.vars,re:Ii(r.re,n.re),im:Ii(r.im,n.im)}:n)}for(const[e,n]of t)pi(n.re)&&pi(n.im)&&t.delete(e);if(t.size>Di)throw new Zr("too many terms to work out");return t.size?1===t.size&&t.has("")&&pi(t.get("").im)?t.get("").re:{kind:"p",terms:t}:ai(0)}function Qi(e){if(Ui(e))return[...e.terms.values()];if("boolean"==typeof e)return[{vars:[],re:ai(e?1:0),im:ai(0)}];if(!ui(e)&&"number"!=typeof e)throw new Zr("not a number");return[{vars:[],re:e,im:ai(0)}]}const Ji=e=>[...e.terms.values()].find(e=>e.vars.length)?.vars[0][0];function Yi(e){if(Hi(e))throw new Zr("a complex number has no real value here");throw new Zr(`no value for '${Ji(e)}'`)}const Ki=e=>Hi(e)?e.terms.get(""):{re:e,im:ai(0)},es=({re:e,im:t})=>Xi([{vars:[],re:e,im:t}]),ts=(e,t)=>({re:Ii(qi(e.re,t.re),Li(qi(e.im,t.im))),im:Ii(qi(e.re,t.im),qi(e.im,t.re))});function ns(e){const t=Ii(qi(e.re,e.re),qi(e.im,e.im));if(pi(t))throw new Fr("division by zero");return{re:Ri(e.re,t),im:Li(Ri(e.im,t))}}const rs=e=>pi(e.im)?fs(e.re,ai(0))<0?Li(e.re):e.re:Bi(Ii(qi(e.re,e.re),qi(e.im,e.im)),ai(1,2));function is(e){return pi(e.im)?fs(e.re,ai(0))<0?li:ai(0):pi(e.re)?fs(e.im,ai(0))>0?oi(Xr(1n,2n),1):oi(Xr(-1n,2n),1):Math.atan2(yi(e.im),yi(e.re))}function ss(e){const t=pi(e.re)?ai(1):Bi(ci,e.re);return es({re:qi(t,ys("cos",e.im)),im:qi(t,ys("sin",e.im))})}function os(e){if(pi(e.re)&&pi(e.im))throw new Fr("ln 0 is undefined");return{re:ws(rs(e)),im:is(e)}}function as(e,t){if(pi(e.re)&&pi(e.im))return Bi(ai(0),t);const n=Bi(rs(e),t),r=qi(t,is(e));return es({re:qi(n,ys("cos",r)),im:qi(n,ys("sin",r))})}function ls(e,t){return Xi([...Qi(e),...Qi(t)])}function cs(e){return Xi(Qi(e).map(e=>({vars:e.vars,re:Li(e.re),im:Li(e.im)})))}function us(e,t){const n=new Map(e);for(const[e,r]of t)n.set(e,(n.get(e)??0)+r);return[...n].filter(([,e])=>0!==e).sort(([e],[t])=>e<t?-1:e>t?1:0)}function hs(e,t){const n=Qi(e),r=Qi(t);Br(n.length*r.length);const i=[];for(const e of n)for(const t of r)i.push({vars:us(e.vars,t.vars),...ts(e,t)});return Xi(i)}function ps(e,t){if(!Hi(e)&&t>1000n)throw new Zr("too large to calculate");if(Ui(e)&&!Hi(e)&&function(e,t){const n=e.terms.size;let r=1;for(let e=1;e<=Math.min(t,n-1)&&r<=Di;e++)r=r*(t+e)/e;const i=new Map;for(const t of e.terms.values())for(const[e]of t.vars)i.set(e,[0,0]);for(const t of e.terms.values())for(const[e,n]of i){const r=t.vars.find(([t])=>t===e)?.[1]??0;n[0]=Math.min(n[0],r),n[1]=Math.max(n[1],r)}let s=1;for(const[e,n]of i.values())if((s*=t*(n-e)+1)>Di)break;return Math.min(r,s)}(e,Number(t))>Di)throw new Zr("too many terms to work out");if(Hi(e)&&t>1n){const{re:n,im:r}=Ki(e),i=e=>ui(e)?Gr(e.c.n)+Gr(e.c.d)+(e.root?Gr(e.root.r):0):64;if(Number(t)*Math.max(i(n),i(r),1)>2e4)return as(Ki(e),ai(t))}let n=ai(1),r=e;for(let e=t;e>0n;e>>=1n)1n&e&&(n=hs(n,r)),e>1n&&(r=hs(r,r));return n}function fs(e,t){if(Hi(e)||Hi(t))throw new Zr("complex numbers have no order");if(hi(e)&&hi(t))return ni(e.c,t.c);if(ui(e)&&ui(t)&&bi(e,t))return 0;const n=yi(e),r=yi(t);if(n===r)return 0;const i=ui(e)&&ui(t)?Math.max(Math.abs(n),Math.abs(r)):Math.max(1,Math.abs(n),Math.abs(r));return Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-r)<=1e-12*i?0:n<r?-1:1}function ms(e,t,n=!1){return Array.isArray(e)||Array.isArray(t)?Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,r)=>ms(e,t[r],n)):e&&"s"===e.kind||t&&"s"===t.kind?Boolean(e&&"s"===e.kind&&t&&"s"===t.kind&&e.text===t.text):"boolean"==typeof e&&"boolean"==typeof t?e===t:"boolean"==typeof e||"boolean"==typeof t?!!n&&ms("boolean"==typeof e?ai(e?1:0):e,"boolean"==typeof t?ai(t?1:0):t):Ui(e)||Ui(t)?function(e,t){const n=Fi(e,t);return Ui(n)?!Hi(n)&&Yi(n):pi(n)}(e,t):0===fs(e,t)}const ds={0:()=>ai(0),2:()=>ai(1,2),3:()=>Ai(Xr(1n,2n),2,2n),4:()=>Ai(Xr(1n,2n),2,3n),6:()=>ai(1)};function gs(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=ds[t];return r?n<0?Ci(r()):r():null}const bs=e=>gs(e+6),$s=(e,t)=>Math.abs(e)<1e-15&&Math.abs(t)>1e-6?0:e;function ys(e,t){const n=function(e){if(pi(e))return 0;if(!ui(e)||1!==e.pi||e.e||e.root)return null;const t=Kr(e.c,Xr(12n));return 1n!==t.d?null:Number((t.n%24n+24n)%24n)}(t);if(null!==n){const t=gs(n),r=bs(n);if(t&&r)switch(e){case"sin":return t;case"cos":return r;case"tan":return Ti(t,r);case"cot":return Ti(r,t);case"sec":return Ti(ai(1),r);case"csc":return Ti(ai(1),t)}}const r=yi(t),i=$s(Math.sin(r),r),s=$s(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 Fr("undefined");return vi(o)}function vs(e,t){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[e],r=t=>"arcsin"===e?gs(t):"arccos"===e?bs(t):bs(t)&&!pi(bs(t))?Ti(gs(t),bs(t)):null;if(ui(t))for(let e=n[0];e<=n[1];e++){const n=r(e);if(n&&ui(n)&&bi(n,t))return oi(Xr(BigInt(e),12n),1)}const i=yi(t);if("arctan"!==e&&Math.abs(i)>1)throw new Fr("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[e](i)}function ws(e){if(Ui(e))return Hi(e)?es(os(Ki(e))):Yi(e);if(Wi&&fs(e,ai(0))<0)return es({re:ws(Li(e)),im:li});if(ui(e)){if(0n===e.c.n)throw new Fr("ln 0 is undefined");if(e.c.n<0n)throw new Fr("not a real number");if(1n===e.c.n&&1n===e.c.d&&!e.pi&&!e.root)return ai(e.e)}const t=yi(e);if(t<=0)throw new Fr(0===t?"ln 0 is undefined":"not a real number");return Math.log(t)}function xs(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*xs(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 Ms(e,t){Ui(e)&&Yi(e);const n=fi(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null===n)throw new Fr(`${t} needs whole numbers`);return n}const ks=(e,t)=>Number(t)*Gr(e)>Rr.bits;const As=Oi(e=>hi(e)?oi(Xr(ri(e.c))):xi(Math.floor(yi(e)))),Es=Oi(e=>hi(e)?oi(Xr(-ri(ti(e.c)))):xi(Math.ceil(yi(e))));function Ns(e,t){const n=Number(Ms(t,"round"));if(Math.abs(n)>Rr.places)throw new Zr("too many decimal places");if(hi(e)){const t=Xr(10n**BigInt(Math.abs(n))),r=n>=0?Kr(e.c,t):ei(e.c,t),i=ri(Yr(Kr(Xr(2n),Xr(Ur(r.n),r.d)),Jr))/2n,s=Xr(r.n<0n?-i:i);return oi(n>=0?ei(s,t):Kr(s,t))}if(n>15)return yi(e);const r=10**n;return 0===r?0:Math.sign(yi(e))*Math.round(Math.abs(yi(e))*r)/r}const _s=(e,t)=>e.toFixed(Math.min(t,100))+(t>100?"0".repeat(t-100):"");function Ss(e,t){if(pi(t))throw new Fr("division by zero");if(hi(e)&&hi(t))return oi(Yr(e.c,ti(Kr(t.c,Xr(ri(ei(e.c,t.c)))))));const n=yi(e),r=yi(t);return vi((n%r+r)%r)}const Os=(e,t)=>e/zs(e,t)*t,zs=(e,t)=>t?zs(t,e%t):e,Is={pi:()=>li,"π":()=>li,tau:()=>oi(Xr(2n),1),"τ":()=>oi(Xr(2n),1),e:()=>ci,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1,"°":()=>oi(Xr(1n,180n),1)},Ls={abs:e=>Hi(e)?rs(Ki(e)):ui(e)?oi(Xr(Ur(e.c.n),e.c.d),e.pi,e.e,e.root):Math.abs(yi(e)),floor:As,ceil:Es,sqrt:e=>Pi(e,ai(1,2)),ln:Oi(ws),loglog:Oi(e=>ws(ws(e))),logloglog:Oi(e=>ws(ws(ws(e)))),expm1:Oi(e=>pi(e)?ai(0):Math.expm1(yi(e))),sinh:Oi(e=>pi(e)?ai(0):Math.sinh(yi(e))),cosh:Oi(e=>pi(e)?ai(1):Math.cosh(yi(e))),tanh:Oi(e=>pi(e)?ai(0):Math.tanh(yi(e))),arcsinh:Oi(e=>pi(e)?ai(0):Math.asinh(yi(e))),arccosh:Oi(e=>{const t=yi(e);if(t<1)throw new Fr("not a real number");return 1===t?ai(0):Math.acosh(t)}),arctanh:Oi(e=>{const t=yi(e);if(Math.abs(t)>=1)throw new Fr("undefined");return pi(e)?ai(0):Math.atanh(t)}),"!":Oi(function(e){const t=fi(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null!==t){if(t<0n)throw new Fr("factorial of a negative number");if(t>BigInt(Rr.factorial))throw new Zr("too large to calculate");Wr(t,Number(t)*Math.log2(Number(t)+1));let e=1n;for(let n=2n;n<=t;n++)e*=n;return oi(Xr(e))}const n=yi(e);if(n<0&&Number.isInteger(n))throw new Fr("factorial of a negative number");return vi(xs(n+1),n)}),neg:Ci,pm:e=>mi([e,Ci(e)],"pm"),"\\not":e=>!wi(e),det:e=>Bs.det(e)};for(const e of["sin","cos","tan","csc","sec","cot"])Ls[e]=Oi(t=>ys(e,t));for(const e of["arcsin","arccos","arctan"])Ls[e]=Oi(t=>vs(e,t));const qs=e=>{if(pi(e))throw new Fr("not a real number");return Ti(ai(1),e)};Ls.arcsec=Oi(e=>vs("arccos",qs(e))),Ls.arccsc=Oi(e=>vs("arcsin",qs(e))),Ls.arccot=Oi(e=>Fi(oi(Xr(1n,2n),1),vs("arctan",e)));const js=new Set(["pmatrix","bmatrix"]),Cs=e=>pe(e)&&(js.has(e.group)||"[]"===e.group&&e.every(e=>"[]"===e.group)&&(e.length>1||e[0].length>1)),Fs=e=>fe(e)&&!Cs(e)&&"pm"!==e.group,Zs=me({add:ji,sub:Fi,mul:Zi,div:Ti,charge:Br,isZero:e=>ui(e)?0n===e.c.n:Math.abs(yi(e))<1e-12,zero:()=>ai(0),one:()=>ai(1),size:e=>Math.abs(yi(e)),fail:e=>{throw new Fr(e)},make:(e,t)=>mi(e.map(e=>mi(e,"[]")),t&&t.group?t.group:"bmatrix")}),Ts=(e,t)=>mi(e,t&&t.group?t.group:"[]"),Rs=(e,t)=>(...n)=>{const r=n.length>1&&n.every(Fs)?mi(n.map(e=>mi(e,"[]")),"[]"):n[0];if(n.length>1&&r===n[0])throw new Zr(`${e} of more than one thing`);if(!Cs(r))throw new Zr(`${e} of something that isn't a matrix`);return t(r)};function Ps(e,t){return Cs(e)&&Cs(t)?Zs.times(e,t):Cs(e)&&Fs(t)?Ts(Zs.timesVector(e,t),t):Fs(e)&&Cs(t)?Ts(Zs.vectorTimes(e,t),e):Zi(e,t)}const Bs={det:Rs("det",e=>Ws(e)),inv:Rs("inv",Zs.inverse),inverse:Rs("inverse",Zs.inverse),transpose:Rs("transpose",Zs.transpose),trace:Rs("trace",Zs.trace),tr:Rs("tr",Zs.trace),rank:Rs("rank",e=>ai(Zs.rank(e))),rref:Rs("rref",Zs.rref),identity:e=>{const t=fi(e);if(null===t||t<1n||t>100n)throw new Zr("identity(n) needs a whole number n");return Zs.identity(Number(t))},dot:(e,t)=>{if(!Fs(e)||!Fs(t))throw new Zr("dot of something that isn't a vector");return Zs.dot(e,t)},cross:(e,t)=>{if(!Fs(e)||!Fs(t))throw new Zr("cross of something that isn't a vector");return Ts(Zs.cross(e,t),e)},linsolve:(e,t)=>{if(!Cs(e)||!Cs(t)&&!Fs(t))throw new Zr("linsolve(A, b) needs a matrix and a vector");return Cs(t)?Zs.solve(e,t):Ts(Zs.solve(e,t),t)}};function Ws(e){if(!e.some(e=>e.some(Ui)))return Zs.det(e);if(e.length!==e[0].length)throw new Fr(`a ${e.length} by ${e[0].length} matrix has no determinant`);if(e.length>6)throw new Zr("too large to calculate");const t=e=>1===e.length?e[0][0]:e[0].reduce((n,r,i)=>{const s=e.slice(1).map(e=>e.filter((e,t)=>t!==i)),o=Zi(r,t(s));return i%2?Fi(n,o):ji(n,o)},ai(0));return t(e)}function Ds(e,t){const n=e.args.map(e=>mi("op"===e.type&&"[]"===e.op?e.args.map(t):[t(e)],"[]"));if(n.some(e=>e.length!==n[0].length))throw new Fr("rows of different lengths");return mi(n,"vmatrix"===e.op?"bmatrix":e.op)}const Us={"+":ji,"-":Fi,"*":Ps,"/":(e,t)=>Cs(t)?Ps(e,Zs.inverse(t)):Ti(e,t),"^":function(e,t){if(!Cs(e))return Pi(e,t);const n=fi(t);if(null===n)throw new Zr("a matrix to a power that is not a whole number");return Zs.power(e,n)},"±":(e,t)=>mi([ji(e,t),Fi(e,t)],"pm"),mod:zi(Ss),log:zi(function(e,t){if(ui(e)&&bi(e,ci))return ws(t);const n=yi(e),r=yi(t);if(n<=0||1===n)throw new Fr("not a valid base");if(r<=0)throw new Fr(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(hi(e)&&hi(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=_i(e,BigInt(r)),o=_i(t,n);if(s&&o&&bi(s,o))return oi(Xr(BigInt(r),n))}return i}),root:zi((e,t)=>Pi(t,Ti(ai(1),e))),atan2:(e,t)=>Math.atan2(yi(e),yi(t)),round:Ns,fixed:function(e,t){const n=Number(Ms(t,"fixed"));if(n<0)throw new Fr("fixed needs 0 or more decimal places");const r=Ns(e,t);if(hi(r)){const e=r.c.n*10n**BigInt(n)/r.c.d,t=(e<0n?-e:e).toString().padStart(n+1,"0");return di(`${e<0n?"-":""}${t.slice(0,t.length-n)}${n?"."+t.slice(-n):""}`)}return di(_s(yi(r),n))},perm:function(e,t){const n=Ms(e,"permutations"),r=Ms(t,"permutations");if(r<0n||r>n)throw new Fr("undefined");if(r>BigInt(Rr.terms)||ks(n,r))throw new Zr("too large to calculate");Wr(r,Number(r)*Gr(n));let i=1n;for(let e=n-r+1n;e<=n;e++)i*=e;return oi(Xr(i))},comb:function(e,t){const n=Ms(e,"combinations");let r=Ms(t,"combinations");if(r<0n||r>n)throw new Fr("undefined");if(n-r<r&&(r=n-r),r>BigInt(Rr.terms)||ks(n,r))throw new Zr("too large to calculate");Wr(2n*r,Number(r)*Gr(n));let i=1n;for(let e=1n;e<=r;e++)i=i*(n-r+e)/e;return oi(Xr(i))},"=":(e,t)=>ms(e,t,!0),"===":(e,t)=>ms(e,t),"≠":(e,t)=>!ms(e,t,!0),"≠=":(e,t)=>!ms(e,t),"≈":(e,t)=>Math.abs(yi(e)-yi(t))<=1e-9*Math.max(1,Math.abs(yi(e)),Math.abs(yi(t))),"<":(e,t)=>fs(e,t)<0,">":(e,t)=>fs(e,t)>0,"≤":(e,t)=>fs(e,t)<=0,"≥":(e,t)=>fs(e,t)>=0,"&":(e,t)=>wi(e)&&wi(t),"|":(e,t)=>wi(e)||wi(t),"\\xor":(e,t)=>wi(e)!==wi(t),"\\nor":(e,t)=>!(wi(e)||wi(t)),"\\nand":(e,t)=>!(wi(e)&&wi(t)),"\\implies":(e,t)=>!wi(e)||wi(t),"\\iff":(e,t)=>wi(e)===wi(t)},Hs={sum:e=>e.reduce((e,t)=>ji(e,t),ai(0)),prod:e=>e.reduce((e,t)=>Zi(e,t),ai(1)),max:e=>e.reduce((e,t)=>fs(t,e)>0?t:e),min:e=>e.reduce((e,t)=>fs(t,e)<0?t:e),mean:e=>Ti(Hs.sum(e),ai(e.length)),gcd:e=>oi(Xr(e.map(e=>Ms(e,"gcd")).reduce(Vr)))},Gs=["∈","∉","∪","∩","pmod","random","(]","[)"];function Vs(e,t){if(++Pr>Rr.steps)throw new Zr("too much to work out");switch(e.type){case"number":return oi(si(e.value));case"string":return di(e.value.slice(1,-1));case"symbol":return Xs(e.value,t)}const n=ce(e);if(n)return Vs(n,t);const{op:r,args:i}=e,s=e=>Vs(e,t);if("?:"===r)return wi(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(e=>"op"!==e.type))return Xs(`${i[0].value}_${i[1].value}`,t);throw new Zr("subscript")}if("der"===r)return function(e,t){const[n,r]=e.args;if("op"===r.type&&"="===r.op){const e=eo(r.args[0]);if(!e)throw new Zr("a derivative at a point names its variable: der(f, x = a)");return to(n,e,yi(Vs(r.args[1],t)),t)}const i=eo(r);if(!i||!t[Js]?.has(i))throw new Zr(`a derivative needs a point: der(f, ${i||"x"} = a)`);return to(n,i,yi(t[i]),t)}(e,t);if("evaluated"===r){const[e,n,r,o]=i;return Fi(Vs(e,Ys(t,n.value,s(o))),Vs(e,Ys(t,n.value,s(r))))}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]=[eo(r),i,s];else{if(3!==e.length||o(r))throw new Zr("an integral needs limits to be calculated");[a,l,c]=[q(n)||"x",r,i]}let u=yi(Vs(l,t)),h=yi(Vs(c,t));if(u===h)return ai(0);let p=1;u>h&&([u,h]=[h,u],p=-1);const f=Ks(n,a,t),{value:m,error:d}=no(f,u,h);return ao(p*m,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]=[eo(r.args[0]),r.args[1]];else if(2===e.length)[o,a]=[q(n),r];else{if(!(e.length>=3))throw new Zr("a limit needs a point");[o,a]=[eo(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 Zr("a limit needs a variable");const c=Vs(a,t),u=yi(c),h=Ks(n,o,t);let p,f;if(Number.isFinite(u))if(l){({value:p,error:f}=io(e=>h(u+l*e*Math.max(1,Math.abs(u)))));try{const e=Vs(n,Ys(t,o,c));if(Math.abs(yi(e)-p)<=Math.max(f,1e-6*Math.max(1,Math.abs(p))))return e}catch(e){if(!(e instanceof Fr))throw e}}else{const e=io(e=>h(u+e*Math.max(1,Math.abs(u)))),r=io(e=>h(u-e*Math.max(1,Math.abs(u))));if(e.value===r.value)({value:p,error:f}=e);else{if(!(Number.isFinite(e.value)&&Number.isFinite(r.value)&&Math.abs(e.value-r.value)<=1e-6*Math.max(1,Math.abs(e.value))))throw new Fr("the limit does not exist");p=(e.value+r.value)/2,f=Math.max(e.error,r.error,Math.abs(e.value-r.value))}try{const e=Vs(n,Ys(t,o,c));if(Math.abs(yi(e)-p)<=1e-6*Math.max(1,Math.abs(p)))return e}catch(e){if(!(e instanceof Fr))throw e}}else({value:p,error:f}=io(e=>h(Math.sign(u)/e)));return Number.isFinite(p)?ao(p,f):p}(i,t);if("\\sumidx"===r||"\\prodidx"===r)return function(e,t,n){const[r,i,s]=t;if(t.length<3)throw new Zr("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=q(r)||"n";const l=Ms(Vs(a,n),"a sum"),c=Vs(s,n),u=e?ji:Zi;if(c===1/0){if(!e)throw new Zr("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 Fr("undefined");i+=t}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2]&&!oo(e,t,s))return ao(i,0)}if(oo(e,t,s))throw new Fr("the series diverges");const o=r[r.length-1]-r[r.length-2],a=r[r.length-2]-r[r.length-3],l=r[r.length-3]-r[r.length-4],c=o/a;if(Math.abs(o)>1e-12&&c>=.999&&a/l>=.999)throw new Fr("the series diverges");if(Math.abs(o)>1e-6*Math.max(1,Math.abs(i))&&c>=.9)throw new Zr("the series grows too slowly to tell whether it has a sum");const u=n.slice(-7).map(e=>1/e),h=r.slice(-7),p=r.slice(-8,-1),f=(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]},m=f(u,h),d=f(n.slice(-8,-1).map(e=>1/e),p);return ao(m,Math.abs(m-d))}(Ks(r,o,n),Number(l))}const h=Ms(c,"a sum");if(h-l+1n>BigInt(Rr.terms))throw new Zr("too many terms to add one by one");let p=ai(e?0:1);for(let e=l;e<=h;e++)p=u(p,Vs(r,Ys(n,o,oi(Xr(e)))));return p}("\\sumidx"===r,i,t);if(["()","[]","{}"].includes(r))return mi(i.map(s),r);if("pmatrix"===r||"bmatrix"===r)return Ds(e,s);if("vmatrix"===r)return Ws(Ds(e,s));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=s(i[0]);if(Cs(e))return Zs.transpose(e)}if("pmod"===r)return function([e,t],n){const r=n(t);return"op"===e.type&&["≡","="].includes(e.op)&&2===e.args.length?pi(Ss(Fi(n(e.args[0]),n(e.args[1])),r)):Ss(n(e),r)}(i,s);if("setbuilder"===r)throw new Zr("a set described by a condition has no list of values");if(T(e))return s(T(e));if("∈"===r||"∉"===r){const t=function(e,t){const[n,r]=e.args,i=t(n);let s;if("symbol"===r.type&&["ℤ","ℕ","ℚ","ℝ"].includes(r.value)&&ui(i))s="ℝ"===r.value||("ℚ"===r.value?hi(i):hi(i)&&1n===i.c.d&&("ℤ"===r.value||i.c.n>0n));else if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[e,n]=r.args.map(t),o=fs(i,e),a=fs(i,n);s=("["===r.op[0]?o>=0:o>0)&&("]"===r.op[1]?a<=0:a<0)}else{if("op"!==r.type||"{}"!==r.op)return;s=r.args.some(e=>ms(i,t(e)))}return"∈"===e.op?s:!s}(e,s);if(void 0!==t)return t}if(Gs.includes(r))return Qs(e,t);if(r.startsWith("\\:")){const n=r.slice(2),o=Object.prototype.hasOwnProperty.call(t,n)?t[n]:void 0;if("function"!=typeof o&&Object.prototype.hasOwnProperty.call(Bs,n))return Bs[n](...i.map(s));if("function"!=typeof o&&ne(r))return Qs(e,t);if("function"!=typeof o)throw new Zr(`no function ${r.slice(2)}`);return xi(o(...i.map(e=>Mi(s(e)))))}if(Ls[r]&&1===i.length)return Ls[r](s(i[0]));if(Us[r]&&2===i.length)return Us[r](s(i[0]),s(i[1]));if(Hs[r])return Hs[r](i.map(s));throw new Zr(`can't calculate '${r}'`)}function Xs(e,t){if(Object.prototype.hasOwnProperty.call(t,e))return t[e];if(Object.prototype.hasOwnProperty.call(Is,e))return Is[e]();if(R(e))return oi(si(R(e)));if("i"===e)return Gi();if(/^[A-Za-z\u0370-\u03FF][A-Za-z0-9_\u0370-\u03FF′]*$/.test(e))return Xi([{vars:[[e,1]],re:ai(1),im:ai(0)}]);throw new Zr(`no value for '${e}'`)}function Qs(e,t){const n={};for(const[e,r]of Object.entries(t))"function"!=typeof r&&(n[e]=Mi(r));try{return xi(function(e,t={}){0===qr&&(Lr=0),qr++;try{return jr(mr(e),t)}finally{qr--}}(e,n))}catch(e){throw new Zr(e.message)}}const Js=Symbol("bound"),Ys=(e,t,n)=>({...e,[t]:n,[Js]:new Set([...e[Js]??[],t])});function Ks(e,t,n){return r=>{try{return yi(Vs(e,Ys(n,t,r)))}catch(e){if(e instanceof Fr)return NaN;if(e instanceof Tr)return 0;throw e}}}const eo=e=>"symbol"===e.type?e.value:null;function to(e,t,n,r){const i=Ks(e,t,r);if(!Number.isFinite(i(n)))throw new Fr("undefined");const s=1e-6*Math.max(1,Math.abs(n)),o=(i(n+s)-i(n))/s,a=(i(n)-i(n-s))/s;if(!Number.isFinite(o)||!Number.isFinite(a)||Math.abs(o-a)>.001*Math.max(1,Math.abs(o)))throw new Fr("not differentiable here");let l=.1*Math.max(1,Math.abs(n));const c=1.4,u=[[(i(n+l)-i(n-l))/(2*l)]];let h=u[0][0],p=1/0;for(let e=1;e<12;e++){l/=c,u[e]=[(i(n+l)-i(n-l))/(2*l)];let t=c*c;for(let n=1;n<=e;n++){u[e][n]=(u[e][n-1]*t-u[e-1][n-1])/(t-1),t*=c*c;const r=Math.max(Math.abs(u[e][n]-u[e][n-1]),Math.abs(u[e][n]-u[e-1][n-1]));r<=p&&(p=r,h=u[e][n])}if(Math.abs(u[e][e]-u[e-1][e-1])>=2*p)break}if(!Number.isFinite(h))throw new Fr("not differentiable here");return ao(h,p)}function no(e,t,n){if(t===-1/0&&n===1/0){const t=no(e,-1/0,0),n=no(e,0,1/0);return{value:t.value+n.value,error:t.error+n.error}}return n===1/0?ro(n=>e(t+n/(1-n))/((1-n)*(1-n)),0,1):t===-1/0?ro(t=>e(n-t/(1-t))/((1-t)*(1-t)),0,1):ro(e,t,n)}function ro(e,t,n,r=0){try{return function(e,t,n){const r=(n-t)/2,i=4;let s=1,o=0,a=NaN,l=NaN,c=0;const u=s=>{const o=Math.PI/2*Math.sinh(Math.abs(s)),a=Math.exp(-2*o),l=2*r*a/(1+a),u=r*(Math.PI/2)*Math.cosh(s)*(4*a)/((1+a)*(1+a));if(0===l||0===u)return 0;const h=s>0?n-l:t+l;if(0!==s&&(h<=t||h>=n))return 0;const p=e(0===s?(t+n)/2:h);if(!Number.isFinite(p)){if(l<1e-6*r)return 0;throw new Fr("the integral diverges")}return Math.abs(s)>i-.5&&(c=Math.max(c,Math.abs(u*p))),u*p};o=u(0);for(let e=s;e<=i;e+=s)o+=u(e)+u(-e);a=s*o;for(let e=1;e<=8;e++){s/=2;for(let e=s;e<=i;e+=2*s)o+=u(e)+u(-e);l=a,a=s*o;const t=Math.max(1,Math.abs(a));if(c>1e-8*t)throw new Fr("the integral diverges");if(e>=3&&Math.abs(a-l)<=1e-13*t)break}const h=Math.abs(a-l);if(!Number.isFinite(a)||h>1e-6*Math.max(1,Math.abs(a)))throw new Fr("the integral does not converge");return{value:a,error:h}}(e,t,n)}catch(e){if(!(e instanceof Fr)||"the integral does not converge"!==e.message||r>=10)throw e}const i=(t+n)/2,s=ro(e,t,i,r+1),o=ro(e,i,n,r+1);return{value:s.value+o.value,error:s.error+o.error}}function io(e){const t=so(e),n=so(t=>e(.7548776662466927*t));if(t.value===n.value)return t;if(!Number.isFinite(t.value)||!Number.isFinite(n.value))throw new Fr("the limit does not exist");const r=Math.max(1,Math.abs(t.value)),i=Math.max(t.error,n.error,1e-6*r);if(i>.001*r)throw new Fr("the limit could not be found");if(Math.abs(t.value-n.value)<=i)return t;throw new Fr("the limit does not exist")}function so(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 Fr("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=e=>{const t=n[e+1]-n[e],r=n[e+2]-n[e+1];return r===t?n[e+2]:n[e+2]-r*r/(r-t)},a=e=>(n[e+2]-n[e+1])/(n[e+1]-n[e]),l=e=>[e,e+1].every(e=>a(e)>0&&a(e)<.95)&&Math.abs(a(e)-a(e+1))<.05;for(let e=0;e+3<n.length;e++){if(!l(e))continue;const t=o(e),n=Math.abs(t-o(e+1));Number.isFinite(t)&&(!s||n<s.error)&&(s={value:t,error:n})}const c=n[n.length-1],u=Math.abs(c-n[n.length-2]);if(!s||s.error>Math.max(u,1e-6*Math.max(1,Math.abs(c)))){if(u<=1e-6*Math.max(1,Math.abs(c)))return{value:c,error:10*u};throw new Fr("the limit could not be found")}return s}function oo(e,t,n){const r=t=>Math.max(...Array.from({length:8},(n,r)=>Math.abs(e(t+r)))),i=r(n);return i>1e-12&&i>=.5*r(t+Math.floor((n-t)/16))}function ao(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 function(e,t){if(!(t>0)||0===e)return e;const n=Math.floor(-Math.log10(t/Math.abs(e)));return n>=15?e:Number(e.toPrecision(Math.max(1,n)))}(e,t);if(Math.abs(e)<=Math.max(4*t,1e-15))return ai(0);if(Math.abs(e)<1e-10)return e;const r=[[ai(1),1e3],[li,100],[oi(Jr,2),100],[ci,100],...[2n,3n,5n,6n,7n].map(e=>[oi(Jr,0,0,{n:2,r:e}),100])];for(const[t,i]of r){const r=e/yi(t),s=lo(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*yi(t)<=n)return Ei(oi(s),t)}return e}function lo(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?Xr(BigInt(r),BigInt(s)):null}function co(e,t){if("boolean"==typeof e)return String(e);if(Ui(e))return uo(e,t);if(e&&"s"===e.kind)return JSON.stringify(e.text);if(Array.isArray(e)){if("pm"===e.group&&2===e.length&&ms(e[1],Ci(e[0])))return`±${po(e[0],t)}`;if(js.has(e.group)&&pe(e))return`${e.group}(${e.map(e=>`[${e.map(e=>co(e,t)).join(", ")}]`).join(", ")})`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[e.group]||"{}";return n+e.map(e=>co(e,t)).join(", ")+r}return"number"==typeof e?fo(e,t):t.decimal||null!==t.places?function(e,t){if(hi(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=Ur(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=t.maxDigits)return(r?"-":"")+mo(o)}}return hi(e)&&null!==t.places?co(Ns(e,ai(t.places)),{...t,places:null,decimal:!0}):fo(yi(e),t)}(e,t):function(e,t){const{c:n}=e,r=Ur(n.n);if(r.toString().length>t.maxDigits||n.d.toString().length>t.maxDigits)return function(e,t){if(!hi(e))return fo(yi(e),t);if(1n!==e.c.d){const n=yi(e);if(0!==n&&Number.isFinite(n))return fo(n,t);const r=Ur(e.c.n),i=e.c.d,s=t.digits+1-(r.toString().length-i.toString().length),o=(s>=0?r*10n**BigInt(s)/i:r/(i*10n**BigInt(-s))).toString(),a=((BigInt(o.slice(0,t.digits+1))+5n)/10n).toString(),l=o.length-1-s+(a.length>t.digits?1:0),c=mo(`${a[0]}.${a.slice(1,t.digits)}`);return`${e.c.n<0n?"-":""}${c}*10^(${l})`}const n=Ur(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=mo(`${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)}function uo(e,t){const n=e=>e.vars.reduce((e,[,t])=>e+t,0),r=[...new Set([...e.terms.values()].flatMap(e=>e.vars.map(([e])=>e)))].sort(),i=(e,t)=>e.vars.find(([e])=>e===t)?.[1]??0,s=[...e.terms.values()].sort((e,t)=>n(t)-n(e)||r.reduce((n,r)=>n||i(t,r)-i(e,r),0)).map(e=>function(e,t){const n=Vi(e.vars);if(!n)return ho(e.re,e.im,t);if(!pi(e.im))return`(${ho(e.re,e.im,t)})*${n}`;const r=e.re,i=co(r,t);if("1"===i)return n;if("-1"===i)return`-${n}`;if(hi(r)&&1n!==r.c.d&&!t.decimal&&null===t.places){const e=Ur(r.c.n);return`${r.c.n<0n?"-":""}${1n===e?n:`${e}*${n}`}/${r.c.d}`}return/^-?[\w.^]+(?:\([\w ,.]*\))?$/.test(i)?`${i}*${n}`:`(${i})*${n}`}(e,t));return s.reduce((e,t,n)=>0===n?t:t.startsWith("-")?`${e} - ${t.slice(1)}`:`${e} + ${t}`,"")}function ho(e,t,n){if(pi(t))return co(e,n);const r=!pi(t)&&fs(t,ai(0))<0,i=co(r?Li(t):t,n),s="1"===i?"i":/^[\d.]+$/.test(i)?`${i}*i`:`(${i})*i`;return pi(e)?r?`-${s}`:s:`${co(e,n)} ${r?"-":"+"} ${s}`}const po=(e,t)=>{const n=co(e,t);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function fo(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 _s(e,t.places);const n=Math.abs(e);if(n>=1e15||n<1e-6){const[n,r]=e.toExponential(t.digits-1).split("e");return`${mo(n)}*10^(${Number(r)})`}return String(Number(e.toPrecision(t.digits)))}const mo=e=>e.includes(".")?e.replace(/\.?0+$/,""):e;function go(e,t={},n={}){0===Dr&&(Pr=0);const r="string"==typeof e?fr(e):I(e),i={};for(const[e,n]of Object.entries(t))i[e]=xi(n);Dr++;const s=Wi;let o,a=!1;L(r,e=>{"symbol"!==e.type||"i"!==e.value||Object.prototype.hasOwnProperty.call(t,"i")||(a=!0)}),Wi=n.complex??(a||Dr>1&&s);try{o=Vs(r,i)}finally{Dr--,Wi=s}const l={decimal:!1,places:null,digits:12,maxDigits:50,...n};if(void 0===l.places&&(l.places=null),null!==l.places&&!(Number.isInteger(l.places)&&l.places>=0&&l.places<=Rr.places))throw new Zr(`places is a whole number from 0 to ${Rr.places}`);const c=e=>Array.isArray(e)?e.every(c):Ui(e)?[...e.terms.values()].every(e=>"number"!=typeof e.re&&"number"!=typeof e.im):"number"!=typeof e;return{value:Mi(o),text:co(o,l),exact:c(o)}}function bo(e,t={}){let n=e.trim();const r={},i=/^(~|≈)(\d+)?\s*/.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}=go(n,t,r);return e.startsWith('"')||/^\d+(\.\d+)?$/.test(e)?e:`(${e})`}catch(e){if(e instanceof Fr)return'"undefined"';if(e instanceof Zr)return`(${n})`;throw e}}hr=bo;for(const e of[Rr,ds,Is,Ls,Us,Hs])Object.setPrototypeOf(e,null);Object.setPrototypeOf(Bs,null);const $o=e=>"op"===e.type&&o(e.op)&&["vec","hat"].includes(ee(e.op)),yo={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",implies:"implies",iff:"if and only if",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",dot:"dot",cross:"cross",vector:"vector",hat:"hat",at:"at",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",evaluatedFrom:"evaluated from",setOf:"the set of",suchThat:"such that",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",matrix:(e,t)=>`the ${e} by ${t} matrix`,row:e=>`row ${e}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",andSoOn:"dot dot dot",emptySet:"the empty set",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},vo={sin:"sine",cos:"cosine",tan:"tangent",csc:"cosecant",sec:"secant",cot:"cotangent",sinh:"hyperbolic sine",cosh:"hyperbolic cosine",tanh:"hyperbolic tangent",arcsin:"inverse sine",arccos:"inverse cosine",arctan:"inverse tangent",arcsec:"inverse secant",arccsc:"inverse cosecant",arccot:"inverse cotangent",arcsinh:"inverse hyperbolic sine",arccosh:"inverse hyperbolic cosine",arctanh:"inverse hyperbolic tangent",ln:"the natural log",log:"log",loglog:"the log of the log",logloglog:"the log of the log of the log",expm1:"e to the power, minus 1, of",max:"the maximum",min:"the minimum",gcd:"the greatest common divisor",mean:"the mean",det:"the determinant",atan2:"the arctangent",round:"round",fixed:"fixed",random:"random"},wo=Object.fromEntries(Object.entries(j).map(([e,t])=>[t,e]));function xo(e,t={}){return ko(function(e,t={}){return Mo(e,t,!0)}(e,t))}function Mo(e,t,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}(new No({...yo,...t.words},{...vo,...t.names},t.say||{},n).speak(e))}function ko(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const Ao={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor","\\implies":"implies","\\iff":"iff"},Eo={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class No{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=>ko(this.speak(e))):[e.value],e,e=>ko(this.speak(e))),id:e.id}]}return"number"===e.type?[this.seg(e,this.number(e.value))]:"string"===e.type?[this.seg(e,e.value.slice(1,-1))]:"symbol"===e.type?[this.seg(e,this.symbol(e.value))]:this.operation(e)}seg(e,t){return{text:t,id:e.id}}number(e){const t=this.w;return e.endsWith("..")?`${e.replace(/\.+$/,"")} ${t.repeating}`:e.startsWith("-")?`${t.negative} ${e.slice(1)}`:e}symbol(e){const t=this.w;if("∞"===e)return t.infinity;if("-∞"===e)return`${t.negative} ${t.infinity}`;if("pi"===e||"π"===e)return t.pi;if("tau"===e||"τ"===e)return"tau";if("\\+"===e)return t.plus;if("\\-"===e)return t.minus;if("°"===e)return t.degrees;if("⋯"===e)return t.andSoOn;if(Eo[e])return t[Eo[e]];if(wo[e])return wo[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;if(/^d[A-Za-z\u03B1-\u03C9]$/.test(e))return`d ${this.symbol(e[1])}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=c(e.op);return void 0!==t&&t<=50&&!a(e.op).group}quantity(e,t="endQuantity"){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}grouped(e,t,n){return this.isCompound(e)||this.audio&&n?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[r,i]=n,s=this.w,a=t=>this.seg(e,t),l=()=>n.flatMap((e,t)=>t?[a(s.comma),...this.listed(e)]:this.listed(e));if(Ao[t])return[...this.speak(r),a(s[Ao[t]]),...this.speak(i)];if(o(t)){if(1===n.length&&"symbol"===r.type&&"vec"===ee(t))return[a(s.vector),...this.speak(r)];if(1===n.length&&"symbol"===r.type&&"hat"===ee(t))return[...this.speak(r),a(s.hat)];const e=this.symbol(ee(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 P(i)?[...this.leftSide(r),a(s.minus),...this.quantityIfSum(i.args[1])]:[...this.leftSide(r),a(s.plus),...this.speak(i)];case"-":return P(i)?[...this.leftSide(r),a(s.plus),...this.speak(i.args[1])]:[...this.leftSide(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.grouped(i,"endSub","op"===i.type):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.grouped(r,"endQuantity","op"===r.type||"number"===r.type&&r.value.startsWith("-")),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):ko(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:`${ko(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 he(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 n.length?[a(s.theSet),...l()]:[a(s.emptySet)];case"setbuilder":return[a(s.setOf),..."op"===n[0].type&&"∈"===n[0].op?[...this.speak(n[0].args[0]),a("in"),...this.speak(n[0].args[1])]:this.speak(n[0]),a(s.suchThat),...this.speak(n[1])];case"evaluated":return[...this.speak(n[0]),a(`${s.comma} ${s.evaluatedFrom}`),...this.speak(n[2]),a(s.to),...this.speak(n[3])];case"der":return this.derivative(e);case"int":return this.integral(e);case"lim":return this.limit(e);case"\\sumidx":return this.bigOperator(e,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=he(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.listed(e)]:this.listed(e))}listed(e){return this.audio?this.quantity(e):this.speak(e)}pauseAfter(e){return this.isCompound(e)?[this.seg(e,this.w.comma)]:[]}leftSide(e){return this.audio&&"op"===e.type&&"?:"===e.op?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,"endQuantity")]:this.speak(e)}quantityIfSum(e){return this.quantity(e)}product(e){const[t,n]=e.args,r=this.w;if(P(e))return this.speak({...e,op:"neg",args:[n]});if("symbol"===n.type&&"°"===n.value)return[...this.speak(t),this.seg(e,r.degrees)];const i=this.audio&&"op"===t.type&&"/"===t.op&&!t.args.every(e=>"number"===e.type&&/^\d$|^10$/.test(e.value))?[this.seg(t,r.quantity),...this.speak(t),...this.closer(t,"endFraction")]:this.quantity(t);this.audio&&"op"===t.type&&"^"===t.op&&"number"!==t.args[1].type&&i.push(...this.closer(t.args[1],"endExponent"));const s=this.quantity(n);if(e.written&&[t,n].some($o))return[...i,this.seg(e,r[e.written]),...s];return Boolean(e.written)||this.isCompound(t)||this.isCompound(n)||this.isWord(t)||this.isWord(n)||this.startsWithNumber(n)||"op"===n.type&&"/"===n.op||this.isCall(t)||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)&&!j[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}`)]}const s=(e,...t)=>"op"===e.type&&t.includes(e.op)&&!P(e),o=this.grouped(t,null,s(t,"/")),a=this.isCall(t)?[i(r.comma)]:[],l=this.speak(n),c=s(n,"/")||this.audio&&s(n,"*")&&l.some(e=>e.id===n.id&&e.text===r.times),u=this.isCompound(n)||this.audio&&c;return[...o,...a,i(r.over),...u?[this.seg(n,r.quantity),...l,...this.closer(n,"endFraction")]:l]}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||"neg"===t.op||P(t))?[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))}`)];if(!(this.isCompound(n)||"op"===n.type&&"/"===n.op&&this.isCompound(n.args[0]))){const e=this.speak(n),t=e[0]&&e[0].text.startsWith(r.quantity);return[...s,i(t?r.toThePowerOf:r.toThe),...e]}return 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,at:i,variable:s}=ie(e),o=this.w,a=t=>this.seg(e,t),l=i?[a(`${o.comma} ${o.at}`),...this.speak(r),a(o.equals),...this.speak(i)]:[];if(s){return[...[a(1===t?o.d:`${o.d} ${2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`}`),...this.speak(n),a(o.d),...this.speak(r),a(1===t?"":2===t?o.squared:3===t?o.cubed:`${o.toThe} ${this.ordinal(t)}`)],...l]}return[a(`${1===t?o.derivative:2===t?o.secondDerivative:o.nthDerivative(this.ordinal(t))} ${o.withRespectTo}`),...this.speak(r),a(o.of),...this.contents(n,"endDerivative"),...l]}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(q(n)||"x")];let u=[];4===t.length?u=[i,s]:3===t.length?u=l?[i]:[r,i]:2!==t.length||l||(u=[r]);return[...2===u.length?[a(o.integralFrom),...this.speak(u[0]),a(o.to),...this.speak(u[1]),a(o.of)]:1===u.length?[a(o.integralFrom),...this.speak(u[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(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=q(n);l=e?[a(e),a(o.approaches),...this.speak(r)]:this.speak(r)}}return this.audio&&"op"===n.type&&"/"===n.op?[a(o.limitAs),...l,a(o.of),...this.grouped(n,"endLimit",!0)]:[a(o.limitAs),...l,a(o.of),...this.contents(n,"endLimit")]}bigOperator(e,t,n,r,i){const{args:s}=e,[o,a,l]=s,c=this.w,u=t=>this.seg(e,t);let h;return h=3===s.length?[u(t),...this.speak(a),u(c.to),...this.speak(l),u(c.of)]:2===s.length?[u(n),...this.speak(a),u(c.of)]:[u(r)],[...h,...this.contents(o,i)]}}for(const e of[yo,vo,Ao,Eo,wo])Object.setPrototypeOf(e,null);function _o(e,t={}){return dr(e)?[]:function(e,t={}){return Mo(e,t,!1)}(mr(e),t)}function So(e,t={}){return dr(e)?"":xo(mr(e),t)}const Oo={"(":{fill:"M0.92,0 C0.1,0.2 0.1,0.8 0.92,1 L1,0.975 C0.48,0.75 0.48,0.25 1,0.025 Z"},")":{fill:"M0.08,0 C0.9,0.2 0.9,0.8 0.08,1 L0,0.975 C0.52,0.75 0.52,0.25 0,0.025 Z"},"{":{fill:"M1,0 C0.45,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.35,0.49 0.05,0.5 C0.35,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.45,1 1,1 L1,0.985 C0.68,0.985 0.64,0.95 0.64,0.8 L0.64,0.62 C0.64,0.53 0.55,0.505 0.3,0.5 C0.55,0.495 0.64,0.47 0.64,0.38 L0.64,0.2 C0.64,0.05 0.68,0.015 1,0.015 Z"},"}":{fill:"M0,0 C0.55,0 0.5,0.05 0.5,0.2 L0.5,0.38 C0.5,0.46 0.65,0.49 0.95,0.5 C0.65,0.51 0.5,0.54 0.5,0.62 L0.5,0.8 C0.5,0.95 0.55,1 0,1 L0,0.985 C0.32,0.985 0.36,0.95 0.36,0.8 L0.36,0.62 C0.36,0.53 0.45,0.505 0.7,0.5 C0.45,0.495 0.36,0.47 0.36,0.38 L0.36,0.2 C0.36,0.05 0.32,0.015 0,0.015 Z"},sqrt:{stroke:"M0,0.62 L0.18,0.55 L0.45,0.97 L0.98,0"},cancel:{stroke:"M0,1 L1,0"},int:{stroke:"M0.95,0.09 C0.9,0.01 0.72,0 0.66,0.12 C0.6,0.25 0.42,0.75 0.34,0.88 C0.28,0.99 0.1,0.99 0.05,0.91"},sum:{fill:"M0.04,0 L0.94,0 L0.98,0.24 L0.94,0.24 C0.9,0.1 0.8,0.07 0.62,0.07 L0.24,0.07 L0.58,0.5 L0.2,0.93 L0.64,0.93 C0.82,0.93 0.92,0.9 0.95,0.76 L0.99,0.76 L0.94,1 L0.02,1 L0.47,0.47 Z"},prod:{fill:"M0,0 L1,0 L1,0.04 L0.88,0.05 L0.88,0.95 L1,0.96 L1,1 L0.62,1 L0.62,0.96 L0.74,0.95 L0.74,0.06 L0.26,0.06 L0.26,0.95 L0.38,0.96 L0.38,1 L0,1 L0,0.96 L0.12,0.95 L0.12,0.05 L0,0.04 Z"}};function zo(e,t,n=""){const r=Oo[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 Io=.8,Lo=.2,qo=.25,jo=.7,Co="−",Fo={"+":"add","-":"sub","*":"mul","/":"frac","^":"pow",_:"subscript",neg:"neg",pm:"pm","!":"factorial","=":"eq","===":"eq","≠":"neq","≠=":"neq","<":"lt",">":"gt","≤":"le","≥":"ge","≈":"approx","≡":"equiv","∈":"in","∉":"notin","∪":"union","∩":"intersect","→":"to","±":"pm","&":"and","|":"or","\\not":"not","\\xor":"xor","\\nand":"nand","\\nor":"nor","\\implies":"implies","\\iff":"iff","?:":"cases","()":"tuple","[]":"list","{}":"set","(]":"interval","[)":"interval","\\sumidx":"sum","\\prodidx":"prod",mod:"mod",pmod:"pmod",pmatrix:"matrix",bmatrix:"matrix",vmatrix:"matrix"},Zo={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},To={"±":"±","∪":"∪","∩":"∩",mod:"mod"},Ro=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],Po={arcsin:"sin",arccos:"cos",arctan:"tan",arcsec:"sec",arccsc:"csc",arccot:"cot",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},Bo=[...Ro,...Object.keys(Po),"ln","det"],Wo={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},Do={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},Uo=["int","lim","\\sumidx","\\prodidx"],Ho={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},Go={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},Vo=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,Xo=e=>"symbol"===e?.type&&Vo.test(j[e.value]??e.value),Qo=["boxed","overline","bar","underline","cancel",...Object.keys(Go)],Jo={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},Yo=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Ko=e=>+e.toFixed(3)+"em",ea=(e,t=Io,n=Lo)=>({html:e,h:t,d:n});function ta(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(Io,...t.map(e=>e.h)),d:Math.max(Lo,...t.map(e=>e.d))}}function na(e,t={}){const n=new ra({...Jo,...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):So(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="${Yo(o)}"`}>${a}${s}</span>`,h:r.h,d:r.d}}class ra{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=ea(this.el(e,Yo(t)));return n.leaf={kind:e,content:Yo(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="${Yo(e.op)}"`);const i=this.o.attributes&&this.o.attributes(e)||{};for(const[e,t]of Object.entries(i))"class"!==e&&"style"!==e&&/^[A-Za-z_:][\w:.-]*$/.test(e)&&(r+=` ${e}="${Yo(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?[Yo(i.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${s?` style="${Yo(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){const t=/^(-?\d*\.)(\d*)\.\.$/.exec(e.value);if(t){const[,n,r]=t;let i=1;for(let e=1;2*e<=r.length;e++)if(r.slice(-e)===r.slice(-2*e,-e)){i=e;break}let s=r;for(;s.endsWith(r.slice(-i))&&s.length>=i;)s=s.slice(0,-i);const o=this.text("num",(n+s).replace(/^-/,Co)),a=this.text("num",r.slice(-i));return this.wrap(e,["number"],ta(o,ea(this.el("over",a.html),a.h+.14,a.d)))}return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,Co)))}symbol(e){return j[e]&&(e=j[e]),Ho[e]?this.text("ord",Ho[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)?ea(this.el("var",Yo(e[0]))+this.el("prime",Yo(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?ea(this.el("ord","Δ")+this.el("var",e[1])):/^d[A-Za-zα-ω]$/.test(e)?ea(this.el("ord","d")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:n,args:r}=e,[i,s]=r,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1,leftFactor:!1}),l=Fo[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),u=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,n)=>D(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(Bo.includes(n)||"log"===n)return u(this.named(e,t));if(Wo[n])return u(ta(this.word(Wo[n]),this.fence(this.list(r,t))));if(o(n))return u(this.custom(e,t));const p=he(e);if(p)return u(this.matrix(e,p,t));if("{}"===n&&!r.length)return u(this.text("op","∅"));if(Do[n])return u(this.fence(this.list(r,t),...Do[n]));if(("|"===n||"&"===n)&&r.length>=2&&r.every(oa)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===n?a(e):this.fence(a(e));return u(ta(r.map((t,r)=>r?[this.text("conj","|"===n?"or":"and"),e(t)]:[e(t)]).flat()))}if(Zo[n]&&2===r.length)return u(ta(h(i,"left"),this.rel(Zo[n]),h(s,"right")));if(To[n]&&2===r.length)return u(ta(h(i,"left"),this.bin(To[n]),h(s,"right")));switch(n){case"+":if(P(s)){const e=s.args[1],t=D({op:"-"},e,"right")?this.fence(a(e)):a(e);return u(ta(h(i,"left"),this.bin(Co),this.wrap(s,["op","op-mul"],t)))}return"number"===s.type&&s.value.startsWith("-")?u(ta(h(i,"left"),this.bin(Co),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):u(ta(h(i,"left"),this.bin("+"),this.signed(s,h(s,"right"))));case"-":return u(ta(h(i,"left"),this.bin(Co),this.signed(s,h(s,"right"))));case"*":return u(this.product(e,t));case"/":return u(this.fraction(e,t));case"^":return u(this.power(e,t));case"_":{const e=B(i)&&c(B(i))<100;return u(this.script(e?this.fence(a(i)):a(i,{forceParens:!0}),null,t,a(s,{level:t.level+1})))}case"neg":return u(ta(this.text("sign",Co),U(n,i)?this.fence(a(i)):a(i,{before:t.before})));case"pm":return u(ta(this.text("sign","±"),U(n,i)?this.fence(a(i)):a(i)));case"!":return u(ta(U(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return u(ta(this.text("sign","¬"),U(n,i)?this.fence(a(i)):a(i)));case"pmod":return u(ta(a(i),this.fence(ta(this.word("mod"),this.text("space",""),a(s)))));case"sqrt":return u(this.radical(a(i)));case"root":return u(this.radical(a(s),this.render(i,{level:t.level+2})));case"abs":return u(this.fence(a(i),"|","|"));case"floor":return u(this.fence(a(i),"⌊","⌋"));case"ceil":return u(this.fence(a(i),"⌈","⌉"));case"loglog":return u(ta(this.word("ln"),this.fence(ta(this.word("ln"),this.fence(a(i))))));case"logloglog":return u(ta(this.word("ln"),this.fence(ta(this.word("ln"),this.fence(ta(this.word("ln"),this.fence(a(i))))))));case"perm":return u(this.script(this.script(ea(""),this.render(i,{level:t.level+1}),t),null,t,this.render(s,{level:t.level+1}),this.word("P")));case"comb":return u(this.fence(this.stack(a(i),a(s),!1)));case"?:":return u(this.o.cases?this.cases(e,t):ta(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":case"prod":{const e={op:"sum"===n?"+":"*"},t=(t,n)=>D(e,t,n?"right":"left")?this.fence(a(t)):a(t);return u(ta(r.map((e,r)=>r?[this.bin("sum"===n?"+":"·"),t(e,r)]:[t(e,r)]).flat()))}case"setbuilder":return u(this.fence(ta(a(i),this.bin("|"),a(s)),"{","}"));case"evaluated":{const e=e=>this.render(e,{...t,level:t.level+1});return u(this.script(this.fence(a(i),"[","]"),e(r[3]),t,e(r[2])))}case"der":return u(this.derivative(e,t));case"int":return u(this.integral(r,t));case"lim":return u(this.limit(r,t));case"\\sumidx":return u(this.bigOperator("sum",r,t));case"\\prodidx":return u(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 ta(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(P(e))return ta(this.text("sign",Co),U("neg",r)?this.fence(this.render(r,t)):this.render(r,t));const i=function(e){const[t,n]=e.args;return{left:D(e,t,"left")&&"/"!==t.op,right:D(e,n,"right")&&"/"!==n.op}}(e);Uo.includes(n.op)&&(i.left=!0);const s=!e.written&&H(n,r,i),a=function(e){for(;"op"===e.type;){if(Bo.includes(e.op)||"log"===e.op||Wo[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,leftFactor:!0}),c=i.right?this.fence(this.render(r,t)):this.render(r,{...t,before:t.before});return ta(l,s?ea(this.el(a?"fnspace":"times","")):this.bin("cross"===e.written?"×":"·"),c)}named(e,t,n=null){const{op:r,args:i}=e,s="log"===r?i[1]:i[0];let o;o=Po[r]&&"power"===this.o.inverseTrig?this.script(this.word(Po[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&&ia(s),l=this.render(s,{...t,forceParens:!1,before:!1});return ta(o,a?ta(ea(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=ee(e.op),r=e.args;if(Qo.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],t),r[0]);return ta(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),ea(this.el("callgap","")),this.fence(this.list(r,t)))}decorate(e,t,n){switch(e){case"boxed":return ea(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return ea(this.el("cancel",t.html+zo("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return ea(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return ea(this.el("over"+(Xo(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const r=Xo(n);return ea(this.el("accent"+(r?" accent-low":""),this.el(`accent-mark accent-${e}`,Go[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[n,r]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&ia(n,!0)&&ia(r,!0)){const e={...t,leftFactor:!1},i=(t,n)=>"op"!==t.type||ia(t)&&(!n||"*"!==t.op||P(t))?this.render(t,e):this.fence(this.render(t,e)),s=ta("op"===n.type&&"neg"===n.op?this.render(n,e):i(n,!1),this.text("ord","/"),i(r,!0));return t.leftFactor?this.fence(s):s}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:${Ko(r)}`),s=n?.06:0,o=qo+s/2+.1+Math.max(Lo,r*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(e))+this.el("denom",i(t)),`vertical-align:${Ko(o)}`);return ea(a,o+Math.max(Io,r*e.h),Math.max(Io,r*t.h)+Math.max(Lo,r*t.d)+.1+s/2-qo)}power(e,t){const[n,r]=e.args,i={...t,level:t.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},s=()=>this.render(r,i);if(this.o.trigPowers&&Ro.includes(n.op)&&la(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=D(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||Bo.includes(n.op)||Uo.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:jo,o=i?ta(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:${Ko(s)}`);if(t&&!r)return ea(e.html+this.el("sup",t.html,`font-size:${Ko(s)};vertical-align:${Ko(a/s)}`),Math.max(o.h,a+s*t.h),Math.max(o.d,s*t.d-a));if(r&&!t)return ea(o.html+this.el("sub",r.html,`font-size:${Ko(s)};vertical-align:${Ko(-l/s)}`),Math.max(o.h,s*r.h-l),Math.max(o.d,l+s*r.d));const u=a+s*t.h,h=l+s*r.d,p=this.el("subsup",c(t)+c(r),`vertical-align:${Ko(a)};height:${Ko(u+h)}`);return ea(o.html+p,Math.max(o.h,u),Math.max(o.d,h))}radical(e,t=null){const n=Math.max(e.h,Io)+.1+.06,r=Math.max(e.d,Lo),i=n+r,s=.5+.06*(i-1),o=zo("sqrt",`${this.p}-hook`,`width:${Ko(s)};left:${Ko(-s)}`);let a="";if(t){const e=.8*jo;a=this.el("rootindex",t.html,`font-size:${Ko(e)};vertical-align:${Ko((.55*i-r)/e)}`)}return ea(this.el("sqrt",a+this.el("radicand",o+e.html,`margin-left:${Ko(s+.05)}`)),n,r)}fence(e,t="(",n=")"){const r=Math.max(e.h,Io)+Math.max(e.d,Lo),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:zo(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${Ko(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");if(!i){const t=ea(this.el("fence fence-line",a.html+e.html+l.html),Math.max(e.h,Io),Math.max(e.d,Lo));return t.fenced=!0,t}const c=`padding:${Ko(s)} ${Ko(l.w)} ${Ko(s)} ${Ko(a.w)}`,u=ea(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,Io)+s,Math.max(e.d,Lo)+s);return u.fenced=!0,u}derivative(e,t){const n=this.leibniz(e,t),{by:r,at:i}=ie(e);if(!i)return n;const s=e.args[1],o=this.render({...s,args:[{...r,id:void 0},i]},{...t,level:t.level+1});return this.script(this.fence(n,"","|"),null,t,o)}leibniz(e,t){const{n:n,body:r,by:i,variable:s}=ie(e),o={...t,level:t.level+1},a=()=>this.text("d","d"),l=()=>n>1?this.render({type:"number",value:String(n)},o):null,u={...t,inFraction:!0},h=ta(a(),l()?this.script(this.render(i,u),l(),u):this.render(i,u)),p=e=>ta(l()?this.script(a(),l(),u):a(),e||[]),f=t.level>0||t.inFraction||!this.o.display?.8:1;if(s)return this.stack(p(this.render(r,u)),h,!0,f);const m=B(r)&&c(B(r))<100,[d,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=m?this.fence(this.render(r,t),d,g):this.render(r,t);return ta(this.stack(p(),h,!0,f),b)}integral(e,t){const[n,r,i,s]=e,o=e=>this.render(e,t),a=e=>e?this.render(e,{...t,level:t.level+1}):null,l=()=>this.text("var",q(n)||"x");let c,u=null,h=null;switch(e.length){case 1:c=l();break;case 2:K(r)?c=o(r):(c=l(),u=a(r));break;case 3:K(r)?(c=o(r),u=a(i)):(c=l(),u=a(r),h=a(i));break;default:c=o(r),u=a(i),h=a(s)}const p=o(n),f=ea(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return ta(this.bigSign("int",p,u,h,t),p,f)}bigSign(e,t,n,r,i){const s=!this.o.display||i.level>0,o=Math.max(s?.6:.95,Math.max(t.h-qo,t.d+qo)+.12),a=zo(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${Ko(2*o)};width:${Ko(s?.38:.5)};vertical-align:${Ko(qo-o)}`);if(!n&&!r)return ea(a,qo+o,o-qo);const l=jo,c=r||ea(""),u=n||ea(""),h=qo+o-l*c.h;u.d;const p=this.el("limits",this.el("script",c.html,`font-size:${Ko(l)}`)+this.el("script lower",u.html,`font-size:${Ko(l)}`),`vertical-align:${Ko(h)};height:${Ko(2*o)}`);return ea(a+p,qo+o,o-qo)}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 ta(this.word("lim"),ea(this.el("fnspace","")),this.body(n,t));case 2:{const e=q(n),t="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=e&&t?ta(this.text("var",e),l(),a(r)):a(r);break}case 3:c=ta(a(r),l(),a(i));break;default:{const e=C(s).toLowerCase().startsWith("r")?"+":Co;c=ta(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",e)),o))}}return ta(this.under(this.word("lim"),c,t),this.body(n,t))}under(e,t,n){return!this.o.display||n.level>0?this.script(e,null,n,t):ea(this.el("under",e.html+this.el("script",t.html,`font-size:${Ko(.7)}`)),e.h,Math.max(e.d,Lo)+.05+.7*(t.h+t.d))}body(e,t){const n=B(e);return n&&c(n)<c("*")?this.fence(this.render(e,t)):this.render(e,t)}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.body(r,n);if(!this.o.display||n.level>0){const t=.55,r=zo(e,`${this.p}-bigsign`,`height:${Ko(2*t)};width:${Ko(.8)};vertical-align:${Ko(qo-t)}`);return ta(this.script(ea(r,qo+t,t-qo),l,n,a),c)}const u=.68,h=jo,p=zo(e,`${this.p}-bigsign`,`height:${Ko(1.36)};width:${Ko("sum"===e?1:1.05)}`),f=l?1.01+h*l.d:qo-u,m=e=>this.el("script",e.html,`font-size:${Ko(h)}`),d=this.el("bigop",(l?m(l):"")+p+(a?m(a):""),`vertical-align:${Ko(f)}`);return ta(ea(d,.93+(l?.08+h*(l.h+l.d):0),u-qo+(a?.08+h*(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(Io,...e.map(e=>e.h)),d:Math.max(Lo,...e.map(e=>e.d))})),s=i.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=qo+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"],ea(r)).html:r}).join(""),l=t[0].length,c=ea(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${Ko(o)}`),qo+s/2,s/2-qo),[u,h]=ue[e.op]??["[","]"];return this.fence(c,u,h)}cases(e,t){const n=[];let r=e;for(;"op"===r.type&&"?:"===r.op;)n.push([this.render(r.args[1],t),ta(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=qo+s/2-i[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=ea(this.el("cases",a,`vertical-align:${Ko(o)}`),qo+s/2,s/2-qo);return this.fence(l,"{","")}}function ia(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||he(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!P(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||aa(e)||"*"===e.op&&ia(e,t)):ia(e.args[0],!0)&&("neg"===e.op||ia(e.args[1],!0)))}const sa=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],oa=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&sa.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(oa)),aa=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(j[e.value])),la=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[Fo,Zo,To,Po,Wo,Do,Ho,Go])Object.setPrototypeOf(e,null);function ca(e){const{id:t,from:n,...r}=e;return r.args&&(r.args=r.args.map(ca)),r}const ua=e=>z(e).join(" ");function ha(e,t){const n=new Set;pa(e,t,n);const r=[];return L(e,e=>{n.has(e)&&r.push(e)}),r}function pa(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>pa(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const r=ua(fr(t));return void L(e,e=>{ua(e)===r&&n.add(e)})}if(t.path){const r=fa(e,t.path);return void(r&&n.add(r))}if(t.type){const r=ua(t);L(e,e=>{e!==t&&ua(e)!==r||n.add(e)})}}else L(e,(e,r)=>{t(e,r)&&n.add(e)});else L(e,e=>{e.id===t&&n.add(e)})}function fa(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}function ma(e,t){const n=[],r=e=>{if(e.id===t)return!0;if("op"!==e.type)return!1;for(let t=0;t<e.args.length;t++){if(n.push(t),r(e.args[t]))return!0;n.pop()}return!1};return r(e)?n:null}function da(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 ga(e,t={}){const{blocks:n}=t;if("string"==typeof e)return fr(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return O(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return L(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),da(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function ba(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($a(r))for(const n of ha(e,t))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:ha(e,r));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}function $a(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}function ya(e,t={}){return ga(e,{...t,blocks:t.blocks??bo})}function va(e,t={}){return function(e,t={}){const n=ga(e,t);return na(n,ba(n,t)).html}(e,{...t,blocks:t.blocks??bo})}function wa(e,t,n){const r=(e,i)=>i===t.length?n:{...e,args:e.args.map((e,n)=>n===t[i]?r(e,i+1):e)};return ca(r(e,0))}function xa(e,t,{parse:n,commit:r,cancel:i,label:s="Edit",prefix:o="mv"}){const a=e.ownerDocument;if(!a||!a.body)return null;const l=a.defaultView,c=e.getBoundingClientRect(),u=a.createElement("input");u.type="text",u.className=`${o}-edit`,u.value=t,u.spellcheck=!1,u.autocomplete="off",u.setAttribute("aria-label",s);const h=()=>{u.style.width=`${Math.max(4,u.value.length+2)}ch`},p=l.getComputedStyle(e);Object.assign(u.style,{position:"absolute",left:`${c.left+l.scrollX}px`,top:`${c.top+l.scrollY+c.height/2}px`,minWidth:`${Math.max(c.width,32)}px`,fontSize:p.fontSize}),h(),a.body.appendChild(u),l.getSelection?.()?.removeAllRanges(),u.focus(),u.select();let f=!1;const m=()=>{f=!0,u.remove()};u.cancelEdit=()=>{f||(m(),i&&i())};const d=e=>{if(f)return!0;if(!e||u.value===t)return m(),i&&i(),!0;let s;try{s=n(u.value)}catch(e){return u.setAttribute("aria-invalid","true"),u.title=e.message,!1}return m(),r(s,u.value),!0};return u.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),d(!0)),"Escape"===e.key&&(e.preventDefault(),d(!1))}),u.addEventListener("input",()=>{h(),u.removeAttribute("aria-invalid"),u.removeAttribute("title")}),u.addEventListener("blur",()=>{d(!0)||d(!1)}),u}class Ma{constructor(e,t,n={}){this.element=e,this.options=n,this.p=n.prefix||"mv",this.handlers=[],this.clicks=[],this.active=null,this.live=ka(e,n.announce,this.p),this.set(t)}set(e,{animate:t=!1,duration:n=600,easing:r="ease-in-out"}={}){const i=ya(e,this.options),{html:s}=na(i,ba(i,this.options));if(this.editor){const e=this.editor;this.editor=null,e.cancelEdit?.()}const o=Aa(t)&&this.tree?this.snapshot():null,a=void 0!==this.tree;return this.tree=i,this.element.innerHTML=s,this.root=this.element.firstElementChild,this.handlers.length&&this.root.classList.add(`${this.p}-clickable`),this.editing&&this.root.classList.add(`${this.p}-editable`),this.active=null,(this.clicks.length||this.editing)&&this.focusable(),o&&this.morph(o,{duration:n,easing:r}),a&&this.live&&this.announce(this.spoken()),this}spoken(){const e=this.root&&this.root.getAttribute&&this.root.getAttribute("aria-label");if(e)return e;try{return So(this.tree)}catch{return""}}announce(e){return this.say(this.live,e)}say(e,t){if(!e)return this;e.textContent="";const n=()=>{e.textContent=t};return"function"==typeof requestAnimationFrame?requestAnimationFrame(()=>requestAnimationFrame(n)):setTimeout(n,50),this}nodes(e){return ha(this.tree,e)}elements(e){return this.nodes(e).map(e=>this.elementOf(e)).filter(Boolean)}elementOf(e){return void 0===e.id?null:this.root.querySelector(`[data-node="${e.id}"]`)}highlight(e,t=`${this.p}-hl`){return this.elements(e).forEach(e=>e.classList.add(t)),this}unhighlight(e=null,t=`${this.p}-hl`){return(null===e?this.root.querySelectorAll(`.${t}`):this.elements(e)).forEach(e=>e.classList.remove(t)),this}color(e,t){return this.elements(e).forEach(e=>{e.style.color=t||""}),this}on(e,t){const n=e=>{const n=e.target.closest?.("[data-node]");if(!n||!this.root.contains(n))return;const r=Number(n.dataset.node),i=ha(this.tree,r)[0];t({node:i,id:r,path:ma(this.tree,r),element:n,event:e})};this.element.addEventListener(e,n);const r=[e,n];return this.handlers.push(r),this.root.classList.add(`${this.p}-clickable`),"click"===e&&(this.clicks.push(t),this.keyboard()),()=>{this.element.removeEventListener(e,n),this.clicks=this.clicks.filter(e=>e!==t),this.handlers=this.handlers.filter(e=>e!==r),!this.handlers.length&&this.root&&this.root.classList.remove(`${this.p}-clickable`)}}destroy(){if(this.editor){const e=this.editor;this.editor=null,e.cancelEdit?.()}for(const[e,t]of this.handlers)this.element.removeEventListener(e,t);this.handlers=[],this.clicks=[],this.keyListener&&this.element.removeEventListener("keydown",this.keyListener),this.editListener&&this.element.removeEventListener("dblclick",this.editListener),this.keyListener=this.editListener=null,this.keysOn=this.editOn=!1;for(const e of new Set([this.live,this.partsLive]))e&&"view"===e.dataset?.mvMadeBy&&e.remove();return this.live=this.partsLive=null,this}editable({toText:e,onEdit:t}={}){if("function"!=typeof e)throw new Error("editable needs { toText } (import { toText } from 'mathzetta/text')");return this.editing={toText:e,onEdit:t},this.root&&this.root.classList&&this.root.classList.add(`${this.p}-editable`),this.keyboard(),!this.editOn&&this.element.addEventListener&&(this.editOn=!0,this.editListener=e=>{const t=e.target.closest?.("[data-node]");t&&this.root.contains(t)&&(e.preventDefault(),this.edit(ha(this.tree,Number(t.dataset.node))[0]))},this.element.addEventListener("dblclick",this.editListener)),this}edit(e=this.tree,{returnFocus:t=!1}={}){if(!this.editing)throw new Error("call editable({ toText }) first");const n="object"==typeof e&&e&&e.type?e:this.nodes(e)[0];if(!n)return null;const r=ma(this.tree,n.id)||[],i=this.elementOf(n)||this.root;let s="Edit";try{s=`Edit ${So(n)}`}catch{}const o=()=>{t&&this.root.focus&&this.root.focus()};return this.editor=xa(i,this.editing.toText(n),{label:s,prefix:this.p,parse:e=>ya(e,this.options),commit:(e,n)=>{this.set(wa(this.tree,r,e),{animate:!0});const i=fa(this.tree,r);t&&i&&this.focusPart(i===this.tree?null:i),o(),this.editing.onEdit&&this.editing.onEdit({tree:this.tree,text:this.editing.toText(this.tree),path:r,part:n})},cancel:o}),this.editor}focusable(){this.root&&this.root.setAttribute&&(this.root.setAttribute("tabindex","0"),this.root.getAttribute("aria-label")||(this.root.setAttribute("role","math"),this.root.setAttribute("aria-label",this.spoken())),this.root.setAttribute("aria-description",this.editing?"Arrow keys move between parts, F2 edits one.":"Arrow keys move between parts, Enter selects one."))}keyboard(){this.focusable(),!this.keysOn&&this.element.addEventListener&&(this.keysOn=!0,this.partsLive=this.live||ka(this.element,!0,this.p),this.keyListener=e=>this.key(e),this.element.addEventListener("keydown",this.keyListener))}key(e){if(!this.root||!this.root.contains(e.target))return;const t=this.active;let n;switch(e.key){case"ArrowDown":n=t?this.partsOf(t)[0]:this.partsOf(this.tree)[0];break;case"ArrowUp":n=t?this.outerOf(t):void 0;break;case"ArrowRight":n=t?this.neighbor(t,1):this.partsOf(this.tree)[0];break;case"ArrowLeft":n=t?this.neighbor(t,-1):void 0;break;case"Home":case"Escape":n=null;break;case"F2":if(!this.editing)return;return e.preventDefault(),void this.edit(t||this.tree,{returnFocus:!0});case"Enter":case" ":{e.preventDefault();const n=t||this.tree,r=this.elementOf(n)||this.root,i={node:n,id:n.id,path:ma(this.tree,n.id),element:r,event:e};for(const e of this.clicks)e(i);return}default:return}e.preventDefault(),void 0!==n&&this.focusPart(n)}focusPart(e){const t=`${this.p}-focus`;this.root.querySelectorAll(`.${t}`).forEach(e=>e.classList.remove(t)),this.active=e;const n=e&&this.elementOf(e);n&&n.classList.add(t);let r="";try{r=e?So(e):this.spoken()}catch{r=""}return this.say(this.partsLive,r),this}partsOf(e){const t=[],n=e=>{this.elementOf(e)?t.push(e):"op"===e.type&&e.args.forEach(n)};return e&&"op"===e.type&&e.args.forEach(n),t}outerOf(e){const t=ma(this.tree,e.id);for(let e=t?t.length-1:-1;e>0;e--){const n=fa(this.tree,t.slice(0,e));if(n&&this.elementOf(n))return n}return null}neighbor(e,t){const n=this.partsOf(this.outerOf(e)||this.tree),r=n.indexOf(e);return r<0?void 0:n[r+t]}segments(e={}){return _o(this.tree,e)}showSegment(e,t=`${this.p}-hl`){return this.unhighlight(null,t),e&&void 0!==e.id&&this.highlight(e.id,t),this}snapshot(){const e=new Map,t=n=>{const r=this.elementOf(n);if(r){const t=ua(n);e.has(t)||e.set(t,[]),e.get(t).push({rect:r.getBoundingClientRect(),node:n,sig:t})}"op"===n.type&&n.args.forEach(t)};return t(this.tree),e}morph(e,{duration:t,easing:n}){if("undefined"==typeof Element||!Element.prototype.animate)return;const r=t=>{if("op"===t.type)for(const n of t.args){const t=e.get(ua(n)),i=t?t.findIndex(e=>e.node===n):-1;i>-1&&t.splice(i,1),r(n)}},i=s=>{const o=this.elementOf(s),a=o&&e.get(ua(s));if(a&&a.length){const{rect:e,node:i}=a.shift();r(i);const s=o.getBoundingClientRect(),l=e.left-s.left,c=e.top-s.top,u=s.width?e.width/s.width:1,h=s.height?e.height/s.height:1;return void((Math.abs(l)+Math.abs(c)>.5||Math.abs(u-1)+Math.abs(h-1)>.01)&&o.animate([{transformOrigin:"0 0",transform:`translate(${l}px, ${c}px) scale(${u}, ${h})`},{transformOrigin:"0 0",transform:"none"}],{duration:t,easing:n}))}"op"===s.type?s.args.forEach(i):o&&o.animate([{opacity:0},{opacity:0},{opacity:1}],{duration:t,easing:n})};i(this.tree)}}function ka(e,t,n){if(!t)return null;if("object"==typeof t&&1===t.nodeType)return t;if("undefined"==typeof document||!e.insertAdjacentElement)return null;const r=e.nextElementSibling;if(r&&"view"===r.dataset?.mvMadeBy&&r.classList.contains(`${n}-sr-only`))return r;const i=document.createElement("span");return i.dataset.mvMadeBy="view",i.className=`${n}-sr-only`,i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),e.insertAdjacentElement("afterend",i),i}function Aa(e){return!!e&&("always"===e||!("function"==typeof matchMedia&&matchMedia("(prefers-reduced-motion: reduce)").matches))}const Ea=Symbol.for("inlinemath.expressions"),Na=new Set(["symbol","number"]);function _a(e){return e?"symbol"===e.type?e.value:"op"===e.type&&"_"===e.op&&2===e.args.length&&"symbol"===e.args[0].type&&Na.has(e.args[1].type)?`${e.args[0].value}_${e.args[1].value}`:null:null}function Sa(e){const{id:t,...n}=e;return n.args&&(n.args=n.args.map(Sa)),n}function Oa(e,t){const n=(e,r)=>{if(!r&&void 0!==e.from)return t(e.from);const{id:i,from:s,...o}=e;return o.args&&(o.args=o.args.map(e=>n(e,!1))),o};return n(e,!0)}const za=new Set;function Ia(e,t){let n=!1;const r=new Set,i=(e,s=za)=>{const o=_a(e);if(null!==o){if(!r.has(o)&&!s.has(o)){const e=t(o);if(e){n=!0,r.add(o);const t={...i(ca(e)),from:o};return r.delete(o),t}}return e}if(e.args){const t=function(e){const[t,n]=e.args,r=e=>e&&"symbol"===e.type?e.value:null;switch(e.op){case"der":return"="===n?.op?r(n.args[0])&&{name:r(n.args[0]),where:e=>0===e,index:1}:r(n)&&{name:r(n),where:e=>e<=1};case"int":{const i=r(n)??(3===e.args.length||1===e.args.length?q(t)||"x":null);return i&&{name:i,where:e=>0===e||1===e&&r(n)===i}}case"lim":return"→"===n?.op&&r(n.args[0])&&{name:r(n.args[0]),where:e=>0===e,index:1};case"\\sumidx":case"\\prodidx":return("="===n?.op||"∈"===n?.op)&&r(n.args[0])&&{name:r(n.args[0]),where:e=>0===e,index:1};default:return null}}(e);if(!t)return{...e,args:e.args.map(e=>i(e,s))};const n=new Set([...s,t.name]);return{...e,args:e.args.map((e,r)=>r===t.index?{...e,args:e.args.map((e,t)=>i(e,0===t?n:s))}:i(e,t.where(r)?n:s))}}return e},s=i(e);return{tree:n?Sa(s):e,changed:n}}const La="[-+]?(?:\\d+\\.?\\d*|\\.\\d+)",qa=new RegExp(`^(${La})\\s*\\.\\.\\s*(${La})(?:\\s+step\\s+(${La}))?(?:\\s*=\\s*(${La}))?$`);function ja(e){const t=/^\s*\[\[([\s\S]*)\]\]\s*$/.exec(e);if(!t||/\]\s*,\s*\[/.test(t[1]))return null;const n=t[1].trim(),r=qa.exec(n);if(r){const e=Number(r[1]),t=Number(r[2]);if(!(t>e))return null;const n=void 0!==r[3]?Number(r[3]):Number.isInteger(e)&&Number.isInteger(t)?1:(t-e)/100;if(!(n>0))return null;const i=void 0!==r[4]?Math.min(t,Math.max(e,Number(r[4]))):e;return{kind:"slider",min:e,max:t,step:n,default:String(i)}}if(n.includes("|")){const e=n.split("|").map(e=>e.trim()).filter(Boolean);if(e.length)return{kind:"dropdown",options:e,default:e[0]}}return{kind:"textbox",default:n}}const Ca=Symbol("set on the page");class Fa{constructor(){this.owners=new Map,this.chosen=new Map,this.listeners=new Set}definitions(e){const t=new Map;for(const[n,r]of this.owners)if(n!==e)for(const[e,n]of r)t.delete(e),t.set(e,n);return t}textOf(e){const t=this.chosen.get(e.name);return t&&t.key===e.key?t.text:e.text}get(e){const t=this.definitions().get(e);return t?this.textOf(t):void 0}names(){return[...this.definitions().keys()]}set(e,t){t=String(t);const n=this.definitions().get(e);if(n&&n.input){const r=this.chosen.get(e);if(r&&r.key===n.key&&r.text===t)return this;this.chosen.set(e,{key:n.key,text:t})}else{const n=new Map(this.owners.get(Ca));n.set(e,{name:e,text:t,key:`page:${t}`,input:null}),this.owners.delete(Ca),this.owners.set(Ca,n)}return this.notify(null,e),this}clear(e){return void 0===e?(this.owners.clear(),this.chosen.clear()):(this.owners.get(Ca)?.delete(e),this.chosen.delete(e)),this.notify(null,e),this}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}own(e,t){const n=this.owners.get(e);var r,i;(r=n,i=t,(r?.size??0)===(i?.size??0)&&[...r??[]].every(([e,t])=>i?.get(e)?.key===t.key))?t&&this.owners.set(e,t):(t&&t.size?this.owners.set(e,t):this.owners.delete(e),this.notify(e))}notify(e,t){for(const n of[...this.listeners])n(e,t)}}function Za(){return new Fa}const Ta=Za(),Ra=new RegExp("(\\d+)","g");function Pa(e,{delimiters:t=["$$","$","\\[","\\("]}={}){const n=[];let r="",i=0;const s=String(e).replace(/[\uE000-\uE003]/g,"�"),o=e=>0===e||"\n"===s[e-1],a=function(e){const t=new Map,n=e=>/^( {4}|\t)/.test(e);let r=0,i=!0,s=!1,o=-1;for(const a of e.split("\n")){const e=!a.trim();o>-1&&!e&&!n(a)&&(t.set(o,r-1),o=-1),o<0&&!e&&n(a)&&i&&!s&&(o=r),e||n(a)||(s=Ja.test(a)||s&&/^\s/.test(a)),i=e,r+=a.length+1}o>-1&&t.set(o,e.length);return t}(s);let l=-1;const c=new Set,u=(e,t,r)=>(n.push({source:e,display:t,raw:r,start:i,end:i+r.length}),`${n.length-1}`);for(;i<s.length;){if(a.has(i)){r+=s.slice(i,a.get(i)),i=a.get(i);continue}if(o(i)){const e=/^( {0,3})(`{3,}|~{3,})([^\n]*)\n?/.exec(s.slice(i));if(e){const t=e[2],n=new RegExp(`\\n {0,3}${"`"===t[0]?"`":"~"}{${t.length},}[ \\t]*(?=\\n|$)`),o=s.slice(i+e[0].length),a=n.exec(`\n${o}`),l=a?o.slice(0,Math.max(0,a.index-1)):o,c=e[0].length+(a?a.index-1+a[0].length:o.length),h=s.slice(i,i+c);"math"===e[3].trim()?r+=u(l,!0,h):r+=h,i+=c;continue}}const e=s[i];if("`"===e){const e=/^`+/.exec(s.slice(i))[0],t=s.indexOf(e,i+e.length);if(t>-1){r+=s.slice(i,t+e.length),i=t+e.length;continue}r+=e,i+=e.length;continue}if("\\"===e){const e=s.slice(i,i+2),n="\\["===e?"\\]":"\\("===e?"\\)":null;if(n&&t.includes(e)){const t=c.has(n)?-1:s.indexOf(n,i+2);if(t<0&&c.add(n),t>-1){r+=u(s.slice(i+2,t),"\\["===e,s.slice(i,t+2)),i=t+2;continue}}r+=e,i+=2;continue}if("$"===e)if("$"===s[i+1]&&t.includes("$$")){const e=s.indexOf("$$",i+2);if(e>-1){r+=u(s.slice(i+2,e),!0,s.slice(i,e+2)),i=e+2;continue}}else if(t.includes("$")&&s[i+1]&&!/\s/.test(s[i+1])&&i+1>=l){const{end:e,stop:t}=Ba(s,i+1);if(e>-1){r+=u(s.slice(i+1,e),!1,s.slice(i,e+1)),i=e+1;continue}l=t}r+=e,i++}return{text:r,math:n}}function Ba(e,t){for(let n=t;n<e.length;n++){const t=e[n];if("\\"!==t){if("`"===t)return{end:-1,stop:n};if("\n"===t&&/^\n[ \t]*\n/.test(e.slice(n,n+64)))return{end:-1,stop:n};if("$"===t&&!/\s/.test(e[n-1])&&!/\d/.test(e[n+1]??"")&&"$"!==e[n+1])return{end:n,stop:n}}else n++}return{end:-1,stop:e.length}}const Wa=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Da=/^\s*([A-Za-z\u0370-\u03ff](?:_\{?\w+\}?)?)\s*=\s*([^=<>≤≥]+)$/;function Ua(e,t,n,r){const{text:i,math:s}=Pa(e,t),o=n?n.definitions(r):new Map,a=e=>n?n.textOf(e):e.text,l={...t.scope??{}},c={},u=new Map,h=new Set,p=[],f=e=>{const t=new Map;return n=>{const r=o.get(n);if(!r)return null;if(!t.has(n)){let i=null;try{i=ya(a(r),e)}catch{}t.set(n,i)}return t.get(n)}};let m=!0;const d=s.map((e,n)=>{const{source:r,display:i}=e;m&&r.includes("{{")&&((()=>{for(const e of Object.keys(c))delete c[e];Object.assign(c,l);for(const e of o.keys())delete c[e];let e=[...o.values()];for(;e.length;){const t=e.filter(e=>{try{const t=go(a(e),c);if("number"==typeof t.value||"bigint"==typeof t.value||Array.isArray(t.value))return c[e.name]=t.exact?t.text:t.value,!1}catch{}return!0});if(t.length===e.length)break;e=t}const t={},n=f({});for(const e of o.keys()){const r=n(e);if(r)try{t[e]=z(Ia(r,t=>t===e?null:n(t)).tree)}catch{}}c[Ea]=t})(),m=!1);const s=i?"mv-md-display":"mv-md-math",d=(e,t="")=>`<span class="${s}${t}" data-mv-md="${n}">${e}</span>`;try{const s={...t.math,display:i,blocks:t.blocks,scope:c},g=function(e){let t=e.trim();const n=t.startsWith("_");n&&(t=t.slice(1).trimStart());let r=t.indexOf(":="),i=2;r<0&&n&&(r=t.search(/(?<![<>!≤≥=])=(?!=)/),i=1);const s=n?{error:"a hidden $_…$ saves a variable: $_A := 2+2$"}:null;if(r<=0)return s;const o=t.slice(0,r).trim(),a=t.slice(r+i).trim();let l=null;try{l=/\{\{/.test(o)?null:_a(ya(o))}catch{}return null!==l&&a?{hidden:n,lhs:o,name:l,rhs:a,input:ja(a)}:s}(r);if(g&&g.error)throw new Error(g.error);if(g){const{name:t,input:r,hidden:i}=g,l=r?{name:t,text:r.default,input:r,key:`input:${JSON.stringify(r)}`}:{name:t,text:g.rhs,input:null,key:`expr:${g.rhs}`,start:e.start,end:e.end};let c="";if(r){const e=function(e,t){const{input:n,name:r}=e,i=`class="mv-md-input mv-md-${n.kind}" data-mv-var="${Wa(r)}" aria-label="${Wa(r)}"`;if("dropdown"===n.kind)return`<select ${i}>${n.options.map(e=>`<option value="${Wa(e)}"${e===t?" selected":""}>${Wa(e)}</option>`).join("")}</select>`;return"slider"===n.kind?`<input type="range" ${i} min="${n.min}" max="${n.max}" step="${n.step}" value="${Wa(t)}"><output class="mv-md-output" data-mv-out="${Wa(r)}">${Wa(t)}</output>`:`<input type="text" ${i} value="${Wa(t)}" size="${Math.max(4,t.length+1)}" spellcheck="false" autocomplete="off">`}(l,a(l));c=i?e:`${va(g.lhs,s)}<span class="mv-md-assign" aria-hidden="true">≔</span>${e}`,h.add(n)}else{const e=Ia(ya(g.rhs,s),f(s)).tree;if(!i){const t=da({type:"op",op:"=",args:[ca(ya(g.lhs)),void 0===e.id?e:ca(e)]});p[n]=t,c=function(e,t="mv"){return e.replace(`<span class="${t}-rel">=</span>`,`<span class="${t}-rel ${t}-rel-def">≔</span>`).replace(/(aria-label="[^"]*?) equals /,"$1 is defined as ").replace("<mo>=</mo>","<mo>≔</mo>")}(va(t,s),s.prefix)}}return o.delete(t),o.set(t,l),u.set(t,l),m=!0,i&&!r?"":d(c,r?" mv-md-input-def":"")}const{tree:b,changed:$}=Ia(ya(r,s),f(s));$&&da(b),p[n]=b;const y=va(b,s);return!$&&!1!==t.define&&function(e,t,n){const r=Da.exec(e);if(!r||/\{\{/.test(r[2]))return!1;const i=r[1].replace(/[{}]/g,"");if(n.has(i))return!1;try{const e=go(r[2],t);if("number"==typeof e.value||"bigint"==typeof e.value||Array.isArray(e.value))return t[i]=e.exact?e.text:e.value,!0}catch{}return!1}(r,l,o)&&(m=!0),d(y)}catch(t){return`<span class="mv-md-error" data-mv-md="${n}" title="${Wa(t.message)}"><code>${Wa(e.raw)}</code></span>`}});return{text:i,math:s,drawn:d,defs:u,inputs:h,trees:p}}const Ha=/^(https?:|mailto:|#|\/|\.{0,2}\/|[^:]*$)/i,Ga=e=>Ha.test(e.trim())?Wa(e.trim()):"#",Va=/\uE002(\d+)\uE003/g;function Xa(e,t,n,r=[]){const i=e=>(r.push(e),`${r.length-1}`),s=e=>(e=>e.replace(/"/g,'"').replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"))(n(e).replace(Va,(e,t)=>(r[Number(t)]??"").replace(/<[^>]*>/g,"")));let o=e;o=o.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g,(e,t,r)=>i(`<code>${Wa(n(r.trim()))}</code>`)),o=o.replace(/\\([\\`*_{}[\]()#+\-.!|~$<>"'])/g,(e,t)=>i(Wa(t))),o=o.replace(/<((?:https?:\/\/|mailto:)[^\s>]+)>/g,(e,t)=>i(`<a href="${Ga(t)}">${Wa(t)}</a>`)),t.html&&(o=o.replace(/<\/?[A-Za-z][^>]*>/g,e=>i(e))),o=o.replace(/!\[([^\[\]]*)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,t,n,r)=>i(`<img src="${Ga(s(n))}" alt="${Wa(s(t))}"${r?` title="${Wa(s(r))}"`:""}>`)),o=o.replace(/\[([^\[\]]+)\]\(\s*((?:[^\s()]|\([^\s()]*\))+)(?:\s+"([^"]*)")?\s*\)/g,(e,o,a,l)=>i(`<a href="${Ga(s(a))}"${l?` title="${Wa(s(l))}"`:""}>${Xa(o,t,n,r)}</a>`)),o=o.replace(/&(?!#\d{1,7};|#x[0-9a-f]{1,6};|[a-z][a-z0-9]{1,31};)/gi,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),o=o.replace(/(\*\*\*|___)(?=\S)([\s\S]*?\S)\1/g,"<strong><em>$2</em></strong>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*\*|__)(?![*_])([\s\S]*?\S)(\*|_)(?![*_])/g,"<em><strong>$2</strong>$4</em>"),o=o.replace(/(\*\*\*|___)(?=\S)([^*_]*?\S)(\*|_)(?![*_])([\s\S]*?\S)(\*\*|__)(?![*_])/g,"<strong><em>$2</em>$4</strong>"),o=o.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g,"<strong>$2</strong>"),o=o.replace(/(^|[^*\w])\*(?=\S)([\s\S]*?\S)\*(?!\*)/g,"$1<em>$2</em>"),o=o.replace(/(^|[^_\w])_(?=\S)([\s\S]*?\S)_(?![_\w])/g,"$1<em>$2</em>"),o=o.replace(/~~(?=\S)([\s\S]*?\S)~~/g,"<del>$1</del>"),o=o.replace(/( {2,}|\\)\n/g,"<br>\n");for(let e=0;e<8&&/\uE002\d+\uE003/.test(o);e++)o=o.replace(Va,(e,t)=>r[Number(t)]??"");return o}const Qa=/^( {0,3})(#{1,6}\s|>|```|~~~|([-*+]|\d{1,9}[.)])\s|(\*[ \t]*){3,}$|(-[ \t]*){3,}$|(_[ \t]*){3,}$)/,Ja=/^( {0,3})([-*+]|\d{1,9}[.)])(\s+|$)/,Ya=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,Ka=e=>Qa.test(e)&&!/^ {0,3}[-=]+\s*$/.test(e)&&!/^ {0,3}(?!1[.)])\d{1,9}[.)]\s/.test(e);function el(e){const t=e.trim();let n=t.length;for(;n>0&&"#"===t[n-1];)n--;return n===t.length?t:0===n?"":/[ \t]/.test(t[n-1])?t.slice(0,n).trimEnd():t}function tl(e,t,n,r=0){const i=[];let s=0;const o=e=>Xa(e,t,n);if(r>100)return`<p>${o(e.join("\n"))}</p>`;for(;s<e.length;){const a=e[s];if(!a.trim()){s++;continue}const l=/^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)/.exec(a);if(l){const t=[];for(s++;s<e.length&&!new RegExp(`^ {0,3}${"`"===l[1][0]?"`":"~"}{${l[1].length},}\\s*$`).test(e[s]);)t.push(e[s++]);s++;const r=l[2]?` class="language-${Wa(l[2])}"`:"";i.push(`<pre><code${r}>${Wa(n(t.join("\n")))}</code></pre>`);continue}const c=/^ {0,3}(#{1,6})[ \t]+/.exec(a);if(c){i.push(`<h${c[1].length}>${o(el(a.slice(c[0].length)))}</h${c[1].length}>`),s++;continue}if(/^ {0,3}((\*[ \t]*){3,}|(-[ \t]*){3,}|(_[ \t]*){3,})$/.test(a)){i.push("<hr>"),s++;continue}if(/^ {0,3}>/.test(a)){const o=[];for(;s<e.length&&e[s].trim()&&(/^ {0,3}>/.test(e[s])||o.length);)o.push(e[s].replace(/^ {0,3}> ?/,"")),s++;i.push(`<blockquote>\n${tl(o,t,n,r+1)}\n</blockquote>`);continue}const u=Ja.exec(a);if(u){const o=/\d/.test(u[2]),a=o?parseInt(u[2],10):1,l=[];let c=!1;for(;s<e.length;){const t=Ja.exec(e[s]);if(!t||/\d/.test(t[2])!==o)break;const n=t[0].length,r=[e[s].slice(n)];for(s++;s<e.length;){const t=e[s];if(!t.trim()){const t=e[s+1];if(void 0!==t&&t.startsWith(" ".repeat(Math.min(n,4)))&&t.trim()){r.push(""),c=!0,s++;continue}void 0!==t&&Ja.test(t)&&(c=!0);break}if(t.startsWith(" ".repeat(Math.min(n,4))))r.push(t.slice(Math.min(n,4)));else{if(Ja.test(t)||Qa.test(t))break;r.push(t)}s++}for(l.push(r);s<e.length&&!e[s].trim()&&void 0!==e[s+1]&&Ja.test(e[s+1]);)s++}const h=o?"ol":"ul",p=l.map(e=>{let i=tl(e,t,n,r+1);return c||(i=i.replace(/^<p>([\s\S]*?)<\/p>/,"$1").replace(/\n<p>([\s\S]*?)<\/p>/g,"\n$1")),`<li>${i}</li>`});i.push(`<${h}${o&&1!==a?` start="${a}"`:""}>\n${p.join("\n")}\n</${h}>`);continue}if(a.includes("|")&&void 0!==e[s+1]&&Ya.test(e[s+1])&&e[s+1].includes("-")){const t=e=>e.trim().replace(/^\|/,"").replace(/\|$/,"").split(/(?<!\\)\|/).map(e=>e.trim()),n=t(e[s+1]).map(e=>e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":e.startsWith(":")?"left":""),r=(e,t,r)=>`<${e}${n[r]?` style="text-align:${n[r]}"`:""}>${o(t)}</${e}>`,l=t(a);s+=2;const c=[];for(;s<e.length&&e[s].trim()&&e[s].includes("|");)c.push(t(e[s++]));i.push(`<table>\n<thead><tr>${l.map((e,t)=>r("th",e,t)).join("")}</tr></thead>\n<tbody>\n${c.map(e=>`<tr>${l.map((t,n)=>r("td",e[n]??"",n)).join("")}</tr>`).join("\n")}\n</tbody>\n</table>`);continue}if(/^( {4}|\t)/.test(a)){const t=[];for(;s<e.length&&(/^( {4}|\t)/.test(e[s])||!e[s].trim());)t.push(e[s++].replace(/^( {4}|\t)/,""));for(;t.length&&!t[t.length-1].trim();)t.pop();i.push(`<pre><code>${Wa(n(t.join("\n")))}</code></pre>`);continue}const h=[];for(;s<e.length&&e[s].trim()&&(!h.length||!Ka(e[s]));){if(h.length&&/^ {0,3}(=+|-+)\s*$/.test(e[s])){const t="="===e[s].trim()[0]?1:2;i.push(`<h${t}>${o(h.join("\n"))}</h${t}>`),h.length=0,s++;break}h.push(e[s].replace(/^ {0,3}/,"")),s++}h.length&&i.push(`<p>${o(h.join("\n"))}</p>`)}return i.join("\n")}function nl(e,t={},n=e=>e){return tl(String(e).replace(/\r\n?/g,"\n").replace(/[\uE002\uE003]/g,"�").split("\n"),t,n)}function rl({text:e,math:t,drawn:n},r){return(r.render?r.render(e):nl(e,r,e=>e.replace(Ra,(e,n)=>t[Number(n)]?.raw??""))).replace(new RegExp("<p>\\s*(\\d+)\\s*</p>","g"),(e,r)=>t[Number(r)].display&&n[Number(r)]?`<div class="mv-md-block">${n[Number(r)]}</div>`:e).replace(Ra,(e,t)=>n[Number(t)]??"").replace(/<p>\s*<\/p>\n?/g,"")}const il=new WeakMap,sl=new Set;function ol(){for(const e of sl)e.connected()&&!e.element.isConnected&&e.stop(!0)}function al(e){const t=e=>function(e){if(e.length>1e6)throw new Error("The output would be too long");return e}("op"===e.type?ul(e,t):function(e){const t=e.value;return"symbol"!==e.type?t:j[t]?j[t]:"\\+"===t||"\\-"===t?t[1]:t}(e));return t(e)}const ll={"+":"+","-":"-","*":"*","/":"/","^":"^",mod:"mod","±":"±","=":"=","===":"===","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","∪":"∪","∩":"∩","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},cl={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]};function ul(e,t){const{op:n,args:r}=e,[i,s]=r,a=(e,r)=>u(n,B(e),r)?`(${t(e)})`:t(e),l=()=>r.map(t).join(", "),c=e=>U(n,e)?`(${t(e)})`:t(e);if("*"===n&&P(e))return ul({...e,op:"neg",args:[s]},t);if("+"===n&&P(s))return ul({...e,op:"-",args:[i,s.args[1]]},t);if("-"===n&&P(s))return ul({...e,op:"+",args:[i,s.args[1]]},t);if("^"===n){const e=a(i,"left");return`${e.startsWith("-")?`(${e})`:e}^${a(s,"right")}`}if("*"===n&&e.written)return`${a(i,"left")} ${"cross"===e.written?"×":"·"} ${a(s,"right")}`;if(ll[n])return`${a(i,"left")} ${ll[n]} ${a(s,"right")}`;if(ue[n])return`${n}(${he(e).map(e=>`[${e.map(t).join(", ")}]`).join(", ")})`;if(cl[n])return cl[n][0]+l()+cl[n][1];if(o(n))return`${ee(n)}(${l()})`;switch(n){case"neg":return"-"+c(i);case"pmod":return`${t(i)} (mod ${t(s)})`;case"pm":return"±"+c(i);case"!":return c(i)+"!";case"\\not":return"¬"+c(i);case"sqrt":return`√(${t(i)})`;case"root":{const e="number"===i.type?{3:"∛",4:"∜"}[i.value]:null;return e?`${e}(${t(s)})`:`root(${t(i)}, ${t(s)})`}case"abs":return`|${t(i)}|`;case"floor":return`⌊${t(i)}⌋`;case"ceil":return`⌈${t(i)}⌉`;case"log":return`log_${"op"===i.type?`(${t(i)})`:t(i)}(${t(s)})`;case"loglog":return`ln(ln(${t(i)}))`;case"logloglog":return`ln(ln(ln(${t(i)})))`;case"perm":return`perm(${t(i)}, ${t(s)})`;case"comb":return`comb(${t(i)}, ${t(s)})`;case"_":return`${t(i)}_${t(s)}`;case"?:":return`${ae(i)?`(${t(i)})`:t(i)} ? ${t(s)} : ${t(r[2])}`;case"sum":return r.map((e,n)=>u("+",B(e),n?"right":"left")?`(${t(e)})`:t(e)).join(" + ");case"prod":return r.map((e,n)=>u("*",B(e),n?"right":"left")?`(${t(e)})`:t(e)).join(" * ");case"setbuilder":return`{${r.map(t).join(" : ")}}`;case"evaluated":return`evaluated(${r.map(t).join(", ")})`;case"der":{const{n:n,body:r,by:i,at:s,variable:o}=ie(e);if(s)return`der(${t(r)}, ${t(i)} = ${t(s)}${n>1?`, ${n}`:""})`;const a=n>1?`^${n}`:"";return o?`d${a}${t(r)}/d${t(i)}${a}`:`d${a}/d${t(i)}${a}(${t(r)})`}case"int":return function(e,t){const[n,r,i,s]=e,o=e.length>=2&&K(r)?t(r):q(n)||"x",a=`${t(n)} d${o}`;return 1===e.length||2===e.length&&K(r)?`∫ ${a}`:`int(${e.map(t).join(", ")})`}(r,t);case"lim":return function(e,t){const[n,r,i,s]=e;return 4===e.length?`lim(${t(n)}, ${t(r)}, ${t(i)}, ${C(s).toLowerCase().startsWith("r")?"r":"l"})`:`lim(${e.map(t).join(", ")})`}(r,t);case"\\sumidx":return hl("∑",r,t);case"\\prodidx":return hl("∏",r,t)}return`${n}(${l()})`}function hl(e,t,n){const[r,i,s]=t,o="∑"===e?"sum":"prod";if(3===t.length&&"op"===i.type&&"="===i.op)return`${o}(${n(r)}, ${n(i)}, ${n(s)})`;if(2===t.length&&"op"===i.type&&"∈"===i.op)return`${o}(${n(r)}, ${n(i)})`;const a=q(r);return 3===t.length&&a?`${o}(${n(r)}, ${a} = ${n(i)}, ${n(s)})`:1===t.length?`${e} ${n(r)}`:2===t.length?`${e}[${n(i)}] ${n(r)}`:`${e}[${n(i)}, ${n(s)}] ${n(r)}`}for(const e of[ll,cl])Object.setPrototypeOf(e,null);var pl='/*\n * Inline Math stylesheet. Everything is under .mv; colors are left to the page.\n *\n * The numbers marked "metric" must match the constants at the top of\n * src/layout.js (line-height 1, bar 0.06em, gap 0.1em); everything else can\n * be changed freely.\n *\n * Handy hooks:\n * .mv-n[data-node="4"] one node (ids from MathZetta)\n * .mv-var .mv-num .mv-word variables, numbers, function names\n * .mv-op-frac .mv-op-pow … a kind of operation\n * .mv-hl the class highlight() adds\n * --mv-hl highlight color\n */\n\n.mv {\n display: inline-block;\n font-family: "Inline Math Roman", "Latin Modern Roman", "STIX Two Text", "Cambria", "Times New Roman", serif;\n font-size: 1.2em;\n font-style: normal;\n font-weight: normal;\n line-height: 1; /* metric */\n white-space: nowrap;\n text-indent: 0;\n text-align: left;\n letter-spacing: 0;\n}\n.mv-display { display: block; text-align: center; margin: 0.6em 0; }\n.mv span, .mv svg { line-height: 1; }\n.mv-n { display: inline-block; border-radius: 0.12em; }\n\n/* ---- letters and signs -------------------------------------------------- */\n.mv-var { font-style: italic; padding-right: 0.03em; }\n.mv-num, .mv-word, .mv-name, .mv-ord, .mv-text, .mv-d, .mv-conj { font-style: normal; }\n.mv-prime { margin-left: 0.04em; }\n.mv-bin { margin: 0 0.22em; }\n.mv-rel { margin: 0 0.28em; }\n.mv-conj { margin: 0 0.6em; } /* x = 2 or x = 3 */\n.mv-punct { margin-right: 0.17em; }\n.mv-sign { margin-right: 0.04em; }\n.mv-times { display: inline-block; width: 0.06em; }\n.mv-callgap { display: inline-block; width: 0.05em; }\n.mv-fnspace { display: inline-block; width: 0.17em; }\n.mv-space { display: inline-block; width: 0.33em; }\n.mv-dx { display: inline-block; margin-left: 0.17em; }\n.mv-text { margin: 0 0.25em; }\n/* Tighter spacing in limits and exponents: n=1, x→0. */\n.mv-script .mv-rel, .mv-sup .mv-rel, .mv-sub .mv-rel { margin: 0 0.12em; }\n.mv-script .mv-bin, .mv-sup .mv-bin, .mv-sub .mv-bin { margin: 0 0.1em; }\n\n/* ---- fractions (metric: padding and border) ------------------------------ */\n.mv-frac { display: inline-flex; flex-direction: column; align-items: stretch; margin: 0 0.12em; }\n.mv-numer, .mv-denom { display: block; text-align: center; padding: 0 0.1em; }\n.mv-numer { padding-bottom: 0.1em; }\n.mv-denom { padding-top: 0.1em; border-top: 0.06em solid currentColor; }\n.mv-frac-nobar > .mv-denom { border-top: 0; }\n.mv-scaled { display: inline-block; }\n\n/* ---- scripts ----------------------------------------------------------------- */\n.mv-sup, .mv-sub { display: inline-block; margin-left: 0.04em; }\n.mv-subsup, .mv-limits { display: inline-flex; flex-direction: column; justify-content: space-between; align-items: flex-start; margin-left: 0.04em; }\n.mv-limits { margin-left: 0.02em; margin-right: 0.12em; }\n.mv-limits > .mv-lower { margin-left: -0.3em; }\n.mv-script { display: block; }\n.mv-under { display: inline-flex; flex-direction: column; align-items: center; margin-right: 0.15em; }\n.mv-under > .mv-script { margin-top: 0.05em; }\n.mv-bigop { display: inline-flex; flex-direction: column; align-items: center; margin: 0 0.12em; }\n.mv-bigop > .mv-script { display: block; margin: 0.08em 0; }\n.mv-bigop > svg { display: block; }\n\n/* ---- radicals (metric: border and padding-top) ----------------------------- */\n.mv-sqrt { display: inline-block; white-space: nowrap; }\n.mv-radicand { display: inline-block; position: relative; border-top: 0.06em solid currentColor; padding: 0.1em 0.1em 0 0.06em; }\n/* the hook, in the radicand\'s left margin (layout.js sets its width and that margin): from the bar\'s center\n (just below the middle of the 0.06em border above the box) to the bottom of what it holds, so the tip always meets the bar */\n.mv-hook { position: absolute; top: -0.02em; height: calc(100% + 0.02em); overflow: visible; } /* a hair below the center: never above the bar */\n.mv-rootindex { display: inline-block; margin: 0 -0.32em 0 0.12em; }\n\n/* ---- delimiters: drawn at the full height of what they enclose -------------- */\n.mv-fence { display: inline-block; position: relative; }\n.mv-delim { position: absolute; top: 0; bottom: 0; height: 100%; }\n.mv-delim-l { left: 0.03em; }\n.mv-delim-r { right: 0.03em; }\nspan.mv-delim { width: 0.16em; border: 0 solid currentColor; box-sizing: border-box; }\n.mv-delim.mv-lbrack { border-width: 0.06em 0 0.06em 0.06em; left: 0.06em; }\n.mv-delim.mv-rbrack { border-width: 0.06em 0.06em 0.06em 0; right: 0.06em; }\n.mv-delim.mv-vert { border-left-width: 0.06em; width: 0; left: 0.07em; }\n.mv-delim.mv-vert.mv-delim-r { left: auto; right: 0.07em; }\n.mv-delim.mv-lfloor { border-width: 0 0 0.06em 0.06em; }\n.mv-delim.mv-rfloor { border-width: 0 0.06em 0.06em 0; }\n.mv-delim.mv-lceil { border-width: 0.06em 0 0 0.06em; }\n.mv-delim.mv-rceil { border-width: 0.06em 0.06em 0 0; }\n/* around one line: inline, placed from the baseline like a typed bracket (0.25em below it, 0.75em above),\n not stretched over the line box, which sits higher or lower in every font; the margins keep the widths */\n.mv-fence-line > .mv-delim { position: static; display: inline-block; vertical-align: -0.25em; height: 1em; }\n.mv-fence-line > svg.mv-delim-l { margin: 0 0.07em 0 0.03em; }\n.mv-fence-line > svg.mv-delim-r { margin: 0 0.03em 0 0.07em; }\n.mv-fence-line > span.mv-delim-l { margin: 0 0.08em 0 0.06em; }\n.mv-fence-line > span.mv-delim-r { margin: 0 0.06em 0 0.08em; }\n.mv-fence-line > .mv-delim.mv-vert.mv-delim-l { margin: 0 0.11em 0 0.07em; }\n.mv-fence-line > .mv-delim.mv-vert.mv-delim-r { margin: 0 0.07em 0 0.11em; }\n\n/* ---- shapes ----------------------------------------------------------------- */\n.mv svg { overflow: visible; }\n.mv svg path[stroke] { stroke-width: 0.065em; stroke-linecap: round; stroke-linejoin: round; }\n.mv-intsign path[stroke] { stroke-width: 0.075em; }\n.mv-bigsign { display: inline-block; margin: 0 0.06em; }\n.mv-intsign { margin-right: 0.12em; }\n\n/* ---- piecewise ------------------------------------------------------------- */\n.mv-cases { display: inline-grid; grid-template-columns: auto auto; column-gap: 1em; row-gap: 0.25em; align-items: baseline; text-align: left; margin: 0 0.1em; }\n.mv-case-value, .mv-case-cond { display: block; }\n.mv-matrix { display: inline-grid; column-gap: 0.8em; row-gap: 0.3em; align-items: baseline; justify-items: center; margin: 0 0.15em; }\n.mv-matrix-row { display: contents; }\n.mv-matrix-cell { display: block; }\n\n/* ---- decorations: \\boxed \\cancel \\overline \\vec … --------------------------- */\n.mv-boxed { display: inline-block; border: 0.06em solid currentColor; padding: 0.16em 0.2em; }\n.mv-over { display: inline-block; position: relative; padding-top: 0.14em; }\n.mv-over::before { content: \'\'; position: absolute; left: 0; right: 0; top: 0.21em; border-top: 0.06em solid currentColor; } /* metric */\n.mv-over-low::before { top: 0.48em; }\n.mv-underline { display: inline-block; border-bottom: 0.06em solid currentColor; padding-bottom: 0.06em; }\n.mv-cancel { display: inline-block; position: relative; }\n.mv-cancel-line { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }\n.mv-accent { display: inline-block; position: relative; padding-top: 0.3em; }\n.mv-accent-mark { position: absolute; top: -0.27em; left: 0; right: 0; text-align: center; font-size: 0.7em; line-height: 0.6; } /* metric: measured over F, h, A */\n/* ˆ ˜ ˙ ¨ are spacing marks that sit high in their em: full size, pulled down onto the letter */\n.mv-accent-hat, .mv-accent-widehat, .mv-accent-tilde, .mv-accent-dot, .mv-accent-ddot { font-size: 1em; line-height: 1; top: 0.02em; }\n/* over an italic letter the mark leans with it, right of the box\'s center */\n.mv-accent:has(> .mv-var) > .mv-accent-mark { transform: translateX(0.1em); }\n/* a letter with no ascender (x, u, α; layout.js adds -low): the mark comes down to its top */\n.mv-accent-low > .mv-accent-mark { top: 0.08em; }\n.mv-accent-low > .mv-accent-hat, .mv-accent-low > .mv-accent-widehat, .mv-accent-low > .mv-accent-tilde, .mv-accent-low > .mv-accent-dot, .mv-accent-low > .mv-accent-ddot { top: 0.31em; }\n\n/* ---- interaction -------------------------------------------------------------- */\n.mv-hl { background: var(--mv-hl, rgba(255, 200, 0, 0.35)); box-shadow: 0 0 0 0.08em var(--mv-hl, rgba(255, 200, 0, 0.35)); }\n/* Windows high contrast (and other forced colors) drops backgrounds and shadows: outline a highlight instead */\n@media (forced-colors: active) {\n .mv-hl { outline: 0.08em solid Highlight; outline-offset: 0.04em; }\n}\n.mv-clickable .mv-n { cursor: pointer; }\n.mv-editable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the box editing a part in place (view.editable, or a Markdown textbox variable) */\n.mv-edit { transform: translateY(-50%); z-index: 1000; box-sizing: content-box; padding: 0.1em 0.35em; font-family: inherit;\n border: 1px solid #1a5fb4; border-radius: 0.25em; background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }\n.mv-edit[aria-invalid="true"] { border-color: #c33; outline: 2px solid #c33; }\n/* the live region a view announces steps through ({ announce: true }): read, never seen */\n.mv-sr-only, .mv-sr-math { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }\n.mv-clickable .mv-n:hover { outline: 1px dashed rgba(0, 0, 0, 0.25); }\n/* the keyboard: the expression is one tab stop, and the part the arrow keys are on is ringed */\n.mv[tabindex]:focus-visible { outline: 0.1em solid #1a5fb4; outline-offset: 0.12em; }\n.mv[tabindex]:focus .mv-focus { outline: 0.1em solid #1a5fb4; outline-offset: 0.06em; border-radius: 0.1em; }\n/* while a part is ringed, the whole expression\'s ring steps back so the part is the one that stands out */\n.mv[tabindex]:focus-visible:has(.mv-focus) { outline: 1px dashed #1a5fb4; }\n@media (forced-colors: active) {\n .mv[tabindex]:focus-visible, .mv[tabindex]:focus .mv-focus { outline-color: Highlight; }\n}\n\n/* ---- steps (stepsHTML from \'@mathzetta/inlinemath/cas\') ---------------------------------------- */\n.mv-steps { margin: 0; padding-left: 1.6em; }\n.mv-step { margin: 0.5em 0 0.9em; }\n.mv-step-name { display: block; font-size: 0.85em; font-weight: 600; color: #555; }\n.mv-step-maths { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4em 0.8em; margin: 0.15em 0; }\n.mv-step-arrow { color: #888; }\n.mv-step-why { margin: 0.1em 0 0; font-size: 0.9em; color: #444; }\n\n/* ---- Markdown with math (markdownToHTML from \'@mathzetta/inlinemath/markdown\') ------------------- */\n.mv-md-math { display: inline-block; vertical-align: middle; }\n.mv-md-display { display: block; text-align: center; margin: 0.6em 0; overflow-x: auto; }\n.mv-md-block { margin: 0.8em 0; }\n.mv-md-error code { background: rgba(200, 60, 0, 0.08); color: #a33; border-bottom: 1px dotted #a33; }\n/* saved variables: $A := 2+2$ draws A ≔ 2 + 2; $A := [[…]]$ an input that sets A */\n.mv-md-input-def { display: inline-flex; align-items: center; gap: 0.3em; }\n.mv-md-assign { margin: 0 0.1em; }\n.mv-md-input { font: inherit; font-size: 0.9em; }\ninput.mv-md-textbox { font-family: inherit; padding: 0.05em 0.3em; field-sizing: content; min-width: 3ch; }\ninput.mv-md-textbox[aria-invalid="true"] { outline: 2px solid #c33; outline-offset: 1px; }\ninput.mv-md-slider { vertical-align: middle; }\n.mv-md-output { font-variant-numeric: tabular-nums; min-width: 2ch; }\n';const fl=pl;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=pl,document.head.append(e)}return e.CSS=fl,e.DEFAULTS=Jo,e.PATHS=Oo,e.View=Ma,e.createVariables=Za,e.extractMath=Pa,e.layout=na,e.markdownToHTML=function(e,t={}){return rl(Ua(e,t,t.variables||null),t)},e.nodeAt=fa,e.numberTree=da,e.pathOf=ma,e.render=function(e,t,n={}){return new Ma(e,t,n)},e.renderMarkdown=nl,e.renderMarkdownInto=function(e,t,n={}){const r=void 0===n.variables?Ta:n.variables||null;ol();const i=il.get(e);i&&i.stop(i.store!==r);let s=Ua(t,n,r,e);if(e.innerHTML=rl(s,n),!r)return il.delete(e),e;r.own(e,s.defs);let o=e.isConnected;const a=t=>{const i=t.target,s=i&&i.dataset&&i.dataset.mvVar;if(void 0!==s&&e.contains(i)){if("text"===i.type)try{ya(i.value,{blocks:n.blocks,scope:{}}),i.removeAttribute("aria-invalid")}catch{return void i.setAttribute("aria-invalid","true")}r.set(s,i.value)}},l=i=>{const o=i.target.closest?.("[data-node]"),a=o&&o.closest("[data-mv-md]");if(!a||!e.contains(a))return;const l=Number(a.dataset.mvMd),c=s.trees[l];if(!c)return;const u=Number(o.dataset.node),h=ma(c,u)||[];let p=null;for(let e=h.length;e>=0&&!p;e--){const t=fa(c,h.slice(0,e));t&&void 0!==t.from&&(p={node:t,depth:e})}const f=p&&r.definitions().get(p.node.from);if(f&&f.input&&"textbox"===f.input.kind){i.preventDefault();const t=f.name,s=e.ownerDocument.querySelector(`[data-mv-var="${CSS.escape(t)}"]`),a=n.editable&&n.editable.toText;if(!a)return void(s&&(s.focus(),s.select()));const l=e=>ya(e),u=fa(c,h);return void xa(o,a(Oa(u,l)),{label:`Edit ${t}`,parse:e=>ya(e,{blocks:n.blocks}),commit:e=>{const n=wa(Oa(p.node,l),h.slice(p.depth),e);r.set(t,a(n))}})}const m=f&&s.defs.get(f.name),d=m&&m.key===f.key&&void 0!==m.start?{...s.math[l],start:m.start,end:m.end,raw:t.slice(m.start,m.end)}:s.math[l];e.dispatchEvent(new CustomEvent("inlinemath:select",{bubbles:!0,detail:{index:l,start:d.start,end:d.end,raw:d.raw,source:d.source,id:u,path:h}}))};e.addEventListener("input",a),e.addEventListener("change",a),e.addEventListener("dblclick",l);const c=r.subscribe(i=>{i!==e&&(e.isConnected?(o=!0,ol(),(()=>{const i=Ua(t,n,r,e);i.drawn.forEach((t,n)=>{if(t===s.drawn[n]||i.inputs.has(n))return;const r=e.querySelector(`[data-mv-md="${n}"]`);r&&(r.outerHTML=t)});for(const t of e.querySelectorAll("[data-mv-var], [data-mv-out]")){const e=i.defs.get(t.dataset.mvVar??t.dataset.mvOut);if(!e)continue;const n=r.textOf(e);void 0!==t.dataset.mvOut?t.textContent=n:t.value!==n&&t!==t.ownerDocument?.activeElement&&(t.value=n)}s=i})()):o&&u(!0))});function u(t){c(),e.removeEventListener("input",a),e.removeEventListener("change",a),e.removeEventListener("dblclick",l),sl.delete(h),il.delete(e),t&&r.own(e,null)}const h={element:e,store:r,stop:u,connected:()=>o};return sl.add(h),il.set(e,h),e},e.select=ha,e.shouldAnimate=Aa,e.signature=ua,e.toHTML=va,e.toText=function(e){return dr(e)?"":al(mr(e))},e.treeOf=ya,e.variables=Ta,e}({});
|