mathjs/math.min.js
2013-07-08 14:31:02 +02:00

30 lines
106 KiB
JavaScript

/**
* math.js
* https://github.com/josdejong/mathjs
*
* Math.js is an extensive math library for JavaScript and Node.js,
* It features real and complex numbers, units, matrices, a large set of
* mathematical functions, and a flexible expression parser.
*
* @version 0.10.0
* @date 2013-07-08
*
* @license
* Copyright (C) 2013 Jos de Jong <wjosdejong@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
!function(){function e(e){return e instanceof Boolean||"boolean"==typeof e}function t(e,n){if(!(this instanceof t))throw new SyntaxError("Complex constructor must be called with the new operator");switch(arguments.length){case 0:this.re=0,this.im=0;break;case 2:if(!g(e)||!g(n))throw new TypeError("Two numbers expected in Complex constructor");this.re=e,this.im=n;break;default:if(0!=arguments.length&&2!=arguments.length)throw new SyntaxError("Two or zero arguments expected in Complex constructor")}}function n(e){e&&tt.extend(this,e)}function r(e){if(!(this instanceof r))throw new SyntaxError("Matrix constructor must be called with the new operator");if(e instanceof r||e instanceof d)this._data=e.toArray();else if(e instanceof Array)this._data=e;else{if(null!=e)throw new TypeError("Unsupported type of data ("+et["typeof"](e)+")");this._data=[]}this._size=tt.size(this._data)}function a(e,t){return tt.validateIndex(t,e.length),e[t-1]}function i(e,t){return t.forEach(function(t){e=a(e,t)}),et.clone(e)}function o(e,t){var n=t[0];return n.map?n.map(function(t){return a(e,t)}):[a(e,n)]}function s(e,t){var n=t[0],r=t[1];if(n.map)return r.map?n.map(function(t){var n=a(e,t);return r.map(function(e){return a(n,e)})}):n.map(function(t){return[a(a(e,t),r)]});if(r.map){var i=a(e,n);return[r.map(function(e){return a(i,e)})]}return[[a(a(e,n),r)]]}function f(e,t,n){var r=n==t.length-1,i=t[n],o=function(i){var o=a(e,i);return r?o:f(o,t,n+1)};return i.map?i.map(o):[o(i)]}function u(e,t,n){if(tt.validateIndex(t),n instanceof Array)throw new TypeError("Dimension mismatch, value expected instead of array");e[t-1]=n}function c(e,t,n,r){var a=!1;n.length>t.length&&(a=!0);for(var i=0;i<n.length;i++){var o=n[i];tt.validateIndex(o),(null==t[i]||o>t[i])&&(t[i]=o,a=!0)}a&&tt.resize(e,t,0);var s=t.length;n.forEach(function(t,n){s-1>n?e=e[t-1]:e[t-1]=r})}function l(e,t,n,r){var a=n[0];tt.validateIndex(a),a>t[0]&&(tt.resize(e,[a],0),t[0]=a),e[a-1]=r}function m(e,t,n,r){var a=n[0],i=n[1];tt.validateIndex(a),tt.validateIndex(i);var o=!1;a>(t[0]||0)&&(t[0]=a,o=!0),i>(t[1]||0)&&(t[1]=i,o=!0),o&&tt.resize(e,t,0),e[a-1][i-1]=r}function h(e,t,n,r,a){var i=r==n.length-1,o=n[r],s=function(o,s){if(i)u(e,o,a[s]),o>(t[r]||0)&&(t[r]=o);else{var f=e[o-1];f instanceof Array||(e[o-1]=f=[f]),o>(t[r]||0)&&(t[r]=o),h(f,t,n,r+1,a[s])}};if(o.map){var f=o.size&&o.size()||o.length;if(f!=a.length)throw new RangeError("Dimensions mismatch ("+f+" != "+a.length+")");o.map(s)}else s(o,0)}function p(e){for(var t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array?p(r):void 0==r&&(e[t]=0)}}function g(e){return e instanceof Number||"number"==typeof e}function v(e){return e==Math.round(e)}function d(e,t,n){if(!(this instanceof d))throw new SyntaxError("Range constructor must be called with the new operator");if(null!=e&&!g(e))throw new TypeError("Parameter start must be a number");if(null!=n&&!g(n))throw new TypeError("Parameter end must be a number");if(null!=t&&!g(t))throw new TypeError("Parameter step must be a number");this.start=null!=e?e:0,this.end=null!=n?n:0,this.step=null!=t?t:1}function y(e,t){var n=et.type.Selector,r=Array.prototype.slice;n.prototype[e]="function"==typeof t?function(){var e=[this.value].concat(r.call(arguments,0));return new n(t.apply(this,e))}:new n(t)}function x(e){return e instanceof String||"string"==typeof e}function w(e,t){if(!(this instanceof w))throw new Error("Unit constructor must be called with the new operator");if(null!=e&&!g(e))throw new TypeError("First parameter in Unit constructor must be a number");if(null!=t&&!x(t))throw new TypeError("Second parameter in Unit constructor must be a string");if(null!=t){var n=b(t);if(!n)throw new SyntaxError('String "'+t+'" is no unit');this.unit=n.unit,this.prefix=n.prefix}else this.unit=w.UNIT_NONE,this.prefix=w.PREFIX_NONE;null!=e?(this.value=this._normalize(e),this.fixPrefix=!1):(this.value=null,this.fixPrefix=!0)}function b(e){for(var t=w.UNITS,n=0,r=t.length;r>n;n++){var a=t[n];if(tt.endsWith(e,a.name)){var i=e.length-a.name.length,o=e.substring(0,i),s=a.prefixes[o];if(void 0!==s)return{unit:a,prefix:s}}}return null}function E(e,t){var n=void 0;if(2==arguments.length){var r=et["typeof"](t);n="Function "+e+"("+r+") not supported"}else if(arguments.length>2){for(var a=[],i=1;i<arguments.length;i++)a.push(et["typeof"](arguments[i]));n="Function "+e+"("+a.join(", ")+") not supported"}else n="Unsupported parameter in function "+e;return new TypeError(n)}function O(e,t,n,r){var a="Wrong number of arguments in function "+e+" ("+t+" provided, "+n+(void 0!=r?"-"+r:"")+" expected)";return new SyntaxError(a)}function N(){}function M(e){this.value=e}function A(e,t,n){this.name=e,this.fn=t,this.params=n}function S(e,t){this.name=e,this.scope=t}function T(e,t,n){if(this.object=e,this.params=t,this.paramScopes=n,this.hasContextParams=!1,t)for(var r={type:et.type.SymbolNode,properties:{name:"end"}},a=0,i=t.length;i>a;a++)if(t[a].find(r).length>0){this.hasContextParams=!0;break}}function q(e){this.nodes=e||[]}function z(){this.params=[],this.visible=[]}function R(e,t,n){this.name=e,this.expr=t,this.scope=n}function C(e,t,n,r,a){this.name=e,this.params=t,this.paramScopes=n,this.expr=r,this.scope=a,this.hasContextParams=!1;for(var i={type:et.type.SymbolNode,properties:{name:"end"}},o=0,s=t.length;s>o;o++)if(t[o].find(i).length>0){this.hasContextParams=!0;break}}function U(e,t,n,r,a){this.name=e,this.variables=t,this.expr=n,this.scope=a,this.fn=function(){var a=t?t.length:0;if(arguments.length!=a)throw O(e,arguments.length,a);for(var i=0;a>i;i++)r.set(t[i],arguments[i]);return n.eval()},this.fn.toString=function(){return e+"("+t.join(", ")+")"}}function L(e,n){var r=n.re*n.re+n.im*n.im;return 0!=r?t.create((e.re*n.re+e.im*n.im)/r,(e.im*n.re-e.re*n.im)/r):t.create(0!=e.re?e.re/0:0,0!=e.im?e.im/0:0)}function I(e,t){if(t>0)return e>0?e%t:0==e?0:e-t*Math.floor(e/t);if(0==t)return e;throw new Error("Cannot calculate mod for a negative divisor")}function _(e,n){return 0==e.im?0==n.im?e.re*n.re:0==n.re?new t(0,e.re*n.im):new t(e.re*n.re,e.re*n.im):0==e.re?0==n.im?new t(0,e.im*n.re):0==n.re?-e.im*n.im:new t(-e.im*n.im,e.im*n.re):0==n.im?new t(e.re*n.re,e.im*n.re):0==n.re?new t(-e.im*n.im,e.re*n.im):new t(e.re*n.re-e.im*n.im,e.re*n.im+e.im*n.re)}function P(e,t){var n=et.log(e),r=et.multiply(n,t);return et.exp(r)}function G(e,t){if(t){var n=Math.pow(10,t);return Math.round(e*n)/n}return Math.round(e)}function B(e){if(e instanceof Array||e instanceof r||e instanceof d){for(var t=e.valueOf(),n="[",a=t.length,i=0;a>i;i++)0!=i&&(n+=", "),n+=B(t[i]);return n+="]"}return g(e)?tt.formatNumber(e):e.toString()}function j(e,t,n,r){if(n>r){if(e.length!=t.length)throw new Error("Dimensions mismatch ("+e.length+" != "+t.length+")");for(var a=[],i=0;i<e.length;i++)a[i]=j(e[i],t[i],n,r+1);return a}return e.concat(t)}function k(e,t,n){var r=et.multiply,a=et.subtract;if(1==t)return e[0][0];if(2==t)return a(r(e[0][0],e[1][1]),r(e[1][0],e[0][1]));for(var i=1,o=0,s=0;t>s&&!(o>=n);s++){for(var f=s;0==e[f][o];)if(f++,f==t&&(f=s,o++,o==n))return tt.deepEqual(e,et.eye(t).valueOf())?et.round(i,6):0;if(f!=s){for(var u=0;n>u;u++){var c=e[f][u];e[f][u]=e[s][u],e[s][u]=c}i*=-1}for(var l=e[s][o],u=0;n>u;u++)e[s][u]=e[s][u]/l;i*=l;for(var m=0;t>m;m++)if(m!=s)for(var h=e[m][o],u=0;n>u;u++)e[m][u]=e[m][u]-e[s][u]*h;o++}return tt.deepEqual(e,et.eye(t).valueOf())?et.round(i,6):0}function F(e,t,n){var r,a,i,o,s,f=et.add,u=et.unary,c=et.multiply,l=et.divide;if(1==t){if(o=e[0][0],0==o)throw Error("Cannot calculate inverse, determinant is zero");return[[l(1,o)]]}if(2==t){var m=et.det(e);if(0==m)throw Error("Cannot calculate inverse, determinant is zero");return[[l(e[1][1],m),l(u(e[0][1]),m)],[l(u(e[1][0]),m),l(e[0][0],m)]]}var h=e.concat();for(r=0;t>r;r++)h[r]=h[r].concat();for(var p=et.eye(t).valueOf(),g=0;n>g;g++){for(r=g;t>r&&0==h[r][g];)r++;if(r==t||0==h[r][g])throw Error("Cannot calculate inverse, determinant is zero");r!=g&&(s=h[g],h[g]=h[r],h[r]=s,s=p[g],p[g]=p[r],p[r]=s);var v=h[g],d=p[g];for(r=0;t>r;r++){var y=h[r],x=p[r];if(r!=g){if(0!=y[g]){for(i=l(u(y[g]),v[g]),a=g;n>a;a++)y[a]=f(y[a],c(i,v[a]));for(a=0;n>a;a++)x[a]=f(x[a],c(i,d[a]))}}else{for(i=v[g],a=g;n>a;a++)y[a]=l(y[a],i);for(a=0;n>a;a++)x[a]=l(x[a],i)}}}return p}function V(e){if(1==e.length)return V(e[0]);for(var t=0,n=e.length;n>t;t++){var r=e[t];r instanceof Array&&(e[t]=V(r))}return e}function H(e,t){var n,a;return e instanceof Array||e instanceof d?(n=et.matrix(e),a=n.get(t),a.valueOf()):e instanceof r?e.get(t):x(e)?D(e,t):(n=et.matrix([e]),a=n.get(t),a.valueOf())}function D(e,t){var n,r;if(t=t.valueOf(),1!=t.length)throw new RangeError("Dimension mismatch ("+t.length+" != 1)");t instanceof Array&&(t=t[0]),t=t.valueOf(),t instanceof Array||(t=[t]);var a="",i=e.length;for(n=0,r=t.length;r>n;n++){var o=t[n];tt.validateIndex(o,i),a+=e.charAt(o-1)}return a}function Y(e,t,n){if(e instanceof Array||e instanceof d){var a=et.matrix(et.clone(e));return a.set(t,n),a.valueOf()}return e instanceof r?e.clone().set(t,n):x(e)?W(e,t,n):(a=et.matrix([e]),a.set(t,n),a.isScalar()?a.toScalar():a.valueOf())}function W(e,t,n){var r,a;if(t=t.valueOf(),1!=t.length)throw new RangeError("Dimension mismatch ("+t.length+" != 1)");if(t instanceof Array&&(t=t[0]),t=t.valueOf(),t instanceof Array||(t=[t]),t.length!=n.length)throw new RangeError("Dimension mismatch ("+t.length+" != "+n.length+")");var i=e.length,o=[];for(r=0;i>r;r++)o[r]=e.charAt(r);for(r=0,a=t.length;a>r;r++){var s=t[r];tt.validateIndex(s),o[s-1]=n.charAt(r)}if(o.length>i)for(r=i-1,a=o.length;a>r;r++)o[r]||(o[r]=" ");return o.join("")}function Q(e){for(var t=et.larger,n=e[0],r=1,a=e.length;a>r;r++){var i=e[r];t(i,n)&&(n=i)}return n}function K(e,t,n){for(var r=et.larger,a=[],i=0;n>i;i++){for(var o=e[0][i],s=1;t>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function X(e){for(var t=et.smaller,n=e[0],r=1,a=e.length;a>r;r++){var i=e[r];t(i,n)&&(n=i)}return n}function Z(e,t,n){for(var r=et.smaller,a=[],i=0;n>i;i++){for(var o=e[0][i],s=1;t>s;s++){var f=e[s][i];r(f,o)&&(o=f)}a[i]=o}return a}function $(e,t,n){(n.override||void 0===et[e])&&(et[e]=n.wrap&&"function"==typeof t?function(){for(var e=[],n=0,r=arguments.length;r>n;n++)e[n]=arguments[n].valueOf();return t.apply(et,e)}:t,y(e,t))}function J(e){return"function"==typeof e||g(e)||x(e)||e instanceof t||e instanceof w}var et={type:{},expr:{node:{handlers:{}}},docs:{},options:{precision:5}},tt=function(){function e(t){if(t instanceof Array){var n=t.length;if(n){var r=e(t[0]);return 0==r[0]?[0].concat(r):[n].concat(r)}return[n]}return[]}function t(e,n,r){var a,i=e.length;if(i!=n[r])throw new RangeError("Dimension mismatch ("+i+" != "+n[r]+")");if(r<n.length-1){var o=r+1;for(a=0;i>a;a++){var s=e[a];if(!(s instanceof Array))throw new RangeError("Dimension mismatch ("+(n.length-1)+" < "+n.length+")");t(e[a],n,o)}}else for(a=0;i>a;a++)if(e[a]instanceof Array)throw new RangeError("Dimension mismatch ("+(n.length+1)+" > "+n.length+")")}function n(e,t,r){if(r<t.length-1){var a=e[0];if(1!=e.length||!(a instanceof Array))throw new RangeError("Dimension mismatch ("+e.length+" > 0)");n(a,t,r+1)}else if(e.length)throw new RangeError("Dimension mismatch ("+e.length+" > 0)")}function a(e,t,n,r){if(!(e instanceof Array))throw new TypeError("Array expected");var i=e.length,o=t[n];if(i!=o){if(o>e.length)for(var s=e.length;o>s;s++)e[s]=r?et.clone(r):0;else e.length=t[n];i=e.length}if(n<t.length-1){var f=n+1;for(s=0;i>s;s++)u=e[s],u instanceof Array||(u=[u],e[s]=u),a(u,t,f,r)}else for(s=0;i>s;s++){for(var u=e[s];u instanceof Array;)u=u[0];e[s]=u}}var i={};i.formatNumber=function(e,t){if(1/0===e)return"Infinity";if(e===-1/0)return"-Infinity";if(isNaN(e))return"NaN";var n=Math.abs(e);if(n>.001&&1e5>n||0==n)return i.toPrecision(e,t);var r=Math.round(Math.log(n)/Math.LN10),a=e/Math.pow(10,r);return i.toPrecision(a,t)+"e"+r},i.toPrecision=function(e,t){return e.toPrecision(t).replace(o,function(e,t,n){return e.substring(0,e.length-(t.length?0:1)-n.length)})};var o=/\.(\d*?)(0+)$/g;return i.formatArray=function(e){if(e instanceof Array){for(var t="[",n=e.length,r=0;n>r;r++)0!=r&&(t+=", "),t+=i.formatArray(e[r]);return t+="]"}return et.format(e)},i.formatArray2d=function(e){var t="[",n=i.size(e);if(2!=n.length)throw new RangeError("Array must be two dimensional (size: "+i.formatArray(n)+")");for(var r=n[0],a=n[1],o=0;r>o;o++){0!=o&&(t+="; ");for(var s=e[o],f=0;a>f;f++){0!=f&&(t+=", ");var u=s[f];void 0!=u&&(t+=et.format(u))}}return t+="]"},i.argsToArray=function(e){var t;if(0==e.length)t=[];else if(1==e.length)t=e[0],t instanceof r&&(t=t.toVector()),t instanceof d&&(t=t.valueOf()),t instanceof Array||(t=[t]);else{t=[];for(var n=0;n<e.length;n++)t[n]=e[n]}return t},i.endsWith=function(e,t){var n=e.length-t.length,r=e.length;return e.substring(n,r)===t},i.extend=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},i.deepExtend=function s(e,t){for(var n in t)t.hasOwnProperty(n)&&(t[n]&&t[n].constructor===Object?(void 0===e[n]&&(e[n]={}),e[n].constructor===Object?s(e[n],t[n]):e[n]=t[n]):e[n]=t[n]);return e},i.randomUUID=function(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()},i.map=function(e,t){if(e instanceof Array||e instanceof r||e instanceof d)return e.map(function(e){return t(e)});throw new TypeError("Array expected")},i.deepMap=function f(e,t){return e instanceof Array||e instanceof r||e instanceof d?e.map(function(e){return f(e,t)}):t(e)},i.map2=function(e,t,n){var a,o,s;if(e instanceof r||t instanceof r)return new r(i.map2(e.valueOf(),t.valueOf(),n));if(e instanceof d||t instanceof d)return i.map2(e.valueOf(),t.valueOf(),n);if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(a=[],o=e.length,s=0;o>s;s++)a[s]=n(e[s],t[s])}else for(a=[],o=e.length,s=0;o>s;s++)a[s]=n(e[s],t);else if(t instanceof Array)for(a=[],o=t.length,s=0;o>s;s++)a[s]=n(e,t[s]);else a=n(e,t);return a},i.deepMap2=function u(e,t,n){var a,i,o;if(e instanceof r||t instanceof r)return new r(u(e.valueOf(),t.valueOf(),n));if(e instanceof d||t instanceof d)return u(e.valueOf(),t.valueOf(),n);if(e instanceof Array)if(t instanceof Array){if(e.length!=t.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+t.length+")");for(a=[],i=e.length,o=0;i>o;o++)a[o]=u(e[o],t[o],n)}else for(a=[],i=e.length,o=0;i>o;o++)a[o]=u(e[o],t,n);else if(t instanceof Array)for(a=[],i=t.length,o=0;i>o;o++)a[o]=u(e,t[o],n);else a=n(e,t);return a},i.forEach=function(e,t){if(e instanceof Array)e.forEach(t);else for(var n in e)e.hasOwnProperty(n)&&t(e[n],n,e)},i.mapObject=function(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n},i.deepEqual=function(e,t){var n,r,a;if(e instanceof Array){if(!(t instanceof Array))return!1;for(r=0,a=e.length;a>r;r++)if(!i.deepEqual(e[r],t[r]))return!1;return!0}if(e instanceof Object){if(t instanceof Array||!(t instanceof Object))return!1;for(n in e)if(e.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;for(n in t)if(t.hasOwnProperty(n)&&!i.deepEqual(e[n],t[n]))return!1;return!0}return e.valueOf()==t.valueOf()},i.size=function(t){var n=e(t);return i.validate(t,n),n},i.validate=function(e,r){var a=0==r.length;if(a){if(e instanceof Array)throw new RangeError("Dimension mismatch ("+e.length+" != 0)")}else{var o=-1!=r.indexOf(0);o?(r.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(r)+")")}),n(e,r,0)):t(e,r,0)}},i.validateIndex=function(e,t){if(!g(e)||!v(e))throw new TypeError("Index must be an integer (value: "+e+")");if(1>e)throw new RangeError("Index out of range ("+e+" < 1)");if(t&&e>t)throw new RangeError("Index out of range ("+e+" > "+t+")")},i.resize=function(e,t,n){if(!(t instanceof Array))throw new TypeError("Size must be an array (size is "+et["typeof"](t)+")");t.forEach(function(e){if(!g(e)||!v(e)||0>e)throw new TypeError("Invalid size, must contain positive integers (size: "+i.formatArray(t)+")")});var r=-1!=t.indexOf(0);r&&t.forEach(function(e){if(0!=e)throw new RangeError("Invalid size, all dimensions must be either zero or non-zero (size: "+i.formatArray(t)+")")}),a(e,t,0,n)},i}();et.type.Complex=t,function(){function e(){for(;" "==c||" "==c;)a()}function n(e){return e>="0"&&"9">=e||"."==e}function r(e){return e>="0"&&"9">=e}function a(){u++,c=f.charAt(u)}function i(e){u=e,c=f.charAt(u)}function o(){var e,t="";if(e=u,"+"==c?a():"-"==c&&(t+=c,a()),!n(c))return i(e),null;if("."==c){if(t+=c,a(),!r(c))return i(e),null}else{for(;r(c);)t+=c,a();"."==c&&(t+=c,a())}for(;r(c);)t+=c,a();if("E"==c||"e"==c){if(t+=c,a(),("+"==c||"-"==c)&&(t+=c,a()),!r(c))return i(e),null;for(;r(c);)t+=c,a()}return t}function s(){var e=f.charAt(u+1);if("I"==c||"i"==c)return a(),"1";if(!("+"!=c&&"-"!=c||"I"!=e&&"i"!=e)){var t="+"==c?"1":"-1";return a(),a(),t}return null}var f,u,c;t.create=function(e,n){return 0==n?e:new t(e,n)},t.parse=function(n){if(f=n,u=-1,c="",!x(f))return null;a(),e();var r=o();if(r){if("I"==c||"i"==c)return a(),e(),c?null:new t(0,Number(r));e();var i=c;if("+"!=i&&"-"!=i)return e(),c?null:new t(Number(r),0);a(),e();var l=o();if(l){if("I"!=c&&"i"!=c)return null;a()}else if(l=s(),!l)return null;return"-"==i&&(l="-"==l[0]?"+"+l.substring(1):"-"+l),a(),e(),c?null:new t(Number(r),Number(l))}return(r=s())?(e(),c?null:new t(0,Number(r))):null}}(),t.prototype.clone=function(){return new t(this.re,this.im)},t.prototype.toString=function(){var e="",t=tt.formatNumber(this.re,et.options.precision),n=tt.formatNumber(this.im,et.options.precision);return e=0==this.im?t:0==this.re?1==this.im?"i":-1==this.im?"-i":n+"i":this.im>0?1==this.im?t+" + i":t+" + "+n+"i":-1==this.im?t+" - i":t+" - "+tt.formatNumber(Math.abs(this.im),et.options.precision)+"i"},et.type.Help=n,n.prototype.toString=function(){var e="";if(this.name&&(e+="NAME\n"+this.name+"\n\n"),this.category&&(e+="CATEGORY\n"+this.category+"\n\n"),this.syntax&&(e+="SYNTAX\n"+this.syntax.join("\n")+"\n\n"),this.examples){var t=et.parser();e+="EXAMPLES\n";for(var n=0;n<this.examples.length;n++){var r,a=this.examples[n];try{r=t.eval(a)}catch(i){r=i}e+=a+"\n",e+=" "+et.format(r)+"\n"}e+="\n"}return this.seealso&&(e+="SEE ALSO\n"+this.seealso.join(", ")+"\n"),e},n.prototype.toJSON=function(){return tt.extend({},this)},et.type.Matrix=r,r.prototype.get=function(e){var t;if(e instanceof r)t=1==e.size().length||!e.size().some(function(e){return 1!=e}),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Invalid index");t=!e.some(function(e){var t=et.size(e);return 0!=t.length&&t!=[1]})}if(e.length!=this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(t)switch(e.length){case 1:return a(this._data,e[0]);case 2:return a(a(this._data,e[0]),e[1]);default:return i(this._data,e)}else switch(e.length){case 1:return new r(o(this._data,e));case 2:return new r(s(this._data,e));default:return new r(f(this._data,e,0))}},r.prototype.set=function(e,t){var n;if(e instanceof r)n=1==e.size().length||!e.size().some(function(e){return 1!=e}),e=e.valueOf();else{if(!(e instanceof Array))throw new TypeError("Invalid index");n=!e.some(function(e){var t=et.size(e);return 0!=t.length&&t!=[1]})}if((t instanceof r||t instanceof d)&&(t=t.valueOf()),e.length<this._size.length)throw new RangeError("Dimension mismatch ("+e.length+" != "+this._size.length+")");if(n){if(0!=et.size(t).valueOf().length)throw new TypeError("Scalar value expected");switch(e.length){case 1:l(this._data,this._size,e,t);break;case 2:m(this._data,this._size,e,t);break;default:c(this._data,this._size,e,t)}}else{var a=this._size.concat();h(this._data,a,e,0,t),tt.deepEqual(this._size,a)||(p(this._data),this.resize(a))}return this},r.prototype.resize=function(e,t){tt.resize(this._data,e,t),this._size=et.clone(e)},r.prototype.clone=function(){var e=new r;return e._data=et.clone(this._data),e._size=et.clone(this._size),e},r.prototype.size=function(){return this._size},r.prototype.map=function(e){var t=this,n=new r,a=[],i=function(n,r){return n instanceof Array?n.map(function(e,t){return a[r]=t+1,i(e,r+1)}):e(n,a,t)};return n._data=i(this._data,0),n._size=et.clone(this._size),n},r.prototype.forEach=function(e){var t=this,n=[],r=function(a,i){a instanceof Array?a.forEach(function(e,t){n[i]=t+1,r(e,i+1)}):e(a,n,t)};r(this._data,0)},r.prototype.toScalar=function(){for(var e=this._data;e instanceof Array&&1==e.length;)e=e[0];return e instanceof Array?null:et.clone(e)},r.prototype.isScalar=function(){return this._size.every(function(e){return 1>=e})},r.prototype.toVector=function(){var e=0,t=void 0,n=[];if(this._size.forEach(function(r,a){r>1&&(e++,t=a),n[a]=0}),0==e){var r=this.toScalar();return r?[r]:[]}if(1==e){var a=[],i=function(e){e instanceof Array?e.forEach(i):a.push(e)};return i(this._data),a}return null},r.prototype.isVector=function(){var e=0;return this._size.forEach(function(t){t>1&&e++}),1>=e},r.prototype.toArray=function(){return et.clone(this._data)},r.prototype.valueOf=function(){return this._data},r.prototype.toString=function(){return et.format(this._data)},et.type.Range=d,d.parse=function(e){if(!x(e))return null;var t=e.split(":"),n=t.map(function(e){return Number(e)}),r=n.some(function(e){return isNaN(e)});if(r)return null;switch(n.length){case 2:return new d(n[0],1,n[1]);case 3:return new d(n[0],n[1],n[2]);default:return null}},d.prototype.clone=function(){return new d(this.start,this.step,this.end)},d.prototype.size=function(){var e=0,t=Number(this.start),n=Number(this.step),r=Number(this.end),a=r-t;return et.sign(n)==et.sign(a)?e=Math.floor(a/n)+1:0==a&&(e=1),isNaN(e)&&(e=0),[e]},d.prototype.forEach=function(e){var t=Number(this.start),n=Number(this.step),r=Number(this.end),a=0;if(n>0)for(;r>=t;)e(t,a,this),t+=n,a++;else if(0>n)for(;t>=r;)e(t,a,this),t+=n,a++},d.prototype.map=function(e){var t=[];return this.forEach(function(n,r,a){t[r]=e(n,r,a)}),t},d.prototype.toMatrix=function(){return new r(this.toArray())},d.prototype.toArray=function(){var e=[];return this.forEach(function(t,n){e[n]=t}),e},d.prototype.toVector=d.prototype.toArray,d.prototype.isVector=function(){return!0},d.prototype.toScalar=function(){var e=this.toArray();return 1==e.length?e[0]:null},d.prototype.isScalar=function(){return 1==this.size()[0]},d.prototype.valueOf=function(){return this.toArray()},d.prototype.toString=function(){var e=et.format(Number(this.start));return 1!=this.step&&(e+=":"+et.format(Number(this.step))),e+=":"+et.format(Number(this.end))},et.type.Selector=function(e){if(!(this instanceof et.type.Selector))throw new SyntaxError("Selector constructor must be called with the new operator");this.value=e instanceof et.type.Selector?e.value:e||void 0},et.type.Selector.prototype={done:function(){return this.value},get:function(e){var t=this.value;if(!t)throw Error("Selector value is undefined");return new et.type.Selector(et.subset(t,e))},set:function(e,t){var n=this.value;if(!n)throw Error("Selector value is undefined");return new et.type.Selector(et.subset(n,e,t))},valueOf:function(){return this.value},toString:function(){return et.format(this.value)}},et.type.Unit=w,function(){function e(){for(;" "==u||" "==u;)r()}function t(e){return e>="0"&&"9">=e||"."==e}function n(e){return e>="0"&&"9">=e}function r(){f++,u=s.charAt(f)}function a(e){f=e,u=s.charAt(f)}function i(){var e,i="";if(e=f,"+"==u?r():"-"==u&&(i+=u,r()),!t(u))return a(e),null;if("."==u){if(i+=u,r(),!n(u))return a(e),null}else{for(;n(u);)i+=u,r();"."==u&&(i+=u,r())}for(;n(u);)i+=u,r();if("E"==u||"e"==u){if(i+=u,r(),("+"==u||"-"==u)&&(i+=u,r()),!n(u))return a(e),null;for(;n(u);)i+=u,r()}return i}function o(){var t="";for(e();u&&" "!=u&&" "!=u;)t+=u,r();return t||null}var s,f,u;w.parse=function(t){if(s=t,f=-1,u="",!x(s))return null;r(),e();var n,a=i();return a?(n=o(),r(),e(),u?null:a&&n?new w(Number(a),n):null):(n=o(),r(),e(),u?null:new w(null,n))}}(),w.prototype.clone=function(){var e=new w;for(var t in this)this.hasOwnProperty(t)&&(e[t]=this[t]);return e},w.prototype._normalize=function(e){return(e+this.unit.offset)*this.unit.value*this.prefix.value},w.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},w.isPlainUnit=function(e){return null!=b(e)},w.prototype.hasBase=function(e){return void 0===this.unit.base?void 0===e:this.unit.base===e},w.prototype.equalBase=function(e){return this.unit.base===e.unit.base},w.prototype.equals=function(e){return this.equalBase(e)&&this.value==e.value},w.prototype["in"]=function(e){var t;if(x(e)){if(t=new w(null,e),!this.equalBase(t))throw new Error("Units do not match");return t.value=this.value,t}if(e instanceof w){if(!this.equalBase(e))throw new Error("Units do not match");if(null!=e.value)throw new Error("Cannot convert to a unit with a value");if(null==e.unit)throw new Error("Unit expected on the right hand side of function in");return t=e.clone(),t.value=this.value,t.fixPrefix=!0,t}throw new Error("String or Unit expected as parameter")},w.prototype.toNumber=function(e){var t=this["in"](e),n=this.fixPrefix?t._bestPrefix():t.prefix;return t._unnormalize(t.value,n.value)},w.prototype.toString=function(){var e,t;if(this.fixPrefix)e=this._unnormalize(this.value),t=null!=this.value?tt.formatNumber(e,et.options.precision)+" ":"",t+=this.prefix.name+this.unit.name;else{var n=this._bestPrefix();e=this._unnormalize(this.value,n.value),t=null!=this.value?tt.formatNumber(e,et.options.precision)+" ":"",t+=n.name+this.unit.name}return t},w.prototype._bestPrefix=function(){var e=Math.abs(this.value/this.unit.value),t=w.PREFIX_NONE,n=Math.abs(Math.log(e/t.value)/Math.LN10-1.2),r=this.unit.prefixes;for(var a in r)if(r.hasOwnProperty(a)){var i=r[a];if(i.scientific){var o=Math.abs(Math.log(e/i.value)/Math.LN10-1.2);n>o&&(t=i,n=o)}}return t},w.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}}},w.PREFIX_NONE={name:"",value:1,scientific:!0},w.BASE_UNITS={NONE:{},LENGTH:{},MASS:{},TIME:{},CURRENT:{},TEMPERATURE:{},LUMINOUS_INTENSITY:{},AMOUNT_OF_SUBSTANCE:{},FORCE:{},SURFACE:{},VOLUME:{},ANGLE:{},BIT:{}};var nt=w.BASE_UNITS,rt=w.PREFIXES;w.BASE_UNIT_NONE={},w.UNIT_NONE={name:"",base:w.BASE_UNIT_NONE,value:1,offset:0},w.UNITS=[{name:"meter",base:nt.LENGTH,prefixes:rt.LONG,value:1,offset:0},{name:"inch",base:nt.LENGTH,prefixes:rt.NONE,value:.0254,offset:0},{name:"foot",base:nt.LENGTH,prefixes:rt.NONE,value:.3048,offset:0},{name:"yard",base:nt.LENGTH,prefixes:rt.NONE,value:.9144,offset:0},{name:"mile",base:nt.LENGTH,prefixes:rt.NONE,value:1609.344,offset:0},{name:"link",base:nt.LENGTH,prefixes:rt.NONE,value:.201168,offset:0},{name:"rod",base:nt.LENGTH,prefixes:rt.NONE,value:5.02921,offset:0},{name:"chain",base:nt.LENGTH,prefixes:rt.NONE,value:20.1168,offset:0},{name:"angstrom",base:nt.LENGTH,prefixes:rt.NONE,value:1e-10,offset:0},{name:"m",base:nt.LENGTH,prefixes:rt.SHORT,value:1,offset:0},{name:"ft",base:nt.LENGTH,prefixes:rt.NONE,value:.3048,offset:0},{name:"yd",base:nt.LENGTH,prefixes:rt.NONE,value:.9144,offset:0},{name:"mi",base:nt.LENGTH,prefixes:rt.NONE,value:1609.344,offset:0},{name:"li",base:nt.LENGTH,prefixes:rt.NONE,value:.201168,offset:0},{name:"rd",base:nt.LENGTH,prefixes:rt.NONE,value:5.02921,offset:0},{name:"ch",base:nt.LENGTH,prefixes:rt.NONE,value:20.1168,offset:0},{name:"mil",base:nt.LENGTH,prefixes:rt.NONE,value:254e-7,offset:0},{name:"m2",base:nt.SURFACE,prefixes:rt.SHORT,value:1,offset:0},{name:"sqin",base:nt.SURFACE,prefixes:rt.NONE,value:64516e-8,offset:0},{name:"sqft",base:nt.SURFACE,prefixes:rt.NONE,value:.09290304,offset:0},{name:"sqyd",base:nt.SURFACE,prefixes:rt.NONE,value:.83612736,offset:0},{name:"sqmi",base:nt.SURFACE,prefixes:rt.NONE,value:2589988.110336,offset:0},{name:"sqrd",base:nt.SURFACE,prefixes:rt.NONE,value:25.29295,offset:0},{name:"sqch",base:nt.SURFACE,prefixes:rt.NONE,value:404.6873,offset:0},{name:"sqmil",base:nt.SURFACE,prefixes:rt.NONE,value:6.4516e-10,offset:0},{name:"m3",base:nt.VOLUME,prefixes:rt.SHORT,value:1,offset:0},{name:"L",base:nt.VOLUME,prefixes:rt.SHORT,value:.001,offset:0},{name:"litre",base:nt.VOLUME,prefixes:rt.LONG,value:.001,offset:0},{name:"cuin",base:nt.VOLUME,prefixes:rt.NONE,value:16387064e-12,offset:0},{name:"cuft",base:nt.VOLUME,prefixes:rt.NONE,value:.028316846592,offset:0},{name:"cuyd",base:nt.VOLUME,prefixes:rt.NONE,value:.764554857984,offset:0},{name:"teaspoon",base:nt.VOLUME,prefixes:rt.NONE,value:5e-6,offset:0},{name:"tablespoon",base:nt.VOLUME,prefixes:rt.NONE,value:15e-6,offset:0},{name:"minim",base:nt.VOLUME,prefixes:rt.NONE,value:6.161152e-8,offset:0},{name:"fluiddram",base:nt.VOLUME,prefixes:rt.NONE,value:36966911e-13,offset:0},{name:"fluidounce",base:nt.VOLUME,prefixes:rt.NONE,value:2957353e-11,offset:0},{name:"gill",base:nt.VOLUME,prefixes:rt.NONE,value:.0001182941,offset:0},{name:"cup",base:nt.VOLUME,prefixes:rt.NONE,value:.0002365882,offset:0},{name:"pint",base:nt.VOLUME,prefixes:rt.NONE,value:.0004731765,offset:0},{name:"quart",base:nt.VOLUME,prefixes:rt.NONE,value:.0009463529,offset:0},{name:"gallon",base:nt.VOLUME,prefixes:rt.NONE,value:.003785412,offset:0},{name:"beerbarrel",base:nt.VOLUME,prefixes:rt.NONE,value:.1173478,offset:0},{name:"oilbarrel",base:nt.VOLUME,prefixes:rt.NONE,value:.1589873,offset:0},{name:"hogshead",base:nt.VOLUME,prefixes:rt.NONE,value:.238481,offset:0},{name:"fldr",base:nt.VOLUME,prefixes:rt.NONE,value:36966911e-13,offset:0},{name:"floz",base:nt.VOLUME,prefixes:rt.NONE,value:2957353e-11,offset:0},{name:"gi",base:nt.VOLUME,prefixes:rt.NONE,value:.0001182941,offset:0},{name:"cp",base:nt.VOLUME,prefixes:rt.NONE,value:.0002365882,offset:0},{name:"pt",base:nt.VOLUME,prefixes:rt.NONE,value:.0004731765,offset:0},{name:"qt",base:nt.VOLUME,prefixes:rt.NONE,value:.0009463529,offset:0},{name:"gal",base:nt.VOLUME,prefixes:rt.NONE,value:.003785412,offset:0},{name:"bbl",base:nt.VOLUME,prefixes:rt.NONE,value:.1173478,offset:0},{name:"obl",base:nt.VOLUME,prefixes:rt.NONE,value:.1589873,offset:0},{name:"g",base:nt.MASS,prefixes:rt.SHORT,value:.001,offset:0},{name:"gram",base:nt.MASS,prefixes:rt.LONG,value:.001,offset:0},{name:"ton",base:nt.MASS,prefixes:rt.SHORT,value:907.18474,offset:0},{name:"tonne",base:nt.MASS,prefixes:rt.SHORT,value:1e3,offset:0},{name:"grain",base:nt.MASS,prefixes:rt.NONE,value:6479891e-11,offset:0},{name:"dram",base:nt.MASS,prefixes:rt.NONE,value:.0017718451953125,offset:0},{name:"ounce",base:nt.MASS,prefixes:rt.NONE,value:.028349523125,offset:0},{name:"poundmass",base:nt.MASS,prefixes:rt.NONE,value:.45359237,offset:0},{name:"hundredweight",base:nt.MASS,prefixes:rt.NONE,value:45.359237,offset:0},{name:"stick",base:nt.MASS,prefixes:rt.NONE,value:.115,offset:0},{name:"gr",base:nt.MASS,prefixes:rt.NONE,value:6479891e-11,offset:0},{name:"dr",base:nt.MASS,prefixes:rt.NONE,value:.0017718451953125,offset:0},{name:"oz",base:nt.MASS,prefixes:rt.NONE,value:.028349523125,offset:0},{name:"lbm",base:nt.MASS,prefixes:rt.NONE,value:.45359237,offset:0},{name:"cwt",base:nt.MASS,prefixes:rt.NONE,value:45.359237,offset:0},{name:"s",base:nt.TIME,prefixes:rt.SHORT,value:1,offset:0},{name:"min",base:nt.TIME,prefixes:rt.NONE,value:60,offset:0},{name:"h",base:nt.TIME,prefixes:rt.NONE,value:3600,offset:0},{name:"seconds",base:nt.TIME,prefixes:rt.LONG,value:1,offset:0},{name:"second",base:nt.TIME,prefixes:rt.LONG,value:1,offset:0},{name:"sec",base:nt.TIME,prefixes:rt.LONG,value:1,offset:0},{name:"minutes",base:nt.TIME,prefixes:rt.NONE,value:60,offset:0},{name:"minute",base:nt.TIME,prefixes:rt.NONE,value:60,offset:0},{name:"hours",base:nt.TIME,prefixes:rt.NONE,value:3600,offset:0},{name:"hour",base:nt.TIME,prefixes:rt.NONE,value:3600,offset:0},{name:"day",base:nt.TIME,prefixes:rt.NONE,value:86400,offset:0},{name:"days",base:nt.TIME,prefixes:rt.NONE,value:86400,offset:0},{name:"rad",base:nt.ANGLE,prefixes:rt.NONE,value:1,offset:0},{name:"deg",base:nt.ANGLE,prefixes:rt.NONE,value:.017453292519943295,offset:0},{name:"grad",base:nt.ANGLE,prefixes:rt.NONE,value:.015707963267948967,offset:0},{name:"cycle",base:nt.ANGLE,prefixes:rt.NONE,value:6.283185307179586,offset:0},{name:"A",base:nt.CURRENT,prefixes:rt.SHORT,value:1,offset:0},{name:"ampere",base:nt.CURRENT,prefixes:rt.LONG,value:1,offset:0},{name:"K",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1,offset:0},{name:"degC",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1,offset:273.15},{name:"degF",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1/1.8,offset:459.67},{name:"degR",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1/1.8,offset:0},{name:"kelvin",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1,offset:0},{name:"celsius",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1,offset:273.15},{name:"fahrenheit",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1/1.8,offset:459.67},{name:"rankine",base:nt.TEMPERATURE,prefixes:rt.NONE,value:1/1.8,offset:0},{name:"mol",base:nt.AMOUNT_OF_SUBSTANCE,prefixes:rt.NONE,value:1,offset:0},{name:"mole",base:nt.AMOUNT_OF_SUBSTANCE,prefixes:rt.NONE,value:1,offset:0},{name:"cd",base:nt.LUMINOUS_INTENSITY,prefixes:rt.NONE,value:1,offset:0},{name:"candela",base:nt.LUMINOUS_INTENSITY,prefixes:rt.NONE,value:1,offset:0},{name:"N",base:nt.FORCE,prefixes:rt.SHORT,value:1,offset:0},{name:"newton",base:nt.FORCE,prefixes:rt.LONG,value:1,offset:0},{name:"lbf",base:nt.FORCE,prefixes:rt.NONE,value:4.4482216152605,offset:0},{name:"poundforce",base:nt.FORCE,prefixes:rt.NONE,value:4.4482216152605,offset:0},{name:"b",base:nt.BIT,prefixes:rt.BINARY_SHORT,value:1,offset:0},{name:"bits",base:nt.BIT,prefixes:rt.BINARY_LONG,value:1,offset:0},{name:"B",base:nt.BIT,prefixes:rt.BINARY_SHORT,value:8,offset:0},{name:"bytes",base:nt.BIT,prefixes:rt.BINARY_LONG,value:8,offset:0}],et.pi=Math.PI,et.e=Math.E,et.tau=2*Math.PI,et.i=new t(0,1),et.Infinity=1/0,et.NaN=0/0,et.E=Math.E,et.LN2=Math.LN2,et.LN10=Math.LN10,et.LOG2E=Math.LOG2E,et.LOG10E=Math.LOG10E,et.PI=Math.PI,et.SQRT1_2=Math.SQRT1_2,et.SQRT2=Math.SQRT2,et.expr.node.Node=N,N.prototype.eval=function(){throw new Error("Cannot evaluate a Node interface")
},N.prototype.find=function(e){return this.match(e)?[this]:[]},N.prototype.match=function(e){var t=!0;if(e&&(!e.type||this instanceof e.type||(t=!1),t&&e.properties))for(var n in e.properties)if(e.properties.hasOwnProperty(n)&&this[n]!=e.properties[n]){t=!1;break}return t},N.prototype.toString=function(){return""},M.prototype=new N,et.expr.node.ConstantNode=M,M.prototype.eval=function(){return this.value},M.prototype.toString=function(){return et.format(this.value||null)},A.prototype=new N,et.expr.node.OperatorNode=A,A.prototype.eval=function(){return this.fn.apply(this,this.params.map(function(e){return e.eval()}))},A.prototype.find=function(e){var t=[];this.match(e)&&t.push(this);var n=this.params;if(n)for(var r=0,a=n.length;a>r;r++)t=t.concat(n[r].find(e));return t},A.prototype.toString=function(){var e=this.params;if(this.fn===et.unary)return"-"+e[0].toString();switch(e.length){case 1:return e[0].toString()+this.name;case 2:var t=e[0].toString();e[0]instanceof A&&(t="("+t+")");var n=e[1].toString();return e[1]instanceof A&&(n="("+n+")"),t+" "+this.name+" "+n;default:return this.name+"("+this.params.join(", ")+")"}},S.prototype=new N,et.expr.node.SymbolNode=S,S.prototype.eval=function(){var e=this.scope.get(this.name);if(void 0===e)throw new Error("Undefined symbol "+this.name);return e},S.prototype.toString=function(){return this.name},T.prototype=new N,et.expr.node.ParamsNode=T,T.prototype.eval=function(){var e,t,n=this.object;if(void 0==n)throw new Error("Node undefined");var r=n.eval();if(this.hasContextParams){var a,i=this.paramScopes;if(a=r.size?r.size():void 0!==r.length?[r.length]:[],i&&a)for(e=0,t=this.params.length;t>e;e++){var o=i[e];o&&o.set("end",a[e])}}var s=this.params,f=[];for(e=0,t=this.params.length;t>e;e++)f[e]=s[e].eval();return"function"==typeof r?r.apply(this,f):et.subset(r,f)},T.prototype.find=function(e){var t=[];this.match(e)&&t.push(this),this.object&&(t=t.concat(this.object.find(e)));var n=this.params;if(n)for(var r=0,a=n.length;a>r;r++)t=t.concat(n[r].find(e));return t},T.prototype.toString=function(){var e=this.object?this.object.toString():"";return this.params&&(e+="("+this.params.join(", ")+")"),e},q.prototype=new N,et.expr.node.MatrixNode=q,function(){function e(e){for(var t=[],n=e.length,a=0;n>a;a++){for(var i=e[a],o=i.length,s=null,f=null,u=0;o>u;u++){var c,l=et.clone(i[u]);if(l instanceof r){if(c=l.size(),l=l.valueOf(),1==c.length)l=[l],c=[1,c[0]];else if(c.length>2)throw new Error("Cannot merge a multi dimensional matrix")}else l instanceof d?(l=[l.valueOf()],c=[1,l[0].length]):l instanceof Array?(c=[1,l.length],l=[l]):(c=[1,1],l=[[l]]);if(null==s)s=l,f=c[0];else{if(c[0]!=f)throw new Error("Dimension mismatch ("+c[0]+" != "+f+")");for(var m=0;f>m;m++)s[m]=s[m].concat(l[m])}}t=t.concat(s)}return t}q.prototype.eval=function(){for(var t=this.nodes,n=[],a=!1,i=0,o=t.length;o>i;i++){for(var s=t[i],f=[],u=0,c=s.length;c>u;u++){var l=s[u].eval();(l instanceof r||l instanceof d||l instanceof Array)&&(a=!0),f[u]=l}n[i]=f}return a&&(n=e(n)),new r(n)},q.prototype.find=function(e){var t=[];this.match(e)&&t.push(this);for(var n=this.nodes,r=0,a=n.length;a>r;r++)for(var i=n[r],o=0,s=i.length;s>o;o++)t=t.concat(i[o].find(e));return t},q.prototype.toString=function(){return tt.formatArray(this.nodes)}}(),z.prototype=new N,et.expr.node.BlockNode=z,z.prototype.add=function(e,t){var n=this.params.length;this.params[n]=e,this.visible[n]=void 0!=t?t:!0},z.prototype.eval=function(){for(var e=[],t=0,n=this.params.length;n>t;t++){var r=this.params[t].eval();this.visible[t]&&e.push(r)}return e},z.prototype.find=function(e){var t=[];this.match(e)&&t.push(this);var n=this.params;if(n)for(var r=0,a=n.length;a>r;r++)t=t.concat(n[r].find(e));return t},z.prototype.toString=function(){for(var e=[],t=0,n=this.params.length;n>t;t++)this.visible[t]&&e.push("\n "+this.params[t].toString());return"["+e.join(",")+"\n]"},R.prototype=new N,et.expr.node.AssignmentNode=R,R.prototype.eval=function(){if(void 0===this.expr)throw new Error("Undefined symbol "+this.name);var e=this.expr.eval();return this.scope.set(this.name,e),e},R.prototype.find=function(e){var t=[];return this.match(e)&&t.push(this),this.expr&&(t=t.concat(this.expr.find(e))),t},R.prototype.toString=function(){return this.name+" = "+this.expr.toString()},C.prototype=new N,et.expr.node.UpdateNode=C,C.prototype.eval=function(){if(void 0===this.expr)throw new Error("Undefined symbol "+this.name);var e;this.params;var t=this.scope.get(this.name);if(void 0==t)throw new Error("Undefined symbol "+this.name);if(this.hasContextParams){var n,r=this.paramScopes;if(n=t.size?t.size():void 0!==t.length?[t.length]:[],r&&n)for(var a=0,i=this.params.length;i>a;a++){var o=r[a];o&&o.set("end",n[a])}}var s=[];this.params.forEach(function(e){s.push(e.eval())});var f=this.expr.eval();return e=et.subset(t,s,f),this.scope.set(this.name,e),e},C.prototype.find=function(e){var t=[];this.match(e)&&t.push(this);var n=this.params;if(n)for(var r=0,a=n.length;a>r;r++)t=t.concat(n[r].find(e));return this.expr&&(t=t.concat(this.expr.find(e))),t},C.prototype.toString=function(){var e="";return e+=this.name,this.params&&this.params.length&&(e+="("+this.params.join(", ")+")"),e+=" = ",e+=this.expr.toString()},U.prototype=new N,et.expr.node.FunctionNode=U,U.prototype.eval=function(){return this.scope.set(this.name,this.fn),this.fn},U.prototype.find=function(e){var t=[];return this.match(e)&&t.push(this),this.expr&&(t=t.concat(this.expr.find(e))),t},U.prototype.toString=function(){return this.fn.toString()},et.expr.Scope=function(){if(this.parentScope=null,this.subScopes=null,this.symbols={},this.cache={},arguments.length>0){var e=arguments[0];e instanceof et.expr.Scope?this.parentScope=e:e instanceof Object&&(this.symbols=e)}if(arguments.length>1){var t=arguments[1];t instanceof Object&&(this.symbols=t)}},et.expr.Scope.prototype={createSubScope:function(){var e=new et.expr.Scope(this);return this.subScopes||(this.subScopes=[]),this.subScopes.push(e),e},get:function(e){var t;if(t=this.symbols[e],void 0!==t)return t;var n=this.cache[e];if(n)return n[e];for(var r=this.parentScope;r;){if(t=r.symbols[e],void 0!==t)return this.cache[e]=r.symbols,t;r=r.parentScope}return t=et[e],void 0!==t?(this.cache[e]=et,t):w.isPlainUnit(e)?(t=new w(null,e),this.cache[e]={},this.cache[e][e]=t,t):void 0},has:function(e){return void 0!==this.symbols[e]},set:function(e,t){return this.symbols[e]=t},remove:function(e){delete this.symbols[e]},clear:function(){var e=this.symbols;for(var t in e)e.hasOwnProperty(t)&&delete e[t];if(this.subScopes)for(var n=this.subScopes,r=0,a=n.length;a>r;r++)n[r].clear();this.clearCache()},clearCache:function(){this.cache={}}},et.expr.Parser=function(){if(!(this instanceof et.expr.Parser))throw new SyntaxError("Parser constructor must be called with the new operator");this.scope=new et.expr.Scope},et.expr.Parser.prototype.parse=function(e){return et.parse(e,this.scope)},et.expr.Parser.prototype.eval=function(e){var t=et.parse(e,this.scope);return t.eval()},et.expr.Parser.prototype.get=function(e){return this.scope.get(e)},et.expr.Parser.prototype.set=function(e,t){this.scope.set(e,t)},et.expr.Parser.prototype.remove=function(e){this.scope.remove(e)},et.expr.Parser.prototype.clear=function(){this.scope.clear()},et.abs=function(e){if(1!=arguments.length)throw O("abs",arguments.length,1);if(g(e))return Math.abs(e);if(e instanceof t)return Math.sqrt(e.re*e.re+e.im*e.im);if(e instanceof Array||e instanceof r)return tt.map(e,et.abs);if(e.valueOf()!==e)return et.abs(e.valueOf());throw E("abs",e)},et.add=function(e,n){if(2!=arguments.length)throw O("add",arguments.length,2);if(g(e)){if(g(n))return e+n;if(n instanceof t)return t.create(e+n.re,n.im)}else if(e instanceof t){if(g(n))return t.create(e.re+n,e.im);if(n instanceof t)return t.create(e.re+n.re,e.im+n.im)}else if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Units do not match");if(null==e.value)throw new Error("Unit on left hand side of operator + has an undefined value");if(null==n.value)throw new Error("Unit on right hand side of operator + has an undefined value");var a=e.clone();return a.value+=n.value,a.fixPrefix=!1,a}if(x(e)||x(n))return e+n;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.add);if(e.valueOf()!==e||n.valueOf()!==n)return et.add(e.valueOf(),n.valueOf());throw E("add",e,n)},et.ceil=function(e){if(1!=arguments.length)throw O("ceil",arguments.length,1);if(g(e))return Math.ceil(e);if(e instanceof t)return t.create(Math.ceil(e.re),Math.ceil(e.im));if(e instanceof Array||e instanceof r)return tt.map(e,et.ceil);if(e.valueOf()!==e)return et.ceil(e.valueOf());throw E("ceil",e)},et.cube=function(e){if(1!=arguments.length)throw O("cube",arguments.length,1);if(g(e))return e*e*e;if(e instanceof t)return et.multiply(et.multiply(e,e),e);if(e instanceof Array||e instanceof r)return tt.map(e,et.cube);if(e.valueOf()!==e)return et.cube(e.valueOf());throw E("cube",e)},et.divide=function(e,n){if(2!=arguments.length)throw O("divide",arguments.length,2);if(g(e)){if(g(n))return e/n;if(n instanceof t)return L(new t(e,0),n)}if(e instanceof t){if(g(n))return L(e,new t(n,0));if(n instanceof t)return L(e,n)}if(e instanceof w&&g(n)){var a=e.clone();return a.value/=n,a}if(e instanceof Array||e instanceof r)return n instanceof Array||n instanceof r?et.multiply(e,et.inv(n)):tt.map2(e,n,et.divide);if(n instanceof Array||n instanceof r)return et.multiply(e,et.inv(n));if(e.valueOf()!==e||n.valueOf()!==n)return et.divide(e.valueOf(),n.valueOf());throw E("divide",e,n)},et.edivide=function(e,t){if(2!=arguments.length)throw O("edivide",arguments.length,2);return tt.deepMap2(e,t,et.divide)},et.emultiply=function(e,t){if(2!=arguments.length)throw O("emultiply",arguments.length,2);return tt.deepMap2(e,t,et.multiply)},et.epow=function(e,t){if(2!=arguments.length)throw O("epow",arguments.length,2);return tt.deepMap2(e,t,et.pow)},et.equal=function it(e,n){if(2!=arguments.length)throw O("equal",arguments.length,2);if(g(e)){if(g(n))return e==n;if(n instanceof t)return e==n.re&&0==n.im}if(e instanceof t){if(g(n))return e.re==n&&0==e.im;if(n instanceof t)return e.re==n.re&&e.im==n.im}if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Cannot compare units with different base");return e.value==n.value}if(x(e)||x(n))return e==n;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.equal);if(e.valueOf()!==e||n.valueOf()!==n)return it(e.valueOf(),n.valueOf());throw E("equal",e,n)},et.exp=function(e){if(1!=arguments.length)throw O("exp",arguments.length,1);if(g(e))return Math.exp(e);if(e instanceof t){var n=Math.exp(e.re);return t.create(n*Math.cos(e.im),n*Math.sin(e.im))}if(e instanceof Array||e instanceof r)return tt.map(e,et.exp);if(e.valueOf()!==e)return et.exp(e.valueOf());throw E("exp",e)},et.fix=function(e){if(1!=arguments.length)throw O("fix",arguments.length,1);if(g(e))return e>0?Math.floor(e):Math.ceil(e);if(e instanceof t)return t.create(e.re>0?Math.floor(e.re):Math.ceil(e.re),e.im>0?Math.floor(e.im):Math.ceil(e.im));if(e instanceof Array||e instanceof r)return tt.map(e,et.fix);if(e.valueOf()!==e)return et.fix(e.valueOf());throw E("fix",e)},et.floor=function(e){if(1!=arguments.length)throw O("floor",arguments.length,1);if(g(e))return Math.floor(e);if(e instanceof t)return t.create(Math.floor(e.re),Math.floor(e.im));if(e instanceof Array||e instanceof r)return tt.map(e,et.floor);if(e.valueOf()!==e)return et.floor(e.valueOf());throw E("floor",e)},et.gcd=function(){var e,t=arguments[0],n=arguments[1];if(2==arguments.length){if(g(t)&&g(n)){if(!v(t)||!v(n))throw new Error("Parameters in function gcd must be integer numbers");for(;0!=n;)e=n,n=t%e,t=e;return Math.abs(t)}if(t instanceof Array||t instanceof r||n instanceof Array||n instanceof r)return tt.map2(t,n,et.gcd);if(t.valueOf()!==t||n.valueOf()!==n)return et.gcd(t.valueOf(),n.valueOf());throw E("gcd",t,n)}if(arguments.length>2){for(var a=1;a<arguments.length;a++)t=et.gcd(t,arguments[a]);return t}throw new SyntaxError("Function gcd expects two or more arguments")},et.larger=function(e,n){if(2!=arguments.length)throw O("larger",arguments.length,2);if(g(e)){if(g(n))return e>n;if(n instanceof t)return e>et.abs(n)}if(e instanceof t){if(g(n))return et.abs(e)>n;if(n instanceof t)return et.abs(e)>et.abs(n)}if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Cannot compare units with different base");return e.value>n.value}if(x(e)||x(n))return e>n;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.larger);if(e.valueOf()!==e||n.valueOf()!==n)return et.larger(e.valueOf(),n.valueOf());throw E("larger",e,n)},et.largereq=function(e,n){if(2!=arguments.length)throw O("largereq",arguments.length,2);if(g(e)){if(g(n))return e>=n;if(n instanceof t)return e>=et.abs(n)}if(e instanceof t){if(g(n))return et.abs(e)>=n;if(n instanceof t)return et.abs(e)>=et.abs(n)}if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Cannot compare units with different base");return e.value>=n.value}if(x(e)||x(n))return e>=n;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.largereq);if(e.valueOf()!==e||n.valueOf()!==n)return et.largereq(e.valueOf(),n.valueOf());throw E("largereq",e,n)},et.lcm=function(){var e,t=arguments[0],n=arguments[1];if(2==arguments.length){if(g(t)&&g(n)){if(!v(t)||!v(n))throw new Error("Parameters in function lcm must be integer numbers");for(var a=t*n;0!=n;)e=n,n=t%e,t=e;return Math.abs(a/t)}if(t instanceof Array||t instanceof r||n instanceof Array||n instanceof r)return tt.map2(t,n,et.lcm);if(t.valueOf()!==t||n.valueOf()!==n)return et.lcm(t.valueOf(),n.valueOf());throw E("lcm",t,n)}if(arguments.length>2){for(var i=1;i<arguments.length;i++)t=et.lcm(t,arguments[i]);return t}throw new SyntaxError("Function lcm expects two or more arguments")},et.log=function(e,n){if(1==arguments.length){if(g(e))return e>=0?Math.log(e):et.log(new t(e,0));if(e instanceof t)return t.create(Math.log(Math.sqrt(e.re*e.re+e.im*e.im)),Math.atan2(e.im,e.re));if(e instanceof Array||e instanceof r)return tt.map(e,et.log);if(e.valueOf()!==e)return et.log(e.valueOf());throw E("log",e)}if(2==arguments.length)return et.divide(et.log(e),et.log(n));throw O("log",arguments.length,1,2)},et.log10=function(e){if(1!=arguments.length)throw O("log10",arguments.length,1);if(g(e))return e>=0?Math.log(e)/Math.LN10:et.log10(new t(e,0));if(e instanceof t)return t.create(Math.log(Math.sqrt(e.re*e.re+e.im*e.im))/Math.LN10,Math.atan2(e.im,e.re)/Math.LN10);if(e instanceof Array||e instanceof r)return tt.map(e,et.log10);if(e.valueOf()!==e)return et.log10(e.valueOf());throw E("log10",e)},et.mod=function(e,t){if(2!=arguments.length)throw O("mod",arguments.length,2);if(g(e)&&g(t))return I(e,t);if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return tt.map2(e,t,et.mod);if(e.valueOf()!==e||t.valueOf()!==t)return et.mod(e.valueOf(),t.valueOf());throw E("mod",e,t)},et.multiply=function ot(e,n){if(2!=arguments.length)throw O("multiply",arguments.length,2);if(g(e)){if(g(n))return e*n;if(n instanceof t)return _(new t(e,0),n);if(n instanceof w)return o=n.clone(),o.value*=e,o}else if(e instanceof t){if(g(n))return _(e,new t(n,0));if(n instanceof t)return _(e,n)}else if(e instanceof w){if(g(n))return o=e.clone(),o.value*=n,o}else{if(e instanceof Array){if(n instanceof Array){var a=tt.size(e),i=tt.size(n);if(2!=a.length)throw new Error("Can only multiply a 2 dimensional matrix (A has "+a.length+" dimensions)");if(2!=i.length)throw new Error("Can only multiply a 2 dimensional matrix (B has "+i.length+" dimensions)");if(a[1]!=i[0])throw new RangeError("Dimensions mismatch in multiplication. Columns of A must match rows of B (A is "+a[0]+"x"+a[1]+", B is "+i[0]+"x"+i[1]+", "+i[1]+" != "+i[0]+")");for(var o=[],s=a[0],f=i[1],u=a[1],ot=et.multiply,c=et.add,l=0;s>l;l++){o[l]=[];for(var m=0;f>m;m++){for(var h=null,p=0;u>p;p++){var v=ot(e[l][p],n[p][m]);h=null==h?v:c(h,v)}o[l][m]=h}}return o}return n instanceof r?new r(et.multiply(e.valueOf(),n.valueOf())):tt.map2(e,n,et.multiply)}if(e instanceof r)return new r(et.multiply(e.valueOf(),n.valueOf()))}if(n instanceof Array)return tt.map2(e,n,et.multiply);if(n instanceof r)return new r(et.multiply(e.valueOf(),n.valueOf()));if(e.valueOf()!==e||n.valueOf()!==n)return et.multiply(e.valueOf(),n.valueOf());throw E("multiply",e,n)},et.pow=function(e,n){if(2!=arguments.length)throw O("pow",arguments.length,2);if(g(e)){if(g(n))return v(n)||e>=0?Math.pow(e,n):P(new t(e,0),new t(n,0));if(n instanceof t)return P(new t(e,0),n)}else if(e instanceof t){if(g(n))return P(e,new t(n,0));if(n instanceof t)return P(e,n)}else{if(e instanceof Array){if(!g(n)||!v(n)||0>n)throw new TypeError("For A^b, b must be a positive integer (value is "+n+")");var a=tt.size(e);if(2!=a.length)throw new Error("For A^b, A must be 2 dimensional (A has "+a.length+" dimensions)");if(a[0]!=a[1])throw new Error("For A^b, A must be square (size is "+a[0]+"x"+a[1]+")");if(0==n)return et.eye(a[0]);for(var i=e,o=1;n>o;o++)i=et.multiply(e,i);return i}if(e instanceof r)return new r(et.pow(e.valueOf(),n))}if(e.valueOf()!==e||n.valueOf()!==n)return et.pow(e.valueOf(),n.valueOf());throw E("pow",e,n)},et.round=function(e,n){if(1!=arguments.length&&2!=arguments.length)throw O("round",arguments.length,1,2);if(void 0==n){if(g(e))return Math.round(e);if(e instanceof t)return t.create(Math.round(e.re),Math.round(e.im));if(e instanceof Array||e instanceof r)return tt.map(e,et.round);if(e.valueOf()!==e)return et.round(e.valueOf());throw E("round",e)}if(!g(n))throw new TypeError("Number of decimals in function round must be an integer");if(n!==Math.round(n))throw new TypeError("Number of decimals in function round must be integer");if(0>n||n>9)throw new Error("Number of decimals in function round must be in te range of 0-9");if(g(e))return G(e,n);if(e instanceof t)return t.create(G(e.re,n),G(e.im,n));if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.round);if(e.valueOf()!==e||n.valueOf()!==n)return et.round(e.valueOf(),n.valueOf());throw E("round",e,n)},et.sign=function st(e){if(1!=arguments.length)throw O("sign",arguments.length,1);if(g(e)){var st;return st=e>0?1:0>e?-1:0}if(e instanceof t){var n=Math.sqrt(e.re*e.re+e.im*e.im);return t.create(e.re/n,e.im/n)}if(e instanceof Array||e instanceof r)return tt.map(e,et.sign);if(e.valueOf()!==e)return et.sign(e.valueOf());throw E("sign",e)},et.smaller=function(e,n){if(2!=arguments.length)throw O("smaller",arguments.length,2);if(g(e)){if(g(n))return n>e;if(n instanceof t)return e<et.abs(n)}if(e instanceof t){if(g(n))return et.abs(e)<n;if(n instanceof t)return et.abs(e)<et.abs(n)}if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Cannot compare units with different base");return e.value<n.value}if(x(e)||x(n))return n>e;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.smaller);if(e.valueOf()!==e||n.valueOf()!==n)return et.smaller(e.valueOf(),n.valueOf());throw E("smaller",e,n)},et.smallereq=function(e,n){if(2!=arguments.length)throw O("smallereq",arguments.length,2);if(g(e)){if(g(n))return n>=e;if(n instanceof t)return e<=et.abs(n)}if(e instanceof t){if(g(n))return et.abs(e)<=n;if(n instanceof t)return et.abs(e)<=et.abs(n)}if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Cannot compare units with different base");return e.value<=n.value}if(x(e)||x(n))return n>=e;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.smallereq);if(e.valueOf()!==e||n.valueOf()!==n)return et.smallereq(e.valueOf(),n.valueOf());throw E("smallereq",e,n)},et.sqrt=function(e){if(1!=arguments.length)throw O("sqrt",arguments.length,1);if(g(e))return e>=0?Math.sqrt(e):et.sqrt(new t(e,0));if(e instanceof t){var n=Math.sqrt(e.re*e.re+e.im*e.im);return e.im>=0?t.create(.5*Math.sqrt(2*(n+e.re)),.5*Math.sqrt(2*(n-e.re))):t.create(.5*Math.sqrt(2*(n+e.re)),-.5*Math.sqrt(2*(n-e.re)))}if(e instanceof Array||e instanceof r)return tt.map(e,et.sqrt);if(e.valueOf()!==e)return et.sqrt(e.valueOf());throw E("sqrt",e)},et.square=function(e){if(1!=arguments.length)throw O("square",arguments.length,1);if(g(e))return e*e;if(e instanceof t)return et.multiply(e,e);if(e instanceof Array||e instanceof r)return tt.map(e,et.square);if(e.valueOf()!==e)return et.square(e.valueOf());throw E("square",e)},et.subtract=function(e,n){if(2!=arguments.length)throw O("subtract",arguments.length,2);if(g(e)){if(g(n))return e-n;if(n instanceof t)return t.create(e-n.re,-n.im)}else if(e instanceof t){if(g(n))return t.create(e.re-n,e.im);if(n instanceof t)return t.create(e.re-n.re,e.im-n.im)}else if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Units do not match");if(null==e.value)throw new Error("Unit on left hand side of operator - has an undefined value");if(null==n.value)throw new Error("Unit on right hand side of operator - has an undefined value");var a=e.clone();return a.value-=n.value,a.fixPrefix=!1,a}if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.subtract);if(e.valueOf()!==e||n.valueOf()!==n)return et.subtract(e.valueOf(),n.valueOf());throw E("subtract",e,n)},et.unary=function(e){if(1!=arguments.length)throw O("unary",arguments.length,1);if(g(e))return-e;if(e instanceof t)return t.create(-e.re,-e.im);if(e instanceof w){var n=e.clone();return n.value=-e.value,n}if(e instanceof Array||e instanceof r)return tt.map(e,et.unary);if(e.valueOf()!==e)return et.unary(e.valueOf());throw E("unary",e)},et.unaryminus=function(){throw new Error("Function unaryminus is deprecated, use unary instead")},et.unequal=function(e,n){if(2!=arguments.length)throw O("unequal",arguments.length,2);if(g(e)){if(g(n))return e!=n;if(n instanceof t)return e!=n.re||0!=n.im}if(e instanceof t){if(g(n))return e.re!=n||0!=e.im;if(n instanceof t)return e.re!=n.re||e.im!=n.im}if(e instanceof w&&n instanceof w){if(!e.equalBase(n))throw new Error("Cannot compare units with different base");return e.value!=n.value}if(x(e)||x(n))return e!=n;if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.unequal);if(e.valueOf()!==e||n.valueOf()!==n)return et.unequal(e.valueOf(),n.valueOf());throw E("unequal",e,n)},et.xgcd=function ft(e,t){if(2==arguments.length){if(g(e)&&g(t)){if(!v(e)||!v(t))throw new Error("Parameters in function xgcd must be integer numbers");if(0==t)return[e,1,0];var n=ft(t,e%t),r=n[0],a=n[1],i=n[2];return[r,i,a-i*Math.floor(e/t)]}throw E("xgcd",e,t)}throw new SyntaxError("Function xgcd expects two arguments")},et.arg=function(e){if(1!=arguments.length)throw O("arg",arguments.length,1);return g(e)?Math.atan2(0,e):e instanceof t?Math.atan2(e.im,e.re):e instanceof Array||e instanceof r?tt.map(e,et.arg):e.valueOf()!==e?et.arg(e.valueOf()):et.atan2(0,e)},et.conj=function(e){if(1!=arguments.length)throw O("conj",arguments.length,1);return g(e)?e:e instanceof t?t.create(e.re,-e.im):e instanceof Array||e instanceof r?tt.map(e,et.conj):e.valueOf()!==e?et.conj(e.valueOf()):clone(e)},et.im=function(e){if(1!=arguments.length)throw O("im",arguments.length,1);return g(e)?0:e instanceof t?e.im:e instanceof Array||e instanceof r?tt.map(e,et.im):e.valueOf()!==e?et.im(e.valueOf()):0},et.re=function(e){if(1!=arguments.length)throw O("re",arguments.length,1);return g(e)?e:e instanceof t?e.re:e instanceof Array||e instanceof r?tt.map(e,et.re):e.valueOf()!==e?et.re(e.valueOf()):et.clone(e)},et.complex=function(){switch(arguments.length){case 0:return new t(0,0);case 1:var e=arguments[0];if(e instanceof t)return e.clone();if(x(e)){var n=t.parse(e);if(n)return n;throw new SyntaxError('String "'+e+'" is no valid complex number')}throw new TypeError("Two numbers or a single string expected in function complex");case 2:return new t(arguments[0],arguments[1]);default:throw O("complex",arguments.length,0,2)}},et.matrix=function(e){if(arguments.length>1)throw O("matrix",arguments.length,0,1);return new r(e)},et.number=function(e){switch(arguments.length){case 0:return 0;case 1:var t=Number(e);if(isNaN(t)&&(t=Number(e.valueOf())),isNaN(t))throw new SyntaxError(e.toString()+" is no valid number");return t;default:throw O("number",arguments.length,0,1)}},et.parser=function(){return new et.expr.Parser},et.range=function(e){switch(arguments.length){case 1:if(e instanceof d)return e.clone();if(x(e)){var t=d.parse(e);if(t)return t;throw new SyntaxError('String "'+t+'" is no valid range')}throw new TypeError("Two or three numbers or a single string expected in function range");case 2:return new d(arguments[0],null,arguments[1]);case 3:return new d(arguments[0],arguments[1],arguments[2]);default:throw O("range",arguments.length,2,3)}},et.string=function(e){switch(arguments.length){case 0:return"";case 1:return B(e);default:throw O("string",arguments.length,0,1)}},et.unit=function(){switch(arguments.length){case 1:var e=arguments[0];if(e instanceof w)return e.clone();if(x(e)){if(w.isPlainUnit(e))return new w(null,e);var t=w.parse(e);if(t)return t;throw new SyntaxError('String "'+e+'" is no valid unit')}throw new TypeError("A string or a number and string expected in function unit");case 2:return new w(arguments[0],arguments[1]);default:throw O("unit",arguments.length,1,2)}},et.workspace=function(){throw new Error("Workspace is no longer supported, sorry...")},et.concat=function(){var e,t,n=arguments.length,a=-1,i=!1,o=[];for(e=0;n>e;e++){var s=arguments[e];if(s instanceof r&&(i=!0),e==n-1&&g(s)){if(t=a,a=s,!v(a)||1>a)throw new TypeError("Dimension number must be a positive integer (dim = "+a+")");if(e>0&&a>t)throw new RangeError("Dimension out of range ("+a+" > "+t+")")}else{if(!(s instanceof Array||s instanceof r))throw E("concat",s);var f=et.clone(s).valueOf(),u=et.size(s).valueOf();if(o[e]=f,t=a,a=u.length,e>0&&a!=t)throw new RangeError("Dimension mismatch ("+t+" != "+a+")")}}if(0==o.length)throw new SyntaxError("At least one matrix expected");for(var c=o.shift();o.length;)c=j(c,o.shift(),a-1,0);return i?new r(c):c},et.det=function(e){if(1!=arguments.length)throw O("det",arguments.length,1);var t=et.size(e).valueOf();switch(t.length){case 0:return et.clone(e);case 1:if(1==t[0])return et.clone(e.valueOf()[0]);throw new RangeError("Matrix must be square (size: "+et.format(t)+")");case 2:var n=t[0],r=t[1];if(n==r)return k(e.valueOf(),n,r);throw new RangeError("Matrix must be square (size: "+et.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+et.format(t)+")")}},et.diag=function(e,t){var n,a,i,o;if(1!=arguments.length&&2!=arguments.length)throw O("diag",arguments.length,1,2);if(t){if(!g(t)||!v(t))throw new TypeError("Second parameter in function diag must be an integer")}else t=0;var s=t>0?t:0,f=0>t?-t:0;e instanceof r||e instanceof d||(e=new r(e));var u;switch(e.isVector()?(e=e.toVector(),u=[e.length]):u=e.size(),u.length){case 1:a=e.valueOf();var c=new r;for(c.resize([a.length+f,a.length+s]),n=c.valueOf(),o=a.length,i=0;o>i;i++)n[i+f][i+s]=et.clone(a[i]);return c;case 2:for(a=[],n=e.valueOf(),o=Math.min(u[0]-f,u[1]-s),i=0;o>i;i++)a[i]=et.clone(n[i+f][i+s]);return new r(a);default:throw new RangeError("Matrix for function diag must be 2 dimensional")}},et.eye=function(){var e=tt.argsToArray(arguments);if(0==e.length)e=[1,1];else if(1==e.length)e[1]=e[0];else if(e.length>2)throw O("eye",e.length,0,2);var t=e[0],n=e[1];if(!g(t)||!v(t)||1>t)throw new Error("Parameters in function eye must be positive integers");if(n&&(!g(n)||!v(n)||1>n))throw new Error("Parameters in function eye must be positive integers");var a=new r;a.resize(e);for(var i=et.min(e),o=a.valueOf(),s=0;i>s;s++)o[s][s]=1;return a},et.inv=function(e){if(1!=arguments.length)throw O("inv",arguments.length,1);var t=et.size(e).valueOf();switch(t.length){case 0:return et.divide(1,e);case 1:if(1==t[0])return e instanceof r?new r([et.divide(1,e.valueOf()[0])]):[et.divide(1,e[0])];throw new RangeError("Matrix must be square (size: "+et.format(t)+")");case 2:var n=t[0],a=t[1];if(n==a)return e instanceof r?new r(F(e.valueOf(),n,a)):F(e,n,a);throw new RangeError("Matrix must be square (size: "+et.format(t)+")");default:throw new RangeError("Matrix must be two dimensional (size: "+et.format(t)+")")}},et.ones=function(){var e=tt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new r,n=1;return t.resize(e,n),t},et.size=function(e){if(1!=arguments.length)throw O("size",arguments.length,1);if(g(e)||e instanceof t||e instanceof w||null==e)return[];if(x(e))return[e.length];if(e instanceof Array)return tt.size(e);if(e instanceof r)return new r(e.size());if(e.valueOf()!==e)return et.size(e.valueOf());throw E("size",e)},et.squeeze=function(e){if(1!=arguments.length)throw O("squeeze",arguments.length,1);return e instanceof Array?V(et.clone(e)):e instanceof r?et.matrix(V(e.toArray())):e.valueOf()instanceof Array?V(et.clone(e.valueOf())):et.clone(e)},et.subset=function(){switch(arguments.length){case 2:return H(arguments[0],arguments[1]);case 3:return Y(arguments[0],arguments[1],arguments[2]);default:throw O("subset",arguments.length,2,3)}},et.transpose=function(e){if(1!=arguments.length)throw O("transpose",arguments.length,1);var t=et.size(e).valueOf();switch(t.length){case 0:return et.clone(e);case 1:return et.clone(e);case 2:for(var n,a=t[1],i=t[0],o=e instanceof r,s=e.valueOf(),f=[],u=et.clone,c=0;a>c;c++){n=f[c]=[];for(var l=0;i>l;l++)n[l]=u(s[l][c])}return 0==i&&(f[0]=[]),o?new r(f):f;default:throw new RangeError("Matrix must be two dimensional (size: "+et.format(t)+")")}},et.zeros=function(){var e=tt.argsToArray(arguments);0==e.length?e=[1,1]:1==e.length&&(e[1]=e[0]);var t=new r;return t.resize(e),t},et.factorial=function(e){if(1!=arguments.length)throw O("factorial",arguments.length,1);if(g(e)){if(!v(e)||0>e)throw new TypeError("Positive integer value expected in function factorial");var t=e,n=t;for(t--;t>1;)n*=t,t--;return 0==n&&(n=1),n}if(e instanceof Array||e instanceof r)return tt.map(e,et.factorial);if(e.valueOf()!==e)return et.factorial(e.valueOf());throw E("factorial",e)},et.random=function(){if(0!=arguments.length)throw O("random",arguments.length,0);return Math.random()},et.max=function(e){if(0==arguments.length)throw new Error("Function max requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof r||e instanceof d){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var t=et.size(e).valueOf();if(1==t.length){if(0==e.length)throw new Error("Cannot calculate max of an empty vector");return Q(e.valueOf())}if(2==t.length){if(0==t[0]||0==t[1])throw new Error("Cannot calculate max of an empty matrix");if(e instanceof Array)return K(e,t[0],t[1]);if(e instanceof r||e instanceof d)return new r(K(e.valueOf(),t[0],t[1]));throw E("max",e)}throw new RangeError("Cannot calculate max for multi dimensional matrix")}return Q(arguments)},et.min=function(e){if(0==arguments.length)throw new Error("Function min requires one or more parameters (0 provided)");if(e instanceof Array||e instanceof r||e instanceof d){if(arguments.length>1)throw Error("Wrong number of parameters (1 matrix or multiple scalars expected)");var t=et.size(e).valueOf();if(1==t.length){if(0==e.length)throw new Error("Cannot calculate min of an empty vector");return X(e.valueOf())}if(2==t.length){if(0==t[0]||0==t[1])throw new Error("Cannot calculate min of an empty matrix");if(e instanceof Array)return Z(e,t[0],t[1]);if(e instanceof r||e instanceof d)return new r(Z(e.valueOf(),t[0],t[1]));throw E("min",e)}throw new RangeError("Cannot calculate min for multi dimensional matrix")}return X(arguments)},et.acos=function(e){if(1!=arguments.length)throw O("acos",arguments.length,1);if(g(e))return e>=-1&&1>=e?Math.acos(e):et.acos(new t(e,0));if(e instanceof t){var n,a=t.create(e.im*e.im-e.re*e.re+1,-2*e.re*e.im),i=et.sqrt(a);
n=i instanceof t?t.create(i.re-e.im,i.im+e.re):t.create(i-e.im,e.re);var o=et.log(n);return o instanceof t?t.create(1.5707963267948966-o.im,o.re):new t(1.5707963267948966,o)}if(e instanceof Array||e instanceof r)return tt.map(e,et.acos);if(e.valueOf()!==e)return et.acos(e.valueOf());throw E("acos",e)},et.asin=function(e){if(1!=arguments.length)throw O("asin",arguments.length,1);if(g(e))return e>=-1&&1>=e?Math.asin(e):et.asin(new t(e,0));if(e instanceof t){var n,a=e.re,i=e.im,o=t.create(i*i-a*a+1,-2*a*i),s=et.sqrt(o);n=s instanceof t?t.create(s.re-i,s.im+a):t.create(s-i,a);var f=et.log(n);return f instanceof t?t.create(f.im,-f.re):t.create(0,-f)}if(e instanceof Array||e instanceof r)return tt.map(e,et.asin);if(e.valueOf()!==e)return et.asin(e.valueOf());throw E("asin",e)},et.atan=function(e){if(1!=arguments.length)throw O("atan",arguments.length,1);if(g(e))return Math.atan(e);if(e instanceof t){var n=e.re,a=e.im,i=n*n+(1-a)*(1-a),o=t.create((1-a*a-n*n)/i,-2*n/i),s=et.log(o);return s instanceof t?t.create(-.5*s.im,.5*s.re):t.create(0,.5*s)}if(e instanceof Array||e instanceof r)return tt.map(e,et.atan);if(e.valueOf()!==e)return et.atan(e.valueOf());throw E("atan",e)},et.atan2=function(e,n){if(2!=arguments.length)throw O("atan2",arguments.length,2);if(g(e)){if(g(n))return Math.atan2(e,n)}else if(e instanceof t&&g(n))return Math.atan2(e.re,n);if(e instanceof Array||e instanceof r||n instanceof Array||n instanceof r)return tt.map2(e,n,et.atan2);if(n.valueOf()!==n||e.valueOf()!==e)return et.atan2(e.valueOf(),n.valueOf());throw E("atan2",e,n)},et.cos=function(e){if(1!=arguments.length)throw O("cos",arguments.length,1);if(g(e))return Math.cos(e);if(e instanceof t)return t.create(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.sin(e.re)*(Math.exp(-e.im)-Math.exp(e.im)));if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.cos(e.value)}if(e instanceof Array||e instanceof r)return tt.map(e,et.cos);if(e.valueOf()!==e)return et.cos(e.valueOf());throw E("cos",e)},et.cot=function(e){if(1!=arguments.length)throw O("cot",arguments.length,1);if(g(e))return 1/Math.tan(e);if(e instanceof t){var n=Math.exp(-4*e.im)-2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return t.create(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/n,(Math.exp(-4*e.im)-1)/n)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cot is no angle");return 1/Math.tan(e.value)}if(e instanceof Array||e instanceof r)return tt.map(e,et.cot);if(e.valueOf()!==e)return et.cot(e.valueOf());throw E("cot",e)},et.csc=function(e){if(1!=arguments.length)throw O("csc",arguments.length,1);if(g(e))return 1/Math.sin(e);if(e instanceof t){var n=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))-.5*Math.cos(2*e.re);return t.create(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/n,.5*Math.cos(e.re)*(Math.exp(-e.im)-Math.exp(e.im))/n)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function csc is no angle");return 1/Math.sin(e.value)}if(e instanceof Array||e instanceof r)return tt.map(e,et.csc);if(e.valueOf()!==e)return et.csc(e.valueOf());throw E("csc",e)},et.sec=function(e){if(1!=arguments.length)throw O("sec",arguments.length,1);if(g(e))return 1/Math.cos(e);if(e instanceof t){var n=.25*(Math.exp(-2*e.im)+Math.exp(2*e.im))+.5*Math.cos(2*e.re);return t.create(.5*Math.cos(e.re)*(Math.exp(-e.im)+Math.exp(e.im))/n,.5*Math.sin(e.re)*(Math.exp(e.im)-Math.exp(-e.im))/n)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function sec is no angle");return 1/Math.cos(e.value)}if(e instanceof Array||e instanceof r)return tt.map(e,et.sec);if(e.valueOf()!==e)return et.sec(e.valueOf());throw E("sec",e)},et.sin=function(e){if(1!=arguments.length)throw O("sin",arguments.length,1);if(g(e))return Math.sin(e);if(e instanceof t)return t.create(.5*Math.sin(e.re)*(Math.exp(-e.im)+Math.exp(e.im)),.5*Math.cos(e.re)*(Math.exp(e.im)-Math.exp(-e.im)));if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function cos is no angle");return Math.sin(e.value)}if(e instanceof Array||e instanceof r)return tt.map(e,et.sin);if(e.valueOf()!==e)return et.sin(e.valueOf());throw E("sin",e)},et.tan=function(e){if(1!=arguments.length)throw O("tan",arguments.length,1);if(g(e))return Math.tan(e);if(e instanceof t){var n=Math.exp(-4*e.im)+2*Math.exp(-2*e.im)*Math.cos(2*e.re)+1;return t.create(2*Math.exp(-2*e.im)*Math.sin(2*e.re)/n,(1-Math.exp(-4*e.im))/n)}if(e instanceof w){if(!e.hasBase(w.BASE_UNITS.ANGLE))throw new TypeError("Unit in function tan is no angle");return Math.tan(e.value)}if(e instanceof Array||e instanceof r)return tt.map(e,et.tan);if(e.valueOf()!==e)return et.tan(e.valueOf());throw E("tan",e)},et["in"]=function(e,t){if(2!=arguments.length)throw O("in",arguments.length,2);if(e instanceof w&&(t instanceof w||x(t)))return e["in"](t);if(e instanceof Array||e instanceof r||t instanceof Array||t instanceof r)return tt.map2(e,t,et["in"]);if(e.valueOf()!==e||t.valueOf()!==t)return et["in"](e.valueOf(),t.valueOf());throw E("in",e,t)},et.clone=function(t){if(1!=arguments.length)throw O("clone",arguments.length,1);if(null==t)return t;if("function"==typeof t.clone)return t.clone();if(g(t)||x(t)||e(t))return t;if(t instanceof Array){var n=et.clone;return t.map(function(e){return n(e)})}if(t instanceof Object)return tt.mapObject(t,et.clone);throw E("clone",t)},et.eval=function(e,t){if(1!=arguments.length&&2!=arguments.length)throw O("eval",arguments.length,1,2);var n;if(n=t?t instanceof et.expr.Scope?t:new et.expr.Scope(t):new et.expr.Scope,x(e)){var a=et.parse(e,n);return a.eval()}if(e instanceof Array||e instanceof r)return tt.map(e,function(e){var t=et.parse(e,n);return t.eval()});throw new TypeError("String or matrix expected")},et.format=function(e,t){var n=arguments.length;if(1!=n&&2!=n)throw O("format",n,1,2);if(1==n){var r=arguments[0];return g(r)?tt.formatNumber(r,et.options.precision):r instanceof Array?tt.formatArray(r):x(r)?'"'+r+'"':r instanceof Object?r.toString():String(r)}if(!x(e))throw new TypeError("String expected as first parameter in function format");if(!(t instanceof Object))throw new TypeError("Object expected as first parameter in function format");return e.replace(/\$([\w\.]+)/g,function(e,n){for(var r=n.split("."),a=t[r.shift()];r.length&&void 0!=a;){var i=r.shift();a=i?a[i]:a+"."}return void 0!=a?a:e})},et.help=function(e){if(1!=arguments.length)throw new SyntaxError("Wrong number of arguments in function help ("+arguments.length+" provided, 1 expected)");var t=null;if(e instanceof String||"string"==typeof e)t=e;else{var r;for(r in et)if(et.hasOwnProperty(r)&&e===et[r]){t=r;break}if(!t)for(r in et.type)if(et.type.hasOwnProperty(r)&&e===et.type[r]){t=r;break}}if(t){var a=et.docs[t];if(!a)throw new Error('No documentation found on "'+t+'"');return new n(a)}throw new Error('Could not find search term "'+e+'"')},et["import"]=function(e,t){var n,r={override:!1,wrap:!0};if(t&&t instanceof Object&&tt.extend(r,t),x(e)){if("undefined"==typeof require)throw new Error("Cannot load file: require not available.");var a=require(e);et["import"](a)}else if(J(e)){if(n=e.name,!n)throw new Error("Cannot import an unnamed function or object");(r.override||void 0===et[n])&&$(n,e,r)}else if(e instanceof Object)for(n in e)if(e.hasOwnProperty(n)){var i=e[n];J(i)?$(n,i,r):et["import"](i)}},function(){function e(){nt=0,rt=J.charAt(0)}function n(){nt++,rt=J.charAt(nt)}function a(){return J.charAt(nt+1)}function i(){for(it=X.NULL,at="";" "==rt||" "==rt;)n();if("#"==rt)for(;"\n"!=rt&&""!=rt;)n();if(""==rt)return it=X.DELIMITER,void 0;var e=rt+a();if(Z[e])return it=X.DELIMITER,at=e,n(),n(),void 0;if(Z[rt])return it=X.DELIMITER,at=rt,n(),void 0;if(s(rt)){if(it=X.NUMBER,"."==rt)at+=rt,n(),f(rt)||(it=X.UNKNOWN);else{for(;f(rt);)at+=rt,n();"."==rt&&(at+=rt,n())}for(;f(rt);)at+=rt,n();if("E"==rt||"e"==rt)for(at+=rt,n(),("+"==rt||"-"==rt)&&(at+=rt,n()),f(rt)||(it=X.UNKNOWN);f(rt);)at+=rt,n()}else{if(!o(rt)){for(it=X.UNKNOWN;""!=rt;)at+=rt,n();throw W('Syntax error in part "'+at+'"')}for(it=X.SYMBOL;o(rt)||f(rt);)at+=rt,n()}}function o(e){return e>="a"&&"z">=e||e>="A"&&"Z">=e||"_"==e}function s(e){return e>="0"&&"9">=e||"."==e}function f(e){return e>="0"&&"9">=e}function u(t){e(),i();var n;if(n=""==at?new M(void 0):c(t),""!=at)throw it==X.DELIMITER?K("Unknown operator "+at):W('Unexpected part "'+at+'"');return n}function c(e){var t,n,r;for("\n"!=at&&";"!=at&&""!=at&&(t=l(e));"\n"==at||";"==at;)n||(n=new z,t&&(r=";"!=at,n.add(t,r))),i(),"\n"!=at&&";"!=at&&""!=at&&(t=l(e),r=";"!=at,n.add(t,r));return n?n:(t||(t=l(e)),t)}function l(e){var t=m(e),n="ans";return new R(n,t,e)}function m(e){if(it==X.SYMBOL&&"function"==at){if(i(),it!=X.SYMBOL)throw W("Function name expected");var t=at;if(i(),"("!=at)throw W("Opening parenthesis ( expected");for(var n=e.createSubScope(),r=[];;){if(i(),it!=X.SYMBOL)throw W("Variable name expected");if(r.push(at),i(),","!=at){if(")"==at)break;throw W('Comma , or closing parenthesis ) expected"')}}if(i(),"="!=at)throw W("Equal sign = expected");i();var a=h(n);return new U(t,r,a,n,e)}return h(e)}function h(e){var t,n,r,a,o=p(e);if("="==at){if(o instanceof S)return i(),t=o.name,n=null,a=h(e),new R(t,a,e);if(o instanceof T&&o.object instanceof S)return i(),t=o.object.name,n=o.params,r=o.paramScopes,a=h(e),new C(t,n,r,a,e);throw W("Symbol expected at the left hand side of assignment operator =")}return o}function p(e){var t,n,r,a=[];if(t=":"==at?new M(1):g(e),":"==at){for(a.push(t);":"==at;)i(),")"==at||","==at||""==at?a.push(new S("end",e)):a.push(g(e));a.length&&(n="range",r=et.range,t=new A(n,r,a))}return t}function g(e){var t,n,r,a,o;for(t=v(e),n={"in":"in"};void 0!==n[at];)r=at,a=et[n[r]],i(),o=[t,v(e)],t=new A(r,a,o);return t}function v(e){var t=d(e);return t}function d(e){var t,n,r,a,o;for(t=y(e),n={"==":"equal","!=":"unequal","<":"smaller",">":"larger","<=":"smallereq",">=":"largereq"};void 0!==n[at];)r=at,a=et[n[r]],i(),o=[t,y(e)],t=new A(r,a,o);return t}function y(e){var t,n,r,a,o;for(t=b(e),n={"+":"add","-":"subtract"};void 0!==n[at];)r=at,a=et[n[r]],i(),o=[t,b(e)],t=new A(r,a,o);return t}function b(e){var t,n,r,a,o;for(t=E(e),n={"*":"multiply",".*":"emultiply","/":"divide","./":"edivide","%":"mod",mod:"mod"};void 0!==n[at];)r=at,a=et[n[r]],i(),o=[t,E(e)],t=new A(r,a,o);return t}function E(e){var t,n,r;return"-"==at?(t=at,n=et.unary,i(),r=[N(e)],new A(t,n,r)):N(e)}function N(e){var t,n,r,a,o,s,f;for(r=[L(e)],a=[];"^"==at||".^"==at;)a.push(at),i(),r.push(L(e));for(t=r.pop();r.length;)n=r.pop(),o=a.pop(),s="^"==o?et.pow:et.epow,f=[n,t],t=new A(o,s,f);return t}function L(e){var t,n,r,a;for(t=I(e);"!"==at;)n=at,r=et.factorial,i(),a=[t],t=new A(n,r,a);return t}function I(e){var t,n,r,a;for(t=_(e);"'"==at;)n=at,r=et.transpose,i(),a=[t],t=new A(n,r,a);return t}function _(e){var t,n,r,a;if(it==X.SYMBOL&&$[at]){if(a=$[at],i(),"("==at){if(t=[],n=[],i(),")"!=at)for(r=e.createSubScope(),n.push(r),t.push(p(r));","==at;)i(),r=e.createSubScope(),n.push(r),t.push(p(r));if(")"!=at)throw W("Parenthesis ) expected");i()}return new a(t,n)}return P(e)}function P(e){var t,n;return it==X.SYMBOL?(n=at,i(),t=new S(n,e),G(e,t)):B(e)}function G(e,t){for(var n,r,a;"("==at;){if(n=[],r=[],i(),")"!=at)for(a=e.createSubScope(),r.push(a),n.push(p(a));","==at;)i(),a=e.createSubScope(),r.push(a),n.push(p(a));if(")"!=at)throw W("Parenthesis ) expected");i(),t=new T(t,n,r)}return t}function B(e){var t,r,a;if('"'==at){for(r="",a="";""!=rt&&('"'!=rt||"\\"==a);)r+=rt,a=rt,n();if(i(),'"'!=at)throw W('End of string " expected');return i(),t=new M(r),t=G(e,t)}return j(e)}function j(e){var t,n,r,a,o,s;if("["==at){for(i();"\n"==at;)i();if("]"!=at){for(n=[],r=0,a=0,n[0]=[h(e)];","==at||";"==at;){for(","==at?a++:(r++,a=0,n[r]=[]),i();"\n"==at;)i();for(n[r][a]=h(e);"\n"==at;)i()}for(o=n.length,s=n.length>0?n[0].length:0,r=1;o>r;r++)if(n[r].length!=s)throw K("Number of columns must match ("+n[r].length+" != "+s+")");if("]"!=at)throw W("End of matrix ] expected");i(),t=new q(n)}else i(),t=new q([[]]);return t=G(e,t)}return k(e)}function k(e){var n,r,a;if(it==X.NUMBER){if(a="."==at?0:Number(at),i(),it==X.SYMBOL){if("i"==at||"I"==at)return r=new t(0,a),i(),new M(r);if(w.isPlainUnit(at))return r=new w(a,at),i(),new M(r);throw Q('Unknown unit "'+at+'"')}return n=new M(a),n=G(e,n)}return F(e)}function F(e){var t;if("("==at){if(i(),t=h(e),")"!=at)throw W("Parenthesis ) expected");return i(),t=G(e,t)}return V(e)}function V(){throw""==at?W("Unexpected end of expression"):W("Value expected")}function H(){return void 0}function D(){return nt-at.length+1}function Y(e){var t=H(),n=D();return void 0===t?void 0===n?e:e+" (char "+n+")":e+" (line "+t+", char "+n+")"}function W(e){return new SyntaxError(Y(e))}function Q(e){return new TypeError(Y(e))}function K(e){return new Error(Y(e))}et.parse=function(e,t){if(1!=arguments.length&&2!=arguments.length)throw O("parse",arguments.length,1,2);var n;if(n=t?t instanceof et.expr.Scope?t:new et.expr.Scope(t):new et.expr.Scope,x(e))return J=e||"",u(n);if(e instanceof Array||e instanceof r)return tt.map(e,function(e){return J=e||"",u(n)});throw new TypeError("String or matrix expected")};var X={NULL:0,DELIMITER:1,NUMBER:2,SYMBOL:3,UNKNOWN:4},Z={",":!0,"(":!0,")":!0,"[":!0,"]":!0,'"':!0,"\n":!0,";":!0,"+":!0,"-":!0,"*":!0,".*":!0,"/":!0,"./":!0,"%":!0,"^":!0,".^":!0,"!":!0,"'":!0,"=":!0,":":!0,"==":!0,"!=":!0,"<":!0,">":!0,"<=":!0,">=":!0},$=et.expr.node.handlers,J="",nt=0,rt="",at="",it=X.NULL}(),et.select=function(e){return new et.type.Selector(e)},et["typeof"]=function(e){if(1!=arguments.length)throw O("typeof",arguments.length,1);var t,n=typeof e;if("object"==n){if(null==e)return"null";if(e instanceof Boolean)return"boolean";if(e instanceof Number)return"number";if(e instanceof String)return"string";if(e instanceof Array)return"array";if(e instanceof Date)return"date";if(e.constructor){for(t in et)if(et.hasOwnProperty(t)&&e.constructor==et[t])return t.toLowerCase();for(t in et.type)if(et.type.hasOwnProperty(t)&&e.constructor==et.type[t])return t.toLowerCase();if(e.constructor.name)return e.constructor.name.toLowerCase()}}return n},et.docs.Infinity={name:"Infinity",category:"Constants",syntax:["Infinity"],description:"Infinity, a number which is larger than the maximum number that can be handled by a floating point number.",examples:["Infinity","1 / 0"],seealso:[]},et.docs.LN10={name:"LN10",category:"Constants",syntax:["LN10"],description:"Returns the natural logarithm of 10, approximately equal to 2.302",examples:["LN10","log(10)"],seealso:[]},et.docs.LN2={name:"LN2",category:"Constants",syntax:["LN2"],description:"Returns the natural logarithm of 2, approximately equal to 0.693",examples:["LN2","log(2)"],seealso:[]},et.docs.LOG10E={name:"LOG10E",category:"Constants",syntax:["LOG10E"],description:"Returns the base-10 logarithm of E, approximately equal to 0.434",examples:["LOG10E","log(e, 10)"],seealso:[]},et.docs.LOG2E={name:"LOG2E",category:"Constants",syntax:["LOG2E"],description:"Returns the base-2 logarithm of E, approximately equal to 1.442",examples:["LOG2E","log(e, 2)"],seealso:[]},et.docs.NaN={name:"NaN",category:"Constants",syntax:["NaN"],description:"Not a number",examples:["NaN","0 / 0"],seealso:[]},et.docs.SQRT1_2={name:"SQRT1_2",category:"Constants",syntax:["SQRT1_2"],description:"Returns the square root of 1/2, approximately equal to 0.707",examples:["SQRT1_2","sqrt(1/2)"],seealso:[]},et.docs.SQRT2={name:"SQRT2",category:"Constants",syntax:["SQRT2"],description:"Returns the square root of 2, approximately equal to 1.414",examples:["SQRT2","sqrt(2)"],seealso:[]},et.docs.e=et.docs.E={name:"e",category:"Constants",syntax:["e"],description:"Euler's number, the base of the natural logarithm. Approximately equal to 2.71828",examples:["e","e ^ 2","exp(2)","log(e)"],seealso:["exp"]},et.docs.i={name:"i",category:"Constants",syntax:["i"],description:"Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part.",examples:["i","i * i","sqrt(-1)"],seealso:[]},et.docs.pi=et.docs.PI={name:"pi",category:"Constants",syntax:["pi"],description:"The number pi is a mathematical constant that is the ratio of a circle's circumference to its diameter, and is approximately equal to 3.14159",examples:["pi","sin(pi/2)"],seealso:["tau"]},et.docs.tau={name:"tau",category:"Constants",syntax:["pi"],description:"Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi, approximately 6.2832.",examples:["tau","2 * pi"],seealso:["pi"]},et.docs.abs={name:"abs",category:"Arithmetic",syntax:["abs(x)"],description:"Compute the absolute value.",examples:["abs(3.5)","abs(-4.2)"],seealso:["sign"]},et.docs.add={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"]},et.docs.ceil={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"]},et.docs.cube={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"]},et.docs.divide={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"]},et.docs.edivide={name:"edivide",category:"Operator",syntax:["x ./ y","edivide(x, y)"],description:"divide two values element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","b = [2, 1, 1; 3, 2, 5]","a ./ b"],seealso:["multiply","emultiply","divide"]},et.docs.emultiply={name:"emultiply",category:"Operator",syntax:["x .* y","emultiply(x, y)"],description:"multiply two values element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","b = [2, 1, 1; 3, 2, 5]","a .* b"],seealso:["multiply","divide","edivide"]},et.docs.epow={name:"epow",category:"Operators",syntax:["x .^ y","epow(x, y)"],description:"Calculates the power of x to y element wise.",examples:["a = [1, 2, 3; 4, 5, 6]","a .^ 2"],seealso:["pow"]},et.docs.equal={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"]},et.docs.exp={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"]},et.docs.fix={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"]},et.docs.floor={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"]},et.docs.gcd={name:"gcd",category:"Arithmetic",syntax:["gcd(a, b)","gcd(a, b, c, ...)"],description:"Compute the greatest common divisor.",examples:["gcd(8, 12)","gcd(-4, 6)","gcd(25, 15, -10)"],seealso:["lcm","xgcd"]},et.docs.larger={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"]},et.docs.largereq={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"]},et.docs.lcm={name:"lcm",category:"Arithmetic",syntax:["lcm(x, y)"],description:"Compute the least common multiple.",examples:["lcm(4, 6)","lcm(6, 21)","lcm(6, 21, 5)"],seealso:["gcd"]},et.docs.log={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"]},et.docs.log10={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"]},et.docs.mod={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:[]},et.docs.multiply={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"]},et.docs.pow={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"]},et.docs.round={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"]},et.docs.sign={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"]},et.docs.smaller={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"]},et.docs.smallereq={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"]},et.docs.sqrt={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"]},et.docs.square={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"]},et.docs.subtract={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"]},et.docs.unary={name:"unary",category:"Operators",syntax:["-x","unary(x)"],description:"Inverse the sign of a value.",examples:["-4.5","-(-5.6)"],seealso:["add","subtract"]},et.docs.unequal={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"]},et.docs.xgcd={name:"xgcd",category:"Arithmetic",syntax:["xgcd(a, b)"],description:"Calculate the extended greatest common divisor for two values",examples:["xgcd(8, 12)","gcd(8, 12)","xgcd(36163, 21199)"],seealso:["gcd","lcm"]},et.docs.arg={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"]},et.docs.conj={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"]},et.docs.im={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"]},et.docs.re={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"]},et.docs.complex={name:"complex",category:"Type",syntax:["complex()","complex(re, im)","complex(string)"],description:"Create a complex number.",examples:["complex()","complex(2, 3)",'complex("7 - 2i")'],seealso:["matrix","number","range","string","unit"]},et.docs.matrix={name:"matrix",category:"Type",syntax:["[]","[a1, b1, ...; a2, b2, ...]","matrix()","matrix([...])"],description:"Create a matrix.",examples:["[]","[1, 2, 3]","[1, 2, 3; 4, 5, 6]","matrix()","matrix([3, 4])"],seealso:["complex","number","range","string","unit"]},et.docs.number={name:"number",category:"Type",syntax:["x","number(x)"],description:"Create a number or convert a string or boolean into a number.",examples:["2","2e3","4.05","number(2)",'number("7.2")',"number(true)"],seealso:["complex","matrix","range","string","unit"]},et.docs.range={name:"range",category:"Type",syntax:["start:end","start:step:end","range(start, end)","range(start, step, end)","range(string)"],description:"Create a range.",examples:["1:5","3:-1:-3","range(3, 6)","range(0, 2, 10)",'range("4:10")',"a = [1, 2, 3; 4, 5, 6]","a(:, 2:3)"],seealso:["complex","matrix","number","string","unit"]},et.docs.string={name:"string",category:"Type",syntax:['"text"',"string(x)"],description:"Create a string or convert a value to a string",examples:['"Hello World!"',"string(4.2)","string(3 + 2i)"],seealso:["complex","matrix","number","range","unit"]},et.docs.unit={name:"unit",category:"Type",syntax:["value unit","unit(value, unit)","unit(string)"],description:"Create a unit.",examples:["5.5 mm","3 inch",'unit(7.1, "kilogram")','unit("23 deg")'],seealso:["complex","matrix","number","range","string"]},et.docs.concat={name:"concat",category:"Matrix",syntax:["concat(a, b, c, ...)","concat(a, b, c, ..., dim)"],description:"Concatenate matrices. By default, the matrices are concatenated by the first dimension. The dimension on which to concatenate can be provided as last argument.",examples:["a = [1, 2; 5, 6]","b = [3, 4; 7, 8]","concat(a, b)","[a, b]","concat(a, b, 2)","[a; b]"],seealso:["det","diag","eye","inv","ones","size","squeeze","subset","transpose","zeros"]},et.docs.det={name:"det",category:"Matrix",syntax:["det(x)"],description:"Calculate the determinant of a matrix",examples:["det([1, 2; 3, 4])","det([-2, 2, 3; -1, 1, 3; 2, 0, -1])"],seealso:["concat","diag","eye","inv","ones","size","squeeze","subset","transpose","zeros"]},et.docs.diag={name:"diag",category:"Matrix",syntax:["diag(x)","diag(x, k)"],description:"Create a diagonal matrix or retrieve the diagonal of a matrix. When x is a vector, a matrix with the vector values on the diagonal will be returned. When x is a matrix, a vector with the diagonal values of the matrix is returned.When k is provided, the k-th diagonal will be filled in or retrieved, if k is positive, the values are placed on the super diagonal. When k is negative, the values are placed on the sub diagonal.",examples:["diag(1:4)","diag(1:4, 1)","a = [1, 2, 3; 4, 5, 6; 7, 8, 9]","diag(a)"],seealso:["concat","det","eye","inv","ones","size","squeeze","subset","transpose","zeros"]},et.docs.eye={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:["concat","det","diag","inv","ones","size","squeeze","subset","transpose","zeros"]},et.docs.inv={name:"inv",category:"Matrix",syntax:["inv(x)"],description:"Calculate the inverse of a matrix",examples:["inv([1, 2; 3, 4])","inv(4)","1 / 4"],seealso:["concat","det","diag","eye","ones","size","squeeze","subset","transpose","zeros"]},et.docs.ones={name:"ones",category:"Matrix",syntax:["ones(n)","ones(m, n)","ones(m, n, p, ...)","ones([m, n])","ones([m, n, p, ...])","ones"],description:"Create a matrix containing ones.",examples:["ones(3)","ones(3, 5)","ones([2,3]) * 4.5","a = [1, 2, 3; 4, 5, 6]","ones(size(a))"],seealso:["concat","det","diag","eye","inv","size","squeeze","subset","transpose","zeros"]},et.docs.size={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:["concat","det","diag","eye","inv","ones","squeeze","subset","transpose","zeros"]},et.docs.squeeze={name:"squeeze",category:"Matrix",syntax:["squeeze(x)"],description:"Remove singleton dimensions from a matrix.",examples:["a = zeros(1,3,2)","size(squeeze(a))","b = zeros(3,1,1)","size(squeeze(b))"],seealso:["concat","det","diag","eye","inv","ones","size","subset","transpose","zeros"]},et.docs.subset={name:"subset",category:"Matrix",syntax:["value(index)","value(index) = replacement","subset(value, [index])","subset(value, [index], replacement)"],description:"Get or set a subset of a matrix or string.",examples:["d = [1, 2; 3, 4]","e = []","e(1, 1:2) = [5, 6]","e(2, :) = [7, 8]","f = d * e","f(2, 1)","f(:, 1)"],seealso:["concat","det","diag","eye","inv","ones","range","size","squeeze","transpose","zeros"]},et.docs.transpose={name:"transpose",category:"Matrix",syntax:["x'","transpose(x)"],description:"Transpose a matrix",examples:["a = [1, 2, 3; 4, 5, 6]","a'","transpose(a)"],seealso:["concat","det","diag","eye","inv","ones","size","squeeze","subset","zeros"]},et.docs.zeros={name:"zeros",category:"Matrix",syntax:["zeros(n)","zeros(m, n)","zeros(m, n, p, ...)","zeros([m, n])","zeros([m, n, p, ...])","zeros"],description:"Create a matrix containing zeros.",examples:["zeros(3)","zeros(3, 5)","a = [1, 2, 3; 4, 5, 6]","zeros(size(a))"],seealso:["concat","det","diag","eye","inv","ones","size","squeeze","subset","transpose"]},et.docs.factorial={name:"factorial",category:"Probability",syntax:["x!","factorial(x)"],description:"Compute the factorial of a value",examples:["5!","5*4*3*2*1","3!"],seealso:[]},et.docs.random={name:"random",category:"Probability",syntax:["random()"],description:"Return a random number between 0 and 1.",examples:["random()","100 * random()"],seealso:[]},et.docs.max={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:["min"]},et.docs.min={name:"min",category:"Statistics",syntax:["min(a, b, c, ...)"],description:"Compute the minimum value of a list of values.",examples:["min(2, 3, 4, 1)","min(2.7, 7.1, -4.5, 2.0, 4.1)","max(2.7, 7.1, -4.5, 2.0, 4.1)"],seealso:["max"]},et.docs.acos={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"]},et.docs.asin={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"]},et.docs.atan={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"]},et.docs.atan2={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"]},et.docs.cos={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"]},et.docs.cot={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"]},et.docs.csc={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"]},et.docs.sec={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"]},et.docs.sin={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"]},et.docs.tan={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"]},et.docs["in"]={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:[]},et.docs.clone={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:[]},et.docs.eval={name:"eval",category:"Utils",syntax:["eval(expression)","eval([expr1, expr2, expr3, ...])"],description:"Evaluate an expression or an array with expressions.",examples:['eval("2 + 3")','eval("sqrt(" + 4 + ")")'],seealso:[]},et.docs.format={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:[]},et.docs.help={name:"help",category:"Utils",syntax:["help(object)"],description:"Display documentation on a function or data type.",examples:['help("sqrt");','help("complex");'],seealso:[]},et.docs["import"]={name:"import",category:"Utils",syntax:["import(string)"],description:"Import functions from a file.",examples:['import("numbers")','import("./mylib.js")'],seealso:[]},et.docs["typeof"]={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:[]},Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var t=0;t<this.length;t++)if(this[t]==e)return t;
return-1}),Array.prototype.forEach||(Array.prototype.forEach=function(e,t){for(var n=0,r=this.length;r>n;++n)e.call(t||this,this[n],n,this)}),Array.prototype.map||(Array.prototype.map=function(e,t){var n,r,a;if(null==this)throw new TypeError(" this is null or not defined");var i=Object(this),o=i.length>>>0;if("function"!=typeof e)throw new TypeError(e+" is not a function");for(t&&(n=t),r=new Array(o),a=0;o>a;){var s,f;a in i&&(s=i[a],f=e.call(n,s,a,i),r[a]=f),a++}return r}),Array.prototype.every||(Array.prototype.every=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&!e.call(r,t[a],a,t))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError;for(var r=arguments[1],a=0;n>a;a++)if(a in t&&e.call(r,t[a],a,t))return!0;return!1}),Function.prototype.bind||(Function.prototype.bind=function(e){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var t=Array.prototype.slice.call(arguments,1),n=this,r=function(){},a=function(){return n.apply(this instanceof r&&e?this:e,t.concat(Array.prototype.slice.call(arguments)))};return r.prototype=this.prototype,a.prototype=new r,a});for(var at in et)et.hasOwnProperty(at)&&at&&y(at,et[at]);"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=et),"undefined"!=typeof exports&&(exports=et),"undefined"!=typeof require&&"undefined"!=typeof define&&define(function(){return et}),"undefined"!=typeof window&&(window.math?tt.deepExtend(window.math,et):window.math=et)}();