@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
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
import{j as t,k as n,r as e,m as r,o,h as i,q as a,u as s,w as u,v as c}from"./lite-6yr4ed_k.js";function l(t){return Array.isArray(t)&&t.length>0&&t.every(n=>Array.isArray(n)&&n.length>0&&n.length===t[0].length&&!n.some(Array.isArray))}const f=t=>Array.isArray(t)&&t.length>0&&!t.some(Array.isArray);function h(t){const n=t,e=n.make??(t=>t),r=n.size??(()=>1),o=n.charge??(()=>{}),i=t=>`${t.length} by ${t[0].length}`,a=(t,r)=>e(Array.from({length:t},(e,r)=>Array.from({length:t},(t,e)=>r===e?n.one():n.zero())),r);function s(t,r){return t[0].length!==r.length&&n.fail(`a ${i(t)} matrix times a ${i(r)} one`),o(t.length*r.length*r[0].length),e(t.map(t=>r[0].map((e,o)=>t.reduce((t,e,i)=>n.add(t,n.mul(e,r[i][o])),n.zero()))),t)}function u(t){const e=t.map(t=>t.slice()),i=e.length,a=e[0].length;o(i*i*a);let s=n.one(),u=0;for(let t=0;t<a&&u<i;t++){let o=-1;for(let a=u;a<i;a++)n.isZero(e[a][t])||(o<0||r(e[a][t])>r(e[o][t]))&&(o=a);if(o<0){s=n.zero();continue}o!==u&&([e[o],e[u]]=[e[u],e[o]],s=n.sub(n.zero(),s));const a=e[u][t];s=n.mul(s,a),e[u]=e[u].map(t=>n.div(t,a));for(let r=0;r<i;r++){if(r===u||n.isZero(e[r][t]))continue;const o=e[r][t];e[r]=e[r].map((t,r)=>n.sub(t,n.mul(o,e[u][r])))}u++}return u<i&&(s=n.zero()),{M:e,det:s,rank:u}}function c(t){const r=t.length;r!==t[0].length&&n.fail(`a ${i(t)} matrix has no inverse`);const o=a(r),{M:s,rank:c}=u(t.map((t,n)=>[...t,...o[n]]));return(c<r||s.some((t,e)=>n.isZero(t[e])))&&n.fail("the matrix has no inverse (its determinant is 0)"),e(s.map(t=>t.slice(r)),t)}return{identity:a,transpose:t=>e(t[0].map((n,e)=>t.map(t=>t[e])),t),times:s,det:function(t){return t.length!==t[0].length&&n.fail(`a ${i(t)} matrix has no determinant`),u(t).det},inverse:c,power:function(t,e){t.length!==t[0].length&&n.fail(`a ${i(t)} matrix has no powers`);let r=e<0n?c(t):t,o=e<0n?-e:e,u=a(t.length,t);for(;o>0n;)1n&o&&(u=s(u,r)),r=s(r,r),o>>=1n;return u},trace:t=>(t.length!==t[0].length&&n.fail(`a ${i(t)} matrix has no trace`),t.reduce((t,e,r)=>n.add(t,e[r]),n.zero())),dot:(t,e)=>(t.length!==e.length&&n.fail("vectors of different lengths"),t.reduce((t,r,o)=>n.add(t,n.mul(r,e[o])),n.zero())),cross:(t,e)=>(3===t.length&&3===e.length||n.fail("the cross product is for vectors of 3 numbers"),[n.sub(n.mul(t[1],e[2]),n.mul(t[2],e[1])),n.sub(n.mul(t[2],e[0]),n.mul(t[0],e[2])),n.sub(n.mul(t[0],e[1]),n.mul(t[1],e[0]))]),solve:function(t,n){return l(n)?s(c(t),n):s(c(t),n.map(t=>[t])).map(t=>t[0])},rank:t=>u(t).rank,rref:t=>e(u(t).M,t),timesVector:(t,n)=>s(t,n.map(t=>[t])).map(t=>t[0]),vectorTimes:(t,n)=>s([t],n)[0]}}const m=h({add:(t,n)=>t+n,sub:(t,n)=>t-n,mul:(t,n)=>t*n,div:(t,n)=>t/n,isZero:t=>Math.abs(t)<1e-12,zero:()=>0,one:()=>1,size:Math.abs,charge:t=>{if(O+=t/16,O>k)throw new Error("Too much to work out")},fail:t=>{throw new Error(t)}}),g=t=>l(t)&&(t.length>1||t[0].length>1),p=t=>f(t)&&!g(t),d=t=>{const n=(e,r)=>{if(Array.isArray(e)&&Array.isArray(r)){if(e.length!==r.length)throw new Error("Lists of different lengths");return e.map((t,e)=>n(t,r[e]))}return Array.isArray(e)?e.map(t=>n(t,r)):Array.isArray(r)?r.map(t=>n(e,t)):t(e,r)};return n},b=(t,n)=>g(t)&&g(n)?m.times(t,n):g(t)&&p(n)?m.timesVector(t,n):p(t)&&g(n)?m.vectorTimes(t,n):d((t,n)=>t*n)(t,n),w=(t,n)=>e=>{const r=e.length>1&&e.every(p)?e:e[0];if(!l(r))throw new Error(`${n}() needs a matrix`);return t(r)},M=(t,n)=>([e,r])=>{if(!f(e)||!f(r))throw new Error(`${n}() needs two lists`);return t(e,r)},y={det:w(m.det,"det"),inv:w(m.inverse,"inv"),inverse:w(m.inverse,"inverse"),transpose:w(m.transpose,"transpose"),trace:w(m.trace,"trace"),tr:w(m.trace,"tr"),rank:w(m.rank,"rank"),rref:w(m.rref,"rref"),identity:([t])=>{if(!Number.isInteger(t)||t<1||t>100)throw new Error("identity(n) takes a whole number from 1 to 100");return m.identity(t)},dot:M(m.dot,"dot"),cross:M(m.cross,"cross"),linsolve:([t,n])=>{if(!l(t)||!Array.isArray(n))throw new Error("linsolve() needs a matrix and a list");return m.solve(t,n)}},v=(t,n)=>t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args.map(t=>E(t,n)):[E(t,n)]),x={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},N=(t,n)=>n?N(n,t%n):Math.abs(t),$=(t,n)=>(t%n+n)%n,A=(t,n)=>Array.isArray(t)&&Array.isArray(n)?t.length===n.length&&t.every((t,e)=>A(t,n[e])):t==n,I={neg:t=>-t,pm:t=>[t,-t],"!":t=>{if(!Number.isInteger(t)||t<0)return NaN;if(t>170)return 1/0;let n=1;for(let e=2;e<=t;e++)n*=e;return n},"\\not":t=>!t,sqrt:Math.sqrt,abs:Math.abs,floor:Math.floor,ceil:Math.ceil,det:t=>y.det([t]),ln:Math.log,loglog:t=>Math.log(Math.log(t)),logloglog:t=>Math.log(Math.log(Math.log(t))),expm1:Math.expm1,sin:Math.sin,cos:Math.cos,tan:Math.tan,csc:t=>1/Math.sin(t),sec:t=>1/Math.cos(t),cot:t=>1/Math.tan(t),sinh:Math.sinh,cosh:Math.cosh,tanh:Math.tanh,arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan,arcsec:t=>Math.acos(1/t),arccsc:t=>Math.asin(1/t),arccot:t=>Math.PI/2-Math.atan(t),arcsinh:Math.asinh,arccosh:Math.acosh,arctanh:Math.atanh},F={"+":(t,n)=>Array.isArray(t)||Array.isArray(n)?d((t,n)=>t+n)(t,n):t+n,"-":(t,n)=>Array.isArray(t)||Array.isArray(n)?d((t,n)=>t-n)(t,n):t-n,"*":b,"/":(t,n)=>g(n)?b(t,m.inverse(n)):Array.isArray(t)||Array.isArray(n)?d((t,n)=>t/n)(t,n):t/n,"^":(t,n)=>{if(!g(t))return Array.isArray(t)?d((t,n)=>t**n)(t,n):t**n;if(!Number.isInteger(n))throw new Error("A matrix to a power that is not a whole number");return m.power(t,BigInt(n))},mod:$,log:(t,n)=>Math.log(n)/Math.log(t),root:(t,n)=>n<0&&Number.isInteger(t)&&t%2!=0?-((-n)**(1/t)):n**(1/t),atan2:Math.atan2,round:(t,n)=>(t=>Math.sign(t)*Math.round(Math.abs(t)))(t*10**n)/10**n,"±":(t,n)=>[t+n,t-n],fixed:(t,n)=>{const e=Math.trunc(n);if(!(e>=0&&e<=100))throw new Error("fixed() takes 0 to 100 decimals");return Number(t).toFixed(e)},perm:(t,n)=>{if(!Number.isInteger(t)||!Number.isInteger(n)||n<0||n>t)return NaN;let e=1;for(let r=t-n+1;r<=t&&e!==1/0;r++)e*=r;return e},comb:(t,n)=>{if(!Number.isInteger(t)||!Number.isInteger(n)||n<0||n>t)return NaN;n=Math.min(n,t-n);let e=1;for(let r=1;r<=n&&e!==1/0;r++)e=e*(t-n+r)/r;return Math.round(e)},"=":A,"===":(t,n)=>t===n,"≠":(t,n)=>!A(t,n),"≠=":(t,n)=>t!==n,"≈":(t,n)=>Math.abs(t-n)<1e-9,"≡":(t,n)=>t===n,"∪":(t,n)=>[...new Set([...[].concat(t),...[].concat(n)])],"∩":(t,n)=>[].concat(t).filter(t=>[].concat(n).includes(t)),"<":(t,n)=>t<n,">":(t,n)=>t>n,"≤":(t,n)=>t<=n,"≥":(t,n)=>t>=n,"&":(t,n)=>t&&n,"|":(t,n)=>t||n,"\\xor":(t,n)=>Boolean(t)!==Boolean(n),"\\nor":(t,n)=>!(t||n),"\\nand":(t,n)=>!(t&&n),"\\implies":(t,n)=>!t||Boolean(n),"\\iff":(t,n)=>Boolean(t)===Boolean(n)},B={max:t=>Math.max(...t),min:t=>Math.min(...t),sum:t=>t.reduce((t,n)=>t+n,0),prod:t=>t.reduce((t,n)=>t*n,1),mean:t=>t.reduce((t,n)=>t+n,0)/t.length,gcd:t=>t.reduce(N,0),"()":t=>t,"[]":t=>t,"{}":t=>t};const k=5e6;let O=0,S=0;function E(t,a){if(++O>k)throw new Error("Too much to work out");switch(t.type){case"number":return t.value.endsWith("..")?Number(e(t.value)):Number(t.value);case"string":return t.value.slice(1,-1);case"symbol":if(Object.prototype.hasOwnProperty.call(a,t.value))return a[t.value];if(Object.prototype.hasOwnProperty.call(x,t.value))return x[t.value];if(n(t.value))return Number(n(t.value));throw new Error(`No value for '${t.value}'`)}const s=r(t);if(s)return E(s,a);const{op:u,args:c}=t;if("?:"===u)return E(c[0],a)?E(c[1],a):E(c[2],a);if("setbuilder"===u)throw new Error("A set described by a condition has no list of values (test membership in it: y ∈ {x | P})");if(("∈"===u||"∉"===u)&&o(t))return E(o(t),a);if("∈"===u||"∉"===u)return function(t,n){const[e,r]=t.args,o=E(e,n);let i;if("symbol"===r.type&&P[r.value])return i=P[r.value](o),"∈"===t.op?i:!i;if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,e]=r.args.map(t=>E(t,n)),a="["===r.op[0]?o>=t:o>t,s="]"===r.op[1]?o<=e:o<e;i=a&&s}else{const t=E(r,n);i=Array.isArray(t)&&t.includes(o)}return"∈"===t.op?i:!i}(t,a);if("random"===u)return Math.random();if("evaluated"===u){const[t,n,e,r]=c,o=e=>E(t,{...a,[n.value]:E(e,a)});return o(r)-o(e)}if(("\\sumidx"===u||"\\prodidx"===u)&&3===c.length){const t="op"===c[1].type&&"="===c[1].op&&"symbol"===c[1].args[0].type,[n,e,r]=[c[0],t?c[1].args[1]:c[1],c[2]],o=t?c[1].args[0].value:i(n);if(!o)throw new Error(`Can't evaluate '${u}' without an index`);const s=E(e,a),l=E(r,a);if(!Number.isFinite(s)||!Number.isFinite(l)||l-s>1e6||Math.abs(s)>Number.MAX_SAFE_INTEGER||Math.abs(l)>Number.MAX_SAFE_INTEGER)throw new Error(`Can't evaluate '${u}' over that range`);let f="\\sumidx"===u?0:1;for(let t=s;t<=l;t++){const e=E(n,{...a,[o]:t});f="\\sumidx"===u?f+e:f*e}return f}if("pmod"===u){const[t,n]=c,e=E(n,a);if("op"===t.type&&["≡","="].includes(t.op)){const[n,r]=t.args.map(t=>E(t,a));return(n-r)%e===0}return $(E(t,a),e)}if("pmatrix"===u||"bmatrix"===u)return v(t,a);if("vmatrix"===u)return m.det(v(t,a));if("^"===u&&"symbol"===c[1].type&&"T"===c[1].value&&!Object.prototype.hasOwnProperty.call(a,"T")){const t=E(c[0],a);if(g(t))return m.transpose(t)}const l=c.map(t=>E(t,a));if(u.startsWith("\\:")&&Object.prototype.hasOwnProperty.call(y,u.slice(2)))return y[u.slice(2)](l);if(I[u]&&1===l.length)return I[u](l[0]);if(F[u]&&2===l.length)return F[u](l[0],l[1]);if(B[u])return B[u](l);throw new Error(`Can't evaluate '${u}'`)}const P={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":t=>Number.isInteger(t)&&t>0,"ℚ":Number.isFinite,"ℂ":t=>"number"==typeof t&&!Number.isNaN(t)};for(const t of[x,I,F,B,P,y])Object.setPrototypeOf(t,null);class z extends Error{}class j extends Error{}class T extends j{}const W={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let _=0;function Z(t){if(_+=t,_>W.steps)throw new j("too much to work out")}const q=(t,n)=>Z(Number(t)*(n/64)/128);let D=0;const C=t=>t<0n?-t:t,G=0xFFFFFFFFFFFFn,L=t=>0n===t?0:C(t).toString(2).length;function R(t,n){for(t=C(t),n=C(n);n;)[t,n]=[n,t%n];return t}function V(t,n=1n){if(0n===n)throw new z("division by zero");if(n<0n&&(t=-t,n=-n),n>G&&(t>G||-t>G)){const e=Math.min(t.toString(16).length-(t<0n?1:0),n.toString(16).length)/16;if(_+=1+e*e/2,_>W.steps)throw new j("too much to work out")}const e=R(t,n)||1n;return{n:t/e,d:n/e}}const X=V(0n),J=V(1n),H=(t,n)=>V(t.n*n.d+n.n*t.d,t.d*n.d),K=(t,n)=>V(t.n*n.n,t.d*n.d),Q=(t,n)=>V(t.n*n.d,t.d*n.n),U=t=>({n:-t.n,d:t.d}),Y=(t,n)=>{const e=t.n*n.d-n.n*t.d;return e<0n?-1:e>0n?1:0},tt=t=>{const n=t.n/t.d;return t.n<0n&&n*t.d!==t.n?n-1n:n};function nt(t){if(t.n<0n)return-nt(U(t));const n=L(t.n),e=L(t.d);if(n<1e3&&e<1e3)return Number(t.n)/Number(t.d);const r=BigInt(Math.max(n,e)-1e3),o=t.d>>r;return 0n===o?t.n<0n?-1/0:1/0:Number(t.n>>r)/Number(o)}function et(t){let n=String(t).trim(),e=1n;n.startsWith("-")&&(e=-1n,n=n.slice(1));const r=n.endsWith("..");r&&(n=n.slice(0,-2));let o=0;const i=n.search(/e/i);i>=0&&(o=Number(n.slice(i+1)),n=n.slice(0,i));const[a="",s=""]=n.split(".");if(!(/^\d*$/.test(a)&&/^\d*$/.test(s)&&a+s))throw new j(`'${t}' is not a number`);let u;if(r&&s){let t=1;for(let n=1;2*n<=s.length;n++)if(s.slice(-n)===s.slice(-2*n,-n)){t=n;break}const n=s.slice(-t);let e=s;for(;e.endsWith(n);)e=e.slice(0,-t);const r=BigInt(e||"0"),o=BigInt(e+n);u=H(V(BigInt(a||"0")),V(o-r,(10n**BigInt(t)-1n)*10n**BigInt(e.length)))}else u=V(BigInt(a+s||"0"),10n**BigInt(s.length));if(Math.abs(o)>W.bits/3)throw new j("too large to calculate");return o&&(u=o>0?K(u,V(10n**BigInt(o))):Q(u,V(10n**BigInt(-o)))),e<0n?U(u):u}function rt(t,n=0,e=0,r=null){return 0n===t.n?{kind:"x",c:X,pi:0,e:0,root:null}:{kind:"x",c:t,pi:n,e:e,root:r}}const ot=(t,n=1n)=>rt(V(BigInt(t),BigInt(n))),it=rt(J,1),at=rt(J,0,1),st=t=>null!==t&&"object"==typeof t&&"x"===t.kind,ut=t=>st(t)&&!t.pi&&!t.e&&!t.root,ct=t=>st(t)?0n===t.c.n:0===t,lt=t=>ut(t)&&1n===t.c.d?t.c.n:null,ft=(t,n)=>Object.assign(t,{group:n}),ht=t=>({kind:"s",text:t});function mt(t,n){return t&&n?t.n===n.n&&t.r===n.r:t===n}const gt=(t,n)=>0===Y(t.c,n.c)&&t.pi===n.pi&&t.e===n.e&&mt(t.root,n.root);function pt(t){const n=Math.max(0,L(t)-60);return n+Math.log2(Number(t>>BigInt(n)))}function dt(t){if("number"==typeof t)return t;if(Ct(t)&&Ht(t),st(t)){let n=nt(t.c);if(t.pi&&(n*=Math.PI**t.pi),t.e&&(n*=Math.E**t.e),t.root){const e=function(t,n){const e=Number(t);return Number.isFinite(e)?e**(1/n):2**(pt(t)/n)}(t.root.r,t.root.n);if(!(0n===t.c.n||0!==n&&Number.isFinite(n)&&Number.isFinite(e))){const n=pt(t.c.n<0n?-t.c.n:t.c.n)-pt(t.c.d)+pt(t.root.r)/t.root.n+t.pi*Math.log2(Math.PI)+t.e*Math.LOG2E;return(t.c.n<0n?-1:1)*2**n}n*=e}return n}if("boolean"==typeof t)return t?1:0;throw new j("not a number")}function bt(t,...n){if(Number.isNaN(t))throw new z("undefined");if(!Number.isFinite(t)&&n.every(Number.isFinite))throw new j("too large to calculate");return t}const wt=t=>"boolean"==typeof t?t:st(t)?0n!==t.c.n:"number"==typeof t?0!==t:Boolean(t);function Mt(t){if("bigint"==typeof t)return rt(V(t));if("number"==typeof t)return Number.isFinite(t)?rt(Number.isInteger(t)&&Math.abs(t)<=Number.MAX_SAFE_INTEGER?V(BigInt(t)):et(String(t))):t;if("boolean"==typeof t)return t;if("string"==typeof t)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(t.trim())?rt(et(t)):Vn(a(t),{});if(Array.isArray(t))return!t.group&&l(t)?ft(t.map(t=>ft(t.map(Mt),"[]")),"[]"):ft(t.map(Mt),t.group||"()");if(st(t)||"function"==typeof t)return t;throw new j(`can't use ${typeof t} as a value`)}function yt(t){if(Array.isArray(t))return t.map(yt);if(Gt(t)){const{re:n,im:e}=Kt(t);return{re:dt(n),im:dt(e)}}return Ct(t)?se(t,{decimal:!1,places:null,digits:12,maxDigits:50}):t&&"s"===t.kind?t.text:"boolean"==typeof t?t:dt(t)}function vt(t,n){if(t<2n)return t;const e=BigInt(n);let r=1n<<BigInt(Math.ceil(L(t)/n));for(;;){const n=((e-1n)*r+t/r**(e-1n))/e;if(n>=r)return r;r=n}}function xt(t,n,e,r=0,o=0){if(0n===e)return rt(X);const{coef:i,root:a}=function(t,n){let e=1n,r=n;const o=BigInt(t),i=r<10n**24n?1000000n:10000n;let a=0;for(let t=2n;t<=i&&t*t<=r;t+=2n===t?1n:2n){const n=t**o;for(;r%n===0n;)r/=n,e*=t;a++}_+=a/4;const s=vt(r,t);if(s**o===r&&(e*=s,r=1n),1n===r)return{coef:e,root:null};for(let n=t;n>=2;n--){if(t%n!==0)continue;const o=vt(r,n);if(o**BigInt(n)===r)return{coef:e,root:{n:t/n,r:o}}}return{coef:e,root:{n:t,r:r}}}(n,e);return a&&1===a.n?rt(K(t,V(i*a.r)),r,o):rt(K(t,V(i)),r,o,a)}function Nt(t,n){const e=K(t.c,n.c);if(L(e.n)+L(e.d)>W.bits)return null;const r=t.pi+n.pi,o=t.e+n.e;if(!t.root||!n.root)return rt(e,r,o,t.root||n.root);const i=Bn(t.root.n,n.root.n);if(i>W.rootIndex)return null;const a=t.root.r**BigInt(i/t.root.n)*n.root.r**BigInt(i/n.root.n);return L(a)>4e3?null:xt(e,i,a,r,o)}function $t(t){if(0n===t.c.n)throw new z("division by zero");const n=rt(Q(J,t.c),-t.pi,-t.e);if(!t.root)return n;const{n:e,r:r}=t.root;return L(r)*(e-1)>4e3?null:Nt(n,xt(V(1n,r),e,r**BigInt(e-1)))}function At(t,n){if(0n===n){if(0n===t.c.n)throw new z("0^0 is undefined");return rt(J)}if(n<0n){const e=$t(t);return e&&At(e,-n)}if((L(t.c.n)+L(t.c.d)+(t.root?L(t.root.r):0))*Number(n)>W.bits||n>100000n)return null;const e=V(t.c.n**n,t.c.d**n),r=Number(n);if(!t.root)return rt(e,t.pi*r,t.e*r);const{n:o,r:i}=t.root,a=i**(n/BigInt(o));return xt(K(e,V(a)),o,i**(n%BigInt(o))||1n,t.pi*r,t.e*r)}function It(t,n,e){if(!ut(t)||e>1000n)return null;const r=At(t,n);if(!r)return null;let{n:o,d:i}=r.c,a=!1;if(o<0n){if(e%2n==0n)throw new z("not a real number");a=!0,o=-o}const s=function(t,n){const e=t.n*t.d**BigInt(n-1);return L(e)>4e3?null:xt(V(1n,t.d),n,e)}({n:o,d:i},Number(e));return s?a?rt(U(s.c),s.pi,s.e,s.root):s:null}function Ft(t){return n=>Array.isArray(n)?ft(n.map(n=>Ft(t)(n)),n.group):t(n)}function Bt(t){const n=(e,r)=>{const o=Array.isArray(e),i=Array.isArray(r);if(o&&i){if(e.length!==r.length)throw new z("lists of different lengths");return ft(e.map((t,e)=>n(t,r[e])),e.group)}return o?ft(e.map(t=>n(t,r)),e.group):i?ft(r.map(t=>n(e,t)),r.group):t(e,r)};return n}const kt=(t,n)=>st(t)&&st(n)&&function(t,n){if(0n===t.c.n)return n;if(0n===n.c.n)return t;if(t.pi!==n.pi||t.e!==n.e||!mt(t.root,n.root))return null;const e=H(t.c,n.c);return L(e.n)+L(e.d)>W.bits?null:rt(e,t.pi,t.e,t.root)}(t,n)||bt(dt(t)+dt(n),dt(t),dt(n)),Ot=t=>st(t)?rt(U(t.c),t.pi,t.e,t.root):-dt(t),St=(t,n)=>st(t)&&st(n)&&Nt(t,n)||bt(dt(t)*dt(n),dt(t),dt(n)),Et=Bt((t,n)=>Ct(t)||Ct(n)?an(t,n):kt(t,n)),Pt=Ft(t=>Ct(t)?sn(t):Ot(t)),zt=(t,n)=>Et(t,Pt(n)),jt=Bt((t,n)=>Ct(t)||Ct(n)?cn(t,n):St(t,n)),Tt=Bt((t,n)=>Ct(t)||Ct(n)?function(t,n){if(!Ct(n)){if(ct(n))throw new z("division by zero");return Vt(Xt(t).map(t=>({vars:t.vars,re:Wt(t.re,n),im:Wt(t.im,n)})))}if(Gt(n))return cn(t,Qt(Yt(Kt(n))));const e=function(t,n){const e=new Set(n.flatMap(t=>t.vars.map(([t])=>t)));if(1!==e.size)return null;const[r]=e,o=t=>t.vars.find(([t])=>t===r)?.[1]??0,i=n.reduce((t,n)=>o(n)>o(t)?n:t),a=o(i);if(1!==i.vars.length)return null;let s=t;const u=[];for(let t=0;t<1e3&&s.length;t++){const t=s.reduce((t,n)=>o(n)>o(t)?n:t);if(o(t)<a)return null;const e={vars:un(t.vars,[[r,-a]]),...Ut(t,Yt(i))};u.push(e);const c=an(Vt(s),sn(cn(Vt([e]),Vt(n))));s=ct(c)?[]:Xt(c)}return s.length?null:Vt(u)}(Xt(t),[...n.terms.values()]);if(null===e)throw new j(`no value for '${Jt(n)}'`);return e}(t,n):Wt(t,n));function Wt(t,n){if(ct(n))throw new z("division by zero");if(st(t)&&st(n)){const e=$t(n),r=e&&Nt(t,e);if(r)return r}return bt(dt(t)/dt(n),dt(t),dt(n))}const _t=Bt((t,n)=>{if(Ct(t)||Ct(n))return function(t,n){if(Ct(n)){Gt(n)||Ht(n),Ct(t)&&!Gt(t)&&Ht(t);const e=Kt(n);return st(t)&>(t,at)?en(e):en(Ut(e,rn(Kt(t))))}const e=lt(n);if(null!==e)return e>=0n?ln(t,e):(Gt(t)||Ht(t),ln(Qt(Yt(Kt(t))),-e));Gt(t)||Ht(t);return on(Kt(t),n)}(t,n);try{return Zt(t,n)}catch(e){if(qt&&e instanceof z&&"not a real number"===e.message)return on({re:t,im:ot(0)},n);throw e}});function Zt(t,n){if(st(t)&&ut(n)){const{n:e,d:r}=n.c,o=1n===r?At(t,e):It(t,e,r);if(o)return o}const e=dt(t),r=dt(n);if(0===e&&0===r)throw new z("0^0 is undefined");if(0===e&&r<0)throw new z("division by zero");if(e<0&&!Number.isInteger(r))throw new z("not a real number");const o=e**r;if(0===o&&0!==e)throw new T("too small to calculate");return bt(o,e,r)}let qt=!1;const Dt=5e3,Ct=t=>null!==t&&"object"==typeof t&&"p"===t.kind,Gt=t=>Ct(t)&&1===t.terms.size&&t.terms.has(""),Lt=()=>Vt([{vars:[],re:ot(0),im:ot(1)}]),Rt=t=>t.map(([t,n])=>1===n?t:`${t}^${n}`).join("*");function Vt(t){const n=new Map;for(const e of t){const t=Rt(e.vars),r=n.get(t);n.set(t,r?{vars:e.vars,re:kt(r.re,e.re),im:kt(r.im,e.im)}:e)}for(const[t,e]of n)ct(e.re)&&ct(e.im)&&n.delete(t);if(n.size>Dt)throw new j("too many terms to work out");return n.size?1===n.size&&n.has("")&&ct(n.get("").im)?n.get("").re:{kind:"p",terms:n}:ot(0)}function Xt(t){if(Ct(t))return[...t.terms.values()];if("boolean"==typeof t)return[{vars:[],re:ot(t?1:0),im:ot(0)}];if(!st(t)&&"number"!=typeof t)throw new j("not a number");return[{vars:[],re:t,im:ot(0)}]}const Jt=t=>[...t.terms.values()].find(t=>t.vars.length)?.vars[0][0];function Ht(t){if(Gt(t))throw new j("a complex number has no real value here");throw new j(`no value for '${Jt(t)}'`)}const Kt=t=>Gt(t)?t.terms.get(""):{re:t,im:ot(0)},Qt=({re:t,im:n})=>Vt([{vars:[],re:t,im:n}]),Ut=(t,n)=>({re:kt(St(t.re,n.re),Ot(St(t.im,n.im))),im:kt(St(t.re,n.im),St(t.im,n.re))});function Yt(t){const n=kt(St(t.re,t.re),St(t.im,t.im));if(ct(n))throw new z("division by zero");return{re:Wt(t.re,n),im:Ot(Wt(t.im,n))}}const tn=t=>ct(t.im)?fn(t.re,ot(0))<0?Ot(t.re):t.re:Zt(kt(St(t.re,t.re),St(t.im,t.im)),ot(1,2));function nn(t){return ct(t.im)?fn(t.re,ot(0))<0?it:ot(0):ct(t.re)?fn(t.im,ot(0))>0?rt(V(1n,2n),1):rt(V(-1n,2n),1):Math.atan2(dt(t.im),dt(t.re))}function en(t){const n=ct(t.re)?ot(1):Zt(at,t.re);return Qt({re:St(n,bn("cos",t.im)),im:St(n,bn("sin",t.im))})}function rn(t){if(ct(t.re)&&ct(t.im))throw new z("ln 0 is undefined");return{re:Mn(tn(t)),im:nn(t)}}function on(t,n){if(ct(t.re)&&ct(t.im))return Zt(ot(0),n);const e=Zt(tn(t),n),r=St(n,nn(t));return Qt({re:St(e,bn("cos",r)),im:St(e,bn("sin",r))})}function an(t,n){return Vt([...Xt(t),...Xt(n)])}function sn(t){return Vt(Xt(t).map(t=>({vars:t.vars,re:Ot(t.re),im:Ot(t.im)})))}function un(t,n){const e=new Map(t);for(const[t,r]of n)e.set(t,(e.get(t)??0)+r);return[...e].filter(([,t])=>0!==t).sort(([t],[n])=>t<n?-1:t>n?1:0)}function cn(t,n){const e=Xt(t),r=Xt(n);Z(e.length*r.length);const o=[];for(const t of e)for(const n of r)o.push({vars:un(t.vars,n.vars),...Ut(t,n)});return Vt(o)}function ln(t,n){if(!Gt(t)&&n>1000n)throw new j("too large to calculate");if(Gt(t)&&n>1n){const{re:e,im:r}=Kt(t),o=t=>st(t)?L(t.c.n)+L(t.c.d)+(t.root?L(t.root.r):0):64;if(Number(n)*Math.max(o(e),o(r),1)>2e4)return on(Kt(t),ot(n))}let e=ot(1),r=t;for(let t=n;t>0n;t>>=1n)1n&t&&(e=cn(e,r)),t>1n&&(r=cn(r,r));return e}function fn(t,n){if(Gt(t)||Gt(n))throw new j("complex numbers have no order");if(ut(t)&&ut(n))return Y(t.c,n.c);if(st(t)&&st(n)&>(t,n))return 0;const e=dt(t),r=dt(n);if(e===r)return 0;const o=st(t)&&st(n)?Math.max(Math.abs(e),Math.abs(r)):Math.max(1,Math.abs(e),Math.abs(r));return Number.isFinite(e)&&Number.isFinite(r)&&Math.abs(e-r)<=1e-12*o?0:e<r?-1:1}function hn(t,n){return Array.isArray(t)||Array.isArray(n)?Array.isArray(t)&&Array.isArray(n)&&t.length===n.length&&t.every((t,e)=>hn(t,n[e])):t&&"s"===t.kind||n&&"s"===n.kind?Boolean(t&&"s"===t.kind&&n&&"s"===n.kind&&t.text===n.text):"boolean"==typeof t||"boolean"==typeof n?t===n:Ct(t)||Ct(n)?function(t,n){const e=zt(t,n);return Ct(e)?!Gt(e)&&Ht(e):ct(e)}(t,n):0===fn(t,n)}const mn={0:()=>ot(0),2:()=>ot(1,2),3:()=>xt(V(1n,2n),2,2n),4:()=>xt(V(1n,2n),2,3n),6:()=>ot(1)};function gn(t){t=(t%24+24)%24;const[n,e]=t<=6?[t,1]:t<=12?[12-t,1]:t<=18?[t-12,-1]:[24-t,-1],r=mn[n];return r?e<0?Pt(r()):r():null}const pn=t=>gn(t+6),dn=(t,n)=>Math.abs(t)<1e-15&&Math.abs(n)>1e-6?0:t;function bn(t,n){const e=function(t){if(ct(t))return 0;if(!st(t)||1!==t.pi||t.e||t.root)return null;const n=K(t.c,V(12n));return 1n!==n.d?null:Number((n.n%24n+24n)%24n)}(n);if(null!==e){const n=gn(e),r=pn(e);if(n&&r)switch(t){case"sin":return n;case"cos":return r;case"tan":return Tt(n,r);case"cot":return Tt(r,n);case"sec":return Tt(ot(1),r);case"csc":return Tt(ot(1),n)}}const r=dt(n),o=dn(Math.sin(r),r),i=dn(Math.cos(r),r),a={sin:o,cos:i,tan:o/i,cot:i/o,sec:1/i,csc:1/o}[t];if(!Number.isFinite(a)&&Number.isFinite(r))throw new z("undefined");return bt(a)}function wn(t,n){const e={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[t],r=n=>"arcsin"===t?gn(n):"arccos"===t?pn(n):pn(n)&&!ct(pn(n))?Tt(gn(n),pn(n)):null;if(st(n))for(let t=e[0];t<=e[1];t++){const e=r(t);if(e&&st(e)&>(e,n))return rt(V(BigInt(t),12n),1)}const o=dt(n);if("arctan"!==t&&Math.abs(o)>1)throw new z("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[t](o)}function Mn(t){if(Ct(t))return Gt(t)?Qt(rn(Kt(t))):Ht(t);if(qt&&fn(t,ot(0))<0)return Qt({re:Mn(Ot(t)),im:it});if(st(t)){if(0n===t.c.n)throw new z("ln 0 is undefined");if(t.c.n<0n)throw new z("not a real number");if(1n===t.c.n&&1n===t.c.d&&!t.pi&&!t.root)return ot(t.e)}const n=dt(t);if(n<=0)throw new z(0===n?"ln 0 is undefined":"not a real number");return Math.log(n)}function yn(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*yn(1-t));const n=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];let e=n[0];const r=(t-=1)+7+.5;for(let r=1;r<9;r++)e+=n[r]/(t+r);return Math.sqrt(2*Math.PI)*r**(t+.5)*Math.exp(-r)*e}function vn(t,n){Ct(t)&&Ht(t);const e=lt(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null===e)throw new z(`${n} needs whole numbers`);return e}const xn=(t,n)=>Number(n)*L(t)>W.bits;const Nn=Ft(t=>ut(t)?rt(V(tt(t.c))):Mt(Math.floor(dt(t)))),$n=Ft(t=>ut(t)?rt(V(-tt(U(t.c)))):Mt(Math.ceil(dt(t))));function An(t,n){const e=Number(vn(n,"round"));if(Math.abs(e)>W.places)throw new j("too many decimal places");if(ut(t)){const n=V(10n**BigInt(Math.abs(e))),r=e>=0?K(t.c,n):Q(t.c,n),o=tt(H(K(V(2n),V(C(r.n),r.d)),J))/2n,i=V(r.n<0n?-o:o);return rt(e>=0?Q(i,n):K(i,n))}if(e>15)return dt(t);const r=10**e;return 0===r?0:Math.sign(dt(t))*Math.round(Math.abs(dt(t))*r)/r}const In=(t,n)=>t.toFixed(Math.min(n,100))+(n>100?"0".repeat(n-100):"");function Fn(t,n){if(ct(n))throw new z("division by zero");if(ut(t)&&ut(n))return rt(H(t.c,U(K(n.c,V(tt(Q(t.c,n.c)))))));const e=dt(t),r=dt(n);return bt((e%r+r)%r)}const Bn=(t,n)=>t/kn(t,n)*n,kn=(t,n)=>n?kn(n,t%n):t,On={pi:()=>it,"π":()=>it,tau:()=>rt(V(2n),1),"τ":()=>rt(V(2n),1),e:()=>at,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1,"°":()=>rt(V(1n,180n),1)},Sn={abs:t=>Gt(t)?tn(Kt(t)):st(t)?rt(V(C(t.c.n),t.c.d),t.pi,t.e,t.root):Math.abs(dt(t)),floor:Nn,ceil:$n,sqrt:t=>_t(t,ot(1,2)),ln:Ft(Mn),loglog:Ft(t=>Mn(Mn(t))),logloglog:Ft(t=>Mn(Mn(Mn(t)))),expm1:Ft(t=>ct(t)?ot(0):Math.expm1(dt(t))),sinh:Ft(t=>ct(t)?ot(0):Math.sinh(dt(t))),cosh:Ft(t=>ct(t)?ot(1):Math.cosh(dt(t))),tanh:Ft(t=>ct(t)?ot(0):Math.tanh(dt(t))),arcsinh:Ft(t=>ct(t)?ot(0):Math.asinh(dt(t))),arccosh:Ft(t=>{const n=dt(t);if(n<1)throw new z("not a real number");return 1===n?ot(0):Math.acosh(n)}),arctanh:Ft(t=>{const n=dt(t);if(Math.abs(n)>=1)throw new z("undefined");return ct(t)?ot(0):Math.atanh(n)}),"!":Ft(function(t){const n=lt(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null!==n){if(n<0n)throw new z("factorial of a negative number");if(n>BigInt(W.factorial))throw new j("too large to calculate");q(n,Number(n)*Math.log2(Number(n)+1));let t=1n;for(let e=2n;e<=n;e++)t*=e;return rt(V(t))}const e=dt(t);if(e<0&&Number.isInteger(e))throw new z("factorial of a negative number");return bt(yn(e+1),e)}),neg:Pt,pm:t=>ft([t,Pt(t)],"pm"),"\\not":t=>!wt(t),det:t=>qn.det(t)};for(const t of["sin","cos","tan","csc","sec","cot"])Sn[t]=Ft(n=>bn(t,n));for(const t of["arcsin","arccos","arctan"])Sn[t]=Ft(n=>wn(t,n));const En=t=>{if(ct(t))throw new z("not a real number");return Tt(ot(1),t)};Sn.arcsec=Ft(t=>wn("arccos",En(t))),Sn.arccsc=Ft(t=>wn("arcsin",En(t))),Sn.arccot=Ft(t=>zt(rt(V(1n,2n),1),wn("arctan",t)));const Pn=new Set(["pmatrix","bmatrix"]),zn=t=>l(t)&&(Pn.has(t.group)||"[]"===t.group&&t.every(t=>"[]"===t.group)&&(t.length>1||t[0].length>1)),jn=t=>f(t)&&!zn(t)&&"pm"!==t.group,Tn=h({add:Et,sub:zt,mul:jt,div:Tt,charge:Z,isZero:t=>st(t)?0n===t.c.n:Math.abs(dt(t))<1e-12,zero:()=>ot(0),one:()=>ot(1),size:t=>Math.abs(dt(t)),fail:t=>{throw new z(t)},make:(t,n)=>ft(t.map(t=>ft(t,"[]")),n&&n.group?n.group:"bmatrix")}),Wn=(t,n)=>ft(t,n&&n.group?n.group:"[]"),_n=(t,n)=>(...e)=>{const r=e.length>1&&e.every(jn)?ft(e.map(t=>ft(t,"[]")),"[]"):e[0];if(e.length>1&&r===e[0])throw new j(`${t} of more than one thing`);if(!zn(r))throw new j(`${t} of something that isn't a matrix`);return n(r)};function Zn(t,n){return zn(t)&&zn(n)?Tn.times(t,n):zn(t)&&jn(n)?Wn(Tn.timesVector(t,n),n):jn(t)&&zn(n)?Wn(Tn.vectorTimes(t,n),t):jt(t,n)}const qn={det:_n("det",t=>Dn(t)),inv:_n("inv",Tn.inverse),inverse:_n("inverse",Tn.inverse),transpose:_n("transpose",Tn.transpose),trace:_n("trace",Tn.trace),tr:_n("tr",Tn.trace),rank:_n("rank",t=>ot(Tn.rank(t))),rref:_n("rref",Tn.rref),identity:t=>{const n=lt(t);if(null===n||n<1n||n>100n)throw new j("identity(n) needs a whole number n");return Tn.identity(Number(n))},dot:(t,n)=>{if(!jn(t)||!jn(n))throw new j("dot of something that isn't a vector");return Tn.dot(t,n)},cross:(t,n)=>{if(!jn(t)||!jn(n))throw new j("cross of something that isn't a vector");return Wn(Tn.cross(t,n),t)},linsolve:(t,n)=>{if(!zn(t)||!zn(n)&&!jn(n))throw new j("linsolve(A, b) needs a matrix and a vector");return zn(n)?Tn.solve(t,n):Wn(Tn.solve(t,n),n)}};function Dn(t){if(!t.some(t=>t.some(Ct)))return Tn.det(t);if(t.length!==t[0].length)throw new z(`a ${t.length} by ${t[0].length} matrix has no determinant`);if(t.length>6)throw new j("too large to calculate");const n=t=>1===t.length?t[0][0]:t[0].reduce((e,r,o)=>{const i=t.slice(1).map(t=>t.filter((t,n)=>n!==o)),a=jt(r,n(i));return o%2?zt(e,a):Et(e,a)},ot(0));return n(t)}function Cn(t,n){const e=t.args.map(t=>ft("op"===t.type&&"[]"===t.op?t.args.map(n):[n(t)],"[]"));if(e.some(t=>t.length!==e[0].length))throw new z("rows of different lengths");return ft(e,"vmatrix"===t.op?"bmatrix":t.op)}const Gn={"+":Et,"-":zt,"*":Zn,"/":(t,n)=>zn(n)?Zn(t,Tn.inverse(n)):Tt(t,n),"^":function(t,n){if(!zn(t))return _t(t,n);const e=lt(n);if(null===e)throw new j("a matrix to a power that is not a whole number");return Tn.power(t,e)},"±":(t,n)=>ft([Et(t,n),zt(t,n)],"pm"),mod:Bt(Fn),log:Bt(function(t,n){if(st(t)&>(t,at))return Mn(n);const e=dt(t),r=dt(n);if(e<=0||1===e)throw new z("not a valid base");if(r<=0)throw new z(0===r?"log 0 is undefined":"not a real number");const o=Math.log(r)/Math.log(e);if(ut(t)&&ut(n))for(let e=1n;e<=12n;e++){const r=Math.round(o*Number(e));if(Math.abs(o*Number(e)-r)>1e-9)continue;const i=At(t,BigInt(r)),a=At(n,e);if(i&&a&>(i,a))return rt(V(BigInt(r),e))}return o}),root:Bt((t,n)=>_t(n,Tt(ot(1),t))),atan2:(t,n)=>Math.atan2(dt(t),dt(n)),round:An,fixed:function(t,n){const e=Number(vn(n,"fixed"));if(e<0)throw new z("fixed needs 0 or more decimal places");const r=An(t,n);if(ut(r)){const t=r.c.n*10n**BigInt(e)/r.c.d,n=(t<0n?-t:t).toString().padStart(e+1,"0");return ht(`${t<0n?"-":""}${n.slice(0,n.length-e)}${e?"."+n.slice(-e):""}`)}return ht(In(dt(r),e))},perm:function(t,n){const e=vn(t,"permutations"),r=vn(n,"permutations");if(r<0n||r>e)throw new z("undefined");if(r>BigInt(W.terms)||xn(e,r))throw new j("too large to calculate");q(r,Number(r)*L(e));let o=1n;for(let t=e-r+1n;t<=e;t++)o*=t;return rt(V(o))},comb:function(t,n){const e=vn(t,"combinations");let r=vn(n,"combinations");if(r<0n||r>e)throw new z("undefined");if(e-r<r&&(r=e-r),r>BigInt(W.terms)||xn(e,r))throw new j("too large to calculate");q(2n*r,Number(r)*L(e));let o=1n;for(let t=1n;t<=r;t++)o=o*(e-r+t)/t;return rt(V(o))},"=":(t,n)=>hn(t,n),"===":(t,n)=>hn(t,n),"≠":(t,n)=>!hn(t,n),"≠=":(t,n)=>!hn(t,n),"≈":(t,n)=>Math.abs(dt(t)-dt(n))<=1e-9*Math.max(1,Math.abs(dt(t)),Math.abs(dt(n))),"<":(t,n)=>fn(t,n)<0,">":(t,n)=>fn(t,n)>0,"≤":(t,n)=>fn(t,n)<=0,"≥":(t,n)=>fn(t,n)>=0,"&":(t,n)=>wt(t)&&wt(n),"|":(t,n)=>wt(t)||wt(n),"\\xor":(t,n)=>wt(t)!==wt(n),"\\nor":(t,n)=>!(wt(t)||wt(n)),"\\nand":(t,n)=>!(wt(t)&&wt(n)),"\\implies":(t,n)=>!wt(t)||wt(n),"\\iff":(t,n)=>wt(t)===wt(n)},Ln={sum:t=>t.reduce((t,n)=>Et(t,n),ot(0)),prod:t=>t.reduce((t,n)=>jt(t,n),ot(1)),max:t=>t.reduce((t,n)=>fn(n,t)>0?n:t),min:t=>t.reduce((t,n)=>fn(n,t)<0?n:t),mean:t=>Tt(Ln.sum(t),ot(t.length)),gcd:t=>rt(V(t.map(t=>vn(t,"gcd")).reduce(R)))},Rn=["∈","∉","∪","∩","pmod","random","(]","[)"];function Vn(n,e){if(++_>W.steps)throw new j("too much to work out");switch(n.type){case"number":return rt(et(n.value));case"string":return ht(n.value.slice(1,-1));case"symbol":return Xn(n.value,e)}const a=r(n);if(a)return Vn(a,e);const{op:s,args:u}=n,c=t=>Vn(t,e);if("?:"===s)return wt(c(u[0]))?c(u[1]):c(u[2]);if("_"===s){if(u.every(t=>"op"!==t.type))return Xn(`${u[0].value}_${u[1].value}`,e);throw new j("subscript")}if("der"===s)return function(t,n){const[e,r]=t.args;if("op"===r.type&&"="===r.op){const t=Qn(r.args[0]);if(!t)throw new j("a derivative at a point names its variable: der(f, x = a)");return Un(e,t,dt(Vn(r.args[1],n)),n)}const o=Qn(r);if(!o||!n[Jn]?.has(o))throw new j(`a derivative needs a point: der(f, ${o||"x"} = a)`);return Un(e,o,dt(n[o]),n)}(n,e);if("evaluated"===s){const[t,n,r,o]=u;return zt(Vn(t,Hn(e,n.value,c(o))),Vn(t,Hn(e,n.value,c(r))))}if("int"===s)return function(t,n){const[e,r,o,a]=t,s=t=>t&&"symbol"===t.type&&/^[a-zA-Zʹ-Ͽ]$/.test(t.value);let u,c,l;if(4===t.length)[u,c,l]=[Qn(r),o,a];else{if(3!==t.length||s(r))throw new j("an integral needs limits to be calculated");[u,c,l]=[i(e)||"x",r,o]}let f=dt(Vn(c,n)),h=dt(Vn(l,n));if(f===h)return ot(0);let m=1;f>h&&([f,h]=[h,f],m=-1);const g=Kn(e,u,n),{value:p,error:d}=Yn(g,f,h);return oe(m*p,d)}(u,e);if("lim"===s)return function(t,n){const[e,r,o,a]=t;let s,u,c=0;if(2===t.length&&"op"===r.type&&"→"===r.op)[s,u]=[Qn(r.args[0]),r.args[1]];else if(2===t.length)[s,u]=[i(e),r];else{if(!(t.length>=3))throw new j("a limit needs a point");[s,u]=[Qn(r),o]}if(4===t.length){const t="op"===a.type?"":String(a.value).toLowerCase();c=t.startsWith("r")||"+"===t?1:-1}if(!s)throw new j("a limit needs a variable");const l=Vn(u,n),f=dt(l),h=Kn(e,s,n);let m,g;if(Number.isFinite(f))if(c){({value:m,error:g}=ne(t=>h(f+c*t*Math.max(1,Math.abs(f)))));try{const t=Vn(e,Hn(n,s,l));if(Math.abs(dt(t)-m)<=Math.max(g,1e-6*Math.max(1,Math.abs(m))))return t}catch(t){if(!(t instanceof z))throw t}}else{const t=ne(t=>h(f+t*Math.max(1,Math.abs(f)))),r=ne(t=>h(f-t*Math.max(1,Math.abs(f))));if(t.value===r.value)({value:m,error:g}=t);else{if(!(Number.isFinite(t.value)&&Number.isFinite(r.value)&&Math.abs(t.value-r.value)<=1e-6*Math.max(1,Math.abs(t.value))))throw new z("the limit does not exist");m=(t.value+r.value)/2,g=Math.max(t.error,r.error,Math.abs(t.value-r.value))}try{const t=Vn(e,Hn(n,s,l));if(Math.abs(dt(t)-m)<=1e-6*Math.max(1,Math.abs(m)))return t}catch(t){if(!(t instanceof z))throw t}}else({value:m,error:g}=ne(t=>h(Math.sign(f)/t)));return Number.isFinite(m)?oe(m,g):m}(u,e);if("\\sumidx"===s||"\\prodidx"===s)return function(t,n,e){const[r,o,a]=n;if(n.length<3)throw new j("a sum needs its limits");let s,u=o;"op"===o.type&&"="===o.op&&"symbol"===o.args[0].type?[s,u]=[o.args[0].value,o.args[1]]:s=i(r)||"n";const c=vn(Vn(u,e),"a sum"),l=Vn(a,e),f=t?Et:jt;if(l===1/0){if(!t)throw new j("an infinite product");return function(t,n){const e=[],r=[];let o=0,i=n;for(let a=4;a<=17;a++){const s=2**a;for(;i<n+s;i++){const n=t(i);if(!Number.isFinite(n))throw new z("undefined");o+=n}if(e.push(s),r.push(o),a>=6&&r[r.length-1]===r[r.length-2]&&!re(t,n,i))return oe(o,0)}if(re(t,n,i))throw new z("the series diverges");const a=r[r.length-1]-r[r.length-2],s=r[r.length-2]-r[r.length-3],u=r[r.length-3]-r[r.length-4],c=a/s;if(Math.abs(a)>1e-12&&c>=.999&&s/u>=.999)throw new z("the series diverges");if(Math.abs(a)>1e-6*Math.max(1,Math.abs(o))&&c>=.9)throw new j("the series grows too slowly to tell whether it has a sum");const l=e.slice(-7).map(t=>1/t),f=r.slice(-7),h=r.slice(-8,-1),m=(t,n)=>{const e=n.slice();for(let n=1;n<t.length;n++)for(let r=0;r<t.length-n;r++)e[r]=(t[r+n]*e[r]-t[r]*e[r+1])/(t[r+n]-t[r]);return e[0]},g=m(l,f),p=m(e.slice(-8,-1).map(t=>1/t),h);return oe(g,Math.abs(g-p))}(Kn(r,s,e),Number(c))}const h=vn(l,"a sum");if(h-c+1n>BigInt(W.terms))throw new j("too many terms to add one by one");let m=ot(t?0:1);for(let t=c;t<=h;t++)m=f(m,Vn(r,Hn(e,s,rt(V(t)))));return m}("\\sumidx"===s,u,e);if(["()","[]","{}"].includes(s))return ft(u.map(c),s);if("pmatrix"===s||"bmatrix"===s)return Cn(n,c);if("vmatrix"===s)return Dn(Cn(n,c));if("^"===s&&"symbol"===u[1].type&&"T"===u[1].value&&!Object.prototype.hasOwnProperty.call(e,"T")){const t=c(u[0]);if(zn(t))return Tn.transpose(t)}if("pmod"===s)return function([t,n],e){const r=e(n);return"op"===t.type&&["≡","="].includes(t.op)&&2===t.args.length?ct(Fn(zt(e(t.args[0]),e(t.args[1])),r)):Fn(e(t),r)}(u,c);if("setbuilder"===s)throw new j("a set described by a condition has no list of values");if(o(n))return c(o(n));if("∈"===s||"∉"===s){const t=function(t,n){const[e,r]=t.args,o=n(e);let i;if("symbol"===r.type&&["ℤ","ℕ","ℚ","ℝ"].includes(r.value)&&st(o))i="ℝ"===r.value||("ℚ"===r.value?ut(o):ut(o)&&1n===o.c.d&&("ℤ"===r.value||o.c.n>0n));else if("op"===r.type&&["()","[]","(]","[)"].includes(r.op)&&2===r.args.length){const[t,e]=r.args.map(n),a=fn(o,t),s=fn(o,e);i=("["===r.op[0]?a>=0:a>0)&&("]"===r.op[1]?s<=0:s<0)}else{if("op"!==r.type||"{}"!==r.op)return;i=r.args.some(t=>hn(o,n(t)))}return"∈"===t.op?i:!i}(n,c);if(void 0!==t)return t}if(Rn.includes(s))return function(n,e){const r={};for(const[t,n]of Object.entries(e))"function"!=typeof n&&(r[t]=yt(n));try{return Mt(function(n,e={}){0===S&&(O=0),S++;try{return E(t(n),e)}finally{S--}}(n,r))}catch(t){throw new j(t.message)}}(n,e);if(s.startsWith("\\:")){const t=s.slice(2),n=Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if("function"!=typeof n&&Object.prototype.hasOwnProperty.call(qn,t))return qn[t](...u.map(c));if("function"!=typeof n)throw new j(`no function ${s.slice(2)}`);return Mt(n(...u.map(t=>yt(c(t)))))}if(Sn[s]&&1===u.length)return Sn[s](c(u[0]));if(Gn[s]&&2===u.length)return Gn[s](c(u[0]),c(u[1]));if(Ln[s])return Ln[s](u.map(c));throw new j(`can't calculate '${s}'`)}function Xn(t,e){if(Object.prototype.hasOwnProperty.call(e,t))return e[t];if(Object.prototype.hasOwnProperty.call(On,t))return On[t]();if(n(t))return rt(et(n(t)));if("i"===t)return Lt();if(/^[A-Za-z\u0370-\u03FF][A-Za-z0-9_\u0370-\u03FF′]*$/.test(t))return Vt([{vars:[[t,1]],re:ot(1),im:ot(0)}]);throw new j(`no value for '${t}'`)}const Jn=Symbol("bound"),Hn=(t,n,e)=>({...t,[n]:e,[Jn]:new Set([...t[Jn]??[],n])});function Kn(t,n,e){return r=>{try{return dt(Vn(t,Hn(e,n,r)))}catch(t){if(t instanceof z)return NaN;if(t instanceof T)return 0;throw t}}}const Qn=t=>"symbol"===t.type?t.value:null;function Un(t,n,e,r){const o=Kn(t,n,r);if(!Number.isFinite(o(e)))throw new z("undefined");const i=1e-6*Math.max(1,Math.abs(e)),a=(o(e+i)-o(e))/i,s=(o(e)-o(e-i))/i;if(!Number.isFinite(a)||!Number.isFinite(s)||Math.abs(a-s)>.001*Math.max(1,Math.abs(a)))throw new z("not differentiable here");let u=.1*Math.max(1,Math.abs(e));const c=1.4,l=[[(o(e+u)-o(e-u))/(2*u)]];let f=l[0][0],h=1/0;for(let t=1;t<12;t++){u/=c,l[t]=[(o(e+u)-o(e-u))/(2*u)];let n=c*c;for(let e=1;e<=t;e++){l[t][e]=(l[t][e-1]*n-l[t-1][e-1])/(n-1),n*=c*c;const r=Math.max(Math.abs(l[t][e]-l[t][e-1]),Math.abs(l[t][e]-l[t-1][e-1]));r<=h&&(h=r,f=l[t][e])}if(Math.abs(l[t][t]-l[t-1][t-1])>=2*h)break}if(!Number.isFinite(f))throw new z("not differentiable here");return oe(f,h)}function Yn(t,n,e){if(n===-1/0&&e===1/0){const n=Yn(t,-1/0,0),e=Yn(t,0,1/0);return{value:n.value+e.value,error:n.error+e.error}}return e===1/0?te(e=>t(n+e/(1-e))/((1-e)*(1-e)),0,1):n===-1/0?te(n=>t(e-n/(1-n))/((1-n)*(1-n)),0,1):te(t,n,e)}function te(t,n,e,r=0){try{return function(t,n,e){const r=(e-n)/2,o=4;let i=1,a=0,s=NaN,u=NaN,c=0;const l=i=>{const a=Math.PI/2*Math.sinh(Math.abs(i)),s=Math.exp(-2*a),u=2*r*s/(1+s),l=r*(Math.PI/2)*Math.cosh(i)*(4*s)/((1+s)*(1+s));if(0===u||0===l)return 0;const f=i>0?e-u:n+u;if(0!==i&&(f<=n||f>=e))return 0;const h=t(0===i?(n+e)/2:f);if(!Number.isFinite(h)){if(u<1e-6*r)return 0;throw new z("the integral diverges")}return Math.abs(i)>o-.5&&(c=Math.max(c,Math.abs(l*h))),l*h};a=l(0);for(let t=i;t<=o;t+=i)a+=l(t)+l(-t);s=i*a;for(let t=1;t<=8;t++){i/=2;for(let t=i;t<=o;t+=2*i)a+=l(t)+l(-t);u=s,s=i*a;const n=Math.max(1,Math.abs(s));if(c>1e-8*n)throw new z("the integral diverges");if(t>=3&&Math.abs(s-u)<=1e-13*n)break}const f=Math.abs(s-u);if(!Number.isFinite(s)||f>1e-6*Math.max(1,Math.abs(s)))throw new z("the integral does not converge");return{value:s,error:f}}(t,n,e)}catch(t){if(!(t instanceof z)||"the integral does not converge"!==t.message||r>=10)throw t}const o=(n+e)/2,i=te(t,n,o,r+1),a=te(t,o,e,r+1);return{value:i.value+a.value,error:i.error+a.error}}function ne(t){const n=ee(t),e=ee(n=>t(.7548776662466927*n));if(n.value===e.value)return n;if(!Number.isFinite(n.value)||!Number.isFinite(e.value))throw new z("the limit does not exist");const r=Math.max(1,Math.abs(n.value)),o=Math.max(n.error,e.error,1e-6*r);if(o>.001*r)throw new z("the limit could not be found");if(Math.abs(n.value-e.value)<=o)return n;throw new z("the limit does not exist")}function ee(t){const n=[],e=[];for(let r=0;r<30;r++){const o=.1/2**r,i=t(o);Number.isFinite(i)&&(n.push(o),e.push(i))}if(e.length<6)throw new z("undefined");const r=e.slice(1).map((t,n)=>t-e[n]).slice(-6);if(r.every(t=>Math.sign(t)===Math.sign(r[0])&&0!==t)&&Math.abs(r[5])>=.95*Math.abs(r[0])&&Math.abs(e[e.length-1])>10)return{value:Math.sign(r[0])*(1/0),error:0};const o=t=>{const r=n.slice(t,t+8),o=e.slice(t,t+8);for(let t=1;t<r.length;t++)for(let n=0;n<r.length-t;n++)o[n]=(r[n+t]*o[n]-r[n]*o[n+1])/(r[n+t]-r[n]);return o[0]};let i=null;for(let t=0;t+9<=e.length;t++){const n=o(t),e=o(t+1),r=Math.abs(n-e);Number.isFinite(n)&&(!i||r<i.error)&&(i={value:n,error:r})}const a=t=>{const n=e[t+1]-e[t],r=e[t+2]-e[t+1];return r===n?e[t+2]:e[t+2]-r*r/(r-n)},s=t=>(e[t+2]-e[t+1])/(e[t+1]-e[t]),u=t=>[t,t+1].every(t=>s(t)>0&&s(t)<.95)&&Math.abs(s(t)-s(t+1))<.05;for(let t=0;t+3<e.length;t++){if(!u(t))continue;const n=a(t),e=Math.abs(n-a(t+1));Number.isFinite(n)&&(!i||e<i.error)&&(i={value:n,error:e})}const c=e[e.length-1],l=Math.abs(c-e[e.length-2]);if(!i||i.error>Math.max(l,1e-6*Math.max(1,Math.abs(c)))){if(l<=1e-6*Math.max(1,Math.abs(c)))return{value:c,error:10*l};throw new z("the limit could not be found")}return i}function re(t,n,e){const r=n=>Math.max(...Array.from({length:8},(e,r)=>Math.abs(t(n+r)))),o=r(e);return o>1e-12&&o>=.5*r(n+Math.floor((e-n)/16))}function oe(t,n=0){if(!Number.isFinite(t))return t;const e=Math.max(1e-10,4*n)*Math.max(1,Math.abs(t));if(e>1e-6*Math.max(1,Math.abs(t)))return function(t,n){if(!(n>0)||0===t)return t;const e=Math.floor(-Math.log10(n/Math.abs(t)));return e>=15?t:Number(t.toPrecision(Math.max(1,e)))}(t,n);if(Math.abs(t)<=Math.max(4*n,1e-15))return ot(0);if(Math.abs(t)<1e-10)return t;const r=[[ot(1),1e3],[it,100],[rt(J,2),100],[at,100],...[2n,3n,5n,6n,7n].map(t=>[rt(J,0,0,{n:2,r:t}),100])];for(const[n,o]of r){const r=t/dt(n),i=ie(r,o);if(i&&Math.abs(Number(i.n)/Number(i.d)-r)*dt(n)<=e)return Nt(rt(i),n)}return t}function ie(t,n){if(!Number.isFinite(t)||Math.abs(t)>1e12)return null;let[e,r,o,i]=[0,1,1,0],a=t;for(let t=0;t<40;t++){const t=Math.floor(a),s=t*r+e,u=t*i+o;if(u>n)break;if([e,r,o,i]=[r,s,i,u],Math.abs(a-t)<1e-15)break;a=1/(a-t)}return i?V(BigInt(r),BigInt(i)):null}function ae(t,n){if("boolean"==typeof t)return String(t);if(Ct(t))return se(t,n);if(t&&"s"===t.kind)return JSON.stringify(t.text);if(Array.isArray(t)){if("pm"===t.group&&2===t.length&&hn(t[1],Pt(t[0])))return`±${ce(t[0],n)}`;if(Pn.has(t.group)&&l(t))return`${t.group}(${t.map(t=>`[${t.map(t=>ae(t,n)).join(", ")}]`).join(", ")})`;const[e,r]={"()":"()","[]":"[]","{}":"{}"}[t.group]||"{}";return e+t.map(t=>ae(t,n)).join(", ")+r}return"number"==typeof t?le(t,n):n.decimal||null!==n.places?function(t,n){if(ut(t)&&null===n.places){let e=t.c.d,r=0,o=0;for(;e%2n==0n;)e/=2n,r++;for(;e%5n==0n;)e/=5n,o++;const i=Math.max(r,o);if(1n===e&&i<=n.digits){const e=t.c.n*10n**BigInt(i)/t.c.d,r=e<0n,o=C(e).toString().padStart(i+1,"0"),a=i?`${o.slice(0,-i)}.${o.slice(-i)}`:o;if(o.length<=n.maxDigits)return(r?"-":"")+fe(a)}}return ut(t)&&null!==n.places?ae(An(t,ot(n.places)),{...n,places:null,decimal:!0}):le(dt(t),n)}(t,n):function(t,n){const{c:e}=t,r=C(e.n);if(r.toString().length>n.maxDigits||e.d.toString().length>n.maxDigits)return function(t,n){if(!ut(t))return le(dt(t),n);if(1n!==t.c.d){const e=dt(t);if(0!==e&&Number.isFinite(e))return le(e,n);const r=C(t.c.n),o=t.c.d,i=n.digits+1-(r.toString().length-o.toString().length),a=(i>=0?r*10n**BigInt(i)/o:r/(o*10n**BigInt(-i))).toString(),s=((BigInt(a.slice(0,n.digits+1))+5n)/10n).toString(),u=a.length-1-i+(s.length>n.digits?1:0),c=fe(`${s[0]}.${s.slice(1,n.digits)}`);return`${t.c.n<0n?"-":""}${c}*10^(${u})`}const e=C(t.c.n).toString(),r=BigInt(e.slice(0,n.digits+1)),o=((r+5n)/10n).toString(),i=e.length-1+(o.length>n.digits?1:0),a=fe(`${o[0]}.${o.slice(1,n.digits)}`);return`${t.c.n<0n?"-":""}${a}*10^(${i})`}(t,n);const o=(t,n)=>1===n?t:`${t}^${n}`,i=[],a=[];t.pi>0&&i.push(o("pi",t.pi));t.pi<0&&a.push(o("pi",-t.pi));t.e>0&&i.push(o("e",t.e));t.e<0&&a.push(o("e",-t.e));t.root&&i.push(2===t.root.n?`sqrt(${t.root.r})`:`root(${t.root.n}, ${t.root.r})`);1n===r&&i.length||i.unshift(r.toString());1n!==e.d&&a.unshift(e.d.toString());const s=t=>t.length>1?`(${t.join("*")})`:t[0],u=a.length?`${s(i)}/${s(a)}`:i.join("*");return(e.n<0n?"-":"")+u}(t,n)}function se(t,n){const e=t=>t.vars.reduce((t,[,n])=>t+n,0),r=[...new Set([...t.terms.values()].flatMap(t=>t.vars.map(([t])=>t)))].sort(),o=(t,n)=>t.vars.find(([t])=>t===n)?.[1]??0,i=[...t.terms.values()].sort((t,n)=>e(n)-e(t)||r.reduce((e,r)=>e||o(n,r)-o(t,r),0)).map(t=>function(t,n){const e=Rt(t.vars);if(!e)return ue(t.re,t.im,n);if(!ct(t.im))return`(${ue(t.re,t.im,n)})*${e}`;const r=t.re,o=ae(r,n);if("1"===o)return e;if("-1"===o)return`-${e}`;if(ut(r)&&1n!==r.c.d&&!n.decimal&&null===n.places){const t=C(r.c.n);return`${r.c.n<0n?"-":""}${1n===t?e:`${t}*${e}`}/${r.c.d}`}return/^-?[\w.^]+(?:\([\w ,.]*\))?$/.test(o)?`${o}*${e}`:`(${o})*${e}`}(t,n));return i.reduce((t,n,e)=>0===e?n:n.startsWith("-")?`${t} - ${n.slice(1)}`:`${t} + ${n}`,"")}function ue(t,n,e){if(ct(n))return ae(t,e);const r=!ct(n)&&fn(n,ot(0))<0,o=ae(r?Ot(n):n,e),i="1"===o?"i":/^[\d.]+$/.test(o)?`${o}*i`:`(${o})*i`;return ct(t)?r?`-${i}`:i:`${ae(t,e)} ${r?"-":"+"} ${i}`}const ce=(t,n)=>{const e=ae(t,n);return/^[\d.]+$|^[a-zπ]+$/i.test(e)?e:`(${e})`};function le(t,n){if(t===1/0)return"∞";if(t===-1/0)return"-∞";if(Object.is(t,-0)||0===t)return"0";if(null!==n.places&&Math.abs(t)<1e21)return In(t,n.places);const e=Math.abs(t);if(e>=1e15||e<1e-6){const[e,r]=t.toExponential(n.digits-1).split("e");return`${fe(e)}*10^(${Number(r)})`}return String(Number(t.toPrecision(n.digits)))}const fe=t=>t.includes(".")?t.replace(/\.?0+$/,""):t;function he(t,n={},e={}){0===D&&(_=0);const r="string"==typeof t?a(t):s(t),o={};for(const[t,e]of Object.entries(n))o[t]=Mt(e);D++;const i=qt;let c,l=!1;u(r,t=>{"symbol"!==t.type||"i"!==t.value||Object.prototype.hasOwnProperty.call(n,"i")||(l=!0)}),qt=e.complex??(l||D>1&&i);try{c=Vn(r,o)}finally{D--,qt=i}const f={decimal:!1,places:null,digits:12,maxDigits:50,...e};if(void 0===f.places&&(f.places=null),null!==f.places&&!(Number.isInteger(f.places)&&f.places>=0&&f.places<=W.places))throw new j(`places is a whole number from 0 to ${W.places}`);const h=t=>Array.isArray(t)?t.every(h):Ct(t)?[...t.terms.values()].every(t=>"number"!=typeof t.re&&"number"!=typeof t.im):"number"!=typeof t;return{value:yt(c),text:ae(c,f),exact:h(c)}}function me(t,n={}){let e=t.trim();const r={},o=/^(~|≈)\s*(\d+)?/.exec(e);o&&(r.decimal=!0,void 0!==o[2]&&(r.places=Number(o[2])),e=e.slice(o[0].length)),/\d\.\d|\.\d/.test(e)&&(r.decimal=!0);try{const{text:t}=he(e,n,r);return t.startsWith('"')||/^\d+(\.\d+)?$/.test(t)?t:`(${t})`}catch(t){if(t instanceof z)return'"undefined"';if(t instanceof j)return`(${e})`;throw t}}c(me);for(const t of[W,mn,On,Sn,Gn,Ln])Object.setPrototypeOf(t,null);Object.setPrototypeOf(qn,null);export{he as a,me as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate (and mathzetta/text, for cas.external.js) with an import map */
|
|
2
|
+
import{GREEK as t,isCustomFunction as e,matrixRows as r,unaryNeedsBrackets as s,bracketOp as i,precedenceOf as n,isMinusOneTimes as l,needsBrackets as a,bracketedSides as o,isImplicitProduct as h,customName as c,derivativeOrder as u,isVariable as d,firstLeaf as p,firstVariable as f,MATRICES as m,walk as g,toPostfix as b,operator as v,VARIADIC as x,parseTree as $,fromPostfix as y}from"mathzetta";import{toAudioSpeech as w}from"mathzetta/speech";const L={"(":{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 M(t,e,r=""){const s=L[t];return`<svg class="${e}" viewBox="0 0 1 1" preserveAspectRatio="none" aria-hidden="true"${r?` style="${r}"`:""}>${s.fill?`<path d="${s.fill}" fill="currentColor"/>`:`<path d="${s.stroke}" fill="none" stroke="currentColor" vector-effect="non-scaling-stroke"/>`}</svg>`}const k=.8,C=.2,z=.25,j=.7,P="−",A={"+":"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"},Z={"=":"=","===":"=","≠":"≠","≠=":"≠","<":"<",">":">","≤":"≤","≥":"≥","∈":"∈","∉":"∉","→":"→","≈":"≈","≡":"≡","&":"∧","|":"∨","\\xor":"⊕","\\nand":"↑","\\nor":"↓","\\implies":"⇒","\\iff":"⇔"},F={"±":"±","∪":"∪","∩":"∩",mod:"mod"},q=["sin","cos","tan","csc","sec","cot","sinh","cosh","tanh"],O={arcsin:"sin",arccos:"cos",arctan:"tan",arcsec:"sec",arccsc:"csc",arccot:"cot",arcsinh:"sinh",arccosh:"cosh",arctanh:"tanh"},B=[...q,...Object.keys(O),"ln","det"],S={atan2:"atan2",max:"max",min:"min",gcd:"gcd",mean:"mean",round:"round",fixed:"fixed",expm1:"expm1",random:"random"},W={"()":["(",")"],"[]":["[","]"],"{}":["{","}"],"(]":["(","]"],"[)":["[",")"]},E=["int","lim","\\sumidx","\\prodidx"],_={"\\partial":"∂","\\nabla":"∇","\\ell":"ℓ","\\infty":"∞","\\emptyset":"∅"},I={vec:"→",hat:"ˆ",widehat:"ˆ",tilde:"˜",dot:"˙",ddot:"¨"},N=/^[acegmnopqrsuvwxyzαγεημνοπρστυχω]$/,T=e=>"symbol"===e?.type&&N.test(t[e.value]??e.value),D=["boxed","overline","bar","underline","cancel",...Object.keys(I)],R={prefix:"mv",display:!0,fnParens:"auto",trigPowers:!0,inverseTrig:"arc",derivativeBrackets:"[",scriptFractions:"slash",cases:!0,label:!0,mathml:null,attributes:null,style:null},G=t=>String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),H=t=>+t.toFixed(3)+"em",J=(t,e=k,r=C)=>({html:t,h:e,d:r});function K(...t){const e=t.flat().filter(Boolean);return{html:e.map(t=>t.html).join(""),h:Math.max(k,...e.map(t=>t.h)),d:Math.max(C,...e.map(t=>t.d))}}function Q(t,e={}){const r=new U({...R,...e}),s=r.render(t,{level:0}),i=`${r.p}${r.o.display?` ${r.p}-display`:""}`,n="function"==typeof r.o.mathml?function(t,e,r,s){try{return String(t(e)).replace(/ id="mz-\d+"/g,"").replace(/^<math>/,`<math class="${r}-sr-math"${s?' display="block"':""}>`)}catch{return""}}(r.o.mathml,t,r.p,r.o.display):"",l=n?null:function(t,e){if(!1===e||null===e)return null;if("string"==typeof e)return e;try{return"function"==typeof e?e(t):w(t)}catch{return null}}(t,r.o.label),a=null!==l||n?s.html.replace(/^<span /,'<span aria-hidden="true" '):s.html;return{html:`<span class="${i}"${null===l?"":` role="math" aria-label="${G(l)}"`}>${a}${n}</span>`,h:s.h,d:s.d}}class U{constructor(t){this.o=t,this.p=t.prefix}el(t,e,r="",s=""){return`<span class="${t.split(" ").map(t=>`${this.p}-${t}`).join(" ")}"${r?` style="${r}"`:""}${s}>${e}</span>`}text(t,e){const r=J(this.el(t,G(e)));return r.leaf={kind:t,content:G(e)},r}bin(t){return this.text("bin",t)}rel(t){return this.text("rel",t)}punct(t){return this.text("punct",t)}word(t){return this.text("word",t)}wrap(t,e,r){let s="";void 0!==t.id&&(s+=` data-node="${t.id}"`),"op"===t.type&&(s+=` data-op="${G(t.op)}"`);const i=this.o.attributes&&this.o.attributes(t)||{};for(const[t,e]of Object.entries(i))"class"!==t&&"style"!==t&&/^[A-Za-z_:][\w:.-]*$/.test(t)&&(s+=` ${t}="${G(e)}"`);const n=[i.style,this.o.style&&this.o.style(t)].filter(Boolean).join(";"),l=(r.leaf?["n",...e,r.leaf.kind]:["n",...e]).map(t=>`${this.p}-${t}`).concat(i.class?[G(i.class)]:[]).join(" "),a=r.leaf?r.leaf.content:r.html;return{html:`<span class="${l}"${n?` style="${G(n)}"`:""}${s}>${a}</span>`,h:r.h,d:r.d}}render(t,e){return"number"===t.type?this.number(t):"string"===t.type?this.wrap(t,["text"],this.text("text",t.value.replace(/^["'`]|["'`]$/g,""))):"symbol"===t.type?this.wrap(t,["symbol"],this.symbol(t.value)):this.operation(t,e)}number(t){const e=/^(-?\d*\.)(\d*)\.\.$/.exec(t.value);if(e){const[,r,s]=e;let i=1;for(let t=1;2*t<=s.length;t++)if(s.slice(-t)===s.slice(-2*t,-t)){i=t;break}let n=s;for(;n.endsWith(s.slice(-i))&&n.length>=i;)n=n.slice(0,-i);const l=this.text("num",(r+n).replace(/^-/,P)),a=this.text("num",s.slice(-i));return this.wrap(t,["number"],K(l,J(this.el("over",a.html),a.h+.14,a.d)))}return this.wrap(t,["number"],this.text("num",t.value.replace(/^-/,P)))}symbol(e){return t[e]&&(e=t[e]),_[e]?this.text("ord",_[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)?J(this.el("var",G(e[0]))+this.el("prime",G(e.slice(1)))):/^Δ[A-Za-z]$/.test(e)?J(this.el("ord","Δ")+this.el("var",e[1])):/^d[A-Za-zα-ω]$/.test(e)?J(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(t,o){const{op:h,args:c}=t,[u,d]=c,p=(t,e={})=>this.render(t,{...o,...e,forceParens:e.forceParens||!1,before:e.before||!1,leftFactor:!1}),f=A[h]??(/^[a-z0-9]+$/i.test(h)?h:"other"),m=e=>this.wrap(t,["op",`op-${f}`],e),g=(e,r)=>a(t,e,r)&&"/"!==e.op?this.fence(p(e)):p(e);if(B.includes(h)||"log"===h)return m(this.named(t,o));if(S[h])return m(K(this.word(S[h]),this.fence(this.list(c,o))));if(e(h))return m(this.custom(t,o));const b=r(t);if(b)return m(this.matrix(t,b,o));if("{}"===h&&!c.length)return m(this.text("op","∅"));if(W[h])return m(this.fence(this.list(c,o),...W[h]));if(("|"===h||"&"===h)&&c.length>=2&&c.every(Y)){const t=t=>"|"!==t.op&&"&"!==t.op||t.op===h?p(t):this.fence(p(t));return m(K(c.map((e,r)=>r?[this.text("conj","|"===h?"or":"and"),t(e)]:[t(e)]).flat()))}if(Z[h]&&2===c.length)return m(K(g(u,"left"),this.rel(Z[h]),g(d,"right")));if(F[h]&&2===c.length)return m(K(g(u,"left"),this.bin(F[h]),g(d,"right")));switch(h){case"+":if(l(d)){const t=d.args[1],e=a({op:"-"},t,"right")?this.fence(p(t)):p(t);return m(K(g(u,"left"),this.bin(P),this.wrap(d,["op","op-mul"],e)))}return"number"===d.type&&d.value.startsWith("-")?m(K(g(u,"left"),this.bin(P),this.wrap(d,["number"],this.text("num",d.value.slice(1))))):m(K(g(u,"left"),this.bin("+"),this.signed(d,g(d,"right"))));case"-":return m(K(g(u,"left"),this.bin(P),this.signed(d,g(d,"right"))));case"*":return m(this.product(t,o));case"/":return m(this.fraction(t,o));case"^":return m(this.power(t,o));case"_":{const t=i(u)&&n(i(u))<100;return m(this.script(t?this.fence(p(u)):p(u,{forceParens:!0}),null,o,p(d,{level:o.level+1})))}case"neg":return m(K(this.text("sign",P),s(h,u)?this.fence(p(u)):p(u,{before:o.before})));case"pm":return m(K(this.text("sign","±"),s(h,u)?this.fence(p(u)):p(u)));case"!":return m(K(s(h,u)?this.fence(p(u)):p(u,{forceParens:!0}),this.text("ord","!")));case"\\not":return m(K(this.text("sign","¬"),s(h,u)?this.fence(p(u)):p(u)));case"pmod":return m(K(p(u),this.fence(K(this.word("mod"),this.text("space",""),p(d)))));case"sqrt":return m(this.radical(p(u)));case"root":return m(this.radical(p(d),this.render(u,{level:o.level+2})));case"abs":return m(this.fence(p(u),"|","|"));case"floor":return m(this.fence(p(u),"⌊","⌋"));case"ceil":return m(this.fence(p(u),"⌈","⌉"));case"loglog":return m(K(this.word("ln"),this.fence(K(this.word("ln"),this.fence(p(u))))));case"logloglog":return m(K(this.word("ln"),this.fence(K(this.word("ln"),this.fence(K(this.word("ln"),this.fence(p(u))))))));case"perm":return m(this.script(this.script(J(""),this.render(u,{level:o.level+1}),o),null,o,this.render(d,{level:o.level+1}),this.word("P")));case"comb":return m(this.fence(this.stack(p(u),p(d),!1)));case"?:":return m(this.o.cases?this.cases(t,o):K(p(u),this.bin("?"),p(d),this.bin(":"),p(c[2])));case"sum":case"prod":{const t={op:"sum"===h?"+":"*"},e=(e,r)=>a(t,e,r?"right":"left")?this.fence(p(e)):p(e);return m(K(c.map((t,r)=>r?[this.bin("sum"===h?"+":"·"),e(t,r)]:[e(t,r)]).flat()))}case"setbuilder":return m(this.fence(K(p(u),this.bin("|"),p(d)),"{","}"));case"evaluated":{const t=t=>this.render(t,{...o,level:o.level+1});return m(this.script(this.fence(p(u),"[","]"),t(c[3]),o,t(c[2])))}case"der":return m(this.derivative(t,o));case"int":return m(this.integral(c,o));case"lim":return m(this.limit(c,o));case"\\sumidx":return m(this.bigOperator("sum",c,o));case"\\prodidx":return m(this.bigOperator("prod",c,o))}throw new Error(`Inline Math cannot draw '${h}'`)}signed(t,e){return("number"===t.type?t.value.startsWith("-"):"neg"===t.op||"pm"===t.op)&&!e.fenced?this.fence(e):e}list(t,e){return K(t.map((t,r)=>r?[this.punct(","),this.render(t,e)]:[this.render(t,e)]).flat())}product(t,r){const[i,n]=t.args;if(l(t))return K(this.text("sign",P),s("neg",n)?this.fence(this.render(n,r)):this.render(n,r));const a=o(t);E.includes(i.op)&&(a.left=!0);const c=!t.written&&h(i,n,a),u=function(t){for(;"op"===t.type;){if(B.includes(t.op)||"log"===t.op||S[t.op]||e(t.op))return!0;if("^"!==t.op&&"*"!==t.op)return!1;t=t.args[0]}return!1}(n),d=a.left?this.fence(this.render(i,r)):this.render(i,{...r,before:c&&!u,leftFactor:!0}),p=a.right?this.fence(this.render(n,r)):this.render(n,{...r,before:r.before});return K(d,c?J(this.el(u?"fnspace":"times","")):this.bin("cross"===t.written?"×":"·"),p)}named(t,e,r=null){const{op:s,args:i}=t,n="log"===s?i[1]:i[0];let l;l=O[s]&&"power"===this.o.inverseTrig?this.script(this.word(O[s]),this.text("num","−1"),e):this.word(s),r&&(l=this.script(l,r,e)),"log"===s&&(l=this.script(l,null,e,this.render(i[0],{level:e.level+1})));const a="auto"===this.o.fnParens&&!e.forceParens&&!e.before&&V(n),o=this.render(n,{...e,forceParens:!1,before:!1});return K(l,a?K(J(this.el("fnspace","")),o):this.fence(o))}custom(t,e){const r=c(t.op),s=t.args;if(D.includes(r)&&1===s.length)return this.decorate(r,this.render(s[0],e),s[0]);return K(/^[A-Za-z]′*(⁻¹)?$/.test(r)?this.symbol(r):this.word(r),J(this.el("callgap","")),this.fence(this.list(s,e)))}decorate(t,e,r){switch(t){case"boxed":return J(this.el("boxed",e.html),e.h+.22,e.d+.22);case"cancel":return J(this.el("cancel",e.html+M("cancel",`${this.p}-cancel-line`)),e.h,e.d);case"underline":return J(this.el("underline",e.html),e.h,e.d+.12);case"overline":case"bar":return J(this.el("over"+(T(r)?" over-low":""),e.html),e.h+.14,e.d);default:{const s=T(r);return J(this.el("accent"+(s?" accent-low":""),this.el(`accent-mark accent-${t}`,I[t])+e.html),e.h+.3,e.d)}}}fraction(t,e){const[r,s]=t.args;if(e.level>0&&"slash"===this.o.scriptFractions&&V(r,!0)&&V(s,!0)){const t={...e,leftFactor:!1},i=(e,r)=>"op"!==e.type||V(e)&&(!r||"*"!==e.op||l(e))?this.render(e,t):this.fence(this.render(e,t)),n=K("op"===r.type&&"neg"===r.op?this.render(r,t):i(r,!1),this.text("ord","/"),i(s,!0));return e.leftFactor?this.fence(n):n}const i=e.level>0||e.inFraction||!this.o.display?.8:1,n={...e,inFraction:!0,forceParens:!1,before:!1};return this.stack(this.render(r,n),this.render(s,n),!0,i)}stack(t,e,r=!0,s=1){const i=t=>1===s?t.html:this.el("scaled",t.html,`font-size:${H(s)}`),n=r?.06:0,l=z+n/2+.1+Math.max(C,s*t.d),a=this.el("frac"+(r?"":" frac-nobar"),this.el("numer",i(t))+this.el("denom",i(e)),`vertical-align:${H(l)}`);return J(a,l+Math.max(k,s*t.h),Math.max(k,s*e.h)+Math.max(C,s*e.d)+.1+n/2-z)}power(t,e){const[r,s]=t.args,i={...e,level:e.level+1,forceParens:!1,before:!1,inFraction:!1,leftFactor:!1},n=()=>this.render(s,i);if(this.o.trigPowers&&q.includes(r.op)&&et(s))return this.wrap(r,["op",`op-${r.op}`],this.named(r,e,n()));if("_"===r.op){const t=this.render(r.args[1],i);return this.wrap(r,["op","op-subscript"],this.script(this.render(r.args[0],{...e,forceParens:!0}),n(),e,t))}const l=a(t,r,"left")||"number"===r.type&&r.value.startsWith("-")||"/"===r.op||B.includes(r.op)||E.includes(r.op)?this.fence(this.render(r,e)):this.render(r,{...e,forceParens:!0});return this.script(l,n(),e)}script(t,e,r,s=null,i=null){const n=r.level>0?.8:j,l=i?K(t,i):t;let a=e?Math.max(.42,t.h-.38,n*e.d+.12):0,o=s?Math.max(.2,t.d-.05,n*s.h-.45):0;if(e&&s){const t=.1-(a-n*e.d-(n*s.h-o));t>0&&(o+=t)}const h=t=>this.el("script",t.html,`font-size:${H(n)}`);if(e&&!s)return J(t.html+this.el("sup",e.html,`font-size:${H(n)};vertical-align:${H(a/n)}`),Math.max(l.h,a+n*e.h),Math.max(l.d,n*e.d-a));if(s&&!e)return J(l.html+this.el("sub",s.html,`font-size:${H(n)};vertical-align:${H(-o/n)}`),Math.max(l.h,n*s.h-o),Math.max(l.d,o+n*s.d));const c=a+n*e.h,u=o+n*s.d,d=this.el("subsup",h(e)+h(s),`vertical-align:${H(a)};height:${H(c+u)}`);return J(l.html+d,Math.max(l.h,c),Math.max(l.d,u))}radical(t,e=null){const r=Math.max(t.h,k)+.1+.06,s=Math.max(t.d,C),i=r+s,n=.5+.06*(i-1),l=M("sqrt",`${this.p}-hook`,`width:${H(n)};left:${H(-n)}`);let a="";if(e){const t=.8*j;a=this.el("rootindex",e.html,`font-size:${H(t)};vertical-align:${H((.55*i-s)/t)}`)}return J(this.el("sqrt",a+this.el("radicand",l+t.html,`margin-left:${H(n+.05)}`)),r,s)}fence(t,e="(",r=")"){const s=Math.max(t.h,k)+Math.max(t.d,C),i=s>1.25,n=i?.1:0,l=(t,e)=>{if(!t)return{html:"",w:0};const r={"(":.26,")":.26,"{":.36,"}":.36}[t];if(r){const n=r+(i?Math.min(.2,.05*(s-1)):0);return{html:M(t,`${this.p}-delim ${this.p}-delim-${e}`,`width:${H(n)}`),w:n+.1}}const n={"[":"lbrack","]":"rbrack","|":"vert","⌊":"lfloor","⌋":"rfloor","⌈":"lceil","⌉":"rceil"}[t];return{html:this.el(`delim ${n} delim-${e}`,""),w:"|"===t?.18:.3}},a=l(e,"l"),o=l(r,"r"),h=`padding:${H(n)} ${H(o.w)} ${H(n)} ${H(a.w)}`,c=J(this.el("fence",a.html+t.html+o.html,h),Math.max(t.h,k)+n,Math.max(t.d,C)+n);return c.fenced=!0,c}derivative(t,e){const r=this.leibniz(t,e),{by:s,at:i}=u(t);if(!i)return r;const n=t.args[1],l=this.render({...n,args:[{...s,id:void 0},i]},{...e,level:e.level+1});return this.script(this.fence(r,"","|"),null,e,l)}leibniz(t,e){const{n:r,body:s,by:l,variable:a}=u(t),o={...e,level:e.level+1},h=()=>this.text("d","d"),c=()=>r>1?this.render({type:"number",value:String(r)},o):null,d={...e,inFraction:!0},p=K(h(),c()?this.script(this.render(l,d),c(),d):this.render(l,d)),f=t=>K(c()?this.script(h(),c(),d):h(),t||[]),m=e.level>0||e.inFraction||!this.o.display?.8:1;if(a)return this.stack(f(this.render(s,d)),p,!0,m);const g=i(s)&&n(i(s))<100,[b,v]="("===this.o.derivativeBrackets?["(",")"]:["[","]"],x=g?this.fence(this.render(s,e),b,v):this.render(s,e);return K(this.stack(f(),p,!0,m),x)}integral(t,e){const[r,s,i,n]=t,l=t=>this.render(t,e),a=t=>t?this.render(t,{...e,level:e.level+1}):null,o=()=>this.text("var",f(r)||"x");let h,c=null,u=null;switch(t.length){case 1:h=o();break;case 2:d(s)?h=l(s):(h=o(),c=a(s));break;case 3:d(s)?(h=l(s),c=a(i)):(h=o(),c=a(s),u=a(i));break;default:h=l(s),c=a(i),u=a(n)}const p=l(r),m=J(this.el("dx",this.el("d","d")+h.html),h.h,h.d);return K(this.bigSign("int",p,c,u,e),p,m)}bigSign(t,e,r,s,i){const n=!this.o.display||i.level>0,l=Math.max(n?.6:.95,Math.max(e.h-z,e.d+z)+.12),a=M(t,`${this.p}-bigsign ${this.p}-${t}sign`,`height:${H(2*l)};width:${H(n?.38:.5)};vertical-align:${H(z-l)}`);if(!r&&!s)return J(a,z+l,l-z);const o=j,h=s||J(""),c=r||J(""),u=z+l-o*h.h;c.d;const d=this.el("limits",this.el("script",h.html,`font-size:${H(o)}`)+this.el("script lower",c.html,`font-size:${H(o)}`),`vertical-align:${H(u)};height:${H(2*l)}`);return J(a+d,z+l,l-z)}limit(t,e){const[r,s,i,n]=t,l={...e,level:e.level+1},a=t=>this.render(t,l),o=()=>this.rel("→");let h;switch(t.length){case 1:return K(this.word("lim"),J(this.el("fnspace","")),this.body(r,e));case 2:{const t=f(r),e="number"===s.type||"symbol"===s.type&&s.value.includes("∞");h=t&&e?K(this.text("var",t),o(),a(s)):a(s);break}case 3:h=K(a(s),o(),a(i));break;default:{const t=p(n).toLowerCase().startsWith("r")?"+":P;h=K(a(s),o(),this.script(a(i),this.wrap(n,["symbol"],this.text("ord",t)),l))}}return K(this.under(this.word("lim"),h,e),this.body(r,e))}under(t,e,r){return!this.o.display||r.level>0?this.script(t,null,r,e):J(this.el("under",t.html+this.el("script",e.html,`font-size:${H(.7)}`)),t.h,Math.max(t.d,C)+.05+.7*(e.h+e.d))}body(t,e){const r=i(t);return r&&n(r)<n("*")?this.fence(this.render(t,e)):this.render(t,e)}bigOperator(t,e,r){const[s,i,n]=e,l={...r,level:r.level+1},a=i?this.render(i,l):null,o=n?this.render(n,l):null,h=this.body(s,r);if(!this.o.display||r.level>0){const e=.55,s=M(t,`${this.p}-bigsign`,`height:${H(2*e)};width:${H(.8)};vertical-align:${H(z-e)}`);return K(this.script(J(s,z+e,e-z),o,r,a),h)}const c=.68,u=j,d=M(t,`${this.p}-bigsign`,`height:${H(1.36)};width:${H("sum"===t?1:1.05)}`),p=o?1.01+u*o.d:z-c,f=t=>this.el("script",t.html,`font-size:${H(u)}`),m=this.el("bigop",(o?f(o):"")+d+(a?f(a):""),`vertical-align:${H(p)}`);return K(J(m,.93+(o?.08+u*(o.h+o.d):0),c-z+(a?.08+u*(a.h+a.d):0)),h)}matrix(t,e,r){const s=e.map(t=>t.map(t=>this.render(t,r))),i=s.map(t=>({h:Math.max(k,...t.map(t=>t.h)),d:Math.max(C,...t.map(t=>t.d))})),n=i.reduce((t,e)=>t+e.h+e.d,0)+.3*(e.length-1),l=z+n/2-i[0].h,a=s.map((e,r)=>{const s=e.map(t=>this.el("matrix-cell",t.html)).join(""),i=t.args[r];return i&&"op"===i.type&&"[]"===i.op?this.wrap(i,["op","op-list","matrix-row"],J(s)).html:s}).join(""),o=e[0].length,h=J(this.el("matrix",a,`grid-template-columns:repeat(${o},auto);vertical-align:${H(l)}`),z+n/2,n/2-z),[c,u]=m[t.op]??["[","]"];return this.fence(h,c,u)}cases(t,e){const r=[];let s=t;for(;"op"===s.type&&"?:"===s.op;)r.push([this.render(s.args[1],e),K(this.word("if"),this.text("space",""),this.render(s.args[0],e))]),s=s.args[2];"symbol"===s.type&&"unchanged"===s.value||r.push([this.render(s,e),this.word("otherwise")]);const i=r.map(([t,e])=>({h:Math.max(t.h,e.h),d:Math.max(t.d,e.d)})),n=i.reduce((t,e)=>t+e.h+e.d,0)+.25*(r.length-1),l=z+n/2-i[0].h,a=r.map(([t,e])=>this.el("case-value",t.html)+this.el("case-cond",e.html)).join(""),o=J(this.el("cases",a,`vertical-align:${H(l)}`),z+n/2,n/2-z);return this.fence(o,"{","")}}function V(t,e=!1){return"number"===t.type?!t.value.startsWith("-")||e:"symbol"===t.type||"op"===t.type&&("abs"===t.op||r(t)?!e:!e||"neg"!==t.op&&"^"!==t.op?"*"===t.op&&!l(t)&&t.args.every(t=>"number"===t.type&&!t.value.startsWith("-")||tt(t)||"*"===t.op&&V(t,e)):V(t.args[0],!0)&&("neg"===t.op||V(t.args[1],!0)))}const X=["=","===","≠","≠=","<",">","≤","≥","≈","≡","∈","∉"],Y=t=>"op"===t.type&&t.args.length>=2&&(2===t.args.length&&X.includes(t.op)||("|"===t.op||"&"===t.op)&&t.args.every(Y)),tt=e=>"symbol"===e.type&&(1===e.value.length||/^[α-ωΑ-Ω]$/.test(e.value)||Boolean(t[e.value])),et=t=>"number"===t.type&&/^[1-9]\d*$/.test(t.value)&&Number(t.value)<10;for(const t of[A,Z,F,O,S,W,_,I])Object.setPrototypeOf(t,null);function rt(t){const{id:e,from:r,...s}=t;return s.args&&(s.args=s.args.map(rt)),s}const st=t=>b(t).join(" ");function it(t,e){const r=new Set;nt(t,e,r);const s=[];return g(t,t=>{r.has(t)&&s.push(t)}),s}function nt(t,e,r){if(null!=e)if(Array.isArray(e))e.forEach(e=>nt(t,e,r));else if("number"!=typeof e)if("function"!=typeof e){if("string"==typeof e){const s=st($(e));return void g(t,t=>{st(t)===s&&r.add(t)})}if(e.path){const s=lt(t,e.path);return void(s&&r.add(s))}if(e.type){const s=st(e);g(t,t=>{t!==e&&st(t)!==s||r.add(t)})}}else g(t,(t,s)=>{e(t,s)&&r.add(t)});else g(t,t=>{t.id===e&&r.add(t)})}function lt(t,e){let r=t;for(const t of e){if("op"!==r.type||!r.args[t])return null;r=r.args[t]}return r}function at(t,e){const r=[],s=t=>{if(t.id===e)return!0;if("op"!==t.type)return!1;for(let e=0;e<t.args.length;e++){if(r.push(e),s(t.args[e]))return!0;r.pop()}return!1};return s(t)?r:null}function ot(t){let e=0;const r=t=>{"op"===t.type&&(t.args.forEach(r),v(t.op)?.arity===x&&e++),t.id=e++};return r(t),t}function ht(t,e={}){const{blocks:r}=e;if("string"==typeof t)return $(t,r?{blocks:t=>r(t,e.scope)}:{});if(Array.isArray(t))return y(t);if(t&&"object"==typeof t&&t.type){if(void 0!==t.id)return t;const e=structuredClone(t);return g(e,t=>{"op"!==t.type&&void 0!==t.value&&(t.value=String(t.value))}),ot(e)}throw new Error("Inline Math needs an expression, standard postfix or a tree")}function ct(t,e={}){const r=ht(t,e);return Q(r,ut(r,e)).html}function ut(t,e){const{colors:r,highlight:s,scope:i,blocks:n,...l}=e,a=new Map;for(const[e,s]of function(t){return t?Array.isArray(t)?t:Object.entries(t).map(([t,e])=>[/^\d+$/.test(t)?Number(t):t,e]):[]}(r))if(dt(s))for(const r of it(t,e))a.set(r,`color:${s}`);const o=new Set(void 0===s?[]:it(t,s));if(!a.size&&!o.size)return l;const h=l.prefix||"mv";return{...l,style:t=>[a.get(t),l.style&&l.style(t)].filter(Boolean).join(";"),attributes:t=>{const e={...l.attributes?l.attributes(t):{}};return o.has(t)&&(e.class=[e.class,`${h}-hl`].filter(Boolean).join(" ")),e}}}function dt(t){return"string"==typeof t&&/^[#\w\s.,%()/+-]+$/.test(t)&&!/url\s*\(|expression/i.test(t)}export{R as D,L as P,ht as a,ut as b,lt as c,st as d,rt as e,Q as l,ot as n,at as p,it as s,ct as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
import{g as e}from"./lite-
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
import{g as e}from"./lite-6yr4ed_k.js";function t(t,n,a){const l=(e,t)=>t===n.length?a:{...e,args:e.args.map((e,a)=>a===n[t]?l(e,t+1):e)};return e(l(t,0))}function n(e,t,{parse:n,commit:a,cancel:l,label:r="Edit",prefix:i="mv"}){const o=e.ownerDocument;if(!o||!o.body)return null;const s=o.defaultView,u=e.getBoundingClientRect(),c=o.createElement("input");c.type="text",c.className=`${i}-edit`,c.value=t,c.spellcheck=!1,c.autocomplete="off",c.setAttribute("aria-label",r);const p=()=>{c.style.width=`${Math.max(4,c.value.length+2)}ch`},d=s.getComputedStyle(e);Object.assign(c.style,{position:"absolute",left:`${u.left+s.scrollX}px`,top:`${u.top+s.scrollY+u.height/2}px`,minWidth:`${Math.max(u.width,32)}px`,fontSize:d.fontSize}),p(),o.body.appendChild(c),s.getSelection?.()?.removeAllRanges(),c.focus(),c.select();let m=!1;const f=()=>{m=!0,c.remove()};c.cancelEdit=()=>{m||(f(),l&&l())};const v=e=>{if(m)return!0;if(!e||c.value===t)return f(),l&&l(),!0;let r;try{r=n(c.value)}catch(e){return c.setAttribute("aria-invalid","true"),c.title=e.message,!1}return f(),a(r,c.value),!0};return c.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),v(!0)),"Escape"===e.key&&(e.preventDefault(),v(!1))}),c.addEventListener("input",()=>{p(),c.removeAttribute("aria-invalid"),c.removeAttribute("title")}),c.addEventListener("blur",()=>{v(!0)||v(!1)}),c}export{n as o,t as r};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
import{e}from"./draw-
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate (and mathzetta/text, for cas.external.js) with an import map */
|
|
2
|
+
import{e}from"./draw-Bw547gEd.js";function t(t,n,a){const r=(e,t)=>t===n.length?a:{...e,args:e.args.map((e,a)=>a===n[t]?r(e,t+1):e)};return e(r(t,0))}function n(e,t,{parse:n,commit:a,cancel:r,label:l="Edit",prefix:i="mv"}){const o=e.ownerDocument;if(!o||!o.body)return null;const s=o.defaultView,u=e.getBoundingClientRect(),c=o.createElement("input");c.type="text",c.className=`${i}-edit`,c.value=t,c.spellcheck=!1,c.autocomplete="off",c.setAttribute("aria-label",l);const p=()=>{c.style.width=`${Math.max(4,c.value.length+2)}ch`},d=s.getComputedStyle(e);Object.assign(c.style,{position:"absolute",left:`${u.left+s.scrollX}px`,top:`${u.top+s.scrollY+u.height/2}px`,minWidth:`${Math.max(u.width,32)}px`,fontSize:d.fontSize}),p(),o.body.appendChild(c),s.getSelection?.()?.removeAllRanges(),c.focus(),c.select();let m=!1;const f=()=>{m=!0,c.remove()};c.cancelEdit=()=>{m||(f(),r&&r())};const v=e=>{if(m)return!0;if(!e||c.value===t)return f(),r&&r(),!0;let l;try{l=n(c.value)}catch(e){return c.setAttribute("aria-invalid","true"),c.title=e.message,!1}return f(),a(l,c.value),!0};return c.addEventListener("keydown",e=>{e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),v(!0)),"Escape"===e.key&&(e.preventDefault(),v(!1))}),c.addEventListener("input",()=>{p(),c.removeAttribute("aria-invalid"),c.removeAttribute("title")}),c.addEventListener("blur",()=>{v(!0)||v(!1)}),c}export{n as o,t as r};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.
|
|
2
|
-
import{calculateBlock as t}from"mathzetta/calculate";import{t as a,a as o}from"./draw-
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; MathZetta not included: map mathzetta, mathzetta/speech and mathzetta/calculate (and mathzetta/text, for cas.external.js) with an import map */
|
|
2
|
+
import{calculateBlock as t}from"mathzetta/calculate";import{t as a,a as o}from"./draw-Bw547gEd.js";function r(a,r={}){return o(a,{...r,blocks:r.blocks??t})}function s(o,r={}){return a(o,{...r,blocks:r.blocks??t})}export{s as a,r as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* Inline Math 0.4.0 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
import{c as o}from"./calculate-DHvovDQK.js";import{e as s,f as t}from"./lite-6yr4ed_k.js";function c(s,c={}){return t(s,{...c,blocks:c.blocks??o})}function r(t,c={}){return s(t,{...c,blocks:c.blocks??o})}export{r as a,c as t};
|