mathjs/math.min.js
2013-03-19 22:08:43 +01:00

29 lines
74 KiB
JavaScript

/**
* math.js
* https://github.com/josdejong/mathjs
*
* Math.js is an extensive math library for JavaScript and Node.js,
* It features real and complex numbers, units, matrices, a large set of
* mathematical functions, and a flexible expression parser.
*
* @version 0.5.0-SNAPSHOT
* @date 2013-03-19
*
* @license
* Copyright (C) 2013 Jos de Jong <wjosdejong@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
(function(){function e(t,n){if(this.constructor!=e)throw new SyntaxError("Complex constructor must be called with the new operator");switch(arguments.length){case 2:if(!r(t)||!r(n))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=t,this.im=n;break;case 1:if(!i(t))throw new TypeError("Two numbers or a single string expected in Complex constructor");var a=e.parse(t);if(a)return a;throw new SyntaxError('String "'+t+'" is no valid complex number');case 0:this.re=0,this.im=0;break;default:throw new SyntaxError("Wrong number of arguments in Complex constructor ("+arguments.length+" provided, 0, 1, or 2 expected)")}}function t(e){if(this.constructor!=t)throw new SyntaxError("Matrix constructor must be called with the new operator");this.array=e||[]}function r(e){return e instanceof Number||"number"==typeof e}function n(e){return e==Math.round(e)}function i(e){return e instanceof String||"string"==typeof e}function a(e,t){if(this.constructor!=a)throw Error("Unit constructor must be called with the new operator");this.value=1,this.unit=a.UNIT_NONE,this.prefix=a.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1;var r=arguments.length;if(0==r);else{if(1==r){if(!i(e))throw new TypeError("A string or a number and string expected in Unit constructor");var n=a.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid unit')}if(2!=r)throw Error("Too many parameters in Unit constructor, 1 or 2 expected");if(!i(t))throw Error("Second parameter in Unit constructor must be a String");for(var s=a.UNITS,o=!1,f=0,u=s.length;u>f;f++){var l=s[f];if(a.endsWith(t,l.name)){var h=t.length-l.name.length,c=t.substring(0,h),p=l.prefixes[c];if(void 0!==p){this.unit=l,this.prefix=p,this.hasUnit=!0,o=!0;break}}}if(!o)throw Error('String "'+t+'" is no unit');null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}}function s(e,t){var r=void 0;if(2==arguments.length){var n=ht(t);r="Function "+e+" does not support a parameter of type "+n}else if(arguments.length>2){for(var i=[],a=1;arguments.length>a;a++)i.push(ht(arguments[a]));r="Function "+e+" does not support a parameters of type "+i.join(", ")}else r="Unsupported parameter in function "+e;return new TypeError(r)}function o(e,t,r,n){var i="Wrong number of arguments in function "+e+" ("+t+" provided, "+r+(void 0!=n?"-"+n:"")+" expected)";return new SyntaxError(i)}function f(t){if(1!=arguments.length)throw o("abs",arguments.length,1);if(r(t))return Math.abs(t);if(t instanceof e)return Math.sqrt(t.re*t.re+t.im*t.im);if(t instanceof Array)return Ot.map(t,f);if(t.valueOf()!==t)return f(t.valueOf());throw s("abs",t)}function u(t,n){if(2!=arguments.length)throw o("add",arguments.length,2);if(r(t)){if(r(n))return t+n;if(n instanceof e)return new e(t+n.re,n.im)}else if(t instanceof e){if(r(n))return new e(t.re+n,t.im);if(n instanceof e)return new e(t.re+n.re,t.im+n.im)}else if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Units do not match");if(!t.hasValue)throw Error("Unit on left hand side of operator + has no value");if(!n.hasValue)throw Error("Unit on right hand side of operator + has no value");var f=t.clone();return f.value+=n.value,f.fixPrefix=!1,f}if(i(t)||i(n))return t+n;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,u);if(t.valueOf()!==t)return u(t.valueOf());throw s("add",t,n)}function l(t){if(1!=arguments.length)throw o("ceil",arguments.length,1);if(r(t))return Math.ceil(t);if(t instanceof e)return new e(Math.ceil(t.re),Math.ceil(t.im));if(t instanceof Array)return Ot.map(t,l);if(t.valueOf()!==t)return l(t.valueOf());throw s("ceil",t)}function h(t){if(1!=arguments.length)throw o("cube",arguments.length,1);if(r(t))return t*t*t;if(t instanceof e)return O(O(t,t),t);if(t instanceof Array)return O(O(t,t),t);if(t.valueOf()!==t)return h(t.valueOf());throw s("cube",t)}function c(t,n){if(2!=arguments.length)throw o("divide",arguments.length,2);if(r(t)){if(r(n))return t/n;if(n instanceof e)return p(new e(t,0),n)}if(t instanceof e){if(r(n))return p(t,new e(n,0));if(n instanceof e)return p(t,n)}if(t instanceof a&&r(n)){var i=t.clone();return i.value/=n,i}if(t instanceof Array&&!(n instanceof Array))return Ot.map2(t,n,c);if(t.valueOf()!==t||n.valueOf()!==n)return c(t.valueOf(),n.valueOf());throw s("divide",t,n)}function p(t,r){var n=r.re*r.re+r.im*r.im;return new e((t.re*r.re+t.im*r.im)/n,(t.im*r.re-t.re*r.im)/n)}function m(t,n){if(2!=arguments.length)throw o("equal",arguments.length,2);if(r(t)){if(r(n))return t==n;if(n instanceof e)return t==n.re&&0==n.im}if(t instanceof e){if(r(n))return t.re==n&&0==t.im;if(n instanceof e)return t.re==n.re&&t.im==n.im}if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value==n.value}if(i(t)||i(n))return t==n;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,m);if(t.valueOf()!==t||n.valueOf()!==n)return m(t.valueOf(),n.valueOf());throw s("equal",t,n)}function v(t){if(1!=arguments.length)throw o("exp",arguments.length,1);if(r(t))return Math.exp(t);if(t instanceof e){var n=Math.exp(t.re);return new e(n*Math.cos(t.im),n*Math.sin(t.im))}if(t instanceof Array)return Ot.map(t,v);if(t.valueOf()!==t)return v(t.valueOf());throw s("exp",t)}function d(t){if(1!=arguments.length)throw o("fix",arguments.length,1);if(r(t))return value>0?Math.floor(t):Math.ceil(t);if(t instanceof e)return new e(t.re>0?Math.floor(t.re):Math.ceil(t.re),t.im>0?Math.floor(t.im):Math.ceil(t.im));if(t instanceof Array)return Ot.map(t,d);if(t.valueOf()!==t)return d(t.valueOf());throw s("fix",t)}function g(t){if(1!=arguments.length)throw o("floor",arguments.length,1);if(r(t))return Math.floor(t);if(t instanceof e)return new e(Math.floor(t.re),Math.floor(t.im));if(t instanceof Array)return Ot.map(t,g);if(t.valueOf()!==t)return g(t.valueOf());throw s("floor",t)}function y(t,n){if(2!=arguments.length)throw o("larger",arguments.length,2);if(r(t)){if(r(n))return t>n;if(n instanceof e)return t>f(n)}if(t instanceof e){if(r(n))return f(t)>n;if(n instanceof e)return f(t)>f(n)}if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value>n.value}if(i(t)||i(n))return t>n;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,m);if(t.valueOf()!==t||n.valueOf()!==n)return y(t.valueOf(),n.valueOf());throw s("larger",t,n)}function x(t,n){if(2!=arguments.length)throw o("largereq",arguments.length,2);if(r(t)){if(r(n))return t>=n;if(n instanceof e)return t>=f(n)}if(t instanceof e){if(r(n))return f(t)>=n;if(n instanceof e)return f(t)>=f(n)}if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value>=n.value}if(i(t)||i(n))return t>=n;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,x);if(t.valueOf()!==t||n.valueOf()!==n)return x(t.valueOf(),n.valueOf());throw s("largereq",t,n)}function w(t,n){if(1!=arguments.length&&2!=arguments.length)throw o("log",arguments.length,1,2);if(void 0!==n)return c(w(t),w(n));if(r(t))return t>=0?Math.log(t):w(new e(t,0));if(t instanceof e)return new e(Math.log(Math.sqrt(t.re*t.re+t.im*t.im)),Math.atan2(t.im,t.re));if(t instanceof Array)return Ot.map(t,w);if(t.valueOf()!==t||n.valueOf()!==n)return w(t.valueOf(),n.valueOf());throw s("log",t,n)}function E(t){if(1!=arguments.length)throw o("log10",arguments.length,1);if(r(t))return t>=0?Math.log(t)/Math.LN10:E(new e(t,0));if(t instanceof e)return new e(Math.log(Math.sqrt(t.re*t.re+t.im*t.im))/Math.LN10,Math.atan2(t.im,t.re)/Math.LN10);if(t instanceof Array)return Ot.map(t,E);if(t.valueOf()!==t)return E(t.valueOf());throw s("log10",t)}function N(t,n){if(2!=arguments.length)throw o("mod",arguments.length,2);if(r(t)){if(r(n))return t%n;if(n instanceof e&&0==n.im)return t%n.re}else if(t instanceof e&&0==t.im){if(r(n))return t.re%n;if(n instanceof e&&0==n.im)return t.re%n.re}if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,N);if(t.valueOf()!==t||n.valueOf()!==n)return N(t.valueOf(),n.valueOf());throw s("mod",t,n)}function O(t,n){if(2!=arguments.length)throw o("multiply",arguments.length,2);if(r(t)){if(r(n))return t*n;if(n instanceof e)return b(new e(t,0),n);if(n instanceof a)return l=n.clone(),l.value*=t,l}else if(t instanceof e){if(r(n))return b(t,new e(n,0));if(n instanceof e)return b(t,n)}else if(t instanceof a){if(r(n))return l=t.clone(),l.value*=n,l}else if(t instanceof Array){if(n instanceof Array){var i=Ot.array.validatedSize(t),f=Ot.array.validatedSize(n);if(2!=i.length)throw Error("Can only multiply a 2 dimensional matrix (A has "+i.length+" dimensions)");if(2!=f.length)throw Error("Can only multiply a 2 dimensional matrix (B has "+f.length+" dimensions)");if(i[1]!=f[0])throw Error("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+i[0]+"x"+i[1]+", B is "+f[0]+"x"+f[1]+", "+f[1]+" != "+f[0]+")");for(var l=[],h=i[0],c=f[1],p=i[1],m=0;h>m;m++){l[m]=[];for(var v=0;c>v;v++){for(var d=null,g=0;p>g;g++){var y=O(t[m][g],n[g][v]);d=null==d?y:u(d,y)}l[m][v]=d}}return l}return Ot.map2(t,n,O)}if(n instanceof Array)return Ot.map2(t,n,O);if(t.valueOf()!==t||n.valueOf()!==n)return O(t.valueOf(),n.valueOf());throw s("multiply",t,n)}function b(t,r){return new e(t.re*r.re-t.im*r.im,t.re*r.im+t.im*r.re)}function M(t,i){if(2!=arguments.length)throw o("pow",arguments.length,2);if(r(t)){if(r(i))return n(i)||t>=0?Math.pow(t,i):T(new e(t,0),new e(i,0));if(i instanceof e)return T(new e(t,0),i)}else if(t instanceof e){if(r(i))return T(t,new e(i,0));if(i instanceof e)return T(t,i)}else if(t instanceof Array){if(!r(i)||!n(i)||0>i)throw new TypeError("For A^b, b must be a positive integer (value is "+i+")");var a=Ot.array.validatedSize(t);if(2!=a.length)throw Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==i)return D(a[0]);for(var f=t,u=1;i>u;u++)f=O(t,f);return f}if(t.valueOf()!==t||i.valueOf()!==i)return M(t.valueOf(),i.valueOf());throw s("pow",t,i)}function T(e,t){var r=w(e),n=O(r,t);return v(n)}function S(t,n){if(1!=arguments.length&&2!=arguments.length)throw o("round",arguments.length,1,2);if(void 0==n){if(r(t))return Math.round(t);if(t instanceof e)return new e(Math.round(t.re),Math.round(t.im));if(t instanceof Array&&Ot.map(t,S),t.valueOf()!==t)return S(t.valueOf());throw s("round",t)}if(!r(n))throw new TypeError("Number of digits in function round must be an integer");if(n!==Math.round(n))throw new TypeError("Number of digits in function round must be integer");if(0>n||n>9)throw Error("Number of digits in function round must be in te range of 0-9");if(r(t))return A(t,n);if(t instanceof e)return new e(A(t.re,n),A(t.im,n));if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,S);if(t.valueOf()!==t||n.valueOf()!==n)return y(t.valueOf(),n.valueOf());throw s("round",t,n)}function A(e,t){var r=Math.pow(10,void 0!=t?t:Nt.options.precision);return Math.round(e*r)/r}function k(t){if(1!=arguments.length)throw o("sign",arguments.length,1);if(r(t)){var n;return n=t>0?1:0>t?-1:0}if(t instanceof e){var i=Math.sqrt(t.re*t.re+t.im*t.im);return new e(t.re/i,t.im/i)}if(t instanceof Array)return Ot.map(t,n);if(t.valueOf()!==t)return n(t.valueOf());throw s("sign",t)}function _(t,n){if(2!=arguments.length)throw o("smaller",arguments.length,2);if(r(t)){if(r(n))return n>t;if(n instanceof e)return f(n)>t}if(t instanceof e){if(r(n))return n>f(t);if(n instanceof e)return f(t)<f(n)}if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value<n.value}if(i(t)||i(n))return n>t;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,_);if(t.valueOf()!==t||n.valueOf()!==n)return _(t.valueOf(),n.valueOf());throw s("smaller",t,n)}function U(t,n){if(2!=arguments.length)throw o("smallereq",arguments.length,2);if(r(t)){if(r(n))return n>=t;if(n instanceof e)return f(n)>=t}if(t instanceof e){if(r(n))return n>=f(t);if(n instanceof e)return f(t)<=f(n)}if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value<=n.value}if(i(t)||i(n))return n>=t;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,U);if(t.valueOf()!==t||n.valueOf()!==n)return U(t.valueOf(),n.valueOf());throw s("smallereq",t,n)}function q(t){if(1!=arguments.length)throw o("sqrt",arguments.length,1);if(r(t))return t>=0?Math.sqrt(t):q(new e(t,0));if(t instanceof e){var n=Math.sqrt(t.re*t.re+t.im*t.im);return t.im>=0?new e(.5*Math.sqrt(2*(n+t.re)),.5*Math.sqrt(2*(n-t.re))):new e(.5*Math.sqrt(2*(n+t.re)),-.5*Math.sqrt(2*(n-t.re)))}if(t instanceof Array)return Ot.map(t,q);if(t.valueOf()!==t)return q(t.valueOf());throw s("sqrt",t)}function L(t){if(1!=arguments.length)throw o("square",arguments.length,1);if(r(t))return t*t;if(t instanceof e)return O(t,t);if(t instanceof Array)return O(t,t);if(t.valueOf()!==t)return L(t.valueOf());throw s("square",t)}function C(t,n){if(2!=arguments.length)throw o("subtract",arguments.length,2);if(r(t)){if(r(n))return t-n;if(n instanceof e)return new e(t-n.re,n.im)}else if(t instanceof e){if(r(n))return new e(t.re-n,t.im);if(n instanceof e)return new e(t.re-n.re,t.im-n.im)}else if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Units do not match");if(!t.hasValue)throw Error("Unit on left hand side of operator - has no value");if(!n.hasValue)throw Error("Unit on right hand side of operator - has no value");var i=t.clone();return i.value-=n.value,i.fixPrefix=!1,i}if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,C);if(t.valueOf()!==t||n.valueOf()!==n)return C(t.valueOf(),n.valueOf());throw s("subtract",t,n)}function R(t){if(1!=arguments.length)throw o("unaryminus",arguments.length,1);if(r(t))return-t;if(t instanceof e)return new e(-t.re,-t.im);if(t instanceof a){var n=t.clone();return n.value=-t.value,n}if(t instanceof Array)return Ot.map(t,R);if(t.valueOf()!==t)return R(t.valueOf());throw s("unaryminus",t)}function I(t,n){if(2!=arguments.length)throw o("unequal",arguments.length,2);if(r(t)){if(r(n))return t==n;if(n instanceof e)return t==n.re&&0==n.im}if(t instanceof e){if(r(n))return t.re==n&&0==t.im;if(n instanceof e)return t.re==n.re&&t.im==n.im}if(t instanceof a&&n instanceof a){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value==n.value}if(i(t)||i(n))return t==n;if(t instanceof Array||n instanceof Array)return Ot.map2(t,n,I);if(t.valueOf()!==t||n.valueOf()!==n)return I(t.valueOf(),n.valueOf());throw s("unequal",t,n)}function P(t){if(1!=arguments.length)throw o("arg",arguments.length,1);if(r(t))return Math.atan2(0,t);if(t instanceof e)return Math.atan2(t.im,t.re);if(t instanceof Array)return Ot.map(t,P);if(t.valueOf()!==t)return P(t.valueOf());throw s("arg",t)}function B(t){if(1!=arguments.length)throw o("conj",arguments.length,1);if(r(t))return t;if(t instanceof e)return new e(t.re,-t.im);if(t instanceof Array)return Ot.map(t,B);if(t.valueOf()!==t)return B(t.valueOf());throw s("conj",t)}function G(t){if(1!=arguments.length)throw o("im",arguments.length,1);if(r(t))return 0;if(t instanceof e)return t.im;if(t instanceof Array)return Ot.map(t,G);if(t.valueOf()!==t)return G(t.valueOf());throw s("im",t)}function z(t){if(1!=arguments.length)throw o("re",arguments.length,1);if(r(t))return t;if(t instanceof e)return t.re;if(t instanceof Array)return Ot.map(t,z);if(t.valueOf()!==t)return z(t.valueOf());throw s("re",t)}function D(e,t){var i,a,s=arguments.length;if(0>s||s>2)throw o("eye",s,0,2);if(0==s)return 1;if(1==s?(i=e,a=e):2==s&&(i=e,a=t),!r(i)||!n(i)||1>i)throw Error("Parameters in function eye must be positive integers");if(a&&(!r(a)||!n(a)||1>a))throw Error("Parameters in function eye must be positive integers");for(var f=[],u=0;i>u;u++){for(var l=[],h=0;a>h;h++)l[h]=0;f[u]=l}for(var c=Math.min(i,a),p=0;c>p;p++)f[p][p]=1;return f}function Y(t){if(1!=arguments.length)throw o("size",arguments.length,1);if(r(t))return[[1,1]];if(t instanceof e)return[[1,1]];if(t instanceof a)return[[1,1]];if(i(t))return[[1,t.length]];if(t instanceof Array){var n=Ot.array.validatedSize(t);return 1==n.length&&n.push(0),[n]}if(t.valueOf()!==t)return Y(t.valueOf());throw s("size",t)}function V(e){if(1!=arguments.length)throw o("factorial",arguments.length,1);if(r(e)){if(!n(e))throw new TypeError("Function factorial can only handle integer values");var t=e,i=t;for(t--;t>1;)i*=t,t--;return 0==i&&(i=1),i}if(e instanceof Array)return Ot.map(e,V);if(e.valueOf()!==e)return V(e.valueOf());throw s("factorial",e)}function F(){if(0!=arguments.length)throw o("random",arguments.length,0);return Math.random()}function j(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return j.apply(this,e.valueOf());for(var t=arguments[0],r=1,n=arguments.length;n>r;r++){var i=arguments[r];y(i,t)&&(t=i)}return t}function H(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return H.apply(this,e.valueOf());for(var t=arguments[0],r=1,n=arguments.length;n>r;r++){var i=arguments[r];_(i,t)&&(t=i)}return t}function K(t){if(1!=arguments.length)throw o("acos",arguments.length,1);if(r(t))return t>=-1&&1>=t?Math.acos(t):K(new e(t,0));if(t instanceof e){var n=new e(t.im*t.im-t.re*t.re+1,-2*t.re*t.im),i=q(n),a=new e(i.re-t.im,i.im+t.re),f=w(a);return new e(1.5707963267948966-f.im,f.re)}if(t instanceof Array)return Ot.map(t,K);if(t.valueOf()!==t)return K(t.valueOf());throw s("acos",t)}function W(t){if(1!=arguments.length)throw o("asin",arguments.length,1);if(r(t))return t>=-1&&1>=t?Math.asin(t):W(new e(t,0));if(t instanceof e){var n=t.re,i=t.im,a=new e(i*i-n*n+1,-2*n*i),f=q(a),u=new e(f.re-i,f.im+n),l=w(u);return new e(l.im,-l.re)}if(t instanceof Array)return Ot.map(t,W);if(t.valueOf()!==t)return W(t.valueOf());throw s("asin",t)}function X(t){if(1!=arguments.length)throw o("atan",arguments.length,1);if(r(t))return Math.atan(t);if(t instanceof e){var n=t.re,i=t.im,a=n*n+(1-i)*(1-i),f=new e((1-i*i-n*n)/a,-2*n/a),u=w(f);return new e(-.5*u.im,.5*u.re)}if(t instanceof Array)return Ot.map(t,X);if(t.valueOf()!==t)return X(t.valueOf());throw s("atan",t)}function Z(t,n){if(2!=arguments.length)throw o("atan2",arguments.length,2);if(r(t)){if(r(n))return Math.atan2(t,n);if(n instanceof e)return Math.atan2(t,n.re)}else if(t instanceof e){if(r(n))return Math.atan2(t.re,n);if(n instanceof e)return Math.atan2(t.re,n.re)}if(n instanceof Array||t instanceof Array)return Ot.map2(t,n,Z);if(n.valueOf()!==n||t.valueOf()!==t)return Z(t.valueOf(),n.valueOf());throw s("atan2",t,n)}function Q(t){if(1!=arguments.length)throw o("cos",arguments.length,1);if(r(t))return Math.cos(t);if(t instanceof e)return new e(.5*Math.cos(t.re)*(Math.exp(-t.im)+Math.exp(t.im)),.5*Math.sin(t.re)*(Math.exp(-t.im)-Math.exp(t.im)));if(t instanceof a){if(!t.hasBase(a.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(t.value)}if(t instanceof Array)return Ot.map(t,Q);if(t.valueOf()!==t)return Q(t.valueOf());throw s("cos",t)}function J(t){if(1!=arguments.length)throw o("cot",arguments.length,1);if(r(t))return 1/Math.tan(t);if(t instanceof e){var n=Math.exp(-4*t.im)-2*Math.exp(-2*t.im)*Math.cos(2*t.re)+1;return new e(2*Math.exp(-2*t.im)*Math.sin(2*t.re)/n,(Math.exp(-4*t.im)-1)/n)}if(t instanceof a){if(!t.hasBase(a.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(t.value)}if(t instanceof Array)return Ot.map(t,J);if(t.valueOf()!==t)return J(t.valueOf());throw s("cot",t)}function $(t){if(1!=arguments.length)throw o("csc",arguments.length,1);if(r(t))return 1/Math.sin(t);if(t instanceof e){var n=.25*(Math.exp(-2*t.im)+Math.exp(2*t.im))-.5*Math.cos(2*t.re);return new e(.5*Math.sin(t.re)*(Math.exp(-t.im)+Math.exp(t.im))/n,.5*Math.cos(t.re)*(Math.exp(-t.im)-Math.exp(t.im))/n)}if(t instanceof a){if(!t.hasBase(a.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(t.value)}if(t instanceof Array)return Ot.map(t,$);if(t.valueOf()!==t)return $(t.valueOf());throw s("csc",t)}function et(t){if(1!=arguments.length)throw o("sec",arguments.length,1);if(r(t))return 1/Math.cos(t);if(t instanceof e){var n=.25*(Math.exp(-2*t.im)+Math.exp(2*t.im))+.5*Math.cos(2*t.re);return new e(.5*Math.cos(t.re)*(Math.exp(-t.im)+Math.exp(t.im))/n,.5*Math.sin(t.re)*(Math.exp(t.im)-Math.exp(-t.im))/n)}if(t instanceof a){if(!t.hasBase(a.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(t.value)}if(t instanceof Array)return Ot.map(t,et);if(t.valueOf()!==t)return et(t.valueOf());throw s("sec",t)}function tt(t){if(1!=arguments.length)throw o("sin",arguments.length,1);if(r(t))return Math.sin(t);if(t instanceof e)return new e(.5*Math.sin(t.re)*(Math.exp(-t.im)+Math.exp(t.im)),.5*Math.cos(t.re)*(Math.exp(t.im)-Math.exp(-t.im)));if(t instanceof a){if(!t.hasBase(a.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(t.value)}if(t instanceof Array)return Ot.map(t,tt);if(t.valueOf()!==t)return tt(t.valueOf());throw s("sin",t)}function rt(t){if(1!=arguments.length)throw o("tan",arguments.length,1);if(r(t))return Math.tan(t);if(t instanceof e){var n=Math.exp(-4*t.im)+2*Math.exp(-2*t.im)*Math.cos(2*t.re)+1;return new e(2*Math.exp(-2*t.im)*Math.sin(2*t.re)/n,(1-Math.exp(-4*t.im))/n)}if(t instanceof a){if(!t.hasBase(a.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(t.value)}if(t instanceof Array)return Ot.map(t,rt);if(t.valueOf()!==t)return rt(t.valueOf());throw s("tan",t)}function nt(e,t){if(2!=arguments.length)throw o("in",arguments.length,2);if(e instanceof a&&t instanceof a){if(!e.equalBase(t))throw Error("Units do not match");if(t.hasValue)throw Error("Cannot convert to a unit with a value");if(!t.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=t.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||t instanceof Array)return Ot.map2(e,t,nt);if(e.valueOf()!==e)return Nt.in(e.valueOf());throw s("in",e)}function it(e,t){var n=arguments.length;if(1!=n&&2!=n)throw o("format",n,1,2);if(1==n){var a=arguments[0];return r(a)?Ot.format(a):a instanceof Array?at(a):i(a)?'"'+a+'"':a instanceof Object?""+a:a+""}if(!i(e))throw new TypeError("String expected as first parameter in function format");if(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,r){for(var n=r.split("."),i=t[n.shift()];n.length&&void 0!=i;){var a=n.shift();i=a?i[a]:i+"."}return void 0!=i?i:e})}function at(e){var t="[",r=Ot.array.validatedSize(e);if(2!=r.length)return st(e);for(var n=r[0],i=r[1],a=0;n>a;a++){0!=a&&(t+="; ");for(var s=e[a],o=0;i>o;o++){0!=o&&(t+=", ");var f=s[o];void 0!=f&&(t+=it(f))}}return t+="]"}function st(e){if(e instanceof Array){for(var t="[",r=e.length,n=0;r>n;n++)0!=n&&(t+=", "),t+=st(e[n]);return t+="]"}return it(e)}function ot(e){if(1!=arguments.length)throw o("help",arguments.length,1);if(void 0!=e){if(e.doc)return ft(e.doc);if(e.constructor.doc)return ft(e.constructor.doc);if(i(e)){var t=Nt[e];if(t&&t.doc)return ft(t.doc)}}return e instanceof Object&&e.name?'No documentation found on subject "'+e.name+'"':e instanceof Object&&e.constructor.name?'No documentation found on subject "'+e.constructor.name+'"':'No documentation found on subject "'+e+'"'}function ft(e){var t="";if(e.name&&(t+="NAME\n"+e.name+"\n\n"),e.category&&(t+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(t+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var r=new Nt.parser.Parser;t+="EXAMPLES\n";for(var n=0;e.examples.length>n;n++){var i,a=e.examples[n];try{i=r.eval(a)}catch(s){i=s}t+=a+"\n",t+=" "+Nt.format(i)+"\n"}t+="\n"}return e.seealso&&(t+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),t}function ut(e,t){var r;if(i(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var n=require(e);ut(n)}else if(lt(e)){if(r=e.name,!r)throw Error("Cannot import an unnamed function");(t||void 0===Nt[r])&&(Nt[r]=e)}else if(e instanceof Object)for(r in e)if(e.hasOwnProperty(r)){var a=e[r];lt(a)?(t||void 0===Nt[r])&&(Nt[r]=a):ut(a)}}function lt(t){return"function"==typeof t||r(t)||i(t)||t instanceof e||t instanceof a}function ht(e){if(1!=arguments.length)throw o("typeof",arguments.length,1);var t=typeof e;if("object"==t){if(null==e)return"null";if(e.constructor){for(var r in Nt)if(Nt.hasOwnProperty(r)&&e.constructor==Nt[r])return r.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t}function ct(){}function pt(e,t,r){this.name=e,this.fn=t,this.params=r}function mt(e){this.value=e}function vt(e){this.nodes=e||[]}function dt(){this.params=[],this.visible=[]}function gt(e,t,r,n){this.name=e,this.params=t,this.expr=r,this.result=n}function yt(e,t,r,n,i){this.name=e,this.variables=r,this.values=[];for(var a=0,s=this.variables.length;s>a;a++)this.values[a]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,t,r,n),this.result=i}function xt(e){this.parentScope=e,this.nestedScopes=void 0,this.symbols={},this.defs={},this.updates={},this.links={}}function wt(){if(this.constructor!=wt)throw new SyntaxError("Parser constructor must be called with the new operator");this.TOKENTYPE={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},this.expr="",this.index=0,this.c="",this.token="",this.token_type=this.TOKENTYPE.NULL,this.scope=new xt}function Et(){this.idMax=-1,this.updateSeq=0,this.parser=new wt,this.scope=new xt,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}var Nt={parser:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=Nt),"undefined"!=typeof exports&&(exports=Nt),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return Nt}),"undefined"!=typeof window&&(window.math=Nt);var Ot={};Ot.format=function it(e,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var r=Math.abs(e);if(r>1e-4&&1e6>r||0==r)return A(e,t)+"";var n=Math.round(Math.log(r)/Math.LN10),i=e/Math.pow(10,n);return A(i,t)+"E"+n},Ot.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},Ot.map=function(e,t){if(!e instanceof Array)throw new TypeError("Array expected");return e.map(function(e){return t(e)})},Ot.map2=function(e,t,r){var n,i,a;if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw Error("Dimension mismatch ("+e.length+" != "+t.length+")");for(n=[],i=e.length,a=0;i>a;a++)n[a]=r(e[a],t[a])}else for(n=[],i=e.length,a=0;i>a;a++)n[a]=r(e[a],t);else if(t instanceof Array)for(n=[],i=t.length,a=0;i>a;a++)n[a]=r(e,t[a]);else n=r(e,t);return n},Ot.array={},Ot.array.size=function Y(e){if(e instanceof Array){var t=e.length;if(t){var r=Ot.array.size(e[0]);return[t].concat(r)}return[t]}return[]},Ot.array.validate=function bt(e,t,r){var n,i=e.length;if(r||(r=0),i!=t[r])throw Error("Dimension mismatch ("+i+" != "+t[r]+")");if(t.length-1>r){var a=r+1;for(n=0;i>n;n++){var s=e[n];if(!(s instanceof Array))throw Error("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");bt(e[n],t,a)}}else for(n=0;i>n;n++)if(e[n]instanceof Array)throw Error("Dimension mismatch ("+(t.length+1)+" > "+t.length+")");return!0},Ot.array.validatedSize=function(e){var t=Ot.array.size(e);return Ot.array.validate(e,t),t},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;this.length>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var r=0,n=this.length;n>r;++r)e.call(t||this,this[r],r,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var r,n,i;if(null==this)throw new TypeError(" this is null or not defined");var a=Object(this),s=a.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(t&&(r=t),n=Array(s),i=0;s>i;){var o,f;i in a&&(o=a[i],f=e.call(r,o,i,a),n[i]=f),i++}return n}),Nt.Complex=e,function(){function t(){for(;" "==h||" "==h;)a()}function r(e){return e>="0"&&"9">=e||"."==e}function n(e){return e>="0"&&"9">=e}function a(){l++,h=u[l]}function s(e){l=e,h=u[l]}function o(){var e="",t=l;if("+"==h?a():"-"==h&&(e+=h,a()),!r(h))return s(t),null;for(;r(h);)e+=h,a();if("E"==h||"e"==h){if(e+=h,a(),("+"==h||"-"==h)&&(e+=h,a()),!n(h))return s(t),null;for(;n(h);)e+=h,a()}return e}function f(){var e=u[l+1];if("I"==h||"i"==h)return a(),"1";if(!("+"!=h&&"-"!=h||"I"!=e&&"i"!=e)){var t="+"==h?"1":"-1";return a(),a(),t}return null}var u,l,h;e.parse=function(r){if(u=r,l=-1,h="",!i(u))return null;a(),t();var n=o();if(n){if("I"==h||"i"==h)return a(),t(),h?null:new e(0,Number(n));t();var s=h;if("+"!=s&&"-"!=s)return t(),h?null:new e(Number(n),0);a(),t();var c=o();if(c){if("I"!=h&&"i"!=h)return null;a()}else if(c=f(),!c)return null;return"-"==s&&(c="-"==c[0]?"+"+c.substring(1):"-"+c),a(),t(),h?null:new e(Number(n),Number(c))}return(n=f())?(t(),h?null:new e(0,Number(n))):null}}(),e.prototype.clone=function(){return new e(this.re,this.im)},e.prototype.toString=function(){var e="";return e=0==this.im?Ot.format(this.re):0==this.re?1==this.im?"i":-1==this.im?"-i":Ot.format(this.im)+"i":this.im>0?1==this.im?Ot.format(this.re)+" + i":Ot.format(this.re)+" + "+Ot.format(this.im)+"i":-1==this.im?Ot.format(this.re)+" - i":Ot.format(this.re)+" - "+Ot.format(Math.abs(this.im))+"i"},e.doc={name:"Complex",category:"type",syntax:["a + bi","a + b * i"],description:"A complex value a + bi, where a is the real part and b is the complex part, and i is the imaginary number defined as sqrt(-1).",examples:["2 + 3i","sqrt(-4)","(1.2 -5i) * 2"],seealso:["abs","arg","conj","im","re"]},Nt.Matrix=t,t.prototype.size=function(){return Ot.array.validatedSize(this.array)},t.prototype.toScalar=function(){for(var e=this.array;e instanceof Array&&1==e.length;)e=e[0];return e instanceof Array?null:e},t.prototype.isScalar=function(){for(var e=this.array;e instanceof Array&&1==e.length;)e=array[0];return!(e instanceof Array)},t.prototype.toVector=function(){var e=Ot.array.validatedSize(this.array);if(2!=e.length)return null;if(1!=e[0]&&1!=e[1])return null;if(1==e[0])return this.array[0].concat();var t=[];return this.array.forEach(function(e,r){t[r]=e[0]}),t},t.prototype.isVector=function(){var e=Ot.array.validatedSize(this.array);return 2!=e.length?!1:1==e[0]||1==e[1]},t.prototype.valueOf=function(){return this.array},Nt.Unit=a,function(){function e(){for(;" "==h||" "==h;)n()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function n(){l++,h=u[l]}function s(e){l=e,h=u[l]}function o(){var e="",i=l;if("+"==h?n():"-"==h&&(e+=h,n()),!t(h))return s(i),null;for(;t(h);)e+=h,n();if("E"==h||"e"==h){if(e+=h,n(),("+"==h||"-"==h)&&(e+=h,n()),!r(h))return s(i),null;for(;r(h);)e+=h,n()}return e}function f(){var t="";for(e();h&&" "!=h&&" "!=h;)t+=h,n();return t||null}var u,l,h;a.parse=function(t){if(u=t,l=-1,h="",!i(u))return null;n(),e();var r,s=o();return s?(r=f(),n(),e(),h?null:s&&r?new a(Number(s),r):null):(r=f(),n(),e(),h?null:new a(null,r))}}(),a.prototype.clone=function(){var e=new a;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},a.endsWith=function(e,t){var r=e.length-t.length,n=e.length;return e.substring(r,n)===t},a.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},a.prototype._unnormalize=function(e,t){return void 0===t?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/t-this.unit.offset},a.isUnit=function(e){for(var t=a.UNITS,r=t.length,n=0;r>n;n++){var i=t[n];if(a.endsWith(e,i.name)){var s=e.length-i.name.length;if(0==s)return!0;var o=e.substring(0,s),f=i.prefixes[o];if(void 0!==f)return!0
}}return!1},a.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},a.prototype.equalBase=function(e){return this.unit.base===e.unit.base},a.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},a.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),Ot.format(e)+" "+this.prefix.name+this.unit.name;var t=Math.abs(this.value/this.unit.value),r=a.PREFIX_NONE,n=Math.abs(Math.log(t/r.value)/Math.LN10-1.2),i=this.unit.prefixes;for(var s in i)if(i.hasOwnProperty(s)){var o=i[s];if(o.scientific){var f=Math.abs(Math.log(t/o.value)/Math.LN10-1.2);n>f&&(r=o,n=f)}}return e=this._unnormalize(this.value,r.value),Ot.format(e)+" "+r.name+this.unit.name},a.PREFIXES={NONE:{"":{name:"",value:1,scientific:!0}},SHORT:{"":{name:"",value:1,scientific:!0},da:{name:"da",value:10,scientific:!1},h:{name:"h",value:100,scientific:!1},k:{name:"k",value:1e3,scientific:!0},M:{name:"M",value:1e6,scientific:!0},G:{name:"G",value:1e9,scientific:!0},T:{name:"T",value:1e12,scientific:!0},P:{name:"P",value:1e15,scientific:!0},E:{name:"E",value:1e18,scientific:!0},Z:{name:"Z",value:1e21,scientific:!0},Y:{name:"Y",value:1e24,scientific:!0},d:{name:"d",value:.1,scientific:!1},c:{name:"c",value:.01,scientific:!1},m:{name:"m",value:.001,scientific:!0},u:{name:"u",value:1e-6,scientific:!0},n:{name:"n",value:1e-9,scientific:!0},p:{name:"p",value:1e-12,scientific:!0},f:{name:"f",value:1e-15,scientific:!0},a:{name:"a",value:1e-18,scientific:!0},z:{name:"z",value:1e-21,scientific:!0},y:{name:"y",value:1e-24,scientific:!0}},LONG:{"":{name:"",value:1,scientific:!0},deca:{name:"deca",value:10,scientific:!1},hecto:{name:"hecto",value:100,scientific:!1},kilo:{name:"kilo",value:1e3,scientific:!0},mega:{name:"mega",value:1e6,scientific:!0},giga:{name:"giga",value:1e9,scientific:!0},tera:{name:"tera",value:1e12,scientific:!0},peta:{name:"peta",value:1e15,scientific:!0},exa:{name:"exa",value:1e18,scientific:!0},zetta:{name:"zetta",value:1e21,scientific:!0},yotta:{name:"yotta",value:1e24,scientific:!0},deci:{name:"deci",value:.1,scientific:!1},centi:{name:"centi",value:.01,scientific:!1},milli:{name:"milli",value:.001,scientific:!0},micro:{name:"micro",value:1e-6,scientific:!0},nano:{name:"nano",value:1e-9,scientific:!0},pico:{name:"pico",value:1e-12,scientific:!0},femto:{name:"femto",value:1e-15,scientific:!0},atto:{name:"atto",value:1e-18,scientific:!0},zepto:{name:"zepto",value:1e-21,scientific:!0},yocto:{name:"yocto",value:1e-24,scientific:!0}},BINARY_SHORT:{"":{name:"",value:1,scientific:!0},k:{name:"k",value:1024,scientific:!0},M:{name:"M",value:Math.pow(1024,2),scientific:!0},G:{name:"G",value:Math.pow(1024,3),scientific:!0},T:{name:"T",value:Math.pow(1024,4),scientific:!0},P:{name:"P",value:Math.pow(1024,5),scientific:!0},E:{name:"E",value:Math.pow(1024,6),scientific:!0},Z:{name:"Z",value:Math.pow(1024,7),scientific:!0},Y:{name:"Y",value:Math.pow(1024,8),scientific:!0},Ki:{name:"Ki",value:1024,scientific:!0},Mi:{name:"Mi",value:Math.pow(1024,2),scientific:!0},Gi:{name:"Gi",value:Math.pow(1024,3),scientific:!0},Ti:{name:"Ti",value:Math.pow(1024,4),scientific:!0},Pi:{name:"Pi",value:Math.pow(1024,5),scientific:!0},Ei:{name:"Ei",value:Math.pow(1024,6),scientific:!0},Zi:{name:"Zi",value:Math.pow(1024,7),scientific:!0},Yi:{name:"Yi",value:Math.pow(1024,8),scientific:!0}},BINARY_LONG:{"":{name:"",value:1,scientific:!0},kilo:{name:"kilo",value:1024,scientific:!0},mega:{name:"mega",value:Math.pow(1024,2),scientific:!0},giga:{name:"giga",value:Math.pow(1024,3),scientific:!0},tera:{name:"tera",value:Math.pow(1024,4),scientific:!0},peta:{name:"peta",value:Math.pow(1024,5),scientific:!0},exa:{name:"exa",value:Math.pow(1024,6),scientific:!0},zetta:{name:"zetta",value:Math.pow(1024,7),scientific:!0},yotta:{name:"yotta",value:Math.pow(1024,8),scientific:!0},kibi:{name:"kibi",value:1024,scientific:!0},mebi:{name:"mebi",value:Math.pow(1024,2),scientific:!0},gibi:{name:"gibi",value:Math.pow(1024,3),scientific:!0},tebi:{name:"tebi",value:Math.pow(1024,4),scientific:!0},pebi:{name:"pebi",value:Math.pow(1024,5),scientific:!0},exi:{name:"exi",value:Math.pow(1024,6),scientific:!0},zebi:{name:"zebi",value:Math.pow(1024,7),scientific:!0},yobi:{name:"yobi",value:Math.pow(1024,8),scientific:!0}}},a.PREFIX_NONE={name:"",value:1,scientific:!0},a.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var Mt=a.BASE_UNITS,Tt=a.PREFIXES;a.BASE_UNIT_NONE={},a.UNIT_NONE={name:"",base:a.BASE_UNIT_NONE,value:1,offset:0},a.UNITS=[{name:"meter",base:Mt.LENGTH,prefixes:Tt.LONG,value:1,offset:0},{name:"inch",base:Mt.LENGTH,prefixes:Tt.NONE,value:.0254,offset:0},{name:"foot",base:Mt.LENGTH,prefixes:Tt.NONE,value:.3048,offset:0},{name:"yard",base:Mt.LENGTH,prefixes:Tt.NONE,value:.9144,offset:0},{name:"mile",base:Mt.LENGTH,prefixes:Tt.NONE,value:1609.344,offset:0},{name:"link",base:Mt.LENGTH,prefixes:Tt.NONE,value:.201168,offset:0},{name:"rod",base:Mt.LENGTH,prefixes:Tt.NONE,value:5.02921,offset:0},{name:"chain",base:Mt.LENGTH,prefixes:Tt.NONE,value:20.1168,offset:0},{name:"angstrom",base:Mt.LENGTH,prefixes:Tt.NONE,value:1e-10,offset:0},{name:"m",base:Mt.LENGTH,prefixes:Tt.SHORT,value:1,offset:0},{name:"ft",base:Mt.LENGTH,prefixes:Tt.NONE,value:.3048,offset:0},{name:"yd",base:Mt.LENGTH,prefixes:Tt.NONE,value:.9144,offset:0},{name:"mi",base:Mt.LENGTH,prefixes:Tt.NONE,value:1609.344,offset:0},{name:"li",base:Mt.LENGTH,prefixes:Tt.NONE,value:.201168,offset:0},{name:"rd",base:Mt.LENGTH,prefixes:Tt.NONE,value:5.02921,offset:0},{name:"ch",base:Mt.LENGTH,prefixes:Tt.NONE,value:20.1168,offset:0},{name:"mil",base:Mt.LENGTH,prefixes:Tt.NONE,value:254e-7,offset:0},{name:"m2",base:Mt.SURFACE,prefixes:Tt.SHORT,value:1,offset:0},{name:"sqin",base:Mt.SURFACE,prefixes:Tt.NONE,value:64516e-8,offset:0},{name:"sqft",base:Mt.SURFACE,prefixes:Tt.NONE,value:.09290304,offset:0},{name:"sqyd",base:Mt.SURFACE,prefixes:Tt.NONE,value:.83612736,offset:0},{name:"sqmi",base:Mt.SURFACE,prefixes:Tt.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:Mt.SURFACE,prefixes:Tt.NONE,value:25.29295,offset:0},{name:"sqch",base:Mt.SURFACE,prefixes:Tt.NONE,value:404.6873,offset:0},{name:"sqmil",base:Mt.SURFACE,prefixes:Tt.NONE,value:6.4516e-10,offset:0},{name:"m3",base:Mt.VOLUME,prefixes:Tt.SHORT,value:1,offset:0},{name:"L",base:Mt.VOLUME,prefixes:Tt.SHORT,value:.001,offset:0},{name:"litre",base:Mt.VOLUME,prefixes:Tt.LONG,value:.001,offset:0},{name:"cuin",base:Mt.VOLUME,prefixes:Tt.NONE,value:16387064e-12,offset:0},{name:"cuft",base:Mt.VOLUME,prefixes:Tt.NONE,value:.028316846592,offset:0},{name:"cuyd",base:Mt.VOLUME,prefixes:Tt.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:Mt.VOLUME,prefixes:Tt.NONE,value:5e-6,offset:0},{name:"tablespoon",base:Mt.VOLUME,prefixes:Tt.NONE,value:15e-6,offset:0},{name:"minim",base:Mt.VOLUME,prefixes:Tt.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:Mt.VOLUME,prefixes:Tt.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:Mt.VOLUME,prefixes:Tt.NONE,value:2957353e-11,offset:0},{name:"gill",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0001182941,offset:0},{name:"cup",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0002365882,offset:0},{name:"pint",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0004731765,offset:0},{name:"quart",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0009463529,offset:0},{name:"gallon",base:Mt.VOLUME,prefixes:Tt.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1589873,offset:0},{name:"hogshead",base:Mt.VOLUME,prefixes:Tt.NONE,value:.238481,offset:0},{name:"fldr",base:Mt.VOLUME,prefixes:Tt.NONE,value:36966911e-13,offset:0},{name:"floz",base:Mt.VOLUME,prefixes:Tt.NONE,value:2957353e-11,offset:0},{name:"gi",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0001182941,offset:0},{name:"cp",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0002365882,offset:0},{name:"pt",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0004731765,offset:0},{name:"qt",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0009463529,offset:0},{name:"gal",base:Mt.VOLUME,prefixes:Tt.NONE,value:.003785412,offset:0},{name:"bbl",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1173478,offset:0},{name:"obl",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1589873,offset:0},{name:"g",base:Mt.MASS,prefixes:Tt.SHORT,value:.001,offset:0},{name:"gram",base:Mt.MASS,prefixes:Tt.LONG,value:.001,offset:0},{name:"ton",base:Mt.MASS,prefixes:Tt.SHORT,value:907.18474,offset:0},{name:"tonne",base:Mt.MASS,prefixes:Tt.SHORT,value:1e3,offset:0},{name:"grain",base:Mt.MASS,prefixes:Tt.NONE,value:6479891e-11,offset:0},{name:"dram",base:Mt.MASS,prefixes:Tt.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:Mt.MASS,prefixes:Tt.NONE,value:.028349523125,offset:0},{name:"poundmass",base:Mt.MASS,prefixes:Tt.NONE,value:.45359237,offset:0},{name:"hundredweight",base:Mt.MASS,prefixes:Tt.NONE,value:45.359237,offset:0},{name:"stick",base:Mt.MASS,prefixes:Tt.NONE,value:.115,offset:0},{name:"gr",base:Mt.MASS,prefixes:Tt.NONE,value:6479891e-11,offset:0},{name:"dr",base:Mt.MASS,prefixes:Tt.NONE,value:.0017718451953125,offset:0},{name:"oz",base:Mt.MASS,prefixes:Tt.NONE,value:.028349523125,offset:0},{name:"lbm",base:Mt.MASS,prefixes:Tt.NONE,value:.45359237,offset:0},{name:"cwt",base:Mt.MASS,prefixes:Tt.NONE,value:45.359237,offset:0},{name:"s",base:Mt.TIME,prefixes:Tt.SHORT,value:1,offset:0},{name:"min",base:Mt.TIME,prefixes:Tt.NONE,value:60,offset:0},{name:"h",base:Mt.TIME,prefixes:Tt.NONE,value:3600,offset:0},{name:"seconds",base:Mt.TIME,prefixes:Tt.LONG,value:1,offset:0},{name:"second",base:Mt.TIME,prefixes:Tt.LONG,value:1,offset:0},{name:"sec",base:Mt.TIME,prefixes:Tt.LONG,value:1,offset:0},{name:"minutes",base:Mt.TIME,prefixes:Tt.NONE,value:60,offset:0},{name:"minute",base:Mt.TIME,prefixes:Tt.NONE,value:60,offset:0},{name:"hours",base:Mt.TIME,prefixes:Tt.NONE,value:3600,offset:0},{name:"hour",base:Mt.TIME,prefixes:Tt.NONE,value:3600,offset:0},{name:"day",base:Mt.TIME,prefixes:Tt.NONE,value:86400,offset:0},{name:"days",base:Mt.TIME,prefixes:Tt.NONE,value:86400,offset:0},{name:"rad",base:Mt.ANGLE,prefixes:Tt.NONE,value:1,offset:0},{name:"deg",base:Mt.ANGLE,prefixes:Tt.NONE,value:.017453292519943295,offset:0},{name:"grad",base:Mt.ANGLE,prefixes:Tt.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:Mt.ANGLE,prefixes:Tt.NONE,value:6.283185307179586,offset:0},{name:"A",base:Mt.CURRENT,prefixes:Tt.SHORT,value:1,offset:0},{name:"ampere",base:Mt.CURRENT,prefixes:Tt.LONG,value:1,offset:0},{name:"K",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:0},{name:"degC",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:273.15},{name:"degF",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:459.67},{name:"degR",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:0},{name:"kelvin",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:0},{name:"celsius",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:273.15},{name:"fahrenheit",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:0},{name:"mol",base:Mt.AMOUNT_OF_SUBSTANCE,prefixes:Tt.NONE,value:1,offset:0},{name:"mole",base:Mt.AMOUNT_OF_SUBSTANCE,prefixes:Tt.NONE,value:1,offset:0},{name:"cd",base:Mt.LUMINOUS_INTENSITY,prefixes:Tt.NONE,value:1,offset:0},{name:"candela",base:Mt.LUMINOUS_INTENSITY,prefixes:Tt.NONE,value:1,offset:0},{name:"N",base:Mt.FORCE,prefixes:Tt.SHORT,value:1,offset:0},{name:"newton",base:Mt.FORCE,prefixes:Tt.LONG,value:1,offset:0},{name:"lbf",base:Mt.FORCE,prefixes:Tt.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:Mt.FORCE,prefixes:Tt.NONE,value:4.4482216152605,offset:0},{name:"b",base:Mt.BIT,prefixes:Tt.BINARY_SHORT,value:1,offset:0},{name:"bits",base:Mt.BIT,prefixes:Tt.BINARY_LONG,value:1,offset:0},{name:"B",base:Mt.BIT,prefixes:Tt.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:Mt.BIT,prefixes:Tt.BINARY_LONG,value:8,offset:0}],Nt.E=Math.E,Nt.LN2=Math.LN2,Nt.LN10=Math.LN10,Nt.LOG2E=Math.LOG2E,Nt.LOG10E=Math.LOG10E,Nt.PI=Math.PI,Nt.SQRT1_2=Math.SQRT1_2,Nt.SQRT2=Math.SQRT2,Nt.I=new e(0,-1),Nt.pi=Nt.PI,Nt.e=Nt.E,Nt.i=Nt.I,Nt.abs=f,f.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},Nt.add=u,u.doc={name:"add",category:"Operators",syntax:["x + y","add(x, y)"],description:"Add two values.",examples:["2.1 + 3.6","ans - 3.6","3 + 2i",'"hello" + " world"',"3 cm + 2 inch"],seealso:["subtract"]},Nt.ceil=l,l.doc={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]},Nt.cube=h,h.doc={name:"cube",category:"Arithmetic",syntax:["cube(x)"],description:"Compute the cube of a value. The cube of x is x * x * x.",examples:["cube(2)","2^3","2 * 2 * 2"],seealso:["multiply","square","pow"]},Nt.divide=c,c.doc={name:"divide",category:"Operators",syntax:["x / y","divide(x, y)"],description:"Divide two values.",examples:["2 / 3","ans * 3","4.5 / 2","3 + 4 / 2","(3 + 4) / 2","18 km / 4.5"],seealso:["multiply"]},Nt.equal=m,m.doc={name:"equal",category:"Operators",syntax:["x == y","equal(x, y)"],description:"Check equality of two values. Returns 1 if the values are equal, and 0 if not.",examples:["2+2 == 3","2+2 == 4","a = 3.2","b = 6-2.8","a == b","50cm == 0.5m"],seealso:["unequal","smaller","larger","smallereq","largereq"]},Nt.exp=v,v.doc={name:"exp",category:"Arithmetic",syntax:["exp(x)"],description:"Calculate the exponent of a value.",examples:["exp(1.3)","e ^ 1.3","log(exp(1.3))","x = 2.4","(exp(i*x) == cos(x) + i*sin(x)) # Euler's formula"],seealso:["square","multiply","log"]},Nt.fix=d,d.doc={name:"fix",category:"Arithmetic",syntax:["fix(x)"],description:"Round a value towards zero.If x is complex, both real and imaginary part are rounded towards zero.",examples:["fix(3.2)","fix(3.8)","fix(-4.2)","fix(-4.8)"],seealso:["ceil","floor","round"]},Nt.floor=g,g.doc={name:"floor",category:"Arithmetic",syntax:["floor(x)"],description:"Round a value towards minus infinity.If x is complex, both real and imaginary part are rounded towards minus infinity.",examples:["floor(3.2)","floor(3.8)","floor(-4.2)"],seealso:["ceil","fix","round"]},Nt.larger=y,y.doc={name:"larger",category:"Operators",syntax:["x > y","larger(x, y)"],description:"Check if value x is larger than y. Returns 1 if x is larger than y, and 0 if not.",examples:["2 > 3","5 > 2*2","a = 3.3","b = 6-2.8","(a > b)","(b < a)","5 cm > 2 inch"],seealso:["equal","unequal","smaller","smallereq","largereq"]},Nt.largereq=x,x.doc={name:"largereq",category:"Operators",syntax:["x >= y","largereq(x, y)"],description:"Check if value x is larger or equal to y. Returns 1 if x is larger or equal to y, and 0 if not.",examples:["2 > 1+1","2 >= 1+1","a = 3.2","b = 6-2.8","(a > b)"],seealso:["equal","unequal","smallereq","smaller","largereq"]},Nt.log=w,w.doc={name:"log",category:"Arithmetic",syntax:["log(x)","log(x, base)"],description:"Compute the logarithm of a value. If no base is provided, the natural logarithm of x is calculated. If base if provided, the logarithm is calculated for the specified base. log(x, base) is defined as log(x) / log(base).",examples:["log(3.5)","a = log(2.4)","exp(a)","10 ^ 3","log(1000, 10)","log(1000) / log(10)","b = logb(1024, 2)","2 ^ b"],seealso:["exp","log10"]},Nt.log10=E,E.doc={name:"log10",category:"Arithmetic",syntax:["log10(x)"],description:"Compute the 10-base logarithm of a value.",examples:["log10(1000)","10 ^ 3","log10(0.01)","log(1000) / log(10)","log(1000, 10)"],seealso:["exp","log"]},Nt.mod=N,N.doc={name:"mod",category:"Operators",syntax:["x % y","x mod y","mod(x, y)"],description:"Calculates the modulus, the remainder of an integer division.",examples:["7 % 3","11 % 2","10 mod 4","function isOdd(x) = x % 2","isOdd(2)","isOdd(3)"],seealso:[]},Nt.multiply=O,O.doc={name:"multiply",category:"Operators",syntax:["x * y","multiply(x, y)"],description:"multiply two values.",examples:["2.1 * 3.6","ans / 3.6","2 * 3 + 4","2 * (3 + 4)","3 * 2.1 km"],seealso:["divide"]},Nt.pow=M,M.doc={name:"pow",category:"Operators",syntax:["x ^ y","pow(x, y)"],description:"Calculates the power of x to y, x^y.",examples:["2^3 = 8","2*2*2","1 + e ^ (pi * i)"],seealso:["unequal","smaller","larger","smallereq","largereq"]},Nt.round=S,S.doc={name:"round",category:"Arithmetic",syntax:["round(x)","round(x, n)"],description:"round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.",examples:["round(3.2)","round(3.8)","round(-4.2)","round(-4.8)","round(pi, 3)","round(123.45678, 2)"],seealso:["ceil","floor","fix"]},Nt.sign=k,k.doc={name:"sign",category:"Arithmetic",syntax:["sign(x)"],description:"Compute the sign of a value. The sign of a value x is 1 when x>1, -1 when x<0, and 0 when x=0.",examples:["sign(3.5)","sign(-4.2)","sign(0)"],seealso:["abs"]},Nt.smaller=_,_.doc={name:"smaller",category:"Operators",syntax:["x < y","smaller(x, y)"],description:"Check if value x is smaller than value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 3","5 < 2*2","a = 3.3","b = 6-2.8","(a < b)","5 cm < 2 inch"],seealso:["equal","unequal","larger","smallereq","largereq"]},Nt.smallereq=U,U.doc={name:"smallereq",category:"Operators",syntax:["x <= y","smallereq(x, y)"],description:"Check if value x is smaller or equal to value y. Returns 1 if x is smaller than y, and 0 if not.",examples:["2 < 1+1","2 <= 1+1","a = 3.2","b = 6-2.8","(a < b)"],seealso:["equal","unequal","larger","smaller","largereq"]},Nt.sqrt=q,q.doc={name:"sqrt",category:"Arithmetic",syntax:["sqrt(x)"],description:"Compute the square root value. If x = y * y, then y is the square root of x.",examples:["sqrt(25)","5 * 5","sqrt(-1)"],seealso:["square","multiply"]},Nt.square=L,L.doc={name:"square",category:"Arithmetic",syntax:["square(x)"],description:"Compute the square of a value. The square of x is x * x.",examples:["square(3)","sqrt(9)","3^2","3 * 3"],seealso:["multiply","pow","sqrt","cube"]},Nt.subtract=C,C.doc={name:"subtract",category:"Operators",syntax:["x - y","subtract(x, y)"],description:"subtract two values.",examples:["5.3 - 2","ans + 2","2/3 - 1/6","2 * 3 - 3","2.1 km - 500m"],seealso:["add"]},Nt.unaryminus=R,R.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},Nt.unequal=I,I.doc={name:"unequal",category:"Operators",syntax:["x != y","unequal(x, y)"],description:"Check unequality of two values. Returns 1 if the values are unequal, and 0 if they are equal.",examples:["2+2 != 3","2+2 != 4","a = 3.2","b = 6-2.8","a != b","50cm != 0.5m","5 cm != 2 inch"],seealso:["equal","smaller","larger","smallereq","largereq"]},Nt.arg=P,P.doc={name:"arg",category:"Complex",syntax:["arg(x)"],description:"Compute the argument of a complex value. If x = a+bi, the argument is computed as atan2(b, a).",examples:["arg(2 + 2i)","atan2(3, 2)","arg(2 - 3i)"],seealso:["re","im","conj","abs"]},Nt.conj=B,B.doc={name:"conj",category:"Complex",syntax:["conj(x)"],description:"Compute the complex conjugate of a complex value. If x = a+bi, the complex conjugate is a-bi.",examples:["conj(2 + 3i)","conj(2 - 3i)","conj(-5.2i)"],seealso:["re","im","abs","arg"]},Nt.im=G,G.doc={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]},Nt.re=z,z.doc={name:"re",category:"Complex",syntax:["re(x)"],description:"Get the real part of a complex number.",examples:["re(2 + 3i)","im(2 + 3i)","re(-5.2i)","re(2.4)"],seealso:["im","conj","abs","arg"]},Nt.eye=D,D.doc={name:"eye",category:"Matrix",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["diag","ones","range","size","transpose","zeros"]},Nt.size=Y,Y.doc={name:"size",category:"Matrix",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["diag","eye","ones","range","transpose","zeros"]},Nt.factorial=V,V.doc={name:"factorial",category:"Probability",syntax:["x!","factorial(x)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]},Nt.random=F,F.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},Nt.max=j,j.doc={name:"max",category:"Statistics",syntax:["max(a, b, c, ...)"],description:"Compute the maximum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},Nt.min=H,H.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},Nt.acos=K,K.doc={name:"acos",category:"Trigonometry",syntax:["acos(x)"],description:"Compute the inverse cosine of a value in radians.",examples:["acos(0.5)","acos(cos(2.3))"],seealso:["cos","acos","asin"]},Nt.asin=W,W.doc={name:"asin",category:"Trigonometry",syntax:["asin(x)"],description:"Compute the inverse sine of a value in radians.",examples:["asin(0.5)","asin(sin(2.3))"],seealso:["sin","acos","asin"]},Nt.atan=X,X.doc={name:"atan",category:"Trigonometry",syntax:["atan(x)"],description:"Compute the inverse tangent of a value in radians.",examples:["atan(0.5)","atan(tan(2.3))"],seealso:["tan","acos","asin"]},Nt.atan2=Z,Z.doc={name:"atan2",category:"Trigonometry",syntax:["atan2(y, x)"],description:"Computes the principal value of the arc tangent of y/x in radians.",examples:["atan2(2, 2) / pi","angle = 60 deg in rad","x = cos(angle)","y = sin(angle)","atan2(y, x)"],seealso:["sin","cos","tan"]},Nt.cos=Q,Q.doc={name:"cos",category:"Trigonometry",syntax:["cos(x)"],description:"Compute the cosine of x in radians.",examples:["cos(2)","cos(pi / 4) ^ 2","cos(180 deg)","cos(60 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["acos","sin","tan"]},Nt.cot=J,J.doc={name:"cot",category:"Trigonometry",syntax:["cot(x)"],description:"Compute the cotangent of x in radians. Defined as 1/tan(x)",examples:["cot(2)","1 / tan(2)"],seealso:["sec","csc","tan"]},Nt.csc=$,$.doc={name:"csc",category:"Trigonometry",syntax:["csc(x)"],description:"Compute the cosecant of x in radians. Defined as 1/sin(x)",examples:["csc(2)","1 / sin(2)"],seealso:["sec","cot","sin"]},Nt.sec=et,et.doc={name:"sec",category:"Trigonometry",syntax:["sec(x)"],description:"Compute the secant of x in radians. Defined as 1/cos(x)",examples:["sec(2)","1 / cos(2)"],seealso:["cot","csc","cos"]},Nt.sin=tt,tt.doc={name:"sin",category:"Trigonometry",syntax:["sin(x)"],description:"Compute the sine of x in radians.",examples:["sin(2)","sin(pi / 4) ^ 2","sin(90 deg)","sin(30 deg)","sin(0.2)^2 + cos(0.2)^2"],seealso:["asin","cos","tan"]},Nt.tan=rt,rt.doc={name:"tan",category:"Trigonometry",syntax:["tan(x)"],description:"Compute the tangent of x in radians.",examples:["tan(0.5)","sin(0.5) / cos(0.5)","tan(pi / 4)","tan(45 deg)"],seealso:["atan","sin","cos"]},Nt.in=nt,nt.doc={name:"in",category:"Units",syntax:["x in unit","in(x, unit)"],description:"Change the unit of a value.",examples:["5 inch in cm","3.2kg in g","16 bytes in bits"],seealso:[]},Nt.format=it,it.doc={name:"format",category:"Utils",syntax:["format(value)"],description:"Format a value of any type as string.",examples:["format(2.3)","format(3 - 4i)","format([])"],seealso:[]},Nt.help=ot,ot.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},Nt["import"]=ut,ut.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},Nt["typeof"]=ht,ht.doc={name:"typeof",category:"Utils",syntax:["typeof(x)"],description:"Get the type of a variable.",examples:["typeof(3.5)","typeof(2 - 4i)","typeof(45 deg)",'typeof("hello world")'],seealso:[]},Nt.parser.node.Node=ct,ct.prototype.eval=function(){throw Error("Cannot evaluate a Node interface")},ct.prototype.toString=function(){return""},pt.prototype=new ct,Nt.parser.node.Symbol=pt,pt.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},pt.prototype.eval=function(){var e=this.fn;if(void 0===e)throw Error("Undefined symbol "+this.name);var t=this.params.map(function(e){return e.eval()});return e.apply(this,t)},pt.prototype.toString=function(){if(this.name&&!this.params)return this.name;var e=this.name;return this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e},mt.prototype=new ct,Nt.parser.node.Constant=mt,mt.prototype.eval=function(){return this.value},mt.prototype.toString=function(){return this.value?Nt.format(this.value):""},vt.prototype=new ct,Nt.parser.node.ArrayNode=vt,function(){function e(t){return t.map(function(t){return t instanceof Array?e(t):t.eval()})}function t(e){if(e instanceof Array){for(var r="[",n=e.length,i=0;n>i;i++)0!=i&&(r+=", "),r+=t(e[i]);return r+="]"}return""+e}vt.prototype.eval=function(){return e(this.nodes)},vt.prototype.toString=function(){return t(this.nodes)}}(),dt.prototype=new ct,Nt.parser.node.Block=dt,dt.prototype.add=function(e,t){var r=this.params.length;this.params[r]=e,this.visible[r]=void 0!=t?t:!0},dt.prototype.eval=function(){for(var e=[],t=0,r=this.params.length;r>t;t++){var n=this.params[t].eval();this.visible[t]&&e.push(n)}return e},dt.prototype.toString=function(){for(var e=[],t=0,r=this.params.length;r>t;t++)this.visible[t]&&e.push("\n "+(""+this.params[t]));return"["+e.join(",")+"\n]"},gt.prototype=new ct,Nt.parser.node.Assignment=gt,gt.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,t=this.params;if(t&&t.length){var r=[];this.params.forEach(function(e){r.push(e.eval())});var n=this.expr.eval();if(void 0==this.result.value)throw Error("Undefined symbol "+this.name);var i=this.result.eval();e=i.set(r,n),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},gt.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},yt.prototype=new ct,Nt.parser.node.FunctionAssignment=yt,yt.prototype.createFunction=function(e,t,r,n){var i=function(){var t=r?r.length:0,i=arguments?arguments.length:0;if(t!=i)throw o(e,i,t);if(t>0)for(var a=0;t>a;a++)r[a].value=arguments[a];return n.eval()};return i.toString=function(){return e+"("+t.join(", ")+")"},i},yt.prototype.eval=function(){for(var e=this.variables,t=this.values,r=0,n=e.length;n>r;r++)e[r].value=t[r];return this.result.value=this.def,this.def},yt.prototype.toString=function(){return""+this.def},Nt.parser.node.Scope=xt,xt.prototype.createNestedScope=function(){var e=new xt(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(e),e},xt.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,t=0,r=e.length;r>t;t++)e[t].clear()},xt.prototype.createSymbol=function(e){var t=this.symbols[e];if(!t){var r=this.findDef(e);t=this.newSymbol(e,r),this.symbols[e]=t}return t},xt.prototype.newSymbol=function(e,t){var r=this,n=function(){if(!n.value&&(n.value=r.findDef(e),!n.value))throw Error("Undefined symbol "+e);return"function"==typeof n.value?n.value.apply(null,arguments):n.value};return n.value=t,n.toString=function(){return n.value?""+n.value:""},n},xt.prototype.createLink=function(e){var t=this.links[e];return t||(t=this.createSymbol(e),this.links[e]=t),t},xt.prototype.createDef=function(e,t){var r=this.defs[e];return r||(r=this.createSymbol(e),this.defs[e]=r),r&&void 0!=t&&(r.value=t),r},xt.prototype.createUpdate=function(e){var t=this.updates[e];return t||(t=this.createLink(e),this.updates[e]=t),t},xt.prototype.findDef=function(t){function r(e,t){var r=i(e,t);return s[e]=r,o[e]=r,r}var n;if(n=this.defs[t])return n;if(n=this.updates[t])return n;if(this.parentScope)return this.parentScope.findDef(t);var i=this.newSymbol,s=this.symbols,o=this.defs;if("pi"==t)return r(t,Nt.PI);if("e"==t)return r(t,Nt.E);if("i"==t)return r(t,new e(0,1));var f=Nt[t];if(f)return r(t,f);if(a.isUnit(t)){var u=new a(null,t);return r(t,u)}return void 0},xt.prototype.removeLink=function(e){delete this.links[e]},xt.prototype.removeDef=function(e){delete this.defs[e]},xt.prototype.removeUpdate=function(e){delete this.updates[e]},xt.prototype.init=function(){var e=this.symbols,t=this.parentScope;for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];n.value=t?t.findDef(r):void 0}this.nestedScopes&&this.nestedScopes.forEach(function(e){e.init()})},xt.prototype.hasLink=function(e){if(this.links[e])return!0;if(this.nestedScopes)for(var t=this.nestedScopes,r=0,n=t.length;n>r;r++)if(t[r].hasLink(e))return!0;return!1},xt.prototype.hasDef=function(e){return void 0!=this.defs[e]},xt.prototype.hasUpdate=function(e){return void 0!=this.updates[e]},xt.prototype.getUndefinedSymbols=function(){var e=this.symbols,t=[];for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];void 0==n.value&&t.push(n)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){t=t.concat(e.getUndefinedSymbols())}),t},Nt.parser.Parser=wt,wt.prototype.parse=function(e,t){return this.expr=e||"",t||(this.newScope(),t=this.scope),this.parse_start(t)},wt.prototype.eval=function(e){var t=this.parse(e);return t.eval()},wt.prototype.get=function(e){this.newScope();var t=this.scope.findDef(e);return t?t.value:void 0},wt.prototype.put=function(e,t){this.scope.createDef(e,t)},wt.prototype.newScope=function(){this.scope=new xt(this.scope)},wt.prototype.clear=function(){this.scope.clear()},wt.prototype.getChar=function(){this.index++,this.c=this.expr.charAt(this.index)},wt.prototype.getFirstChar=function(){this.index=0,this.c=this.expr.charAt(0)},wt.prototype.getToken=function(){for(this.token_type=this.TOKENTYPE.NULL,this.token="";" "==this.c||" "==this.c;)this.getChar();if("#"==this.c)for(;"\n"!=this.c&&""!=this.c;)this.getChar();if(""==this.c)return this.token_type=this.TOKENTYPE.DELIMITER,void 0;if("-"==this.c||","==this.c||"("==this.c||")"==this.c||"["==this.c||"]"==this.c||'"'==this.c||"\n"==this.c||";"==this.c||":"==this.c)return this.token_type=this.TOKENTYPE.DELIMITER,this.token+=this.c,this.getChar(),void 0;if(this.isDelimiter(this.c))for(this.token_type=this.TOKENTYPE.DELIMITER;this.isDelimiter(this.c);)this.token+=this.c,this.getChar();else if(this.isDigitDot(this.c)){for(this.token_type=this.TOKENTYPE.NUMBER;this.isDigitDot(this.c);)this.token+=this.c,this.getChar();if("E"==this.c||"e"==this.c)for(this.token+=this.c,this.getChar(),("+"==this.c||"-"==this.c)&&(this.token+=this.c,this.getChar()),this.isDigit(this.c)||(this.token_type=this.TOKENTYPE.UNKNOWN);this.isDigit(this.c);)this.token+=this.c,this.getChar()}else{if(!this.isAlpha(this.c)){for(this.token_type=this.TOKENTYPE.UNKNOWN;""!=this.c;)this.token+=this.c,this.getChar();throw this.createSyntaxError('Syntax error in part "'+this.token+'"')}for(this.token_type=this.TOKENTYPE.SYMBOL;this.isAlpha(this.c)||this.isDigit(this.c);)this.token+=this.c,this.getChar()}},wt.prototype.isDelimiter=function(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e
},wt.prototype.isValidSymbolName=function(e){for(var t=0,r=e.length;r>t;t++){var n=e.charAt(t),i=this.isAlpha(n);if(!i)return!1}return!0},wt.prototype.isAlpha=function(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e},wt.prototype.isDigitDot=function(e){return e>="0"&&"9">=e||"."==e},wt.prototype.isDigit=function(e){return e>="0"&&"9">=e},wt.prototype.parse_start=function(e){this.getFirstChar(),this.getToken();var t;if(t=""==this.token?new mt(void 0):this.parse_block(e),""!=this.token)throw this.token_type==this.TOKENTYPE.DELIMITER?this.createError("Unknown operator "+this.token):this.createSyntaxError('Unexpected part "'+this.token+'"');return t},wt.prototype.parse_ans=function(e){var t=this.parse_function_assignment(e);if(!(t instanceof gt)){var r="ans",n=void 0,i=e.createDef(r);return new gt(r,n,t,i)}return t},wt.prototype.parse_block=function(e){var t,r,n;for("\n"!=this.token&&";"!=this.token&&""!=this.token&&(t=this.parse_ans(e));"\n"==this.token||";"==this.token;)r||(r=new dt,t&&(n=";"!=this.token,r.add(t,n))),this.getToken(),"\n"!=this.token&&";"!=this.token&&""!=this.token&&(t=this.parse_ans(e),n=";"!=this.token,r.add(t,n));return r?r:(t||(t=this.parse_ans(e)),t)},wt.prototype.parse_function_assignment=function(e){if(this.token_type==this.TOKENTYPE.SYMBOL&&"function"==this.token){if(this.getToken(),this.token_type!=this.TOKENTYPE.SYMBOL)throw this.createSyntaxError("Function name expected");var t=this.token;if(this.getToken(),"("!=this.token)throw this.createSyntaxError("Opening parenthesis ( expected");for(var r=e.createNestedScope(),n=[],i=[];;){if(this.getToken(),this.token_type!=this.TOKENTYPE.SYMBOL)throw this.createSyntaxError("Variable name expected");var a=this.token,s=r.createDef(a);if(n.push(a),i.push(s),this.getToken(),","!=this.token){if(")"==this.token)break;throw this.createSyntaxError('Comma , or closing parenthesis ) expected"')}}if(this.getToken(),"="!=this.token)throw this.createSyntaxError("Equal sign = expected");this.getToken();var o=this.parse_range(r),f=e.createDef(t);return new yt(t,n,i,o,f)}return this.parse_assignment(e)},wt.prototype.parse_assignment=function(e){var t=!1;this.token_type==this.TOKENTYPE.SYMBOL&&(t=e.hasLink(this.token));var r=this.parse_range(e);if("="==this.token){if(!(r instanceof pt))throw this.createSyntaxError("Symbol expected at the left hand side of assignment operator =");var n=r.name,i=r.params;t||e.removeLink(n),this.getToken();var a=this.parse_range(e),s=r.hasParams()?e.createUpdate(n):e.createDef(n);return new gt(n,i,a,s)}return r},wt.prototype.parse_range=function(e){var t=this.parse_conditions(e);return t},wt.prototype.parse_conditions=function(e){for(var t=this.parse_bitwise_conditions(e),r={"in":"in"};void 0!==r[this.token];){var n=this.token,i=Nt[r[n]];this.getToken();var a=[t,this.parse_bitwise_conditions(e)];t=new pt(n,i,a)}return t},wt.prototype.parse_bitwise_conditions=function(e){var t=this.parse_comparison(e);return t},wt.prototype.parse_comparison=function(e){for(var t=this.parse_addsubtract(e),r={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==r[this.token];){var n=this.token,i=Nt[r[n]];this.getToken();var a=[t,this.parse_addsubtract(e)];t=new pt(n,i,a)}return t},wt.prototype.parse_addsubtract=function(e){for(var t=this.parse_multiplydivide(e),r={"+":"add","-":"subtract"};void 0!==r[this.token];){var n=this.token,i=Nt[r[n]];this.getToken();var a=[t,this.parse_multiplydivide(e)];t=new pt(n,i,a)}return t},wt.prototype.parse_multiplydivide=function(e){for(var t=this.parse_pow(e),r={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==r[this.token];){var n=this.token,i=Nt[r[n]];this.getToken();var a=[t,this.parse_pow(e)];t=new pt(n,i,a)}return t},wt.prototype.parse_pow=function(e){for(var t=this.parse_factorial(e);"^"==this.token;){var r=this.token,n=M;this.getToken();var i=[t,this.parse_factorial(e)];t=new pt(r,n,i)}return t},wt.prototype.parse_factorial=function(e){for(var t=this.parse_unaryminus(e);"!"==this.token;){var r=this.token,n=V;this.getToken();var i=[t];t=new pt(r,n,i)}return t},wt.prototype.parse_unaryminus=function(e){if("-"==this.token){var t=this.token,r=R;this.getToken();var n=[this.parse_plot(e)];return new pt(t,r,n)}return this.parse_plot(e)},wt.prototype.parse_plot=function(e){return this.parse_symbol(e)},wt.prototype.parse_symbol=function(e){if(this.token_type==this.TOKENTYPE.SYMBOL){var t=this.token;this.getToken();var r=e.createLink(t),n=this.parse_arguments(e),i=new pt(t,r,n);return i}return this.parse_string(e)},wt.prototype.parse_arguments=function(e){var t=[];if("("==this.token){if(this.getToken(),")"!=this.token)for(t.push(this.parse_range(e));","==this.token;)this.getToken(),t.push(this.parse_range(e));if(")"!=this.token)throw this.createSyntaxError("Parenthesis ) missing");this.getToken()}return t},wt.prototype.parse_string=function(e){if('"'==this.token){for(var t="",r="";""!=this.c&&('"'!=this.c||"\\"==r);)t+=this.c,r=this.c,this.getChar();if(this.getToken(),'"'!=this.token)throw this.createSyntaxError('End of string " missing');this.getToken();var n=new mt(t);return n}return this.parse_matrix(e)},wt.prototype.parse_matrix=function(e){if("["==this.token){var t;for(this.getToken();"\n"==this.token;)this.getToken();if("]"!=this.token){var r=[],n=0,i=0;for(r[0]=[this.parse_range(e)];","==this.token||";"==this.token;){for(","==this.token?i++:(n++,i=0,r[n]=[]),this.getToken();"\n"==this.token;)this.getToken();for(r[n][i]=this.parse_range(e);"\n"==this.token;)this.getToken()}var a=r.length,s=r.length>0?r[0].length:0;for(n=1;a>n;n++)if(r[n].length!=s)throw this.createError("Number of columns must match ("+r[n].length+" != "+s+")");if("]"!=this.token)throw this.createSyntaxError("End of matrix ] missing");this.getToken(),t=new vt(r)}else this.getToken(),t=new vt([]);for(;"("==this.token;)t=this.parse_arguments(e,t);return t}return this.parse_number(e)},wt.prototype.parse_number=function(t){if(this.token_type==this.TOKENTYPE.NUMBER){var r;r="."==this.token?0:Number(this.token),this.getToken();var n;if(this.token_type==this.TOKENTYPE.SYMBOL){if("i"==this.token||"I"==this.token)return n=new e(0,r),this.getToken(),new mt(n);if(a.isUnit(this.token))return n=new a(r,this.token),this.getToken(),new mt(n);throw this.createTypeError('Unknown unit "'+this.token+'"')}var i=new mt(r);return i}return this.parse_parentheses(t)},wt.prototype.parse_parentheses=function(e){if("("==this.token){this.getToken();var t=this.parse_range(e);if(")"!=this.token)throw this.createSyntaxError("Parenthesis ) expected");return this.getToken(),t}return this.parse_end(e)},wt.prototype.parse_end=function(){throw""==this.token?this.createSyntaxError("Unexpected end of expression"):this.createSyntaxError("Value expected")},wt.prototype.row=function(){return void 0},wt.prototype.col=function(){return this.index-this.token.length+1},wt.prototype.createErrorMessage=function(e){var t=this.row(),r=this.col();return void 0===t?void 0===r?e:e+" (col "+r+")":e+" (ln "+t+", col "+r+")"},wt.prototype.createSyntaxError=function(e){return new SyntaxError(this.createErrorMessage(e))},wt.prototype.createTypeError=function(e){return new TypeError(this.createErrorMessage(e))},wt.prototype.createError=function(e){return Error(this.createErrorMessage(e))},Nt.parser.Workspace=Et,Et.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},Et.prototype.append=function(e){var t=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,n=new xt(r),i=new Et.Node({id:t,expression:e,parser:this.parser,scope:n,nextNode:void 0,previousNode:this.lastNode});return this.nodes[t]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([t]),t},Et.prototype.insertBefore=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var n=r.previousNode,i=this._getNewId(),a=n?n.scope:this.scope,s=new xt(a),o=new Et.Node({id:i,expression:e,parser:this.parser,scope:s,nextNode:r,previousNode:n});this.nodes[i]=o,n?n.nextNode=o:this.firstNode=o,r.previousNode=o,r.scope.parentScope=o.scope;var f=this.getDependencies(i);return-1==f.indexOf(i)&&f.unshift(i),this._update(f),i},Et.prototype.insertAfter=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';return r==this.lastNode?this.append(e):this.insertBefore(t+1,e)},Et.prototype.remove=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';var r=this.getDependencies(e),n=t.previousNode,i=t.nextNode;n?n.nextNode=i:this.firstNode=i,i?i.previousNode=n:this.lastNode=n;var a=n?n.scope:this.scope;i&&(i.scope.parentScope=a),delete this.nodes[e],this._update(r)},Et.prototype.replace=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var n=[t];Et._merge(n,this.getDependencies(t));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(e),Et._merge(n,this.getDependencies(t)),this._update(n)},Et.Node=function(e){this.id=e.id,this.parser=e.parser,this.scope=e.scope,this.nextNode=e.nextNode,this.previousNode=e.previousNode,this.updateSeq=0,this.result=void 0,this.setExpr(e.expression)},Et.Node.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse()},Et.Node.prototype.getExpr=function(){return this.expression},Et.Node.prototype.getResult=function(){return this.result},Et.Node.prototype._parse=function(){try{this.fn=this.parser.parse(this.expression,this.scope)}catch(e){var t="Error: "+((e.message||e)+"");this.fn=new mt(t)}},Et.Node.prototype.eval=function(){try{this.scope.init(),this.result=this.fn.eval()}catch(e){this.scope.init(),this.result="Error: "+((e.message||e)+"")}return this.result},Et._merge=function(e,t){for(var r=0,n=t.length;n>r;r++){var i=t[r];-1==e.indexOf(i)&&e.push(i)}},Et.prototype.getDependencies=function(e){var t,r=[],n=this.nodes[e];if(n){var i=n.scope.defs,a=n.scope.updates,s=[];for(t in i)i.hasOwnProperty(t)&&s.push(t);for(t in a)a.hasOwnProperty(t)&&-1==s.indexOf(t)&&s.push(t);for(var o=n.nextNode;o&&s.length;){for(var f=o.scope,u=0;s.length>u;){if(t=s[u],(f.hasLink(t)||f.hasUpdate(t))&&-1==r.indexOf(o.id)){r.push(o.id);var l=this.getDependencies(o.id);Et._merge(r,l)}f.hasDef(t)&&(s.splice(u,1),u--),u++}o=o.nextNode}}return r},Et.prototype.getExpr=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getExpr()},Et.prototype.getResult=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getResult()},Et.prototype._update=function(e){this.updateSeq++;for(var t=this.updateSeq,r=this.nodes,n=0,i=e.length;i>n;n++){var a=e[n],s=r[a];s&&(s.eval(),s.updateSeq=t)}},Et.prototype.getChanges=function(e){var t=[],r=this.firstNode;for(e=e||0;r;)r.updateSeq>e&&t.push(r.id),r=r.nextNode;return{ids:t,updateSeq:this.updateSeq}},Et.prototype._getNewId=function(){return this.idMax++,this.idMax},Et.prototype.toString=function(){return JSON.stringify(this.toJSON())},Et.prototype.toJSON=function(){for(var e=[],t=this.firstNode;t;){var r={id:t.id,expression:t.expression,dependencies:this.getDependencies(t.id)};try{r.result=t.getResult()}catch(n){r.result="Error: "+((n.message||n)+"")}e.push(r),t=t.nextNode}return e}})();