@mathzetta/inlinemath 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-DHvovDQK.js +2 -0
- package/dist/chunks/draw-Bw547gEd.js +2 -0
- package/dist/chunks/{edit-CTMRUElt.js → edit-BC9D1cIE.js} +2 -2
- package/dist/chunks/{edit-D2RO7fg0.js → edit-CCe3uoyk.js} +2 -2
- package/dist/chunks/{html-1wCO6EpZ.js → html-6HJlblNm.js} +2 -2
- package/dist/chunks/html-DzjcaM8w.js +2 -0
- package/dist/chunks/lite-6yr4ed_k.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 +4 -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 +4 -2
- package/package.json +5 -5
- package/src/cas.js +57 -10
- package/src/glyphs.js +3 -2
- package/src/layout.js +28 -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(e){"use strict";const t=-1,n={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt:r(1),abs:r(1),floor:r(1),ceil:r(1),det:r(1),ln:r(1),loglog:r(1),logloglog:r(1),expm1:r(1),sin:r(1),cos:r(1),tan:r(1),csc:r(1),sec:r(1),cot:r(1),sinh:r(1),cosh:r(1),tanh:r(1),arcsin:r(1),arccos:r(1),arctan:r(1),arcsinh:r(1),arccosh:r(1),arctanh:r(1),random:r(0),log:r(2),root:r(2),atan2:r(2),round:r(2),fixed:r(2),perm:r(2),comb:r(2),der:r(2),max:r(t),min:r(t),gcd:r(t),mean:r(t),sum:r(t),prod:r(t),int:r(t),lim:r(t),"\\sumidx":r(t),"\\prodidx":r(t),pmatrix:r(t),bmatrix:r(t),vmatrix:r(t),"()":i(),"[]":i(),"{}":i(),"(]":i(),"[)":i(),"=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"===":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≠=":{prec:30,assoc:"left",arity:2,fixity:"infix"},"<":{prec:34,assoc:"left",arity:2,fixity:"infix"},">":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≤":{prec:34,assoc:"left",arity:2,fixity:"infix"},"≥":{prec:34,assoc:"left",arity:2,fixity:"infix"},"∈":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∉":{prec:32,assoc:"left",arity:2,fixity:"infix"},"∪":{prec:33,assoc:"left",arity:2,fixity:"infix"},"∩":{prec:33,assoc:"left",arity:2,fixity:"infix"},"≈":{prec:30,assoc:"left",arity:2,fixity:"infix"},"≡":{prec:30,assoc:"left",arity:2,fixity:"infix"},pmod:{prec:2,assoc:"left",arity:2,fixity:"infix"},"→":{prec:38,assoc:"left",arity:2,fixity:"infix"},"\\not":{prec:85,assoc:"none",arity:1,fixity:"prefix"},"&":{prec:20,assoc:"left",arity:2,fixity:"infix"},"\\xor":{prec:19,assoc:"left",arity:2,fixity:"infix"},"|":{prec:18,assoc:"left",arity:2,fixity:"infix"},"\\nor":{prec:17,assoc:"left",arity:2,fixity:"infix"},"\\nand":{prec:17,assoc:"left",arity:2,fixity:"infix"},"?:":{prec:10,assoc:"right",arity:3,fixity:"infix"}};function r(e){return{prec:100,assoc:"none",arity:e,fixity:"prefix"}}function i(){return{prec:5,assoc:"left",arity:t,fixity:"none",group:!0}}const s="\\:",o=e=>"string"==typeof e&&e.startsWith(s)&&e.length>2;function a(e){return Object.prototype.hasOwnProperty.call(n,e)?n[e]:o(e)?l:void 0}const l=r(t),c=e=>a(e)?.prec;const h=100,u="",p="",m={[u]:"dot",[p]:"cross"},f="",d={ln:h,log:h,loglog:h,logloglog:h,sqrt:h,sqrtpow:h,pow:h,expm1:h,der:h,lim:h,int:h,round:h,fixed:h,floor:h,ceil:h,abs:h,random:h,sum:h,prod:h,"\\sumidx":h,"\\prodidx":h,perm:h,comb:h,"\\perm":h,"\\comb":h,"\\binom":h,max:h,min:h,gcd:h,mean:h,pmatrix:h,bmatrix:h,vmatrix:h,det:h,sin:h,cos:h,tan:h,csc:h,sec:h,cot:h,sinh:h,cosh:h,tanh:h,arcsin:h,arccos:h,arctan:h,arcsinh:h,arccosh:h,arctanh:h,atan2:h,_:h,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,[u]:70,[p]:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"?:":10,"?":9,",":5},g=e=>Object.prototype.hasOwnProperty.call(d,e),b=new Set(["^","?:","?","log"]),y=["(","{","["],w=[")","}","]"];function x(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[d])Object.setPrototypeOf(e,null);const v=e=>({type:"number",value:String(e)}),$=e=>({type:"symbol",value:e}),M=(e,t)=>({type:"op",op:e,args:t}),k=['"',"'","`"];function A(e){return x(e,!0)?v(e):k.includes(e[0])?{type:"string",value:e}:$(e)}const N={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function E(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],r=[];if(e.forEach((e,i)=>{const s=N[e]??String(e),l=a(s);if(!l)return n.push({...A(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 h=1+Math.max(0,...r.splice(r.length-c,c));if(h>1e3)throw new Error("Nested too deeply (more than 1000 levels)");r.push(h),n.push({...M(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 O(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 E(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}function _(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>_(n,t,e))}function S(e){let t="";return _(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[N])Object.setPrototypeOf(e,null);const q={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(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function j(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 F(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==z(n)}function L(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":F(e)?"neg":e.op}const T=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),C=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!T.has(e.op))&&function(e,t,n){if("mod"===e&&t)return c(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const r=c(e),i=c(t);if(!r||!i)return!1;if(i!==r)return i<r;const s=a(e).assoc;return"left"===s?"right"===n:"right"===s&&"left"===n}(e.op,L(t),n);function R(e,t){const n=L(t),r=n&&a(n)?.prec;return r?"!"===e?r<=a("!").prec:"\\not"===e?r<a("\\not").prec:r<70||G(t)||"\\not"===n:"\\not"!==e&&G(t)}function P(e,t,n={}){const r=n.left?"bracket":D(e),i=n.right?"bracket":W(t);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function Z(e){return 1===e.length||Boolean(q[e])||/^Δ.$/.test(e)||/^.′+$/.test(e)}function B(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function W(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&Z(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||F(e)?"sign":"/"===t?"frac":a(t)?.group||B(e)?"bracket":U(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?B(e.args[0])?"bracket":W(e.args[0]):["*","sum","prod","perm"].includes(t)?W(e.args[0]):"other"}function D(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&Z(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||B(e)||U(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?D(e.args[e.args.length-1]):"other"}function U(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function G(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||F(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!C(e,e.args[0],"left")&&G(e.args[0])}const H=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),X=e=>e.slice(2);function V(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&&Q(s.args[1],n);)i++,s=s.args[0];return{n:i,body:s,by:n,at:r,variable:"symbol"===s.type&&Z(s.value)}}const Q=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,J=new Set(["<",">","≤","≥","=","≠"]);function Y(e){if("op"!==e.type||!J.has(e.op)||2!==e.args.length)return null;const[t,n]=e.args;if("op"!==t.type||!J.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[Y(t)??t,{type:"op",op:e.op,args:[t.args[1],n]}]}}for(const e of[q])Object.setPrototypeOf(e,null);const K={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function ee(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(K,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 te(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 ne=e=>Array.isArray(e)&&e.length>0&&!e.some(Array.isArray);function re(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 te(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 ie(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 oe(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=se(n,e,i);s?(r+=t.get(e.slice(i,i+s)),i+=s):r+=e[i++]}return r}}function se(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 oe(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),ae(e)]);return t.delete(e),t}function ae(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 le=[["Math.atan2","atan2"],["Math.atan2(","atan2("],["atan2","atan2"],["\\atan2","atan2"],["Math.random()","random(1)"],["random.random()","random(1)"],["Math.log2(","log_{2}("],["Math.log10(","log_{10}("],["Math.log_{","log_{"],["Math.log","log_{e}"],["Math.ln","log_{e}"],["Math.abs(","abs("],["Math.fabs(","abs("],["Math.gcd(","gcd("],["Math.comb(","comb("],["Math.perm(","perm("],["Math.fmod(","mod("],["Math.exp(","(e)^("],["Math.exp2(","(2)^("],["Math.expm1(","expm1("],["Math.pow(","pow("],["**","^"],["Math.floor(","floor("],["Math.ceil(","ceil("],["Math.round(","round("],["Math.max(","max("],["Math.min(","min("],["Math.pi","π"],["Math.PI","π"],["math.Pi","π"],["Math.e","e"],["math.E","e"],["Math.sqrt2","sqrt(2)"],["Math.sqrt(","sqrt("],["Math.SQRT1_2","sqrt(1/2)"],["Math.SQRT1_{2}","sqrt(1/2)"],["Math.SQRT2","sqrt(2)"],["cbrt","sqrt[3]"],["Math.cbrt","sqrt[3]"],["Sqrt","sqrt"],["Root","sqrt"],["\\sqrt{","sqrt{"],["\\frac","frac"],["\\dfrac","frac"],["\\tfrac","frac"],["\\cfrac","frac"],["\\lim","lim"],["\\sum","\\sumidx"],["\\prod","\\prodidx"],["\\displaystyle",""],["\\textstyle",""],["\\,",""],["\\;",""],["\\!",""],["\\quad",""],["\\qquad",""],["\\lvert","|"],["\\rvert","|"],["\\vert","|"],["^\\prime","′"],["^{\\prime}","′"],["^{\\prime\\prime}","′′"],["\\prime","′"],["\\approx","≈"],["\\varepsilon","ε"],["\\vartheta","θ"],["\\varphi","φ"],["\\cup","∪"],["\\mathbb{R}","ℝ",!0],["\\mathbb{N}","ℕ",!0],["\\mathbb{Z}","ℤ",!0],["\\mathbb{Q}","ℚ",!0],["\\mathbb{C}","ℂ",!0],["\\cap","∩"],["\\%","%"],["\\barwedge","\\nand"],["∧","&"],["¬","!"],["↑","\\nand"],["↓","\\nor"],["∫","\\int"],["∑","\\sum"],["∏","\\prod"],["asin(","arcsin("],["acos(","arccos("],["atan(","arctan("],["asinh(","arcsinh("],["acosh(","arccosh("],["atanh(","arctanh("],["\\sqrt*","sqrt"],["Log","log"],["Max","max"],["Min","min"],["Floor","floor"],["Ceil","ceil"],["Round","round"],["Abs","abs"],["Sum","sum"],["Prod","prod"],["Mean","mean"],["Avg","mean"],["Average","mean"],["Gcd","gcd"],["Math.LOG2e","log_{2}(e)"],["Math.LOG10e","log_{10}(e)"],["Math.LN2","log_{e}(2)"],["Math.LN10","log_{e}(10)"],["Math.tau","τ"],["infinity","∞"],["\\infty","∞"],["\\cdot",u],["\\times",p],["×",p],["·",u],["÷","/"],["->","→"],["\\to","→"],["\\max","max"],["\\min","min"],["\\det","det"],["^{\\top}","^{T}",!0],["^\\top","^T",!0],["^{\\intercal}","^{T}",!0],["^\\intercal","^T",!0],["^{\\mathsf{T}}","^{T}",!0],["^{\\mathrm{T}}","^{T}",!0],["product(","prod("],["log[","log_["],["\\log[","log_["],["\\log_","log_"],["\\log","log_{e}"],["\\ln","log_{e}"],["log(","log_{e}("],["ln(","log_{e}("],...["","\\"].flatMap(e=>["(","{"].flatMap(t=>[2,3,4,5,6,7,8,9,10].map(n=>[`${e}log${n}${t}`,`log_{${n}}${t}`]))),["\\log_10","log_{10}"],["log_10","log_{10}"],["\\log\\log","\\loglog"],["\\log\\log\\log","\\logloglog"],["\\loglog","\\loglog"],["\\logloglog","\\logloglog"],["loglog(","loglog("],["\\exp","e^"],["exp(","e^("],["\\div","/"],["\\int","\\int"],["\\in","∈"],["\\not\\in","∉"],["\\notin","∉"],["\\nor"," \\nor "],["\\xor"," \\xor "],["\\nand"," \\nand "],["\\uparrow"," \\nand "],["\\downarrow"," \\nor "],["\\oplus"," \\xor "],["\\lor","∨"],["\\land","&"],["Not"," \\not "],["&&","&"],["\\neg"," \\not "],["\\not"," \\not "],["\\rightarrow","→"],["\\limits_","_"],["\\pmod"," pmod "],["\\equiv","≡"],["\\mod"," mod "],["\\bmod"," mod "],["\\pm","±"],["\\plusmn","±"],["\\neq","≠"],["\\ne","≠"],["!==","≠="],["==","="],["=...=","==="],["!=","≠"],["\\gt",">"],["\\lt","<"],["\\ge","≥"],["\\geq","≥"],[">=","≥"],["\\le","≤"],["\\leq","≤"],["<=","≤"],["<>","≠"],["\\lparen","("],["\\rparen",")"],["\\left(","("],["\\right)",")"],["\\left[","["],["\\right]","]"],["\\left{","{"],["\\right}","}"],["\\left\\{","{"],["\\{","{"],["\\}","}"],["\\right\\}","}"],["\\left.",f],["\\left|","|"],["\\right|","|"],["\\lfloor","⌊"],["\\rfloor","⌋"],["\\lceil","⌈"],["\\rceil","⌉"],["ceiling(","ceil("],["√","sqrt"],["²","^2"],["³","^3"],["⁴","^4"],["⁵","^5"],["⁶","^6"],["⁷","^7"],["⁸","^8"],["⁹","^9"],["⁰","^0"],["¹","^1"],["ⁿ","^n"],["⁻¹","^{-1}"],["⁻²","^{-2}"],["⁻³","^{-3}"],["∛","sqrt[3]"],["∜","sqrt[4]"],["½","(1/2)"],["⅓","(1/3)"],["⅔","(2/3)"],["¼","(1/4)"],["¾","(3/4)"],["⅛","(1/8)"],["⅜","(3/8)"],["⅝","(5/8)"],["⅞","(7/8)"],["⅕","(1/5)"],["⅖","(2/5)"],["⅗","(3/5)"],["⅘","(4/5)"],["⅙","(1/6)"],["⅚","(5/6)"],["⅐","(1/7)"],["⅑","(1/9)"],["⅒","(1/10)"],["⊕"," \\xor "],["∞","∞"],["⋅",u],["−","-"],["\\wedge","&"],["∨","∨"],["\\vee","∨"],["\\Pi","Π",!0],["\\Alpha","Α",!0],["\\Beta","Β",!0],["\\Gamma","Γ",!0],["\\Delta","Δ",!0],["\\Delta ","Δ",!0],["\\Epsilon","Ε",!0],["\\Zeta","Ζ",!0],["\\Eta","Η",!0],["\\Theta","Θ",!0],["\\Iota","Ι",!0],["\\Kappa","Κ",!0],["\\Lambda","Λ",!0],["\\Mu","Μ",!0],["\\Nu","Ν",!0],["\\Xi","Ξ",!0],["\\Omicron","Ο",!0],["\\Rho","Ρ",!0],["\\Sigma","Σ",!0],["\\Tau","Τ",!0],["\\Upsilon","Υ",!0],["\\Phi","Φ",!0],["\\Chi","Χ",!0],["\\Psi","Ψ",!0],["\\Omega","Ω",!0],["\\pi","π",!0],["\\alpha","α",!0],["\\beta","β",!0],["\\gamma","γ",!0],["\\delta","δ",!0],["\\epsilon","ε",!0],["\\zeta","ζ",!0],["\\eta","η",!0],["\\theta","θ",!0],["\\iota","ι",!0],["\\kappa","κ",!0],["\\lambda","λ",!0],["\\mu","μ",!0],["\\nu","ν",!0],["\\xi","ξ",!0],["\\omicron","ο",!0],["\\rho","ρ",!0],["\\sigma","σ",!0],["\\tau","τ",!0],["\\upsilon","υ",!0],["\\phi","φ",!0],["\\chi","χ",!0],["\\psi","ψ",!0],["\\omega","ω",!0]];const ce=e=>" "===e||"\t"===e||"\n"===e,he="({[",ue=")}]";const pe={__proto__:null},me={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((e,t)=>{pe[e]=String(t)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((e,t)=>{me[e]=String(t)}),Object.assign(pe,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"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(me,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const fe=new RegExp(`[${Object.keys(pe).join("")}]+|[${Object.keys(me).join("")}]+`,"g");const de={__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"},ge=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys(de).join("")}])`,"g"),be=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,ye=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function we(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 xe(e,t){const n=[];let r=0,i=0;for(let s=0;s<e.length;s++)he.includes(e[s])?r++:ue.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 ve(e,t,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(he.includes(e[n]))r++;else if(ue.includes(e[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(e)))return n;return-1}function $e(e,t){let n=0;for(let r=t;r<e.length;r++)if(he.includes(e[r]))n++;else if(ue.includes(e[r])&&--n<0)return r;return e.length}function Me(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 ke(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(he.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 Ae(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 Ne(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 Ee=new Set(["pmatrix","bmatrix","vmatrix"]);function Oe(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 Ee.has(r)?r+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function Ie(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 _e(e){const{lower:t,upper:n,next:r}=function(e){let t="",n="",r=0;return"_"===e[0]&&([t,r]=Ie(e,0),"^"===e[r]&&([n,r]=Ie(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(he.includes(e[n]))t++;else if(ue.includes(e[n]))t--;else if(0===t&&"d"===e[n]&&/[A-Za-z\u0370-\u03FF]/.test(e[n+1]??"")&&!/[A-Za-z]/.test(e[n+2]??""))return n;return-1}(i))>=0?(o=i.slice(0,c),a=i[c+1],l=i.slice(c+2)):o=i;if(!a){const e=/frac\{d([A-Za-z])\}/.exec(o);e&&(a=e[1],o=o.replace(e[0],"frac{1}"))}if(!a&&/^[A-Za-z]$/.test(t)){a=[...s(o).matchAll(/(?<![A-Za-z\\])([A-Za-z])(?![A-Za-z(])/g)].map(e=>e[1]).find(e=>e!==t&&e!==n)??"x"}let h="int("+(s(o).trim()?s(o):"1");return a&&(h+=","+a),(t||n)&&(h+=","+t+","+n),h+")"+l}function Se(e){const t=e[0];if(!(t>="A"&&t<="Z"||t>="a"&&t<="z"||t>="α"&&t<="ω"))return!1;const n=e.slice(2);let r=1;for(let e=0;e<n.length;e++)if(ue.includes(n[e])?r--:he.includes(n[e])&&r++,0===r)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function qe(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const ze=/[A-Za-z\u0370-\u03FF]/;function je(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 Fe(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function Le(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 Te(e,t){if(he.includes(e[t])){let n=0;for(let r=t;r<e.length;r++)if(he.includes(e[r]))n++;else if(ue.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(he.includes(e[r]))n++;else{if(ue.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 Ce=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const Re="strtktk",Pe="ABCDEFGHIJ",Ze=e=>Re+[...String(e)].map(e=>Pe[e]).join(""),Be=new RegExp(`^${Re}[${Pe}]+$`);function We(e){let t="";for(let n=0;n<e.length;n++){const r=e[n];if('"'===r||"`"===r){const r=De(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=De(e,n);t+=e.slice(n,r+1),n=r}else t+=r}return t}function De(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 Ue=new RegExp(`${Re}[${Pe}]+|§\\d+§`,"g");function Ge(e,t){return t&&0!==t.size?e.map(e=>"string"!=typeof e?e:e.replace(Ue,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 He={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))"};for(const e of[He])Object.setPrototypeOf(e,null);const Xe="([{",Ve=")]}";function Qe(e,t){let n=0;for(let r=t;r<e.length;r++)if(Xe.includes(e[r]))n++;else if(Ve.includes(e[r])&&0===--n)return r;return-1}function Je(e){if(!e.trim())return[];const t=[];let n=0,r=0;for(let i=0;i<e.length;i++)Xe.includes(e[i])?n++:Ve.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 Ye(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=Qe(e,s);if(o<0)continue;const a=n(Je(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 Ke=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),et=e=>`(${e})`,tt=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const nt={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(et).join(" & ")})`,OR:e=>e.length&&`(${e.map(et).join(" ∨ ")})`,NOT:e=>1===e.length&&`(!(${e[0]}))`,XOR:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,LOG:e=>2===e.length?`log_{${e[1]}}(${e[0]})`:1===e.length&&`log_{10}(${e[0]})`,ATAN2:e=>2===e.length&&`atan2(${e[1]}, ${e[0]})`,INT:e=>1===e.length&&`floor(${e[0]})`,FIXED:e=>(1===e.length||2===e.length)&&`fixed(${e[0]}, ${e[1]??2})`,"FLOOR.MATH":e=>1===e.length&&`floor(${e[0]})`,"CEILING.MATH":e=>1===e.length&&`ceil(${e[0]})`,FACT:e=>1===e.length&&`((${e[0]})!)`,COMBIN:e=>2===e.length&&`comb(${e.join(", ")})`,PERMUT:e=>2===e.length&&`perm(${e.join(", ")})`,AVERAGE:e=>`mean(${e.join(", ")})`,SUM:e=>`sum(${e.join(", ")})`,PRODUCT:e=>`prod(${e.join(", ")})`,MAX:e=>`max(${e.join(", ")})`,MIN:e=>`min(${e.join(", ")})`,MEDIAN:e=>`median(${e.join(", ")})`,"STDEV.P":e=>`stdev(${e.join(", ")})`,STDEVP:e=>`stdev(${e.join(", ")})`,CEILING:e=>(1===e.length||2===e.length&&"1"===e[1].trim())&&`ceil(${e[0]})`,RAND:e=>!e.length&&"random()",ISNUMBER:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,LOG10:e=>1===e.length&&`log_{10}(${e[0]})`};function rt(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 it(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=Qe(e,o)+1;else{const t=n.exec(e.slice(o));s=t?o+t[0].length:0,t&&"("===e[s]&&(s=Qe(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=rt(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),Ye(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>nt[t[1]]?.(e)||null)}const st={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"},ot="strtktk[A-J]+";function at(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${ot})\\s*\\|\\|\\s*(${ot})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${ot},\\s*${ot}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const r=Qe(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=Ye(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=Ye(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})`,et(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=>st[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=Qe(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 lt={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"},ct={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 ht={inf:"∞",nan:"NaN"};function ut(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)=>lt[t]?`Math.${lt[t]}`:ct[t]?ct[t]:ht[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)=>mt[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>mt[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>ft[t]??pt[t]??e)}(e=(e=(e=e.replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>ht[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 pt={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},mt={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},ft={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:""},dt={open:"()",Lopen:"(]",Ropen:"[)"};const gt=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?Je(t[1]):null},bt=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,yt=e=>gt(e)??[e],wt={where:e=>3===e.length&&`((${e[0]}) ? (${e[1]}) : (${e[2]}))`,logical_and:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,logical_or:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,logical_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,logical_not:e=>1===e.length&&`(!(${e[0]}))`,isin:e=>2===e.length&&`((${e[0]}) ∈ ${tt(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${tt(e[0])})`,isclose:e=>e.length>=2&&`((${e[0]}) ≈ (${e[1]}))`,isfinite:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,isinteger:e=>1===e.length&&`((${e[0]}) ∈ ℤ)`,factorial:e=>1===e.length&&`((${e[0]})!)`,union:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,union_:e=>2===e.length&&`((${e[0]}) ∪ (${e[1]}))`,intersection:e=>2===e.length&&`((${e[0]}) ∩ (${e[1]}))`,sq:e=>1===e.length&&`((${e[0]})^2)`,cube:e=>1===e.length&&`((${e[0]})^3)`,fract:e=>1===e.length&&`((${e[0]}) - floor(${e[0]}))`,inversesqrt:e=>1===e.length&&`(1/sqrt(${e[0]}))`,mod:e=>2===e.length&&`((${e[0]}) \\mod (${e[1]}))`,atan:e=>2===e.length&&`atan2(${e[0]}, ${e[1]})`,exp2:e=>1===e.length&&`((2)^(${e[0]}))`,trunc:e=>1===e.length&&`((${e[0]}) < 0 ? (ceil(${e[0]})) : floor(${e[0]}))`,vec2:e=>`(${e.join(", ")})`,vec3:e=>`(${e.join(", ")})`,vec4:e=>`(${e.join(", ")})`,derivative:e=>e.length>=2&&`der(${e.join(", ")})`,sympy_rational:e=>2===e.length&&`((${e[0]})/(${e[1]}))`,sympy_value:e=>1===e.length&&`(${e[0]})`,sympy_eq:e=>2===e.length&&`((${e[0]}) = (${e[1]}))`,sympy_ne:e=>2===e.length&&`((${e[0]}) ≠ (${e[1]}))`,sympy_and:e=>e.length&&`(${e.map(et).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(et).join(" ∨ ")})`,sympy_not:e=>1===e.length&&`(!(${e[0]}))`,sympy_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,sympy_nand:e=>2===e.length&&`((${e[0]}) \\nand (${e[1]}))`,sympy_nor:e=>2===e.length&&`((${e[0]}) \\nor (${e[1]}))`,sympy_piecewise:e=>{const t=e.map(gt);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:bt("[]"),sympy_interval_open:bt("()"),sympy_interval_Lopen:bt("(]"),sympy_interval_Ropen:bt("[)"),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=yt(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&&yt(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&&yt(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:xt("sum"),prod:xt("prod")};function xt(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=Je(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 vt(e){e=function(e){for(let t=e.lastIndexOf("(lambda");t>=0;t=t>0?e.lastIndexOf("(lambda",t-1):-1){const n=Qe(e,t);if(n<0||"("!==e[n+1])continue;const r=Qe(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=Je(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=Ye(e,Ke("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=Ye(e,Ke(Object.keys(wt).join("|")),(e,t)=>wt[t[1]](e)||null);for(let t=(e=Ye(e,Ke("float"),(e,t,n)=>{const r=/^\s*\.is_integer\(\s*\)/.exec(n);return r&&1===e.length?[`((${e[0]}) ∈ ℤ)`,r[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,r=Qe(e,n);let i=t;if(Ve.includes(e[t-1])){let n=0;for(i=t-1;i>=0;i--)if(Ve.includes(e[i]))n++;else if(Xe.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)}) ∈ ${tt(e.slice(i,t))})${e.slice(r+1)}`)}return e}for(const e of[nt,st,lt,ct,pt,mt,ft,dt,wt,ht])Object.setPrototypeOf(e,null);const $t=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,Mt=e=>e.trim().split(/\s+/).join(String.raw`\s+`),kt=e=>new RegExp(String.raw`(?<![\w.])${Mt(e)}(?![\w.])`,"gi"),At=[["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","="]],Nt="[<>≤≥=≠≈]",Et={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(Et,null);const Ot=Object.entries({sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot","natural log":"ln","natural logarithm":"ln",arcsine:"arcsin",arccosine:"arccos",arctangent:"arctan","hyperbolic sine":"sinh","hyperbolic cosine":"cosh","hyperbolic tangent":"tanh",floor:"floor",ceiling:"ceil"}).sort((e,t)=>t[0].length-e[0].length),It=[["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","∈ ℚ"]],_t=/(?<![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;At.map(([e])=>e),It.map(([e])=>e),Ot.map(([e])=>`${e} of`);const St=ie([[" 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 ","→"],["===","=...="]]),qt=ie([...le,...function(){const e=[],t=(t,n)=>{e.push([t,n],[t+"(",n+"("])};for(const n of["sin","cos","tan","cot","csc","sec"])if(e.push(["Math."+n+"(",n+"("],["\\"+n+"(",n+"("],["\\"+n,n]),["sin","cos","tan"].includes(n))for(const e of["","h"]){const r=n+e,i="arc"+n+e;e&&(t("Math."+r,r),t("\\"+r,r));for(const n of["^-1","^{-1}","-1"])t("\\"+r+n,i),t(r+n,i),e||t("Math."+r+n,i);e||t("\\a"+r,i),t("\\arc"+r,i),t("Math.a"+r,i),t("Math.arc"+r,i)}return e}()]),zt=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=it(e)),e=function(e){return e.includes("sorted")?Ye(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&&Qe(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=ut(e=at(e=(e=(e=function(e){for(const[t,n]of Object.entries(He))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]?Qe(e,i):-1;if(s<0)continue;let o=e.slice(i+1,s);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===t?`((${o})!)`:`${t}(${o})`;e=e.slice(0,r)+a+e.slice(s+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const n=t+10-1,r=Qe(e,n),i=e.lastIndexOf("Number(",t);r<0||i<0||Qe(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(Xe.includes(e[t]))i++;else{if(Ve.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(Ve.includes(e[t]))i++;else{if(Xe.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=vt(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(!_t.test(e))return e;let t=e;const n=(e,n,r,i="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${Mt(e)}\s+(${$t})\s+(?:and|to)\s+(${$t})(?:\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+(${$t})\s+to\s+(${$t})`,"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`(${$t})\s+`;t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${$t})\s*(%|\s+percent)?\s+of\s+(${$t})`,"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+(${$t})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${$t})`,"gi"),(e,t,n,r)=>`((${t}) mod (${r}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${$t})\s+divides\s+(${$t})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,n,r)=>`((${t}) mod 2 ${"even"===r.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[e,n]of It)t=t.replace(kt(e),` ${n} `);t=t.replace(kt("is not in")," ∉ ").replace(kt("is in")," ∈ ").replace(kt("is an element of")," ∈ ");for(const[e,n]of At)t=t.replace(kt(e),` ${n} `);t=t.replace(kt("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`(${$t})\s*(${Nt})\s*(${$t})\s+(and|or)\s+(${Nt})`,"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+(${$t})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${$t})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${$t})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${$t})\s+to\s+the\s+power\s+of\s+(${$t})`,"gi"),"($1)^($2)"),t=t.replace(new RegExp(String.raw`(${$t})\s+to\s+the\s+(${Object.keys(Et).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,r)=>`(${t})^(${Et[n.toLowerCase()]??r})`),t=t.replace(new RegExp(String.raw`(${$t})\s+to\s+the\s+(${$t})(?![\w.])`,"gi"),"($1)^($2)");for(const[e,n]of Ot)t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${Mt(e)}\s+of\s+(${$t})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${$t})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${$t})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${$t})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${$t})`,"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+)${Mt(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",St],["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(;ce(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(;ce(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(ge,(e,t,n)=>`(${t}+${de[n]})`),e=e.replace(be,(e,t,n,r)=>Number(n)<Number(r)&&3!==n.length?`(${t}+${n}/${r})`:e),e.replace(ye,(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 pe;return`${t?"^":"_"}{${[...e].map(e=>(t?pe:me)[e]).join("")}}`})}(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=ve(e,n+2,"then");if(r<0)return e;const i=e.slice(n+2,r),s=ve(e,r+4,"else"),o=$e(e,s<0?r+4:s+4),a=e.slice(r+4,s<0?o:s),l=s<0?"unchanged":e.slice(s+4,o).trim();e=`${e.slice(0,n)}((${i.trim()}) ? (${a.trim()}) : (${l}))${e.slice(o)}`}return e}(e),e=function(e){for(let t=0;t<e.length;t++){const n=n=>e.slice(Math.max(0,t-n),t+1);if("t"===e[t]&&"\\text"===n(4)&&"{"===e[t+1]){let n=1,r=t+2,i="";for(;n>0&&r<e.length;)"{"===e[r]?n++:"}"===e[r]?n--:i+=e[r],r++;e=e.slice(0,t-4)+i+e.slice(r)}}return e}(e=(e=e.replace(/\(\s*\\?b?mod\s+([^()\s](?:[^()]*[^()\s])?)\s*\)/g," \\pmod{$1}")).replace(/(^|[^A-Za-z\\])lim\s+([^\s_{}]+?)\s*(->|→|\\to)\s*([^\s]+)\s+/g,"$1lim_{$2→$4} ")),e=ke(e);for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=Me(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.replace(/\s+/g,(t,n)=>{const r=e[n-1]??"",i=e[n+t.length]??"";return"Δ"===r?"":/[A-Za-z\u0370-\u03FF′]/.test(r)&&/[A-Za-z\u0370-\u03FF]/.test(i)?" ":""})}],["symbols",qt],["bar",function(e){let t=0;for(let n=e.indexOf(f,t);n>=0;n=e.indexOf(f,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&&jt(),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)+Ce(e.slice(r,t+1),"x",i)+e.slice(t+1+i),t=r}return e}(e=(e=ke(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&&ze.test(e[t-1]);let r,i=null,s=t;if(e.startsWith("frac{",t)){const n=je(e,t+4),r=n&&je(e,n[1]);i=r&&Le(n[0],r[0]),i&&(s=r[1])}else if("d"===e[t]&&!n){let[n,r]=Fe(e,t+1),o="";if(ze.test(e[r]??"")&&"/"===e[r+1]&&(o=e[r++]),"/"===e[r]&&"d"===e[r+1]&&ze.test(e[r+2]??"")){const t=e[r+2],[,a]=Fe(e,r+3);i={n:n,of:o,by:t},s=a}}if(i){if(i.of)r=Ce(i.of,i.by,i.n);else{const[t,n]=Te(e,s);if(!t)continue;r=Ce(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=Oe(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"+Ne(e.slice(t+1)):"sqrt"===r(4)&&(e=e.slice(0,t-4)+"sqrt"+Ne(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+Ae(e.slice(t));else if("t"===n)"\\int"===i(3)&&(e=e.slice(0,t-3)+_e(e.slice(t+1)));else if("m"===n)"\\binom"===i(5)&&(e=e.slice(0,t-5)+"\\binom"+qe(e.slice(t+1)));else if("d"===n&&"dd"===i(1)&&"("===e[t+2]){const n=Se(e.slice(t+1));n&&(e=e.slice(0,t-1)+"der"+n)}}return(e=e.replace(/\\(?:text|textrm|textit|mathrm|mathit|mathbf|mathsf|operatorname)\{([A-Za-z])\}/g,"$1")).replace(/\\log/g,"log")}],["bars",function(e){for(let t=e.indexOf(f);t>=0;t=e.indexOf(f)){const n=jt;e.startsWith("(der(",t+1)||n();const r=Ft(e,t+1,"(",")"),i=Ft(e,t+5,"(",")");(i<0||r!==i+1)&&n();const s=Lt(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=Ft(e,o+3,"{","}"),l<0&&n(),a=e.slice(o+4,l)):(l=o+3,a=e[l]??"");const[c,h,u]=s;a.trim()||n();const p=a.includes("=")?a:`${h}=${a}`;e=`${e.slice(0,t)}der(${c},${p}${u?`,${u}`:""})${e.slice(l+1)}`}return e}],["tidy",e=>e.replace(/ {2,}/g," ").trim()]],jt=()=>{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 Ft(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 Lt(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 Tt(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=Ze(t.size);t.set(l,i+o+i),n+=l,r=s+1}return{text:n,strings:t}}(We(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&&Ct.test(e.slice(0,s));if(Rt(e,s)||a&&"{"===e[s+2]?s+=1:o=a,!e.startsWith("{{",s)){i=s;continue}const l=Pt(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=Ze(t.size);t.set(e,r),r=e}const a=e.slice(0,s).trimEnd(),h=e.slice(l+2).trimStart();/^[\d.]/.test(r)&&(/[\d.]$/.test(a)||/^[\d.]/.test(h))&&(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 zt){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 Ct=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function Rt(e,t){let n=0;for(;"\\"===e[t-1-n];)n++;return n%2==1}function Pt(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 Zt=Object.keys(d).filter(e=>100===d[e]&&/^[a-z]{2,}$/.test(e)),Bt=["frac"],Wt=[...Object.keys(q),"pi","tau","inf","infinity","exp"],Dt="\n cost costs coast cosine cosines cosy sine sines since sincere sinus single\n tank tanks tango stand stank\n point points print prints paint paints pint pints mint hint hints lint tint saint faint joint into\n spin spine pipe pipes pine pines pick picks pink pity pie pies pilot pivot pixel pizza piano\n order orders under wonder border render older elder ladder cider rider wider bidder\n logic logo logs blog clog login slog\n model models mode modes modal modest modern module modules\n limb limbs slim lime limo limit limits climb\n maxi minute minutes mince mind mine mines\n sums sumo summit rounds floors ceils means meant sect sects secs expo kiln\n meta metal metals taxi must mute muse nut nuts\n".trim().split(/\s+/),Ut=new Set([...Wt,...Dt,"true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),Gt=/^[a-zA-ZͰ-Ͽ]$/,Ht=new Set(["f","g","h","u","v","F","G","H"]),Xt=e=>Zt.includes(e)||Bt.includes(e),Vt=[...Zt,...Bt,...Wt].sort((e,t)=>t.length-e.length),Qt=[...Zt,...Bt,"pi"].sort((e,t)=>t.length-e.length);function Jt(e,t=Vt){const n=[];let r=0;for(;r<e.length;){const i=t.find(t=>e.startsWith(t,r))??e[r];n.push(i),r+=i.length}return n}function Yt(e){if(Xt(e))return!0;const t=Jt(e,Qt);return t.length>1&&Xt(t[t.length-1])&&!Ut.has(e)}function Kt(e,{mode:t="plain",followed:n=!0}={}){if(e.includes("′")&&/^[a-zA-Z′]+$/.test(e)&&!/^.′+$/.test(e))return e.match(/[a-zA-Z]′*/g);if(!((r=e).length>0&&[...r].every(e=>Gt.test(e)))||1===e.length||Ut.has(e)||Xt(e))return[e];var r;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return en(Jt(e),n);if(e.length<=2)return[...e];const i=en(Jt(e,Qt),n),s=i.findIndex(e=>e.length>1);if(s<0)return[e];if("pi"===i[s]&&!i.some(e=>Zt.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 en(e,t){const n=e[e.length-1];return t||!Zt.includes(n)?e:[...e.slice(0,-1),...n]}const tn="§",nn=/[A-Za-zͰ-Ͽ′]/,rn=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function sn(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=e=>{r&&(rn(r)?n.push(...function(e,t,n){if((e=>Be.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 Ht.has(e)?[s+e]:[e];if(g(e))return[e];const n=Kt(e,{mode:t,followed:!0});return n.length>1?n:e.length<=2?[...e]:[s+e]}(e,n);const r=void 0!==t&&!/[+\-*/=<>),\]}|!≤≥≠]/.test(t);return Kt(e,{mode:n,followed:r})}(r,e,t)):n.push(r),r="")};for(let t=0;t<e.length;t++){const o=e[t];if(o===tn){i(o);const r=e.indexOf(tn,t+1);if(r<0)throw new Error(`An unmatched ${tn}`);const a=e.slice(t,r+1);n.push(y.includes(e[r+1])?s+a:a),t=r;continue}if(rn(r)&&/[0-9]/.test(o)&&g(r+o)){const{op:i,end:s}=on(e,t,r+o);n.push(i),r="",t=s;continue}if(nn.test(o)&&"′"!==o&&x(r)&&(n.push(r),r=""),nn.test(o)&&(""===r?"′"!==o:rn(r)))r+=o;else if(/[0-9]/.test(o)&&rn(r)&&!Yt(r))r+=o;else if(rn(r)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))r&&n.push(...an(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(g(r+o)){const{op:i,end:s}=on(e,t,r+o);n.push(i),r="",t=s;continue}if(g(o)){i(o);const{op:r,end:s}=on(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 on(e,t,n){let r=t;for(;r+1<e.length&&g(n+e[r+1]);)n+=e[r+1],r++;return"!"===n&&"_"===e[r+1]&&r++,{op:n,end:r}}function an(e,t){if(!y.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[g(t)?t:s+t]}return x(e)?[e,"*"]:g(e)||Xt(e)||x(e[0])?[e]:[s+e]}const ln=70,cn=100,hn="%mod",un=e=>y.includes(e),pn=e=>w.includes(e),mn=e=>o(e)||d[e]===cn&&"_"!==e,fn=new Set(["\\comb","\\perm","comb","perm"]),dn={frac:"/","\\binom":"\\binom"},gn=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","∈","∉","true","false"]),bn={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class yn{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(pn(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||pn(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:d.mod,run:()=>this.modulo()};if(e===hn)return{lbp:ln,run:()=>{this.next(),this.parseExpression(ln),this.emit("mod")}};if("pmod"===e)return{lbp:d.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:cn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(fn.has(e))return{lbp:cn,run:()=>{this.next(),this.parseExpression(cn),this.emit(e)}};const n=d[e];if("="===e&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!mn(e)&&"\\not"!==e&&!(e in dn)){const t=b.has(e)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:t&&!mn(e)?71:ln,run:()=>{this.parseExpression(ln),this.emit("*")}}}startsOperand(e){return void 0===e||pn(e)||"|"===e?"|"===e:e!==hn&&(!!(un(e)||mn(e)||e in dn)||!g(e))}pipe(){if(this.absDepth>0)return null;let e=0;for(let t=this.pos;t<this.tokens.length;t++)"|"===this.tokens[t]&&e++;const t="|"===this.peek(1);return e%2==0&&!t&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:d["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(d["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression(ln,!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(un(n))e++;else if(pn(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(un(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||pn(n))||un(t)&&pn(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 dn)return this.parseScript(),this.parseScript(),this.emit(dn[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(mn(e))return this.functionCall(e);if(e===hn)throw new Error("'%' is missing an operand");if(pn(e)||g(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!x(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(pn(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();pn(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(un(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(mn(e))return this.parseOperand();if(this.next(),void 0===e||pn(e)||g(e))throw new Error("Missing a sub- or superscript");this.emit(e)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const e=this.out.length;this.parseScript();const t=this.out.splice(e);this.parseExpression(d["+"],!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(d["+"],!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&&!un(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(un(e))return this.next(),this.bracket(e);this.parseExpression(ln,!0)}}function wn(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(Ht.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:x(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)g(r)||un(r)||pn(r)||"_"===r||o(r)||x(r)?n.push(r):n.push(...xn(r,t));return n}function xn(e,t){if("%"===e)return[hn];if(!e.includes("%"))return vn(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(hn),""!==e&&r.push(...vn(e,t))}),r}function vn(e,t){let n=0;for(;n<e.length&&x(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,wn(sn(i,t),t))];var i}for(const e of[dn,bn])Object.setPrototypeOf(e,null);const $n=new Set(["()","[]","{}","(]","[)"]),Mn={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(m).map(e=>[e,"*"]))},kn=new Set(["round","fixed","der"]),An=e=>o(e)||100===d[e];function Nn(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($n.has(o)){const t=i(r(o));if(!t.length&&!An(e[l+1]))throw new Error("Empty brackets");return void n.push(M(o,t))}const c=Mn[o]??o,h=a(c);if(!h){if("?"===o||"abs("===o)throw new Error(`Unmatched '${o[0]}'`);return void n.push(A(o))}let u;if(An(o)&&$n.has(e[l-1])&&n[n.length-1]?.op===e[l-1])u=n.pop().args;else{let e=h.arity===t||kn.has(c)?1:h.arity;if(n.length<e)throw new Error(`'${o}' needs ${e} operand${1===e?"":"s"}`);u=n.splice(n.length-e,e).map(e=>s(e,o))}const p=function(e,t){switch(e){case"sqrt":if(2===t.length)return M("root",t);break;case"round":if(1===t.length)return M("round",[t[0],v(0)]);break;case"sum":case"prod":{const n=t[1];if("op"===n?.type&&"symbol"===n.args[0]?.type&&(3===t.length&&"="===n.op||2===t.length&&"∈"===n.op))return M("sum"===e?"\\sumidx":"\\prodidx",t);break}case"det":if(t.length>1&&t.every(e=>"op"===e.type&&"[]"===e.op))return M("det",[M("[]",t)]);break;case"fixed":if(1===t.length)return M("fixed",[t[0],v(2)]);break;case"der":if(1===t.length)return M("der",[t[0],$("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=M("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 M("ln",[t[1]]);break;case"lim":return On(e,t),M("lim",function(e){const t=e=>"op"===e.type&&"^"===e.op&&"symbol"===e.args[1].type?En[e.args[1].value]:void 0,[n,r,i]=e;if(2===e.length&&"op"===r.type&&"→"===r.op&&t(r.args[1])){const[e,i]=r.args;return[n,e,i.args[0],$(t(i))]}return 3===e.length&&t(i)?[n,r,i.args[0],$(t(i))]:e}(t));case"\\:if":if(2===t.length||3===t.length)return M("?:",[t[0],t[1],t[2]??$("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return On(e,t),M(e,t)}(c,u);m[o]&&"*"===p.op&&(p.written=m[o]),n.push(p)}),1!==n.length)throw new Error(n.length?"Some values are not connected by an operator":"Empty expression");return s(n[0],"end")}const En={"\\+":"r","\\-":"l"};function On(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[Mn,En])Object.setPrototypeOf(e,null);const In=new RegExp(`[${Object.keys(m).join("")}]`,"g"),_n=e=>e.replace(In,"*"),Sn=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const qn=e=>/^[a-z][a-z0-9]*$/.test(e)&&g(e);function zn(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=xe(e.slice(t+13,n),"\\\\").map(e=>xe(e,"&")).filter(e=>e.join("").trim());let i=null;for(let e=r.length-1;e>=0;e--){const t=r[e][0].trim(),n=we(r[e].slice(1).join("&"));i=null!==i||n?`((${n||"true"}) ? (${t}) : ${i??"(unchanged)"})`:`(${t})`}e=e.slice(0,t)+(i??"")+e.slice(n+11)}return e}(e),e.replace(/\{\}\^\{([^{}]*)\}\s*\\mathrm\{P\}\s*_\{([^{}]*)\}/g,"\\perm($1,$2)")):e}let jn=null;function Fn(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=We(e);let i="";for(let s=0;s<r.length;s++){const o=r[s];if('"'===o||"`"===o||"'"===o){const o=De(r,s);i+=e.slice(s,o+1).replaceAll(t,n),s=o}else i+=e[s]}return i}(e,tn,"")).includes(tn))throw new Error(`The character ${tn} 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=`${tn}${r.size}${tn}`,r.set(t,e),i.set(e,t)),t};e=e.replace(Sn,(e,t)=>qn(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}}(zn(e),t.names,[...t.values??[],...s]),l=(e=>/\\[A-Za-z]/.test(e)?"latex":"plain")(o),{cleaned:c,stringMap:h,steps:u}=function(e,t={}){const n=void 0===t.blocks?jn:t.blocks;return Tt(e,{evaluate:n?e=>n(e,t.scope):void 0})}(o,{blocks:t.blocks,scope:t.scope}),p=e=>Ge(Ge(e,h),a).map(e=>"string"==typeof e?e.replaceAll("",tn):e);n.mode=l,n.cleaned=_n(p([c])[0]),n.cleanSteps=u.map(([e,t])=>[e,_n(t)]);const m=sn(c,l);n.tokens=m.map(_n);const f=p(function(e,t="plain"){return new yn(wn(e,t)).parseAll().map(e=>bn[e]??e)}(m,l));n.rawPostfix=f.map(_n);const d={},g=O(Nn(f),d);n.postfix=g,n.written=d,n.tree=E(g),Object.keys(d).length&&_(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 Ln(e,t={}){const n=Fn(e,t);if(n.error)throw new Error(`Failed to parse expression "${r=e,"string"==typeof r&&r.length>80?`${r.slice(0,77)}…`:r}": ${n.error}`);var r;return n.tree}const Tn=(e,t)=>"string"==typeof e?Ln(e,t):I(e),Cn=re({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(tr+=e/16,tr>er)throw new Error("Too much to work out")},fail:e=>{throw new Error(e)}}),Rn=e=>te(e)&&(e.length>1||e[0].length>1),Pn=e=>ne(e)&&!Rn(e),Zn=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},Bn=(e,t)=>Rn(e)&&Rn(t)?Cn.times(e,t):Rn(e)&&Pn(t)?Cn.timesVector(e,t):Pn(e)&&Rn(t)?Cn.vectorTimes(e,t):Zn((e,t)=>e*t)(e,t),Wn=(e,t)=>n=>{const r=n.length>1&&n.every(Pn)?n:n[0];if(!te(r))throw new Error(`${t}() needs a matrix`);return e(r)},Dn=(e,t)=>([n,r])=>{if(!ne(n)||!ne(r))throw new Error(`${t}() needs two lists`);return e(n,r)},Un={det:Wn(Cn.det,"det"),inv:Wn(Cn.inverse,"inv"),inverse:Wn(Cn.inverse,"inverse"),transpose:Wn(Cn.transpose,"transpose"),trace:Wn(Cn.trace,"trace"),tr:Wn(Cn.trace,"tr"),rank:Wn(Cn.rank,"rank"),rref:Wn(Cn.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 Cn.identity(e)},dot:Dn(Cn.dot,"dot"),cross:Dn(Cn.cross,"cross"),linsolve:([e,t])=>{if(!te(e)||!Array.isArray(t))throw new Error("linsolve() needs a matrix and a list");return Cn.solve(e,t)}},Gn=(e,t)=>e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args.map(e=>rr(e,t)):[rr(e,t)]),Hn={pi:Math.PI,"π":Math.PI,e:Math.E,tau:2*Math.PI,"τ":2*Math.PI,"∞":1/0,"-∞":-1/0,true:!0,false:!1},Xn=(e,t)=>t?Xn(t,e%t):Math.abs(e),Vn=(e,t)=>(e%t+t)%t,Qn=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>Qn(e,t[n])):e==t,Jn={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=>Un.det([e]),ln:Math.log,loglog:e=>Math.log(Math.log(e)),logloglog:e=>Math.log(Math.log(Math.log(e))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:e=>1/Math.sin(e),sec:e=>1/Math.cos(e),cot:e=>1/Math.tan(e),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},Yn={"+":(e,t)=>Array.isArray(e)||Array.isArray(t)?Zn((e,t)=>e+t)(e,t):e+t,"-":(e,t)=>Array.isArray(e)||Array.isArray(t)?Zn((e,t)=>e-t)(e,t):e-t,"*":Bn,"/":(e,t)=>Rn(t)?Bn(e,Cn.inverse(t)):Array.isArray(e)||Array.isArray(t)?Zn((e,t)=>e/t)(e,t):e/t,"^":(e,t)=>{if(!Rn(e))return Array.isArray(e)?Zn((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 Cn.power(e,BigInt(t))},mod:Vn,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)},"=":Qn,"===":(e,t)=>e===t,"≠":(e,t)=>!Qn(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)},Kn={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(Xn,0),"()":e=>e,"[]":e=>e,"{}":e=>e};const er=5e6;let tr=0,nr=0;function rr(e,t){if(++tr>er)throw new Error("Too much to work out");switch(e.type){case"number":return Number(e.value);case"string":return e.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(t,e.value))return t[e.value];if(Object.prototype.hasOwnProperty.call(Hn,e.value))return Hn[e.value];if(j(e.value))return Number(j(e.value));throw new Error(`No value for '${e.value}'`)}const n=Y(e);if(n)return rr(n,t);const{op:r,args:i}=e;if("?:"===r)return rr(i[0],t)?rr(i[1],t):rr(i[2],t);if("∈"===r||"∉"===r)return function(e,t){const[n,r]=e.args,i=rr(n,t);let s;if("symbol"===r.type&&ir[r.value])return s=ir[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=>rr(e,t)),o="["===r.op[0]?i>=e:i>e,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const e=rr(r,t);s=Array.isArray(e)&&e.includes(i)}return"∈"===e.op?s:!s}(e,t);if("random"===r)return Math.random();if(("\\sumidx"===r||"\\prodidx"===r)&&3===i.length){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:S(n);if(!a)throw new Error(`Can't evaluate '${r}' without an index`);const l=rr(s,t),c=rr(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 h="\\sumidx"===r?0:1;for(let e=l;e<=c;e++){const i=rr(n,{...t,[a]:e});h="\\sumidx"===r?h+i:h*i}return h}if("pmod"===r){const[e,n]=i,r=rr(n,t);if("op"===e.type&&["≡","="].includes(e.op)){const[n,i]=e.args.map(e=>rr(e,t));return(n-i)%r===0}return Vn(rr(e,t),r)}if("pmatrix"===r||"bmatrix"===r)return Gn(e,t);if("vmatrix"===r)return Cn.det(Gn(e,t));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=rr(i[0],t);if(Rn(e))return Cn.transpose(e)}const s=i.map(e=>rr(e,t));if(r.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(Un,r.slice(2)))return Un[r.slice(2)](s);if(Jn[r]&&1===s.length)return Jn[r](s[0]);if(Yn[r]&&2===s.length)return Yn[r](s[0],s[1]);if(Kn[r])return Kn[r](s);throw new Error(`Can't evaluate '${r}'`)}const ir={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":e=>Number.isInteger(e)&&e>0,"ℚ":Number.isFinite,"ℂ":e=>"number"==typeof e&&!Number.isNaN(e)};for(const e of[Hn,Jn,Yn,Kn,ir,Un])Object.setPrototypeOf(e,null);class sr extends Error{}class or extends Error{}const ar={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let lr=0;function cr(e){if(lr+=e,lr>ar.steps)throw new or("too much to work out")}const hr=(e,t)=>cr(Number(e)*(t/64)/128);let ur=0;const pr=e=>e<0n?-e:e,mr=0xFFFFFFFFFFFFn,fr=e=>0n===e?0:pr(e).toString(2).length;function dr(e,t){for(e=pr(e),t=pr(t);t;)[e,t]=[t,e%t];return e}function gr(e,t=1n){if(0n===t)throw new sr("division by zero");if(t<0n&&(e=-e,t=-t),t>mr&&(e>mr||-e>mr)){const n=Math.min(e.toString(16).length-(e<0n?1:0),t.toString(16).length)/16;if(lr+=1+n*n/2,lr>ar.steps)throw new or("too much to work out")}const n=dr(e,t)||1n;return{n:e/n,d:t/n}}const br=gr(0n),yr=gr(1n),wr=(e,t)=>gr(e.n*t.d+t.n*e.d,e.d*t.d),xr=(e,t)=>gr(e.n*t.n,e.d*t.d),vr=(e,t)=>gr(e.n*t.d,e.d*t.n),$r=e=>({n:-e.n,d:e.d}),Mr=(e,t)=>{const n=e.n*t.d-t.n*e.d;return n<0n?-1:n>0n?1:0},kr=e=>{const t=e.n/e.d;return e.n<0n&&t*e.d!==e.n?t-1n:t};function Ar(e){if(e.n<0n)return-Ar($r(e));const t=fr(e.n),n=fr(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 Nr(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 or(`'${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=wr(gr(BigInt(o||"0")),gr(i-r,(10n**BigInt(e)-1n)*10n**BigInt(n.length)))}else l=gr(BigInt(o+a||"0"),10n**BigInt(a.length));if(Math.abs(i)>ar.bits/3)throw new or("too large to calculate");return i&&(l=i>0?xr(l,gr(10n**BigInt(i))):vr(l,gr(10n**BigInt(-i)))),n<0n?$r(l):l}function Er(e,t=0,n=0,r=null){return 0n===e.n?{kind:"x",c:br,pi:0,e:0,root:null}:{kind:"x",c:e,pi:t,e:n,root:r}}const Or=(e,t=1n)=>Er(gr(BigInt(e),BigInt(t))),Ir=Er(yr,1),_r=Er(yr,0,1),Sr=e=>null!==e&&"object"==typeof e&&"x"===e.kind,qr=e=>Sr(e)&&!e.pi&&!e.e&&!e.root,zr=e=>Sr(e)?0n===e.c.n:0===e,jr=e=>qr(e)&&1n===e.c.d?e.c.n:null,Fr=(e,t)=>Object.assign(e,{group:t}),Lr=e=>({kind:"s",text:e});function Tr(e,t){return e&&t?e.n===t.n&&e.r===t.r:e===t}const Cr=(e,t)=>0===Mr(e.c,t.c)&&e.pi===t.pi&&e.e===t.e&&Tr(e.root,t.root);function Rr(e){const t=Math.max(0,fr(e)-60);return t+Math.log2(Number(e>>BigInt(t)))}function Pr(e){if("number"==typeof e)return e;if(Sr(e)){let t=Ar(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**(Rr(e)/t)}(e.root.r,e.root.n);if(!(0n===e.c.n||0!==t&&Number.isFinite(t)&&Number.isFinite(n))){const t=Rr(e.c.n<0n?-e.c.n:e.c.n)-Rr(e.c.d)+Rr(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 or("not a number")}function Zr(e,...t){if(Number.isNaN(e))throw new sr("undefined");if(!Number.isFinite(e)&&t.every(Number.isFinite))throw new or("too large to calculate");return e}const Br=e=>"boolean"==typeof e?e:Sr(e)?0n!==e.c.n:"number"==typeof e?0!==e:Boolean(e);function Wr(e){if("bigint"==typeof e)return Er(gr(e));if("number"==typeof e)return Number.isFinite(e)?Er(Number.isInteger(e)&&Math.abs(e)<=Number.MAX_SAFE_INTEGER?gr(BigInt(e)):Nr(String(e))):e;if("boolean"==typeof e)return e;if("string"==typeof e)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(e.trim())?Er(Nr(e)):Ci(Ln(e),{});if(Array.isArray(e))return!e.group&&te(e)?Fr(e.map(e=>Fr(e.map(Wr),"[]")),"[]"):Fr(e.map(Wr),e.group||"()");if(Sr(e)||"function"==typeof e)return e;throw new or(`can't use ${typeof e} as a value`)}function Dr(e){return Array.isArray(e)?e.map(Dr):e&&"s"===e.kind?e.text:"boolean"==typeof e?e:Pr(e)}function Ur(e,t){if(e<2n)return e;const n=BigInt(t);let r=1n<<BigInt(Math.ceil(fr(e)/t));for(;;){const t=((n-1n)*r+e/r**(n-1n))/n;if(t>=r)return r;r=t}}function Gr(e,t,n,r=0,i=0){if(0n===n)return Er(br);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++}lr+=o/4;const a=Ur(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=Ur(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?Er(xr(e,gr(s*o.r)),r,i):Er(xr(e,gr(s)),r,i,o)}function Hr(e,t){const n=xr(e.c,t.c);if(fr(n.n)+fr(n.d)>ar.bits)return null;const r=e.pi+t.pi,i=e.e+t.e;if(!e.root||!t.root)return Er(n,r,i,e.root||t.root);const s=$i(e.root.n,t.root.n);if(s>ar.rootIndex)return null;const o=e.root.r**BigInt(s/e.root.n)*t.root.r**BigInt(s/t.root.n);return fr(o)>4e3?null:Gr(n,s,o,r,i)}function Xr(e){if(0n===e.c.n)throw new sr("division by zero");const t=Er(vr(yr,e.c),-e.pi,-e.e);if(!e.root)return t;const{n:n,r:r}=e.root;return fr(r)*(n-1)>4e3?null:Hr(t,Gr(gr(1n,r),n,r**BigInt(n-1)))}function Vr(e,t){if(0n===t){if(0n===e.c.n)throw new sr("0^0 is undefined");return Er(yr)}if(t<0n){const n=Xr(e);return n&&Vr(n,-t)}if((fr(e.c.n)+fr(e.c.d)+(e.root?fr(e.root.r):0))*Number(t)>ar.bits||t>100000n)return null;const n=gr(e.c.n**t,e.c.d**t),r=Number(t);if(!e.root)return Er(n,e.pi*r,e.e*r);const{n:i,r:s}=e.root,o=s**(t/BigInt(i));return Gr(xr(n,gr(o)),i,s**(t%BigInt(i))||1n,e.pi*r,e.e*r)}function Qr(e,t,n){if(!qr(e)||n>1000n)return null;const r=Vr(e,t);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new sr("not a real number");o=!0,i=-i}const a=function(e,t){const n=e.n*e.d**BigInt(t-1);return fr(n)>4e3?null:Gr(gr(1n,e.d),t,n)}({n:i,d:s},Number(n));return a?o?Er($r(a.c),a.pi,a.e,a.root):a:null}function Jr(e){return t=>Array.isArray(t)?Fr(t.map(t=>Jr(e)(t)),t.group):e(t)}function Yr(e){const t=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new sr("lists of different lengths");return Fr(n.map((e,n)=>t(e,r[n])),n.group)}return i?Fr(n.map(e=>t(e,r)),n.group):s?Fr(r.map(e=>t(n,e)),r.group):e(n,r)};return t}const Kr=Yr((e,t)=>Sr(e)&&Sr(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||!Tr(e.root,t.root))return null;const n=wr(e.c,t.c);return fr(n.n)+fr(n.d)>ar.bits?null:Er(n,e.pi,e.e,e.root)}(e,t)||Zr(Pr(e)+Pr(t),Pr(e),Pr(t))),ei=Jr(e=>Sr(e)?Er($r(e.c),e.pi,e.e,e.root):-Pr(e)),ti=(e,t)=>Kr(e,ei(t)),ni=Yr((e,t)=>Sr(e)&&Sr(t)&&Hr(e,t)||Zr(Pr(e)*Pr(t),Pr(e),Pr(t))),ri=Yr((e,t)=>{if(zr(t))throw new sr("division by zero");if(Sr(e)&&Sr(t)){const n=Xr(t),r=n&&Hr(e,n);if(r)return r}return Zr(Pr(e)/Pr(t),Pr(e),Pr(t))}),ii=Yr((e,t)=>{if(Sr(e)&&qr(t)){const{n:n,d:r}=t.c,i=1n===r?Vr(e,n):Qr(e,n,r);if(i)return i}const n=Pr(e),r=Pr(t);if(0===n&&0===r)throw new sr("0^0 is undefined");if(0===n&&r<0)throw new sr("division by zero");if(n<0&&!Number.isInteger(r))throw new sr("not a real number");const i=n**r;if(0===i&&0!==n)throw new or("too small to calculate");return Zr(i,n,r)});function si(e,t){if(qr(e)&&qr(t))return Mr(e.c,t.c);if(Sr(e)&&Sr(t)&&Cr(e,t))return 0;const n=Pr(e),r=Pr(t);if(n===r)return 0;const i=Sr(e)&&Sr(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 oi(e,t){return Array.isArray(e)||Array.isArray(t)?Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>oi(e,t[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:0===si(e,t)}const ai={0:()=>Or(0),2:()=>Or(1,2),3:()=>Gr(gr(1n,2n),2,2n),4:()=>Gr(gr(1n,2n),2,3n),6:()=>Or(1)};function li(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=ai[t];return r?n<0?ei(r()):r():null}const ci=e=>li(e+6),hi=(e,t)=>Math.abs(e)<1e-15&&Math.abs(t)>1e-6?0:e;function ui(e,t){const n=function(e){if(zr(e))return 0;if(!Sr(e)||1!==e.pi||e.e||e.root)return null;const t=xr(e.c,gr(12n));return 1n!==t.d?null:Number((t.n%24n+24n)%24n)}(t);if(null!==n){const t=li(n),r=ci(n);if(t&&r)switch(e){case"sin":return t;case"cos":return r;case"tan":return ri(t,r);case"cot":return ri(r,t);case"sec":return ri(Or(1),r);case"csc":return ri(Or(1),t)}}const r=Pr(t),i=hi(Math.sin(r),r),s=hi(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 sr("undefined");return Zr(o)}function pi(e,t){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[e],r=t=>"arcsin"===e?li(t):"arccos"===e?ci(t):ci(t)&&!zr(ci(t))?ri(li(t),ci(t)):null;if(Sr(t))for(let e=n[0];e<=n[1];e++){const n=r(e);if(n&&Sr(n)&&Cr(n,t))return Er(gr(BigInt(e),12n),1)}const i=Pr(t);if("arctan"!==e&&Math.abs(i)>1)throw new sr("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[e](i)}function mi(e){if(Sr(e)){if(0n===e.c.n)throw new sr("ln 0 is undefined");if(e.c.n<0n)throw new sr("not a real number");if(1n===e.c.n&&1n===e.c.d&&!e.pi&&!e.root)return Or(e.e)}const t=Pr(e);if(t<=0)throw new sr(0===t?"ln 0 is undefined":"not a real number");return Math.log(t)}function fi(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*fi(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 di(e,t){const n=jr(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null===n)throw new sr(`${t} needs whole numbers`);return n}const gi=(e,t)=>Number(t)*fr(e)>ar.bits;const bi=Jr(e=>qr(e)?Er(gr(kr(e.c))):Wr(Math.floor(Pr(e)))),yi=Jr(e=>qr(e)?Er(gr(-kr($r(e.c)))):Wr(Math.ceil(Pr(e))));function wi(e,t){const n=Number(di(t,"round"));if(Math.abs(n)>ar.places)throw new or("too many decimal places");if(qr(e)){const t=gr(10n**BigInt(Math.abs(n))),r=n>=0?xr(e.c,t):vr(e.c,t),i=kr(wr(xr(gr(2n),gr(pr(r.n),r.d)),yr))/2n,s=gr(r.n<0n?-i:i);return Er(n>=0?vr(s,t):xr(s,t))}if(n>15)return Pr(e);const r=10**n;return 0===r?0:Math.sign(Pr(e))*Math.round(Math.abs(Pr(e))*r)/r}const xi=(e,t)=>e.toFixed(Math.min(t,100))+(t>100?"0".repeat(t-100):"");function vi(e,t){if(zr(t))throw new sr("division by zero");if(qr(e)&&qr(t))return Er(wr(e.c,$r(xr(t.c,gr(kr(vr(e.c,t.c)))))));const n=Pr(e),r=Pr(t);return Zr((n%r+r)%r)}const $i=(e,t)=>e/Mi(e,t)*t,Mi=(e,t)=>t?Mi(t,e%t):e,ki={pi:()=>Ir,"π":()=>Ir,tau:()=>Er(gr(2n),1),"τ":()=>Er(gr(2n),1),e:()=>_r,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1},Ai={abs:e=>Sr(e)?Er(gr(pr(e.c.n),e.c.d),e.pi,e.e,e.root):Math.abs(Pr(e)),floor:bi,ceil:yi,sqrt:e=>ii(e,Or(1,2)),ln:Jr(mi),loglog:Jr(e=>mi(mi(e))),logloglog:Jr(e=>mi(mi(mi(e)))),expm1:Jr(e=>zr(e)?Or(0):Math.expm1(Pr(e))),sinh:Jr(e=>zr(e)?Or(0):Math.sinh(Pr(e))),cosh:Jr(e=>zr(e)?Or(1):Math.cosh(Pr(e))),tanh:Jr(e=>zr(e)?Or(0):Math.tanh(Pr(e))),arcsinh:Jr(e=>zr(e)?Or(0):Math.asinh(Pr(e))),arccosh:Jr(e=>{const t=Pr(e);if(t<1)throw new sr("not a real number");return 1===t?Or(0):Math.acosh(t)}),arctanh:Jr(e=>{const t=Pr(e);if(Math.abs(t)>=1)throw new sr("undefined");return zr(e)?Or(0):Math.atanh(t)}),"!":Jr(function(e){const t=jr(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null!==t){if(t<0n)throw new sr("factorial of a negative number");if(t>BigInt(ar.factorial))throw new or("too large to calculate");hr(t,Number(t)*Math.log2(Number(t)+1));let e=1n;for(let n=2n;n<=t;n++)e*=n;return Er(gr(e))}const n=Pr(e);if(n<0&&Number.isInteger(n))throw new sr("factorial of a negative number");return Zr(fi(n+1),n)}),neg:ei,pm:e=>Fr([e,ei(e)],"pm"),"\\not":e=>!Br(e),det:e=>zi.det(e)};for(const e of["sin","cos","tan","csc","sec","cot"])Ai[e]=Jr(t=>ui(e,t));for(const e of["arcsin","arccos","arctan"])Ai[e]=Jr(t=>pi(e,t));const Ni=new Set(["pmatrix","bmatrix"]),Ei=e=>te(e)&&(Ni.has(e.group)||"[]"===e.group&&e.every(e=>"[]"===e.group)&&(e.length>1||e[0].length>1)),Oi=e=>ne(e)&&!Ei(e)&&"pm"!==e.group,Ii=re({add:Kr,sub:ti,mul:ni,div:ri,charge:cr,isZero:e=>Sr(e)?0n===e.c.n:Math.abs(Pr(e))<1e-12,zero:()=>Or(0),one:()=>Or(1),size:e=>Math.abs(Pr(e)),fail:e=>{throw new sr(e)},make:(e,t)=>Fr(e.map(e=>Fr(e,"[]")),t&&t.group?t.group:"bmatrix")}),_i=(e,t)=>Fr(e,t&&t.group?t.group:"[]"),Si=(e,t)=>(...n)=>{const r=n.length>1&&n.every(Oi)?Fr(n.map(e=>Fr(e,"[]")),"[]"):n[0];if(n.length>1&&r===n[0])throw new or(`${e} of more than one thing`);if(!Ei(r))throw new or(`${e} of something that isn't a matrix`);return t(r)};function qi(e,t){return Ei(e)&&Ei(t)?Ii.times(e,t):Ei(e)&&Oi(t)?_i(Ii.timesVector(e,t),t):Oi(e)&&Ei(t)?_i(Ii.vectorTimes(e,t),e):ni(e,t)}const zi={det:Si("det",Ii.det),inv:Si("inv",Ii.inverse),inverse:Si("inverse",Ii.inverse),transpose:Si("transpose",Ii.transpose),trace:Si("trace",Ii.trace),tr:Si("tr",Ii.trace),rank:Si("rank",e=>Or(Ii.rank(e))),rref:Si("rref",Ii.rref),identity:e=>{const t=jr(e);if(null===t||t<1n||t>100n)throw new or("identity(n) needs a whole number n");return Ii.identity(Number(t))},dot:(e,t)=>{if(!Oi(e)||!Oi(t))throw new or("dot of something that isn't a vector");return Ii.dot(e,t)},cross:(e,t)=>{if(!Oi(e)||!Oi(t))throw new or("cross of something that isn't a vector");return _i(Ii.cross(e,t),e)},linsolve:(e,t)=>{if(!Ei(e)||!Ei(t)&&!Oi(t))throw new or("linsolve(A, b) needs a matrix and a vector");return Ei(t)?Ii.solve(e,t):_i(Ii.solve(e,t),t)}};function ji(e,t){const n=e.args.map(e=>Fr("op"===e.type&&"[]"===e.op?e.args.map(t):[t(e)],"[]"));if(n.some(e=>e.length!==n[0].length))throw new sr("rows of different lengths");return Fr(n,"vmatrix"===e.op?"bmatrix":e.op)}const Fi={"+":Kr,"-":ti,"*":qi,"/":(e,t)=>Ei(t)?qi(e,Ii.inverse(t)):ri(e,t),"^":function(e,t){if(!Ei(e))return ii(e,t);const n=jr(t);if(null===n)throw new or("a matrix to a power that is not a whole number");return Ii.power(e,n)},"±":(e,t)=>Fr([Kr(e,t),ti(e,t)],"pm"),mod:Yr(vi),log:Yr(function(e,t){if(Sr(e)&&Cr(e,_r))return mi(t);const n=Pr(e),r=Pr(t);if(n<=0||1===n)throw new sr("not a valid base");if(r<=0)throw new sr(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(qr(e)&&qr(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=Vr(e,BigInt(r)),o=Vr(t,n);if(s&&o&&Cr(s,o))return Er(gr(BigInt(r),n))}return i}),root:Yr((e,t)=>ii(t,ri(Or(1),e))),atan2:(e,t)=>Math.atan2(Pr(e),Pr(t)),round:wi,fixed:function(e,t){const n=Number(di(t,"fixed"));if(n<0)throw new sr("fixed needs 0 or more decimal places");const r=wi(e,t);if(qr(r)){const e=r.c.n*10n**BigInt(n)/r.c.d,t=(e<0n?-e:e).toString().padStart(n+1,"0");return Lr(`${e<0n?"-":""}${t.slice(0,t.length-n)}${n?"."+t.slice(-n):""}`)}return Lr(xi(Pr(r),n))},perm:function(e,t){const n=di(e,"permutations"),r=di(t,"permutations");if(r<0n||r>n)throw new sr("undefined");if(r>BigInt(ar.terms)||gi(n,r))throw new or("too large to calculate");hr(r,Number(r)*fr(n));let i=1n;for(let e=n-r+1n;e<=n;e++)i*=e;return Er(gr(i))},comb:function(e,t){const n=di(e,"combinations");let r=di(t,"combinations");if(r<0n||r>n)throw new sr("undefined");if(n-r<r&&(r=n-r),r>BigInt(ar.terms)||gi(n,r))throw new or("too large to calculate");hr(2n*r,Number(r)*fr(n));let i=1n;for(let e=1n;e<=r;e++)i=i*(n-r+e)/e;return Er(gr(i))},"=":(e,t)=>oi(e,t),"===":(e,t)=>oi(e,t),"≠":(e,t)=>!oi(e,t),"≠=":(e,t)=>!oi(e,t),"≈":(e,t)=>Math.abs(Pr(e)-Pr(t))<=1e-9*Math.max(1,Math.abs(Pr(e)),Math.abs(Pr(t))),"<":(e,t)=>si(e,t)<0,">":(e,t)=>si(e,t)>0,"≤":(e,t)=>si(e,t)<=0,"≥":(e,t)=>si(e,t)>=0,"&":(e,t)=>Br(e)&&Br(t),"|":(e,t)=>Br(e)||Br(t),"\\xor":(e,t)=>Br(e)!==Br(t),"\\nor":(e,t)=>!(Br(e)||Br(t)),"\\nand":(e,t)=>!(Br(e)&&Br(t))},Li={sum:e=>e.reduce((e,t)=>Kr(e,t),Or(0)),prod:e=>e.reduce((e,t)=>ni(e,t),Or(1)),max:e=>e.reduce((e,t)=>si(t,e)>0?t:e),min:e=>e.reduce((e,t)=>si(t,e)<0?t:e),mean:e=>ri(Li.sum(e),Or(e.length)),gcd:e=>Er(gr(e.map(e=>di(e,"gcd")).reduce(dr)))},Ti=["∈","∉","∪","∩","pmod","random","(]","[)"];function Ci(e,t){if(++lr>ar.steps)throw new or("too much to work out");switch(e.type){case"number":return Er(Nr(e.value));case"string":return Lr(e.value.slice(1,-1));case"symbol":return Ri(e.value,t)}const n=Y(e);if(n)return Ci(n,t);const{op:r,args:i}=e,s=e=>Ci(e,t);if("?:"===r)return Br(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(e=>"op"!==e.type))return Ri(`${i[0].value}_${i[1].value}`,t);throw new or("subscript")}if("der"===r)return function(e,t){const[n,r]=e.args;if("op"===r.type&&"="===r.op){const e=Wi(r.args[0]);if(!e)throw new or("a derivative at a point names its variable: der(f, x = a)");return Di(n,e,Pr(Ci(r.args[1],t)),t)}const i=Wi(r);if(!i||!t[Pi]?.has(i))throw new or(`a derivative needs a point: der(f, ${i||"x"} = a)`);return Di(n,i,Pr(t[i]),t)}(e,t);if("int"===r)return function(e,t){const[n,r,i,s]=e,o=e=>e&&"symbol"===e.type&&/^[a-zA-Zʹ-Ͽ]$/.test(e.value);let a,l,c;if(4===e.length)[a,l,c]=[Wi(r),i,s];else{if(3!==e.length||o(r))throw new or("an integral needs limits to be calculated");[a,l,c]=[S(n)||"x",r,i]}let h=Pr(Ci(l,t)),u=Pr(Ci(c,t));if(h===u)return Or(0);let p=1;h>u&&([h,u]=[u,h],p=-1);const m=Bi(n,a,t),{value:f,error:d}=Ui(m,h,u);return Qi(p*f,d)}(i,t);if("lim"===r)return function(e,t){const[n,r,i,s]=e;let o,a,l=0;if(2===e.length&&"op"===r.type&&"→"===r.op)[o,a]=[Wi(r.args[0]),r.args[1]];else if(2===e.length)[o,a]=[S(n),r];else{if(!(e.length>=3))throw new or("a limit needs a point");[o,a]=[Wi(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 or("a limit needs a variable");const c=Ci(a,t),h=Pr(c),u=Bi(n,o,t);let p,m;if(Number.isFinite(h))if(l){({value:p,error:m}=Hi(e=>u(h+l*e*Math.max(1,Math.abs(h)))));try{const e=Ci(n,Zi(t,o,c));if(Math.abs(Pr(e)-p)<=Math.max(m,1e-6*Math.max(1,Math.abs(p))))return e}catch(e){if(!(e instanceof sr))throw e}}else{const e=Hi(e=>u(h+e*Math.max(1,Math.abs(h)))),r=Hi(e=>u(h-e*Math.max(1,Math.abs(h))));if(e.value===r.value)({value:p,error:m}=e);else{if(!(Number.isFinite(e.value)&&Number.isFinite(r.value)&&Math.abs(e.value-r.value)<=1e-6*Math.max(1,Math.abs(e.value))))throw new sr("the limit does not exist");p=(e.value+r.value)/2,m=Math.max(e.error,r.error,Math.abs(e.value-r.value))}try{const e=Ci(n,Zi(t,o,c));if(Math.abs(Pr(e)-p)<=1e-6*Math.max(1,Math.abs(p)))return e}catch(e){if(!(e instanceof sr))throw e}}else({value:p,error:m}=Hi(e=>u(Math.sign(h)/e)));return Number.isFinite(p)?Qi(p,m):p}(i,t);if("\\sumidx"===r||"\\prodidx"===r)return function(e,t,n){const[r,i,s]=t;if(t.length<3)throw new or("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=S(r)||"n";const l=di(Ci(a,n),"a sum"),c=Ci(s,n),h=e?Kr:ni;if(c===1/0){if(!e)throw new or("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 sr("undefined");i+=t}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2]&&!Vi(e,t,s))return Qi(i,0)}if(Vi(e,t,s))throw new sr("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 sr("the series diverges");if(Math.abs(o)>1e-6*Math.max(1,Math.abs(i))&&c>=.9)throw new or("the series grows too slowly to tell whether it has a sum");const h=n.slice(-7).map(e=>1/e),u=r.slice(-7),p=r.slice(-8,-1),m=(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]},f=m(h,u),d=m(n.slice(-8,-1).map(e=>1/e),p);return Qi(f,Math.abs(f-d))}(Bi(r,o,n),Number(l))}const u=di(c,"a sum");if(u-l+1n>BigInt(ar.terms))throw new or("too many terms to add one by one");let p=Or(e?0:1);for(let e=l;e<=u;e++)p=h(p,Ci(r,Zi(n,o,Er(gr(e)))));return p}("\\sumidx"===r,i,t);if(["()","[]","{}"].includes(r))return Fr(i.map(s),r);if("pmatrix"===r||"bmatrix"===r)return ji(e,s);if("vmatrix"===r)return Ii.det(ji(e,s));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=s(i[0]);if(Ei(e))return Ii.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?zr(vi(ti(n(e.args[0]),n(e.args[1])),r)):vi(n(e),r)}(i,s);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)&&Sr(i))s="ℝ"===r.value||("ℚ"===r.value?qr(i):qr(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=si(i,e),a=si(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=>oi(i,t(e)))}return"∈"===e.op?s:!s}(e,s);if(void 0!==t)return t}if(Ti.includes(r))return function(e,t){const n={};for(const[e,r]of Object.entries(t))"function"!=typeof r&&(n[e]=Dr(r));try{return Wr(function(e,t={}){0===nr&&(tr=0),nr++;try{return rr(Tn(e),t)}finally{nr--}}(e,n))}catch(e){throw new or(e.message)}}(e,t);if(r.startsWith("\\:")){const e=r.slice(2),n=Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;if("function"!=typeof n&&Object.prototype.hasOwnProperty.call(zi,e))return zi[e](...i.map(s));if("function"!=typeof n)throw new or(`no function ${r.slice(2)}`);return Wr(n(...i.map(e=>Dr(s(e)))))}if(Ai[r]&&1===i.length)return Ai[r](s(i[0]));if(Fi[r]&&2===i.length)return Fi[r](s(i[0]),s(i[1]));if(Li[r])return Li[r](i.map(s));throw new or(`can't calculate '${r}'`)}function Ri(e,t){if(Object.prototype.hasOwnProperty.call(t,e))return t[e];if(Object.prototype.hasOwnProperty.call(ki,e))return ki[e]();if(j(e))return Er(Nr(j(e)));throw new or(`no value for '${e}'`)}const Pi=Symbol("bound"),Zi=(e,t,n)=>({...e,[t]:n,[Pi]:new Set([...e[Pi]??[],t])});function Bi(e,t,n){return r=>{try{return Pr(Ci(e,Zi(n,t,r)))}catch(e){if(e instanceof sr)return NaN;throw e}}}const Wi=e=>"symbol"===e.type?e.value:null;function Di(e,t,n,r){const i=Bi(e,t,r);if(!Number.isFinite(i(n)))throw new sr("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 sr("not differentiable here");let l=.1*Math.max(1,Math.abs(n));const c=1.4,h=[[(i(n+l)-i(n-l))/(2*l)]];let u=h[0][0],p=1/0;for(let e=1;e<12;e++){l/=c,h[e]=[(i(n+l)-i(n-l))/(2*l)];let t=c*c;for(let n=1;n<=e;n++){h[e][n]=(h[e][n-1]*t-h[e-1][n-1])/(t-1),t*=c*c;const r=Math.max(Math.abs(h[e][n]-h[e][n-1]),Math.abs(h[e][n]-h[e-1][n-1]));r<=p&&(p=r,u=h[e][n])}if(Math.abs(h[e][e]-h[e-1][e-1])>=2*p)break}if(!Number.isFinite(u))throw new sr("not differentiable here");return Qi(u,p)}function Ui(e,t,n){if(t===-1/0&&n===1/0){const t=Ui(e,-1/0,0),n=Ui(e,0,1/0);return{value:t.value+n.value,error:t.error+n.error}}return n===1/0?Gi(n=>e(t+n/(1-n))/((1-n)*(1-n)),0,1):t===-1/0?Gi(t=>e(n-t/(1-t))/((1-t)*(1-t)),0,1):Gi(e,t,n)}function Gi(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 h=s=>{const o=Math.PI/2*Math.sinh(Math.abs(s)),a=Math.exp(-2*o),l=2*r*a/(1+a),h=r*(Math.PI/2)*Math.cosh(s)*(4*a)/((1+a)*(1+a));if(0===l||0===h)return 0;const u=s>0?n-l:t+l;if(0!==s&&(u<=t||u>=n))return 0;const p=e(0===s?(t+n)/2:u);if(!Number.isFinite(p)){if(l<1e-6*r)return 0;throw new sr("the integral diverges")}return Math.abs(s)>i-.5&&(c=Math.max(c,Math.abs(h*p))),h*p};o=h(0);for(let e=s;e<=i;e+=s)o+=h(e)+h(-e);a=s*o;for(let e=1;e<=8;e++){s/=2;for(let e=s;e<=i;e+=2*s)o+=h(e)+h(-e);l=a,a=s*o;const t=Math.max(1,Math.abs(a));if(c>1e-8*t)throw new sr("the integral diverges");if(e>=3&&Math.abs(a-l)<=1e-13*t)break}const u=Math.abs(a-l);if(!Number.isFinite(a)||u>1e-6*Math.max(1,Math.abs(a)))throw new sr("the integral does not converge");return{value:a,error:u}}(e,t,n)}catch(e){if(!(e instanceof sr)||"the integral does not converge"!==e.message||r>=10)throw e}const i=(t+n)/2,s=Gi(e,t,i,r+1),o=Gi(e,i,n,r+1);return{value:s.value+o.value,error:s.error+o.error}}function Hi(e){const t=Xi(e),n=Xi(t=>e(.7548776662466927*t));if(t.value===n.value)return t;if(!Number.isFinite(t.value)||!Number.isFinite(n.value))throw new sr("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 sr("the limit could not be found");if(Math.abs(t.value-n.value)<=i)return t;throw new sr("the limit does not exist")}function Xi(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 sr("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],h=Math.abs(c-n[n.length-2]);if(!s||s.error>Math.max(h,1e-6*Math.max(1,Math.abs(c)))){if(h<=1e-6*Math.max(1,Math.abs(c)))return{value:c,error:10*h};throw new sr("the limit could not be found")}return s}function Vi(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 Qi(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 Or(0);if(Math.abs(e)<1e-10)return e;const r=[[Or(1),1e3],[Ir,100],[Er(yr,2),100],[_r,100],...[2n,3n,5n,6n,7n].map(e=>[Er(yr,0,0,{n:2,r:e}),100])];for(const[t,i]of r){const r=e/Pr(t),s=Ji(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*Pr(t)<=n)return Hr(Er(s),t)}return e}function Ji(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?gr(BigInt(r),BigInt(s)):null}function Yi(e,t){if("boolean"==typeof e)return String(e);if(e&&"s"===e.kind)return JSON.stringify(e.text);if(Array.isArray(e)){if("pm"===e.group&&2===e.length&&oi(e[1],ei(e[0])))return`±${Ki(e[0],t)}`;if(Ni.has(e.group)&&te(e))return`${e.group}(${e.map(e=>`[${e.map(e=>Yi(e,t)).join(", ")}]`).join(", ")})`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[e.group]||"{}";return n+e.map(e=>Yi(e,t)).join(", ")+r}return"number"==typeof e?es(e,t):t.decimal||null!==t.places?function(e,t){if(qr(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=pr(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=t.maxDigits)return(r?"-":"")+ts(o)}}return qr(e)&&null!==t.places?Yi(wi(e,Or(t.places)),{...t,places:null,decimal:!0}):es(Pr(e),t)}(e,t):function(e,t){const{c:n}=e,r=pr(n.n);if(r.toString().length>t.maxDigits||n.d.toString().length>t.maxDigits)return function(e,t){if(!qr(e))return es(Pr(e),t);if(1n!==e.c.d){const n=Pr(e);if(0!==n&&Number.isFinite(n))return es(n,t);const r=pr(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=ts(`${a[0]}.${a.slice(1,t.digits)}`);return`${e.c.n<0n?"-":""}${c}*10^(${l})`}const n=pr(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=ts(`${i[0]}.${i.slice(1,t.digits)}`);return`${e.c.n<0n?"-":""}${o}*10^(${s})`}(e,t);const i=(e,t)=>1===t?e:`${e}^${t}`,s=[],o=[];e.pi>0&&s.push(i("pi",e.pi));e.pi<0&&o.push(i("pi",-e.pi));e.e>0&&s.push(i("e",e.e));e.e<0&&o.push(i("e",-e.e));e.root&&s.push(2===e.root.n?`sqrt(${e.root.r})`:`root(${e.root.n}, ${e.root.r})`);1n===r&&s.length||s.unshift(r.toString());1n!==n.d&&o.unshift(n.d.toString());const a=e=>e.length>1?`(${e.join("*")})`:e[0],l=o.length?`${a(s)}/${a(o)}`:s.join("*");return(n.n<0n?"-":"")+l}(e,t)}const Ki=(e,t)=>{const n=Yi(e,t);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function es(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 xi(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`${ts(n)}*10^(${Number(r)})`}return String(Number(e.toPrecision(t.digits)))}const ts=e=>e.includes(".")?e.replace(/\.?0+$/,""):e;function ns(e,t={},n={}){0===ur&&(lr=0);const r="string"==typeof e?Ln(e):I(e),i={};for(const[e,n]of Object.entries(t))i[e]=Wr(n);let s;ur++;try{s=Ci(r,i)}finally{ur--}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<=ar.places))throw new or(`places is a whole number from 0 to ${ar.places}`);const a=e=>Array.isArray(e)?e.every(a):"number"!=typeof e;return{value:Dr(s),text:Yi(s,o),exact:a(s)}}function rs(e,t={}){let n=e.trim();const r={},i=/^(~|≈)\s*(\d+)?/.exec(n);i&&(r.decimal=!0,void 0!==i[2]&&(r.places=Number(i[2])),n=n.slice(i[0].length)),/\d\.\d|\.\d/.test(n)&&(r.decimal=!0);try{const{text:e}=ns(n,t,r);return e.startsWith('"')||/^\d+(\.\d+)?$/.test(e)?e:`(${e})`}catch(e){if(e instanceof sr)return'"undefined"';if(e instanceof or)return`(${n})`;throw e}}jn=rs;for(const e of[ar,ai,ki,Ai,Fi,Li])Object.setPrototypeOf(e,null);Object.setPrototypeOf(zi,null);const is=e=>"op"===e.type&&o(e.op)&&["vec","hat"].includes(X(e.op)),ss={plus:"plus",minus:"minus",times:"times",over:"over",negative:"negative",plusOrMinus:"plus or minus",quantity:"the quantity",of:"of",and:"and",or:"or",not:"not",xor:"exclusive or",nand:"nand",nor:"nor",squared:"squared",cubed:"cubed",toThe:"to the",toThePowerOf:"to the power of",power:"power",sub:"sub",factorial:"factorial",prime:"prime",doublePrime:"double prime",triplePrime:"triple prime",inverse:"inverse",mod:"mod",percent:"percent",degrees:"degrees",dot:"dot",cross:"cross",vector:"vector",hat:"hat",at:"at",equals:"equals",notEqual:"is not equal to",lessThan:"is less than",greaterThan:"is greater than",lessOrEqual:"is less than or equal to",greaterOrEqual:"is greater than or equal to",approx:"is approximately",congruent:"is congruent to",approaches:"approaches",tendsTo:"approaches",isIn:"is in",isNotIn:"is not in",union:"union",intersect:"intersect",squareRoot:"the square root of",cubeRoot:"the cube root of",nthRoot:e=>`the ${e} root of`,absoluteValue:"the absolute value of",floor:"the floor of",ceiling:"the ceiling of",logBase:"log base",naturalLog:"the natural log of",choose:"choose",permute:"permute",derivative:"the derivative",secondDerivative:"the second derivative",nthDerivative:e=>`the ${e} derivative`,withRespectTo:"with respect to",d:"d",integralOf:"the integral of",integralFrom:"the integral from",to:"to",limitAs:"the limit as",fromTheRight:"from the right",fromTheLeft:"from the left",sumFrom:"the sum from",sumOver:"the sum over",sumOf:"the sum of",productFrom:"the product from",productOver:"the product over",productOf:"the product of",matrix:(e,t)=>`the ${e} by ${t} matrix`,row:e=>`row ${e}`,determinantOf:"the determinant of",theSet:"the set",theList:"the list",openInterval:"the open interval from",closedInterval:"the closed interval from",halfOpenInterval:"the half-open interval from",comma:",",if:"if",then:"then",otherwise:"otherwise",infinity:"infinity",pi:"pi",e:"e",delta:"delta",randomNumber:"a random number",rounded:"rounded to",decimalPlaces:"decimal places",nearestWholeNumber:"the nearest whole number",writtenTo:"written to",asWholeNumber:"written as a whole number",reals:"the real numbers",integers:"the integers",naturals:"the natural numbers",rationals:"the rational numbers",complexes:"the complex numbers",repeating:"repeating",eToThe:"e to the",endQuantity:"end quantity",endFraction:"end fraction",endRoot:"end root",endExponent:"end exponent",endSub:"end sub",endAbsoluteValue:"end absolute value",endFloor:"end floor",endCeiling:"end ceiling",endLimit:"end limit",endSum:"end sum",endMatrix:"end matrix",endProduct:"end product",endDerivative:"end derivative",half:"half",halves:"halves",ordinals:["","","half","third","quarter","fifth","sixth","seventh","eighth","ninth","tenth"],numerators:["","one","two","three","four","five","six","seven","eight","nine"],powers:["","first","squared","cubed","fourth","fifth","sixth","seventh","eighth","ninth","tenth"]},os={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"},as=Object.fromEntries(Object.entries(q).map(([e,t])=>[t,e]));function ls(e,t={}){return cs(function(e,t={}){return function(e,t,n){const r=new ps({...ss,...t.words},{...os,...t.names},t.say||{},n);return function(e){let t=e.length;for(;t>0&&(e[t-1].close||!e[t-1].text.replace(/,/g,"").trim());)t--;const n=[];for(const{text:r,id:i}of e.slice(0,t)){const e=r.trim();if(!e)continue;const t=e.startsWith(","),s=t?e.slice(1).trim():e;t&&n.length&&!n[n.length-1].text.endsWith(",")&&(n[n.length-1].text+=","),s&&n.push({text:s,id:i})}n.length&&(n[n.length-1].text=n[n.length-1].text.replace(/,$/,""));return n}(r.speak(e))}(e,t,!0)}(e,t))}function cs(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const hs={"=":"equals","===":"equals","≠":"notEqual","≠=":"notEqual","<":"lessThan",">":"greaterThan","≤":"lessOrEqual","≥":"greaterOrEqual","≈":"approx","≡":"congruent","→":"tendsTo","∈":"isIn","∉":"isNotIn","∪":"union","∩":"intersect","±":"plusOrMinus","&":"and","|":"or","\\xor":"xor","\\nand":"nand","\\nor":"nor"},us={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class ps{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=>cs(this.speak(e))):[e.value],e,e=>cs(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(us[e])return t[us[e]];if(as[e])return as[e].toLowerCase();if(/^Δ.+$/.test(e))return`${t.delta} ${this.symbol(e.slice(1))}`;const n=/′+$/.exec(e);return n?`${this.symbol(e.slice(0,-n[0].length))} ${this.primes(n[0].length)}`:e.endsWith("⁻¹")?`${this.symbol(e.slice(0,-2))} ${t.inverse}`:e}primes(e){const t=this.w;return[t.prime,t.doublePrime,t.triplePrime][e-1]??`${e} ${t.prime}`}isCompound(e){if("op"!==e.type)return!1;if("sum"===e.op||"?:"===e.op)return!0;const t=c(e.op);return void 0!==t&&t<=50&&!a(e.op).group}quantity(e,t="endQuantity"){return this.isCompound(e)?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}grouped(e,t,n){return this.isCompound(e)||this.audio&&n?[this.seg(e,this.w.quantity),...this.speak(e),...this.closer(e,t)]:this.speak(e)}closer(e,t){const n=this.seg(e,this.w.comma);return this.audio&&t?[n,{text:this.w[t],id:e.id,close:!0},n]:[n]}contents(e,t){return this.audio&&this.isCompound(e)?this.quantity(e,t):[...this.speak(e),...this.pauseAfter(e)]}argument(e){return this.quantity(e)}operation(e){const{op:t,args:n}=e,[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(hs[t])return[...this.speak(r),a(s[hs[t]]),...this.speak(i)];if(o(t)){if(1===n.length&&"symbol"===r.type&&"vec"===X(t))return[a(s.vector),...this.speak(r)];if(1===n.length&&"symbol"===r.type&&"hat"===X(t))return[...this.speak(r),a(s.hat)];const e=this.symbol(X(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 F(i)?[...this.leftSide(r),a(s.minus),...this.quantityIfSum(i.args[1])]:[...this.leftSide(r),a(s.plus),...this.speak(i)];case"-":return F(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):cs(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:`${cs(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 ee(e)?this.matrix(e):2===n.length?[a(s.closedInterval),...this.speak(r),a(s.to),...this.speak(i)]:[a(s.theList),...l()];case"(]":case"[)":return[a(s.halfOpenInterval),...this.speak(r),a(s.to),...this.speak(i)];case"{}":return[a(s.theSet),...l()];case"der":return this.derivative(e);case"int":return this.integral(e);case"lim":return this.limit(e);case"\\sumidx":return this.bigOperator(e,s.sumFrom,s.sumOver,s.sumOf,"endSum");case"\\prodidx":return this.bigOperator(e,s.productFrom,s.productOver,s.productOf,"endProduct")}throw new Error(`No speech for '${t}'`)}matrix(e){const t=this.w,n=ee(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(F(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(is))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)&&!q[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)&&!F(e);return[...this.grouped(t,null,s(t,"/")),...this.isCall(t)?[i(r.comma)]:[],i(r.over),...this.grouped(n,"endFraction",s(n,"/"))]}power(e){const[t,n]=e.args,r=this.w,i=t=>this.seg(e,t),s=this.isCompound(t)||this.isCall(t)||"number"===t.type&&t.value.startsWith("-")||"op"===t.type&&"/"===t.op||this.audio&&"op"===t.type&&("^"===t.op||"neg"===t.op||F(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}=V(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(S(n)||"x")];let h=[];4===t.length?h=[i,s]:3===t.length?h=l?[i]:[r,i]:2!==t.length||l||(h=[r]);return[...2===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.to),...this.speak(h[1]),a(o.of)]:1===h.length?[a(o.integralFrom),...this.speak(h[0]),a(o.of)]:[a(o.integralOf)],...this.speak(n),a(`${o.comma} ${o.d}`),...c]}limit(e){const{args:t}=e,[n,r,i,s]=t,o=this.w,a=t=>this.seg(e,t);let l;if(t.length>=3){if(l=[...this.speak(r),a(o.approaches),...this.speak(i)],4===t.length){const e=String(s.value??"").toLowerCase().startsWith("r");l.push(a(e?o.fromTheRight:o.fromTheLeft))}}else if(2===t.length&&"op"===r.type&&"→"===r.op)l=[...this.speak(r.args[0]),a(o.approaches),...this.speak(r.args[1])];else{if(2!==t.length)return[a(`${o.limitAs.replace(/ as$/,"")} ${o.of}`),...this.speak(n)];{const e=S(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,h=t=>this.seg(e,t);let u;return u=3===s.length?[h(t),...this.speak(a),h(c.to),...this.speak(l),h(c.of)]:2===s.length?[h(n),...this.speak(a),h(c.of)]:[h(r)],[...u,...this.contents(o,i)]}}for(const e of[ss,os,hs,us,as])Object.setPrototypeOf(e,null);function ms(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":ls(Tn(e),t)}const fs={"(":{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 ds(e,t,n=""){const r=fs[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 gs=.8,bs=.2,ys=.25,ws=.7,xs="−",vs={"+":"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"},$s={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓"},Ms={"±":"±","∪":"∪","∩":"∩",mod:"mod"},ks=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],As={arcsin:"sin",arccos:"cos",arctan:"tan",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},Ns=[...ks,...Object.keys(As),"ln","det"],Es={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},Os={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},Is=["int","lim","\\sumidx","\\prodidx"],_s={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},Ss={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},qs=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,zs=e=>"symbol"===e?.type&&qs.test(q[e.value]??e.value),js=["boxed","overline","bar","underline","cancel",...Object.keys(Ss)],Fs={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},Ls=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),Ts=e=>+e.toFixed(3)+"em",Cs=(e,t=gs,n=bs)=>({html:e,h:t,d:n});function Rs(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(gs,...t.map(e=>e.h)),d:Math.max(bs,...t.map(e=>e.d))}}function Ps(e,t={}){const n=new Zs({...Fs,...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):ms(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="${Ls(o)}"`}>${a}${s}</span>`,h:r.h,d:r.d}}class Zs{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=Cs(this.el(e,Ls(t)));return n.leaf={kind:e,content:Ls(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="${Ls(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}="${Ls(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?[Ls(i.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${s?` style="${Ls(s)}"`:""}${r}>${a}</span>`,h:n.h,d:n.d}}render(e,t){return"number"===e.type?this.number(e):"string"===e.type?this.wrap(e,["text"],this.text("text",e.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===e.type?this.wrap(e,["symbol"],this.symbol(e.value)):this.operation(e,t)}number(e){return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,xs)))}symbol(e){return q[e]&&(e=q[e]),_s[e]?this.text("ord",_s[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)?Cs(this.el("var",Ls(e[0]))+this.el("prime",Ls(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?Cs(this.el("ord","Δ")+this.el("var",e[1])):e.endsWith("⁻¹")?this.script(this.symbol(e.slice(0,-2)),this.text("num","−1"),{level:0}):/^\\[A-Za-z]+$/.test(e)?this.text("name",e.slice(1)):/^[A-Za-z]{2,}$/.test(e)?this.text("name",e):this.text("ord",e)}operation(e,t){const{op:n,args:r}=e,[i,s]=r,a=(e,n={})=>this.render(e,{...t,...n,forceParens:n.forceParens||!1,before:n.before||!1,leftFactor:!1}),l=vs[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),h=t=>this.wrap(e,["op",`op-${l}`],t),u=(t,n)=>C(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if(Ns.includes(n)||"log"===n)return h(this.named(e,t));if(Es[n])return h(Rs(this.word(Es[n]),this.fence(this.list(r,t))));if(o(n))return h(this.custom(e,t));const p=ee(e);if(p)return h(this.matrix(e,p,t));if(Os[n])return h(this.fence(this.list(r,t),...Os[n]));if(("|"===n||"&"===n)&&r.length>=2&&r.every(Ds)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===n?a(e):this.fence(a(e));return h(Rs(r.map((t,r)=>r?[this.text("conj","|"===n?"or":"and"),e(t)]:[e(t)]).flat()))}if($s[n]&&2===r.length)return h(Rs(u(i,"left"),this.rel($s[n]),u(s,"right")));if(Ms[n]&&2===r.length)return h(Rs(u(i,"left"),this.bin(Ms[n]),u(s,"right")));switch(n){case"+":if(F(s)){const e=s.args[1],t=C({op:"-"},e,"right")?this.fence(a(e)):a(e);return h(Rs(u(i,"left"),this.bin(xs),this.wrap(s,["op","op-mul"],t)))}return"number"===s.type&&s.value.startsWith("-")?h(Rs(u(i,"left"),this.bin(xs),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):h(Rs(u(i,"left"),this.bin("+"),this.signed(s,u(s,"right"))));case"-":return h(Rs(u(i,"left"),this.bin(xs),this.signed(s,u(s,"right"))));case"*":return h(this.product(e,t));case"/":return h(this.fraction(e,t));case"^":return h(this.power(e,t));case"_":{const e=L(i)&&c(L(i))<100;return h(this.script(e?this.fence(a(i)):a(i,{forceParens:!0}),null,t,a(s,{level:t.level+1})))}case"neg":return h(Rs(this.text("sign",xs),R(n,i)?this.fence(a(i)):a(i,{before:t.before})));case"pm":return h(Rs(this.text("sign","±"),R(n,i)?this.fence(a(i)):a(i)));case"!":return h(Rs(R(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return h(Rs(this.text("sign","¬"),R(n,i)?this.fence(a(i)):a(i)));case"pmod":return h(Rs(a(i),this.fence(Rs(this.word("mod"),this.text("space",""),a(s)))));case"sqrt":return h(this.radical(a(i)));case"root":return h(this.radical(a(s),this.render(i,{level:t.level+2})));case"abs":return h(this.fence(a(i),"|","|"));case"floor":return h(this.fence(a(i),"⌊","⌋"));case"ceil":return h(this.fence(a(i),"⌈","⌉"));case"loglog":return h(Rs(this.word("ln"),this.fence(Rs(this.word("ln"),this.fence(a(i))))));case"logloglog":return h(Rs(this.word("ln"),this.fence(Rs(this.word("ln"),this.fence(Rs(this.word("ln"),this.fence(a(i))))))));case"perm":return h(this.script(this.script(Cs(""),this.render(i,{level:t.level+1}),t),null,t,this.render(s,{level:t.level+1}),this.word("P")));case"comb":return h(this.fence(this.stack(a(i),a(s),!1)));case"?:":return h(this.o.cases?this.cases(e,t):Rs(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":case"prod":{const e={op:"sum"===n?"+":"*"},t=(t,n)=>C(e,t,n?"right":"left")?this.fence(a(t)):a(t);return h(Rs(r.map((e,r)=>r?[this.bin("sum"===n?"+":"·"),t(e,r)]:[t(e,r)]).flat()))}case"der":return h(this.derivative(e,t));case"int":return h(this.integral(r,t));case"lim":return h(this.limit(r,t));case"\\sumidx":return h(this.bigOperator("sum",r,t));case"\\prodidx":return h(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 Rs(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(F(e))return Rs(this.text("sign",xs),R("neg",r)?this.fence(this.render(r,t)):this.render(r,t));const i=function(e){const[t,n]=e.args;return{left:C(e,t,"left")&&"/"!==t.op,right:C(e,n,"right")&&"/"!==n.op}}(e);Is.includes(n.op)&&(i.left=!0);const s=!e.written&&P(n,r,i),a=function(e){for(;"op"===e.type;){if(Ns.includes(e.op)||"log"===e.op||Es[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 Rs(l,s?Cs(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=As[r]&&"power"===this.o.inverseTrig?this.script(this.word(As[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&&Bs(s),l=this.render(s,{...t,forceParens:!1,before:!1});return Rs(o,a?Rs(Cs(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=X(e.op),r=e.args;if(js.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],t),r[0]);return Rs(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),Cs(this.el("callgap","")),this.fence(this.list(r,t)))}decorate(e,t,n){switch(e){case"boxed":return Cs(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return Cs(this.el("cancel",t.html+ds("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return Cs(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return Cs(this.el("over"+(zs(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const r=zs(n);return Cs(this.el("accent"+(r?" accent-low":""),this.el(`accent-mark accent-${e}`,Ss[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[n,r]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&Bs(n,!0)&&Bs(r,!0)){const e={...t,leftFactor:!1},i=(t,n)=>"op"!==t.type||Bs(t)&&(!n||"*"!==t.op||F(t))?this.render(t,e):this.fence(this.render(t,e)),s=Rs("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:${Ts(r)}`),s=n?.06:0,o=ys+s/2+.1+Math.max(bs,r*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(e))+this.el("denom",i(t)),`vertical-align:${Ts(o)}`);return Cs(a,o+Math.max(gs,r*e.h),Math.max(gs,r*t.h)+Math.max(bs,r*t.d)+.1+s/2-ys)}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&&ks.includes(n.op)&&Gs(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=C(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||Ns.includes(n.op)||Is.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:ws,o=i?Rs(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:${Ts(s)}`);if(t&&!r)return Cs(e.html+this.el("sup",t.html,`font-size:${Ts(s)};vertical-align:${Ts(a/s)}`),Math.max(o.h,a+s*t.h),Math.max(o.d,s*t.d-a));if(r&&!t)return Cs(o.html+this.el("sub",r.html,`font-size:${Ts(s)};vertical-align:${Ts(-l/s)}`),Math.max(o.h,s*r.h-l),Math.max(o.d,l+s*r.d));const h=a+s*t.h,u=l+s*r.d,p=this.el("subsup",c(t)+c(r),`vertical-align:${Ts(a)};height:${Ts(h+u)}`);return Cs(o.html+p,Math.max(o.h,h),Math.max(o.d,u))}radical(e,t=null){const n=Math.max(e.h,gs)+.1+.06,r=Math.max(e.d,bs),i=n+r,s=ds("sqrt",`${this.p}-hook`,`height:${Ts(i)};width:${Ts(.5+.06*(i-1))};vertical-align:${Ts(-r)}`);let o="";if(t){const e=.8*ws;o=this.el("rootindex",t.html,`font-size:${Ts(e)};vertical-align:${Ts((.55*i-r)/e)}`)}return Cs(this.el("sqrt",o+s+this.el("radicand",e.html)),n,r)}fence(e,t="(",n=")"){const r=Math.max(e.h,gs)+Math.max(e.d,bs),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:ds(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${Ts(s)}`),w:s+.1}}const s={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${s} delim-${t}`,""),w:"|"===e?.18:.3}},a=o(t,"l"),l=o(n,"r"),c=`padding:${Ts(s)} ${Ts(l.w)} ${Ts(s)} ${Ts(a.w)}`,h=Cs(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,gs)+s,Math.max(e.d,bs)+s);return h.fenced=!0,h}derivative(e,t){const n=this.leibniz(e,t),{by:r,at:i}=V(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}=V(e),o={...t,level:t.level+1},a=()=>this.text("d","d"),l=()=>n>1?this.render({type:"number",value:String(n)},o):null,h={...t,inFraction:!0},u=Rs(a(),l()?this.script(this.render(i,h),l(),h):this.render(i,h)),p=e=>Rs(l()?this.script(a(),l(),h):a(),e||[]),m=t.level>0||t.inFraction||!this.o.display?.8:1;if(s)return this.stack(p(this.render(r,h)),u,!0,m);const f=L(r)&&c(L(r))<100,[d,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=f?this.fence(this.render(r,t),d,g):this.render(r,t);return Rs(this.stack(p(),u,!0,m),b)}integral(e,t){const[n,r,i,s]=e,o=e=>this.render(e,t),a=e=>e?this.render(e,{...t,level:t.level+1}):null,l=()=>this.text("var",S(n)||"x");let c,h=null,u=null;switch(e.length){case 1:c=l();break;case 2:H(r)?c=o(r):(c=l(),h=a(r));break;case 3:H(r)?(c=o(r),h=a(i)):(c=l(),h=a(r),u=a(i));break;default:c=o(r),h=a(i),u=a(s)}const p=o(n),m=Cs(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Rs(this.bigSign("int",p,h,u,t),p,m)}bigSign(e,t,n,r,i){const s=!this.o.display||i.level>0,o=Math.max(s?.6:.95,Math.max(t.h-ys,t.d+ys)+.12),a=ds(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${Ts(2*o)};width:${Ts(s?.38:.5)};vertical-align:${Ts(ys-o)}`);if(!n&&!r)return Cs(a,ys+o,o-ys);const l=ws,c=r||Cs(""),h=n||Cs(""),u=ys+o-l*c.h;h.d;const p=this.el("limits",this.el("script",c.html,`font-size:${Ts(l)}`)+this.el("script lower",h.html,`font-size:${Ts(l)}`),`vertical-align:${Ts(u)};height:${Ts(2*o)}`);return Cs(a+p,ys+o,o-ys)}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 Rs(this.word("lim"),Cs(this.el("fnspace","")),this.body(n,t));case 2:{const e=S(n),t="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=e&&t?Rs(this.text("var",e),l(),a(r)):a(r);break}case 3:c=Rs(a(r),l(),a(i));break;default:{const e=z(s).toLowerCase().startsWith("r")?"+":xs;c=Rs(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",e)),o))}}return Rs(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):Cs(this.el("under",e.html+this.el("script",t.html,`font-size:${Ts(.7)}`)),e.h,Math.max(e.d,bs)+.05+.7*(t.h+t.d))}body(e,t){const n=L(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=ds(e,`${this.p}-bigsign`,`height:${Ts(2*t)};width:${Ts(.8)};vertical-align:${Ts(ys-t)}`);return Rs(this.script(Cs(r,ys+t,t-ys),l,n,a),c)}const h=.68,u=ws,p=ds(e,`${this.p}-bigsign`,`height:${Ts(1.36)};width:${Ts("sum"===e?1:1.05)}`),m=l?1.01+u*l.d:ys-h,f=e=>this.el("script",e.html,`font-size:${Ts(u)}`),d=this.el("bigop",(l?f(l):"")+p+(a?f(a):""),`vertical-align:${Ts(m)}`);return Rs(Cs(d,.93+(l?.08+u*(l.h+l.d):0),h-ys+(a?.08+u*(a.h+a.d):0)),c)}matrix(e,t,n){const r=t.map(e=>e.map(e=>this.render(e,n))),i=r.map(e=>({h:Math.max(gs,...e.map(e=>e.h)),d:Math.max(bs,...e.map(e=>e.d))})),s=i.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=ys+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"],Cs(r)).html:r}).join(""),l=t[0].length,c=Cs(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${Ts(o)}`),ys+s/2,s/2-ys),[h,u]=K[e.op]??["[","]"];return this.fence(c,h,u)}cases(e,t){const n=[];let r=e;for(;"op"===r.type&&"?:"===r.op;)n.push([this.render(r.args[1],t),Rs(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=ys+s/2-i[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=Cs(this.el("cases",a,`vertical-align:${Ts(o)}`),ys+s/2,s/2-ys);return this.fence(l,"{","")}}function Bs(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||ee(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!F(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Us(e)||"*"===e.op&&Bs(e,t)):Bs(e.args[0],!0)&&("neg"===e.op||Bs(e.args[1],!0)))}const Ws=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],Ds=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&Ws.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(Ds)),Us=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(q[e.value])),Gs=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[vs,$s,Ms,As,Es,Os,_s,Ss])Object.setPrototypeOf(e,null);const Hs=e=>O(e).join(" ");function Xs(e,t){const n=new Set;Vs(e,t,n);const r=[];return _(e,e=>{n.has(e)&&r.push(e)}),r}function Vs(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>Vs(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const r=Hs(Ln(t));return void _(e,e=>{Hs(e)===r&&n.add(e)})}if(t.path){const r=function(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}(e,t.path);return void(r&&n.add(r))}if(t.type){const r=Hs(t);_(e,e=>{e!==t&&Hs(e)!==r||n.add(e)})}}else _(e,(e,r)=>{t(e,r)&&n.add(e)});else _(e,e=>{e.id===t&&n.add(e)})}function Qs(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 Js(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Ln(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return E(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return _(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),Qs(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Ys(e,t={}){const n=Js(e,t);return Ps(n,function(e,t){const{colors:n,highlight:r,scope:i,blocks:s,...o}=t,a=new Map;for(const[t,r]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(Ks(r))for(const n of Xs(e,t))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:Xs(e,r));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}(n,t)).html}function Ks(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var eo='/*\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 to=eo;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=eo,document.head.append(e)}return e.CSS=to,e.DEFAULTS=Fs,e.calculate=ns,e.calculateBlock=rs,e.layout=Ps,e.numberTree=Qs,e.select=Xs,e.toHTML=(e,t={})=>Ys(e,{...t,blocks:t.blocks??rs}),e.treeOf=(e,t={})=>Js(e,{...t,blocks:t.blocks??rs}),e}({});
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
var InlineMath=function(e){"use strict";const t=-1,n={"+":{prec:50,assoc:"left",arity:2,fixity:"infix"},"-":{prec:50,assoc:"left",arity:2,fixity:"infix"},"±":{prec:50,assoc:"left",arity:2,fixity:"infix"},"*":{prec:70,assoc:"left",arity:2,fixity:"infix"},"/":{prec:70,assoc:"left",arity:2,fixity:"infix"},"^":{prec:80,assoc:"right",arity:2,fixity:"infix"},mod:{prec:45,assoc:"left",arity:2,fixity:"infix"},neg:{prec:75,assoc:"none",arity:1,fixity:"prefix"},pm:{prec:75,assoc:"none",arity:1,fixity:"prefix"},"!":{prec:90,assoc:"none",arity:1,fixity:"postfix"},_:{prec:100,assoc:"none",arity:2,fixity:"infix"},sqrt: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;const u=100,h="",p="",f={[h]:"dot",[p]:"cross"},m="",d={ln:u,log:u,loglog:u,logloglog:u,sqrt:u,sqrtpow:u,pow:u,expm1:u,der:u,lim:u,int:u,round:u,fixed:u,floor:u,ceil:u,abs:u,random:u,sum:u,prod:u,"\\sumidx":u,"\\prodidx":u,perm:u,comb:u,"\\perm":u,"\\comb":u,"\\binom":u,max:u,min:u,gcd:u,mean:u,pmatrix:u,bmatrix:u,vmatrix:u,det:u,sin:u,cos:u,tan:u,csc:u,sec:u,cot:u,sinh:u,cosh:u,tanh:u,evaluated:u,setbuilder:u,arcsin:u,arccos:u,arctan:u,arcsec:u,arccsc:u,arccot:u,arcsinh:u,arccosh:u,arctanh:u,atan2:u,_:u,"!":90,"\\not":85,"^":80,"*":70,"/":70,frac:70,[h]:70,[p]:70,mod:45,"+":50,"-":50,"±":50,"→":38,"<":34,">":34,"≤":34,"≥":34,"∈":32,"∉":32,"∪":33,"∩":33,"=":30,"==":30,"===":30,"≠":30,"≠=":30,"!==":30,"≈":30,"≡":30,pmod:2,"&":20,"\\xor":19,"|":18,"∨":18,"\\nor":17,"\\nand":17,"\\implies":15,"\\iff":14,"?:":10,"?":9,",":5},g=e=>Object.prototype.hasOwnProperty.call(d,e),b=new Set(["^","?:","?","log"]),y=["(","{","["],v=[")","}","]"];function w(e,t=!1){if(!e)return!1;for(let n=0;n<e.length;n++)if(!("0123456789.".includes(e[n])||t&&0===n&&"-"===e[n]&&e.length>1))return!1;return!0}for(const e of[d])Object.setPrototypeOf(e,null);const $=e=>({type:"number",value:String(e)}),x=e=>({type:"symbol",value:e}),M=(e,t)=>({type:"op",op:e,args:t}),k=['"',"'","`"];function A(e){return w(e,!0)?$(e):k.includes(e[0])?{type:"string",value:e}:x(e)}const N={"0-":"neg",sqrtpow:"root",pow:"^","==":"=","!==":"≠="};function E(e){if(!Array.isArray(e)||0===e.length)throw new Error("Empty postfix");const n=[],r=[];if(e.forEach((e,i)=>{const s=N[e]??String(e),l=a(s);if(!l)return n.push({...A(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({...M(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 _(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 O(e){if(Array.isArray(e))return E(e);if(e&&"object"==typeof e&&e.type)return e;throw new Error("Expected a postfix array or an expression tree")}function I(e,t,n=null){t(e,n),"op"===e.type&&e.args.forEach(n=>I(n,t,e))}function z(e){let t="";return I(e,e=>{!t&&"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value)&&(t=e.value)}),t}for(const e of[N])Object.setPrototypeOf(e,null);const S={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 q(e){for(;"op"===e.type&&e.args.length;)e=e.args[0];return"op"===e.type?"":e.value}function F(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=function(e,t,n){const r=e=>"symbol"===e.type?e.value===t?n:e:"op"!==e.type||["der","int","lim","\\sumidx","\\prodidx","evaluated","setbuilder"].includes(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:{...e,id:void 0,args:e.args.map(r)};return r(e)}(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 Z(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 j(e){if("*"!==e.op)return!1;const[t,n]=e.args;return"number"===t.type&&"-1"===t.value&&"-1"!==q(n)}function C(e){return"op"!==e.type||a(e.op)?.group?null:"sum"===e.op?"+":"prod"===e.op?"*":j(e)?"neg":e.op}const L=new Set(["=","===","≠","≠=","<",">","≤","≥","≈","≡","→"]),T=(e,t,n)=>("op"!==t.type||"?:"!==t.op||!L.has(e.op))&&function(e,t,n){if("mod"===e&&t)return c(t)<=70;if("mod"===t&&["*","/"].includes(e))return!0;if("mod"===t&&["+","-","±"].includes(e))return"right"===n;const r=c(e),i=c(t);if(!r||!i)return!1;if(i!==r)return i<r;const s=a(e).assoc;return"left"===s?"right"===n:"right"===s&&"left"===n}(e.op,C(t),n);function R(e,t){const n=C(t),r=n&&a(n)?.prec;return r?"!"===e?r<=a("!").prec:"\\not"===e?r<a("\\not").prec:r<70||H(t)||"\\not"===n:"\\not"!==e&&H(t)}function P(e,t,n={}){const r=n.left?"bracket":U(e),i=n.right?"bracket":D(t);return"digit"!==i&&"sign"!==i&&"word"!==r&&"word"!==i&&"other"!==r&&("frac"!==i||"digit"!==r&&"frac"!==r)}function B(e){return 1===e.length||Boolean(S[e])||/^Δ.$/.test(e)||/^d[A-Za-z\u03B1-\u03C9]$/.test(e)||/^.′+$/.test(e)}function W(e){return"op"===e.type&&!a(e.op)?.group&&(a(e.op)?.prec??100)<70&&!["sum","prod"].includes(e.op)}function D(e){if("number"===e.type)return e.value.startsWith("-")?"sign":"digit";if("op"!==e.type)return"symbol"===e.type&&B(e.value)?"name":"word";const t=e.op;return"neg"===t||"pm"===t||j(e)?"sign":"/"===t?"frac":a(t)?.group||W(e)?"bracket":G(e)||["der","int","lim","comb"].includes(t)?"call":["^","!","_"].includes(t)?W(e.args[0])?"bracket":D(e.args[0]):["*","sum","prod","perm"].includes(t)?D(e.args[0]):"other"}function U(e){if("number"===e.type)return"digit";if("op"!==e.type)return"symbol"===e.type&&B(e.value)?"name":"word";const t=e.op;return"/"===t?"frac":"^"===t||"_"===t?"script":a(t)?.group||W(e)||G(e)||["der","int","lim","comb","perm"].includes(t)?"bracket":["*","neg","pm","sum","prod"].includes(t)?U(e.args[e.args.length-1]):"other"}function G(e){if("op"!==e.type)return!1;const t=a(e.op);return"prefix"===t?.fixity&&100===t.prec}function H(e){if("number"===e.type)return e.value.startsWith("-");if("op"!==e.type)return!1;if("neg"===e.op||j(e))return!0;const t=a(e.op);return"infix"===t?.fixity&&!T(e,e.args[0],"left")&&H(e.args[0])}const X=e=>"symbol"===e.type&&1===e.value.length&&/[a-zA-Zʹ-Ͽ]/.test(e.value),V=e=>e.slice(2);function Q(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&&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=(e,t)=>e.type===t.type&&e.value===t.value&&"op"!==e.type,Y=new Set(["<",">","≤","≥","=","≠"]);function K(e){if("op"!==e.type||!Y.has(e.op)||2!==e.args.length)return null;const[t,n]=e.args;if("op"!==t.type||!Y.has(t.op)||2!==t.args.length)return null;return{type:"op",op:"&",args:[K(t)??t,{type:"op",op:e.op,args:[t.args[1],n]}]}}for(const e of[S])Object.setPrototypeOf(e,null);const ee={pmatrix:["(",")"],bmatrix:["[","]"],vmatrix:["|","|"]};function te(e){if(!e||"op"!==e.type)return null;if(Object.prototype.hasOwnProperty.call(ee,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 ne(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 re=e=>Array.isArray(e)&&e.length>0&&!e.some(Array.isArray);function ie(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 ne(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 se(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 ae(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=oe(n,e,i);s?(r+=t.get(e.slice(i,i+s)),i+=s):r+=e[i++]}return r}}function oe(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 ae(e){const t=new Set([e.toLowerCase(),e.toUpperCase(),le(e)]);return t.delete(e),t}function le(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 ce=[["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("],["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",h],["\\times",p],["×",p],["·",h],["÷","/"],["->","→"],["\\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.",m],["\\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 "],["∞","∞"],["⋅",h],["−","-"],["\\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 ue=e=>" "===e||"\t"===e||"\n"===e,he="({[",pe=")}]";const fe="ⅆ",me=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 de(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 ge=String.raw`\\(?:[Bb]igg?|right)[lrm]?`,be=new RegExp(`(?:${ge}\\s*([\\]|])|(\\]))\\s*(?=[_^])`,"g");function ye(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 ve(e,t){let n=t;for(;" "===e[n];)n++;const r=e[n];if("_"!==r&&"^"!==r)return null;const i=ye(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=ye(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 we(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 $e(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 xe(e){for(let t=0;t<50;t++){be.lastIndex=0;let t=null;for(let n=be.exec(e);n;n=be.exec(e)){const r=ve(e,n.index+n[0].length);if(!r)continue;const i=Boolean(n[2]),s="|"===(n[1]??n[2]),o=we(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:$e(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 Me={__proto__:null,sine:"sin",cosine:"cos",tangent:"tan",secant:"sec",cosecant:"csc",cotangent:"cot"};const ke={__proto__:null},Ae={__proto__:null};[..."⁰¹²³⁴⁵⁶⁷⁸⁹"].forEach((e,t)=>{ke[e]=String(t)}),[..."₀₁₂₃₄₅₆₇₈₉"].forEach((e,t)=>{Ae[e]=String(t)}),Object.assign(ke,{"⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","ᵃ":"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(Ae,{"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x"});const Ne=new RegExp(`[${Object.keys(ke).join("")}]+|[${Object.keys(Ae).join("")}]+`,"g");const Ee={__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"},_e=new RegExp(`(?<![\\w.,^_])(\\d+)[ \\t]?([${Object.keys(Ee).join("")}])`,"g"),Oe=/(?<![\w.,^_/])(\d+)[ \t]+([1-9]\d*)\/(\d+)(?![\d./^!])/g,Ie=/(?<![\w.,^_])(\d+)\s*\\[dtc]?frac\s*(?:\{\s*(\d+)\s*\}\s*\{\s*(\d+)\s*\}|(\d)(\d)(?!\d))/g;function ze(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 Se(e,t){const n=[];let r=0,i=0;for(let s=0;s<e.length;s++)he.includes(e[s])?r++:pe.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 qe(e,t,n){let r=0;const i=new RegExp(`\\b${n}\\b`,"iy");for(let n=t;n<e.length;n++)if(he.includes(e[n]))r++;else if(pe.includes(e[n])){if(--r<0)return-1}else if(0===r&&(i.lastIndex=n,i.test(e)))return n;return-1}function Fe(e,t){let n=0;for(let r=t;r<e.length;r++)if(he.includes(e[r]))n++;else if(pe.includes(e[r])&&--n<0)return r;return e.length}function Ze(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 je(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(he.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 Ce(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 Le(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 Te=new Set(["pmatrix","bmatrix","vmatrix"]);function Re(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 Te.has(r)?r+"("+o.join(", ")+")"+a:"["+o.join(", ")+"]"+a}function Pe(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 Be(e){const{lower:t,upper:n,next:r}=function(e){let t="",n="",r=0;return"_"===e[0]&&([t,r]=Pe(e,0),"^"===e[r]&&([n,r]=Pe(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(he.includes(e[n]))t++;else if(pe.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 We(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(pe.includes(n[e])?r--:he.includes(n[e])&&r++,0===r)return"("+n.slice(0,e)+","+t+")"+n.slice(e+1);return!1}function De(e){return"{"===e[0]||e.length<2?e:"{"+e[0]+"}{"+e[1]+"}"+e.slice(2)}const Ue=/[A-Za-z\u0370-\u03FF]/;function Ge(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 He(e,t){const n=/^\^(?:\{(\d+)\}|(\d))/.exec(e.slice(t));return n?[Number(n[1]??n[2]),t+n[0].length]:[1,t]}function Xe(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 Ve(e,t){if(he.includes(e[t])){let n=0;for(let r=t;r<e.length;r++)if(he.includes(e[r]))n++;else if(pe.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(he.includes(e[r]))n++;else{if(pe.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 Qe=(e,t,n)=>`der(${e},${t}${n>1?","+n:""})`;const Je="strtktk",Ye="ABCDEFGHIJ",Ke=e=>Je+[...String(e)].map(e=>Ye[e]).join(""),et=new RegExp(`^${Je}[${Ye}]+$`);function tt(e){let t="";for(let n=0;n<e.length;n++){const r=e[n];if('"'===r||"`"===r){const r=nt(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=nt(e,n);t+=e.slice(n,r+1),n=r}else t+=r}return t}function nt(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 rt=new RegExp(`${Je}[${Ye}]+|§\\d+§`,"g");function it(e,t){return t&&0!==t.size?e.map(e=>"string"!=typeof e?e:e.replace(rt,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 st={factorial:"((n) => { if (!Number.isInteger(n) || n < 0) return NaN; if (n > 170) return Infinity; let r = 1; for (let i = 2; i <= n; i++) r *= i; return r; })",perm:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; let r = 1; for (let i = n - k + 1; i <= n && r !== Infinity; i++) r *= i; return r; })",comb:"((n, k) => { if (!Number.isInteger(n) || !Number.isInteger(k) || k < 0 || k > n) return NaN; k = Math.min(k, n - k); let r = 1; for (let i = 1; i <= k && r !== Infinity; i++) r = r * (n - k + i) / i; return Math.round(r); })",gcd:"((args)=>{let gcd = function(a,b) { return (!b)?a:gcd(b,a%b); }; return Math.abs(args.reduce(gcd));})",det:"((m) => { const a = m.map((r) => r.slice()); const n = a.length; let d = 1; for (let i = 0; i < n; i++) { let p = i; for (let r = i + 1; r < n; r++) if (Math.abs(a[r][i]) > Math.abs(a[p][i])) p = r; if (a[p][i] === 0) return 0; if (p !== i) { const t = a[p]; a[p] = a[i]; a[i] = t; d = -d; } d *= a[i][i]; for (let r = i + 1; r < n; r++) { const f = a[r][i] / a[i][i]; for (let c = i; c < n; c++) a[r][c] -= f * a[i][c]; } } return d; })",union:"((a, b) => [...new Set([].concat(a, b))])",intersection:"((a, b) => [].concat(a).filter((x) => [].concat(b).includes(x)))",round:"((x, d) => { const p = Math.pow(10, d); return (x < 0 ? -Math.round(-x * p) : Math.round(x * p)) / p; })",mod:"((a, n) => ((a % n) + n) % n)",root:"((n, x) => (x < 0 ? -Math.pow(-x, 1 / n) : Math.pow(x, 1 / n)))"};for(const e of[st])Object.setPrototypeOf(e,null);const ot="([{",at=")]}";function lt(e,t){let n=0;for(let r=t;r<e.length;r++)if(ot.includes(e[r]))n++;else if(at.includes(e[r])&&0===--n)return r;return-1}function ct(e){if(!e.trim())return[];const t=[];let n=0,r=0;for(let i=0;i<e.length;i++)ot.includes(e[i])?n++:at.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 ut(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=lt(e,s);if(o<0)continue;const a=n(ct(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 ht=e=>new RegExp(`(?<![\\w.])(${e})\\s*\\(`,"g"),pt=e=>`(${e})`,ft=e=>/^\[.*\]$/s.test(e.trim())?`{${e.trim().slice(1,-1)}}`:e;const mt={IF:e=>e.length>=2&&`((${e[0]}) ? (${e[1]}) : (${e[2]??"false"}))`,AND:e=>e.length&&`(${e.map(pt).join(" & ")})`,OR:e=>e.length&&`(${e.map(pt).join(" ∨ ")})`,NOT:e=>1===e.length&&`(!(${e[0]}))`,XOR:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,LOG:e=>2===e.length?`log_{${e[1]}}(${e[0]})`:1===e.length&&`log_{10}(${e[0]})`,ATAN2:e=>2===e.length&&`atan2(${e[1]}, ${e[0]})`,INT:e=>1===e.length&&`floor(${e[0]})`,FIXED:e=>(1===e.length||2===e.length)&&`fixed(${e[0]}, ${e[1]??2})`,"FLOOR.MATH":e=>1===e.length&&`floor(${e[0]})`,"CEILING.MATH":e=>1===e.length&&`ceil(${e[0]})`,FACT:e=>1===e.length&&`((${e[0]})!)`,COMBIN:e=>2===e.length&&`comb(${e.join(", ")})`,PERMUT:e=>2===e.length&&`perm(${e.join(", ")})`,AVERAGE:e=>`mean(${e.join(", ")})`,SUM:e=>`sum(${e.join(", ")})`,PRODUCT:e=>`prod(${e.join(", ")})`,MAX:e=>`max(${e.join(", ")})`,MIN:e=>`min(${e.join(", ")})`,MEDIAN:e=>`median(${e.join(", ")})`,"STDEV.P":e=>`stdev(${e.join(", ")})`,STDEVP:e=>`stdev(${e.join(", ")})`,CEILING:e=>(1===e.length||2===e.length&&"1"===e[1].trim())&&`ceil(${e[0]})`,RAND:e=>!e.length&&"random()",ISNUMBER:e=>1===e.length&&`((${e[0]}) ∈ ℝ)`,LOG10:e=>1===e.length&&`log_{10}(${e[0]})`};function dt(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 gt(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=lt(e,o)+1;else{const t=n.exec(e.slice(o));s=t?o+t[0].length:0,t&&"("===e[s]&&(s=lt(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=dt(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),ut(e,/(?<![\w.])([A-Z][A-Z0-9]*(?:\.[A-Z]+)?)\s*\(/g,(e,t)=>mt[t[1]]?.(e)||null)}const bt={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"},yt="strtktk[A-J]+";function vt(e){for(let t=!0;t;){const n=e;t=(e=e.replace(new RegExp(`(${yt})\\s*\\|\\|\\s*(${yt})`,"g"),"$1 + $2"))!==n}const t=new RegExp(`^\\(typeof\\(([^()]*)\\)\\s+IN\\s+\\(${yt},\\s*${yt}\\)\\s+AND\\s+(.*)\\)$`,"s");for(let n=e.lastIndexOf("(typeof(");n>=0;n=n>0?e.lastIndexOf("(typeof(",n-1):-1){const r=lt(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=ut(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=ut(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})`,pt(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=>bt[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=lt(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 wt={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"},$t={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 xt=e=>e.replace(/(?<![\w.])set\s*\(\s*\)/g,"∅"),Mt={inf:"∞",nan:"NaN"};function kt(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)=>wt[t]?`Math.${wt[t]}`:$t[t]?$t[t]:Mt[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)=>Nt[t]??e),e=e.replace(/(?<![\w.])sympy\.(Reals|Integers|Naturals0?|Rationals|Complexes)\b/g,(e,t)=>Nt[t]),e.replace(/(?<![\w.])sympy\.(\w+)/g,(e,t)=>Et[t]??At[t]??e)}(e=(e=(e=e.replace(/(?<![\w.])(?:math|Math)\.(factorial|isfinite|isclose|prod|inf|nan|abs|trunc)\b/g,(e,t)=>Mt[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 At={pi:"π",E:"e",oo:"∞",true:"true",false:"false",nan:"NaN",I:"i"},Nt={Reals:"ℝ",Integers:"ℤ",Naturals:"ℕ",Naturals0:"ℕ",Rationals:"ℚ",Complexes:"ℂ"},Et={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:""},_t={open:"()",Lopen:"(]",Ropen:"[)"};const Ot=e=>{const t=/^\((.*)\)$/s.exec(e.trim());return t?ct(t[1]):null},It=e=>t=>2===t.length&&`${e[0]}${t[0]}, ${t[1]}${e[1]}`,zt=e=>Ot(e)??[e],St={where:e=>3===e.length&&`((${e[0]}) ? (${e[1]}) : (${e[2]}))`,logical_and:e=>2===e.length&&`((${e[0]}) & (${e[1]}))`,logical_or:e=>2===e.length&&`((${e[0]}) ∨ (${e[1]}))`,logical_xor:e=>2===e.length&&`((${e[0]}) \\xor (${e[1]}))`,logical_not:e=>1===e.length&&`(!(${e[0]}))`,isin:e=>2===e.length&&`((${e[0]}) ∈ ${ft(e[1])})`,contains:e=>2===e.length&&`((${e[1]}) ∈ ${ft(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]}))`,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(pt).join(" & ")})`,sympy_or:e=>e.length&&`(${e.map(pt).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(Ot);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:It("[]"),sympy_interval_open:It("()"),sympy_interval_Lopen:It("(]"),sympy_interval_Ropen:It("[)"),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=zt(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&&zt(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&&zt(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=ct(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 Ft(e){e=function(e){for(let t=e.lastIndexOf("(lambda");t>=0;t=t>0?e.lastIndexOf("(lambda",t-1):-1){const n=lt(e,t);if(n<0||"("!==e[n+1])continue;const r=lt(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=ct(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=ut(e,ht("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=ut(e,ht(Object.keys(St).join("|")),(e,t)=>St[t[1]](e)||null);for(let t=(e=ut(e,ht("float"),(e,t,n)=>{const r=/^\s*\.is_integer\(\s*\)/.exec(n);return r&&1===e.length?[`((${e[0]}) ∈ ℤ)`,r[0].length]:null})).lastIndexOf(".includes(");t>=0;t=t>0?e.lastIndexOf(".includes(",t-1):-1){const n=t+9,r=lt(e,n);let i=t;if(at.includes(e[t-1])){let n=0;for(i=t-1;i>=0;i--)if(at.includes(e[i]))n++;else if(ot.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)}) ∈ ${ft(e.slice(i,t))})${e.slice(r+1)}`)}return e}for(const e of[mt,bt,wt,$t,At,Nt,Et,_t,St,Mt])Object.setPrototypeOf(e,null);const Zt=String.raw`(?:\([^()]*\)|\[[^\[\]]*\]|\{[^{}]*\}|(?<![\w.′^])[\w.′^]+)`,jt=e=>e.trim().split(/\s+/).join(String.raw`\s+`),Ct=e=>new RegExp(String.raw`(?<![\w.])${jt(e)}(?![\w.])`,"gi"),Lt=[["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","="]],Tt="[<>≤≥=≠≈]",Rt={second:2,third:3,fourth:4,fifth:5,sixth:6,seventh:7,eighth:8,ninth:9,tenth:10};Object.setPrototypeOf(Rt,null);const Pt=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),Bt=[["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","∈ ℚ"]],Wt=/(?<![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;Lt.map(([e])=>e),Bt.map(([e])=>e),Pt.map(([e])=>`${e} of`);const Dt=se([[" 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 ","→"],["===","=...="]]),Ut=se([...ce,...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}()]),Gt=[["code",function(e){return/^\s*=|[(.%^<_eE]|\|\||\bif\b|\b(?:True|False|None|TRUE|FALSE|NULL)\b/.test(e)?(/^\s*=(?!=)/.test(e)&&(e=gt(e)),e=function(e){return e.includes("set")?xt(ut(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&<(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=kt(e=vt(e=(e=(e=function(e){for(const[t,n]of Object.entries(st))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]?lt(e,i):-1;if(s<0)continue;let o=e.slice(i+1,s);"gcd"===t&&(o=o.trim().replace(/^\[|\]$/g,""));const a="factorial"===t?`((${o})!)`:`${t}(${o})`;e=e.slice(0,r)+a+e.slice(s+1)}for(let t=e.lastIndexOf(").toFixed(");t>=0;t=t>0?e.lastIndexOf(").toFixed(",t-1):-1){const n=t+10-1,r=lt(e,n),i=e.lastIndexOf("Number(",t);r<0||i<0||lt(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(ot.includes(e[t]))i++;else{if(at.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(at.includes(e[t]))i++;else{if(ot.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=Ft(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(!Wt.test(e))return e;let t=e;const n=(e,n,r,i="∈")=>{t=t.replace(new RegExp(String.raw`(?<![\w.])${jt(e)}\s+(${Zt})\s+(?:and|to)\s+(${Zt})(?:\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+(${Zt})\s+to\s+(${Zt})`,"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`(${Zt})\s+`;t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?within\s+(${Zt})\s*(%|\s+percent)?\s+of\s+(${Zt})`,"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+(${Zt})`,"gi"),"(($1) mod ($2) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?divisible\s+by\s+(${Zt})`,"gi"),(e,t,n,r)=>`((${t}) mod (${r}) ${n?"≠":"="} 0)`),t=t.replace(new RegExp(String.raw`(${Zt})\s+divides\s+(${Zt})`,"gi"),"(($2) mod ($1) = 0)"),t=t.replace(new RegExp(r+String.raw`is\s+(not\s+)?(even|odd)(?![\w.])`,"gi"),(e,t,n,r)=>`((${t}) mod 2 ${"even"===r.toLowerCase()!==Boolean(n)?"=":"≠"} 0)`);for(const[e,n]of Bt)t=t.replace(Ct(e),` ${n} `);t=t.replace(Ct("is not in")," ∉ ").replace(Ct("is in")," ∈ ").replace(Ct("is an element of")," ∈ ");for(const[e,n]of Lt)t=t.replace(Ct(e),` ${n} `);t=t.replace(Ct("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`(${Zt})\s*(${Tt})\s*(${Zt})\s+(and|or)\s+(${Tt})`,"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+(${Zt})`,"gi"),"abs($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?square\s+root\s+of\s+(${Zt})`,"gi"),"sqrt($1)"),t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?cube\s+root\s+of\s+(${Zt})`,"gi"),"root(3, $1)"),t=t.replace(new RegExp(String.raw`(${Zt})\s+to\s+the\s+power\s+of\s+(${Zt})`,"gi"),"($1)^($2)"),t=t.replace(new RegExp(String.raw`(${Zt})\s+to\s+the\s+(${Object.keys(Rt).join("|")}|(\d+|n)(?:st|nd|rd|th))(?:\s+power)?(?![\w.])`,"gi"),(e,t,n,r)=>`(${t})^(${Rt[n.toLowerCase()]??r})`),t=t.replace(new RegExp(String.raw`(${Zt})\s+to\s+the\s+(${Zt})(?![\w.])`,"gi"),"($1)^($2)");for(const[e,n]of Pt)t=t.replace(new RegExp(String.raw`(?<![\w.])(?:the\s+)?${jt(e)}\s+of\s+(${Zt})`,"gi"),`${n}($1)`);t=t.replace(new RegExp(String.raw`(${Zt})\s+squared(?![\w.])`,"gi"),"($1)^2"),t=t.replace(new RegExp(String.raw`(${Zt})\s+cubed(?![\w.])`,"gi"),"($1)^3"),t=t.replace(new RegExp(String.raw`(?<![\w.])half\s+of\s+(${Zt})`,"gi"),"($1)/2"),t=t.replace(new RegExp(String.raw`(?<![\w.])twice\s+(${Zt})`,"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+)${jt(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",Dt],["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(;ue(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(;ue(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(_e,(e,t,n)=>`(${t}+${Ee[n]})`),e=e.replace(Oe,(e,t,n,r)=>Number(n)<Number(r)&&3!==n.length?`(${t}+${n}/${r})`:e),e.replace(Ie,(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(Ne,e=>{const t=e[0]in ke;return`${t?"^":"_"}{${[...e].map(e=>(t?ke:Ae)[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(me)){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)+fe+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])\s*\)\s*\}?(?=\s*\()/g,(e,t,n)=>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":"")+Me[n.toLowerCase()])}(e)))),/\\/.test(e)||(e=de(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=qe(e,n+2,"then");if(r<0)return e;const i=e.slice(n+2,r),s=qe(e,r+4,"else"),o=Fe(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=je(e);for(let t=0;t<e.length-1;t++)if("?"===e[t]&&":"!==e[t+1])e=Ze(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.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)&&/\d/.test(i)&&!/\\[A-Za-z]+$/.test(e.slice(0,n))?" ":""})}],["symbols",Ut],["bar",function(e){let t=0;for(let n=e.indexOf(m,t);n>=0;n=e.indexOf(m,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&&Ht(),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)+Qe(e.slice(r,t+1),"x",i)+e.slice(t+1+i),t=r}return e}(e=(e=je(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&&Ue.test(e[t-1]);let r,i=null,s=t;if(e.startsWith("frac{",t)){const n=Ge(e,t+4),r=n&&Ge(e,n[1]);i=r&&Xe(n[0],r[0]),i&&(s=r[1])}else if("d"===e[t]&&!n){let[n,r]=He(e,t+1),o="";if(Ue.test(e[r]??"")&&"/"===e[r+1]&&(o=e[r++]),"/"===e[r]&&"d"===e[r+1]&&Ue.test(e[r+2]??"")){const t=e[r+2],[,a]=He(e,r+3);i={n:n,of:o,by:t},s=a}}if(i){if(i.of)r=Qe(i.of,i.by,i.n);else{const[t,n]=Ve(e,s);if(!t)continue;r=Qe(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=Re(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"+Le(e.slice(t+1)):"sqrt"===r(4)&&(e=e.slice(0,t-4)+"sqrt"+Le(e.slice(t+1)));else if("⌊"===n||"⌈"===n)e=e.slice(0,t)+Ce(e.slice(t));else if("t"===n)"\\int"===i(3)&&(e=e.slice(0,t-3)+Be(e.slice(t+1)));else if("m"===n)"\\binom"===i(5)&&(e=e.slice(0,t-5)+"\\binom"+De(e.slice(t+1)));else if("d"===n&&"dd"===i(1)&&"("===e[t+2]){const n=We(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(m);t>=0;t=e.indexOf(m)){const n=Ht;e.startsWith("(der(",t+1)||n();const r=Xt(e,t+1,"(",")"),i=Xt(e,t+5,"(",")");(i<0||r!==i+1)&&n();const s=Vt(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=Xt(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()]],Ht=()=>{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 Xt(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 Vt(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 Qt(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=Ke(t.size);t.set(l,i+o+i),n+=l,r=s+1}return{text:n,strings:t}}(tt(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&&Jt.test(e.slice(0,s));if(Yt(e,s)||a&&"{"===e[s+2]?s+=1:o=a,!e.startsWith("{{",s)){i=s;continue}const l=Kt(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=Ke(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 Gt){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 Jt=/(?:\\[A-Za-z]+\*?|[\^_}\]])$/;function Yt(e,t){let n=0;for(;"\\"===e[t-1-n];)n++;return n%2==1}function Kt(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 en=Object.keys(d).filter(e=>100===d[e]&&/^[a-z]{2,}$/.test(e)),tn=["frac"],nn=[...Object.keys(S),"pi","tau","inf","infinity","exp"],rn="\n cost costs coast cosine cosines cosy sine sines since sincere sinus single\n tank tanks tango stand stank\n point points print prints paint paints pint pints mint hint hints lint tint saint faint joint into\n spin spine pipe pipes pine pines pick picks pink pity pie pies pilot pivot pixel pizza piano\n order orders under wonder border render older elder ladder cider rider wider bidder\n logic logo logs blog clog login slog\n model models mode modes modal modest modern module modules\n limb limbs slim lime limo limit limits climb\n maxi minute minutes mince mind mine mines\n sums sumo summit rounds floors ceils means meant sect sects secs expo kiln\n meta metal metals taxi must mute muse nut nuts\n".trim().split(/\s+/),sn=new Set([...nn,...rn,"simplify","expand","factor","cancel","diff","integrate","solve","approx","limit","true","false","null","undefined","unchanged","deg","mod","pmod","NaN","Infinity"]),on=/^[a-zA-ZͰ-Ͽ]$/,an=new Set(["f","g","h","u","v","F","G","H"]),ln=e=>en.includes(e)||tn.includes(e),cn=[...en,...tn,...nn].sort((e,t)=>t.length-e.length),un=[...en,...tn,"pi"].sort((e,t)=>t.length-e.length);function hn(e,t=cn){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 pn(e){if(ln(e))return!0;const t=hn(e,un);return t.length>1&&ln(t[t.length-1])&&!sn.has(e)}function fn(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=>on.test(e)))||1===e.length||sn.has(e)||ln(e))return[e];var r;if("Δ"===e[0]&&2===e.length)return[e];if("latex"===t)return mn(hn(e),n);if(e.length<=2)return[...e];const i=mn(hn(e,un),n),s=i.findIndex(e=>e.length>1);if(s<0)return[e];if("pi"===i[s]&&!i.some(e=>en.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 mn(e,t){const n=e[e.length-1];return t||!en.includes(n)?e:[...e.slice(0,-1),...n]}const dn="§",gn=/[A-Za-zͰ-Ͽ′]/,bn=e=>/^[A-Za-zͰ-Ͽ][A-Za-zͰ-Ͽ′]*$/.test(e);function yn(e,t="plain"){if("string"!=typeof e)throw new Error("Tokenizer input must be a string");const n=[];let r="";const i=e=>{r&&(bn(r)?n.push(...function(e,t,n){if((e=>et.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 an.has(e)?[s+e]:[e];if(g(e))return[e];const n=fn(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 fn(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===dn){i(o);const r=e.indexOf(dn,t+1);if(r<0)throw new Error(`An unmatched ${dn}`);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(bn(r)&&/[0-9]/.test(o)&&g(r+o)){const{op:i,end:s}=vn(e,t,r+o);n.push(i),r="",t=s;continue}if(gn.test(o)&&"′"!==o&&w(r)&&(n.push(r),r=""),gn.test(o)&&(""===r?"′"!==o:bn(r)))r+=o;else if(/[0-9]/.test(o)&&bn(r)&&!pn(r))r+=o;else if(bn(r)&&i(" "===o?e[t+1]:o),"(){}[]".includes(o))r&&n.push(...wn(r,o)),r="",n.push(o);else if("_"!==o&&" "!==o){if(g(r+o)){const{op:i,end:s}=vn(e,t,r+o);n.push(i),r="",t=s;continue}if(g(o)){i(o);const{op:r,end:s}=vn(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 vn(e,t,n){let r=t;for(;r+1<e.length&&g(n+e[r+1]);)n+=e[r+1],r++;return"!"===n&&"_"===e[r+1]&&r++,{op:n,end:r}}function wn(e,t){if(!y.includes(t))return[e];if("\\"===e[0]){const t=e.slice(1);return[g(t)?t:s+t]}return w(e)?[e,"*"]:g(e)||ln(e)||w(e[0])?[e]:[s+e]}const $n=70,xn=100,Mn="%mod",kn=/^d[A-Za-z\u0370-\u03FF]$/,An=e=>y.includes(e),Nn=e=>v.includes(e),En=e=>o(e)||d[e]===xn&&"_"!==e,_n=new Set(["\\comb","\\perm","comb","perm"]),On={frac:"/","\\binom":"\\binom"},In=new Set(["<",">","≤","≥","=","==","===","≠","≠=","!=","!==","&","|","\\not","\\xor","\\implies","\\iff","∈","∉","true","false"]),zn={"\\comb":"comb","\\perm":"perm",deg:"°","π":"pi","∨":"|"};class Sn{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(Nn(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||Nn(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:d.mod,run:()=>this.modulo()};if(e===Mn)return{lbp:$n,run:()=>{this.next(),this.parseExpression($n),this.emit("mod")}};if("pmod"===e)return{lbp:d.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:xn,run:()=>{this.next(),this.parseScript(),this.emit("_")}};if(_n.has(e))return{lbp:xn,run:()=>{this.next(),this.parseExpression(xn),this.emit(e)}};const n=d[e];if("="===e&&void 0!==n)return{lbp:n,run:()=>this.equals(n)};if(void 0!==n&&!En(e)&&"\\not"!==e&&!(e in On)){const t=b.has(e)?n-1:n;return{lbp:n,run:()=>{this.next(),this.parseExpression(t),this.emit(e)}}}return this.startsOperand(e)?this.implicit(e,t):null}implicit(e,t){return{lbp:!t||En(e)||kn.test(e)?$n:71,run:()=>{this.parseExpression($n),this.emit("*")}}}startsOperand(e){return void 0===e||Nn(e)||"|"===e?"|"===e:e!==Mn&&(!!(An(e)||En(e)||e in On)||!g(e))}pipe(){if(this.absDepth>0)return null;let e=0;for(let t=this.pos;t<this.tokens.length;t++)"|"===this.tokens[t]&&e++;const t="|"===this.peek(1);return e%2==0&&!t&&this.startsOperand(this.peek(1))?this.implicit("|",!1):{lbp:d["|"],run:()=>{this.next(),t&&e%2==0&&this.next(),this.parseExpression(d["|"]),this.emit("|")}}}modulo(){this.next(),this.parseExpression($n,!0),this.emit("mod")}equals(e){this.next(),this.parseExpression(e),In.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(An(n))e++;else if(Nn(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(An(e))return this.bracket(e,"{"===e&&("∈"===t||"∉"===t));if("|"===e)return this.absolute();if("-"===e||"+"===e){return"^"===t&&(void 0===n||Nn(n))||An(t)&&Nn(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 On)return this.parseScript(),this.parseScript(),this.emit(On[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(En(e))return this.functionCall(e);if(e===Mn)throw new Error("'%' is missing an operand");if(Nn(e)||g(e))throw new Error(`'${e}' is missing an operand`);this.emit(e)}negate(){const e=this.out.length;this.parseExpression(75);const t=this.out.slice(e);1!==t.length||!w(t[0])&&"∞"!==t[0]?this.emit("neg"):this.out[e]="-"+t[0]}bracket(e,t=!1){if(Nn(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();Nn(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(An(e))return this.parseOperand();if("-"===e||"+"===e)return this.parseOperand();if(En(e))return this.parseOperand();if(this.next(),void 0===e||Nn(e)||g(e))throw new Error("Missing a sub- or superscript");this.emit(e)}logarithm(){"_"===this.peek()?(this.next(),this.parseScript()):this.emit("e"),this.argument(),this.emit("log")}limit(){this.next();const e=this.out.length;this.parseScript();const t=this.out.splice(e);this.parseExpression(d["+"],!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(d["+"],!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&&!An(this.peek()))return this.emit(e);this.argument(),this.emit(e),t&&this.emit(...t,"^")}argument(){const e=this.peek();if(An(e))return this.next(),this.bracket(e);this.parseExpression($n,!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(an.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)g(r)||An(r)||Nn(r)||"_"===r||o(r)||w(r)?n.push(r):n.push(...Fn(r,t));return n}function Fn(e,t){if("%"===e)return[Mn];if(!e.includes("%"))return Zn(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(Mn),""!==e&&r.push(...Zn(e,t))}),r}function Zn(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(yn(i,t),t))];var i}for(const e of[On,zn])Object.setPrototypeOf(e,null);const jn=new Set(["()","[]","{}","(]","[)"]),Cn={pow:"^",sqrtpow:"root","\\binom":"comb","\\comb":"comb","\\perm":"perm",frac:"/","==":"=","!==":"≠=",...Object.fromEntries(Object.keys(f).map(e=>[e,"*"]))},Ln=new Set(["round","fixed","der"]),Tn=e=>o(e)||100===d[e];function Rn(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(jn.has(o)){const t=i(r(o));if(!t.length&&"{}"!==o&&!Tn(e[l+1]))throw new Error("Empty brackets");return void n.push(M(o,t))}const c=Cn[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(Tn(o)&&jn.has(e[l-1])&&n[n.length-1]?.op===e[l-1])h=n.pop().args;else{let e=u.arity===t||Ln.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 M("root",t);break;case"round":if(1===t.length)return M("round",[t[0],$(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 M("sum"===e?"\\sumidx":"\\prodidx",t);break}case"evaluated":if(3===t.length)return M("evaluated",[t[0],x(z(t[0])||"x"),t[1],t[2]]);break;case"det":if(t.length>1&&t.every(e=>"op"===e.type&&"[]"===e.op))return M("det",[M("[]",t)]);break;case"fixed":if(1===t.length)return M("fixed",[t[0],$(2)]);break;case"der":if(1===t.length)return M("der",[t[0],x("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=M("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 M("ln",[t[1]]);break;case"lim":return Bn(e,t),M("lim",function(e){const t=e=>{if("op"!==e.type)return null;if("^"===e.op&&"symbol"===e.args[1].type&&Pn[e.args[1].value])return{point:e.args[0],side:Pn[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,x(s.side)]}const s=3===e.length&&t(i);return s?[n,r,s.point,x(s.side)]:e}(t));case"\\:if":if(2===t.length||3===t.length)return M("?:",[t[0],t[1],t[2]??x("unchanged")]);throw new Error("if() takes a condition, a value, and optionally an alternative")}return Bn(e,t),M(e,t)}(c,h);f[o]&&"*"===p.op&&(p.written=f[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)=>M("&",[e,t])):s(n[0],"end")}const Pn={"\\+":"r","\\-":"l"};function Bn(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[Cn,Pn])Object.setPrototypeOf(e,null);const Wn=new RegExp(`[${Object.keys(f).join("")}]`,"g"),Dn=e=>e.replace(Wn,"*"),Un=/\\(?:text|textrm|textit|mathrm|mathit|operatorname)\{\s*([A-Za-z][A-Za-z0-9 ]*[A-Za-z0-9])\s*\}/g;const Gn=e=>/^[a-z][a-z0-9]*$/.test(e)&&g(e);function Hn(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=Se(e.slice(t+13,n),"\\\\").map(e=>Se(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=ze(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=xe(e),e=de(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)?xe(e):e}let Xn=null;function Vn(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=tt(e);let i="";for(let s=0;s<r.length;s++){const o=r[s];if('"'===o||"`"===o||"'"===o){const o=nt(r,s);i+=e.slice(s,o+1).replaceAll(t,n),s=o}else i+=e[s]}return i}(e,dn,"")).includes(dn))throw new Error(`The character ${dn} 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=`${dn}${r.size}${dn}`,r.set(t,e),i.set(e,t)),t};e=e.replace(Un,(e,t)=>Gn(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}}(Hn(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?Xn:t.blocks;return Qt(e,{evaluate:n?e=>n(e,t.scope):void 0})}(o,{blocks:t.blocks,scope:t.scope}),p=e=>it(it(e,u),a).map(e=>"string"==typeof e?e.replaceAll("",dn):e);n.mode=l,n.cleaned=Dn(p([c])[0]),n.cleanSteps=h.map(([e,t])=>[e,Dn(t)]);const f=yn(c,l);n.tokens=f.map(Dn);const m=p(function(e,t="plain"){return new Sn(qn(e,t)).parseAll().map(e=>zn[e]??e)}(f,l));n.rawPostfix=m.map(Dn);const d={},g=_(Rn(m),d);n.postfix=g,n.written=d,n.tree=E(g),Object.keys(d).length&&I(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 Qn(e,t={}){const n=Vn(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 Jn=(e,t)=>"string"==typeof e?Qn(e,t):O(e),Yn=ie({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(dr+=e/16,dr>mr)throw new Error("Too much to work out")},fail:e=>{throw new Error(e)}}),Kn=e=>ne(e)&&(e.length>1||e[0].length>1),er=e=>re(e)&&!Kn(e),tr=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},nr=(e,t)=>Kn(e)&&Kn(t)?Yn.times(e,t):Kn(e)&&er(t)?Yn.timesVector(e,t):er(e)&&Kn(t)?Yn.vectorTimes(e,t):tr((e,t)=>e*t)(e,t),rr=(e,t)=>n=>{const r=n.length>1&&n.every(er)?n:n[0];if(!ne(r))throw new Error(`${t}() needs a matrix`);return e(r)},ir=(e,t)=>([n,r])=>{if(!re(n)||!re(r))throw new Error(`${t}() needs two lists`);return e(n,r)},sr={det:rr(Yn.det,"det"),inv:rr(Yn.inverse,"inv"),inverse:rr(Yn.inverse,"inverse"),transpose:rr(Yn.transpose,"transpose"),trace:rr(Yn.trace,"trace"),tr:rr(Yn.trace,"tr"),rank:rr(Yn.rank,"rank"),rref:rr(Yn.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 Yn.identity(e)},dot:ir(Yn.dot,"dot"),cross:ir(Yn.cross,"cross"),linsolve:([e,t])=>{if(!ne(e)||!Array.isArray(t))throw new Error("linsolve() needs a matrix and a list");return Yn.solve(e,t)}},or=(e,t)=>e.args.map(e=>"op"===e.type&&"[]"===e.op?e.args.map(e=>br(e,t)):[br(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},lr=(e,t)=>t?lr(t,e%t):Math.abs(e),cr=(e,t)=>(e%t+t)%t,ur=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>ur(e,t[n])):e==t,hr={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=>sr.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},pr={"+":(e,t)=>Array.isArray(e)||Array.isArray(t)?tr((e,t)=>e+t)(e,t):e+t,"-":(e,t)=>Array.isArray(e)||Array.isArray(t)?tr((e,t)=>e-t)(e,t):e-t,"*":nr,"/":(e,t)=>Kn(t)?nr(e,Yn.inverse(t)):Array.isArray(e)||Array.isArray(t)?tr((e,t)=>e/t)(e,t):e/t,"^":(e,t)=>{if(!Kn(e))return Array.isArray(e)?tr((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 Yn.power(e,BigInt(t))},mod:cr,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)},"=":ur,"===":(e,t)=>e===t,"≠":(e,t)=>!ur(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)},fr={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(lr,0),"()":e=>e,"[]":e=>e,"{}":e=>e};const mr=5e6;let dr=0,gr=0;function br(e,t){if(++dr>mr)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(Z(e.value))return Number(Z(e.value));throw new Error(`No value for '${e.value}'`)}const n=K(e);if(n)return br(n,t);const{op:r,args:i}=e;if("?:"===r)return br(i[0],t)?br(i[1],t):br(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)&&F(e))return br(F(e),t);if("∈"===r||"∉"===r)return function(e,t){const[n,r]=e.args,i=br(n,t);let s;if("symbol"===r.type&&yr[r.value])return s=yr[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=>br(e,t)),o="["===r.op[0]?i>=e:i>e,a="]"===r.op[1]?i<=n:i<n;s=o&&a}else{const e=br(r,t);s=Array.isArray(e)&&e.includes(i)}return"∈"===e.op?s:!s}(e,t);if("random"===r)return Math.random();if("evaluated"===r){const[e,n,r,s]=i,o=r=>br(e,{...t,[n.value]:br(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:z(n);if(!a)throw new Error(`Can't evaluate '${r}' without an index`);const l=br(s,t),c=br(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=br(n,{...t,[a]:e});u="\\sumidx"===r?u+i:u*i}return u}if("pmod"===r){const[e,n]=i,r=br(n,t);if("op"===e.type&&["≡","="].includes(e.op)){const[n,i]=e.args.map(e=>br(e,t));return(n-i)%r===0}return cr(br(e,t),r)}if("pmatrix"===r||"bmatrix"===r)return or(e,t);if("vmatrix"===r)return Yn.det(or(e,t));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=br(i[0],t);if(Kn(e))return Yn.transpose(e)}const s=i.map(e=>br(e,t));if(r.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(sr,r.slice(2)))return sr[r.slice(2)](s);if(hr[r]&&1===s.length)return hr[r](s[0]);if(pr[r]&&2===s.length)return pr[r](s[0],s[1]);if(fr[r])return fr[r](s);throw new Error(`Can't evaluate '${r}'`)}const yr={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":e=>Number.isInteger(e)&&e>0,"ℚ":Number.isFinite,"ℂ":e=>"number"==typeof e&&!Number.isNaN(e)};for(const e of[ar,hr,pr,fr,yr,sr])Object.setPrototypeOf(e,null);class vr extends Error{}class wr extends Error{}class $r extends wr{}const xr={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let Mr=0;function kr(e){if(Mr+=e,Mr>xr.steps)throw new wr("too much to work out")}const Ar=(e,t)=>kr(Number(e)*(t/64)/128);let Nr=0;const Er=e=>e<0n?-e:e,_r=0xFFFFFFFFFFFFn,Or=e=>0n===e?0:Er(e).toString(2).length;function Ir(e,t){for(e=Er(e),t=Er(t);t;)[e,t]=[t,e%t];return e}function zr(e,t=1n){if(0n===t)throw new vr("division by zero");if(t<0n&&(e=-e,t=-t),t>_r&&(e>_r||-e>_r)){const n=Math.min(e.toString(16).length-(e<0n?1:0),t.toString(16).length)/16;if(Mr+=1+n*n/2,Mr>xr.steps)throw new wr("too much to work out")}const n=Ir(e,t)||1n;return{n:e/n,d:t/n}}const Sr=zr(0n),qr=zr(1n),Fr=(e,t)=>zr(e.n*t.d+t.n*e.d,e.d*t.d),Zr=(e,t)=>zr(e.n*t.n,e.d*t.d),jr=(e,t)=>zr(e.n*t.d,e.d*t.n),Cr=e=>({n:-e.n,d:e.d}),Lr=(e,t)=>{const n=e.n*t.d-t.n*e.d;return n<0n?-1:n>0n?1:0},Tr=e=>{const t=e.n/e.d;return e.n<0n&&t*e.d!==e.n?t-1n:t};function Rr(e){if(e.n<0n)return-Rr(Cr(e));const t=Or(e.n),n=Or(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 Pr(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 wr(`'${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=Fr(zr(BigInt(o||"0")),zr(i-r,(10n**BigInt(e)-1n)*10n**BigInt(n.length)))}else l=zr(BigInt(o+a||"0"),10n**BigInt(a.length));if(Math.abs(i)>xr.bits/3)throw new wr("too large to calculate");return i&&(l=i>0?Zr(l,zr(10n**BigInt(i))):jr(l,zr(10n**BigInt(-i)))),n<0n?Cr(l):l}function Br(e,t=0,n=0,r=null){return 0n===e.n?{kind:"x",c:Sr,pi:0,e:0,root:null}:{kind:"x",c:e,pi:t,e:n,root:r}}const Wr=(e,t=1n)=>Br(zr(BigInt(e),BigInt(t))),Dr=Br(qr,1),Ur=Br(qr,0,1),Gr=e=>null!==e&&"object"==typeof e&&"x"===e.kind,Hr=e=>Gr(e)&&!e.pi&&!e.e&&!e.root,Xr=e=>Gr(e)?0n===e.c.n:0===e,Vr=e=>Hr(e)&&1n===e.c.d?e.c.n:null,Qr=(e,t)=>Object.assign(e,{group:t}),Jr=e=>({kind:"s",text:e});function Yr(e,t){return e&&t?e.n===t.n&&e.r===t.r:e===t}const Kr=(e,t)=>0===Lr(e.c,t.c)&&e.pi===t.pi&&e.e===t.e&&Yr(e.root,t.root);function ei(e){const t=Math.max(0,Or(e)-60);return t+Math.log2(Number(e>>BigInt(t)))}function ti(e){if("number"==typeof e)return e;if(Ei(e)&&Fi(e),Gr(e)){let t=Rr(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**(ei(e)/t)}(e.root.r,e.root.n);if(!(0n===e.c.n||0!==t&&Number.isFinite(t)&&Number.isFinite(n))){const t=ei(e.c.n<0n?-e.c.n:e.c.n)-ei(e.c.d)+ei(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 wr("not a number")}function ni(e,...t){if(Number.isNaN(e))throw new vr("undefined");if(!Number.isFinite(e)&&t.every(Number.isFinite))throw new wr("too large to calculate");return e}const ri=e=>"boolean"==typeof e?e:Gr(e)?0n!==e.c.n:"number"==typeof e?0!==e:Boolean(e);function ii(e){if("bigint"==typeof e)return Br(zr(e));if("number"==typeof e)return Number.isFinite(e)?Br(Number.isInteger(e)&&Math.abs(e)<=Number.MAX_SAFE_INTEGER?zr(BigInt(e)):Pr(String(e))):e;if("boolean"==typeof e)return e;if("string"==typeof e)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(e.trim())?Br(Pr(e)):Is(Qn(e),{});if(Array.isArray(e))return!e.group&&ne(e)?Qr(e.map(e=>Qr(e.map(ii),"[]")),"[]"):Qr(e.map(ii),e.group||"()");if(Gr(e)||"function"==typeof e)return e;throw new wr(`can't use ${typeof e} as a value`)}function si(e){if(Array.isArray(e))return e.map(si);if(_i(e)){const{re:t,im:n}=Zi(e);return{re:ti(t),im:ti(n)}}return Ei(e)?Us(e,{decimal:!1,places:null,digits:12,maxDigits:50}):e&&"s"===e.kind?e.text:"boolean"==typeof e?e:ti(e)}function oi(e,t){if(e<2n)return e;const n=BigInt(t);let r=1n<<BigInt(Math.ceil(Or(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 Br(Sr);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++}Mr+=o/4;const a=oi(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=oi(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?Br(Zr(e,zr(s*o.r)),r,i):Br(Zr(e,zr(s)),r,i,o)}function li(e,t){const n=Zr(e.c,t.c);if(Or(n.n)+Or(n.d)>xr.bits)return null;const r=e.pi+t.pi,i=e.e+t.e;if(!e.root||!t.root)return Br(n,r,i,e.root||t.root);const s=ps(e.root.n,t.root.n);if(s>xr.rootIndex)return null;const o=e.root.r**BigInt(s/e.root.n)*t.root.r**BigInt(s/t.root.n);return Or(o)>4e3?null:ai(n,s,o,r,i)}function ci(e){if(0n===e.c.n)throw new vr("division by zero");const t=Br(jr(qr,e.c),-e.pi,-e.e);if(!e.root)return t;const{n:n,r:r}=e.root;return Or(r)*(n-1)>4e3?null:li(t,ai(zr(1n,r),n,r**BigInt(n-1)))}function ui(e,t){if(0n===t){if(0n===e.c.n)throw new vr("0^0 is undefined");return Br(qr)}if(t<0n){const n=ci(e);return n&&ui(n,-t)}if((Or(e.c.n)+Or(e.c.d)+(e.root?Or(e.root.r):0))*Number(t)>xr.bits||t>100000n)return null;const n=zr(e.c.n**t,e.c.d**t),r=Number(t);if(!e.root)return Br(n,e.pi*r,e.e*r);const{n:i,r:s}=e.root,o=s**(t/BigInt(i));return ai(Zr(n,zr(o)),i,s**(t%BigInt(i))||1n,e.pi*r,e.e*r)}function hi(e,t,n){if(!Hr(e)||n>1000n)return null;const r=ui(e,t);if(!r)return null;let{n:i,d:s}=r.c,o=!1;if(i<0n){if(n%2n==0n)throw new vr("not a real number");o=!0,i=-i}const a=function(e,t){const n=e.n*e.d**BigInt(t-1);return Or(n)>4e3?null:ai(zr(1n,e.d),t,n)}({n:i,d:s},Number(n));return a?o?Br(Cr(a.c),a.pi,a.e,a.root):a:null}function pi(e){return t=>Array.isArray(t)?Qr(t.map(t=>pi(e)(t)),t.group):e(t)}function fi(e){const t=(n,r)=>{const i=Array.isArray(n),s=Array.isArray(r);if(i&&s){if(n.length!==r.length)throw new vr("lists of different lengths");return Qr(n.map((e,n)=>t(e,r[n])),n.group)}return i?Qr(n.map(e=>t(e,r)),n.group):s?Qr(r.map(e=>t(n,e)),r.group):e(n,r)};return t}const mi=(e,t)=>Gr(e)&&Gr(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||!Yr(e.root,t.root))return null;const n=Fr(e.c,t.c);return Or(n.n)+Or(n.d)>xr.bits?null:Br(n,e.pi,e.e,e.root)}(e,t)||ni(ti(e)+ti(t),ti(e),ti(t)),di=e=>Gr(e)?Br(Cr(e.c),e.pi,e.e,e.root):-ti(e),gi=(e,t)=>Gr(e)&&Gr(t)&&li(e,t)||ni(ti(e)*ti(t),ti(e),ti(t)),bi=fi((e,t)=>Ei(e)||Ei(t)?Di(e,t):mi(e,t)),yi=pi(e=>Ei(e)?Ui(e):di(e)),vi=(e,t)=>bi(e,yi(t)),wi=fi((e,t)=>Ei(e)||Ei(t)?Hi(e,t):gi(e,t)),$i=fi((e,t)=>Ei(e)||Ei(t)?function(e,t){if(!Ei(t)){if(Xr(t))throw new vr("division by zero");return zi(Si(e).map(e=>({vars:e.vars,re:xi(e.re,t),im:xi(e.im,t)})))}if(_i(t))return Hi(e,ji(Li(Zi(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:Gi(e.vars,[[r,-o]]),...Ci(e,Li(s))};l.push(n);const c=Di(zi(a),Ui(Hi(zi([n]),zi(t))));a=Xr(c)?[]:Si(c)}return a.length?null:zi(l)}(Si(e),[...t.terms.values()]);if(null===n)throw new wr(`no value for '${qi(t)}'`);return n}(e,t):xi(e,t));function xi(e,t){if(Xr(t))throw new vr("division by zero");if(Gr(e)&&Gr(t)){const n=ci(t),r=n&&li(e,n);if(r)return r}return ni(ti(e)/ti(t),ti(e),ti(t))}const Mi=fi((e,t)=>{if(Ei(e)||Ei(t))return function(e,t){if(Ei(t)){_i(t)||Fi(t),Ei(e)&&!_i(e)&&Fi(e);const n=Zi(t);return Gr(e)&&Kr(e,Ur)?Pi(n):Pi(Ci(n,Bi(Zi(e))))}const n=Vr(t);if(null!==n)return n>=0n?Xi(e,n):(_i(e)||Fi(e),Xi(ji(Li(Zi(e))),-n));_i(e)||Fi(e);return Wi(Zi(e),t)}(e,t);try{return ki(e,t)}catch(n){if(Ai&&n instanceof vr&&"not a real number"===n.message)return Wi({re:e,im:Wr(0)},t);throw n}});function ki(e,t){if(Gr(e)&&Hr(t)){const{n:n,d:r}=t.c,i=1n===r?ui(e,n):hi(e,n,r);if(i)return i}const n=ti(e),r=ti(t);if(0===n&&0===r)throw new vr("0^0 is undefined");if(0===n&&r<0)throw new vr("division by zero");if(n<0&&!Number.isInteger(r))throw new vr("not a real number");const i=n**r;if(0===i&&0!==n)throw new $r("too small to calculate");return ni(i,n,r)}let Ai=!1;const Ni=5e3,Ei=e=>null!==e&&"object"==typeof e&&"p"===e.kind,_i=e=>Ei(e)&&1===e.terms.size&&e.terms.has(""),Oi=()=>zi([{vars:[],re:Wr(0),im:Wr(1)}]),Ii=e=>e.map(([e,t])=>1===t?e:`${e}^${t}`).join("*");function zi(e){const t=new Map;for(const n of e){const e=Ii(n.vars),r=t.get(e);t.set(e,r?{vars:n.vars,re:mi(r.re,n.re),im:mi(r.im,n.im)}:n)}for(const[e,n]of t)Xr(n.re)&&Xr(n.im)&&t.delete(e);if(t.size>Ni)throw new wr("too many terms to work out");return t.size?1===t.size&&t.has("")&&Xr(t.get("").im)?t.get("").re:{kind:"p",terms:t}:Wr(0)}function Si(e){if(Ei(e))return[...e.terms.values()];if("boolean"==typeof e)return[{vars:[],re:Wr(e?1:0),im:Wr(0)}];if(!Gr(e)&&"number"!=typeof e)throw new wr("not a number");return[{vars:[],re:e,im:Wr(0)}]}const qi=e=>[...e.terms.values()].find(e=>e.vars.length)?.vars[0][0];function Fi(e){if(_i(e))throw new wr("a complex number has no real value here");throw new wr(`no value for '${qi(e)}'`)}const Zi=e=>_i(e)?e.terms.get(""):{re:e,im:Wr(0)},ji=({re:e,im:t})=>zi([{vars:[],re:e,im:t}]),Ci=(e,t)=>({re:mi(gi(e.re,t.re),di(gi(e.im,t.im))),im:mi(gi(e.re,t.im),gi(e.im,t.re))});function Li(e){const t=mi(gi(e.re,e.re),gi(e.im,e.im));if(Xr(t))throw new vr("division by zero");return{re:xi(e.re,t),im:di(xi(e.im,t))}}const Ti=e=>Xr(e.im)?Vi(e.re,Wr(0))<0?di(e.re):e.re:ki(mi(gi(e.re,e.re),gi(e.im,e.im)),Wr(1,2));function Ri(e){return Xr(e.im)?Vi(e.re,Wr(0))<0?Dr:Wr(0):Xr(e.re)?Vi(e.im,Wr(0))>0?Br(zr(1n,2n),1):Br(zr(-1n,2n),1):Math.atan2(ti(e.im),ti(e.re))}function Pi(e){const t=Xr(e.re)?Wr(1):ki(Ur,e.re);return ji({re:gi(t,ts("cos",e.im)),im:gi(t,ts("sin",e.im))})}function Bi(e){if(Xr(e.re)&&Xr(e.im))throw new vr("ln 0 is undefined");return{re:rs(Ti(e)),im:Ri(e)}}function Wi(e,t){if(Xr(e.re)&&Xr(e.im))return ki(Wr(0),t);const n=ki(Ti(e),t),r=gi(t,Ri(e));return ji({re:gi(n,ts("cos",r)),im:gi(n,ts("sin",r))})}function Di(e,t){return zi([...Si(e),...Si(t)])}function Ui(e){return zi(Si(e).map(e=>({vars:e.vars,re:di(e.re),im:di(e.im)})))}function Gi(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 Hi(e,t){const n=Si(e),r=Si(t);kr(n.length*r.length);const i=[];for(const e of n)for(const t of r)i.push({vars:Gi(e.vars,t.vars),...Ci(e,t)});return zi(i)}function Xi(e,t){if(!_i(e)&&t>1000n)throw new wr("too large to calculate");if(_i(e)&&t>1n){const{re:n,im:r}=Zi(e),i=e=>Gr(e)?Or(e.c.n)+Or(e.c.d)+(e.root?Or(e.root.r):0):64;if(Number(t)*Math.max(i(n),i(r),1)>2e4)return Wi(Zi(e),Wr(t))}let n=Wr(1),r=e;for(let e=t;e>0n;e>>=1n)1n&e&&(n=Hi(n,r)),e>1n&&(r=Hi(r,r));return n}function Vi(e,t){if(_i(e)||_i(t))throw new wr("complex numbers have no order");if(Hr(e)&&Hr(t))return Lr(e.c,t.c);if(Gr(e)&&Gr(t)&&Kr(e,t))return 0;const n=ti(e),r=ti(t);if(n===r)return 0;const i=Gr(e)&&Gr(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 Qi(e,t){return Array.isArray(e)||Array.isArray(t)?Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>Qi(e,t[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:Ei(e)||Ei(t)?function(e,t){const n=vi(e,t);return Ei(n)?!_i(n)&&Fi(n):Xr(n)}(e,t):0===Vi(e,t)}const Ji={0:()=>Wr(0),2:()=>Wr(1,2),3:()=>ai(zr(1n,2n),2,2n),4:()=>ai(zr(1n,2n),2,3n),6:()=>Wr(1)};function Yi(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=Ji[t];return r?n<0?yi(r()):r():null}const Ki=e=>Yi(e+6),es=(e,t)=>Math.abs(e)<1e-15&&Math.abs(t)>1e-6?0:e;function ts(e,t){const n=function(e){if(Xr(e))return 0;if(!Gr(e)||1!==e.pi||e.e||e.root)return null;const t=Zr(e.c,zr(12n));return 1n!==t.d?null:Number((t.n%24n+24n)%24n)}(t);if(null!==n){const t=Yi(n),r=Ki(n);if(t&&r)switch(e){case"sin":return t;case"cos":return r;case"tan":return $i(t,r);case"cot":return $i(r,t);case"sec":return $i(Wr(1),r);case"csc":return $i(Wr(1),t)}}const r=ti(t),i=es(Math.sin(r),r),s=es(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 vr("undefined");return ni(o)}function ns(e,t){const n={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[e],r=t=>"arcsin"===e?Yi(t):"arccos"===e?Ki(t):Ki(t)&&!Xr(Ki(t))?$i(Yi(t),Ki(t)):null;if(Gr(t))for(let e=n[0];e<=n[1];e++){const n=r(e);if(n&&Gr(n)&&Kr(n,t))return Br(zr(BigInt(e),12n),1)}const i=ti(t);if("arctan"!==e&&Math.abs(i)>1)throw new vr("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[e](i)}function rs(e){if(Ei(e))return _i(e)?ji(Bi(Zi(e))):Fi(e);if(Ai&&Vi(e,Wr(0))<0)return ji({re:rs(di(e)),im:Dr});if(Gr(e)){if(0n===e.c.n)throw new vr("ln 0 is undefined");if(e.c.n<0n)throw new vr("not a real number");if(1n===e.c.n&&1n===e.c.d&&!e.pi&&!e.root)return Wr(e.e)}const t=ti(e);if(t<=0)throw new vr(0===t?"ln 0 is undefined":"not a real number");return Math.log(t)}function is(e){if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*is(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 ss(e,t){Ei(e)&&Fi(e);const n=Vr(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null===n)throw new vr(`${t} needs whole numbers`);return n}const os=(e,t)=>Number(t)*Or(e)>xr.bits;const as=pi(e=>Hr(e)?Br(zr(Tr(e.c))):ii(Math.floor(ti(e)))),ls=pi(e=>Hr(e)?Br(zr(-Tr(Cr(e.c)))):ii(Math.ceil(ti(e))));function cs(e,t){const n=Number(ss(t,"round"));if(Math.abs(n)>xr.places)throw new wr("too many decimal places");if(Hr(e)){const t=zr(10n**BigInt(Math.abs(n))),r=n>=0?Zr(e.c,t):jr(e.c,t),i=Tr(Fr(Zr(zr(2n),zr(Er(r.n),r.d)),qr))/2n,s=zr(r.n<0n?-i:i);return Br(n>=0?jr(s,t):Zr(s,t))}if(n>15)return ti(e);const r=10**n;return 0===r?0:Math.sign(ti(e))*Math.round(Math.abs(ti(e))*r)/r}const us=(e,t)=>e.toFixed(Math.min(t,100))+(t>100?"0".repeat(t-100):"");function hs(e,t){if(Xr(t))throw new vr("division by zero");if(Hr(e)&&Hr(t))return Br(Fr(e.c,Cr(Zr(t.c,zr(Tr(jr(e.c,t.c)))))));const n=ti(e),r=ti(t);return ni((n%r+r)%r)}const ps=(e,t)=>e/fs(e,t)*t,fs=(e,t)=>t?fs(t,e%t):e,ms={pi:()=>Dr,"π":()=>Dr,tau:()=>Br(zr(2n),1),"τ":()=>Br(zr(2n),1),e:()=>Ur,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1,"°":()=>Br(zr(1n,180n),1)},ds={abs:e=>_i(e)?Ti(Zi(e)):Gr(e)?Br(zr(Er(e.c.n),e.c.d),e.pi,e.e,e.root):Math.abs(ti(e)),floor:as,ceil:ls,sqrt:e=>Mi(e,Wr(1,2)),ln:pi(rs),loglog:pi(e=>rs(rs(e))),logloglog:pi(e=>rs(rs(rs(e)))),expm1:pi(e=>Xr(e)?Wr(0):Math.expm1(ti(e))),sinh:pi(e=>Xr(e)?Wr(0):Math.sinh(ti(e))),cosh:pi(e=>Xr(e)?Wr(1):Math.cosh(ti(e))),tanh:pi(e=>Xr(e)?Wr(0):Math.tanh(ti(e))),arcsinh:pi(e=>Xr(e)?Wr(0):Math.asinh(ti(e))),arccosh:pi(e=>{const t=ti(e);if(t<1)throw new vr("not a real number");return 1===t?Wr(0):Math.acosh(t)}),arctanh:pi(e=>{const t=ti(e);if(Math.abs(t)>=1)throw new vr("undefined");return Xr(e)?Wr(0):Math.atanh(t)}),"!":pi(function(e){const t=Vr(e)??("number"==typeof e&&Number.isInteger(e)?BigInt(e):null);if(null!==t){if(t<0n)throw new vr("factorial of a negative number");if(t>BigInt(xr.factorial))throw new wr("too large to calculate");Ar(t,Number(t)*Math.log2(Number(t)+1));let e=1n;for(let n=2n;n<=t;n++)e*=n;return Br(zr(e))}const n=ti(e);if(n<0&&Number.isInteger(n))throw new vr("factorial of a negative number");return ni(is(n+1),n)}),neg:yi,pm:e=>Qr([e,yi(e)],"pm"),"\\not":e=>!ri(e),det:e=>ks.det(e)};for(const e of["sin","cos","tan","csc","sec","cot"])ds[e]=pi(t=>ts(e,t));for(const e of["arcsin","arccos","arctan"])ds[e]=pi(t=>ns(e,t));const gs=e=>{if(Xr(e))throw new vr("not a real number");return $i(Wr(1),e)};ds.arcsec=pi(e=>ns("arccos",gs(e))),ds.arccsc=pi(e=>ns("arcsin",gs(e))),ds.arccot=pi(e=>vi(Br(zr(1n,2n),1),ns("arctan",e)));const bs=new Set(["pmatrix","bmatrix"]),ys=e=>ne(e)&&(bs.has(e.group)||"[]"===e.group&&e.every(e=>"[]"===e.group)&&(e.length>1||e[0].length>1)),vs=e=>re(e)&&!ys(e)&&"pm"!==e.group,ws=ie({add:bi,sub:vi,mul:wi,div:$i,charge:kr,isZero:e=>Gr(e)?0n===e.c.n:Math.abs(ti(e))<1e-12,zero:()=>Wr(0),one:()=>Wr(1),size:e=>Math.abs(ti(e)),fail:e=>{throw new vr(e)},make:(e,t)=>Qr(e.map(e=>Qr(e,"[]")),t&&t.group?t.group:"bmatrix")}),$s=(e,t)=>Qr(e,t&&t.group?t.group:"[]"),xs=(e,t)=>(...n)=>{const r=n.length>1&&n.every(vs)?Qr(n.map(e=>Qr(e,"[]")),"[]"):n[0];if(n.length>1&&r===n[0])throw new wr(`${e} of more than one thing`);if(!ys(r))throw new wr(`${e} of something that isn't a matrix`);return t(r)};function Ms(e,t){return ys(e)&&ys(t)?ws.times(e,t):ys(e)&&vs(t)?$s(ws.timesVector(e,t),t):vs(e)&&ys(t)?$s(ws.vectorTimes(e,t),e):wi(e,t)}const ks={det:xs("det",e=>As(e)),inv:xs("inv",ws.inverse),inverse:xs("inverse",ws.inverse),transpose:xs("transpose",ws.transpose),trace:xs("trace",ws.trace),tr:xs("tr",ws.trace),rank:xs("rank",e=>Wr(ws.rank(e))),rref:xs("rref",ws.rref),identity:e=>{const t=Vr(e);if(null===t||t<1n||t>100n)throw new wr("identity(n) needs a whole number n");return ws.identity(Number(t))},dot:(e,t)=>{if(!vs(e)||!vs(t))throw new wr("dot of something that isn't a vector");return ws.dot(e,t)},cross:(e,t)=>{if(!vs(e)||!vs(t))throw new wr("cross of something that isn't a vector");return $s(ws.cross(e,t),e)},linsolve:(e,t)=>{if(!ys(e)||!ys(t)&&!vs(t))throw new wr("linsolve(A, b) needs a matrix and a vector");return ys(t)?ws.solve(e,t):$s(ws.solve(e,t),t)}};function As(e){if(!e.some(e=>e.some(Ei)))return ws.det(e);if(e.length!==e[0].length)throw new vr(`a ${e.length} by ${e[0].length} matrix has no determinant`);if(e.length>6)throw new wr("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=wi(r,t(s));return i%2?vi(n,o):bi(n,o)},Wr(0));return t(e)}function Ns(e,t){const n=e.args.map(e=>Qr("op"===e.type&&"[]"===e.op?e.args.map(t):[t(e)],"[]"));if(n.some(e=>e.length!==n[0].length))throw new vr("rows of different lengths");return Qr(n,"vmatrix"===e.op?"bmatrix":e.op)}const Es={"+":bi,"-":vi,"*":Ms,"/":(e,t)=>ys(t)?Ms(e,ws.inverse(t)):$i(e,t),"^":function(e,t){if(!ys(e))return Mi(e,t);const n=Vr(t);if(null===n)throw new wr("a matrix to a power that is not a whole number");return ws.power(e,n)},"±":(e,t)=>Qr([bi(e,t),vi(e,t)],"pm"),mod:fi(hs),log:fi(function(e,t){if(Gr(e)&&Kr(e,Ur))return rs(t);const n=ti(e),r=ti(t);if(n<=0||1===n)throw new vr("not a valid base");if(r<=0)throw new vr(0===r?"log 0 is undefined":"not a real number");const i=Math.log(r)/Math.log(n);if(Hr(e)&&Hr(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=ui(e,BigInt(r)),o=ui(t,n);if(s&&o&&Kr(s,o))return Br(zr(BigInt(r),n))}return i}),root:fi((e,t)=>Mi(t,$i(Wr(1),e))),atan2:(e,t)=>Math.atan2(ti(e),ti(t)),round:cs,fixed:function(e,t){const n=Number(ss(t,"fixed"));if(n<0)throw new vr("fixed needs 0 or more decimal places");const r=cs(e,t);if(Hr(r)){const e=r.c.n*10n**BigInt(n)/r.c.d,t=(e<0n?-e:e).toString().padStart(n+1,"0");return Jr(`${e<0n?"-":""}${t.slice(0,t.length-n)}${n?"."+t.slice(-n):""}`)}return Jr(us(ti(r),n))},perm:function(e,t){const n=ss(e,"permutations"),r=ss(t,"permutations");if(r<0n||r>n)throw new vr("undefined");if(r>BigInt(xr.terms)||os(n,r))throw new wr("too large to calculate");Ar(r,Number(r)*Or(n));let i=1n;for(let e=n-r+1n;e<=n;e++)i*=e;return Br(zr(i))},comb:function(e,t){const n=ss(e,"combinations");let r=ss(t,"combinations");if(r<0n||r>n)throw new vr("undefined");if(n-r<r&&(r=n-r),r>BigInt(xr.terms)||os(n,r))throw new wr("too large to calculate");Ar(2n*r,Number(r)*Or(n));let i=1n;for(let e=1n;e<=r;e++)i=i*(n-r+e)/e;return Br(zr(i))},"=":(e,t)=>Qi(e,t),"===":(e,t)=>Qi(e,t),"≠":(e,t)=>!Qi(e,t),"≠=":(e,t)=>!Qi(e,t),"≈":(e,t)=>Math.abs(ti(e)-ti(t))<=1e-9*Math.max(1,Math.abs(ti(e)),Math.abs(ti(t))),"<":(e,t)=>Vi(e,t)<0,">":(e,t)=>Vi(e,t)>0,"≤":(e,t)=>Vi(e,t)<=0,"≥":(e,t)=>Vi(e,t)>=0,"&":(e,t)=>ri(e)&&ri(t),"|":(e,t)=>ri(e)||ri(t),"\\xor":(e,t)=>ri(e)!==ri(t),"\\nor":(e,t)=>!(ri(e)||ri(t)),"\\nand":(e,t)=>!(ri(e)&&ri(t)),"\\implies":(e,t)=>!ri(e)||ri(t),"\\iff":(e,t)=>ri(e)===ri(t)},_s={sum:e=>e.reduce((e,t)=>bi(e,t),Wr(0)),prod:e=>e.reduce((e,t)=>wi(e,t),Wr(1)),max:e=>e.reduce((e,t)=>Vi(t,e)>0?t:e),min:e=>e.reduce((e,t)=>Vi(t,e)<0?t:e),mean:e=>$i(_s.sum(e),Wr(e.length)),gcd:e=>Br(zr(e.map(e=>ss(e,"gcd")).reduce(Ir)))},Os=["∈","∉","∪","∩","pmod","random","(]","[)"];function Is(e,t){if(++Mr>xr.steps)throw new wr("too much to work out");switch(e.type){case"number":return Br(Pr(e.value));case"string":return Jr(e.value.slice(1,-1));case"symbol":return zs(e.value,t)}const n=K(e);if(n)return Is(n,t);const{op:r,args:i}=e,s=e=>Is(e,t);if("?:"===r)return ri(s(i[0]))?s(i[1]):s(i[2]);if("_"===r){if(i.every(e=>"op"!==e.type))return zs(`${i[0].value}_${i[1].value}`,t);throw new wr("subscript")}if("der"===r)return function(e,t){const[n,r]=e.args;if("op"===r.type&&"="===r.op){const e=Zs(r.args[0]);if(!e)throw new wr("a derivative at a point names its variable: der(f, x = a)");return js(n,e,ti(Is(r.args[1],t)),t)}const i=Zs(r);if(!i||!t[Ss]?.has(i))throw new wr(`a derivative needs a point: der(f, ${i||"x"} = a)`);return js(n,i,ti(t[i]),t)}(e,t);if("evaluated"===r){const[e,n,r,o]=i;return vi(Is(e,qs(t,n.value,s(o))),Is(e,qs(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]=[Zs(r),i,s];else{if(3!==e.length||o(r))throw new wr("an integral needs limits to be calculated");[a,l,c]=[z(n)||"x",r,i]}let u=ti(Is(l,t)),h=ti(Is(c,t));if(u===h)return Wr(0);let p=1;u>h&&([u,h]=[h,u],p=-1);const f=Fs(n,a,t),{value:m,error:d}=Cs(f,u,h);return Bs(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]=[Zs(r.args[0]),r.args[1]];else if(2===e.length)[o,a]=[z(n),r];else{if(!(e.length>=3))throw new wr("a limit needs a point");[o,a]=[Zs(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 wr("a limit needs a variable");const c=Is(a,t),u=ti(c),h=Fs(n,o,t);let p,f;if(Number.isFinite(u))if(l){({value:p,error:f}=Ts(e=>h(u+l*e*Math.max(1,Math.abs(u)))));try{const e=Is(n,qs(t,o,c));if(Math.abs(ti(e)-p)<=Math.max(f,1e-6*Math.max(1,Math.abs(p))))return e}catch(e){if(!(e instanceof vr))throw e}}else{const e=Ts(e=>h(u+e*Math.max(1,Math.abs(u)))),r=Ts(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 vr("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=Is(n,qs(t,o,c));if(Math.abs(ti(e)-p)<=1e-6*Math.max(1,Math.abs(p)))return e}catch(e){if(!(e instanceof vr))throw e}}else({value:p,error:f}=Ts(e=>h(Math.sign(u)/e)));return Number.isFinite(p)?Bs(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 wr("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=z(r)||"n";const l=ss(Is(a,n),"a sum"),c=Is(s,n),u=e?bi:wi;if(c===1/0){if(!e)throw new wr("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 vr("undefined");i+=t}if(n.push(a),r.push(i),o>=6&&r[r.length-1]===r[r.length-2]&&!Ps(e,t,s))return Bs(i,0)}if(Ps(e,t,s))throw new vr("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 vr("the series diverges");if(Math.abs(o)>1e-6*Math.max(1,Math.abs(i))&&c>=.9)throw new wr("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 Bs(m,Math.abs(m-d))}(Fs(r,o,n),Number(l))}const h=ss(c,"a sum");if(h-l+1n>BigInt(xr.terms))throw new wr("too many terms to add one by one");let p=Wr(e?0:1);for(let e=l;e<=h;e++)p=u(p,Is(r,qs(n,o,Br(zr(e)))));return p}("\\sumidx"===r,i,t);if(["()","[]","{}"].includes(r))return Qr(i.map(s),r);if("pmatrix"===r||"bmatrix"===r)return Ns(e,s);if("vmatrix"===r)return As(Ns(e,s));if("^"===r&&"symbol"===i[1].type&&"T"===i[1].value&&!Object.prototype.hasOwnProperty.call(t,"T")){const e=s(i[0]);if(ys(e))return ws.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?Xr(hs(vi(n(e.args[0]),n(e.args[1])),r)):hs(n(e),r)}(i,s);if("setbuilder"===r)throw new wr("a set described by a condition has no list of values");if(F(e))return s(F(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)&&Gr(i))s="ℝ"===r.value||("ℚ"===r.value?Hr(i):Hr(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=Vi(i,e),a=Vi(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=>Qi(i,t(e)))}return"∈"===e.op?s:!s}(e,s);if(void 0!==t)return t}if(Os.includes(r))return function(e,t){const n={};for(const[e,r]of Object.entries(t))"function"!=typeof r&&(n[e]=si(r));try{return ii(function(e,t={}){0===gr&&(dr=0),gr++;try{return br(Jn(e),t)}finally{gr--}}(e,n))}catch(e){throw new wr(e.message)}}(e,t);if(r.startsWith("\\:")){const e=r.slice(2),n=Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0;if("function"!=typeof n&&Object.prototype.hasOwnProperty.call(ks,e))return ks[e](...i.map(s));if("function"!=typeof n)throw new wr(`no function ${r.slice(2)}`);return ii(n(...i.map(e=>si(s(e)))))}if(ds[r]&&1===i.length)return ds[r](s(i[0]));if(Es[r]&&2===i.length)return Es[r](s(i[0]),s(i[1]));if(_s[r])return _s[r](i.map(s));throw new wr(`can't calculate '${r}'`)}function zs(e,t){if(Object.prototype.hasOwnProperty.call(t,e))return t[e];if(Object.prototype.hasOwnProperty.call(ms,e))return ms[e]();if(Z(e))return Br(Pr(Z(e)));if("i"===e)return Oi();if(/^[A-Za-z\u0370-\u03FF][A-Za-z0-9_\u0370-\u03FF′]*$/.test(e))return zi([{vars:[[e,1]],re:Wr(1),im:Wr(0)}]);throw new wr(`no value for '${e}'`)}const Ss=Symbol("bound"),qs=(e,t,n)=>({...e,[t]:n,[Ss]:new Set([...e[Ss]??[],t])});function Fs(e,t,n){return r=>{try{return ti(Is(e,qs(n,t,r)))}catch(e){if(e instanceof vr)return NaN;if(e instanceof $r)return 0;throw e}}}const Zs=e=>"symbol"===e.type?e.value:null;function js(e,t,n,r){const i=Fs(e,t,r);if(!Number.isFinite(i(n)))throw new vr("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 vr("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 vr("not differentiable here");return Bs(h,p)}function Cs(e,t,n){if(t===-1/0&&n===1/0){const t=Cs(e,-1/0,0),n=Cs(e,0,1/0);return{value:t.value+n.value,error:t.error+n.error}}return n===1/0?Ls(n=>e(t+n/(1-n))/((1-n)*(1-n)),0,1):t===-1/0?Ls(t=>e(n-t/(1-t))/((1-t)*(1-t)),0,1):Ls(e,t,n)}function Ls(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 vr("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 vr("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 vr("the integral does not converge");return{value:a,error:h}}(e,t,n)}catch(e){if(!(e instanceof vr)||"the integral does not converge"!==e.message||r>=10)throw e}const i=(t+n)/2,s=Ls(e,t,i,r+1),o=Ls(e,i,n,r+1);return{value:s.value+o.value,error:s.error+o.error}}function Ts(e){const t=Rs(e),n=Rs(t=>e(.7548776662466927*t));if(t.value===n.value)return t;if(!Number.isFinite(t.value)||!Number.isFinite(n.value))throw new vr("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 vr("the limit could not be found");if(Math.abs(t.value-n.value)<=i)return t;throw new vr("the limit does not exist")}function Rs(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 vr("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 vr("the limit could not be found")}return s}function Ps(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 Bs(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 Wr(0);if(Math.abs(e)<1e-10)return e;const r=[[Wr(1),1e3],[Dr,100],[Br(qr,2),100],[Ur,100],...[2n,3n,5n,6n,7n].map(e=>[Br(qr,0,0,{n:2,r:e}),100])];for(const[t,i]of r){const r=e/ti(t),s=Ws(r,i);if(s&&Math.abs(Number(s.n)/Number(s.d)-r)*ti(t)<=n)return li(Br(s),t)}return e}function Ws(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?zr(BigInt(r),BigInt(s)):null}function Ds(e,t){if("boolean"==typeof e)return String(e);if(Ei(e))return Us(e,t);if(e&&"s"===e.kind)return JSON.stringify(e.text);if(Array.isArray(e)){if("pm"===e.group&&2===e.length&&Qi(e[1],yi(e[0])))return`±${Hs(e[0],t)}`;if(bs.has(e.group)&&ne(e))return`${e.group}(${e.map(e=>`[${e.map(e=>Ds(e,t)).join(", ")}]`).join(", ")})`;const[n,r]={"()":"()","[]":"[]","{}":"{}"}[e.group]||"{}";return n+e.map(e=>Ds(e,t)).join(", ")+r}return"number"==typeof e?Xs(e,t):t.decimal||null!==t.places?function(e,t){if(Hr(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=Er(n).toString().padStart(s+1,"0"),o=s?`${i.slice(0,-s)}.${i.slice(-s)}`:i;if(i.length<=t.maxDigits)return(r?"-":"")+Vs(o)}}return Hr(e)&&null!==t.places?Ds(cs(e,Wr(t.places)),{...t,places:null,decimal:!0}):Xs(ti(e),t)}(e,t):function(e,t){const{c:n}=e,r=Er(n.n);if(r.toString().length>t.maxDigits||n.d.toString().length>t.maxDigits)return function(e,t){if(!Hr(e))return Xs(ti(e),t);if(1n!==e.c.d){const n=ti(e);if(0!==n&&Number.isFinite(n))return Xs(n,t);const r=Er(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=Vs(`${a[0]}.${a.slice(1,t.digits)}`);return`${e.c.n<0n?"-":""}${c}*10^(${l})`}const n=Er(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=Vs(`${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 Us(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=Ii(e.vars);if(!n)return Gs(e.re,e.im,t);if(!Xr(e.im))return`(${Gs(e.re,e.im,t)})*${n}`;const r=e.re,i=Ds(r,t);if("1"===i)return n;if("-1"===i)return`-${n}`;if(Hr(r)&&1n!==r.c.d&&!t.decimal&&null===t.places){const e=Er(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 Gs(e,t,n){if(Xr(t))return Ds(e,n);const r=!Xr(t)&&Vi(t,Wr(0))<0,i=Ds(r?di(t):t,n),s="1"===i?"i":/^[\d.]+$/.test(i)?`${i}*i`:`(${i})*i`;return Xr(e)?r?`-${s}`:s:`${Ds(e,n)} ${r?"-":"+"} ${s}`}const Hs=(e,t)=>{const n=Ds(e,t);return/^[\d.]+$|^[a-zπ]+$/i.test(n)?n:`(${n})`};function Xs(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 us(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`${Vs(n)}*10^(${Number(r)})`}return String(Number(e.toPrecision(t.digits)))}const Vs=e=>e.includes(".")?e.replace(/\.?0+$/,""):e;function Qs(e,t={},n={}){0===Nr&&(Mr=0);const r="string"==typeof e?Qn(e):O(e),i={};for(const[e,n]of Object.entries(t))i[e]=ii(n);Nr++;const s=Ai;let o,a=!1;I(r,e=>{"symbol"!==e.type||"i"!==e.value||Object.prototype.hasOwnProperty.call(t,"i")||(a=!0)}),Ai=n.complex??(a||Nr>1&&s);try{o=Is(r,i)}finally{Nr--,Ai=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<=xr.places))throw new wr(`places is a whole number from 0 to ${xr.places}`);const c=e=>Array.isArray(e)?e.every(c):Ei(e)?[...e.terms.values()].every(e=>"number"!=typeof e.re&&"number"!=typeof e.im):"number"!=typeof e;return{value:si(o),text:Ds(o,l),exact:c(o)}}function Js(e,t={}){let n=e.trim();const r={},i=/^(~|≈)\s*(\d+)?/.exec(n);i&&(r.decimal=!0,void 0!==i[2]&&(r.places=Number(i[2])),n=n.slice(i[0].length)),/\d\.\d|\.\d/.test(n)&&(r.decimal=!0);try{const{text:e}=Qs(n,t,r);return e.startsWith('"')||/^\d+(\.\d+)?$/.test(e)?e:`(${e})`}catch(e){if(e instanceof vr)return'"undefined"';if(e instanceof wr)return`(${n})`;throw e}}Xn=Js;for(const e of[xr,Ji,ms,ds,Es,_s])Object.setPrototypeOf(e,null);Object.setPrototypeOf(ks,null);const Ys=e=>"op"===e.type&&o(e.op)&&["vec","hat"].includes(V(e.op)),Ks={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"]},eo={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"},to=Object.fromEntries(Object.entries(S).map(([e,t])=>[t,e]));function no(e,t={}){return ro(function(e,t={}){return function(e,t,n){const r=new oo({...Ks,...t.words},{...eo,...t.names},t.say||{},n);return function(e){let t=e.length;for(;t>0&&(e[t-1].close||!e[t-1].text.replace(/,/g,"").trim());)t--;const n=[];for(const{text:r,id:i}of e.slice(0,t)){const e=r.trim();if(!e)continue;const t=e.startsWith(","),s=t?e.slice(1).trim():e;t&&n.length&&!n[n.length-1].text.endsWith(",")&&(n[n.length-1].text+=","),s&&n.push({text:s,id:i})}n.length&&(n[n.length-1].text=n[n.length-1].text.replace(/,$/,""));return n}(r.speak(e))}(e,t,!0)}(e,t))}function ro(e){return e.map(e=>e.text).join(" ").replace(/\s+/g," ").replace(/ ,/g,",").replace(/,(\s*,)+/g,",").replace(/^,\s*/,"").replace(/,\s*$/,"").trim()}const io={"=":"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"},so={"ℝ":"reals","ℤ":"integers","ℕ":"naturals","ℚ":"rationals","ℂ":"complexes"};class oo{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=>ro(this.speak(e))):[e.value],e,e=>ro(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(so[e])return t[so[e]];if(to[e])return to[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(io[t])return[...this.speak(r),a(s[io[t]]),...this.speak(i)];if(o(t)){if(1===n.length&&"symbol"===r.type&&"vec"===V(t))return[a(s.vector),...this.speak(r)];if(1===n.length&&"symbol"===r.type&&"hat"===V(t))return[...this.speak(r),a(s.hat)];const e=this.symbol(V(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 j(i)?[...this.leftSide(r),a(s.minus),...this.quantityIfSum(i.args[1])]:[...this.leftSide(r),a(s.plus),...this.speak(i)];case"-":return j(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):ro(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:`${ro(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 te(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=te(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(j(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(Ys))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)&&!S[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)&&!j(e);return[...this.grouped(t,null,s(t,"/")),...this.isCall(t)?[i(r.comma)]:[],i(r.over),...this.grouped(n,"endFraction",s(n,"/"))]}power(e){const[t,n]=e.args,r=this.w,i=t=>this.seg(e,t),s=this.isCompound(t)||this.isCall(t)||"number"===t.type&&t.value.startsWith("-")||"op"===t.type&&"/"===t.op||this.audio&&"op"===t.type&&("^"===t.op||"neg"===t.op||j(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}=Q(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(z(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=z(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[Ks,eo,io,so,to])Object.setPrototypeOf(e,null);function ao(e,t={}){return(e=>Array.isArray(e)&&0===e.length)(e)?"":no(Jn(e),t)}const lo={"(":{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 co(e,t,n=""){const r=lo[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 uo=.8,ho=.2,po=.25,fo=.7,mo="−",go={"+":"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"},bo={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},yo={"±":"±","∪":"∪","∩":"∩",mod:"mod"},vo=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],wo={arcsin:"sin",arccos:"cos",arctan:"tan",arcsec:"sec",arccsc:"csc",arccot:"cot",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},$o=[...vo,...Object.keys(wo),"ln","det"],xo={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},Mo={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},ko=["int","lim","\\sumidx","\\prodidx"],Ao={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},No={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},Eo=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,_o=e=>"symbol"===e?.type&&Eo.test(S[e.value]??e.value),Oo=["boxed","overline","bar","underline","cancel",...Object.keys(No)],Io={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},zo=e=>String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),So=e=>+e.toFixed(3)+"em",qo=(e,t=uo,n=ho)=>({html:e,h:t,d:n});function Fo(...e){const t=e.flat().filter(Boolean);return{html:t.map(e=>e.html).join(""),h:Math.max(uo,...t.map(e=>e.h)),d:Math.max(ho,...t.map(e=>e.d))}}function Zo(e,t={}){const n=new jo({...Io,...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):ao(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="${zo(o)}"`}>${a}${s}</span>`,h:r.h,d:r.d}}class jo{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=qo(this.el(e,zo(t)));return n.leaf={kind:e,content:zo(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="${zo(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}="${zo(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?[zo(i.class)]:[]).join(" "),a=n.leaf?n.leaf.content:n.html;return{html:`<span class="${o}"${s?` style="${zo(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(/^-/,mo)),a=this.text("num",r.slice(-i));return this.wrap(e,["number"],Fo(o,qo(this.el("over",a.html),a.h+.14,a.d)))}return this.wrap(e,["number"],this.text("num",e.value.replace(/^-/,mo)))}symbol(e){return S[e]&&(e=S[e]),Ao[e]?this.text("ord",Ao[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)?qo(this.el("var",zo(e[0]))+this.el("prime",zo(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?qo(this.el("ord","Δ")+this.el("var",e[1])):/^d[A-Za-zα-ω]$/.test(e)?qo(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=go[n]??(/^[a-z0-9]+$/i.test(n)?n:"other"),u=t=>this.wrap(e,["op",`op-${l}`],t),h=(t,n)=>T(e,t,n)&&"/"!==t.op?this.fence(a(t)):a(t);if($o.includes(n)||"log"===n)return u(this.named(e,t));if(xo[n])return u(Fo(this.word(xo[n]),this.fence(this.list(r,t))));if(o(n))return u(this.custom(e,t));const p=te(e);if(p)return u(this.matrix(e,p,t));if("{}"===n&&!r.length)return u(this.text("op","∅"));if(Mo[n])return u(this.fence(this.list(r,t),...Mo[n]));if(("|"===n||"&"===n)&&r.length>=2&&r.every(To)){const e=e=>"|"!==e.op&&"&"!==e.op||e.op===n?a(e):this.fence(a(e));return u(Fo(r.map((t,r)=>r?[this.text("conj","|"===n?"or":"and"),e(t)]:[e(t)]).flat()))}if(bo[n]&&2===r.length)return u(Fo(h(i,"left"),this.rel(bo[n]),h(s,"right")));if(yo[n]&&2===r.length)return u(Fo(h(i,"left"),this.bin(yo[n]),h(s,"right")));switch(n){case"+":if(j(s)){const e=s.args[1],t=T({op:"-"},e,"right")?this.fence(a(e)):a(e);return u(Fo(h(i,"left"),this.bin(mo),this.wrap(s,["op","op-mul"],t)))}return"number"===s.type&&s.value.startsWith("-")?u(Fo(h(i,"left"),this.bin(mo),this.wrap(s,["number"],this.text("num",s.value.slice(1))))):u(Fo(h(i,"left"),this.bin("+"),this.signed(s,h(s,"right"))));case"-":return u(Fo(h(i,"left"),this.bin(mo),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=C(i)&&c(C(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(Fo(this.text("sign",mo),R(n,i)?this.fence(a(i)):a(i,{before:t.before})));case"pm":return u(Fo(this.text("sign","±"),R(n,i)?this.fence(a(i)):a(i)));case"!":return u(Fo(R(n,i)?this.fence(a(i)):a(i,{forceParens:!0}),this.text("ord","!")));case"\\not":return u(Fo(this.text("sign","¬"),R(n,i)?this.fence(a(i)):a(i)));case"pmod":return u(Fo(a(i),this.fence(Fo(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(Fo(this.word("ln"),this.fence(Fo(this.word("ln"),this.fence(a(i))))));case"logloglog":return u(Fo(this.word("ln"),this.fence(Fo(this.word("ln"),this.fence(Fo(this.word("ln"),this.fence(a(i))))))));case"perm":return u(this.script(this.script(qo(""),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):Fo(a(i),this.bin("?"),a(s),this.bin(":"),a(r[2])));case"sum":case"prod":{const e={op:"sum"===n?"+":"*"},t=(t,n)=>T(e,t,n?"right":"left")?this.fence(a(t)):a(t);return u(Fo(r.map((e,r)=>r?[this.bin("sum"===n?"+":"·"),t(e,r)]:[t(e,r)]).flat()))}case"setbuilder":return u(this.fence(Fo(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 Fo(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(j(e))return Fo(this.text("sign",mo),R("neg",r)?this.fence(this.render(r,t)):this.render(r,t));const i=function(e){const[t,n]=e.args;return{left:T(e,t,"left")&&"/"!==t.op,right:T(e,n,"right")&&"/"!==n.op}}(e);ko.includes(n.op)&&(i.left=!0);const s=!e.written&&P(n,r,i),a=function(e){for(;"op"===e.type;){if($o.includes(e.op)||"log"===e.op||xo[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 Fo(l,s?qo(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=wo[r]&&"power"===this.o.inverseTrig?this.script(this.word(wo[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&&Co(s),l=this.render(s,{...t,forceParens:!1,before:!1});return Fo(o,a?Fo(qo(this.el("fnspace","")),l):this.fence(l))}custom(e,t){const n=V(e.op),r=e.args;if(Oo.includes(n)&&1===r.length)return this.decorate(n,this.render(r[0],t),r[0]);return Fo(/^[A-Za-z]′*(⁻¹)?$/.test(n)?this.symbol(n):this.word(n),qo(this.el("callgap","")),this.fence(this.list(r,t)))}decorate(e,t,n){switch(e){case"boxed":return qo(this.el("boxed",t.html),t.h+.22,t.d+.22);case"cancel":return qo(this.el("cancel",t.html+co("cancel",`${this.p}-cancel-line`)),t.h,t.d);case"underline":return qo(this.el("underline",t.html),t.h,t.d+.12);case"overline":case"bar":return qo(this.el("over"+(_o(n)?" over-low":""),t.html),t.h+.14,t.d);default:{const r=_o(n);return qo(this.el("accent"+(r?" accent-low":""),this.el(`accent-mark accent-${e}`,No[e])+t.html),t.h+.3,t.d)}}}fraction(e,t){const[n,r]=e.args;if(t.level>0&&"slash"===this.o.scriptFractions&&Co(n,!0)&&Co(r,!0)){const e={...t,leftFactor:!1},i=(t,n)=>"op"!==t.type||Co(t)&&(!n||"*"!==t.op||j(t))?this.render(t,e):this.fence(this.render(t,e)),s=Fo("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:${So(r)}`),s=n?.06:0,o=po+s/2+.1+Math.max(ho,r*e.d),a=this.el("frac"+(n?"":" frac-nobar"),this.el("numer",i(e))+this.el("denom",i(t)),`vertical-align:${So(o)}`);return qo(a,o+Math.max(uo,r*e.h),Math.max(uo,r*t.h)+Math.max(ho,r*t.d)+.1+s/2-po)}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&&vo.includes(n.op)&&Po(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=T(e,n,"left")||"number"===n.type&&n.value.startsWith("-")||"/"===n.op||$o.includes(n.op)||ko.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:fo,o=i?Fo(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:${So(s)}`);if(t&&!r)return qo(e.html+this.el("sup",t.html,`font-size:${So(s)};vertical-align:${So(a/s)}`),Math.max(o.h,a+s*t.h),Math.max(o.d,s*t.d-a));if(r&&!t)return qo(o.html+this.el("sub",r.html,`font-size:${So(s)};vertical-align:${So(-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:${So(a)};height:${So(u+h)}`);return qo(o.html+p,Math.max(o.h,u),Math.max(o.d,h))}radical(e,t=null){const n=Math.max(e.h,uo)+.1+.06,r=Math.max(e.d,ho),i=n+r,s=.5+.06*(i-1),o=co("sqrt",`${this.p}-hook`,`width:${So(s)};left:${So(-s)}`);let a="";if(t){const e=.8*fo;a=this.el("rootindex",t.html,`font-size:${So(e)};vertical-align:${So((.55*i-r)/e)}`)}return qo(this.el("sqrt",a+this.el("radicand",o+e.html,`margin-left:${So(s+.05)}`)),n,r)}fence(e,t="(",n=")"){const r=Math.max(e.h,uo)+Math.max(e.d,ho),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:co(e,`${this.p}-delim ${this.p}-delim-${t}`,`width:${So(s)}`),w:s+.1}}const s={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[e];return{html:this.el(`delim ${s} delim-${t}`,""),w:"|"===e?.18:.3}},a=o(t,"l"),l=o(n,"r"),c=`padding:${So(s)} ${So(l.w)} ${So(s)} ${So(a.w)}`,u=qo(this.el("fence",a.html+e.html+l.html,c),Math.max(e.h,uo)+s,Math.max(e.d,ho)+s);return u.fenced=!0,u}derivative(e,t){const n=this.leibniz(e,t),{by:r,at:i}=Q(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}=Q(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=Fo(a(),l()?this.script(this.render(i,u),l(),u):this.render(i,u)),p=e=>Fo(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=C(r)&&c(C(r))<100,[d,g]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],b=m?this.fence(this.render(r,t),d,g):this.render(r,t);return Fo(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",z(n)||"x");let c,u=null,h=null;switch(e.length){case 1:c=l();break;case 2:X(r)?c=o(r):(c=l(),u=a(r));break;case 3:X(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=qo(this.el("dx",this.el("d","d")+c.html),c.h,c.d);return Fo(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-po,t.d+po)+.12),a=co(e,`${this.p}-bigsign ${this.p}-${e}sign`,`height:${So(2*o)};width:${So(s?.38:.5)};vertical-align:${So(po-o)}`);if(!n&&!r)return qo(a,po+o,o-po);const l=fo,c=r||qo(""),u=n||qo(""),h=po+o-l*c.h;u.d;const p=this.el("limits",this.el("script",c.html,`font-size:${So(l)}`)+this.el("script lower",u.html,`font-size:${So(l)}`),`vertical-align:${So(h)};height:${So(2*o)}`);return qo(a+p,po+o,o-po)}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 Fo(this.word("lim"),qo(this.el("fnspace","")),this.body(n,t));case 2:{const e=z(n),t="number"===r.type||"symbol"===r.type&&r.value.includes("∞");c=e&&t?Fo(this.text("var",e),l(),a(r)):a(r);break}case 3:c=Fo(a(r),l(),a(i));break;default:{const e=q(s).toLowerCase().startsWith("r")?"+":mo;c=Fo(a(r),l(),this.script(a(i),this.wrap(s,["symbol"],this.text("ord",e)),o))}}return Fo(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):qo(this.el("under",e.html+this.el("script",t.html,`font-size:${So(.7)}`)),e.h,Math.max(e.d,ho)+.05+.7*(t.h+t.d))}body(e,t){const n=C(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=co(e,`${this.p}-bigsign`,`height:${So(2*t)};width:${So(.8)};vertical-align:${So(po-t)}`);return Fo(this.script(qo(r,po+t,t-po),l,n,a),c)}const u=.68,h=fo,p=co(e,`${this.p}-bigsign`,`height:${So(1.36)};width:${So("sum"===e?1:1.05)}`),f=l?1.01+h*l.d:po-u,m=e=>this.el("script",e.html,`font-size:${So(h)}`),d=this.el("bigop",(l?m(l):"")+p+(a?m(a):""),`vertical-align:${So(f)}`);return Fo(qo(d,.93+(l?.08+h*(l.h+l.d):0),u-po+(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(uo,...e.map(e=>e.h)),d:Math.max(ho,...e.map(e=>e.d))})),s=i.reduce((e,t)=>e+t.h+t.d,0)+.3*(t.length-1),o=po+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"],qo(r)).html:r}).join(""),l=t[0].length,c=qo(this.el("matrix",a,`grid-template-columns:repeat(${l},auto);vertical-align:${So(o)}`),po+s/2,s/2-po),[u,h]=ee[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),Fo(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=po+s/2-i[0].h,a=n.map(([e,t])=>this.el("case-value",e.html)+this.el("case-cond",t.html)).join(""),l=qo(this.el("cases",a,`vertical-align:${So(o)}`),po+s/2,s/2-po);return this.fence(l,"{","")}}function Co(e,t=!1){return"number"===e.type?!e.value.startsWith("-")||t:"symbol"===e.type||"op"===e.type&&("abs"===e.op||te(e)?!t:!t||"neg"!==e.op&&"^"!==e.op?"*"===e.op&&!j(e)&&e.args.every(e=>"number"===e.type&&!e.value.startsWith("-")||Ro(e)||"*"===e.op&&Co(e,t)):Co(e.args[0],!0)&&("neg"===e.op||Co(e.args[1],!0)))}const Lo=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],To=e=>"op"===e.type&&e.args.length>=2&&(2===e.args.length&&Lo.includes(e.op)||("|"===e.op||"&"===e.op)&&e.args.every(To)),Ro=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(S[e.value])),Po=e=>"number"===e.type&&/^[1-9]\d*$/.test(e.value)&&Number(e.value)<10;for(const e of[go,bo,yo,wo,xo,Mo,Ao,No])Object.setPrototypeOf(e,null);const Bo=e=>_(e).join(" ");function Wo(e,t){const n=new Set;Do(e,t,n);const r=[];return I(e,e=>{n.has(e)&&r.push(e)}),r}function Do(e,t,n){if(null!=t)if(Array.isArray(t))t.forEach(t=>Do(e,t,n));else if("number"!=typeof t)if("function"!=typeof t){if("string"==typeof t){const r=Bo(Qn(t));return void I(e,e=>{Bo(e)===r&&n.add(e)})}if(t.path){const r=function(e,t){let n=e;for(const e of t){if("op"!==n.type||!n.args[e])return null;n=n.args[e]}return n}(e,t.path);return void(r&&n.add(r))}if(t.type){const r=Bo(t);I(e,e=>{e!==t&&Bo(e)!==r||n.add(e)})}}else I(e,(e,r)=>{t(e,r)&&n.add(e)});else I(e,e=>{e.id===t&&n.add(e)})}function Uo(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 Go(e,t={}){const{blocks:n}=t;if("string"==typeof e)return Qn(e,n?{blocks:e=>n(e,t.scope)}:{});if(Array.isArray(e))return E(e);if(e&&"object"==typeof e&&e.type){if(void 0!==e.id)return e;const t=structuredClone(e);return I(t,e=>{"op"!==e.type&&void 0!==e.value&&(e.value=String(e.value))}),Uo(t)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function Ho(e,t={}){const n=Go(e,t);return Zo(n,function(e,t){const{colors:n,highlight:r,scope:i,blocks:s,...o}=t,a=new Map;for(const[t,r]of function(e){return e?Array.isArray(e)?e:Object.entries(e).map(([e,t])=>[/^\d+$/.test(e)?Number(e):e,t]):[]}(n))if(Xo(r))for(const n of Wo(e,t))a.set(n,`color:${r}`);const l=new Set(void 0===r?[]:Wo(e,r));if(!a.size&&!l.size)return o;const c=o.prefix||"mv";return{...o,style:e=>[a.get(e),o.style&&o.style(e)].filter(Boolean).join(";"),attributes:e=>{const t={...o.attributes?o.attributes(e):{}};return l.has(e)&&(t.class=[t.class,`${c}-hl`].filter(Boolean).join(" ")),t}}}(n,t)).html}function Xo(e){return"string"==typeof e&&/^[#\w\s.,%()/+-]+$/.test(e)&&!/url\s*\(|expression/i.test(e)}var Vo='/*\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\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 Qo=Vo;if("undefined"!=typeof document&&!document.getElementById("inlinemath-css")){const e=document.createElement("style");e.id="inlinemath-css",e.textContent=Vo,document.head.append(e)}return e.CSS=Qo,e.DEFAULTS=Io,e.calculate=Qs,e.calculateBlock=Js,e.layout=Zo,e.numberTree=Uo,e.select=Wo,e.toHTML=(e,t={})=>Ho(e,{...t,blocks:t.blocks??Js}),e.treeOf=(e,t={})=>Go(e,{...t,blocks:t.blocks??Js}),e}({});
|