diff --git a/CHANGELOG.md b/CHANGELOG.md index 8595dcb6f..321c87fc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,20 @@ # math.js changelog https://github.com/josdejong/mathjs + ## not yet relesed, version 0.6.0 - Implemented methods gcd and lcm. +- Implemented method `Unit.in(unit)`, which creates a clone of the unit with a + fixed representation. For example `math.unit('5.08 cm').in('inch')` will + return a unit which string representation always is in inch, thus `2 inch`. + `Unit.in(unit)` is the same as method `math.in(x, unit)`. +- Implemented `Unit.toNumber(unit)`, which returns the value of the unit when + represented with given unit. For example + `math.unit('5.08 cm').toNumber('inch')` returns the number `2`, as the + representation of the unit in inches has 2 as value. +- Improved: method `math.in(x, unit)` now supports a string as second parameter, + for example `math.in(math.unit('5.08 cm'), 'inch')`. ## 2013-04-06, version 0.5.0 @@ -13,18 +24,18 @@ https://github.com/josdejong/mathjs - Implemented data types Matrix and Range. - Implemented matrix methods clone, concat, det, diag, eye, inv, ones, size, squeeze, transpose, zeros. -- Implemented range operator (:), and transpose operator (') in parser.s +- Implemented range operator `:`, and transpose operator `'` in parser. - Changed: created construction methods for easy object creation for all data types and for the parser. For example, a complex value is now created - with "math.complex(2, 3)" instead of "new math.Complex(2, 3)", and a parser - is now created with "math.parser()" instead of "new math.parser.Parser()". + with `math.complex(2, 3)` instead of `new math.Complex(2, 3)`, and a parser + is now created with `math.parser()` instead of `new math.parser.Parser()`. - Changed: moved all data types under the namespace math.type, and moved the Parser, Workspace, etc. under the namespace math.expr. - Changed: changed operator precedence of the power operator: - it is now right associative instead of left associative like most scripting - languages. So 2^3^4 is now calculated as 2^(3^4). - - it has now higher precedence than unary minus most languages, thus -3^2 is - now calculated as -(3^2). + languages. So `2^3^4` is now calculated as `2^(3^4)`. + - it has now higher precedence than unary minus most languages, thus `-3^2` is + now calculated as `-(3^2)`. - Changed: renamed the parsers method 'put' into 'set'. - Fixed: method 'in' did not check for units to have the same base. diff --git a/README.md b/README.md index dd8a8c7ea..64b0d44dd 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,8 @@ Math.js supports units. var a = math.unit(55, 'cm'); // 550 mm var b = math.unit('0.1m'); // 100 mm math.add(a, b); // 0.65 m +b.in('cm'); // 10 cm +b.toNumber('cm'); // 10 var parser = math.parser(); parser.eval('2 inch in cm'); // 5.08 cm diff --git a/math.js b/math.js index a073f49b9..818882424 100644 --- a/math.js +++ b/math.js @@ -2451,7 +2451,7 @@ Unit.prototype.in = function (plainUnit) { * @param {String | Unit} plainUnit For example 'cm' or 'inch' * @return {Number} value */ -Unit.prototype.as = function (plainUnit) { +Unit.prototype.toNumber = function (plainUnit) { var other = this.in(plainUnit); var prefix = this.fixPrefix ? other._bestPrefix() : other.prefix; return other._unnormalize(other.value, prefix.value); diff --git a/math.min.js b/math.min.js index 55bd987cb..ec25d67cd 100644 --- a/math.min.js +++ b/math.min.js @@ -25,5 +25,5 @@ * the License. */ (function(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function n(e,t){if(this.constructor!=n)throw new SyntaxError("Complex constructor must be called with the new operator");if(null!=e&&!v(e)||null!=t&&!v(t))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=e||0,this.im=t||0}function t(e){if(this.constructor!=t)throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof t||e instanceof g)this._data=e.toArray();else if(e instanceof Array)this._data=e;else{if(null!=e)throw new TypeError("Unsupported type of data ("+st.typeof(e)+")");this._data=[]}this._size=ft.size(this._data)}function r(e,n){if(!v(e)||!d(e))throw new TypeError("Index must be an integer (value: "+e+")");if(1>e)throw new RangeError("Index out of range ("+e+" < 1)");if(n&&e>n)throw new RangeError("Index out of range ("+e+" > "+n+")")}function a(e,n){return r(n,e.length),e[n-1]}function i(e,n){return n.forEach(function(n){e=a(e,n)}),Hn(e)}function o(e,n){var t=n[0];return t.map?t.map(function(n){return a(e,n)}):[a(e,t)]}function s(e,n){var t=n[0],r=n[1];if(t.map)return r.map?t.map(function(n){var t=a(e,n);return r.map(function(e){return a(t,e)})}):t.map(function(n){return[a(a(e,n),r)]});if(r.map){var i=a(e,t);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,t),r)]]}function f(e,n,t){var r=t==n.length-1,i=n[t],o=function(i){var o=a(e,i);return r?o:f(o,n,t+1)};return i.map?i.map(o):[o(i)]}function u(e,n,t){if(r(n),t instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[n-1]=t}function c(e,n,t,a){var i=!1;t.length>n.length&&(i=!0);for(var o=0;t.length>o;o++){var s=t[o];r(s),(null==n[o]||s>n[o])&&(n[o]=s,i=!0)}i&&ft.resize(e,n,0);var f=n.length;t.forEach(function(n,t){f-1>t?e=e[n-1]:e[n-1]=a})}function l(e,n,t,a){var i=t[0];r(i),i>n[0]&&ft.resize(e,[i],0),e[i-1]=a}function h(e,n,t,a){var i=t[0],o=t[1];r(i),r(o);var s=!1;i>(n[0]||0)&&(n[0]=i,s=!0),o>(n[1]||0)&&(n[1]=o,s=!0),s&&ft.resize(e,n,0),e[i-1][o-1]=a}function m(e,n,t,r,a){var i=r==t.length-1,o=t[r],s=function(o,s){if(i)u(e,o,a[s]),e.length>(n[r]||0)&&(n[r]=e.length);else{var f=e[o-1];f instanceof Array||(e[o-1]=f=[f],e.length>(n[r]||0)&&(n[r]=e.length)),m(f,n,t,r+1,a[s])}};if(o.map){var f=o.size&&o.size()||o.length;if(f!=a.length)throw new RangeError("Dimensions mismatch ("+f+" != "+a.length+")");o.map(s)}else s(o,0)}function p(e){for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array?p(r):void 0==r&&(e[n]=0)}}function v(e){return e instanceof Number||"number"==typeof e}function d(e){return e==Math.round(e)}function g(e,n,t){if(this.constructor!=g)throw new SyntaxError("Range constructor must be called with the new operator");if(null!=e&&!v(e))throw new TypeError("Parameter start must be a number");if(null!=t&&!v(t))throw new TypeError("Parameter end must be a number");if(null!=n&&!v(n))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=t?t:0,this.step=null!=n?n:1}function y(e){return e instanceof String||"string"==typeof e}function x(e,n){if(this.constructor!=x)throw Error("Unit constructor must be called with the new operator");if(null!=e&&!v(e))throw Error("First parameter in Unit constructor must be a number");if(null!=n&&!y(n))throw Error("Second parameter in Unit constructor must be a string");if(null!=n){var t=w(n);if(!t)throw Error('String "'+n+'" is no unit');this.unit=t.unit,this.prefix=t.prefix,this.hasUnit=!0}else this.unit=x.UNIT_NONE,this.prefix=x.PREFIX_NONE,this.hasUnit=!1;null!=e?(this.value=this._normalize(e),this.hasValue=!0,this.fixPrefix=!1):(this.value=this._normalize(1),this.hasValue=!1,this.fixPrefix=!0)}function w(e){for(var n=x.UNITS,t=0,r=n.length;r>t;t++){var a=n[t];if(ft.endsWith(e,a.name)){var i=e.length-a.name.length,o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return{unit:a,prefix:s}}}return null}function E(e,n){var t=void 0;if(2==arguments.length){var r=Qn(n);t="Function "+e+" does not support a parameter of type "+r}else if(arguments.length>2){for(var a=[],i=1;arguments.length>i;i++)a.push(Qn(arguments[i]));t="Function "+e+" does not support a parameters of type "+a.join(", ")}else t="Unsupported parameter in function "+e;return new TypeError(t)}function b(e,n,t,r){var a="Wrong number of arguments in function "+e+" ("+n+" provided, "+t+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(e){if(1!=arguments.length)throw b("abs",arguments.length,1);if(v(e))return Math.abs(e);if(e instanceof n)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,N);if(e.valueOf()!==e)return N(e.valueOf());throw E("abs",e)}function O(e,r){if(2!=arguments.length)throw b("add",arguments.length,2);if(v(e)){if(v(r))return e+r;if(r instanceof n)return new n(e+r.re,r.im)}else if(e instanceof n){if(v(r))return new n(e.re+r,e.im);if(r instanceof n)return new n(e.re+r.re,e.im+r.im)}else if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Units do not match");if(!e.hasValue)throw Error("Unit on left hand side of operator + has no value");if(!r.hasValue)throw Error("Unit on right hand side of operator + has no value");var a=e.clone();return a.value+=r.value,a.fixPrefix=!1,a}if(y(e)||y(r))return e+r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,O);if(e.valueOf()!==e)return O(e.valueOf(),r.valueOf());throw E("add",e,r)}function M(e){if(1!=arguments.length)throw b("ceil",arguments.length,1);if(v(e))return Math.ceil(e);if(e instanceof n)return new n(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,M);if(e.valueOf()!==e)return M(e.valueOf());throw E("ceil",e)}function A(e){if(1!=arguments.length)throw b("cube",arguments.length,1);if(v(e))return e*e*e;if(e instanceof n)return G(G(e,e),e);if(e instanceof Array||e instanceof t||e instanceof g)return G(G(e,e),e);if(e.valueOf()!==e)return A(e.valueOf());throw E("cube",e)}function S(e,r){if(2!=arguments.length)throw b("divide",arguments.length,2);if(v(e)){if(v(r))return e/r;if(r instanceof n)return T(new n(e,0),r)}if(e instanceof n){if(v(r))return T(e,new n(r,0));if(r instanceof n)return T(e,r)}if(e instanceof x&&v(r)){var a=e.clone();return a.value/=r,a}if(e instanceof Array||e instanceof t)return r instanceof Array||r instanceof t?st.multiply(e,st.inv(r)):ft.map2(e,r,S);if(r instanceof Array||r instanceof t)return st.multiply(e,st.inv(r));if(e.valueOf()!==e||r.valueOf()!==r)return S(e.valueOf(),r.valueOf());throw E("divide",e,r)}function T(e,t){var r=t.re*t.re+t.im*t.im;return new n((e.re*t.re+e.im*t.im)/r,(e.im*t.re-e.re*t.im)/r)}function z(e,r){if(2!=arguments.length)throw b("equal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof n)return e==r.re&&0==r.im}if(e instanceof n){if(v(r))return e.re==r&&0==e.im;if(r instanceof n)return e.re==r.re&&e.im==r.im}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value==r.value}if(y(e)||y(r))return e==r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,z);if(e.valueOf()!==e||r.valueOf()!==r)return z(e.valueOf(),r.valueOf());throw E("equal",e,r)}function q(e){if(1!=arguments.length)throw b("exp",arguments.length,1);if(v(e))return Math.exp(e);if(e instanceof n){var r=Math.exp(e.re);return new n(r*Math.cos(e.im),r*Math.sin(e.im))}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,q);if(e.valueOf()!==e)return q(e.valueOf());throw E("exp",e)}function U(e){if(1!=arguments.length)throw b("fix",arguments.length,1);if(v(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof n)return new n(e.re>0?Math.floor(e.re):Math.ceil(e.re),e.im>0?Math.floor(e.im):Math.ceil(e.im));if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,U);if(e.valueOf()!==e)return U(e.valueOf());throw E("fix",e)}function R(e){if(1!=arguments.length)throw b("floor",arguments.length,1);if(v(e))return Math.floor(e);if(e instanceof n)return new n(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,R);if(e.valueOf()!==e)return R(e.valueOf());throw E("floor",e)}function L(){var e,n=arguments[0],r=arguments[1];if(2==arguments.length){if(v(n)&&v(r)){if(!d(n)||!d(r))throw Error("Parameters in function gcd must be integer numbers");for(;0!=r;)e=r,r=n%e,n=e;return Math.abs(n)}if(n instanceof Array||n instanceof t||r instanceof Array||r instanceof t)return ft.map2(n,r,L);if(n.valueOf()!==n||r.valueOf()!==r)return L(n.valueOf(),r.valueOf());throw E("gcd",n,r)}if(arguments.length>2){for(var a=1;arguments.length>a;a++)n=L(n,arguments[a]);return n}throw new SyntaxError("Function gcd expects two or more arguments")}function C(e,r){if(2!=arguments.length)throw b("larger",arguments.length,2);if(v(e)){if(v(r))return e>r;if(r instanceof n)return e>N(r)}if(e instanceof n){if(v(r))return N(e)>r;if(r instanceof n)return N(e)>N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value>r.value}if(y(e)||y(r))return e>r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,C);if(e.valueOf()!==e||r.valueOf()!==r)return C(e.valueOf(),r.valueOf());throw E("larger",e,r)}function _(e,r){if(2!=arguments.length)throw b("largereq",arguments.length,2);if(v(e)){if(v(r))return e>=r;if(r instanceof n)return e>=N(r)}if(e instanceof n){if(v(r))return N(e)>=r;if(r instanceof n)return N(e)>=N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value>=r.value}if(y(e)||y(r))return e>=r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,_);if(e.valueOf()!==e||r.valueOf()!==r)return _(e.valueOf(),r.valueOf());throw E("largereq",e,r)}function I(){var e,n=arguments[0],r=arguments[1];if(2==arguments.length){if(v(n)&&v(r)){if(!d(n)||!d(r))throw Error("Parameters in function lcm must be integer numbers");for(var a=n*r;0!=r;)e=r,r=n%e,n=e;return Math.abs(a/n)}if(n instanceof Array||n instanceof t||r instanceof Array||r instanceof t)return ft.map2(n,r,I);if(n.valueOf()!==n||r.valueOf()!==r)return I(n.valueOf(),r.valueOf());throw E("lcm",n,r)}if(arguments.length>2){for(var i=1;arguments.length>i;i++)n=I(n,arguments[i]);return n}throw new SyntaxError("Function lcm expects two or more arguments")}function P(e,r){if(1!=arguments.length&&2!=arguments.length)throw b("log",arguments.length,1,2);if(void 0!==r)return S(P(e),P(r));if(v(e))return e>=0?Math.log(e):P(new n(e,0));if(e instanceof n)return new n(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,P);if(e.valueOf()!==e||r.valueOf()!==r)return P(e.valueOf(),r.valueOf());throw E("log",e,r)}function B(e){if(1!=arguments.length)throw b("log10",arguments.length,1);if(v(e))return e>=0?Math.log(e)/Math.LN10:B(new n(e,0));if(e instanceof n)return new n(Math.log(Math.sqrt(e.re*e.re+e.im*e.im))/Math.LN10,Math.atan2(e.im,e.re)/Math.LN10);if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,B);if(e.valueOf()!==e)return B(e.valueOf());throw E("log10",e)}function k(e,r){if(2!=arguments.length)throw b("mod",arguments.length,2);if(v(e)){if(v(r))return e%r;if(r instanceof n&&0==r.im)return e%r.re}else if(e instanceof n&&0==e.im){if(v(r))return e.re%r;if(r instanceof n&&0==r.im)return e.re%r.re}if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,k);if(e.valueOf()!==e||r.valueOf()!==r)return k(e.valueOf(),r.valueOf());throw E("mod",e,r)}function G(e,r){if(2!=arguments.length)throw b("multiply",arguments.length,2);if(v(e)){if(v(r))return e*r;if(r instanceof n)return D(new n(e,0),r);if(r instanceof x)return o=r.clone(),o.value*=e,o}else if(e instanceof n){if(v(r))return D(e,new n(r,0));if(r instanceof n)return D(e,r)}else if(e instanceof x){if(v(r))return o=e.clone(),o.value*=r,o}else{if(e instanceof Array){if(r instanceof Array){var a=ft.size(e),i=ft.size(r);if(2!=a.length)throw Error("Can only multiply a 2 dimensional matrix (A has "+a.length+" dimensions)");if(2!=i.length)throw Error("Can only multiply a 2 dimensional matrix (B has "+i.length+" dimensions)");if(a[1]!=i[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+a[0]+"x"+a[1]+", B is "+i[0]+"x"+i[1]+", "+i[1]+" != "+i[0]+")");for(var o=[],s=a[0],f=i[1],u=a[1],c=0;s>c;c++){o[c]=[];for(var l=0;f>l;l++){for(var h=null,m=0;u>m;m++){var p=G(e[c][m],r[m][l]);h=null==h?p:O(h,p)}o[c][l]=h}}return o}return r instanceof t?new t(G(e.valueOf(),r.valueOf())):ft.map2(e,r,G)}if(e instanceof t)return new t(G(e.valueOf(),r.valueOf()))}if(r instanceof Array)return ft.map2(e,r,G);if(r instanceof t)return new t(G(e.valueOf(),r.valueOf()));if(e.valueOf()!==e||r.valueOf()!==r)return G(e.valueOf(),r.valueOf());throw E("multiply",e,r)}function D(e,t){return new n(e.re*t.re-e.im*t.im,e.re*t.im+e.im*t.re)}function j(e,r){if(2!=arguments.length)throw b("pow",arguments.length,2);if(v(e)){if(v(r))return d(r)||e>=0?Math.pow(e,r):V(new n(e,0),new n(r,0));if(r instanceof n)return V(new n(e,0),r)}else if(e instanceof n){if(v(r))return V(e,new n(r,0));if(r instanceof n)return V(e,r)}else{if(e instanceof Array){if(!v(r)||!d(r)||0>r)throw new TypeError("For A^b, b must be a positive integer (value is "+r+")");var a=ft.size(e);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==r)return identity(a[0]);for(var i=e,o=1;r>o;o++)i=G(e,i);return i}if(e instanceof t)return new t(j(e.valueOf(),r))}if(e.valueOf()!==e||r.valueOf()!==r)return j(e.valueOf(),r.valueOf());throw E("pow",e,r)}function V(e,n){var t=P(e),r=G(t,n);return q(r)}function F(e,r){if(1!=arguments.length&&2!=arguments.length)throw b("round",arguments.length,1,2);if(void 0==r){if(v(e))return Math.round(e);if(e instanceof n)return new n(Math.round(e.re),Math.round(e.im));if((e instanceof Array||e instanceof t||e instanceof g)&&ft.map(e,F),e.valueOf()!==e)return F(e.valueOf());throw E("round",e)}if(!v(r))throw new TypeError("Number of digits in function round must be an integer");if(r!==Math.round(r))throw new TypeError("Number of digits in function round must be integer");if(0>r||r>9)throw Error("Number of digits in function round must be in te range of 0-9");if(v(e))return H(e,r);if(e instanceof n)return new n(H(e.re,r),H(e.im,r));if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,F);if(e.valueOf()!==e||r.valueOf()!==r)return C(e.valueOf(),r.valueOf());throw E("round",e,r)}function H(e,n){var t=Math.pow(10,void 0!=n?n:st.options.precision);return Math.round(e*t)/t}function Y(e){if(1!=arguments.length)throw b("sign",arguments.length,1);if(v(e)){var r;return r=e>0?1:0>e?-1:0}if(e instanceof n){var a=Math.sqrt(e.re*e.re+e.im*e.im);return new n(e.re/a,e.im/a)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,r);if(e.valueOf()!==e)return r(e.valueOf());throw E("sign",e)}function W(e,r){if(2!=arguments.length)throw b("smaller",arguments.length,2);if(v(e)){if(v(r))return r>e;if(r instanceof n)return N(r)>e}if(e instanceof n){if(v(r))return r>N(e);if(r instanceof n)return N(e)e;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,W);if(e.valueOf()!==e||r.valueOf()!==r)return W(e.valueOf(),r.valueOf());throw E("smaller",e,r)}function X(e,r){if(2!=arguments.length)throw b("smallereq",arguments.length,2);if(v(e)){if(v(r))return r>=e;if(r instanceof n)return N(r)>=e}if(e instanceof n){if(v(r))return r>=N(e);if(r instanceof n)return N(e)<=N(r)}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value<=r.value}if(y(e)||y(r))return r>=e;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,X);if(e.valueOf()!==e||r.valueOf()!==r)return X(e.valueOf(),r.valueOf());throw E("smallereq",e,r)}function Z(e){if(1!=arguments.length)throw b("sqrt",arguments.length,1);if(v(e))return e>=0?Math.sqrt(e):Z(new n(e,0));if(e instanceof n){var r=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new n(.5*Math.sqrt(2*(r+e.re)),.5*Math.sqrt(2*(r-e.re))):new n(.5*Math.sqrt(2*(r+e.re)),-.5*Math.sqrt(2*(r-e.re)))}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Z);if(e.valueOf()!==e)return Z(e.valueOf());throw E("sqrt",e)}function K(e){if(1!=arguments.length)throw b("square",arguments.length,1);if(v(e))return e*e;if(e instanceof n)return G(e,e);if(e instanceof Array||e instanceof t||e instanceof g)return G(e,e);if(e.valueOf()!==e)return K(e.valueOf());throw E("square",e)}function Q(e,r){if(2!=arguments.length)throw b("subtract",arguments.length,2);if(v(e)){if(v(r))return e-r;if(r instanceof n)return new n(e-r.re,r.im)}else if(e instanceof n){if(v(r))return new n(e.re-r,e.im);if(r instanceof n)return new n(e.re-r.re,e.im-r.im)}else if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Units do not match");if(!e.hasValue)throw Error("Unit on left hand side of operator - has no value");if(!r.hasValue)throw Error("Unit on right hand side of operator - has no value");var a=e.clone();return a.value-=r.value,a.fixPrefix=!1,a}if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,Q);if(e.valueOf()!==e||r.valueOf()!==r)return Q(e.valueOf(),r.valueOf());throw E("subtract",e,r)}function J(e){if(1!=arguments.length)throw b("unaryminus",arguments.length,1);if(v(e))return-e;if(e instanceof n)return new n(-e.re,-e.im);if(e instanceof x){var r=e.clone();return r.value=-e.value,r}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,J);if(e.valueOf()!==e)return J(e.valueOf());throw E("unaryminus",e)}function $(e,r){if(2!=arguments.length)throw b("unequal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof n)return e==r.re&&0==r.im}if(e instanceof n){if(v(r))return e.re==r&&0==e.im;if(r instanceof n)return e.re==r.re&&e.im==r.im}if(e instanceof x&&r instanceof x){if(!e.equalBase(r))throw Error("Cannot compare units with different base");return e.value==r.value}if(y(e)||y(r))return e==r;if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,$);if(e.valueOf()!==e||r.valueOf()!==r)return $(e.valueOf(),r.valueOf());throw E("unequal",e,r)}function en(e){if(1!=arguments.length)throw b("arg",arguments.length,1);if(v(e))return Math.atan2(0,e);if(e instanceof n)return Math.atan2(e.im,e.re);if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,en);if(e.valueOf()!==e)return en(e.valueOf());throw E("arg",e)}function nn(e){if(1!=arguments.length)throw b("conj",arguments.length,1);if(v(e))return e;if(e instanceof n)return new n(e.re,-e.im);if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,nn);if(e.valueOf()!==e)return nn(e.valueOf());throw E("conj",e)}function tn(e){if(1!=arguments.length)throw b("im",arguments.length,1);if(v(e))return 0;if(e instanceof n)return e.im;if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,tn);if(e.valueOf()!==e)return tn(e.valueOf());throw E("im",e)}function rn(e){if(1!=arguments.length)throw b("re",arguments.length,1);if(v(e))return e;if(e instanceof n)return e.re;if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,rn);if(e.valueOf()!==e)return rn(e.valueOf());throw E("re",e)}function an(){switch(arguments.length){case 0:return new n(0,0);case 1:var e=arguments[0];if(!y(e))throw new TypeError("Two numbers or a single string expected in function complex");var t=n.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid complex number');case 2:return new n(arguments[0],arguments[1]);default:throw b("complex",arguments.length,0,2)}}function on(e){if(arguments.length>1)throw b("matrix",arguments.length,0,1);return new t(e)}function sn(){return new st.expr.Parser}function fn(e){switch(arguments.length){case 1:if(!y(e))throw new TypeError("Two or three numbers or a single string expected in function range");var n=g.parse(e);if(n)return n;throw new SyntaxError('String "'+n+'" is no valid range');case 2:return new g(arguments[0],null,arguments[1]);case 3:return new g(arguments[0],arguments[1],arguments[2]);default:throw b("range",arguments.length,2,3)}}function un(){switch(arguments.length){case 1:var e=arguments[0];if(!y(e))throw new TypeError("A string or a number and string expected in function unit");if(x.isPlainUnit(e))return new x(null,e);var n=x.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid unit');case 2:return new x(arguments[0],arguments[1]);default:throw b("unit",arguments.length,1,2)}}function cn(){return new st.expr.Workspace}function ln(){var e,n,r=arguments.length,a=-1,i=!1,o=[];for(e=0;r>e;e++){var s=arguments[e];if(s instanceof t&&(i=!0),e==r-1&&v(s)){if(n=a,a=s,!d(a)||1>a)throw new TypeError("Dimension number must be a positive integer (dim = "+a+")");if(e>0&&a>n)throw new RangeError("Dimension out of range ("+a+" > "+n+")")}else{if(!(s instanceof Array||s instanceof t))throw E("concat",s);var f=st.clone(s.valueOf()),u=st.size(s);if(o[e]=f,n=a,a=u.length,e>0&&a!=n)throw new RangeError("Dimension mismatch ("+n+" != "+a+")")}}if(0==o.length)throw new SyntaxError("At least one matrix expected");for(var c=o.shift();o.length;)c=hn(c,o.shift(),a-1,0);return i?new t(c):c}function hn(e,n,t,r){if(t>r){if(e.length!=n.length)throw Error("Dimensions mismatch ("+e.length+" != "+n.length+")");for(var a=[],i=0;e.length>i;i++)a[i]=hn(e[i],n[i],t,r+1);return a}return e.concat(n)}function mn(e){if(1!=arguments.length)throw b("det",arguments.length,1);var n=st.size(e);switch(n.length){case 0:return st.clone(e);case 1:if(1==n[0])return st.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+st.format(n)+")");case 2:var t=n[0],r=n[1];if(t==r)return pn(e.valueOf(),t,r);throw new RangeError("Matrix must be square (size: "+st.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+st.format(n)+")")}}function pn(e,n,t){var r=st.multiply,a=st.subtract;if(1==n)return e[0][0];if(2==n)return a(r(e[0][0],e[1][1]),r(e[1][0],e[0][1]));for(var i=0,o=0;t>o;o++){var s=vn(e,n,t,0,o);i+=r(r((o+1)%2+(o+1)%2-1,e[0][o]),pn(s,n-1,t-1))}return i}function vn(e,n,t,r,a){for(var i,o=[],s=0;n>s;s++)if(s!=r){i=o[s-(s>r)]=[];for(var f=0;t>f;f++)f!=a&&(i[f-(f>a)]=e[s][f])}return o}function dn(e,n){var r,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw b("diag",arguments.length,1,2);if(n){if(!v(n)||!d(n))throw new TypeError("Second parameter in function diag must be an integer")}else n=0;var s=n>0?n:0,f=0>n?-n:0;e instanceof t||e instanceof g||(e=new t(e));var u;switch(e.isVector()?(e=e.toVector(),u=[e.length]):u=e.size(),u.length){case 1:a=e.valueOf();var c=new t;for(c.resize([a.length+f,a.length+s]),r=c.valueOf(),o=a.length,i=0;o>i;i++)r[i+f][i+s]=Hn(a[i]);return c;case 2:for(a=[],r=e.valueOf(),o=Math.min(u[0]-f,u[1]-s),i=0;o>i;i++)a[i]=Hn(r[i+f][i+s]);return new t(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}function gn(){var e=ft.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw b("eye",num,0,2);var n=e[0],r=e[1];if(!v(n)||!d(n)||1>n)throw Error("Parameters in function eye must be positive integers");if(r&&(!v(r)||!d(r)||1>r))throw Error("Parameters in function eye must be positive integers");var a=new t;a.resize(e);for(var i=st.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a}function yn(e){if(1!=arguments.length)throw b("inv",arguments.length,1);var n=st.size(e);switch(n.length){case 0:return st.divide(1,e);case 1:if(1==n[0])return e instanceof t?new t([st.divide(1,e.valueOf()[0])]):[st.divide(1,e[0])];throw new RangeError("Matrix must be square (size: "+st.format(n)+")");case 2:var r=n[0],a=n[1];if(r==a)return e instanceof t?new t(xn(e.valueOf(),r,a)):xn(e,r,a);throw new RangeError("Matrix must be square (size: "+st.format(n)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+st.format(n)+")")}}function xn(e,n,t){var r,a,i,o,s,f=st.add,u=st.unaryminus,c=st.multiply,l=st.divide;if(1==n){if(o=e[0][0],0==o)throw Error("Cannot calculate inverse, determinant is zero");return[[st.divide(1,o)]]}if(2==n){var h=st.det(e);if(0==h)throw Error("Cannot calculate inverse, determinant is zero");return[[l(e[1][1],h),l(u(e[0][1]),h)],[l(u(e[1][0]),h),l(e[0][0],h)]]}var m=e.concat();for(r=0;n>r;r++)m[r]=m[r].concat();for(var p=st.eye(n).valueOf(),v=0;t>v;v++){for(r=v;n>r&&0==m[r][v];)r++;if(r==n||0==m[r][v])throw Error("Cannot calculate inverse, determinant is zero");r!=v&&(s=m[v],m[v]=m[r],m[r]=s,s=p[v],p[v]=p[r],p[r]=s);var d=m[v],g=p[v];for(r=0;n>r;r++){var y=m[r],x=p[r];if(r!=v){if(0!=y[v]){for(i=l(u(y[v]),d[v]),a=v;t>a;a++)y[a]=f(y[a],c(i,d[a]));for(a=0;t>a;a++)x[a]=f(x[a],c(i,g[a]))}}else{for(i=d[v],a=v;t>a;a++)y[a]=l(y[a],i);for(a=0;t>a;a++)x[a]=l(x[a],i)}}}return p}function wn(){var e=ft.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new t,r=1;return n.resize(e,r),n}function En(e){if(1!=arguments.length)throw b("size",arguments.length,1);if(v(e)||e instanceof n||e instanceof x||null==e)return[];if(y(e))return[e.length];if(e instanceof Array)return ft.size(e);if(e instanceof t||e instanceof g)return e.size();if(e.valueOf()!==e)return En(e.valueOf());throw E("size",e)}function bn(e){if(1!=arguments.length)throw b("squeeze",arguments.length,1);return e instanceof t||e instanceof g?Nn(e.toArray()):e instanceof Array?Nn(Hn(e)):Hn(e)}function Nn(e){if(1==e.length)return Nn(e[0]);for(var n=0,t=e.length;t>n;n++){var r=e[n];r instanceof Array&&(e[n]=Nn(r))}return e}function On(e){if(1!=arguments.length)throw b("transpose",arguments.length,1);var n=st.size(e);switch(n.length){case 0:return st.clone(e);case 1:return st.clone(e);case 2:for(var r,a=n[1],i=n[0],o=e instanceof t,s=e.valueOf(),f=[],u=st.clone,c=0;a>c;c++){r=f[c]=[];for(var l=0;i>l;l++)r[l]=u(s[l][c])}return 0==i&&(f[0]=[]),o?new t(f):f;default:throw new RangeError("Matrix must be two dimensional (size: "+st.format(n)+")")}}function Mn(){var e=ft.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var n=new t;return n.resize(e),n}function An(e){if(1!=arguments.length)throw b("factorial",arguments.length,1);if(v(e)){if(!d(e))throw new TypeError("Function factorial can only handle integer values");var n=e,r=n;for(n--;n>1;)r*=n,n--;return 0==r&&(r=1),r}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,An);if(e.valueOf()!==e)return An(e.valueOf());throw E("factorial",e)}function Sn(){if(0!=arguments.length)throw b("random",arguments.length,0);return Math.random()}function Tn(e){if(0==arguments.length)throw Error("Function max requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof t||e instanceof g){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=st.size(e);if(1==n.length){if(0==e.length)throw Error("Cannot calculate max of an empty vector");return zn(e.valueOf())}if(2==n.length){if(0==n[0]||0==n[1])throw Error("Cannot calculate max of an empty matrix");if(e instanceof Array)return qn(e,n[0],n[1]);if(e instanceof t||e instanceof g)return new t(qn(e.valueOf(),n[0],n[1]));throw E("max",e)}throw new RangeError("Cannot calculate max for multi dimensional matrix")}return zn(arguments)}function zn(e){for(var n=st.larger,t=e[0],r=1,a=e.length;a>r;r++){var i=e[r];n(i,t)&&(t=i)}return t}function qn(e,n,t){for(var r=st.larger,a=[],i=0;t>i;i++){for(var o=e[0][i],s=1;n>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function Un(e){if(0==arguments.length)throw Error("Function min requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof t||e instanceof g){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var n=st.size(e);if(1==n.length){if(0==e.length)throw Error("Cannot calculate min of an empty vector");return Rn(e.valueOf())}if(2==n.length){if(0==n[0]||0==n[1])throw Error("Cannot calculate min of an empty matrix");if(e instanceof Array)return Ln(e,n[0],n[1]);if(e instanceof t||e instanceof g)return new t(Ln(e.valueOf(),n[0],n[1]));throw E("min",e)}throw new RangeError("Cannot calculate min for multi dimensional matrix")}return Rn(arguments)}function Rn(e){for(var n=st.smaller,t=e[0],r=1,a=e.length;a>r;r++){var i=e[r];n(i,t)&&(t=i)}return t}function Ln(e,n,t){for(var r=st.smaller,a=[],i=0;t>i;i++){for(var o=e[0][i],s=1;n>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function Cn(e){if(1!=arguments.length)throw b("acos",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.acos(e):Cn(new n(e,0));if(e instanceof n){var r=new n(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),a=Z(r),i=new n(a.re-e.im,a.im+e.re),o=P(i);return new n(1.5707963267948966-o.im,o.re)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Cn);if(e.valueOf()!==e)return Cn(e.valueOf());throw E("acos",e)}function _n(e){if(1!=arguments.length)throw b("asin",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.asin(e):_n(new n(e,0));if(e instanceof n){var r=e.re,a=e.im,i=new n(a*a-r*r+1,-2*r*a),o=Z(i),s=new n(o.re-a,o.im+r),f=P(s);return new n(f.im,-f.re)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,_n);if(e.valueOf()!==e)return _n(e.valueOf());throw E("asin",e)}function In(e){if(1!=arguments.length)throw b("atan",arguments.length,1);if(v(e))return Math.atan(e);if(e instanceof n){var r=e.re,a=e.im,i=r*r+(1-a)*(1-a),o=new n((1-a*a-r*r)/i,-2*r/i),s=P(o);return new n(-.5*s.im,.5*s.re)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,In);if(e.valueOf()!==e)return In(e.valueOf());throw E("atan",e)}function Pn(e,r){if(2!=arguments.length)throw b("atan2",arguments.length,2);if(v(e)){if(v(r))return Math.atan2(e,r);if(r instanceof n)return Math.atan2(e,r.re)}else if(e instanceof n){if(v(r))return Math.atan2(e.re,r);if(r instanceof n)return Math.atan2(e.re,r.re)}if(e instanceof Array||e instanceof t||e instanceof g||r instanceof Array||r instanceof t||r instanceof g)return ft.map2(e,r,Pn);if(r.valueOf()!==r||e.valueOf()!==e)return Pn(e.valueOf(),r.valueOf());throw E("atan2",e,r)}function Bn(e){if(1!=arguments.length)throw b("cos",arguments.length,1);if(v(e))return Math.cos(e);if(e instanceof n)return new n(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.sin(e.re)*(Math.exp(-e.im)-Math.exp(e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Bn);if(e.valueOf()!==e)return Bn(e.valueOf());throw E("cos",e)}function kn(e){if(1!=arguments.length)throw b("cot",arguments.length,1);if(v(e))return 1/Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(Math.exp(-4*e.im)-1)/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,kn);if(e.valueOf()!==e)return kn(e.valueOf()); -throw E("cot",e)}function Gn(e){if(1!=arguments.length)throw b("csc",arguments.length,1);if(v(e))return 1/Math.sin(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Gn);if(e.valueOf()!==e)return Gn(e.valueOf());throw E("csc",e)}function Dn(e){if(1!=arguments.length)throw b("sec",arguments.length,1);if(v(e))return 1/Math.cos(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new n(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Dn);if(e.valueOf()!==e)return Dn(e.valueOf());throw E("sec",e)}function jn(e){if(1!=arguments.length)throw b("sin",arguments.length,1);if(v(e))return Math.sin(e);if(e instanceof n)return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.cos(e.re)*(Math.exp(e.im)-Math.exp(-e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,jn);if(e.valueOf()!==e)return jn(e.valueOf());throw E("sin",e)}function Vn(e){if(1!=arguments.length)throw b("tan",arguments.length,1);if(v(e))return Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(1-Math.exp(-4*e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Vn);if(e.valueOf()!==e)return Vn(e.valueOf());throw E("tan",e)}function Fn(e,n){if(2!=arguments.length)throw b("in",arguments.length,2);if(e instanceof x&&(n instanceof x||y(n)))return e.in(n);if(e instanceof Array||e instanceof t||e instanceof g||n instanceof Array||n instanceof t||n instanceof g)return ft.map2(e,n,Fn);if(e.valueOf()!==e)return st.in(e.valueOf());throw E("in",e,n)}function Hn(n){if(1!=arguments.length)throw b("clone",arguments.length,1);if(null==n)return n;if("function"==typeof n.clone)return n.clone();if(v(n)||y(n)||e(n))return n;if(n instanceof Array)return n.map(function(e){return Hn(e)});if(n instanceof Object)return ft.mapObject(n,Hn);throw E("clone",n)}function Yn(e,n){var t=arguments.length;if(1!=t&&2!=t)throw b("format",t,1,2);if(1==t){var r=arguments[0];return v(r)?ft.formatNumber(r):r instanceof Array?ft.formatArray(r):y(r)?'"'+r+'"':r instanceof Object?""+r:r+""}if(!y(e))throw new TypeError("String expected as first parameter in function format");if(!(n instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,t){for(var r=t.split("."),a=n[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})}function Wn(e){if(1!=arguments.length)throw b("help",arguments.length,1);if(void 0!=e){if(e.doc)return Xn(e.doc);if(e.constructor.doc)return Xn(e.constructor.doc);if(y(e)){var n=st[e];if(n&&n.doc)return Xn(n.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 Xn(e){var n="";if(e.name&&(n+="NAME\n"+e.name+"\n\n"),e.category&&(n+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(n+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var t=st.parser();n+="EXAMPLES\n";for(var r=0;e.examples.length>r;r++){var a,i=e.examples[r];try{a=t.eval(i)}catch(o){a=o}n+=i+"\n",n+=" "+st.format(a)+"\n"}n+="\n"}return e.seealso&&(n+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),n}function Zn(e,n){var t;if(y(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var r=require(e);Zn(r)}else if(Kn(e)){if(t=e.name,!t)throw Error("Cannot import an unnamed function");(n||void 0===st[t])&&(st[t]=e)}else if(e instanceof Object)for(t in e)if(e.hasOwnProperty(t)){var a=e[t];Kn(a)?(n||void 0===st[t])&&(st[t]=a):Zn(a)}}function Kn(e){return"function"==typeof e||v(e)||y(e)||e instanceof n||e instanceof x}function Qn(e){if(1!=arguments.length)throw b("typeof",arguments.length,1);var n=typeof e;if("object"==n){if(null==e)return"null";if(e.constructor){for(var t in st)if(st.hasOwnProperty(t)&&e.constructor==st[t])return t.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return n}function Jn(){}function $n(e,n,t){this.name=e,this.fn=n,this.params=t}function et(e){this.value=e}function nt(e){this.nodes=e||[]}function tt(){this.params=[],this.visible=[]}function rt(e,n,t,r){this.name=e,this.params=n,this.expr=t,this.result=r}function at(e,n){this.object=e,this.params=n}function it(e,n,t,r,a){this.name=e,this.variables=t,this.values=[];for(var i=0,o=this.variables.length;o>i;i++)this.values[i]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,n,t,r),this.result=a}function ot(e,n){throw Error('Constructor "'+e+'" has been replaced by '+'constructor method "'+n+'" in math.js v0.5.0')}var st={type:{},expr:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=st),"undefined"!=typeof exports&&(exports=st),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return st}),"undefined"!=typeof window&&(window.math=st);var ft=function(){function e(n){if(n instanceof Array){var t=n.length;if(t){var r=e(n[0]);return 0==r[0]?[0].concat(r):[t].concat(r)}return[t]}return[]}function n(e,t,r){var a,i=e.length;if(i!=t[r])throw new RangeError("Dimension mismatch ("+i+" != "+t[r]+")");if(t.length-1>r){var o=r+1;for(a=0;i>a;a++){var s=e[a];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");n(e[a],t,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(t.length+1)+" > "+t.length+")")}function r(e,n,t){if(n.length-1>t){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(a,n,t+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,n,t,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=n[t];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?Hn(r):0;else e.length=n[t];i=e.length}if(n.length-1>t){var f=t+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,n,f,r)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var i={};return i.formatNumber=function(e,n){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var t=Math.abs(e);if(t>1e-4&&1e6>t||0==t)return H(e,n)+"";var r=Math.round(Math.log(t)/Math.LN10),a=e/Math.pow(10,r);return H(a,n)+"E"+r},i.formatArray=function(e){if(e instanceof Array){for(var n="[",t=e.length,r=0;t>r;r++)0!=r&&(n+=", "),n+=i.formatArray(e[r]);return n+="]"}return st.format(e)},i.formatArray2d=function(e){var n="[",t=i.size(e);if(2!=t.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(t)+")");for(var r=t[0],a=t[1],o=0;r>o;o++){0!=o&&(n+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(n+=", ");var u=s[f];void 0!=u&&(n+=Yn(u))}}return n+="]"},i.argsToArray=function(e){var n;if(0==e.length)n=[];else if(1==e.length)n=e[0],n instanceof t&&(n=n.toVector()),n instanceof g&&(n=n.valueOf()),n instanceof Array||(n=[n]);else{n=[];for(var r=0;e.length>r;r++)n[r]=e[r]}return n},i.endsWith=function(e,n){var t=e.length-n.length,r=e.length;return e.substring(t,r)===n},i.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},i.map=function(e,n){if(e instanceof Array||e instanceof t||e instanceof g)return e.map(function(e){return n(e)});throw new TypeError("Array expected")},i.map2=function(e,n,r){var a,o,s;if(e instanceof t||n instanceof t)return new t(i.map2(e.valueOf(),n.valueOf(),r));if(e instanceof g||n instanceof g)return new t(i.map2(e.valueOf(),n.valueOf(),r));if(e instanceof Array)if(n instanceof Array){if(e.length!=n.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+n.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],n[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],n);else if(n instanceof Array)for(a=[],o=n.length,s=0;o>s;s++)a[s]=r(e,n[s]);else a=r(e,n);return a},i.forEach=function(e,n){if(e instanceof Array)e.forEach(n);else for(var t in e)e.hasOwnProperty(t)&&n(e[t],t,e)},i.mapObject=function(e,n){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},i.deepEqual=function(e,n){var t,r,a;if(e instanceof Array){if(!(n instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],n[r]))return!1;return!0}if(e instanceof Object){if(n instanceof Array||!(n instanceof Object))return!1;for(t in e)if(e.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;for(t in n)if(n.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;return!0}return e.valueOf()==n.valueOf()},i.size=function(n){var t=e(n);return i.validate(n,t),t},i.validate=function(e,t){var a=0==t.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=t.indexOf(0);o?(t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(t)+")")}),r(e,t,0)):n(e,t,0)}},i.resize=function(e,n,t){if(!(n instanceof Array))throw new TypeError("Size must be an array (size is "+st.typeof(n)+")");n.forEach(function(e){if(!v(e)||!d(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(n)+")")});var r=-1!=n.indexOf(0);r&&n.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(n)+")")}),a(e,n,0,t)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;this.length>n;n++)if(this[n]==e)return n;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,n){for(var t=0,r=this.length;r>t;++t)e.call(n||this,this[t],t,this)}),Array.prototype.map||(Array.prototype.map=function(e,n){var t,r,a;if(null==this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(n&&(t=n),r=Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(t,s,a,i),r[a]=f),a++}return r}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&!e.call(r,n[a],a,n))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&e.call(r,n[a],a,n))return!0;return!1}),i}();st.type.Complex=n,function(){function e(){for(;" "==c||" "==c;)a()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function a(){u++,c=f[u]}function i(e){u=e,c=f[u]}function o(){var e="",n=u;if("+"==c?a():"-"==c&&(e+=c,a()),!t(c))return i(n),null;for(;t(c);)e+=c,a();if("E"==c||"e"==c){if(e+=c,a(),("+"==c||"-"==c)&&(e+=c,a()),!r(c))return i(n),null;for(;r(c);)e+=c,a()}return e}function s(){var e=f[u+1];if("I"==c||"i"==c)return a(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var n="+"==c?"1":"-1";return a(),a(),n}return null}var f,u,c;n.parse=function(t){if(f=t,u=-1,c="",!y(f))return null;a(),e();var r=o();if(r){if("I"==c||"i"==c)return a(),e(),c?null:new n(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new n(Number(r),0);a(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;a()}else if(l=s(),!l)return null;return"-"==i&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),a(),e(),c?null:new n(Number(r),Number(l))}return(r=s())?(e(),c?null:new n(0,Number(r))):null}}(),n.prototype.clone=function(){return new n(this.re,this.im)},n.prototype.toString=function(){var e="",n=ft.formatNumber(this.re),t=ft.formatNumber(this.im);return e=0==this.im?n:0==this.re?1==this.im?"i":-1==this.im?"-i":t+"i":this.im>0?1==this.im?n+" + i":n+" + "+t+"i":-1==this.im?n+" - i":n+" - "+ft.formatNumber(Math.abs(this.im))+"i"},n.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"]},st.type.Matrix=t,t.prototype.get=function(e){var n;if(e instanceof t)n=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+st.typeof(e));n=!e.some(function(e){return e.forEach})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(n)switch(e.length){case 1:return a(this._data,e[0]);case 2:return a(a(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new t(o(this._data,e));case 2:return new t(s(this._data,e));default:return new t(f(this._data,e,0))}},t.prototype.set=function(e,n){var r;if(e instanceof t)r=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+st.typeof(e));r=!e.some(function(e){return e.forEach})}if((n instanceof t||n instanceof g)&&(n=n.valueOf()),e.length=e})},t.prototype.toVector=function(){var e=0,n=void 0,t=[];if(this._size.forEach(function(r,a){r>1&&(e++,n=a),t[a]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var a=[],i=function(e){e instanceof Array?e.forEach(i):a.push(e)};return i(this._data),a}return null},t.prototype.isVector=function(){var e=0;return this._size.forEach(function(n){n>1&&e++}),1>=e},t.prototype.toArray=function(){return Hn(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.toString=function(){return ft.formatArray(this._data)},st.type.Range=g,g.parse=function(e){if(!y(e))return null;var n=e.split(":"),t=n.map(function(e){return Number(e)}),r=t.some(function(e){return isNaN(e)});if(r)return null;switch(t.length){case 2:return new g(t[0],1,t[1]);case 3:return new g(t[0],t[1],t[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,n=Number(this.start),t=Number(this.step),r=Number(this.end),a=r-n;return Y(t)==Y(a)?e=Math.floor(a/t)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var n=Number(this.start),t=Number(this.step),r=Number(this.end),a=0;if(t>0)for(;r>=n;)e(n,a,this),n+=t,a++;else if(0>t)for(;n>=r;)e(n,a,this),n+=t,a++},g.prototype.map=function(e){var n=[];return this.forEach(function(t,r,a){n[r]=e(t,r,a)}),n},g.prototype.toMatrix=function(){return new t(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(n,t){e[t]=n}),e},g.prototype.toVector=g.prototype.toArray,g.prototype.isVector=function(){return!0},g.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},g.prototype.isScalar=function(){return 1==this.size()[0]},g.prototype.valueOf=function(){return this.toArray()},g.prototype.toString=function(){var e=Yn(Number(this.start));return 1!=this.step&&(e+=":"+Yn(Number(this.step))),e+=":"+Yn(Number(this.end))},st.type.Unit=x,function(){function e(){for(;" "==u||" "==u;)r()}function n(e){return e>="0"&&"9">=e||"."==e}function t(e){return e>="0"&&"9">=e}function r(){f++,u=s[f]}function a(e){f=e,u=s[f]}function i(){var e="",i=f;if("+"==u?r():"-"==u&&(e+=u,r()),!n(u))return a(i),null;for(;n(u);)e+=u,r();if("E"==u||"e"==u){if(e+=u,r(),("+"==u||"-"==u)&&(e+=u,r()),!t(u))return a(i),null;for(;t(u);)e+=u,r()}return e}function o(){var n="";for(e();u&&" "!=u&&" "!=u;)n+=u,r();return n||null}var s,f,u;x.parse=function(n){if(s=n,f=-1,u="",!y(s))return null;r(),e();var t,a=i();return a?(t=o(),r(),e(),u?null:a&&t?new x(Number(a),t):null):(t=o(),r(),e(),u?null:new x(null,t))}}(),x.prototype.clone=function(){var e=new x;for(var n in this)this.hasOwnProperty(n)&&(e[n]=this[n]);return e},x.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},x.prototype._unnormalize=function(e,n){return void 0==n?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/n-this.unit.offset},x.isPlainUnit=function(e){return null!=w(e)},x.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},x.prototype.equalBase=function(e){return this.unit.base===e.unit.base},x.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},x.prototype.in=function(e){var n;if(y(e)){if(n=new x(null,e),!this.equalBase(n))throw Error("Units do not match");return n.value=this.value,n}if(e instanceof x){if(!this.equalBase(e))throw Error("Units do not match");if(e.hasValue)throw Error("Cannot convert to a unit with a value");if(!e.hasUnit)throw Error("Unit expected on the right hand side of function in");return n=e.clone(),n.value=this.value,n.fixPrefix=!0,n}throw Error("String or Unit expected as parameter")},x.prototype.as=function(e){var n=this.in(e),t=this.fixPrefix?n._bestPrefix():n.prefix;return n._unnormalize(n.value,t.value)},x.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),ft.formatNumber(e)+" "+this.prefix.name+this.unit.name;var n=this._bestPrefix();return e=this._unnormalize(this.value,n.value),ft.formatNumber(e)+" "+n.name+this.unit.name},x.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),n=x.PREFIX_NONE,t=Math.abs(Math.log(e/n.value)/Math.LN10-1.2),r=this.unit.prefixes;for(var a in r)if(r.hasOwnProperty(a)){var i=r[a];if(i.scientific){var o=Math.abs(Math.log(e/i.value)/Math.LN10-1.2);t>o&&(n=i,t=o)}}return n},x.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}}},x.PREFIX_NONE={name:"",value:1,scientific:!0},x.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var ut=x.BASE_UNITS,ct=x.PREFIXES;x.BASE_UNIT_NONE={},x.UNIT_NONE={name:"",base:x.BASE_UNIT_NONE,value:1,offset:0},x.UNITS=[{name:"meter",base:ut.LENGTH,prefixes:ct.LONG,value:1,offset:0},{name:"inch",base:ut.LENGTH,prefixes:ct.NONE,value:.0254,offset:0},{name:"foot",base:ut.LENGTH,prefixes:ct.NONE,value:.3048,offset:0},{name:"yard",base:ut.LENGTH,prefixes:ct.NONE,value:.9144,offset:0},{name:"mile",base:ut.LENGTH,prefixes:ct.NONE,value:1609.344,offset:0},{name:"link",base:ut.LENGTH,prefixes:ct.NONE,value:.201168,offset:0},{name:"rod",base:ut.LENGTH,prefixes:ct.NONE,value:5.02921,offset:0},{name:"chain",base:ut.LENGTH,prefixes:ct.NONE,value:20.1168,offset:0},{name:"angstrom",base:ut.LENGTH,prefixes:ct.NONE,value:1e-10,offset:0},{name:"m",base:ut.LENGTH,prefixes:ct.SHORT,value:1,offset:0},{name:"ft",base:ut.LENGTH,prefixes:ct.NONE,value:.3048,offset:0},{name:"yd",base:ut.LENGTH,prefixes:ct.NONE,value:.9144,offset:0},{name:"mi",base:ut.LENGTH,prefixes:ct.NONE,value:1609.344,offset:0},{name:"li",base:ut.LENGTH,prefixes:ct.NONE,value:.201168,offset:0},{name:"rd",base:ut.LENGTH,prefixes:ct.NONE,value:5.02921,offset:0},{name:"ch",base:ut.LENGTH,prefixes:ct.NONE,value:20.1168,offset:0},{name:"mil",base:ut.LENGTH,prefixes:ct.NONE,value:254e-7,offset:0},{name:"m2",base:ut.SURFACE,prefixes:ct.SHORT,value:1,offset:0},{name:"sqin",base:ut.SURFACE,prefixes:ct.NONE,value:64516e-8,offset:0},{name:"sqft",base:ut.SURFACE,prefixes:ct.NONE,value:.09290304,offset:0},{name:"sqyd",base:ut.SURFACE,prefixes:ct.NONE,value:.83612736,offset:0},{name:"sqmi",base:ut.SURFACE,prefixes:ct.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:ut.SURFACE,prefixes:ct.NONE,value:25.29295,offset:0},{name:"sqch",base:ut.SURFACE,prefixes:ct.NONE,value:404.6873,offset:0},{name:"sqmil",base:ut.SURFACE,prefixes:ct.NONE,value:6.4516e-10,offset:0},{name:"m3",base:ut.VOLUME,prefixes:ct.SHORT,value:1,offset:0},{name:"L",base:ut.VOLUME,prefixes:ct.SHORT,value:.001,offset:0},{name:"litre",base:ut.VOLUME,prefixes:ct.LONG,value:.001,offset:0},{name:"cuin",base:ut.VOLUME,prefixes:ct.NONE,value:16387064e-12,offset:0},{name:"cuft",base:ut.VOLUME,prefixes:ct.NONE,value:.028316846592,offset:0},{name:"cuyd",base:ut.VOLUME,prefixes:ct.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:ut.VOLUME,prefixes:ct.NONE,value:5e-6,offset:0},{name:"tablespoon",base:ut.VOLUME,prefixes:ct.NONE,value:15e-6,offset:0},{name:"minim",base:ut.VOLUME,prefixes:ct.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:ut.VOLUME,prefixes:ct.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:ut.VOLUME,prefixes:ct.NONE,value:2957353e-11,offset:0},{name:"gill",base:ut.VOLUME,prefixes:ct.NONE,value:.0001182941,offset:0},{name:"cup",base:ut.VOLUME,prefixes:ct.NONE,value:.0002365882,offset:0},{name:"pint",base:ut.VOLUME,prefixes:ct.NONE,value:.0004731765,offset:0},{name:"quart",base:ut.VOLUME,prefixes:ct.NONE,value:.0009463529,offset:0},{name:"gallon",base:ut.VOLUME,prefixes:ct.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:ut.VOLUME,prefixes:ct.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:ut.VOLUME,prefixes:ct.NONE,value:.1589873,offset:0},{name:"hogshead",base:ut.VOLUME,prefixes:ct.NONE,value:.238481,offset:0},{name:"fldr",base:ut.VOLUME,prefixes:ct.NONE,value:36966911e-13,offset:0},{name:"floz",base:ut.VOLUME,prefixes:ct.NONE,value:2957353e-11,offset:0},{name:"gi",base:ut.VOLUME,prefixes:ct.NONE,value:.0001182941,offset:0},{name:"cp",base:ut.VOLUME,prefixes:ct.NONE,value:.0002365882,offset:0},{name:"pt",base:ut.VOLUME,prefixes:ct.NONE,value:.0004731765,offset:0},{name:"qt",base:ut.VOLUME,prefixes:ct.NONE,value:.0009463529,offset:0},{name:"gal",base:ut.VOLUME,prefixes:ct.NONE,value:.003785412,offset:0},{name:"bbl",base:ut.VOLUME,prefixes:ct.NONE,value:.1173478,offset:0},{name:"obl",base:ut.VOLUME,prefixes:ct.NONE,value:.1589873,offset:0},{name:"g",base:ut.MASS,prefixes:ct.SHORT,value:.001,offset:0},{name:"gram",base:ut.MASS,prefixes:ct.LONG,value:.001,offset:0},{name:"ton",base:ut.MASS,prefixes:ct.SHORT,value:907.18474,offset:0},{name:"tonne",base:ut.MASS,prefixes:ct.SHORT,value:1e3,offset:0},{name:"grain",base:ut.MASS,prefixes:ct.NONE,value:6479891e-11,offset:0},{name:"dram",base:ut.MASS,prefixes:ct.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:ut.MASS,prefixes:ct.NONE,value:.028349523125,offset:0},{name:"poundmass",base:ut.MASS,prefixes:ct.NONE,value:.45359237,offset:0},{name:"hundredweight",base:ut.MASS,prefixes:ct.NONE,value:45.359237,offset:0},{name:"stick",base:ut.MASS,prefixes:ct.NONE,value:.115,offset:0},{name:"gr",base:ut.MASS,prefixes:ct.NONE,value:6479891e-11,offset:0},{name:"dr",base:ut.MASS,prefixes:ct.NONE,value:.0017718451953125,offset:0},{name:"oz",base:ut.MASS,prefixes:ct.NONE,value:.028349523125,offset:0},{name:"lbm",base:ut.MASS,prefixes:ct.NONE,value:.45359237,offset:0},{name:"cwt",base:ut.MASS,prefixes:ct.NONE,value:45.359237,offset:0},{name:"s",base:ut.TIME,prefixes:ct.SHORT,value:1,offset:0},{name:"min",base:ut.TIME,prefixes:ct.NONE,value:60,offset:0},{name:"h",base:ut.TIME,prefixes:ct.NONE,value:3600,offset:0},{name:"seconds",base:ut.TIME,prefixes:ct.LONG,value:1,offset:0},{name:"second",base:ut.TIME,prefixes:ct.LONG,value:1,offset:0},{name:"sec",base:ut.TIME,prefixes:ct.LONG,value:1,offset:0},{name:"minutes",base:ut.TIME,prefixes:ct.NONE,value:60,offset:0},{name:"minute",base:ut.TIME,prefixes:ct.NONE,value:60,offset:0},{name:"hours",base:ut.TIME,prefixes:ct.NONE,value:3600,offset:0},{name:"hour",base:ut.TIME,prefixes:ct.NONE,value:3600,offset:0},{name:"day",base:ut.TIME,prefixes:ct.NONE,value:86400,offset:0},{name:"days",base:ut.TIME,prefixes:ct.NONE,value:86400,offset:0},{name:"rad",base:ut.ANGLE,prefixes:ct.NONE,value:1,offset:0},{name:"deg",base:ut.ANGLE,prefixes:ct.NONE,value:.017453292519943295,offset:0},{name:"grad",base:ut.ANGLE,prefixes:ct.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:ut.ANGLE,prefixes:ct.NONE,value:6.283185307179586,offset:0},{name:"A",base:ut.CURRENT,prefixes:ct.SHORT,value:1,offset:0},{name:"ampere",base:ut.CURRENT,prefixes:ct.LONG,value:1,offset:0},{name:"K",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:0},{name:"degC",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:273.15},{name:"degF",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:459.67},{name:"degR",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:0},{name:"kelvin",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:0},{name:"celsius",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:273.15},{name:"fahrenheit",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:0},{name:"mol",base:ut.AMOUNT_OF_SUBSTANCE,prefixes:ct.NONE,value:1,offset:0},{name:"mole",base:ut.AMOUNT_OF_SUBSTANCE,prefixes:ct.NONE,value:1,offset:0},{name:"cd",base:ut.LUMINOUS_INTENSITY,prefixes:ct.NONE,value:1,offset:0},{name:"candela",base:ut.LUMINOUS_INTENSITY,prefixes:ct.NONE,value:1,offset:0},{name:"N",base:ut.FORCE,prefixes:ct.SHORT,value:1,offset:0},{name:"newton",base:ut.FORCE,prefixes:ct.LONG,value:1,offset:0},{name:"lbf",base:ut.FORCE,prefixes:ct.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:ut.FORCE,prefixes:ct.NONE,value:4.4482216152605,offset:0},{name:"b",base:ut.BIT,prefixes:ct.BINARY_SHORT,value:1,offset:0},{name:"bits",base:ut.BIT,prefixes:ct.BINARY_LONG,value:1,offset:0},{name:"B",base:ut.BIT,prefixes:ct.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:ut.BIT,prefixes:ct.BINARY_LONG,value:8,offset:0}],st.E=Math.E,st.LN2=Math.LN2,st.LN10=Math.LN10,st.LOG2E=Math.LOG2E,st.LOG10E=Math.LOG10E,st.PI=Math.PI,st.SQRT1_2=Math.SQRT1_2,st.SQRT2=Math.SQRT2,st.I=new n(0,-1),st.pi=st.PI,st.e=st.E,st.i=st.I,st.abs=N,N.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},st.add=O,O.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"]},st.ceil=M,M.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"]},st.cube=A,A.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"]},st.divide=S,S.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"]},st.equal=z,z.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"]},st.exp=q,q.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"]},st.fix=U,U.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"]},st.floor=R,R.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"]},st.gcd=L,L.doc={name:"gcd",category:"Arithmetic",syntax:["gcd(a, b)","gcd(a, b, c, ...)"],description:"Compute the greatest common divisor.",examples:["gcd(8, 12)","gcd(-4, 6)","gcd(25, 15, -10)"],seealso:["lcm"]},st.larger=C,C.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"]},st.largereq=_,_.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"]},st.lcm=I,I.doc={name:"lcm",category:"Arithmetic",syntax:["lcm(x, y)"],description:"Compute the least common multiple.",examples:["lcm(4, 6)","lcm(6, 21)","lcm(6, 21, 5)"],seealso:["gcd"]},st.log=P,P.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"]},st.log10=B,B.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"]},st.mod=k,k.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:[]},st.multiply=G,G.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"]},st.pow=j,j.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"]},st.round=F,F.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"]},st.sign=Y,Y.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"]},st.smaller=W,W.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"]},st.smallereq=X,X.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"]},st.sqrt=Z,Z.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"]},st.square=K,K.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"]},st.subtract=Q,Q.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"]},st.unaryminus=J,J.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},st.unequal=$,$.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"]},st.arg=en,en.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"]},st.conj=nn,nn.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"]},st.im=tn,tn.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"]},st.re=rn,rn.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"]},st.complex=an,st.matrix=on,st.parser=sn,st.range=fn,st.unit=un,st.workspace=cn,st.concat=ln,ln.doc={name:"concat",category:"Numerics",syntax:["concat(a, b, c, ...)","concat(a, b, c, ..., dim)"],description:"Concatenate matrices. By default, the matrices are concatenated by the first dimension. The dimension on which to concatenate can be provided as last argument.",examples:["a = [1, 2; 5, 6]","b = [3, 4; 7, 8]","concat(a, b)","[a, b]","concat(a, b, 2)","[a; b]"],seealso:[]},st.det=mn,mn.doc={name:"det",category:"Numerics",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["concat","diag","eye","inv","range","size","squeeze","transpose","zeros"]},st.diag=dn,dn.doc={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],description:"Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned.When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.",examples:["diag(1:4)","diag(1:4, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["concat","det","eye","inv","ones","range","size","squeeze","transpose","zeros"]},st.eye=gn,gn.doc={name:"eye",category:"Numerics",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:["concat","det","diag","inv","ones","range","size","squeeze","transpose","zeros"]},st.inv=yn,yn.doc={name:"inv",category:"Numerics",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["concat","det","diag","eye","ones","range","size","squeeze","transpose","zeros"]},st.ones=wn,wn.doc={name:"ones",category:"Numerics",syntax:["ones(n)","ones(m, n)","ones(m, n, p, ...)","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["concat","det","diag","eye","inv","range","size","squeeze","transpose","zeros"]},st.size=En,En.doc={name:"size",category:"Numerics",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:["concat","det","diag","eye","inv","ones","range","squeeze","transpose","zeros"]},st.squeeze=bn,bn.doc={name:"squeeze",category:"Numerics",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["concat","det","diag","eye","inv","ones","range","size","transpose","zeros"]},st.transpose=On,On.doc={name:"transpose",category:"Numerics",syntax:["transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","transpose(a)"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","zeros"]},st.zeros=Mn,Mn.doc={name:"zeros",category:"Numerics",syntax:["zeros(n)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","transpose"]},st.factorial=An,An.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:[]},st.random=Sn,Sn.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},st.max=Tn,Tn.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"]},st.min=Un,Un.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},st.acos=Cn,Cn.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"]},st.asin=_n,_n.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"]},st.atan=In,In.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"]},st.atan2=Pn,Pn.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"]},st.cos=Bn,Bn.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"]},st.cot=kn,kn.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"]},st.csc=Gn,Gn.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"]},st.sec=Dn,Dn.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"]},st.sin=jn,jn.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"]},st.tan=Vn,Vn.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"]},st.in=Fn,Fn.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:[]},st.clone=Hn,Hn.doc={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]},st.format=Yn,Yn.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:[]},st.help=Wn,Wn.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},st["import"]=Zn,Zn.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},st["typeof"]=Qn,Qn.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:[]},st.expr.node.Node=Jn,Jn.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") +throw E("cot",e)}function Gn(e){if(1!=arguments.length)throw b("csc",arguments.length,1);if(v(e))return 1/Math.sin(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Gn);if(e.valueOf()!==e)return Gn(e.valueOf());throw E("csc",e)}function Dn(e){if(1!=arguments.length)throw b("sec",arguments.length,1);if(v(e))return 1/Math.cos(e);if(e instanceof n){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new n(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/r,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Dn);if(e.valueOf()!==e)return Dn(e.valueOf());throw E("sec",e)}function jn(e){if(1!=arguments.length)throw b("sin",arguments.length,1);if(v(e))return Math.sin(e);if(e instanceof n)return new n(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.cos(e.re)*(Math.exp(e.im)-Math.exp(-e.im)));if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,jn);if(e.valueOf()!==e)return jn(e.valueOf());throw E("sin",e)}function Vn(e){if(1!=arguments.length)throw b("tan",arguments.length,1);if(v(e))return Math.tan(e);if(e instanceof n){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new n(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/r,(1-Math.exp(-4*e.im))/r)}if(e instanceof x){if(!e.hasBase(x.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof t||e instanceof g)return ft.map(e,Vn);if(e.valueOf()!==e)return Vn(e.valueOf());throw E("tan",e)}function Fn(e,n){if(2!=arguments.length)throw b("in",arguments.length,2);if(e instanceof x&&(n instanceof x||y(n)))return e.in(n);if(e instanceof Array||e instanceof t||e instanceof g||n instanceof Array||n instanceof t||n instanceof g)return ft.map2(e,n,Fn);if(e.valueOf()!==e)return st.in(e.valueOf());throw E("in",e,n)}function Hn(n){if(1!=arguments.length)throw b("clone",arguments.length,1);if(null==n)return n;if("function"==typeof n.clone)return n.clone();if(v(n)||y(n)||e(n))return n;if(n instanceof Array)return n.map(function(e){return Hn(e)});if(n instanceof Object)return ft.mapObject(n,Hn);throw E("clone",n)}function Yn(e,n){var t=arguments.length;if(1!=t&&2!=t)throw b("format",t,1,2);if(1==t){var r=arguments[0];return v(r)?ft.formatNumber(r):r instanceof Array?ft.formatArray(r):y(r)?'"'+r+'"':r instanceof Object?""+r:r+""}if(!y(e))throw new TypeError("String expected as first parameter in function format");if(!(n instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,t){for(var r=t.split("."),a=n[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})}function Wn(e){if(1!=arguments.length)throw b("help",arguments.length,1);if(void 0!=e){if(e.doc)return Xn(e.doc);if(e.constructor.doc)return Xn(e.constructor.doc);if(y(e)){var n=st[e];if(n&&n.doc)return Xn(n.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 Xn(e){var n="";if(e.name&&(n+="NAME\n"+e.name+"\n\n"),e.category&&(n+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(n+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var t=st.parser();n+="EXAMPLES\n";for(var r=0;e.examples.length>r;r++){var a,i=e.examples[r];try{a=t.eval(i)}catch(o){a=o}n+=i+"\n",n+=" "+st.format(a)+"\n"}n+="\n"}return e.seealso&&(n+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),n}function Zn(e,n){var t;if(y(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var r=require(e);Zn(r)}else if(Kn(e)){if(t=e.name,!t)throw Error("Cannot import an unnamed function");(n||void 0===st[t])&&(st[t]=e)}else if(e instanceof Object)for(t in e)if(e.hasOwnProperty(t)){var a=e[t];Kn(a)?(n||void 0===st[t])&&(st[t]=a):Zn(a)}}function Kn(e){return"function"==typeof e||v(e)||y(e)||e instanceof n||e instanceof x}function Qn(e){if(1!=arguments.length)throw b("typeof",arguments.length,1);var n=typeof e;if("object"==n){if(null==e)return"null";if(e.constructor){for(var t in st)if(st.hasOwnProperty(t)&&e.constructor==st[t])return t.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return n}function Jn(){}function $n(e,n,t){this.name=e,this.fn=n,this.params=t}function et(e){this.value=e}function nt(e){this.nodes=e||[]}function tt(){this.params=[],this.visible=[]}function rt(e,n,t,r){this.name=e,this.params=n,this.expr=t,this.result=r}function at(e,n){this.object=e,this.params=n}function it(e,n,t,r,a){this.name=e,this.variables=t,this.values=[];for(var i=0,o=this.variables.length;o>i;i++)this.values[i]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,n,t,r),this.result=a}function ot(e,n){throw Error('Constructor "'+e+'" has been replaced by '+'constructor method "'+n+'" in math.js v0.5.0')}var st={type:{},expr:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=st),"undefined"!=typeof exports&&(exports=st),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return st}),"undefined"!=typeof window&&(window.math=st);var ft=function(){function e(n){if(n instanceof Array){var t=n.length;if(t){var r=e(n[0]);return 0==r[0]?[0].concat(r):[t].concat(r)}return[t]}return[]}function n(e,t,r){var a,i=e.length;if(i!=t[r])throw new RangeError("Dimension mismatch ("+i+" != "+t[r]+")");if(t.length-1>r){var o=r+1;for(a=0;i>a;a++){var s=e[a];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");n(e[a],t,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(t.length+1)+" > "+t.length+")")}function r(e,n,t){if(n.length-1>t){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(a,n,t+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,n,t,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=n[t];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?Hn(r):0;else e.length=n[t];i=e.length}if(n.length-1>t){var f=t+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,n,f,r)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var i={};return i.formatNumber=function(e,n){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var t=Math.abs(e);if(t>1e-4&&1e6>t||0==t)return H(e,n)+"";var r=Math.round(Math.log(t)/Math.LN10),a=e/Math.pow(10,r);return H(a,n)+"E"+r},i.formatArray=function(e){if(e instanceof Array){for(var n="[",t=e.length,r=0;t>r;r++)0!=r&&(n+=", "),n+=i.formatArray(e[r]);return n+="]"}return st.format(e)},i.formatArray2d=function(e){var n="[",t=i.size(e);if(2!=t.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(t)+")");for(var r=t[0],a=t[1],o=0;r>o;o++){0!=o&&(n+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(n+=", ");var u=s[f];void 0!=u&&(n+=Yn(u))}}return n+="]"},i.argsToArray=function(e){var n;if(0==e.length)n=[];else if(1==e.length)n=e[0],n instanceof t&&(n=n.toVector()),n instanceof g&&(n=n.valueOf()),n instanceof Array||(n=[n]);else{n=[];for(var r=0;e.length>r;r++)n[r]=e[r]}return n},i.endsWith=function(e,n){var t=e.length-n.length,r=e.length;return e.substring(t,r)===n},i.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},i.map=function(e,n){if(e instanceof Array||e instanceof t||e instanceof g)return e.map(function(e){return n(e)});throw new TypeError("Array expected")},i.map2=function(e,n,r){var a,o,s;if(e instanceof t||n instanceof t)return new t(i.map2(e.valueOf(),n.valueOf(),r));if(e instanceof g||n instanceof g)return new t(i.map2(e.valueOf(),n.valueOf(),r));if(e instanceof Array)if(n instanceof Array){if(e.length!=n.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+n.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],n[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],n);else if(n instanceof Array)for(a=[],o=n.length,s=0;o>s;s++)a[s]=r(e,n[s]);else a=r(e,n);return a},i.forEach=function(e,n){if(e instanceof Array)e.forEach(n);else for(var t in e)e.hasOwnProperty(t)&&n(e[t],t,e)},i.mapObject=function(e,n){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},i.deepEqual=function(e,n){var t,r,a;if(e instanceof Array){if(!(n instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],n[r]))return!1;return!0}if(e instanceof Object){if(n instanceof Array||!(n instanceof Object))return!1;for(t in e)if(e.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;for(t in n)if(n.hasOwnProperty(t)&&!i.deepEqual(e[t],n[t]))return!1;return!0}return e.valueOf()==n.valueOf()},i.size=function(n){var t=e(n);return i.validate(n,t),t},i.validate=function(e,t){var a=0==t.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=t.indexOf(0);o?(t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(t)+")")}),r(e,t,0)):n(e,t,0)}},i.resize=function(e,n,t){if(!(n instanceof Array))throw new TypeError("Size must be an array (size is "+st.typeof(n)+")");n.forEach(function(e){if(!v(e)||!d(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(n)+")")});var r=-1!=n.indexOf(0);r&&n.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(n)+")")}),a(e,n,0,t)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;this.length>n;n++)if(this[n]==e)return n;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,n){for(var t=0,r=this.length;r>t;++t)e.call(n||this,this[t],t,this)}),Array.prototype.map||(Array.prototype.map=function(e,n){var t,r,a;if(null==this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(n&&(t=n),r=Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(t,s,a,i),r[a]=f),a++}return r}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&!e.call(r,n[a],a,n))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var n=Object(this),t=n.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;t>a;a++)if(a in n&&e.call(r,n[a],a,n))return!0;return!1}),i}();st.type.Complex=n,function(){function e(){for(;" "==c||" "==c;)a()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function a(){u++,c=f[u]}function i(e){u=e,c=f[u]}function o(){var e="",n=u;if("+"==c?a():"-"==c&&(e+=c,a()),!t(c))return i(n),null;for(;t(c);)e+=c,a();if("E"==c||"e"==c){if(e+=c,a(),("+"==c||"-"==c)&&(e+=c,a()),!r(c))return i(n),null;for(;r(c);)e+=c,a()}return e}function s(){var e=f[u+1];if("I"==c||"i"==c)return a(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var n="+"==c?"1":"-1";return a(),a(),n}return null}var f,u,c;n.parse=function(t){if(f=t,u=-1,c="",!y(f))return null;a(),e();var r=o();if(r){if("I"==c||"i"==c)return a(),e(),c?null:new n(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new n(Number(r),0);a(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;a()}else if(l=s(),!l)return null;return"-"==i&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),a(),e(),c?null:new n(Number(r),Number(l))}return(r=s())?(e(),c?null:new n(0,Number(r))):null}}(),n.prototype.clone=function(){return new n(this.re,this.im)},n.prototype.toString=function(){var e="",n=ft.formatNumber(this.re),t=ft.formatNumber(this.im);return e=0==this.im?n:0==this.re?1==this.im?"i":-1==this.im?"-i":t+"i":this.im>0?1==this.im?n+" + i":n+" + "+t+"i":-1==this.im?n+" - i":n+" - "+ft.formatNumber(Math.abs(this.im))+"i"},n.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"]},st.type.Matrix=t,t.prototype.get=function(e){var n;if(e instanceof t)n=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+st.typeof(e));n=!e.some(function(e){return e.forEach})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(n)switch(e.length){case 1:return a(this._data,e[0]);case 2:return a(a(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new t(o(this._data,e));case 2:return new t(s(this._data,e));default:return new t(f(this._data,e,0))}},t.prototype.set=function(e,n){var r;if(e instanceof t)r=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+st.typeof(e));r=!e.some(function(e){return e.forEach})}if((n instanceof t||n instanceof g)&&(n=n.valueOf()),e.length=e})},t.prototype.toVector=function(){var e=0,n=void 0,t=[];if(this._size.forEach(function(r,a){r>1&&(e++,n=a),t[a]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var a=[],i=function(e){e instanceof Array?e.forEach(i):a.push(e)};return i(this._data),a}return null},t.prototype.isVector=function(){var e=0;return this._size.forEach(function(n){n>1&&e++}),1>=e},t.prototype.toArray=function(){return Hn(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.toString=function(){return ft.formatArray(this._data)},st.type.Range=g,g.parse=function(e){if(!y(e))return null;var n=e.split(":"),t=n.map(function(e){return Number(e)}),r=t.some(function(e){return isNaN(e)});if(r)return null;switch(t.length){case 2:return new g(t[0],1,t[1]);case 3:return new g(t[0],t[1],t[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,n=Number(this.start),t=Number(this.step),r=Number(this.end),a=r-n;return Y(t)==Y(a)?e=Math.floor(a/t)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var n=Number(this.start),t=Number(this.step),r=Number(this.end),a=0;if(t>0)for(;r>=n;)e(n,a,this),n+=t,a++;else if(0>t)for(;n>=r;)e(n,a,this),n+=t,a++},g.prototype.map=function(e){var n=[];return this.forEach(function(t,r,a){n[r]=e(t,r,a)}),n},g.prototype.toMatrix=function(){return new t(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(n,t){e[t]=n}),e},g.prototype.toVector=g.prototype.toArray,g.prototype.isVector=function(){return!0},g.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},g.prototype.isScalar=function(){return 1==this.size()[0]},g.prototype.valueOf=function(){return this.toArray()},g.prototype.toString=function(){var e=Yn(Number(this.start));return 1!=this.step&&(e+=":"+Yn(Number(this.step))),e+=":"+Yn(Number(this.end))},st.type.Unit=x,function(){function e(){for(;" "==u||" "==u;)r()}function n(e){return e>="0"&&"9">=e||"."==e}function t(e){return e>="0"&&"9">=e}function r(){f++,u=s[f]}function a(e){f=e,u=s[f]}function i(){var e="",i=f;if("+"==u?r():"-"==u&&(e+=u,r()),!n(u))return a(i),null;for(;n(u);)e+=u,r();if("E"==u||"e"==u){if(e+=u,r(),("+"==u||"-"==u)&&(e+=u,r()),!t(u))return a(i),null;for(;t(u);)e+=u,r()}return e}function o(){var n="";for(e();u&&" "!=u&&" "!=u;)n+=u,r();return n||null}var s,f,u;x.parse=function(n){if(s=n,f=-1,u="",!y(s))return null;r(),e();var t,a=i();return a?(t=o(),r(),e(),u?null:a&&t?new x(Number(a),t):null):(t=o(),r(),e(),u?null:new x(null,t))}}(),x.prototype.clone=function(){var e=new x;for(var n in this)this.hasOwnProperty(n)&&(e[n]=this[n]);return e},x.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},x.prototype._unnormalize=function(e,n){return void 0==n?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/n-this.unit.offset},x.isPlainUnit=function(e){return null!=w(e)},x.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},x.prototype.equalBase=function(e){return this.unit.base===e.unit.base},x.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},x.prototype.in=function(e){var n;if(y(e)){if(n=new x(null,e),!this.equalBase(n))throw Error("Units do not match");return n.value=this.value,n}if(e instanceof x){if(!this.equalBase(e))throw Error("Units do not match");if(e.hasValue)throw Error("Cannot convert to a unit with a value");if(!e.hasUnit)throw Error("Unit expected on the right hand side of function in");return n=e.clone(),n.value=this.value,n.fixPrefix=!0,n}throw Error("String or Unit expected as parameter")},x.prototype.toNumber=function(e){var n=this.in(e),t=this.fixPrefix?n._bestPrefix():n.prefix;return n._unnormalize(n.value,t.value)},x.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),ft.formatNumber(e)+" "+this.prefix.name+this.unit.name;var n=this._bestPrefix();return e=this._unnormalize(this.value,n.value),ft.formatNumber(e)+" "+n.name+this.unit.name},x.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),n=x.PREFIX_NONE,t=Math.abs(Math.log(e/n.value)/Math.LN10-1.2),r=this.unit.prefixes;for(var a in r)if(r.hasOwnProperty(a)){var i=r[a];if(i.scientific){var o=Math.abs(Math.log(e/i.value)/Math.LN10-1.2);t>o&&(n=i,t=o)}}return n},x.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}}},x.PREFIX_NONE={name:"",value:1,scientific:!0},x.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var ut=x.BASE_UNITS,ct=x.PREFIXES;x.BASE_UNIT_NONE={},x.UNIT_NONE={name:"",base:x.BASE_UNIT_NONE,value:1,offset:0},x.UNITS=[{name:"meter",base:ut.LENGTH,prefixes:ct.LONG,value:1,offset:0},{name:"inch",base:ut.LENGTH,prefixes:ct.NONE,value:.0254,offset:0},{name:"foot",base:ut.LENGTH,prefixes:ct.NONE,value:.3048,offset:0},{name:"yard",base:ut.LENGTH,prefixes:ct.NONE,value:.9144,offset:0},{name:"mile",base:ut.LENGTH,prefixes:ct.NONE,value:1609.344,offset:0},{name:"link",base:ut.LENGTH,prefixes:ct.NONE,value:.201168,offset:0},{name:"rod",base:ut.LENGTH,prefixes:ct.NONE,value:5.02921,offset:0},{name:"chain",base:ut.LENGTH,prefixes:ct.NONE,value:20.1168,offset:0},{name:"angstrom",base:ut.LENGTH,prefixes:ct.NONE,value:1e-10,offset:0},{name:"m",base:ut.LENGTH,prefixes:ct.SHORT,value:1,offset:0},{name:"ft",base:ut.LENGTH,prefixes:ct.NONE,value:.3048,offset:0},{name:"yd",base:ut.LENGTH,prefixes:ct.NONE,value:.9144,offset:0},{name:"mi",base:ut.LENGTH,prefixes:ct.NONE,value:1609.344,offset:0},{name:"li",base:ut.LENGTH,prefixes:ct.NONE,value:.201168,offset:0},{name:"rd",base:ut.LENGTH,prefixes:ct.NONE,value:5.02921,offset:0},{name:"ch",base:ut.LENGTH,prefixes:ct.NONE,value:20.1168,offset:0},{name:"mil",base:ut.LENGTH,prefixes:ct.NONE,value:254e-7,offset:0},{name:"m2",base:ut.SURFACE,prefixes:ct.SHORT,value:1,offset:0},{name:"sqin",base:ut.SURFACE,prefixes:ct.NONE,value:64516e-8,offset:0},{name:"sqft",base:ut.SURFACE,prefixes:ct.NONE,value:.09290304,offset:0},{name:"sqyd",base:ut.SURFACE,prefixes:ct.NONE,value:.83612736,offset:0},{name:"sqmi",base:ut.SURFACE,prefixes:ct.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:ut.SURFACE,prefixes:ct.NONE,value:25.29295,offset:0},{name:"sqch",base:ut.SURFACE,prefixes:ct.NONE,value:404.6873,offset:0},{name:"sqmil",base:ut.SURFACE,prefixes:ct.NONE,value:6.4516e-10,offset:0},{name:"m3",base:ut.VOLUME,prefixes:ct.SHORT,value:1,offset:0},{name:"L",base:ut.VOLUME,prefixes:ct.SHORT,value:.001,offset:0},{name:"litre",base:ut.VOLUME,prefixes:ct.LONG,value:.001,offset:0},{name:"cuin",base:ut.VOLUME,prefixes:ct.NONE,value:16387064e-12,offset:0},{name:"cuft",base:ut.VOLUME,prefixes:ct.NONE,value:.028316846592,offset:0},{name:"cuyd",base:ut.VOLUME,prefixes:ct.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:ut.VOLUME,prefixes:ct.NONE,value:5e-6,offset:0},{name:"tablespoon",base:ut.VOLUME,prefixes:ct.NONE,value:15e-6,offset:0},{name:"minim",base:ut.VOLUME,prefixes:ct.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:ut.VOLUME,prefixes:ct.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:ut.VOLUME,prefixes:ct.NONE,value:2957353e-11,offset:0},{name:"gill",base:ut.VOLUME,prefixes:ct.NONE,value:.0001182941,offset:0},{name:"cup",base:ut.VOLUME,prefixes:ct.NONE,value:.0002365882,offset:0},{name:"pint",base:ut.VOLUME,prefixes:ct.NONE,value:.0004731765,offset:0},{name:"quart",base:ut.VOLUME,prefixes:ct.NONE,value:.0009463529,offset:0},{name:"gallon",base:ut.VOLUME,prefixes:ct.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:ut.VOLUME,prefixes:ct.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:ut.VOLUME,prefixes:ct.NONE,value:.1589873,offset:0},{name:"hogshead",base:ut.VOLUME,prefixes:ct.NONE,value:.238481,offset:0},{name:"fldr",base:ut.VOLUME,prefixes:ct.NONE,value:36966911e-13,offset:0},{name:"floz",base:ut.VOLUME,prefixes:ct.NONE,value:2957353e-11,offset:0},{name:"gi",base:ut.VOLUME,prefixes:ct.NONE,value:.0001182941,offset:0},{name:"cp",base:ut.VOLUME,prefixes:ct.NONE,value:.0002365882,offset:0},{name:"pt",base:ut.VOLUME,prefixes:ct.NONE,value:.0004731765,offset:0},{name:"qt",base:ut.VOLUME,prefixes:ct.NONE,value:.0009463529,offset:0},{name:"gal",base:ut.VOLUME,prefixes:ct.NONE,value:.003785412,offset:0},{name:"bbl",base:ut.VOLUME,prefixes:ct.NONE,value:.1173478,offset:0},{name:"obl",base:ut.VOLUME,prefixes:ct.NONE,value:.1589873,offset:0},{name:"g",base:ut.MASS,prefixes:ct.SHORT,value:.001,offset:0},{name:"gram",base:ut.MASS,prefixes:ct.LONG,value:.001,offset:0},{name:"ton",base:ut.MASS,prefixes:ct.SHORT,value:907.18474,offset:0},{name:"tonne",base:ut.MASS,prefixes:ct.SHORT,value:1e3,offset:0},{name:"grain",base:ut.MASS,prefixes:ct.NONE,value:6479891e-11,offset:0},{name:"dram",base:ut.MASS,prefixes:ct.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:ut.MASS,prefixes:ct.NONE,value:.028349523125,offset:0},{name:"poundmass",base:ut.MASS,prefixes:ct.NONE,value:.45359237,offset:0},{name:"hundredweight",base:ut.MASS,prefixes:ct.NONE,value:45.359237,offset:0},{name:"stick",base:ut.MASS,prefixes:ct.NONE,value:.115,offset:0},{name:"gr",base:ut.MASS,prefixes:ct.NONE,value:6479891e-11,offset:0},{name:"dr",base:ut.MASS,prefixes:ct.NONE,value:.0017718451953125,offset:0},{name:"oz",base:ut.MASS,prefixes:ct.NONE,value:.028349523125,offset:0},{name:"lbm",base:ut.MASS,prefixes:ct.NONE,value:.45359237,offset:0},{name:"cwt",base:ut.MASS,prefixes:ct.NONE,value:45.359237,offset:0},{name:"s",base:ut.TIME,prefixes:ct.SHORT,value:1,offset:0},{name:"min",base:ut.TIME,prefixes:ct.NONE,value:60,offset:0},{name:"h",base:ut.TIME,prefixes:ct.NONE,value:3600,offset:0},{name:"seconds",base:ut.TIME,prefixes:ct.LONG,value:1,offset:0},{name:"second",base:ut.TIME,prefixes:ct.LONG,value:1,offset:0},{name:"sec",base:ut.TIME,prefixes:ct.LONG,value:1,offset:0},{name:"minutes",base:ut.TIME,prefixes:ct.NONE,value:60,offset:0},{name:"minute",base:ut.TIME,prefixes:ct.NONE,value:60,offset:0},{name:"hours",base:ut.TIME,prefixes:ct.NONE,value:3600,offset:0},{name:"hour",base:ut.TIME,prefixes:ct.NONE,value:3600,offset:0},{name:"day",base:ut.TIME,prefixes:ct.NONE,value:86400,offset:0},{name:"days",base:ut.TIME,prefixes:ct.NONE,value:86400,offset:0},{name:"rad",base:ut.ANGLE,prefixes:ct.NONE,value:1,offset:0},{name:"deg",base:ut.ANGLE,prefixes:ct.NONE,value:.017453292519943295,offset:0},{name:"grad",base:ut.ANGLE,prefixes:ct.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:ut.ANGLE,prefixes:ct.NONE,value:6.283185307179586,offset:0},{name:"A",base:ut.CURRENT,prefixes:ct.SHORT,value:1,offset:0},{name:"ampere",base:ut.CURRENT,prefixes:ct.LONG,value:1,offset:0},{name:"K",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:0},{name:"degC",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:273.15},{name:"degF",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:459.67},{name:"degR",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:0},{name:"kelvin",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:0},{name:"celsius",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1,offset:273.15},{name:"fahrenheit",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:ut.TEMPERATURE,prefixes:ct.NONE,value:1/1.8,offset:0},{name:"mol",base:ut.AMOUNT_OF_SUBSTANCE,prefixes:ct.NONE,value:1,offset:0},{name:"mole",base:ut.AMOUNT_OF_SUBSTANCE,prefixes:ct.NONE,value:1,offset:0},{name:"cd",base:ut.LUMINOUS_INTENSITY,prefixes:ct.NONE,value:1,offset:0},{name:"candela",base:ut.LUMINOUS_INTENSITY,prefixes:ct.NONE,value:1,offset:0},{name:"N",base:ut.FORCE,prefixes:ct.SHORT,value:1,offset:0},{name:"newton",base:ut.FORCE,prefixes:ct.LONG,value:1,offset:0},{name:"lbf",base:ut.FORCE,prefixes:ct.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:ut.FORCE,prefixes:ct.NONE,value:4.4482216152605,offset:0},{name:"b",base:ut.BIT,prefixes:ct.BINARY_SHORT,value:1,offset:0},{name:"bits",base:ut.BIT,prefixes:ct.BINARY_LONG,value:1,offset:0},{name:"B",base:ut.BIT,prefixes:ct.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:ut.BIT,prefixes:ct.BINARY_LONG,value:8,offset:0}],st.E=Math.E,st.LN2=Math.LN2,st.LN10=Math.LN10,st.LOG2E=Math.LOG2E,st.LOG10E=Math.LOG10E,st.PI=Math.PI,st.SQRT1_2=Math.SQRT1_2,st.SQRT2=Math.SQRT2,st.I=new n(0,-1),st.pi=st.PI,st.e=st.E,st.i=st.I,st.abs=N,N.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},st.add=O,O.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"]},st.ceil=M,M.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"]},st.cube=A,A.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"]},st.divide=S,S.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"]},st.equal=z,z.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"]},st.exp=q,q.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"]},st.fix=U,U.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"]},st.floor=R,R.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"]},st.gcd=L,L.doc={name:"gcd",category:"Arithmetic",syntax:["gcd(a, b)","gcd(a, b, c, ...)"],description:"Compute the greatest common divisor.",examples:["gcd(8, 12)","gcd(-4, 6)","gcd(25, 15, -10)"],seealso:["lcm"]},st.larger=C,C.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"]},st.largereq=_,_.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"]},st.lcm=I,I.doc={name:"lcm",category:"Arithmetic",syntax:["lcm(x, y)"],description:"Compute the least common multiple.",examples:["lcm(4, 6)","lcm(6, 21)","lcm(6, 21, 5)"],seealso:["gcd"]},st.log=P,P.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"]},st.log10=B,B.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"]},st.mod=k,k.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:[]},st.multiply=G,G.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"]},st.pow=j,j.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"]},st.round=F,F.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"]},st.sign=Y,Y.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"]},st.smaller=W,W.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"]},st.smallereq=X,X.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"]},st.sqrt=Z,Z.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"]},st.square=K,K.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"]},st.subtract=Q,Q.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"]},st.unaryminus=J,J.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},st.unequal=$,$.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"]},st.arg=en,en.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"]},st.conj=nn,nn.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"]},st.im=tn,tn.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"]},st.re=rn,rn.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"]},st.complex=an,st.matrix=on,st.parser=sn,st.range=fn,st.unit=un,st.workspace=cn,st.concat=ln,ln.doc={name:"concat",category:"Numerics",syntax:["concat(a, b, c, ...)","concat(a, b, c, ..., dim)"],description:"Concatenate matrices. By default, the matrices are concatenated by the first dimension. The dimension on which to concatenate can be provided as last argument.",examples:["a = [1, 2; 5, 6]","b = [3, 4; 7, 8]","concat(a, b)","[a, b]","concat(a, b, 2)","[a; b]"],seealso:[]},st.det=mn,mn.doc={name:"det",category:"Numerics",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["concat","diag","eye","inv","range","size","squeeze","transpose","zeros"]},st.diag=dn,dn.doc={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],description:"Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned.When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.",examples:["diag(1:4)","diag(1:4, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["concat","det","eye","inv","ones","range","size","squeeze","transpose","zeros"]},st.eye=gn,gn.doc={name:"eye",category:"Numerics",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:["concat","det","diag","inv","ones","range","size","squeeze","transpose","zeros"]},st.inv=yn,yn.doc={name:"inv",category:"Numerics",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["concat","det","diag","eye","ones","range","size","squeeze","transpose","zeros"]},st.ones=wn,wn.doc={name:"ones",category:"Numerics",syntax:["ones(n)","ones(m, n)","ones(m, n, p, ...)","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["concat","det","diag","eye","inv","range","size","squeeze","transpose","zeros"]},st.size=En,En.doc={name:"size",category:"Numerics",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:["concat","det","diag","eye","inv","ones","range","squeeze","transpose","zeros"]},st.squeeze=bn,bn.doc={name:"squeeze",category:"Numerics",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["concat","det","diag","eye","inv","ones","range","size","transpose","zeros"]},st.transpose=On,On.doc={name:"transpose",category:"Numerics",syntax:["transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","transpose(a)"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","zeros"]},st.zeros=Mn,Mn.doc={name:"zeros",category:"Numerics",syntax:["zeros(n)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","transpose"]},st.factorial=An,An.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:[]},st.random=Sn,Sn.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},st.max=Tn,Tn.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"]},st.min=Un,Un.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},st.acos=Cn,Cn.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"]},st.asin=_n,_n.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"]},st.atan=In,In.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"]},st.atan2=Pn,Pn.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"]},st.cos=Bn,Bn.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"]},st.cot=kn,kn.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"]},st.csc=Gn,Gn.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"]},st.sec=Dn,Dn.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"]},st.sin=jn,jn.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"]},st.tan=Vn,Vn.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"]},st.in=Fn,Fn.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:[]},st.clone=Hn,Hn.doc={name:"clone",category:"Utils",syntax:["clone(x)"],description:"Clone a variable. Creates a copy of primitive variables,and a deep copy of matrices",examples:["clone(3.5)","clone(2 - 4i)","clone(45 deg)","clone([1, 2; 3, 4])",'clone("hello world")'],seealso:[]},st.format=Yn,Yn.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:[]},st.help=Wn,Wn.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},st["import"]=Zn,Zn.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},st["typeof"]=Qn,Qn.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:[]},st.expr.node.Node=Jn,Jn.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") },Jn.prototype.toString=function(){return""},$n.prototype=new Jn,st.expr.node.Symbol=$n,$n.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},$n.prototype.eval=function(){var e=this.fn;if(void 0===e)throw Error("Undefined symbol "+this.name);var n=this.params.map(function(e){return e.eval()});return e.apply(this,n)},$n.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},et.prototype=new Jn,st.expr.node.Constant=et,et.prototype.eval=function(){return this.value},et.prototype.toString=function(){return this.value?st.format(this.value):""},nt.prototype=new Jn,st.expr.node.MatrixNode=nt,function(){function e(n){return n.map(function(n){return n instanceof Array?e(n):n.eval()})}function n(e){for(var n=[],r=e.length,a=0;r>a;a++){for(var i=e[a],o=i.length,s=null,f=null,u=0;o>u;u++){var c,l=st.clone(i[u]);if(l instanceof t){if(c=l.size(),l=l.valueOf(),1==c.length)l=[l],c=[1,c[0]];else if(c.length>2)throw Error("Cannot merge a multi dimensional matrix")}else l instanceof g?(l=[l.valueOf()],c=[1,l[0].length]):(c=[1,1],l=[[l]]);if(null==s)s=l,f=c[0];else{if(c[0]!=f)throw Error("Dimension mismatch ("+c[0]+" != "+f+")");for(var h=0;f>h;h++)s[h]=s[h].concat(l[h])}}n=n.concat(s)}return n}function r(e){return e.some(function(e){return e instanceof t||e instanceof g?!0:e instanceof Array?r(e):!1})}nt.prototype.eval=function(){var a=e(this.nodes);return r(a)&&(a=n(a)),new t(a)},nt.prototype.toString=function(){return ft.formatArray(this.nodes)}}(),tt.prototype=new Jn,st.expr.node.Block=tt,tt.prototype.add=function(e,n){var t=this.params.length;this.params[t]=e,this.visible[t]=void 0!=n?n:!0},tt.prototype.eval=function(){for(var e=[],n=0,t=this.params.length;t>n;n++){var r=this.params[n].eval();this.visible[n]&&e.push(r)}return e},tt.prototype.toString=function(){for(var e=[],n=0,t=this.params.length;t>n;n++)this.visible[n]&&e.push("\n "+(""+this.params[n]));return"["+e.join(",")+"\n]"},rt.prototype=new Jn,st.expr.node.Assignment=rt,rt.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,n=this.params;if(n&&n.length){var t=[];this.params.forEach(function(e){t.push(e.eval())});var r=this.expr.eval();if(void 0==this.result.value)throw Error("Undefined symbol "+this.name);var a=this.result();if(!a.set)throw new TypeError("Cannot apply a subset to object of type "+st.typeof(a));e=a.set(t,r),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},rt.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},at.prototype=new Jn,st.expr.node.Arguments=at,at.prototype.eval=function(){var e=this.object;if(void 0==e)throw Error("Node undefined");for(var n=e.eval(),t=this.params,r=[],a=0,i=t.length;i>a;a++)r[a]=t[a].eval();if(!n.get)throw new TypeError("Cannot apply arguments to object of type "+st.typeof(n));return n.get(r)},at.prototype.toString=function(){var e=this.object?""+this.object:"";return this.params&&(e+="("+this.params.join(", ")+")"),e},it.prototype=new Jn,st.expr.node.FunctionAssignment=it,it.prototype.createFunction=function(e,n,t,r){var a=function(){var n=t?t.length:0,a=arguments?arguments.length:0;if(n!=a)throw b(e,a,n);if(n>0)for(var i=0;n>i;i++)t[i].value=arguments[i];return r.eval()};return a.toString=function(){return e+"("+n.join(", ")+")"},a},it.prototype.eval=function(){for(var e=this.variables,n=this.values,t=0,r=e.length;r>t;t++)e[t].value=n[t];return this.result.value=this.def,this.def},it.prototype.toString=function(){return""+this.def},function(){function e(e){this.parentScope=e,this.nestedScopes=void 0,this.symbols={},this.defs={},this.updates={},this.links={}}st.expr.Scope=e,e.prototype.createNestedScope=function(){var n=new e(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(n),n},e.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,n=0,t=e.length;t>n;n++)e[n].clear()},e.prototype.createSymbol=function(e){var n=this.symbols[e];if(!n){var t=this.findDef(e);n=this.newSymbol(e,t),this.symbols[e]=n}return n},e.prototype.newSymbol=function(e,n){var r=this,a=function(){var n,i;if(!a.value&&(a.value=r.findDef(e),!a.value))throw Error("Undefined symbol "+e);if("function"==typeof a.value)return a.value.apply(null,arguments);if(a.value instanceof t||a.value instanceof g||a.value instanceof Array){if(arguments.length){var o=a.value instanceof Array?new t(a.value):a.value;for(n=[],i=0;arguments.length>i;i++)n[i]=arguments[i];return o.get(n)}return a.value}return a.value};return a.value=n,a.toString=function(){return a.value?""+a.value:""},a},e.prototype.createLink=function(e){var n=this.links[e];return n||(n=this.createSymbol(e),this.links[e]=n),n},e.prototype.createDef=function(e,n){var t=this.defs[e];return t||(t=this.createSymbol(e),this.defs[e]=t),t&&void 0!=n&&(t.value=n),t},e.prototype.createUpdate=function(e){var n=this.updates[e];return n||(n=this.createLink(e),this.updates[e]=n),n},e.prototype.findDef=function(e){function t(e,n){var t=a(e,n);return i[e]=t,o[e]=t,t}var r;if(r=this.defs[e])return r;if(r=this.updates[e])return r;if(this.parentScope)return this.parentScope.findDef(e);var a=this.newSymbol,i=this.symbols,o=this.defs;if("pi"==e)return t(e,st.PI);if("e"==e)return t(e,st.E);if("i"==e)return t(e,new n(0,1));var s=st[e];if(s)return t(e,s);if(x.isPlainUnit(e)){var f=new x(null,e);return t(e,f)}return void 0},e.prototype.removeLink=function(e){delete this.links[e]},e.prototype.removeDef=function(e){delete this.defs[e]},e.prototype.removeUpdate=function(e){delete this.updates[e]},e.prototype.init=function(){var e=this.symbols,n=this.parentScope;for(var t in e)if(e.hasOwnProperty(t)){var r=e[t];r.value=n?n.findDef(t):void 0}this.nestedScopes&&this.nestedScopes.forEach(function(e){e.init()})},e.prototype.hasLink=function(e){if(this.links[e])return!0;if(this.nestedScopes)for(var n=this.nestedScopes,t=0,r=n.length;r>t;t++)if(n[t].hasLink(e))return!0;return!1},e.prototype.hasDef=function(e){return void 0!=this.defs[e]},e.prototype.hasUpdate=function(e){return void 0!=this.updates[e]},e.prototype.getUndefinedSymbols=function(){var e=this.symbols,n=[];for(var t in e)if(e.hasOwnProperty(t)){var r=e[t];void 0==r.value&&n.push(r)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){n=n.concat(e.getUndefinedSymbols())}),n}}(),function(){function e(){D++,V=G.charAt(D)}function t(){D=0,V=G.charAt(0)}function r(){for(H=k.NULL,F="";" "==V||" "==V;)e();if("#"==V)for(;"\n"!=V&&""!=V;)e();if(""==V)return H=k.DELIMITER,void 0;if("-"==V||","==V||"("==V||")"==V||"["==V||"]"==V||'"'==V||"\n"==V||";"==V||":"==V||"!"==V||"'"==V)return H=k.DELIMITER,F+=V,e(),void 0;if(a(V))for(H=k.DELIMITER;a(V);)F+=V,e();else if(o(V)){for(H=k.NUMBER;o(V);)F+=V,e();if("E"==V||"e"==V)for(F+=V,e(),("+"==V||"-"==V)&&(F+=V,e()),s(V)||(H=k.UNKNOWN);s(V);)F+=V,e()}else{if(!i(V)){for(H=k.UNKNOWN;""!=V;)F+=V,e();throw _('Syntax error in part "'+F+'"')}for(H=k.SYMBOL;i(V)||s(V);)F+=V,e()}}function a(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e||"'"==e}function i(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function o(e){return e>="0"&&"9">=e||"."==e}function s(e){return e>="0"&&"9">=e}function f(e){t(),r();var n;if(n=""==F?new et(void 0):c(e),""!=F)throw H==k.DELIMITER?P("Unknown operator "+F):_('Unexpected part "'+F+'"');return n}function u(e){var n=l(e);if(!(n instanceof rt)){var t="ans",r=void 0,a=e.createDef(t);return new rt(t,r,n,a)}return n}function c(e){var n,t,a;for("\n"!=F&&";"!=F&&""!=F&&(n=u(e));"\n"==F||";"==F;)t||(t=new tt,n&&(a=";"!=F,t.add(n,a))),r(),"\n"!=F&&";"!=F&&""!=F&&(n=u(e),a=";"!=F,t.add(n,a));return t?t:(n||(n=u(e)),n)}function l(e){if(H==k.SYMBOL&&"function"==F){if(r(),H!=k.SYMBOL)throw _("Function name expected");var n=F;if(r(),"("!=F)throw _("Opening parenthesis ( expected");for(var t=e.createNestedScope(),a=[],i=[];;){if(r(),H!=k.SYMBOL)throw _("Variable name expected");var o=F,s=t.createDef(o);if(a.push(o),i.push(s),r(),","!=F){if(")"==F)break;throw _('Comma , or closing parenthesis ) expected"')}}if(r(),"="!=F)throw _("Equal sign = expected");r();var f=m(t),u=e.createDef(n);return new it(n,a,i,f,u)}return h(e)}function h(e){var n=!1;H==k.SYMBOL&&(n=e.hasLink(F));var t=m(e);if("="==F){if(!(t instanceof $n))throw _("Symbol expected at the left hand side of assignment operator =");var a=t.name,i=t.params;n||e.removeLink(a),r();var o=m(e),s=t.hasParams()?e.createUpdate(a):e.createDef(a);return new rt(a,i,o,s)}return t}function m(e){var n=p(e);if(":"==F){for(var t=[n];":"==F;)r(),t.push(p(e));if(t.length>3)throw new TypeError("Invalid range");var a="range",i=fn;n=new $n(a,i,t)}return n}function p(e){for(var n=v(e),t={"in":"in"};void 0!==t[F];){var a=F,i=st[t[a]];r();var o=[n,v(e)];n=new $n(a,i,o)}return n}function v(e){var n=d(e);return n}function d(e){for(var n=g(e),t={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==t[F];){var a=F,i=st[t[a]];r();var o=[n,g(e)];n=new $n(a,i,o)}return n}function g(e){for(var n=y(e),t={"+":"add","-":"subtract"};void 0!==t[F];){var a=F,i=st[t[a]];r();var o=[n,y(e)];n=new $n(a,i,o)}return n}function y(e){for(var n=w(e),t={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==t[F];){var a=F,i=st[t[a]];r();var o=[n,w(e)];n=new $n(a,i,o)}return n}function w(e){if("-"==F){var n=F,t=J;r();var a=[E(e)];return new $n(n,t,a)}return E(e)}function E(e){for(var n=[b(e)];"^"==F;)r(),n.push(b(e));for(var t=n.pop();n.length;){var a=n.pop(),i="^",o=j,s=[a,t];t=new $n(i,o,s)}return t}function b(e){for(var n=N(e);"!"==F;){var t=F,a=An;r();var i=[n];n=new $n(t,a,i)}return n}function N(e){for(var n=O(e);"'"==F;){var t=F,a=On;r();var i=[n];n=new $n(t,a,i)}return n}function O(e){return M(e)}function M(e){if(H==k.SYMBOL){var n=F;r();var t=e.createLink(n),a=A(e),i=new $n(n,t,a);return i}return S(e)}function A(e){var n=[];if("("==F){if(r(),")"!=F)for(n.push(m(e));","==F;)r(),n.push(m(e));if(")"!=F)throw _("Parenthesis ) missing");r()}return n}function S(n){if('"'==F){for(var t="",a="";""!=V&&('"'!=V||"\\"==a);)t+=V,a=V,e();if(r(),'"'!=F)throw _('End of string " missing');r();var i=new et(t);return i}return T(n)}function T(e){if("["==F){var n;for(r();"\n"==F;)r();if("]"!=F){var t=[],a=0,i=0;for(t[0]=[m(e)];","==F||";"==F;){for(","==F?i++:(a++,i=0,t[a]=[]),r();"\n"==F;)r();for(t[a][i]=m(e);"\n"==F;)r()}var o=t.length,s=t.length>0?t[0].length:0;for(a=1;o>a;a++)if(t[a].length!=s)throw P("Number of columns must match ("+t[a].length+" != "+s+")");if("]"!=F)throw _("End of matrix ] missing");r(),n=new nt(t)}else r(),n=new nt([[]]);return n}return z(e)}function z(e){if(H==k.NUMBER){var t;t="."==F?0:Number(F),r();var a;if(H==k.SYMBOL){if("i"==F||"I"==F)return a=new n(0,t),r(),new et(a);if(x.isPlainUnit(F))return a=new x(t,F),r(),new et(a);throw I('Unknown unit "'+F+'"')}var i=new et(t);return i}return q(e)}function q(e){if("("==F){r();var n=m(e);if(")"!=F)throw _("Parenthesis ) expected");return r(),n}return U(e)}function U(){throw""==F?_("Unexpected end of expression"):_("Value expected")}function R(){return void 0}function L(){return D-F.length+1}function C(e){var n=R(),t=L();return void 0===n?void 0===t?e:e+" (char "+t+")":e+" (line "+n+", char "+t+")"}function _(e){return new SyntaxError(C(e))}function I(e){return new TypeError(C(e))}function P(e){return Error(C(e))}st.expr.Parser=function B(){if(this.constructor!=B)throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new st.expr.Scope},st.expr.Parser.prototype.parse=function(e,n){return G=e||"",n||(this._newScope(),n=this.scope),f(n)},st.expr.Parser.prototype.eval=function(e){var n=this.parse(e);return n.eval()},st.expr.Parser.prototype.get=function(e){this._newScope();var n=this.scope.findDef(e);return n?n.value:void 0},st.expr.Parser.prototype.set=function(e,n){this.scope.createDef(e,n)},st.expr.Parser.prototype._newScope=function(){this.scope=new st.expr.Scope(this.scope)},st.expr.Parser.prototype.clear=function(){this.scope.clear()};var k={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},G="",D=0,V="",F="",H=k.NULL}(),function(){function e(){this.idMax=-1,this.updateSeq=0,this.parser=new st.expr.Parser,this.scope=new st.expr.Scope,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}st.expr.Workspace=e,e.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},e.prototype.append=function(n){var t=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,a=new st.expr.Scope(r),i=new e.Node({id:t,expression:n,parser:this.parser,scope:a,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},e.prototype.insertBefore=function(n,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var a=r.previousNode,i=this._getNewId(),o=a?a.scope:this.scope,s=new st.expr.Scope(o),f=new e.Node({id:i,expression:n,parser:this.parser,scope:s,nextNode:r,previousNode:a});this.nodes[i]=f,a?a.nextNode=f:this.firstNode=f,r.previousNode=f,r.scope.parentScope=f.scope;var u=this.getDependencies(i);return-1==u.indexOf(i)&&u.unshift(i),this._update(u),i},e.prototype.insertAfter=function(e,n){var t=this.nodes[n];if(!t)throw'Node with id "'+n+'" not found';return t==this.lastNode?this.append(e):this.insertBefore(n+1,e)},e.prototype.remove=function(e){var n=this.nodes[e];if(!n)throw'Node with id "'+e+'" not found';var t=this.getDependencies(e),r=n.previousNode,a=n.nextNode;r?r.nextNode=a:this.firstNode=a,a?a.previousNode=r:this.lastNode=r;var i=r?r.scope:this.scope;a&&(a.scope.parentScope=i),delete this.nodes[e],this._update(t)},e.prototype.replace=function(n,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var a=[t];e._merge(a,this.getDependencies(t));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(n),e._merge(a,this.getDependencies(t)),this._update(a)},e.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)},e.Node.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse()},e.Node.prototype.getExpr=function(){return this.expression},e.Node.prototype.getResult=function(){return this.result},e.Node.prototype._parse=function(){try{this.fn=this.parser.parse(this.expression,this.scope)}catch(e){var n="Error: "+((e.message||e)+"");this.fn=new et(n)}},e.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},e._merge=function(e,n){for(var t=0,r=n.length;r>t;t++){var a=n[t];-1==e.indexOf(a)&&e.push(a)}},e.prototype.getDependencies=function(n){var t,r=[],a=this.nodes[n];if(a){var i=a.scope.defs,o=a.scope.updates,s=[];for(t in i)i.hasOwnProperty(t)&&s.push(t);for(t in o)o.hasOwnProperty(t)&&-1==s.indexOf(t)&&s.push(t);for(var f=a.nextNode;f&&s.length;){for(var u=f.scope,c=0;s.length>c;){if(t=s[c],(u.hasLink(t)||u.hasUpdate(t))&&-1==r.indexOf(f.id)){r.push(f.id);var l=this.getDependencies(f.id);e._merge(r,l)}u.hasDef(t)&&(s.splice(c,1),c--),c++}f=f.nextNode}}return r},e.prototype.getExpr=function(e){var n=this.nodes[e];if(!n)throw'Node with id "'+e+'" not found';return n.getExpr()},e.prototype.getResult=function(e){var n=this.nodes[e];if(!n)throw'Node with id "'+e+'" not found';return n.getResult()},e.prototype._update=function(e){this.updateSeq++;for(var n=this.updateSeq,t=this.nodes,r=0,a=e.length;a>r;r++){var i=e[r],o=t[i];o&&(o.eval(),o.updateSeq=n)}},e.prototype.getChanges=function(e){var n=[],t=this.firstNode;for(e=e||0;t;)t.updateSeq>e&&n.push(t.id),t=t.nextNode;return{ids:n,updateSeq:this.updateSeq}},e.prototype._getNewId=function(){return this.idMax++,this.idMax},e.prototype.toString=function(){return JSON.stringify(this.toJSON())},e.prototype.toJSON=function(){for(var e=[],n=this.firstNode;n;){var t={id:n.id,expression:n.expression,dependencies:this.getDependencies(n.id)};try{t.result=n.getResult()}catch(r){t.result="Error: "+((r.message||r)+"")}e.push(t),n=n.nextNode}return e}}(),st.Complex=function(){ot("new math.Complex()","math.complex()")},st.Unit=function(){ot("new math.Unit()","math.unit()")},st.parser.Parser=function(){ot("new math.parser.Parser()","math.parser()")},st.parser.Workspace=function(){ot("new math.parser.Workspace()","math.workspace()")}})(); \ No newline at end of file diff --git a/src/type/Unit.js b/src/type/Unit.js index 259f211ec..e1a530ec0 100644 --- a/src/type/Unit.js +++ b/src/type/Unit.js @@ -361,7 +361,7 @@ Unit.prototype.in = function (plainUnit) { * @param {String | Unit} plainUnit For example 'cm' or 'inch' * @return {Number} value */ -Unit.prototype.as = function (plainUnit) { +Unit.prototype.toNumber = function (plainUnit) { var other = this.in(plainUnit); var prefix = this.fixPrefix ? other._bestPrefix() : other.prefix; return other._unnormalize(other.value, prefix.value); diff --git a/test/type/unit.js b/test/type/unit.js index 9969d2cd1..a40c7131a 100644 --- a/test/type/unit.js +++ b/test/type/unit.js @@ -32,11 +32,11 @@ var u = math.unit(5000, 'cm'); assert.equal(u.toString(), '50 m'); var u2 = u.in('mm'); assert.equal(u2.toString(), '50000 mm'); -assert.strictEqual(u.as('mm'), 50000); +assert.strictEqual(u.toNumber('mm'), 50000); assert.throws( function () {u.in('5mm'); }); var u3 = math.unit('5.08 cm').in('inch'); assert.equal(u3.toString(), '2 inch'); -assert.strictEqual(math.format(math.unit('5.08 cm').as('inch')), '2'); +assert.strictEqual(math.format(math.unit('5.08 cm').toNumber('inch')), '2'); // test calculation of best prefix assert.equal(math.unit('0.001m').toString(), '1 mm');