mathjslab
Version:
MathJSLab - An interpreter with language syntax like MATLAB®/Octave, ISBN 978-65-00-82338-7.
2 lines • 394 kB
JavaScript
/*! For license information please see mathjslab.web.umd2022.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("mathjslab",[],e):"object"==typeof exports?exports.mathjslab=e():t.mathjslab=e()}(globalThis,()=>(()=>{var __webpack_modules__={109:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.nodeElse=e.nodeElseIf=e.nodeIfAppendElseIf=e.nodeIfAppendElse=e.nodeIfBegin=e.nodeAppendDeclaration=e.nodeDeclarationFirst=e.nodeArguments=e.nodeArgumentValidation=e.nodeFunction=e.nodeFunctionHandle=e.nodeReturnList=e.nodeIndirectRef=e.nodeAppendRow=e.nodeFirstRow=e.nodeList=e.appendNodeList=e.nodeListFirst=e.nodeOp=e.nodeRange=e.nodeIndexExpr=e.nodeCmdWList=e.nodeIdentifier=e.nodeLiteral=e.emptyArray=e.appendRow=e.firstRow=e.nodeNumber=e.nodeString=void 0;const i=r(956),n=r(826),s=r(271),a=r(679),o=i.CharString.create;e.nodeString=o;const l=n.ComplexDecimal.parse;e.nodeNumber=l;const c=a.MultiArray.firstRow;e.firstRow=c;const h=a.MultiArray.appendRow;e.appendRow=h;const u=a.MultiArray.emptyArray;e.emptyArray=u,e.nodeLiteral=t=>({type:t}),e.nodeIdentifier=t=>({type:"IDENT",id:t.replace(/(\r\n|[\n\r])|[\ ]/gm,"")}),e.nodeCmdWList=(t,e)=>({type:"CMDWLIST",id:t.id,args:e?e.list:[],omitAns:!0}),e.nodeIndexExpr=(t,e=null,r="()")=>({type:"IDX",expr:t,args:e?e.list:[],delim:r}),e.nodeRange=(t,e,r)=>({type:"RANGE",start_:t,stop_:e,stride_:r??null}),e.nodeOp=(t,e,r)=>{switch(t){case"+":case"-":case".*":case"*":case"./":case"/":case".\\":case"\\":case".^":case"^":case".**":case"**":case"<":case"<=":case"==":case">=":case">":case"!=":case"~=":case"&":case"|":case"&&":case"||":return{type:t,left:e,right:r};case"=":case"+=":case"-=":case"*=":case"/=":case"\\=":case"^=":case"**=":case".*=":case"./=":case".\\=":case".^=":case".**=":case"&=":case"|=":return{type:t,left:e,right:r,omitAns:!0};case"()":case"!":case"~":case"+_":case"-_":return{type:t,right:e};case"++_":case"--_":return{type:t,right:e,omitAns:!0};case".'":case"'":return{type:t,left:e};case"_++":case"_--":return{type:t,left:e,omitAns:!0};default:return{type:`INVALID:${t}`}}},e.nodeListFirst=t=>{if(t){const e={type:"LIST",list:[t]};return t.parent=e,e}return{type:"LIST",list:[]}},e.appendNodeList=(t,e)=>(e.parent=t,t.list.push(e),t),e.nodeList=t=>({type:"LIST",list:t}),e.nodeFirstRow=(t=null,e)=>t?c(t.list,e):u(e),e.nodeAppendRow=(t,e=null)=>e?h(t,e.list):t,e.nodeIndirectRef=(t,e)=>"."===t.type?(t.field.push(e),t):{type:".",obj:t,field:[e]},e.nodeReturnList=t=>({type:"RETLIST",selector:t}),e.nodeFunctionHandle=(t=null,e=null,r=null)=>new s.FunctionHandle(t?t.id:null,!0,e?e.list:[],r),e.nodeFunction=(t,e,r,i,n)=>({type:"FCN",id:t.id,return:e.list,parameter:r.list,arguments:i.list,statements:n.list}),e.nodeArgumentValidation=(t,e,r=null,i,n=null)=>({name:t,size:e.list,class:r,functions:i.list,default:n}),e.nodeArguments=(t,e)=>({attribute:t,validation:e.list}),e.nodeDeclarationFirst=t=>({type:t,list:[]}),e.nodeAppendDeclaration=(t,e)=>(t.list.push(e),t),e.nodeIfBegin=(t,e)=>({type:"IF",expression:[t],then:[e],else:null,omitAns:!0}),e.nodeIfAppendElse=(t,e)=>(t.else=e.else,t),e.nodeIfAppendElseIf=(t,e)=>(t.expression.push(e.expression),t.then.push(e.then),t),e.nodeElseIf=(t,e)=>({expression:t,then:e}),e.nodeElse=t=>({else:t})},110:function(t,e,r){var i;!function(){"use strict";var n,s,a,o=9e15,l=1e9,c="0123456789abcdef",h="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",u="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",d={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-o,maxE:o,crypto:!1},p=!0,m="[DecimalError] ",f=m+"Invalid argument: ",_=m+"Precision limit exceeded",g=m+"crypto unavailable",E="[object Decimal]",x=Math.floor,T=Math.pow,L=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,y=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,C=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,A=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,N=1e7,R=h.length-1,S=u.length-1,M={toStringTag:E};function I(t){var e,r,i,n=t.length-1,s="",a=t[0];if(n>0){for(s+=a,e=1;e<n;e++)(r=7-(i=t[e]+"").length)&&(s+=B(r)),s+=i;(r=7-(i=(a=t[e])+"").length)&&(s+=B(r))}else if(0===a)return"0";for(;a%10==0;)a/=10;return s+a}function w(t,e,r){if(t!==~~t||t<e||t>r)throw Error(f+t)}function D(t,e,r,i){var n,s,a,o;for(s=t[0];s>=10;s/=10)--e;return--e<0?(e+=7,n=0):(n=Math.ceil((e+1)/7),e%=7),s=T(10,7-e),o=t[n]%s|0,null==i?e<3?(0==e?o=o/100|0:1==e&&(o=o/10|0),a=r<4&&99999==o||r>3&&49999==o||5e4==o||0==o):a=(r<4&&o+1==s||r>3&&o+1==s/2)&&(t[n+1]/s/100|0)==T(10,e-2)-1||(o==s/2||0==o)&&!(t[n+1]/s/100|0):e<4?(0==e?o=o/1e3|0:1==e?o=o/100|0:2==e&&(o=o/10|0),a=(i||r<4)&&9999==o||!i&&r>3&&4999==o):a=((i||r<4)&&o+1==s||!i&&r>3&&o+1==s/2)&&(t[n+1]/s/1e3|0)==T(10,e-3)-1,a}function O(t,e,r){for(var i,n,s=[0],a=0,o=t.length;a<o;){for(n=s.length;n--;)s[n]*=e;for(s[0]+=c.indexOf(t.charAt(a++)),i=0;i<s.length;i++)s[i]>r-1&&(void 0===s[i+1]&&(s[i+1]=0),s[i+1]+=s[i]/r|0,s[i]%=r)}return s.reverse()}M.absoluteValue=M.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),v(t)},M.ceil=function(){return v(new this.constructor(this),this.e+1,2)},M.clampedTo=M.clamp=function(t,e){var r=this,i=r.constructor;if(t=new i(t),e=new i(e),!t.s||!e.s)return new i(NaN);if(t.gt(e))throw Error(f+e);return r.cmp(t)<0?t:r.cmp(e)>0?e:new i(r)},M.comparedTo=M.cmp=function(t){var e,r,i,n,s=this,a=s.d,o=(t=new s.constructor(t)).d,l=s.s,c=t.s;if(!a||!o)return l&&c?l!==c?l:a===o?0:!a^l<0?1:-1:NaN;if(!a[0]||!o[0])return a[0]?l:o[0]?-c:0;if(l!==c)return l;if(s.e!==t.e)return s.e>t.e^l<0?1:-1;for(e=0,r=(i=a.length)<(n=o.length)?i:n;e<r;++e)if(a[e]!==o[e])return a[e]>o[e]^l<0?1:-1;return i===n?0:i>n^l<0?1:-1},M.cosine=M.cos=function(){var t,e,r=this,i=r.constructor;return r.d?r.d[0]?(t=i.precision,e=i.rounding,i.precision=t+Math.max(r.e,r.sd())+7,i.rounding=1,r=function(t,e){var r,i,n;if(e.isZero())return e;(i=e.d.length)<32?n=(1/$(4,r=Math.ceil(i/3))).toString():(r=16,n="2.3283064365386962890625e-10"),t.precision+=r,e=J(t,1,e.times(n),new t(1));for(var s=r;s--;){var a=e.times(e);e=a.times(a).minus(a).times(8).plus(1)}return t.precision-=r,e}(i,K(i,r)),i.precision=t,i.rounding=e,v(2==a||3==a?r.neg():r,t,e,!0)):new i(1):new i(NaN)},M.cubeRoot=M.cbrt=function(){var t,e,r,i,n,s,a,o,l,c,h=this,u=h.constructor;if(!h.isFinite()||h.isZero())return new u(h);for(p=!1,(s=h.s*T(h.s*h,1/3))&&Math.abs(s)!=1/0?i=new u(s.toString()):(r=I(h.d),(s=((t=h.e)-r.length+1)%3)&&(r+=1==s||-2==s?"0":"00"),s=T(r,1/3),t=x((t+1)/3)-(t%3==(t<0?-1:2)),(i=new u(r=s==1/0?"5e"+t:(r=s.toExponential()).slice(0,r.indexOf("e")+1)+t)).s=h.s),a=(t=u.precision)+3;;)if(c=(l=(o=i).times(o).times(o)).plus(h),i=b(c.plus(h).times(o),c.plus(l),a+2,1),I(o.d).slice(0,a)===(r=I(i.d)).slice(0,a)){if("9999"!=(r=r.slice(a-3,a+1))&&(n||"4999"!=r)){+r&&(+r.slice(1)||"5"!=r.charAt(0))||(v(i,t+1,1),e=!i.times(i).times(i).eq(h));break}if(!n&&(v(o,t+1,0),o.times(o).times(o).eq(h))){i=o;break}a+=4,n=1}return p=!0,v(i,t,u.rounding,e)},M.decimalPlaces=M.dp=function(){var t,e=this.d,r=NaN;if(e){if(r=7*((t=e.length-1)-x(this.e/7)),t=e[t])for(;t%10==0;t/=10)r--;r<0&&(r=0)}return r},M.dividedBy=M.div=function(t){return b(this,new this.constructor(t))},M.dividedToIntegerBy=M.divToInt=function(t){var e=this.constructor;return v(b(this,new e(t),0,1,1),e.precision,e.rounding)},M.equals=M.eq=function(t){return 0===this.cmp(t)},M.floor=function(){return v(new this.constructor(this),this.e+1,3)},M.greaterThan=M.gt=function(t){return this.cmp(t)>0},M.greaterThanOrEqualTo=M.gte=function(t){var e=this.cmp(t);return 1==e||0===e},M.hyperbolicCosine=M.cosh=function(){var t,e,r,i,n,s=this,a=s.constructor,o=new a(1);if(!s.isFinite())return new a(s.s?1/0:NaN);if(s.isZero())return o;r=a.precision,i=a.rounding,a.precision=r+Math.max(s.e,s.sd())+4,a.rounding=1,(n=s.d.length)<32?e=(1/$(4,t=Math.ceil(n/3))).toString():(t=16,e="2.3283064365386962890625e-10"),s=J(a,1,s.times(e),new a(1),!0);for(var l,c=t,h=new a(8);c--;)l=s.times(s),s=o.minus(l.times(h.minus(l.times(h))));return v(s,a.precision=r,a.rounding=i,!0)},M.hyperbolicSine=M.sinh=function(){var t,e,r,i,n=this,s=n.constructor;if(!n.isFinite()||n.isZero())return new s(n);if(e=s.precision,r=s.rounding,s.precision=e+Math.max(n.e,n.sd())+4,s.rounding=1,(i=n.d.length)<3)n=J(s,2,n,n,!0);else{t=(t=1.4*Math.sqrt(i))>16?16:0|t,n=J(s,2,n=n.times(1/$(5,t)),n,!0);for(var a,o=new s(5),l=new s(16),c=new s(20);t--;)a=n.times(n),n=n.times(o.plus(a.times(l.times(a).plus(c))))}return s.precision=e,s.rounding=r,v(n,e,r,!0)},M.hyperbolicTangent=M.tanh=function(){var t,e,r=this,i=r.constructor;return r.isFinite()?r.isZero()?new i(r):(t=i.precision,e=i.rounding,i.precision=t+7,i.rounding=1,b(r.sinh(),r.cosh(),i.precision=t,i.rounding=e)):new i(r.s)},M.inverseCosine=M.acos=function(){var t=this,e=t.constructor,r=t.abs().cmp(1),i=e.precision,n=e.rounding;return-1!==r?0===r?t.isNeg()?F(e,i,n):new e(0):new e(NaN):t.isZero()?F(e,i+4,n).times(.5):(e.precision=i+6,e.rounding=1,t=new e(1).minus(t).div(t.plus(1)).sqrt().atan(),e.precision=i,e.rounding=n,t.times(2))},M.inverseHyperbolicCosine=M.acosh=function(){var t,e,r=this,i=r.constructor;return r.lte(1)?new i(r.eq(1)?0:NaN):r.isFinite()?(t=i.precision,e=i.rounding,i.precision=t+Math.max(Math.abs(r.e),r.sd())+4,i.rounding=1,p=!1,r=r.times(r).minus(1).sqrt().plus(r),p=!0,i.precision=t,i.rounding=e,r.ln()):new i(r)},M.inverseHyperbolicSine=M.asinh=function(){var t,e,r=this,i=r.constructor;return!r.isFinite()||r.isZero()?new i(r):(t=i.precision,e=i.rounding,i.precision=t+2*Math.max(Math.abs(r.e),r.sd())+6,i.rounding=1,p=!1,r=r.times(r).plus(1).sqrt().plus(r),p=!0,i.precision=t,i.rounding=e,r.ln())},M.inverseHyperbolicTangent=M.atanh=function(){var t,e,r,i,n=this,s=n.constructor;return n.isFinite()?n.e>=0?new s(n.abs().eq(1)?n.s/0:n.isZero()?n:NaN):(t=s.precision,e=s.rounding,i=n.sd(),Math.max(i,t)<2*-n.e-1?v(new s(n),t,e,!0):(s.precision=r=i-n.e,n=b(n.plus(1),new s(1).minus(n),r+t,1),s.precision=t+4,s.rounding=1,n=n.ln(),s.precision=t,s.rounding=e,n.times(.5))):new s(NaN)},M.inverseSine=M.asin=function(){var t,e,r,i,n=this,s=n.constructor;return n.isZero()?new s(n):(e=n.abs().cmp(1),r=s.precision,i=s.rounding,-1!==e?0===e?((t=F(s,r+4,i).times(.5)).s=n.s,t):new s(NaN):(s.precision=r+6,s.rounding=1,n=n.div(new s(1).minus(n.times(n)).sqrt().plus(1)).atan(),s.precision=r,s.rounding=i,n.times(2)))},M.inverseTangent=M.atan=function(){var t,e,r,i,n,s,a,o,l,c=this,h=c.constructor,u=h.precision,d=h.rounding;if(c.isFinite()){if(c.isZero())return new h(c);if(c.abs().eq(1)&&u+4<=S)return(a=F(h,u+4,d).times(.25)).s=c.s,a}else{if(!c.s)return new h(NaN);if(u+4<=S)return(a=F(h,u+4,d).times(.5)).s=c.s,a}for(h.precision=o=u+10,h.rounding=1,t=r=Math.min(28,o/7+2|0);t;--t)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(p=!1,e=Math.ceil(o/7),i=1,l=c.times(c),a=new h(c),n=c;-1!==t;)if(n=n.times(l),s=a.minus(n.div(i+=2)),n=n.times(l),void 0!==(a=s.plus(n.div(i+=2))).d[e])for(t=e;a.d[t]===s.d[t]&&t--;);return r&&(a=a.times(2<<r-1)),p=!0,v(a,h.precision=u,h.rounding=d,!0)},M.isFinite=function(){return!!this.d},M.isInteger=M.isInt=function(){return!!this.d&&x(this.e/7)>this.d.length-2},M.isNaN=function(){return!this.s},M.isNegative=M.isNeg=function(){return this.s<0},M.isPositive=M.isPos=function(){return this.s>0},M.isZero=function(){return!!this.d&&0===this.d[0]},M.lessThan=M.lt=function(t){return this.cmp(t)<0},M.lessThanOrEqualTo=M.lte=function(t){return this.cmp(t)<1},M.logarithm=M.log=function(t){var e,r,i,n,s,a,o,l,c=this,h=c.constructor,u=h.precision,d=h.rounding;if(null==t)t=new h(10),e=!0;else{if(r=(t=new h(t)).d,t.s<0||!r||!r[0]||t.eq(1))return new h(NaN);e=t.eq(10)}if(r=c.d,c.s<0||!r||!r[0]||c.eq(1))return new h(r&&!r[0]?-1/0:1!=c.s?NaN:r?0:1/0);if(e)if(r.length>1)s=!0;else{for(n=r[0];n%10==0;)n/=10;s=1!==n}if(p=!1,a=W(c,o=u+5),i=e?U(h,o+10):W(t,o),D((l=b(a,i,o,1)).d,n=u,d))do{if(a=W(c,o+=10),i=e?U(h,o+10):W(t,o),l=b(a,i,o,1),!s){+I(l.d).slice(n+1,n+15)+1==1e14&&(l=v(l,u+1,0));break}}while(D(l.d,n+=10,d));return p=!0,v(l,u,d)},M.minus=M.sub=function(t){var e,r,i,n,s,a,o,l,c,h,u,d,m=this,f=m.constructor;if(t=new f(t),!m.d||!t.d)return m.s&&t.s?m.d?t.s=-t.s:t=new f(t.d||m.s!==t.s?m:NaN):t=new f(NaN),t;if(m.s!=t.s)return t.s=-t.s,m.plus(t);if(c=m.d,d=t.d,o=f.precision,l=f.rounding,!c[0]||!d[0]){if(d[0])t.s=-t.s;else{if(!c[0])return new f(3===l?-0:0);t=new f(m)}return p?v(t,o,l):t}if(r=x(t.e/7),h=x(m.e/7),c=c.slice(),s=h-r){for((u=s<0)?(e=c,s=-s,a=d.length):(e=d,r=h,a=c.length),s>(i=Math.max(Math.ceil(o/7),a)+2)&&(s=i,e.length=1),e.reverse(),i=s;i--;)e.push(0);e.reverse()}else{for((u=(i=c.length)<(a=d.length))&&(a=i),i=0;i<a;i++)if(c[i]!=d[i]){u=c[i]<d[i];break}s=0}for(u&&(e=c,c=d,d=e,t.s=-t.s),a=c.length,i=d.length-a;i>0;--i)c[a++]=0;for(i=d.length;i>s;){if(c[--i]<d[i]){for(n=i;n&&0===c[--n];)c[n]=N-1;--c[n],c[i]+=N}c[i]-=d[i]}for(;0===c[--a];)c.pop();for(;0===c[0];c.shift())--r;return c[0]?(t.d=c,t.e=k(c,r),p?v(t,o,l):t):new f(3===l?-0:0)},M.modulo=M.mod=function(t){var e,r=this,i=r.constructor;return t=new i(t),!r.d||!t.s||t.d&&!t.d[0]?new i(NaN):!t.d||r.d&&!r.d[0]?v(new i(r),i.precision,i.rounding):(p=!1,9==i.modulo?(e=b(r,t.abs(),0,3,1)).s*=t.s:e=b(r,t,0,i.modulo,1),e=e.times(t),p=!0,r.minus(e))},M.naturalExponential=M.exp=function(){return q(this)},M.naturalLogarithm=M.ln=function(){return W(this)},M.negated=M.neg=function(){var t=new this.constructor(this);return t.s=-t.s,v(t)},M.plus=M.add=function(t){var e,r,i,n,s,a,o,l,c,h,u=this,d=u.constructor;if(t=new d(t),!u.d||!t.d)return u.s&&t.s?u.d||(t=new d(t.d||u.s===t.s?u:NaN)):t=new d(NaN),t;if(u.s!=t.s)return t.s=-t.s,u.minus(t);if(c=u.d,h=t.d,o=d.precision,l=d.rounding,!c[0]||!h[0])return h[0]||(t=new d(u)),p?v(t,o,l):t;if(s=x(u.e/7),i=x(t.e/7),c=c.slice(),n=s-i){for(n<0?(r=c,n=-n,a=h.length):(r=h,i=s,a=c.length),n>(a=(s=Math.ceil(o/7))>a?s+1:a+1)&&(n=a,r.length=1),r.reverse();n--;)r.push(0);r.reverse()}for((a=c.length)-(n=h.length)<0&&(n=a,r=h,h=c,c=r),e=0;n;)e=(c[--n]=c[n]+h[n]+e)/N|0,c[n]%=N;for(e&&(c.unshift(e),++i),a=c.length;0==c[--a];)c.pop();return t.d=c,t.e=k(c,i),p?v(t,o,l):t},M.precision=M.sd=function(t){var e,r=this;if(void 0!==t&&t!==!!t&&1!==t&&0!==t)throw Error(f+t);return r.d?(e=H(r.d),t&&r.e+1>e&&(e=r.e+1)):e=NaN,e},M.round=function(){var t=this,e=t.constructor;return v(new e(t),t.e+1,e.rounding)},M.sine=M.sin=function(){var t,e,r=this,i=r.constructor;return r.isFinite()?r.isZero()?new i(r):(t=i.precision,e=i.rounding,i.precision=t+Math.max(r.e,r.sd())+7,i.rounding=1,r=function(t,e){var r,i=e.d.length;if(i<3)return e.isZero()?e:J(t,2,e,e);r=(r=1.4*Math.sqrt(i))>16?16:0|r,e=J(t,2,e=e.times(1/$(5,r)),e);for(var n,s=new t(5),a=new t(16),o=new t(20);r--;)n=e.times(e),e=e.times(s.plus(n.times(a.times(n).minus(o))));return e}(i,K(i,r)),i.precision=t,i.rounding=e,v(a>2?r.neg():r,t,e,!0)):new i(NaN)},M.squareRoot=M.sqrt=function(){var t,e,r,i,n,s,a=this,o=a.d,l=a.e,c=a.s,h=a.constructor;if(1!==c||!o||!o[0])return new h(!c||c<0&&(!o||o[0])?NaN:o?a:1/0);for(p=!1,0==(c=Math.sqrt(+a))||c==1/0?(((e=I(o)).length+l)%2==0&&(e+="0"),c=Math.sqrt(e),l=x((l+1)/2)-(l<0||l%2),i=new h(e=c==1/0?"5e"+l:(e=c.toExponential()).slice(0,e.indexOf("e")+1)+l)):i=new h(c.toString()),r=(l=h.precision)+3;;)if(i=(s=i).plus(b(a,s,r+2,1)).times(.5),I(s.d).slice(0,r)===(e=I(i.d)).slice(0,r)){if("9999"!=(e=e.slice(r-3,r+1))&&(n||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(v(i,l+1,1),t=!i.times(i).eq(a));break}if(!n&&(v(s,l+1,0),s.times(s).eq(a))){i=s;break}r+=4,n=1}return p=!0,v(i,l,h.rounding,t)},M.tangent=M.tan=function(){var t,e,r=this,i=r.constructor;return r.isFinite()?r.isZero()?new i(r):(t=i.precision,e=i.rounding,i.precision=t+10,i.rounding=1,(r=r.sin()).s=1,r=b(r,new i(1).minus(r.times(r)).sqrt(),t+10,0),i.precision=t,i.rounding=e,v(2==a||4==a?r.neg():r,t,e,!0)):new i(NaN)},M.times=M.mul=function(t){var e,r,i,n,s,a,o,l,c,h=this,u=h.constructor,d=h.d,m=(t=new u(t)).d;if(t.s*=h.s,!(d&&d[0]&&m&&m[0]))return new u(!t.s||d&&!d[0]&&!m||m&&!m[0]&&!d?NaN:d&&m?0*t.s:t.s/0);for(r=x(h.e/7)+x(t.e/7),(l=d.length)<(c=m.length)&&(s=d,d=m,m=s,a=l,l=c,c=a),s=[],i=a=l+c;i--;)s.push(0);for(i=c;--i>=0;){for(e=0,n=l+i;n>i;)o=s[n]+m[i]*d[n-i-1]+e,s[n--]=o%N|0,e=o/N|0;s[n]=(s[n]+e)%N|0}for(;!s[--a];)s.pop();return e?++r:s.shift(),t.d=s,t.e=k(s,r),p?v(t,u.precision,u.rounding):t},M.toBinary=function(t,e){return Y(this,2,t,e)},M.toDecimalPlaces=M.toDP=function(t,e){var r=this,i=r.constructor;return r=new i(r),void 0===t?r:(w(t,0,l),void 0===e?e=i.rounding:w(e,0,8),v(r,t+r.e+1,e))},M.toExponential=function(t,e){var r,i=this,n=i.constructor;return void 0===t?r=P(i,!0):(w(t,0,l),void 0===e?e=n.rounding:w(e,0,8),r=P(i=v(new n(i),t+1,e),!0,t+1)),i.isNeg()&&!i.isZero()?"-"+r:r},M.toFixed=function(t,e){var r,i,n=this,s=n.constructor;return void 0===t?r=P(n):(w(t,0,l),void 0===e?e=s.rounding:w(e,0,8),r=P(i=v(new s(n),t+n.e+1,e),!1,t+i.e+1)),n.isNeg()&&!n.isZero()?"-"+r:r},M.toFraction=function(t){var e,r,i,n,s,a,o,l,c,h,u,d,m=this,_=m.d,g=m.constructor;if(!_)return new g(m);if(c=r=new g(1),i=l=new g(0),a=(s=(e=new g(i)).e=H(_)-m.e-1)%7,e.d[0]=T(10,a<0?7+a:a),null==t)t=s>0?e:c;else{if(!(o=new g(t)).isInt()||o.lt(c))throw Error(f+o);t=o.gt(e)?s>0?e:c:o}for(p=!1,o=new g(I(_)),h=g.precision,g.precision=s=7*_.length*2;u=b(o,e,0,1,1),1!=(n=r.plus(u.times(i))).cmp(t);)r=i,i=n,n=c,c=l.plus(u.times(n)),l=n,n=e,e=o.minus(u.times(n)),o=n;return n=b(t.minus(r),i,0,1,1),l=l.plus(n.times(c)),r=r.plus(n.times(i)),l.s=c.s=m.s,d=b(c,i,s,1).minus(m).abs().cmp(b(l,r,s,1).minus(m).abs())<1?[c,i]:[l,r],g.precision=h,p=!0,d},M.toHexadecimal=M.toHex=function(t,e){return Y(this,16,t,e)},M.toNearest=function(t,e){var r=this,i=r.constructor;if(r=new i(r),null==t){if(!r.d)return r;t=new i(1),e=i.rounding}else{if(t=new i(t),void 0===e?e=i.rounding:w(e,0,8),!r.d)return t.s?r:t;if(!t.d)return t.s&&(t.s=r.s),t}return t.d[0]?(p=!1,r=b(r,t,0,e,1).times(t),p=!0,v(r)):(t.s=r.s,r=t),r},M.toNumber=function(){return+this},M.toOctal=function(t,e){return Y(this,8,t,e)},M.toPower=M.pow=function(t){var e,r,i,n,s,a,o=this,l=o.constructor,c=+(t=new l(t));if(!(o.d&&t.d&&o.d[0]&&t.d[0]))return new l(T(+o,c));if((o=new l(o)).eq(1))return o;if(i=l.precision,s=l.rounding,t.eq(1))return v(o,i,s);if((e=x(t.e/7))>=t.d.length-1&&(r=c<0?-c:c)<=9007199254740991)return n=Q(l,o,r,i),t.s<0?new l(1).div(n):v(n,i,s);if((a=o.s)<0){if(e<t.d.length-1)return new l(NaN);if(1&t.d[e]||(a=1),0==o.e&&1==o.d[0]&&1==o.d.length)return o.s=a,o}return(e=0!=(r=T(+o,c))&&isFinite(r)?new l(r+"").e:x(c*(Math.log("0."+I(o.d))/Math.LN10+o.e+1)))>l.maxE+1||e<l.minE-1?new l(e>0?a/0:0):(p=!1,l.rounding=o.s=1,r=Math.min(12,(e+"").length),(n=q(t.times(W(o,i+r)),i)).d&&D((n=v(n,i+5,1)).d,i,s)&&(e=i+10,+I((n=v(q(t.times(W(o,e+r)),e),e+5,1)).d).slice(i+1,i+15)+1==1e14&&(n=v(n,i+1,0))),n.s=a,p=!0,l.rounding=s,v(n,i,s))},M.toPrecision=function(t,e){var r,i=this,n=i.constructor;return void 0===t?r=P(i,i.e<=n.toExpNeg||i.e>=n.toExpPos):(w(t,1,l),void 0===e?e=n.rounding:w(e,0,8),r=P(i=v(new n(i),t,e),t<=i.e||i.e<=n.toExpNeg,t)),i.isNeg()&&!i.isZero()?"-"+r:r},M.toSignificantDigits=M.toSD=function(t,e){var r=this.constructor;return void 0===t?(t=r.precision,e=r.rounding):(w(t,1,l),void 0===e?e=r.rounding:w(e,0,8)),v(new r(this),t,e)},M.toString=function(){var t=this,e=t.constructor,r=P(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()&&!t.isZero()?"-"+r:r},M.truncated=M.trunc=function(){return v(new this.constructor(this),this.e+1,1)},M.valueOf=M.toJSON=function(){var t=this,e=t.constructor,r=P(t,t.e<=e.toExpNeg||t.e>=e.toExpPos);return t.isNeg()?"-"+r:r};var b=function(){function t(t,e,r){var i,n=0,s=t.length;for(t=t.slice();s--;)i=t[s]*e+n,t[s]=i%r|0,n=i/r|0;return n&&t.unshift(n),t}function e(t,e,r,i){var n,s;if(r!=i)s=r>i?1:-1;else for(n=s=0;n<r;n++)if(t[n]!=e[n]){s=t[n]>e[n]?1:-1;break}return s}function r(t,e,r,i){for(var n=0;r--;)t[r]-=n,n=t[r]<e[r]?1:0,t[r]=n*i+t[r]-e[r];for(;!t[0]&&t.length>1;)t.shift()}return function(i,n,a,o,l,c){var h,u,d,p,m,f,_,g,E,T,L,y,C,A,R,S,M,I,w,D,O=i.constructor,b=i.s==n.s?1:-1,P=i.d,k=n.d;if(!(P&&P[0]&&k&&k[0]))return new O(i.s&&n.s&&(P?!k||P[0]!=k[0]:k)?P&&0==P[0]||!k?0*b:b/0:NaN);for(c?(m=1,u=i.e-n.e):(c=N,m=7,u=x(i.e/m)-x(n.e/m)),w=k.length,M=P.length,T=(E=new O(b)).d=[],d=0;k[d]==(P[d]||0);d++);if(k[d]>(P[d]||0)&&u--,null==a?(A=a=O.precision,o=O.rounding):A=l?a+(i.e-n.e)+1:a,A<0)T.push(1),f=!0;else{if(A=A/m+2|0,d=0,1==w){for(p=0,k=k[0],A++;(d<M||p)&&A--;d++)R=p*c+(P[d]||0),T[d]=R/k|0,p=R%k|0;f=p||d<M}else{for((p=c/(k[0]+1)|0)>1&&(k=t(k,p,c),P=t(P,p,c),w=k.length,M=P.length),S=w,y=(L=P.slice(0,w)).length;y<w;)L[y++]=0;(D=k.slice()).unshift(0),I=k[0],k[1]>=c/2&&++I;do{p=0,(h=e(k,L,w,y))<0?(C=L[0],w!=y&&(C=C*c+(L[1]||0)),(p=C/I|0)>1?(p>=c&&(p=c-1),1==(h=e(_=t(k,p,c),L,g=_.length,y=L.length))&&(p--,r(_,w<g?D:k,g,c))):(0==p&&(h=p=1),_=k.slice()),(g=_.length)<y&&_.unshift(0),r(L,_,y,c),-1==h&&(h=e(k,L,w,y=L.length))<1&&(p++,r(L,w<y?D:k,y,c)),y=L.length):0===h&&(p++,L=[0]),T[d++]=p,h&&L[0]?L[y++]=P[S]||0:(L=[P[S]],y=1)}while((S++<M||void 0!==L[0])&&A--);f=void 0!==L[0]}T[0]||T.shift()}if(1==m)E.e=u,s=f;else{for(d=1,p=T[0];p>=10;p/=10)d++;E.e=d+u*m-1,v(E,l?a+E.e+1:a,o,f)}return E}}();function v(t,e,r,i){var n,s,a,o,l,c,h,u,d,m=t.constructor;t:if(null!=e){if(!(u=t.d))return t;for(n=1,o=u[0];o>=10;o/=10)n++;if((s=e-n)<0)s+=7,a=e,l=(h=u[d=0])/T(10,n-a-1)%10|0;else if((d=Math.ceil((s+1)/7))>=(o=u.length)){if(!i)break t;for(;o++<=d;)u.push(0);h=l=0,n=1,a=(s%=7)-7+1}else{for(h=o=u[d],n=1;o>=10;o/=10)n++;l=(a=(s%=7)-7+n)<0?0:h/T(10,n-a-1)%10|0}if(i=i||e<0||void 0!==u[d+1]||(a<0?h:h%T(10,n-a-1)),c=r<4?(l||i)&&(0==r||r==(t.s<0?3:2)):l>5||5==l&&(4==r||i||6==r&&(s>0?a>0?h/T(10,n-a):0:u[d-1])%10&1||r==(t.s<0?8:7)),e<1||!u[0])return u.length=0,c?(e-=t.e+1,u[0]=T(10,(7-e%7)%7),t.e=-e||0):u[0]=t.e=0,t;if(0==s?(u.length=d,o=1,d--):(u.length=d+1,o=T(10,7-s),u[d]=a>0?(h/T(10,n-a)%T(10,a)|0)*o:0),c)for(;;){if(0==d){for(s=1,a=u[0];a>=10;a/=10)s++;for(a=u[0]+=o,o=1;a>=10;a/=10)o++;s!=o&&(t.e++,u[0]==N&&(u[0]=1));break}if(u[d]+=o,u[d]!=N)break;u[d--]=0,o=1}for(s=u.length;0===u[--s];)u.pop()}return p&&(t.e>m.maxE?(t.d=null,t.e=NaN):t.e<m.minE&&(t.e=0,t.d=[0])),t}function P(t,e,r){if(!t.isFinite())return z(t);var i,n=t.e,s=I(t.d),a=s.length;return e?(r&&(i=r-a)>0?s=s.charAt(0)+"."+s.slice(1)+B(i):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(t.e<0?"e":"e+")+t.e):n<0?(s="0."+B(-n-1)+s,r&&(i=r-a)>0&&(s+=B(i))):n>=a?(s+=B(n+1-a),r&&(i=r-n-1)>0&&(s=s+"."+B(i))):((i=n+1)<a&&(s=s.slice(0,i)+"."+s.slice(i)),r&&(i=r-a)>0&&(n+1===a&&(s+="."),s+=B(i))),s}function k(t,e){var r=t[0];for(e*=7;r>=10;r/=10)e++;return e}function U(t,e,r){if(e>R)throw p=!0,r&&(t.precision=r),Error(_);return v(new t(h),e,1,!0)}function F(t,e,r){if(e>S)throw Error(_);return v(new t(u),e,r,!0)}function H(t){var e=t.length-1,r=7*e+1;if(e=t[e]){for(;e%10==0;e/=10)r--;for(e=t[0];e>=10;e/=10)r++}return r}function B(t){for(var e="";t--;)e+="0";return e}function Q(t,e,r,i){var n,s=new t(1),a=Math.ceil(i/7+4);for(p=!1;;){if(r%2&&Z((s=s.times(e)).d,a)&&(n=!0),0===(r=x(r/2))){r=s.d.length-1,n&&0===s.d[r]&&++s.d[r];break}Z((e=e.times(e)).d,a)}return p=!0,s}function V(t){return 1&t.d[t.d.length-1]}function G(t,e,r){for(var i,n,s=new t(e[0]),a=0;++a<e.length;){if(!(n=new t(e[a])).s){s=n;break}((i=s.cmp(n))===r||0===i&&s.s===r)&&(s=n)}return s}function q(t,e){var r,i,n,s,a,o,l,c=0,h=0,u=0,d=t.constructor,m=d.rounding,f=d.precision;if(!t.d||!t.d[0]||t.e>17)return new d(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:NaN);for(null==e?(p=!1,l=f):l=e,o=new d(.03125);t.e>-2;)t=t.times(o),u+=5;for(l+=i=Math.log(T(2,u))/Math.LN10*2+5|0,r=s=a=new d(1),d.precision=l;;){if(s=v(s.times(t),l,1),r=r.times(++h),I((o=a.plus(b(s,r,l,1))).d).slice(0,l)===I(a.d).slice(0,l)){for(n=u;n--;)a=v(a.times(a),l,1);if(null!=e)return d.precision=f,a;if(!(c<3&&D(a.d,l-i,m,c)))return v(a,d.precision=f,m,p=!0);d.precision=l+=10,r=s=o=new d(1),h=0,c++}a=o}}function W(t,e){var r,i,n,s,a,o,l,c,h,u,d,m=1,f=t,_=f.d,g=f.constructor,E=g.rounding,x=g.precision;if(f.s<0||!_||!_[0]||!f.e&&1==_[0]&&1==_.length)return new g(_&&!_[0]?-1/0:1!=f.s?NaN:_?0:f);if(null==e?(p=!1,h=x):h=e,g.precision=h+=10,i=(r=I(_)).charAt(0),!(Math.abs(s=f.e)<15e14))return c=U(g,h+2,x).times(s+""),f=W(new g(i+"."+r.slice(1)),h-10).plus(c),g.precision=x,null==e?v(f,x,E,p=!0):f;for(;i<7&&1!=i||1==i&&r.charAt(1)>3;)i=(r=I((f=f.times(t)).d)).charAt(0),m++;for(s=f.e,i>1?(f=new g("0."+r),s++):f=new g(i+"."+r.slice(1)),u=f,l=a=f=b(f.minus(1),f.plus(1),h,1),d=v(f.times(f),h,1),n=3;;){if(a=v(a.times(d),h,1),I((c=l.plus(b(a,new g(n),h,1))).d).slice(0,h)===I(l.d).slice(0,h)){if(l=l.times(2),0!==s&&(l=l.plus(U(g,h+2,x).times(s+""))),l=b(l,new g(m),h,1),null!=e)return g.precision=x,l;if(!D(l.d,h-10,E,o))return v(l,g.precision=x,E,p=!0);g.precision=h+=10,c=a=f=b(u.minus(1),u.plus(1),h,1),d=v(f.times(f),h,1),n=o=1}l=c,n+=2}}function z(t){return String(t.s*t.s/0)}function j(t,e){var r,i,n;for((r=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(r<0&&(r=i),r+=+e.slice(i+1),e=e.substring(0,i)):r<0&&(r=e.length),i=0;48===e.charCodeAt(i);i++);for(n=e.length;48===e.charCodeAt(n-1);--n);if(e=e.slice(i,n)){if(n-=i,t.e=r=r-i-1,t.d=[],i=(r+1)%7,r<0&&(i+=7),i<n){for(i&&t.d.push(+e.slice(0,i)),n-=7;i<n;)t.d.push(+e.slice(i,i+=7));i=7-(e=e.slice(i)).length}else i-=n;for(;i--;)e+="0";t.d.push(+e),p&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function X(t,e){var r,i,s,a,o,l,c,h,u;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),A.test(e))return j(t,e)}else if("Infinity"===e||"NaN"===e)return+e||(t.s=NaN),t.e=NaN,t.d=null,t;if(y.test(e))r=16,e=e.toLowerCase();else if(L.test(e))r=2;else{if(!C.test(e))throw Error(f+e);r=8}for((a=e.search(/p/i))>0?(c=+e.slice(a+1),e=e.substring(2,a)):e=e.slice(2),o=(a=e.indexOf("."))>=0,i=t.constructor,o&&(a=(l=(e=e.replace(".","")).length)-a,s=Q(i,new i(r),a,2*a)),a=u=(h=O(e,r,N)).length-1;0===h[a];--a)h.pop();return a<0?new i(0*t.s):(t.e=k(h,u),t.d=h,p=!1,o&&(t=b(t,s,4*l)),c&&(t=t.times(Math.abs(c)<54?T(2,c):n.pow(2,c))),p=!0,t)}function J(t,e,r,i,n){var s,a,o,l,c=t.precision,h=Math.ceil(c/7);for(p=!1,l=r.times(r),o=new t(i);;){if(a=b(o.times(l),new t(e++*e++),c,1),o=n?i.plus(a):i.minus(a),i=b(a.times(l),new t(e++*e++),c,1),void 0!==(a=o.plus(i)).d[h]){for(s=h;a.d[s]===o.d[s]&&s--;);if(-1==s)break}s=o,o=i,i=a,a=s}return p=!0,a.d.length=h+1,a}function $(t,e){for(var r=t;--e;)r*=t;return r}function K(t,e){var r,i=e.s<0,n=F(t,t.precision,1),s=n.times(.5);if((e=e.abs()).lte(s))return a=i?4:1,e;if((r=e.divToInt(n)).isZero())a=i?3:2;else{if((e=e.minus(r.times(n))).lte(s))return a=V(r)?i?2:3:i?4:1,e;a=V(r)?i?1:4:i?3:2}return e.minus(n).abs()}function Y(t,e,r,i){var n,a,o,h,u,d,p,m,f,_=t.constructor,g=void 0!==r;if(g?(w(r,1,l),void 0===i?i=_.rounding:w(i,0,8)):(r=_.precision,i=_.rounding),t.isFinite()){for(g?(n=2,16==e?r=4*r-3:8==e&&(r=3*r-2)):n=e,(o=(p=P(t)).indexOf("."))>=0&&(p=p.replace(".",""),(f=new _(1)).e=p.length-o,f.d=O(P(f),10,n),f.e=f.d.length),a=u=(m=O(p,10,n)).length;0==m[--u];)m.pop();if(m[0]){if(o<0?a--:((t=new _(t)).d=m,t.e=a,m=(t=b(t,f,r,i,0,n)).d,a=t.e,d=s),o=m[r],h=n/2,d=d||void 0!==m[r+1],d=i<4?(void 0!==o||d)&&(0===i||i===(t.s<0?3:2)):o>h||o===h&&(4===i||d||6===i&&1&m[r-1]||i===(t.s<0?8:7)),m.length=r,d)for(;++m[--r]>n-1;)m[r]=0,r||(++a,m.unshift(1));for(u=m.length;!m[u-1];--u);for(o=0,p="";o<u;o++)p+=c.charAt(m[o]);if(g){if(u>1)if(16==e||8==e){for(o=16==e?4:3,--u;u%o;u++)p+="0";for(u=(m=O(p,n,e)).length;!m[u-1];--u);for(o=1,p="1.";o<u;o++)p+=c.charAt(m[o])}else p=p.charAt(0)+"."+p.slice(1);p=p+(a<0?"p":"p+")+a}else if(a<0){for(;++a;)p="0"+p;p="0."+p}else if(++a>u)for(a-=u;a--;)p+="0";else a<u&&(p=p.slice(0,a)+"."+p.slice(a))}else p=g?"0p+0":"0";p=(16==e?"0x":2==e?"0b":8==e?"0o":"")+p}else p=z(t);return t.s<0?"-"+p:p}function Z(t,e){if(t.length>e)return t.length=e,!0}function tt(t){return new this(t).abs()}function et(t){return new this(t).acos()}function rt(t){return new this(t).acosh()}function it(t,e){return new this(t).plus(e)}function nt(t){return new this(t).asin()}function st(t){return new this(t).asinh()}function at(t){return new this(t).atan()}function ot(t){return new this(t).atanh()}function lt(t,e){t=new this(t),e=new this(e);var r,i=this.precision,n=this.rounding,s=i+4;return t.s&&e.s?t.d||e.d?!e.d||t.isZero()?(r=e.s<0?F(this,i,n):new this(0)).s=t.s:!t.d||e.isZero()?(r=F(this,s,1).times(.5)).s=t.s:e.s<0?(this.precision=s,this.rounding=1,r=this.atan(b(t,e,s,1)),e=F(this,s,1),this.precision=i,this.rounding=n,r=t.s<0?r.minus(e):r.plus(e)):r=this.atan(b(t,e,s,1)):(r=F(this,s,1).times(e.s>0?.25:.75)).s=t.s:r=new this(NaN),r}function ct(t){return new this(t).cbrt()}function ht(t){return v(t=new this(t),t.e+1,2)}function ut(t,e,r){return new this(t).clamp(e,r)}function dt(t){if(!t||"object"!=typeof t)throw Error(m+"Object expected");var e,r,i,n=!0===t.defaults,s=["precision",1,l,"rounding",0,8,"toExpNeg",-o,0,"toExpPos",0,o,"maxE",0,o,"minE",-o,0,"modulo",0,9];for(e=0;e<s.length;e+=3)if(r=s[e],n&&(this[r]=d[r]),void 0!==(i=t[r])){if(!(x(i)===i&&i>=s[e+1]&&i<=s[e+2]))throw Error(f+r+": "+i);this[r]=i}if(r="crypto",n&&(this[r]=d[r]),void 0!==(i=t[r])){if(!0!==i&&!1!==i&&0!==i&&1!==i)throw Error(f+r+": "+i);if(i){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw Error(g);this[r]=!0}else this[r]=!1}return this}function pt(t){return new this(t).cos()}function mt(t){return new this(t).cosh()}function ft(t,e){return new this(t).div(e)}function _t(t){return new this(t).exp()}function gt(t){return v(t=new this(t),t.e+1,3)}function Et(){var t,e,r=new this(0);for(p=!1,t=0;t<arguments.length;)if((e=new this(arguments[t++])).d)r.d&&(r=r.plus(e.times(e)));else{if(e.s)return p=!0,new this(1/0);r=e}return p=!0,r.sqrt()}function xt(t){return t instanceof n||t&&t.toStringTag===E||!1}function Tt(t){return new this(t).ln()}function Lt(t,e){return new this(t).log(e)}function yt(t){return new this(t).log(2)}function Ct(t){return new this(t).log(10)}function At(){return G(this,arguments,-1)}function Nt(){return G(this,arguments,1)}function Rt(t,e){return new this(t).mod(e)}function St(t,e){return new this(t).mul(e)}function Mt(t,e){return new this(t).pow(e)}function It(t){var e,r,i,n,s=0,a=new this(1),o=[];if(void 0===t?t=this.precision:w(t,1,l),i=Math.ceil(t/7),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(i));s<i;)(n=e[s])>=429e7?e[s]=crypto.getRandomValues(new Uint32Array(1))[0]:o[s++]=n%1e7;else{if(!crypto.randomBytes)throw Error(g);for(e=crypto.randomBytes(i*=4);s<i;)(n=e[s]+(e[s+1]<<8)+(e[s+2]<<16)+((127&e[s+3])<<24))>=214e7?crypto.randomBytes(4).copy(e,s):(o.push(n%1e7),s+=4);s=i/4}else for(;s<i;)o[s++]=1e7*Math.random()|0;for(t%=7,(i=o[--s])&&t&&(n=T(10,7-t),o[s]=(i/n|0)*n);0===o[s];s--)o.pop();if(s<0)r=0,o=[0];else{for(r=-1;0===o[0];r-=7)o.shift();for(i=1,n=o[0];n>=10;n/=10)i++;i<7&&(r-=7-i)}return a.e=r,a.d=o,a}function wt(t){return v(t=new this(t),t.e+1,this.rounding)}function Dt(t){return(t=new this(t)).d?t.d[0]?t.s:0*t.s:t.s||NaN}function Ot(t){return new this(t).sin()}function bt(t){return new this(t).sinh()}function vt(t){return new this(t).sqrt()}function Pt(t,e){return new this(t).sub(e)}function kt(){var t=0,e=arguments,r=new this(e[t]);for(p=!1;r.s&&++t<e.length;)r=r.plus(e[t]);return p=!0,v(r,this.precision,this.rounding)}function Ut(t){return new this(t).tan()}function Ft(t){return new this(t).tanh()}function Ht(t){return v(t=new this(t),t.e+1,1)}(n=function t(e){var r,i,n;function s(t){var e,r,i,n=this;if(!(n instanceof s))return new s(t);if(n.constructor=s,xt(t))return n.s=t.s,void(p?!t.d||t.e>s.maxE?(n.e=NaN,n.d=null):t.e<s.minE?(n.e=0,n.d=[0]):(n.e=t.e,n.d=t.d.slice()):(n.e=t.e,n.d=t.d?t.d.slice():t.d));if("number"==(i=typeof t)){if(0===t)return n.s=1/t<0?-1:1,n.e=0,void(n.d=[0]);if(t<0?(t=-t,n.s=-1):n.s=1,t===~~t&&t<1e7){for(e=0,r=t;r>=10;r/=10)e++;return void(p?e>s.maxE?(n.e=NaN,n.d=null):e<s.minE?(n.e=0,n.d=[0]):(n.e=e,n.d=[t]):(n.e=e,n.d=[t]))}return 0*t!=0?(t||(n.s=NaN),n.e=NaN,void(n.d=null)):j(n,t.toString())}if("string"===i)return 45===(r=t.charCodeAt(0))?(t=t.slice(1),n.s=-1):(43===r&&(t=t.slice(1)),n.s=1),A.test(t)?j(n,t):X(n,t);if("bigint"===i)return t<0?(t=-t,n.s=-1):n.s=1,j(n,t.toString());throw Error(f+t)}if(s.prototype=M,s.ROUND_UP=0,s.ROUND_DOWN=1,s.ROUND_CEIL=2,s.ROUND_FLOOR=3,s.ROUND_HALF_UP=4,s.ROUND_HALF_DOWN=5,s.ROUND_HALF_EVEN=6,s.ROUND_HALF_CEIL=7,s.ROUND_HALF_FLOOR=8,s.EUCLID=9,s.config=s.set=dt,s.clone=t,s.isDecimal=xt,s.abs=tt,s.acos=et,s.acosh=rt,s.add=it,s.asin=nt,s.asinh=st,s.atan=at,s.atanh=ot,s.atan2=lt,s.cbrt=ct,s.ceil=ht,s.clamp=ut,s.cos=pt,s.cosh=mt,s.div=ft,s.exp=_t,s.floor=gt,s.hypot=Et,s.ln=Tt,s.log=Lt,s.log10=Ct,s.log2=yt,s.max=At,s.min=Nt,s.mod=Rt,s.mul=St,s.pow=Mt,s.random=It,s.round=wt,s.sign=Dt,s.sin=Ot,s.sinh=bt,s.sqrt=vt,s.sub=Pt,s.sum=kt,s.tan=Ut,s.tanh=Ft,s.trunc=Ht,void 0===e&&(e={}),e&&!0!==e.defaults)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],r=0;r<n.length;)e.hasOwnProperty(i=n[r++])||(e[i]=this[i]);return s.config(e),s}(d)).prototype.constructor=n,n.default=n.Decimal=n,h=new n(h),u=new n(u),void 0===(i=function(){return n}.call(e,r,e,t))||(t.exports=i)}()},152:function(t,e,r){"use strict";var i,n=this&&this.__createBinding||(Object.create?function(t,e,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(e,r);n&&!("get"in n?!e.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,n)}:function(t,e,r,i){void 0===i&&(i=r),t[i]=e[r]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),a=this&&this.__importStar||(i=function(t){return i=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},i(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=i(t),a=0;a<r.length;a++)"default"!==r[a]&&n(e,t,r[a]);return s(e,t),e}),o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Evaluator=void 0;const l=r(168),c=o(r(207)),h=o(r(770)),u=r(645),d=r(430),p=a(r(109)),m=r(424),f=r(956),_=r(826),g=r(679),E=r(717),x=r(610),T=r(554),L=r(947),y=r(212),C=r(271),A=r(686);class N{response={EXTERNAL:-2,WARNING:-1,OK:0,LEX_ERROR:1,PARSER_ERROR:2,EVAL_ERROR:3};debug=!1;nativeNameTable={false:_.ComplexDecimal.false(),true:_.ComplexDecimal.true(),i:_.ComplexDecimal.onei(),I:_.ComplexDecimal.onei(),j:_.ComplexDecimal.onei(),J:_.ComplexDecimal.onei(),e:_.ComplexDecimal.e(),pi:_.ComplexDecimal.pi(),inf:_.ComplexDecimal.inf_0(),Inf:_.ComplexDecimal.inf_0(),nan:_.ComplexDecimal.NaN_0(),NaN:_.ComplexDecimal.NaN_0()};nativeNameTableList=Object.keys(this.nativeNameTable);aliasNameTable;nameTable={};builtInFunctionTable={};get builtInFunctionList(){return Object.keys(this.builtInFunctionTable)}localTable={};commandWordListTable={clear:{func:(...t)=>this.Clear(...t)},__operators__:{func:(...t)=>{const e=Object.keys(this.opTable).sort(),r=new g.MultiArray([e.length,1],null,!0);return r.array=e.map(t=>[new f.CharString(t)]),r}},__keywords__:{func:(...t)=>{const e=c.default.keywordNames.slice(1).sort(),r=new g.MultiArray([e.length,1],null,!0);return r.array=e.map(t=>[new f.CharString(t)]),r}},__builtins__:{func:(...t)=>{const e=new g.MultiArray([this.builtInFunctionList.length,1],null,!0);return e.array=this.builtInFunctionList.sort().map(t=>[new f.CharString(t)]),e}},__list_functions__:{func:(...t)=>g.MultiArray.emptyArray(!0)},localfunctions:{func:(...t)=>g.MultiArray.emptyArray(!0)},__dump_symtab_info__:{func:(...t)=>g.MultiArray.emptyArray(!0)}};exitStatus;incDecOp(t,e){return t?t=>{if("IDENT"===t.type){if(this.nameTable[t.id])return this.nameTable[t.id]=T.MathOperation[e](this.nameTable[t.id],_.ComplexDecimal.one()),this.nameTable[t.id];throw new EvalError("in x++ or ++x, x must be defined first.")}throw new SyntaxError(`invalid ${"plus"===e?"increment":"decrement"} variable.`)}:t=>{if("IDENT"===t.type){if(this.nameTable[t.id]){const r=T.MathOperation.copy(this.nameTable[t.id]);return this.nameTable[t.id]=T.MathOperation[e](this.nameTable[t.id],_.ComplexDecimal.one()),r}throw new EvalError("in x++ or ++x, x must be defined first.")}throw new SyntaxError(`invalid ${"plus"===e?"increment":"decrement"} variable.`)}}opTable={"+":T.MathOperation.plus,"-":T.MathOperation.minus,".*":T.MathOperation.times,"*":T.MathOperation.mtimes,"./":T.MathOperation.rdivide,"/":T.MathOperation.mrdivide,".\\":T.MathOperation.ldivide,"\\":T.MathOperation.mldivide,".^":T.MathOperation.power,"^":T.MathOperation.mpower,"+_":T.MathOperation.uplus,"-_":T.MathOperation.uminus,".'":T.MathOperation.transpose,"'":T.MathOperation.ctranspose,"<":T.MathOperation.lt,"<=":T.MathOperation.le,"==":T.MathOperation.eq,">=":T.MathOperation.ge,">":T.MathOperation.gt,"!=":T.MathOperation.ne,"&":T.MathOperation.and,"|":T.MathOperation.or,"!":T.MathOperation.not,"&&":T.MathOperation.mand,"||":T.MathOperation.mor,"++_":this.incDecOp(!0,"plus"),"--_":this.incDecOp(!0,"minus"),"_++":this.incDecOp(!1,"plus"),"_--":this.incDecOp(!1,"minus")};static precedence=[["min","=","+=","-=","*=","/=","\\="],["||"],["&&"],["|"],["&"],["!=","<",">","<=",">="],["+","-"],[".*","*","./","/",".\\","\\"],["^",".**","**",".'","'"],["!","~","-_","+_"],["preMax","_.^","_.**","_^","_**","__.'","__'","__++"],["max","()","IDENT","ENDRANGE",":","<~>","."]];precedenceTable;nodePrecedence(t){if("number"==typeof t.type)return t instanceof _.ComplexDecimal?_.ComplexDecimal.precedence(t,this):this.precedenceTable.max;if("IDX"===t.type){const e=this.aliasName(t.expr.id);return"IDENT"===t.expr.type&&e in this.builtInFunctionTable&&(this.builtInFunctionTable[e].unparserMathML||e in A.MathML.format)?this.precedenceTable.max:this.precedenceTable.preMax}return"RANGE"===t.type?t.start_&&t.stop_?this.precedenceTable.min:this.precedenceTable.max:this.precedenceTable[t.type]||0}functions={unparse:t=>new f.CharString(this.Unparse(t))};unparseString=f.CharString.unparse;unparseStringMathML=f.CharString.unparseMathML;newNumber=_.ComplexDecimal.newThis;unparseNumber=_.ComplexDecimal.unparse;unparseNumberMathML=_.ComplexDecimal.unparseMathML;isRowVector=g.MultiArray.isRowVector;unparseArray=g.MultiArray.unparse;unparseStructure=y.Structure.unparse;unparseStructureMathML=y.Structure.unparseMathML;newFunctionHandle=C.FunctionHandle.newThis;unparseFunctionHandle=C.FunctionHandle.unparse;unparseFunctionHandleMathML=C.FunctionHandle.unparseMathML;unparseArrayMathML=g.MultiArray.unparseMathML;evaluateArray=g.MultiArray.evaluate;mapArray=g.MultiArray.rawMap;getElements=g.MultiArray.getElements;getElementsLogical=g.MultiArray.getElementsLogical;setElements=g.MultiArray.setElements;setElementsLogical=g.MultiArray.setElementsLogical;expandRange=g.MultiArray.expandRange;expandColon=g.MultiArray.expandColon;array0x0=g.MultiArray.emptyArray;linearize=g.MultiArray.linearize;scalarToArray=g.MultiArray.scalarToMultiArray;scalarOrCellToArray=g.MultiArray.scalarOrCellToMultiArray;arrayToScalar=g.MultiArray.MultiArrayToScalar;linearLength=g.MultiArray.linearLength;getDimension=g.MultiArray.getDimension;toLogical=g.MultiArray.toLogical;getFields=y.Structure.getFields;setNewField=y.Structure.setNewField;unparseMathMLFunctions={logb:t=>{let e=this.unparserMathML(t.args[1]);return this.nodePrecedence(t.args[1])<this.precedenceTable.max&&(e=A.MathML.format["()"]("(",e,")")),A.MathML.format.logb(this.unparserMathML(t.args[0]),e)},log2:t=>{let e=this.unparserMathML(t.args[0]);return this.nodePrecedence(t.args[0])<this.precedenceTable.max&&(e=A.MathML.format["()"]("(",e,")")),A.MathML.format.log2(e)},log10:t=>{let e=this.unparserMathML(t.args[0]);return this.nodePrecedence(t.args[0])<this.precedenceTable.max&&(e=A.MathML.format["()"]("(",e,")")),A.MathML.format.log10(e)},factorial:t=>{let e=this.unparserMathML(t.args[0]);return this.nodePrecedence(t.args[0])<this.precedenceTable.max&&(e=A.MathML.format["()"]("(",e,")")),A.MathML.format.factorial(e)}};aliasName=t=>t;constructor(t){this.exitStatus=this.response.OK,this.precedenceTable={},N.precedence.forEach((t,e)=>{t.forEach(t=>{this.precedenceTable[t]=e+1})}),this.opTable["**"]=this.opTable["^"],this.precedenceTable["**"]=this.precedenceTable["^"],this.opTable[".**"]=this.opTable[".^"],this.precedenceTable[".**"]=this.precedenceTable[".^"],this.precedenceTable["_**"]=this.precedenceTable["_^"],this.precedenceTable["_.**"]=this.precedenceTable["_.^"],this.opTable["~="]=this.opTable["!="],this.precedenceTable["~="]=this.precedenceTable["!="],this.opTable["~"]=this.opTable["!"],this.precedenceTable["~"]=this.precedenceTable["!"],this.loadNativeTable();for(const t in this.functions)this.defineFunction(t,this.functions[t]);for(const t in T.MathOperation.leftAssociativeMultipleOperations)this.defineLeftAssociativeMultipleOperationFunction(t,T.MathOperation.leftAssociativeMultipleOperations[t]);for(const t in T.MathOperation.binaryOperations)this.defineBinaryOperatorFunction(t,T.MathOperation.binaryOperations[t]);for(const t in T.MathOperation.unaryOperations)this.defineUnaryOperatorFunction(t,T.MathOperation.unaryOperations[t]);for(const t in _.ComplexDecimal.mapFunction)this.defineFunction(t,_.ComplexDecimal.mapFunction[t],!0);for(const t in _.ComplexDecimal.twoArgFunction)this.defineFunction(t,_.ComplexDecimal.twoArgFunction[t]);for(const t in L.Configuration.functions)this.defineFunction(t,L.Configuration.functions[t]);for(const t in E.CoreFunctions.functions)this.defineFunction(t,E.CoreFunctions.functions[t]);for(const t in x.LinearAlgebra.functions)this.defineFunction(t,x.LinearAlgebra.functions[t]);for(const t in this.unparseMathMLFunctions)this.builtInFunctionTable[t].unparserMathML=this.unparseMathMLFunctions[t];t?(t.aliasNameTable?(this.aliasNameTable=t.aliasNameTable,this.aliasName=t=>{let e=!1,r="";for(const i in this.aliasNameTable)if(this.aliasNameTable[i].test(t)){e=!0,r=i;break}return e?r:t}):this.aliasName=t=>t,t.externalFunctionTable&&Object.assign(this.builtInFunctionTable,t.externalFunctionTable),t.externalCmdWListTable&&Object.assign(this.commandWordListTable,t.externalCmdWListTable)):this.aliasName=t=>t}Parse(t){const e=l.CharStreams.fromString(t),r=new c.default(e);r.commandNames=Object.keys(this.commandWordListTable);const i=new l.CommonTokenStream(r),n=new h.default(i);return n.buildParseTrees=!0,r.removeErrorListeners(),r.addErrorListener(new u.LexerErrorListener),n.removeErrorListeners(),n.addErrorListener(new d.ParserErrorListener),this.debug,n.input().node}loadNativeTable(){for(const t in this.nativeNameTable)this.nameTable[t]=this.nativeNameTable[t]}Restart(){this.nameTable={},this.localTable={},this.loadNativeTable()}Clear(...t){0===t.length?this.Restart():t.forEach(t=>{delete this.nameTable[t],delete this.builtInFunctionTable[t],this.nativeNameTableList.includes(t)&&(this.nameTable[t]=this.nativeNameTable[t])})}static throwErrorIfGreaterThanReturnList(t,e){if(e>t)throw new EvalError(`element number ${t+1} undefined in return list`)}reduceIfReturnList(t){if("RETLIST"===t.type){const e=t.selector(1,0);return e.parent=t.parent,e}return t}validateAssignment(t,e,r,i){const n="invalid left hand side of assignment";if("IDENT"===t.type)return[{id:t.id,index:[],field:[]}];if("IDX"===t.type&&"IDENT"===t.expr.type)return[{id:t.expr.id,index:t.args,field:[]}];if("."===t.type){const e=t.field.map(t=>{if("string"==typeof t)return t;{const e=this.reduceIfReturnList(this.Evaluator(t,r,i));if(e instanceof f.CharString)return e.str;throw new EvalError(`${n}: dynamic structure field names must be strings.`)}});if("IDENT"===t.obj.type)return[{id:t.obj.id,index:[],field:e}];if("IDX"===t.obj.type&&"IDENT"===t.obj.expr.type)return[{id:t.obj.expr.id,index:t.obj.args,field:e}];throw new EvalError(`${n}.`)}if("<~>"===t.type)return[{id:"~",index:[],field:[]}];if(e&&this.isRowVector(t))return t.array[0].map(t=>this.validateAssignment(t,!1,r,i)[0]);throw new EvalError(`${n}.`)}defineFunction(t,e,r=!1,i=[]){this.builtInFunctionTable[t]={type:"BUILTIN",mapper:r,ev:i,func:e}}defineUnaryOperatorFunction(t,e){this.builtInFunctionTable[t]={type:"BUILTIN",mapper:!1,ev:[],func:(...r)=>{if(1===r.length)return e(r[0]);throw new EvalError(`Invalid call to ${t}. Type 'help ${t}' to see correct usage.`)}}}defineBinaryOperatorFunction(t,e){this.builtInFunctionTable[t]={type:"BUILTIN",mapper:!1,ev:[],func:(r,...i)=>{if(1===i.length)return e(r,i[0]);throw new EvalError(`Invalid call to ${t}. Type 'help ${t}' to see correct usage.`)}}}defineLeftAssociativeMultipleOperationFunction(t,e){this.builtInFunctionTable[t]={type:"BUILTIN",mapper:!1,ev:[],func:(r,...i)=>{if(1===i.length)return e(r,i[0]);if(i.length>1){let t=e(r,i[0]);for(let r=1;r<i.length;r++)t=e(t,i[r]);return t}throw new EvalError(`Invalid call to ${t}. Type 'help ${t}' to see correct usage.`)}}}toBoolean(t){const e=t instanceof g.MultiArray?this.toLogical(t):t;return e instanceof _.ComplexDecimal?Boolean(e.re.toNumber()||e.im.toNumber()):!!e.str}Evaluator(t,e=!1,r=""){if(this.debug&&console.log(`Evaluator(\ntree:${JSON.stringify(t,(t,e)=>"parent"!==t?e:null!==e||"root",2)},\nlocal:${e},\nfname:${r});`),!t)return null;if(t instanceof _.ComplexDecimal||t instanceof C.FunctionHandle||t instanceof f.CharString||t instanceof y.Structure)return t;if(t instanceof g.MultiArray)return this.evaluateArray(t,this,e,r);switch(t.type){case"+":case"-":case".*":case"*":case"./":case"/":case".\\":case"\\":case".^":case"^":case".**":case"**":case"<":case"<=":case"==":case">=":case">":case"!=":case"~=":case"&":case"|":case"&&":case"||":return t.left.parent=t,t.right.parent=t,this.opTable[t.type](this.reduceIfReturnList(this.Evaluator(t.left,e,r)),this.reduceIfReturnList(this.Evaluator(t.right,e,r)));case"()":return t.right.parent=t,this.reduceIfReturnList(this.Evaluator(t.right,e,r));case"!":case"~":case"+_":case"-_":return t.right.parent=t,this.opTable[t.type](this.reduceIfReturnList(this.Evaluator(t.right,e,r)));case"++_":case"--_":return t.right.parent=t,this.opTable[t.type](t.right);case".'":case"'":return t.left.parent=t,this.opTable[t.type](this.reduceIfReturnList(this.Evaluator(t.left,e,r)));case"_++":case"_--":return t.left.parent=t,this.opTable[t.type](t.left);case"=":case"+=":case"-=":case"*=":case"/=":case"\\=":case"^=":case"**=":case".*=":case"./=":case".\\=":case".^=":case".**=":case"&=":case"|=":{t.left.parent=t,t.right.parent=t;const i=this.validateAssignment(t.left,!0,e,r),n=t.type.substring(0,t.type.length-1);if(i.length>1&&n.length>0)throw new EvalError("computed multiple assignment not allowed.");let s;try{s=this.Evaluator(t.right,!1,r)}catch{s=t.right}"RETLIST"!==s.type&&(s=p.nodeReturnList((e,r)=>{if(0===r)return t.right;throw new EvalError(`element number ${r+1} undefined in return list`)}));const a=p.nodeListFirst();for(let o=0;o<i.length;o++){const{id:l,index:c,field:h}=i[o];if("~"!==l)if(0===c.length){"RETLIST"!==s.type&&(s=this.Evaluator(s,!1,r));const e=s.selector(i.length,o);e.parent=t.right;const c=n.length?p.nodeOp(n,p.nodeIdentifier(l),e):e;try{if(h.length>0){if(void 0===this.nameTable[l]&&(this.nameTable[l]=new y.Structure({})),!(this.nameTable[l]instanceof y.Structure))throw new EvalError("in indexed assignment.");this.setNewField(this.nameTable[l],h,this.reduceIfReturnList(this.Evaluator(c))),p.appendNodeList(a,p.nodeOp("=",p.nodeIdentifier(l),this.nameTable[l]))}else this.nameTable[l]=this.reduceIfReturnList(this.Evaluator(c)),p.appendNodeList(a,p.nodeOp("=",p.nodeIdentifier(l),this.nameTable[l]));continue}catch(t){throw this.nameTable[l]=c,t}}else{if(n){if(void 0!==this.nameTable[l]){if(this.nameTable[l]instanceof C.FunctionHandle)throw new EvalError("can't perform indexed assignment for function handle type.");if(1===c.length){const t=this.reduceIfReturnList(this.Evaluator(c[0],e,r));t instanceof g.MultiArray&&t.type===_.ComplexDecimal.LOGICAL?this.setElementsLogical(this.nameTable,l,h,this.linearize(t),this.scalarToArray(this.reduceIfReturnList(this.Evaluator(p.nodeOp(n,th