diff --git a/Calculus.js b/Calculus.js index b1bc13d..d176830 100644 --- a/Calculus.js +++ b/Calculus.js @@ -489,7 +489,7 @@ if((typeof module) !== 'undefined' && typeof nerdamer === 'undefined') { return symbol; } - ; + function derive(symbol) { var g = symbol.group, a, b, cp; @@ -696,7 +696,8 @@ if((typeof module) !== 'undefined' && typeof nerdamer === 'undefined') { symbol = _.multiply(polydiff(symbol.clone()), derive(b)); } else if(g === CP || g === PL) { - var c = _.parse(symbol); + // Note: Do not use `parse` since this puts back the sqrt and causes a bug as in #610. Use clone. + var c = symbol.clone(); var result = new Symbol(0); for(var x in symbol.symbols) { result = _.add(result, __.diff(symbol.symbols[x].clone(), d)); @@ -2667,4 +2668,4 @@ if((typeof module) !== 'undefined' && typeof nerdamer === 'undefined') { //link registered functions externally nerdamer.api(); -})(); +})(); \ No newline at end of file diff --git a/all.min.js b/all.min.js index 622cc9d..d59f3dc 100644 --- a/all.min.js +++ b/all.min.js @@ -1 +1 @@ -var nerdamer=function(e){"use strict";var d=new P,S=e.bigInt,k=e.bigDec;k.set({precision:250});var t={},o=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083],M={},F={callPeekers:!1,init_primes:1e3,exclude:[],suppress_errors:!1,PARSE2NUMBER:!1,SAFE:!1,IMAGINARY:"i",FUNCTION_MODULES:[Math],ALLOW_CHARS:["π"],USE_MULTICHARACTER_VARS:!0,POWER_OPERATOR:"^",VALIDATION_REGEX:/^[a-z_αAβBγΓδΔϵEζZηHθΘιIκKλΛμMνNξΞoOπΠρPσΣτTυϒϕΦχXψΨωΩ∞][0-9a-z_αAβBγΓδΔϵEζZηHθΘιIκKλΛμMνNξΞoOπΠρPσΣτTυϒϕΦχXψΨωΩ]*$/i,IMPLIED_MULTIPLICATION_REGEX:/([\+\-\/\*]*[0-9]+)([a-z_αAβBγΓδΔϵEζZηHθΘιIκKλΛμMνNξΞoOπΠρPσΣτTυϒϕΦχXψΨωΩ]+[\+\-\/\*]*)/gi,ALIASES:{"π":"pi","∞":"Infinity"},POSITIVE_MULTIPLIERS:!1,CACHE:{},SILENCE_WARNINGS:!1,PRECISION:21,VECTOR:"vector",PARENTHESIS:"parens",SQRT:"sqrt",ABS:"abs",FACTORIAL:"factorial",DOUBLEFACTORIAL:"dfactorial",LONG_PI:"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196",LONG_E:"2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901",PI:Math.PI,E:Math.E,LOG:"log",LOG10:"log10",LOG10_LATEX:"log_{10}",MAX_EXP:2e5,SCIENTIFIC_MAX_DECIMAL_PLACES:14,SCIENTIFIC_IGNORE_ZERO_EXPONENTS:!0};!function(){F.CACHE.roots={};for(var e=2;e<=40;e++)for(var t=2;t<=40;t++){var n=S(e).pow(t);F.CACHE.roots[n+"-"+t]=e}}();function n(t){function e(e){this.name=t,this.message=void 0!==e?e:"",(e=new Error(this.message)).name=this.name,this.stack=e.stack}return e.prototype=Object.create(Error.prototype),e}function r(e){return-1!==f.indexOf(e)}function i(e){return e instanceof O}function A(e){return(e=ne(e)?e.multiplier:e).lessThan(0)}function c(e){return Math.min.apply(void 0,e)}function s(e,t){if(ae(e))for(var n=e.length,r=0;r=Number.MAX_VALUE?e.toString():Number(e):(t=void 0===t?14:t,Math.round(e*Math.pow(10,t))/Math.pow(10,t))},ge=function(e){return e%2==0},de=function(e){return 1/(e%1)%2==0},ve=function(e,t){var n=typeof t;"function"==n&&"undefined"!=n||(t=function(e,t){return e===t});for(var r=[];e.length;){var i=e[0];if(1===e.length){r.push(i);break}var s=[];r.push(i);for(var o=1;ou)throw new Error("stopping");i=i.pow(2).add(1).mod(a),s=S.gcd(i.minus(n).abs(),a)}r*=2,n=i}return s.equals(a)?e(t+1):s}(2);r(i),a=a.divide(i)}}catch(e){n={},r(t)}}return-1==e&&(e=c(q(n)),n["-"+e]=n[e],delete n[e]),n},boxfactor:function(e,t){t=t||200;for(var n,r,i=Math.floor(5/12*e),s=0,o=!1;n=Math.floor(e/i),0!=(r=e%i);){if(o)return[e,1];i=Math.max(r,i-r),o=t<++s}return[n,i,s]},fib:function(e){var t=Math.sign(e);e=Math.abs(e);for(var t=ge(e)?t:Math.abs(t),n=0,r=1,i=1,s=2;s<=e;s++)i=n+r,n=r,r=i;return i*t},mod:function(e,t){return e%t},integer_part:function(e){return Math.sign(e)*Math.floor(Math.abs(e))},simpson:function(e,t,n,r){function i(e,t,n){var r=e(t);return r=isNaN(r)?e(1===n?t+1e-12:t-1e-12):r}r=r||1e-4;var s=Math.abs(Math.floor((n-t)/r));s%2!=0&&s++;for(var o=(n-t)/s,a=i(e,t,1),u=!1,l=t+o,c=1;c1e3*l))return l":{precedence:1,operator:">",action:"gt",prefix:!1,postfix:!1,leftAssoc:!1},"=>":{precedence:1,operator:"=>",action:"gte",prefix:!1,postfix:!1,leftAssoc:!1},",":{precedence:0,operator:",",action:"comma",prefix:!1,postfix:!1,leftAssoc:!1},":":{precedence:0,operator:",",action:"assign",prefix:!1,postfix:!1,leftAssoc:!1,vectorFn:"slice"},":=":{precedence:0,operator:",",action:"function_assign",prefix:!1,postfix:!1,leftAssoc:!0}},q={"(":{type:"round",id:1,is_open:!0,is_close:!1},")":{type:"round",id:2,is_open:!1,is_close:!0},"[":{type:"square",id:3,is_open:!0,is_close:!1,maps_to:"vector"},"]":{type:"square",id:4,is_open:!1,is_close:!0},"{":{type:"curly",id:5,is_open:!0,is_close:!1,maps_to:"Set"},"}":{type:"curly",id:6,is_open:!1,is_close:!0}},U=this.functions={cos:[I.cos,1],sin:[I.sin,1],tan:[I.tan,1],sec:[I.sec,1],csc:[I.csc,1],cot:[I.cot,1],acos:[I.acos,1],asin:[I.asin,1],atan:[I.atan,1],arccos:[I.acos,1],arcsin:[I.asin,1],arctan:[I.atan,1],asec:[I.asec,1],acsc:[I.acsc,1],acot:[I.acot,1],atan2:[I.atan2,2],acoth:[e.acoth,1],asech:[e.asech,1],acsch:[e.acsch,1],sinh:[e.sinh,1],cosh:[e.cosh,1],tanh:[e.tanh,1],asinh:[e.asinh,1],sech:[e.sech,1],csch:[e.csch,1],coth:[e.coth,1],acosh:[e.acosh,1],atanh:[e.atanh,1],log10:[,1],exp:[function(e){if(e.fname===F.LOG&&e.isLinear())return C.pow(e.args[0],De.create(e.multiplier));return C.parse(ce("e^({0})",e))},1],radians:[function(e){return C.parse(ce("({0})*pi/180",e))},1],degrees:[function(e){return C.parse(ce("({0})*180/pi",e))},1],min:[function(){var e=[].slice.call(arguments);return w(e)?e[0]:Me(e)?new De(Math.min.apply(null,e)):F.SYMBOLIC_MIN_MAX&&Ne(e)?h("min",e):C.symfunction("min",e)},-1],max:[function(){var e=[].slice.call(arguments);return w(e)?e[0]:Me(e)?new De(Math.max.apply(null,e)):F.SYMBOLIC_MIN_MAX&&Ne(e)?h("max",e):C.symfunction("max",e)},-1],erf:[,1],floor:[,1],ceil:[,1],trunc:[,1],Si:[,1],step:[,1],rect:[,1],sinc:[function(e){if(F.PARSE2NUMBER)return e.isConstant()?new De(Te.sinc(e)):C.parse(ce("sin({0})/({0})",e));return C.symfunction("sinc",[e])},1],tri:[,1],sign:[function(e){return e.isConstant(!0)?new De(Math.sign(Se(e))):C.symfunction("sign",arguments)},1],Ci:[,1],Ei:[,1],Shi:[,1],Chi:[,1],Li:[,1],fib:[,1],fact:[u,1],factorial:[u,1],continued_fraction:[function(e,t){e=Se(e);if(e.isConstant()){e=Te.continuedFraction(e,t),t=Ve.fromArray(e.fractions.map(function(e){return new De(e)}));return Ve.fromArray([new De(e.sign),new De(e.whole),t])}return C.symfunction("continued_fraction",arguments)},[1,2]],dfactorial:[,1],gamma_incomplete:[,[1,2]],round:[m,[1,2]],scientific:[function(e,t){return e.scientific=t||10,e},[1,2]],mod:[t,2],pfactor:[N,1],vector:[function(){return new Ve([].slice.call(arguments))},-1],matrix:[function(){return He.fromArray(arguments)},-1],Set:[function(){return je.fromArray(arguments)},-1],imatrix:[function(e){return He.identity(e)},-1],parens:[function(e){if(F.PARSE2NUMBER)return e;return C.symfunction("parens",[e])},-1],sqrt:[R,1],cbrt:[i,1],nthroot:[s,2],log:[O,[1,2]],expand:[function(e,t){return T(e,t=t||{expand_denominator:!0,expand_functions:!0})},1],abs:[_,1],invert:[function(e){if(ie(e))return e.invert();K("invert expects a matrix")},1],determinant:[function(e){if(ie(e))return e.determinant();return e},1],size:[function(e){var t;ie(e)?t=[new De(e.cols()),new De(e.rows())]:re(e)||se(e)?t=new De(e.elements.length):K("size expects a matrix or a vector");return t},1],transpose:[function(e){if(ie(e))return e.transpose();K("function transpose expects a matrix")},1],dot:[function(e,t){if(re(e)&&re(t))return e.dot(t);K("function dot expects 2 vectors")},2],cross:[function(e,t){if(re(e)&&re(t))return e.cross(t);K("function cross expects 2 vectors")},2],vecget:[function(e,t){return t.isConstant()&&ue(t)?e.elements[t]:C.symfunction("vecget",arguments)},2],vecset:[function(e,t,n){return t.isConstant?(e.elements[t]=n,e):C.symfunction("vecset",arguments)},3],vectrim:[function(e,n){return n=void 0===n?1e-14:n,e=e.clone(),n=Number(n),e.elements.sort(function(e,t){return t.group-e.group}),e.elements=ve(e.elements,function(e,t){return Number(C.subtract(Se(e),Se(t)).abs())<=n}),e},[1,2]],matget:[function(e,t,n){return t.isConstant()&&n.isConstant()?e.elements[t][n]:C.symfunction("matget",arguments)},3],matset:[function(e,t,n,r){return e.elements[t][n]=r,e},4],matgetrow:[function(e,t){return t.isConstant()?new He(e.elements[t]):C.symfunction("matgetrow",arguments)},2],matsetrow:[function(e,t,n){if(!t.isConstant())return C.symfunction("matsetrow",arguments);if(e.elements[t].length!==n.elements.length)throw new _e("Matrix row must match row dimensions!");e=e.clone();return e.elements[t]=n.clone().elements,e},3],matgetcol:[function(e,r){if(!r.isConstant())return C.symfunction("matgetcol",arguments);r=Number(r);var i=He.fromArray([]);return e.each(function(e,t,n){n===r&&i.elements.push([e.clone()])}),i},2],matsetcol:[function(n,r,e){if(!r.isConstant())return C.symfunction("matsetcol",arguments);if(r=Number(r),n.rows()!==e.elements.length)throw new _e("Matrix columns must match number of columns!");return e.each(function(e,t){n.set(t-1,r,e.elements[0].clone())}),n},3],rationalize:[r,1],IF:[function(e,t,n){"boolean"!=typeof e&&oe(e)&&(e=!!Number(e));return e?t:n},3],is_in:[function(e,t){if(ie(e)){for(var n=0,r=e.rows();n=s:o.precedence>s)&&o.precedence++}}},this.getOperator=function(e){return E[e]},this.aliasOperator=function(e,t){var n,r={},i=E[e];for(n in i)r[n]=i[n];r.operator=t,this.setOperator(r)},this.getOperators=function(){return E},this.getBrackets=function(){return q};function a(e){this.type=e.type,this.value=e.value,this.left=e.left,this.right=e.right}this.initConstants=function(){this.CONSTANTS={E:new De(F.E),PI:new De(F.PI)}},this.pretty_print=function(e){if(Array.isArray(e)){var t=e.map(e=>C.pretty_print(e)).join(", ");return"vector"===e.type?"vector<"+t+">":"("+t+")"}return e.toString()},this.peekers={pre_operator:[],post_operator:[],pre_function:[],post_function:[]},this.callPeekers=function(e){if(F.callPeekers)for(var t=this.peekers[e],n=be(arguments).slice(1).map(le),r=0;rc.precedence||!c.leftAssoc&&p.precedence===c.precedence))break;r.push(i.pop())}if(("vector"===t||"set"===t)&&"vectorFn"in c&&(c.action=c.vectorFn),c.postfix){var f=e[a-1];if(!f)throw new Ie("Unexpected prefix operator '"+l.value+"'! at "+l.column);if(f.type===A.OPERATOR&&!f.postfix)throw new Ie("Unexpected prefix operator '"+f.value+"'! at "+f.column)}else do{var h,m=!!(h=e[a+1])&&h.type===A.OPERATOR;if(m){if(!h.prefix)throw new Ie("A prefix operator was expected at "+h.column);h.is_prefix=!0,s.push(h),a++}}while(m);for((c.is_prefix?s:i).push(c);s.length&&(c.leftAssoc||!c.leftAssoc&&s[s.length-1].precedence>=c.precedence);)i.push(s.pop())}else l.type===A.VARIABLE_OR_LITERAL?(0===r.length&&o(s,i),r.push(l),(f=i[i.length-1])&&f.leftAssoc||o(s,r)):l.type===A.FUNCTION?i.push(l):l.type===A.UNIT&&r.push(l);Array.isArray(l)&&(r.push(this.toRPN(l)),l.type&&r.push(new A(l.type,A.FUNCTION,l.column)))}return o(i,r),o(s,r),r},this.parseRPN=function(e,t){try{for(var n in t=t||{})t[n]=C.parse(t[n],{});F.PARSE2NUMBER&&("e"in t||(t.e=new De(F.E)),"pi"in t||(t.pi=new De(F.PI)));for(var r=[],i=0,s=e.length;i\n"+this.left.toHTML(e+2,t)+n(e+1)+" \n":"",s=this.right?n(e+1)+"
  • \n"+this.right.toHTML(e+2,t)+n(e+1)+"
  • \n":"",r=n(e)+'
    '+this.value+"
    "+n(e)+"\n";return(i||s)&&(r+=n(e)+"
      \n"+i+s+n(e)+"
    \n"),r+=""},this.tree=function(e){for(var t=[],n=0;nr.numVal)&&(t.pop(),t.push(n))}}function O(e,t){if(e.equals(1))return new De(0);var n,r,i;if(e.fname===z&&e.multiplier.equals(1))return n=C.divide(O(e.args[0]),new De(2)),e.power.sign()<0&&n.negate(),n;if(e.equals(0))throw new Ae(F.LOG+"(0) is undefined!");return e.isImaginary()?b.evaluate(e,F.LOG):(e.isConstant()&&void 0!==t&&t.isConstant()?n=new De(Math.log(e)/Math.log(t)):e.group===V&&e.power.multiplier.lessThan(0)||"-1"===e.power.toString()?(e.power.negate(),n=O(e).negate()):"e"===e.value&&e.multiplier.equals(1)?(t=e.power,n=ne(t)?t:new De(t)):e.group===H&&"exp"===e.fname?(i=e.args[0],n=e.multiplier.equals(1)?C.multiply(i,new De(e.power)):C.symfunction(F.LOG,[e])):F.PARSE2NUMBER&&oe(e)?((e=C.parse(e)).multiplier.lessThan(0)&&(e.negate(),r=C.multiply(new De(Math.PI),new De("i"))),n=new De(Math.log(e.multiplier.toDecimal())),r&&(n=C.add(n,r))):(e.power.equals(1)||e.contains("e")||(i=e.group===V?e.power:new De(e.power),e.toLinear()),n=1i.length&&i.group===n.group&&([i,n]=[n,i])),i.multiplier.equals(0))return n;if(n.multiplier.equals(0))return i;if(i.isConstant()&&n.isConstant()&&F.PARSE2NUMBER)return h=new De(i.multiplier.add(n.multiplier).toDecimal(F.PRECISION));var a=i.group,u=n.group,l=i.power.toString(),c=n.power.toString();if(ai.group&&n.group!==X)return this.multiply(n,i);i.group===Z&&n.group===j&&i.value===n.value&&(p=i,i=n,n=p);var a=i.group,u=n.group,l=n.multiplier.num,c=n.multiplier.den;a!==H||i.fname!==z||n.isConstant()||i.args[0].value!==n.value||i.args[0].multiplier.lessThan(0)?a===H&&i.fname===z&&i.multiplier.equals(1)&&i.power.equals(-1)&&n.isConstant()&&i.args[0].equals(n)&&(i=C.symfunction(z,[n.clone()]),n=new De(1)):(m=i.power,h=C.parse(i.multiplier),(i=C.multiply(h,i.args[0].clone())).setPower(new Fe(.5).multiply(m)),a=i.group);var p,f=i.value,o=n.value,s=new Fe(i.sign()),h=a===B&&u===D&&n.multiplier.equals(i.value),m=(h?new Fe(1).multiply(i.multiplier):i.multiplier.multiply(n.multiplier)).abs(),r=i.clone().toUnitMultiplier();if(n=n.clone().toUnitMultiplier(!0),a===H&&u===H){var g=i.args[0].clone(),d=n.args[0].clone();if(i.fname===z&&n.fname===z&&i.isLinear()&&n.isLinear()){var v=C.divide(g,d).invert();v.gt(1)&&ue(v)&&(r=C.multiply(i.args[0].clone(),R(v.clone())),n=new De(1))}else if(i.fname===Y&&n.fname===Y&&!g.isConstant()&&!d.isConstant()&&n.power<0){v=C.subtract(g.clone(),d.clone());if(v.isConstant())if(p=new De(1),v<0){for(var w=0,y=Math.abs(v);w<=y;w++){var b=C.add(g.clone(),new De(w));p=C.multiply(p,b)}r=C.multiply(C.pow(g,new De(i.power)),C.pow(p,new De(n.power))),n=new De(1)}else{for(w=0,y=Math.abs(v);w<=y;w++){b=C.add(d.clone(),new De(w));p=C.multiply(p,b)}r=C.multiply(C.pow(p,new De(i.power)),C.pow(d,new De(n.power))),n=new De(1)}}}if(f===o&&a===j&&a===u&&(f=i.text("hash"),o=n.text("hash")),(f=u===V&&n.previousGroup===j&&a===j?Pe(i,"hash",V):f)!==o&&!h||a===j&&(u===G||u===B||u===H)||a===j&&u===Z)if(a===Z&&i.isLinear())if(u===Z&&n.distributeExponent(),u===Z&&n.isLinear()){for(var b in n.symbols){var S=n.symbols[b];r=r.combine(S)}r.multiplier=r.multiplier.multiply(n.multiplier)}else r.combine(n);else a!==D?a===Z?(r.distributeExponent(),r.combine(n)):n.isOne()||(E=n.multiplier.clone(),n.toUnitMultiplier(),(r=De.shell(Z).combine([r,n])).multiplier=r.multiplier.multiply(E)):r=n.clone().toUnitMultiplier();else{var M=i.power,N=n.power,E=ne(M),q=ne(N),q=E||q;a===j&&u!==j&&n.previousGroup!==j&&M.equals(1)?(r=new De(0),i.each(function(e){r=C.add(r,C.multiply(e,n.clone()))},!0)):(r.power=q?C.add(ne(M)?M:new De(M),ne(N)?N:new De(N)):a===D?M:M.add(N),r.power.equals(0)&&(r=r.convert(D)),q&&r.convert(V),i.imaginary&&n.imaginary&&ge(r.power%2)&&(r=new De(1),m.negate()),r.group!==V&&r.previousGroup&&(r.previousGroup=void 0),r.multiplier=r.multiplier.multiply(n.multiplier))}r.group===B&&(a=Math.log(r.value),M=Math.log(l)/a,N=Math.log(c)/a,q=m.num/l,a=m.den/c,0!=M&&ue(M)&&ue(q)&&(r.power=r.power.add(new Fe(M)),m.num/=l),0!=N&&ue(N)&&ue(a)&&(r.power=r.power.subtract(new Fe(N)),m.den/=c)),1===r.length&&(p=r.multiplier,(r=pe(r.symbols)).multiplier=r.multiplier.multiply(p));c=r.power.toString();return ge(c)&&r.fname===z?(s*=r.sign(),c=r.power,r=r.args[0],r=C.multiply(new De(m),C.pow(r,new De(c.divide(new Fe(2))))),s<0&&r.negate()):(r.multiplier=r.multiplier.multiply(m).multiply(s),r.group===X&&r.isImaginary()&&r.distributeMultiplier()),r=r.group===B&&ue(r.power.toDecimal())?r.convert(D):r}t&&!e&&(p=i,i=n,n=p,p=t,t=e,e=p);s=ie(n),t=ie(i);if(e&&s){var x=new He;n.eachElement(function(e,t,n){x.set(t,n,C.multiply(i.clone(),e))}),n=x}else if(t&&s)n=i.multiply(n);else if(e&&re(n))n.each(function(e,t){n.elements[--t]=C.multiply(i.clone(),n.elements[t])});else if(re(i)&&re(n))n.each(function(e,t){n.elements[--t]=C.multiply(i.elements[t],n.elements[t])});else{if(re(i)&&ie(n))return this.multiply(n,i);if(ie(i)&&re(n)){if(n.elements.length===i.rows()){var x=new He,A=i.cols();return n.each(function(e,t){for(var n=[],r=0;re.power.den)return e;e=ue(t)?De(Math.pow(n,t)):new De(n).setPower(t)}return e}(C.multiply(S,M))):a).fname===z?(M=((S=a.group===V)?a.power.multiplier:a.power).toString(),ge(M)&&(S=S?C.divide(a.power,new De(2)):new De(a.power.divide(new Fe(2))),n=a.multiplier,(a=C.pow(a.args[0],S)).multiplier=a.multiplier.multiply(n))):!F.IGNORE_E&&a.isE()&&a.group===V&&a.power.contains("pi")&&a.power.contains(F.IMAGINARY)&&i.group===Z&&(l=i.stripVar(F.IMAGINARY),a=C.add(I.cos(l),C.multiply(De.imaginary(),I.sin(l)))),a}return re(r)&&t?r=r.map(function(e){return C.pow(e,i.clone())}):ie(r)&&t?(s=new He,r.eachElement(function(e,t,n){s.set(t,n,C.pow(e,i.clone()))}),r=s):e&&ie(i)&&(s=new He,i.eachElement(function(e,t,n){s.set(t,n,C.pow(r.clone(),e))}),r=s),r},this.comma=function(e,t){return(e=!(e instanceof L)?L.create(e):e).append(t),e},this.mod=t,this.slice=function(e,t){return new x(e,t)},this.equals=function(e,t){return e.group===G||e.isLinear()||K("Cannot set equality for "+e.toString()),J[e.value]=t.clone(),t},this.percent=function(e){return C.divide(e,new De(100))},this.assign=function(e,n){if(e instanceof L&&n instanceof L)return e.elements.map(function(e,t){return C.assign(e,n.elements[t])}),Ve.fromArray(n.elements);if(e.parent){var t=e.parent;return t.elements[t.getter]=n,delete t.getter,t}if(e.group!==G)throw new Re("Cannot complete operation. Incorrect LH value for "+e);return J[e.value]=n},this.function_assign=function(e,t){var n=e.elements.pop();return fe(n,e.elements,t)};function v(e){return new De(!0===e?1:0)}this.eq=function(e,t){return v(e.equals(t))},this.gt=function(e,t){return v(e.gt(t))},this.gte=function(e,t){return v(e.gte(t))},this.lt=function(e,t){return v(e.lt(t))},this.lte=function(e,t){return v(e.lte(t))},this.factorial=function(e){return this.symfunction(Y,[e])},this.dfactorial=function(e){return this.symfunction(W,[e])}}F.FUNCTION_MODULES.push(Te),x(Te),Math.sign=Math.sign||function(e){return 0===(e=+e)||isNaN(e)?e:0this.elements.length?null:this.elements[e-1]},set:function(e,t){ne(t)||(t=new De(t)),this.elements[e]=t},dimensions:function(){return this.elements.length},modulus:function(){return ye("SAFE",function(){return d.pow(this.dot(this.clone()),new De(.5))},void 0,this)},eql:function(e){var t=this.elements.length,n=e.elements||e;if(t!==n.length)return!1;do{if(Math.abs(d.subtract(this.elements[t-1],n[t-1]).valueOf())>PRECISION)return!1}while(--t);return!0},clone:function(){for(var e=new Ve,t=this.elements.length,n=0;nMath.abs(t.valueOf())&&(t=this.elements[e]),--n;);return t},magnitude:function(){var t=new De(0);return this.each(function(e){t=d.add(t,d.pow(e,new De(2)))}),d.sqrt(t)},indexOf:function(e){for(var t,n=null,r=this.elements.length,i=r;t=i-r,null===n&&this.elements[t].valueOf()===e.valueOf()&&(n=1+t),--r;);return n},text:function(e){return Pe(this)},toString:function(){return this.text()},latex:function(e){for(var t=[],n=0;nthis.cols()?[]:this.elements[e-1]},col:function(e){var t=this.rows(),n=[];if(e>this.cols()||!e)return n;for(var r=0;r\n
      \n
    • \n'+this.tree(e).toHTML(3,t)+"\n
    • \n
    \n"},Xe.addPeeker=function(e,t){d.peekers[e]&&d.peekers[e].push(t)},Xe.removePeeker=function(e,t){we(d.peekers[e],t)},Xe.parse=function(e){return String(e).split(";").map(function(e){return d.parse(e)})},Xe.api(),Xe}({bigInt:function(){var Q=function(o){"use strict";var v=1e7,l=7,t=9007199254740992,n=m(t),c=Math.log(t);function u(e,t){return void 0===e?u[0]:void 0===t||10==+t?z(e):V(e,t)}function p(e,t){this.value=e,this.sign=t,this.isSmall=!1}function f(e){this.value=e,this.sign=e<0,this.isSmall=!0}function h(e){return-t=t.length?r(e,t):r(t,e)}function i(e,t){for(var n,r=e.length,i=new Array(r),s=v,o=0;ot.length?1:-1;for(var n=e.length-1;0<=n;n--)if(e[n]!==t[n])return e[n]>t[n]?1:-1;return 0}function L(e){e=e.abs();return!e.isUnit()&&(!!(e.equals(2)||e.equals(3)||e.equals(5))||!(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))&&(!!e.lesser(49)||void 0))}function I(e,t){for(var n,r,i,s=e.prev(),o=s,a=0;o.isEven();)o=o.divide(2),a++;e:for(r=0;r=r)throw new Error(s+" is not a valid digit in base "+t+".")}if(2<=t&&t<=36&&n<=c/Math.log(t)){var o=parseInt(e,t);if(isNaN(o))throw new Error(s+" is not a valid digit in base "+t+".");return new f(parseInt(e,t))}t=z(t);var a=[],o="-"===e[0];for(i=o?1:0;i"!==e[++i];);a.push(z(e.slice(u+1,i)))}}return H(a,t,o)};function H(e,t,n){for(var r=u[0],i=u[1],s=e.length-1;0<=s;s--)r=r.add(e[s].times(i)),i=i.times(t);return n?r.negate():r}function j(e){return e<=35?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e):"<"+e+">"}function Z(e,t){if((t=Q(t)).isZero()){if(e.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(t.equals(-1)){if(e.isZero())return{value:[0],isNegative:!1};if(e.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-e)).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var n=Array.apply(null,Array(+e-1)).map(Array.prototype.valueOf,[0,1]);return n.unshift([1]),{value:[].concat.apply([],n),isNegative:!1}}n=!1;if(e.isNegative()&&t.isPositive()&&(n=!0,e=e.abs()),t.equals(1))return e.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(+e)).map(Number.prototype.valueOf,1),isNegative:n};for(var r=[],i=e;i.isNegative()||0<=i.compareAbs(t);){var i=(s=i.divmod(t)).quotient,s=s.remainder;s.isNegative()&&(s=t.minus(s).abs(),i=i.next()),r.push(s.toJSNumber())}return r.push(i.toJSNumber()),{value:r.reverse(),isNegative:n}}function X(e,t){t=Z(e,t);return(t.isNegative?"-":"")+t.value.map(j).join("")}function $(e){if(h(+e)){var t=+e;if(t===d(t))return new f(t);throw new Error("Invalid integer: "+e)}var n="-"===e[0],r=(e=n?e.slice(1):e).split(/e/i);if(2n-1&&(void 0===s[r+1]&&(s[r+1]=0),s[r+1]+=s[r]/n|0,s[r]%=n)}return s.reverse()}N.absoluteValue=N.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)},N.ceil=function(){return P(new this.constructor(this),this.e+1,2)},N.comparedTo=N.cmp=function(e){var t,n,r=this,i=r.d,s=(e=new r.constructor(e)).d,o=r.s,a=e.s;if(!i||!s)return o&&a?o!==a?o:i===s?0:!i^o<0?1:-1:NaN;if(!i[0]||!s[0])return i[0]?o:s[0]?-a:0;if(o!==a)return o;if(r.e!==e.e)return r.e>e.e^o<0?1:-1;for(t=0,n=(r=i.length)<(e=s.length)?r:e;ts[t]^o<0?1:-1;return r===e?0:ethis.d.length-2},N.isNaN=function(){return!this.s},N.isNegative=N.isNeg=function(){return this.s<0},N.isPositive=N.isPos=function(){return 0(r=Math.max(Math.ceil(a/_),o)+2)&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for((c=(r=l.length)<(o=p.length))&&(o=r),r=0;r(i=(c=Math.ceil(s/_))>i?c+1:i+1)&&(r=i,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for((i=a.length)-(r=u.length)<0&&(r=i,n=u,u=a,a=n),t=0;r;)t=(a[--r]=a[r]+u[r]+t)/U|0,a[r]%=U;for(t&&(a.unshift(t),++l),i=a.length;0==a[--i];)a.pop();return e.d=a,e.e=F(a,l),y?P(e,s,o):e},N.precision=N.sd=function(e){var t;if(void 0!==e&&e!==!!e&&1!==e&&0!==e)throw Error(d+e);return this.d?(t=G(this.d),e&&this.e+1>t&&(t=this.e+1)):t=NaN,t},N.round=function(){var e=this.constructor;return P(new e(this),this.e+1,e.rounding)},N.sine=N.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+_,r.rounding=1,n=function(e,t){var n,r=t.d.length;if(r<3)return Q(e,2,t,t);n=16<(n=1.4*Math.sqrt(r))?16:0|n,t=Q(e,2,t=t.times(1/Y(5,n)),t);for(var i,s=new e(5),o=new e(16),a=new e(20);n--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(a))));return t}(r,W(r,n)),r.precision=e,r.rounding=t,P(2=e.d.length-1&&(n=l<0?-l:l)<=9007199254740991)return i=H(u,a,n,r),e.s<0?new u(1).div(i):P(i,r,s);if((o=a.s)<0){if(tu.maxE+1||t=r.toExpPos):(q(e,1,m),void 0===t?t=r.rounding:q(t,0,8),k(n=P(new r(n),e,t),e<=n.e||n.e<=r.toExpNeg,e));return n.isNeg()&&!n.isZero()?"-"+e:e},N.toSignificantDigits=N.toSD=function(e,t){var n=this.constructor;return void 0===e?(e=n.precision,t=n.rounding):(q(e,1,m),void 0===t?t=n.rounding:q(t,0,8)),P(new n(this),e,t)},N.toString=function(){var e=this.constructor,e=k(this,this.e<=e.toExpNeg||this.e>=e.toExpPos);return this.isNeg()&&!this.isZero()?"-"+e:e},N.truncated=N.trunc=function(){return P(new this.constructor(this),this.e+1,1)},N.valueOf=N.toJSON=function(){var e=this.constructor,e=k(this,this.e<=e.toExpNeg||this.e>=e.toExpPos);return this.isNeg()?"-"+e:e};var C=function(e,t,n,r,i,s){var o,a,u,l,c,p,f,h,m,g,d,v,w,y,b,S,M,N,E,q=e.constructor,x=e.s==t.s?1:-1,A=e.d,C=t.d;if(!(A&&A[0]&&C&&C[0]))return new q(e.s&&t.s&&(A?!C||A[0]!=C[0]:C)?A&&0==A[0]||!C?0*x:x/0:NaN);for(a=s?(c=1,e.e-t.e):(s=U,I(e.e/(c=_))-I(t.e/c)),N=C.length,S=A.length,m=(x=new q(x)).d=[],u=0;C[u]==(A[u]||0);u++);if(C[u]>(A[u]||0)&&a--,null==n?(w=n=q.precision,r=q.rounding):w=i?n+(e.e-t.e)+1:n,w<0)m.push(1),p=!0;else{if(w=w/c+2|0,u=0,1==N){for(C=C[l=0],w++;(u=s/2&&++M;l=0,(o=O(C,g,N,d))<0?(v=g[0],1<(l=(v=N!=d?v*s+(g[1]||0):v)/M|0)?1==(o=O(f=R(C,l=s<=l?s-1:l,s),g,h=f.length,d=g.length))&&(l--,T(f,Nt[i]?1:-1;break}return s}function T(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]=(a=c.length)){if(!r)break e;for(;a++<=p;)c.push(0);l=u=0,o=(s%=_)-_+(i=1)}else{for(l=a=c[p],i=1;10<=a;a/=10)i++;u=(o=(s%=_)-_+i)<0?0:l/v(10,i-o-1)%10|0}if(r=r||t<0||void 0!==c[p+1]||(o<0?l:l%v(10,i-o-1)),u=n<4?(u||r)&&(0==n||n==(e.s<0?3:2)):5f.maxE?(e.d=null,e.e=NaN):e.ee.constructor.maxE?(e.d=null,e.e=NaN):e.ei-1;)c[n]=0,n||(++s,c.unshift(1));for(a=c.length;!c[a-1];--a);for(o=0,l="";oa)for(s-=a;s--;)l+="0";else st&&(e.length=t,1)}function ee(e){return new this(e).abs()}function te(e){return new this(e).acos()}function ne(e){return new this(e).acosh()}function re(e,t){return new this(e).plus(t)}function ie(e){return new this(e).asin()}function se(e){return new this(e).asinh()}function oe(e){return new this(e).atan()}function ae(e){return new this(e).atanh()}function ue(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,s=r+4;return e.s&&t.s?e.d||t.d?!t.d||e.isZero()?(n=t.s<0?B(this,r,i):new this(0)).s=e.s:!e.d||t.isZero()?(n=B(this,s,1).times(.5)).s=e.s:n=t.s<0?(this.precision=s,this.rounding=1,n=this.atan(C(e,t,s,1)),t=B(this,s,1),this.precision=r,this.rounding=i,e.s<0?n.minus(t):n.plus(t)):this.atan(C(e,t,s,1)):(n=B(this,s,1).times(0s.maxE?(i.e=NaN,i.d=null):e.et.group}),n=0,r=t.length;ne.length&&(n=t,t=e,e=n),e.some(function(e){return-1=Math.abs(i.c)?(c=2,i.e=n/i.d,i.f=i.c/i.d,i.g=o*r,i.a3=i.e*(i.g+n)+i.h*(r/i.d),i.a1=-n+i.f*r,i.a7=i.h+(i.f+o)*n):(c=1,i.e=n/i.c,i.f=i.d/i.c,i.g=i.e*o,i.a3=i.e*n+(i.g+i.h/i.c)*r,i.a1=-(n*(i.d/i.c))+r,i.a7=i.g*i.d+i.h*i.f+n)),c}function j(e,t,n,r,i,s,o,a,u){if(3!=n)if(r=1==n?i:r,Math.abs(s.a1)>10*e*Math.abs(r)){s.a7/=s.a1,s.a3/=s.a1,o[0]=u[0],o[1]=-(u[0]*s.a7)+u[1];for(l=2;l.01*Math.abs(n.lzr))break;for(V(o,g,v,u,s,a),w=Math.abs(-(n.szr*a.b)+a.a)+Math.abs(n.szi*a.b),y=Math.sqrt(Math.abs(v)),f=2*Math.abs(s[0]),d=-(n.szr*a.b),b=1;b10*Math.abs(a[b])*e)for(d=-m/c,a[0]=o[0],w=1;w10*Math.abs(a[b])*e?-m/c:0}return v}(e,p,k,o,a,u,l,s,D),b=k.a,0=a)&&(m=0==m?Number.MIN_VALUE:m,m=Math.floor(Math.log(m)/b+.5),1!=(o=Math.pow(2,m))))for(O=0;Or(i[1])||i[1].isConstant(!0))&&s.multiplier.lessThan(0)&&(t.add(new Q(-1)),e.each(function(e){e.negate()},!0)):(e.each(function(e){e.isComposite()?e.each(function(e){e.multiplier=e.multiplier.divide(n)}):e.multiplier=e.multiplier.divide(n)}),e.updateHash()),t&&t.add(new Q(n))),e},trialAndError:function(e,t,n){var r=e.clone();try{var i=[];if(e.isConstant()||e.group===j)return e;for(var s=new W(e,n),o=s.coeffs[0],a=$.Math2.ifactor(o),u=_.proots(e),l=0;lE[0].count?E:N,x=S(q),A=[];if(x){var C=x[1],L=function(e,t){var n=e.len(),r=t.len(),t=t.terms[C],e=e.terms[C];return n=r.length);){if(200=E.length)for(R=1;R=Number(_.degree(y,o))?(p=(s=_.div(w.clone(),H.expand(y.clone())))[0],i=(w=s[1]).groupTerms(o)):p=new Q(0),1===Number(_.degree(y,o))){var b=H.divide(w,y);return n?[p,b]:H.add(p,b)}r=_.Factor.factor(y),m=_.PartFrac.createTemplate(y.clone(),r,[],o),g=m[0],f=m[1],u=m[2],c=[i.length],l=[],a=[],h=[],f.map(function(e,t){d=g[t],v=u[t];for(var n=0;nct.Settings.integration_depth&&Vt.integration.stop("Maximum depth reached. Exiting!"),ce.contains(n,!0)){if(e===St)t=Vt.integration.poly_integrate(ce,n,ut);else if(e===qt)if(ce.previousGroup===gt&&"sqrt"!==ce.fname&&ce.fname!==ht.PARENTHESIS&&Vt.integration.stop(),ce.contains(n)&&ce.previousGroup!==gt)ce.power.contains(n)?Vt.integration.stop():((We=Vt.diff(ce.clone().toLinear(),n)).contains(n)&&Vt.integration.stop(),t=Vt.integration.poly_integrate(ce,n,ut));else{if((f=Vt.diff(ce.power.clone(),n)).contains(n)){var r=f.stripVar(n);if((h=pt.divide(f.clone(),r.clone())).group===St&&h.isLinear())return r.multiplier=r.multiplier.divide(new ft(2)),pt.parse(yt("({2})*(sqrt(pi)*erf(sqrt(-{0})*{1}))/(2*sqrt(-{0}))",r,n,ce.multiplier));Vt.integration.stop()}ce.isE()?f.isLinear()?t=ce:f.isE()&&f.power.group===St&&f.power.power.equals(1)?t=pt.multiply(pt.symfunction("Ei",[ce.power.clone()]),ce.power):Vt.integration.stop():(g=pt.symfunction(xt,[pt.parse(ce.value)]),t=pt.divide(ce,g)),t=pt.divide(t,f)}else if(ce.isComposite()&&ce.isLinear()){var i=pt.parse(ce.multiplier);ce.toUnitMultiplier(),t=new dt(0),ce.each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))}),t=pt.multiply(i,t)}else if(e===Nt)if((ce=ce.power.greaterThan(1)?pt.expand(ce):ce).power.equals(1))t=new dt(0),ce.each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))},!0);else{var s=Number(ce.power),i=ce.multiplier.clone();ce.toUnitMultiplier();var o,a,u,l=ce.clone().toLinear(),c=(Ve=Vt.integration.decompose_arg(l,n))[3],p=Ve[2],f=Ve[0],h=Ve[1];if(-1===s&&h.group!==Mt&&h.power.equals(2)){var m,g,d,v,w,y,b,S,M,N,E,q=!wt(c)||0e.fname});var Ve,He=Fe.args[0];He.isLinear()&&(He.group===Nt||He.group===Et||He.group===St)||Vt.integration.stop(),h=(Ve=Vt.integration.decompose_arg(He,n))[1],f=Ve[0],h.isLinear()||Vt.integration.stop();var je,Ze=De.args[0];if(He.equals(Ze))if(Be===Ct&&Ge===Lt||Be===Lt&&Ge===Ct)if(Fe.power.lessThan(0)&&Vt.integration.stop(),Be===Ct&&Fe.power.add(De.power).equals(0))Fe.fname=It,Fe.updateHash(),t=Vt.integrate(Fe,n,ut);else if(bt(Fe.power)&&Ge===Lt&&De.power.lessThan(0)){var _=Number(Fe.power)/2,Xe=pt.parse(yt("(1-cos({0})^2)^({1})",Fe.args[0],_));t=Vt.integrate(pt.expand(pt.multiply(Xe,De.clone())),n,ut,lt)}else if(bt(Fe.power)&&Ge===Ct&&De.power.lessThan(0)){_=Number(Fe.power)/2,Xe=pt.parse(yt("(1-sin({0})^2)^({1})",Fe.args[0],_));t=Vt.integrate(pt.expand(pt.multiply(Xe,De.clone())),n,ut,lt)}else{var $e,ze=ct.Utils.even(Fe.power),Qe=ct.Utils.even(De.power);if(t=new dt(0),ze&&Qe){var Ye=function(e){var t=e.power/2,t=e.fname===Lt?"((1/2)+(cos(2*("+e.args[0]+"))/2))^"+t:"((1/2)-(cos(2*("+e.args[0]+"))/2))^"+t;return pt.parse(t)},f=Ye(Fe),c=Ye(De),We=pt.multiply(f,c);return(Je=pt.expand(We)).each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))}),pt.multiply(t,ne)}nt=ze?($e=Fe,De):($e=De,Fe);var Je,Ke=$e.fname===Lt?-1:1,et=((_=nt.power)-1)/2,tt=pt.parse("(1-"+$e.fname+ct.Utils.inBrackets(He)+"^2)^"+et);(Je=pt.expand(pt.multiply(new dt(Ke),pt.multiply($e.clone(),tt)))).each(function(e){t=pt.add(t,Vt.integration.poly_integrate(e.clone()))})}else Be===Ut&&Ge===It&&h.isLinear()&&De.isLinear()?t=pt.parse(yt("sec({0})^({1})/({1})",Fe.args[0],Fe.power)):Be===It&&Ge===Ut&&h.isLinear()?Fe.isLinear()&&De.isLinear()?t=pt.divide(pt.symfunction(Ut,[He.clone()]),f):bt(Fe.power)?(s=Number(Fe.power)/2,We=pt.parse(yt("(sec({0})^2-1)^({1})",Fe.args[0],s)),t=Vt.integrate(pt.expand(pt.multiply(We,De)),n,ut)):Vt.integration.stop():t=Be===Ut&&Ge===Lt?(Fe.fname=Lt,Fe.invert().updateHash(),Vt.integrate(pt.multiply(Fe,De),n,ut)):Be===Ct&&Ge===_t?(De.fname=Ct,De.invert().updateHash(),Vt.integrate(pt.multiply(Fe,De),n,ut)):(We=Be!==It||Ge!==Lt&&Ge!==Ct||!De.power.lessThan(0)?pt.multiply(Fe.fnTransform(),De.fnTransform()):pt.multiply(Fe.fnTransform(),De),Vt.integrate(pt.expand(We),n,ut));else Be!==Ct&&Be!==Lt||Ge!==Ct&&Ge!==Lt?Vt.integration.stop():Fe.isLinear()&&De.isLinear()?t=Fe.args[0].isLinear()&&De.args[0].isLinear()?(Ge===Ct?(p=Fe.args[0],je=De.args[0]):(je=Fe.args[0],p=De.args[0]),O=pt.parse(yt("(sin(({1})+({0}))+sin(({1})-({0})))/2",p.toString(),je.toString())),Vt.integrate(O,n,ut)):(st=Gt(ie),Vt.integrate(pt.expand(st),n,ut)):(st=new dt(1),ie.map(function(e){e=e.fnTransform();st=pt.multiply(st,e)}),We=pt.expand(st),(t=Vt.integrate(We,n,ut)).hasIntegral()&&(t=Vt.integrate(Gt(st.collectSymbols()),n,ut)))}else Pe===gt&&ke===St?(oe=Fe.isLinear(),Fe.fname===Lt&&oe&&De.power.equals(-1)?t=pt.symfunction("Ci",[Fe.args[0]]):Fe.fname===Lt&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===kt&&oe&&De.power.equals(-1)?t=pt.symfunction("Chi",[Fe.args[0]]):Fe.fname===kt&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===Ct&&oe&&De.power.equals(-1)?t=pt.symfunction("Si",[Fe.args[0]]):Fe.fname===Ct&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===Pt&&oe&&De.power.equals(-1)?t=pt.symfunction("Shi",[Fe.args[0]]):Fe.fname===Pt&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===xt&&De.power.equals(-1)?t=Vt.integration.poly_integrate(Fe,n,ut):"erf"===Fe.fname?De.power.equals(1)&&(ee=(Se=Vt.integration.decompose_arg(Fe.args[0],n))[0],K=Se[1],D=Fe.args[0].toString(),t=pt.parse(yt("(e^(-(({2}))^2)*(sqrt(pi)*e^((({2}))^2)*(2*({0})^2*({1})^2-3)*erf(({2}))+2*({0})*({1})-2))/(4*sqrt(pi)*({0})^2)",ee,K,D))):t=Vt.integration.by_parts(ce,n,ut,lt)):Pe===qt&&ke===St?(h=Be===xt?Vt.integration.decompose_arg(Fe.args[0],n)[1]:null,t=Fe.isE()&&(Fe.power.group===St||Fe.power.group===Et)&&De.power.equals(-1)?pt.symfunction("Ei",[Fe.power.clone()]):Be===xt&&h.value===De.value?Vt.integration.poly_integrate(Fe,n,ut):Vt.integration.by_parts(ce,n,ut,lt)):Pe===Mt&&ke===St?(ce=De.value===Fe.value&&Fe.power.equals(-1)?(ae=Math.min.apply(null,ct.Utils.keys(Fe.symbols)),ue=Math.min(ae,De.power),(le=De.clone()).power=new ft(ue),De=pt.divide(De,le.clone()),We=new dt(0),Fe.each(function(e){We=pt.add(We,pt.divide(e.clone(),le.clone()))}),We.multiplier=Fe.multiplier,pt.divide(De,We)):pt.expand(ce),t=Vt.integration.partial_fraction(ce,n,ut)):Pe===Nt&&ke===St?(O=Fe.clone().toLinear(),pe=ct.Algebra.degree(O,pt.parse(n)).equals(1),Fe.power.equals(-.5)?(f=(Ve=Vt.integration.decompose_arg(Fe.clone().toLinear(),n))[0].negate(),h=Ve[1],c=Ve[3],xe=Number(Fe.power),Ae=Number(De.power),wt(Ae)&&ct.Utils.even(Ae)&&h.power.equals(2)?(Me=pt.divide(pt.multiply(pt.pow(c.clone(),new dt(2)),pt.symfunction(At,[pt.divide(c.clone(),f.clone())])),pt.pow(f.clone(),new dt(2))),Me=pt.multiply(Me,pt.symfunction(At,[c]).invert()),(fe=pt.parse("sin(u)")).power=fe.power.multiply(De.power),R=Vt.integrate(fe,"u",ut),he=pt.parse("asin(sqrt("+f+"/"+c+")*"+n+")"),t=pt.multiply(Me,R.sub(new dt("u"),he))):-.5===xe&&(me=function(e,t){t=pt.parse(Vt.integrate(e,n,ut,lt).sub(n,yt(t,n)));if(!t.hasIntegral())return t},-1===Ae?t=me(pt.expand(pt.expand(pt.pow(pt.multiply(Fe.invert(),De.invert()),new dt(2)))).invert(),"sqrt(1-1/({0})^2)"):-2===Ae&&(t=me(pt.sqrt(pt.expand(pt.divide(pt.pow(ce,new dt(2)).invert(),pt.pow(new dt(n),new dt(2))).negate())).invert(),"sqrt(1-1/({0})^2)")))):Fe.power.equals(-1)&&De.isLinear()&&pe?t=Vt.integration.partial_fraction(ce,n,ut):!Fe.power.lessThan(0)&&wt(Fe.power)?(ge=pt.expand(Fe),t=new dt(0),ge.each(function(e){e.group===Mt?e.each(function(e){t=pt.add(t,Vt.integrate(pt.multiply(De.clone(),e),n,ut))}):t=pt.add(t,Vt.integrate(pt.multiply(De.clone(),e),n,ut))})):Fe.power.lessThan(-2)?t=Vt.integration.by_parts(ce,n,ut,lt):Fe.power.lessThan(0)&&De.power.greaterThan(1)?(f=(Ve=Vt.integration.decompose_arg(Fe.clone().toLinear(),n))[0].negate(),h=Ve[1],c=Ve[3],l=Fe.clone().toLinear(),t=h.group!==Mt&&h.isLinear()?(s=Number(De.power),$e=new dt(Ce="_u_"),de=pt.expand(pt.divide(pt.pow(pt.subtract($e.clone(),c.clone()),new dt(s)),$e.clone())),(ve={})[Ce]=l,we=pt.parse(de,ve),Vt.integrate(we,n,0)):De.power.greaterThan(h.power)||De.power.equals(h.power)?(ye=new ct.Algebra.Classes.Factors,Fe=ct.Algebra.Factor.coeffFactor(Fe.invert(),ye),(be=ct.Algebra.divide(De,Fe)).group!==Et?(t=new dt(0),be.each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))}),ye.each(function(e){t=pt.divide(t,e)}),pt.expand(t)):Vt.integration.by_parts(ce,n,ut,lt)):Vt.integration.partial_fraction(ce,n,ut)):Fe.power.den.equals(2)?(f=(Se=Vt.integration.decompose_arg(Fe.clone().toLinear(),n))[3],h=Se[1],c=Se[0],je=Se[2],t=h.power.equals(2)&&c.lessThan(0)?(f.equals(1)||(ne=pt.multiply(ne,pt.pow(f,new dt(2)))),$e=n,Me=pt.divide(pt.pow(c.clone().negate(),new dt(.5)),pt.pow(f,new dt(.5))),Ce=pt.symfunction(Lt,[new dt($e)]),Ne=pt.pow(pt.symfunction(Lt,[new dt($e)]),new dt(Fe.power.num)),Ee=pt.pow(pt.symfunction(Ct,[new dt($e)]),new dt(De.power)),qe=pt.multiply(pt.multiply(Ne,Ce),Ee),(R=Vt.integrate(qe,$e,ut)).sub($e,pt.symfunction(Ot,[pt.multiply(new dt(n),Me)]))):Vt.integration.partial_fraction(ce,n,ut,lt)):pe&&(t=Vt.integration.partial_fraction(ce,n,ut))):Fe.isComposite()&&De.isComposite()?(t=new dt(0),Fe.power.greaterThan(0)&&De.power.greaterThan(0)?(Je=pt.expand(ce)).each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))},!0):(xe=Number(Fe.power),Ae=Number(De.power),xe<0&&0ht.max_lim_depth)){e.clone();var s=t.clone();if("abs"===t.fname){var o=e.sign(),a=r.sign();if(r.isInfinity)return pt.multiply(new dt(o),new dt(a));if(r.equals(0)){var a=pt.parse(e.multiplier),u=pt.parse(t.multiplier);return pt.divide(pt.multiply(a,Vt.Limit.interval("-1","1")),u)}Vt.Limit.diverges()}var l=function(e){if(ct.Utils.isVector(e)){for(var t=0;tht.max_lim_depth)){var e=pt.parse(t.multiplier);t.toUnitMultiplier();try{if(t.isConstant(!0))d=t;else{var o={};o[n]=r;try{var a=pt.parse(t.sub(n,r),o);(a.isConstant(!0)||a.isInfinity)&&(d=a)}catch(e){}if(!d){var u,l=t.getNum(),c=t.getDenom();if(c.isConstant(!0)){if(t.group===qt){var p,f,h,m,g,d,v=t.clone().toLinear(),w=(t.power.clone(),v.getNum()),y=v.getDenom(),b=ct.Utils.decompose_fn(y,n,!0);d=w.group===St&&w.multiplier.isOne()&&b.ax.group===St&&b.b.isConstant(!0)&&b.a.isOne()&&b.b.isConstant(!0)?pt.parse(yt("(1/e^({0}))",b.b)):(f=(p=Vt.Limit.rewriteToLog(t.clone())).power.clone(),h=p.clone().toLinear(),m=Vt.Limit.limit(h,n,r,i),g=Vt.Limit.limit(f,n,r,i),pt.pow(m,g))}else if(t.group===gt&&1===t.args.length){var S,M=Vt.Limit.limit(t.args[0],n,r,i);if(ct.Utils.isVector(M))return d=M.map(function(e){return t.clone().args[0]=e,Vt.Limit.limit(pt.symfunction(t.fname,[e]),n,r,i)}),pt.multiply(e,d);if(M.isConstant(!0)){var N=pt.symfunction(t.fname,[M]);try{k(N),S=!0}catch(e){S=!1}}if(S)d=N;else if(Vt.Limit.isConvergent(M))if(t.fname===xt)switch(M.toString()){case"0":d=dt.infinity().negate();break;case"Infinity":case"-Infinity":d=dt.infinity()}else if(t.fname!==Lt&&t.fname!==Ct||!r.isInfinity){if(t.fname===It){var E=t.args[0],q=E.getNum(),x=E.getDenom(),A=q.toUnitMultiplier();(r.isInfinity||A.equals("pi")&&x.equals(2))&&(d=divergent())}else if(t.fname===ht.FACTORIAL&&M.isInfinity)return dt.infinity()}else d=Vt.Limit.interval(-1,1)}else if(t.group===St){if(0ht.max_lim_depth)return;d=Vt.Limit.limit(Vt.diff(t,n),n,r,i)}}}}else d=Vt.Limit.divide(l,c,n,r,i)}}d=d||pt.symfunction("limit",[t,n,r])}catch(e){d=pt.symfunction("limit",[t,n,r])}return pt.multiply(e,d)}}},Fresnel:{S:function(e){return e.isConstant(!0)?Vt.defint(pt.parse("sin(pi*x^2/2)"),dt(0),e,"x"):pt.symfunction("S",arguments)},C:function(e){return e.isConstant(!0)?Vt.defint(pt.parse("cos(pi*x^2/2)"),dt(0),e,"x"):pt.symfunction("C",arguments)}}};nerdamer.register([{name:"diff",visible:!0,numargs:[1,3],build:function(){return Vt.diff}},{name:"sum",visible:!0,numargs:4,build:function(){return Vt.sum}},{name:"product",visible:!0,numargs:4,build:function(){return Vt.product}},{name:"integrate",visible:!0,numargs:[1,2],build:function(){return Vt.integrate}},{name:"defint",visible:!0,numargs:[3,4],build:function(){return Vt.defint}},{name:"S",visible:!0,numargs:1,build:function(){return Vt.Fresnel.S}},{name:"C",visible:!0,numargs:1,build:function(){return Vt.Fresnel.C}},{name:"limit",visible:!0,numargs:[3,4],build:function(){return Vt.Limit.limit}}]),nerdamer.api()}(),"undefined"!=typeof module&&(nerdamer=require("./nerdamer.core.js"),require("./Calculus.js"),require("./Algebra.js")),function(){var t,G=nerdamer.getCore(),V=G.PARSER,H=G.Algebra,j=G.Calculus,Z=j.integration.decompose_arg,X=G.Utils.evaluate,E=G.Utils.remove,c=G.Utils.format,$=G.Utils.build,f=G.Utils.knownVariable,z=G.Symbol,Q=G.Utils.isSymbol,l=G.Utils.variables,Y=G.groups.S,W=G.groups.PL,J=G.groups.CB,K=G.groups.CP,ee=G.groups.FN,te=G.Settings,s=G.Utils.range,ne=G.Utils.isArray;function re(e,t){if(t.isConstant()&&e.isConstant()&&!e.equals(t)||e.equals(G.Settings.IMAGINARY)||t.equals(G.Settings.IMAGINARY))throw new G.exceptions.NerdamerValueError(e.toString()+" does not equal "+t.toString());this.LHS=e,this.RHS=t}G.Settings.SOLVE_RADIUS=1e3,G.Settings.ROOTS_PER_SIDE=10,G.Settings.make_pi_conversions=!1,G.Settings.STEP_SIZE=.1,G.Settings.EPSILON=1e-13,G.Settings.MAX_NEWTON_ITERATIONS=200,G.Settings.MAX_NON_LINEAR_TRIES=12,G.Settings.NON_LINEAR_JUMP_AT=50,G.Settings.NON_LINEAR_JUMP_SIZE=100,G.Settings.NON_LINEAR_START=.01,G.Settings.NEWTON_SLICES=200,G.Settings.NEWTON_EPSILON=2*Number.EPSILON,G.Settings.SOLUTION_PROXIMITY=1e-14,G.Settings.FILTER_SOLUTIONS=!0,G.Settings.MAX_SOLVE_DEPTH=10,G.Settings.ZERO_EPSILON=1e-9,G.Settings.MAX_BISECTION_ITER=2e3,G.Settings.BI_SECTION_EPSILON=1e-12,G.Symbol.prototype.hasTrig=function(){return this.containsFunction(["cos","sin","tan","cot","csc","sec"])},G.Symbol.prototype.hasNegativeTerms=function(){if(this.isComposite())for(var e in this.symbols){var t=this.symbols[e];if(t.group===W&&t.hasNegativeTerms()||this.symbols[e].power.lessThan(0))return!0}return!1},re.prototype={toString:function(){return this.LHS.toString()+"="+this.RHS.toString()},text:function(e){return this.LHS.text(e)+"="+this.RHS.text(e)},toLHS:function(e){var t=(n=(e=void 0===e)?this.removeDenom():this.clone()).LHS,n=n.RHS;t.isConstant(!0)&&!n.isConstant(!0)&&([t,n]=[n,t]);n=V.subtract(t,n);return e?V.expand(n):n},removeDenom:function(){var e=this.LHS.clone(),t=this.RHS.clone(),n=V.multiply(e.getDenom(),t.getDenom());if(e=V.expand(V.multiply(e,n.clone())),(t=V.expand(V.multiply(t,n))).group===K&&t.group!==K&&(r=e,e=t,t=r),e.group===J){var r=new z(e.multiplier),i=t.clone();e.each(function(e){e.power.lessThan(0)?i=V.divide(i,e):r=V.multiply(r,e)}),e=r,t=i}else if(e.group===K)for(var s in e.symbols){var o=e.symbols[s];if(o.group===J)for(var a in o.symbols){a=o.symbols[a];if(a.power.lessThan(0))return new re(V.expand(V.multiply(a.clone().toLinear(),e)),V.expand(V.multiply(a.clone().toLinear(),t)))}}return new re(e,t)},clone:function(){return new re(this.LHS.clone(),this.RHS.clone())},sub:function(e,t){var n=this.clone();return n.LHS=n.LHS.sub(e.clone(),t.clone()),n.RHS=n.RHS.sub(e.clone(),t.clone()),n},isZero:function(){return G.Utils.evaluate(this.toLHS()).equals(0)},latex:function(e){return[this.LHS.latex(e),this.RHS.latex(e)].join("=")}},V.equals=function(e,t){return new re(e,t)},t=V.functions.simplify[0],V.functions.simplify[0]=function(e){return e instanceof re?(e.LHS=t(e.LHS),e.RHS=t(e.RHS),e):t(e)},G.Expression.prototype.equals=function(e){return e instanceof G.Expression&&(e=e.symbol),new re(this.symbol,e)},G.Expression.prototype.solveFor=function(e){var t;if(this.symbol instanceof re){if(this.symbol.LHS.isConstant()&&this.symbol.RHS.equals(e))return new G.Expression(this.symbol.LHS);if(this.symbol.RHS.isConstant()&&this.symbol.LHS.equals(e))return new G.Expression(this.symbol.RHS);t=this.symbol.toLHS()}else t=this.symbol;return oe(t,e).map(function(e){return new G.Expression(e)})},G.Expression.prototype.expand=function(){if(this.symbol instanceof re){var e=this.symbol.clone();return e.RHS=V.expand(e.RHS),e.LHS=V.expand(e.LHS),new G.Expression(e)}return new G.Expression(V.expand(this.symbol))},G.Expression.prototype.variables=function(){return this.symbol instanceof re?G.Utils.arrayUnique(l(this.symbol.LHS).concat(l(this.symbol.RHS))):l(this.symbol)};function e(e,t){return V.equals(e,t)}G.Equation=re;var ie=G.Utils.checkAll=function(e,t){for(var n=0;nr[1][2]&&([p,c]=[c,p],[r[1],r[0]]=[r[0],r[1]]),1===r[0][0]&&2===r[0][2]&&2===r[1][0]&&4===r[1][2]&&(u=t[0],l=t[1],t=oe(V.parse(p,f(u,oe(V.parse(c),u)[0])),l).map(function(e){return e.toString()}),p=[oe(V.parse(c,f(l,t[0])))[0].toString()],t[1]&&p.push(oe(V.parse(c,f(l,t[1])))[0].toString()),te.SOLUTIONS_AS_OBJECT?((i={})[u]=p,i[l]=t):(t.unshift(l),p.unshift(u),i=[p,t])),i},solveNonLinearSystem:function(e,t,r){if(t<0)return[];r=void 0===r?G.Settings.NON_LINEAR_START:r;var i=G.Settings.MAX_NON_LINEAR_TRIES,s=Math.floor(i/2);t=void 0===t?i:t;var o,a,u,l,c,p=G.Settings.NON_LINEAR_JUMP_AT,f=G.Settings.NON_LINEAR_JUMP_SIZE,h=!0,m=G.Utils.arrayGetVariables(e),i=G.Matrix.jacobian(e,m,function(e){return $(e,m)},!0),g=G.Settings.MAX_NEWTON_ITERATIONS,d=e.map(function(e){return $(e,m)}),v=i.map(function(e){return $(e,m)},!0),w=G.Matrix.cMatrix(0,m),y=G.Matrix.cMatrix(r,m),b=0;do{if(g=Number.EPSILON);return h?se.systemSolutions(y,m,!0,function(e){return G.Utils.round(Number(e),14)}):[]},systemSolutions:function(e,r,i,s){var o=G.Settings.SOLUTIONS_AS_OBJECT?{}:[];return e.each(function(e,t){var n=(i?V.expand(e):e).valueOf();s&&(n=s.call(e,n));t=r[t];G.Settings.SOLUTIONS_AS_OBJECT?o[t]=n:o.push([t,n])}),o},solveSystemBySubstitution:function(e){var t=l(e[0]),n=l(e[1]);return 2===e.length&&2===t.length&&G.Utils.arrayEqual(t,n)?se.solveCircle(e,t):[]},solveSystem:function(e,t){for(var n=0;nt||(i!==c&&s.push(n),c=i);u=u.concat(s)};return t(e,r),t(n,i),u},bisection:function(e,t){var n=e-1,r=e+1;if(Math.sign(t(n))!==Math.sign(t(r))){var i,s,o=0;do{if(i=Math.abs(r-n),o++>G.Settings.MAX_BISECTION_ITER||isNaN(i))return}while(s=(n+r)/2,0=te.EPSILON);var a=(n+r)/2,e=t(a);if(!isNaN(e)&&Math.abs(e)<=G.Settings.BI_SECTION_EPSILON)return G.Utils.round(a,13)}},Newton:function(e,t,n){var r=G.Settings.MAX_NEWTON_ITERATIONS,i=0,s=e;do{var o=t(s);if(0===s&&0===o){a=0;break}if(r<++i)return;var a=s-o/n(s),o=Math.abs(a-s),s=a}while(o>te.NEWTON_EPSILON);if(Math.abs(t(a))<=te.EPSILON)return a},rewrite:function(e,t,n){var r,i;t=t||new z(0),e.isComposite()&&e.isLinear()?(r=[],i=[],e.each(function(e){("sqrt"===(e=e.clone()).fname&&e.contains(n)?r:i).push(e)},!0),1===r.length&&(t=V.expand(V.pow(V.subtract(t,G.Utils.arraySum(i)),new z(2))),e=V.expand(V.pow(z.unwrapSQRT(r[0]),new z(2))))):e=z.unwrapSQRT(V.expand(e));var s=0,o=e.length;if(e.group===K&&e.contains(n)&&e.isLinear()){e.distributeMultiplier();var a=new z(0);return e.each(function(e){e.contains(n)?(s++,a=V.add(a,e.clone())):t=V.subtract(t,e.clone())}),e=a,s!==o?se.rewrite(e,t,n):[e,t]}if(e.group===J&&e.contains(n)&&e.isLinear()){if(e.multiplier.lessThan(0)&&(e.multiplier=e.multiplier.multiply(new G.Frac(-1)),t.multiplier=t.multiplier.multiply(new G.Frac(-1))),t.equals(0))return new z(0);a=new z(1);return e.each(function(e){e.contains(n)?a=V.multiply(a,e.clone()):t=V.divide(t,e.clone())}),se.rewrite(e=a,t,n)}if(!e.isLinear()&&e.contains(n)){o=V.parse(e.power.clone().invert());return e=V.pow(e,o.clone()),t=V.pow(V.expand(t),o.clone()),se.rewrite(e,t,n)}if(e.group===ee||e.group===Y||e.group===W)return[e,t]},sqrtSolve:function(n,r){var t=new z(0),i=new z(0);if(n.isComposite()&&(n.each(function(e){"sqrt"===e.fname&&e.contains(r)?t=V.add(t,e.clone()):i=V.add(i,e.clone())}),!t.equals(0))){var e=V.expand(V.multiply(V.parse(n.multiplier),V.subtract(V.pow(i,new z(2)),V.pow(t,new z(2)))));return oe(e,r).filter(function(e){if(e.isImaginary())return e;var t={};return t[r]=e,X(n,t).equals(0)?e:void 0})}}},oe=function(n,p,i,t,e){if(t=t||0,t++>te.MAX_SOLVE_DEPTH)return i;if(n instanceof re){if(n.isZero())return[new z(0)];if(n.LHS.equals(p)&&!n.RHS.contains(p))return[n.RHS];if(n.RHS.equals(p)&&!n.LHS.contains(p))return[n.LHS]}if(n instanceof G.Vector&&(n=n.elements),p=p||"x",ne(n))return se.solveSystem.apply(void 0,arguments);i=i||[];var s={},r={};if(r[p]=0,Q(n)&&!0===X(n.getDenom(),r).equals(0))return i;var o=function(e,t){var n,r=Q(e);void 0===e||"number"==typeof e&&isNaN(e)||(ne(e)?e.forEach(function(e){o(e)}):"null"!==e.valueOf()&&("function"==typeof G.Settings.PRE_ADD_SOLUTION&&(e=G.Settings.PRE_ADD_SOLUTION(e)),r||(e=V.parse(e)),G.Settings.make_pi_conversions&&t&&(r=(n=V.divide(e.clone(),new z(Math.PI))).multiplier,t=Math.abs(r.num),r=Math.abs(r.den),t<10&&r<10&&(e=V.multiply(n,new z("pi")))),n=e.toString(),s[n]||i.push(e),s[n]=!0))};if(n.group===Y&&n.contains(p)){try{var a={};a[p]=0,X(e,a,"numer"),o(new z(0))}catch(e){}return i}if(n.group===J){var u=n.getNum();if(u.group!==J)return oe(u,p,i,t,e);var l=String(p);return u.each(function(e){e.contains(l)&&oe(e,p,i,t,n)}),i}n.group===ee&&"sqrt"===n.fname&&(n=V.pow(z.unwrapSQRT(n),new z(2)));var c=(G.Utils.isSymbol(n)?n:se.toLHS(n,!1)).getNum(),r=G.Utils.variables(c),a=r.length;if((c=G.Utils.isInt(c.power)&&0=Number.MAX_VALUE?e.toString():Number(e):(t=void 0===t?14:t,Math.round(e*Math.pow(10,t))/Math.pow(10,t))},ge=function(e){return e%2==0},de=function(e){return 1/(e%1)%2==0},ve=function(e,t){var n=typeof t;"function"==n&&"undefined"!=n||(t=function(e,t){return e===t});for(var r=[];e.length;){var i=e[0];if(1===e.length){r.push(i);break}var s=[];r.push(i);for(var o=1;ou)throw new Error("stopping");i=i.pow(2).add(1).mod(a),s=S.gcd(i.minus(n).abs(),a)}r*=2,n=i}return s.equals(a)?e(t+1):s}(2);r(i),a=a.divide(i)}}catch(e){n={},r(t)}}return-1==e&&(e=c(q(n)),n["-"+e]=n[e],delete n[e]),n},boxfactor:function(e,t){t=t||200;for(var n,r,i=Math.floor(5/12*e),s=0,o=!1;n=Math.floor(e/i),0!=(r=e%i);){if(o)return[e,1];i=Math.max(r,i-r),o=t<++s}return[n,i,s]},fib:function(e){var t=Math.sign(e);e=Math.abs(e);for(var t=ge(e)?t:Math.abs(t),n=0,r=1,i=1,s=2;s<=e;s++)i=n+r,n=r,r=i;return i*t},mod:function(e,t){return e%t},integer_part:function(e){return Math.sign(e)*Math.floor(Math.abs(e))},simpson:function(e,t,n,r){function i(e,t,n){var r=e(t);return r=isNaN(r)?e(1===n?t+1e-12:t-1e-12):r}r=r||1e-4;var s=Math.abs(Math.floor((n-t)/r));s%2!=0&&s++;for(var o=(n-t)/s,a=i(e,t,1),u=!1,l=t+o,c=1;c1e3*l))return l":{precedence:1,operator:">",action:"gt",prefix:!1,postfix:!1,leftAssoc:!1},"=>":{precedence:1,operator:"=>",action:"gte",prefix:!1,postfix:!1,leftAssoc:!1},",":{precedence:0,operator:",",action:"comma",prefix:!1,postfix:!1,leftAssoc:!1},":":{precedence:0,operator:",",action:"assign",prefix:!1,postfix:!1,leftAssoc:!1,vectorFn:"slice"},":=":{precedence:0,operator:",",action:"function_assign",prefix:!1,postfix:!1,leftAssoc:!0}},q={"(":{type:"round",id:1,is_open:!0,is_close:!1},")":{type:"round",id:2,is_open:!1,is_close:!0},"[":{type:"square",id:3,is_open:!0,is_close:!1,maps_to:"vector"},"]":{type:"square",id:4,is_open:!1,is_close:!0},"{":{type:"curly",id:5,is_open:!0,is_close:!1,maps_to:"Set"},"}":{type:"curly",id:6,is_open:!1,is_close:!0}},U=this.functions={cos:[I.cos,1],sin:[I.sin,1],tan:[I.tan,1],sec:[I.sec,1],csc:[I.csc,1],cot:[I.cot,1],acos:[I.acos,1],asin:[I.asin,1],atan:[I.atan,1],arccos:[I.acos,1],arcsin:[I.asin,1],arctan:[I.atan,1],asec:[I.asec,1],acsc:[I.acsc,1],acot:[I.acot,1],atan2:[I.atan2,2],acoth:[e.acoth,1],asech:[e.asech,1],acsch:[e.acsch,1],sinh:[e.sinh,1],cosh:[e.cosh,1],tanh:[e.tanh,1],asinh:[e.asinh,1],sech:[e.sech,1],csch:[e.csch,1],coth:[e.coth,1],acosh:[e.acosh,1],atanh:[e.atanh,1],log10:[,1],exp:[function(e){if(e.fname===F.LOG&&e.isLinear())return C.pow(e.args[0],De.create(e.multiplier));return C.parse(ce("e^({0})",e))},1],radians:[function(e){return C.parse(ce("({0})*pi/180",e))},1],degrees:[function(e){return C.parse(ce("({0})*180/pi",e))},1],min:[function(){var e=[].slice.call(arguments);return w(e)?e[0]:Me(e)?new De(Math.min.apply(null,e)):F.SYMBOLIC_MIN_MAX&&Ne(e)?h("min",e):C.symfunction("min",e)},-1],max:[function(){var e=[].slice.call(arguments);return w(e)?e[0]:Me(e)?new De(Math.max.apply(null,e)):F.SYMBOLIC_MIN_MAX&&Ne(e)?h("max",e):C.symfunction("max",e)},-1],erf:[,1],floor:[,1],ceil:[,1],trunc:[,1],Si:[,1],step:[,1],rect:[,1],sinc:[function(e){if(F.PARSE2NUMBER)return e.isConstant()?new De(Te.sinc(e)):C.parse(ce("sin({0})/({0})",e));return C.symfunction("sinc",[e])},1],tri:[,1],sign:[function(e){return e.isConstant(!0)?new De(Math.sign(Se(e))):C.symfunction("sign",arguments)},1],Ci:[,1],Ei:[,1],Shi:[,1],Chi:[,1],Li:[,1],fib:[,1],fact:[u,1],factorial:[u,1],continued_fraction:[function(e,t){e=Se(e);if(e.isConstant()){e=Te.continuedFraction(e,t),t=Ve.fromArray(e.fractions.map(function(e){return new De(e)}));return Ve.fromArray([new De(e.sign),new De(e.whole),t])}return C.symfunction("continued_fraction",arguments)},[1,2]],dfactorial:[,1],gamma_incomplete:[,[1,2]],round:[m,[1,2]],scientific:[function(e,t){return e.scientific=t||10,e},[1,2]],mod:[t,2],pfactor:[N,1],vector:[function(){return new Ve([].slice.call(arguments))},-1],matrix:[function(){return He.fromArray(arguments)},-1],Set:[function(){return je.fromArray(arguments)},-1],imatrix:[function(e){return He.identity(e)},-1],parens:[function(e){if(F.PARSE2NUMBER)return e;return C.symfunction("parens",[e])},-1],sqrt:[R,1],cbrt:[i,1],nthroot:[s,2],log:[O,[1,2]],expand:[function(e,t){return T(e,t=t||{expand_denominator:!0,expand_functions:!0})},1],abs:[_,1],invert:[function(e){if(ie(e))return e.invert();K("invert expects a matrix")},1],determinant:[function(e){if(ie(e))return e.determinant();return e},1],size:[function(e){var t;ie(e)?t=[new De(e.cols()),new De(e.rows())]:re(e)||se(e)?t=new De(e.elements.length):K("size expects a matrix or a vector");return t},1],transpose:[function(e){if(ie(e))return e.transpose();K("function transpose expects a matrix")},1],dot:[function(e,t){if(re(e)&&re(t))return e.dot(t);K("function dot expects 2 vectors")},2],cross:[function(e,t){if(re(e)&&re(t))return e.cross(t);K("function cross expects 2 vectors")},2],vecget:[function(e,t){return t.isConstant()&&ue(t)?e.elements[t]:C.symfunction("vecget",arguments)},2],vecset:[function(e,t,n){return t.isConstant?(e.elements[t]=n,e):C.symfunction("vecset",arguments)},3],vectrim:[function(e,n){return n=void 0===n?1e-14:n,e=e.clone(),n=Number(n),e.elements.sort(function(e,t){return t.group-e.group}),e.elements=ve(e.elements,function(e,t){return Number(C.subtract(Se(e),Se(t)).abs())<=n}),e},[1,2]],matget:[function(e,t,n){return t.isConstant()&&n.isConstant()?e.elements[t][n]:C.symfunction("matget",arguments)},3],matset:[function(e,t,n,r){return e.elements[t][n]=r,e},4],matgetrow:[function(e,t){return t.isConstant()?new He(e.elements[t]):C.symfunction("matgetrow",arguments)},2],matsetrow:[function(e,t,n){if(!t.isConstant())return C.symfunction("matsetrow",arguments);if(e.elements[t].length!==n.elements.length)throw new _e("Matrix row must match row dimensions!");e=e.clone();return e.elements[t]=n.clone().elements,e},3],matgetcol:[function(e,r){if(!r.isConstant())return C.symfunction("matgetcol",arguments);r=Number(r);var i=He.fromArray([]);return e.each(function(e,t,n){n===r&&i.elements.push([e.clone()])}),i},2],matsetcol:[function(n,r,e){if(!r.isConstant())return C.symfunction("matsetcol",arguments);if(r=Number(r),n.rows()!==e.elements.length)throw new _e("Matrix columns must match number of columns!");return e.each(function(e,t){n.set(t-1,r,e.elements[0].clone())}),n},3],rationalize:[r,1],IF:[function(e,t,n){"boolean"!=typeof e&&oe(e)&&(e=!!Number(e));return e?t:n},3],is_in:[function(e,t){if(ie(e)){for(var n=0,r=e.rows();n=s:o.precedence>s)&&o.precedence++}}},this.getOperator=function(e){return E[e]},this.aliasOperator=function(e,t){var n,r={},i=E[e];for(n in i)r[n]=i[n];r.operator=t,this.setOperator(r)},this.getOperators=function(){return E},this.getBrackets=function(){return q};function a(e){this.type=e.type,this.value=e.value,this.left=e.left,this.right=e.right}this.initConstants=function(){this.CONSTANTS={E:new De(F.E),PI:new De(F.PI)}},this.pretty_print=function(e){if(Array.isArray(e)){var t=e.map(e=>C.pretty_print(e)).join(", ");return"vector"===e.type?"vector<"+t+">":"("+t+")"}return e.toString()},this.peekers={pre_operator:[],post_operator:[],pre_function:[],post_function:[]},this.callPeekers=function(e){if(F.callPeekers)for(var t=this.peekers[e],n=be(arguments).slice(1).map(le),r=0;rc.precedence||!c.leftAssoc&&p.precedence===c.precedence))break;r.push(i.pop())}if(("vector"===t||"set"===t)&&"vectorFn"in c&&(c.action=c.vectorFn),c.postfix){var f=e[a-1];if(!f)throw new Ie("Unexpected prefix operator '"+l.value+"'! at "+l.column);if(f.type===A.OPERATOR&&!f.postfix)throw new Ie("Unexpected prefix operator '"+f.value+"'! at "+f.column)}else do{var h,m=!!(h=e[a+1])&&h.type===A.OPERATOR;if(m){if(!h.prefix)throw new Ie("A prefix operator was expected at "+h.column);h.is_prefix=!0,s.push(h),a++}}while(m);for((c.is_prefix?s:i).push(c);s.length&&(c.leftAssoc||!c.leftAssoc&&s[s.length-1].precedence>=c.precedence);)i.push(s.pop())}else l.type===A.VARIABLE_OR_LITERAL?(0===r.length&&o(s,i),r.push(l),(f=i[i.length-1])&&f.leftAssoc||o(s,r)):l.type===A.FUNCTION?i.push(l):l.type===A.UNIT&&r.push(l);Array.isArray(l)&&(r.push(this.toRPN(l)),l.type&&r.push(new A(l.type,A.FUNCTION,l.column)))}return o(i,r),o(s,r),r},this.parseRPN=function(e,t){try{for(var n in t=t||{})t[n]=C.parse(t[n],{});F.PARSE2NUMBER&&("e"in t||(t.e=new De(F.E)),"pi"in t||(t.pi=new De(F.PI)));for(var r=[],i=0,s=e.length;i\n"+this.left.toHTML(e+2,t)+n(e+1)+" \n":"",s=this.right?n(e+1)+"
  • \n"+this.right.toHTML(e+2,t)+n(e+1)+"
  • \n":"",r=n(e)+'
    '+this.value+"
    "+n(e)+"\n";return(i||s)&&(r+=n(e)+"
      \n"+i+s+n(e)+"
    \n"),r+=""},this.tree=function(e){for(var t=[],n=0;nr.numVal)&&(t.pop(),t.push(n))}}function O(e,t){if(e.equals(1))return new De(0);var n,r,i;if(e.fname===z&&e.multiplier.equals(1))return n=C.divide(O(e.args[0]),new De(2)),e.power.sign()<0&&n.negate(),n;if(e.equals(0))throw new Ae(F.LOG+"(0) is undefined!");return e.isImaginary()?b.evaluate(e,F.LOG):(e.isConstant()&&void 0!==t&&t.isConstant()?n=new De(Math.log(e)/Math.log(t)):e.group===V&&e.power.multiplier.lessThan(0)||"-1"===e.power.toString()?(e.power.negate(),n=O(e).negate()):"e"===e.value&&e.multiplier.equals(1)?(t=e.power,n=ne(t)?t:new De(t)):e.group===H&&"exp"===e.fname?(i=e.args[0],n=e.multiplier.equals(1)?C.multiply(i,new De(e.power)):C.symfunction(F.LOG,[e])):F.PARSE2NUMBER&&oe(e)?((e=C.parse(e)).multiplier.lessThan(0)&&(e.negate(),r=C.multiply(new De(Math.PI),new De("i"))),n=new De(Math.log(e.multiplier.toDecimal())),r&&(n=C.add(n,r))):(e.power.equals(1)||e.contains("e")||(i=e.group===V?e.power:new De(e.power),e.toLinear()),n=1i.length&&i.group===n.group&&([i,n]=[n,i])),i.multiplier.equals(0))return n;if(n.multiplier.equals(0))return i;if(i.isConstant()&&n.isConstant()&&F.PARSE2NUMBER)return h=new De(i.multiplier.add(n.multiplier).toDecimal(F.PRECISION));var a=i.group,u=n.group,l=i.power.toString(),c=n.power.toString();if(ai.group&&n.group!==X)return this.multiply(n,i);i.group===Z&&n.group===j&&i.value===n.value&&(p=i,i=n,n=p);var a=i.group,u=n.group,l=n.multiplier.num,c=n.multiplier.den;a!==H||i.fname!==z||n.isConstant()||i.args[0].value!==n.value||i.args[0].multiplier.lessThan(0)?a===H&&i.fname===z&&i.multiplier.equals(1)&&i.power.equals(-1)&&n.isConstant()&&i.args[0].equals(n)&&(i=C.symfunction(z,[n.clone()]),n=new De(1)):(m=i.power,h=C.parse(i.multiplier),(i=C.multiply(h,i.args[0].clone())).setPower(new Fe(.5).multiply(m)),a=i.group);var p,f=i.value,o=n.value,s=new Fe(i.sign()),h=a===B&&u===D&&n.multiplier.equals(i.value),m=(h?new Fe(1).multiply(i.multiplier):i.multiplier.multiply(n.multiplier)).abs(),r=i.clone().toUnitMultiplier();if(n=n.clone().toUnitMultiplier(!0),a===H&&u===H){var g=i.args[0].clone(),d=n.args[0].clone();if(i.fname===z&&n.fname===z&&i.isLinear()&&n.isLinear()){var v=C.divide(g,d).invert();v.gt(1)&&ue(v)&&(r=C.multiply(i.args[0].clone(),R(v.clone())),n=new De(1))}else if(i.fname===Y&&n.fname===Y&&!g.isConstant()&&!d.isConstant()&&n.power<0){v=C.subtract(g.clone(),d.clone());if(v.isConstant())if(p=new De(1),v<0){for(var w=0,y=Math.abs(v);w<=y;w++){var b=C.add(g.clone(),new De(w));p=C.multiply(p,b)}r=C.multiply(C.pow(g,new De(i.power)),C.pow(p,new De(n.power))),n=new De(1)}else{for(w=0,y=Math.abs(v);w<=y;w++){b=C.add(d.clone(),new De(w));p=C.multiply(p,b)}r=C.multiply(C.pow(p,new De(i.power)),C.pow(d,new De(n.power))),n=new De(1)}}}if(f===o&&a===j&&a===u&&(f=i.text("hash"),o=n.text("hash")),(f=u===V&&n.previousGroup===j&&a===j?Pe(i,"hash",V):f)!==o&&!h||a===j&&(u===G||u===B||u===H)||a===j&&u===Z)if(a===Z&&i.isLinear())if(u===Z&&n.distributeExponent(),u===Z&&n.isLinear()){for(var b in n.symbols){var S=n.symbols[b];r=r.combine(S)}r.multiplier=r.multiplier.multiply(n.multiplier)}else r.combine(n);else a!==D?a===Z?(r.distributeExponent(),r.combine(n)):n.isOne()||(E=n.multiplier.clone(),n.toUnitMultiplier(),(r=De.shell(Z).combine([r,n])).multiplier=r.multiplier.multiply(E)):r=n.clone().toUnitMultiplier();else{var M=i.power,N=n.power,E=ne(M),q=ne(N),q=E||q;a===j&&u!==j&&n.previousGroup!==j&&M.equals(1)?(r=new De(0),i.each(function(e){r=C.add(r,C.multiply(e,n.clone()))},!0)):(r.power=q?C.add(ne(M)?M:new De(M),ne(N)?N:new De(N)):a===D?M:M.add(N),r.power.equals(0)&&(r=r.convert(D)),q&&r.convert(V),i.imaginary&&n.imaginary&&ge(r.power%2)&&(r=new De(1),m.negate()),r.group!==V&&r.previousGroup&&(r.previousGroup=void 0),r.multiplier=r.multiplier.multiply(n.multiplier))}r.group===B&&(a=Math.log(r.value),M=Math.log(l)/a,N=Math.log(c)/a,q=m.num/l,a=m.den/c,0!=M&&ue(M)&&ue(q)&&(r.power=r.power.add(new Fe(M)),m.num/=l),0!=N&&ue(N)&&ue(a)&&(r.power=r.power.subtract(new Fe(N)),m.den/=c)),1===r.length&&(p=r.multiplier,(r=pe(r.symbols)).multiplier=r.multiplier.multiply(p));c=r.power.toString();return ge(c)&&r.fname===z?(s*=r.sign(),c=r.power,r=r.args[0],r=C.multiply(new De(m),C.pow(r,new De(c.divide(new Fe(2))))),s<0&&r.negate()):(r.multiplier=r.multiplier.multiply(m).multiply(s),r.group===X&&r.isImaginary()&&r.distributeMultiplier()),r=r.group===B&&ue(r.power.toDecimal())?r.convert(D):r}t&&!e&&(p=i,i=n,n=p,p=t,t=e,e=p);s=ie(n),t=ie(i);if(e&&s){var x=new He;n.eachElement(function(e,t,n){x.set(t,n,C.multiply(i.clone(),e))}),n=x}else if(t&&s)n=i.multiply(n);else if(e&&re(n))n.each(function(e,t){n.elements[--t]=C.multiply(i.clone(),n.elements[t])});else if(re(i)&&re(n))n.each(function(e,t){n.elements[--t]=C.multiply(i.elements[t],n.elements[t])});else{if(re(i)&&ie(n))return this.multiply(n,i);if(ie(i)&&re(n)){if(n.elements.length===i.rows()){var x=new He,A=i.cols();return n.each(function(e,t){for(var n=[],r=0;re.power.den)return e;e=ue(t)?De(Math.pow(n,t)):new De(n).setPower(t)}return e}(C.multiply(S,M))):a).fname===z?(M=((S=a.group===V)?a.power.multiplier:a.power).toString(),ge(M)&&(S=S?C.divide(a.power,new De(2)):new De(a.power.divide(new Fe(2))),n=a.multiplier,(a=C.pow(a.args[0],S)).multiplier=a.multiplier.multiply(n))):!F.IGNORE_E&&a.isE()&&a.group===V&&a.power.contains("pi")&&a.power.contains(F.IMAGINARY)&&i.group===Z&&(l=i.stripVar(F.IMAGINARY),a=C.add(I.cos(l),C.multiply(De.imaginary(),I.sin(l)))),a}return re(r)&&t?r=r.map(function(e){return C.pow(e,i.clone())}):ie(r)&&t?(s=new He,r.eachElement(function(e,t,n){s.set(t,n,C.pow(e,i.clone()))}),r=s):e&&ie(i)&&(s=new He,i.eachElement(function(e,t,n){s.set(t,n,C.pow(r.clone(),e))}),r=s),r},this.comma=function(e,t){return(e=!(e instanceof L)?L.create(e):e).append(t),e},this.mod=t,this.slice=function(e,t){return new x(e,t)},this.equals=function(e,t){return e.group===G||e.isLinear()||K("Cannot set equality for "+e.toString()),J[e.value]=t.clone(),t},this.percent=function(e){return C.divide(e,new De(100))},this.assign=function(e,n){if(e instanceof L&&n instanceof L)return e.elements.map(function(e,t){return C.assign(e,n.elements[t])}),Ve.fromArray(n.elements);if(e.parent){var t=e.parent;return t.elements[t.getter]=n,delete t.getter,t}if(e.group!==G)throw new Re("Cannot complete operation. Incorrect LH value for "+e);return J[e.value]=n},this.function_assign=function(e,t){var n=e.elements.pop();return fe(n,e.elements,t)};function v(e){return new De(!0===e?1:0)}this.eq=function(e,t){return v(e.equals(t))},this.gt=function(e,t){return v(e.gt(t))},this.gte=function(e,t){return v(e.gte(t))},this.lt=function(e,t){return v(e.lt(t))},this.lte=function(e,t){return v(e.lte(t))},this.factorial=function(e){return this.symfunction(Y,[e])},this.dfactorial=function(e){return this.symfunction(W,[e])}}F.FUNCTION_MODULES.push(Te),x(Te),Math.sign=Math.sign||function(e){return 0===(e=+e)||isNaN(e)?e:0this.elements.length?null:this.elements[e-1]},set:function(e,t){ne(t)||(t=new De(t)),this.elements[e]=t},dimensions:function(){return this.elements.length},modulus:function(){return ye("SAFE",function(){return d.pow(this.dot(this.clone()),new De(.5))},void 0,this)},eql:function(e){var t=this.elements.length,n=e.elements||e;if(t!==n.length)return!1;do{if(Math.abs(d.subtract(this.elements[t-1],n[t-1]).valueOf())>PRECISION)return!1}while(--t);return!0},clone:function(){for(var e=new Ve,t=this.elements.length,n=0;nMath.abs(t.valueOf())&&(t=this.elements[e]),--n;);return t},magnitude:function(){var t=new De(0);return this.each(function(e){t=d.add(t,d.pow(e,new De(2)))}),d.sqrt(t)},indexOf:function(e){for(var t,n=null,r=this.elements.length,i=r;t=i-r,null===n&&this.elements[t].valueOf()===e.valueOf()&&(n=1+t),--r;);return n},text:function(e){return Pe(this)},toString:function(){return this.text()},latex:function(e){for(var t=[],n=0;nthis.cols()?[]:this.elements[e-1]},col:function(e){var t=this.rows(),n=[];if(e>this.cols()||!e)return n;for(var r=0;r\n
      \n
    • \n'+this.tree(e).toHTML(3,t)+"\n
    • \n
    \n"},Xe.addPeeker=function(e,t){d.peekers[e]&&d.peekers[e].push(t)},Xe.removePeeker=function(e,t){we(d.peekers[e],t)},Xe.parse=function(e){return String(e).split(";").map(function(e){return d.parse(e)})},Xe.api(),Xe}({bigInt:function(){var Q=function(o){"use strict";var v=1e7,l=7,t=9007199254740992,n=m(t),c=Math.log(t);function u(e,t){return void 0===e?u[0]:void 0===t||10==+t?z(e):V(e,t)}function p(e,t){this.value=e,this.sign=t,this.isSmall=!1}function f(e){this.value=e,this.sign=e<0,this.isSmall=!0}function h(e){return-t=t.length?r(e,t):r(t,e)}function i(e,t){for(var n,r=e.length,i=new Array(r),s=v,o=0;ot.length?1:-1;for(var n=e.length-1;0<=n;n--)if(e[n]!==t[n])return e[n]>t[n]?1:-1;return 0}function L(e){e=e.abs();return!e.isUnit()&&(!!(e.equals(2)||e.equals(3)||e.equals(5))||!(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))&&(!!e.lesser(49)||void 0))}function I(e,t){for(var n,r,i,s=e.prev(),o=s,a=0;o.isEven();)o=o.divide(2),a++;e:for(r=0;r=r)throw new Error(s+" is not a valid digit in base "+t+".")}if(2<=t&&t<=36&&n<=c/Math.log(t)){var o=parseInt(e,t);if(isNaN(o))throw new Error(s+" is not a valid digit in base "+t+".");return new f(parseInt(e,t))}t=z(t);var a=[],o="-"===e[0];for(i=o?1:0;i"!==e[++i];);a.push(z(e.slice(u+1,i)))}}return H(a,t,o)};function H(e,t,n){for(var r=u[0],i=u[1],s=e.length-1;0<=s;s--)r=r.add(e[s].times(i)),i=i.times(t);return n?r.negate():r}function j(e){return e<=35?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e):"<"+e+">"}function Z(e,t){if((t=Q(t)).isZero()){if(e.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(t.equals(-1)){if(e.isZero())return{value:[0],isNegative:!1};if(e.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-e)).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var n=Array.apply(null,Array(+e-1)).map(Array.prototype.valueOf,[0,1]);return n.unshift([1]),{value:[].concat.apply([],n),isNegative:!1}}n=!1;if(e.isNegative()&&t.isPositive()&&(n=!0,e=e.abs()),t.equals(1))return e.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(+e)).map(Number.prototype.valueOf,1),isNegative:n};for(var r=[],i=e;i.isNegative()||0<=i.compareAbs(t);){var i=(s=i.divmod(t)).quotient,s=s.remainder;s.isNegative()&&(s=t.minus(s).abs(),i=i.next()),r.push(s.toJSNumber())}return r.push(i.toJSNumber()),{value:r.reverse(),isNegative:n}}function X(e,t){t=Z(e,t);return(t.isNegative?"-":"")+t.value.map(j).join("")}function $(e){if(h(+e)){var t=+e;if(t===d(t))return new f(t);throw new Error("Invalid integer: "+e)}var n="-"===e[0],r=(e=n?e.slice(1):e).split(/e/i);if(2n-1&&(void 0===s[r+1]&&(s[r+1]=0),s[r+1]+=s[r]/n|0,s[r]%=n)}return s.reverse()}N.absoluteValue=N.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)},N.ceil=function(){return P(new this.constructor(this),this.e+1,2)},N.comparedTo=N.cmp=function(e){var t,n,r=this,i=r.d,s=(e=new r.constructor(e)).d,o=r.s,a=e.s;if(!i||!s)return o&&a?o!==a?o:i===s?0:!i^o<0?1:-1:NaN;if(!i[0]||!s[0])return i[0]?o:s[0]?-a:0;if(o!==a)return o;if(r.e!==e.e)return r.e>e.e^o<0?1:-1;for(t=0,n=(r=i.length)<(e=s.length)?r:e;ts[t]^o<0?1:-1;return r===e?0:ethis.d.length-2},N.isNaN=function(){return!this.s},N.isNegative=N.isNeg=function(){return this.s<0},N.isPositive=N.isPos=function(){return 0(r=Math.max(Math.ceil(a/_),o)+2)&&(s=r,t.length=1),t.reverse(),r=s;r--;)t.push(0);t.reverse()}else{for((c=(r=l.length)<(o=p.length))&&(o=r),r=0;r(i=(c=Math.ceil(s/_))>i?c+1:i+1)&&(r=i,n.length=1),n.reverse();r--;)n.push(0);n.reverse()}for((i=a.length)-(r=u.length)<0&&(r=i,n=u,u=a,a=n),t=0;r;)t=(a[--r]=a[r]+u[r]+t)/U|0,a[r]%=U;for(t&&(a.unshift(t),++l),i=a.length;0==a[--i];)a.pop();return e.d=a,e.e=F(a,l),y?P(e,s,o):e},N.precision=N.sd=function(e){var t;if(void 0!==e&&e!==!!e&&1!==e&&0!==e)throw Error(d+e);return this.d?(t=G(this.d),e&&this.e+1>t&&(t=this.e+1)):t=NaN,t},N.round=function(){var e=this.constructor;return P(new e(this),this.e+1,e.rounding)},N.sine=N.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+_,r.rounding=1,n=function(e,t){var n,r=t.d.length;if(r<3)return Q(e,2,t,t);n=16<(n=1.4*Math.sqrt(r))?16:0|n,t=Q(e,2,t=t.times(1/Y(5,n)),t);for(var i,s=new e(5),o=new e(16),a=new e(20);n--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(a))));return t}(r,W(r,n)),r.precision=e,r.rounding=t,P(2=e.d.length-1&&(n=l<0?-l:l)<=9007199254740991)return i=H(u,a,n,r),e.s<0?new u(1).div(i):P(i,r,s);if((o=a.s)<0){if(tu.maxE+1||t=r.toExpPos):(q(e,1,m),void 0===t?t=r.rounding:q(t,0,8),k(n=P(new r(n),e,t),e<=n.e||n.e<=r.toExpNeg,e));return n.isNeg()&&!n.isZero()?"-"+e:e},N.toSignificantDigits=N.toSD=function(e,t){var n=this.constructor;return void 0===e?(e=n.precision,t=n.rounding):(q(e,1,m),void 0===t?t=n.rounding:q(t,0,8)),P(new n(this),e,t)},N.toString=function(){var e=this.constructor,e=k(this,this.e<=e.toExpNeg||this.e>=e.toExpPos);return this.isNeg()&&!this.isZero()?"-"+e:e},N.truncated=N.trunc=function(){return P(new this.constructor(this),this.e+1,1)},N.valueOf=N.toJSON=function(){var e=this.constructor,e=k(this,this.e<=e.toExpNeg||this.e>=e.toExpPos);return this.isNeg()?"-"+e:e};var C=function(e,t,n,r,i,s){var o,a,u,l,c,p,f,h,m,g,d,v,w,y,b,S,M,N,E,q=e.constructor,x=e.s==t.s?1:-1,A=e.d,C=t.d;if(!(A&&A[0]&&C&&C[0]))return new q(e.s&&t.s&&(A?!C||A[0]!=C[0]:C)?A&&0==A[0]||!C?0*x:x/0:NaN);for(a=s?(c=1,e.e-t.e):(s=U,I(e.e/(c=_))-I(t.e/c)),N=C.length,S=A.length,m=(x=new q(x)).d=[],u=0;C[u]==(A[u]||0);u++);if(C[u]>(A[u]||0)&&a--,null==n?(w=n=q.precision,r=q.rounding):w=i?n+(e.e-t.e)+1:n,w<0)m.push(1),p=!0;else{if(w=w/c+2|0,u=0,1==N){for(C=C[l=0],w++;(u=s/2&&++M;l=0,(o=O(C,g,N,d))<0?(v=g[0],1<(l=(v=N!=d?v*s+(g[1]||0):v)/M|0)?1==(o=O(f=R(C,l=s<=l?s-1:l,s),g,h=f.length,d=g.length))&&(l--,T(f,Nt[i]?1:-1;break}return s}function T(e,t,n,r){for(var i=0;n--;)e[n]-=i,i=e[n]=(a=c.length)){if(!r)break e;for(;a++<=p;)c.push(0);l=u=0,o=(s%=_)-_+(i=1)}else{for(l=a=c[p],i=1;10<=a;a/=10)i++;u=(o=(s%=_)-_+i)<0?0:l/v(10,i-o-1)%10|0}if(r=r||t<0||void 0!==c[p+1]||(o<0?l:l%v(10,i-o-1)),u=n<4?(u||r)&&(0==n||n==(e.s<0?3:2)):5f.maxE?(e.d=null,e.e=NaN):e.ee.constructor.maxE?(e.d=null,e.e=NaN):e.ei-1;)c[n]=0,n||(++s,c.unshift(1));for(a=c.length;!c[a-1];--a);for(o=0,l="";oa)for(s-=a;s--;)l+="0";else st&&(e.length=t,1)}function ee(e){return new this(e).abs()}function te(e){return new this(e).acos()}function ne(e){return new this(e).acosh()}function re(e,t){return new this(e).plus(t)}function ie(e){return new this(e).asin()}function se(e){return new this(e).asinh()}function oe(e){return new this(e).atan()}function ae(e){return new this(e).atanh()}function ue(e,t){e=new this(e),t=new this(t);var n,r=this.precision,i=this.rounding,s=r+4;return e.s&&t.s?e.d||t.d?!t.d||e.isZero()?(n=t.s<0?B(this,r,i):new this(0)).s=e.s:!e.d||t.isZero()?(n=B(this,s,1).times(.5)).s=e.s:n=t.s<0?(this.precision=s,this.rounding=1,n=this.atan(C(e,t,s,1)),t=B(this,s,1),this.precision=r,this.rounding=i,e.s<0?n.minus(t):n.plus(t)):this.atan(C(e,t,s,1)):(n=B(this,s,1).times(0s.maxE?(i.e=NaN,i.d=null):e.et.group}),n=0,r=t.length;ne.length&&(n=t,t=e,e=n),e.some(function(e){return-1=Math.abs(i.c)?(c=2,i.e=n/i.d,i.f=i.c/i.d,i.g=o*r,i.a3=i.e*(i.g+n)+i.h*(r/i.d),i.a1=-n+i.f*r,i.a7=i.h+(i.f+o)*n):(c=1,i.e=n/i.c,i.f=i.d/i.c,i.g=i.e*o,i.a3=i.e*n+(i.g+i.h/i.c)*r,i.a1=-(n*(i.d/i.c))+r,i.a7=i.g*i.d+i.h*i.f+n)),c}function j(e,t,n,r,i,s,o,a,u){if(3!=n)if(r=1==n?i:r,Math.abs(s.a1)>10*e*Math.abs(r)){s.a7/=s.a1,s.a3/=s.a1,o[0]=u[0],o[1]=-(u[0]*s.a7)+u[1];for(l=2;l.01*Math.abs(n.lzr))break;for(V(o,g,v,u,s,a),w=Math.abs(-(n.szr*a.b)+a.a)+Math.abs(n.szi*a.b),y=Math.sqrt(Math.abs(v)),f=2*Math.abs(s[0]),d=-(n.szr*a.b),b=1;b10*Math.abs(a[b])*e)for(d=-m/c,a[0]=o[0],w=1;w10*Math.abs(a[b])*e?-m/c:0}return v}(e,p,k,o,a,u,l,s,D),b=k.a,0=a)&&(m=0==m?Number.MIN_VALUE:m,m=Math.floor(Math.log(m)/b+.5),1!=(o=Math.pow(2,m))))for(O=0;Or(i[1])||i[1].isConstant(!0))&&s.multiplier.lessThan(0)&&(t.add(new Q(-1)),e.each(function(e){e.negate()},!0)):(e.each(function(e){e.isComposite()?e.each(function(e){e.multiplier=e.multiplier.divide(n)}):e.multiplier=e.multiplier.divide(n)}),e.updateHash()),t&&t.add(new Q(n))),e},trialAndError:function(e,t,n){var r=e.clone();try{var i=[];if(e.isConstant()||e.group===j)return e;for(var s=new W(e,n),o=s.coeffs[0],a=$.Math2.ifactor(o),u=_.proots(e),l=0;lE[0].count?E:N,x=S(q),A=[];if(x){var C=x[1],L=function(e,t){var n=e.len(),r=t.len(),t=t.terms[C],e=e.terms[C];return n=r.length);){if(200=E.length)for(R=1;R=Number(_.degree(y,o))?(p=(s=_.div(w.clone(),H.expand(y.clone())))[0],i=(w=s[1]).groupTerms(o)):p=new Q(0),1===Number(_.degree(y,o))){var b=H.divide(w,y);return n?[p,b]:H.add(p,b)}r=_.Factor.factor(y),m=_.PartFrac.createTemplate(y.clone(),r,[],o),g=m[0],f=m[1],u=m[2],c=[i.length],l=[],a=[],h=[],f.map(function(e,t){d=g[t],v=u[t];for(var n=0;nct.Settings.integration_depth&&Vt.integration.stop("Maximum depth reached. Exiting!"),ce.contains(n,!0)){if(e===St)t=Vt.integration.poly_integrate(ce,n,ut);else if(e===qt)if(ce.previousGroup===gt&&"sqrt"!==ce.fname&&ce.fname!==ht.PARENTHESIS&&Vt.integration.stop(),ce.contains(n)&&ce.previousGroup!==gt)ce.power.contains(n)?Vt.integration.stop():((We=Vt.diff(ce.clone().toLinear(),n)).contains(n)&&Vt.integration.stop(),t=Vt.integration.poly_integrate(ce,n,ut));else{if((f=Vt.diff(ce.power.clone(),n)).contains(n)){var r=f.stripVar(n);if((h=pt.divide(f.clone(),r.clone())).group===St&&h.isLinear())return r.multiplier=r.multiplier.divide(new ft(2)),pt.parse(yt("({2})*(sqrt(pi)*erf(sqrt(-{0})*{1}))/(2*sqrt(-{0}))",r,n,ce.multiplier));Vt.integration.stop()}ce.isE()?f.isLinear()?t=ce:f.isE()&&f.power.group===St&&f.power.power.equals(1)?t=pt.multiply(pt.symfunction("Ei",[ce.power.clone()]),ce.power):Vt.integration.stop():(g=pt.symfunction(xt,[pt.parse(ce.value)]),t=pt.divide(ce,g)),t=pt.divide(t,f)}else if(ce.isComposite()&&ce.isLinear()){var i=pt.parse(ce.multiplier);ce.toUnitMultiplier(),t=new dt(0),ce.each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))}),t=pt.multiply(i,t)}else if(e===Nt)if((ce=ce.power.greaterThan(1)?pt.expand(ce):ce).power.equals(1))t=new dt(0),ce.each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))},!0);else{var s=Number(ce.power),i=ce.multiplier.clone();ce.toUnitMultiplier();var o,a,u,l=ce.clone().toLinear(),c=(Ve=Vt.integration.decompose_arg(l,n))[3],p=Ve[2],f=Ve[0],h=Ve[1];if(-1===s&&h.group!==Mt&&h.power.equals(2)){var m,g,d,v,w,y,b,S,M,N,E,q=!wt(c)||0e.fname});var Ve,He=Fe.args[0];He.isLinear()&&(He.group===Nt||He.group===Et||He.group===St)||Vt.integration.stop(),h=(Ve=Vt.integration.decompose_arg(He,n))[1],f=Ve[0],h.isLinear()||Vt.integration.stop();var je,Ze=De.args[0];if(He.equals(Ze))if(Be===Ct&&Ge===Lt||Be===Lt&&Ge===Ct)if(Fe.power.lessThan(0)&&Vt.integration.stop(),Be===Ct&&Fe.power.add(De.power).equals(0))Fe.fname=It,Fe.updateHash(),t=Vt.integrate(Fe,n,ut);else if(bt(Fe.power)&&Ge===Lt&&De.power.lessThan(0)){var _=Number(Fe.power)/2,Xe=pt.parse(yt("(1-cos({0})^2)^({1})",Fe.args[0],_));t=Vt.integrate(pt.expand(pt.multiply(Xe,De.clone())),n,ut,lt)}else if(bt(Fe.power)&&Ge===Ct&&De.power.lessThan(0)){_=Number(Fe.power)/2,Xe=pt.parse(yt("(1-sin({0})^2)^({1})",Fe.args[0],_));t=Vt.integrate(pt.expand(pt.multiply(Xe,De.clone())),n,ut,lt)}else{var $e,ze=ct.Utils.even(Fe.power),Qe=ct.Utils.even(De.power);if(t=new dt(0),ze&&Qe){var Ye=function(e){var t=e.power/2,t=e.fname===Lt?"((1/2)+(cos(2*("+e.args[0]+"))/2))^"+t:"((1/2)-(cos(2*("+e.args[0]+"))/2))^"+t;return pt.parse(t)},f=Ye(Fe),c=Ye(De),We=pt.multiply(f,c);return(Je=pt.expand(We)).each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))}),pt.multiply(t,ne)}nt=ze?($e=Fe,De):($e=De,Fe);var Je,Ke=$e.fname===Lt?-1:1,et=((_=nt.power)-1)/2,tt=pt.parse("(1-"+$e.fname+ct.Utils.inBrackets(He)+"^2)^"+et);(Je=pt.expand(pt.multiply(new dt(Ke),pt.multiply($e.clone(),tt)))).each(function(e){t=pt.add(t,Vt.integration.poly_integrate(e.clone()))})}else Be===Ut&&Ge===It&&h.isLinear()&&De.isLinear()?t=pt.parse(yt("sec({0})^({1})/({1})",Fe.args[0],Fe.power)):Be===It&&Ge===Ut&&h.isLinear()?Fe.isLinear()&&De.isLinear()?t=pt.divide(pt.symfunction(Ut,[He.clone()]),f):bt(Fe.power)?(s=Number(Fe.power)/2,We=pt.parse(yt("(sec({0})^2-1)^({1})",Fe.args[0],s)),t=Vt.integrate(pt.expand(pt.multiply(We,De)),n,ut)):Vt.integration.stop():t=Be===Ut&&Ge===Lt?(Fe.fname=Lt,Fe.invert().updateHash(),Vt.integrate(pt.multiply(Fe,De),n,ut)):Be===Ct&&Ge===_t?(De.fname=Ct,De.invert().updateHash(),Vt.integrate(pt.multiply(Fe,De),n,ut)):(We=Be!==It||Ge!==Lt&&Ge!==Ct||!De.power.lessThan(0)?pt.multiply(Fe.fnTransform(),De.fnTransform()):pt.multiply(Fe.fnTransform(),De),Vt.integrate(pt.expand(We),n,ut));else Be!==Ct&&Be!==Lt||Ge!==Ct&&Ge!==Lt?Vt.integration.stop():Fe.isLinear()&&De.isLinear()?t=Fe.args[0].isLinear()&&De.args[0].isLinear()?(Ge===Ct?(p=Fe.args[0],je=De.args[0]):(je=Fe.args[0],p=De.args[0]),O=pt.parse(yt("(sin(({1})+({0}))+sin(({1})-({0})))/2",p.toString(),je.toString())),Vt.integrate(O,n,ut)):(st=Gt(ie),Vt.integrate(pt.expand(st),n,ut)):(st=new dt(1),ie.map(function(e){e=e.fnTransform();st=pt.multiply(st,e)}),We=pt.expand(st),(t=Vt.integrate(We,n,ut)).hasIntegral()&&(t=Vt.integrate(Gt(st.collectSymbols()),n,ut)))}else Pe===gt&&ke===St?(oe=Fe.isLinear(),Fe.fname===Lt&&oe&&De.power.equals(-1)?t=pt.symfunction("Ci",[Fe.args[0]]):Fe.fname===Lt&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===kt&&oe&&De.power.equals(-1)?t=pt.symfunction("Chi",[Fe.args[0]]):Fe.fname===kt&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===Ct&&oe&&De.power.equals(-1)?t=pt.symfunction("Si",[Fe.args[0]]):Fe.fname===Ct&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===Pt&&oe&&De.power.equals(-1)?t=pt.symfunction("Shi",[Fe.args[0]]):Fe.fname===Pt&&De.power.equals(-1)?t=Vt.integrate(pt.multiply(Fe.fnTransform(),De.clone()),n,ut):Fe.fname===xt&&De.power.equals(-1)?t=Vt.integration.poly_integrate(Fe,n,ut):"erf"===Fe.fname?De.power.equals(1)&&(ee=(Se=Vt.integration.decompose_arg(Fe.args[0],n))[0],K=Se[1],D=Fe.args[0].toString(),t=pt.parse(yt("(e^(-(({2}))^2)*(sqrt(pi)*e^((({2}))^2)*(2*({0})^2*({1})^2-3)*erf(({2}))+2*({0})*({1})-2))/(4*sqrt(pi)*({0})^2)",ee,K,D))):t=Vt.integration.by_parts(ce,n,ut,lt)):Pe===qt&&ke===St?(h=Be===xt?Vt.integration.decompose_arg(Fe.args[0],n)[1]:null,t=Fe.isE()&&(Fe.power.group===St||Fe.power.group===Et)&&De.power.equals(-1)?pt.symfunction("Ei",[Fe.power.clone()]):Be===xt&&h.value===De.value?Vt.integration.poly_integrate(Fe,n,ut):Vt.integration.by_parts(ce,n,ut,lt)):Pe===Mt&&ke===St?(ce=De.value===Fe.value&&Fe.power.equals(-1)?(ae=Math.min.apply(null,ct.Utils.keys(Fe.symbols)),ue=Math.min(ae,De.power),(le=De.clone()).power=new ft(ue),De=pt.divide(De,le.clone()),We=new dt(0),Fe.each(function(e){We=pt.add(We,pt.divide(e.clone(),le.clone()))}),We.multiplier=Fe.multiplier,pt.divide(De,We)):pt.expand(ce),t=Vt.integration.partial_fraction(ce,n,ut)):Pe===Nt&&ke===St?(O=Fe.clone().toLinear(),pe=ct.Algebra.degree(O,pt.parse(n)).equals(1),Fe.power.equals(-.5)?(f=(Ve=Vt.integration.decompose_arg(Fe.clone().toLinear(),n))[0].negate(),h=Ve[1],c=Ve[3],xe=Number(Fe.power),Ae=Number(De.power),wt(Ae)&&ct.Utils.even(Ae)&&h.power.equals(2)?(Me=pt.divide(pt.multiply(pt.pow(c.clone(),new dt(2)),pt.symfunction(At,[pt.divide(c.clone(),f.clone())])),pt.pow(f.clone(),new dt(2))),Me=pt.multiply(Me,pt.symfunction(At,[c]).invert()),(fe=pt.parse("sin(u)")).power=fe.power.multiply(De.power),R=Vt.integrate(fe,"u",ut),he=pt.parse("asin(sqrt("+f+"/"+c+")*"+n+")"),t=pt.multiply(Me,R.sub(new dt("u"),he))):-.5===xe&&(me=function(e,t){t=pt.parse(Vt.integrate(e,n,ut,lt).sub(n,yt(t,n)));if(!t.hasIntegral())return t},-1===Ae?t=me(pt.expand(pt.expand(pt.pow(pt.multiply(Fe.invert(),De.invert()),new dt(2)))).invert(),"sqrt(1-1/({0})^2)"):-2===Ae&&(t=me(pt.sqrt(pt.expand(pt.divide(pt.pow(ce,new dt(2)).invert(),pt.pow(new dt(n),new dt(2))).negate())).invert(),"sqrt(1-1/({0})^2)")))):Fe.power.equals(-1)&&De.isLinear()&&pe?t=Vt.integration.partial_fraction(ce,n,ut):!Fe.power.lessThan(0)&&wt(Fe.power)?(ge=pt.expand(Fe),t=new dt(0),ge.each(function(e){e.group===Mt?e.each(function(e){t=pt.add(t,Vt.integrate(pt.multiply(De.clone(),e),n,ut))}):t=pt.add(t,Vt.integrate(pt.multiply(De.clone(),e),n,ut))})):Fe.power.lessThan(-2)?t=Vt.integration.by_parts(ce,n,ut,lt):Fe.power.lessThan(0)&&De.power.greaterThan(1)?(f=(Ve=Vt.integration.decompose_arg(Fe.clone().toLinear(),n))[0].negate(),h=Ve[1],c=Ve[3],l=Fe.clone().toLinear(),t=h.group!==Mt&&h.isLinear()?(s=Number(De.power),$e=new dt(Ce="_u_"),de=pt.expand(pt.divide(pt.pow(pt.subtract($e.clone(),c.clone()),new dt(s)),$e.clone())),(ve={})[Ce]=l,we=pt.parse(de,ve),Vt.integrate(we,n,0)):De.power.greaterThan(h.power)||De.power.equals(h.power)?(ye=new ct.Algebra.Classes.Factors,Fe=ct.Algebra.Factor.coeffFactor(Fe.invert(),ye),(be=ct.Algebra.divide(De,Fe)).group!==Et?(t=new dt(0),be.each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))}),ye.each(function(e){t=pt.divide(t,e)}),pt.expand(t)):Vt.integration.by_parts(ce,n,ut,lt)):Vt.integration.partial_fraction(ce,n,ut)):Fe.power.den.equals(2)?(f=(Se=Vt.integration.decompose_arg(Fe.clone().toLinear(),n))[3],h=Se[1],c=Se[0],je=Se[2],t=h.power.equals(2)&&c.lessThan(0)?(f.equals(1)||(ne=pt.multiply(ne,pt.pow(f,new dt(2)))),$e=n,Me=pt.divide(pt.pow(c.clone().negate(),new dt(.5)),pt.pow(f,new dt(.5))),Ce=pt.symfunction(Lt,[new dt($e)]),Ne=pt.pow(pt.symfunction(Lt,[new dt($e)]),new dt(Fe.power.num)),Ee=pt.pow(pt.symfunction(Ct,[new dt($e)]),new dt(De.power)),qe=pt.multiply(pt.multiply(Ne,Ce),Ee),(R=Vt.integrate(qe,$e,ut)).sub($e,pt.symfunction(Ot,[pt.multiply(new dt(n),Me)]))):Vt.integration.partial_fraction(ce,n,ut,lt)):pe&&(t=Vt.integration.partial_fraction(ce,n,ut))):Fe.isComposite()&&De.isComposite()?(t=new dt(0),Fe.power.greaterThan(0)&&De.power.greaterThan(0)?(Je=pt.expand(ce)).each(function(e){t=pt.add(t,Vt.integrate(e,n,ut))},!0):(xe=Number(Fe.power),Ae=Number(De.power),xe<0&&0ht.max_lim_depth)){e.clone();var s=t.clone();if("abs"===t.fname){var o=e.sign(),a=r.sign();if(r.isInfinity)return pt.multiply(new dt(o),new dt(a));if(r.equals(0)){var a=pt.parse(e.multiplier),u=pt.parse(t.multiplier);return pt.divide(pt.multiply(a,Vt.Limit.interval("-1","1")),u)}Vt.Limit.diverges()}var l=function(e){if(ct.Utils.isVector(e)){for(var t=0;tht.max_lim_depth)){var e=pt.parse(t.multiplier);t.toUnitMultiplier();try{if(t.isConstant(!0))d=t;else{var o={};o[n]=r;try{var a=pt.parse(t.sub(n,r),o);(a.isConstant(!0)||a.isInfinity)&&(d=a)}catch(e){}if(!d){var u,l=t.getNum(),c=t.getDenom();if(c.isConstant(!0)){if(t.group===qt){var p,f,h,m,g,d,v=t.clone().toLinear(),w=(t.power.clone(),v.getNum()),y=v.getDenom(),b=ct.Utils.decompose_fn(y,n,!0);d=w.group===St&&w.multiplier.isOne()&&b.ax.group===St&&b.b.isConstant(!0)&&b.a.isOne()&&b.b.isConstant(!0)?pt.parse(yt("(1/e^({0}))",b.b)):(f=(p=Vt.Limit.rewriteToLog(t.clone())).power.clone(),h=p.clone().toLinear(),m=Vt.Limit.limit(h,n,r,i),g=Vt.Limit.limit(f,n,r,i),pt.pow(m,g))}else if(t.group===gt&&1===t.args.length){var S,M=Vt.Limit.limit(t.args[0],n,r,i);if(ct.Utils.isVector(M))return d=M.map(function(e){return t.clone().args[0]=e,Vt.Limit.limit(pt.symfunction(t.fname,[e]),n,r,i)}),pt.multiply(e,d);if(M.isConstant(!0)){var N=pt.symfunction(t.fname,[M]);try{k(N),S=!0}catch(e){S=!1}}if(S)d=N;else if(Vt.Limit.isConvergent(M))if(t.fname===xt)switch(M.toString()){case"0":d=dt.infinity().negate();break;case"Infinity":case"-Infinity":d=dt.infinity()}else if(t.fname!==Lt&&t.fname!==Ct||!r.isInfinity){if(t.fname===It){var E=t.args[0],q=E.getNum(),x=E.getDenom(),A=q.toUnitMultiplier();(r.isInfinity||A.equals("pi")&&x.equals(2))&&(d=divergent())}else if(t.fname===ht.FACTORIAL&&M.isInfinity)return dt.infinity()}else d=Vt.Limit.interval(-1,1)}else if(t.group===St){if(0ht.max_lim_depth)return;d=Vt.Limit.limit(Vt.diff(t,n),n,r,i)}}}}else d=Vt.Limit.divide(l,c,n,r,i)}}d=d||pt.symfunction("limit",[t,n,r])}catch(e){d=pt.symfunction("limit",[t,n,r])}return pt.multiply(e,d)}}},Fresnel:{S:function(e){return e.isConstant(!0)?Vt.defint(pt.parse("sin(pi*x^2/2)"),dt(0),e,"x"):pt.symfunction("S",arguments)},C:function(e){return e.isConstant(!0)?Vt.defint(pt.parse("cos(pi*x^2/2)"),dt(0),e,"x"):pt.symfunction("C",arguments)}}};nerdamer.register([{name:"diff",visible:!0,numargs:[1,3],build:function(){return Vt.diff}},{name:"sum",visible:!0,numargs:4,build:function(){return Vt.sum}},{name:"product",visible:!0,numargs:4,build:function(){return Vt.product}},{name:"integrate",visible:!0,numargs:[1,2],build:function(){return Vt.integrate}},{name:"defint",visible:!0,numargs:[3,4],build:function(){return Vt.defint}},{name:"S",visible:!0,numargs:1,build:function(){return Vt.Fresnel.S}},{name:"C",visible:!0,numargs:1,build:function(){return Vt.Fresnel.C}},{name:"limit",visible:!0,numargs:[3,4],build:function(){return Vt.Limit.limit}}]),nerdamer.api()}(),"undefined"!=typeof module&&(nerdamer=require("./nerdamer.core.js"),require("./Calculus.js"),require("./Algebra.js")),function(){var t,G=nerdamer.getCore(),V=G.PARSER,H=G.Algebra,j=G.Calculus,Z=j.integration.decompose_arg,X=G.Utils.evaluate,E=G.Utils.remove,c=G.Utils.format,$=G.Utils.build,f=G.Utils.knownVariable,z=G.Symbol,Q=G.Utils.isSymbol,l=G.Utils.variables,Y=G.groups.S,W=G.groups.PL,J=G.groups.CB,K=G.groups.CP,ee=G.groups.FN,te=G.Settings,s=G.Utils.range,ne=G.Utils.isArray;function re(e,t){if(t.isConstant()&&e.isConstant()&&!e.equals(t)||e.equals(G.Settings.IMAGINARY)||t.equals(G.Settings.IMAGINARY))throw new G.exceptions.NerdamerValueError(e.toString()+" does not equal "+t.toString());this.LHS=e,this.RHS=t}G.Settings.SOLVE_RADIUS=1e3,G.Settings.ROOTS_PER_SIDE=10,G.Settings.make_pi_conversions=!1,G.Settings.STEP_SIZE=.1,G.Settings.EPSILON=1e-13,G.Settings.MAX_NEWTON_ITERATIONS=200,G.Settings.MAX_NON_LINEAR_TRIES=12,G.Settings.NON_LINEAR_JUMP_AT=50,G.Settings.NON_LINEAR_JUMP_SIZE=100,G.Settings.NON_LINEAR_START=.01,G.Settings.NEWTON_SLICES=200,G.Settings.NEWTON_EPSILON=2*Number.EPSILON,G.Settings.SOLUTION_PROXIMITY=1e-14,G.Settings.FILTER_SOLUTIONS=!0,G.Settings.MAX_SOLVE_DEPTH=10,G.Settings.ZERO_EPSILON=1e-9,G.Settings.MAX_BISECTION_ITER=2e3,G.Settings.BI_SECTION_EPSILON=1e-12,G.Symbol.prototype.hasTrig=function(){return this.containsFunction(["cos","sin","tan","cot","csc","sec"])},G.Symbol.prototype.hasNegativeTerms=function(){if(this.isComposite())for(var e in this.symbols){var t=this.symbols[e];if(t.group===W&&t.hasNegativeTerms()||this.symbols[e].power.lessThan(0))return!0}return!1},re.prototype={toString:function(){return this.LHS.toString()+"="+this.RHS.toString()},text:function(e){return this.LHS.text(e)+"="+this.RHS.text(e)},toLHS:function(e){var t=(n=(e=void 0===e)?this.removeDenom():this.clone()).LHS,n=n.RHS;t.isConstant(!0)&&!n.isConstant(!0)&&([t,n]=[n,t]);n=V.subtract(t,n);return e?V.expand(n):n},removeDenom:function(){var e=this.LHS.clone(),t=this.RHS.clone(),n=V.multiply(e.getDenom(),t.getDenom());if(e=V.expand(V.multiply(e,n.clone())),(t=V.expand(V.multiply(t,n))).group===K&&t.group!==K&&(r=e,e=t,t=r),e.group===J){var r=new z(e.multiplier),i=t.clone();e.each(function(e){e.power.lessThan(0)?i=V.divide(i,e):r=V.multiply(r,e)}),e=r,t=i}else if(e.group===K)for(var s in e.symbols){var o=e.symbols[s];if(o.group===J)for(var a in o.symbols){a=o.symbols[a];if(a.power.lessThan(0))return new re(V.expand(V.multiply(a.clone().toLinear(),e)),V.expand(V.multiply(a.clone().toLinear(),t)))}}return new re(e,t)},clone:function(){return new re(this.LHS.clone(),this.RHS.clone())},sub:function(e,t){var n=this.clone();return n.LHS=n.LHS.sub(e.clone(),t.clone()),n.RHS=n.RHS.sub(e.clone(),t.clone()),n},isZero:function(){return G.Utils.evaluate(this.toLHS()).equals(0)},latex:function(e){return[this.LHS.latex(e),this.RHS.latex(e)].join("=")}},V.equals=function(e,t){return new re(e,t)},t=V.functions.simplify[0],V.functions.simplify[0]=function(e){return e instanceof re?(e.LHS=t(e.LHS),e.RHS=t(e.RHS),e):t(e)},G.Expression.prototype.equals=function(e){return e instanceof G.Expression&&(e=e.symbol),new re(this.symbol,e)},G.Expression.prototype.solveFor=function(e){var t;if(this.symbol instanceof re){if(this.symbol.LHS.isConstant()&&this.symbol.RHS.equals(e))return new G.Expression(this.symbol.LHS);if(this.symbol.RHS.isConstant()&&this.symbol.LHS.equals(e))return new G.Expression(this.symbol.RHS);t=this.symbol.toLHS()}else t=this.symbol;return oe(t,e).map(function(e){return new G.Expression(e)})},G.Expression.prototype.expand=function(){if(this.symbol instanceof re){var e=this.symbol.clone();return e.RHS=V.expand(e.RHS),e.LHS=V.expand(e.LHS),new G.Expression(e)}return new G.Expression(V.expand(this.symbol))},G.Expression.prototype.variables=function(){return this.symbol instanceof re?G.Utils.arrayUnique(l(this.symbol.LHS).concat(l(this.symbol.RHS))):l(this.symbol)};function e(e,t){return V.equals(e,t)}G.Equation=re;var ie=G.Utils.checkAll=function(e,t){for(var n=0;nr[1][2]&&([p,c]=[c,p],[r[1],r[0]]=[r[0],r[1]]),1===r[0][0]&&2===r[0][2]&&2===r[1][0]&&4===r[1][2]&&(u=t[0],l=t[1],t=oe(V.parse(p,f(u,oe(V.parse(c),u)[0])),l).map(function(e){return e.toString()}),p=[oe(V.parse(c,f(l,t[0])))[0].toString()],t[1]&&p.push(oe(V.parse(c,f(l,t[1])))[0].toString()),te.SOLUTIONS_AS_OBJECT?((i={})[u]=p,i[l]=t):(t.unshift(l),p.unshift(u),i=[p,t])),i},solveNonLinearSystem:function(e,t,r){if(t<0)return[];r=void 0===r?G.Settings.NON_LINEAR_START:r;var i=G.Settings.MAX_NON_LINEAR_TRIES,s=Math.floor(i/2);t=void 0===t?i:t;var o,a,u,l,c,p=G.Settings.NON_LINEAR_JUMP_AT,f=G.Settings.NON_LINEAR_JUMP_SIZE,h=!0,m=G.Utils.arrayGetVariables(e),i=G.Matrix.jacobian(e,m,function(e){return $(e,m)},!0),g=G.Settings.MAX_NEWTON_ITERATIONS,d=e.map(function(e){return $(e,m)}),v=i.map(function(e){return $(e,m)},!0),w=G.Matrix.cMatrix(0,m),y=G.Matrix.cMatrix(r,m),b=0;do{if(g=Number.EPSILON);return h?se.systemSolutions(y,m,!0,function(e){return G.Utils.round(Number(e),14)}):[]},systemSolutions:function(e,r,i,s){var o=G.Settings.SOLUTIONS_AS_OBJECT?{}:[];return e.each(function(e,t){var n=(i?V.expand(e):e).valueOf();s&&(n=s.call(e,n));t=r[t];G.Settings.SOLUTIONS_AS_OBJECT?o[t]=n:o.push([t,n])}),o},solveSystemBySubstitution:function(e){var t=l(e[0]),n=l(e[1]);return 2===e.length&&2===t.length&&G.Utils.arrayEqual(t,n)?se.solveCircle(e,t):[]},solveSystem:function(e,t){for(var n=0;nt||(i!==c&&s.push(n),c=i);u=u.concat(s)};return t(e,r),t(n,i),u},bisection:function(e,t){var n=e-1,r=e+1;if(Math.sign(t(n))!==Math.sign(t(r))){var i,s,o=0;do{if(i=Math.abs(r-n),o++>G.Settings.MAX_BISECTION_ITER||isNaN(i))return}while(s=(n+r)/2,0=te.EPSILON);var a=(n+r)/2,e=t(a);if(!isNaN(e)&&Math.abs(e)<=G.Settings.BI_SECTION_EPSILON)return G.Utils.round(a,13)}},Newton:function(e,t,n){var r=G.Settings.MAX_NEWTON_ITERATIONS,i=0,s=e;do{var o=t(s);if(0===s&&0===o){a=0;break}if(r<++i)return;var a=s-o/n(s),o=Math.abs(a-s),s=a}while(o>te.NEWTON_EPSILON);if(Math.abs(t(a))<=te.EPSILON)return a},rewrite:function(e,t,n){var r,i;t=t||new z(0),e.isComposite()&&e.isLinear()?(r=[],i=[],e.each(function(e){("sqrt"===(e=e.clone()).fname&&e.contains(n)?r:i).push(e)},!0),1===r.length&&(t=V.expand(V.pow(V.subtract(t,G.Utils.arraySum(i)),new z(2))),e=V.expand(V.pow(z.unwrapSQRT(r[0]),new z(2))))):e=z.unwrapSQRT(V.expand(e));var s=0,o=e.length;if(e.group===K&&e.contains(n)&&e.isLinear()){e.distributeMultiplier();var a=new z(0);return e.each(function(e){e.contains(n)?(s++,a=V.add(a,e.clone())):t=V.subtract(t,e.clone())}),e=a,s!==o?se.rewrite(e,t,n):[e,t]}if(e.group===J&&e.contains(n)&&e.isLinear()){if(e.multiplier.lessThan(0)&&(e.multiplier=e.multiplier.multiply(new G.Frac(-1)),t.multiplier=t.multiplier.multiply(new G.Frac(-1))),t.equals(0))return new z(0);a=new z(1);return e.each(function(e){e.contains(n)?a=V.multiply(a,e.clone()):t=V.divide(t,e.clone())}),se.rewrite(e=a,t,n)}if(!e.isLinear()&&e.contains(n)){o=V.parse(e.power.clone().invert());return e=V.pow(e,o.clone()),t=V.pow(V.expand(t),o.clone()),se.rewrite(e,t,n)}if(e.group===ee||e.group===Y||e.group===W)return[e,t]},sqrtSolve:function(n,r){var t=new z(0),i=new z(0);if(n.isComposite()&&(n.each(function(e){"sqrt"===e.fname&&e.contains(r)?t=V.add(t,e.clone()):i=V.add(i,e.clone())}),!t.equals(0))){var e=V.expand(V.multiply(V.parse(n.multiplier),V.subtract(V.pow(i,new z(2)),V.pow(t,new z(2)))));return oe(e,r).filter(function(e){if(e.isImaginary())return e;var t={};return t[r]=e,X(n,t).equals(0)?e:void 0})}}},oe=function(n,p,i,t,e){if(t=t||0,t++>te.MAX_SOLVE_DEPTH)return i;if(n instanceof re){if(n.isZero())return[new z(0)];if(n.LHS.equals(p)&&!n.RHS.contains(p))return[n.RHS];if(n.RHS.equals(p)&&!n.LHS.contains(p))return[n.LHS]}if(n instanceof G.Vector&&(n=n.elements),p=p||"x",ne(n))return se.solveSystem.apply(void 0,arguments);i=i||[];var s={},r={};if(r[p]=0,Q(n)&&!0===X(n.getDenom(),r).equals(0))return i;var o=function(e,t){var n,r=Q(e);void 0===e||"number"==typeof e&&isNaN(e)||(ne(e)?e.forEach(function(e){o(e)}):"null"!==e.valueOf()&&("function"==typeof G.Settings.PRE_ADD_SOLUTION&&(e=G.Settings.PRE_ADD_SOLUTION(e)),r||(e=V.parse(e)),G.Settings.make_pi_conversions&&t&&(r=(n=V.divide(e.clone(),new z(Math.PI))).multiplier,t=Math.abs(r.num),r=Math.abs(r.den),t<10&&r<10&&(e=V.multiply(n,new z("pi")))),n=e.toString(),s[n]||i.push(e),s[n]=!0))};if(n.group===Y&&n.contains(p)){try{var a={};a[p]=0,X(e,a,"numer"),o(new z(0))}catch(e){}return i}if(n.group===J){var u=n.getNum();if(u.group!==J)return oe(u,p,i,t,e);var l=String(p);return u.each(function(e){e.contains(l)&&oe(e,p,i,t,n)}),i}n.group===ee&&"sqrt"===n.fname&&(n=V.pow(z.unwrapSQRT(n),new z(2)));var c=(G.Utils.isSymbol(n)?n:se.toLHS(n,!1)).getNum(),r=G.Utils.variables(c),a=r.length;if((c=G.Utils.isInt(c.power)&&0