@mathzetta/inlinemath 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/dist/cas.external.js +2 -2
- package/dist/cas.js +2 -2
- package/dist/chunks/calculate-HWNd7HTQ.js +2 -0
- package/dist/chunks/{draw-Bw547gEd.js → draw-SJQZoo2a.js} +2 -2
- package/dist/chunks/{edit-BC9D1cIE.js → edit-BPcpKq9t.js} +2 -2
- package/dist/chunks/{edit-CCe3uoyk.js → edit-lks88rjH.js} +2 -2
- package/dist/chunks/{html-6HJlblNm.js → html-CzXOU7ql.js} +2 -2
- package/dist/chunks/html-hyetRykq.js +2 -0
- package/dist/chunks/lite-OfhVrBim.js +2 -0
- package/dist/inlinemath-cas.external.global.min.js +2 -2
- package/dist/inlinemath-cas.global.min.js +2 -2
- package/dist/inlinemath-lite-calc.global.min.js +2 -2
- package/dist/inlinemath-lite.external.global.min.js +2 -2
- package/dist/inlinemath-lite.global.min.js +2 -2
- package/dist/inlinemath.css +9 -0
- 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 +9 -0
- package/package.json +1 -1
- package/src/layout.js +7 -0
- package/dist/chunks/calculate-DHvovDQK.js +0 -2
- package/dist/chunks/html-DzjcaM8w.js +0 -2
- package/dist/chunks/lite-6yr4ed_k.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/* Inline Math 0.4.1 — 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,q as i,u as a,v as s,w as u,h as c,x as l,y as f,z as h,A as m}from"./lite-OfhVrBim.js";function g(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 p=t=>Array.isArray(t)&&t.length>0&&!t.some(Array.isArray);function d(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 g(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 b=d({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(P+=t/16,P>E)throw new Error("Too much to work out")},fail:t=>{throw new Error(t)}}),w=t=>g(t)&&(t.length>1||t[0].length>1),M=t=>p(t)&&!w(t),y=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},v=(t,n)=>w(t)&&w(n)?b.times(t,n):w(t)&&M(n)?b.timesVector(t,n):M(t)&&w(n)?b.vectorTimes(t,n):y((t,n)=>t*n)(t,n),x=(t,n)=>e=>{const r=e.length>1&&e.every(M)?e:e[0];if(!g(r))throw new Error(`${n}() needs a matrix`);return t(r)},N=(t,n)=>([e,r])=>{if(!p(e)||!p(r))throw new Error(`${n}() needs two lists`);return t(e,r)},$={det:x(b.det,"det"),inv:x(b.inverse,"inv"),inverse:x(b.inverse,"inverse"),transpose:x(b.transpose,"transpose"),trace:x(b.trace,"trace"),tr:x(b.trace,"tr"),rank:x(b.rank,"rank"),rref:x(b.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 b.identity(t)},dot:N(b.dot,"dot"),cross:N(b.cross,"cross"),linsolve:([t,n])=>{if(!g(t)||!Array.isArray(n))throw new Error("linsolve() needs a matrix and a list");return b.solve(t,n)}},A=(t,n)=>t.args.map(t=>"op"===t.type&&"[]"===t.op?t.args.map(t=>T(t,n)):[T(t,n)]),I={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},F=(t,n)=>n?F(n,t%n):Math.abs(t),B=(t,n)=>(t%n+n)%n,k=(t,n)=>Array.isArray(t)&&Array.isArray(n)?t.length===n.length&&t.every((t,e)=>k(t,n[e])):t==n,O={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=>$.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},S={"+":(t,n)=>Array.isArray(t)||Array.isArray(n)?y((t,n)=>t+n)(t,n):t+n,"-":(t,n)=>Array.isArray(t)||Array.isArray(n)?y((t,n)=>t-n)(t,n):t-n,"*":v,"/":(t,n)=>w(n)?v(t,b.inverse(n)):Array.isArray(t)||Array.isArray(n)?y((t,n)=>t/n)(t,n):t/n,"^":(t,n)=>{if(!w(t))return Array.isArray(t)?y((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 b.power(t,BigInt(n))},mod:B,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)},"=":k,"===":(t,n)=>t===n,"≠":(t,n)=>!k(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)},z={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(F,0),"()":t=>t,"[]":t=>t,"{}":t=>t};const E=5e6;let P=0,j=0;function T(t,l){if(++P>E)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(l,t.value))return l[t.value];if(Object.prototype.hasOwnProperty.call(I,t.value))return I[t.value];if(n(t.value))return Number(n(t.value));throw new Error(`No value for '${t.value}'`)}const f=r(t);if(f)return T(f,l);const{op:h,args:m}=t;if("?:"===h)return T(m[0],l)?T(m[1],l):T(m[2],l);if("setbuilder"===h)throw new Error("A set described by a condition has no list of values (test membership in it: y ∈ {x | P})");if(("∈"===h||"∉"===h)&&o(t))return T(o(t),l);if("∈"===h||"∉"===h){const n=i(t);if(n){const t=T(n.within,l);if(!Array.isArray(t))return a(t).includes(a(T(n.text,l)))===("∈"===h)}else if("symbol"===m[1].type&&l&&Object.prototype.hasOwnProperty.call(l,m[1].value)){const t=T(m[1],l);if("string"==typeof t)return a(t).includes(a(T(m[0],l)))===("∈"===h)}return function(t,n){const[e,r]=t.args,o=T(e,n);let i;if("symbol"===r.type&&W[r.value])return i=W[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=>T(t,n)),a="["===r.op[0]?o>=t:o>t,s="]"===r.op[1]?o<=e:o<e;i=a&&s}else{const t=T(r,n);i=Array.isArray(t)&&t.includes(o)}return"∈"===t.op?i:!i}(t,l)}if(s(h)){const[n,e]=u(t).map(t=>T(t,l));return a(n).startsWith(a(e))}if("random"===h)return Math.random();if("evaluated"===h){const[t,n,e,r]=m,o=e=>T(t,{...l,[n.value]:T(e,l)});return o(r)-o(e)}if(("\\sumidx"===h||"\\prodidx"===h)&&3===m.length){const t="op"===m[1].type&&"="===m[1].op&&"symbol"===m[1].args[0].type,[n,e,r]=[m[0],t?m[1].args[1]:m[1],m[2]],o=t?m[1].args[0].value:c(n);if(!o)throw new Error(`Can't evaluate '${h}' without an index`);const i=T(e,l),a=T(r,l);if(!Number.isFinite(i)||!Number.isFinite(a)||a-i>1e6||Math.abs(i)>Number.MAX_SAFE_INTEGER||Math.abs(a)>Number.MAX_SAFE_INTEGER)throw new Error(`Can't evaluate '${h}' over that range`);let s="\\sumidx"===h?0:1;for(let t=i;t<=a;t++){const e=T(n,{...l,[o]:t});s="\\sumidx"===h?s+e:s*e}return s}if("pmod"===h){const[t,n]=m,e=T(n,l);if("op"===t.type&&["≡","="].includes(t.op)){const[n,r]=t.args.map(t=>T(t,l));return(n-r)%e===0}return B(T(t,l),e)}if("pmatrix"===h||"bmatrix"===h)return A(t,l);if("vmatrix"===h)return b.det(A(t,l));if("^"===h&&"symbol"===m[1].type&&"T"===m[1].value&&!Object.prototype.hasOwnProperty.call(l,"T")){const t=T(m[0],l);if(w(t))return b.transpose(t)}const g=m.map(t=>T(t,l));if(h.startsWith("\\:")&&Object.prototype.hasOwnProperty.call($,h.slice(2)))return $[h.slice(2)](g);if(O[h]&&1===g.length)return O[h](g[0]);if(S[h]&&2===g.length)return S[h](g[0],g[1]);if(z[h])return z[h](g);throw new Error(`Can't evaluate '${h}'`)}const W={"ℝ":Number.isFinite,"ℤ":Number.isInteger,"ℕ":t=>Number.isInteger(t)&&t>0,"ℚ":Number.isFinite,"ℂ":t=>"number"==typeof t&&!Number.isNaN(t)};for(const t of[I,O,S,z,W,$])Object.setPrototypeOf(t,null);class _ extends Error{}class Z extends Error{}class q extends Z{}const D={bits:2e5,factorial:2e4,terms:1e5,rootIndex:12,steps:5e6,places:1e4};let C=0;function G(t){if(C+=t,C>D.steps)throw new Z("too much to work out")}const L=(t,n)=>G(Number(t)*(n/64)/128);let R=0;const V=t=>t<0n?-t:t,X=0xFFFFFFFFFFFFn,J=t=>0n===t?0:V(t).toString(2).length;function H(t,n){for(t=V(t),n=V(n);n;)[t,n]=[n,t%n];return t}function K(t,n=1n){if(0n===n)throw new _("division by zero");if(n<0n&&(t=-t,n=-n),n>X&&(t>X||-t>X)){const e=Math.min(t.toString(16).length-(t<0n?1:0),n.toString(16).length)/16;if(C+=1+e*e/2,C>D.steps)throw new Z("too much to work out")}const e=H(t,n)||1n;return{n:t/e,d:n/e}}const Q=K(0n),U=K(1n),Y=(t,n)=>K(t.n*n.d+n.n*t.d,t.d*n.d),tt=(t,n)=>K(t.n*n.n,t.d*n.d),nt=(t,n)=>K(t.n*n.d,t.d*n.n),et=t=>({n:-t.n,d:t.d}),rt=(t,n)=>{const e=t.n*n.d-n.n*t.d;return e<0n?-1:e>0n?1:0},ot=t=>{const n=t.n/t.d;return t.n<0n&&n*t.d!==t.n?n-1n:n};function it(t){if(t.n<0n)return-it(et(t));const n=J(t.n),e=J(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 at(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 Z(`'${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=Y(K(BigInt(a||"0")),K(o-r,(10n**BigInt(t)-1n)*10n**BigInt(e.length)))}else u=K(BigInt(a+s||"0"),10n**BigInt(s.length));if(Math.abs(o)>D.bits/3)throw new Z("too large to calculate");return o&&(u=o>0?tt(u,K(10n**BigInt(o))):nt(u,K(10n**BigInt(-o)))),e<0n?et(u):u}function st(t,n=0,e=0,r=null){return 0n===t.n?{kind:"x",c:Q,pi:0,e:0,root:null}:{kind:"x",c:t,pi:n,e:e,root:r}}const ut=(t,n=1n)=>st(K(BigInt(t),BigInt(n))),ct=st(U,1),lt=st(U,0,1),ft=t=>null!==t&&"object"==typeof t&&"x"===t.kind,ht=t=>ft(t)&&!t.pi&&!t.e&&!t.root,mt=t=>ft(t)?0n===t.c.n:0===t,gt=t=>ht(t)&&1n===t.c.d?t.c.n:null,pt=(t,n)=>Object.assign(t,{group:n}),dt=t=>({kind:"s",text:t});function bt(t,n){return t&&n?t.n===n.n&&t.r===n.r:t===n}const wt=(t,n)=>0===rt(t.c,n.c)&&t.pi===n.pi&&t.e===n.e&&bt(t.root,n.root);function Mt(t){const n=Math.max(0,J(t)-60);return n+Math.log2(Number(t>>BigInt(n)))}function yt(t){if("number"==typeof t)return t;if(Vt(t)&&Yt(t),ft(t)){let n=it(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**(Mt(t)/n)}(t.root.r,t.root.n);if(!(0n===t.c.n||0!==n&&Number.isFinite(n)&&Number.isFinite(e))){const n=Mt(t.c.n<0n?-t.c.n:t.c.n)-Mt(t.c.d)+Mt(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 Z("not a number")}function vt(t,...n){if(Number.isNaN(t))throw new _("undefined");if(!Number.isFinite(t)&&n.every(Number.isFinite))throw new Z("too large to calculate");return t}const xt=t=>"boolean"==typeof t?t:ft(t)?0n!==t.c.n:"number"==typeof t?0!==t:Boolean(t);function Nt(t){if("bigint"==typeof t)return st(K(t));if("number"==typeof t)return Number.isFinite(t)?st(Number.isInteger(t)&&Math.abs(t)<=Number.MAX_SAFE_INTEGER?K(BigInt(t)):at(String(t))):t;if("boolean"==typeof t)return t;if("string"==typeof t)return/^-?(\d+\.?\d*|\.\d+)(\.\.)?$/.test(t.trim())?st(at(t)):Kn(l(t),{});if(Array.isArray(t))return!t.group&&g(t)?pt(t.map(t=>pt(t.map(Nt),"[]")),"[]"):pt(t.map(Nt),t.group||"()");if(ft(t)||"function"==typeof t)return t;throw new Z(`can't use ${typeof t} as a value`)}function $t(t){if(Array.isArray(t))return t.map($t);if(Xt(t)){const{re:n,im:e}=tn(t);return{re:yt(n),im:yt(e)}}return Vt(t)?he(t,{decimal:!1,places:null,digits:12,maxDigits:50}):t&&"s"===t.kind?t.text:"boolean"==typeof t?t:yt(t)}function At(t,n){if(t<2n)return t;const e=BigInt(n);let r=1n<<BigInt(Math.ceil(J(t)/n));for(;;){const n=((e-1n)*r+t/r**(e-1n))/e;if(n>=r)return r;r=n}}function It(t,n,e,r=0,o=0){if(0n===e)return st(Q);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++}C+=a/4;const s=At(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=At(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?st(tt(t,K(i*a.r)),r,o):st(tt(t,K(i)),r,o,a)}function Ft(t,n){const e=tt(t.c,n.c);if(J(e.n)+J(e.d)>D.bits)return null;const r=t.pi+n.pi,o=t.e+n.e;if(!t.root||!n.root)return st(e,r,o,t.root||n.root);const i=zn(t.root.n,n.root.n);if(i>D.rootIndex)return null;const a=t.root.r**BigInt(i/t.root.n)*n.root.r**BigInt(i/n.root.n);return J(a)>4e3?null:It(e,i,a,r,o)}function Bt(t){if(0n===t.c.n)throw new _("division by zero");const n=st(nt(U,t.c),-t.pi,-t.e);if(!t.root)return n;const{n:e,r:r}=t.root;return J(r)*(e-1)>4e3?null:Ft(n,It(K(1n,r),e,r**BigInt(e-1)))}function kt(t,n){if(0n===n){if(0n===t.c.n)throw new _("0^0 is undefined");return st(U)}if(n<0n){const e=Bt(t);return e&&kt(e,-n)}if((J(t.c.n)+J(t.c.d)+(t.root?J(t.root.r):0))*Number(n)>D.bits||n>100000n)return null;const e=K(t.c.n**n,t.c.d**n),r=Number(n);if(!t.root)return st(e,t.pi*r,t.e*r);const{n:o,r:i}=t.root,a=i**(n/BigInt(o));return It(tt(e,K(a)),o,i**(n%BigInt(o))||1n,t.pi*r,t.e*r)}function Ot(t,n,e){if(!ht(t)||e>1000n)return null;const r=kt(t,n);if(!r)return null;let{n:o,d:i}=r.c,a=!1;if(o<0n){if(e%2n==0n)throw new _("not a real number");a=!0,o=-o}const s=function(t,n){const e=t.n*t.d**BigInt(n-1);return J(e)>4e3?null:It(K(1n,t.d),n,e)}({n:o,d:i},Number(e));return s?a?st(et(s.c),s.pi,s.e,s.root):s:null}function St(t){return n=>Array.isArray(n)?pt(n.map(n=>St(t)(n)),n.group):t(n)}function zt(t){const n=(e,r)=>{const o=Array.isArray(e),i=Array.isArray(r);if(o&&i){if(e.length!==r.length)throw new _("lists of different lengths");return pt(e.map((t,e)=>n(t,r[e])),e.group)}return o?pt(e.map(t=>n(t,r)),e.group):i?pt(r.map(t=>n(e,t)),r.group):t(e,r)};return n}const Et=(t,n)=>ft(t)&&ft(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||!bt(t.root,n.root))return null;const e=Y(t.c,n.c);return J(e.n)+J(e.d)>D.bits?null:st(e,t.pi,t.e,t.root)}(t,n)||vt(yt(t)+yt(n),yt(t),yt(n)),Pt=t=>ft(t)?st(et(t.c),t.pi,t.e,t.root):-yt(t),jt=(t,n)=>ft(t)&&ft(n)&&Ft(t,n)||vt(yt(t)*yt(n),yt(t),yt(n)),Tt=zt((t,n)=>Vt(t)||Vt(n)?ln(t,n):Et(t,n)),Wt=St(t=>Vt(t)?fn(t):Pt(t)),_t=(t,n)=>Tt(t,Wt(n)),Zt=zt((t,n)=>Vt(t)||Vt(n)?mn(t,n):jt(t,n)),qt=zt((t,n)=>Vt(t)||Vt(n)?function(t,n){if(!Vt(n)){if(mt(n))throw new _("division by zero");return Kt(Qt(t).map(t=>({vars:t.vars,re:Dt(t.re,n),im:Dt(t.im,n)})))}if(Xt(n))return mn(t,nn(rn(tn(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:hn(t.vars,[[r,-a]]),...en(t,rn(i))};u.push(e);const c=ln(Kt(s),fn(mn(Kt([e]),Kt(n))));s=mt(c)?[]:Qt(c)}return s.length?null:Kt(u)}(Qt(t),[...n.terms.values()]);if(null===e)throw new Z(`no value for '${Ut(n)}'`);return e}(t,n):Dt(t,n));function Dt(t,n){if(mt(n))throw new _("division by zero");if(ft(t)&&ft(n)){const e=Bt(n),r=e&&Ft(t,e);if(r)return r}return vt(yt(t)/yt(n),yt(t),yt(n))}const Ct=zt((t,n)=>{if(Vt(t)||Vt(n))return function(t,n){if(Vt(n)){Xt(n)||Yt(n),Vt(t)&&!Xt(t)&&Yt(t);const e=tn(n);return ft(t)&&wt(t,lt)?sn(e):sn(en(e,un(tn(t))))}const e=gt(n);if(null!==e)return e>=0n?gn(t,e):(Xt(t)||Yt(t),gn(nn(rn(tn(t))),-e));Xt(t)||Yt(t);return cn(tn(t),n)}(t,n);try{return Gt(t,n)}catch(e){if(Lt&&e instanceof _&&"not a real number"===e.message)return cn({re:t,im:ut(0)},n);throw e}});function Gt(t,n){if(ft(t)&&ht(n)){const{n:e,d:r}=n.c,o=1n===r?kt(t,e):Ot(t,e,r);if(o)return o}const e=yt(t),r=yt(n);if(0===e&&0===r)throw new _("0^0 is undefined");if(0===e&&r<0)throw new _("division by zero");if(e<0&&!Number.isInteger(r))throw new _("not a real number");const o=e**r;if(0===o&&0!==e)throw new q("too small to calculate");return vt(o,e,r)}let Lt=!1;const Rt=5e3,Vt=t=>null!==t&&"object"==typeof t&&"p"===t.kind,Xt=t=>Vt(t)&&1===t.terms.size&&t.terms.has(""),Jt=()=>Kt([{vars:[],re:ut(0),im:ut(1)}]),Ht=t=>t.map(([t,n])=>1===n?t:`${t}^${n}`).join("*");function Kt(t){const n=new Map;for(const e of t){const t=Ht(e.vars),r=n.get(t);n.set(t,r?{vars:e.vars,re:Et(r.re,e.re),im:Et(r.im,e.im)}:e)}for(const[t,e]of n)mt(e.re)&&mt(e.im)&&n.delete(t);if(n.size>Rt)throw new Z("too many terms to work out");return n.size?1===n.size&&n.has("")&&mt(n.get("").im)?n.get("").re:{kind:"p",terms:n}:ut(0)}function Qt(t){if(Vt(t))return[...t.terms.values()];if("boolean"==typeof t)return[{vars:[],re:ut(t?1:0),im:ut(0)}];if(!ft(t)&&"number"!=typeof t)throw new Z("not a number");return[{vars:[],re:t,im:ut(0)}]}const Ut=t=>[...t.terms.values()].find(t=>t.vars.length)?.vars[0][0];function Yt(t){if(Xt(t))throw new Z("a complex number has no real value here");throw new Z(`no value for '${Ut(t)}'`)}const tn=t=>Xt(t)?t.terms.get(""):{re:t,im:ut(0)},nn=({re:t,im:n})=>Kt([{vars:[],re:t,im:n}]),en=(t,n)=>({re:Et(jt(t.re,n.re),Pt(jt(t.im,n.im))),im:Et(jt(t.re,n.im),jt(t.im,n.re))});function rn(t){const n=Et(jt(t.re,t.re),jt(t.im,t.im));if(mt(n))throw new _("division by zero");return{re:Dt(t.re,n),im:Pt(Dt(t.im,n))}}const on=t=>mt(t.im)?pn(t.re,ut(0))<0?Pt(t.re):t.re:Gt(Et(jt(t.re,t.re),jt(t.im,t.im)),ut(1,2));function an(t){return mt(t.im)?pn(t.re,ut(0))<0?ct:ut(0):mt(t.re)?pn(t.im,ut(0))>0?st(K(1n,2n),1):st(K(-1n,2n),1):Math.atan2(yt(t.im),yt(t.re))}function sn(t){const n=mt(t.re)?ut(1):Gt(lt,t.re);return nn({re:jt(n,vn("cos",t.im)),im:jt(n,vn("sin",t.im))})}function un(t){if(mt(t.re)&&mt(t.im))throw new _("ln 0 is undefined");return{re:Nn(on(t)),im:an(t)}}function cn(t,n){if(mt(t.re)&&mt(t.im))return Gt(ut(0),n);const e=Gt(on(t),n),r=jt(n,an(t));return nn({re:jt(e,vn("cos",r)),im:jt(e,vn("sin",r))})}function ln(t,n){return Kt([...Qt(t),...Qt(n)])}function fn(t){return Kt(Qt(t).map(t=>({vars:t.vars,re:Pt(t.re),im:Pt(t.im)})))}function hn(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 mn(t,n){const e=Qt(t),r=Qt(n);G(e.length*r.length);const o=[];for(const t of e)for(const n of r)o.push({vars:hn(t.vars,n.vars),...en(t,n)});return Kt(o)}function gn(t,n){if(!Xt(t)&&n>1000n)throw new Z("too large to calculate");if(Vt(t)&&!Xt(t)&&function(t,n){const e=t.terms.size;let r=1;for(let t=1;t<=Math.min(n,e-1)&&r<=Rt;t++)r=r*(n+t)/t;const o=new Map;for(const n of t.terms.values())for(const[t]of n.vars)o.set(t,[0,0]);for(const n of t.terms.values())for(const[t,e]of o){const r=n.vars.find(([n])=>n===t)?.[1]??0;e[0]=Math.min(e[0],r),e[1]=Math.max(e[1],r)}let i=1;for(const[t,e]of o.values())if((i*=n*(e-t)+1)>Rt)break;return Math.min(r,i)}(t,Number(n))>Rt)throw new Z("too many terms to work out");if(Xt(t)&&n>1n){const{re:e,im:r}=tn(t),o=t=>ft(t)?J(t.c.n)+J(t.c.d)+(t.root?J(t.root.r):0):64;if(Number(n)*Math.max(o(e),o(r),1)>2e4)return cn(tn(t),ut(n))}let e=ut(1),r=t;for(let t=n;t>0n;t>>=1n)1n&t&&(e=mn(e,r)),t>1n&&(r=mn(r,r));return e}function pn(t,n){if(Xt(t)||Xt(n))throw new Z("complex numbers have no order");if(ht(t)&&ht(n))return rt(t.c,n.c);if(ft(t)&&ft(n)&&wt(t,n))return 0;const e=yt(t),r=yt(n);if(e===r)return 0;const o=ft(t)&&ft(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 dn(t,n,e=!1){return Array.isArray(t)||Array.isArray(n)?Array.isArray(t)&&Array.isArray(n)&&t.length===n.length&&t.every((t,r)=>dn(t,n[r],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:"boolean"==typeof t||"boolean"==typeof n?!!e&&dn("boolean"==typeof t?ut(t?1:0):t,"boolean"==typeof n?ut(n?1:0):n):Vt(t)||Vt(n)?function(t,n){const e=_t(t,n);return Vt(e)?!Xt(e)&&Yt(e):mt(e)}(t,n):0===pn(t,n)}const bn={0:()=>ut(0),2:()=>ut(1,2),3:()=>It(K(1n,2n),2,2n),4:()=>It(K(1n,2n),2,3n),6:()=>ut(1)};function wn(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=bn[n];return r?e<0?Wt(r()):r():null}const Mn=t=>wn(t+6),yn=(t,n)=>Math.abs(t)<1e-15&&Math.abs(n)>1e-6?0:t;function vn(t,n){const e=function(t){if(mt(t))return 0;if(!ft(t)||1!==t.pi||t.e||t.root)return null;const n=tt(t.c,K(12n));return 1n!==n.d?null:Number((n.n%24n+24n)%24n)}(n);if(null!==e){const n=wn(e),r=Mn(e);if(n&&r)switch(t){case"sin":return n;case"cos":return r;case"tan":return qt(n,r);case"cot":return qt(r,n);case"sec":return qt(ut(1),r);case"csc":return qt(ut(1),n)}}const r=yt(n),o=yn(Math.sin(r),r),i=yn(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 _("undefined");return vt(a)}function xn(t,n){const e={arcsin:[-6,6],arccos:[0,12],arctan:[-5,5]}[t],r=n=>"arcsin"===t?wn(n):"arccos"===t?Mn(n):Mn(n)&&!mt(Mn(n))?qt(wn(n),Mn(n)):null;if(ft(n))for(let t=e[0];t<=e[1];t++){const e=r(t);if(e&&ft(e)&&wt(e,n))return st(K(BigInt(t),12n),1)}const o=yt(n);if("arctan"!==t&&Math.abs(o)>1)throw new _("not a real number");return{arcsin:Math.asin,arccos:Math.acos,arctan:Math.atan}[t](o)}function Nn(t){if(Vt(t))return Xt(t)?nn(un(tn(t))):Yt(t);if(Lt&&pn(t,ut(0))<0)return nn({re:Nn(Pt(t)),im:ct});if(ft(t)){if(0n===t.c.n)throw new _("ln 0 is undefined");if(t.c.n<0n)throw new _("not a real number");if(1n===t.c.n&&1n===t.c.d&&!t.pi&&!t.root)return ut(t.e)}const n=yt(t);if(n<=0)throw new _(0===n?"ln 0 is undefined":"not a real number");return Math.log(n)}function $n(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*$n(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 An(t,n){Vt(t)&&Yt(t);const e=gt(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null===e)throw new _(`${n} needs whole numbers`);return e}const In=(t,n)=>Number(n)*J(t)>D.bits;const Fn=St(t=>ht(t)?st(K(ot(t.c))):Nt(Math.floor(yt(t)))),Bn=St(t=>ht(t)?st(K(-ot(et(t.c)))):Nt(Math.ceil(yt(t))));function kn(t,n){const e=Number(An(n,"round"));if(Math.abs(e)>D.places)throw new Z("too many decimal places");if(ht(t)){const n=K(10n**BigInt(Math.abs(e))),r=e>=0?tt(t.c,n):nt(t.c,n),o=ot(Y(tt(K(2n),K(V(r.n),r.d)),U))/2n,i=K(r.n<0n?-o:o);return st(e>=0?nt(i,n):tt(i,n))}if(e>15)return yt(t);const r=10**e;return 0===r?0:Math.sign(yt(t))*Math.round(Math.abs(yt(t))*r)/r}const On=(t,n)=>t.toFixed(Math.min(n,100))+(n>100?"0".repeat(n-100):"");function Sn(t,n){if(mt(n))throw new _("division by zero");if(ht(t)&&ht(n))return st(Y(t.c,et(tt(n.c,K(ot(nt(t.c,n.c)))))));const e=yt(t),r=yt(n);return vt((e%r+r)%r)}const zn=(t,n)=>t/En(t,n)*n,En=(t,n)=>n?En(n,t%n):t,Pn={pi:()=>ct,"π":()=>ct,tau:()=>st(K(2n),1),"τ":()=>st(K(2n),1),e:()=>lt,"∞":()=>1/0,"-∞":()=>-1/0,true:()=>!0,false:()=>!1,"°":()=>st(K(1n,180n),1)},jn={abs:t=>Xt(t)?on(tn(t)):ft(t)?st(K(V(t.c.n),t.c.d),t.pi,t.e,t.root):Math.abs(yt(t)),floor:Fn,ceil:Bn,sqrt:t=>Ct(t,ut(1,2)),ln:St(Nn),loglog:St(t=>Nn(Nn(t))),logloglog:St(t=>Nn(Nn(Nn(t)))),expm1:St(t=>mt(t)?ut(0):Math.expm1(yt(t))),sinh:St(t=>mt(t)?ut(0):Math.sinh(yt(t))),cosh:St(t=>mt(t)?ut(1):Math.cosh(yt(t))),tanh:St(t=>mt(t)?ut(0):Math.tanh(yt(t))),arcsinh:St(t=>mt(t)?ut(0):Math.asinh(yt(t))),arccosh:St(t=>{const n=yt(t);if(n<1)throw new _("not a real number");return 1===n?ut(0):Math.acosh(n)}),arctanh:St(t=>{const n=yt(t);if(Math.abs(n)>=1)throw new _("undefined");return mt(t)?ut(0):Math.atanh(n)}),"!":St(function(t){const n=gt(t)??("number"==typeof t&&Number.isInteger(t)?BigInt(t):null);if(null!==n){if(n<0n)throw new _("factorial of a negative number");if(n>BigInt(D.factorial))throw new Z("too large to calculate");L(n,Number(n)*Math.log2(Number(n)+1));let t=1n;for(let e=2n;e<=n;e++)t*=e;return st(K(t))}const e=yt(t);if(e<0&&Number.isInteger(e))throw new _("factorial of a negative number");return vt($n(e+1),e)}),neg:Wt,pm:t=>pt([t,Wt(t)],"pm"),"\\not":t=>!xt(t),det:t=>Ln.det(t)};for(const t of["sin","cos","tan","csc","sec","cot"])jn[t]=St(n=>vn(t,n));for(const t of["arcsin","arccos","arctan"])jn[t]=St(n=>xn(t,n));const Tn=t=>{if(mt(t))throw new _("not a real number");return qt(ut(1),t)};jn.arcsec=St(t=>xn("arccos",Tn(t))),jn.arccsc=St(t=>xn("arcsin",Tn(t))),jn.arccot=St(t=>_t(st(K(1n,2n),1),xn("arctan",t)));const Wn=new Set(["pmatrix","bmatrix"]),_n=t=>g(t)&&(Wn.has(t.group)||"[]"===t.group&&t.every(t=>"[]"===t.group)&&(t.length>1||t[0].length>1)),Zn=t=>p(t)&&!_n(t)&&"pm"!==t.group,qn=d({add:Tt,sub:_t,mul:Zt,div:qt,charge:G,isZero:t=>ft(t)?0n===t.c.n:Math.abs(yt(t))<1e-12,zero:()=>ut(0),one:()=>ut(1),size:t=>Math.abs(yt(t)),fail:t=>{throw new _(t)},make:(t,n)=>pt(t.map(t=>pt(t,"[]")),n&&n.group?n.group:"bmatrix")}),Dn=(t,n)=>pt(t,n&&n.group?n.group:"[]"),Cn=(t,n)=>(...e)=>{const r=e.length>1&&e.every(Zn)?pt(e.map(t=>pt(t,"[]")),"[]"):e[0];if(e.length>1&&r===e[0])throw new Z(`${t} of more than one thing`);if(!_n(r))throw new Z(`${t} of something that isn't a matrix`);return n(r)};function Gn(t,n){return _n(t)&&_n(n)?qn.times(t,n):_n(t)&&Zn(n)?Dn(qn.timesVector(t,n),n):Zn(t)&&_n(n)?Dn(qn.vectorTimes(t,n),t):Zt(t,n)}const Ln={det:Cn("det",t=>Rn(t)),inv:Cn("inv",qn.inverse),inverse:Cn("inverse",qn.inverse),transpose:Cn("transpose",qn.transpose),trace:Cn("trace",qn.trace),tr:Cn("tr",qn.trace),rank:Cn("rank",t=>ut(qn.rank(t))),rref:Cn("rref",qn.rref),identity:t=>{const n=gt(t);if(null===n||n<1n||n>100n)throw new Z("identity(n) needs a whole number n");return qn.identity(Number(n))},dot:(t,n)=>{if(!Zn(t)||!Zn(n))throw new Z("dot of something that isn't a vector");return qn.dot(t,n)},cross:(t,n)=>{if(!Zn(t)||!Zn(n))throw new Z("cross of something that isn't a vector");return Dn(qn.cross(t,n),t)},linsolve:(t,n)=>{if(!_n(t)||!_n(n)&&!Zn(n))throw new Z("linsolve(A, b) needs a matrix and a vector");return _n(n)?qn.solve(t,n):Dn(qn.solve(t,n),n)}};function Rn(t){if(!t.some(t=>t.some(Vt)))return qn.det(t);if(t.length!==t[0].length)throw new _(`a ${t.length} by ${t[0].length} matrix has no determinant`);if(t.length>6)throw new Z("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=Zt(r,n(i));return o%2?_t(e,a):Tt(e,a)},ut(0));return n(t)}function Vn(t,n){const e=t.args.map(t=>pt("op"===t.type&&"[]"===t.op?t.args.map(n):[n(t)],"[]"));if(e.some(t=>t.length!==e[0].length))throw new _("rows of different lengths");return pt(e,"vmatrix"===t.op?"bmatrix":t.op)}const Xn={"+":Tt,"-":_t,"*":Gn,"/":(t,n)=>_n(n)?Gn(t,qn.inverse(n)):qt(t,n),"^":function(t,n){if(!_n(t))return Ct(t,n);const e=gt(n);if(null===e)throw new Z("a matrix to a power that is not a whole number");return qn.power(t,e)},"±":(t,n)=>pt([Tt(t,n),_t(t,n)],"pm"),mod:zt(Sn),log:zt(function(t,n){if(ft(t)&&wt(t,lt))return Nn(n);const e=yt(t),r=yt(n);if(e<=0||1===e)throw new _("not a valid base");if(r<=0)throw new _(0===r?"log 0 is undefined":"not a real number");const o=Math.log(r)/Math.log(e);if(ht(t)&&ht(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=kt(t,BigInt(r)),a=kt(n,e);if(i&&a&&wt(i,a))return st(K(BigInt(r),e))}return o}),root:zt((t,n)=>Ct(n,qt(ut(1),t))),atan2:(t,n)=>Math.atan2(yt(t),yt(n)),round:kn,fixed:function(t,n){const e=Number(An(n,"fixed"));if(e<0)throw new _("fixed needs 0 or more decimal places");const r=kn(t,n);if(ht(r)){const t=r.c.n*10n**BigInt(e)/r.c.d,n=(t<0n?-t:t).toString().padStart(e+1,"0");return dt(`${t<0n?"-":""}${n.slice(0,n.length-e)}${e?"."+n.slice(-e):""}`)}return dt(On(yt(r),e))},perm:function(t,n){const e=An(t,"permutations"),r=An(n,"permutations");if(r<0n||r>e)throw new _("undefined");if(r>BigInt(D.terms)||In(e,r))throw new Z("too large to calculate");L(r,Number(r)*J(e));let o=1n;for(let t=e-r+1n;t<=e;t++)o*=t;return st(K(o))},comb:function(t,n){const e=An(t,"combinations");let r=An(n,"combinations");if(r<0n||r>e)throw new _("undefined");if(e-r<r&&(r=e-r),r>BigInt(D.terms)||In(e,r))throw new Z("too large to calculate");L(2n*r,Number(r)*J(e));let o=1n;for(let t=1n;t<=r;t++)o=o*(e-r+t)/t;return st(K(o))},"=":(t,n)=>dn(t,n,!0),"===":(t,n)=>dn(t,n),"≠":(t,n)=>!dn(t,n,!0),"≠=":(t,n)=>!dn(t,n),"≈":(t,n)=>Math.abs(yt(t)-yt(n))<=1e-9*Math.max(1,Math.abs(yt(t)),Math.abs(yt(n))),"<":(t,n)=>pn(t,n)<0,">":(t,n)=>pn(t,n)>0,"≤":(t,n)=>pn(t,n)<=0,"≥":(t,n)=>pn(t,n)>=0,"&":(t,n)=>xt(t)&&xt(n),"|":(t,n)=>xt(t)||xt(n),"\\xor":(t,n)=>xt(t)!==xt(n),"\\nor":(t,n)=>!(xt(t)||xt(n)),"\\nand":(t,n)=>!(xt(t)&&xt(n)),"\\implies":(t,n)=>!xt(t)||xt(n),"\\iff":(t,n)=>xt(t)===xt(n)},Jn={sum:t=>t.reduce((t,n)=>Tt(t,n),ut(0)),prod:t=>t.reduce((t,n)=>Zt(t,n),ut(1)),max:t=>t.reduce((t,n)=>pn(n,t)>0?n:t),min:t=>t.reduce((t,n)=>pn(n,t)<0?n:t),mean:t=>qt(Jn.sum(t),ut(t.length)),gcd:t=>st(K(t.map(t=>An(t,"gcd")).reduce(H)))},Hn=["∈","∉","∪","∩","pmod","random","(]","[)"];function Kn(t,n){if(++C>D.steps)throw new Z("too much to work out");switch(t.type){case"number":return st(at(t.value));case"string":return dt(t.value.slice(1,-1));case"symbol":return Qn(t.value,n)}const e=r(t);if(e)return Kn(e,n);const{op:i,args:a}=t,u=t=>Kn(t,n);if("?:"===i)return xt(u(a[0]))?u(a[1]):u(a[2]);if("_"===i){if(a.every(t=>"op"!==t.type))return Qn(`${a[0].value}_${a[1].value}`,n);throw new Z("subscript")}if("der"===i)return function(t,n){const[e,r]=t.args;if("op"===r.type&&"="===r.op){const t=ee(r.args[0]);if(!t)throw new Z("a derivative at a point names its variable: der(f, x = a)");return re(e,t,yt(Kn(r.args[1],n)),n)}const o=ee(r);if(!o||!n[Yn]?.has(o))throw new Z(`a derivative needs a point: der(f, ${o||"x"} = a)`);return re(e,o,yt(n[o]),n)}(t,n);if("evaluated"===i){const[t,e,r,o]=a;return _t(Kn(t,te(n,e.value,u(o))),Kn(t,te(n,e.value,u(r))))}if("int"===i)return function(t,n){const[e,r,o,i]=t,a=t=>t&&"symbol"===t.type&&/^[a-zA-Zʹ-Ͽ]$/.test(t.value);let s,u,l;if(4===t.length)[s,u,l]=[ee(r),o,i];else{if(3!==t.length||a(r))throw new Z("an integral needs limits to be calculated");[s,u,l]=[c(e)||"x",r,o]}let f=yt(Kn(u,n)),h=yt(Kn(l,n));if(f===h)return ut(0);let m=1;f>h&&([f,h]=[h,f],m=-1);const g=ne(e,s,n),{value:p,error:d}=oe(g,f,h);return ce(m*p,d)}(a,n);if("lim"===i)return function(t,n){const[e,r,o,i]=t;let a,s,u=0;if(2===t.length&&"op"===r.type&&"→"===r.op)[a,s]=[ee(r.args[0]),r.args[1]];else if(2===t.length)[a,s]=[c(e),r];else{if(!(t.length>=3))throw new Z("a limit needs a point");[a,s]=[ee(r),o]}if(4===t.length){const t="op"===i.type?"":String(i.value).toLowerCase();u=t.startsWith("r")||"+"===t?1:-1}if(!a)throw new Z("a limit needs a variable");const l=Kn(s,n),f=yt(l),h=ne(e,a,n);let m,g;if(Number.isFinite(f))if(u){({value:m,error:g}=ae(t=>h(f+u*t*Math.max(1,Math.abs(f)))));try{const t=Kn(e,te(n,a,l));if(Math.abs(yt(t)-m)<=Math.max(g,1e-6*Math.max(1,Math.abs(m))))return t}catch(t){if(!(t instanceof _))throw t}}else{const t=ae(t=>h(f+t*Math.max(1,Math.abs(f)))),r=ae(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 _("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=Kn(e,te(n,a,l));if(Math.abs(yt(t)-m)<=1e-6*Math.max(1,Math.abs(m)))return t}catch(t){if(!(t instanceof _))throw t}}else({value:m,error:g}=ae(t=>h(Math.sign(f)/t)));return Number.isFinite(m)?ce(m,g):m}(a,n);if("\\sumidx"===i||"\\prodidx"===i)return function(t,n,e){const[r,o,i]=n;if(n.length<3)throw new Z("a sum needs its limits");let a,s=o;"op"===o.type&&"="===o.op&&"symbol"===o.args[0].type?[a,s]=[o.args[0].value,o.args[1]]:a=c(r)||"n";const u=An(Kn(s,e),"a sum"),l=Kn(i,e),f=t?Tt:Zt;if(l===1/0){if(!t)throw new Z("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 _("undefined");o+=n}if(e.push(s),r.push(o),a>=6&&r[r.length-1]===r[r.length-2]&&!ue(t,n,i))return ce(o,0)}if(ue(t,n,i))throw new _("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 _("the series diverges");if(Math.abs(a)>1e-6*Math.max(1,Math.abs(o))&&c>=.9)throw new Z("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 ce(g,Math.abs(g-p))}(ne(r,a,e),Number(u))}const h=An(l,"a sum");if(h-u+1n>BigInt(D.terms))throw new Z("too many terms to add one by one");let m=ut(t?0:1);for(let t=u;t<=h;t++)m=f(m,Kn(r,te(e,a,st(K(t)))));return m}("\\sumidx"===i,a,n);if(["()","[]","{}"].includes(i))return pt(a.map(u),i);if("pmatrix"===i||"bmatrix"===i)return Vn(t,u);if("vmatrix"===i)return Rn(Vn(t,u));if("^"===i&&"symbol"===a[1].type&&"T"===a[1].value&&!Object.prototype.hasOwnProperty.call(n,"T")){const t=u(a[0]);if(_n(t))return qn.transpose(t)}if("pmod"===i)return function([t,n],e){const r=e(n);return"op"===t.type&&["≡","="].includes(t.op)&&2===t.args.length?mt(Sn(_t(e(t.args[0]),e(t.args[1])),r)):Sn(e(t),r)}(a,u);if("setbuilder"===i)throw new Z("a set described by a condition has no list of values");if(o(t))return u(o(t));if("∈"===i||"∉"===i){const n=function(t,n){const[e,r]=t.args,o=n(e);let i;if("symbol"===r.type&&["ℤ","ℕ","ℚ","ℝ"].includes(r.value)&&ft(o))i="ℝ"===r.value||("ℚ"===r.value?ht(o):ht(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=pn(o,t),s=pn(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=>dn(o,n(t)))}return"∈"===t.op?i:!i}(t,u);if(void 0!==n)return n}if(Hn.includes(i))return Un(t,n);if(i.startsWith("\\:")){const e=i.slice(2),r=Object.prototype.hasOwnProperty.call(n,e)?n[e]:void 0;if("function"!=typeof r&&Object.prototype.hasOwnProperty.call(Ln,e))return Ln[e](...a.map(u));if("function"!=typeof r&&s(i))return Un(t,n);if("function"!=typeof r)throw new Z(`no function ${i.slice(2)}`);return Nt(r(...a.map(t=>$t(u(t)))))}if(jn[i]&&1===a.length)return jn[i](u(a[0]));if(Xn[i]&&2===a.length)return Xn[i](u(a[0]),u(a[1]));if(Jn[i])return Jn[i](a.map(u));throw new Z(`can't calculate '${i}'`)}function Qn(t,e){if(Object.prototype.hasOwnProperty.call(e,t))return e[t];if(Object.prototype.hasOwnProperty.call(Pn,t))return Pn[t]();if(n(t))return st(at(n(t)));if("i"===t)return Jt();if(/^[A-Za-z\u0370-\u03FF][A-Za-z0-9_\u0370-\u03FF′]*$/.test(t))return Kt([{vars:[[t,1]],re:ut(1),im:ut(0)}]);throw new Z(`no value for '${t}'`)}function Un(n,e){const r={};for(const[t,n]of Object.entries(e))"function"!=typeof n&&(r[t]=$t(n));try{return Nt(function(n,e={}){0===j&&(P=0),j++;try{return T(t(n),e)}finally{j--}}(n,r))}catch(t){throw new Z(t.message)}}const Yn=Symbol("bound"),te=(t,n,e)=>({...t,[n]:e,[Yn]:new Set([...t[Yn]??[],n])});function ne(t,n,e){return r=>{try{return yt(Kn(t,te(e,n,r)))}catch(t){if(t instanceof _)return NaN;if(t instanceof q)return 0;throw t}}}const ee=t=>"symbol"===t.type?t.value:null;function re(t,n,e,r){const o=ne(t,n,r);if(!Number.isFinite(o(e)))throw new _("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 _("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 _("not differentiable here");return ce(f,h)}function oe(t,n,e){if(n===-1/0&&e===1/0){const n=oe(t,-1/0,0),e=oe(t,0,1/0);return{value:n.value+e.value,error:n.error+e.error}}return e===1/0?ie(e=>t(n+e/(1-e))/((1-e)*(1-e)),0,1):n===-1/0?ie(n=>t(e-n/(1-n))/((1-n)*(1-n)),0,1):ie(t,n,e)}function ie(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 _("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 _("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 _("the integral does not converge");return{value:s,error:f}}(t,n,e)}catch(t){if(!(t instanceof _)||"the integral does not converge"!==t.message||r>=10)throw t}const o=(n+e)/2,i=ie(t,n,o,r+1),a=ie(t,o,e,r+1);return{value:i.value+a.value,error:i.error+a.error}}function ae(t){const n=se(t),e=se(n=>t(.7548776662466927*n));if(n.value===e.value)return n;if(!Number.isFinite(n.value)||!Number.isFinite(e.value))throw new _("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 _("the limit could not be found");if(Math.abs(n.value-e.value)<=o)return n;throw new _("the limit does not exist")}function se(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 _("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 _("the limit could not be found")}return i}function ue(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 ce(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 ut(0);if(Math.abs(t)<1e-10)return t;const r=[[ut(1),1e3],[ct,100],[st(U,2),100],[lt,100],...[2n,3n,5n,6n,7n].map(t=>[st(U,0,0,{n:2,r:t}),100])];for(const[n,o]of r){const r=t/yt(n),i=le(r,o);if(i&&Math.abs(Number(i.n)/Number(i.d)-r)*yt(n)<=e)return Ft(st(i),n)}return t}function le(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?K(BigInt(r),BigInt(i)):null}function fe(t,n){if("boolean"==typeof t)return String(t);if(Vt(t))return he(t,n);if(t&&"s"===t.kind)return JSON.stringify(t.text);if(Array.isArray(t)){if("pm"===t.group&&2===t.length&&dn(t[1],Wt(t[0])))return`±${ge(t[0],n)}`;if(Wn.has(t.group)&&g(t))return`${t.group}(${t.map(t=>`[${t.map(t=>fe(t,n)).join(", ")}]`).join(", ")})`;const[e,r]={"()":"()","[]":"[]","{}":"{}"}[t.group]||"{}";return e+t.map(t=>fe(t,n)).join(", ")+r}return"number"==typeof t?pe(t,n):n.decimal||null!==n.places?function(t,n){if(ht(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=V(e).toString().padStart(i+1,"0"),a=i?`${o.slice(0,-i)}.${o.slice(-i)}`:o;if(o.length<=n.maxDigits)return(r?"-":"")+de(a)}}return ht(t)&&null!==n.places?fe(kn(t,ut(n.places)),{...n,places:null,decimal:!0}):pe(yt(t),n)}(t,n):function(t,n){const{c:e}=t,r=V(e.n);if(r.toString().length>n.maxDigits||e.d.toString().length>n.maxDigits)return function(t,n){if(!ht(t))return pe(yt(t),n);if(1n!==t.c.d){const e=yt(t);if(0!==e&&Number.isFinite(e))return pe(e,n);const r=V(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=de(`${s[0]}.${s.slice(1,n.digits)}`);return`${t.c.n<0n?"-":""}${c}*10^(${u})`}const e=V(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=de(`${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 he(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=Ht(t.vars);if(!e)return me(t.re,t.im,n);if(!mt(t.im))return`(${me(t.re,t.im,n)})*${e}`;const r=t.re,o=fe(r,n);if("1"===o)return e;if("-1"===o)return`-${e}`;if(ht(r)&&1n!==r.c.d&&!n.decimal&&null===n.places){const t=V(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 me(t,n,e){if(mt(n))return fe(t,e);const r=!mt(n)&&pn(n,ut(0))<0,o=fe(r?Pt(n):n,e),i="1"===o?"i":/^[\d.]+$/.test(o)?`${o}*i`:`(${o})*i`;return mt(t)?r?`-${i}`:i:`${fe(t,e)} ${r?"-":"+"} ${i}`}const ge=(t,n)=>{const e=fe(t,n);return/^[\d.]+$|^[a-zπ]+$/i.test(e)?e:`(${e})`};function pe(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 On(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`${de(e)}*10^(${Number(r)})`}return String(Number(t.toPrecision(n.digits)))}const de=t=>t.includes(".")?t.replace(/\.?0+$/,""):t;function be(t,n={},e={}){0===R&&(C=0);const r="string"==typeof t?l(t):f(t),o={};for(const[t,e]of Object.entries(n))o[t]=Nt(e);R++;const i=Lt;let a,s=!1;h(r,t=>{"symbol"!==t.type||"i"!==t.value||Object.prototype.hasOwnProperty.call(n,"i")||(s=!0)}),Lt=e.complex??(s||R>1&&i);try{a=Kn(r,o)}finally{R--,Lt=i}const u={decimal:!1,places:null,digits:12,maxDigits:50,...e};if(void 0===u.places&&(u.places=null),null!==u.places&&!(Number.isInteger(u.places)&&u.places>=0&&u.places<=D.places))throw new Z(`places is a whole number from 0 to ${D.places}`);const c=t=>Array.isArray(t)?t.every(c):Vt(t)?[...t.terms.values()].every(t=>"number"!=typeof t.re&&"number"!=typeof t.im):"number"!=typeof t;return{value:$t(a),text:fe(a,u),exact:c(a)}}function we(t,n={}){let e=t.trim();const r={},o=/^(~|≈)(\d+)?\s*/.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}=be(e,n,r);return t.startsWith('"')||/^\d+(\.\d+)?$/.test(t)?t:`(${t})`}catch(t){if(t instanceof _)return'"undefined"';if(t instanceof Z)return`(${e})`;throw t}}m(we);for(const t of[D,bn,Pn,jn,Xn,Jn])Object.setPrototypeOf(t,null);Object.setPrototypeOf(Ln,null);export{be as a,we as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* Inline Math 0.4.
|
|
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
|
+
/* Inline Math 0.4.1 — 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");if(!i){const e=J(this.el("fence fence-line",a.html+t.html+o.html),Math.max(t.h,k),Math.max(t.d,C));return e.fenced=!0,e}const 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.4.
|
|
2
|
-
import{g as e}from"./lite-
|
|
1
|
+
/* Inline Math 0.4.1 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
import{g as e}from"./lite-OfhVrBim.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.4.
|
|
2
|
-
import{e}from"./draw-
|
|
1
|
+
/* Inline Math 0.4.1 — 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-SJQZoo2a.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.4.
|
|
2
|
-
import{calculateBlock as t}from"mathzetta/calculate";import{t as a,a as o}from"./draw-
|
|
1
|
+
/* Inline Math 0.4.1 — 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-SJQZoo2a.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.1 — MIT license; includes mathzetta (and @mathzetta/cas, for the CAS) */
|
|
2
|
+
import{c as o}from"./calculate-HWNd7HTQ.js";import{e as s,f as t}from"./lite-OfhVrBim.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};
|