mathjs/math.min.js
2013-03-28 21:44:29 +01:00

29 lines
80 KiB
JavaScript

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