diff --git a/math.js b/math.js index 97a417f3e..81dff3152 100644 --- a/math.js +++ b/math.js @@ -439,8 +439,102 @@ var util = (function () { } }; - // Internet Explorer 8 and older does not support Array.indexOf, so we define - // it here in that case. + /** + * Recursively resize a multi dimensional array + * @param {Array} array Array to be resized + * @param {Number[]} size Array with the size of each dimension + * @param {Number} dim Current dimension + * @param {*} [defaultValue] Value to be filled in in new entries, + * 0 by default. + * @private + */ + function _resize (array, size, dim, defaultValue) { + if (!(array instanceof Array)) { + throw new TypeError('Array expected'); + } + + var len = array.length, + newLen = size[dim]; + + if (len != newLen) { + if(newLen > array.length) { + // enlarge + for (var i = array.length; i < newLen; i++) { + array[i] = defaultValue ? clone(defaultValue) : 0; + } + } + else { + // shrink + array.length = size[dim]; + } + len = array.length; + } + + if (dim < size.length - 1) { + // recursively validate each child array + var dimNext = dim + 1; + for (i = 0; i < len; i++) { + child = array[i]; + if (!(child instanceof Array)) { + child = [child]; + array[i] = child; + } + _resize(child, size, dimNext, defaultValue); + } + } + else { + // last dimension + for (i = 0; i < len; i++) { + var child = array[i]; + while (child instanceof Array) { + child = child[0]; + } + array[i] = child; + } + } + } + + /** + * Resize a multi dimensional array + * @param {Array} array Array to be resized + * @param {Number[]} size Array with the size of each dimension + * @param {*} [defaultValue] Value to be filled in in new entries, + * 0 by default + */ + util.resize = function resize(array, size, defaultValue) { + // TODO: what to do with scalars, when size=[] ? + + // check the type of size + if (!(size instanceof Array)) { + throw new TypeError('Size must be an array (size is ' + type(size) + ')'); + } + + // check whether size contains positive integers + size.forEach(function (value) { + if (!isNumber(value) || !isInteger(value) || value < 0) { + throw new TypeError('Invalid size, must contain positive integers ' + + '(size: ' + formatArray(size) + ')'); + } + }); + + var hasZeros = (size.indexOf(0) != -1); + if (hasZeros) { + // array where all dimensions are zero + size.forEach(function (value) { + if (value != 0) { + throw new RangeError('Invalid size, all dimensions must be ' + + 'either zero or non-zero (size: ' + formatArray(size) + ')'); + } + }); + } + + // recursively resize + _resize(array, size, 0, defaultValue); + }; + + + // Internet Explorer 8 and older does not support Array.indexOf, + // so we define it here in that case. // http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/ if(!Array.prototype.indexOf) { Array.prototype.indexOf = function(obj){ @@ -453,8 +547,8 @@ var util = (function () { }; } - // Internet Explorer 8 and older does not support Array.forEach, so we define - // it here in that case. + // Internet Explorer 8 and older does not support Array.forEach, + // so we define it here in that case. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach if (!Array.prototype.forEach) { Array.prototype.forEach = function(fn, scope) { @@ -464,8 +558,8 @@ var util = (function () { } } - // Internet Explorer 8 and older does not support Array.map, so we define it - // here in that case. + // Internet Explorer 8 and older does not support Array.map, + // so we define it here in that case. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map // Production steps of ECMA-262, Edition 5, 15.4.4.19 // Reference: http://es5.github.com/#x15.4.4.19 @@ -541,6 +635,34 @@ var util = (function () { }; } + // Internet Explorer 8 and older does not support Array.every, + // so we define it here in that case. + // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/every + if (!Array.prototype.every) { + Array.prototype.every = function(fun /*, thisp */) { + "use strict"; + + if (this == null) { + throw new TypeError(); + } + + var t = Object(this); + var len = t.length >>> 0; + if (typeof fun != "function") { + throw new TypeError(); + } + + var thisp = arguments[1]; + for (var i = 0; i < len; i++) { + if (i in t && !fun.call(thisp, t[i], i, t)) { + return false; + } + } + + return true; + }; + } + return util; })(); @@ -912,7 +1034,20 @@ Complex.doc = { /** * @constructor Matrix * - * TODO: document Matrix + * A Matrix is a wrapper around an Array. A matrix can hold a multi dimensional + * array. A matrix can be constructed as: + * var matrix = new Matrix(data) + * + * Matrix contains the functions to resize, get and set values, get the size, + * clone the matrix and to convert the matrix to a vector, array, or scalar. + * The internal Array of the Matrix can be accessed using the method valueOf. + * + * Example usage: + * var matrix = new Matrix([[1, 2], [3, 4]); + * matix.size(); // [2, 2] + * matrix.resize([3, 2], 5); + * matrix.valueOf(); // [[1, 2], [3, 4], [5, 5]] + * matrix.get([1, 0]) // 3 * * @param {Array | Matrix | Vector | Range} [data] A multi dimensional array */ @@ -926,9 +1061,17 @@ function Matrix(data) { // clone data from Vector, Matrix, or Range this._data = data.toArray(); } + else if (data instanceof Array) { + // use array as is + this._data = data; + } + else if (data != null) { + // a scalar provided + this._data = [data]; + } else { - // use data as is - this._data = data || null; + // nothing provided + this._data = []; } // verify the size of the array @@ -937,9 +1080,148 @@ function Matrix(data) { math.Matrix = Matrix; -// TODO: implement method get +/** + * Get a value or a set of values from the matrix. + * Indexes are zero-based. + * @param {Array | Vector | Matrix} index + */ +Matrix.prototype.get = function (index) { + // TODO: support getting a range of values + + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); + } + index = index.toVector(); + } + if (index instanceof Vector) { + index = index.valueOf(); + } + + if (index instanceof Array) { + if (index.length != this._size.length) { + throw new RangeError('Number of dimensions do not match ' + + '(' + index.length + ' != ' + this._size.length + ')'); + } + + var value = this._data; + index.forEach(function (i) { + if (!isNumber(i) || !isInteger(i) || i < 0) { + throw new TypeError('Positive integer expected as index in method get'); + } + if (i > value.length - 1) { + throw new RangeError('Index out of range (' + i + ')'); + } + value = value[i]; + }); + return value; + } + else { + // TODO: support a single number as index in case the matrix is a vector + throw new TypeError('Unsupported type of index ' + type(index)); + } +}; + // TODO: implement method set -// TODO: implement method resize + +/** + * Get a value or a set of values from the matrix. + * Indexes are zero-based. + * @param {Array | Vector | Matrix} index + * @param {*} value + */ +Matrix.prototype.set = function (index, value) { + // TODO: support setting a range of values + + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); + } + index = index.toVector(); + } + if (index instanceof Vector) { + index = index.valueOf(); + } + if (value instanceof Matrix || value instanceof Vector || value instanceof Range) { + value = value.valueOf(); + } + + if (index instanceof Array) { + if (value instanceof Array) { + throw new Error('Setting a range of values is not yet implemented...'); + } + else { + if (index.length != this._size.length) { + throw new RangeError('Number of dimensions do not match ' + + '(' + index.length + ' != ' + this._size.length + ')'); + } + + var size = this._size.concat([]); + var needResize = false; + for (var i = 0; i < size.length; i++) { + var index_i = index[i]; + if (!isNumber(index_i) || !isInteger(index_i) || index_i < 0) { + throw new TypeError('Positive integer expected as index in method get'); + } + if (index[i] > size[i]) { + size[i] = index_i; + needResize = true; + } + } + if (needResize) { + this.resize(size); + } + + var len = size.length; + var arr = this._data; + index.forEach(function (v, i) { + if (i < len - 1) { + arr = arr[v]; + } + else { + arr[v] = value; + } + }); + } + + /* TODO: cleanup + if (index.length != this._size.length) { + throw new RangeError('Number of dimensions do not match ' + + '(' + index.length + ' != ' + this._size.length + ')'); + } + + var value = this._data; + index.forEach(function (i) { + if (!isNumber(i) || !isInteger(i) || i < 0) { + throw new TypeError('Positive integer expected as index in method get'); + } + if (i > value.length - 1) { + throw new RangeError('Index out of range (' + i + ')'); + } + value = value[i]; + }); + return value; + */ + } + else { + // TODO: support a single number as index in case the matrix is a vector + throw new TypeError('Unsupported type of index ' + type(index)); + } +}; + +/** + * Resize the matrix + * @param {Number[]} size + * @param {*} [defaultValue] Default value, filled in on new entries. + * If not provided, the vector will be filled + * with zeros. + */ +Matrix.prototype.resize = function (size, defaultValue) { + util.resize(this._data, size, defaultValue); + this._size = clone(size); +}; /** * Create a clone of the matrix @@ -951,7 +1233,6 @@ Matrix.prototype.clone = function () { return matrix; }; - /** * Retrieve the size of the matrix. * The size of the matrix will be validated too @@ -969,7 +1250,7 @@ Matrix.prototype.size = function () { Matrix.prototype.toScalar = function () { var scalar = this._data; while (scalar instanceof Array && scalar.length == 1) { - scalar = value[0]; + scalar = scalar[0]; } if (scalar instanceof Array) { @@ -985,11 +1266,9 @@ Matrix.prototype.toScalar = function () { * @return {boolean} isScalar */ Matrix.prototype.isScalar = function () { - var scalar = this._data; - while (scalar instanceof Array && scalar.length == 1) { - scalar = scalar[0]; - } - return !(scalar instanceof Array); + return this._size.every(function (s) { + return (s <= 1); + }); }; /** @@ -997,26 +1276,37 @@ Matrix.prototype.isScalar = function () { * A matrix is a vector when it has 0 or 1 dimensions, or has multiple * dimensions where maximum one of the dimensions has a size larger than 1. * Returns null if the Matrix is no vector - * return {Vector} vector + * return {Vector | null} vector */ Matrix.prototype.toVector = function () { - /* TODO: implement toVector var count = 0; var dim = undefined; - var s = util.size(this._data); - s.forEach(function (length, index) { + var index = []; + this._size.forEach(function (length, i) { if (length > 1) { count++; - dim = index; + dim = i; } + index[i] = 0; }); - if (count > 1) { + + if (count == 0) { + // scalar or empty + return new Vector(this.toScalar()); + } + else if (count == 1) { + // valid vector + var vector = []; + for (var i = 0, iMax = this._size[dim]; i < iMax; i++) { + index[dim] = i; + vector[i] = this.get(index); + } + return new Vector(vector); + } + else { + // count > 1, this is no vector return null; } - - /// TODO: clone the values - */ - throw new Error('not yet implemented'); }; /** @@ -1027,8 +1317,7 @@ Matrix.prototype.toVector = function () { */ Matrix.prototype.isVector = function () { var count = 0; - var s = util.size(this._data); - s.forEach(function (length) { + this._size.forEach(function (length) { if (length > 1) { count++; } @@ -1042,11 +1331,7 @@ Matrix.prototype.isVector = function () { * @returns {Array} array */ Matrix.prototype.toArray = function () { - var array = clone(this._data); - if (!(array instanceof Array)) { - array = [array]; - } - return array; + return clone(this._data); }; /** @@ -1959,26 +2244,16 @@ Unit.UNITS = [ * array. A vector can be constructed as: * var vector = new Vector(data) * - * Vector contains the following functions: - * resize(size, defaultValue) - * get(index) - * get(indexes) - * set(index, value) - * set(indexes, values) - * size() - * clone() - * isScalar() - * toScalar() - * isArray() - * toArray() // create an Array with the vector data cloned - * valueOf() // get the internal data Array of the vector + * Vector contains the functions to resize, get and set values, get the size, + * clone the vector and to convert the vector to an array or scalar. + * The internal Array of the Vector can be accessed using the method valueOf. * * Example usage: - * var vector = new Vector([4, 5, 6, 7]) + * var vector = new Vector([4, 5, 6, 7]); * vector.resize(6, -1); * vector.set(2, 9); * vector.valueOf(); // [4, 5, 9, 7, -1, -1] - * vector.get([3,4 ]) // [7, -1] + * vector.get([3, 4]) // [7, -1] * * @param {Array | Matrix | Vector | Range} [data] A one dimensional array */ @@ -1996,9 +2271,17 @@ function Vector(data) { // clone data from Vector or Range this._data = data.toArray(); } + else if (data instanceof Array) { + // use array as is + this._data = data; + } + else if (data != null) { + // a scalar provided + this._data = [data]; + } else { - // use data as is - this._data = data || null; + // nothing provided + this._data = []; } // verify whether the data is a one dimensional array @@ -2033,25 +2316,18 @@ Vector.prototype.resize = function (size, defaultValue) { throw new TypeError('Positive integer expected as size in method resize'); } - if (!(this._data instanceof Array) && size > 1) { - // vector currently contains a scalar. change that to an array - this._data = [this._data]; - this.resize(size, defaultValue); + if(size > this._data.length) { + // enlarge + for (var i = this._data.length; i < size; i++) { + this._data[i] = defaultValue ? clone(defaultValue) : 0; + } } else { - if(size > this._data.length) { - // enlarge - for (var i = this._data.length; i < size; i++) { - this._data[i] = defaultValue ? clone(defaultValue) : 0; - } - } - else { - // shrink - this._data.length = size; - } - - this._size = [this._data.length]; + // shrink + this._data.length = size; } + + this._size = [this._data.length]; } }; @@ -2059,13 +2335,24 @@ Vector.prototype.resize = function (size, defaultValue) { * get a value or a subset of the vector. Throws an RangeError when index is * out of range. * Indexes are zero-based. - * @param {Number | Number[] | Range} index - * @return {* | *[]} value + * @param {Number | Array | Matrix | Vector | Range} index + * @return {* | Array | Matrix | Vector | Range} value */ Vector.prototype.get = function (index) { var me = this; index = index.valueOf(); + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); + } + index = index.toVector(); + } + if (index instanceof Vector) { + index = index.valueOf(); + } + if (index instanceof Range || index instanceof Array) { return index.map(function (i) { return me.get(i); @@ -2075,58 +2362,61 @@ Vector.prototype.get = function (index) { if (!isNumber(index) || !isInteger(index) || index < 0) { throw new TypeError('Positive integer expected as index in method get'); } - if (this._data instanceof Array) { - return this._data[index]; - } - else if (index == 0) { - return this._data; - } - else { + if (index > this._data.length - 1) { throw new RangeError('Index out of range (' + index + ')'); } + return this._data[index]; } }; /** - * Set a value or a set of value in the vector. + * Set a value or a set of values in the vector. * Indexes are zero-based. - * @param {Number | Number[]} index - * @param {* | *[]} value + * @param {Number | Array | Matrix | Vector | Range} index + * @param {* | Array | Matrix | Vector | Range} value */ Vector.prototype.set = function (index, value) { var me = this; - index = index.valueOf(); - if (index instanceof Range) { - if (index.size() != value.length) { - throw new RangeError('Dimension mismatch (' + index.size() + ' != ' + - value.length + ')'); + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); } - - index.forEach(function (v, i) { - me._set(v, value[i]); - }); + index = index.toVector(); } - else if (index instanceof Array) { + if (index instanceof Vector) { + index = index.valueOf(); + } + if (value instanceof Matrix || value instanceof Vector || value instanceof Range) { + value = value.valueOf(); + } + + if (index instanceof Range || index instanceof Array) { if (value instanceof Array) { - if (index.length != value.length) { - throw new RangeError('Dimension mismatch (' + index.length+ ' != ' + - value.length + ')'); + if (size(index) != value.length) { + throw new RangeError('Dimension mismatch ' + + '(' + size(index) + ' != ' + value.length + ')'); } index.forEach(function (v, i) { - me._set(v, value[i]); + me._set(v, value[i]); }); } else { - this.set(index, [value]); + index.forEach(function (v) { + me._set(v, value); + }); } } else { + // index is a scalar if (value instanceof Array) { + // try as two arrays this.set([index], value); } else { + // set single value this._set(index, value); } } @@ -2139,9 +2429,6 @@ Vector.prototype.set = function (index, value) { * @private */ Vector.prototype._set = function (index, value) { - if (!(this._data instanceof Array)) { - this._data = [this._data]; - } if (index > this._data.length) { this.resize(index); } @@ -2173,16 +2460,11 @@ Vector.prototype.size = function () { * @return {* | null} scalar */ Vector.prototype.toScalar = function () { - var value = this._data; - while (value instanceof Array && value.length == 1) { - value = value[0]; - } - - if (value instanceof Array) { - return null; + if (this._data.length == 1) { + return this._data[0]; } else { - return value; + return null; } }; @@ -2191,11 +2473,7 @@ Vector.prototype.toScalar = function () { * @return {boolean} isScalar */ Vector.prototype.isScalar = function () { - var value = this._data; - while (value instanceof Array && value.length == 1) { - value = value[0]; - } - return !(value instanceof Array); + return (this._data.length <= 1); }; /** @@ -2204,11 +2482,7 @@ Vector.prototype.isScalar = function () { * @returns {Array} array */ Vector.prototype.toArray = function () { - var array = clone(this._data); - if (!(array instanceof Array)) { - array = [array]; - } - return array; + return clone(this._data); }; /** @@ -4556,49 +4830,6 @@ eye.doc = { 'diag', 'ones', 'range', 'size', 'transpose', 'zeros' ] }; -/** - * Create a range. range(start[, step], end) or start:end - * @param {Number} start - * @param {Number} [step] - * @param {Number} end - * @return {Number[]} range - */ -function range (start, step, end) { - if (arguments.length != 1 && arguments.length != 2) { - throw newArgumentsError('range', arguments.length, 1); - } - - var r = new Range(start, end, step); - return r.toArray(); -} - -math.range = range; - -/** - * Function documentation - */ -range.doc = { - 'name': 'range', - 'category': 'Matrix', - 'syntax': [ - 'start : end', - 'start : step : end', - 'range(start, end)', - 'range(start, step, end)' - ], - 'description': 'Create a range.', - 'examples': [ - '1:10', - '0:10:100', - '0:0.2:1', - 'range(20, -1, 10)', - 'matrix = [1, 2, 3; 4, 5, 6; 7, 8, 9]', - 'matrix(2:3, 1:2)' - ], - 'seealso': [ - 'diag', 'eye', 'ones', 'size', 'transpose', 'zeros' - ] -}; /** * Calculate the size of a vector, matrix, or scalar. size(x) * @param {Number | Complex | Array} x @@ -5615,11 +5846,16 @@ function clone(x) { throw newArgumentsError('clone', arguments.length, 1); } + if (x == null) { + // null or undefined + return x; + } + if (typeof(x.clone) === 'function') { return x.clone(); } - if (isNumber(x) || isString(x) || x === null) { + if (isNumber(x) || isString(x)) { return x; } diff --git a/math.min.js b/math.min.js index 0caeae5fa..6fcc62d4c 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(t,n){if(this.constructor!=e)throw new SyntaxError("Complex constructor must be called with the new operator");switch(arguments.length){case 2:if(!r(t)||!r(n))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=t,this.im=n;break;case 1:if(!a(t))throw new TypeError("Two numbers or a single string expected in Complex constructor");var i=e.parse(t);if(i)return i;throw new SyntaxError('String "'+t+'" is no valid complex number');case 0:this.re=0,this.im=0;break;default:throw new SyntaxError("Wrong number of arguments in Complex constructor ("+arguments.length+" provided, 0, 1, or 2 expected)")}}function t(e){if(this.constructor!=t)throw new SyntaxError("Matrix constructor must be called with the new operator");this._data=e instanceof t||e instanceof o||e instanceof i?e.toArray():e||null,this._size=Mt.size(this._data)}function r(e){return e instanceof Number||"number"==typeof e}function n(e){return e==Math.round(e)}function i(e,t,n){if(this.constructor!=i)throw new SyntaxError("Range constructor must be called with the new operator");if(null==n&&(n=t,t=null),2!=arguments.length&&3!=arguments.length)throw new TypeError("Wrong number of parameters in Range constructor (2 or 3 expected, "+arguments.length+" provided)");if(null!=e&&!r(e))throw new TypeError("Parameter start must be a number");if(null!=n&&!r(n))throw new TypeError("Parameter end must be a number");if(null!=t&&!r(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 a(e){return e instanceof String||"string"==typeof e}function s(e,t){if(this.constructor!=s)throw Error("Unit constructor must be called with the new operator");this.value=1,this.unit=s.UNIT_NONE,this.prefix=s.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1;var r=arguments.length;if(0==r);else{if(1==r){if(!a(e))throw new TypeError("A string or a number and string expected in Unit constructor");var n=s.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid unit')}if(2!=r)throw Error("Too many parameters in Unit constructor, 1 or 2 expected");if(!a(t))throw Error("Second parameter in Unit constructor must be a String");for(var i=s.UNITS,o=!1,f=0,u=i.length;u>f;f++){var h=i[f];if(s.endsWith(t,h.name)){var c=t.length-h.name.length,l=t.substring(0,c),p=h.prefixes[l];if(void 0!==p){this.unit=h,this.prefix=p,this.hasUnit=!0,o=!0;break}}}if(!o)throw Error('String "'+t+'" is no unit');null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}}function o(e){if(this.constructor!=o)throw new SyntaxError("Vector constructor must be called with the new operator");if(this._data=e instanceof t?e.toVector():e instanceof o||e instanceof i?e.toArray():e||null,this._size=Mt.size(this._data),this._size.length>1)throw Error("Vector can only contain one dimension (size: "+ft(this._size)+")")}function f(e,t){var r=void 0;if(2==arguments.length){var n=pt(t);r="Function "+e+" does not support a parameter of type "+n}else if(arguments.length>2){for(var i=[],a=1;arguments.length>a;a++)i.push(pt(arguments[a]));r="Function "+e+" does not support a parameters of type "+i.join(", ")}else r="Unsupported parameter in function "+e;return new TypeError(r)}function u(e,t,r,n){var i="Wrong number of arguments in function "+e+" ("+t+" provided, "+r+(void 0!=n?"-"+n:"")+" expected)";return new SyntaxError(i)}function h(t){if(1!=arguments.length)throw u("abs",arguments.length,1);if(r(t))return Math.abs(t);if(t instanceof e)return Math.sqrt(t.re*t.re+t.im*t.im);if(t instanceof Array)return Mt.map(t,h);if(t.valueOf()!==t)return h(t.valueOf());throw f("abs",t)}function c(t,n){if(2!=arguments.length)throw u("add",arguments.length,2);if(r(t)){if(r(n))return t+n;if(n instanceof e)return new e(t+n.re,n.im)}else if(t instanceof e){if(r(n))return new e(t.re+n,t.im);if(n instanceof e)return new e(t.re+n.re,t.im+n.im)}else if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Units do not match");if(!t.hasValue)throw Error("Unit on left hand side of operator + has no value");if(!n.hasValue)throw Error("Unit on right hand side of operator + has no value");var i=t.clone();return i.value+=n.value,i.fixPrefix=!1,i}if(a(t)||a(n))return t+n;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,c);if(t.valueOf()!==t)return c(t.valueOf());throw f("add",t,n)}function l(t){if(1!=arguments.length)throw u("ceil",arguments.length,1);if(r(t))return Math.ceil(t);if(t instanceof e)return new e(Math.ceil(t.re),Math.ceil(t.im));if(t instanceof Array)return Mt.map(t,l);if(t.valueOf()!==t)return l(t.valueOf());throw f("ceil",t)}function p(t){if(1!=arguments.length)throw u("cube",arguments.length,1);if(r(t))return t*t*t;if(t instanceof e)return M(M(t,t),t);if(t instanceof Array)return M(M(t,t),t);if(t.valueOf()!==t)return p(t.valueOf());throw f("cube",t)}function m(t,n){if(2!=arguments.length)throw u("divide",arguments.length,2);if(r(t)){if(r(n))return t/n;if(n instanceof e)return v(new e(t,0),n)}if(t instanceof e){if(r(n))return v(t,new e(n,0));if(n instanceof e)return v(t,n)}if(t instanceof s&&r(n)){var i=t.clone();return i.value/=n,i}if(t instanceof Array&&!(n instanceof Array))return Mt.map2(t,n,m);if(t.valueOf()!==t||n.valueOf()!==n)return m(t.valueOf(),n.valueOf());throw f("divide",t,n)}function v(t,r){var n=r.re*r.re+r.im*r.im;return new e((t.re*r.re+t.im*r.im)/n,(t.im*r.re-t.re*r.im)/n)}function d(t,n){if(2!=arguments.length)throw u("equal",arguments.length,2);if(r(t)){if(r(n))return t==n;if(n instanceof e)return t==n.re&&0==n.im}if(t instanceof e){if(r(n))return t.re==n&&0==t.im;if(n instanceof e)return t.re==n.re&&t.im==n.im}if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value==n.value}if(a(t)||a(n))return t==n;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,d);if(t.valueOf()!==t||n.valueOf()!==n)return d(t.valueOf(),n.valueOf());throw f("equal",t,n)}function g(t){if(1!=arguments.length)throw u("exp",arguments.length,1);if(r(t))return Math.exp(t);if(t instanceof e){var n=Math.exp(t.re);return new e(n*Math.cos(t.im),n*Math.sin(t.im))}if(t instanceof Array)return Mt.map(t,g);if(t.valueOf()!==t)return g(t.valueOf());throw f("exp",t)}function y(t){if(1!=arguments.length)throw u("fix",arguments.length,1);if(r(t))return value>0?Math.floor(t):Math.ceil(t);if(t instanceof e)return new e(t.re>0?Math.floor(t.re):Math.ceil(t.re),t.im>0?Math.floor(t.im):Math.ceil(t.im));if(t instanceof Array)return Mt.map(t,y);if(t.valueOf()!==t)return y(t.valueOf());throw f("fix",t)}function x(t){if(1!=arguments.length)throw u("floor",arguments.length,1);if(r(t))return Math.floor(t);if(t instanceof e)return new e(Math.floor(t.re),Math.floor(t.im));if(t instanceof Array)return Mt.map(t,x);if(t.valueOf()!==t)return x(t.valueOf());throw f("floor",t)}function w(t,n){if(2!=arguments.length)throw u("larger",arguments.length,2);if(r(t)){if(r(n))return t>n;if(n instanceof e)return t>h(n)}if(t instanceof e){if(r(n))return h(t)>n;if(n instanceof e)return h(t)>h(n)}if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value>n.value}if(a(t)||a(n))return t>n;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,d);if(t.valueOf()!==t||n.valueOf()!==n)return w(t.valueOf(),n.valueOf());throw f("larger",t,n)}function E(t,n){if(2!=arguments.length)throw u("largereq",arguments.length,2);if(r(t)){if(r(n))return t>=n;if(n instanceof e)return t>=h(n)}if(t instanceof e){if(r(n))return h(t)>=n;if(n instanceof e)return h(t)>=h(n)}if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value>=n.value}if(a(t)||a(n))return t>=n;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,E);if(t.valueOf()!==t||n.valueOf()!==n)return E(t.valueOf(),n.valueOf());throw f("largereq",t,n)}function N(t,n){if(1!=arguments.length&&2!=arguments.length)throw u("log",arguments.length,1,2);if(void 0!==n)return m(N(t),N(n));if(r(t))return t>=0?Math.log(t):N(new e(t,0));if(t instanceof e)return new e(Math.log(Math.sqrt(t.re*t.re+t.im*t.im)),Math.atan2(t.im,t.re));if(t instanceof Array)return Mt.map(t,N);if(t.valueOf()!==t||n.valueOf()!==n)return N(t.valueOf(),n.valueOf());throw f("log",t,n)}function O(t){if(1!=arguments.length)throw u("log10",arguments.length,1);if(r(t))return t>=0?Math.log(t)/Math.LN10:O(new e(t,0));if(t instanceof e)return new e(Math.log(Math.sqrt(t.re*t.re+t.im*t.im))/Math.LN10,Math.atan2(t.im,t.re)/Math.LN10);if(t instanceof Array)return Mt.map(t,O);if(t.valueOf()!==t)return O(t.valueOf());throw f("log10",t)}function b(t,n){if(2!=arguments.length)throw u("mod",arguments.length,2);if(r(t)){if(r(n))return t%n;if(n instanceof e&&0==n.im)return t%n.re}else if(t instanceof e&&0==t.im){if(r(n))return t.re%n;if(n instanceof e&&0==n.im)return t.re%n.re}if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,b);if(t.valueOf()!==t||n.valueOf()!==n)return b(t.valueOf(),n.valueOf());throw f("mod",t,n)}function M(t,n){if(2!=arguments.length)throw u("multiply",arguments.length,2);if(r(t)){if(r(n))return t*n;if(n instanceof e)return T(new e(t,0),n);if(n instanceof s)return o=n.clone(),o.value*=t,o}else if(t instanceof e){if(r(n))return T(t,new e(n,0));if(n instanceof e)return T(t,n)}else if(t instanceof s){if(r(n))return o=t.clone(),o.value*=n,o}else if(t instanceof Array){if(n instanceof Array){var i=Mt.size(t),a=Mt.size(n);if(2!=i.length)throw Error("Can only multiply a 2 dimensional matrix (A has "+i.length+" dimensions)");if(2!=a.length)throw Error("Can only multiply a 2 dimensional matrix (B has "+a.length+" dimensions)");if(i[1]!=a[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+i[0]+"x"+i[1]+", B is "+a[0]+"x"+a[1]+", "+a[1]+" != "+a[0]+")");for(var o=[],h=i[0],l=a[1],p=i[1],m=0;h>m;m++){o[m]=[];for(var v=0;l>v;v++){for(var d=null,g=0;p>g;g++){var y=M(t[m][g],n[g][v]);d=null==d?y:c(d,y)}o[m][v]=d}}return o}return Mt.map2(t,n,M)}if(n instanceof Array)return Mt.map2(t,n,M);if(t.valueOf()!==t||n.valueOf()!==n)return M(t.valueOf(),n.valueOf());throw f("multiply",t,n)}function T(t,r){return new e(t.re*r.re-t.im*r.im,t.re*r.im+t.im*r.re)}function A(t,i){if(2!=arguments.length)throw u("pow",arguments.length,2);if(r(t)){if(r(i))return n(i)||t>=0?Math.pow(t,i):S(new e(t,0),new e(i,0));if(i instanceof e)return S(new e(t,0),i)}else if(t instanceof e){if(r(i))return S(t,new e(i,0));if(i instanceof e)return S(t,i)}else if(t instanceof Array){if(!r(i)||!n(i)||0>i)throw new TypeError("For A^b, b must be a positive integer (value is "+i+")");var a=Mt.size(t);if(2!=a.length)throw Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==i)return Y(a[0]);for(var s=t,o=1;i>o;o++)s=M(t,s);return s}if(t.valueOf()!==t||i.valueOf()!==i)return A(t.valueOf(),i.valueOf());throw f("pow",t,i)}function S(e,t){var r=N(e),n=M(r,t);return g(n)}function _(t,n){if(1!=arguments.length&&2!=arguments.length)throw u("round",arguments.length,1,2);if(void 0==n){if(r(t))return Math.round(t);if(t instanceof e)return new e(Math.round(t.re),Math.round(t.im));if(t instanceof Array&&Mt.map(t,_),t.valueOf()!==t)return _(t.valueOf());throw f("round",t)}if(!r(n))throw new TypeError("Number of digits in function round must be an integer");if(n!==Math.round(n))throw new TypeError("Number of digits in function round must be integer");if(0>n||n>9)throw Error("Number of digits in function round must be in te range of 0-9");if(r(t))return k(t,n);if(t instanceof e)return new e(k(t.re,n),k(t.im,n));if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,_);if(t.valueOf()!==t||n.valueOf()!==n)return w(t.valueOf(),n.valueOf());throw f("round",t,n)}function k(e,t){var r=Math.pow(10,void 0!=t?t:bt.options.precision);return Math.round(e*r)/r}function U(t){if(1!=arguments.length)throw u("sign",arguments.length,1);if(r(t)){var n;return n=t>0?1:0>t?-1:0}if(t instanceof e){var i=Math.sqrt(t.re*t.re+t.im*t.im);return new e(t.re/i,t.im/i)}if(t instanceof Array)return Mt.map(t,n);if(t.valueOf()!==t)return n(t.valueOf());throw f("sign",t)}function q(t,n){if(2!=arguments.length)throw u("smaller",arguments.length,2);if(r(t)){if(r(n))return n>t;if(n instanceof e)return h(n)>t}if(t instanceof e){if(r(n))return n>h(t);if(n instanceof e)return h(t)t;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,q);if(t.valueOf()!==t||n.valueOf()!==n)return q(t.valueOf(),n.valueOf());throw f("smaller",t,n)}function L(t,n){if(2!=arguments.length)throw u("smallereq",arguments.length,2);if(r(t)){if(r(n))return n>=t;if(n instanceof e)return h(n)>=t}if(t instanceof e){if(r(n))return n>=h(t);if(n instanceof e)return h(t)<=h(n)}if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value<=n.value}if(a(t)||a(n))return n>=t;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,L);if(t.valueOf()!==t||n.valueOf()!==n)return L(t.valueOf(),n.valueOf());throw f("smallereq",t,n)}function R(t){if(1!=arguments.length)throw u("sqrt",arguments.length,1);if(r(t))return t>=0?Math.sqrt(t):R(new e(t,0));if(t instanceof e){var n=Math.sqrt(t.re*t.re+t.im*t.im);return t.im>=0?new e(.5*Math.sqrt(2*(n+t.re)),.5*Math.sqrt(2*(n-t.re))):new e(.5*Math.sqrt(2*(n+t.re)),-.5*Math.sqrt(2*(n-t.re)))}if(t instanceof Array)return Mt.map(t,R);if(t.valueOf()!==t)return R(t.valueOf());throw f("sqrt",t)}function C(t){if(1!=arguments.length)throw u("square",arguments.length,1);if(r(t))return t*t;if(t instanceof e)return M(t,t);if(t instanceof Array)return M(t,t);if(t.valueOf()!==t)return C(t.valueOf());throw f("square",t)}function I(t,n){if(2!=arguments.length)throw u("subtract",arguments.length,2);if(r(t)){if(r(n))return t-n;if(n instanceof e)return new e(t-n.re,n.im)}else if(t instanceof e){if(r(n))return new e(t.re-n,t.im);if(n instanceof e)return new e(t.re-n.re,t.im-n.im)}else if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Units do not match");if(!t.hasValue)throw Error("Unit on left hand side of operator - has no value");if(!n.hasValue)throw Error("Unit on right hand side of operator - has no value");var i=t.clone();return i.value-=n.value,i.fixPrefix=!1,i}if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,I);if(t.valueOf()!==t||n.valueOf()!==n)return I(t.valueOf(),n.valueOf());throw f("subtract",t,n)}function P(t){if(1!=arguments.length)throw u("unaryminus",arguments.length,1);if(r(t))return-t;if(t instanceof e)return new e(-t.re,-t.im);if(t instanceof s){var n=t.clone();return n.value=-t.value,n}if(t instanceof Array)return Mt.map(t,P);if(t.valueOf()!==t)return P(t.valueOf());throw f("unaryminus",t)}function z(t,n){if(2!=arguments.length)throw u("unequal",arguments.length,2);if(r(t)){if(r(n))return t==n;if(n instanceof e)return t==n.re&&0==n.im}if(t instanceof e){if(r(n))return t.re==n&&0==t.im;if(n instanceof e)return t.re==n.re&&t.im==n.im}if(t instanceof s&&n instanceof s){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value==n.value}if(a(t)||a(n))return t==n;if(t instanceof Array||n instanceof Array)return Mt.map2(t,n,z);if(t.valueOf()!==t||n.valueOf()!==n)return z(t.valueOf(),n.valueOf());throw f("unequal",t,n)}function B(t){if(1!=arguments.length)throw u("arg",arguments.length,1);if(r(t))return Math.atan2(0,t);if(t instanceof e)return Math.atan2(t.im,t.re);if(t instanceof Array)return Mt.map(t,B);if(t.valueOf()!==t)return B(t.valueOf());throw f("arg",t)}function G(t){if(1!=arguments.length)throw u("conj",arguments.length,1);if(r(t))return t;if(t instanceof e)return new e(t.re,-t.im);if(t instanceof Array)return Mt.map(t,G);if(t.valueOf()!==t)return G(t.valueOf());throw f("conj",t)}function D(t){if(1!=arguments.length)throw u("im",arguments.length,1);if(r(t))return 0;if(t instanceof e)return t.im;if(t instanceof Array)return Mt.map(t,D);if(t.valueOf()!==t)return D(t.valueOf());throw f("im",t)}function V(t){if(1!=arguments.length)throw u("re",arguments.length,1);if(r(t))return t;if(t instanceof e)return t.re;if(t instanceof Array)return Mt.map(t,V);if(t.valueOf()!==t)return V(t.valueOf());throw f("re",t)}function Y(e,t){var i,a,s=arguments.length;if(0>s||s>2)throw u("eye",s,0,2);if(0==s)return 1;if(1==s?(i=e,a=e):2==s&&(i=e,a=t),!r(i)||!n(i)||1>i)throw Error("Parameters in function eye must be positive integers");if(a&&(!r(a)||!n(a)||1>a))throw Error("Parameters in function eye must be positive integers");for(var o=[],f=0;i>f;f++){for(var h=[],c=0;a>c;c++)h[c]=0;o[f]=h}for(var l=Math.min(i,a),p=0;l>p;p++)o[p][p]=1;return o}function F(e,t,r){if(1!=arguments.length&&2!=arguments.length)throw u("range",arguments.length,1);var n=new i(e,r,t);return n.toArray()}function j(n){if(1!=arguments.length)throw u("size",arguments.length,1);if(r(n)||n instanceof e||n instanceof s||null==n)return[];if(a(n))return[n.length];if(n instanceof Array)return Mt.size(n);if(n instanceof t||n instanceof o||n instanceof i)return n.size();if(n.valueOf()!==n)return j(n.valueOf());throw f("size",n)}function H(e){if(1!=arguments.length)throw u("factorial",arguments.length,1);if(r(e)){if(!n(e))throw new TypeError("Function factorial can only handle integer values");var t=e,i=t;for(t--;t>1;)i*=t,t--;return 0==i&&(i=1),i}if(e instanceof Array)return Mt.map(e,H);if(e.valueOf()!==e)return H(e.valueOf());throw f("factorial",e)}function K(){if(0!=arguments.length)throw u("random",arguments.length,0);return Math.random()}function W(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 W.apply(this,e.valueOf());for(var t=arguments[0],r=1,n=arguments.length;n>r;r++){var i=arguments[r];w(i,t)&&(t=i)}return t}function X(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 X.apply(this,e.valueOf());for(var t=arguments[0],r=1,n=arguments.length;n>r;r++){var i=arguments[r];q(i,t)&&(t=i)}return t}function Z(t){if(1!=arguments.length)throw u("acos",arguments.length,1);if(r(t))return t>=-1&&1>=t?Math.acos(t):Z(new e(t,0));if(t instanceof e){var n=new e(t.im*t.im-t.re*t.re+1,-2*t.re*t.im),i=R(n),a=new e(i.re-t.im,i.im+t.re),s=N(a);return new e(1.5707963267948966-s.im,s.re)}if(t instanceof Array)return Mt.map(t,Z);if(t.valueOf()!==t)return Z(t.valueOf());throw f("acos",t)}function Q(t){if(1!=arguments.length)throw u("asin",arguments.length,1);if(r(t))return t>=-1&&1>=t?Math.asin(t):Q(new e(t,0));if(t instanceof e){var n=t.re,i=t.im,a=new e(i*i-n*n+1,-2*n*i),s=R(a),o=new e(s.re-i,s.im+n),h=N(o);return new e(h.im,-h.re)}if(t instanceof Array)return Mt.map(t,Q);if(t.valueOf()!==t)return Q(t.valueOf());throw f("asin",t)}function J(t){if(1!=arguments.length)throw u("atan",arguments.length,1);if(r(t))return Math.atan(t);if(t instanceof e){var n=t.re,i=t.im,a=n*n+(1-i)*(1-i),s=new e((1-i*i-n*n)/a,-2*n/a),o=N(s);return new e(-.5*o.im,.5*o.re)}if(t instanceof Array)return Mt.map(t,J);if(t.valueOf()!==t)return J(t.valueOf());throw f("atan",t)}function $(t,n){if(2!=arguments.length)throw u("atan2",arguments.length,2);if(r(t)){if(r(n))return Math.atan2(t,n);if(n instanceof e)return Math.atan2(t,n.re)}else if(t instanceof e){if(r(n))return Math.atan2(t.re,n);if(n instanceof e)return Math.atan2(t.re,n.re)}if(n instanceof Array||t instanceof Array)return Mt.map2(t,n,$);if(n.valueOf()!==n||t.valueOf()!==t)return $(t.valueOf(),n.valueOf());throw f("atan2",t,n)}function et(t){if(1!=arguments.length)throw u("cos",arguments.length,1);if(r(t))return Math.cos(t);if(t instanceof e)return new e(.5*Math.cos(t.re)*(Math.exp(-t.im)+Math.exp(t.im)),.5*Math.sin(t.re)*(Math.exp(-t.im)-Math.exp(t.im)));if(t instanceof s){if(!t.hasBase(s.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(t.value)}if(t instanceof Array)return Mt.map(t,et);if(t.valueOf()!==t)return et(t.valueOf());throw f("cos",t)}function tt(t){if(1!=arguments.length)throw u("cot",arguments.length,1);if(r(t))return 1/Math.tan(t);if(t instanceof e){var n=Math.exp(-4*t.im)-2*Math.exp(-2*t.im)*Math.cos(2*t.re)+1;return new e(2*Math.exp(-2*t.im)*Math.sin(2*t.re)/n,(Math.exp(-4*t.im)-1)/n)}if(t instanceof s){if(!t.hasBase(s.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(t.value)}if(t instanceof Array)return Mt.map(t,tt);if(t.valueOf()!==t)return tt(t.valueOf());throw f("cot",t)}function rt(t){if(1!=arguments.length)throw u("csc",arguments.length,1);if(r(t))return 1/Math.sin(t);if(t instanceof e){var n=.25*(Math.exp(-2*t.im)+Math.exp(2*t.im))-.5*Math.cos(2*t.re);return new e(.5*Math.sin(t.re)*(Math.exp(-t.im)+Math.exp(t.im))/n,.5*Math.cos(t.re)*(Math.exp(-t.im)-Math.exp(t.im))/n)}if(t instanceof s){if(!t.hasBase(s.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(t.value)}if(t instanceof Array)return Mt.map(t,rt);if(t.valueOf()!==t)return rt(t.valueOf());throw f("csc",t)}function nt(t){if(1!=arguments.length)throw u("sec",arguments.length,1);if(r(t))return 1/Math.cos(t);if(t instanceof e){var n=.25*(Math.exp(-2*t.im)+Math.exp(2*t.im))+.5*Math.cos(2*t.re);return new e(.5*Math.cos(t.re)*(Math.exp(-t.im)+Math.exp(t.im))/n,.5*Math.sin(t.re)*(Math.exp(t.im)-Math.exp(-t.im))/n)}if(t instanceof s){if(!t.hasBase(s.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(t.value)}if(t instanceof Array)return Mt.map(t,nt);if(t.valueOf()!==t)return nt(t.valueOf());throw f("sec",t)}function it(t){if(1!=arguments.length)throw u("sin",arguments.length,1);if(r(t))return Math.sin(t);if(t instanceof e)return new e(.5*Math.sin(t.re)*(Math.exp(-t.im)+Math.exp(t.im)),.5*Math.cos(t.re)*(Math.exp(t.im)-Math.exp(-t.im)));if(t instanceof s){if(!t.hasBase(s.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(t.value)}if(t instanceof Array)return Mt.map(t,it);if(t.valueOf()!==t)return it(t.valueOf());throw f("sin",t)}function at(t){if(1!=arguments.length)throw u("tan",arguments.length,1);if(r(t))return Math.tan(t);if(t instanceof e){var n=Math.exp(-4*t.im)+2*Math.exp(-2*t.im)*Math.cos(2*t.re)+1;return new e(2*Math.exp(-2*t.im)*Math.sin(2*t.re)/n,(1-Math.exp(-4*t.im))/n)}if(t instanceof s){if(!t.hasBase(s.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(t.value)}if(t instanceof Array)return Mt.map(t,at);if(t.valueOf()!==t)return at(t.valueOf());throw f("tan",t)}function st(e,t){if(2!=arguments.length)throw u("in",arguments.length,2);if(e instanceof s&&t instanceof s){if(!e.equalBase(t))throw Error("Units do not match");if(t.hasValue)throw Error("Cannot convert to a unit with a value");if(!t.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=t.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||t instanceof Array)return Mt.map2(e,t,st);if(e.valueOf()!==e)return bt.in(e.valueOf());throw f("in",e)}function ot(e){if(1!=arguments.length)throw u("clone",arguments.length,1);if("function"==typeof e.clone)return e.clone();if(r(e)||a(e)||null===e)return e;if(e instanceof Array)return e.map(function(e){return ot(e)});if(e instanceof Object)return Mt.map(e,ot);throw f("clone",e)}function ft(e,t){var n=arguments.length;if(1!=n&&2!=n)throw u("format",n,1,2);if(1==n){var i=arguments[0];return r(i)?Mt.formatNumber(i):i instanceof Array?Mt.formatArray(i):a(i)?'"'+i+'"':i instanceof Object?""+i:i+""}if(!a(e))throw new TypeError("String expected as first parameter in function format");if(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,r){for(var n=r.split("."),i=t[n.shift()];n.length&&void 0!=i;){var a=n.shift();i=a?i[a]:i+"."}return void 0!=i?i:e})}function ut(e){if(1!=arguments.length)throw u("help",arguments.length,1);if(void 0!=e){if(e.doc)return ht(e.doc);if(e.constructor.doc)return ht(e.constructor.doc);if(a(e)){var t=bt[e];if(t&&t.doc)return ht(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 ht(e){var t="";if(e.name&&(t+="NAME\n"+e.name+"\n\n"),e.category&&(t+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(t+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var r=new bt.parser.Parser;t+="EXAMPLES\n";for(var n=0;e.examples.length>n;n++){var i,a=e.examples[n];try{i=r.eval(a)}catch(s){i=s}t+=a+"\n",t+=" "+bt.format(i)+"\n"}t+="\n"}return e.seealso&&(t+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),t}function ct(e,t){var r;if(a(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var n=require(e);ct(n)}else if(lt(e)){if(r=e.name,!r)throw Error("Cannot import an unnamed function");(t||void 0===bt[r])&&(bt[r]=e)}else if(e instanceof Object)for(r in e)if(e.hasOwnProperty(r)){var i=e[r];lt(i)?(t||void 0===bt[r])&&(bt[r]=i):ct(i)}}function lt(t){return"function"==typeof t||r(t)||a(t)||t instanceof e||t instanceof s}function pt(e){if(1!=arguments.length)throw u("typeof",arguments.length,1);var t=typeof e;if("object"==t){if(null==e)return"null";if(e.constructor){for(var r in bt)if(bt.hasOwnProperty(r)&&e.constructor==bt[r])return r.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t}function mt(){}function vt(e,t,r){this.name=e,this.fn=t,this.params=r}function dt(e){this.value=e}function gt(e){this.nodes=e||[]}function yt(){this.params=[],this.visible=[]}function xt(e,t,r,n){this.name=e,this.params=t,this.expr=r,this.result=n}function wt(e,t,r,n,i){this.name=e,this.variables=r,this.values=[];for(var a=0,s=this.variables.length;s>a;a++)this.values[a]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,t,r,n),this.result=i}function Et(e){this.parentScope=e,this.nestedScopes=void 0,this.symbols={},this.defs={},this.updates={},this.links={}}function Nt(){if(this.constructor!=Nt)throw new SyntaxError("Parser constructor must be called with the new operator");this.TOKENTYPE={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},this.expr="",this.index=0,this.c="",this.token="",this.token_type=this.TOKENTYPE.NULL,this.scope=new Et}function Ot(){this.idMax=-1,this.updateSeq=0,this.parser=new Nt,this.scope=new Et,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}var bt={parser:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=bt),"undefined"!=typeof exports&&(exports=bt),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return bt}),"undefined"!=typeof window&&(window.math=bt);var Mt=function(){function e(e){if(e instanceof Array){var t=e.length;if(t){var r=n(e[0]);return[t].concat(r)}return[t]}return[]}var t={};return t.formatNumber=function(e,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var r=Math.abs(e);if(r>1e-4&&1e6>r||0==r)return k(e,t)+"";var n=Math.round(Math.log(r)/Math.LN10),i=e/Math.pow(10,n);return k(i,t)+"E"+n},t.formatArray=function r(e){if(e instanceof Array){for(var t="[",n=e.length,i=0;n>i;i++)0!=i&&(t+=", "),t+=r(e[i]);return t+="]"}return ft(e)},t.formatArray2d=function(e){var n="[",i=t.size(e);if(2!=i.length)throw new RangeError("Array must be two dimensional (size: "+r(i)+")");for(var a=i[0],s=i[1],o=0;a>o;o++){0!=o&&(n+="; ");for(var f=e[o],u=0;s>u;u++){0!=u&&(n+=", ");var h=f[u];void 0!=h&&(n+=ft(h))}}return n+="]"},t.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},t.map=function(e,t){if(!e instanceof Array)throw new TypeError("Array expected");return e.map(function(e){return t(e)})},t.map2=function(e,t,r){var n,i,a;if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(n=[],i=e.length,a=0;i>a;a++)n[a]=r(e[a],t[a])}else for(n=[],i=e.length,a=0;i>a;a++)n[a]=r(e[a],t);else if(t instanceof Array)for(n=[],i=t.length,a=0;i>a;a++)n[a]=r(e,t[a]);else n=r(e,t);return n},t.forEach=function(e,t){if(e instanceof Array)e.forEach(t);else for(var r in e)e.hasOwnProperty(r)&&t(e[r],r,e)},t.map=function(e,t){if(e instanceof Array)return e.map(t);var r={};for(var n in e)e.hasOwnProperty(n)&&(r[n]=t(e[n]));return r},t.array={},t.size=function n(r){var n=e(r);return t.validate(r,n),n},t.validate=function i(e,t,r){if(0!=t.length){var n,a=e.length;if(r||(r=0),a!=t[r])throw new RangeError("Dimension mismatch ("+a+" != "+t[r]+")");if(t.length-1>r){var s=r+1;for(n=0;a>n;n++){var o=e[n];if(!(o instanceof Array))throw new RangeError("Dimension mismatch ("+(t.length-1)+" < "+t.length+")");i(e[n],t,s)}}else for(n=0;a>n;n++)if(e[n]instanceof Array)throw new RangeError("Dimension mismatch ("+(t.length+1)+" > "+t.length+")")}else if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;this.length>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var r=0,n=this.length;n>r;++r)e.call(t||this,this[r],r,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var r,n,i;if(null==this)throw new TypeError(" this is null or not defined");var a=Object(this),s=a.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(t&&(r=t),n=Array(s),i=0;s>i;){var o,f;i in a&&(o=a[i],f=e.call(r,o,i,a),n[i]=f),i++}return n}),t}();bt.Complex=e,function(){function t(){for(;" "==c||" "==c;)i()}function r(e){return e>="0"&&"9">=e||"."==e}function n(e){return e>="0"&&"9">=e}function i(){h++,c=u[h]}function s(e){h=e,c=u[h]}function o(){var e="",t=h;if("+"==c?i():"-"==c&&(e+=c,i()),!r(c))return s(t),null;for(;r(c);)e+=c,i();if("E"==c||"e"==c){if(e+=c,i(),("+"==c||"-"==c)&&(e+=c,i()),!n(c))return s(t),null;for(;n(c);)e+=c,i()}return e}function f(){var e=u[h+1];if("I"==c||"i"==c)return i(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var t="+"==c?"1":"-1";return i(),i(),t}return null}var u,h,c;e.parse=function(r){if(u=r,h=-1,c="",!a(u))return null;i(),t();var n=o();if(n){if("I"==c||"i"==c)return i(),t(),c?null:new e(0,Number(n));t();var s=c;if("+"!=s&&"-"!=s)return t(),c?null:new e(Number(n),0);i(),t();var l=o();if(l){if("I"!=c&&"i"!=c)return null;i()}else if(l=f(),!l)return null;return"-"==s&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),i(),t(),c?null:new e(Number(n),Number(l))}return(n=f())?(t(),c?null:new e(0,Number(n))):null}}(),e.prototype.clone=function(){return new e(this.re,this.im)},e.prototype.toString=function(){var e="",t=Mt.formatNumber(this.re),r=Mt.formatNumber(this.im);return e=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":r+"i":this.im>0?1==this.im?t+" + i":t+" + "+r+"i":-1==this.im?t+" - i":t+" - "+Mt.formatNumber(Math.abs(this.im))+"i"},e.doc={name:"Complex",category:"type",syntax:["a + bi","a + b * i"],description:"A complex value a + bi, where a is the real part and b is the complex part, and i is the imaginary number defined as sqrt(-1).",examples:["2 + 3i","sqrt(-4)","(1.2 -5i) * 2"],seealso:["abs","arg","conj","im","re"]},bt.Matrix=t,t.prototype.clone=function(){var e=new t;return e._data=ot(this._data),e},t.prototype.size=function(){return this._size},t.prototype.toScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=value[0];return e instanceof Array?null:e},t.prototype.isScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0]; -return!(e instanceof Array)},t.prototype.toVector=function(){throw Error("not yet implemented")},t.prototype.isVector=function(){var e=0,t=Mt.size(this._data);return t.forEach(function(t){t>1&&e++}),1>=e},t.prototype.toArray=function(){var e=ot(this._data);return e instanceof Array||(e=[e]),e},t.prototype.valueOf=function(){return this._data},t.prototype.toString=function(){return Mt.formatArray(this._data)},bt.Range=i,i.prototype.clone=function(){return new i(this.start,this.step,this.end)},i.prototype.size=function(){var e=0,t=Number(this.start),r=Number(this.step),n=Number(this.end),i=n-t;return U(r)==U(i)?e=Math.floor(i/r)+1:0==i&&(e=1),isNaN(e)&&(e=0),[e]},i.prototype.forEach=function(e){var t=Number(this.start),r=Number(this.step),n=Number(this.end),i=0;if(r>0)for(;n>=t;)e(t,i),t+=r,i++;else if(0>r)for(;t>=n;)e(t,i),t+=r,i++},i.prototype.map=function(e){var t=[];return this.forEach(function(r,n){t[n]=e(r)}),t},i.prototype.toVector=function(){return new o(this.toArray())},i.prototype.toArray=function(){var e=[];return this.forEach(function(t,r){e[r]=t}),e},i.prototype.valueOf=function(){return this.toArray()},i.prototype.toString=function(){var e=ft(Number(this.start));return 1!=this.step&&(e+=":"+ft(Number(this.step))),e+=":"+ft(Number(this.end))},bt.Unit=s,function(){function e(){for(;" "==c||" "==c;)n()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function n(){h++,c=u[h]}function i(e){h=e,c=u[h]}function o(){var e="",a=h;if("+"==c?n():"-"==c&&(e+=c,n()),!t(c))return i(a),null;for(;t(c);)e+=c,n();if("E"==c||"e"==c){if(e+=c,n(),("+"==c||"-"==c)&&(e+=c,n()),!r(c))return i(a),null;for(;r(c);)e+=c,n()}return e}function f(){var t="";for(e();c&&" "!=c&&" "!=c;)t+=c,n();return t||null}var u,h,c;s.parse=function(t){if(u=t,h=-1,c="",!a(u))return null;n(),e();var r,i=o();return i?(r=f(),n(),e(),c?null:i&&r?new s(Number(i),r):null):(r=f(),n(),e(),c?null:new s(null,r))}}(),s.prototype.clone=function(){var e=new s;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},s.endsWith=function(e,t){var r=e.length-t.length,n=e.length;return e.substring(r,n)===t},s.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},s.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},s.isUnit=function(e){for(var t=s.UNITS,r=t.length,n=0;r>n;n++){var i=t[n];if(s.endsWith(e,i.name)){var a=e.length-i.name.length;if(0==a)return!0;var o=e.substring(0,a),f=i.prefixes[o];if(void 0!==f)return!0}}return!1},s.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},s.prototype.equalBase=function(e){return this.unit.base===e.unit.base},s.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},s.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),Mt.formatNumber(e)+" "+this.prefix.name+this.unit.name;var t=Math.abs(this.value/this.unit.value),r=s.PREFIX_NONE,n=Math.abs(Math.log(t/r.value)/Math.LN10-1.2),i=this.unit.prefixes;for(var a in i)if(i.hasOwnProperty(a)){var o=i[a];if(o.scientific){var f=Math.abs(Math.log(t/o.value)/Math.LN10-1.2);n>f&&(r=o,n=f)}}return e=this._unnormalize(this.value,r.value),Mt.formatNumber(e)+" "+r.name+this.unit.name},s.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}}},s.PREFIX_NONE={name:"",value:1,scientific:!0},s.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var Tt=s.BASE_UNITS,At=s.PREFIXES;s.BASE_UNIT_NONE={},s.UNIT_NONE={name:"",base:s.BASE_UNIT_NONE,value:1,offset:0},s.UNITS=[{name:"meter",base:Tt.LENGTH,prefixes:At.LONG,value:1,offset:0},{name:"inch",base:Tt.LENGTH,prefixes:At.NONE,value:.0254,offset:0},{name:"foot",base:Tt.LENGTH,prefixes:At.NONE,value:.3048,offset:0},{name:"yard",base:Tt.LENGTH,prefixes:At.NONE,value:.9144,offset:0},{name:"mile",base:Tt.LENGTH,prefixes:At.NONE,value:1609.344,offset:0},{name:"link",base:Tt.LENGTH,prefixes:At.NONE,value:.201168,offset:0},{name:"rod",base:Tt.LENGTH,prefixes:At.NONE,value:5.02921,offset:0},{name:"chain",base:Tt.LENGTH,prefixes:At.NONE,value:20.1168,offset:0},{name:"angstrom",base:Tt.LENGTH,prefixes:At.NONE,value:1e-10,offset:0},{name:"m",base:Tt.LENGTH,prefixes:At.SHORT,value:1,offset:0},{name:"ft",base:Tt.LENGTH,prefixes:At.NONE,value:.3048,offset:0},{name:"yd",base:Tt.LENGTH,prefixes:At.NONE,value:.9144,offset:0},{name:"mi",base:Tt.LENGTH,prefixes:At.NONE,value:1609.344,offset:0},{name:"li",base:Tt.LENGTH,prefixes:At.NONE,value:.201168,offset:0},{name:"rd",base:Tt.LENGTH,prefixes:At.NONE,value:5.02921,offset:0},{name:"ch",base:Tt.LENGTH,prefixes:At.NONE,value:20.1168,offset:0},{name:"mil",base:Tt.LENGTH,prefixes:At.NONE,value:254e-7,offset:0},{name:"m2",base:Tt.SURFACE,prefixes:At.SHORT,value:1,offset:0},{name:"sqin",base:Tt.SURFACE,prefixes:At.NONE,value:64516e-8,offset:0},{name:"sqft",base:Tt.SURFACE,prefixes:At.NONE,value:.09290304,offset:0},{name:"sqyd",base:Tt.SURFACE,prefixes:At.NONE,value:.83612736,offset:0},{name:"sqmi",base:Tt.SURFACE,prefixes:At.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:Tt.SURFACE,prefixes:At.NONE,value:25.29295,offset:0},{name:"sqch",base:Tt.SURFACE,prefixes:At.NONE,value:404.6873,offset:0},{name:"sqmil",base:Tt.SURFACE,prefixes:At.NONE,value:6.4516e-10,offset:0},{name:"m3",base:Tt.VOLUME,prefixes:At.SHORT,value:1,offset:0},{name:"L",base:Tt.VOLUME,prefixes:At.SHORT,value:.001,offset:0},{name:"litre",base:Tt.VOLUME,prefixes:At.LONG,value:.001,offset:0},{name:"cuin",base:Tt.VOLUME,prefixes:At.NONE,value:16387064e-12,offset:0},{name:"cuft",base:Tt.VOLUME,prefixes:At.NONE,value:.028316846592,offset:0},{name:"cuyd",base:Tt.VOLUME,prefixes:At.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:Tt.VOLUME,prefixes:At.NONE,value:5e-6,offset:0},{name:"tablespoon",base:Tt.VOLUME,prefixes:At.NONE,value:15e-6,offset:0},{name:"minim",base:Tt.VOLUME,prefixes:At.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:Tt.VOLUME,prefixes:At.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:Tt.VOLUME,prefixes:At.NONE,value:2957353e-11,offset:0},{name:"gill",base:Tt.VOLUME,prefixes:At.NONE,value:.0001182941,offset:0},{name:"cup",base:Tt.VOLUME,prefixes:At.NONE,value:.0002365882,offset:0},{name:"pint",base:Tt.VOLUME,prefixes:At.NONE,value:.0004731765,offset:0},{name:"quart",base:Tt.VOLUME,prefixes:At.NONE,value:.0009463529,offset:0},{name:"gallon",base:Tt.VOLUME,prefixes:At.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:Tt.VOLUME,prefixes:At.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:Tt.VOLUME,prefixes:At.NONE,value:.1589873,offset:0},{name:"hogshead",base:Tt.VOLUME,prefixes:At.NONE,value:.238481,offset:0},{name:"fldr",base:Tt.VOLUME,prefixes:At.NONE,value:36966911e-13,offset:0},{name:"floz",base:Tt.VOLUME,prefixes:At.NONE,value:2957353e-11,offset:0},{name:"gi",base:Tt.VOLUME,prefixes:At.NONE,value:.0001182941,offset:0},{name:"cp",base:Tt.VOLUME,prefixes:At.NONE,value:.0002365882,offset:0},{name:"pt",base:Tt.VOLUME,prefixes:At.NONE,value:.0004731765,offset:0},{name:"qt",base:Tt.VOLUME,prefixes:At.NONE,value:.0009463529,offset:0},{name:"gal",base:Tt.VOLUME,prefixes:At.NONE,value:.003785412,offset:0},{name:"bbl",base:Tt.VOLUME,prefixes:At.NONE,value:.1173478,offset:0},{name:"obl",base:Tt.VOLUME,prefixes:At.NONE,value:.1589873,offset:0},{name:"g",base:Tt.MASS,prefixes:At.SHORT,value:.001,offset:0},{name:"gram",base:Tt.MASS,prefixes:At.LONG,value:.001,offset:0},{name:"ton",base:Tt.MASS,prefixes:At.SHORT,value:907.18474,offset:0},{name:"tonne",base:Tt.MASS,prefixes:At.SHORT,value:1e3,offset:0},{name:"grain",base:Tt.MASS,prefixes:At.NONE,value:6479891e-11,offset:0},{name:"dram",base:Tt.MASS,prefixes:At.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:Tt.MASS,prefixes:At.NONE,value:.028349523125,offset:0},{name:"poundmass",base:Tt.MASS,prefixes:At.NONE,value:.45359237,offset:0},{name:"hundredweight",base:Tt.MASS,prefixes:At.NONE,value:45.359237,offset:0},{name:"stick",base:Tt.MASS,prefixes:At.NONE,value:.115,offset:0},{name:"gr",base:Tt.MASS,prefixes:At.NONE,value:6479891e-11,offset:0},{name:"dr",base:Tt.MASS,prefixes:At.NONE,value:.0017718451953125,offset:0},{name:"oz",base:Tt.MASS,prefixes:At.NONE,value:.028349523125,offset:0},{name:"lbm",base:Tt.MASS,prefixes:At.NONE,value:.45359237,offset:0},{name:"cwt",base:Tt.MASS,prefixes:At.NONE,value:45.359237,offset:0},{name:"s",base:Tt.TIME,prefixes:At.SHORT,value:1,offset:0},{name:"min",base:Tt.TIME,prefixes:At.NONE,value:60,offset:0},{name:"h",base:Tt.TIME,prefixes:At.NONE,value:3600,offset:0},{name:"seconds",base:Tt.TIME,prefixes:At.LONG,value:1,offset:0},{name:"second",base:Tt.TIME,prefixes:At.LONG,value:1,offset:0},{name:"sec",base:Tt.TIME,prefixes:At.LONG,value:1,offset:0},{name:"minutes",base:Tt.TIME,prefixes:At.NONE,value:60,offset:0},{name:"minute",base:Tt.TIME,prefixes:At.NONE,value:60,offset:0},{name:"hours",base:Tt.TIME,prefixes:At.NONE,value:3600,offset:0},{name:"hour",base:Tt.TIME,prefixes:At.NONE,value:3600,offset:0},{name:"day",base:Tt.TIME,prefixes:At.NONE,value:86400,offset:0},{name:"days",base:Tt.TIME,prefixes:At.NONE,value:86400,offset:0},{name:"rad",base:Tt.ANGLE,prefixes:At.NONE,value:1,offset:0},{name:"deg",base:Tt.ANGLE,prefixes:At.NONE,value:.017453292519943295,offset:0},{name:"grad",base:Tt.ANGLE,prefixes:At.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:Tt.ANGLE,prefixes:At.NONE,value:6.283185307179586,offset:0},{name:"A",base:Tt.CURRENT,prefixes:At.SHORT,value:1,offset:0},{name:"ampere",base:Tt.CURRENT,prefixes:At.LONG,value:1,offset:0},{name:"K",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1,offset:0},{name:"degC",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1,offset:273.15},{name:"degF",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1/1.8,offset:459.67},{name:"degR",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1/1.8,offset:0},{name:"kelvin",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1,offset:0},{name:"celsius",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1,offset:273.15},{name:"fahrenheit",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:Tt.TEMPERATURE,prefixes:At.NONE,value:1/1.8,offset:0},{name:"mol",base:Tt.AMOUNT_OF_SUBSTANCE,prefixes:At.NONE,value:1,offset:0},{name:"mole",base:Tt.AMOUNT_OF_SUBSTANCE,prefixes:At.NONE,value:1,offset:0},{name:"cd",base:Tt.LUMINOUS_INTENSITY,prefixes:At.NONE,value:1,offset:0},{name:"candela",base:Tt.LUMINOUS_INTENSITY,prefixes:At.NONE,value:1,offset:0},{name:"N",base:Tt.FORCE,prefixes:At.SHORT,value:1,offset:0},{name:"newton",base:Tt.FORCE,prefixes:At.LONG,value:1,offset:0},{name:"lbf",base:Tt.FORCE,prefixes:At.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:Tt.FORCE,prefixes:At.NONE,value:4.4482216152605,offset:0},{name:"b",base:Tt.BIT,prefixes:At.BINARY_SHORT,value:1,offset:0},{name:"bits",base:Tt.BIT,prefixes:At.BINARY_LONG,value:1,offset:0},{name:"B",base:Tt.BIT,prefixes:At.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:Tt.BIT,prefixes:At.BINARY_LONG,value:8,offset:0}],bt.Vector=o,o.prototype.resize=function(e,t){if(e=e.valueOf(),e instanceof Array){if(e.length>1)throw new RangeError("Cannot resize a vector to multiple dimensions (size: "+ft(e)+")");this.resize(e[0],t)}else{if(!r(e)||!n(e)||0>e)throw new TypeError("Positive integer expected as size in method resize");if(!(this._data instanceof Array)&&e>1)this._data=[this._data],this.resize(e,t);else{if(e>this._data.length)for(var i=this._data.length;e>i;i++)this._data[i]=t?ot(t):0;else this._data.length=e;this._size=[this._data.length]}}},o.prototype.get=function(e){var t=this;if(e=e.valueOf(),e instanceof i||e instanceof Array)return e.map(function(e){return t.get(e)});if(!r(e)||!n(e)||0>e)throw new TypeError("Positive integer expected as index in method get");if(this._data instanceof Array)return this._data[e];if(0==e)return this._data;throw new RangeError("Index out of range ("+e+")")},o.prototype.set=function(e,t){var r=this;if(e=e.valueOf(),e instanceof i){if(e.size()!=t.length)throw new RangeError("Dimension mismatch ("+e.size()+" != "+t.length+")");e.forEach(function(e,n){r._set(e,t[n])})}else if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");e.forEach(function(e,n){r._set(e,t[n])})}else this.set(e,[t]);else t instanceof Array?this.set([e],t):this._set(e,t)},o.prototype._set=function(e,t){this._data instanceof Array||(this._data=[this._data]),e>this._data.length&&this.resize(e),this._data[e]=t},o.prototype.clone=function(){var e=new o;return e._data=ot(this._data),e},o.prototype.size=function(){return this._size},o.prototype.toScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0];return e instanceof Array?null:e},o.prototype.isScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0];return!(e instanceof Array)},o.prototype.toArray=function(){var e=ot(this._data);return e instanceof Array||(e=[e]),e},o.prototype.valueOf=function(){return this._data},o.prototype.toString=function(){return Mt.formatArray(this._data)},bt.E=Math.E,bt.LN2=Math.LN2,bt.LN10=Math.LN10,bt.LOG2E=Math.LOG2E,bt.LOG10E=Math.LOG10E,bt.PI=Math.PI,bt.SQRT1_2=Math.SQRT1_2,bt.SQRT2=Math.SQRT2,bt.I=new e(0,-1),bt.pi=bt.PI,bt.e=bt.E,bt.i=bt.I,bt.abs=h,h.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},bt.add=c,c.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"]},bt.ceil=l,l.doc={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]},bt.cube=p,p.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"]},bt.divide=m,m.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"]},bt.equal=d,d.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"]},bt.exp=g,g.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"]},bt.fix=y,y.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"]},bt.floor=x,x.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"]},bt.larger=w,w.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"]},bt.largereq=E,E.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"]},bt.log=N,N.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"]},bt.log10=O,O.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"]},bt.mod=b,b.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:[]},bt.multiply=M,M.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"]},bt.pow=A,A.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"]},bt.round=_,_.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"]},bt.sign=U,U.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"]},bt.smaller=q,q.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"]},bt.smallereq=L,L.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"]},bt.sqrt=R,R.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"]},bt.square=C,C.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"]},bt.subtract=I,I.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"]},bt.unaryminus=P,P.doc={name:"unaryminus",category:"Operators",syntax:["-x","unaryminus(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},bt.unequal=z,z.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"]},bt.arg=B,B.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"]},bt.conj=G,G.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"]},bt.im=D,D.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"]},bt.re=V,V.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"]},bt.eye=Y,Y.doc={name:"eye",category:"Matrix",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["diag","ones","range","size","transpose","zeros"]},bt.range=F,F.doc={name:"range",category:"Matrix",syntax:["start : end","start : step : end","range(start, end)","range(start, step, end)"],description:"Create a range.",examples:["1:10","0:10:100","0:0.2:1","range(20, -1, 10)","matrix = [1, 2, 3; 4, 5, 6; 7, 8, 9]","matrix(2:3, 1:2)"],seealso:["diag","eye","ones","size","transpose","zeros"]},bt.size=j,j.doc={name:"size",category:"Matrix",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["diag","eye","ones","range","transpose","zeros"]},bt.factorial=H,H.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:[]},bt.random=K,K.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},bt.max=W,W.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"]},bt.min=X,X.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"]},bt.acos=Z,Z.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"]},bt.asin=Q,Q.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"]},bt.atan=J,J.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"]},bt.atan2=$,$.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"]},bt.cos=et,et.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"]},bt.cot=tt,tt.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"]},bt.csc=rt,rt.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"]},bt.sec=nt,nt.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"]},bt.sin=it,it.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"]},bt.tan=at,at.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"]},bt.in=st,st.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:[]},bt.clone=ot,ot.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:[]},bt.format=ft,ft.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:[]},bt.help=ut,ut.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},bt["import"]=ct,ct.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},bt["typeof"]=pt,pt.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:[]},bt.parser.node.Node=mt,mt.prototype.eval=function(){throw Error("Cannot evaluate a Node interface")},mt.prototype.toString=function(){return""},vt.prototype=new mt,bt.parser.node.Symbol=vt,vt.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},vt.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)},vt.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},dt.prototype=new mt,bt.parser.node.Constant=dt,dt.prototype.eval=function(){return this.value},dt.prototype.toString=function(){return this.value?bt.format(this.value):""},gt.prototype=new mt,bt.parser.node.ArrayNode=gt,function(){function e(t){return t.map(function(t){return t instanceof Array?e(t):t.eval()})}function t(e){if(e instanceof Array){for(var r="[",n=e.length,i=0;n>i;i++)0!=i&&(r+=", "),r+=t(e[i]);return r+="]"}return""+e}gt.prototype.eval=function(){return e(this.nodes)},gt.prototype.toString=function(){return t(this.nodes)}}(),yt.prototype=new mt,bt.parser.node.Block=yt,yt.prototype.add=function(e,t){var r=this.params.length;this.params[r]=e,this.visible[r]=void 0!=t?t:!0},yt.prototype.eval=function(){for(var e=[],t=0,r=this.params.length;r>t;t++){var n=this.params[t].eval();this.visible[t]&&e.push(n)}return e},yt.prototype.toString=function(){for(var e=[],t=0,r=this.params.length;r>t;t++)this.visible[t]&&e.push("\n "+(""+this.params[t]));return"["+e.join(",")+"\n]"},xt.prototype=new mt,bt.parser.node.Assignment=xt,xt.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,t=this.params;if(t&&t.length){var r=[];this.params.forEach(function(e){r.push(e.eval())});var n=this.expr.eval();if(void 0==this.result.value)throw Error("Undefined symbol "+this.name); -var i=this.result.eval();e=i.set(r,n),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},xt.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},wt.prototype=new mt,bt.parser.node.FunctionAssignment=wt,wt.prototype.createFunction=function(e,t,r,n){var i=function(){var t=r?r.length:0,i=arguments?arguments.length:0;if(t!=i)throw u(e,i,t);if(t>0)for(var a=0;t>a;a++)r[a].value=arguments[a];return n.eval()};return i.toString=function(){return e+"("+t.join(", ")+")"},i},wt.prototype.eval=function(){for(var e=this.variables,t=this.values,r=0,n=e.length;n>r;r++)e[r].value=t[r];return this.result.value=this.def,this.def},wt.prototype.toString=function(){return""+this.def},bt.parser.node.Scope=Et,Et.prototype.createNestedScope=function(){var e=new Et(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(e),e},Et.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,t=0,r=e.length;r>t;t++)e[t].clear()},Et.prototype.createSymbol=function(e){var t=this.symbols[e];if(!t){var r=this.findDef(e);t=this.newSymbol(e,r),this.symbols[e]=t}return t},Et.prototype.newSymbol=function(e,t){var r=this,n=function(){if(!n.value&&(n.value=r.findDef(e),!n.value))throw Error("Undefined symbol "+e);return"function"==typeof n.value?n.value.apply(null,arguments):n.value};return n.value=t,n.toString=function(){return n.value?""+n.value:""},n},Et.prototype.createLink=function(e){var t=this.links[e];return t||(t=this.createSymbol(e),this.links[e]=t),t},Et.prototype.createDef=function(e,t){var r=this.defs[e];return r||(r=this.createSymbol(e),this.defs[e]=r),r&&void 0!=t&&(r.value=t),r},Et.prototype.createUpdate=function(e){var t=this.updates[e];return t||(t=this.createLink(e),this.updates[e]=t),t},Et.prototype.findDef=function(t){function r(e,t){var r=i(e,t);return a[e]=r,o[e]=r,r}var n;if(n=this.defs[t])return n;if(n=this.updates[t])return n;if(this.parentScope)return this.parentScope.findDef(t);var i=this.newSymbol,a=this.symbols,o=this.defs;if("pi"==t)return r(t,bt.PI);if("e"==t)return r(t,bt.E);if("i"==t)return r(t,new e(0,1));var f=bt[t];if(f)return r(t,f);if(s.isUnit(t)){var u=new s(null,t);return r(t,u)}return void 0},Et.prototype.removeLink=function(e){delete this.links[e]},Et.prototype.removeDef=function(e){delete this.defs[e]},Et.prototype.removeUpdate=function(e){delete this.updates[e]},Et.prototype.init=function(){var e=this.symbols,t=this.parentScope;for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];n.value=t?t.findDef(r):void 0}this.nestedScopes&&this.nestedScopes.forEach(function(e){e.init()})},Et.prototype.hasLink=function(e){if(this.links[e])return!0;if(this.nestedScopes)for(var t=this.nestedScopes,r=0,n=t.length;n>r;r++)if(t[r].hasLink(e))return!0;return!1},Et.prototype.hasDef=function(e){return void 0!=this.defs[e]},Et.prototype.hasUpdate=function(e){return void 0!=this.updates[e]},Et.prototype.getUndefinedSymbols=function(){var e=this.symbols,t=[];for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];void 0==n.value&&t.push(n)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){t=t.concat(e.getUndefinedSymbols())}),t},bt.parser.Parser=Nt,Nt.prototype.parse=function(e,t){return this.expr=e||"",t||(this.newScope(),t=this.scope),this.parse_start(t)},Nt.prototype.eval=function(e){var t=this.parse(e);return t.eval()},Nt.prototype.get=function(e){this.newScope();var t=this.scope.findDef(e);return t?t.value:void 0},Nt.prototype.set=function(e,t){this.scope.createDef(e,t)},Nt.prototype.newScope=function(){this.scope=new Et(this.scope)},Nt.prototype.clear=function(){this.scope.clear()},Nt.prototype.getChar=function(){this.index++,this.c=this.expr.charAt(this.index)},Nt.prototype.getFirstChar=function(){this.index=0,this.c=this.expr.charAt(0)},Nt.prototype.getToken=function(){for(this.token_type=this.TOKENTYPE.NULL,this.token="";" "==this.c||" "==this.c;)this.getChar();if("#"==this.c)for(;"\n"!=this.c&&""!=this.c;)this.getChar();if(""==this.c)return this.token_type=this.TOKENTYPE.DELIMITER,void 0;if("-"==this.c||","==this.c||"("==this.c||")"==this.c||"["==this.c||"]"==this.c||'"'==this.c||"\n"==this.c||";"==this.c||":"==this.c)return this.token_type=this.TOKENTYPE.DELIMITER,this.token+=this.c,this.getChar(),void 0;if(this.isDelimiter(this.c))for(this.token_type=this.TOKENTYPE.DELIMITER;this.isDelimiter(this.c);)this.token+=this.c,this.getChar();else if(this.isDigitDot(this.c)){for(this.token_type=this.TOKENTYPE.NUMBER;this.isDigitDot(this.c);)this.token+=this.c,this.getChar();if("E"==this.c||"e"==this.c)for(this.token+=this.c,this.getChar(),("+"==this.c||"-"==this.c)&&(this.token+=this.c,this.getChar()),this.isDigit(this.c)||(this.token_type=this.TOKENTYPE.UNKNOWN);this.isDigit(this.c);)this.token+=this.c,this.getChar()}else{if(!this.isAlpha(this.c)){for(this.token_type=this.TOKENTYPE.UNKNOWN;""!=this.c;)this.token+=this.c,this.getChar();throw this.createSyntaxError('Syntax error in part "'+this.token+'"')}for(this.token_type=this.TOKENTYPE.SYMBOL;this.isAlpha(this.c)||this.isDigit(this.c);)this.token+=this.c,this.getChar()}},Nt.prototype.isDelimiter=function(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e},Nt.prototype.isValidSymbolName=function(e){for(var t=0,r=e.length;r>t;t++){var n=e.charAt(t),i=this.isAlpha(n);if(!i)return!1}return!0},Nt.prototype.isAlpha=function(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e},Nt.prototype.isDigitDot=function(e){return e>="0"&&"9">=e||"."==e},Nt.prototype.isDigit=function(e){return e>="0"&&"9">=e},Nt.prototype.parse_start=function(e){this.getFirstChar(),this.getToken();var t;if(t=""==this.token?new dt(void 0):this.parse_block(e),""!=this.token)throw this.token_type==this.TOKENTYPE.DELIMITER?this.createError("Unknown operator "+this.token):this.createSyntaxError('Unexpected part "'+this.token+'"');return t},Nt.prototype.parse_ans=function(e){var t=this.parse_function_assignment(e);if(!(t instanceof xt)){var r="ans",n=void 0,i=e.createDef(r);return new xt(r,n,t,i)}return t},Nt.prototype.parse_block=function(e){var t,r,n;for("\n"!=this.token&&";"!=this.token&&""!=this.token&&(t=this.parse_ans(e));"\n"==this.token||";"==this.token;)r||(r=new yt,t&&(n=";"!=this.token,r.add(t,n))),this.getToken(),"\n"!=this.token&&";"!=this.token&&""!=this.token&&(t=this.parse_ans(e),n=";"!=this.token,r.add(t,n));return r?r:(t||(t=this.parse_ans(e)),t)},Nt.prototype.parse_function_assignment=function(e){if(this.token_type==this.TOKENTYPE.SYMBOL&&"function"==this.token){if(this.getToken(),this.token_type!=this.TOKENTYPE.SYMBOL)throw this.createSyntaxError("Function name expected");var t=this.token;if(this.getToken(),"("!=this.token)throw this.createSyntaxError("Opening parenthesis ( expected");for(var r=e.createNestedScope(),n=[],i=[];;){if(this.getToken(),this.token_type!=this.TOKENTYPE.SYMBOL)throw this.createSyntaxError("Variable name expected");var a=this.token,s=r.createDef(a);if(n.push(a),i.push(s),this.getToken(),","!=this.token){if(")"==this.token)break;throw this.createSyntaxError('Comma , or closing parenthesis ) expected"')}}if(this.getToken(),"="!=this.token)throw this.createSyntaxError("Equal sign = expected");this.getToken();var o=this.parse_range(r),f=e.createDef(t);return new wt(t,n,i,o,f)}return this.parse_assignment(e)},Nt.prototype.parse_assignment=function(e){var t=!1;this.token_type==this.TOKENTYPE.SYMBOL&&(t=e.hasLink(this.token));var r=this.parse_range(e);if("="==this.token){if(!(r instanceof vt))throw this.createSyntaxError("Symbol expected at the left hand side of assignment operator =");var n=r.name,i=r.params;t||e.removeLink(n),this.getToken();var a=this.parse_range(e),s=r.hasParams()?e.createUpdate(n):e.createDef(n);return new xt(n,i,a,s)}return r},Nt.prototype.parse_range=function(e){var t=this.parse_conditions(e);if(":"==this.token){for(var r=[t];":"==this.token;)this.getToken(),r.push(this.parse_conditions(e));if(r.length>3)throw new TypeError("Invalid range");var n="range",a=function(e,t,r){return new i(e,t,r)};t=new vt(n,a,r)}return t},Nt.prototype.parse_conditions=function(e){for(var t=this.parse_bitwise_conditions(e),r={"in":"in"};void 0!==r[this.token];){var n=this.token,i=bt[r[n]];this.getToken();var a=[t,this.parse_bitwise_conditions(e)];t=new vt(n,i,a)}return t},Nt.prototype.parse_bitwise_conditions=function(e){var t=this.parse_comparison(e);return t},Nt.prototype.parse_comparison=function(e){for(var t=this.parse_addsubtract(e),r={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==r[this.token];){var n=this.token,i=bt[r[n]];this.getToken();var a=[t,this.parse_addsubtract(e)];t=new vt(n,i,a)}return t},Nt.prototype.parse_addsubtract=function(e){for(var t=this.parse_multiplydivide(e),r={"+":"add","-":"subtract"};void 0!==r[this.token];){var n=this.token,i=bt[r[n]];this.getToken();var a=[t,this.parse_multiplydivide(e)];t=new vt(n,i,a)}return t},Nt.prototype.parse_multiplydivide=function(e){for(var t=this.parse_unaryminus(e),r={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==r[this.token];){var n=this.token,i=bt[r[n]];this.getToken();var a=[t,this.parse_unaryminus(e)];t=new vt(n,i,a)}return t},Nt.prototype.parse_unaryminus=function(e){if("-"==this.token){var t=this.token,r=P;this.getToken();var n=[this.parse_pow(e)];return new vt(t,r,n)}return this.parse_pow(e)},Nt.prototype.parse_pow=function(e){for(var t=[this.parse_factorial(e)];"^"==this.token;)this.getToken(),t.push(this.parse_factorial(e));for(var r=t.pop();t.length;){var n=t.pop(),i="^",a=A,s=[n,r];r=new vt(i,a,s)}return r},Nt.prototype.parse_factorial=function(e){for(var t=this.parse_plot(e);"!"==this.token;){var r=this.token,n=H;this.getToken();var i=[t];t=new vt(r,n,i)}return t},Nt.prototype.parse_plot=function(e){return this.parse_symbol(e)},Nt.prototype.parse_symbol=function(e){if(this.token_type==this.TOKENTYPE.SYMBOL){var t=this.token;this.getToken();var r=e.createLink(t),n=this.parse_arguments(e),i=new vt(t,r,n);return i}return this.parse_string(e)},Nt.prototype.parse_arguments=function(e){var t=[];if("("==this.token){if(this.getToken(),")"!=this.token)for(t.push(this.parse_range(e));","==this.token;)this.getToken(),t.push(this.parse_range(e));if(")"!=this.token)throw this.createSyntaxError("Parenthesis ) missing");this.getToken()}return t},Nt.prototype.parse_string=function(e){if('"'==this.token){for(var t="",r="";""!=this.c&&('"'!=this.c||"\\"==r);)t+=this.c,r=this.c,this.getChar();if(this.getToken(),'"'!=this.token)throw this.createSyntaxError('End of string " missing');this.getToken();var n=new dt(t);return n}return this.parse_matrix(e)},Nt.prototype.parse_matrix=function(e){if("["==this.token){var t;for(this.getToken();"\n"==this.token;)this.getToken();if("]"!=this.token){var r=[],n=0,i=0;for(r[0]=[this.parse_range(e)];","==this.token||";"==this.token;){for(","==this.token?i++:(n++,i=0,r[n]=[]),this.getToken();"\n"==this.token;)this.getToken();for(r[n][i]=this.parse_range(e);"\n"==this.token;)this.getToken()}var a=r.length,s=r.length>0?r[0].length:0;for(n=1;a>n;n++)if(r[n].length!=s)throw this.createError("Number of columns must match ("+r[n].length+" != "+s+")");if("]"!=this.token)throw this.createSyntaxError("End of matrix ] missing");this.getToken(),t=new gt(r)}else this.getToken(),t=new gt([]);for(;"("==this.token;)t=this.parse_arguments(e,t);return t}return this.parse_number(e)},Nt.prototype.parse_number=function(t){if(this.token_type==this.TOKENTYPE.NUMBER){var r;r="."==this.token?0:Number(this.token),this.getToken();var n;if(this.token_type==this.TOKENTYPE.SYMBOL){if("i"==this.token||"I"==this.token)return n=new e(0,r),this.getToken(),new dt(n);if(s.isUnit(this.token))return n=new s(r,this.token),this.getToken(),new dt(n);throw this.createTypeError('Unknown unit "'+this.token+'"')}var i=new dt(r);return i}return this.parse_parentheses(t)},Nt.prototype.parse_parentheses=function(e){if("("==this.token){this.getToken();var t=this.parse_range(e);if(")"!=this.token)throw this.createSyntaxError("Parenthesis ) expected");return this.getToken(),t}return this.parse_end(e)},Nt.prototype.parse_end=function(){throw""==this.token?this.createSyntaxError("Unexpected end of expression"):this.createSyntaxError("Value expected")},Nt.prototype.row=function(){return void 0},Nt.prototype.col=function(){return this.index-this.token.length+1},Nt.prototype.createErrorMessage=function(e){var t=this.row(),r=this.col();return void 0===t?void 0===r?e:e+" (col "+r+")":e+" (ln "+t+", col "+r+")"},Nt.prototype.createSyntaxError=function(e){return new SyntaxError(this.createErrorMessage(e))},Nt.prototype.createTypeError=function(e){return new TypeError(this.createErrorMessage(e))},Nt.prototype.createError=function(e){return Error(this.createErrorMessage(e))},bt.parser.Workspace=Ot,Ot.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},Ot.prototype.append=function(e){var t=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,n=new Et(r),i=new Ot.Node({id:t,expression:e,parser:this.parser,scope:n,nextNode:void 0,previousNode:this.lastNode});return this.nodes[t]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([t]),t},Ot.prototype.insertBefore=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var n=r.previousNode,i=this._getNewId(),a=n?n.scope:this.scope,s=new Et(a),o=new Ot.Node({id:i,expression:e,parser:this.parser,scope:s,nextNode:r,previousNode:n});this.nodes[i]=o,n?n.nextNode=o:this.firstNode=o,r.previousNode=o,r.scope.parentScope=o.scope;var f=this.getDependencies(i);return-1==f.indexOf(i)&&f.unshift(i),this._update(f),i},Ot.prototype.insertAfter=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';return r==this.lastNode?this.append(e):this.insertBefore(t+1,e)},Ot.prototype.remove=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';var r=this.getDependencies(e),n=t.previousNode,i=t.nextNode;n?n.nextNode=i:this.firstNode=i,i?i.previousNode=n:this.lastNode=n;var a=n?n.scope:this.scope;i&&(i.scope.parentScope=a),delete this.nodes[e],this._update(r)},Ot.prototype.replace=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var n=[t];Ot._merge(n,this.getDependencies(t));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(e),Ot._merge(n,this.getDependencies(t)),this._update(n)},Ot.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)},Ot.Node.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse()},Ot.Node.prototype.getExpr=function(){return this.expression},Ot.Node.prototype.getResult=function(){return this.result},Ot.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 dt(t)}},Ot.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},Ot._merge=function(e,t){for(var r=0,n=t.length;n>r;r++){var i=t[r];-1==e.indexOf(i)&&e.push(i)}},Ot.prototype.getDependencies=function(e){var t,r=[],n=this.nodes[e];if(n){var i=n.scope.defs,a=n.scope.updates,s=[];for(t in i)i.hasOwnProperty(t)&&s.push(t);for(t in a)a.hasOwnProperty(t)&&-1==s.indexOf(t)&&s.push(t);for(var o=n.nextNode;o&&s.length;){for(var f=o.scope,u=0;s.length>u;){if(t=s[u],(f.hasLink(t)||f.hasUpdate(t))&&-1==r.indexOf(o.id)){r.push(o.id);var h=this.getDependencies(o.id);Ot._merge(r,h)}f.hasDef(t)&&(s.splice(u,1),u--),u++}o=o.nextNode}}return r},Ot.prototype.getExpr=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getExpr()},Ot.prototype.getResult=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getResult()},Ot.prototype._update=function(e){this.updateSeq++;for(var t=this.updateSeq,r=this.nodes,n=0,i=e.length;i>n;n++){var a=e[n],s=r[a];s&&(s.eval(),s.updateSeq=t)}},Ot.prototype.getChanges=function(e){var t=[],r=this.firstNode;for(e=e||0;r;)r.updateSeq>e&&t.push(r.id),r=r.nextNode;return{ids:t,updateSeq:this.updateSeq}},Ot.prototype._getNewId=function(){return this.idMax++,this.idMax},Ot.prototype.toString=function(){return JSON.stringify(this.toJSON())},Ot.prototype.toJSON=function(){for(var e=[],t=this.firstNode;t;){var r={id:t.id,expression:t.expression,dependencies:this.getDependencies(t.id)};try{r.result=t.getResult()}catch(n){r.result="Error: "+((n.message||n)+"")}e.push(r),t=t.nextNode}return e}})(); \ No newline at end of file +(function(){function e(t,n){if(this.constructor!=e)throw new SyntaxError("Complex constructor must be called with the new operator");switch(arguments.length){case 2:if(!r(t)||!r(n))throw new TypeError("Two numbers or a single string expected in Complex constructor");this.re=t,this.im=n;break;case 1:if(!a(t))throw new TypeError("Two numbers or a single string expected in Complex constructor");var i=e.parse(t);if(i)return i;throw new SyntaxError('String "'+t+'" is no valid complex number');case 0:this.re=0,this.im=0;break;default:throw new SyntaxError("Wrong number of arguments in Complex constructor ("+arguments.length+" provided, 0, 1, or 2 expected)")}}function t(e){if(this.constructor!=t)throw new SyntaxError("Matrix constructor must be called with the new operator");this._data=e instanceof t||e instanceof s||e instanceof i?e.toArray():e instanceof Array?e:null!=e?[e]:[],this._size=bt.size(this._data)}function r(e){return e instanceof Number||"number"==typeof e}function n(e){return e==Math.round(e)}function i(e,t,n){if(this.constructor!=i)throw new SyntaxError("Range constructor must be called with the new operator");if(null==n&&(n=t,t=null),2!=arguments.length&&3!=arguments.length)throw new TypeError("Wrong number of parameters in Range constructor (2 or 3 expected, "+arguments.length+" provided)");if(null!=e&&!r(e))throw new TypeError("Parameter start must be a number");if(null!=n&&!r(n))throw new TypeError("Parameter end must be a number");if(null!=t&&!r(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 a(e){return e instanceof String||"string"==typeof e}function o(e,t){if(this.constructor!=o)throw Error("Unit constructor must be called with the new operator");this.value=1,this.unit=o.UNIT_NONE,this.prefix=o.PREFIX_NONE,this.hasUnit=!1,this.hasValue=!1,this.fixPrefix=!1;var r=arguments.length;if(0==r);else{if(1==r){if(!a(e))throw new TypeError("A string or a number and string expected in Unit constructor");var n=o.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid unit')}if(2!=r)throw Error("Too many parameters in Unit constructor, 1 or 2 expected");if(!a(t))throw Error("Second parameter in Unit constructor must be a String");for(var i=o.UNITS,s=!1,f=0,u=i.length;u>f;f++){var h=i[f];if(o.endsWith(t,h.name)){var c=t.length-h.name.length,l=t.substring(0,c),p=h.prefixes[l];if(void 0!==p){this.unit=h,this.prefix=p,this.hasUnit=!0,s=!0;break}}}if(!s)throw Error('String "'+t+'" is no unit');null!=e?(this.value=this._normalize(e),this.hasValue=!0):this.value=this._normalize(1)}}function s(e){if(this.constructor!=s)throw new SyntaxError("Vector constructor must be called with the new operator");if(this._data=e instanceof t?e.toVector():e instanceof s||e instanceof i?e.toArray():e instanceof Array?e:null!=e?[e]:[],this._size=bt.size(this._data),this._size.length>1)throw Error("Vector can only contain one dimension (size: "+st(this._size)+")")}function f(e,t){var r=void 0;if(2==arguments.length){var n=lt(t);r="Function "+e+" does not support a parameter of type "+n}else if(arguments.length>2){for(var i=[],a=1;arguments.length>a;a++)i.push(lt(arguments[a]));r="Function "+e+" does not support a parameters of type "+i.join(", ")}else r="Unsupported parameter in function "+e;return new TypeError(r)}function u(e,t,r,n){var i="Wrong number of arguments in function "+e+" ("+t+" provided, "+r+(void 0!=n?"-"+n:"")+" expected)";return new SyntaxError(i)}function h(t){if(1!=arguments.length)throw u("abs",arguments.length,1);if(r(t))return Math.abs(t);if(t instanceof e)return Math.sqrt(t.re*t.re+t.im*t.im);if(t instanceof Array)return bt.map(t,h);if(t.valueOf()!==t)return h(t.valueOf());throw f("abs",t)}function c(t,n){if(2!=arguments.length)throw u("add",arguments.length,2);if(r(t)){if(r(n))return t+n;if(n instanceof e)return new e(t+n.re,n.im)}else if(t instanceof e){if(r(n))return new e(t.re+n,t.im);if(n instanceof e)return new e(t.re+n.re,t.im+n.im)}else if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Units do not match");if(!t.hasValue)throw Error("Unit on left hand side of operator + has no value");if(!n.hasValue)throw Error("Unit on right hand side of operator + has no value");var i=t.clone();return i.value+=n.value,i.fixPrefix=!1,i}if(a(t)||a(n))return t+n;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,c);if(t.valueOf()!==t)return c(t.valueOf());throw f("add",t,n)}function l(t){if(1!=arguments.length)throw u("ceil",arguments.length,1);if(r(t))return Math.ceil(t);if(t instanceof e)return new e(Math.ceil(t.re),Math.ceil(t.im));if(t instanceof Array)return bt.map(t,l);if(t.valueOf()!==t)return l(t.valueOf());throw f("ceil",t)}function p(t){if(1!=arguments.length)throw u("cube",arguments.length,1);if(r(t))return t*t*t;if(t instanceof e)return M(M(t,t),t);if(t instanceof Array)return M(M(t,t),t);if(t.valueOf()!==t)return p(t.valueOf());throw f("cube",t)}function m(t,n){if(2!=arguments.length)throw u("divide",arguments.length,2);if(r(t)){if(r(n))return t/n;if(n instanceof e)return v(new e(t,0),n)}if(t instanceof e){if(r(n))return v(t,new e(n,0));if(n instanceof e)return v(t,n)}if(t instanceof o&&r(n)){var i=t.clone();return i.value/=n,i}if(t instanceof Array&&!(n instanceof Array))return bt.map2(t,n,m);if(t.valueOf()!==t||n.valueOf()!==n)return m(t.valueOf(),n.valueOf());throw f("divide",t,n)}function v(t,r){var n=r.re*r.re+r.im*r.im;return new e((t.re*r.re+t.im*r.im)/n,(t.im*r.re-t.re*r.im)/n)}function d(t,n){if(2!=arguments.length)throw u("equal",arguments.length,2);if(r(t)){if(r(n))return t==n;if(n instanceof e)return t==n.re&&0==n.im}if(t instanceof e){if(r(n))return t.re==n&&0==t.im;if(n instanceof e)return t.re==n.re&&t.im==n.im}if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value==n.value}if(a(t)||a(n))return t==n;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,d);if(t.valueOf()!==t||n.valueOf()!==n)return d(t.valueOf(),n.valueOf());throw f("equal",t,n)}function g(t){if(1!=arguments.length)throw u("exp",arguments.length,1);if(r(t))return Math.exp(t);if(t instanceof e){var n=Math.exp(t.re);return new e(n*Math.cos(t.im),n*Math.sin(t.im))}if(t instanceof Array)return bt.map(t,g);if(t.valueOf()!==t)return g(t.valueOf());throw f("exp",t)}function y(t){if(1!=arguments.length)throw u("fix",arguments.length,1);if(r(t))return value>0?Math.floor(t):Math.ceil(t);if(t instanceof e)return new e(t.re>0?Math.floor(t.re):Math.ceil(t.re),t.im>0?Math.floor(t.im):Math.ceil(t.im));if(t instanceof Array)return bt.map(t,y);if(t.valueOf()!==t)return y(t.valueOf());throw f("fix",t)}function x(t){if(1!=arguments.length)throw u("floor",arguments.length,1);if(r(t))return Math.floor(t);if(t instanceof e)return new e(Math.floor(t.re),Math.floor(t.im));if(t instanceof Array)return bt.map(t,x);if(t.valueOf()!==t)return x(t.valueOf());throw f("floor",t)}function w(t,n){if(2!=arguments.length)throw u("larger",arguments.length,2);if(r(t)){if(r(n))return t>n;if(n instanceof e)return t>h(n)}if(t instanceof e){if(r(n))return h(t)>n;if(n instanceof e)return h(t)>h(n)}if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value>n.value}if(a(t)||a(n))return t>n;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,d);if(t.valueOf()!==t||n.valueOf()!==n)return w(t.valueOf(),n.valueOf());throw f("larger",t,n)}function E(t,n){if(2!=arguments.length)throw u("largereq",arguments.length,2);if(r(t)){if(r(n))return t>=n;if(n instanceof e)return t>=h(n)}if(t instanceof e){if(r(n))return h(t)>=n;if(n instanceof e)return h(t)>=h(n)}if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value>=n.value}if(a(t)||a(n))return t>=n;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,E);if(t.valueOf()!==t||n.valueOf()!==n)return E(t.valueOf(),n.valueOf());throw f("largereq",t,n)}function N(t,n){if(1!=arguments.length&&2!=arguments.length)throw u("log",arguments.length,1,2);if(void 0!==n)return m(N(t),N(n));if(r(t))return t>=0?Math.log(t):N(new e(t,0));if(t instanceof e)return new e(Math.log(Math.sqrt(t.re*t.re+t.im*t.im)),Math.atan2(t.im,t.re));if(t instanceof Array)return bt.map(t,N);if(t.valueOf()!==t||n.valueOf()!==n)return N(t.valueOf(),n.valueOf());throw f("log",t,n)}function O(t){if(1!=arguments.length)throw u("log10",arguments.length,1);if(r(t))return t>=0?Math.log(t)/Math.LN10:O(new e(t,0));if(t instanceof e)return new e(Math.log(Math.sqrt(t.re*t.re+t.im*t.im))/Math.LN10,Math.atan2(t.im,t.re)/Math.LN10);if(t instanceof Array)return bt.map(t,O);if(t.valueOf()!==t)return O(t.valueOf());throw f("log10",t)}function b(t,n){if(2!=arguments.length)throw u("mod",arguments.length,2);if(r(t)){if(r(n))return t%n;if(n instanceof e&&0==n.im)return t%n.re}else if(t instanceof e&&0==t.im){if(r(n))return t.re%n;if(n instanceof e&&0==n.im)return t.re%n.re}if(t instanceof Array||n instanceof Array)return bt.map2(t,n,b);if(t.valueOf()!==t||n.valueOf()!==n)return b(t.valueOf(),n.valueOf());throw f("mod",t,n)}function M(t,n){if(2!=arguments.length)throw u("multiply",arguments.length,2);if(r(t)){if(r(n))return t*n;if(n instanceof e)return T(new e(t,0),n);if(n instanceof o)return s=n.clone(),s.value*=t,s}else if(t instanceof e){if(r(n))return T(t,new e(n,0));if(n instanceof e)return T(t,n)}else if(t instanceof o){if(r(n))return s=t.clone(),s.value*=n,s}else if(t instanceof Array){if(n instanceof Array){var i=bt.size(t),a=bt.size(n);if(2!=i.length)throw Error("Can only multiply a 2 dimensional matrix (A has "+i.length+" dimensions)");if(2!=a.length)throw Error("Can only multiply a 2 dimensional matrix (B has "+a.length+" dimensions)");if(i[1]!=a[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+i[0]+"x"+i[1]+", B is "+a[0]+"x"+a[1]+", "+a[1]+" != "+a[0]+")");for(var s=[],h=i[0],l=a[1],p=i[1],m=0;h>m;m++){s[m]=[];for(var v=0;l>v;v++){for(var d=null,g=0;p>g;g++){var y=M(t[m][g],n[g][v]);d=null==d?y:c(d,y)}s[m][v]=d}}return s}return bt.map2(t,n,M)}if(n instanceof Array)return bt.map2(t,n,M);if(t.valueOf()!==t||n.valueOf()!==n)return M(t.valueOf(),n.valueOf());throw f("multiply",t,n)}function T(t,r){return new e(t.re*r.re-t.im*r.im,t.re*r.im+t.im*r.re)}function A(t,i){if(2!=arguments.length)throw u("pow",arguments.length,2);if(r(t)){if(r(i))return n(i)||t>=0?Math.pow(t,i):S(new e(t,0),new e(i,0));if(i instanceof e)return S(new e(t,0),i)}else if(t instanceof e){if(r(i))return S(t,new e(i,0));if(i instanceof e)return S(t,i)}else if(t instanceof Array){if(!r(i)||!n(i)||0>i)throw new TypeError("For A^b, b must be a positive integer (value is "+i+")");var a=bt.size(t);if(2!=a.length)throw Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==i)return Y(a[0]);for(var o=t,s=1;i>s;s++)o=M(t,o);return o}if(t.valueOf()!==t||i.valueOf()!==i)return A(t.valueOf(),i.valueOf());throw f("pow",t,i)}function S(e,t){var r=N(e),n=M(r,t);return g(n)}function _(t,n){if(1!=arguments.length&&2!=arguments.length)throw u("round",arguments.length,1,2);if(void 0==n){if(r(t))return Math.round(t);if(t instanceof e)return new e(Math.round(t.re),Math.round(t.im));if(t instanceof Array&&bt.map(t,_),t.valueOf()!==t)return _(t.valueOf());throw f("round",t)}if(!r(n))throw new TypeError("Number of digits in function round must be an integer");if(n!==Math.round(n))throw new TypeError("Number of digits in function round must be integer");if(0>n||n>9)throw Error("Number of digits in function round must be in te range of 0-9");if(r(t))return k(t,n);if(t instanceof e)return new e(k(t.re,n),k(t.im,n));if(t instanceof Array||n instanceof Array)return bt.map2(t,n,_);if(t.valueOf()!==t||n.valueOf()!==n)return w(t.valueOf(),n.valueOf());throw f("round",t,n)}function k(e,t){var r=Math.pow(10,void 0!=t?t:Ot.options.precision);return Math.round(e*r)/r}function U(t){if(1!=arguments.length)throw u("sign",arguments.length,1);if(r(t)){var n;return n=t>0?1:0>t?-1:0}if(t instanceof e){var i=Math.sqrt(t.re*t.re+t.im*t.im);return new e(t.re/i,t.im/i)}if(t instanceof Array)return bt.map(t,n);if(t.valueOf()!==t)return n(t.valueOf());throw f("sign",t)}function q(t,n){if(2!=arguments.length)throw u("smaller",arguments.length,2);if(r(t)){if(r(n))return n>t;if(n instanceof e)return h(n)>t}if(t instanceof e){if(r(n))return n>h(t);if(n instanceof e)return h(t)t;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,q);if(t.valueOf()!==t||n.valueOf()!==n)return q(t.valueOf(),n.valueOf());throw f("smaller",t,n)}function L(t,n){if(2!=arguments.length)throw u("smallereq",arguments.length,2);if(r(t)){if(r(n))return n>=t;if(n instanceof e)return h(n)>=t}if(t instanceof e){if(r(n))return n>=h(t);if(n instanceof e)return h(t)<=h(n)}if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value<=n.value}if(a(t)||a(n))return n>=t;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,L);if(t.valueOf()!==t||n.valueOf()!==n)return L(t.valueOf(),n.valueOf());throw f("smallereq",t,n)}function R(t){if(1!=arguments.length)throw u("sqrt",arguments.length,1);if(r(t))return t>=0?Math.sqrt(t):R(new e(t,0));if(t instanceof e){var n=Math.sqrt(t.re*t.re+t.im*t.im);return t.im>=0?new e(.5*Math.sqrt(2*(n+t.re)),.5*Math.sqrt(2*(n-t.re))):new e(.5*Math.sqrt(2*(n+t.re)),-.5*Math.sqrt(2*(n-t.re)))}if(t instanceof Array)return bt.map(t,R);if(t.valueOf()!==t)return R(t.valueOf());throw f("sqrt",t)}function C(t){if(1!=arguments.length)throw u("square",arguments.length,1);if(r(t))return t*t;if(t instanceof e)return M(t,t);if(t instanceof Array)return M(t,t);if(t.valueOf()!==t)return C(t.valueOf());throw f("square",t)}function I(t,n){if(2!=arguments.length)throw u("subtract",arguments.length,2);if(r(t)){if(r(n))return t-n;if(n instanceof e)return new e(t-n.re,n.im)}else if(t instanceof e){if(r(n))return new e(t.re-n,t.im);if(n instanceof e)return new e(t.re-n.re,t.im-n.im)}else if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Units do not match");if(!t.hasValue)throw Error("Unit on left hand side of operator - has no value");if(!n.hasValue)throw Error("Unit on right hand side of operator - has no value");var i=t.clone();return i.value-=n.value,i.fixPrefix=!1,i}if(t instanceof Array||n instanceof Array)return bt.map2(t,n,I);if(t.valueOf()!==t||n.valueOf()!==n)return I(t.valueOf(),n.valueOf());throw f("subtract",t,n)}function z(t){if(1!=arguments.length)throw u("unaryminus",arguments.length,1);if(r(t))return-t;if(t instanceof e)return new e(-t.re,-t.im);if(t instanceof o){var n=t.clone();return n.value=-t.value,n}if(t instanceof Array)return bt.map(t,z);if(t.valueOf()!==t)return z(t.valueOf());throw f("unaryminus",t)}function P(t,n){if(2!=arguments.length)throw u("unequal",arguments.length,2);if(r(t)){if(r(n))return t==n;if(n instanceof e)return t==n.re&&0==n.im}if(t instanceof e){if(r(n))return t.re==n&&0==t.im;if(n instanceof e)return t.re==n.re&&t.im==n.im}if(t instanceof o&&n instanceof o){if(!t.equalBase(n))throw Error("Cannot compare units with different base");return t.value==n.value}if(a(t)||a(n))return t==n;if(t instanceof Array||n instanceof Array)return bt.map2(t,n,P);if(t.valueOf()!==t||n.valueOf()!==n)return P(t.valueOf(),n.valueOf());throw f("unequal",t,n)}function B(t){if(1!=arguments.length)throw u("arg",arguments.length,1);if(r(t))return Math.atan2(0,t);if(t instanceof e)return Math.atan2(t.im,t.re);if(t instanceof Array)return bt.map(t,B);if(t.valueOf()!==t)return B(t.valueOf());throw f("arg",t)}function D(t){if(1!=arguments.length)throw u("conj",arguments.length,1);if(r(t))return t;if(t instanceof e)return new e(t.re,-t.im);if(t instanceof Array)return bt.map(t,D);if(t.valueOf()!==t)return D(t.valueOf());throw f("conj",t)}function G(t){if(1!=arguments.length)throw u("im",arguments.length,1);if(r(t))return 0;if(t instanceof e)return t.im;if(t instanceof Array)return bt.map(t,G);if(t.valueOf()!==t)return G(t.valueOf());throw f("im",t)}function V(t){if(1!=arguments.length)throw u("re",arguments.length,1);if(r(t))return t;if(t instanceof e)return t.re;if(t instanceof Array)return bt.map(t,V);if(t.valueOf()!==t)return V(t.valueOf());throw f("re",t)}function Y(e,t){var i,a,o=arguments.length;if(0>o||o>2)throw u("eye",o,0,2);if(0==o)return 1;if(1==o?(i=e,a=e):2==o&&(i=e,a=t),!r(i)||!n(i)||1>i)throw Error("Parameters in function eye must be positive integers");if(a&&(!r(a)||!n(a)||1>a))throw Error("Parameters in function eye must be positive integers");for(var s=[],f=0;i>f;f++){for(var h=[],c=0;a>c;c++)h[c]=0;s[f]=h}for(var l=Math.min(i,a),p=0;l>p;p++)s[p][p]=1;return s}function F(n){if(1!=arguments.length)throw u("size",arguments.length,1);if(r(n)||n instanceof e||n instanceof o||null==n)return[];if(a(n))return[n.length];if(n instanceof Array)return bt.size(n);if(n instanceof t||n instanceof s||n instanceof i)return n.size();if(n.valueOf()!==n)return F(n.valueOf());throw f("size",n)}function j(e){if(1!=arguments.length)throw u("factorial",arguments.length,1);if(r(e)){if(!n(e))throw new TypeError("Function factorial can only handle integer values");var t=e,i=t;for(t--;t>1;)i*=t,t--;return 0==i&&(i=1),i}if(e instanceof Array)return bt.map(e,j);if(e.valueOf()!==e)return j(e.valueOf());throw f("factorial",e)}function H(){if(0!=arguments.length)throw u("random",arguments.length,0);return Math.random()}function K(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 K.apply(this,e.valueOf());for(var t=arguments[0],r=1,n=arguments.length;n>r;r++){var i=arguments[r];w(i,t)&&(t=i)}return t}function W(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 W.apply(this,e.valueOf());for(var t=arguments[0],r=1,n=arguments.length;n>r;r++){var i=arguments[r];q(i,t)&&(t=i)}return t}function X(t){if(1!=arguments.length)throw u("acos",arguments.length,1);if(r(t))return t>=-1&&1>=t?Math.acos(t):X(new e(t,0));if(t instanceof e){var n=new e(t.im*t.im-t.re*t.re+1,-2*t.re*t.im),i=R(n),a=new e(i.re-t.im,i.im+t.re),o=N(a);return new e(1.5707963267948966-o.im,o.re)}if(t instanceof Array)return bt.map(t,X);if(t.valueOf()!==t)return X(t.valueOf());throw f("acos",t)}function Z(t){if(1!=arguments.length)throw u("asin",arguments.length,1);if(r(t))return t>=-1&&1>=t?Math.asin(t):Z(new e(t,0));if(t instanceof e){var n=t.re,i=t.im,a=new e(i*i-n*n+1,-2*n*i),o=R(a),s=new e(o.re-i,o.im+n),h=N(s);return new e(h.im,-h.re)}if(t instanceof Array)return bt.map(t,Z);if(t.valueOf()!==t)return Z(t.valueOf());throw f("asin",t)}function Q(t){if(1!=arguments.length)throw u("atan",arguments.length,1);if(r(t))return Math.atan(t);if(t instanceof e){var n=t.re,i=t.im,a=n*n+(1-i)*(1-i),o=new e((1-i*i-n*n)/a,-2*n/a),s=N(o);return new e(-.5*s.im,.5*s.re)}if(t instanceof Array)return bt.map(t,Q);if(t.valueOf()!==t)return Q(t.valueOf());throw f("atan",t)}function J(t,n){if(2!=arguments.length)throw u("atan2",arguments.length,2);if(r(t)){if(r(n))return Math.atan2(t,n);if(n instanceof e)return Math.atan2(t,n.re)}else if(t instanceof e){if(r(n))return Math.atan2(t.re,n);if(n instanceof e)return Math.atan2(t.re,n.re)}if(n instanceof Array||t instanceof Array)return bt.map2(t,n,J);if(n.valueOf()!==n||t.valueOf()!==t)return J(t.valueOf(),n.valueOf());throw f("atan2",t,n)}function $(t){if(1!=arguments.length)throw u("cos",arguments.length,1);if(r(t))return Math.cos(t);if(t instanceof e)return new e(.5*Math.cos(t.re)*(Math.exp(-t.im)+Math.exp(t.im)),.5*Math.sin(t.re)*(Math.exp(-t.im)-Math.exp(t.im)));if(t instanceof o){if(!t.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(t.value)}if(t instanceof Array)return bt.map(t,$);if(t.valueOf()!==t)return $(t.valueOf());throw f("cos",t)}function et(t){if(1!=arguments.length)throw u("cot",arguments.length,1);if(r(t))return 1/Math.tan(t);if(t instanceof e){var n=Math.exp(-4*t.im)-2*Math.exp(-2*t.im)*Math.cos(2*t.re)+1;return new e(2*Math.exp(-2*t.im)*Math.sin(2*t.re)/n,(Math.exp(-4*t.im)-1)/n)}if(t instanceof o){if(!t.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(t.value)}if(t instanceof Array)return bt.map(t,et);if(t.valueOf()!==t)return et(t.valueOf());throw f("cot",t)}function tt(t){if(1!=arguments.length)throw u("csc",arguments.length,1);if(r(t))return 1/Math.sin(t);if(t instanceof e){var n=.25*(Math.exp(-2*t.im)+Math.exp(2*t.im))-.5*Math.cos(2*t.re);return new e(.5*Math.sin(t.re)*(Math.exp(-t.im)+Math.exp(t.im))/n,.5*Math.cos(t.re)*(Math.exp(-t.im)-Math.exp(t.im))/n)}if(t instanceof o){if(!t.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(t.value)}if(t instanceof Array)return bt.map(t,tt);if(t.valueOf()!==t)return tt(t.valueOf());throw f("csc",t)}function rt(t){if(1!=arguments.length)throw u("sec",arguments.length,1);if(r(t))return 1/Math.cos(t);if(t instanceof e){var n=.25*(Math.exp(-2*t.im)+Math.exp(2*t.im))+.5*Math.cos(2*t.re);return new e(.5*Math.cos(t.re)*(Math.exp(-t.im)+Math.exp(t.im))/n,.5*Math.sin(t.re)*(Math.exp(t.im)-Math.exp(-t.im))/n)}if(t instanceof o){if(!t.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(t.value)}if(t instanceof Array)return bt.map(t,rt);if(t.valueOf()!==t)return rt(t.valueOf());throw f("sec",t)}function nt(t){if(1!=arguments.length)throw u("sin",arguments.length,1);if(r(t))return Math.sin(t);if(t instanceof e)return new e(.5*Math.sin(t.re)*(Math.exp(-t.im)+Math.exp(t.im)),.5*Math.cos(t.re)*(Math.exp(t.im)-Math.exp(-t.im)));if(t instanceof o){if(!t.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(t.value)}if(t instanceof Array)return bt.map(t,nt);if(t.valueOf()!==t)return nt(t.valueOf());throw f("sin",t)}function it(t){if(1!=arguments.length)throw u("tan",arguments.length,1);if(r(t))return Math.tan(t);if(t instanceof e){var n=Math.exp(-4*t.im)+2*Math.exp(-2*t.im)*Math.cos(2*t.re)+1;return new e(2*Math.exp(-2*t.im)*Math.sin(2*t.re)/n,(1-Math.exp(-4*t.im))/n)}if(t instanceof o){if(!t.hasBase(o.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(t.value)}if(t instanceof Array)return bt.map(t,it);if(t.valueOf()!==t)return it(t.valueOf());throw f("tan",t)}function at(e,t){if(2!=arguments.length)throw u("in",arguments.length,2);if(e instanceof o&&t instanceof o){if(!e.equalBase(t))throw Error("Units do not match");if(t.hasValue)throw Error("Cannot convert to a unit with a value");if(!t.hasUnit)throw Error("Unit expected on the right hand side of function in");var r=t.clone();return r.value=e.value,r.fixPrefix=!0,r}if(e instanceof Array||t instanceof Array)return bt.map2(e,t,at);if(e.valueOf()!==e)return Ot.in(e.valueOf());throw f("in",e)}function ot(e){if(1!=arguments.length)throw u("clone",arguments.length,1);if(null==e)return e;if("function"==typeof e.clone)return e.clone();if(r(e)||a(e))return e;if(e instanceof Array)return e.map(function(e){return ot(e)});if(e instanceof Object)return bt.map(e,ot);throw f("clone",e)}function st(e,t){var n=arguments.length;if(1!=n&&2!=n)throw u("format",n,1,2);if(1==n){var i=arguments[0];return r(i)?bt.formatNumber(i):i instanceof Array?bt.formatArray(i):a(i)?'"'+i+'"':i instanceof Object?""+i:i+""}if(!a(e))throw new TypeError("String expected as first parameter in function format");if(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,r){for(var n=r.split("."),i=t[n.shift()];n.length&&void 0!=i;){var a=n.shift();i=a?i[a]:i+"."}return void 0!=i?i:e})}function ft(e){if(1!=arguments.length)throw u("help",arguments.length,1);if(void 0!=e){if(e.doc)return ut(e.doc);if(e.constructor.doc)return ut(e.constructor.doc);if(a(e)){var t=Ot[e];if(t&&t.doc)return ut(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 ut(e){var t="";if(e.name&&(t+="NAME\n"+e.name+"\n\n"),e.category&&(t+="CATEGORY\n"+e.category+"\n\n"),e.syntax&&(t+="SYNTAX\n"+e.syntax.join("\n")+"\n\n"),e.examples){var r=new Ot.parser.Parser;t+="EXAMPLES\n";for(var n=0;e.examples.length>n;n++){var i,a=e.examples[n];try{i=r.eval(a)}catch(o){i=o}t+=a+"\n",t+=" "+Ot.format(i)+"\n"}t+="\n"}return e.seealso&&(t+="SEE ALSO\n"+e.seealso.join(", ")+"\n"),t}function ht(e,t){var r;if(a(e)){if("undefined"==typeof require)throw Error("Cannot load file: require not available.");var n=require(e);ht(n)}else if(ct(e)){if(r=e.name,!r)throw Error("Cannot import an unnamed function");(t||void 0===Ot[r])&&(Ot[r]=e)}else if(e instanceof Object)for(r in e)if(e.hasOwnProperty(r)){var i=e[r];ct(i)?(t||void 0===Ot[r])&&(Ot[r]=i):ht(i)}}function ct(t){return"function"==typeof t||r(t)||a(t)||t instanceof e||t instanceof o}function lt(e){if(1!=arguments.length)throw u("typeof",arguments.length,1);var t=typeof e;if("object"==t){if(null==e)return"null";if(e.constructor){for(var r in Ot)if(Ot.hasOwnProperty(r)&&e.constructor==Ot[r])return r.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return t}function pt(){}function mt(e,t,r){this.name=e,this.fn=t,this.params=r}function vt(e){this.value=e}function dt(e){this.nodes=e||[]}function gt(){this.params=[],this.visible=[]}function yt(e,t,r,n){this.name=e,this.params=t,this.expr=r,this.result=n}function xt(e,t,r,n,i){this.name=e,this.variables=r,this.values=[];for(var a=0,o=this.variables.length;o>a;a++)this.values[a]=function(){var e=function(){return e.value};return e.value=void 0,e}();this.def=this.createFunction(e,t,r,n),this.result=i}function wt(e){this.parentScope=e,this.nestedScopes=void 0,this.symbols={},this.defs={},this.updates={},this.links={}}function Et(){if(this.constructor!=Et)throw new SyntaxError("Parser constructor must be called with the new operator");this.TOKENTYPE={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},this.expr="",this.index=0,this.c="",this.token="",this.token_type=this.TOKENTYPE.NULL,this.scope=new wt}function Nt(){this.idMax=-1,this.updateSeq=0,this.parser=new Et,this.scope=new wt,this.nodes={},this.firstNode=void 0,this.lastNode=void 0}var Ot={parser:{node:{}},options:{precision:10}};"undefined"!=typeof module&&module.exports!==void 0&&(module.exports=Ot),"undefined"!=typeof exports&&(exports=Ot),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return Ot}),"undefined"!=typeof window&&(window.math=Ot);var bt=function(){function e(e){if(e instanceof Array){var t=e.length;if(t){var r=f(e[0]);return 0==r[0]?[0].concat(r):[t].concat(r)}return[t]}return[]}function t(e,r,n){var i,a=e.length;if(a!=r[n])throw new RangeError("Dimension mismatch ("+a+" != "+r[n]+")");if(r.length-1>n){var o=n+1;for(i=0;a>i;i++){var s=e[i];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(r.length-1)+" < "+r.length+")");t(e[i],r,o)}}else for(i=0;a>i;i++)if(e[i]instanceof Array)throw new RangeError("Dimension mismatch ("+(r.length+1)+" > "+r.length+")")}function i(e,t,r){if(t.length-1>r){var n=e[0];if(1!=e.length||!(n instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");i(n,t,r+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,t,r,n){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=t[r];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=n?ot(n):0;else e.length=t[r];i=e.length}if(t.length-1>r){var f=r+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,t,f,n)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var o={};return o.formatNumber=function(e,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(0/0===e)return"NaN";var r=Math.abs(e);if(r>1e-4&&1e6>r||0==r)return k(e,t)+"";var n=Math.round(Math.log(r)/Math.LN10),i=e/Math.pow(10,n);return k(i,t)+"E"+n},o.formatArray=function s(e){if(e instanceof Array){for(var t="[",r=e.length,n=0;r>n;n++)0!=n&&(t+=", "),t+=s(e[n]);return t+="]"}return st(e)},o.formatArray2d=function(e){var t="[",r=o.size(e);if(2!=r.length)throw new RangeError("Array must be two dimensional (size: "+s(r)+")");for(var n=r[0],i=r[1],a=0;n>a;a++){0!=a&&(t+="; ");for(var f=e[a],u=0;i>u;u++){0!=u&&(t+=", ");var h=f[u];void 0!=h&&(t+=st(h))}}return t+="]"},o.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},o.map=function(e,t){if(!e instanceof Array)throw new TypeError("Array expected");return e.map(function(e){return t(e)})},o.map2=function(e,t,r){var n,i,a;if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(n=[],i=e.length,a=0;i>a;a++)n[a]=r(e[a],t[a])}else for(n=[],i=e.length,a=0;i>a;a++)n[a]=r(e[a],t);else if(t instanceof Array)for(n=[],i=t.length,a=0;i>a;a++)n[a]=r(e,t[a]);else n=r(e,t);return n},o.forEach=function(e,t){if(e instanceof Array)e.forEach(t);else for(var r in e)e.hasOwnProperty(r)&&t(e[r],r,e)},o.map=function(e,t){if(e instanceof Array)return e.map(t);var r={};for(var n in e)e.hasOwnProperty(n)&&(r[n]=t(e[n]));return r},o.size=function f(t){var r=e(t);return o.validate(t,r),r},o.validate=function(e,r){var n=0==r.length;if(n){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var a=-1!=r.indexOf(0);a?(r.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+s(r)+")")}),i(e,r,0)):t(e,r,0)}},o.resize=function(e,t,i){if(!(t instanceof Array))throw new TypeError("Size must be an array (size is "+type(t)+")");t.forEach(function(e){if(!r(e)||!n(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+s(t)+")")});var o=-1!=t.indexOf(0);o&&t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+s(t)+")")}),a(e,t,0,i)},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;this.length>t;t++)if(this[t]==e)return t;return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var r=0,n=this.length;n>r;++r)e.call(t||this,this[r],r,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var r,n,i;if(null==this)throw new TypeError(" this is null or not defined");var a=Object(this),o=a.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(t&&(r=t),n=Array(o),i=0;o>i;){var s,f;i in a&&(s=a[i],f=e.call(r,s,i,a),n[i]=f),i++}return n}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),r=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var n=arguments[1],i=0;r>i;i++)if(i in t&&!e.call(n,t[i],i,t))return!1;return!0}),o}();Ot.Complex=e,function(){function t(){for(;" "==c||" "==c;)i()}function r(e){return e>="0"&&"9">=e||"."==e}function n(e){return e>="0"&&"9">=e}function i(){h++,c=u[h]}function o(e){h=e,c=u[h]}function s(){var e="",t=h;if("+"==c?i():"-"==c&&(e+=c,i()),!r(c))return o(t),null;for(;r(c);)e+=c,i();if("E"==c||"e"==c){if(e+=c,i(),("+"==c||"-"==c)&&(e+=c,i()),!n(c))return o(t),null;for(;n(c);)e+=c,i()}return e}function f(){var e=u[h+1];if("I"==c||"i"==c)return i(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var t="+"==c?"1":"-1"; +return i(),i(),t}return null}var u,h,c;e.parse=function(r){if(u=r,h=-1,c="",!a(u))return null;i(),t();var n=s();if(n){if("I"==c||"i"==c)return i(),t(),c?null:new e(0,Number(n));t();var o=c;if("+"!=o&&"-"!=o)return t(),c?null:new e(Number(n),0);i(),t();var l=s();if(l){if("I"!=c&&"i"!=c)return null;i()}else if(l=f(),!l)return null;return"-"==o&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),i(),t(),c?null:new e(Number(n),Number(l))}return(n=f())?(t(),c?null:new e(0,Number(n))):null}}(),e.prototype.clone=function(){return new e(this.re,this.im)},e.prototype.toString=function(){var e="",t=bt.formatNumber(this.re),r=bt.formatNumber(this.im);return e=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":r+"i":this.im>0?1==this.im?t+" + i":t+" + "+r+"i":-1==this.im?t+" - i":t+" - "+bt.formatNumber(Math.abs(this.im))+"i"},e.doc={name:"Complex",category:"type",syntax:["a + bi","a + b * i"],description:"A complex value a + bi, where a is the real part and b is the complex part, and i is the imaginary number defined as sqrt(-1).",examples:["2 + 3i","sqrt(-4)","(1.2 -5i) * 2"],seealso:["abs","arg","conj","im","re"]},Ot.Matrix=t,t.prototype.get=function(e){if(e instanceof t){if(!e.isVector())throw new RangeError("Index must be a vector (size: "+st(e.size())+")");e=e.toVector()}if(e instanceof s&&(e=e.valueOf()),e instanceof Array){if(e.length!=this._size.length)throw new RangeError("Number of dimensions do not match ("+e.length+" != "+this._size.length+")");var i=this._data;return e.forEach(function(e){if(!r(e)||!n(e)||0>e)throw new TypeError("Positive integer expected as index in method get");if(e>i.length-1)throw new RangeError("Index out of range ("+e+")");i=i[e]}),i}throw new TypeError("Unsupported type of index "+type(e))},t.prototype.set=function(e,a){if(e instanceof t){if(!e.isVector())throw new RangeError("Index must be a vector (size: "+st(e.size())+")");e=e.toVector()}if(e instanceof s&&(e=e.valueOf()),(a instanceof t||a instanceof s||a instanceof i)&&(a=a.valueOf()),!(e instanceof Array))throw new TypeError("Unsupported type of index "+type(e));if(a instanceof Array)throw Error("Setting a range of values is not yet implemented...");if(e.length!=this._size.length)throw new RangeError("Number of dimensions do not match ("+e.length+" != "+this._size.length+")");for(var o=this._size.concat([]),f=!1,u=0;o.length>u;u++){var h=e[u];if(!r(h)||!n(h)||0>h)throw new TypeError("Positive integer expected as index in method get");e[u]>o[u]&&(o[u]=h,f=!0)}f&&this.resize(o);var c=o.length,l=this._data;e.forEach(function(e,t){c-1>t?l=l[e]:l[e]=a})},t.prototype.resize=function(e,t){bt.resize(this._data,e,t),this._size=ot(e)},t.prototype.clone=function(){var e=new t;return e._data=ot(this._data),e},t.prototype.size=function(){return this._size},t.prototype.toScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0];return e instanceof Array?null:e},t.prototype.isScalar=function(){return this._size.every(function(e){return 1>=e})},t.prototype.toVector=function(){var e=0,t=void 0,r=[];if(this._size.forEach(function(n,i){n>1&&(e++,t=i),r[i]=0}),0==e)return new s(this.toScalar());if(1==e){for(var n=[],i=0,a=this._size[t];a>i;i++)r[t]=i,n[i]=this.get(r);return new s(n)}return null},t.prototype.isVector=function(){var e=0;return this._size.forEach(function(t){t>1&&e++}),1>=e},t.prototype.toArray=function(){return ot(this._data)},t.prototype.valueOf=function(){return this._data},t.prototype.toString=function(){return bt.formatArray(this._data)},Ot.Range=i,i.prototype.clone=function(){return new i(this.start,this.step,this.end)},i.prototype.size=function(){var e=0,t=Number(this.start),r=Number(this.step),n=Number(this.end),i=n-t;return U(r)==U(i)?e=Math.floor(i/r)+1:0==i&&(e=1),isNaN(e)&&(e=0),[e]},i.prototype.forEach=function(e){var t=Number(this.start),r=Number(this.step),n=Number(this.end),i=0;if(r>0)for(;n>=t;)e(t,i),t+=r,i++;else if(0>r)for(;t>=n;)e(t,i),t+=r,i++},i.prototype.map=function(e){var t=[];return this.forEach(function(r,n){t[n]=e(r)}),t},i.prototype.toVector=function(){return new s(this.toArray())},i.prototype.toArray=function(){var e=[];return this.forEach(function(t,r){e[r]=t}),e},i.prototype.valueOf=function(){return this.toArray()},i.prototype.toString=function(){var e=st(Number(this.start));return 1!=this.step&&(e+=":"+st(Number(this.step))),e+=":"+st(Number(this.end))},Ot.Unit=o,function(){function e(){for(;" "==c||" "==c;)n()}function t(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function n(){h++,c=u[h]}function i(e){h=e,c=u[h]}function s(){var e="",a=h;if("+"==c?n():"-"==c&&(e+=c,n()),!t(c))return i(a),null;for(;t(c);)e+=c,n();if("E"==c||"e"==c){if(e+=c,n(),("+"==c||"-"==c)&&(e+=c,n()),!r(c))return i(a),null;for(;r(c);)e+=c,n()}return e}function f(){var t="";for(e();c&&" "!=c&&" "!=c;)t+=c,n();return t||null}var u,h,c;o.parse=function(t){if(u=t,h=-1,c="",!a(u))return null;n(),e();var r,i=s();return i?(r=f(),n(),e(),c?null:i&&r?new o(Number(i),r):null):(r=f(),n(),e(),c?null:new o(null,r))}}(),o.prototype.clone=function(){var e=new o;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},o.endsWith=function(e,t){var r=e.length-t.length,n=e.length;return e.substring(r,n)===t},o.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},o.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},o.isUnit=function(e){for(var t=o.UNITS,r=t.length,n=0;r>n;n++){var i=t[n];if(o.endsWith(e,i.name)){var a=e.length-i.name.length;if(0==a)return!0;var s=e.substring(0,a),f=i.prefixes[s];if(void 0!==f)return!0}}return!1},o.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},o.prototype.equalBase=function(e){return this.unit.base===e.unit.base},o.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},o.prototype.toString=function(){var e;if(this.fixPrefix)return e=this._unnormalize(this.value),bt.formatNumber(e)+" "+this.prefix.name+this.unit.name;var t=Math.abs(this.value/this.unit.value),r=o.PREFIX_NONE,n=Math.abs(Math.log(t/r.value)/Math.LN10-1.2),i=this.unit.prefixes;for(var a in i)if(i.hasOwnProperty(a)){var s=i[a];if(s.scientific){var f=Math.abs(Math.log(t/s.value)/Math.LN10-1.2);n>f&&(r=s,n=f)}}return e=this._unnormalize(this.value,r.value),bt.formatNumber(e)+" "+r.name+this.unit.name},o.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}}},o.PREFIX_NONE={name:"",value:1,scientific:!0},o.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var Mt=o.BASE_UNITS,Tt=o.PREFIXES;o.BASE_UNIT_NONE={},o.UNIT_NONE={name:"",base:o.BASE_UNIT_NONE,value:1,offset:0},o.UNITS=[{name:"meter",base:Mt.LENGTH,prefixes:Tt.LONG,value:1,offset:0},{name:"inch",base:Mt.LENGTH,prefixes:Tt.NONE,value:.0254,offset:0},{name:"foot",base:Mt.LENGTH,prefixes:Tt.NONE,value:.3048,offset:0},{name:"yard",base:Mt.LENGTH,prefixes:Tt.NONE,value:.9144,offset:0},{name:"mile",base:Mt.LENGTH,prefixes:Tt.NONE,value:1609.344,offset:0},{name:"link",base:Mt.LENGTH,prefixes:Tt.NONE,value:.201168,offset:0},{name:"rod",base:Mt.LENGTH,prefixes:Tt.NONE,value:5.02921,offset:0},{name:"chain",base:Mt.LENGTH,prefixes:Tt.NONE,value:20.1168,offset:0},{name:"angstrom",base:Mt.LENGTH,prefixes:Tt.NONE,value:1e-10,offset:0},{name:"m",base:Mt.LENGTH,prefixes:Tt.SHORT,value:1,offset:0},{name:"ft",base:Mt.LENGTH,prefixes:Tt.NONE,value:.3048,offset:0},{name:"yd",base:Mt.LENGTH,prefixes:Tt.NONE,value:.9144,offset:0},{name:"mi",base:Mt.LENGTH,prefixes:Tt.NONE,value:1609.344,offset:0},{name:"li",base:Mt.LENGTH,prefixes:Tt.NONE,value:.201168,offset:0},{name:"rd",base:Mt.LENGTH,prefixes:Tt.NONE,value:5.02921,offset:0},{name:"ch",base:Mt.LENGTH,prefixes:Tt.NONE,value:20.1168,offset:0},{name:"mil",base:Mt.LENGTH,prefixes:Tt.NONE,value:254e-7,offset:0},{name:"m2",base:Mt.SURFACE,prefixes:Tt.SHORT,value:1,offset:0},{name:"sqin",base:Mt.SURFACE,prefixes:Tt.NONE,value:64516e-8,offset:0},{name:"sqft",base:Mt.SURFACE,prefixes:Tt.NONE,value:.09290304,offset:0},{name:"sqyd",base:Mt.SURFACE,prefixes:Tt.NONE,value:.83612736,offset:0},{name:"sqmi",base:Mt.SURFACE,prefixes:Tt.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:Mt.SURFACE,prefixes:Tt.NONE,value:25.29295,offset:0},{name:"sqch",base:Mt.SURFACE,prefixes:Tt.NONE,value:404.6873,offset:0},{name:"sqmil",base:Mt.SURFACE,prefixes:Tt.NONE,value:6.4516e-10,offset:0},{name:"m3",base:Mt.VOLUME,prefixes:Tt.SHORT,value:1,offset:0},{name:"L",base:Mt.VOLUME,prefixes:Tt.SHORT,value:.001,offset:0},{name:"litre",base:Mt.VOLUME,prefixes:Tt.LONG,value:.001,offset:0},{name:"cuin",base:Mt.VOLUME,prefixes:Tt.NONE,value:16387064e-12,offset:0},{name:"cuft",base:Mt.VOLUME,prefixes:Tt.NONE,value:.028316846592,offset:0},{name:"cuyd",base:Mt.VOLUME,prefixes:Tt.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:Mt.VOLUME,prefixes:Tt.NONE,value:5e-6,offset:0},{name:"tablespoon",base:Mt.VOLUME,prefixes:Tt.NONE,value:15e-6,offset:0},{name:"minim",base:Mt.VOLUME,prefixes:Tt.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:Mt.VOLUME,prefixes:Tt.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:Mt.VOLUME,prefixes:Tt.NONE,value:2957353e-11,offset:0},{name:"gill",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0001182941,offset:0},{name:"cup",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0002365882,offset:0},{name:"pint",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0004731765,offset:0},{name:"quart",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0009463529,offset:0},{name:"gallon",base:Mt.VOLUME,prefixes:Tt.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1589873,offset:0},{name:"hogshead",base:Mt.VOLUME,prefixes:Tt.NONE,value:.238481,offset:0},{name:"fldr",base:Mt.VOLUME,prefixes:Tt.NONE,value:36966911e-13,offset:0},{name:"floz",base:Mt.VOLUME,prefixes:Tt.NONE,value:2957353e-11,offset:0},{name:"gi",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0001182941,offset:0},{name:"cp",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0002365882,offset:0},{name:"pt",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0004731765,offset:0},{name:"qt",base:Mt.VOLUME,prefixes:Tt.NONE,value:.0009463529,offset:0},{name:"gal",base:Mt.VOLUME,prefixes:Tt.NONE,value:.003785412,offset:0},{name:"bbl",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1173478,offset:0},{name:"obl",base:Mt.VOLUME,prefixes:Tt.NONE,value:.1589873,offset:0},{name:"g",base:Mt.MASS,prefixes:Tt.SHORT,value:.001,offset:0},{name:"gram",base:Mt.MASS,prefixes:Tt.LONG,value:.001,offset:0},{name:"ton",base:Mt.MASS,prefixes:Tt.SHORT,value:907.18474,offset:0},{name:"tonne",base:Mt.MASS,prefixes:Tt.SHORT,value:1e3,offset:0},{name:"grain",base:Mt.MASS,prefixes:Tt.NONE,value:6479891e-11,offset:0},{name:"dram",base:Mt.MASS,prefixes:Tt.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:Mt.MASS,prefixes:Tt.NONE,value:.028349523125,offset:0},{name:"poundmass",base:Mt.MASS,prefixes:Tt.NONE,value:.45359237,offset:0},{name:"hundredweight",base:Mt.MASS,prefixes:Tt.NONE,value:45.359237,offset:0},{name:"stick",base:Mt.MASS,prefixes:Tt.NONE,value:.115,offset:0},{name:"gr",base:Mt.MASS,prefixes:Tt.NONE,value:6479891e-11,offset:0},{name:"dr",base:Mt.MASS,prefixes:Tt.NONE,value:.0017718451953125,offset:0},{name:"oz",base:Mt.MASS,prefixes:Tt.NONE,value:.028349523125,offset:0},{name:"lbm",base:Mt.MASS,prefixes:Tt.NONE,value:.45359237,offset:0},{name:"cwt",base:Mt.MASS,prefixes:Tt.NONE,value:45.359237,offset:0},{name:"s",base:Mt.TIME,prefixes:Tt.SHORT,value:1,offset:0},{name:"min",base:Mt.TIME,prefixes:Tt.NONE,value:60,offset:0},{name:"h",base:Mt.TIME,prefixes:Tt.NONE,value:3600,offset:0},{name:"seconds",base:Mt.TIME,prefixes:Tt.LONG,value:1,offset:0},{name:"second",base:Mt.TIME,prefixes:Tt.LONG,value:1,offset:0},{name:"sec",base:Mt.TIME,prefixes:Tt.LONG,value:1,offset:0},{name:"minutes",base:Mt.TIME,prefixes:Tt.NONE,value:60,offset:0},{name:"minute",base:Mt.TIME,prefixes:Tt.NONE,value:60,offset:0},{name:"hours",base:Mt.TIME,prefixes:Tt.NONE,value:3600,offset:0},{name:"hour",base:Mt.TIME,prefixes:Tt.NONE,value:3600,offset:0},{name:"day",base:Mt.TIME,prefixes:Tt.NONE,value:86400,offset:0},{name:"days",base:Mt.TIME,prefixes:Tt.NONE,value:86400,offset:0},{name:"rad",base:Mt.ANGLE,prefixes:Tt.NONE,value:1,offset:0},{name:"deg",base:Mt.ANGLE,prefixes:Tt.NONE,value:.017453292519943295,offset:0},{name:"grad",base:Mt.ANGLE,prefixes:Tt.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:Mt.ANGLE,prefixes:Tt.NONE,value:6.283185307179586,offset:0},{name:"A",base:Mt.CURRENT,prefixes:Tt.SHORT,value:1,offset:0},{name:"ampere",base:Mt.CURRENT,prefixes:Tt.LONG,value:1,offset:0},{name:"K",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:0},{name:"degC",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:273.15},{name:"degF",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:459.67},{name:"degR",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:0},{name:"kelvin",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:0},{name:"celsius",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1,offset:273.15},{name:"fahrenheit",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:Mt.TEMPERATURE,prefixes:Tt.NONE,value:1/1.8,offset:0},{name:"mol",base:Mt.AMOUNT_OF_SUBSTANCE,prefixes:Tt.NONE,value:1,offset:0},{name:"mole",base:Mt.AMOUNT_OF_SUBSTANCE,prefixes:Tt.NONE,value:1,offset:0},{name:"cd",base:Mt.LUMINOUS_INTENSITY,prefixes:Tt.NONE,value:1,offset:0},{name:"candela",base:Mt.LUMINOUS_INTENSITY,prefixes:Tt.NONE,value:1,offset:0},{name:"N",base:Mt.FORCE,prefixes:Tt.SHORT,value:1,offset:0},{name:"newton",base:Mt.FORCE,prefixes:Tt.LONG,value:1,offset:0},{name:"lbf",base:Mt.FORCE,prefixes:Tt.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:Mt.FORCE,prefixes:Tt.NONE,value:4.4482216152605,offset:0},{name:"b",base:Mt.BIT,prefixes:Tt.BINARY_SHORT,value:1,offset:0},{name:"bits",base:Mt.BIT,prefixes:Tt.BINARY_LONG,value:1,offset:0},{name:"B",base:Mt.BIT,prefixes:Tt.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:Mt.BIT,prefixes:Tt.BINARY_LONG,value:8,offset:0}],Ot.Vector=s,s.prototype.resize=function(e,t){if(e=e.valueOf(),e instanceof Array){if(e.length>1)throw new RangeError("Cannot resize a vector to multiple dimensions (size: "+st(e)+")");this.resize(e[0],t)}else{if(!r(e)||!n(e)||0>e)throw new TypeError("Positive integer expected as size in method resize");if(e>this._data.length)for(var i=this._data.length;e>i;i++)this._data[i]=t?ot(t):0;else this._data.length=e;this._size=[this._data.length]}},s.prototype.get=function(e){var a=this;if(e=e.valueOf(),e instanceof t){if(!e.isVector())throw new RangeError("Index must be a vector (size: "+st(e.size())+")");e=e.toVector()}if(e instanceof s&&(e=e.valueOf()),e instanceof i||e instanceof Array)return e.map(function(e){return a.get(e)});if(!r(e)||!n(e)||0>e)throw new TypeError("Positive integer expected as index in method get");if(e>this._data.length-1)throw new RangeError("Index out of range ("+e+")");return this._data[e]},s.prototype.set=function(e,r){var n=this;if(e instanceof t){if(!e.isVector())throw new RangeError("Index must be a vector (size: "+st(e.size())+")");e=e.toVector()}if(e instanceof s&&(e=e.valueOf()),(r instanceof t||r instanceof s||r instanceof i)&&(r=r.valueOf()),e instanceof i||e instanceof Array)if(r instanceof Array){if(F(e)!=r.length)throw new RangeError("Dimension mismatch ("+F(e)+" != "+r.length+")");e.forEach(function(e,t){n._set(e,r[t])})}else e.forEach(function(e){n._set(e,r)});else r instanceof Array?this.set([e],r):this._set(e,r)},s.prototype._set=function(e,t){e>this._data.length&&this.resize(e),this._data[e]=t},s.prototype.clone=function(){var e=new s;return e._data=ot(this._data),e},s.prototype.size=function(){return this._size},s.prototype.toScalar=function(){return 1==this._data.length?this._data[0]:null},s.prototype.isScalar=function(){return 1>=this._data.length},s.prototype.toArray=function(){return ot(this._data)},s.prototype.valueOf=function(){return this._data},s.prototype.toString=function(){return bt.formatArray(this._data)},Ot.E=Math.E,Ot.LN2=Math.LN2,Ot.LN10=Math.LN10,Ot.LOG2E=Math.LOG2E,Ot.LOG10E=Math.LOG10E,Ot.PI=Math.PI,Ot.SQRT1_2=Math.SQRT1_2,Ot.SQRT2=Math.SQRT2,Ot.I=new e(0,-1),Ot.pi=Ot.PI,Ot.e=Ot.E,Ot.i=Ot.I,Ot.abs=h,h.doc={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},Ot.add=c,c.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"]},Ot.ceil=l,l.doc={name:"ceil",category:"Arithmetic",syntax:["ceil(x)"],description:"Round a value towards plus infinity.If x is complex, both real and imaginary part are rounded towards plus infinity.",examples:["ceil(3.2)","ceil(3.8)","ceil(-4.2)"],seealso:["floor","fix","round"]},Ot.cube=p,p.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"]},Ot.divide=m,m.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"]},Ot.equal=d,d.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"]},Ot.exp=g,g.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"]},Ot.fix=y,y.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"]},Ot.floor=x,x.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"]},Ot.larger=w,w.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"]},Ot.largereq=E,E.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"]},Ot.log=N,N.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"]},Ot.log10=O,O.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"]},Ot.mod=b,b.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:[]},Ot.multiply=M,M.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"]},Ot.pow=A,A.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"]},Ot.round=_,_.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"]},Ot.sign=U,U.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"]},Ot.smaller=q,q.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"]},Ot.smallereq=L,L.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"]},Ot.sqrt=R,R.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"]},Ot.square=C,C.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"]},Ot.subtract=I,I.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"]},Ot.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"]},Ot.unequal=P,P.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"]},Ot.arg=B,B.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"]},Ot.conj=D,D.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"]},Ot.im=G,G.doc={name:"im",category:"Complex",syntax:["im(x)"],description:"Get the imaginary part of a complex number.",examples:["im(2 + 3i)","re(2 + 3i)","im(-5.2i)","im(2.4)"],seealso:["re","conj","abs","arg"]},Ot.re=V,V.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"]},Ot.eye=Y,Y.doc={name:"eye",category:"Matrix",syntax:["eye(n)","eye(m, n)","eye([m, n])","eye"],description:"Returns the identity matrix with size m-by-n. The matrix has ones on the diagonal and zeros elsewhere.",examples:["eye(3)","eye(3, 5)","a = [1, 2, 3; 4, 5, 6]","eye(size(a))"],seealso:["diag","ones","range","size","transpose","zeros"]},Ot.size=F,F.doc={name:"size",category:"Matrix",syntax:["size(x)"],description:"Calculate the size of a matrix.",examples:["size(2.3)",'size("hello world")',"a = [1, 2; 3, 4; 5, 6]","size(a)","size(1:6)"],seealso:["diag","eye","ones","range","transpose","zeros"]},Ot.factorial=j,j.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:[]},Ot.random=H,H.doc={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},Ot.max=K,K.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"]},Ot.min=W,W.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"]},Ot.acos=X,X.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"]},Ot.asin=Z,Z.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"]},Ot.atan=Q,Q.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"]},Ot.atan2=J,J.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"]},Ot.cos=$,$.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"]},Ot.cot=et,et.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"]},Ot.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"]},Ot.sec=rt,rt.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"]},Ot.sin=nt,nt.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"]},Ot.tan=it,it.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"]},Ot.in=at,at.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:[]},Ot.clone=ot,ot.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:[]},Ot.format=st,st.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:[]},Ot.help=ft,ft.doc={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt")','help("Complex")'],seealso:[]},Ot["import"]=ht,ht.doc={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},Ot["typeof"]=lt,lt.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:[]},Ot.parser.node.Node=pt,pt.prototype.eval=function(){throw Error("Cannot evaluate a Node interface") +},pt.prototype.toString=function(){return""},mt.prototype=new pt,Ot.parser.node.Symbol=mt,mt.prototype.hasParams=function(){return void 0!=this.params&&this.params.length>0},mt.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)},mt.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 pt,Ot.parser.node.Constant=vt,vt.prototype.eval=function(){return this.value},vt.prototype.toString=function(){return this.value?Ot.format(this.value):""},dt.prototype=new pt,Ot.parser.node.ArrayNode=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 r="[",n=e.length,i=0;n>i;i++)0!=i&&(r+=", "),r+=t(e[i]);return r+="]"}return""+e}dt.prototype.eval=function(){return e(this.nodes)},dt.prototype.toString=function(){return t(this.nodes)}}(),gt.prototype=new pt,Ot.parser.node.Block=gt,gt.prototype.add=function(e,t){var r=this.params.length;this.params[r]=e,this.visible[r]=void 0!=t?t:!0},gt.prototype.eval=function(){for(var e=[],t=0,r=this.params.length;r>t;t++){var n=this.params[t].eval();this.visible[t]&&e.push(n)}return e},gt.prototype.toString=function(){for(var e=[],t=0,r=this.params.length;r>t;t++)this.visible[t]&&e.push("\n "+(""+this.params[t]));return"["+e.join(",")+"\n]"},yt.prototype=new pt,Ot.parser.node.Assignment=yt,yt.prototype.eval=function(){if(void 0===this.expr)throw Error("Undefined symbol "+this.name);var e,t=this.params;if(t&&t.length){var r=[];this.params.forEach(function(e){r.push(e.eval())});var n=this.expr.eval();if(void 0==this.result.value)throw Error("Undefined symbol "+this.name);var i=this.result.eval();e=i.set(r,n),this.result.value=e}else e=this.expr.eval(),this.result.value=e;return e},yt.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=""+this.expr},xt.prototype=new pt,Ot.parser.node.FunctionAssignment=xt,xt.prototype.createFunction=function(e,t,r,n){var i=function(){var t=r?r.length:0,i=arguments?arguments.length:0;if(t!=i)throw u(e,i,t);if(t>0)for(var a=0;t>a;a++)r[a].value=arguments[a];return n.eval()};return i.toString=function(){return e+"("+t.join(", ")+")"},i},xt.prototype.eval=function(){for(var e=this.variables,t=this.values,r=0,n=e.length;n>r;r++)e[r].value=t[r];return this.result.value=this.def,this.def},xt.prototype.toString=function(){return""+this.def},Ot.parser.node.Scope=wt,wt.prototype.createNestedScope=function(){var e=new wt(this);return this.nestedScopes||(this.nestedScopes=[]),this.nestedScopes.push(e),e},wt.prototype.clear=function(){if(this.symbols={},this.defs={},this.links={},this.updates={},this.nestedScopes)for(var e=this.nestedScopes,t=0,r=e.length;r>t;t++)e[t].clear()},wt.prototype.createSymbol=function(e){var t=this.symbols[e];if(!t){var r=this.findDef(e);t=this.newSymbol(e,r),this.symbols[e]=t}return t},wt.prototype.newSymbol=function(e,t){var r=this,n=function(){if(!n.value&&(n.value=r.findDef(e),!n.value))throw Error("Undefined symbol "+e);return"function"==typeof n.value?n.value.apply(null,arguments):n.value};return n.value=t,n.toString=function(){return n.value?""+n.value:""},n},wt.prototype.createLink=function(e){var t=this.links[e];return t||(t=this.createSymbol(e),this.links[e]=t),t},wt.prototype.createDef=function(e,t){var r=this.defs[e];return r||(r=this.createSymbol(e),this.defs[e]=r),r&&void 0!=t&&(r.value=t),r},wt.prototype.createUpdate=function(e){var t=this.updates[e];return t||(t=this.createLink(e),this.updates[e]=t),t},wt.prototype.findDef=function(t){function r(e,t){var r=i(e,t);return a[e]=r,s[e]=r,r}var n;if(n=this.defs[t])return n;if(n=this.updates[t])return n;if(this.parentScope)return this.parentScope.findDef(t);var i=this.newSymbol,a=this.symbols,s=this.defs;if("pi"==t)return r(t,Ot.PI);if("e"==t)return r(t,Ot.E);if("i"==t)return r(t,new e(0,1));var f=Ot[t];if(f)return r(t,f);if(o.isUnit(t)){var u=new o(null,t);return r(t,u)}return void 0},wt.prototype.removeLink=function(e){delete this.links[e]},wt.prototype.removeDef=function(e){delete this.defs[e]},wt.prototype.removeUpdate=function(e){delete this.updates[e]},wt.prototype.init=function(){var e=this.symbols,t=this.parentScope;for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];n.value=t?t.findDef(r):void 0}this.nestedScopes&&this.nestedScopes.forEach(function(e){e.init()})},wt.prototype.hasLink=function(e){if(this.links[e])return!0;if(this.nestedScopes)for(var t=this.nestedScopes,r=0,n=t.length;n>r;r++)if(t[r].hasLink(e))return!0;return!1},wt.prototype.hasDef=function(e){return void 0!=this.defs[e]},wt.prototype.hasUpdate=function(e){return void 0!=this.updates[e]},wt.prototype.getUndefinedSymbols=function(){var e=this.symbols,t=[];for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];void 0==n.value&&t.push(n)}return this.nestedScopes&&this.nestedScopes.forEach(function(e){t=t.concat(e.getUndefinedSymbols())}),t},Ot.parser.Parser=Et,Et.prototype.parse=function(e,t){return this.expr=e||"",t||(this.newScope(),t=this.scope),this.parse_start(t)},Et.prototype.eval=function(e){var t=this.parse(e);return t.eval()},Et.prototype.get=function(e){this.newScope();var t=this.scope.findDef(e);return t?t.value:void 0},Et.prototype.set=function(e,t){this.scope.createDef(e,t)},Et.prototype.newScope=function(){this.scope=new wt(this.scope)},Et.prototype.clear=function(){this.scope.clear()},Et.prototype.getChar=function(){this.index++,this.c=this.expr.charAt(this.index)},Et.prototype.getFirstChar=function(){this.index=0,this.c=this.expr.charAt(0)},Et.prototype.getToken=function(){for(this.token_type=this.TOKENTYPE.NULL,this.token="";" "==this.c||" "==this.c;)this.getChar();if("#"==this.c)for(;"\n"!=this.c&&""!=this.c;)this.getChar();if(""==this.c)return this.token_type=this.TOKENTYPE.DELIMITER,void 0;if("-"==this.c||","==this.c||"("==this.c||")"==this.c||"["==this.c||"]"==this.c||'"'==this.c||"\n"==this.c||";"==this.c||":"==this.c)return this.token_type=this.TOKENTYPE.DELIMITER,this.token+=this.c,this.getChar(),void 0;if(this.isDelimiter(this.c))for(this.token_type=this.TOKENTYPE.DELIMITER;this.isDelimiter(this.c);)this.token+=this.c,this.getChar();else if(this.isDigitDot(this.c)){for(this.token_type=this.TOKENTYPE.NUMBER;this.isDigitDot(this.c);)this.token+=this.c,this.getChar();if("E"==this.c||"e"==this.c)for(this.token+=this.c,this.getChar(),("+"==this.c||"-"==this.c)&&(this.token+=this.c,this.getChar()),this.isDigit(this.c)||(this.token_type=this.TOKENTYPE.UNKNOWN);this.isDigit(this.c);)this.token+=this.c,this.getChar()}else{if(!this.isAlpha(this.c)){for(this.token_type=this.TOKENTYPE.UNKNOWN;""!=this.c;)this.token+=this.c,this.getChar();throw this.createSyntaxError('Syntax error in part "'+this.token+'"')}for(this.token_type=this.TOKENTYPE.SYMBOL;this.isAlpha(this.c)||this.isDigit(this.c);)this.token+=this.c,this.getChar()}},Et.prototype.isDelimiter=function(e){return"&"==e||"|"==e||"<"==e||">"==e||"="==e||"+"==e||"/"==e||"*"==e||"%"==e||"^"==e||","==e||";"==e||"\n"==e||"!"==e},Et.prototype.isValidSymbolName=function(e){for(var t=0,r=e.length;r>t;t++){var n=e.charAt(t),i=this.isAlpha(n);if(!i)return!1}return!0},Et.prototype.isAlpha=function(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e},Et.prototype.isDigitDot=function(e){return e>="0"&&"9">=e||"."==e},Et.prototype.isDigit=function(e){return e>="0"&&"9">=e},Et.prototype.parse_start=function(e){this.getFirstChar(),this.getToken();var t;if(t=""==this.token?new vt(void 0):this.parse_block(e),""!=this.token)throw this.token_type==this.TOKENTYPE.DELIMITER?this.createError("Unknown operator "+this.token):this.createSyntaxError('Unexpected part "'+this.token+'"');return t},Et.prototype.parse_ans=function(e){var t=this.parse_function_assignment(e);if(!(t instanceof yt)){var r="ans",n=void 0,i=e.createDef(r);return new yt(r,n,t,i)}return t},Et.prototype.parse_block=function(e){var t,r,n;for("\n"!=this.token&&";"!=this.token&&""!=this.token&&(t=this.parse_ans(e));"\n"==this.token||";"==this.token;)r||(r=new gt,t&&(n=";"!=this.token,r.add(t,n))),this.getToken(),"\n"!=this.token&&";"!=this.token&&""!=this.token&&(t=this.parse_ans(e),n=";"!=this.token,r.add(t,n));return r?r:(t||(t=this.parse_ans(e)),t)},Et.prototype.parse_function_assignment=function(e){if(this.token_type==this.TOKENTYPE.SYMBOL&&"function"==this.token){if(this.getToken(),this.token_type!=this.TOKENTYPE.SYMBOL)throw this.createSyntaxError("Function name expected");var t=this.token;if(this.getToken(),"("!=this.token)throw this.createSyntaxError("Opening parenthesis ( expected");for(var r=e.createNestedScope(),n=[],i=[];;){if(this.getToken(),this.token_type!=this.TOKENTYPE.SYMBOL)throw this.createSyntaxError("Variable name expected");var a=this.token,o=r.createDef(a);if(n.push(a),i.push(o),this.getToken(),","!=this.token){if(")"==this.token)break;throw this.createSyntaxError('Comma , or closing parenthesis ) expected"')}}if(this.getToken(),"="!=this.token)throw this.createSyntaxError("Equal sign = expected");this.getToken();var s=this.parse_range(r),f=e.createDef(t);return new xt(t,n,i,s,f)}return this.parse_assignment(e)},Et.prototype.parse_assignment=function(e){var t=!1;this.token_type==this.TOKENTYPE.SYMBOL&&(t=e.hasLink(this.token));var r=this.parse_range(e);if("="==this.token){if(!(r instanceof mt))throw this.createSyntaxError("Symbol expected at the left hand side of assignment operator =");var n=r.name,i=r.params;t||e.removeLink(n),this.getToken();var a=this.parse_range(e),o=r.hasParams()?e.createUpdate(n):e.createDef(n);return new yt(n,i,a,o)}return r},Et.prototype.parse_range=function(e){var t=this.parse_conditions(e);if(":"==this.token){for(var r=[t];":"==this.token;)this.getToken(),r.push(this.parse_conditions(e));if(r.length>3)throw new TypeError("Invalid range");var n="range",a=function(e,t,r){return new i(e,t,r)};t=new mt(n,a,r)}return t},Et.prototype.parse_conditions=function(e){for(var t=this.parse_bitwise_conditions(e),r={"in":"in"};void 0!==r[this.token];){var n=this.token,i=Ot[r[n]];this.getToken();var a=[t,this.parse_bitwise_conditions(e)];t=new mt(n,i,a)}return t},Et.prototype.parse_bitwise_conditions=function(e){var t=this.parse_comparison(e);return t},Et.prototype.parse_comparison=function(e){for(var t=this.parse_addsubtract(e),r={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==r[this.token];){var n=this.token,i=Ot[r[n]];this.getToken();var a=[t,this.parse_addsubtract(e)];t=new mt(n,i,a)}return t},Et.prototype.parse_addsubtract=function(e){for(var t=this.parse_multiplydivide(e),r={"+":"add","-":"subtract"};void 0!==r[this.token];){var n=this.token,i=Ot[r[n]];this.getToken();var a=[t,this.parse_multiplydivide(e)];t=new mt(n,i,a)}return t},Et.prototype.parse_multiplydivide=function(e){for(var t=this.parse_unaryminus(e),r={"*":"multiply","/":"divide","%":"mod",mod:"mod"};void 0!==r[this.token];){var n=this.token,i=Ot[r[n]];this.getToken();var a=[t,this.parse_unaryminus(e)];t=new mt(n,i,a)}return t},Et.prototype.parse_unaryminus=function(e){if("-"==this.token){var t=this.token,r=z;this.getToken();var n=[this.parse_pow(e)];return new mt(t,r,n)}return this.parse_pow(e)},Et.prototype.parse_pow=function(e){for(var t=[this.parse_factorial(e)];"^"==this.token;)this.getToken(),t.push(this.parse_factorial(e));for(var r=t.pop();t.length;){var n=t.pop(),i="^",a=A,o=[n,r];r=new mt(i,a,o)}return r},Et.prototype.parse_factorial=function(e){for(var t=this.parse_plot(e);"!"==this.token;){var r=this.token,n=j;this.getToken();var i=[t];t=new mt(r,n,i)}return t},Et.prototype.parse_plot=function(e){return this.parse_symbol(e)},Et.prototype.parse_symbol=function(e){if(this.token_type==this.TOKENTYPE.SYMBOL){var t=this.token;this.getToken();var r=e.createLink(t),n=this.parse_arguments(e),i=new mt(t,r,n);return i}return this.parse_string(e)},Et.prototype.parse_arguments=function(e){var t=[];if("("==this.token){if(this.getToken(),")"!=this.token)for(t.push(this.parse_range(e));","==this.token;)this.getToken(),t.push(this.parse_range(e));if(")"!=this.token)throw this.createSyntaxError("Parenthesis ) missing");this.getToken()}return t},Et.prototype.parse_string=function(e){if('"'==this.token){for(var t="",r="";""!=this.c&&('"'!=this.c||"\\"==r);)t+=this.c,r=this.c,this.getChar();if(this.getToken(),'"'!=this.token)throw this.createSyntaxError('End of string " missing');this.getToken();var n=new vt(t);return n}return this.parse_matrix(e)},Et.prototype.parse_matrix=function(e){if("["==this.token){var t;for(this.getToken();"\n"==this.token;)this.getToken();if("]"!=this.token){var r=[],n=0,i=0;for(r[0]=[this.parse_range(e)];","==this.token||";"==this.token;){for(","==this.token?i++:(n++,i=0,r[n]=[]),this.getToken();"\n"==this.token;)this.getToken();for(r[n][i]=this.parse_range(e);"\n"==this.token;)this.getToken()}var a=r.length,o=r.length>0?r[0].length:0;for(n=1;a>n;n++)if(r[n].length!=o)throw this.createError("Number of columns must match ("+r[n].length+" != "+o+")");if("]"!=this.token)throw this.createSyntaxError("End of matrix ] missing");this.getToken(),t=new dt(r)}else this.getToken(),t=new dt([]);for(;"("==this.token;)t=this.parse_arguments(e,t);return t}return this.parse_number(e)},Et.prototype.parse_number=function(t){if(this.token_type==this.TOKENTYPE.NUMBER){var r;r="."==this.token?0:Number(this.token),this.getToken();var n;if(this.token_type==this.TOKENTYPE.SYMBOL){if("i"==this.token||"I"==this.token)return n=new e(0,r),this.getToken(),new vt(n);if(o.isUnit(this.token))return n=new o(r,this.token),this.getToken(),new vt(n);throw this.createTypeError('Unknown unit "'+this.token+'"')}var i=new vt(r);return i}return this.parse_parentheses(t)},Et.prototype.parse_parentheses=function(e){if("("==this.token){this.getToken();var t=this.parse_range(e);if(")"!=this.token)throw this.createSyntaxError("Parenthesis ) expected");return this.getToken(),t}return this.parse_end(e)},Et.prototype.parse_end=function(){throw""==this.token?this.createSyntaxError("Unexpected end of expression"):this.createSyntaxError("Value expected")},Et.prototype.row=function(){return void 0},Et.prototype.col=function(){return this.index-this.token.length+1},Et.prototype.createErrorMessage=function(e){var t=this.row(),r=this.col();return void 0===t?void 0===r?e:e+" (col "+r+")":e+" (ln "+t+", col "+r+")"},Et.prototype.createSyntaxError=function(e){return new SyntaxError(this.createErrorMessage(e))},Et.prototype.createTypeError=function(e){return new TypeError(this.createErrorMessage(e))},Et.prototype.createError=function(e){return Error(this.createErrorMessage(e))},Ot.parser.Workspace=Nt,Nt.prototype.clear=function(){this.nodes={},this.firstNode=void 0,this.lastNode=void 0},Nt.prototype.append=function(e){var t=this._getNewId(),r=this.lastNode?this.lastNode.scope:this.scope,n=new wt(r),i=new Nt.Node({id:t,expression:e,parser:this.parser,scope:n,nextNode:void 0,previousNode:this.lastNode});return this.nodes[t]=i,this.firstNode||(this.firstNode=i),this.lastNode&&(this.lastNode.nextNode=i),this.lastNode=i,this._update([t]),t},Nt.prototype.insertBefore=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var n=r.previousNode,i=this._getNewId(),a=n?n.scope:this.scope,o=new wt(a),s=new Nt.Node({id:i,expression:e,parser:this.parser,scope:o,nextNode:r,previousNode:n});this.nodes[i]=s,n?n.nextNode=s:this.firstNode=s,r.previousNode=s,r.scope.parentScope=s.scope;var f=this.getDependencies(i);return-1==f.indexOf(i)&&f.unshift(i),this._update(f),i},Nt.prototype.insertAfter=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';return r==this.lastNode?this.append(e):this.insertBefore(t+1,e)},Nt.prototype.remove=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';var r=this.getDependencies(e),n=t.previousNode,i=t.nextNode;n?n.nextNode=i:this.firstNode=i,i?i.previousNode=n:this.lastNode=n;var a=n?n.scope:this.scope;i&&(i.scope.parentScope=a),delete this.nodes[e],this._update(r)},Nt.prototype.replace=function(e,t){var r=this.nodes[t];if(!r)throw'Node with id "'+t+'" not found';var n=[t];Nt._merge(n,this.getDependencies(t));var i=r.previousNode;r.nextNode,i?i.scope:this.scope,r.setExpr(e),Nt._merge(n,this.getDependencies(t)),this._update(n)},Nt.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)},Nt.Node.prototype.setExpr=function(e){this.expression=e||"",this.scope.clear(),this._parse()},Nt.Node.prototype.getExpr=function(){return this.expression},Nt.Node.prototype.getResult=function(){return this.result},Nt.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)}},Nt.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},Nt._merge=function(e,t){for(var r=0,n=t.length;n>r;r++){var i=t[r];-1==e.indexOf(i)&&e.push(i)}},Nt.prototype.getDependencies=function(e){var t,r=[],n=this.nodes[e];if(n){var i=n.scope.defs,a=n.scope.updates,o=[];for(t in i)i.hasOwnProperty(t)&&o.push(t);for(t in a)a.hasOwnProperty(t)&&-1==o.indexOf(t)&&o.push(t);for(var s=n.nextNode;s&&o.length;){for(var f=s.scope,u=0;o.length>u;){if(t=o[u],(f.hasLink(t)||f.hasUpdate(t))&&-1==r.indexOf(s.id)){r.push(s.id);var h=this.getDependencies(s.id);Nt._merge(r,h)}f.hasDef(t)&&(o.splice(u,1),u--),u++}s=s.nextNode}}return r},Nt.prototype.getExpr=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getExpr()},Nt.prototype.getResult=function(e){var t=this.nodes[e];if(!t)throw'Node with id "'+e+'" not found';return t.getResult()},Nt.prototype._update=function(e){this.updateSeq++;for(var t=this.updateSeq,r=this.nodes,n=0,i=e.length;i>n;n++){var a=e[n],o=r[a];o&&(o.eval(),o.updateSeq=t)}},Nt.prototype.getChanges=function(e){var t=[],r=this.firstNode;for(e=e||0;r;)r.updateSeq>e&&t.push(r.id),r=r.nextNode;return{ids:t,updateSeq:this.updateSeq}},Nt.prototype._getNewId=function(){return this.idMax++,this.idMax},Nt.prototype.toString=function(){return JSON.stringify(this.toJSON())},Nt.prototype.toJSON=function(){for(var e=[],t=this.firstNode;t;){var r={id:t.id,expression:t.expression,dependencies:this.getDependencies(t.id)};try{r.result=t.getResult()}catch(n){r.result="Error: "+((n.message||n)+"")}e.push(r),t=t.nextNode}return e}})(); \ No newline at end of file diff --git a/src/function/utils/clone.js b/src/function/utils/clone.js index 66f4af611..ca8185107 100644 --- a/src/function/utils/clone.js +++ b/src/function/utils/clone.js @@ -8,11 +8,16 @@ function clone(x) { throw newArgumentsError('clone', arguments.length, 1); } + if (x == null) { + // null or undefined + return x; + } + if (typeof(x.clone) === 'function') { return x.clone(); } - if (isNumber(x) || isString(x) || x === null) { + if (isNumber(x) || isString(x)) { return x; } diff --git a/src/type/Matrix.js b/src/type/Matrix.js index 379814622..e4f915785 100644 --- a/src/type/Matrix.js +++ b/src/type/Matrix.js @@ -1,7 +1,20 @@ /** * @constructor Matrix * - * TODO: document Matrix + * A Matrix is a wrapper around an Array. A matrix can hold a multi dimensional + * array. A matrix can be constructed as: + * var matrix = new Matrix(data) + * + * Matrix contains the functions to resize, get and set values, get the size, + * clone the matrix and to convert the matrix to a vector, array, or scalar. + * The internal Array of the Matrix can be accessed using the method valueOf. + * + * Example usage: + * var matrix = new Matrix([[1, 2], [3, 4]); + * matix.size(); // [2, 2] + * matrix.resize([3, 2], 5); + * matrix.valueOf(); // [[1, 2], [3, 4], [5, 5]] + * matrix.get([1, 0]) // 3 * * @param {Array | Matrix | Vector | Range} [data] A multi dimensional array */ @@ -15,9 +28,17 @@ function Matrix(data) { // clone data from Vector, Matrix, or Range this._data = data.toArray(); } + else if (data instanceof Array) { + // use array as is + this._data = data; + } + else if (data != null) { + // a scalar provided + this._data = [data]; + } else { - // use data as is - this._data = data || null; + // nothing provided + this._data = []; } // verify the size of the array @@ -26,9 +47,148 @@ function Matrix(data) { math.Matrix = Matrix; -// TODO: implement method get +/** + * Get a value or a set of values from the matrix. + * Indexes are zero-based. + * @param {Array | Vector | Matrix} index + */ +Matrix.prototype.get = function (index) { + // TODO: support getting a range of values + + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); + } + index = index.toVector(); + } + if (index instanceof Vector) { + index = index.valueOf(); + } + + if (index instanceof Array) { + if (index.length != this._size.length) { + throw new RangeError('Number of dimensions do not match ' + + '(' + index.length + ' != ' + this._size.length + ')'); + } + + var value = this._data; + index.forEach(function (i) { + if (!isNumber(i) || !isInteger(i) || i < 0) { + throw new TypeError('Positive integer expected as index in method get'); + } + if (i > value.length - 1) { + throw new RangeError('Index out of range (' + i + ')'); + } + value = value[i]; + }); + return value; + } + else { + // TODO: support a single number as index in case the matrix is a vector + throw new TypeError('Unsupported type of index ' + type(index)); + } +}; + // TODO: implement method set -// TODO: implement method resize + +/** + * Get a value or a set of values from the matrix. + * Indexes are zero-based. + * @param {Array | Vector | Matrix} index + * @param {*} value + */ +Matrix.prototype.set = function (index, value) { + // TODO: support setting a range of values + + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); + } + index = index.toVector(); + } + if (index instanceof Vector) { + index = index.valueOf(); + } + if (value instanceof Matrix || value instanceof Vector || value instanceof Range) { + value = value.valueOf(); + } + + if (index instanceof Array) { + if (value instanceof Array) { + throw new Error('Setting a range of values is not yet implemented...'); + } + else { + if (index.length != this._size.length) { + throw new RangeError('Number of dimensions do not match ' + + '(' + index.length + ' != ' + this._size.length + ')'); + } + + var size = this._size.concat([]); + var needResize = false; + for (var i = 0; i < size.length; i++) { + var index_i = index[i]; + if (!isNumber(index_i) || !isInteger(index_i) || index_i < 0) { + throw new TypeError('Positive integer expected as index in method get'); + } + if (index[i] > size[i]) { + size[i] = index_i; + needResize = true; + } + } + if (needResize) { + this.resize(size); + } + + var len = size.length; + var arr = this._data; + index.forEach(function (v, i) { + if (i < len - 1) { + arr = arr[v]; + } + else { + arr[v] = value; + } + }); + } + + /* TODO: cleanup + if (index.length != this._size.length) { + throw new RangeError('Number of dimensions do not match ' + + '(' + index.length + ' != ' + this._size.length + ')'); + } + + var value = this._data; + index.forEach(function (i) { + if (!isNumber(i) || !isInteger(i) || i < 0) { + throw new TypeError('Positive integer expected as index in method get'); + } + if (i > value.length - 1) { + throw new RangeError('Index out of range (' + i + ')'); + } + value = value[i]; + }); + return value; + */ + } + else { + // TODO: support a single number as index in case the matrix is a vector + throw new TypeError('Unsupported type of index ' + type(index)); + } +}; + +/** + * Resize the matrix + * @param {Number[]} size + * @param {*} [defaultValue] Default value, filled in on new entries. + * If not provided, the vector will be filled + * with zeros. + */ +Matrix.prototype.resize = function (size, defaultValue) { + util.resize(this._data, size, defaultValue); + this._size = clone(size); +}; /** * Create a clone of the matrix @@ -40,7 +200,6 @@ Matrix.prototype.clone = function () { return matrix; }; - /** * Retrieve the size of the matrix. * The size of the matrix will be validated too @@ -58,7 +217,7 @@ Matrix.prototype.size = function () { Matrix.prototype.toScalar = function () { var scalar = this._data; while (scalar instanceof Array && scalar.length == 1) { - scalar = value[0]; + scalar = scalar[0]; } if (scalar instanceof Array) { @@ -74,11 +233,9 @@ Matrix.prototype.toScalar = function () { * @return {boolean} isScalar */ Matrix.prototype.isScalar = function () { - var scalar = this._data; - while (scalar instanceof Array && scalar.length == 1) { - scalar = scalar[0]; - } - return !(scalar instanceof Array); + return this._size.every(function (s) { + return (s <= 1); + }); }; /** @@ -86,26 +243,37 @@ Matrix.prototype.isScalar = function () { * A matrix is a vector when it has 0 or 1 dimensions, or has multiple * dimensions where maximum one of the dimensions has a size larger than 1. * Returns null if the Matrix is no vector - * return {Vector} vector + * return {Vector | null} vector */ Matrix.prototype.toVector = function () { - /* TODO: implement toVector var count = 0; var dim = undefined; - var s = util.size(this._data); - s.forEach(function (length, index) { + var index = []; + this._size.forEach(function (length, i) { if (length > 1) { count++; - dim = index; + dim = i; } + index[i] = 0; }); - if (count > 1) { + + if (count == 0) { + // scalar or empty + return new Vector(this.toScalar()); + } + else if (count == 1) { + // valid vector + var vector = []; + for (var i = 0, iMax = this._size[dim]; i < iMax; i++) { + index[dim] = i; + vector[i] = this.get(index); + } + return new Vector(vector); + } + else { + // count > 1, this is no vector return null; } - - /// TODO: clone the values - */ - throw new Error('not yet implemented'); }; /** @@ -116,8 +284,7 @@ Matrix.prototype.toVector = function () { */ Matrix.prototype.isVector = function () { var count = 0; - var s = util.size(this._data); - s.forEach(function (length) { + this._size.forEach(function (length) { if (length > 1) { count++; } @@ -131,11 +298,7 @@ Matrix.prototype.isVector = function () { * @returns {Array} array */ Matrix.prototype.toArray = function () { - var array = clone(this._data); - if (!(array instanceof Array)) { - array = [array]; - } - return array; + return clone(this._data); }; /** diff --git a/src/type/Vector.js b/src/type/Vector.js index af78741d6..293275198 100644 --- a/src/type/Vector.js +++ b/src/type/Vector.js @@ -4,26 +4,16 @@ * array. A vector can be constructed as: * var vector = new Vector(data) * - * Vector contains the following functions: - * resize(size, defaultValue) - * get(index) - * get(indexes) - * set(index, value) - * set(indexes, values) - * size() - * clone() - * isScalar() - * toScalar() - * isArray() - * toArray() // create an Array with the vector data cloned - * valueOf() // get the internal data Array of the vector + * Vector contains the functions to resize, get and set values, get the size, + * clone the vector and to convert the vector to an array or scalar. + * The internal Array of the Vector can be accessed using the method valueOf. * * Example usage: - * var vector = new Vector([4, 5, 6, 7]) + * var vector = new Vector([4, 5, 6, 7]); * vector.resize(6, -1); * vector.set(2, 9); * vector.valueOf(); // [4, 5, 9, 7, -1, -1] - * vector.get([3,4 ]) // [7, -1] + * vector.get([3, 4]) // [7, -1] * * @param {Array | Matrix | Vector | Range} [data] A one dimensional array */ @@ -41,9 +31,17 @@ function Vector(data) { // clone data from Vector or Range this._data = data.toArray(); } + else if (data instanceof Array) { + // use array as is + this._data = data; + } + else if (data != null) { + // a scalar provided + this._data = [data]; + } else { - // use data as is - this._data = data || null; + // nothing provided + this._data = []; } // verify whether the data is a one dimensional array @@ -78,25 +76,18 @@ Vector.prototype.resize = function (size, defaultValue) { throw new TypeError('Positive integer expected as size in method resize'); } - if (!(this._data instanceof Array) && size > 1) { - // vector currently contains a scalar. change that to an array - this._data = [this._data]; - this.resize(size, defaultValue); + if(size > this._data.length) { + // enlarge + for (var i = this._data.length; i < size; i++) { + this._data[i] = defaultValue ? clone(defaultValue) : 0; + } } else { - if(size > this._data.length) { - // enlarge - for (var i = this._data.length; i < size; i++) { - this._data[i] = defaultValue ? clone(defaultValue) : 0; - } - } - else { - // shrink - this._data.length = size; - } - - this._size = [this._data.length]; + // shrink + this._data.length = size; } + + this._size = [this._data.length]; } }; @@ -104,13 +95,24 @@ Vector.prototype.resize = function (size, defaultValue) { * get a value or a subset of the vector. Throws an RangeError when index is * out of range. * Indexes are zero-based. - * @param {Number | Number[] | Range} index - * @return {* | *[]} value + * @param {Number | Array | Matrix | Vector | Range} index + * @return {* | Array | Matrix | Vector | Range} value */ Vector.prototype.get = function (index) { var me = this; index = index.valueOf(); + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); + } + index = index.toVector(); + } + if (index instanceof Vector) { + index = index.valueOf(); + } + if (index instanceof Range || index instanceof Array) { return index.map(function (i) { return me.get(i); @@ -120,58 +122,61 @@ Vector.prototype.get = function (index) { if (!isNumber(index) || !isInteger(index) || index < 0) { throw new TypeError('Positive integer expected as index in method get'); } - if (this._data instanceof Array) { - return this._data[index]; - } - else if (index == 0) { - return this._data; - } - else { + if (index > this._data.length - 1) { throw new RangeError('Index out of range (' + index + ')'); } + return this._data[index]; } }; /** - * Set a value or a set of value in the vector. + * Set a value or a set of values in the vector. * Indexes are zero-based. - * @param {Number | Number[]} index - * @param {* | *[]} value + * @param {Number | Array | Matrix | Vector | Range} index + * @param {* | Array | Matrix | Vector | Range} value */ Vector.prototype.set = function (index, value) { var me = this; - index = index.valueOf(); - if (index instanceof Range) { - if (index.size() != value.length) { - throw new RangeError('Dimension mismatch (' + index.size() + ' != ' + - value.length + ')'); + if (index instanceof Matrix) { + if (!index.isVector()) { + throw new RangeError('Index must be a vector ' + + '(size: ' + format(index.size()) + ')'); } - - index.forEach(function (v, i) { - me._set(v, value[i]); - }); + index = index.toVector(); } - else if (index instanceof Array) { + if (index instanceof Vector) { + index = index.valueOf(); + } + if (value instanceof Matrix || value instanceof Vector || value instanceof Range) { + value = value.valueOf(); + } + + if (index instanceof Range || index instanceof Array) { if (value instanceof Array) { - if (index.length != value.length) { - throw new RangeError('Dimension mismatch (' + index.length+ ' != ' + - value.length + ')'); + if (size(index) != value.length) { + throw new RangeError('Dimension mismatch ' + + '(' + size(index) + ' != ' + value.length + ')'); } index.forEach(function (v, i) { - me._set(v, value[i]); + me._set(v, value[i]); }); } else { - this.set(index, [value]); + index.forEach(function (v) { + me._set(v, value); + }); } } else { + // index is a scalar if (value instanceof Array) { + // try as two arrays this.set([index], value); } else { + // set single value this._set(index, value); } } @@ -184,9 +189,6 @@ Vector.prototype.set = function (index, value) { * @private */ Vector.prototype._set = function (index, value) { - if (!(this._data instanceof Array)) { - this._data = [this._data]; - } if (index > this._data.length) { this.resize(index); } @@ -218,16 +220,11 @@ Vector.prototype.size = function () { * @return {* | null} scalar */ Vector.prototype.toScalar = function () { - var value = this._data; - while (value instanceof Array && value.length == 1) { - value = value[0]; - } - - if (value instanceof Array) { - return null; + if (this._data.length == 1) { + return this._data[0]; } else { - return value; + return null; } }; @@ -236,11 +233,7 @@ Vector.prototype.toScalar = function () { * @return {boolean} isScalar */ Vector.prototype.isScalar = function () { - var value = this._data; - while (value instanceof Array && value.length == 1) { - value = value[0]; - } - return !(value instanceof Array); + return (this._data.length <= 1); }; /** @@ -249,11 +242,7 @@ Vector.prototype.isScalar = function () { * @returns {Array} array */ Vector.prototype.toArray = function () { - var array = clone(this._data); - if (!(array instanceof Array)) { - array = [array]; - } - return array; + return clone(this._data); }; /** diff --git a/src/util.js b/src/util.js index e792e9c80..9f3ff6bc6 100644 --- a/src/util.js +++ b/src/util.js @@ -372,8 +372,102 @@ var util = (function () { } }; - // Internet Explorer 8 and older does not support Array.indexOf, so we define - // it here in that case. + /** + * Recursively resize a multi dimensional array + * @param {Array} array Array to be resized + * @param {Number[]} size Array with the size of each dimension + * @param {Number} dim Current dimension + * @param {*} [defaultValue] Value to be filled in in new entries, + * 0 by default. + * @private + */ + function _resize (array, size, dim, defaultValue) { + if (!(array instanceof Array)) { + throw new TypeError('Array expected'); + } + + var len = array.length, + newLen = size[dim]; + + if (len != newLen) { + if(newLen > array.length) { + // enlarge + for (var i = array.length; i < newLen; i++) { + array[i] = defaultValue ? clone(defaultValue) : 0; + } + } + else { + // shrink + array.length = size[dim]; + } + len = array.length; + } + + if (dim < size.length - 1) { + // recursively validate each child array + var dimNext = dim + 1; + for (i = 0; i < len; i++) { + child = array[i]; + if (!(child instanceof Array)) { + child = [child]; + array[i] = child; + } + _resize(child, size, dimNext, defaultValue); + } + } + else { + // last dimension + for (i = 0; i < len; i++) { + var child = array[i]; + while (child instanceof Array) { + child = child[0]; + } + array[i] = child; + } + } + } + + /** + * Resize a multi dimensional array + * @param {Array} array Array to be resized + * @param {Number[]} size Array with the size of each dimension + * @param {*} [defaultValue] Value to be filled in in new entries, + * 0 by default + */ + util.resize = function resize(array, size, defaultValue) { + // TODO: what to do with scalars, when size=[] ? + + // check the type of size + if (!(size instanceof Array)) { + throw new TypeError('Size must be an array (size is ' + type(size) + ')'); + } + + // check whether size contains positive integers + size.forEach(function (value) { + if (!isNumber(value) || !isInteger(value) || value < 0) { + throw new TypeError('Invalid size, must contain positive integers ' + + '(size: ' + formatArray(size) + ')'); + } + }); + + var hasZeros = (size.indexOf(0) != -1); + if (hasZeros) { + // array where all dimensions are zero + size.forEach(function (value) { + if (value != 0) { + throw new RangeError('Invalid size, all dimensions must be ' + + 'either zero or non-zero (size: ' + formatArray(size) + ')'); + } + }); + } + + // recursively resize + _resize(array, size, 0, defaultValue); + }; + + + // Internet Explorer 8 and older does not support Array.indexOf, + // so we define it here in that case. // http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/ if(!Array.prototype.indexOf) { Array.prototype.indexOf = function(obj){ @@ -386,8 +480,8 @@ var util = (function () { }; } - // Internet Explorer 8 and older does not support Array.forEach, so we define - // it here in that case. + // Internet Explorer 8 and older does not support Array.forEach, + // so we define it here in that case. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach if (!Array.prototype.forEach) { Array.prototype.forEach = function(fn, scope) { @@ -397,8 +491,8 @@ var util = (function () { } } - // Internet Explorer 8 and older does not support Array.map, so we define it - // here in that case. + // Internet Explorer 8 and older does not support Array.map, + // so we define it here in that case. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map // Production steps of ECMA-262, Edition 5, 15.4.4.19 // Reference: http://es5.github.com/#x15.4.4.19 @@ -474,5 +568,33 @@ var util = (function () { }; } + // Internet Explorer 8 and older does not support Array.every, + // so we define it here in that case. + // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/every + if (!Array.prototype.every) { + Array.prototype.every = function(fun /*, thisp */) { + "use strict"; + + if (this == null) { + throw new TypeError(); + } + + var t = Object(this); + var len = t.length >>> 0; + if (typeof fun != "function") { + throw new TypeError(); + } + + var thisp = arguments[1]; + for (var i = 0; i < len; i++) { + if (i in t && !fun.call(thisp, t[i], i, t)) { + return false; + } + } + + return true; + }; + } + return util; })(); diff --git a/test/function/matrix.js b/test/function/matrix.js index 08fa85135..daedb5138 100644 --- a/test/function/matrix.js +++ b/test/function/matrix.js @@ -24,8 +24,8 @@ assert.deepEqual(math.size('hello'), [5]); assert.deepEqual(math.size(''), [0]); assert.deepEqual(math.size(new Complex(2,3)), []); assert.deepEqual(math.size(null), []); -assert.deepEqual(math.size(new Vector()), []); -assert.deepEqual(math.size(new Matrix()), []); +assert.deepEqual(math.size(new Vector()), [0]); +assert.deepEqual(math.size(new Matrix()), [0]); assert.deepEqual(math.size(new Range(2,5)), [4]); // TODO: test whether math.size throws an error in case of invalid data or size diff --git a/test/test.html b/test/test.html index 69cfa61be..ca297c0b9 100644 --- a/test/test.html +++ b/test/test.html @@ -11,6 +11,9 @@