From 2ecac3ae3bd72c75fa4ae6208ada4e532cbea5fc Mon Sep 17 00:00:00 2001 From: josdejong Date: Wed, 3 Apr 2013 22:32:07 +0200 Subject: [PATCH] Implemented transpose --- math.js | 73 +++++++++++++++++++++++++++++++- math.min.js | 6 +-- src/function/matrix/squeeze.js | 2 +- src/function/matrix/transpose.js | 71 +++++++++++++++++++++++++++++++ test/function/numerics.js | 10 +++++ 5 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 src/function/matrix/transpose.js diff --git a/math.js b/math.js index c88086ad3..4eb8fb13f 100644 --- a/math.js +++ b/math.js @@ -5746,7 +5746,78 @@ squeeze.doc = { 'size(squeeze(b))' ], 'seealso': [ - 'det', 'diag', 'eye', 'ones', 'range', 'transpose', 'zeros' + 'det', 'diag', 'eye', 'ones', 'range', 'size', 'transpose', 'zeros' + ] +}; +/** + * @constructor transpose + * Calculate the determinant of a matrix, transpose(x) + * @param {Array | Matrix} x + * @return {Array | Matrix} transpose + */ +function transpose (x) { + if (arguments.length != 1) { + throw newArgumentsError('transpose', arguments.length, 1); + } + + var size = math.size(x); + switch (size.length) { + case 0: + // scalar + return math.clone(x); + break; + + case 1: + // vector + // TODO: is it logic to return a 1 dimensional vector itself as transpose? + return math.clone(x); + break; + + case 2: + // two dimensional array + var rows = size[1], // index 1 is no error + cols = size[0], // index 0 is no error + array = x.valueOf(), + transposed = [], + transposedRow, + clone = math.clone; + for (var r = 0; r < rows; r++) { + transposedRow = transposed[r] = []; + for (var c = 0; c < cols; c++) { + transposedRow[c] = clone(array[c][r]); + } + } + if (cols == 0) { + transposed[0] = []; + } + return transposed; + break; + + default: + // multi dimensional array + throw new RangeError('Matrix must be two dimensional ' + + '(size: ' + math.format(size) + ')'); + } +} + +math.transpose = transpose; + +/** + * Function documentation + */ +transpose.doc = { + 'name': this.name, + 'category': 'Numerics', + 'syntax': [ + 'transpose(x)' + ], + 'description': 'Transpose a matrix', + 'examples': [ + 'a = [1, 2, 3; 4, 5, 6]', + 'transpose(a)' + ], + 'seealso': [ + 'det', 'diag', 'eye', 'ones', 'range', 'size', 'squeeze', 'transpose', 'zeros' ] }; /** diff --git a/math.min.js b/math.min.js index dcb58459c..a0541096e 100644 --- a/math.min.js +++ b/math.min.js @@ -24,6 +24,6 @@ * License for the specific language governing permissions and limitations under * the License. */ -(function(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function t(e,n){if(this.constructor!=t)throw new SyntaxError("Complex constructor must be called with the new operator");if(null!=e&&!v(e)||null!=n&&!v(n))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=e||0,this.im=n||0}function n(e){if(this.constructor!=n)throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof n||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 ("+Wt.typeof(e)+")");this._data=[]}this._size=Xt.size(this._data)}function r(e,t){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(t&&e>t)throw new RangeError("Index out of range ("+e+" > "+t+")")}function a(e,t){return r(t,e.length),e[t-1]}function i(e,t){return t.forEach(function(t){e=a(e,t)}),Lt(e)}function o(e,t){var n=t[0];return n.map?n.map(function(t){return a(e,t)}):[a(e,n)]}function s(e,t){var n=t[0],r=t[1];if(n.map)return r.map?n.map(function(t){var n=a(e,t);return r.map(function(e){return a(n,e)})}):n.map(function(t){return[a(a(e,t),r)]});if(r.map){var i=a(e,n);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,n),r)]]}function f(e,t,n){var r=n==t.length-1,i=t[n],o=function(i){var o=a(e,i);return r?o:f(o,t,n+1)};return i.map?i.map(o):[o(i)]}function u(e,t,n){if(r(t),n instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[t-1]=n}function c(e,t,n,a){var i=!1;n.length>t.length&&(i=!0);for(var o=0;n.length>o;o++){var s=n[o];r(s),(null==t[o]||s>t[o])&&(t[o]=s,i=!0)}i&&Xt.resize(e,t,0);var f=t.length;n.forEach(function(t,n){f-1>n?e=e[t-1]:e[t-1]=a})}function l(e,t,n,a){var i=n[0];r(i),i>t[0]&&Xt.resize(e,[i],0),e[i-1]=a}function h(e,t,n,a){var i=n[0],o=n[1];r(i),r(o);var s=!1;i>(t[0]||0)&&(t[0]=i,s=!0),o>(t[1]||0)&&(t[1]=o,s=!0),s&&Xt.resize(e,t,0),e[i-1][o-1]=a}function m(e,t,n,r,a){var i=r==n.length-1,o=n[r],s=function(o,s){if(i)u(e,o,a[s]),e.length>(t[r]||0)&&(t[r]=e.length);else{var f=e[o-1];f instanceof Array||(e[o-1]=f=[f],e.length>(t[r]||0)&&(t[r]=e.length)),m(f,t,n,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 t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array?p(r):void 0==r&&(e[t]=0)}}function v(e){return e instanceof Number||"number"==typeof e}function d(e){return e==Math.round(e)}function g(e,t,n){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!=n&&!v(n))throw new TypeError("Parameter end must be a number");if(null!=t&&!v(t))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=n?n:0,this.step=null!=t?t:1}function y(e){return e instanceof String||"string"==typeof e}function x(e,t){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!=t&&!y(t))throw Error("Second parameter in Unit constructor must be a string");if(this.value=1,this.unit=x.UNIT_NONE,this.prefix=x.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1,null!=t){for(var n=x.UNITS,r=!1,a=0,i=n.length;i>a;a++){var o=n[a];if(x.endsWith(t,o.name)){var s=t.length-o.name.length,f=t.substring(0,s),u=o.prefixes[f];if(void 0!==u){this.unit=o,this.prefix=u,this.hasUnit=!0,r=!0;break}}}if(!r)throw Error('String "'+t+'" is no unit')}null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}function w(e,t){var n=void 0;if(2==arguments.length){var r=Bt(t);n="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(Bt(arguments[i]));n="Function "+e+" does not support a parameters of type "+a.join(", ")}else n="Unsupported parameter in function "+e;return new TypeError(n)}function E(e,t,n,r){var a="Wrong number of arguments in function "+e+" ("+t+" provided, "+n+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(e){if(1!=arguments.length)throw E("abs",arguments.length,1);if(v(e))return Math.abs(e);if(e instanceof t)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,N);if(e.valueOf()!==e)return N(e.valueOf());throw w("abs",e)}function b(e,r){if(2!=arguments.length)throw E("add",arguments.length,2);if(v(e)){if(v(r))return e+r;if(r instanceof t)return new t(e+r.re,r.im)}else if(e instanceof t){if(v(r))return new t(e.re+r,e.im);if(r instanceof t)return new t(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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,b);if(e.valueOf()!==e)return b(e.valueOf(),r.valueOf());throw w("add",e,r)}function O(e){if(1!=arguments.length)throw E("ceil",arguments.length,1);if(v(e))return Math.ceil(e);if(e instanceof t)return new t(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,O);if(e.valueOf()!==e)return O(e.valueOf());throw w("ceil",e)}function M(e){if(1!=arguments.length)throw E("cube",arguments.length,1);if(v(e))return e*e*e;if(e instanceof t)return P(P(e,e),e);if(e instanceof Array||e instanceof n||e instanceof g)return P(P(e,e),e);if(e.valueOf()!==e)return M(e.valueOf());throw w("cube",e)}function A(e,r){if(2!=arguments.length)throw E("divide",arguments.length,2);if(v(e)){if(v(r))return e/r;if(r instanceof t)return S(new t(e,0),r)}if(e instanceof t){if(v(r))return S(e,new t(r,0));if(r instanceof t)return S(e,r)}if(e instanceof x&&v(r)){var a=e.clone();return a.value/=r,a}if((e instanceof Array||e instanceof n||e instanceof g)&&!(r instanceof Array||r instanceof n||r instanceof g))return Xt.map2(e,r,A);if(e.valueOf()!==e||r.valueOf()!==r)return A(e.valueOf(),r.valueOf());throw w("divide",e,r)}function S(e,n){var r=n.re*n.re+n.im*n.im;return new t((e.re*n.re+e.im*n.im)/r,(e.im*n.re-e.re*n.im)/r)}function T(e,r){if(2!=arguments.length)throw E("equal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof t)return e==r.re&&0==r.im}if(e instanceof t){if(v(r))return e.re==r&&0==e.im;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return T(e.valueOf(),r.valueOf());throw w("equal",e,r)}function q(e){if(1!=arguments.length)throw E("exp",arguments.length,1);if(v(e))return Math.exp(e);if(e instanceof t){var r=Math.exp(e.re);return new t(r*Math.cos(e.im),r*Math.sin(e.im))}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,q);if(e.valueOf()!==e)return q(e.valueOf());throw w("exp",e)}function z(e){if(1!=arguments.length)throw E("fix",arguments.length,1);if(v(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof t)return new t(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 n||e instanceof g)return Xt.map(e,z);if(e.valueOf()!==e)return z(e.valueOf());throw w("fix",e)}function U(e){if(1!=arguments.length)throw E("floor",arguments.length,1);if(v(e))return Math.floor(e);if(e instanceof t)return new t(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,U);if(e.valueOf()!==e)return U(e.valueOf());throw w("floor",e)}function L(e,r){if(2!=arguments.length)throw E("larger",arguments.length,2);if(v(e)){if(v(r))return e>r;if(r instanceof t)return e>N(r)}if(e instanceof t){if(v(r))return N(e)>r;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("larger",e,r)}function R(e,r){if(2!=arguments.length)throw E("largereq",arguments.length,2);if(v(e)){if(v(r))return e>=r;if(r instanceof t)return e>=N(r)}if(e instanceof t){if(v(r))return N(e)>=r;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,R);if(e.valueOf()!==e||r.valueOf()!==r)return R(e.valueOf(),r.valueOf());throw w("largereq",e,r)}function _(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("log",arguments.length,1,2);if(void 0!==r)return A(_(e),_(r));if(v(e))return e>=0?Math.log(e):_(new t(e,0));if(e instanceof t)return new t(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,_);if(e.valueOf()!==e||r.valueOf()!==r)return _(e.valueOf(),r.valueOf());throw w("log",e,r)}function I(e){if(1!=arguments.length)throw E("log10",arguments.length,1);if(v(e))return e>=0?Math.log(e)/Math.LN10:I(new t(e,0));if(e instanceof t)return new t(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 n||e instanceof g)return Xt.map(e,I);if(e.valueOf()!==e)return I(e.valueOf());throw w("log10",e)}function C(e,r){if(2!=arguments.length)throw E("mod",arguments.length,2);if(v(e)){if(v(r))return e%r;if(r instanceof t&&0==r.im)return e%r.re}else if(e instanceof t&&0==e.im){if(v(r))return e.re%r;if(r instanceof t&&0==r.im)return e.re%r.re}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,C);if(e.valueOf()!==e||r.valueOf()!==r)return C(e.valueOf(),r.valueOf());throw w("mod",e,r)}function P(e,r){if(2!=arguments.length)throw E("multiply",arguments.length,2);if(v(e)){if(v(r))return e*r;if(r instanceof t)return B(new t(e,0),r);if(r instanceof x)return o=r.clone(),o.value*=e,o}else if(e instanceof t){if(v(r))return B(e,new t(r,0));if(r instanceof t)return B(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=Xt.size(e),i=Xt.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=P(e[c][m],r[m][l]);h=null==h?p:b(h,p)}o[c][l]=h}}return o}return r instanceof n?new n(P(e.valueOf(),r.valueOf())):Xt.map2(e,r,P)}if(e instanceof n)return new n(P(e.valueOf(),r.valueOf()))}if(r instanceof Array)return Xt.map2(e,r,P);if(r instanceof n)return new n(P(e.valueOf(),r.valueOf()));if(e.valueOf()!==e||r.valueOf()!==r)return P(e.valueOf(),r.valueOf());throw w("multiply",e,r)}function B(e,n){return new t(e.re*n.re-e.im*n.im,e.re*n.im+e.im*n.re)}function G(e,r){if(2!=arguments.length)throw E("pow",arguments.length,2);if(v(e)){if(v(r))return d(r)||e>=0?Math.pow(e,r):k(new t(e,0),new t(r,0));if(r instanceof t)return k(new t(e,0),r)}else if(e instanceof t){if(v(r))return k(e,new t(r,0));if(r instanceof t)return k(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=Xt.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=P(e,i);return i}if(e instanceof n)return new n(G(e.valueOf(),r))}if(e.valueOf()!==e||r.valueOf()!==r)return G(e.valueOf(),r.valueOf());throw w("pow",e,r)}function k(e,t){var n=_(e),r=P(n,t);return q(r)}function j(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("round",arguments.length,1,2);if(void 0==r){if(v(e))return Math.round(e);if(e instanceof t)return new t(Math.round(e.re),Math.round(e.im));if((e instanceof Array||e instanceof n||e instanceof g)&&Xt.map(e,j),e.valueOf()!==e)return j(e.valueOf());throw w("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 V(e,r);if(e instanceof t)return new t(V(e.re,r),V(e.im,r));if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,j);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("round",e,r)}function V(e,t){var n=Math.pow(10,void 0!=t?t:Wt.options.precision);return Math.round(e*n)/n}function D(e){if(1!=arguments.length)throw E("sign",arguments.length,1);if(v(e)){var r;return r=e>0?1:0>e?-1:0}if(e instanceof t){var a=Math.sqrt(e.re*e.re+e.im*e.im);return new t(e.re/a,e.im/a)}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,r);if(e.valueOf()!==e)return r(e.valueOf());throw w("sign",e)}function F(e,r){if(2!=arguments.length)throw E("smaller",arguments.length,2);if(v(e)){if(v(r))return r>e;if(r instanceof t)return N(r)>e}if(e instanceof t){if(v(r))return r>N(e);if(r instanceof t)return N(e)e;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,F);if(e.valueOf()!==e||r.valueOf()!==r)return F(e.valueOf(),r.valueOf());throw w("smaller",e,r)}function H(e,r){if(2!=arguments.length)throw E("smallereq",arguments.length,2);if(v(e)){if(v(r))return r>=e;if(r instanceof t)return N(r)>=e}if(e instanceof t){if(v(r))return r>=N(e);if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,H);if(e.valueOf()!==e||r.valueOf()!==r)return H(e.valueOf(),r.valueOf());throw w("smallereq",e,r)}function Y(e){if(1!=arguments.length)throw E("sqrt",arguments.length,1);if(v(e))return e>=0?Math.sqrt(e):Y(new t(e,0));if(e instanceof t){var r=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new t(.5*Math.sqrt(2*(r+e.re)),.5*Math.sqrt(2*(r-e.re))):new t(.5*Math.sqrt(2*(r+e.re)),-.5*Math.sqrt(2*(r-e.re)))}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,Y);if(e.valueOf()!==e)return Y(e.valueOf());throw w("sqrt",e)}function W(e){if(1!=arguments.length)throw E("square",arguments.length,1);if(v(e))return e*e;if(e instanceof t)return P(e,e);if(e instanceof Array||e instanceof n||e instanceof g)return P(e,e);if(e.valueOf()!==e)return W(e.valueOf());throw w("square",e)}function X(e,r){if(2!=arguments.length)throw E("subtract",arguments.length,2);if(v(e)){if(v(r))return e-r;if(r instanceof t)return new t(e-r.re,r.im)}else if(e instanceof t){if(v(r))return new t(e.re-r,e.im);if(r instanceof t)return new t(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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,X);if(e.valueOf()!==e||r.valueOf()!==r)return X(e.valueOf(),r.valueOf());throw w("subtract",e,r)}function Z(e){if(1!=arguments.length)throw E("unaryminus",arguments.length,1);if(v(e))return-e;if(e instanceof t)return new t(-e.re,-e.im);if(e instanceof x){var r=e.clone();return r.value=-e.value,r}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,Z);if(e.valueOf()!==e)return Z(e.valueOf());throw w("unaryminus",e)}function K(e,r){if(2!=arguments.length)throw E("unequal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof t)return e==r.re&&0==r.im}if(e instanceof t){if(v(r))return e.re==r&&0==e.im;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,K);if(e.valueOf()!==e||r.valueOf()!==r)return K(e.valueOf(),r.valueOf());throw w("unequal",e,r)}function Q(e){if(1!=arguments.length)throw E("arg",arguments.length,1);if(v(e))return Math.atan2(0,e);if(e instanceof t)return Math.atan2(e.im,e.re);if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,Q);if(e.valueOf()!==e)return Q(e.valueOf());throw w("arg",e)}function J(e){if(1!=arguments.length)throw E("conj",arguments.length,1);if(v(e))return e;if(e instanceof t)return new t(e.re,-e.im);if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,J);if(e.valueOf()!==e)return J(e.valueOf());throw w("conj",e)}function $(e){if(1!=arguments.length)throw E("im",arguments.length,1);if(v(e))return 0;if(e instanceof t)return e.im;if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,$);if(e.valueOf()!==e)return $(e.valueOf());throw w("im",e)}function et(e){if(1!=arguments.length)throw E("re",arguments.length,1);if(v(e))return e;if(e instanceof t)return e.re;if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,et);if(e.valueOf()!==e)return et(e.valueOf());throw w("re",e)}function tt(){switch(arguments.length){case 0:return new t(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 n=t.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid complex number');case 2:return new t(arguments[0],arguments[1]);default:throw E("complex",arguments.length,0,2)}}function nt(e){if(arguments.length>1)throw E("matrix",arguments.length,0,1);return new n(e)}function rt(){return new Wt.expr.Parser}function at(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 t=g.parse(e);if(t)return t;throw new SyntaxError('String "'+t+'" 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 E("range",arguments.length,2,3)}}function it(){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.isUnit(e))return new x(null,e);var t=x.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid unit');case 2:return new x(arguments[0],arguments[1]);default:throw E("unit",arguments.length,1,2)}}function ot(){return new Wt.expr.Workspace}function st(e){if(1!=arguments.length)throw E("det",arguments.length,1);var t=Wt.size(e);switch(t.length){case 0:return Wt.clone(e);case 1:if(1==t[0])return Wt.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+Wt.format(t)+")");case 2:var n=t[0],r=t[1];if(n==r)return ft(e.valueOf(),n,r);throw new RangeError("Matrix must be square (size: "+Wt.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+Wt.format(t)+")")}}function ft(e,t,n){if(1==t)return e[0][0];if(2==t)return e[0][0]*e[1][1]-e[1][0]*e[0][1];for(var r=0,a=0;n>a;a++){var i=ut(e,t,n,0,a);r+=((a+1)%2+(a+1)%2-1)*e[0][a]*ft(i,t-1,n-1)}return r}function ut(e,t,n,r,a){for(var i,o=[],s=0;t>s;s++)if(s!=r){i=o[s-(s>r)]=[];for(var f=0;n>f;f++)f!=a&&(i[f-(f>a)]=e[s][f])}return o}function ct(e,t){var r,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw E("diag",arguments.length,1,2);if(t){if(!v(t)||!d(t))throw new TypeError("Second parameter in function diag must be an integer")}else t=0;var s=t>0?t:0,f=0>t?-t:0;e instanceof n||e instanceof g||(e=new n(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 n;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]=Lt(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]=Lt(r[i+f][i+s]);return new n(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}function lt(){var e=Xt.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw E("eye",num,0,2);var t=e[0],r=e[1];if(!v(t)||!d(t)||1>t)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 n;a.resize(e);for(var i=Wt.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a}function ht(){var e=Xt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new n,r=1;return t.resize(e,r),t}function mt(e){if(1!=arguments.length)throw E("size",arguments.length,1);if(v(e)||e instanceof t||e instanceof x||null==e)return[];if(y(e))return[e.length];if(e instanceof Array)return Xt.size(e);if(e instanceof n||e instanceof g)return e.size();if(e.valueOf()!==e)return mt(e.valueOf());throw w("size",e)}function pt(e){if(1!=arguments.length)throw E("squeeze",arguments.length,1);return e instanceof n||e instanceof g?vt(e.toArray()):e instanceof Array?vt(Lt(e)):Lt(e)}function vt(e){if(1==e.length)return vt(e[0]);for(var t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array&&(e[t]=vt(r))}return e}function dt(){var e=Xt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new n;return t.resize(e),t}function gt(e){if(1!=arguments.length)throw E("factorial",arguments.length,1);if(v(e)){if(!d(e))throw new TypeError("Function factorial can only handle integer values");var t=e,r=t;for(t--;t>1;)r*=t,t--;return 0==r&&(r=1),r}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,gt);if(e.valueOf()!==e)return gt(e.valueOf());throw w("factorial",e)}function yt(){if(0!=arguments.length)throw E("random",arguments.length,0);return Math.random()}function xt(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return xt.apply(this,e.valueOf());for(var t=arguments[0],n=1,r=arguments.length;r>n;n++){var a=arguments[n];L(a,t)&&(t=a)}return t}function wt(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return wt.apply(this,e.valueOf());for(var t=arguments[0],n=1,r=arguments.length;r>n;n++){var a=arguments[n];F(a,t)&&(t=a)}return t}function Et(e){if(1!=arguments.length)throw E("acos",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.acos(e):Et(new t(e,0));if(e instanceof t){var r=new t(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),a=Y(r),i=new t(a.re-e.im,a.im+e.re),o=_(i);return new t(1.5707963267948966-o.im,o.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,Et);if(e.valueOf()!==e)return Et(e.valueOf());throw w("acos",e)}function Nt(e){if(1!=arguments.length)throw E("asin",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.asin(e):Nt(new t(e,0));if(e instanceof t){var r=e.re,a=e.im,i=new t(a*a-r*r+1,-2*r*a),o=Y(i),s=new t(o.re-a,o.im+r),f=_(s);return new t(f.im,-f.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,Nt);if(e.valueOf()!==e)return Nt(e.valueOf());throw w("asin",e)}function bt(e){if(1!=arguments.length)throw E("atan",arguments.length,1);if(v(e))return Math.atan(e);if(e instanceof t){var r=e.re,a=e.im,i=r*r+(1-a)*(1-a),o=new t((1-a*a-r*r)/i,-2*r/i),s=_(o);return new t(-.5*s.im,.5*s.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Xt.map(e,bt);if(e.valueOf()!==e)return bt(e.valueOf());throw w("atan",e)}function Ot(e,r){if(2!=arguments.length)throw E("atan2",arguments.length,2);if(v(e)){if(v(r))return Math.atan2(e,r);if(r instanceof t)return Math.atan2(e,r.re)}else if(e instanceof t){if(v(r))return Math.atan2(e.re,r);if(r instanceof t)return Math.atan2(e.re,r.re)}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Xt.map2(e,r,Ot);if(r.valueOf()!==r||e.valueOf()!==e)return Ot(e.valueOf(),r.valueOf());throw w("atan2",e,r)}function Mt(e){if(1!=arguments.length)throw E("cos",arguments.length,1);if(v(e))return Math.cos(e);if(e instanceof t)return new t(.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 n||e instanceof g)return Xt.map(e,Mt);if(e.valueOf()!==e)return Mt(e.valueOf());throw w("cos",e)}function At(e){if(1!=arguments.length)throw E("cot",arguments.length,1);if(v(e))return 1/Math.tan(e);if(e instanceof t){var r=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new t(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 n||e instanceof g)return Xt.map(e,At);if(e.valueOf()!==e)return At(e.valueOf());throw w("cot",e)}function St(e){if(1!=arguments.length)throw E("csc",arguments.length,1);if(v(e))return 1/Math.sin(e);if(e instanceof t){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new t(.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 n||e instanceof g)return Xt.map(e,St);if(e.valueOf()!==e)return St(e.valueOf());throw w("csc",e)}function Tt(e){if(1!=arguments.length)throw E("sec",arguments.length,1);if(v(e))return 1/Math.cos(e);if(e instanceof t){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new t(.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 n||e instanceof g)return Xt.map(e,Tt);if(e.valueOf()!==e)return Tt(e.valueOf());throw w("sec",e)}function qt(e){if(1!=arguments.length)throw E("sin",arguments.length,1);if(v(e))return Math.sin(e);if(e instanceof t)return new t(.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 n||e instanceof g)return Xt.map(e,qt);if(e.valueOf()!==e)return qt(e.valueOf());throw w("sin",e)}function zt(e){if(1!=arguments.length)throw E("tan",arguments.length,1);if(v(e))return Math.tan(e);if(e instanceof t){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new t(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 n||e instanceof g)return Xt.map(e,zt);if(e.valueOf()!==e)return zt(e.valueOf());throw w("tan",e)}function Ut(e,t){if(2!=arguments.length)throw E("in",arguments.length,2);if(e instanceof x&&t instanceof x){if(!e.equalBase(t))throw Error("Units do not match");if(t.hasValue)throw Error("Cannot convert to a unit with a value");if(!t.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=t.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||e instanceof n||e instanceof g||t instanceof Array||t instanceof n||t instanceof g)return Xt.map2(e,t,Ut);if(e.valueOf()!==e)return Wt.in(e.valueOf());throw w("in",e)}function Lt(t){if(1!=arguments.length)throw E("clone",arguments.length,1);if(null==t)return t;if("function"==typeof t.clone)return t.clone();if(v(t)||y(t)||e(t))return t;if(t instanceof Array)return t.map(function(e){return Lt(e)});if(t instanceof Object)return Xt.mapObject(t,Lt);throw w("clone",t)}function Rt(e,t){var n=arguments.length;if(1!=n&&2!=n)throw E("format",n,1,2);if(1==n){var r=arguments[0];return v(r)?Xt.formatNumber(r):r instanceof Array?Xt.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(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,n){for(var r=n.split("."),a=t[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})}function _t(e){if(1!=arguments.length)throw E("help",arguments.length,1);if(void 0!=e){if(e.doc)return It(e.doc);if(e.constructor.doc)return It(e.constructor.doc);if(y(e)){var t=Wt[e];if(t&&t.doc)return It(t.doc)}}return e instanceof Object&&e.name?'No documentation found on subject "'+e.name+'"':e instanceof Object&&e.constructor.name?'No documentation found on subject "'+e.constructor.name+'"':'No documentation found on subject "'+e+'"'}function It(e){var t="";if(e.name&&(t+="NAME\n"+e.name+"\n\n"),e.category&&(t+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(t+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var n=Wt.parser();t+="EXAMPLES\n";for(var r=0;e.examples.length>r;r++){var a,i=e.examples[r];try{a=n.eval(i)}catch(o){a=o}t+=i+"\n",t+=" "+Wt.format(a)+"\n"}t+="\n"}return e.seealso&&(t+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),t}function Ct(e,t){var n;if(y(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var r=require(e);Ct(r)}else if(Pt(e)){if(n=e.name,!n)throw Error("Cannot import an unnamed function");(t||void 0===Wt[n])&&(Wt[n]=e)}else if(e instanceof Object)for(n in e)if(e.hasOwnProperty(n)){var a=e[n];Pt(a)?(t||void 0===Wt[n])&&(Wt[n]=a):Ct(a)}}function Pt(e){return"function"==typeof e||v(e)||y(e)||e instanceof t||e instanceof x}function Bt(e){if(1!=arguments.length)throw E("typeof",arguments.length,1);var t=typeof e;if("object"==t){if(null==e)return"null";if(e.constructor){for(var n in Wt)if(Wt.hasOwnProperty(n)&&e.constructor==Wt[n])return n.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t}function Gt(){}function kt(e,t,n){this.name=e,this.fn=t,this.params=n}function jt(e){this.value=e -}function Vt(e){this.nodes=e||[]}function Dt(){this.params=[],this.visible=[]}function Ft(e,t,n,r){this.name=e,this.params=t,this.expr=n,this.result=r}function Ht(e,t){this.object=e,this.params=t}function Yt(e,t,n,r,a){this.name=e,this.variables=n,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,t,n,r),this.result=a}var Wt={type:{},expr:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=Wt),"undefined"!=typeof exports&&(exports=Wt),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return Wt}),"undefined"!=typeof window&&(window.math=Wt);var Xt=function(){function e(e){if(e instanceof Array){var t=e.length;if(t){var n=o(e[0]);return 0==n[0]?[0].concat(n):[t].concat(n)}return[t]}return[]}function t(e,n,r){var a,i=e.length;if(i!=n[r])throw new RangeError("Dimension mismatch ("+i+" != "+n[r]+")");if(n.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 ("+(n.length-1)+" < "+n.length+")");t(e[a],n,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(n.length+1)+" > "+n.length+")")}function r(e,t,n){if(t.length-1>n){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(a,t,n+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,t,n,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=t[n];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?Lt(r):0;else e.length=t[n];i=e.length}if(t.length-1>n){var f=n+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,t,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,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var n=Math.abs(e);if(n>1e-4&&1e6>n||0==n)return V(e,t)+"";var r=Math.round(Math.log(n)/Math.LN10),a=e/Math.pow(10,r);return V(a,t)+"E"+r},i.formatArray=function(e){if(e instanceof Array){for(var t="[",n=e.length,r=0;n>r;r++)0!=r&&(t+=", "),t+=i.formatArray(e[r]);return t+="]"}return Rt(e)},i.formatArray2d=function(e){var t="[",n=i.size(e);if(2!=n.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(n)+")");for(var r=n[0],a=n[1],o=0;r>o;o++){0!=o&&(t+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(t+=", ");var u=s[f];void 0!=u&&(t+=Rt(u))}}return t+="]"},i.argsToArray=function(e){var t;if(0==e.length)t=[];else if(1==e.length)t=e[0],t instanceof n&&(t=t.toVector()),t instanceof g&&(t=t.valueOf()),t instanceof Array||(t=[t]);else{t=[];for(var r=0;e.length>r;r++)t[r]=e[r]}return t},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,t){if(e instanceof Array||e instanceof n||e instanceof g)return e.map(function(e){return t(e)});throw new TypeError("Array expected")},i.map2=function(e,t,r){var a,o,s;if(e instanceof n||t instanceof n)return new n(i.map2(e.valueOf(),t.valueOf(),r));if(e instanceof g||t instanceof g)return new n(i.map2(e.valueOf(),t.valueOf(),r));if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],t[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],t);else if(t instanceof Array)for(a=[],o=t.length,s=0;o>s;s++)a[s]=r(e,t[s]);else a=r(e,t);return a},i.forEach=function(e,t){if(e instanceof Array)e.forEach(t);else for(var n in e)e.hasOwnProperty(n)&&t(e[n],n,e)},i.mapObject=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n},i.deepEqual=function(e,t){var n,r,a;if(e instanceof Array){if(!(t instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],t[r]))return!1;return!0}if(e instanceof Object){if(t instanceof Array||!(t instanceof Object))return!1;for(n in e)if(e.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;for(n in t)if(t.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;return!0}return e.valueOf()==t.valueOf()},i.size=function o(t){var n=e(t);return i.validate(t,n),n},i.validate=function(e,n){var a=0==n.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=n.indexOf(0);o?(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)+")")}),r(e,n,0)):t(e,n,0)}},i.resize=function(e,t,n){if(!(t instanceof Array))throw new TypeError("Size must be an array (size is "+Wt.typeof(t)+")");t.forEach(function(e){if(!v(e)||!d(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(t)+")")});var r=-1!=t.indexOf(0);r&&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)+")")}),a(e,t,0,n)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;this.length>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var n=0,r=this.length;r>n;++n)e.call(t||this,this[n],n,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var n,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(t&&(n=t),r=Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(n,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 t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&!e.call(r,t[a],a,t))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&e.call(r,t[a],a,t))return!0;return!1}),i}();Wt.type.Complex=t,function(){function e(){for(;" "==c||" "==c;)a()}function n(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="",t=u;if("+"==c?a():"-"==c&&(e+=c,a()),!n(c))return i(t),null;for(;n(c);)e+=c,a();if("E"==c||"e"==c){if(e+=c,a(),("+"==c||"-"==c)&&(e+=c,a()),!r(c))return i(t),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 t="+"==c?"1":"-1";return a(),a(),t}return null}var f,u,c;t.parse=function(n){if(f=n,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 t(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new t(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 t(Number(r),Number(l))}return(r=s())?(e(),c?null:new t(0,Number(r))):null}}(),t.prototype.clone=function(){return new t(this.re,this.im)},t.prototype.toString=function(){var e="",t=Xt.formatNumber(this.re),n=Xt.formatNumber(this.im);return e=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":n+"i":this.im>0?1==this.im?t+" + i":t+" + "+n+"i":-1==this.im?t+" - i":t+" - "+Xt.formatNumber(Math.abs(this.im))+"i"},t.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"]},Wt.type.Matrix=n,n.prototype.get=function(e){var t;if(e instanceof n)t=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+Wt.typeof(e));t=!e.some(function(e){return e.forEach})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(t)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 n(o(this._data,e));case 2:return new n(s(this._data,e));default:return new n(f(this._data,e,0))}},n.prototype.set=function(e,t){var r;if(e instanceof n)r=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+Wt.typeof(e));r=!e.some(function(e){return e.forEach})}if((t instanceof n||t instanceof g)&&(t=t.valueOf()),e.length=e})},n.prototype.toVector=function(){var e=0,t=void 0,n=[];if(this._size.forEach(function(r,a){r>1&&(e++,t=a),n[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},n.prototype.isVector=function(){var e=0;return this._size.forEach(function(t){t>1&&e++}),1>=e},n.prototype.toArray=function(){return Lt(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.toString=function(){return Xt.formatArray(this._data)},Wt.type.Range=g,g.parse=function(e){if(!y(e))return null;var t=e.split(":"),n=t.map(function(e){return Number(e)}),r=n.some(function(e){return isNaN(e)});if(r)return null;switch(n.length){case 2:return new g(n[0],1,n[1]);case 3:return new g(n[0],n[1],n[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,t=Number(this.start),n=Number(this.step),r=Number(this.end),a=r-t;return D(n)==D(a)?e=Math.floor(a/n)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var t=Number(this.start),n=Number(this.step),r=Number(this.end),a=0;if(n>0)for(;r>=t;)e(t,a,this),t+=n,a++;else if(0>n)for(;t>=r;)e(t,a,this),t+=n,a++},g.prototype.map=function(e){var t=[];return this.forEach(function(n,r,a){t[r]=e(n,r,a)}),t},g.prototype.toMatrix=function(){return new n(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(t,n){e[n]=t}),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=Rt(Number(this.start));return 1!=this.step&&(e+=":"+Rt(Number(this.step))),e+=":"+Rt(Number(this.end))},Wt.type.Unit=x,function(){function e(){for(;" "==u||" "==u;)r()}function t(e){return e>="0"&&"9">=e||"."==e}function n(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()),!t(u))return a(i),null;for(;t(u);)e+=u,r();if("E"==u||"e"==u){if(e+=u,r(),("+"==u||"-"==u)&&(e+=u,r()),!n(u))return a(i),null;for(;n(u);)e+=u,r()}return e}function o(){var t="";for(e();u&&" "!=u&&" "!=u;)t+=u,r();return t||null}var s,f,u;x.parse=function(t){if(s=t,f=-1,u="",!y(s))return null;r(),e();var n,a=i();return a?(n=o(),r(),e(),u?null:a&&n?new x(Number(a),n):null):(n=o(),r(),e(),u?null:new x(null,n))}}(),x.prototype.clone=function(){var e=new x;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},x.endsWith=function(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t},x.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},x.prototype._unnormalize=function(e,t){return void 0===t?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/t-this.unit.offset},x.isUnit=function(e){for(var t=x.UNITS,n=t.length,r=0;n>r;r++){var a=t[r];if(x.endsWith(e,a.name)){var i=e.length-a.name.length;if(0==i)return!0;var o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return!0}}return!1},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.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),Xt.formatNumber(e)+" "+this.prefix.name+this.unit.name;var t=Math.abs(this.value/this.unit.value),n=x.PREFIX_NONE,r=Math.abs(Math.log(t/n.value)/Math.LN10-1.2),a=this.unit.prefixes;for(var i in a)if(a.hasOwnProperty(i)){var o=a[i];if(o.scientific){var s=Math.abs(Math.log(t/o.value)/Math.LN10-1.2);r>s&&(n=o,r=s)}}return e=this._unnormalize(this.value,n.value),Xt.formatNumber(e)+" "+n.name+this.unit.name},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 Zt=x.BASE_UNITS,Kt=x.PREFIXES;x.BASE_UNIT_NONE={},x.UNIT_NONE={name:"",base:x.BASE_UNIT_NONE,value:1,offset:0},x.UNITS=[{name:"meter",base:Zt.LENGTH,prefixes:Kt.LONG,value:1,offset:0},{name:"inch",base:Zt.LENGTH,prefixes:Kt.NONE,value:.0254,offset:0},{name:"foot",base:Zt.LENGTH,prefixes:Kt.NONE,value:.3048,offset:0},{name:"yard",base:Zt.LENGTH,prefixes:Kt.NONE,value:.9144,offset:0},{name:"mile",base:Zt.LENGTH,prefixes:Kt.NONE,value:1609.344,offset:0},{name:"link",base:Zt.LENGTH,prefixes:Kt.NONE,value:.201168,offset:0},{name:"rod",base:Zt.LENGTH,prefixes:Kt.NONE,value:5.02921,offset:0},{name:"chain",base:Zt.LENGTH,prefixes:Kt.NONE,value:20.1168,offset:0},{name:"angstrom",base:Zt.LENGTH,prefixes:Kt.NONE,value:1e-10,offset:0},{name:"m",base:Zt.LENGTH,prefixes:Kt.SHORT,value:1,offset:0},{name:"ft",base:Zt.LENGTH,prefixes:Kt.NONE,value:.3048,offset:0},{name:"yd",base:Zt.LENGTH,prefixes:Kt.NONE,value:.9144,offset:0},{name:"mi",base:Zt.LENGTH,prefixes:Kt.NONE,value:1609.344,offset:0},{name:"li",base:Zt.LENGTH,prefixes:Kt.NONE,value:.201168,offset:0},{name:"rd",base:Zt.LENGTH,prefixes:Kt.NONE,value:5.02921,offset:0},{name:"ch",base:Zt.LENGTH,prefixes:Kt.NONE,value:20.1168,offset:0},{name:"mil",base:Zt.LENGTH,prefixes:Kt.NONE,value:254e-7,offset:0},{name:"m2",base:Zt.SURFACE,prefixes:Kt.SHORT,value:1,offset:0},{name:"sqin",base:Zt.SURFACE,prefixes:Kt.NONE,value:64516e-8,offset:0},{name:"sqft",base:Zt.SURFACE,prefixes:Kt.NONE,value:.09290304,offset:0},{name:"sqyd",base:Zt.SURFACE,prefixes:Kt.NONE,value:.83612736,offset:0},{name:"sqmi",base:Zt.SURFACE,prefixes:Kt.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:Zt.SURFACE,prefixes:Kt.NONE,value:25.29295,offset:0},{name:"sqch",base:Zt.SURFACE,prefixes:Kt.NONE,value:404.6873,offset:0},{name:"sqmil",base:Zt.SURFACE,prefixes:Kt.NONE,value:6.4516e-10,offset:0},{name:"m3",base:Zt.VOLUME,prefixes:Kt.SHORT,value:1,offset:0},{name:"L",base:Zt.VOLUME,prefixes:Kt.SHORT,value:.001,offset:0},{name:"litre",base:Zt.VOLUME,prefixes:Kt.LONG,value:.001,offset:0},{name:"cuin",base:Zt.VOLUME,prefixes:Kt.NONE,value:16387064e-12,offset:0},{name:"cuft",base:Zt.VOLUME,prefixes:Kt.NONE,value:.028316846592,offset:0},{name:"cuyd",base:Zt.VOLUME,prefixes:Kt.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:Zt.VOLUME,prefixes:Kt.NONE,value:5e-6,offset:0},{name:"tablespoon",base:Zt.VOLUME,prefixes:Kt.NONE,value:15e-6,offset:0},{name:"minim",base:Zt.VOLUME,prefixes:Kt.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:Zt.VOLUME,prefixes:Kt.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:Zt.VOLUME,prefixes:Kt.NONE,value:2957353e-11,offset:0},{name:"gill",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0001182941,offset:0},{name:"cup",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0002365882,offset:0},{name:"pint",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0004731765,offset:0},{name:"quart",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0009463529,offset:0},{name:"gallon",base:Zt.VOLUME,prefixes:Kt.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:Zt.VOLUME,prefixes:Kt.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:Zt.VOLUME,prefixes:Kt.NONE,value:.1589873,offset:0},{name:"hogshead",base:Zt.VOLUME,prefixes:Kt.NONE,value:.238481,offset:0},{name:"fldr",base:Zt.VOLUME,prefixes:Kt.NONE,value:36966911e-13,offset:0},{name:"floz",base:Zt.VOLUME,prefixes:Kt.NONE,value:2957353e-11,offset:0},{name:"gi",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0001182941,offset:0},{name:"cp",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0002365882,offset:0},{name:"pt",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0004731765,offset:0},{name:"qt",base:Zt.VOLUME,prefixes:Kt.NONE,value:.0009463529,offset:0},{name:"gal",base:Zt.VOLUME,prefixes:Kt.NONE,value:.003785412,offset:0},{name:"bbl",base:Zt.VOLUME,prefixes:Kt.NONE,value:.1173478,offset:0},{name:"obl",base:Zt.VOLUME,prefixes:Kt.NONE,value:.1589873,offset:0},{name:"g",base:Zt.MASS,prefixes:Kt.SHORT,value:.001,offset:0},{name:"gram",base:Zt.MASS,prefixes:Kt.LONG,value:.001,offset:0},{name:"ton",base:Zt.MASS,prefixes:Kt.SHORT,value:907.18474,offset:0},{name:"tonne",base:Zt.MASS,prefixes:Kt.SHORT,value:1e3,offset:0},{name:"grain",base:Zt.MASS,prefixes:Kt.NONE,value:6479891e-11,offset:0},{name:"dram",base:Zt.MASS,prefixes:Kt.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:Zt.MASS,prefixes:Kt.NONE,value:.028349523125,offset:0},{name:"poundmass",base:Zt.MASS,prefixes:Kt.NONE,value:.45359237,offset:0},{name:"hundredweight",base:Zt.MASS,prefixes:Kt.NONE,value:45.359237,offset:0},{name:"stick",base:Zt.MASS,prefixes:Kt.NONE,value:.115,offset:0},{name:"gr",base:Zt.MASS,prefixes:Kt.NONE,value:6479891e-11,offset:0},{name:"dr",base:Zt.MASS,prefixes:Kt.NONE,value:.0017718451953125,offset:0},{name:"oz",base:Zt.MASS,prefixes:Kt.NONE,value:.028349523125,offset:0},{name:"lbm",base:Zt.MASS,prefixes:Kt.NONE,value:.45359237,offset:0},{name:"cwt",base:Zt.MASS,prefixes:Kt.NONE,value:45.359237,offset:0},{name:"s",base:Zt.TIME,prefixes:Kt.SHORT,value:1,offset:0},{name:"min",base:Zt.TIME,prefixes:Kt.NONE,value:60,offset:0},{name:"h",base:Zt.TIME,prefixes:Kt.NONE,value:3600,offset:0},{name:"seconds",base:Zt.TIME,prefixes:Kt.LONG,value:1,offset:0},{name:"second",base:Zt.TIME,prefixes:Kt.LONG,value:1,offset:0},{name:"sec",base:Zt.TIME,prefixes:Kt.LONG,value:1,offset:0},{name:"minutes",base:Zt.TIME,prefixes:Kt.NONE,value:60,offset:0},{name:"minute",base:Zt.TIME,prefixes:Kt.NONE,value:60,offset:0},{name:"hours",base:Zt.TIME,prefixes:Kt.NONE,value:3600,offset:0},{name:"hour",base:Zt.TIME,prefixes:Kt.NONE,value:3600,offset:0},{name:"day",base:Zt.TIME,prefixes:Kt.NONE,value:86400,offset:0},{name:"days",base:Zt.TIME,prefixes:Kt.NONE,value:86400,offset:0},{name:"rad",base:Zt.ANGLE,prefixes:Kt.NONE,value:1,offset:0},{name:"deg",base:Zt.ANGLE,prefixes:Kt.NONE,value:.017453292519943295,offset:0},{name:"grad",base:Zt.ANGLE,prefixes:Kt.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:Zt.ANGLE,prefixes:Kt.NONE,value:6.283185307179586,offset:0},{name:"A",base:Zt.CURRENT,prefixes:Kt.SHORT,value:1,offset:0},{name:"ampere",base:Zt.CURRENT,prefixes:Kt.LONG,value:1,offset:0},{name:"K",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1,offset:0},{name:"degC",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1,offset:273.15},{name:"degF",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1/1.8,offset:459.67},{name:"degR",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1/1.8,offset:0},{name:"kelvin",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1,offset:0},{name:"celsius",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1,offset:273.15},{name:"fahrenheit",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:Zt.TEMPERATURE,prefixes:Kt.NONE,value:1/1.8,offset:0},{name:"mol",base:Zt.AMOUNT_OF_SUBSTANCE,prefixes:Kt.NONE,value:1,offset:0},{name:"mole",base:Zt.AMOUNT_OF_SUBSTANCE,prefixes:Kt.NONE,value:1,offset:0},{name:"cd",base:Zt.LUMINOUS_INTENSITY,prefixes:Kt.NONE,value:1,offset:0},{name:"candela",base:Zt.LUMINOUS_INTENSITY,prefixes:Kt.NONE,value:1,offset:0},{name:"N",base:Zt.FORCE,prefixes:Kt.SHORT,value:1,offset:0},{name:"newton",base:Zt.FORCE,prefixes:Kt.LONG,value:1,offset:0},{name:"lbf",base:Zt.FORCE,prefixes:Kt.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:Zt.FORCE,prefixes:Kt.NONE,value:4.4482216152605,offset:0},{name:"b",base:Zt.BIT,prefixes:Kt.BINARY_SHORT,value:1,offset:0},{name:"bits",base:Zt.BIT,prefixes:Kt.BINARY_LONG,value:1,offset:0},{name:"B",base:Zt.BIT,prefixes:Kt.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:Zt.BIT,prefixes:Kt.BINARY_LONG,value:8,offset:0}],Wt.E=Math.E,Wt.LN2=Math.LN2,Wt.LN10=Math.LN10,Wt.LOG2E=Math.LOG2E,Wt.LOG10E=Math.LOG10E,Wt.PI=Math.PI,Wt.SQRT1_2=Math.SQRT1_2,Wt.SQRT2=Math.SQRT2,Wt.I=new t(0,-1),Wt.pi=Wt.PI,Wt.e=Wt.E,Wt.i=Wt.I,Wt.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"]},Wt.add=b,b.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"]},Wt.ceil=O,O.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"]},Wt.cube=M,M.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"]},Wt.divide=A,A.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"]},Wt.equal=T,T.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"]},Wt.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"]},Wt.fix=z,z.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"]},Wt.floor=U,U.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"]},Wt.larger=L,L.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"]},Wt.largereq=R,R.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"]},Wt.log=_,_.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"]},Wt.log10=I,I.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"]},Wt.mod=C,C.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:[]},Wt.multiply=P,P.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"]},Wt.pow=G,G.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"]},Wt.round=j,j.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"]},Wt.sign=D,D.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"]},Wt.smaller=F,F.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"]},Wt.smallereq=H,H.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"]},Wt.sqrt=Y,Y.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"]},Wt.square=W,W.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"]},Wt.subtract=X,X.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"]},Wt.unaryminus=Z,Z.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},Wt.unequal=K,K.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"]},Wt.arg=Q,Q.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"]},Wt.conj=J,J.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"]},Wt.im=$,$.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"]},Wt.re=et,et.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"]},Wt.complex=tt,Wt.matrix=nt,Wt.parser=rt,Wt.range=at,Wt.unit=it,Wt.workspace=ot,Wt.det=st,st.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:["diag","eye","range","size","squeeze","transpose","zeros"]},Wt.diag=ct,ct.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:["det","eye","ones","range","size","squeeze","transpose","zeros"]},Wt.eye=lt,lt.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:["det","diag","ones","range","size","squeeze","transpose","zeros"]},Wt.ones=ht,ht.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:["det","diag","eye","range","size","squeeze","transpose","zeros"]},Wt.size=mt,mt.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:["det","diag","eye","ones","range","squeeze","transpose","zeros"]},Wt.squeeze=pt,pt.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:["det","diag","eye","ones","range","transpose","zeros"]},Wt.zeros=dt,dt.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:["det","diag","eye","ones","range","size","squeeze","transpose"]},Wt.factorial=gt,gt.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:[]},Wt.random=yt,yt.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},Wt.max=xt,xt.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"]},Wt.min=wt,wt.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},Wt.acos=Et,Et.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"]},Wt.asin=Nt,Nt.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"]},Wt.atan=bt,bt.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"]},Wt.atan2=Ot,Ot.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"]},Wt.cos=Mt,Mt.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"]},Wt.cot=At,At.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"]},Wt.csc=St,St.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"]},Wt.sec=Tt,Tt.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"]},Wt.sin=qt,qt.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"]},Wt.tan=zt,zt.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"]},Wt.in=Ut,Ut.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:[]},Wt.clone=Lt,Lt.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:[]},Wt.format=Rt,Rt.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:[]},Wt.help=_t,_t.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},Wt["import"]=Ct,Ct.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},Wt["typeof"]=Bt,Bt.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:[]},Wt.expr.node.Node=Gt,Gt.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") -},Gt.prototype.toString=function(){return""},kt.prototype=new Gt,Wt.expr.node.Symbol=kt,kt.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},kt.prototype.eval=function(){var e=this.fn;if(void 0===e)throw Error("Undefined symbol "+this.name);var t=this.params.map(function(e){return e.eval()});return e.apply(this,t)},kt.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},jt.prototype=new Gt,Wt.expr.node.Constant=jt,jt.prototype.eval=function(){return this.value},jt.prototype.toString=function(){return this.value?Wt.format(this.value):""},Vt.prototype=new Gt,Wt.expr.node.MatrixNode=Vt,function(){function e(t){return t.map(function(t){return t instanceof Array?e(t):t.eval()})}function t(e){if(e instanceof Array){for(var n="[",r=e.length,a=0;r>a;a++)0!=a&&(n+=", "),n+=t(e[a]);return n+="]"}return""+e}Vt.prototype.eval=function(){return new n(e(this.nodes))},Vt.prototype.toString=function(){return t(this.nodes)}}(),Dt.prototype=new Gt,Wt.expr.node.Block=Dt,Dt.prototype.add=function(e,t){var n=this.params.length;this.params[n]=e,this.visible[n]=void 0!=t?t:!0},Dt.prototype.eval=function(){for(var e=[],t=0,n=this.params.length;n>t;t++){var r=this.params[t].eval();this.visible[t]&&e.push(r)}return e},Dt.prototype.toString=function(){for(var e=[],t=0,n=this.params.length;n>t;t++)this.visible[t]&&e.push("\n "+(""+this.params[t]));return"["+e.join(",")+"\n]"},Ft.prototype=new Gt,Wt.expr.node.Assignment=Ft,Ft.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,t=this.params;if(t&&t.length){var n=[];this.params.forEach(function(e){n.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 "+Wt.typeof(a));e=a.set(n,r),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},Ft.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},Ht.prototype=new Gt,Wt.expr.node.Arguments=Ht,Ht.prototype.eval=function(){var e=this.object;if(void 0==e)throw Error("Node undefined");for(var t=e.eval(),n=this.params,r=[],a=0,i=n.length;i>a;a++)r[a]=n[a].eval();if(!t.get)throw new TypeError("Cannot apply arguments to object of type "+Wt.typeof(t));return t.get(r)},Ht.prototype.toString=function(){var e=this.object?""+this.object:"";return this.params&&(e+="("+this.params.join(", ")+")"),e},Yt.prototype=new Gt,Wt.expr.node.FunctionAssignment=Yt,Yt.prototype.createFunction=function(e,t,n,r){var a=function(){var t=n?n.length:0,a=arguments?arguments.length:0;if(t!=a)throw E(e,a,t);if(t>0)for(var i=0;t>i;i++)n[i].value=arguments[i];return r.eval()};return a.toString=function(){return e+"("+t.join(", ")+")"},a},Yt.prototype.eval=function(){for(var e=this.variables,t=this.values,n=0,r=e.length;r>n;n++)e[n].value=t[n];return this.result.value=this.def,this.def},Yt.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={}}Wt.expr.Scope=e,e.prototype.createNestedScope=function(){var t=new e(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(t),t},e.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,t=0,n=e.length;n>t;t++)e[t].clear()},e.prototype.createSymbol=function(e){var t=this.symbols[e];if(!t){var n=this.findDef(e);t=this.newSymbol(e,n),this.symbols[e]=t}return t},e.prototype.newSymbol=function(e,t){var r=this,a=function(){var t,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 n||a.value instanceof g||a.value instanceof Array){if(arguments.length){var o=a.value instanceof Array?new n(a.value):a.value;for(t=[],i=0;arguments.length>i;i++)t[i]=arguments[i];return o.get(t)}return a.value}return a.value};return a.value=t,a.toString=function(){return a.value?""+a.value:""},a},e.prototype.createLink=function(e){var t=this.links[e];return t||(t=this.createSymbol(e),this.links[e]=t),t},e.prototype.createDef=function(e,t){var n=this.defs[e];return n||(n=this.createSymbol(e),this.defs[e]=n),n&&void 0!=t&&(n.value=t),n},e.prototype.createUpdate=function(e){var t=this.updates[e];return t||(t=this.createLink(e),this.updates[e]=t),t},e.prototype.findDef=function(e){function n(e,t){var n=a(e,t);return i[e]=n,o[e]=n,n}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 n(e,Wt.PI);if("e"==e)return n(e,Wt.E);if("i"==e)return n(e,new t(0,1));var s=Wt[e];if(s)return n(e,s);if(x.isUnit(e)){var f=new x(null,e);return n(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,t=this.parentScope;for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];r.value=t?t.findDef(n):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 t=this.nestedScopes,n=0,r=t.length;r>n;n++)if(t[n].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,t=[];for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];void 0==r.value&&t.push(r)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){t=t.concat(e.getUndefinedSymbols())}),t}}(),function(){function e(){B++,k=P.charAt(B)}function n(){B=0,k=P.charAt(0)}function r(){for(V=C.NULL,j="";" "==k||" "==k;)e();if("#"==k)for(;"\n"!=k&&""!=k;)e();if(""==k)return V=C.DELIMITER,void 0;if("-"==k||","==k||"("==k||")"==k||"["==k||"]"==k||'"'==k||"\n"==k||";"==k||":"==k)return V=C.DELIMITER,j+=k,e(),void 0;if(a(k))for(V=C.DELIMITER;a(k);)j+=k,e();else if(o(k)){for(V=C.NUMBER;o(k);)j+=k,e();if("E"==k||"e"==k)for(j+=k,e(),("+"==k||"-"==k)&&(j+=k,e()),s(k)||(V=C.UNKNOWN);s(k);)j+=k,e()}else{if(!i(k)){for(V=C.UNKNOWN;""!=k;)j+=k,e();throw L('Syntax error in part "'+j+'"')}for(V=C.SYMBOL;i(k)||s(k);)j+=k,e()}}function a(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==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){n(),r();var t;if(t=""==j?new jt(void 0):c(e),""!=j)throw V==C.DELIMITER?_("Unknown operator "+j):L('Unexpected part "'+j+'"');return t}function u(e){var t=l(e);if(!(t instanceof Ft)){var n="ans",r=void 0,a=e.createDef(n);return new Ft(n,r,t,a)}return t}function c(e){var t,n,a;for("\n"!=j&&";"!=j&&""!=j&&(t=u(e));"\n"==j||";"==j;)n||(n=new Dt,t&&(a=";"!=j,n.add(t,a))),r(),"\n"!=j&&";"!=j&&""!=j&&(t=u(e),a=";"!=j,n.add(t,a));return n?n:(t||(t=u(e)),t)}function l(e){if(V==C.SYMBOL&&"function"==j){if(r(),V!=C.SYMBOL)throw L("Function name expected");var t=j;if(r(),"("!=j)throw L("Opening parenthesis ( expected");for(var n=e.createNestedScope(),a=[],i=[];;){if(r(),V!=C.SYMBOL)throw L("Variable name expected");var o=j,s=n.createDef(o);if(a.push(o),i.push(s),r(),","!=j){if(")"==j)break;throw L('Comma , or closing parenthesis ) expected"')}}if(r(),"="!=j)throw L("Equal sign = expected");r();var f=m(n),u=e.createDef(t);return new Yt(t,a,i,f,u)}return h(e)}function h(e){var t=!1;V==C.SYMBOL&&(t=e.hasLink(j));var n=m(e);if("="==j){if(!(n instanceof kt))throw L("Symbol expected at the left hand side of assignment operator =");var a=n.name,i=n.params;t||e.removeLink(a),r();var o=m(e),s=n.hasParams()?e.createUpdate(a):e.createDef(a);return new Ft(a,i,o,s)}return n}function m(e){var t=p(e);if(":"==j){for(var n=[t];":"==j;)r(),n.push(p(e));if(n.length>3)throw new TypeError("Invalid range");var a="range",i=at;t=new kt(a,i,n)}return t}function p(e){for(var t=v(e),n={"in":"in"};void 0!==n[j];){var a=j,i=Wt[n[a]];r();var o=[t,v(e)];t=new kt(a,i,o)}return t}function v(e){var t=d(e);return t}function d(e){for(var t=g(e),n={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==n[j];){var a=j,i=Wt[n[a]];r();var o=[t,g(e)];t=new kt(a,i,o)}return t}function g(e){for(var t=y(e),n={"+":"add","-":"subtract"};void 0!==n[j];){var a=j,i=Wt[n[a]];r();var o=[t,y(e)];t=new kt(a,i,o)}return t}function y(e){for(var t=w(e),n={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==n[j];){var a=j,i=Wt[n[a]];r();var o=[t,w(e)];t=new kt(a,i,o)}return t}function w(e){if("-"==j){var t=j,n=Z;r();var a=[E(e)];return new kt(t,n,a)}return E(e)}function E(e){for(var t=[N(e)];"^"==j;)r(),t.push(N(e));for(var n=t.pop();t.length;){var a=t.pop(),i="^",o=G,s=[a,n];n=new kt(i,o,s)}return n}function N(e){for(var t=b(e);"!"==j;){var n=j,a=gt;r();var i=[t];t=new kt(n,a,i)}return t}function b(e){return O(e)}function O(e){if(V==C.SYMBOL){var t=j;r();var n=e.createLink(t),a=M(e),i=new kt(t,n,a);return i}return A(e)}function M(e){var t=[];if("("==j){if(r(),")"!=j)for(t.push(m(e));","==j;)r(),t.push(m(e));if(")"!=j)throw L("Parenthesis ) missing");r()}return t}function A(t){if('"'==j){for(var n="",a="";""!=k&&('"'!=k||"\\"==a);)n+=k,a=k,e();if(r(),'"'!=j)throw L('End of string " missing');r();var i=new jt(n);return i}return S(t)}function S(e){if("["==j){var t;for(r();"\n"==j;)r();if("]"!=j){var n=[],a=0,i=0;for(n[0]=[m(e)];","==j||";"==j;){for(","==j?i++:(a++,i=0,n[a]=[]),r();"\n"==j;)r();for(n[a][i]=m(e);"\n"==j;)r()}var o=n.length,s=n.length>0?n[0].length:0;for(a=1;o>a;a++)if(n[a].length!=s)throw _("Number of columns must match ("+n[a].length+" != "+s+")");if("]"!=j)throw L("End of matrix ] missing");r(),t=new Vt(n)}else r(),t=new Vt([]);return t}return T(e)}function T(e){if(V==C.NUMBER){var n;n="."==j?0:Number(j),r();var a;if(V==C.SYMBOL){if("i"==j||"I"==j)return a=new t(0,n),r(),new jt(a);if(x.isUnit(j))return a=new x(n,j),r(),new jt(a);throw R('Unknown unit "'+j+'"')}var i=new jt(n);return i}return q(e)}function q(e){if("("==j){r();var t=m(e);if(")"!=j)throw L("Parenthesis ) expected");return r(),t}return z(e)}function z(){throw""==j?L("Unexpected end of expression"):L("Value expected")}function U(e){var t=t(),n=n();return void 0===t?void 0===n?e:e+" (col "+n+")":e+" (ln "+t+", col "+n+")"}function L(e){return new SyntaxError(U(e))}function R(e){return new TypeError(U(e))}function _(e){return Error(U(e))}Wt.expr.Parser=function I(){if(this.constructor!=I)throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new Wt.expr.Scope},Wt.expr.Parser.prototype.parse=function(e,t){return P=e||"",t||(this._newScope(),t=this.scope),f(t)},Wt.expr.Parser.prototype.eval=function(e){var t=this.parse(e);return t.eval()},Wt.expr.Parser.prototype.get=function(e){this._newScope();var t=this.scope.findDef(e);return t?t.value:void 0},Wt.expr.Parser.prototype.set=function(e,t){this.scope.createDef(e,t)},Wt.expr.Parser.prototype._newScope=function(){this.scope=new Wt.expr.Scope(this.scope)},Wt.expr.Parser.prototype.clear=function(){this.scope.clear()};var C={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},P="",B=0,k="",j="",V=C.NULL}(),function(){function e(){this.idMax=-1,this.updateSeq=0,this.parser=new Wt.expr.Parser,this.scope=new Wt.expr.Scope,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}Wt.expr.Workspace=e,e.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},e.prototype.append=function(t){var n=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,a=new Wt.expr.Scope(r),i=new e.Node({id:n,expression:t,parser:this.parser,scope:a,nextNode:void 0,previousNode:this.lastNode});return this.nodes[n]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([n]),n},e.prototype.insertBefore=function(t,n){var r=this.nodes[n];if(!r)throw'Node with id "'+n+'" not found';var a=r.previousNode,i=this._getNewId(),o=a?a.scope:this.scope,s=new Wt.expr.Scope(o),f=new e.Node({id:i,expression:t,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,t){var n=this.nodes[t];if(!n)throw'Node with id "'+t+'" not found';return n==this.lastNode?this.append(e):this.insertBefore(t+1,e)},e.prototype.remove=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';var n=this.getDependencies(e),r=t.previousNode,a=t.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(n)},e.prototype.replace=function(t,n){var r=this.nodes[n];if(!r)throw'Node with id "'+n+'" not found';var a=[n];e._merge(a,this.getDependencies(n));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(t),e._merge(a,this.getDependencies(n)),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 t="Error: "+((e.message||e)+"");this.fn=new jt(t)}},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,t){for(var n=0,r=t.length;r>n;n++){var a=t[n];-1==e.indexOf(a)&&e.push(a)}},e.prototype.getDependencies=function(t){var n,r=[],a=this.nodes[t];if(a){var i=a.scope.defs,o=a.scope.updates,s=[];for(n in i)i.hasOwnProperty(n)&&s.push(n);for(n in o)o.hasOwnProperty(n)&&-1==s.indexOf(n)&&s.push(n);for(var f=a.nextNode;f&&s.length;){for(var u=f.scope,c=0;s.length>c;){if(n=s[c],(u.hasLink(n)||u.hasUpdate(n))&&-1==r.indexOf(f.id)){r.push(f.id);var l=this.getDependencies(f.id);e._merge(r,l)}u.hasDef(n)&&(s.splice(c,1),c--),c++}f=f.nextNode}}return r},e.prototype.getExpr=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getExpr()},e.prototype.getResult=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getResult()},e.prototype._update=function(e){this.updateSeq++;for(var t=this.updateSeq,n=this.nodes,r=0,a=e.length;a>r;r++){var i=e[r],o=n[i];o&&(o.eval(),o.updateSeq=t)}},e.prototype.getChanges=function(e){var t=[],n=this.firstNode;for(e=e||0;n;)n.updateSeq>e&&t.push(n.id),n=n.nextNode;return{ids:t,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=[],t=this.firstNode;t;){var n={id:t.id,expression:t.expression,dependencies:this.getDependencies(t.id)};try{n.result=t.getResult()}catch(r){n.result="Error: "+((r.message||r)+"")}e.push(n),t=t.nextNode}return e}}()})(); \ No newline at end of file +(function(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function t(e,n){if(this.constructor!=t)throw new SyntaxError("Complex constructor must be called with the new operator");if(null!=e&&!v(e)||null!=n&&!v(n))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=e||0,this.im=n||0}function n(e){if(this.constructor!=n)throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof n||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 ("+Xt.typeof(e)+")");this._data=[]}this._size=Zt.size(this._data)}function r(e,t){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(t&&e>t)throw new RangeError("Index out of range ("+e+" > "+t+")")}function a(e,t){return r(t,e.length),e[t-1]}function i(e,t){return t.forEach(function(t){e=a(e,t)}),Rt(e)}function o(e,t){var n=t[0];return n.map?n.map(function(t){return a(e,t)}):[a(e,n)]}function s(e,t){var n=t[0],r=t[1];if(n.map)return r.map?n.map(function(t){var n=a(e,t);return r.map(function(e){return a(n,e)})}):n.map(function(t){return[a(a(e,t),r)]});if(r.map){var i=a(e,n);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,n),r)]]}function f(e,t,n){var r=n==t.length-1,i=t[n],o=function(i){var o=a(e,i);return r?o:f(o,t,n+1)};return i.map?i.map(o):[o(i)]}function u(e,t,n){if(r(t),n instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[t-1]=n}function c(e,t,n,a){var i=!1;n.length>t.length&&(i=!0);for(var o=0;n.length>o;o++){var s=n[o];r(s),(null==t[o]||s>t[o])&&(t[o]=s,i=!0)}i&&Zt.resize(e,t,0);var f=t.length;n.forEach(function(t,n){f-1>n?e=e[t-1]:e[t-1]=a})}function l(e,t,n,a){var i=n[0];r(i),i>t[0]&&Zt.resize(e,[i],0),e[i-1]=a}function h(e,t,n,a){var i=n[0],o=n[1];r(i),r(o);var s=!1;i>(t[0]||0)&&(t[0]=i,s=!0),o>(t[1]||0)&&(t[1]=o,s=!0),s&&Zt.resize(e,t,0),e[i-1][o-1]=a}function m(e,t,n,r,a){var i=r==n.length-1,o=n[r],s=function(o,s){if(i)u(e,o,a[s]),e.length>(t[r]||0)&&(t[r]=e.length);else{var f=e[o-1];f instanceof Array||(e[o-1]=f=[f],e.length>(t[r]||0)&&(t[r]=e.length)),m(f,t,n,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 t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array?p(r):void 0==r&&(e[t]=0)}}function v(e){return e instanceof Number||"number"==typeof e}function d(e){return e==Math.round(e)}function g(e,t,n){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!=n&&!v(n))throw new TypeError("Parameter end must be a number");if(null!=t&&!v(t))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=n?n:0,this.step=null!=t?t:1}function y(e){return e instanceof String||"string"==typeof e}function x(e,t){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!=t&&!y(t))throw Error("Second parameter in Unit constructor must be a string");if(this.value=1,this.unit=x.UNIT_NONE,this.prefix=x.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1,null!=t){for(var n=x.UNITS,r=!1,a=0,i=n.length;i>a;a++){var o=n[a];if(x.endsWith(t,o.name)){var s=t.length-o.name.length,f=t.substring(0,s),u=o.prefixes[f];if(void 0!==u){this.unit=o,this.prefix=u,this.hasUnit=!0,r=!0;break}}}if(!r)throw Error('String "'+t+'" is no unit')}null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}function w(e,t){var n=void 0;if(2==arguments.length){var r=Gt(t);n="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(Gt(arguments[i]));n="Function "+e+" does not support a parameters of type "+a.join(", ")}else n="Unsupported parameter in function "+e;return new TypeError(n)}function E(e,t,n,r){var a="Wrong number of arguments in function "+e+" ("+t+" provided, "+n+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(e){if(1!=arguments.length)throw E("abs",arguments.length,1);if(v(e))return Math.abs(e);if(e instanceof t)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,N);if(e.valueOf()!==e)return N(e.valueOf());throw w("abs",e)}function b(e,r){if(2!=arguments.length)throw E("add",arguments.length,2);if(v(e)){if(v(r))return e+r;if(r instanceof t)return new t(e+r.re,r.im)}else if(e instanceof t){if(v(r))return new t(e.re+r,e.im);if(r instanceof t)return new t(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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,b);if(e.valueOf()!==e)return b(e.valueOf(),r.valueOf());throw w("add",e,r)}function O(e){if(1!=arguments.length)throw E("ceil",arguments.length,1);if(v(e))return Math.ceil(e);if(e instanceof t)return new t(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,O);if(e.valueOf()!==e)return O(e.valueOf());throw w("ceil",e)}function M(e){if(1!=arguments.length)throw E("cube",arguments.length,1);if(v(e))return e*e*e;if(e instanceof t)return P(P(e,e),e);if(e instanceof Array||e instanceof n||e instanceof g)return P(P(e,e),e);if(e.valueOf()!==e)return M(e.valueOf());throw w("cube",e)}function A(e,r){if(2!=arguments.length)throw E("divide",arguments.length,2);if(v(e)){if(v(r))return e/r;if(r instanceof t)return S(new t(e,0),r)}if(e instanceof t){if(v(r))return S(e,new t(r,0));if(r instanceof t)return S(e,r)}if(e instanceof x&&v(r)){var a=e.clone();return a.value/=r,a}if((e instanceof Array||e instanceof n||e instanceof g)&&!(r instanceof Array||r instanceof n||r instanceof g))return Zt.map2(e,r,A);if(e.valueOf()!==e||r.valueOf()!==r)return A(e.valueOf(),r.valueOf());throw w("divide",e,r)}function S(e,n){var r=n.re*n.re+n.im*n.im;return new t((e.re*n.re+e.im*n.im)/r,(e.im*n.re-e.re*n.im)/r)}function T(e,r){if(2!=arguments.length)throw E("equal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof t)return e==r.re&&0==r.im}if(e instanceof t){if(v(r))return e.re==r&&0==e.im;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return T(e.valueOf(),r.valueOf());throw w("equal",e,r)}function q(e){if(1!=arguments.length)throw E("exp",arguments.length,1);if(v(e))return Math.exp(e);if(e instanceof t){var r=Math.exp(e.re);return new t(r*Math.cos(e.im),r*Math.sin(e.im))}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,q);if(e.valueOf()!==e)return q(e.valueOf());throw w("exp",e)}function z(e){if(1!=arguments.length)throw E("fix",arguments.length,1);if(v(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof t)return new t(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 n||e instanceof g)return Zt.map(e,z);if(e.valueOf()!==e)return z(e.valueOf());throw w("fix",e)}function U(e){if(1!=arguments.length)throw E("floor",arguments.length,1);if(v(e))return Math.floor(e);if(e instanceof t)return new t(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,U);if(e.valueOf()!==e)return U(e.valueOf());throw w("floor",e)}function L(e,r){if(2!=arguments.length)throw E("larger",arguments.length,2);if(v(e)){if(v(r))return e>r;if(r instanceof t)return e>N(r)}if(e instanceof t){if(v(r))return N(e)>r;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,T);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("larger",e,r)}function R(e,r){if(2!=arguments.length)throw E("largereq",arguments.length,2);if(v(e)){if(v(r))return e>=r;if(r instanceof t)return e>=N(r)}if(e instanceof t){if(v(r))return N(e)>=r;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,R);if(e.valueOf()!==e||r.valueOf()!==r)return R(e.valueOf(),r.valueOf());throw w("largereq",e,r)}function _(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("log",arguments.length,1,2);if(void 0!==r)return A(_(e),_(r));if(v(e))return e>=0?Math.log(e):_(new t(e,0));if(e instanceof t)return new t(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,_);if(e.valueOf()!==e||r.valueOf()!==r)return _(e.valueOf(),r.valueOf());throw w("log",e,r)}function I(e){if(1!=arguments.length)throw E("log10",arguments.length,1);if(v(e))return e>=0?Math.log(e)/Math.LN10:I(new t(e,0));if(e instanceof t)return new t(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 n||e instanceof g)return Zt.map(e,I);if(e.valueOf()!==e)return I(e.valueOf());throw w("log10",e)}function C(e,r){if(2!=arguments.length)throw E("mod",arguments.length,2);if(v(e)){if(v(r))return e%r;if(r instanceof t&&0==r.im)return e%r.re}else if(e instanceof t&&0==e.im){if(v(r))return e.re%r;if(r instanceof t&&0==r.im)return e.re%r.re}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,C);if(e.valueOf()!==e||r.valueOf()!==r)return C(e.valueOf(),r.valueOf());throw w("mod",e,r)}function P(e,r){if(2!=arguments.length)throw E("multiply",arguments.length,2);if(v(e)){if(v(r))return e*r;if(r instanceof t)return B(new t(e,0),r);if(r instanceof x)return o=r.clone(),o.value*=e,o}else if(e instanceof t){if(v(r))return B(e,new t(r,0));if(r instanceof t)return B(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=Zt.size(e),i=Zt.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=P(e[c][m],r[m][l]);h=null==h?p:b(h,p)}o[c][l]=h}}return o}return r instanceof n?new n(P(e.valueOf(),r.valueOf())):Zt.map2(e,r,P)}if(e instanceof n)return new n(P(e.valueOf(),r.valueOf()))}if(r instanceof Array)return Zt.map2(e,r,P);if(r instanceof n)return new n(P(e.valueOf(),r.valueOf()));if(e.valueOf()!==e||r.valueOf()!==r)return P(e.valueOf(),r.valueOf());throw w("multiply",e,r)}function B(e,n){return new t(e.re*n.re-e.im*n.im,e.re*n.im+e.im*n.re)}function G(e,r){if(2!=arguments.length)throw E("pow",arguments.length,2);if(v(e)){if(v(r))return d(r)||e>=0?Math.pow(e,r):k(new t(e,0),new t(r,0));if(r instanceof t)return k(new t(e,0),r)}else if(e instanceof t){if(v(r))return k(e,new t(r,0));if(r instanceof t)return k(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=Zt.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=P(e,i);return i}if(e instanceof n)return new n(G(e.valueOf(),r))}if(e.valueOf()!==e||r.valueOf()!==r)return G(e.valueOf(),r.valueOf());throw w("pow",e,r)}function k(e,t){var n=_(e),r=P(n,t);return q(r)}function j(e,r){if(1!=arguments.length&&2!=arguments.length)throw E("round",arguments.length,1,2);if(void 0==r){if(v(e))return Math.round(e);if(e instanceof t)return new t(Math.round(e.re),Math.round(e.im));if((e instanceof Array||e instanceof n||e instanceof g)&&Zt.map(e,j),e.valueOf()!==e)return j(e.valueOf());throw w("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 V(e,r);if(e instanceof t)return new t(V(e.re,r),V(e.im,r));if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,j);if(e.valueOf()!==e||r.valueOf()!==r)return L(e.valueOf(),r.valueOf());throw w("round",e,r)}function V(e,t){var n=Math.pow(10,void 0!=t?t:Xt.options.precision);return Math.round(e*n)/n}function D(e){if(1!=arguments.length)throw E("sign",arguments.length,1);if(v(e)){var r;return r=e>0?1:0>e?-1:0}if(e instanceof t){var a=Math.sqrt(e.re*e.re+e.im*e.im);return new t(e.re/a,e.im/a)}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,r);if(e.valueOf()!==e)return r(e.valueOf());throw w("sign",e)}function F(e,r){if(2!=arguments.length)throw E("smaller",arguments.length,2);if(v(e)){if(v(r))return r>e;if(r instanceof t)return N(r)>e}if(e instanceof t){if(v(r))return r>N(e);if(r instanceof t)return N(e)e;if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,F);if(e.valueOf()!==e||r.valueOf()!==r)return F(e.valueOf(),r.valueOf());throw w("smaller",e,r)}function H(e,r){if(2!=arguments.length)throw E("smallereq",arguments.length,2);if(v(e)){if(v(r))return r>=e;if(r instanceof t)return N(r)>=e}if(e instanceof t){if(v(r))return r>=N(e);if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,H);if(e.valueOf()!==e||r.valueOf()!==r)return H(e.valueOf(),r.valueOf());throw w("smallereq",e,r)}function Y(e){if(1!=arguments.length)throw E("sqrt",arguments.length,1);if(v(e))return e>=0?Math.sqrt(e):Y(new t(e,0));if(e instanceof t){var r=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?new t(.5*Math.sqrt(2*(r+e.re)),.5*Math.sqrt(2*(r-e.re))):new t(.5*Math.sqrt(2*(r+e.re)),-.5*Math.sqrt(2*(r-e.re)))}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,Y);if(e.valueOf()!==e)return Y(e.valueOf());throw w("sqrt",e)}function W(e){if(1!=arguments.length)throw E("square",arguments.length,1);if(v(e))return e*e;if(e instanceof t)return P(e,e);if(e instanceof Array||e instanceof n||e instanceof g)return P(e,e);if(e.valueOf()!==e)return W(e.valueOf());throw w("square",e)}function X(e,r){if(2!=arguments.length)throw E("subtract",arguments.length,2);if(v(e)){if(v(r))return e-r;if(r instanceof t)return new t(e-r.re,r.im)}else if(e instanceof t){if(v(r))return new t(e.re-r,e.im);if(r instanceof t)return new t(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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,X);if(e.valueOf()!==e||r.valueOf()!==r)return X(e.valueOf(),r.valueOf());throw w("subtract",e,r)}function Z(e){if(1!=arguments.length)throw E("unaryminus",arguments.length,1);if(v(e))return-e;if(e instanceof t)return new t(-e.re,-e.im);if(e instanceof x){var r=e.clone();return r.value=-e.value,r}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,Z);if(e.valueOf()!==e)return Z(e.valueOf());throw w("unaryminus",e)}function K(e,r){if(2!=arguments.length)throw E("unequal",arguments.length,2);if(v(e)){if(v(r))return e==r;if(r instanceof t)return e==r.re&&0==r.im}if(e instanceof t){if(v(r))return e.re==r&&0==e.im;if(r instanceof t)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 n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,K);if(e.valueOf()!==e||r.valueOf()!==r)return K(e.valueOf(),r.valueOf());throw w("unequal",e,r)}function Q(e){if(1!=arguments.length)throw E("arg",arguments.length,1);if(v(e))return Math.atan2(0,e);if(e instanceof t)return Math.atan2(e.im,e.re);if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,Q);if(e.valueOf()!==e)return Q(e.valueOf());throw w("arg",e)}function J(e){if(1!=arguments.length)throw E("conj",arguments.length,1);if(v(e))return e;if(e instanceof t)return new t(e.re,-e.im);if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,J);if(e.valueOf()!==e)return J(e.valueOf());throw w("conj",e)}function $(e){if(1!=arguments.length)throw E("im",arguments.length,1);if(v(e))return 0;if(e instanceof t)return e.im;if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,$);if(e.valueOf()!==e)return $(e.valueOf());throw w("im",e)}function et(e){if(1!=arguments.length)throw E("re",arguments.length,1);if(v(e))return e;if(e instanceof t)return e.re;if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,et);if(e.valueOf()!==e)return et(e.valueOf());throw w("re",e)}function tt(){switch(arguments.length){case 0:return new t(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 n=t.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid complex number');case 2:return new t(arguments[0],arguments[1]);default:throw E("complex",arguments.length,0,2)}}function nt(e){if(arguments.length>1)throw E("matrix",arguments.length,0,1);return new n(e)}function rt(){return new Xt.expr.Parser}function at(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 t=g.parse(e);if(t)return t;throw new SyntaxError('String "'+t+'" 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 E("range",arguments.length,2,3)}}function it(){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.isUnit(e))return new x(null,e);var t=x.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid unit');case 2:return new x(arguments[0],arguments[1]);default:throw E("unit",arguments.length,1,2)}}function ot(){return new Xt.expr.Workspace}function st(e){if(1!=arguments.length)throw E("det",arguments.length,1);var t=Xt.size(e);switch(t.length){case 0:return Xt.clone(e);case 1:if(1==t[0])return Xt.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+Xt.format(t)+")");case 2:var n=t[0],r=t[1];if(n==r)return ft(e.valueOf(),n,r);throw new RangeError("Matrix must be square (size: "+Xt.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+Xt.format(t)+")")}}function ft(e,t,n){if(1==t)return e[0][0];if(2==t)return e[0][0]*e[1][1]-e[1][0]*e[0][1];for(var r=0,a=0;n>a;a++){var i=ut(e,t,n,0,a);r+=((a+1)%2+(a+1)%2-1)*e[0][a]*ft(i,t-1,n-1)}return r}function ut(e,t,n,r,a){for(var i,o=[],s=0;t>s;s++)if(s!=r){i=o[s-(s>r)]=[];for(var f=0;n>f;f++)f!=a&&(i[f-(f>a)]=e[s][f])}return o}function ct(e,t){var r,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw E("diag",arguments.length,1,2);if(t){if(!v(t)||!d(t))throw new TypeError("Second parameter in function diag must be an integer")}else t=0;var s=t>0?t:0,f=0>t?-t:0;e instanceof n||e instanceof g||(e=new n(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 n;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]=Rt(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]=Rt(r[i+f][i+s]);return new n(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}}function lt(){var e=Zt.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw E("eye",num,0,2);var t=e[0],r=e[1];if(!v(t)||!d(t)||1>t)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 n;a.resize(e);for(var i=Xt.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a}function ht(){var e=Zt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new n,r=1;return t.resize(e,r),t}function mt(e){if(1!=arguments.length)throw E("size",arguments.length,1);if(v(e)||e instanceof t||e instanceof x||null==e)return[];if(y(e))return[e.length];if(e instanceof Array)return Zt.size(e);if(e instanceof n||e instanceof g)return e.size();if(e.valueOf()!==e)return mt(e.valueOf());throw w("size",e)}function pt(e){if(1!=arguments.length)throw E("squeeze",arguments.length,1);return e instanceof n||e instanceof g?vt(e.toArray()):e instanceof Array?vt(Rt(e)):Rt(e)}function vt(e){if(1==e.length)return vt(e[0]);for(var t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array&&(e[t]=vt(r))}return e}function dt(e){if(1!=arguments.length)throw E("transpose",arguments.length,1);var t=Xt.size(e);switch(t.length){case 0:return Xt.clone(e);case 1:return Xt.clone(e);case 2:for(var n,r=t[1],a=t[0],i=e.valueOf(),o=[],s=Xt.clone,f=0;r>f;f++){n=o[f]=[];for(var u=0;a>u;u++)n[u]=s(i[u][f])}return 0==a&&(o[0]=[]),o;default:throw new RangeError("Matrix must be two dimensional (size: "+Xt.format(t)+")")}}function gt(){var e=Zt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new n;return t.resize(e),t}function yt(e){if(1!=arguments.length)throw E("factorial",arguments.length,1);if(v(e)){if(!d(e))throw new TypeError("Function factorial can only handle integer values");var t=e,r=t;for(t--;t>1;)r*=t,t--;return 0==r&&(r=1),r}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,yt);if(e.valueOf()!==e)return yt(e.valueOf());throw w("factorial",e)}function xt(){if(0!=arguments.length)throw E("random",arguments.length,0);return Math.random()}function wt(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return wt.apply(this,e.valueOf());for(var t=arguments[0],n=1,r=arguments.length;r>n;n++){var a=arguments[n];L(a,t)&&(t=a)}return t}function Et(e){if(0==arguments.length)throw Error("Function sum requires one or more parameters (0 provided)");if(1==arguments.length&&e.valueOf()instanceof Array)return Et.apply(this,e.valueOf());for(var t=arguments[0],n=1,r=arguments.length;r>n;n++){var a=arguments[n];F(a,t)&&(t=a)}return t}function Nt(e){if(1!=arguments.length)throw E("acos",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.acos(e):Nt(new t(e,0));if(e instanceof t){var r=new t(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),a=Y(r),i=new t(a.re-e.im,a.im+e.re),o=_(i);return new t(1.5707963267948966-o.im,o.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,Nt);if(e.valueOf()!==e)return Nt(e.valueOf());throw w("acos",e)}function bt(e){if(1!=arguments.length)throw E("asin",arguments.length,1);if(v(e))return e>=-1&&1>=e?Math.asin(e):bt(new t(e,0));if(e instanceof t){var r=e.re,a=e.im,i=new t(a*a-r*r+1,-2*r*a),o=Y(i),s=new t(o.re-a,o.im+r),f=_(s);return new t(f.im,-f.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,bt);if(e.valueOf()!==e)return bt(e.valueOf());throw w("asin",e)}function Ot(e){if(1!=arguments.length)throw E("atan",arguments.length,1);if(v(e))return Math.atan(e);if(e instanceof t){var r=e.re,a=e.im,i=r*r+(1-a)*(1-a),o=new t((1-a*a-r*r)/i,-2*r/i),s=_(o);return new t(-.5*s.im,.5*s.re)}if(e instanceof Array||e instanceof n||e instanceof g)return Zt.map(e,Ot);if(e.valueOf()!==e)return Ot(e.valueOf());throw w("atan",e)}function Mt(e,r){if(2!=arguments.length)throw E("atan2",arguments.length,2);if(v(e)){if(v(r))return Math.atan2(e,r);if(r instanceof t)return Math.atan2(e,r.re)}else if(e instanceof t){if(v(r))return Math.atan2(e.re,r);if(r instanceof t)return Math.atan2(e.re,r.re)}if(e instanceof Array||e instanceof n||e instanceof g||r instanceof Array||r instanceof n||r instanceof g)return Zt.map2(e,r,Mt);if(r.valueOf()!==r||e.valueOf()!==e)return Mt(e.valueOf(),r.valueOf());throw w("atan2",e,r)}function At(e){if(1!=arguments.length)throw E("cos",arguments.length,1);if(v(e))return Math.cos(e);if(e instanceof t)return new t(.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 n||e instanceof g)return Zt.map(e,At);if(e.valueOf()!==e)return At(e.valueOf());throw w("cos",e)}function St(e){if(1!=arguments.length)throw E("cot",arguments.length,1);if(v(e))return 1/Math.tan(e);if(e instanceof t){var r=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new t(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 n||e instanceof g)return Zt.map(e,St);if(e.valueOf()!==e)return St(e.valueOf());throw w("cot",e)}function Tt(e){if(1!=arguments.length)throw E("csc",arguments.length,1);if(v(e))return 1/Math.sin(e);if(e instanceof t){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return new t(.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 n||e instanceof g)return Zt.map(e,Tt);if(e.valueOf()!==e)return Tt(e.valueOf());throw w("csc",e)}function qt(e){if(1!=arguments.length)throw E("sec",arguments.length,1);if(v(e))return 1/Math.cos(e);if(e instanceof t){var r=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return new t(.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 n||e instanceof g)return Zt.map(e,qt);if(e.valueOf()!==e)return qt(e.valueOf());throw w("sec",e)}function zt(e){if(1!=arguments.length)throw E("sin",arguments.length,1);if(v(e))return Math.sin(e);if(e instanceof t)return new t(.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 n||e instanceof g)return Zt.map(e,zt);if(e.valueOf()!==e)return zt(e.valueOf());throw w("sin",e)}function Ut(e){if(1!=arguments.length)throw E("tan",arguments.length,1);if(v(e))return Math.tan(e);if(e instanceof t){var r=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return new t(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 n||e instanceof g)return Zt.map(e,Ut);if(e.valueOf()!==e)return Ut(e.valueOf());throw w("tan",e)}function Lt(e,t){if(2!=arguments.length)throw E("in",arguments.length,2);if(e instanceof x&&t instanceof x){if(!e.equalBase(t))throw Error("Units do not match");if(t.hasValue)throw Error("Cannot convert to a unit with a value");if(!t.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=t.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||e instanceof n||e instanceof g||t instanceof Array||t instanceof n||t instanceof g)return Zt.map2(e,t,Lt);if(e.valueOf()!==e)return Xt.in(e.valueOf());throw w("in",e)}function Rt(t){if(1!=arguments.length)throw E("clone",arguments.length,1);if(null==t)return t;if("function"==typeof t.clone)return t.clone();if(v(t)||y(t)||e(t))return t;if(t instanceof Array)return t.map(function(e){return Rt(e)});if(t instanceof Object)return Zt.mapObject(t,Rt);throw w("clone",t)}function _t(e,t){var n=arguments.length;if(1!=n&&2!=n)throw E("format",n,1,2);if(1==n){var r=arguments[0];return v(r)?Zt.formatNumber(r):r instanceof Array?Zt.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(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,n){for(var r=n.split("."),a=t[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})}function It(e){if(1!=arguments.length)throw E("help",arguments.length,1);if(void 0!=e){if(e.doc)return Ct(e.doc);if(e.constructor.doc)return Ct(e.constructor.doc);if(y(e)){var t=Xt[e];if(t&&t.doc)return Ct(t.doc)}}return e instanceof Object&&e.name?'No documentation found on subject "'+e.name+'"':e instanceof Object&&e.constructor.name?'No documentation found on subject "'+e.constructor.name+'"':'No documentation found on subject "'+e+'"'}function Ct(e){var t="";if(e.name&&(t+="NAME\n"+e.name+"\n\n"),e.category&&(t+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(t+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var n=Xt.parser();t+="EXAMPLES\n";for(var r=0;e.examples.length>r;r++){var a,i=e.examples[r];try{a=n.eval(i)}catch(o){a=o}t+=i+"\n",t+=" "+Xt.format(a)+"\n"}t+="\n"}return e.seealso&&(t+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),t}function Pt(e,t){var n;if(y(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var r=require(e);Pt(r)}else if(Bt(e)){if(n=e.name,!n)throw Error("Cannot import an unnamed function");(t||void 0===Xt[n])&&(Xt[n]=e)}else if(e instanceof Object)for(n in e)if(e.hasOwnProperty(n)){var a=e[n];Bt(a)?(t||void 0===Xt[n])&&(Xt[n]=a):Pt(a)}}function Bt(e){return"function"==typeof e||v(e)||y(e)||e instanceof t||e instanceof x +}function Gt(e){if(1!=arguments.length)throw E("typeof",arguments.length,1);var t=typeof e;if("object"==t){if(null==e)return"null";if(e.constructor){for(var n in Xt)if(Xt.hasOwnProperty(n)&&e.constructor==Xt[n])return n.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t}function kt(){}function jt(e,t,n){this.name=e,this.fn=t,this.params=n}function Vt(e){this.value=e}function Dt(e){this.nodes=e||[]}function Ft(){this.params=[],this.visible=[]}function Ht(e,t,n,r){this.name=e,this.params=t,this.expr=n,this.result=r}function Yt(e,t){this.object=e,this.params=t}function Wt(e,t,n,r,a){this.name=e,this.variables=n,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,t,n,r),this.result=a}var Xt={type:{},expr:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=Xt),"undefined"!=typeof exports&&(exports=Xt),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return Xt}),"undefined"!=typeof window&&(window.math=Xt);var Zt=function(){function e(e){if(e instanceof Array){var t=e.length;if(t){var n=o(e[0]);return 0==n[0]?[0].concat(n):[t].concat(n)}return[t]}return[]}function t(e,n,r){var a,i=e.length;if(i!=n[r])throw new RangeError("Dimension mismatch ("+i+" != "+n[r]+")");if(n.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 ("+(n.length-1)+" < "+n.length+")");t(e[a],n,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(n.length+1)+" > "+n.length+")")}function r(e,t,n){if(t.length-1>n){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");r(a,t,n+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,t,n,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=t[n];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?Rt(r):0;else e.length=t[n];i=e.length}if(t.length-1>n){var f=n+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,t,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,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var n=Math.abs(e);if(n>1e-4&&1e6>n||0==n)return V(e,t)+"";var r=Math.round(Math.log(n)/Math.LN10),a=e/Math.pow(10,r);return V(a,t)+"E"+r},i.formatArray=function(e){if(e instanceof Array){for(var t="[",n=e.length,r=0;n>r;r++)0!=r&&(t+=", "),t+=i.formatArray(e[r]);return t+="]"}return _t(e)},i.formatArray2d=function(e){var t="[",n=i.size(e);if(2!=n.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(n)+")");for(var r=n[0],a=n[1],o=0;r>o;o++){0!=o&&(t+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(t+=", ");var u=s[f];void 0!=u&&(t+=_t(u))}}return t+="]"},i.argsToArray=function(e){var t;if(0==e.length)t=[];else if(1==e.length)t=e[0],t instanceof n&&(t=t.toVector()),t instanceof g&&(t=t.valueOf()),t instanceof Array||(t=[t]);else{t=[];for(var r=0;e.length>r;r++)t[r]=e[r]}return t},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,t){if(e instanceof Array||e instanceof n||e instanceof g)return e.map(function(e){return t(e)});throw new TypeError("Array expected")},i.map2=function(e,t,r){var a,o,s;if(e instanceof n||t instanceof n)return new n(i.map2(e.valueOf(),t.valueOf(),r));if(e instanceof g||t instanceof g)return new n(i.map2(e.valueOf(),t.valueOf(),r));if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],t[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=r(e[s],t);else if(t instanceof Array)for(a=[],o=t.length,s=0;o>s;s++)a[s]=r(e,t[s]);else a=r(e,t);return a},i.forEach=function(e,t){if(e instanceof Array)e.forEach(t);else for(var n in e)e.hasOwnProperty(n)&&t(e[n],n,e)},i.mapObject=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n},i.deepEqual=function(e,t){var n,r,a;if(e instanceof Array){if(!(t instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],t[r]))return!1;return!0}if(e instanceof Object){if(t instanceof Array||!(t instanceof Object))return!1;for(n in e)if(e.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;for(n in t)if(t.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;return!0}return e.valueOf()==t.valueOf()},i.size=function o(t){var n=e(t);return i.validate(t,n),n},i.validate=function(e,n){var a=0==n.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=n.indexOf(0);o?(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)+")")}),r(e,n,0)):t(e,n,0)}},i.resize=function(e,t,n){if(!(t instanceof Array))throw new TypeError("Size must be an array (size is "+Xt.typeof(t)+")");t.forEach(function(e){if(!v(e)||!d(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(t)+")")});var r=-1!=t.indexOf(0);r&&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)+")")}),a(e,t,0,n)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;this.length>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var n=0,r=this.length;r>n;++n)e.call(t||this,this[n],n,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var n,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(t&&(n=t),r=Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(n,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 t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&!e.call(r,t[a],a,t))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&e.call(r,t[a],a,t))return!0;return!1}),i}();Xt.type.Complex=t,function(){function e(){for(;" "==c||" "==c;)a()}function n(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="",t=u;if("+"==c?a():"-"==c&&(e+=c,a()),!n(c))return i(t),null;for(;n(c);)e+=c,a();if("E"==c||"e"==c){if(e+=c,a(),("+"==c||"-"==c)&&(e+=c,a()),!r(c))return i(t),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 t="+"==c?"1":"-1";return a(),a(),t}return null}var f,u,c;t.parse=function(n){if(f=n,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 t(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new t(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 t(Number(r),Number(l))}return(r=s())?(e(),c?null:new t(0,Number(r))):null}}(),t.prototype.clone=function(){return new t(this.re,this.im)},t.prototype.toString=function(){var e="",t=Zt.formatNumber(this.re),n=Zt.formatNumber(this.im);return e=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":n+"i":this.im>0?1==this.im?t+" + i":t+" + "+n+"i":-1==this.im?t+" - i":t+" - "+Zt.formatNumber(Math.abs(this.im))+"i"},t.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"]},Xt.type.Matrix=n,n.prototype.get=function(e){var t;if(e instanceof n)t=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+Xt.typeof(e));t=!e.some(function(e){return e.forEach})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(t)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 n(o(this._data,e));case 2:return new n(s(this._data,e));default:return new n(f(this._data,e,0))}},n.prototype.set=function(e,t){var r;if(e instanceof n)r=e.isVector(),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Unsupported type of index "+Xt.typeof(e));r=!e.some(function(e){return e.forEach})}if((t instanceof n||t instanceof g)&&(t=t.valueOf()),e.length=e})},n.prototype.toVector=function(){var e=0,t=void 0,n=[];if(this._size.forEach(function(r,a){r>1&&(e++,t=a),n[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},n.prototype.isVector=function(){var e=0;return this._size.forEach(function(t){t>1&&e++}),1>=e},n.prototype.toArray=function(){return Rt(this._data)},n.prototype.valueOf=function(){return this._data},n.prototype.toString=function(){return Zt.formatArray(this._data)},Xt.type.Range=g,g.parse=function(e){if(!y(e))return null;var t=e.split(":"),n=t.map(function(e){return Number(e)}),r=n.some(function(e){return isNaN(e)});if(r)return null;switch(n.length){case 2:return new g(n[0],1,n[1]);case 3:return new g(n[0],n[1],n[2]);default:return null}},g.prototype.clone=function(){return new g(this.start,this.step,this.end)},g.prototype.size=function(){var e=0,t=Number(this.start),n=Number(this.step),r=Number(this.end),a=r-t;return D(n)==D(a)?e=Math.floor(a/n)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},g.prototype.forEach=function(e){var t=Number(this.start),n=Number(this.step),r=Number(this.end),a=0;if(n>0)for(;r>=t;)e(t,a,this),t+=n,a++;else if(0>n)for(;t>=r;)e(t,a,this),t+=n,a++},g.prototype.map=function(e){var t=[];return this.forEach(function(n,r,a){t[r]=e(n,r,a)}),t},g.prototype.toMatrix=function(){return new n(this.toArray())},g.prototype.toArray=function(){var e=[];return this.forEach(function(t,n){e[n]=t}),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=_t(Number(this.start));return 1!=this.step&&(e+=":"+_t(Number(this.step))),e+=":"+_t(Number(this.end))},Xt.type.Unit=x,function(){function e(){for(;" "==u||" "==u;)r()}function t(e){return e>="0"&&"9">=e||"."==e}function n(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()),!t(u))return a(i),null;for(;t(u);)e+=u,r();if("E"==u||"e"==u){if(e+=u,r(),("+"==u||"-"==u)&&(e+=u,r()),!n(u))return a(i),null;for(;n(u);)e+=u,r()}return e}function o(){var t="";for(e();u&&" "!=u&&" "!=u;)t+=u,r();return t||null}var s,f,u;x.parse=function(t){if(s=t,f=-1,u="",!y(s))return null;r(),e();var n,a=i();return a?(n=o(),r(),e(),u?null:a&&n?new x(Number(a),n):null):(n=o(),r(),e(),u?null:new x(null,n))}}(),x.prototype.clone=function(){var e=new x;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},x.endsWith=function(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t},x.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},x.prototype._unnormalize=function(e,t){return void 0===t?e/this.unit.value/this.prefix.value-this.unit.offset:e/this.unit.value/t-this.unit.offset},x.isUnit=function(e){for(var t=x.UNITS,n=t.length,r=0;n>r;r++){var a=t[r];if(x.endsWith(e,a.name)){var i=e.length-a.name.length;if(0==i)return!0;var o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return!0}}return!1},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.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),Zt.formatNumber(e)+" "+this.prefix.name+this.unit.name;var t=Math.abs(this.value/this.unit.value),n=x.PREFIX_NONE,r=Math.abs(Math.log(t/n.value)/Math.LN10-1.2),a=this.unit.prefixes;for(var i in a)if(a.hasOwnProperty(i)){var o=a[i];if(o.scientific){var s=Math.abs(Math.log(t/o.value)/Math.LN10-1.2);r>s&&(n=o,r=s)}}return e=this._unnormalize(this.value,n.value),Zt.formatNumber(e)+" "+n.name+this.unit.name},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 Kt=x.BASE_UNITS,Qt=x.PREFIXES;x.BASE_UNIT_NONE={},x.UNIT_NONE={name:"",base:x.BASE_UNIT_NONE,value:1,offset:0},x.UNITS=[{name:"meter",base:Kt.LENGTH,prefixes:Qt.LONG,value:1,offset:0},{name:"inch",base:Kt.LENGTH,prefixes:Qt.NONE,value:.0254,offset:0},{name:"foot",base:Kt.LENGTH,prefixes:Qt.NONE,value:.3048,offset:0},{name:"yard",base:Kt.LENGTH,prefixes:Qt.NONE,value:.9144,offset:0},{name:"mile",base:Kt.LENGTH,prefixes:Qt.NONE,value:1609.344,offset:0},{name:"link",base:Kt.LENGTH,prefixes:Qt.NONE,value:.201168,offset:0},{name:"rod",base:Kt.LENGTH,prefixes:Qt.NONE,value:5.02921,offset:0},{name:"chain",base:Kt.LENGTH,prefixes:Qt.NONE,value:20.1168,offset:0},{name:"angstrom",base:Kt.LENGTH,prefixes:Qt.NONE,value:1e-10,offset:0},{name:"m",base:Kt.LENGTH,prefixes:Qt.SHORT,value:1,offset:0},{name:"ft",base:Kt.LENGTH,prefixes:Qt.NONE,value:.3048,offset:0},{name:"yd",base:Kt.LENGTH,prefixes:Qt.NONE,value:.9144,offset:0},{name:"mi",base:Kt.LENGTH,prefixes:Qt.NONE,value:1609.344,offset:0},{name:"li",base:Kt.LENGTH,prefixes:Qt.NONE,value:.201168,offset:0},{name:"rd",base:Kt.LENGTH,prefixes:Qt.NONE,value:5.02921,offset:0},{name:"ch",base:Kt.LENGTH,prefixes:Qt.NONE,value:20.1168,offset:0},{name:"mil",base:Kt.LENGTH,prefixes:Qt.NONE,value:254e-7,offset:0},{name:"m2",base:Kt.SURFACE,prefixes:Qt.SHORT,value:1,offset:0},{name:"sqin",base:Kt.SURFACE,prefixes:Qt.NONE,value:64516e-8,offset:0},{name:"sqft",base:Kt.SURFACE,prefixes:Qt.NONE,value:.09290304,offset:0},{name:"sqyd",base:Kt.SURFACE,prefixes:Qt.NONE,value:.83612736,offset:0},{name:"sqmi",base:Kt.SURFACE,prefixes:Qt.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:Kt.SURFACE,prefixes:Qt.NONE,value:25.29295,offset:0},{name:"sqch",base:Kt.SURFACE,prefixes:Qt.NONE,value:404.6873,offset:0},{name:"sqmil",base:Kt.SURFACE,prefixes:Qt.NONE,value:6.4516e-10,offset:0},{name:"m3",base:Kt.VOLUME,prefixes:Qt.SHORT,value:1,offset:0},{name:"L",base:Kt.VOLUME,prefixes:Qt.SHORT,value:.001,offset:0},{name:"litre",base:Kt.VOLUME,prefixes:Qt.LONG,value:.001,offset:0},{name:"cuin",base:Kt.VOLUME,prefixes:Qt.NONE,value:16387064e-12,offset:0},{name:"cuft",base:Kt.VOLUME,prefixes:Qt.NONE,value:.028316846592,offset:0},{name:"cuyd",base:Kt.VOLUME,prefixes:Qt.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:Kt.VOLUME,prefixes:Qt.NONE,value:5e-6,offset:0},{name:"tablespoon",base:Kt.VOLUME,prefixes:Qt.NONE,value:15e-6,offset:0},{name:"minim",base:Kt.VOLUME,prefixes:Qt.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:Kt.VOLUME,prefixes:Qt.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:Kt.VOLUME,prefixes:Qt.NONE,value:2957353e-11,offset:0},{name:"gill",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0001182941,offset:0},{name:"cup",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0002365882,offset:0},{name:"pint",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0004731765,offset:0},{name:"quart",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0009463529,offset:0},{name:"gallon",base:Kt.VOLUME,prefixes:Qt.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:Kt.VOLUME,prefixes:Qt.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:Kt.VOLUME,prefixes:Qt.NONE,value:.1589873,offset:0},{name:"hogshead",base:Kt.VOLUME,prefixes:Qt.NONE,value:.238481,offset:0},{name:"fldr",base:Kt.VOLUME,prefixes:Qt.NONE,value:36966911e-13,offset:0},{name:"floz",base:Kt.VOLUME,prefixes:Qt.NONE,value:2957353e-11,offset:0},{name:"gi",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0001182941,offset:0},{name:"cp",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0002365882,offset:0},{name:"pt",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0004731765,offset:0},{name:"qt",base:Kt.VOLUME,prefixes:Qt.NONE,value:.0009463529,offset:0},{name:"gal",base:Kt.VOLUME,prefixes:Qt.NONE,value:.003785412,offset:0},{name:"bbl",base:Kt.VOLUME,prefixes:Qt.NONE,value:.1173478,offset:0},{name:"obl",base:Kt.VOLUME,prefixes:Qt.NONE,value:.1589873,offset:0},{name:"g",base:Kt.MASS,prefixes:Qt.SHORT,value:.001,offset:0},{name:"gram",base:Kt.MASS,prefixes:Qt.LONG,value:.001,offset:0},{name:"ton",base:Kt.MASS,prefixes:Qt.SHORT,value:907.18474,offset:0},{name:"tonne",base:Kt.MASS,prefixes:Qt.SHORT,value:1e3,offset:0},{name:"grain",base:Kt.MASS,prefixes:Qt.NONE,value:6479891e-11,offset:0},{name:"dram",base:Kt.MASS,prefixes:Qt.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:Kt.MASS,prefixes:Qt.NONE,value:.028349523125,offset:0},{name:"poundmass",base:Kt.MASS,prefixes:Qt.NONE,value:.45359237,offset:0},{name:"hundredweight",base:Kt.MASS,prefixes:Qt.NONE,value:45.359237,offset:0},{name:"stick",base:Kt.MASS,prefixes:Qt.NONE,value:.115,offset:0},{name:"gr",base:Kt.MASS,prefixes:Qt.NONE,value:6479891e-11,offset:0},{name:"dr",base:Kt.MASS,prefixes:Qt.NONE,value:.0017718451953125,offset:0},{name:"oz",base:Kt.MASS,prefixes:Qt.NONE,value:.028349523125,offset:0},{name:"lbm",base:Kt.MASS,prefixes:Qt.NONE,value:.45359237,offset:0},{name:"cwt",base:Kt.MASS,prefixes:Qt.NONE,value:45.359237,offset:0},{name:"s",base:Kt.TIME,prefixes:Qt.SHORT,value:1,offset:0},{name:"min",base:Kt.TIME,prefixes:Qt.NONE,value:60,offset:0},{name:"h",base:Kt.TIME,prefixes:Qt.NONE,value:3600,offset:0},{name:"seconds",base:Kt.TIME,prefixes:Qt.LONG,value:1,offset:0},{name:"second",base:Kt.TIME,prefixes:Qt.LONG,value:1,offset:0},{name:"sec",base:Kt.TIME,prefixes:Qt.LONG,value:1,offset:0},{name:"minutes",base:Kt.TIME,prefixes:Qt.NONE,value:60,offset:0},{name:"minute",base:Kt.TIME,prefixes:Qt.NONE,value:60,offset:0},{name:"hours",base:Kt.TIME,prefixes:Qt.NONE,value:3600,offset:0},{name:"hour",base:Kt.TIME,prefixes:Qt.NONE,value:3600,offset:0},{name:"day",base:Kt.TIME,prefixes:Qt.NONE,value:86400,offset:0},{name:"days",base:Kt.TIME,prefixes:Qt.NONE,value:86400,offset:0},{name:"rad",base:Kt.ANGLE,prefixes:Qt.NONE,value:1,offset:0},{name:"deg",base:Kt.ANGLE,prefixes:Qt.NONE,value:.017453292519943295,offset:0},{name:"grad",base:Kt.ANGLE,prefixes:Qt.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:Kt.ANGLE,prefixes:Qt.NONE,value:6.283185307179586,offset:0},{name:"A",base:Kt.CURRENT,prefixes:Qt.SHORT,value:1,offset:0},{name:"ampere",base:Kt.CURRENT,prefixes:Qt.LONG,value:1,offset:0},{name:"K",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1,offset:0},{name:"degC",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1,offset:273.15},{name:"degF",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1/1.8,offset:459.67},{name:"degR",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1/1.8,offset:0},{name:"kelvin",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1,offset:0},{name:"celsius",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1,offset:273.15},{name:"fahrenheit",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:Kt.TEMPERATURE,prefixes:Qt.NONE,value:1/1.8,offset:0},{name:"mol",base:Kt.AMOUNT_OF_SUBSTANCE,prefixes:Qt.NONE,value:1,offset:0},{name:"mole",base:Kt.AMOUNT_OF_SUBSTANCE,prefixes:Qt.NONE,value:1,offset:0},{name:"cd",base:Kt.LUMINOUS_INTENSITY,prefixes:Qt.NONE,value:1,offset:0},{name:"candela",base:Kt.LUMINOUS_INTENSITY,prefixes:Qt.NONE,value:1,offset:0},{name:"N",base:Kt.FORCE,prefixes:Qt.SHORT,value:1,offset:0},{name:"newton",base:Kt.FORCE,prefixes:Qt.LONG,value:1,offset:0},{name:"lbf",base:Kt.FORCE,prefixes:Qt.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:Kt.FORCE,prefixes:Qt.NONE,value:4.4482216152605,offset:0},{name:"b",base:Kt.BIT,prefixes:Qt.BINARY_SHORT,value:1,offset:0},{name:"bits",base:Kt.BIT,prefixes:Qt.BINARY_LONG,value:1,offset:0},{name:"B",base:Kt.BIT,prefixes:Qt.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:Kt.BIT,prefixes:Qt.BINARY_LONG,value:8,offset:0}],Xt.E=Math.E,Xt.LN2=Math.LN2,Xt.LN10=Math.LN10,Xt.LOG2E=Math.LOG2E,Xt.LOG10E=Math.LOG10E,Xt.PI=Math.PI,Xt.SQRT1_2=Math.SQRT1_2,Xt.SQRT2=Math.SQRT2,Xt.I=new t(0,-1),Xt.pi=Xt.PI,Xt.e=Xt.E,Xt.i=Xt.I,Xt.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"]},Xt.add=b,b.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"]},Xt.ceil=O,O.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"]},Xt.cube=M,M.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"]},Xt.divide=A,A.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"]},Xt.equal=T,T.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"]},Xt.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"]},Xt.fix=z,z.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"]},Xt.floor=U,U.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"]},Xt.larger=L,L.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"]},Xt.largereq=R,R.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"]},Xt.log=_,_.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"]},Xt.log10=I,I.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"]},Xt.mod=C,C.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:[]},Xt.multiply=P,P.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"]},Xt.pow=G,G.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"]},Xt.round=j,j.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"]},Xt.sign=D,D.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"]},Xt.smaller=F,F.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"]},Xt.smallereq=H,H.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"]},Xt.sqrt=Y,Y.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"]},Xt.square=W,W.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"]},Xt.subtract=X,X.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"]},Xt.unaryminus=Z,Z.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},Xt.unequal=K,K.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"]},Xt.arg=Q,Q.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"]},Xt.conj=J,J.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"]},Xt.im=$,$.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"]},Xt.re=et,et.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"]},Xt.complex=tt,Xt.matrix=nt,Xt.parser=rt,Xt.range=at,Xt.unit=it,Xt.workspace=ot,Xt.det=st,st.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:["diag","eye","range","size","squeeze","transpose","zeros"]},Xt.diag=ct,ct.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:["det","eye","ones","range","size","squeeze","transpose","zeros"]},Xt.eye=lt,lt.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:["det","diag","ones","range","size","squeeze","transpose","zeros"]},Xt.ones=ht,ht.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:["det","diag","eye","range","size","squeeze","transpose","zeros"]},Xt.size=mt,mt.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:["det","diag","eye","ones","range","squeeze","transpose","zeros"]},Xt.squeeze=pt,pt.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:["det","diag","eye","ones","range","size","transpose","zeros"]},Xt.transpose=dt,dt.doc={name:this.name,category:"Numerics",syntax:["transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","transpose(a)"],seealso:["det","diag","eye","ones","range","size","squeeze","transpose","zeros"]},Xt.zeros=gt,gt.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:["det","diag","eye","ones","range","size","squeeze","transpose"]},Xt.factorial=yt,yt.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:[]},Xt.random=xt,xt.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},Xt.max=wt,wt.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"]},Xt.min=Et,Et.doc={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["max(2, 3, 4, 1)","max(2.7, 7.1, -4.5, 2.0, 4.1)","min(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["sum","prod","avg","var","std","min","median"]},Xt.acos=Nt,Nt.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"]},Xt.asin=bt,bt.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"]},Xt.atan=Ot,Ot.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"]},Xt.atan2=Mt,Mt.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"]},Xt.cos=At,At.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"]},Xt.cot=St,St.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"]},Xt.csc=Tt,Tt.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"]},Xt.sec=qt,qt.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"]},Xt.sin=zt,zt.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"]},Xt.tan=Ut,Ut.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"]},Xt.in=Lt,Lt.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:[]},Xt.clone=Rt,Rt.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:[]},Xt.format=_t,_t.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:[]},Xt.help=It,It.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},Xt["import"]=Pt,Pt.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},Xt["typeof"]=Gt,Gt.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:[]},Xt.expr.node.Node=kt,kt.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") +},kt.prototype.toString=function(){return""},jt.prototype=new kt,Xt.expr.node.Symbol=jt,jt.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},jt.prototype.eval=function(){var e=this.fn;if(void 0===e)throw Error("Undefined symbol "+this.name);var t=this.params.map(function(e){return e.eval()});return e.apply(this,t)},jt.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},Vt.prototype=new kt,Xt.expr.node.Constant=Vt,Vt.prototype.eval=function(){return this.value},Vt.prototype.toString=function(){return this.value?Xt.format(this.value):""},Dt.prototype=new kt,Xt.expr.node.MatrixNode=Dt,function(){function e(t){return t.map(function(t){return t instanceof Array?e(t):t.eval()})}function t(e){if(e instanceof Array){for(var n="[",r=e.length,a=0;r>a;a++)0!=a&&(n+=", "),n+=t(e[a]);return n+="]"}return""+e}Dt.prototype.eval=function(){return new n(e(this.nodes))},Dt.prototype.toString=function(){return t(this.nodes)}}(),Ft.prototype=new kt,Xt.expr.node.Block=Ft,Ft.prototype.add=function(e,t){var n=this.params.length;this.params[n]=e,this.visible[n]=void 0!=t?t:!0},Ft.prototype.eval=function(){for(var e=[],t=0,n=this.params.length;n>t;t++){var r=this.params[t].eval();this.visible[t]&&e.push(r)}return e},Ft.prototype.toString=function(){for(var e=[],t=0,n=this.params.length;n>t;t++)this.visible[t]&&e.push("\n "+(""+this.params[t]));return"["+e.join(",")+"\n]"},Ht.prototype=new kt,Xt.expr.node.Assignment=Ht,Ht.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,t=this.params;if(t&&t.length){var n=[];this.params.forEach(function(e){n.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 "+Xt.typeof(a));e=a.set(n,r),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},Ht.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},Yt.prototype=new kt,Xt.expr.node.Arguments=Yt,Yt.prototype.eval=function(){var e=this.object;if(void 0==e)throw Error("Node undefined");for(var t=e.eval(),n=this.params,r=[],a=0,i=n.length;i>a;a++)r[a]=n[a].eval();if(!t.get)throw new TypeError("Cannot apply arguments to object of type "+Xt.typeof(t));return t.get(r)},Yt.prototype.toString=function(){var e=this.object?""+this.object:"";return this.params&&(e+="("+this.params.join(", ")+")"),e},Wt.prototype=new kt,Xt.expr.node.FunctionAssignment=Wt,Wt.prototype.createFunction=function(e,t,n,r){var a=function(){var t=n?n.length:0,a=arguments?arguments.length:0;if(t!=a)throw E(e,a,t);if(t>0)for(var i=0;t>i;i++)n[i].value=arguments[i];return r.eval()};return a.toString=function(){return e+"("+t.join(", ")+")"},a},Wt.prototype.eval=function(){for(var e=this.variables,t=this.values,n=0,r=e.length;r>n;n++)e[n].value=t[n];return this.result.value=this.def,this.def},Wt.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={}}Xt.expr.Scope=e,e.prototype.createNestedScope=function(){var t=new e(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(t),t},e.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,t=0,n=e.length;n>t;t++)e[t].clear()},e.prototype.createSymbol=function(e){var t=this.symbols[e];if(!t){var n=this.findDef(e);t=this.newSymbol(e,n),this.symbols[e]=t}return t},e.prototype.newSymbol=function(e,t){var r=this,a=function(){var t,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 n||a.value instanceof g||a.value instanceof Array){if(arguments.length){var o=a.value instanceof Array?new n(a.value):a.value;for(t=[],i=0;arguments.length>i;i++)t[i]=arguments[i];return o.get(t)}return a.value}return a.value};return a.value=t,a.toString=function(){return a.value?""+a.value:""},a},e.prototype.createLink=function(e){var t=this.links[e];return t||(t=this.createSymbol(e),this.links[e]=t),t},e.prototype.createDef=function(e,t){var n=this.defs[e];return n||(n=this.createSymbol(e),this.defs[e]=n),n&&void 0!=t&&(n.value=t),n},e.prototype.createUpdate=function(e){var t=this.updates[e];return t||(t=this.createLink(e),this.updates[e]=t),t},e.prototype.findDef=function(e){function n(e,t){var n=a(e,t);return i[e]=n,o[e]=n,n}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 n(e,Xt.PI);if("e"==e)return n(e,Xt.E);if("i"==e)return n(e,new t(0,1));var s=Xt[e];if(s)return n(e,s);if(x.isUnit(e)){var f=new x(null,e);return n(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,t=this.parentScope;for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];r.value=t?t.findDef(n):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 t=this.nestedScopes,n=0,r=t.length;r>n;n++)if(t[n].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,t=[];for(var n in e)if(e.hasOwnProperty(n)){var r=e[n];void 0==r.value&&t.push(r)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){t=t.concat(e.getUndefinedSymbols())}),t}}(),function(){function e(){B++,k=P.charAt(B)}function n(){B=0,k=P.charAt(0)}function r(){for(V=C.NULL,j="";" "==k||" "==k;)e();if("#"==k)for(;"\n"!=k&&""!=k;)e();if(""==k)return V=C.DELIMITER,void 0;if("-"==k||","==k||"("==k||")"==k||"["==k||"]"==k||'"'==k||"\n"==k||";"==k||":"==k)return V=C.DELIMITER,j+=k,e(),void 0;if(a(k))for(V=C.DELIMITER;a(k);)j+=k,e();else if(o(k)){for(V=C.NUMBER;o(k);)j+=k,e();if("E"==k||"e"==k)for(j+=k,e(),("+"==k||"-"==k)&&(j+=k,e()),s(k)||(V=C.UNKNOWN);s(k);)j+=k,e()}else{if(!i(k)){for(V=C.UNKNOWN;""!=k;)j+=k,e();throw L('Syntax error in part "'+j+'"')}for(V=C.SYMBOL;i(k)||s(k);)j+=k,e()}}function a(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==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){n(),r();var t;if(t=""==j?new Vt(void 0):c(e),""!=j)throw V==C.DELIMITER?_("Unknown operator "+j):L('Unexpected part "'+j+'"');return t}function u(e){var t=l(e);if(!(t instanceof Ht)){var n="ans",r=void 0,a=e.createDef(n);return new Ht(n,r,t,a)}return t}function c(e){var t,n,a;for("\n"!=j&&";"!=j&&""!=j&&(t=u(e));"\n"==j||";"==j;)n||(n=new Ft,t&&(a=";"!=j,n.add(t,a))),r(),"\n"!=j&&";"!=j&&""!=j&&(t=u(e),a=";"!=j,n.add(t,a));return n?n:(t||(t=u(e)),t)}function l(e){if(V==C.SYMBOL&&"function"==j){if(r(),V!=C.SYMBOL)throw L("Function name expected");var t=j;if(r(),"("!=j)throw L("Opening parenthesis ( expected");for(var n=e.createNestedScope(),a=[],i=[];;){if(r(),V!=C.SYMBOL)throw L("Variable name expected");var o=j,s=n.createDef(o);if(a.push(o),i.push(s),r(),","!=j){if(")"==j)break;throw L('Comma , or closing parenthesis ) expected"')}}if(r(),"="!=j)throw L("Equal sign = expected");r();var f=m(n),u=e.createDef(t);return new Wt(t,a,i,f,u)}return h(e)}function h(e){var t=!1;V==C.SYMBOL&&(t=e.hasLink(j));var n=m(e);if("="==j){if(!(n instanceof jt))throw L("Symbol expected at the left hand side of assignment operator =");var a=n.name,i=n.params;t||e.removeLink(a),r();var o=m(e),s=n.hasParams()?e.createUpdate(a):e.createDef(a);return new Ht(a,i,o,s)}return n}function m(e){var t=p(e);if(":"==j){for(var n=[t];":"==j;)r(),n.push(p(e));if(n.length>3)throw new TypeError("Invalid range");var a="range",i=at;t=new jt(a,i,n)}return t}function p(e){for(var t=v(e),n={"in":"in"};void 0!==n[j];){var a=j,i=Xt[n[a]];r();var o=[t,v(e)];t=new jt(a,i,o)}return t}function v(e){var t=d(e);return t}function d(e){for(var t=g(e),n={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==n[j];){var a=j,i=Xt[n[a]];r();var o=[t,g(e)];t=new jt(a,i,o)}return t}function g(e){for(var t=y(e),n={"+":"add","-":"subtract"};void 0!==n[j];){var a=j,i=Xt[n[a]];r();var o=[t,y(e)];t=new jt(a,i,o)}return t}function y(e){for(var t=w(e),n={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==n[j];){var a=j,i=Xt[n[a]];r();var o=[t,w(e)];t=new jt(a,i,o)}return t}function w(e){if("-"==j){var t=j,n=Z;r();var a=[E(e)];return new jt(t,n,a)}return E(e)}function E(e){for(var t=[N(e)];"^"==j;)r(),t.push(N(e));for(var n=t.pop();t.length;){var a=t.pop(),i="^",o=G,s=[a,n];n=new jt(i,o,s)}return n}function N(e){for(var t=b(e);"!"==j;){var n=j,a=yt;r();var i=[t];t=new jt(n,a,i)}return t}function b(e){return O(e)}function O(e){if(V==C.SYMBOL){var t=j;r();var n=e.createLink(t),a=M(e),i=new jt(t,n,a);return i}return A(e)}function M(e){var t=[];if("("==j){if(r(),")"!=j)for(t.push(m(e));","==j;)r(),t.push(m(e));if(")"!=j)throw L("Parenthesis ) missing");r()}return t}function A(t){if('"'==j){for(var n="",a="";""!=k&&('"'!=k||"\\"==a);)n+=k,a=k,e();if(r(),'"'!=j)throw L('End of string " missing');r();var i=new Vt(n);return i}return S(t)}function S(e){if("["==j){var t;for(r();"\n"==j;)r();if("]"!=j){var n=[],a=0,i=0;for(n[0]=[m(e)];","==j||";"==j;){for(","==j?i++:(a++,i=0,n[a]=[]),r();"\n"==j;)r();for(n[a][i]=m(e);"\n"==j;)r()}var o=n.length,s=n.length>0?n[0].length:0;for(a=1;o>a;a++)if(n[a].length!=s)throw _("Number of columns must match ("+n[a].length+" != "+s+")");if("]"!=j)throw L("End of matrix ] missing");r(),t=new Dt(n)}else r(),t=new Dt([]);return t}return T(e)}function T(e){if(V==C.NUMBER){var n;n="."==j?0:Number(j),r();var a;if(V==C.SYMBOL){if("i"==j||"I"==j)return a=new t(0,n),r(),new Vt(a);if(x.isUnit(j))return a=new x(n,j),r(),new Vt(a);throw R('Unknown unit "'+j+'"')}var i=new Vt(n);return i}return q(e)}function q(e){if("("==j){r();var t=m(e);if(")"!=j)throw L("Parenthesis ) expected");return r(),t}return z(e)}function z(){throw""==j?L("Unexpected end of expression"):L("Value expected")}function U(e){var t=t(),n=n();return void 0===t?void 0===n?e:e+" (col "+n+")":e+" (ln "+t+", col "+n+")"}function L(e){return new SyntaxError(U(e))}function R(e){return new TypeError(U(e))}function _(e){return Error(U(e))}Xt.expr.Parser=function I(){if(this.constructor!=I)throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new Xt.expr.Scope},Xt.expr.Parser.prototype.parse=function(e,t){return P=e||"",t||(this._newScope(),t=this.scope),f(t)},Xt.expr.Parser.prototype.eval=function(e){var t=this.parse(e);return t.eval()},Xt.expr.Parser.prototype.get=function(e){this._newScope();var t=this.scope.findDef(e);return t?t.value:void 0},Xt.expr.Parser.prototype.set=function(e,t){this.scope.createDef(e,t)},Xt.expr.Parser.prototype._newScope=function(){this.scope=new Xt.expr.Scope(this.scope)},Xt.expr.Parser.prototype.clear=function(){this.scope.clear()};var C={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},P="",B=0,k="",j="",V=C.NULL}(),function(){function e(){this.idMax=-1,this.updateSeq=0,this.parser=new Xt.expr.Parser,this.scope=new Xt.expr.Scope,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}Xt.expr.Workspace=e,e.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},e.prototype.append=function(t){var n=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,a=new Xt.expr.Scope(r),i=new e.Node({id:n,expression:t,parser:this.parser,scope:a,nextNode:void 0,previousNode:this.lastNode});return this.nodes[n]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([n]),n},e.prototype.insertBefore=function(t,n){var r=this.nodes[n];if(!r)throw'Node with id "'+n+'" not found';var a=r.previousNode,i=this._getNewId(),o=a?a.scope:this.scope,s=new Xt.expr.Scope(o),f=new e.Node({id:i,expression:t,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,t){var n=this.nodes[t];if(!n)throw'Node with id "'+t+'" not found';return n==this.lastNode?this.append(e):this.insertBefore(t+1,e)},e.prototype.remove=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';var n=this.getDependencies(e),r=t.previousNode,a=t.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(n)},e.prototype.replace=function(t,n){var r=this.nodes[n];if(!r)throw'Node with id "'+n+'" not found';var a=[n];e._merge(a,this.getDependencies(n));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(t),e._merge(a,this.getDependencies(n)),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 t="Error: "+((e.message||e)+"");this.fn=new Vt(t)}},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,t){for(var n=0,r=t.length;r>n;n++){var a=t[n];-1==e.indexOf(a)&&e.push(a)}},e.prototype.getDependencies=function(t){var n,r=[],a=this.nodes[t];if(a){var i=a.scope.defs,o=a.scope.updates,s=[];for(n in i)i.hasOwnProperty(n)&&s.push(n);for(n in o)o.hasOwnProperty(n)&&-1==s.indexOf(n)&&s.push(n);for(var f=a.nextNode;f&&s.length;){for(var u=f.scope,c=0;s.length>c;){if(n=s[c],(u.hasLink(n)||u.hasUpdate(n))&&-1==r.indexOf(f.id)){r.push(f.id);var l=this.getDependencies(f.id);e._merge(r,l)}u.hasDef(n)&&(s.splice(c,1),c--),c++}f=f.nextNode}}return r},e.prototype.getExpr=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getExpr()},e.prototype.getResult=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getResult()},e.prototype._update=function(e){this.updateSeq++;for(var t=this.updateSeq,n=this.nodes,r=0,a=e.length;a>r;r++){var i=e[r],o=n[i];o&&(o.eval(),o.updateSeq=t)}},e.prototype.getChanges=function(e){var t=[],n=this.firstNode;for(e=e||0;n;)n.updateSeq>e&&t.push(n.id),n=n.nextNode;return{ids:t,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=[],t=this.firstNode;t;){var n={id:t.id,expression:t.expression,dependencies:this.getDependencies(t.id)};try{n.result=t.getResult()}catch(r){n.result="Error: "+((r.message||r)+"")}e.push(n),t=t.nextNode}return e}}()})(); \ No newline at end of file diff --git a/src/function/matrix/squeeze.js b/src/function/matrix/squeeze.js index 4dc3624e4..e9831c447 100644 --- a/src/function/matrix/squeeze.js +++ b/src/function/matrix/squeeze.js @@ -62,6 +62,6 @@ squeeze.doc = { 'size(squeeze(b))' ], 'seealso': [ - 'det', 'diag', 'eye', 'ones', 'range', 'transpose', 'zeros' + 'det', 'diag', 'eye', 'ones', 'range', 'size', 'transpose', 'zeros' ] }; \ No newline at end of file diff --git a/src/function/matrix/transpose.js b/src/function/matrix/transpose.js new file mode 100644 index 000000000..58b76d0f6 --- /dev/null +++ b/src/function/matrix/transpose.js @@ -0,0 +1,71 @@ +/** + * @constructor transpose + * Calculate the determinant of a matrix, transpose(x) + * @param {Array | Matrix} x + * @return {Array | Matrix} transpose + */ +function transpose (x) { + if (arguments.length != 1) { + throw newArgumentsError('transpose', arguments.length, 1); + } + + var size = math.size(x); + switch (size.length) { + case 0: + // scalar + return math.clone(x); + break; + + case 1: + // vector + // TODO: is it logic to return a 1 dimensional vector itself as transpose? + return math.clone(x); + break; + + case 2: + // two dimensional array + var rows = size[1], // index 1 is no error + cols = size[0], // index 0 is no error + array = x.valueOf(), + transposed = [], + transposedRow, + clone = math.clone; + for (var r = 0; r < rows; r++) { + transposedRow = transposed[r] = []; + for (var c = 0; c < cols; c++) { + transposedRow[c] = clone(array[c][r]); + } + } + if (cols == 0) { + transposed[0] = []; + } + return transposed; + break; + + default: + // multi dimensional array + throw new RangeError('Matrix must be two dimensional ' + + '(size: ' + math.format(size) + ')'); + } +} + +math.transpose = transpose; + +/** + * Function documentation + */ +transpose.doc = { + 'name': this.name, + 'category': 'Numerics', + 'syntax': [ + 'transpose(x)' + ], + 'description': 'Transpose a matrix', + 'examples': [ + 'a = [1, 2, 3; 4, 5, 6]', + 'transpose(a)' + ], + 'seealso': [ + 'det', 'diag', 'eye', 'ones', 'range', 'size', 'squeeze', 'transpose', 'zeros' + ] +}; \ No newline at end of file diff --git a/test/function/numerics.js b/test/function/numerics.js index c9ca79412..b4bb07552 100644 --- a/test/function/numerics.js +++ b/test/function/numerics.js @@ -30,6 +30,7 @@ assert.deepEqual(math.diag([[1,2,3],[4,5,6]],1).valueOf(), [2,6]); assert.deepEqual(math.diag([[1,2,3],[4,5,6]],-1).valueOf(), [4]); assert.deepEqual(math.diag([[1,2,3],[4,5,6]],-2).valueOf(), []); assert.deepEqual(math.diag(math.range(1,3)).valueOf(), [[1,0,0],[0,2,0],[0,0,3]]); +assert.throws(function () {math.diag([[[1],[2]],[[3],[4]]])}); // TODO: test diag for all types of input (also scalar) // test eye @@ -91,6 +92,15 @@ assert.deepEqual(math.size(math.squeeze(m)).valueOf(), [3]); assert.deepEqual(math.squeeze(2.3), 2.3); assert.deepEqual(math.size(math.squeeze(math.range(1,5))), [5]); +// test transpose +assert.deepEqual(math.transpose(3), 3); +assert.deepEqual(math.transpose([1,2,3]), [1,2,3]); +assert.deepEqual(math.transpose([[1,2,3],[4,5,6]]), [[1,4],[2,5],[3,6]]); +assert.deepEqual(math.transpose([[1,2],[3,4]]), [[1,3],[2,4]]); +assert.deepEqual(math.transpose([[1,2,3,4]]), [[1],[2],[3],[4]]); +assert.deepEqual(math.transpose([[]]), [[]]); +assert.throws(function () {math.transpose([[[1],[2]],[[3],[4]]])}); + // test zeros assert.deepEqual(math.zeros().valueOf(), [[0]]); assert.deepEqual(math.zeros([]).valueOf(), [[0]]);