@holgerengels/compute-engine
Version:
Symbolic computing and numeric evaluations for JavaScript and Node.js
11 lines • 523 kB
JavaScript
/** Compute Engine 0.26.0-alpha2 */
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngine = {}));})(this, (function (exports) { 'use strict';
var ComputeEngine=(()=>{var io=Object.defineProperty;var jf=Object.getOwnPropertyDescriptor;var Zf=Object.getOwnPropertyNames;var Hf=Object.prototype.hasOwnProperty;var Wf=(e,n)=>{for(var i in n)io(e,i,{get:n[i],enumerable:!0})},Jf=(e,n,i,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Zf(n))!Hf.call(e,r)&&r!==i&&io(e,r,{get:()=>n[r],enumerable:!(t=jf(n,r))||t.enumerable});return e};var Yf=e=>Jf(io({},"__esModule",{value:!0}),e);var pm={};Wf(pm,{ComputeEngine:()=>tt,highlightCodeBlock:()=>Uf,highlightCodeSpan:()=>zf,isBoxedRule:()=>ro,isRuleStep:()=>to,terminal:()=>qf,version:()=>dm});function to(e){return e&&typeof e=="object"&&"because"in e&&"value"in e}function ro(e){return e&&typeof e=="object"&&e._tag==="boxed-rule"}var Se=Math.cosh||function(e){return Math.abs(e)<1e-9?1-e:(Math.exp(e)+Math.exp(-e))*.5},$e=Math.sinh||function(e){return Math.abs(e)<1e-9?e:(Math.exp(e)-Math.exp(-e))*.5},Qf=function(e){var n=Math.PI/4;if(-n>e||e>n)return Math.cos(e)-1;var i=e*e;return i*(i*(i*(i*(i*(i*(i*(i/20922789888e3-1/87178291200)+1/479001600)-1/3628800)+1/40320)-1/720)+1/24)-1/2)},Xf=function(e,n){var i=Math.abs(e),t=Math.abs(n);return i<3e3&&t<3e3?Math.sqrt(i*i+t*t):(i<t?(i=t,t=e/n):t=n/e,i*Math.sqrt(1+t*t))},xi=function(){throw SyntaxError("Invalid Param")};function oo(e,n){var i=Math.abs(e),t=Math.abs(n);return e===0?Math.log(t):n===0?Math.log(i):i<3e3&&t<3e3?Math.log(e*e+n*n)*.5:(e=e/2,n=n/2,.5*Math.log(e*e+n*n)+Math.LN2)}var Kf=function(e,n){var i={re:0,im:0};if(e==null)i.re=i.im=0;else if(n!==void 0)i.re=e,i.im=n;else switch(typeof e){case"object":if("im"in e&&"re"in e)i.re=e.re,i.im=e.im;else if("abs"in e&&"arg"in e){if(!Number.isFinite(e.abs)&&Number.isFinite(e.arg))return O.INFINITY;i.re=e.abs*Math.cos(e.arg),i.im=e.abs*Math.sin(e.arg)}else if("r"in e&&"phi"in e){if(!Number.isFinite(e.r)&&Number.isFinite(e.phi))return O.INFINITY;i.re=e.r*Math.cos(e.phi),i.im=e.r*Math.sin(e.phi)}else e.length===2?(i.re=e[0],i.im=e[1]):xi();break;case"string":i.im=i.re=0;var t=e.match(/\d+\.?\d*e[+-]?\d+|\d+\.?\d*|\.\d+|./g),r=1,o=0;t===null&&xi();for(var s=0;s<t.length;s++){var a=t[s];a===" "||a===" "||a===`
`||(a==="+"?r++:a==="-"?o++:a==="i"||a==="I"?(r+o===0&&xi(),t[s+1]!==" "&&!isNaN(Number(t[s+1]))?(i.im+=parseFloat((o%2?"-":"")+t[s+1]),s++):i.im+=parseFloat((o%2?"-":"")+"1"),r=o=0):((r+o===0||isNaN(Number(a)))&&xi(),t[s+1]==="i"||t[s+1]==="I"?(i.im+=parseFloat((o%2?"-":"")+a),s++):i.re+=parseFloat((o%2?"-":"")+a),r=o=0))}r+o>0&&xi();break;case"number":i.im=0,i.re=e;break;default:xi()}return isNaN(i.re)||isNaN(i.im),i},O=class e{constructor(n,i){this.re=0,this.im=0;var t=Kf(n,i);this.re=t.re,this.im=t.im}sign(){var n=this.abs();return new e(this.re/n,this.im/n)}add(n,i){var t=new e(n,i);return this.isInfinite()&&t.isInfinite()?e.NAN:this.isInfinite()||t.isInfinite()?e.INFINITY:new e(this.re+t.re,this.im+t.im)}sub(n,i){var t=new e(n,i);return this.isInfinite()&&t.isInfinite()?e.NAN:this.isInfinite()||t.isInfinite()?e.INFINITY:new e(this.re-t.re,this.im-t.im)}mul(n,i){var t=new e(n,i);return this.isInfinite()&&t.isZero()||this.isZero()&&t.isInfinite()?e.NAN:this.isInfinite()||t.isInfinite()?e.INFINITY:t.im===0&&this.im===0?new e(this.re*t.re,0):new e(this.re*t.re-this.im*t.im,this.re*t.im+this.im*t.re)}div(n,i){var t=new e(n,i);if(this.isZero()&&t.isZero()||this.isInfinite()&&t.isInfinite())return e.NAN;if(this.isInfinite()||t.isZero())return e.INFINITY;if(this.isZero()||t.isInfinite())return e.ZERO;n=this.re,i=this.im;var r=t.re,o=t.im,s,a;return o===0?new e(n/r,i/r):Math.abs(r)<Math.abs(o)?(a=r/o,s=r*a+o,new e((n*a+i)/s,(i*a-n)/s)):(a=o/r,s=o*a+r,new e((n+i*a)/s,(i-n*a)/s))}pow(n,i){var t=new e(n,i);if(n=this.re,i=this.im,t.isZero())return e.ONE;if(t.im===0){if(i===0&&n>0)return new e(Math.pow(n,t.re),0);if(n===0)switch((t.re%4+4)%4){case 0:return new e(Math.pow(i,t.re),0);case 1:return new e(0,Math.pow(i,t.re));case 2:return new e(-Math.pow(i,t.re),0);case 3:return new e(0,-Math.pow(i,t.re))}}if(n===0&&i===0&&t.re>0&&t.im>=0)return e.ZERO;var r=Math.atan2(i,n),o=oo(n,i);return n=Math.exp(t.re*o-t.im*r),i=t.im*o+t.re*r,new e(n*Math.cos(i),n*Math.sin(i))}sqrt(){var n=this.re,i=this.im,t=this.abs(),r,o;if(n>=0){if(i===0)return new e(Math.sqrt(n),0);r=.5*Math.sqrt(2*(t+n))}else r=Math.abs(i)/Math.sqrt(2*(t-n));return n<=0?o=.5*Math.sqrt(2*(t-n)):o=Math.abs(i)/Math.sqrt(2*(t+n)),new e(r,i<0?-o:o)}exp(){var n=Math.exp(this.re);return this.im,new e(n*Math.cos(this.im),n*Math.sin(this.im))}expm1(){var n=this.re,i=this.im;return new e(Math.expm1(n)*Math.cos(i)+Qf(i),Math.exp(n)*Math.sin(i))}log(){var n=this.re,i=this.im;return i===0&&n>0,new e(oo(n,i),Math.atan2(i,n))}abs(){return Xf(this.re,this.im)}arg(){return Math.atan2(this.im,this.re)}sin(){var n=this.re,i=this.im;return new e(Math.sin(n)*Se(i),Math.cos(n)*$e(i))}cos(){var n=this.re,i=this.im;return new e(Math.cos(n)*Se(i),-Math.sin(n)*$e(i))}tan(){var n=2*this.re,i=2*this.im,t=Math.cos(n)+Se(i);return new e(Math.sin(n)/t,$e(i)/t)}cot(){var n=2*this.re,i=2*this.im,t=Math.cos(n)-Se(i);return new e(-Math.sin(n)/t,$e(i)/t)}sec(){var n=this.re,i=this.im,t=.5*Se(2*i)+.5*Math.cos(2*n);return new e(Math.cos(n)*Se(i)/t,Math.sin(n)*$e(i)/t)}csc(){var n=this.re,i=this.im,t=.5*Se(2*i)-.5*Math.cos(2*n);return new e(Math.sin(n)*Se(i)/t,-Math.cos(n)*$e(i)/t)}asin(){var n=this.re,i=this.im,t=new e(i*i-n*n+1,-2*n*i).sqrt(),r=new e(t.re-i,t.im+n).log();return new e(r.im,-r.re)}acos(){var n=this.re,i=this.im,t=new e(i*i-n*n+1,-2*n*i).sqrt(),r=new e(t.re-i,t.im+n).log();return new e(Math.PI/2-r.im,r.re)}atan(){var n=this.re,i=this.im;if(n===0){if(i===1)return new e(0,1/0);if(i===-1)return new e(0,-1/0)}var t=n*n+(1-i)*(1-i),r=new e((1-i*i-n*n)/t,-2*n/t).log();return new e(-.5*r.im,.5*r.re)}acot(){var n=this.re,i=this.im;if(i===0)return new e(Math.atan2(1,n),0);var t=n*n+i*i;return t!==0?new e(n/t,-i/t).atan():new e(n!==0?n/0:0,i!==0?-i/0:0).atan()}asec(){var n=this.re,i=this.im;if(n===0&&i===0)return new e(0,1/0);var t=n*n+i*i;return t!==0?new e(n/t,-i/t).acos():new e(n!==0?n/0:0,i!==0?-i/0:0).acos()}acsc(){var n=this.re,i=this.im;if(n===0&&i===0)return new e(Math.PI/2,1/0);var t=n*n+i*i;return t!==0?new e(n/t,-i/t).asin():new e(n!==0?n/0:0,i!==0?-i/0:0).asin()}sinh(){var n=this.re,i=this.im;return new e($e(n)*Math.cos(i),Se(n)*Math.sin(i))}cosh(){var n=this.re,i=this.im;return new e(Se(n)*Math.cos(i),$e(n)*Math.sin(i))}tanh(){var n=2*this.re,i=2*this.im,t=Se(n)+Math.cos(i);return new e($e(n)/t,Math.sin(i)/t)}coth(){var n=2*this.re,i=2*this.im,t=Se(n)-Math.cos(i);return new e($e(n)/t,-Math.sin(i)/t)}csch(){var n=this.re,i=this.im,t=Math.cos(2*i)-Se(2*n);return new e(-2*$e(n)*Math.cos(i)/t,2*Se(n)*Math.sin(i)/t)}sech(){var n=this.re,i=this.im,t=Math.cos(2*i)+Se(2*n);return new e(2*Se(n)*Math.cos(i)/t,-2*$e(n)*Math.sin(i)/t)}asinh(){var n=this.im;this.im=-this.re,this.re=n;var i=this.asin();return this.re=-this.im,this.im=n,n=i.re,i.re=-i.im,i.im=n,i}acosh(){var n=this.acos();if(n.im<=0){var i=n.re;n.re=-n.im,n.im=i}else{var i=n.im;n.im=-n.re,n.re=i}return n}atanh(){var n=this.re,i=this.im,t=n>1&&i===0,r=1-n,o=1+n,s=r*r+i*i,a=s!==0?new e((o*r-i*i)/s,(i*r+o*i)/s):new e(n!==-1?n/0:0,i!==0?i/0:0),u=a.re;return a.re=oo(a.re,a.im)/2,a.im=Math.atan2(a.im,u)/2,t&&(a.im=-a.im),a}acoth(){var n=this.re,i=this.im;if(n===0&&i===0)return new e(0,Math.PI/2);var t=n*n+i*i;return t!==0?new e(n/t,-i/t).atanh():new e(n!==0?n/0:0,i!==0?-i/0:0).atanh()}acsch(){var n=this.re,i=this.im;if(i===0)return new e(n!==0?Math.log(n+Math.sqrt(n*n+1)):1/0,0);var t=n*n+i*i;return t!==0?new e(n/t,-i/t).asinh():new e(n!==0?n/0:0,i!==0?-i/0:0).asinh()}asech(){var n=this.re,i=this.im;if(this.isZero())return e.INFINITY;var t=n*n+i*i;return t!==0?new e(n/t,-i/t).acosh():new e(n!==0?n/0:0,i!==0?-i/0:0).acosh()}inverse(){if(this.isZero())return e.INFINITY;if(this.isInfinite())return e.ZERO;var n=this.re,i=this.im,t=n*n+i*i;return new e(n/t,-i/t)}conjugate(){return new e(this.re,-this.im)}neg(){return new e(-this.re,-this.im)}ceil(n){return n=Math.pow(10,n||0),new e(Math.ceil(this.re*n)/n,Math.ceil(this.im*n)/n)}floor(n){return n=Math.pow(10,n||0),new e(Math.floor(this.re*n)/n,Math.floor(this.im*n)/n)}round(n){return n=Math.pow(10,n||0),new e(Math.round(this.re*n)/n,Math.round(this.im*n)/n)}equals(n,i){var t=new e(n,i);return Math.abs(t.re-this.re)<=e.EPSILON&&Math.abs(t.im-this.im)<=e.EPSILON}clone(){return new e(this.re,this.im)}toString(){var n=this.re,i=this.im,t="";return this.isNaN()?"NaN":this.isInfinite()?"Infinity":(Math.abs(n)<e.EPSILON&&(n=0),Math.abs(i)<e.EPSILON&&(i=0),i===0?t+n:(n!==0?(t+=n,t+=" ",i<0?(i=-i,t+="-"):t+="+",t+=" "):i<0&&(i=-i,t+="-"),i!==1&&(t+=i),t+"i"))}toVector(){return[this.re,this.im]}valueOf(){return this.im===0?this.re:null}isNaN(){return isNaN(this.re)||isNaN(this.im)}isZero(){return this.im===0&&this.re===0}isFinite(){return isFinite(this.re)&&isFinite(this.im)}isInfinite(){return!(this.isNaN()||this.isFinite())}};O.ZERO=new O(0,0);O.ONE=new O(1,0);O.I=new O(0,1);O.PI=new O(Math.PI,0);O.E=new O(Math.E,0);O.INFINITY=new O(1/0,1/0);O.NAN=new O(NaN,NaN);O.EPSILON=1e-15;var yi=9e15,Ln=1e9,so="0123456789abcdef",Jt="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Yt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ao={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-yi,maxE:yi,crypto:!1},oa,vn,B=!0,Xt="[DecimalError] ",On=Xt+"Invalid argument: ",sa=Xt+"Precision limit exceeded",aa=Xt+"crypto unavailable",ua="[object Decimal]",Te=Math.floor,pe=Math.pow,ec=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,nc=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,ic=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,la=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,tn=1e7,I=7,tc=9007199254740991,rc=Jt.length-1,uo=Yt.length-1,h={toStringTag:ua};h.absoluteValue=h.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),S(e)};h.ceil=function(){return S(new this.constructor(this),this.e+1,2)};h.clampedTo=h.clamp=function(e,n){var i,t=this,r=t.constructor;if(e=new r(e),n=new r(n),!e.s||!n.s)return new r(NaN);if(e.gt(n))throw Error(On+n);return i=t.cmp(e),i<0?e:t.cmp(n)>0?n:new r(t)};h.comparedTo=h.cmp=function(e){var n,i,t,r,o=this,s=o.d,a=(e=new o.constructor(e)).d,u=o.s,l=e.s;if(!s||!a)return!u||!l?NaN:u!==l?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-l:0;if(u!==l)return u;if(o.e!==e.e)return o.e>e.e^u<0?1:-1;for(t=s.length,r=a.length,n=0,i=t<r?t:r;n<i;++n)if(s[n]!==a[n])return s[n]>a[n]^u<0?1:-1;return t===r?0:t>r^u<0?1:-1};h.cosine=h.cos=function(){var e,n,i=this,t=i.constructor;return i.d?i.d[0]?(e=t.precision,n=t.rounding,t.precision=e+Math.max(i.e,i.sd())+I,t.rounding=1,i=oc(t,ma(t,i)),t.precision=e,t.rounding=n,S(vn==2||vn==3?i.neg():i,e,n,!0)):new t(1):new t(NaN)};h.cubeRoot=h.cbrt=function(){var e,n,i,t,r,o,s,a,u,l,f=this,c=f.constructor;if(!f.isFinite()||f.isZero())return new c(f);for(B=!1,o=f.s*pe(f.s*f,1/3),!o||Math.abs(o)==1/0?(i=Ee(f.d),e=f.e,(o=(e-i.length+1)%3)&&(i+=o==1||o==-2?"0":"00"),o=pe(i,1/3),e=Te((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?i="5e"+e:(i=o.toExponential(),i=i.slice(0,i.indexOf("e")+1)+e),t=new c(i),t.s=f.s):t=new c(o.toString()),s=(e=c.precision)+3;;)if(a=t,u=a.times(a).times(a),l=u.plus(f),t=U(l.plus(f).times(a),l.plus(u),s+2,1),Ee(a.d).slice(0,s)===(i=Ee(t.d)).slice(0,s))if(i=i.slice(s-3,s+1),i=="9999"||!r&&i=="4999"){if(!r&&(S(a,e+1,0),a.times(a).times(a).eq(f))){t=a;break}s+=4,r=1}else{(!+i||!+i.slice(1)&&i.charAt(0)=="5")&&(S(t,e+1,1),n=!t.times(t).times(t).eq(f));break}return B=!0,S(t,e,c.rounding,n)};h.decimalPlaces=h.dp=function(){var e,n=this.d,i=NaN;if(n){if(e=n.length-1,i=(e-Te(this.e/I))*I,e=n[e],e)for(;e%10==0;e/=10)i--;i<0&&(i=0)}return i};h.dividedBy=h.div=function(e){return U(this,new this.constructor(e))};h.dividedToIntegerBy=h.divToInt=function(e){var n=this,i=n.constructor;return S(U(n,new i(e),0,1,1),i.precision,i.rounding)};h.equals=h.eq=function(e){return this.cmp(e)===0};h.floor=function(){return S(new this.constructor(this),this.e+1,3)};h.greaterThan=h.gt=function(e){return this.cmp(e)>0};h.greaterThanOrEqualTo=h.gte=function(e){var n=this.cmp(e);return n==1||n===0};h.hyperbolicCosine=h.cosh=function(){var e,n,i,t,r,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;i=s.precision,t=s.rounding,s.precision=i+Math.max(o.e,o.sd())+4,s.rounding=1,r=o.d.length,r<32?(e=Math.ceil(r/3),n=(1/er(4,e)).toString()):(e=16,n="2.3283064365386962890625e-10"),o=bi(s,1,o.times(n),new s(1),!0);for(var u,l=e,f=new s(8);l--;)u=o.times(o),o=a.minus(u.times(f.minus(u.times(f))));return S(o,s.precision=i,s.rounding=t,!0)};h.hyperbolicSine=h.sinh=function(){var e,n,i,t,r=this,o=r.constructor;if(!r.isFinite()||r.isZero())return new o(r);if(n=o.precision,i=o.rounding,o.precision=n+Math.max(r.e,r.sd())+4,o.rounding=1,t=r.d.length,t<3)r=bi(o,2,r,r,!0);else{e=1.4*Math.sqrt(t),e=e>16?16:e|0,r=r.times(1/er(5,e)),r=bi(o,2,r,r,!0);for(var s,a=new o(5),u=new o(16),l=new o(20);e--;)s=r.times(r),r=r.times(a.plus(s.times(u.times(s).plus(l))))}return o.precision=n,o.rounding=i,S(r,n,i,!0)};h.hyperbolicTangent=h.tanh=function(){var e,n,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(e=t.precision,n=t.rounding,t.precision=e+7,t.rounding=1,U(i.sinh(),i.cosh(),t.precision=e,t.rounding=n)):new t(i.s)};h.inverseCosine=h.acos=function(){var e,n=this,i=n.constructor,t=n.abs().cmp(1),r=i.precision,o=i.rounding;return t!==-1?t===0?n.isNeg()?nn(i,r,o):new i(0):new i(NaN):n.isZero()?nn(i,r+4,o).times(.5):(i.precision=r+6,i.rounding=1,n=n.asin(),e=nn(i,r+4,o).times(.5),i.precision=r,i.rounding=o,e.minus(n))};h.inverseHyperbolicCosine=h.acosh=function(){var e,n,i=this,t=i.constructor;return i.lte(1)?new t(i.eq(1)?0:NaN):i.isFinite()?(e=t.precision,n=t.rounding,t.precision=e+Math.max(Math.abs(i.e),i.sd())+4,t.rounding=1,B=!1,i=i.times(i).minus(1).sqrt().plus(i),B=!0,t.precision=e,t.rounding=n,i.ln()):new t(i)};h.inverseHyperbolicSine=h.asinh=function(){var e,n,i=this,t=i.constructor;return!i.isFinite()||i.isZero()?new t(i):(e=t.precision,n=t.rounding,t.precision=e+2*Math.max(Math.abs(i.e),i.sd())+6,t.rounding=1,B=!1,i=i.times(i).plus(1).sqrt().plus(i),B=!0,t.precision=e,t.rounding=n,i.ln())};h.inverseHyperbolicTangent=h.atanh=function(){var e,n,i,t,r=this,o=r.constructor;return r.isFinite()?r.e>=0?new o(r.abs().eq(1)?r.s/0:r.isZero()?r:NaN):(e=o.precision,n=o.rounding,t=r.sd(),Math.max(t,e)<2*-r.e-1?S(new o(r),e,n,!0):(o.precision=i=t-r.e,r=U(r.plus(1),new o(1).minus(r),i+e,1),o.precision=e+4,o.rounding=1,r=r.ln(),o.precision=e,o.rounding=n,r.times(.5))):new o(NaN)};h.inverseSine=h.asin=function(){var e,n,i,t,r=this,o=r.constructor;return r.isZero()?new o(r):(n=r.abs().cmp(1),i=o.precision,t=o.rounding,n!==-1?n===0?(e=nn(o,i+4,t).times(.5),e.s=r.s,e):new o(NaN):(o.precision=i+6,o.rounding=1,r=r.div(new o(1).minus(r.times(r)).sqrt().plus(1)).atan(),o.precision=i,o.rounding=t,r.times(2)))};h.inverseTangent=h.atan=function(){var e,n,i,t,r,o,s,a,u,l=this,f=l.constructor,c=f.precision,d=f.rounding;if(l.isFinite()){if(l.isZero())return new f(l);if(l.abs().eq(1)&&c+4<=uo)return s=nn(f,c+4,d).times(.25),s.s=l.s,s}else{if(!l.s)return new f(NaN);if(c+4<=uo)return s=nn(f,c+4,d).times(.5),s.s=l.s,s}for(f.precision=a=c+10,f.rounding=1,i=Math.min(28,a/I+2|0),e=i;e;--e)l=l.div(l.times(l).plus(1).sqrt().plus(1));for(B=!1,n=Math.ceil(a/I),t=1,u=l.times(l),s=new f(l),r=l;e!==-1;)if(r=r.times(u),o=s.minus(r.div(t+=2)),r=r.times(u),s=o.plus(r.div(t+=2)),s.d[n]!==void 0)for(e=n;s.d[e]===o.d[e]&&e--;);return i&&(s=s.times(2<<i-1)),B=!0,S(s,f.precision=c,f.rounding=d,!0)};h.isFinite=function(){return!!this.d};h.isInteger=h.isInt=function(){return!!this.d&&Te(this.e/I)>this.d.length-2};h.isNaN=function(){return!this.s};h.isNegative=h.isNeg=function(){return this.s<0};h.isPositive=h.isPos=function(){return this.s>0};h.isZero=function(){return!!this.d&&this.d[0]===0};h.lessThan=h.lt=function(e){return this.cmp(e)<0};h.lessThanOrEqualTo=h.lte=function(e){return this.cmp(e)<1};h.logarithm=h.log=function(e){var n,i,t,r,o,s,a,u,l=this,f=l.constructor,c=f.precision,d=f.rounding,m=5;if(e==null)e=new f(10),n=!0;else{if(e=new f(e),i=e.d,e.s<0||!i||!i[0]||e.eq(1))return new f(NaN);n=e.eq(10)}if(i=l.d,l.s<0||!i||!i[0]||l.eq(1))return new f(i&&!i[0]?-1/0:l.s!=1?NaN:i?0:1/0);if(n)if(i.length>1)o=!0;else{for(r=i[0];r%10===0;)r/=10;o=r!==1}if(B=!1,a=c+m,s=Pn(l,a),t=n?Qt(f,a+10):Pn(e,a),u=U(s,t,a,1),ot(u.d,r=c,d))do if(a+=10,s=Pn(l,a),t=n?Qt(f,a+10):Pn(e,a),u=U(s,t,a,1),!o){+Ee(u.d).slice(r+1,r+15)+1==1e14&&(u=S(u,c+1,0));break}while(ot(u.d,r+=10,d));return B=!0,S(u,c,d)};h.minus=h.sub=function(e){var n,i,t,r,o,s,a,u,l,f,c,d,m=this,b=m.constructor;if(e=new b(e),!m.d||!e.d)return!m.s||!e.s?e=new b(NaN):m.d?e.s=-e.s:e=new b(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(l=m.d,d=e.d,a=b.precision,u=b.rounding,!l[0]||!d[0]){if(d[0])e.s=-e.s;else if(l[0])e=new b(m);else return new b(u===3?-0:0);return B?S(e,a,u):e}if(i=Te(e.e/I),f=Te(m.e/I),l=l.slice(),o=f-i,o){for(c=o<0,c?(n=l,o=-o,s=d.length):(n=d,i=f,s=l.length),t=Math.max(Math.ceil(a/I),s)+2,o>t&&(o=t,n.length=1),n.reverse(),t=o;t--;)n.push(0);n.reverse()}else{for(t=l.length,s=d.length,c=t<s,c&&(s=t),t=0;t<s;t++)if(l[t]!=d[t]){c=l[t]<d[t];break}o=0}for(c&&(n=l,l=d,d=n,e.s=-e.s),s=l.length,t=d.length-s;t>0;--t)l[s++]=0;for(t=d.length;t>o;){if(l[--t]<d[t]){for(r=t;r&&l[--r]===0;)l[r]=tn-1;--l[r],l[t]+=tn}l[t]-=d[t]}for(;l[--s]===0;)l.pop();for(;l[0]===0;l.shift())--i;return l[0]?(e.d=l,e.e=Kt(l,i),B?S(e,a,u):e):new b(u===3?-0:0)};h.modulo=h.mod=function(e){var n,i=this,t=i.constructor;return e=new t(e),!i.d||!e.s||e.d&&!e.d[0]?new t(NaN):!e.d||i.d&&!i.d[0]?S(new t(i),t.precision,t.rounding):(B=!1,t.modulo==9?(n=U(i,e.abs(),0,3,1),n.s*=e.s):n=U(i,e,0,t.modulo,1),n=n.times(e),B=!0,i.minus(n))};h.naturalExponential=h.exp=function(){return lo(this)};h.naturalLogarithm=h.ln=function(){return Pn(this)};h.negated=h.neg=function(){var e=new this.constructor(this);return e.s=-e.s,S(e)};h.plus=h.add=function(e){var n,i,t,r,o,s,a,u,l,f,c=this,d=c.constructor;if(e=new d(e),!c.d||!e.d)return!c.s||!e.s?e=new d(NaN):c.d||(e=new d(e.d||c.s===e.s?c:NaN)),e;if(c.s!=e.s)return e.s=-e.s,c.minus(e);if(l=c.d,f=e.d,a=d.precision,u=d.rounding,!l[0]||!f[0])return f[0]||(e=new d(c)),B?S(e,a,u):e;if(o=Te(c.e/I),t=Te(e.e/I),l=l.slice(),r=o-t,r){for(r<0?(i=l,r=-r,s=f.length):(i=f,t=o,s=l.length),o=Math.ceil(a/I),s=o>s?o+1:s+1,r>s&&(r=s,i.length=1),i.reverse();r--;)i.push(0);i.reverse()}for(s=l.length,r=f.length,s-r<0&&(r=s,i=f,f=l,l=i),n=0;r;)n=(l[--r]=l[r]+f[r]+n)/tn|0,l[r]%=tn;for(n&&(l.unshift(n),++t),s=l.length;l[--s]==0;)l.pop();return e.d=l,e.e=Kt(l,t),B?S(e,a,u):e};h.precision=h.sd=function(e){var n,i=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(On+e);return i.d?(n=fa(i.d),e&&i.e+1>n&&(n=i.e+1)):n=NaN,n};h.round=function(){var e=this,n=e.constructor;return S(new n(e),e.e+1,n.rounding)};h.sine=h.sin=function(){var e,n,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(e=t.precision,n=t.rounding,t.precision=e+Math.max(i.e,i.sd())+I,t.rounding=1,i=ac(t,ma(t,i)),t.precision=e,t.rounding=n,S(vn>2?i.neg():i,e,n,!0)):new t(NaN)};h.squareRoot=h.sqrt=function(){var e,n,i,t,r,o,s=this,a=s.d,u=s.e,l=s.s,f=s.constructor;if(l!==1||!a||!a[0])return new f(!l||l<0&&(!a||a[0])?NaN:a?s:1/0);for(B=!1,l=Math.sqrt(+s),l==0||l==1/0?(n=Ee(a),(n.length+u)%2==0&&(n+="0"),l=Math.sqrt(n),u=Te((u+1)/2)-(u<0||u%2),l==1/0?n="5e"+u:(n=l.toExponential(),n=n.slice(0,n.indexOf("e")+1)+u),t=new f(n)):t=new f(l.toString()),i=(u=f.precision)+3;;)if(o=t,t=o.plus(U(s,o,i+2,1)).times(.5),Ee(o.d).slice(0,i)===(n=Ee(t.d)).slice(0,i))if(n=n.slice(i-3,i+1),n=="9999"||!r&&n=="4999"){if(!r&&(S(o,u+1,0),o.times(o).eq(s))){t=o;break}i+=4,r=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(S(t,u+1,1),e=!t.times(t).eq(s));break}return B=!0,S(t,u,f.rounding,e)};h.tangent=h.tan=function(){var e,n,i=this,t=i.constructor;return i.isFinite()?i.isZero()?new t(i):(e=t.precision,n=t.rounding,t.precision=e+10,t.rounding=1,i=i.sin(),i.s=1,i=U(i,new t(1).minus(i.times(i)).sqrt(),e+10,0),t.precision=e,t.rounding=n,S(vn==2||vn==4?i.neg():i,e,n,!0)):new t(NaN)};h.times=h.mul=function(e){var n,i,t,r,o,s,a,u,l,f=this,c=f.constructor,d=f.d,m=(e=new c(e)).d;if(e.s*=f.s,!d||!d[0]||!m||!m[0])return new c(!e.s||d&&!d[0]&&!m||m&&!m[0]&&!d?NaN:!d||!m?e.s/0:e.s*0);for(i=Te(f.e/I)+Te(e.e/I),u=d.length,l=m.length,u<l&&(o=d,d=m,m=o,s=u,u=l,l=s),o=[],s=u+l,t=s;t--;)o.push(0);for(t=l;--t>=0;){for(n=0,r=u+t;r>t;)a=o[r]+m[t]*d[r-t-1]+n,o[r--]=a%tn|0,n=a/tn|0;o[r]=(o[r]+n)%tn|0}for(;!o[--s];)o.pop();return n?++i:o.shift(),e.d=o,e.e=Kt(o,i),B?S(e,c.precision,c.rounding):e};h.toBinary=function(e,n){return co(this,2,e,n)};h.toDecimalPlaces=h.toDP=function(e,n){var i=this,t=i.constructor;return i=new t(i),e===void 0?i:(De(e,0,Ln),n===void 0?n=t.rounding:De(n,0,8),S(i,e+i.e+1,n))};h.toExponential=function(e,n){var i,t=this,r=t.constructor;return e===void 0?i=cn(t,!0):(De(e,0,Ln),n===void 0?n=r.rounding:De(n,0,8),t=S(new r(t),e+1,n),i=cn(t,!0,e+1)),t.isNeg()&&!t.isZero()?"-"+i:i};h.toFixed=function(e,n){var i,t,r=this,o=r.constructor;return e===void 0?i=cn(r):(De(e,0,Ln),n===void 0?n=o.rounding:De(n,0,8),t=S(new o(r),e+r.e+1,n),i=cn(t,!1,e+t.e+1)),r.isNeg()&&!r.isZero()?"-"+i:i};h.toFraction=function(e){var n,i,t,r,o,s,a,u,l,f,c,d,m=this,b=m.d,y=m.constructor;if(!b)return new y(m);if(l=i=new y(1),t=u=new y(0),n=new y(t),o=n.e=fa(b)-m.e-1,s=o%I,n.d[0]=pe(10,s<0?I+s:s),e==null)e=o>0?n:l;else{if(a=new y(e),!a.isInt()||a.lt(l))throw Error(On+a);e=a.gt(n)?o>0?n:l:a}for(B=!1,a=new y(Ee(b)),f=y.precision,y.precision=o=b.length*I*2;c=U(a,n,0,1,1),r=i.plus(c.times(t)),r.cmp(e)!=1;)i=t,t=r,r=l,l=u.plus(c.times(r)),u=r,r=n,n=a.minus(c.times(r)),a=r;return r=U(e.minus(i),t,0,1,1),u=u.plus(r.times(l)),i=i.plus(r.times(t)),u.s=l.s=m.s,d=U(l,t,o,1).minus(m).abs().cmp(U(u,i,o,1).minus(m).abs())<1?[l,t]:[u,i],y.precision=f,B=!0,d};h.toHexadecimal=h.toHex=function(e,n){return co(this,16,e,n)};h.toNearest=function(e,n){var i=this,t=i.constructor;if(i=new t(i),e==null){if(!i.d)return i;e=new t(1),n=t.rounding}else{if(e=new t(e),n===void 0?n=t.rounding:De(n,0,8),!i.d)return e.s?i:e;if(!e.d)return e.s&&(e.s=i.s),e}return e.d[0]?(B=!1,i=U(i,e,0,n,1).times(e),B=!0,S(i)):(e.s=i.s,i=e),i};h.toNumber=function(){return+this};h.toOctal=function(e,n){return co(this,8,e,n)};h.toPower=h.pow=function(e){var n,i,t,r,o,s,a=this,u=a.constructor,l=+(e=new u(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new u(pe(+a,l));if(a=new u(a),a.eq(1))return a;if(t=u.precision,o=u.rounding,e.eq(1))return S(a,t,o);if(n=Te(e.e/I),n>=e.d.length-1&&(i=l<0?-l:l)<=tc)return r=ca(u,a,i,t),e.s<0?new u(1).div(r):S(r,t,o);if(s=a.s,s<0){if(n<e.d.length-1)return new u(NaN);if(e.d[n]&1||(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return i=pe(+a,l),n=i==0||!isFinite(i)?Te(l*(Math.log("0."+Ee(a.d))/Math.LN10+a.e+1)):new u(i+"").e,n>u.maxE+1||n<u.minE-1?new u(n>0?s/0:0):(B=!1,u.rounding=a.s=1,i=Math.min(12,(n+"").length),r=lo(e.times(Pn(a,t+i)),t),r.d&&(r=S(r,t+5,1),ot(r.d,t,o)&&(n=t+10,r=S(lo(e.times(Pn(a,n+i)),n),n+5,1),+Ee(r.d).slice(t+1,t+15)+1==1e14&&(r=S(r,t+1,0)))),r.s=s,B=!0,u.rounding=o,S(r,t,o))};h.toPrecision=function(e,n){var i,t=this,r=t.constructor;return e===void 0?i=cn(t,t.e<=r.toExpNeg||t.e>=r.toExpPos):(De(e,1,Ln),n===void 0?n=r.rounding:De(n,0,8),t=S(new r(t),e,n),i=cn(t,e<=t.e||t.e<=r.toExpNeg,e)),t.isNeg()&&!t.isZero()?"-"+i:i};h.toSignificantDigits=h.toSD=function(e,n){var i=this,t=i.constructor;return e===void 0?(e=t.precision,n=t.rounding):(De(e,1,Ln),n===void 0?n=t.rounding:De(n,0,8)),S(new t(i),e,n)};h.toString=function(){var e=this,n=e.constructor,i=cn(e,e.e<=n.toExpNeg||e.e>=n.toExpPos);return e.isNeg()&&!e.isZero()?"-"+i:i};h.truncated=h.trunc=function(){return S(new this.constructor(this),this.e+1,1)};h.valueOf=h.toJSON=function(){var e=this,n=e.constructor,i=cn(e,e.e<=n.toExpNeg||e.e>=n.toExpPos);return e.isNeg()?"-"+i:i};function Ee(e){var n,i,t,r=e.length-1,o="",s=e[0];if(r>0){for(o+=s,n=1;n<r;n++)t=e[n]+"",i=I-t.length,i&&(o+=Cn(i)),o+=t;s=e[n],t=s+"",i=I-t.length,i&&(o+=Cn(i))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function De(e,n,i){if(e!==~~e||e<n||e>i)throw Error(On+e)}function ot(e,n,i,t){var r,o,s,a;for(o=e[0];o>=10;o/=10)--n;return--n<0?(n+=I,r=0):(r=Math.ceil((n+1)/I),n%=I),o=pe(10,I-n),a=e[r]%o|0,t==null?n<3?(n==0?a=a/100|0:n==1&&(a=a/10|0),s=i<4&&a==99999||i>3&&a==49999||a==5e4||a==0):s=(i<4&&a+1==o||i>3&&a+1==o/2)&&(e[r+1]/o/100|0)==pe(10,n-2)-1||(a==o/2||a==0)&&(e[r+1]/o/100|0)==0:n<4?(n==0?a=a/1e3|0:n==1?a=a/100|0:n==2&&(a=a/10|0),s=(t||i<4)&&a==9999||!t&&i>3&&a==4999):s=((t||i<4)&&a+1==o||!t&&i>3&&a+1==o/2)&&(e[r+1]/o/1e3|0)==pe(10,n-3)-1,s}function Wt(e,n,i){for(var t,r=[0],o,s=0,a=e.length;s<a;){for(o=r.length;o--;)r[o]*=n;for(r[0]+=so.indexOf(e.charAt(s++)),t=0;t<r.length;t++)r[t]>i-1&&(r[t+1]===void 0&&(r[t+1]=0),r[t+1]+=r[t]/i|0,r[t]%=i)}return r.reverse()}function oc(e,n){var i,t,r;if(n.isZero())return n;t=n.d.length,t<32?(i=Math.ceil(t/3),r=(1/er(4,i)).toString()):(i=16,r="2.3283064365386962890625e-10"),e.precision+=i,n=bi(e,1,n.times(r),new e(1));for(var o=i;o--;){var s=n.times(n);n=s.times(s).minus(s).times(8).plus(1)}return e.precision-=i,n}var U=function(){function e(t,r,o){var s,a=0,u=t.length;for(t=t.slice();u--;)s=t[u]*r+a,t[u]=s%o|0,a=s/o|0;return a&&t.unshift(a),t}function n(t,r,o,s){var a,u;if(o!=s)u=o>s?1:-1;else for(a=u=0;a<o;a++)if(t[a]!=r[a]){u=t[a]>r[a]?1:-1;break}return u}function i(t,r,o,s){for(var a=0;o--;)t[o]-=a,a=t[o]<r[o]?1:0,t[o]=a*s+t[o]-r[o];for(;!t[0]&&t.length>1;)t.shift()}return function(t,r,o,s,a,u){var l,f,c,d,m,b,y,N,T,R,_,P,xe,be,hi,jt,rt,eo,en,Zt,Ht=t.constructor,no=t.s==r.s?1:-1,ve=t.d,H=r.d;if(!ve||!ve[0]||!H||!H[0])return new Ht(!t.s||!r.s||(ve?H&&ve[0]==H[0]:!H)?NaN:ve&&ve[0]==0||!H?no*0:no/0);for(u?(m=1,f=t.e-r.e):(u=tn,m=I,f=Te(t.e/m)-Te(r.e/m)),en=H.length,rt=ve.length,T=new Ht(no),R=T.d=[],c=0;H[c]==(ve[c]||0);c++);if(H[c]>(ve[c]||0)&&f--,o==null?(be=o=Ht.precision,s=Ht.rounding):a?be=o+(t.e-r.e)+1:be=o,be<0)R.push(1),b=!0;else{if(be=be/m+2|0,c=0,en==1){for(d=0,H=H[0],be++;(c<rt||d)&&be--;c++)hi=d*u+(ve[c]||0),R[c]=hi/H|0,d=hi%H|0;b=d||c<rt}else{for(d=u/(H[0]+1)|0,d>1&&(H=e(H,d,u),ve=e(ve,d,u),en=H.length,rt=ve.length),jt=en,_=ve.slice(0,en),P=_.length;P<en;)_[P++]=0;Zt=H.slice(),Zt.unshift(0),eo=H[0],H[1]>=u/2&&++eo;do d=0,l=n(H,_,en,P),l<0?(xe=_[0],en!=P&&(xe=xe*u+(_[1]||0)),d=xe/eo|0,d>1?(d>=u&&(d=u-1),y=e(H,d,u),N=y.length,P=_.length,l=n(y,_,N,P),l==1&&(d--,i(y,en<N?Zt:H,N,u))):(d==0&&(l=d=1),y=H.slice()),N=y.length,N<P&&y.unshift(0),i(_,y,P,u),l==-1&&(P=_.length,l=n(H,_,en,P),l<1&&(d++,i(_,en<P?Zt:H,P,u))),P=_.length):l===0&&(d++,_=[0]),R[c++]=d,l&&_[0]?_[P++]=ve[jt]||0:(_=[ve[jt]],P=1);while((jt++<rt||_[0]!==void 0)&&be--);b=_[0]!==void 0}R[0]||R.shift()}if(m==1)T.e=f,oa=b;else{for(c=1,d=R[0];d>=10;d/=10)c++;T.e=c+f*m-1,S(T,a?o+T.e+1:o,s,b)}return T}}();function S(e,n,i,t){var r,o,s,a,u,l,f,c,d,m=e.constructor;e:if(n!=null){if(c=e.d,!c)return e;for(r=1,a=c[0];a>=10;a/=10)r++;if(o=n-r,o<0)o+=I,s=n,f=c[d=0],u=f/pe(10,r-s-1)%10|0;else if(d=Math.ceil((o+1)/I),a=c.length,d>=a)if(t){for(;a++<=d;)c.push(0);f=u=0,r=1,o%=I,s=o-I+1}else break e;else{for(f=a=c[d],r=1;a>=10;a/=10)r++;o%=I,s=o-I+r,u=s<0?0:f/pe(10,r-s-1)%10|0}if(t=t||n<0||c[d+1]!==void 0||(s<0?f:f%pe(10,r-s-1)),l=i<4?(u||t)&&(i==0||i==(e.s<0?3:2)):u>5||u==5&&(i==4||t||i==6&&(o>0?s>0?f/pe(10,r-s):0:c[d-1])%10&1||i==(e.s<0?8:7)),n<1||!c[0])return c.length=0,l?(n-=e.e+1,c[0]=pe(10,(I-n%I)%I),e.e=-n||0):c[0]=e.e=0,e;if(o==0?(c.length=d,a=1,d--):(c.length=d+1,a=pe(10,I-o),c[d]=s>0?(f/pe(10,r-s)%pe(10,s)|0)*a:0),l)for(;;)if(d==0){for(o=1,s=c[0];s>=10;s/=10)o++;for(s=c[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(e.e++,c[0]==tn&&(c[0]=1));break}else{if(c[d]+=a,c[d]!=tn)break;c[d--]=0,a=1}for(o=c.length;c[--o]===0;)c.pop()}return B&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function cn(e,n,i){if(!e.isFinite())return pa(e);var t,r=e.e,o=Ee(e.d),s=o.length;return n?(i&&(t=i-s)>0?o=o.charAt(0)+"."+o.slice(1)+Cn(t):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):r<0?(o="0."+Cn(-r-1)+o,i&&(t=i-s)>0&&(o+=Cn(t))):r>=s?(o+=Cn(r+1-s),i&&(t=i-r-1)>0&&(o=o+"."+Cn(t))):((t=r+1)<s&&(o=o.slice(0,t)+"."+o.slice(t)),i&&(t=i-s)>0&&(r+1===s&&(o+="."),o+=Cn(t))),o}function Kt(e,n){var i=e[0];for(n*=I;i>=10;i/=10)n++;return n}function Qt(e,n,i){if(n>rc)throw B=!0,i&&(e.precision=i),Error(sa);return S(new e(Jt),n,1,!0)}function nn(e,n,i){if(n>uo)throw Error(sa);return S(new e(Yt),n,i,!0)}function fa(e){var n=e.length-1,i=n*I+1;if(n=e[n],n){for(;n%10==0;n/=10)i--;for(n=e[0];n>=10;n/=10)i++}return i}function Cn(e){for(var n="";e--;)n+="0";return n}function ca(e,n,i,t){var r,o=new e(1),s=Math.ceil(t/I+4);for(B=!1;;){if(i%2&&(o=o.times(n),ta(o.d,s)&&(r=!0)),i=Te(i/2),i===0){i=o.d.length-1,r&&o.d[i]===0&&++o.d[i];break}n=n.times(n),ta(n.d,s)}return B=!0,o}function ia(e){return e.d[e.d.length-1]&1}function da(e,n,i){for(var t,r=new e(n[0]),o=0;++o<n.length;)if(t=new e(n[o]),t.s)r[i](t)&&(r=t);else{r=t;break}return r}function lo(e,n){var i,t,r,o,s,a,u,l=0,f=0,c=0,d=e.constructor,m=d.rounding,b=d.precision;if(!e.d||!e.d[0]||e.e>17)return new d(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:NaN);for(n==null?(B=!1,u=b):u=n,a=new d(.03125);e.e>-2;)e=e.times(a),c+=5;for(t=Math.log(pe(2,c))/Math.LN10*2+5|0,u+=t,i=o=s=new d(1),d.precision=u;;){if(o=S(o.times(e),u,1),i=i.times(++f),a=s.plus(U(o,i,u,1)),Ee(a.d).slice(0,u)===Ee(s.d).slice(0,u)){for(r=c;r--;)s=S(s.times(s),u,1);if(n==null)if(l<3&&ot(s.d,u-t,m,l))d.precision=u+=10,i=o=a=new d(1),f=0,l++;else return S(s,d.precision=b,m,B=!0);else return d.precision=b,s}s=a}}function Pn(e,n){var i,t,r,o,s,a,u,l,f,c,d,m=1,b=10,y=e,N=y.d,T=y.constructor,R=T.rounding,_=T.precision;if(y.s<0||!N||!N[0]||!y.e&&N[0]==1&&N.length==1)return new T(N&&!N[0]?-1/0:y.s!=1?NaN:N?0:y);if(n==null?(B=!1,f=_):f=n,T.precision=f+=b,i=Ee(N),t=i.charAt(0),Math.abs(o=y.e)<15e14){for(;t<7&&t!=1||t==1&&i.charAt(1)>3;)y=y.times(e),i=Ee(y.d),t=i.charAt(0),m++;o=y.e,t>1?(y=new T("0."+i),o++):y=new T(t+"."+i.slice(1))}else return l=Qt(T,f+2,_).times(o+""),y=Pn(new T(t+"."+i.slice(1)),f-b).plus(l),T.precision=_,n==null?S(y,_,R,B=!0):y;for(c=y,u=s=y=U(y.minus(1),y.plus(1),f,1),d=S(y.times(y),f,1),r=3;;){if(s=S(s.times(d),f,1),l=u.plus(U(s,new T(r),f,1)),Ee(l.d).slice(0,f)===Ee(u.d).slice(0,f))if(u=u.times(2),o!==0&&(u=u.plus(Qt(T,f+2,_).times(o+""))),u=U(u,new T(m),f,1),n==null)if(ot(u.d,f-b,R,a))T.precision=f+=b,l=s=y=U(c.minus(1),c.plus(1),f,1),d=S(y.times(y),f,1),r=a=1;else return S(u,T.precision=_,R,B=!0);else return T.precision=_,u;u=l,r+=2}}function pa(e){return String(e.s*e.s/0)}function fo(e,n){var i,t,r;for((i=n.indexOf("."))>-1&&(n=n.replace(".","")),(t=n.search(/e/i))>0?(i<0&&(i=t),i+=+n.slice(t+1),n=n.substring(0,t)):i<0&&(i=n.length),t=0;n.charCodeAt(t)===48;t++);for(r=n.length;n.charCodeAt(r-1)===48;--r);if(n=n.slice(t,r),n){if(r-=t,e.e=i=i-t-1,e.d=[],t=(i+1)%I,i<0&&(t+=I),t<r){for(t&&e.d.push(+n.slice(0,t)),r-=I;t<r;)e.d.push(+n.slice(t,t+=I));n=n.slice(t),t=I-n.length}else t-=r;for(;t--;)n+="0";e.d.push(+n),B&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function sc(e,n){var i,t,r,o,s,a,u,l,f;if(n.indexOf("_")>-1){if(n=n.replace(/(\d)_(?=\d)/g,"$1"),la.test(n))return fo(e,n)}else if(n==="Infinity"||n==="NaN")return+n||(e.s=NaN),e.e=NaN,e.d=null,e;if(nc.test(n))i=16,n=n.toLowerCase();else if(ec.test(n))i=2;else if(ic.test(n))i=8;else throw Error(On+n);for(o=n.search(/p/i),o>0?(u=+n.slice(o+1),n=n.substring(2,o)):n=n.slice(2),o=n.indexOf("."),s=o>=0,t=e.constructor,s&&(n=n.replace(".",""),a=n.length,o=a-o,r=ca(t,new t(i),o,o*2)),l=Wt(n,i,tn),f=l.length-1,o=f;l[o]===0;--o)l.pop();return o<0?new t(e.s*0):(e.e=Kt(l,f),e.d=l,B=!1,s&&(e=U(e,r,a*4)),u&&(e=e.times(Math.abs(u)<54?pe(2,u):Q.pow(2,u))),B=!0,e)}function ac(e,n){var i,t=n.d.length;if(t<3)return n.isZero()?n:bi(e,2,n,n);i=1.4*Math.sqrt(t),i=i>16?16:i|0,n=n.times(1/er(5,i)),n=bi(e,2,n,n);for(var r,o=new e(5),s=new e(16),a=new e(20);i--;)r=n.times(n),n=n.times(o.plus(r.times(s.times(r).minus(a))));return n}function bi(e,n,i,t,r){var o,s,a,u,l=1,f=e.precision,c=Math.ceil(f/I);for(B=!1,u=i.times(i),a=new e(t);;){if(s=U(a.times(u),new e(n++*n++),f,1),a=r?t.plus(s):t.minus(s),t=U(s.times(u),new e(n++*n++),f,1),s=a.plus(t),s.d[c]!==void 0){for(o=c;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=t,t=s,s=o,l++}return B=!0,s.d.length=c+1,s}function er(e,n){for(var i=e;--n;)i*=e;return i}function ma(e,n){var i,t=n.s<0,r=nn(e,e.precision,1),o=r.times(.5);if(n=n.abs(),n.lte(o))return vn=t?4:1,n;if(i=n.divToInt(r),i.isZero())vn=t?3:2;else{if(n=n.minus(i.times(r)),n.lte(o))return vn=ia(i)?t?2:3:t?4:1,n;vn=ia(i)?t?1:4:t?3:2}return n.minus(r).abs()}function co(e,n,i,t){var r,o,s,a,u,l,f,c,d,m=e.constructor,b=i!==void 0;if(b?(De(i,1,Ln),t===void 0?t=m.rounding:De(t,0,8)):(i=m.precision,t=m.rounding),!e.isFinite())f=pa(e);else{for(f=cn(e),s=f.indexOf("."),b?(r=2,n==16?i=i*4-3:n==8&&(i=i*3-2)):r=n,s>=0&&(f=f.replace(".",""),d=new m(1),d.e=f.length-s,d.d=Wt(cn(d),10,r),d.e=d.d.length),c=Wt(f,10,r),o=u=c.length;c[--u]==0;)c.pop();if(!c[0])f=b?"0p+0":"0";else{if(s<0?o--:(e=new m(e),e.d=c,e.e=o,e=U(e,d,i,t,0,r),c=e.d,o=e.e,l=oa),s=c[i],a=r/2,l=l||c[i+1]!==void 0,l=t<4?(s!==void 0||l)&&(t===0||t===(e.s<0?3:2)):s>a||s===a&&(t===4||l||t===6&&c[i-1]&1||t===(e.s<0?8:7)),c.length=i,l)for(;++c[--i]>r-1;)c[i]=0,i||(++o,c.unshift(1));for(u=c.length;!c[u-1];--u);for(s=0,f="";s<u;s++)f+=so.charAt(c[s]);if(b){if(u>1)if(n==16||n==8){for(s=n==16?4:3,--u;u%s;u++)f+="0";for(c=Wt(f,r,n),u=c.length;!c[u-1];--u);for(s=1,f="1.";s<u;s++)f+=so.charAt(c[s])}else f=f.charAt(0)+"."+f.slice(1);f=f+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)f="0"+f;f="0."+f}else if(++o>u)for(o-=u;o--;)f+="0";else o<u&&(f=f.slice(0,o)+"."+f.slice(o))}f=(n==16?"0x":n==2?"0b":n==8?"0o":"")+f}return e.s<0?"-"+f:f}function ta(e,n){if(e.length>n)return e.length=n,!0}function uc(e){return new this(e).abs()}function lc(e){return new this(e).acos()}function fc(e){return new this(e).acosh()}function cc(e,n){return new this(e).plus(n)}function dc(e){return new this(e).asin()}function pc(e){return new this(e).asinh()}function mc(e){return new this(e).atan()}function gc(e){return new this(e).atanh()}function hc(e,n){e=new this(e),n=new this(n);var i,t=this.precision,r=this.rounding,o=t+4;return!e.s||!n.s?i=new this(NaN):!e.d&&!n.d?(i=nn(this,o,1).times(n.s>0?.25:.75),i.s=e.s):!n.d||e.isZero()?(i=n.s<0?nn(this,t,r):new this(0),i.s=e.s):!e.d||n.isZero()?(i=nn(this,o,1).times(.5),i.s=e.s):n.s<0?(this.precision=o,this.rounding=1,i=this.atan(U(e,n,o,1)),n=nn(this,o,1),this.precision=t,this.rounding=r,i=e.s<0?i.minus(n):i.plus(n)):i=this.atan(U(e,n,o,1)),i}function xc(e){return new this(e).cbrt()}function yc(e){return S(e=new this(e),e.e+1,2)}function bc(e,n,i){return new this(e).clamp(n,i)}function Ec(e){if(!e||typeof e!="object")throw Error(Xt+"Object expected");var n,i,t,r=e.defaults===!0,o=["precision",1,Ln,"rounding",0,8,"toExpNeg",-yi,0,"toExpPos",0,yi,"maxE",0,yi,"minE",-yi,0,"modulo",0,9];for(n=0;n<o.length;n+=3)if(i=o[n],r&&(this[i]=ao[i]),(t=e[i])!==void 0)if(Te(t)===t&&t>=o[n+1]&&t<=o[n+2])this[i]=t;else throw Error(On+i+": "+t);if(i="crypto",r&&(this[i]=ao[i]),(t=e[i])!==void 0)if(t===!0||t===!1||t===0||t===1)if(t)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[i]=!0;else throw Error(aa);else this[i]=!1;else throw Error(On+i+": "+t);return this}function Nc(e){return new this(e).cos()}function vc(e){return new this(e).cosh()}function ga(e){var n,i,t;function r(o){var s,a,u,l=this;if(!(l instanceof r))return new r(o);if(l.constructor=r,ra(o)){l.s=o.s,B?!o.d||o.e>r.maxE?(l.e=NaN,l.d=null):o.e<r.minE?(l.e=0,l.d=[0]):(l.e=o.e,l.d=o.d.slice()):(l.e=o.e,l.d=o.d?o.d.slice():o.d);return}if(u=typeof o,u==="number"){if(o===0){l.s=1/o<0?-1:1,l.e=0,l.d=[0];return}if(o<0?(o=-o,l.s=-1):l.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;B?s>r.maxE?(l.e=NaN,l.d=null):s<r.minE?(l.e=0,l.d=[0]):(l.e=s,l.d=[o]):(l.e=s,l.d=[o]);return}else if(o*0!==0){o||(l.s=NaN),l.e=NaN,l.d=null;return}return fo(l,o.toString())}else if(u!=="string")throw Error(On+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),l.s=-1):(a===43&&(o=o.slice(1)),l.s=1),la.test(o)?fo(l,o):sc(l,o)}if(r.prototype=h,r.ROUND_UP=0,r.ROUND_DOWN=1,r.ROUND_CEIL=2,r.ROUND_FLOOR=3,r.ROUND_HALF_UP=4,r.ROUND_HALF_DOWN=5,r.ROUND_HALF_EVEN=6,r.ROUND_HALF_CEIL=7,r.ROUND_HALF_FLOOR=8,r.EUCLID=9,r.config=r.set=Ec,r.clone=ga,r.isDecimal=ra,r.abs=uc,r.acos=lc,r.acosh=fc,r.add=cc,r.asin=dc,r.asinh=pc,r.atan=mc,r.atanh=gc,r.atan2=hc,r.cbrt=xc,r.ceil=yc,r.clamp=bc,r.cos=Nc,r.cosh=vc,r.div=Sc,r.exp=Tc,r.floor=_c,r.hypot=Ic,r.ln=Bc,r.log=kc,r.log10=Dc,r.log2=wc,r.max=Rc,r.min=Ac,r.mod=Mc,r.mul=Cc,r.pow=Pc,r.random=Oc,r.round=Lc,r.sign=Fc,r.sin=qc,r.sinh=Vc,r.sqrt=$c,r.sub=Gc,r.sum=zc,r.tan=Uc,r.tanh=jc,r.trunc=Zc,e===void 0&&(e={}),e&&e.defaults!==!0)for(t=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;n<t.length;)e.hasOwnProperty(i=t[n++])||(e[i]=this[i]);return r.config(e),r}function Sc(e,n){return new this(e).div(n)}function Tc(e){return new this(e).exp()}function _c(e){return S(e=new this(e),e.e+1,3)}function Ic(){var e,n,i=new this(0);for(B=!1,e=0;e<arguments.length;)if(n=new this(arguments[e++]),n.d)i.d&&(i=i.plus(n.times(n)));else{if(n.s)return B=!0,new this(1/0);i=n}return B=!0,i.sqrt()}function ra(e){return e instanceof Q||e&&e.toStringTag===ua||!1}function Bc(e){return new this(e).ln()}function kc(e,n){return new this(e).log(n)}function wc(e){return new this(e).log(2)}function Dc(e){return new this(e).log(10)}function Rc(){return da(this,arguments,"lt")}function Ac(){return da(this,arguments,"gt")}function Mc(e,n){return new this(e).mod(n)}function Cc(e,n){return new this(e).mul(n)}function Pc(e,n){return new this(e).pow(n)}function Oc(e){var n,i,t,r,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:De(e,1,Ln),t=Math.ceil(e/I),this.crypto)if(crypto.getRandomValues)for(n=crypto.getRandomValues(new Uint32Array(t));o<t;)r=n[o],r>=429e7?n[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=r%1e7;else if(crypto.randomBytes){for(n=crypto.randomBytes(t*=4);o<t;)r=n[o]+(n[o+1]<<8)+(n[o+2]<<16)+((n[o+3]&127)<<24),r>=214e7?crypto.randomBytes(4).copy(n,o):(a.push(r%1e7),o+=4);o=t/4}else throw Error(aa);else for(;o<t;)a[o++]=Math.random()*1e7|0;for(t=a[--o],e%=I,t&&e&&(r=pe(10,I-e),a[o]=(t/r|0)*r);a[o]===0;o--)a.pop();if(o<0)i=0,a=[0];else{for(i=-1;a[0]===0;i-=I)a.shift();for(t=1,r=a[0];r>=10;r/=10)t++;t<I&&(i-=I-t)}return s.e=i,s.d=a,s}function Lc(e){return S(e=new this(e),e.e+1,this.rounding)}function Fc(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function qc(e){return new this(e).sin()}function Vc(e){return new this(e).sinh()}function $c(e){return new this(e).sqrt()}function Gc(e,n){return new this(e).sub(n)}function zc(){var e=0,n=arguments,i=new this(n[e]);for(B=!1;i.s&&++e<n.length;)i=i.plus(n[e]);return B=!0,S(i,this.precision,this.rounding)}function Uc(e){return new this(e).tan()}function jc(e){return new this(e).tanh()}function Zc(e){return S(e=new this(e),e.e+1,1)}h[Symbol.for("nodejs.util.inspect.custom")]=h.toString;h[Symbol.toStringTag]="Decimal";var Q=h.constructor=ga(ao);Jt=new Q(Jt);Yt=new Q(Yt);var me=Q;var nr=["number","finite_number","complex","finite_complex","imaginary","finite_imaginary","real","finite_real","rational","finite_rational","integer","finite_integer","non_finite_number"],ir=["collection","list","set","tuple","map"],tr=["scalar",...nr,"boolean","string"],po=["value",...ir,...tr],mo=["expression","symbol","function",...po],Fn=["any","unknown","nothing","never","error",...mo];var ha=3,xa=1,ya=2,Hc=4,Wc=5,Jc=6,Yc=7,Qc=8,Xc=9;function Ie(e,n=0){if(typeof e=="string")return e;let i="";switch(e.kind){case"value":i=e.value.toString();break;case"reference":i=e.ref;break;case"negation":i=`!${Ie(e.type,ha)}`;break;case"union":i=e.types.map(u=>Ie(u,xa)).join(" | ");break;case"intersection":i=e.types.map(u=>Ie(u,ya)).join(" & ");break;case"list":if(e.dimensions&&g(e.elements,"number")){if(e.dimensions===void 0)e.elements==="number"&&(i="tensor");else if(e.dimensions.length===1)e.elements==="number"?e.dimensions[0]<0?i="vector":i=`vector<${e.dimensions[0]}>`:e.dimensions[0]<0?i=`vector<${e.elements}>`:i=`vector<${e.elements}^${e.dimensions[0]}>`;else if(e.dimensions.length===2){let u=e.dimensions;e.elements==="number"?u[0]<0&&u[1]<0?i="matrix":i=`matrix<${u[0]}x${u[1]}>`:u[0]<0&&u[1]<0?i=`matrix<${e.elements}>`:i=`matrix<${e.elements}^(${u[0]}x${u[1]})>`}}if(!i){let u=e.dimensions?e.dimensions.length===1?`^${e.dimensions[0].toString()}`:`^(${e.dimensions.join("x")})`:"";i=`list<${Ie(e.elements)}${u}>`}break;case"map":i=`map<${Object.entries(e.elements).map(([u,l])=>`${u}: ${Ie(l)}`).join(", ")}>`;break;case"set":i=`set<${Ie(e.elements)}>`;break;case"collection":i=`collection<${Ie(e.elements)}>`;break;case"tuple":if(e.elements.length===0)i="tuple";else if(e.elements.length===1){let[u]=e.elements;i=`tuple<${st(u)}>`}else i="tuple<"+e.elements.map(u=>st(u)).join(", ")+">";break;case"signature":let r=e.args?e.args.map(u=>st(u)).join(", "):"",o=e.optArgs?e.optArgs.map(u=>st(u)+"?").join(", "):"",s=e.restArg?`...${st(e.restArg)}`:"";i=`(${[r,o,s].filter(u=>u).join(", ")}) -> ${Ie(e.result)}`;break;default:i="error"}return n>0&&n>Kc(e.kind)?`(${i})`:i}function st(e){return e.name?`${e.name}: ${Ie(e.type)}`:Ie(e.type)}function Kc(e){switch(e){case"negation":return ha;case"union":return xa;case"intersection":return ya;case"list":return Hc;case"map":return Wc;case"set":return Jc;case"collection":return Yc;case"tuple":return Qc;case"signature":return Xc;default:return 0}}function ed(e,n){return e===n?e:e==="nothing"||n==="nothing"?"nothing":e==="any"?n:n==="any"?e:e==="never"?n:n==="never"?e:e==="unknown"?n:n==="unknown"||g(e,n)?e:g(n,e)?n:Ea(e,n)}function nd(e,n){return e===n?e:e==="any"||n==="any"?"any":e==="never"?n:n==="never"?e:e==="unknown"?n:n==="unknown"?e:e==="nothing"?n:n==="nothing"?e:g(e,n)?n:g(n,e)?e:Ea(e,n)}function rr(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce(ed)}function Ce(...e){return e.length===0?"nothing":e.length===1?e[0]:e.reduce(nd)}function at(e){return e=typeof e=="string"?k(e):e,typeof e!="string"&&e.kind==="signature"}function ba(e){if(e==="function")return k("...any -> any");if(typeof e!="string"&&e.kind==="signature")return e}function Ei(e){if(e==="function")return"any";if(typeof e!="string"&&e.kind==="signature")return e.result}function Jn(e){if(e==="collection")return"any";if(typeof e!="string"){if(e.kind==="collection"||e.kind==="list")return e.elements;if(e.kind==="map")return k(`tuple<string, ${Ce(...Object.values(e.elements))}>`);if(e.kind==="set")return e.elements;if(e.kind==="tuple")return Ce(...e.elements.map(n=>n.type))}}function Sn(e){return typeof e=="string"?Fn.includes(e):typeof e!="object"||!("kind"in e)?!1:e.kind==="signature"||e.kind==="union"||e.kind==="intersection"||e.kind==="negation"||e.kind==="tuple"||e.kind==="list"||e.kind==="map"||e.kind==="set"||e.kind==="function"||e.kind==="collection"||e.kind==="reference"}function Ea(e,n){return e===n?e:e==="any"||n==="any"?"any":e==="never"?n:n==="never"?e:e==="unknown"?n:n==="unknown"?e:e==="nothing"?n:n==="nothing"?e:oe(e,n,"non_finite_number")?"non_finite_number":oe(e,n,"finite_integer")?"finite_integer":oe(e,n,"integer")?"integer":oe(e,n,"finite_rational")?"finite_rational":oe(e,n,"rational")?"rational":oe(e,n,"finite_real")?"finite_real":oe(e,n,"real")?"real":oe(e,n,"finite_imaginary")?"finite_imaginary":oe(e,n,"imaginary")?"imaginary":oe(e,n,"finite_complex")?"finite_complex":oe(e,n,"complex")?"complex":oe(e,n,"finite_number")?"finite_number":oe(e,n,"number")?"number":oe(e,n,"list")?"list":oe(e,n,"map")?"map":oe(e,n,"set")?"set":oe(e,n,"tuple")?"tuple":oe(e,n,"collection")?"collection":oe(e,n,"scalar")?"scalar":oe(e,n,"value")?"value":oe(e,n,"function")?"function":oe(e,n,"expression")?"expression":"any"}function oe(e,n,i){return!!(g(e,i)&&g(n,i))}var go=class extends String{constructor(n){super(n)}isSubtypeOf(n){return g(this.toString(),n)}};function ye(e){return typeof e=="string"?Object.freeze(new go(e)):(Object.defineProperty(e,"toString",{value:()=>Ie(e)}),Object.defineProperty(e,"isSubtypeOf",{value:n=>g(e,n)}),Object.freeze(e))}function id(e,n){let i=[];for(let t=0;t<=n.length;t++)i[t]=[t];for(let t=0;t<=e.length;t++)i[0][t]=t;for(let t=1;t<=n.length;t++)for(let r=1;r<=e.length;r++)n.charAt(t-1)===e.charAt(r-1)?i[t][r]=i[t-1][r-1]:i[t][r]=Math.min(i[t-1][r-1]+1,i[t][r-1]+1,i[t-1][r]+1);return i[n.length][e.length]}function Na(e,n){let i=null,t=1/0,r=3;for(let o of n){let s=id(e,o);s<=r&&Math.abs(e.length-o.length)<=2&&s<t&&(t=s,i=o)}return i}var ho=class{constructor(n,i={value:()=>null,type:()=>null}){this.buffer=n,this.pos=0,this._valueParser=i.value,this._typeParser=i.type}error(...n){throw new Error(`
Invalid type
| ${this.buffer}
| ${" ".repeat(this.pos)}^
|
| ${n.join(`
| `)}
`)}peek(){return this.buffer[this.pos]}consume(){return this.buffer[this.pos++]}match(n){if(n.length===1&&this.buffer[this.pos]===n)return this.pos++,!0;let i=this.pos;return this.buffer.slice(i,i+n.length)===n?(this.pos+=n.length,!0):!1}skipWhitespace(){for(;this.pos<this.buffer.length&&/\s/.test(this.buffer[this.pos]);)this.pos++}isEOF(){return this.pos>=this.buffer.length}parseValue(){this.skipWhitespace();let n=this._valueParser(this);return n===null?null:ye({kind:"value",value:n})}parseTypeReference(){this.skipWhitespace();let n=this._typeParser(this);return n===null?null:ye({kind:"reference",ref:n})}parsePrimitiveType(){this.skipWhitespace(),this.isEOF()&&this.error("Unexpected end of input");for(let n of Fn)if(this.match(n))return n;return null}parseArguments(){let n=[],i=[];for(;;){let s=this.parseNamedElement();if(s===null||(this.match("?")?i.push(s):(i.length>0&&this.error("Optional arguments must come after required arguments"),n.push(s)),this.skipWhitespace(),!this.match(",")))break}let t=this.pos,r=this.parseRestArgument()??void 0;r&&i.length>0&&(this.pos=t,this.error("Optional arguments cannot be followed by a rest argument"));let o=va([...n,...i,...r?[r]:[]]);return o&&this.error(`Duplicate argument name "${o}"`),[n,i,r]}parseRestArgument(){let n=this.pos,i=this.parseName();if(this.skipWhitespace(),!this.match("..."))return this.pos=n,null;let t=this.parsePrimitiveType()??this.parsePrimaryGroup();if(!t&&!i&&(this.pos=n,this.match("...")&&this.parseName())){let r=this.parsePrimitiveType()??this.parsePrimaryGroup();this.pos=n,this.error("The rest argument indicator is placed before the type, not the name",`Use "${i}: ...${r?Ie(r):"number"}"`)}return this.skipWhitespace(),this.match(":")&&this.error('Unexpected ":" after rest argument. Use "x: ...number"'),t??(t="any"),i?{name:i,type:t}:{type:t}}parseFunctionSignature(){let n=[],i=[],t;this.skipWhitespace();let r=this.pos;if(!this.match("()")){if(this.match("(")){if([n,i,t]=this.parseArguments(),this.skipWhitespace(),!this.match(")"))return t&&(this.parseNamedElement()&&(this.pos=r,this.error("The rest argument must be the last argument")),this.error("The rest argument must have a valid type")),i.length>0&&(this.parseNamedElement()&&this.error("Optional arguments cannot be followed by required arguments"),this.skipWhitespace(),r=this.pos,this.match("->")&&(this.pos=r,this.error('Expected ")" to close the argument list')),this.error("Expected an argument")),this.pos=r,null}else if(t=this.parseRestArgument()??void 0,t?.name&&(this.pos=r,this.error("Named arguments must be enclosed in parentheses")),!t)return this.pos=r,null}if(this.skipWhitespace(),!this.match("->"))