diff --git a/src/js/Abacus.js b/src/js/Abacus.js index 23202a3..1e919f9 100644 --- a/src/js/Abacus.js +++ b/src/js/Abacus.js @@ -4218,10 +4218,23 @@ function factorial( n, m ) { // recursive and memoized // binomial = C(n,m) = C(n-1,m-1)+C(n-1,m) = n!/m!(n-m)! - res = Arithmetic.isDefault() ? stdMath.round(operate(function(Cnm,i){ - // this is faster and will not overflow unnecesarily for default arithmetic - return Cnm*(1+n/i); - }, (n=n-m)+1, null, 2, m)) : add(factorial(sub(n, I), sub(m, I)), factorial(sub(n, I), m))/*div(factorial(n,-m), factorial(m))*/; + if ( Arithmetic.lte(n, 10) ) + { + res = add(factorial(sub(n, I), sub(m, I)), factorial(sub(n, I), m));/*div(factorial(n,-m), factorial(m))*/ + } + else if ( Arithmetic.isDefault() ) + { + res = stdMath.round(operate(function(Cnm,i){ + // this is faster and will not overflow unnecesarily for default arithmetic + return Cnm*(1+n/i); + }, (n=n-m)+1, null, 2, m)); + } + else + { + i = add(sub(n, m), I); res = i; + while( Arithmetic.lt(i, n) ) { i = add(i, I); res = mul(res, i); } + res = div(res, factorial(m)); + } // memoize only up to MAXMEM results if ( Arithmetic.lt(n, MAXMEM) ) factorial.mem3[key] = res; diff --git a/src/js/Abacus.min.js b/src/js/Abacus.min.js index fa81631..56ac3db 100644 --- a/src/js/Abacus.min.js +++ b/src/js/Abacus.min.js @@ -5,4 +5,4 @@ * @version: 1.0.0 * https://github.com/foo123/Abacus **/ -!function(t,n,e){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(t.$deps=t.$deps||{})&&(t.EXPORTED_SYMBOLS=[n])&&(t[n]=t.$deps[n]=e.call(t)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=e.call(t)):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return e.moduleUri=n.uri,e.call(t)}):n in t||(t[n]=e.call(t)||1)&&"function"==typeof define&&define.amd&&define(function(){return t[n]})}("undefined"!=typeof self?self:this,"Abacus",function(){"use strict";function m(){return Object.create(null)}function r(){var n,t,e,r,i=arguments,u=i.length;for(n=(u?i[0]:{})||{},e=1;ee[h]||-1===r&&fe[h]||-1===r&&t[f]e[g][0]?(n[_++]=v=t[d],d+=a):(1===r&&t[d][0]>e[g][0]||-1===r&&t[d][0]e[g][1]?(n[_++]=v=t[d],b&&(n[_++]=e[g])):(n[_++]=v=e[g],b&&(n[_++]=t[d])),d+=a),g+=f):1===r&&t[d]e[g]?(n[_++]=v=t[d],d+=a):(1===r&&t[d]>e[g]||-1===r&&t[d]>=1;return i?En(e,e,1):e}function Gn(n,t,e,r){var i,u,l,s=n.length;if(null==e&&(e=0),null==r&&(r=s-1),null==t||0===t){for(t=0,u=n[e],i=e+1;i<=r;i++){if(u<(l=n[i])){if(-1===t)return 0;0===t&&(t=1)}else if(l>>1],t)?r=l+1:i=l;else for(;r>>1])?i=l:r=l+1;return r}function Bn(e){return!0===e?function(n,t){return n.equ(t)?0:n.lt(t)?-1:1}:e?function(n,t){return e.equ(n,t)?0:e.lt(n,t)?-1:1}:function(n,t){return n===t?0:n>=1,n=rt(n,n,e);else for(r=u.II;!u.equ(t,l);)u.equ(s,u.mod(t,r))&&(i=rt(i,n,e)),t=u.div(t,r),n=rt(n,n,e);return i}function lt(n,t){var e,r,i=U.Arithmetic,u=i.O,l=i.I;i.num;if(i.gt(u,t))return null;if(i.equ(u,t))return l;if(i.equ(l,t))return n;if(r=l,i.isDefault()||i.lte(t,un))for(t=i.val(t);0!==t;)1&t&&(r=i.mul(r,n)),t>>=1,n=i.mul(n,n);else for(e=i.II;!i.equ(u,t);)i.equ(l,i.mod(t,e))&&(r=i.mul(r,n)),t=i.div(t,e),n=i.mul(n,n);return r}function st(n){var t,e,r,i,u,l,s=U.Arithmetic,o=(s.num,s.O),c=s.I;if(s.equ(n,o)||s.equ(n,c))return n;if(s.isDefault()||s.lte(n,un))return s.num(Q.floor(Q.sqrt(s.val(n))));for(l=s.II,t=c,e=s.div(n,l),u=t;s.lte(t,e);){if(r=s.div(s.add(t,e),l),i=s.mul(r,r),s.equ(i,n))return r;s.lt(i,n)?(t=s.add(r,c),u=r):e=s.sub(r,c)}return u}function ot(n,t){var e,r,i;return 0===(t=+t)?null:(t<0&&(n=1/n,t=-t),1===t?n:(1==(e=1&t)&&n<0&&(n=-n),r=Q.pow(n,1/t),i=Q.pow(r,t),Q.abs(n-i)<1&&0c&&(d++,u.terms.length>=e||e<=d))););return 0===d&&t.mod(h).equ(a)?u.abs():u}function at(n,t){var e,r,i,u,l=U.Arithmetic,s=l.O,o=l.I,c=l.II,m=b.Epsilon();if(t.equ(s))return null;if(Cn(n,f)&&(n.equ(s)||n.equ(o))||l.isNumber(n)&&(l.equ(s,n)||l.equ(o,n)))return n;if(n=(e=l.isNumber(n)||Cn(n,q)?b:n[X]).cast(n),Sn(e,b)&&n.lt(s)&&t.mod(c).equ(s)&&(n=(e=v).cast(n)),t.lt(s)&&(n=n.inv(),t=t.neg()),t.equ(o))return n;if(r=Sn(e,R)?new e(mt(n.num,t),mt(n.den,t)):Sn(e,b)?new e(ct(n.num,t.num),ct(n.den,t.num)):Sn(e,v)?!n.isReal()||!n.real().gte(s)&&t.mod(c).equ(s)?new e(o,o):new e(b(ct(n.real().num,t.num),ct(n.real().den,t.num)),b.Zero()):e.One(),u=t.sub(o),Sn(e,v))for(;;){if((i=n.div(r.pow(u)).sub(r).div(t)).real().abs().lte(m)&&i.imag().abs().lte(m))break;r=r.add(i)}else for(;;){if((i=n.div(r.pow(u)).sub(r).div(t)).abs().lte(m))break;r=r.add(i)}return r}function ft(n,t,e){var r,i,u,l,s,o,c=U.Arithmetic,m=c.num,a=c.O,f=c.J,h=c.I,d=c.II;if(c.lt(t,a)||c.equ(a,c.mod(t,d)))return null;if((c.lt(n,a)||c.gt(n,t))&&(n=c.mod(n,t)),c.equ(a,n))return c.equ(h,t)?h:a;if(c.equ(h,t)||c.equ(h,n))return h;if(null==e&&(e=St(n,t)),!c.equ(h,e))return a;for(u=m(3),l=m(4),s=m(5),o=m(8),r=h,c.lt(n,a)&&(n=c.mul(f,n),c.equ(c.mod(t,l),u)&&(r=c.mul(f,r)));!c.equ(a,n);){for(;c.gt(n,a)&&c.equ(a,c.mod(n,d));)n=c.div(n,d),i=c.mod(t,o),(c.equ(i,u)||c.equ(i,s))&&(r=c.mul(f,r));i=n,n=t,t=i,c.equ(u,c.mod(n,l))&&c.equ(u,c.mod(t,l))&&(r=c.mul(f,r)),n=c.mod(n,t)}return c.equ(h,t)||(r=a),r}function ht(n,t){var e=U.Arithmetic,r=(e.num,e.I),i=e.II;return ut(n,e.div(e.sub(t,r),i),t)}function dt(n,t){var e,r,i,u,l,s,o,c,m,a,f,h,d,g=U.Arithmetic,_=(g.num,g.O),v=g.I;if(!g.equ(v,ht(n,t)))return null;for(e=g.II,i=r=g.sub(t,v),u=0;g.equ(_,g.mod(i,e));)i=g.div(i,e),u+=1;if(1===u)return ut(n,g.div(g.add(t,v),4),t);for(l=_;g.lt(l,t)&&!g.equ(r,ht(l,t));l=g.add(l,v));for(s=ut(l,i,t),o=ut(n,g.div(g.add(i,v),e),t),m=ut(n,i,t),a=u,f=_;!g.equ(_,g.mod(g.sub(m,v),t));){for(f=rt(m,m,t),d=1;do&&(e.length=o),e}(It(t),It(r.div(n,t)))),i?e.map(function(n){return[new i(n[0]),new i(n[1])]}):e}function Ot(n,t){return n===t}function wt(n,t,e){var r,i,u,l;for(e=e||Ot,r=n(t),i=n(r);!e(r,i);)r=n(r),i=n(n(i));for(u=0,r=t;!e(r,i);)r=n(r),i=n(i),u++;for(l=1,i=n(r);!e(r,i);)i=n(i),l++;return[l,u]}function St(){var n,t,e,r,i=arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments,u=i.length,l=U.Arithmetic,s=(l.num,l.O),o=l.I;if(0===u)return s;for(r=0;r(n=_.cast(n)).length&&(n=n.concat(Dn(i-n.length,function(n){return v}))),s=(l=t.t().concat(M.I(_,u)).ref(!0,[u,i]))[0],o=l[1].length,m=s.slice(0,i,-1,-1).t(),c=s.slice(0,0,u-1,i-1).t(),d=new Array(u),g=new Array(u-o),a=0;a>>1;return i.mul(n(t,e,u),n(t,1+u,r))}(l,0,l.length-1)},n=function n(t,e){if(a.lt(t,d))return h;var r=n(a.div(t,d),e);return a.mul(a.mul(r,r),i(t,e))},a.lt(t,d)?h:(e=a.sub(t,a.digits(t,2).split("").reduce(function(n,t){return a.add(n,"1"===t?h:f)},f)),r=(u=T()).get(function(n){return a.lte(n,t)}),u.dispose(),a.mul(n(t,r),Xt(e)))}function Wt(e,n){var t,r,i=U.Arithmetic,u=i.O,l=i.I,s=i.J,o=i.II,c=i.num,m=i.val,a=i.add,f=i.sub,h=i.div,d=i.mul,g=i.mod,_=u,v=U.Options.MAXMEM;if(Cn(e,q))return new e[X](Wt(e.num,n));if(e=c(e),null==n){if(i.lte(e,12))return i.lt(e,u)?u:c([1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600][m(e)]);if(i.gte(e,100))return zt(e);t=String(e),null==Wt.mem1[t]?(_=d(Wt(f(e,l)),e),i.lt(e,v)&&(Wt.mem1[t]=_)):_=Wt.mem1[t]}else if(!1===n){if(i.lte(e,12))return i.lt(e,o)?u:c([1,2,9,44,265,1854,14833,133496,1334961,14684570,176214841][m(f(e,o))]);t="!"+String(e),null==Wt.mem2[t]?(_=a(i.equ(u,g(e,o))?l:s,d(Wt(f(e,l),!1),e)),i.lt(e,v)&&(Wt.mem2[t]=_)):_=Wt.mem2[t]}else if(!0===n){if(i.lte(e,18))return i.lt(e,u)?u:c([1,1,2,4,10,26,76,232,764,2620,9496,35696,140152,568504,2390480,10349536,46206736,211799312,997313824][m(e)]);t="I"+String(e),null==Wt.mem2[t]?(_=a(Wt(f(e,l),!0),d(Wt(f(e,o),!0),f(e,l))),i.lt(e,v)&&(Wt.mem2[t]=_)):_=Wt.mem2[t]}else if(xn(n)){if(!n.length)return i.lt(e,u)?u:Wt(e);if(i.lt(e,u))return u;t=String(e)+"@"+Xn(n.map(String),1,!0).join(","),null==Wt.mem3[t]?(_=h(Wt(e),Mn(function(n,t){return d(n,Wt(t))},Wt(n[n.length-1]),n,n.length-2,0)),i.lt(e,v)&&(Wt.mem3[t]=_)):_=Wt.mem3[t]}else if(i.isNumber(n)||Cn(n,q))if(n=Cn(n,q)?n.num:c(n),i.lt(n,u)){if(i.lte(e,i.neg(n)))return i.equ(e,i.neg(n))?Wt(e):u;if(t=String(e)+"@"+String(n),null==Wt.mem3[t]){for(_=r=a(a(e,n),l);i.lt(r,e);)r=a(r,l),_=d(_,r);i.lt(e,v)&&(Wt.mem3[t]=_)}else _=Wt.mem3[t]}else{if(i.lt(n,u)||i.lt(e,l)||i.gt(n,e))return u;if(i.lt(e,d(n,o))&&(n=f(e,n)),i.equ(n,u)||i.equ(e,l))return l;if(i.equ(n,l))return e;t=String(e)+"@"+String(n),null==Wt.mem3[t]?(_=i.isDefault()?Q.round(Mn(function(n,t){return n*(1+e/t)},1+(e-=n),null,2,n)):a(Wt(f(e,l),f(n,l)),Wt(f(e,l),n)),i.lt(e,v)&&(Wt.mem3[t]=_)):_=Wt.mem3[t]}return _}function Vt(n,t,e){var r,i=U.Arithmetic,u=i.O,l=i.I,s=i.add,o=i.sub,c=i.mul,m=u,a=U.Options.MAXMEM;if(Cn(n,q))return new n[X](Vt(n.num,Cn(t,q)?t.num:t,e));if(Cn(t,q)&&(t=t.num),n=i.num(n),t=i.num(t),e=+e,i.lt(n,u)||i.lt(t,u))return u;if(2===e){if(i.equ(n,t)||i.equ(t,l)&&i.lt(n,u))return l;if(i.equ(n,u)||i.equ(t,u))return u;r=String(n)+","+String(t),null==Vt.mem2[r]?(m=s(Vt(o(n,l),o(t,l),2),c(Vt(o(n,l),t,2),t)),i.lt(n,a)&&(Vt.mem2[r]=m)):m=Vt.mem2[r]}else if(-1===e){if(i.gt(t,n)||i.equ(t,u)&&i.lt(n,u))return u;if(i.equ(n,t))return l;r=String(n)+","+String(t)+"-",null==Vt.mem1[r]?(m=s(Vt(o(n,l),o(t,l),-1),c(Vt(o(n,l),t,-1),o(l,n))),i.lt(n,a)&&(Vt.mem1[r]=m)):m=Vt.mem1[r]}else{if(i.gt(t,n)||i.equ(t,u)&&i.lt(n,u))return u;if(i.equ(n,t))return l;if(i.equ(t,l))return Wt(o(n,l));m=i.equ(u,i.mod(o(n,t),i.II))?Vt(n,t,-1):i.neg(Vt(n,t,-1))}return m}function Bt(n,t,e,r){var i,u,l,s,o=U.Arithmetic,c=o.O,m=o.I,a=o.II,f=o.add,h=o.sub,d=o.mul,g=c;if(o.lt(n,c)||o.lte(t,c)||o.gt(e,r)||o.gt(f(e,t),f(n,m))||o.lt(d(t,r),n))return g;if(o.equ(r,n)&&o.equ(t,m)||o.equ(t,n)&&o.equ(r,m))return m;if(i=String(n)+","+String(t)+","+String(e)+","+String(r),null==Bt.mem[i]){if(n=h(n,d(t,h(e,m))),r=f(h(r,e),m),u=String(n)+","+String(t)+","+String(e)+","+String(r),null==Bt.mem[u]){for(l=o.max(m,o.divceil(h(n,r),h(t,m))),s=o.min(r,f(h(h(n,r),t),a));o.lte(l,s);)g=f(g,Bt(h(n,r),h(t,m),m,l)),l=f(l,m);Bt.mem[u]=g}Bt.mem[i]=Bt.mem[u]}return Bt.mem[i]}function Ht(n,t,e){if(Cn(n,q))return new n[X](Ht(n.num,t,e));var r,i,u,l,s,o,c,m=U.Arithmetic,a=m.num,f=m.O,h=m.I,d=m.add,g=m.sub,_=m.mul,v=f;if(Cn(t,q)&&(t=t.num),Cn(e,q)&&(e=e.num),t=null==t?null:m.abs(a(t)),e=null==e?null:m.abs(a(e)),n=a(n),r=null!=e?e:f,i=null!=e?e:h,u=null!=t?t:h,l=null!=t?t:n,m.lt(n,f)||null!=t&&null!=e&&(m.gt(d(t,e),d(n,h))||m.lt(_(t,e),n))||null!=e&&m.gt(e,n)||null!=t&&m.gt(t,n))return v;if(null!=e&&null==t&&(r=f,i=h,t=l=u=e,e=null),c=String(n)+"|"+String(t)+"|"+String(e),null==Ht.mem[c]){for(s=u;m.lte(s,l);){for(r=m.equ(f,r)?d(g(n,s),h):r,o=i;m.lte(o,r);)v=d(v,Bt(n,s,h,o)),o=d(o,h);s=d(s,h)}Ht.mem[c]=v}return Ht.mem[c]}function Kt(n,t,e,r){var i,u,l,s=U.Arithmetic,o=s.add,c=s.sub,m=s.mul,a=s.O,f=s.I,h=a;if(s.lt(n,a)||s.lte(t,a)||s.gt(e,r)||s.gt(m(e,t),n)||s.lt(m(t,r),n))return h;if(s.equ(t,f))return s.lte(e,n)&&s.lte(n,r)?f:h;if(s.equ(n,t))return s.lte(e,f)&&s.lte(f,r)?f:h;if(s.equ(e,r))return s.equ(m(t,e),n)?f:h;if(s.equ(n,r))return Wt(o(c(n,m(t,e)),c(t,f)),c(t,f));if(s.equ(o(e,f),r))return Wt(t,c(n,m(t,e)));if(l=String(n)+","+String(t)+","+String(e)+","+String(r),null==Kt.mem[l]){for(u=c(n,e),i=s.max(a,c(n,r)),t=c(t,f);s.lte(i,u);)h=o(h,Kt(i,t,e,r)),i=o(i,f);Kt.mem[l]=h}return Kt.mem[l]}function Yt(n,t,e){if(Cn(n,q))return new n[X](Yt(n.num,t,e));var r,i,u,l,s,o,c=U.Arithmetic,m=c.num,a=c.O,f=c.I,h=c.add,d=c.sub,g=c.mul,_=(c.div,c.mod),v=a;if(Cn(t,q)&&(t=t.num),Cn(e,q)&&(e=e.num),t=null==t?null:c.abs(m(t)),e=null==e?null:c.abs(m(e)),n=m(n),c.lt(n,a)||null!=t&&null!=e&&(c.gt(h(t,e),h(n,f))||c.lt(g(t,e),n))||null!=e&&c.gt(e,n)||null!=t&&c.gt(t,n))return v;if(o=String(n)+"|"+String(t)+"|"+String(e),null==Yt.mem[o]){if(null!=t&&null!=e)if(c.equ(g(t,e),n))v=f;else for(u=d(s=e,r=f);c.lte(s,n);)l=Kt(d(n,s),d(t,r),f,u),c.equ(a,l)||(v=h(v,g(l,Wt(t,r)))),s=h(s,e),r=h(r,f);else if(null!=t)v=Kt(n,t,f,n);else if(null!=e)if(c.equ(e,n))v=f;else for(c.equ(a,_(n,e))&&(v=f),u=d(s=e,r=f);c.lte(s,n);){for(i=f,t=d(n,r);c.lte(i,t);)l=Kt(d(n,s),i,f,u),c.equ(a,l)||(v=h(v,g(l,Wt(h(i,r),r)))),i=h(i,f);s=h(s,e),r=h(r,f)}else v=c.gte(n,f)?Xt(d(n,f)):f;Yt.mem[o]=v}return Yt.mem[o]}function ne(n){var t,e=U.Arithmetic,r=e.O,i=e.I,u=e.II,l=e.num,s=e.val,o=e.add,c=e.sub,m=e.div,a=e.mul,f=r,h=U.Options.MAXMEM;return Cn(n,q)?new n[X](ne(n.num)):(n=l(n),e.lte(n,17)?e.lt(n,r)?r:l([1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790][s(n)]):(t=String(n),null==ne.mem[t]?e.lt(n,h)?(f=m(a(ne(c(n,i)),c(a(n,4),u)),o(n,i)),ne.mem[t]=f):f=m(Wt(a(n,u),n),o(n,i)):f=ne.mem[t],f))}function te(n){var t,e,r=U.Arithmetic,i=r.O,u=r.I,l=r.num,s=r.val,o=r.add,c=r.sub,m=r.mul,a=i,f=U.Options.MAXMEM;if(Cn(n,q))return new n[X](te(n.num));if(n=l(n),r.lte(n,14))return r.lt(n,i)?i:l([1,1,2,5,15,52,203,877,4140,21147,115975,678570,4213597,27644437,190899322][s(n)]);if(t=String(n),null==te.mem[t]){for(e=a=i,n=c(n,u);r.lte(e,n);)a=o(a,m(Wt(n,e),te(e))),e=o(e,u);r.lt(n,f)&&(te.mem[t]=a)}else a=te.mem[t];return a}function ee(n){var t,e,r,i,u=U.Arithmetic,l=u.O,s=u.I,o=u.II,c=u.num,m=u.val,a=l,f=U.Options.MAXMEM;return Cn(n,q)?new n[X](ee(n.num)):(n=c(n),u.lte(n,36)?u.lt(n,l)?l:c([0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352][m(n)]):(i=String(n),null==ee.mem[i]?(t=u.div(n,o),e=ee(u.add(t,s)),r=ee(t),a=u.equ(l,u.mod(n,o))?u.mul(r,u.sub(u.mul(e,u.II),r)):u.add(u.mul(e,e),u.mul(r,r)),u.lt(n,f)&&(ee.mem[i]=a)):a=ee.mem[i],a))}function re(){var n,t,e,r,i,u,l,s,o,c,m,a=arguments,f=a.length;if(!f)return[];if(!0===a[0]){for(c=a[1].length,n=2;n_&&(v.length=_),v}function ue(n,t,e,r,i){r=!0===r,e=e===A?A:x,i=i||Z.Q();for(var u,l=0,s=0,o=0,c=n.length,m=t.length,a=new Array(c+m),f=U.Arithmetic.O;lo&&(a.length=o),a}function le(t,e,r,i){r=r===A?A:x,i=i||Z.Q();var n,u,l,s,o,c,m,a,f=U.Arithmetic.O;if(t.length>e.length&&(u=t,t=e,e=u),l=t.length,s=e.length,o=new Array(l*s),0n+1&&(o.length=n+1)}return o}function se(n,t,e,r,i){r=!0===r,e=e===A?A:x,i=i||Z.Q();var u,l,s,o,c=n.length,m=t.length,a=U.Arithmetic.O,f=_([],"max",function(n,t){return e.cmp(n.term,t.term)}),h=[],d=[],g=0;if(!t.length)return null;for(o=t[0].cast(i);(u=f.peek())||gu.n?f.replace({term:u.Q.mul(t[u.n].cast(i)),n:u.n+1,Q:u.Q}):f.pop(),g++):(l=u.term.neg(),m>u.n?f.replace({term:u.Q.mul(t[u.n].cast(i)),n:u.n+1,Q:u.Q}):f.pop()),l.equ(a)||(o.divides(l)?(h=ue(h,[s=l.div(o)],e,!1,i),1>>1<<1]),s[r]+=1,r>>>=1;return s[r]+=1,n[e]=t,n},n||new Array(r),t)}function ve(n,t,e){var r,i,u,l=t.length,s=Q.ceil(V(e||l)),o=1<=c[r<<=1]&&(t-=c[r],r++);return c[r]=0,n[e]=r-o,n},n||new Array(l),t)}function be(n,t,e){var r,i=n.length,u=null==t;if(1>t},bor:function(n,t){return n|t},band:function(n,t){return n&t},xor:function(n,t){return n^t},abs:Q.abs,min:Q.min,max:Q.max,rnd:Ae},U.Arithmetic=r({},t,{isDefault:function(){return 0===this.O&&this.add===Kn},neg:function(n){return U.Arithmetic.mul(U.Arithmetic.J,n)},abs:function(n){return U.Arithmetic.gt(U.Arithmetic.O,n)?U.Arithmetic.neg(n):n},min:function(n,t){return U.Arithmetic.lt(n,t)?n:t},max:function(n,t){return U.Arithmetic.gt(n,t)?n:t},divceil:function(n,t){if(null==t)return n;var e,r=U.Arithmetic,i=r.O,u=r.I;return e=r.div(n,t),r.equ(i,r.mod(n,t))?e:r.gt(n,i)===r.gt(t,i)?r.add(e,u):e}}),U.Math={rnd:Q.random,rndInt:Ae,factorial:Wt,stirling:Vt,partitions:Ht,compositions:Yt,bell:te,catalan:ne,fibonacci:ee,polygonal:function n(t,e){var r=U.Arithmetic,i=(r.O,r.I,r.II),u=r.num;return Cn(e,q)&&(e=e.num),e=u(e),r.lt(e,3)?null:Cn(t,q)?new t[X](n(t.num,e)):(t=u(t),r.div(r.mul(t,r.sub(r.mul(t,r.sub(e,i)),r.sub(e,4))),i))},sum:Yn,product:nt,pow2:Xt,exp:Gt,powsq:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](lt(n.num,t)):lt(e.num(n),t)},addm:function(n,t,e){var r=U.Arithmetic;return e=Cn(e,q)?e.num:r.num(e),t=Cn(t,q)?t.num:r.num(t),Cn(n,q)?new n[X](et(n.num,t,e)):et(r.num(n),t,e)},negm:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](tt(n.num,t)):tt(e.num(n),t)},mulm:function(n,t,e){var r=U.Arithmetic;return e=Cn(e,q)?e.num:r.num(e),t=Cn(t,q)?t.num:r.num(t),Cn(n,q)?new n[X](rt(n.num,t,e)):rt(r.num(n),t,e)},invm:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](it(n.num,t)):it(e.num(n),t)},powm:function(n,t,e){var r=U.Arithmetic;return e=Cn(e,q)?e.num:r.num(e),t=Cn(t,q)?t.num:r.num(t),Cn(n,q)?new n[X](ut(n.num,t,e)):ut(r.num(n),t,e)},isqrt:function(n){var t=U.Arithmetic;return Cn(n,q)?new n[X](st(n.num)):st(t.num(n))},ikthroot:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](ct(n.num,t)):ct(e.num(n),t)},isqrtp:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](dt(n.num,t)):dt(e.num(n),t)},ilog:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](gt(n.num,t)):gt(e.num(n),t)},divisors:function(n,t){var e=U.Arithmetic;return $t(Cn(n,q)?n:e.num(n),!0===t)},legendre:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](ht(n.num,t)):ht(e.num(n),t)},jacobi:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](ft(n.num,t)):ft(e.num(n),t)},moebius:function(n){var t=U.Arithmetic;return Cn(n,q)?new n[X](kt(n.num)):kt(t.num(n))},pollardRho:function(n,t,e,r,i,u){var l,s=U.Arithmetic.num;return null!=e&&(e=Cn(e,q)?e.num:s(e)),null!=t&&(t=Cn(t,q)?t.num:s(t)),Cn(n,q)?null==(l=qt(n.num,t,e,r,i||null,u||null))?l:new n[X](l):qt(s(n),t,e,r,i||null,u||null)},factorize:function(n){var t=U.Arithmetic;return It(Cn(n,q)?n:t.num(n))},isProbablePrime:function(n){var t=U.Arithmetic;return yt(Cn(n,q)?n.num:t.num(n))},isPrime:function(n){var t=U.Arithmetic;return At(Cn(n,q)?n.num:t.num(n))},nextPrime:function(n,t){var e=U.Arithmetic;return function(n,t){var e,r=U.Arithmetic,i=(r.num,r.O),u=r.I,l=r.II;if((t=-1===t?-1:1)<0){if(r.lte(n,l))return null;if(r.equ(n,3))return l;for(e=r.sub(n,r.equ(i,r.mod(n,l))?u:l);;e=r.sub(e,l))if(yt(e)&&At(e))return e}else{if(r.lt(n,l))return l;for(e=r.add(n,r.equ(i,r.mod(n,l))?u:l);;e=r.add(e,l))if(yt(e)&&At(e))return e}}(Cn(n,q)?n.num:e.num(n),-1===t?-1:1)},gcd:function(){var n,t=U.Arithmetic,e=G.call(arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),r=null;return n=St(e.map(function(n){return Cn(n,q)?(r=r||n[X],n.num):t.num(n)})),r?new r(n):n},xgcd:function(){var n,t=U.Arithmetic,e=G.call(arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),r=null;return n=Rt(e.map(function(n){return Cn(n,q)?(r=r||n[X],n.num):t.num(n)})),r&&n?n.map(function(n){return new r(n)}):n},lcm:function(){var n,t=U.Arithmetic,e=G.call(arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),r=null;return n=Nt(e.map(function(n){return Cn(n,q)?(r=r||n[X],n.num):t.num(n)})),r?new r(n):n},diophantine:function(n,t,e,r){var i=U.Arithmetic;return(xn(n)||An(n))&&n.length?Ut(i.nums(n),i.num(t||0),e,!0===r):null},diophantines:function(n,t,e,r){var i=Z.Z();return(Cn(n,M)||xn(n)||An(n))&&(!Cn(n,M)||n.nr&&n.nc)&&(Cn(n,M)||n.length)?(Cn(t,M)||xn(t)||An(t)||(t=Dn(Cn(n,M)?n.nr:n.length,function(){return t||0})),Qt(n,t=Cn(t,M)?t:i.cast(t),e,!0===r)):null},congruence:function(n,t,e,r,i){var u,l,s,o,c,m,a,f,h,d=U.Arithmetic;return(xn(n)||An(n))&&n.length?(u=d.nums(n),l=d.num(t||0),s=d.num(e||0),o=r,c=!0===i,f=U.Arithmetic,h=f.O,u.length?(c=!0===c,(m=Ut(u.concat(s),l,o,c))&&c&&(a=m[1],m=m[0]),null==(m=null==m?null:Dn(m.length-1,function(n){var t=m[n];return!1===o?f.gt(h,t)&&(t=f.add(t,s)):t.c().real().lt(h)&&(t=t.add(s)),t}))?null:c?[m,a]:m):null):null},congruences:function(n,t,e,r,i){var u,l,s,o,c,m,a,f,h,d,g,_,v=Z.Z();return(Cn(n,M)||xn(n)||An(n))&&(!Cn(n,M)||n.nr&&n.nc)&&(Cn(n,M)||n.length)?(n=Cn(n,M)?n:v.cast(n),Cn(t,M)||xn(t)||An(t)||(t=Dn(Cn(n,M)?n.nr:n.length,function(){return t||0})),t=Cn(t,M)?t:v.cast(t),Cn(e,M)||xn(e)||An(e)||(e=Dn(Cn(n,M)?n.nr:n.length,function(){return e||0})),e=Cn(e,M)?e:v.cast(e),u=n,l=t,s=e,o=r,c=!0===i,d=Z.Z(),g=U.Arithmetic,_=d.Zero(),Cn(u,M)&&Sn(u.ring.NumberClass,q)||(u=M(d,u)),u.nr&&u.nc?(xn(s)||An(s)||Cn(s,M)||(s=Dn(u.nr,function(n){return s})),(xn(s)||An(s))&&(s=M(d,s)),(xn(l)||An(l))&&(l=M(d,l)),f=s.col(0),a=d.lcm(f),u=u.concat(s),c=!0===c,null!=(m=Qt(u,l,o,!0))&&(h=m[1],m=m[0]),null==(m=null==m?null:Dn(m.length-1,function(n){var t,e,r=m[n],i=!0;if(!1===o)g.gt(g.O,r)&&(r=g.add(r,a.num));else{for(t in r.terms)if(z.call(r.terms,t)&&"1"!==t&&g.equ(g.O,g.mod(a.num,r.terms[t].c().real().num))){i=!1;break}i&&(e=h.symbol+"_"+(h.length+1),h.push(e),r=r.add(C(S(e),a))),r.c().real().lt(_)&&(r=r.add(a))}return r}))?null:c?[m,h]:m):null):null},pythagorean:function(n,t){var e=U.Arithmetic;return(xn(n)||An(n))&&n.length?function(t,n){var e,r,i,u,l,s,o,c,m,a,f,h=U.Arithmetic,d=h.O,g=h.I,_=h.J,v=h.II,b=t.length,p=In(n)&&n.length?n:"i";if(!b)return null;if(a=t.filter(function(n){return 1===Ft(n)}).length,f=t.filter(function(n){return-1===Ft(n)}).length,1===b||0===a||0===f)return Dn(b,function(){return N()});if(m=Dn(b,function(n){return st(h.abs(t[n]))}),b!==t.filter(function(n,t){return h.equ(h.abs(n),h.mul(m[t],m[t]))}).length)return Dn(b,function(){return N()});if(u=Dn(b-1,function(n){return p+"_"+(n+1)}),2===b)return[N(C(S(u[0]),m[1])),N(C(S(u[0]),m[0]))];for(Ft(t[0])+Ft(t[1])+Ft(t[2])<0&&(t=t.map(function(n){return h.neg(n)})),l=e=0;ll&&(u.length=l),u},intersection:function(n,t,e,r,i,u,l,s){r=-1===r?-1:1,null==i&&(i=0),null==u&&(u=t.length-1),null==l&&(l=0),null==s&&(s=e.length-1);var o=ue[h]?f+=o:(1===r&&t[f]>e[h]||-1===r&&t[f]r[f]?f+=c:(n[h++]=e[a],t[e[a]]--,a+=o);for(;0<=o*(u-a);)0>>1]))return s;l(o,n)?m=s-1:c=s+1}else for(;c>>1]))return s;l(n,o)?m=s-1:c=s+1}return-1},bisect:Vn,complementation:Pn,reflection:Tn,reversion:$n,gray:kn,finitedifference:Ln,partialsum:Jn,convolution:function(n,t,e){var r,i,u,l=n.length,s=t.length;if(!0===e)for(u=Dn(l+s-1,function(){return 0}),r=0;r>>5]&1<<(31&n))},set:function(n){return this.bits[n>>>5]|=1<<(31&n),this},unset:function(n){return this.bits[n>>>5]&=~(1<<(31&n)),this},toggle:function(n){return this.bits[n>>>5]^=1<<(31&n),this}}),p=U.Node=function n(t,e,r,i){var u=this;if(!Cn(u,n))return new n(t,e,r,i);u.v=t,u.l=e||null,u.r=r||null,u.t=i||null,u.dispose=function(){return u.v=null,u.l=null,u.r=null,u.t=null,u}},_=U.Heap=n({constructor:function n(t,e,r){var i=this;if(!Cn(i,n))return new n(t,e,r);e=String(e||"min").toLowerCase().slice(0,3),i.type="max"===e?"max":"min",wn(r)||(r=n.CMP),i.cmp=r,t=t||[],i._h=n.heapify(t,i.type,i.cmp)},__static__:{CMP:function(n,t){return n>>1)-1;0<=r;r--)_._siftup_max(n,r,e);else for(r=(i>>>1)-1;0<=r;r--)_._siftup(n,r,e);return n},_siftdown:function(n,t,e,r){for(var i,u,l=n[e];t>>1])<0;)n[e]=u,e=i;n[e]=l},_siftup:function(n,t,e){var r,i,u=n.length,l=t,s=n[t];for(r=2*t+1;r>>1],l)<0;)n[e]=u,e=i;n[e]=l},_siftup_max:function(n,t,e){var r,i,u=n.length,l=t,s=n[t];for(r=2*t+1;r=b.length&&v.slice(-b.length)===b;)v=v.slice(0,-b.length);v.length||(v=null)}i=f.sub(f.pow(c,(v?v.length:0)+b.length),v?f.pow(c,v.length):d),r=f.add(f.mul(i,e),f.sub(g((v||"")+b),v?g(v):h))}else{for(;v&&"0"===v.slice(-1);)v=v.slice(0,-1);r=v&&v.length?(i=f.pow(c,v.length),f.add(f.mul(i,e),g(v))):(i=d,e),u[6]&&(o=g(u[6].slice(1)),f.lt(o,h)?i=f.mul(i,f.pow(c,f.neg(o))):r=f.mul(r,f.pow(c,o)))}return!1!==t&&(l=St(r,i),r=f.div(r,l),i=f.div(i,l)),m[0]=_?f.neg(r):r,m[1]=i,m}(n,!0);return t?b(t[0],t[1],!0):b.Zero()},fromString:function(n){var t,e,r,i,u=U.Arithmetic,l="+",s=b.Zero();if(!(n=H(String(n))).length)return s;if("+"!==n.charAt(0)&&"-"!==n.charAt(0)||(l=n.charAt(0),n=H(n.slice(1))),!n.length)return s;if("("===n.charAt(0)&&")"===n.charAt(n.length-1)&&(n=H(n.slice(1,-1))),!n.length)return s;if(-1!==n.indexOf(".")||-1!==n.indexOf("e"))return e=b.fromDec(n),"-"===l&&(e=e.neg()),e;if(-1!==n.indexOf("\\frac")){if(!(e=n.match(/^(-)?\\frac\{(-?\d+)\}\{(-?\d+)\}$/)))return s;"-"===e[1]&&(l="-"===l?"+":"-"),r=u.num(e[2]),i=u.num(e[3])}else t=String(n).split("/"),r=u.num(t[0].length?t[0]:"0"),i=1>=1,e=e.mul(e);return t},rad:function(n){var t,e=this,r=U.Arithmetic;return(n=q.cast(n)).equ(r.I)?e:n.equ(r.II)?e.imag().equ(0)?e.real().lt(0)?v(b.Zero(),e.real().abs().rad(n)):v(e.real().rad(n),b.Zero()):(t=e.norm().rad(2),v(t.add(e.real()).div(2).rad(n),t.sub(e.real()).div(2).rad(n).mul(e.imag().lt(0)?-1:1))):at(e,n)},simpl:function(){var n=this;return n._simpl||(n.re.simpl(),n.im.simpl(),n._str=null,n._strp=null,n._tex=null,n._simpl=!0),n},round:function(n){n=!1!==n;return v(this.re.round(n),this.im.round(n))},integer:function(){var n=this;return null==n._int&&(n._int=v(n.re.integer(),n.im.integer())),n._int},remainder:function(){var n=this;return null==n._rem&&(n._rem=v(n.re.remainder(),n.im.remainder())),n._rem},tuple:function(){return[this.re,this.im]},valueOf:function(){return this.re.valueOf()},toString:function(n){var t,e=this,r=U.Arithmetic,i=r.O;return null==e._str&&(t=e.re.equ(i),e._str=(t?"":e.re.toString())+(e.im.equ(i)?"":(e.im.gt(i)?t?"":"+":"")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+v.Symbol),e._str.length||(e._str="0"),e._strp=(t?"":e.re.toString(!0))+(e.im.equ(i)?"":(e.im.gt(i)?t?"":"+":"")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+v.Symbol),e._strp.length||(e._strp="0")),n?e._strp:e._str},toTex:function(){var n,t=this,e=U.Arithmetic,r=e.O;return null==t._tex&&(n=t.re.equ(r),t._tex=(n?"":t.re.toTex())+(t.im.equ(r)?"":(t.im.gt(r)?n?"":"+":"")+(t.im.equ(e.I)?"":t.im.equ(e.J)?"-":t.im.toTex())+v.Symbol),t._tex.length||(t._tex="0")),t._tex},toDec:function(n){var t,e,r=this,i=U.Arithmetic,u=i.O;return null==r._dec&&(t=r.re.equ(u),r._dec=(t?"":r.re.toDec())+(r.im.equ(u)?"":(r.im.gt(u)?t?"":"+":"")+(r.im.equ(i.I)?"":r.im.equ(i.J)?"-":r.im.toDec())+v.Symbol),r._dec.length||(r._dec="0")),On(n)&&0<=n?((e=((t=r.re.equ(u))?"":r.re.toDec(n))+(r.im.equ(u)?"":(r.im.gt(u)?t?"":"+":"")+(r.im.equ(i.I)?"":r.im.equ(i.J)?"-":r.im.toDec(n))+v.Symbol)).length||(e="0",0>=1,e=e.mul(e);return t},rad:function(n){var t=this,e=U.Arithmetic,r=e.O,i=e.I;return n=q.cast(n),t.equ(r)?N():n.equ(r)?null:n.equ(i)?t:N(1===t.symbols().length?t.terms[1].rad(n):C(d(t,b(i,n.num)),i))},d:function(t,e){var r=this;return null==e&&(e=1),e=+e,t=String(t||"x"),e<0?null:N(r.symbols().map(function(n){return"1"===n?U.Arithmetic.O:r.terms[n].d(t,e)}))},evaluate:function(e){var r=this;U.Arithmetic.O;return e=e||{},r.symbols().reduce(function(n,t){return n.add(r.terms[t].evaluate(e))},v.Zero())},toString:function(){var n,t,e,r,i,u=this,l=U.Arithmetic.O,s="",o=!1;if(null==u._str){for(e=(n=u.symbols()).length,t=0;tn.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],w.Add(w(n,i,t.ring),w(t,i,t.ring),e);n.terms.length&&(t.terms=ue(t.terms,n.terms,x,!0===e,t.ring))}else(Cn(n,f)||u.isNumber(n))&&((n=x(n,0,t.ring)).equ(u.O)||(r=t.terms.length?ue([t.terms.pop()],[n],x,!0===e,t.ring):[n],t.terms=t.terms.concat(r)));return t},Mul:function(n,t){var e,r,i=U.Arithmetic,u=i.O;if(!t.terms.length)return t;if(Cn(n,I)){if(n.symbol!==t.symbol)return r=t.symbol>n.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],w.Mul(w(n,r,n.ring),w(t,r,t.ring));t.terms=n.terms.length?le(t.terms,n.terms,x,t.ring):[]}else if(Cn(n,f)||i.isNumber(n))if((n=t.ring.cast(n)).equ(u))t.terms=[];else if(!n.equ(i.I))for(e=t.terms.length-1;0<=e;e--)t.terms[e]=t.terms[e].mul(n);return t},Div:function(t,e,n){var r,i,u=U.Arithmetic,l=u.O,s=u.I;if(n=!0===n,Cn(e,I)){if(!e.terms.length)throw new Error("Division by zero in Abacus.Polynomial!");return e.isConst()?(i=(e=e.cc()).equ(s)?t:I(Dn(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i):e.symbol===t.symbol?(i=se(t.terms,e.terms,x,n,t.ring),n?[I(i[0],t.symbol,t.ring),I(i[1],t.symbol,t.ring)]:I(i,t.symbol,t.ring)):(r=t.symbol>e.symbol?[e.symbol,t.symbol]:[t.symbol,e.symbol],w.Div(w(t,r,t.ring),w(e,r,e.ring),n))}if(Cn(e,f)||u.isNumber(e)){if((e=t.ring.cast(e)).equ(l))throw new Error("Division by zero in Abacus.Polynomial!");return i=e.equ(s)?t:I(Dn(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i}return t},C:function(n,t,e){return new I(n||U.Arithmetic.O,t||"x",e||Z.Q())},gcd:Dt,xgcd:Et,lcm:Tt,bezier:function(n,t){t=String(t||"x");var e,r,i,u,l,s=Z.Q(),o=I.Zero(t,s);if(xn(n)&&n.length)for(e=n.length,l=I([1,-1],t,s),i=I.One(t,s).shift(e-1),u=I.One(t,s),o=o.add(i.mul(s.cast(n[e-1]))),r=e-2;0<=r;r--)i=i.shift(-1),u=u.mul(l),o=o.add(u.mul(i).mul(Wt(e-1,r)).mul(s.cast(n[r])));return o},bezierThrough:function(n,t){t=String(t||"x");var e,r,i,u,m=Z.Q();if(r=function(n){var t,e,r,i,u,l,s,o,c=n.length-1;for(e=new Array(c),r=new Array(c),i=new Array(c),u=new Array(c),l=new Array(c),s=new Array(c),i[0]=m.Zero(),u[0]=m.create(2),l[0]=m.One(),s[0]=n[0].add(n[1].mul(2)),t=1;tt.length+1&&t+"^"===i.slice(0,t.length+1)&&-1===i.indexOf("*")&&(o[i.slice(t.length+1)]=u));return new I(o,t,e)},fromString:function(n,t,e){var r,i,u,l,s,o,c=U.Arithmetic,m={},a=null,f=/(\(?(?:(?:[\+\-])?\s*\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))?\)?)(?:\s*(?:[\+\-])?\s*(?:\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))\)?\*?)?(?:[ij]))?\)?)?(?:\s*\*?\s*([a-zA-Z](?:_\{?\d+\}?)?)(?:\^\{?(\d+)\}?)?)?/g;if(e=e||Z.Q(),!(n=H(String(n))).length)return I.Zero(t||"x",e);for(;r=f.exec(n);){if(!r[0].length){if(f.lastIndex>=1,e=I.Mul(e,e);return t},rad:function(n){var t=U.Arithmetic;return(n=q.cast(n)).equ(t.I)?this:mt(this,n)},compose:function(n){var t,e,r,i,u=this,l=U.Arithmetic;l.O;if(Cn(n,C)&&(n=N(n)),Cn(n,N)&&(n=I.fromExpr(n,u.symbol,u.ring)),l.isNumber(n)||Cn(n,f))return I(u.evaluate(n),u.symbol,u.ring);if(Cn(n,I)){if(!u.terms.length)return I.Zero(n.symbol,u.ring);if(0===u.deg())return I(u.terms.slice(),n.symbol,u.ring);if(0===n.deg())return I(u.evaluate(n.cc()),n.symbol,u.ring);for(r=(e=u.terms)[0].e,t=I(e[0].c,n.symbol,u.ring),i=1;0=i.terms[0].e?I.Zero(i.symbol,i.ring):I(i.terms.map(function(n){if(r>n.e)return null;for(var t=u.I,e=n.e;e+r>n.e;e--)t=u.mul(t,e);return x(n.c.mul(t),n.e-r,i.ring)}).filter(x.isNonZero),i.symbol,i.ring)},polarForm:function(t){t=String(t||"u");var i=this.ring.associatedField(),u=this.deg(),l=Dn(u,function(n){return t+"_"+(n+1)});return this.terms.reduce(function(n,e){if(!e.e)return n;var t=k(u,e.e),r=t.total();return t.get().reduce(function(n,t){return n.add(w(A(i.cast(e.c).div(r),Dn(u,function(n){return-1===t.indexOf(n)?0:1})),l,i))},n)},w(A(this.cc(),Dn(u,0)),l,i))},evaluate:function(n){var t,e,r,i=this.ring,u=U.Arithmetic,l=u.O,s=this.terms;if(!s.length)return i.Zero();for(Cn(n,f)||u.isNumber(n)||!qn(n)||(n=n[this.symbol]),n=n||l,t=s[0].e,r=s[0].c,e=1;0=n.length&&e>=t.length?0:e>=t.length?0===n[e]?r(n,t,e+1):n[e]:e>=n.length?0===t[e]?r(n,t,e+1):-t[e]:n[e]===t[e]?r(n,t,e+1):n[e]-t[e]}if((xn(n)||An(n))&&(xn(t)||An(t)))return r(n,t,0);var i=r(n.e,t.e,0);return!0===e&&0===i?n.c.equ(t.c)?0:n.c.lt(t.c)?-1:1:i},sortDecr:function(n,t){return A.cmp(t,n)},gcd:function(t,e,n){return A(!0===n?Cn(t.c,[w,R,y])||Cn(e.c,[w,R,y])||!t.ring.hasGCD()?t.ring.One():t.ring.gcd(t.c,e.c):t.ring.One(),Dn(Q.max(t.e.length,e.e.length),function(n){return n=e.length);t++)if(t>=r.length){if(0r[t])return!1;return!0},pow:function(t){var e=this;return 1===(t=+t)?e:A(e.c.pow(t),Dn(e.e.length,function(n){return Q.floor(e.e[n]*t)}),e.ring)},rad:function(t){var e=this;return 1===(t=+t)?e:A(e.c.rad(t),Dn(e.e.length,function(n){return Q.max(Q.floor(e.e[n]/t),Q.min(1,e.e[n]))}),e.ring)},toTerm:function(n,t,e,r,i){var u,l=this.e,s=this.c,o=U.Arithmetic;if(!0===r){if(u=n.reduce(function(n,t,e){return 0t.e[e])&&(n=t),n},null,i),!0===n?w([r],l,u):r):!0===n?w([],l,u):A(u.Zero(),Dn(l.length,0),u):!0===n?w(i.length?[i[i.length-1]]:[],l,u):i.length?i[i.length-1]:A(0,Dn(l.length,0),u)},lm:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).e},lc:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).c},tm:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).e},tc:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).c},cc:function(){var n=this.terms;return n.length&&0===A.cmp(n[n.length-1].e,[0])?n[n.length-1].c:this.ring.Zero()},c:function(){return this.cc()},recur:function(l){var s,o,n,t=this,e=t.terms,c=t.symbol,m=t.ring,r=U.Arithmetic,i=null;if(!1===l)return null==t._flat&&(t._flat=c.length<=1||!t.isRecur()?t:Mn(function(n,t){return n._add(Cn(t.c,w)?w([A(m.One(),t.e,m)],c,m)._mul(t.c.recur(!1)):w([t],c,m))},w.Zero(c,m),e),t._flat._rsym=null,t._flat._flat=t._flat),t._flat;if(!0===l)return null==t._recur&&(t._recur=c.length<=1?t:Mn(function(n,t){return n.recur(t)},t.recur(!1),c),t._recur._flat=t.recur(!1),t._recur._recur=t._recur),t._recur;if(xn(l))return Mn(function(n,t){return n.recur(t)},t,l);if(l){if(c.length<=1)return t;if(l=String(l||"x"),-1===(s=c.indexOf(l))||t._rsym&&-1!==t._rsym.indexOf(l))return t;if(0===(o=t.maxdeg(l,!0)))return t._rsym=(t._rsym||[]).concat(l),t;for(n=w(Mn(function(n,t){var e,r,i=t.e[s],u=o-i;return r=Cn(t.c,w)?t.c.isUni(l)?w([t],c,m):((e=t.clone()).c=t.c.recur(l),e.e[s]=0,w([e],c,m)):0!==i?((e=t.clone()).e[s]=0,w([e],c,m)):w([t],c,m),n[u]=n[u]?n[u]._add(r):r,n},new Array(o+1),e).map(function(n,t){return n.equ(r.O)?null:A(n,Dn(c.length,function(n){return s===n?o-t:0}))}).filter(A.isNonZero),c,m);n.isConst()&&Cn(i=n.cc(),w);)n=i;return i===n&&(n=n.clone()),n._rsym=(t._rsym||[]).concat(l),n}return t},monic:function(){var n,t,e,r=this,i=U.Arithmetic,u=r.lc();if(u.equ(i.I)||u.equ(i.O)||Cn(u,w))return r;if(r.ring.isField())return w(r.terms.map(function(n){return n.div(u)}),r.symbol,r.ring);for(e=!0,n=(t=r.terms).length-1;0>=1,e=w.Mul(e,e,!1);return i&&(t=t.recur(i)),t},rad:function(n){var t=U.Arithmetic;return(n=q.cast(n)).equ(t.I)?this:mt(this,n)},compose:function(n){var t,a=this.symbol,f=this.ring,e=this._rsym,h=U.Arithmetic,d=w.Zero(a,f),g=m();return t=function n(t,e,r){for(r=r||0;r=a.length)return w(t.cc(),a,f);var i,u,l,s,o,c,m=t.terms;if(!m.length)return d;if(i=t.toString(),z.call(g,i))return g[i];for(o=z.call(e,a[r])?w(e[a[r]]||h.O,a,f):w([A(f.One(),Dn(a.length,function(n){return n===r?1:0}),f)],a,f),c=Cn(m[0].c,w)?n(m[0].c,e,r+1):w(m[0].c,a,f),u=m[0].e[r],s=c,l=1;0this.maxdeg(r,!0)?w.Zero(n,l):w(this.terms.map(function(n){var t,e;return Cn((n=n.clone()).c,w)?(e=n.e[u],t=i,0=-i?n.e[u]+=i:n.c=l.Zero(),n}).filter(A.isNonZero).sort(A.sortDecr),n,l):w(this.terms.map(function(n){return Cn((n=n.clone()).c,w)&&0this.maxdeg(r,!0)?w.Zero(n,t):w(this.terms.map(function(n){var t,e;if(Cn(n.c,w)){if(n.c.isConst(!0)){if(i>n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c._mul(t),n.e[u]-=i,n}for(n=n.clone(),e=i;e--,n.c=n.c.d(r,1)._add(n.c._mul(n.e[u])),n.e[u]=Q.max(n.e[u]-1,0),0n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c.mul(t),n.e[u]-=i,n}).filter(A.isNonZero).sort(A.sortDecr),n,t))},evaluate:function(n){var a=this.symbol,f=this.ring,h=U.Arithmetic.O,d=m();return function n(t,e,r){for(r=r||0;r=a.length)return t.cc();var i,u,l,s,o,c,m=t.terms;if(!m.length)return f.Zero();if(i=t.toString(),z.call(d,i))return d[i];for(o=(z.call(e,a[r])?e[a[r]]:h)||h,c=Cn(m[0].c,w)?n(m[0].c,e,r+1):m[0].c,u=m[0].e[r],s=c,l=1;0r[t]&&(r[t]=e.length):e.length>r&&(r=e.length),e});var e=String(n);return xn(r)?e.length>r[0]&&(r[0]=e.length):e.length>r&&(r=e.length),e})).map(function(n,t){return e+(xn(n)?n.map(function(n,t){return Hn(n,xn(r)?r[t]:r)}).join(" "):Hn(n,xn(r)?r[0]:r))+e}).join("\n")},toTex:function(n,t){return xn(n)?"\\begin{"+(t="pmatrix"===t?"pmatrix":"bmatrix")+"}"+n.map(function(n){return xn(n)?n.map(function(n){return Zn(n)}).join(" & "):Zn(n)}).join(" \\\\ ")+"\\end{"+t+"}":Zn(n)},toDec:function(n,r,e){if(!xn(n))return wn(n.toDec)?n.toDec(r):String(n);e=String(e||"|");var i=xn(n[0])?Dn(n[0].length,0):0;return(n=n.map(function(n,t){if(xn(n))return n.map(function(n,t){var e=n.toDec(r);return xn(i)?e.length>i[t]&&(i[t]=e.length):e.length>i&&(i=e.length),e});var e=n.toDec(r);return xn(i)?e.length>i[0]&&(i[0]=e.length):e.length>i&&(i=e.length),e})).map(function(n,t){return e+(xn(n)?n.map(function(n,t){return Hn(n,xn(i)?i[t]:i)}).join(" "):Hn(n,xn(i)?i[0]:i))+e}).join("\n")}},nr:0,nc:0,val:null,ring:null,_str:null,_tex:null,_n:null,_t:null,_h:null,_a:null,_i:null,_ir:null,_pi:null,_p:null,_snf:null,_lu:null,_qr:null,_ref:null,_rref:null,_evd:null,_svd:null,_rn:null,_ln:null,_rs:null,_cs:null,_tr:null,_det:null,dispose:function(){var n=this;return n._n&&n===n._n._n&&(n._n._n=null),n._t&&n===n._t._t&&(n._t._t=null,n._t._tr=null,n._t._det=null),n._h&&n===n._h._h&&(n._h._h=null),n._i&&n===n._i._i&&(n._i._i=null),n.nr=null,n.nc=null,n.val=null,n.ring=null,n._str=null,n._tex=null,n._n=null,n._t=null,n._h=null,n._a=null,n._i=null,n._ir=null,n._pi=null,n._p=null,n._snf=null,n._lu=null,n._qr=null,n._ref=null,n._rref=null,n._evd=null,n._svd=null,n._rn=null,n._ln=null,n._rs=null,n._cs=null,n._tr=null,n._det=null,n},clone:function(n){var t=this.val.map(function(n){return n.slice()});return!0===n?t:new M(this.ring,t)},map:function(r,n){var t,i=this;return t=i.val.map(function(n,e){return n.map(function(n,t){return r(n,[e,t],i)})}),!0===n?t:new M(i.ring,t)},array:function(n){var t=this;return Dn(t.nr*t.nc,n?function(n){return t.val[n%t.nr][~~(n/t.nr)]}:function(n){return t.val[~~(n/t.nc)][n%t.nc]})},row:function(n){return 0<=n&&n=e.nr?r.val[t].slice():t>=r.nr?e.val[t].slice():Dn(Q.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?e.val[t][n]:r.val[t][n].add(e.val[t][n])})})):((On(e)||In(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.add(e)}))},sub:function(e){var r=this;return Cn(e,M)?M(r.ring,Dn(Q.max(r.nr,e.nr),function(t){return t>=e.nr?r.val[t].slice():t>=r.nr?e.val[t].map(function(n){return Arithmetic.neg(n)}):Dn(Q.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?Arithmetic.neg(e.val[t][n]):r.val[t][n].sub(e.val[t][n])})})):((On(e)||In(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.sub(e)}))},mul:function(i){var u,l,s=this;return Cn(i,M)?(u=Q.min(s.nc,i.nr),l=s.ring.Zero(),M(s.ring,Dn(s.nr,function(r){return Dn(i.nc,function(n){for(var t=l,e=0;e=r.nr?e.val[t].slice():t>=e.nr?r.val[t].slice():Dn(Q.max(r.nc,e.nc),function(n){return n>=r.nc?e.val[t][n]:n>=e.nc?r.val[t][n]:r.val[t][n].mul(e.val[t][n])})})):((On(e)||In(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.mul(e)}))},prod:function(u){var n,t,e,l,r,s,o=this;return Cn(u,M)?(n=o.nr,t=o.nc,e=u.nr,l=u.nc,r=n*e,s=t*l,M(o.ring,Dn(r,function(n){var r=~~(n/e),i=n%e;return Dn(s,function(n){var t=~~(n/l),e=n%l;return o.val[r][t].mul(u.val[i][e])})}))):((On(u)||In(u))&&(u=o.ring.cast(u)),o.map(function(n){return n.mul(u)}))},div:function(t){return Cn(t,f)||U.Arithmetic.isNumber(t)||In(t)?((On(t)||In(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.div(t)})):this},mod:function(t){return Cn(t,f)||U.Arithmetic.isNumber(t)||In(t)?((On(t)||In(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.mod(t)})):this},divmod:function(n){return[this.div(n),this.mod(n)]},pow:function(n){var t,e,r=U.Arithmetic;if((n=q.cast(n)).lt(r.O)||n.gt(un))return null;if(0===(n=r.val(n.num)))return M.I(this.ring,this.nc);if(1===n)return this;for(t=null,e=this;0!==n;)1&n&&(t=null==t?e:e.mul(t)),n>>=1,e=e.mul(e);return t},fwdsub:function(n,t){var e,r,i,u,l,s,o,c=this.ring,m=c.Zero(),a=this.val;for(Cn(n,M)&&(n=n.col(0)),Cn(t,M)&&(t=t.diag()),n=c.cast(n),t=t&&c.cast(t),u=Q.min(this.nr,this.nc,n.length),l=new Array(u),e=0;eq&&(r.length=q),this._ref=[g,r,i]}return n?this._ref.slice():this._ref[0]},rref:function(n,t){var e,r,i,u,l,s,o,c,m,a,f=this.ring,h=f.Zero(),d=f.One(),g=f.MinusOne(),_=(this.nr,this.nc);if(null==this._rref){for(c=(a=this.ref(!0,t))[0].clone(),e=a[1],r=a[2],i=e.length,l=0;l=r.nc?t=e.nc?t=r.nr?n=e.nr?n"===n?(n=-1,i=!0):"<="===n||"=<"===n?i=!(n=1):">="!==n&&"=>"!==n||(i=!(n=-1))),u(-1===(n=-1===(n=+n)?-1:1)?function(n){for(var t=n[0],e=1,r=n.length;e=n[e]||!i&&t>n[e])return!1;t=n[e]}return!0})},LEN:function(t,n){return t=+t,u(">="===(n=n||"==")?function(n){return n.length>=t}:">"===n?function(n){return n.length>t}:"<"===n?function(n){return n.length="===(n=n||"==")||"=>"===n?function(n){return 0<=t&&t=e}:">"===n?function(n){return 0<=t&&te}:"<"===n?function(n){return 0<=t&&t="===(t=t||"==")||"=>"===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>=n}:">"===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>n}:"<"===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)<=n}:"!="===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)!==n}:function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)===n})},MIN:function(n,t){return n=+n,u(">="===(t=t||"==")||"=>"===t?function(e){return Mn(function(n,t){return e[t]=n}:">"===t?function(e){return Mn(function(n,t){return e[t]n}:"<"===t?function(e){return Mn(function(n,t){return e[t]i)return!1;return!0}:function(n){for(var t=0,e=n.length;t=i)return!1;return!0})}},filter:null,dispose:function(){return this.filter=null,this},apply:function(n,t){var e=this.filter;return!e||!wn(e)||Boolean(e.call(t||null,n))},NOT:function(){var t=this;return u(function(n){return!t.apply(n,this)})},OR:function(t){var e=this;return wn(t)||Cn(t,u)?(Cn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)||t.apply(n,this)})):e},XOR:function(r){var i=this;return wn(r)||Cn(r,u)?(Cn(r,u)||(r=u(r)),u(function(n){var t=i.apply(n,this),e=r.apply(n,this);return t&&!e||!t&&e})):i},AND:function(t){var e=this;return wn(t)||Cn(t,u)?(Cn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)&&t.apply(n,this)})):e}}),D=U.Iterator=n({constructor:function n(t,e){var r=this,i=U.Arithmetic;if(!Cn(r,n))return new n(t,e);(xn(t)||An(t))&&(Cn(t[0],n)||Cn(t[t.length-1],n))?(r.name="Iterator",r.$=e||{},r.$.seq=An(t)?G.call(t):t,r.$.count=Mn(function(n,t){return i.add(n,t.total())},i.O,r.$.seq),r.rewind()):wn(t)?(r.name="Generator",r.$={},r.$.generator=t,r.$.state=e||{},r.$.count=i.I,r.rewind()):(r.name=t||"Iterator",r.$=e||{},r.$.count=r.$.count||i.O)},__static__:{Iterable:function n(t,e){if(!Cn(this,n))return new n(t,e);e=-1===e?-1:1,this.next=function(){var n=t.hasNext(e)?t.next(e):null;return null==n?{done:!0}:{value:n}}}},name:"Iterator",$:null,__index:null,__item:null,_index:null,_item:null,__subindex:null,_subindex:null,__subitem:null,_subitem:null,dispose:function(){var n=this;return n.$.seq&&n.$.seq.length&&(Mn(function(n,t){t.dispose()},null,n.$.seq),n.$.seq=null),n.$=null,n.__index=null,n.__item=null,n._index=null,n._item=null,n.__subindex=null,n._subindex=null,n.__subitem=null,n._subitem=null,n},filterBy:function(n){var t=this.$;return!1===n?t.filter&&(t.filter=null):(Cn(n,u)||wn(n))&&(t.filter=Cn(n,u)?n:u(n)),this},mapTo:function(n){var t=this.$;return!1===n?t.output&&(t.output=null):wn(n)&&(t.output=n),this._item=this.output(this.__item),this},fuse:function(n,t,e){var r=this.$;return 1===arguments.length&&!1===n?r.sub&&(r.sub=null,r.submethod=null,r.subcascade=null,r.subcount=null,this.rewind()):Cn(t,D)&&wn(n)&&(r.sub=t,r.submethod=n,r.subcascade=-1===e?-1:1,r.subcount=U.Arithmetic.mul(r.count,t.total()),this.rewind()),this},unfuse:function(){return this.fuse(!1)},juxtaposeWith:function(n,t){return this.fuse(function(n,t){return[].concat(n).concat(t)},n,t)},state:function(n){return arguments.length?(this.$.state=n,this):this.$.state},output:function(n){var t=this.$.output;return null==n?null:wn(t)?t(n):n},fusion:function(n,t){var e,r=this.$;return r.sub?(-1===r.subcascade&&(e=n,n=t,t=e),null==n||null==t?n||t||null:r.submethod.call(this,n,t)):n},order:function(){return this},rewind:function(n,t){var e,r,i,u=this,l=u.$;if(n=-1===n?-1:1,xn(l.seq)){for(e=0,r=l.seq.length;e=u.seq.length)&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),r=i.__item,i.__subitem=u.sub.next(n)),i.__item=r,i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null}while(u.filter&&null!=e&&!u.filter.apply(e,i));return e}if(wn(u.generator)){for(;t=i.__item,e=u.sub?i._subitem:i._item,i.__item=u.generator.call(i,t,n,u.state,!1),null==i.__item&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),i.__subitem=u.sub.next(n)),i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null,u.filter&&null!=e&&!u.filter.apply(e,i););return e}return null},get:function(n){var t,e,r=[];if(wn(n))for(;this.hasNext()&&null!=(t=this.next())&&n(t);)r.push(t);else for(e=!arguments.length||null==n,null!=n&&(n=+n);(e||r.length=o.$.mindimension&&u<=o.$.maxdimension){if(l=o[X].rank(n,o.n,o.$),m.gt(l,f)){c=!0;break}s=m.add(s,o.total())}return c?m.add(l,s):f}return pn()},unrank:function(n,t,e){if(e&&"sequence"===e.type){var r,i,u=U.Arithmetic,l=u.O,s=e.seq;if(!s||!s.length)return null;if(null==n||!u.inside(n,u.J,null!=e.count?e.count:this.count(t,e)))return null;for(i=s.length,r=0;u.gte(n,s[r].total())&&(n=u.sub(n,s[r].total()),!(i<=++r||u.lt(n,l))););return rc&&(c=e[n]+1),e[n]):c+r[n-e.length]}:function(n){return nl&&(r.length=l),_<0&&1n[1]&&(n[1]=t),n},[1/0,0],r);if(n.base=r,n.minbase=s[0],n.maxbase=s[1],n.dimension=r.length,"gray"===n.output)n.output=function(n,t){return e.gray(n,t)};else if("inversion"===n.output)n.output=function(n,t){return e.inversion(n)};else if(xn(n.output)){var o=n.output;n.output=function(n,t){return e.component(n,o)}}}E.call(this,"Tensor",r,n,t?{method:"partial"===n.type?n.submethod||"complete":n.submethod,iter:t,pos:"partial"===n.type?n.subpos||n.position:n.subpos,cascade:n.subcascade}:null)},__static__:{C:E.C,P:E.P,T:E.T,DUAL:E.DUAL,count:function(n,t){var e=U.Arithmetic.O,r=t&&t.type?t.type:"tensor";return"partial"===r?t.data&&t.data.length?U.Arithmetic.num(t.data.length):e:"tuple"===r?!n||n[0]<=0?e:Gt(n[1],n[0]):n&&n.length?nt(n):e},initial:function(t,n,e){var r,i=n&&n.type?n.type:"tensor",u=n&&n.order?n.order:hn;return e=-1===e?-1:1,(!(dn&u)&&fn&u||dn&u&&!(fn&u))&&(e=-e),r="partial"===i?n.data&&n.data.length?e<0?n.data[n.data.length-1]:n.data[0]:null:(r="tuple"===i?t[0]?Dn(t[0],e<0?t[1]-1:0,0):[]:t.length?e<0?Dn(t.length,function(n){return t[n]-1}):Dn(t.length,0,0):[],this.DUAL(r,t,n))},succ:function(n,t,e,r,i,u){if(!e||null==n)return null;var l,s=r&&r.type?r.type:"tensor",o=r&&null!=r.order?r.order:hn,c=U.Arithmetic;return i=-1===i?-1:1,"partial"===s?r.data&&r.data.length?(fn&o&&(i=-i,null!=t&&(t=c.sub(c.num(r.data.length-1),t))),null==t&&(t=xe(r.data,n,!0)),l=c.val(t),i<0?0<=l-1?r.data[l-1]:null:0<=l&&l+1=t+r[e].length&&(t+=r[e++].length),t+r[e][n-t]})},component:function(t,e){return null==t?null:null==e?t:Dn(t.length,function(n){return n=r.length||null==r[n])return e[n];var t=r[n];return On(t)?e[n]+t:t[0]*e[n]+(t[1]||0)})}:yn},conditional:ie,generate:function(n,t,i,u,l){function s(n){return _<=n&&n<=v}l=l||{},i=i||Dn(t.length||0,0,1);var e,r,o,c,m,a,f,h,d,g,_=null==l.min?0:l.min,v=null==l.max?n-1:l.max,b=v-_+1,p=t,y=p.length,x=!1,A=[],q=[],I={};for(x=!(t=[]),o=a=0;oe[1]?oe(n,Dn(e[0]-e[1]+1,e[1],1).filter(s)).reverse():oe(n,Dn(e[1]-e[0]+1,e[0],1).filter(s)):oe(n,e[1].split(",").map(Number).filter(s))).length){x=!0;break}t.push(c)}else if(e=r.match(Y)){if(!(c=0e[1]?Dn(e[0]-e[1]+1,e[0],-1):Dn(e[1]-e[0]+1,e[0],1)).filter(s):e[1].split(",").map(Number).filter(s)).length){x=!0;break}t.push(c)}else{if(h=!0,f=[],d=null,r=r.replace(K,function(n,t){var e=parseInt(t,10),r="v"+String(e);return!isNaN(e)&&s(e)||(h=!1),h&&-1===f.indexOf(e)&&f.push(e),r}),!h){i&&i.splice(a--,1);continue}f.sort(Bn());try{d=new Function(f.map(function(n){return"v"+String(n)}).join(","),"return Math.floor("+r+");")}catch(n){d=null}if(!wn(d)){i&&i.splice(a--,1);continue}for(m=0;m"===u?sn:"<"===u?on:"<="===u||"=<"===u?an:">"===u?cn:(">="===u||"=>"===u)&&mn,g=wn(l.extra_conditions)?function(n,t,e){var r=n[t];return!(r<_||vr||cn===u&&i[i.length-1]-i[t]>r)&&l.extra_conditions(n,t,e)}:function(n,t,e){var r=n[t];return!(r<_||vr||cn===u&&i[i.length-1]-i[t]>r)},!0===l.lazy?t:ie(t,u,g))}}}),U.Permutation=n(E,{constructor:function n(t,e){var r=null;if(!Cn(this,n))return new n(t,e);(e=e||{}).type=String(e.type||"permutation").toLowerCase(),Cn(t=t||0,E)?t=(r=t).dimension():r=e.sub,e.base=e.dimension=t,e.rand=e.rand||{},e.rand.derangement=1,e.rand.involution=1,e.rand.connected=1,"multiset"===e.type&&(e.multiplicity=xn(e.multiplicity)&&e.multiplicity.length?e.multiplicity.slice():Dn(t,1,0),e.multiplicity=e.multiplicity.concat(Dn(t-Mn(Kn,0,e.multiplicity),1,0)),e.base=e.multiplicity.length,e.multiset=de(e.multiplicity,t)),E.call(this,"Permutation",t,e,r?{method:e.submethod,iter:r,pos:e.subpos,cascade:e.subcascade}:null)},__static__:{C:E.C,P:E.P,T:E.T,DUAL:E.DUAL,count:function(n,t){var e=U.Arithmetic,r=e.O,i=t&&t.type?t.type:"permutation",u=t&&null!=t["cycles="]?0|t["cycles="]:null,l=t&&null!=t["fixed="]?0|t["fixed="]:null;return n<0?r:"cyclic"===i?e.num(n):"multiset"===i?Wt(n,t.multiplicity):"derangement"===i?l?n-l<2?r:e.mul(Wt(n,l),Wt(n-l,!1)):n<2?r:Wt(n,!1):"involution"===i?Wt(n,!0):"connected"===i?Wt(n-1):u?Vt(n,u,1):Wt(n)},initial:function(n,t,e){var r,i=t&&t.type?t.type:"permutation",u=t&&null!=-t.order?t.order:hn,l=t&&null!=t["cycles="]?0|t["cycles="]:null,s=t&&null!=t["fixed="]?0|t["fixed="]:null;if(0===n)return[];if(e=-1===e?-1:1,(!(dn&u)&&fn&u||dn&u&&!(fn&u))&&(e=-e),"cyclic"===i)r=e<0?[n-1].concat(Dn(n-1,0,1)):Dn(n,0,1);else if("derangement"===i){if(s||n<2)return null;if(1&n){var o=Q.floor(n/2);r=e<0?Dn(n-o-1,n-1,-1).concat([o-1,o]).concat(Dn(o-1,o-2,-1)):Dn(n-3,function(n){return 1&n?n-1:n+1}).concat([n-2,n-1,n-3])}else r=e<0?Dn(n,n-1,-1):Dn(n,function(n){return 1&n?n-1:n+1})}else r="multiset"===i?e<0?t.multiset.slice().reverse():t.multiset.slice():"connected"===i?null:"involution"===i?e<0?Dn(n,n-1,-1):Dn(n,0,1):l?null:e<0?Dn(n,n-1,-1):Dn(n,0,1);return r=this.DUAL(r,n,t)},succ:function(n,t,e,r,i,u){if(!e||e<=0||null==n)return null;var l=r&&r.type?r.type:"permutation",s=r&&null!=r["cycles="]?0|r["cycles="]:null,o=r&&null!=r["fixed="]?0|r["fixed="]:null;return"derangement"===l&&o||"permutation"===l&&s?null:function(n,t,e,r,i,u){var l,s,o,c,m,a,f,h,d,g,_,v,b,p=t,y=null==u?p:u;f=b=p-1,_=d=h=1,v=g=0,dn&i&&(h=-h,f=b-f,d=-d,g=y-1-g,e=-e);2&i&&(h=-h,f=b-f,_=-1,v=y-1);fn&i&&(e=-e);if(e<0)if("cyclic"===r)if(0=d*n[l+h];)l-=h;if(0<=l&&l<=b){for(s=f;0<=s&&s<=b&&0=d*n[s];)s-=h;for(m=n[l],n[l]=n[s],n[s]=m,o=l+h,c=f;0<=o&&o<=b&&0<=c&&c<=b&&0=l&&(i=0,r++);else for(i=r=0;r=l&&(i=0,r++);return n}:function(n,t,e){var r,i,u=t.length,l=u*u;for(n=n||new Array(l),i=r=0;r=u&&(i=0,r+=u);if(!0===e)for(r=0;rt)return!1;return!0!==e||r===t},isInvolution:function(n){for(var t=n.length,e=0,r=n[e];e="===e||"=>"===e?t<=l:l===t}},_update:function(){return this.item__=(this.__item,this.n,this.$.order,this.$.type,null),this}}),(k=U.Combination=n(E,{constructor:function e(n,t,r){var i=null;if(!Cn(this,e))return new e(n,t,r);if(xn(n)||An(n)?(r=t||{},t=n[1]||0,n=n[0]||0):(r=r||{},n=n||0,t=t||0),r.type=String(r.type||"combination").toLowerCase(),-1p||b&&0n[l-a]+v){o=l;break}if(!(0<=o&&o<=f)&&0n[c-s]+1?(--n[c],n[c+s]=f,n[a]++):n[a]--:n[a]=0:n=null:0===n[a]?(n[i]=0*m+0,n[a]=1):m*n[o]+0n[s]+1?(n[l]=n[s],n[s]=i):(i===n[l]&&n[y][1]--,n[l]--,n[s]++,i===n[s]&&n[y][1]++)}else if(dn&u)if((a=n[o])n[y][0]){for(l=c,d=0;_<=l&&l<=v&&1===n[l];)l-=g,d++;if(a=n[l]-1,n[l]=a,0<++d)if(_<=l+g&&l+g<=v)n[l+=g]=d,d=0,n[y][0]=g<0?p-l:l+1;else for(;0n[l]+1&&d-(m-1)-1n[l]+1?(n[s]=n[l],n[l]=i):(i===n[s]&&n[y][1]--,n[l]++,n[s]--,i===n[l]&&n[y][1]++)}else if(dn&u)if(b-r+1>n[c]){for(l=o;_<=l&&l<=v&&1===n[l];)l+=g;a=n[l],n[l]=1,n[o]=a-1,_<=l+g&&l+g<=v&&n[l+g]++}else n=null;else if(b-r+1>n[o]){for(l=c;_<=l&&l<=v&&1===n[l];)l-=g;a=n[l],n[l]=1,n[c]=a-1,_<=l-g&&l-g<=v&&n[l-g]++}else n=null;else if(dn&u)n=null;else if(i)if(d=n[c],l=c-g,m=n[y][0]-1,1===n[y][1]&&d===i)if(b===i)n=null;else for(d+=n[l]-i,n[l]=i,n[y][0]--;0n[o])for(d=n[c],n[c-g]++,n[y][0]--,l=c-g,d--;0m||n[o+(m-1)*g]n[0]&&(e-t+un[0]){for(n[u]--,c[u]=c[u-1],l=u+1;l>>1,a=new Array(u);for(t=0;t>>1;for(_=new Array(t),e=0;e>>1==(r+1&3)>>>1?p-i:i+1;else{for(u=n(y),m=(c=(o=s=y*y)<<1)+s,r=e=i=0;i>>1,r=0;r=i&&(f=0,i<=++m&&(o+=i,f=m=0,r<=++a&&(c++,s+=i,f=m=o=a=0),ce[h]||-1===r&&fe[h]||-1===r&&t[f]e[g][0]?(n[_++]=v=t[d],d+=a):(1===r&&t[d][0]>e[g][0]||-1===r&&t[d][0]e[g][1]?(n[_++]=v=t[d],b&&(n[_++]=e[g])):(n[_++]=v=e[g],b&&(n[_++]=t[d])),d+=a),g+=f):1===r&&t[d]e[g]?(n[_++]=v=t[d],d+=a):(1===r&&t[d]>e[g]||-1===r&&t[d]>=1;return i?En(e,e,1):e}function Gn(n,t,e,r){var i,u,l,s=n.length;if(null==e&&(e=0),null==r&&(r=s-1),null==t||0===t){for(t=0,u=n[e],i=e+1;i<=r;i++){if(u<(l=n[i])){if(-1===t)return 0;0===t&&(t=1)}else if(l>>1],t)?r=l+1:i=l;else for(;r>>1])?i=l:r=l+1;return r}function Bn(e){return!0===e?function(n,t){return n.equ(t)?0:n.lt(t)?-1:1}:e?function(n,t){return e.equ(n,t)?0:e.lt(n,t)?-1:1}:function(n,t){return n===t?0:n>=1,n=rt(n,n,e);else for(r=u.II;!u.equ(t,l);)u.equ(s,u.mod(t,r))&&(i=rt(i,n,e)),t=u.div(t,r),n=rt(n,n,e);return i}function lt(n,t){var e,r,i=U.Arithmetic,u=i.O,l=i.I;i.num;if(i.gt(u,t))return null;if(i.equ(u,t))return l;if(i.equ(l,t))return n;if(r=l,i.isDefault()||i.lte(t,un))for(t=i.val(t);0!==t;)1&t&&(r=i.mul(r,n)),t>>=1,n=i.mul(n,n);else for(e=i.II;!i.equ(u,t);)i.equ(l,i.mod(t,e))&&(r=i.mul(r,n)),t=i.div(t,e),n=i.mul(n,n);return r}function st(n){var t,e,r,i,u,l,s=U.Arithmetic,o=(s.num,s.O),c=s.I;if(s.equ(n,o)||s.equ(n,c))return n;if(s.isDefault()||s.lte(n,un))return s.num(Q.floor(Q.sqrt(s.val(n))));for(l=s.II,t=c,e=s.div(n,l),u=t;s.lte(t,e);){if(r=s.div(s.add(t,e),l),i=s.mul(r,r),s.equ(i,n))return r;s.lt(i,n)?(t=s.add(r,c),u=r):e=s.sub(r,c)}return u}function ot(n,t){var e,r,i;return 0===(t=+t)?null:(t<0&&(n=1/n,t=-t),1===t?n:(1==(e=1&t)&&n<0&&(n=-n),r=Q.pow(n,1/t),i=Q.pow(r,t),Q.abs(n-i)<1&&0c&&(d++,u.terms.length>=e||e<=d))););return 0===d&&t.mod(h).equ(a)?u.abs():u}function at(n,t){var e,r,i,u,l=U.Arithmetic,s=l.O,o=l.I,c=l.II,m=b.Epsilon();if(t.equ(s))return null;if(Cn(n,f)&&(n.equ(s)||n.equ(o))||l.isNumber(n)&&(l.equ(s,n)||l.equ(o,n)))return n;if(n=(e=l.isNumber(n)||Cn(n,q)?b:n[X]).cast(n),Sn(e,b)&&n.lt(s)&&t.mod(c).equ(s)&&(n=(e=v).cast(n)),t.lt(s)&&(n=n.inv(),t=t.neg()),t.equ(o))return n;if(r=Sn(e,R)?new e(mt(n.num,t),mt(n.den,t)):Sn(e,b)?new e(ct(n.num,t.num),ct(n.den,t.num)):Sn(e,v)?!n.isReal()||!n.real().gte(s)&&t.mod(c).equ(s)?new e(o,o):new e(b(ct(n.real().num,t.num),ct(n.real().den,t.num)),b.Zero()):e.One(),u=t.sub(o),Sn(e,v))for(;;){if((i=n.div(r.pow(u)).sub(r).div(t)).real().abs().lte(m)&&i.imag().abs().lte(m))break;r=r.add(i)}else for(;;){if((i=n.div(r.pow(u)).sub(r).div(t)).abs().lte(m))break;r=r.add(i)}return r}function ft(n,t,e){var r,i,u,l,s,o,c=U.Arithmetic,m=c.num,a=c.O,f=c.J,h=c.I,d=c.II;if(c.lt(t,a)||c.equ(a,c.mod(t,d)))return null;if((c.lt(n,a)||c.gt(n,t))&&(n=c.mod(n,t)),c.equ(a,n))return c.equ(h,t)?h:a;if(c.equ(h,t)||c.equ(h,n))return h;if(null==e&&(e=St(n,t)),!c.equ(h,e))return a;for(u=m(3),l=m(4),s=m(5),o=m(8),r=h,c.lt(n,a)&&(n=c.mul(f,n),c.equ(c.mod(t,l),u)&&(r=c.mul(f,r)));!c.equ(a,n);){for(;c.gt(n,a)&&c.equ(a,c.mod(n,d));)n=c.div(n,d),i=c.mod(t,o),(c.equ(i,u)||c.equ(i,s))&&(r=c.mul(f,r));i=n,n=t,t=i,c.equ(u,c.mod(n,l))&&c.equ(u,c.mod(t,l))&&(r=c.mul(f,r)),n=c.mod(n,t)}return c.equ(h,t)||(r=a),r}function ht(n,t){var e=U.Arithmetic,r=(e.num,e.I),i=e.II;return ut(n,e.div(e.sub(t,r),i),t)}function dt(n,t){var e,r,i,u,l,s,o,c,m,a,f,h,d,g=U.Arithmetic,_=(g.num,g.O),v=g.I;if(!g.equ(v,ht(n,t)))return null;for(e=g.II,i=r=g.sub(t,v),u=0;g.equ(_,g.mod(i,e));)i=g.div(i,e),u+=1;if(1===u)return ut(n,g.div(g.add(t,v),4),t);for(l=_;g.lt(l,t)&&!g.equ(r,ht(l,t));l=g.add(l,v));for(s=ut(l,i,t),o=ut(n,g.div(g.add(i,v),e),t),m=ut(n,i,t),a=u,f=_;!g.equ(_,g.mod(g.sub(m,v),t));){for(f=rt(m,m,t),d=1;do&&(e.length=o),e}(It(t),It(r.div(n,t)))),i?e.map(function(n){return[new i(n[0]),new i(n[1])]}):e}function Ot(n,t){return n===t}function wt(n,t,e){var r,i,u,l;for(e=e||Ot,r=n(t),i=n(r);!e(r,i);)r=n(r),i=n(n(i));for(u=0,r=t;!e(r,i);)r=n(r),i=n(i),u++;for(l=1,i=n(r);!e(r,i);)i=n(i),l++;return[l,u]}function St(){var n,t,e,r,i=arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments,u=i.length,l=U.Arithmetic,s=(l.num,l.O),o=l.I;if(0===u)return s;for(r=0;r(n=_.cast(n)).length&&(n=n.concat(Dn(i-n.length,function(n){return v}))),s=(l=t.t().concat(M.I(_,u)).ref(!0,[u,i]))[0],o=l[1].length,m=s.slice(0,i,-1,-1).t(),c=s.slice(0,0,u-1,i-1).t(),d=new Array(u),g=new Array(u-o),a=0;a>>1;return i.mul(n(t,e,u),n(t,1+u,r))}(l,0,l.length-1)},n=function n(t,e){if(a.lt(t,d))return h;var r=n(a.div(t,d),e);return a.mul(a.mul(r,r),i(t,e))},a.lt(t,d)?h:(e=a.sub(t,a.digits(t,2).split("").reduce(function(n,t){return a.add(n,"1"===t?h:f)},f)),r=(u=T()).get(function(n){return a.lte(n,t)}),u.dispose(),a.mul(n(t,r),Xt(e)))}function Wt(e,n){var t,r,i=U.Arithmetic,u=i.O,l=i.I,s=i.J,o=i.II,c=i.num,m=i.val,a=i.add,f=i.sub,h=i.div,d=i.mul,g=i.mod,_=u,v=U.Options.MAXMEM;if(Cn(e,q))return new e[X](Wt(e.num,n));if(e=c(e),null==n){if(i.lte(e,12))return i.lt(e,u)?u:c([1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600][m(e)]);if(i.gte(e,100))return zt(e);t=String(e),null==Wt.mem1[t]?(_=d(Wt(f(e,l)),e),i.lt(e,v)&&(Wt.mem1[t]=_)):_=Wt.mem1[t]}else if(!1===n){if(i.lte(e,12))return i.lt(e,o)?u:c([1,2,9,44,265,1854,14833,133496,1334961,14684570,176214841][m(f(e,o))]);t="!"+String(e),null==Wt.mem2[t]?(_=a(i.equ(u,g(e,o))?l:s,d(Wt(f(e,l),!1),e)),i.lt(e,v)&&(Wt.mem2[t]=_)):_=Wt.mem2[t]}else if(!0===n){if(i.lte(e,18))return i.lt(e,u)?u:c([1,1,2,4,10,26,76,232,764,2620,9496,35696,140152,568504,2390480,10349536,46206736,211799312,997313824][m(e)]);t="I"+String(e),null==Wt.mem2[t]?(_=a(Wt(f(e,l),!0),d(Wt(f(e,o),!0),f(e,l))),i.lt(e,v)&&(Wt.mem2[t]=_)):_=Wt.mem2[t]}else if(xn(n)){if(!n.length)return i.lt(e,u)?u:Wt(e);if(i.lt(e,u))return u;t=String(e)+"@"+Xn(n.map(String),1,!0).join(","),null==Wt.mem3[t]?(_=h(Wt(e),Mn(function(n,t){return d(n,Wt(t))},Wt(n[n.length-1]),n,n.length-2,0)),i.lt(e,v)&&(Wt.mem3[t]=_)):_=Wt.mem3[t]}else if(i.isNumber(n)||Cn(n,q))if(n=Cn(n,q)?n.num:c(n),i.lt(n,u)){if(i.lte(e,i.neg(n)))return i.equ(e,i.neg(n))?Wt(e):u;if(t=String(e)+"@"+String(n),null==Wt.mem3[t]){for(_=r=a(a(e,n),l);i.lt(r,e);)r=a(r,l),_=d(_,r);i.lt(e,v)&&(Wt.mem3[t]=_)}else _=Wt.mem3[t]}else{if(i.lt(n,u)||i.lt(e,l)||i.gt(n,e))return u;if(i.lt(e,d(n,o))&&(n=f(e,n)),i.equ(n,u)||i.equ(e,l))return l;if(i.equ(n,l))return e;if(t=String(e)+"@"+String(n),null==Wt.mem3[t]){if(i.lte(e,10))_=a(Wt(f(e,l),f(n,l)),Wt(f(e,l),n));else if(i.isDefault())_=Q.round(Mn(function(n,t){return n*(1+e/t)},1+(e-=n),null,2,n));else{for(_=r=a(f(e,n),l);i.lt(r,e);)r=a(r,l),_=d(_,r);_=h(_,Wt(n))}i.lt(e,v)&&(Wt.mem3[t]=_)}else _=Wt.mem3[t]}return _}function Vt(n,t,e){var r,i=U.Arithmetic,u=i.O,l=i.I,s=i.add,o=i.sub,c=i.mul,m=u,a=U.Options.MAXMEM;if(Cn(n,q))return new n[X](Vt(n.num,Cn(t,q)?t.num:t,e));if(Cn(t,q)&&(t=t.num),n=i.num(n),t=i.num(t),e=+e,i.lt(n,u)||i.lt(t,u))return u;if(2===e){if(i.equ(n,t)||i.equ(t,l)&&i.lt(n,u))return l;if(i.equ(n,u)||i.equ(t,u))return u;r=String(n)+","+String(t),null==Vt.mem2[r]?(m=s(Vt(o(n,l),o(t,l),2),c(Vt(o(n,l),t,2),t)),i.lt(n,a)&&(Vt.mem2[r]=m)):m=Vt.mem2[r]}else if(-1===e){if(i.gt(t,n)||i.equ(t,u)&&i.lt(n,u))return u;if(i.equ(n,t))return l;r=String(n)+","+String(t)+"-",null==Vt.mem1[r]?(m=s(Vt(o(n,l),o(t,l),-1),c(Vt(o(n,l),t,-1),o(l,n))),i.lt(n,a)&&(Vt.mem1[r]=m)):m=Vt.mem1[r]}else{if(i.gt(t,n)||i.equ(t,u)&&i.lt(n,u))return u;if(i.equ(n,t))return l;if(i.equ(t,l))return Wt(o(n,l));m=i.equ(u,i.mod(o(n,t),i.II))?Vt(n,t,-1):i.neg(Vt(n,t,-1))}return m}function Bt(n,t,e,r){var i,u,l,s,o=U.Arithmetic,c=o.O,m=o.I,a=o.II,f=o.add,h=o.sub,d=o.mul,g=c;if(o.lt(n,c)||o.lte(t,c)||o.gt(e,r)||o.gt(f(e,t),f(n,m))||o.lt(d(t,r),n))return g;if(o.equ(r,n)&&o.equ(t,m)||o.equ(t,n)&&o.equ(r,m))return m;if(i=String(n)+","+String(t)+","+String(e)+","+String(r),null==Bt.mem[i]){if(n=h(n,d(t,h(e,m))),r=f(h(r,e),m),u=String(n)+","+String(t)+","+String(e)+","+String(r),null==Bt.mem[u]){for(l=o.max(m,o.divceil(h(n,r),h(t,m))),s=o.min(r,f(h(h(n,r),t),a));o.lte(l,s);)g=f(g,Bt(h(n,r),h(t,m),m,l)),l=f(l,m);Bt.mem[u]=g}Bt.mem[i]=Bt.mem[u]}return Bt.mem[i]}function Ht(n,t,e){if(Cn(n,q))return new n[X](Ht(n.num,t,e));var r,i,u,l,s,o,c,m=U.Arithmetic,a=m.num,f=m.O,h=m.I,d=m.add,g=m.sub,_=m.mul,v=f;if(Cn(t,q)&&(t=t.num),Cn(e,q)&&(e=e.num),t=null==t?null:m.abs(a(t)),e=null==e?null:m.abs(a(e)),n=a(n),r=null!=e?e:f,i=null!=e?e:h,u=null!=t?t:h,l=null!=t?t:n,m.lt(n,f)||null!=t&&null!=e&&(m.gt(d(t,e),d(n,h))||m.lt(_(t,e),n))||null!=e&&m.gt(e,n)||null!=t&&m.gt(t,n))return v;if(null!=e&&null==t&&(r=f,i=h,t=l=u=e,e=null),c=String(n)+"|"+String(t)+"|"+String(e),null==Ht.mem[c]){for(s=u;m.lte(s,l);){for(r=m.equ(f,r)?d(g(n,s),h):r,o=i;m.lte(o,r);)v=d(v,Bt(n,s,h,o)),o=d(o,h);s=d(s,h)}Ht.mem[c]=v}return Ht.mem[c]}function Kt(n,t,e,r){var i,u,l,s=U.Arithmetic,o=s.add,c=s.sub,m=s.mul,a=s.O,f=s.I,h=a;if(s.lt(n,a)||s.lte(t,a)||s.gt(e,r)||s.gt(m(e,t),n)||s.lt(m(t,r),n))return h;if(s.equ(t,f))return s.lte(e,n)&&s.lte(n,r)?f:h;if(s.equ(n,t))return s.lte(e,f)&&s.lte(f,r)?f:h;if(s.equ(e,r))return s.equ(m(t,e),n)?f:h;if(s.equ(n,r))return Wt(o(c(n,m(t,e)),c(t,f)),c(t,f));if(s.equ(o(e,f),r))return Wt(t,c(n,m(t,e)));if(l=String(n)+","+String(t)+","+String(e)+","+String(r),null==Kt.mem[l]){for(u=c(n,e),i=s.max(a,c(n,r)),t=c(t,f);s.lte(i,u);)h=o(h,Kt(i,t,e,r)),i=o(i,f);Kt.mem[l]=h}return Kt.mem[l]}function Yt(n,t,e){if(Cn(n,q))return new n[X](Yt(n.num,t,e));var r,i,u,l,s,o,c=U.Arithmetic,m=c.num,a=c.O,f=c.I,h=c.add,d=c.sub,g=c.mul,_=(c.div,c.mod),v=a;if(Cn(t,q)&&(t=t.num),Cn(e,q)&&(e=e.num),t=null==t?null:c.abs(m(t)),e=null==e?null:c.abs(m(e)),n=m(n),c.lt(n,a)||null!=t&&null!=e&&(c.gt(h(t,e),h(n,f))||c.lt(g(t,e),n))||null!=e&&c.gt(e,n)||null!=t&&c.gt(t,n))return v;if(o=String(n)+"|"+String(t)+"|"+String(e),null==Yt.mem[o]){if(null!=t&&null!=e)if(c.equ(g(t,e),n))v=f;else for(u=d(s=e,r=f);c.lte(s,n);)l=Kt(d(n,s),d(t,r),f,u),c.equ(a,l)||(v=h(v,g(l,Wt(t,r)))),s=h(s,e),r=h(r,f);else if(null!=t)v=Kt(n,t,f,n);else if(null!=e)if(c.equ(e,n))v=f;else for(c.equ(a,_(n,e))&&(v=f),u=d(s=e,r=f);c.lte(s,n);){for(i=f,t=d(n,r);c.lte(i,t);)l=Kt(d(n,s),i,f,u),c.equ(a,l)||(v=h(v,g(l,Wt(h(i,r),r)))),i=h(i,f);s=h(s,e),r=h(r,f)}else v=c.gte(n,f)?Xt(d(n,f)):f;Yt.mem[o]=v}return Yt.mem[o]}function ne(n){var t,e=U.Arithmetic,r=e.O,i=e.I,u=e.II,l=e.num,s=e.val,o=e.add,c=e.sub,m=e.div,a=e.mul,f=r,h=U.Options.MAXMEM;return Cn(n,q)?new n[X](ne(n.num)):(n=l(n),e.lte(n,17)?e.lt(n,r)?r:l([1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845,35357670,129644790][s(n)]):(t=String(n),null==ne.mem[t]?e.lt(n,h)?(f=m(a(ne(c(n,i)),c(a(n,4),u)),o(n,i)),ne.mem[t]=f):f=m(Wt(a(n,u),n),o(n,i)):f=ne.mem[t],f))}function te(n){var t,e,r=U.Arithmetic,i=r.O,u=r.I,l=r.num,s=r.val,o=r.add,c=r.sub,m=r.mul,a=i,f=U.Options.MAXMEM;if(Cn(n,q))return new n[X](te(n.num));if(n=l(n),r.lte(n,14))return r.lt(n,i)?i:l([1,1,2,5,15,52,203,877,4140,21147,115975,678570,4213597,27644437,190899322][s(n)]);if(t=String(n),null==te.mem[t]){for(e=a=i,n=c(n,u);r.lte(e,n);)a=o(a,m(Wt(n,e),te(e))),e=o(e,u);r.lt(n,f)&&(te.mem[t]=a)}else a=te.mem[t];return a}function ee(n){var t,e,r,i,u=U.Arithmetic,l=u.O,s=u.I,o=u.II,c=u.num,m=u.val,a=l,f=U.Options.MAXMEM;return Cn(n,q)?new n[X](ee(n.num)):(n=c(n),u.lte(n,36)?u.lt(n,l)?l:c([0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352][m(n)]):(i=String(n),null==ee.mem[i]?(t=u.div(n,o),e=ee(u.add(t,s)),r=ee(t),a=u.equ(l,u.mod(n,o))?u.mul(r,u.sub(u.mul(e,u.II),r)):u.add(u.mul(e,e),u.mul(r,r)),u.lt(n,f)&&(ee.mem[i]=a)):a=ee.mem[i],a))}function re(){var n,t,e,r,i,u,l,s,o,c,m,a=arguments,f=a.length;if(!f)return[];if(!0===a[0]){for(c=a[1].length,n=2;n_&&(v.length=_),v}function ue(n,t,e,r,i){r=!0===r,e=e===A?A:x,i=i||Z.Q();for(var u,l=0,s=0,o=0,c=n.length,m=t.length,a=new Array(c+m),f=U.Arithmetic.O;lo&&(a.length=o),a}function le(t,e,r,i){r=r===A?A:x,i=i||Z.Q();var n,u,l,s,o,c,m,a,f=U.Arithmetic.O;if(t.length>e.length&&(u=t,t=e,e=u),l=t.length,s=e.length,o=new Array(l*s),0n+1&&(o.length=n+1)}return o}function se(n,t,e,r,i){r=!0===r,e=e===A?A:x,i=i||Z.Q();var u,l,s,o,c=n.length,m=t.length,a=U.Arithmetic.O,f=_([],"max",function(n,t){return e.cmp(n.term,t.term)}),h=[],d=[],g=0;if(!t.length)return null;for(o=t[0].cast(i);(u=f.peek())||gu.n?f.replace({term:u.Q.mul(t[u.n].cast(i)),n:u.n+1,Q:u.Q}):f.pop(),g++):(l=u.term.neg(),m>u.n?f.replace({term:u.Q.mul(t[u.n].cast(i)),n:u.n+1,Q:u.Q}):f.pop()),l.equ(a)||(o.divides(l)?(h=ue(h,[s=l.div(o)],e,!1,i),1>>1<<1]),s[r]+=1,r>>>=1;return s[r]+=1,n[e]=t,n},n||new Array(r),t)}function ve(n,t,e){var r,i,u,l=t.length,s=Q.ceil(V(e||l)),o=1<=c[r<<=1]&&(t-=c[r],r++);return c[r]=0,n[e]=r-o,n},n||new Array(l),t)}function be(n,t,e){var r,i=n.length,u=null==t;if(1>t},bor:function(n,t){return n|t},band:function(n,t){return n&t},xor:function(n,t){return n^t},abs:Q.abs,min:Q.min,max:Q.max,rnd:Ae},U.Arithmetic=r({},t,{isDefault:function(){return 0===this.O&&this.add===Kn},neg:function(n){return U.Arithmetic.mul(U.Arithmetic.J,n)},abs:function(n){return U.Arithmetic.gt(U.Arithmetic.O,n)?U.Arithmetic.neg(n):n},min:function(n,t){return U.Arithmetic.lt(n,t)?n:t},max:function(n,t){return U.Arithmetic.gt(n,t)?n:t},divceil:function(n,t){if(null==t)return n;var e,r=U.Arithmetic,i=r.O,u=r.I;return e=r.div(n,t),r.equ(i,r.mod(n,t))?e:r.gt(n,i)===r.gt(t,i)?r.add(e,u):e}}),U.Math={rnd:Q.random,rndInt:Ae,factorial:Wt,stirling:Vt,partitions:Ht,compositions:Yt,bell:te,catalan:ne,fibonacci:ee,polygonal:function n(t,e){var r=U.Arithmetic,i=(r.O,r.I,r.II),u=r.num;return Cn(e,q)&&(e=e.num),e=u(e),r.lt(e,3)?null:Cn(t,q)?new t[X](n(t.num,e)):(t=u(t),r.div(r.mul(t,r.sub(r.mul(t,r.sub(e,i)),r.sub(e,4))),i))},sum:Yn,product:nt,pow2:Xt,exp:Gt,powsq:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](lt(n.num,t)):lt(e.num(n),t)},addm:function(n,t,e){var r=U.Arithmetic;return e=Cn(e,q)?e.num:r.num(e),t=Cn(t,q)?t.num:r.num(t),Cn(n,q)?new n[X](et(n.num,t,e)):et(r.num(n),t,e)},negm:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](tt(n.num,t)):tt(e.num(n),t)},mulm:function(n,t,e){var r=U.Arithmetic;return e=Cn(e,q)?e.num:r.num(e),t=Cn(t,q)?t.num:r.num(t),Cn(n,q)?new n[X](rt(n.num,t,e)):rt(r.num(n),t,e)},invm:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](it(n.num,t)):it(e.num(n),t)},powm:function(n,t,e){var r=U.Arithmetic;return e=Cn(e,q)?e.num:r.num(e),t=Cn(t,q)?t.num:r.num(t),Cn(n,q)?new n[X](ut(n.num,t,e)):ut(r.num(n),t,e)},isqrt:function(n){var t=U.Arithmetic;return Cn(n,q)?new n[X](st(n.num)):st(t.num(n))},ikthroot:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](ct(n.num,t)):ct(e.num(n),t)},isqrtp:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](dt(n.num,t)):dt(e.num(n),t)},ilog:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](gt(n.num,t)):gt(e.num(n),t)},divisors:function(n,t){var e=U.Arithmetic;return $t(Cn(n,q)?n:e.num(n),!0===t)},legendre:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](ht(n.num,t)):ht(e.num(n),t)},jacobi:function(n,t){var e=U.Arithmetic;return t=Cn(t,q)?t.num:e.num(t),Cn(n,q)?new n[X](ft(n.num,t)):ft(e.num(n),t)},moebius:function(n){var t=U.Arithmetic;return Cn(n,q)?new n[X](kt(n.num)):kt(t.num(n))},pollardRho:function(n,t,e,r,i,u){var l,s=U.Arithmetic.num;return null!=e&&(e=Cn(e,q)?e.num:s(e)),null!=t&&(t=Cn(t,q)?t.num:s(t)),Cn(n,q)?null==(l=qt(n.num,t,e,r,i||null,u||null))?l:new n[X](l):qt(s(n),t,e,r,i||null,u||null)},factorize:function(n){var t=U.Arithmetic;return It(Cn(n,q)?n:t.num(n))},isProbablePrime:function(n){var t=U.Arithmetic;return yt(Cn(n,q)?n.num:t.num(n))},isPrime:function(n){var t=U.Arithmetic;return At(Cn(n,q)?n.num:t.num(n))},nextPrime:function(n,t){var e=U.Arithmetic;return function(n,t){var e,r=U.Arithmetic,i=(r.num,r.O),u=r.I,l=r.II;if((t=-1===t?-1:1)<0){if(r.lte(n,l))return null;if(r.equ(n,3))return l;for(e=r.sub(n,r.equ(i,r.mod(n,l))?u:l);;e=r.sub(e,l))if(yt(e)&&At(e))return e}else{if(r.lt(n,l))return l;for(e=r.add(n,r.equ(i,r.mod(n,l))?u:l);;e=r.add(e,l))if(yt(e)&&At(e))return e}}(Cn(n,q)?n.num:e.num(n),-1===t?-1:1)},gcd:function(){var n,t=U.Arithmetic,e=G.call(arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),r=null;return n=St(e.map(function(n){return Cn(n,q)?(r=r||n[X],n.num):t.num(n)})),r?new r(n):n},xgcd:function(){var n,t=U.Arithmetic,e=G.call(arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),r=null;return n=Rt(e.map(function(n){return Cn(n,q)?(r=r||n[X],n.num):t.num(n)})),r&&n?n.map(function(n){return new r(n)}):n},lcm:function(){var n,t=U.Arithmetic,e=G.call(arguments.length&&(xn(arguments[0])||An(arguments[0]))?arguments[0]:arguments),r=null;return n=Nt(e.map(function(n){return Cn(n,q)?(r=r||n[X],n.num):t.num(n)})),r?new r(n):n},diophantine:function(n,t,e,r){var i=U.Arithmetic;return(xn(n)||An(n))&&n.length?Ut(i.nums(n),i.num(t||0),e,!0===r):null},diophantines:function(n,t,e,r){var i=Z.Z();return(Cn(n,M)||xn(n)||An(n))&&(!Cn(n,M)||n.nr&&n.nc)&&(Cn(n,M)||n.length)?(Cn(t,M)||xn(t)||An(t)||(t=Dn(Cn(n,M)?n.nr:n.length,function(){return t||0})),Qt(n,t=Cn(t,M)?t:i.cast(t),e,!0===r)):null},congruence:function(n,t,e,r,i){var u,l,s,o,c,m,a,f,h,d=U.Arithmetic;return(xn(n)||An(n))&&n.length?(u=d.nums(n),l=d.num(t||0),s=d.num(e||0),o=r,c=!0===i,f=U.Arithmetic,h=f.O,u.length?(c=!0===c,(m=Ut(u.concat(s),l,o,c))&&c&&(a=m[1],m=m[0]),null==(m=null==m?null:Dn(m.length-1,function(n){var t=m[n];return!1===o?f.gt(h,t)&&(t=f.add(t,s)):t.c().real().lt(h)&&(t=t.add(s)),t}))?null:c?[m,a]:m):null):null},congruences:function(n,t,e,r,i){var u,l,s,o,c,m,a,f,h,d,g,_,v=Z.Z();return(Cn(n,M)||xn(n)||An(n))&&(!Cn(n,M)||n.nr&&n.nc)&&(Cn(n,M)||n.length)?(n=Cn(n,M)?n:v.cast(n),Cn(t,M)||xn(t)||An(t)||(t=Dn(Cn(n,M)?n.nr:n.length,function(){return t||0})),t=Cn(t,M)?t:v.cast(t),Cn(e,M)||xn(e)||An(e)||(e=Dn(Cn(n,M)?n.nr:n.length,function(){return e||0})),e=Cn(e,M)?e:v.cast(e),u=n,l=t,s=e,o=r,c=!0===i,d=Z.Z(),g=U.Arithmetic,_=d.Zero(),Cn(u,M)&&Sn(u.ring.NumberClass,q)||(u=M(d,u)),u.nr&&u.nc?(xn(s)||An(s)||Cn(s,M)||(s=Dn(u.nr,function(n){return s})),(xn(s)||An(s))&&(s=M(d,s)),(xn(l)||An(l))&&(l=M(d,l)),f=s.col(0),a=d.lcm(f),u=u.concat(s),c=!0===c,null!=(m=Qt(u,l,o,!0))&&(h=m[1],m=m[0]),null==(m=null==m?null:Dn(m.length-1,function(n){var t,e,r=m[n],i=!0;if(!1===o)g.gt(g.O,r)&&(r=g.add(r,a.num));else{for(t in r.terms)if(z.call(r.terms,t)&&"1"!==t&&g.equ(g.O,g.mod(a.num,r.terms[t].c().real().num))){i=!1;break}i&&(e=h.symbol+"_"+(h.length+1),h.push(e),r=r.add(C(S(e),a))),r.c().real().lt(_)&&(r=r.add(a))}return r}))?null:c?[m,h]:m):null):null},pythagorean:function(n,t){var e=U.Arithmetic;return(xn(n)||An(n))&&n.length?function(t,n){var e,r,i,u,l,s,o,c,m,a,f,h=U.Arithmetic,d=h.O,g=h.I,_=h.J,v=h.II,b=t.length,p=In(n)&&n.length?n:"i";if(!b)return null;if(a=t.filter(function(n){return 1===Ft(n)}).length,f=t.filter(function(n){return-1===Ft(n)}).length,1===b||0===a||0===f)return Dn(b,function(){return N()});if(m=Dn(b,function(n){return st(h.abs(t[n]))}),b!==t.filter(function(n,t){return h.equ(h.abs(n),h.mul(m[t],m[t]))}).length)return Dn(b,function(){return N()});if(u=Dn(b-1,function(n){return p+"_"+(n+1)}),2===b)return[N(C(S(u[0]),m[1])),N(C(S(u[0]),m[0]))];for(Ft(t[0])+Ft(t[1])+Ft(t[2])<0&&(t=t.map(function(n){return h.neg(n)})),l=e=0;ll&&(u.length=l),u},intersection:function(n,t,e,r,i,u,l,s){r=-1===r?-1:1,null==i&&(i=0),null==u&&(u=t.length-1),null==l&&(l=0),null==s&&(s=e.length-1);var o=ue[h]?f+=o:(1===r&&t[f]>e[h]||-1===r&&t[f]r[f]?f+=c:(n[h++]=e[a],t[e[a]]--,a+=o);for(;0<=o*(u-a);)0>>1]))return s;l(o,n)?m=s-1:c=s+1}else for(;c>>1]))return s;l(n,o)?m=s-1:c=s+1}return-1},bisect:Vn,complementation:Pn,reflection:Tn,reversion:$n,gray:kn,finitedifference:Ln,partialsum:Jn,convolution:function(n,t,e){var r,i,u,l=n.length,s=t.length;if(!0===e)for(u=Dn(l+s-1,function(){return 0}),r=0;r>>5]&1<<(31&n))},set:function(n){return this.bits[n>>>5]|=1<<(31&n),this},unset:function(n){return this.bits[n>>>5]&=~(1<<(31&n)),this},toggle:function(n){return this.bits[n>>>5]^=1<<(31&n),this}}),p=U.Node=function n(t,e,r,i){var u=this;if(!Cn(u,n))return new n(t,e,r,i);u.v=t,u.l=e||null,u.r=r||null,u.t=i||null,u.dispose=function(){return u.v=null,u.l=null,u.r=null,u.t=null,u}},_=U.Heap=n({constructor:function n(t,e,r){var i=this;if(!Cn(i,n))return new n(t,e,r);e=String(e||"min").toLowerCase().slice(0,3),i.type="max"===e?"max":"min",wn(r)||(r=n.CMP),i.cmp=r,t=t||[],i._h=n.heapify(t,i.type,i.cmp)},__static__:{CMP:function(n,t){return n>>1)-1;0<=r;r--)_._siftup_max(n,r,e);else for(r=(i>>>1)-1;0<=r;r--)_._siftup(n,r,e);return n},_siftdown:function(n,t,e,r){for(var i,u,l=n[e];t>>1])<0;)n[e]=u,e=i;n[e]=l},_siftup:function(n,t,e){var r,i,u=n.length,l=t,s=n[t];for(r=2*t+1;r>>1],l)<0;)n[e]=u,e=i;n[e]=l},_siftup_max:function(n,t,e){var r,i,u=n.length,l=t,s=n[t];for(r=2*t+1;r=b.length&&v.slice(-b.length)===b;)v=v.slice(0,-b.length);v.length||(v=null)}i=f.sub(f.pow(c,(v?v.length:0)+b.length),v?f.pow(c,v.length):d),r=f.add(f.mul(i,e),f.sub(g((v||"")+b),v?g(v):h))}else{for(;v&&"0"===v.slice(-1);)v=v.slice(0,-1);r=v&&v.length?(i=f.pow(c,v.length),f.add(f.mul(i,e),g(v))):(i=d,e),u[6]&&(o=g(u[6].slice(1)),f.lt(o,h)?i=f.mul(i,f.pow(c,f.neg(o))):r=f.mul(r,f.pow(c,o)))}return!1!==t&&(l=St(r,i),r=f.div(r,l),i=f.div(i,l)),m[0]=_?f.neg(r):r,m[1]=i,m}(n,!0);return t?b(t[0],t[1],!0):b.Zero()},fromString:function(n){var t,e,r,i,u=U.Arithmetic,l="+",s=b.Zero();if(!(n=H(String(n))).length)return s;if("+"!==n.charAt(0)&&"-"!==n.charAt(0)||(l=n.charAt(0),n=H(n.slice(1))),!n.length)return s;if("("===n.charAt(0)&&")"===n.charAt(n.length-1)&&(n=H(n.slice(1,-1))),!n.length)return s;if(-1!==n.indexOf(".")||-1!==n.indexOf("e"))return e=b.fromDec(n),"-"===l&&(e=e.neg()),e;if(-1!==n.indexOf("\\frac")){if(!(e=n.match(/^(-)?\\frac\{(-?\d+)\}\{(-?\d+)\}$/)))return s;"-"===e[1]&&(l="-"===l?"+":"-"),r=u.num(e[2]),i=u.num(e[3])}else t=String(n).split("/"),r=u.num(t[0].length?t[0]:"0"),i=1>=1,e=e.mul(e);return t},rad:function(n){var t,e=this,r=U.Arithmetic;return(n=q.cast(n)).equ(r.I)?e:n.equ(r.II)?e.imag().equ(0)?e.real().lt(0)?v(b.Zero(),e.real().abs().rad(n)):v(e.real().rad(n),b.Zero()):(t=e.norm().rad(2),v(t.add(e.real()).div(2).rad(n),t.sub(e.real()).div(2).rad(n).mul(e.imag().lt(0)?-1:1))):at(e,n)},simpl:function(){var n=this;return n._simpl||(n.re.simpl(),n.im.simpl(),n._str=null,n._strp=null,n._tex=null,n._simpl=!0),n},round:function(n){n=!1!==n;return v(this.re.round(n),this.im.round(n))},integer:function(){var n=this;return null==n._int&&(n._int=v(n.re.integer(),n.im.integer())),n._int},remainder:function(){var n=this;return null==n._rem&&(n._rem=v(n.re.remainder(),n.im.remainder())),n._rem},tuple:function(){return[this.re,this.im]},valueOf:function(){return this.re.valueOf()},toString:function(n){var t,e=this,r=U.Arithmetic,i=r.O;return null==e._str&&(t=e.re.equ(i),e._str=(t?"":e.re.toString())+(e.im.equ(i)?"":(e.im.gt(i)?t?"":"+":"")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+v.Symbol),e._str.length||(e._str="0"),e._strp=(t?"":e.re.toString(!0))+(e.im.equ(i)?"":(e.im.gt(i)?t?"":"+":"")+(e.im.equ(r.I)?"":e.im.equ(r.J)?"-":e.im.toString(!0)+"*")+v.Symbol),e._strp.length||(e._strp="0")),n?e._strp:e._str},toTex:function(){var n,t=this,e=U.Arithmetic,r=e.O;return null==t._tex&&(n=t.re.equ(r),t._tex=(n?"":t.re.toTex())+(t.im.equ(r)?"":(t.im.gt(r)?n?"":"+":"")+(t.im.equ(e.I)?"":t.im.equ(e.J)?"-":t.im.toTex())+v.Symbol),t._tex.length||(t._tex="0")),t._tex},toDec:function(n){var t,e,r=this,i=U.Arithmetic,u=i.O;return null==r._dec&&(t=r.re.equ(u),r._dec=(t?"":r.re.toDec())+(r.im.equ(u)?"":(r.im.gt(u)?t?"":"+":"")+(r.im.equ(i.I)?"":r.im.equ(i.J)?"-":r.im.toDec())+v.Symbol),r._dec.length||(r._dec="0")),On(n)&&0<=n?((e=((t=r.re.equ(u))?"":r.re.toDec(n))+(r.im.equ(u)?"":(r.im.gt(u)?t?"":"+":"")+(r.im.equ(i.I)?"":r.im.equ(i.J)?"-":r.im.toDec(n))+v.Symbol)).length||(e="0",0>=1,e=e.mul(e);return t},rad:function(n){var t=this,e=U.Arithmetic,r=e.O,i=e.I;return n=q.cast(n),t.equ(r)?N():n.equ(r)?null:n.equ(i)?t:N(1===t.symbols().length?t.terms[1].rad(n):C(d(t,b(i,n.num)),i))},d:function(t,e){var r=this;return null==e&&(e=1),e=+e,t=String(t||"x"),e<0?null:N(r.symbols().map(function(n){return"1"===n?U.Arithmetic.O:r.terms[n].d(t,e)}))},evaluate:function(e){var r=this;U.Arithmetic.O;return e=e||{},r.symbols().reduce(function(n,t){return n.add(r.terms[t].evaluate(e))},v.Zero())},toString:function(){var n,t,e,r,i,u=this,l=U.Arithmetic.O,s="",o=!1;if(null==u._str){for(e=(n=u.symbols()).length,t=0;tn.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],w.Add(w(n,i,t.ring),w(t,i,t.ring),e);n.terms.length&&(t.terms=ue(t.terms,n.terms,x,!0===e,t.ring))}else(Cn(n,f)||u.isNumber(n))&&((n=x(n,0,t.ring)).equ(u.O)||(r=t.terms.length?ue([t.terms.pop()],[n],x,!0===e,t.ring):[n],t.terms=t.terms.concat(r)));return t},Mul:function(n,t){var e,r,i=U.Arithmetic,u=i.O;if(!t.terms.length)return t;if(Cn(n,I)){if(n.symbol!==t.symbol)return r=t.symbol>n.symbol?[n.symbol,t.symbol]:[t.symbol,n.symbol],w.Mul(w(n,r,n.ring),w(t,r,t.ring));t.terms=n.terms.length?le(t.terms,n.terms,x,t.ring):[]}else if(Cn(n,f)||i.isNumber(n))if((n=t.ring.cast(n)).equ(u))t.terms=[];else if(!n.equ(i.I))for(e=t.terms.length-1;0<=e;e--)t.terms[e]=t.terms[e].mul(n);return t},Div:function(t,e,n){var r,i,u=U.Arithmetic,l=u.O,s=u.I;if(n=!0===n,Cn(e,I)){if(!e.terms.length)throw new Error("Division by zero in Abacus.Polynomial!");return e.isConst()?(i=(e=e.cc()).equ(s)?t:I(Dn(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i):e.symbol===t.symbol?(i=se(t.terms,e.terms,x,n,t.ring),n?[I(i[0],t.symbol,t.ring),I(i[1],t.symbol,t.ring)]:I(i,t.symbol,t.ring)):(r=t.symbol>e.symbol?[e.symbol,t.symbol]:[t.symbol,e.symbol],w.Div(w(t,r,t.ring),w(e,r,e.ring),n))}if(Cn(e,f)||u.isNumber(e)){if((e=t.ring.cast(e)).equ(l))throw new Error("Division by zero in Abacus.Polynomial!");return i=e.equ(s)?t:I(Dn(t.terms.length,function(n){return t.terms[n].div(e)}),t.symbol,t.ring),n?[i,I.Zero(t.symbol,t.ring)]:i}return t},C:function(n,t,e){return new I(n||U.Arithmetic.O,t||"x",e||Z.Q())},gcd:Dt,xgcd:Et,lcm:Tt,bezier:function(n,t){t=String(t||"x");var e,r,i,u,l,s=Z.Q(),o=I.Zero(t,s);if(xn(n)&&n.length)for(e=n.length,l=I([1,-1],t,s),i=I.One(t,s).shift(e-1),u=I.One(t,s),o=o.add(i.mul(s.cast(n[e-1]))),r=e-2;0<=r;r--)i=i.shift(-1),u=u.mul(l),o=o.add(u.mul(i).mul(Wt(e-1,r)).mul(s.cast(n[r])));return o},bezierThrough:function(n,t){t=String(t||"x");var e,r,i,u,m=Z.Q();if(r=function(n){var t,e,r,i,u,l,s,o,c=n.length-1;for(e=new Array(c),r=new Array(c),i=new Array(c),u=new Array(c),l=new Array(c),s=new Array(c),i[0]=m.Zero(),u[0]=m.create(2),l[0]=m.One(),s[0]=n[0].add(n[1].mul(2)),t=1;tt.length+1&&t+"^"===i.slice(0,t.length+1)&&-1===i.indexOf("*")&&(o[i.slice(t.length+1)]=u));return new I(o,t,e)},fromString:function(n,t,e){var r,i,u,l,s,o,c=U.Arithmetic,m={},a=null,f=/(\(?(?:(?:[\+\-])?\s*\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))?\)?)(?:\s*(?:[\+\-])?\s*(?:\(?(?:(?:\\frac\{\-?\d+\}\{\-?\d+\})|(?:\-?\d+(?:\.\d*(?:\[\d+\])?)?(?:e-?\d+)?(?:\/\-?\d+)?))\)?\*?)?(?:[ij]))?\)?)?(?:\s*\*?\s*([a-zA-Z](?:_\{?\d+\}?)?)(?:\^\{?(\d+)\}?)?)?/g;if(e=e||Z.Q(),!(n=H(String(n))).length)return I.Zero(t||"x",e);for(;r=f.exec(n);){if(!r[0].length){if(f.lastIndex>=1,e=I.Mul(e,e);return t},rad:function(n){var t=U.Arithmetic;return(n=q.cast(n)).equ(t.I)?this:mt(this,n)},compose:function(n){var t,e,r,i,u=this,l=U.Arithmetic;l.O;if(Cn(n,C)&&(n=N(n)),Cn(n,N)&&(n=I.fromExpr(n,u.symbol,u.ring)),l.isNumber(n)||Cn(n,f))return I(u.evaluate(n),u.symbol,u.ring);if(Cn(n,I)){if(!u.terms.length)return I.Zero(n.symbol,u.ring);if(0===u.deg())return I(u.terms.slice(),n.symbol,u.ring);if(0===n.deg())return I(u.evaluate(n.cc()),n.symbol,u.ring);for(r=(e=u.terms)[0].e,t=I(e[0].c,n.symbol,u.ring),i=1;0=i.terms[0].e?I.Zero(i.symbol,i.ring):I(i.terms.map(function(n){if(r>n.e)return null;for(var t=u.I,e=n.e;e+r>n.e;e--)t=u.mul(t,e);return x(n.c.mul(t),n.e-r,i.ring)}).filter(x.isNonZero),i.symbol,i.ring)},polarForm:function(t){t=String(t||"u");var i=this.ring.associatedField(),u=this.deg(),l=Dn(u,function(n){return t+"_"+(n+1)});return this.terms.reduce(function(n,e){if(!e.e)return n;var t=k(u,e.e),r=t.total();return t.get().reduce(function(n,t){return n.add(w(A(i.cast(e.c).div(r),Dn(u,function(n){return-1===t.indexOf(n)?0:1})),l,i))},n)},w(A(this.cc(),Dn(u,0)),l,i))},evaluate:function(n){var t,e,r,i=this.ring,u=U.Arithmetic,l=u.O,s=this.terms;if(!s.length)return i.Zero();for(Cn(n,f)||u.isNumber(n)||!qn(n)||(n=n[this.symbol]),n=n||l,t=s[0].e,r=s[0].c,e=1;0=n.length&&e>=t.length?0:e>=t.length?0===n[e]?r(n,t,e+1):n[e]:e>=n.length?0===t[e]?r(n,t,e+1):-t[e]:n[e]===t[e]?r(n,t,e+1):n[e]-t[e]}if((xn(n)||An(n))&&(xn(t)||An(t)))return r(n,t,0);var i=r(n.e,t.e,0);return!0===e&&0===i?n.c.equ(t.c)?0:n.c.lt(t.c)?-1:1:i},sortDecr:function(n,t){return A.cmp(t,n)},gcd:function(t,e,n){return A(!0===n?Cn(t.c,[w,R,y])||Cn(e.c,[w,R,y])||!t.ring.hasGCD()?t.ring.One():t.ring.gcd(t.c,e.c):t.ring.One(),Dn(Q.max(t.e.length,e.e.length),function(n){return n=e.length);t++)if(t>=r.length){if(0r[t])return!1;return!0},pow:function(t){var e=this;return 1===(t=+t)?e:A(e.c.pow(t),Dn(e.e.length,function(n){return Q.floor(e.e[n]*t)}),e.ring)},rad:function(t){var e=this;return 1===(t=+t)?e:A(e.c.rad(t),Dn(e.e.length,function(n){return Q.max(Q.floor(e.e[n]/t),Q.min(1,e.e[n]))}),e.ring)},toTerm:function(n,t,e,r,i){var u,l=this.e,s=this.c,o=U.Arithmetic;if(!0===r){if(u=n.reduce(function(n,t,e){return 0t.e[e])&&(n=t),n},null,i),!0===n?w([r],l,u):r):!0===n?w([],l,u):A(u.Zero(),Dn(l.length,0),u):!0===n?w(i.length?[i[i.length-1]]:[],l,u):i.length?i[i.length-1]:A(0,Dn(l.length,0),u)},lm:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).e},lc:function(n){return(arguments.length?this.ltm(!1,n):this.ltm(!1)).c},tm:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).e},tc:function(n){return(arguments.length?this.ttm(!1,n):this.ttm(!1)).c},cc:function(){var n=this.terms;return n.length&&0===A.cmp(n[n.length-1].e,[0])?n[n.length-1].c:this.ring.Zero()},c:function(){return this.cc()},recur:function(l){var s,o,n,t=this,e=t.terms,c=t.symbol,m=t.ring,r=U.Arithmetic,i=null;if(!1===l)return null==t._flat&&(t._flat=c.length<=1||!t.isRecur()?t:Mn(function(n,t){return n._add(Cn(t.c,w)?w([A(m.One(),t.e,m)],c,m)._mul(t.c.recur(!1)):w([t],c,m))},w.Zero(c,m),e),t._flat._rsym=null,t._flat._flat=t._flat),t._flat;if(!0===l)return null==t._recur&&(t._recur=c.length<=1?t:Mn(function(n,t){return n.recur(t)},t.recur(!1),c),t._recur._flat=t.recur(!1),t._recur._recur=t._recur),t._recur;if(xn(l))return Mn(function(n,t){return n.recur(t)},t,l);if(l){if(c.length<=1)return t;if(l=String(l||"x"),-1===(s=c.indexOf(l))||t._rsym&&-1!==t._rsym.indexOf(l))return t;if(0===(o=t.maxdeg(l,!0)))return t._rsym=(t._rsym||[]).concat(l),t;for(n=w(Mn(function(n,t){var e,r,i=t.e[s],u=o-i;return r=Cn(t.c,w)?t.c.isUni(l)?w([t],c,m):((e=t.clone()).c=t.c.recur(l),e.e[s]=0,w([e],c,m)):0!==i?((e=t.clone()).e[s]=0,w([e],c,m)):w([t],c,m),n[u]=n[u]?n[u]._add(r):r,n},new Array(o+1),e).map(function(n,t){return n.equ(r.O)?null:A(n,Dn(c.length,function(n){return s===n?o-t:0}))}).filter(A.isNonZero),c,m);n.isConst()&&Cn(i=n.cc(),w);)n=i;return i===n&&(n=n.clone()),n._rsym=(t._rsym||[]).concat(l),n}return t},monic:function(){var n,t,e,r=this,i=U.Arithmetic,u=r.lc();if(u.equ(i.I)||u.equ(i.O)||Cn(u,w))return r;if(r.ring.isField())return w(r.terms.map(function(n){return n.div(u)}),r.symbol,r.ring);for(e=!0,n=(t=r.terms).length-1;0>=1,e=w.Mul(e,e,!1);return i&&(t=t.recur(i)),t},rad:function(n){var t=U.Arithmetic;return(n=q.cast(n)).equ(t.I)?this:mt(this,n)},compose:function(n){var t,a=this.symbol,f=this.ring,e=this._rsym,h=U.Arithmetic,d=w.Zero(a,f),g=m();return t=function n(t,e,r){for(r=r||0;r=a.length)return w(t.cc(),a,f);var i,u,l,s,o,c,m=t.terms;if(!m.length)return d;if(i=t.toString(),z.call(g,i))return g[i];for(o=z.call(e,a[r])?w(e[a[r]]||h.O,a,f):w([A(f.One(),Dn(a.length,function(n){return n===r?1:0}),f)],a,f),c=Cn(m[0].c,w)?n(m[0].c,e,r+1):w(m[0].c,a,f),u=m[0].e[r],s=c,l=1;0this.maxdeg(r,!0)?w.Zero(n,l):w(this.terms.map(function(n){var t,e;return Cn((n=n.clone()).c,w)?(e=n.e[u],t=i,0=-i?n.e[u]+=i:n.c=l.Zero(),n}).filter(A.isNonZero).sort(A.sortDecr),n,l):w(this.terms.map(function(n){return Cn((n=n.clone()).c,w)&&0this.maxdeg(r,!0)?w.Zero(n,t):w(this.terms.map(function(n){var t,e;if(Cn(n.c,w)){if(n.c.isConst(!0)){if(i>n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c._mul(t),n.e[u]-=i,n}for(n=n.clone(),e=i;e--,n.c=n.c.d(r,1)._add(n.c._mul(n.e[u])),n.e[u]=Q.max(n.e[u]-1,0),0n.e[u])return null;for(n=n.clone(),t=o,e=n.e[u];e+i>n.e[u];e--)t=l.mul(t,e);return n.c=n.c.mul(t),n.e[u]-=i,n}).filter(A.isNonZero).sort(A.sortDecr),n,t))},evaluate:function(n){var a=this.symbol,f=this.ring,h=U.Arithmetic.O,d=m();return function n(t,e,r){for(r=r||0;r=a.length)return t.cc();var i,u,l,s,o,c,m=t.terms;if(!m.length)return f.Zero();if(i=t.toString(),z.call(d,i))return d[i];for(o=(z.call(e,a[r])?e[a[r]]:h)||h,c=Cn(m[0].c,w)?n(m[0].c,e,r+1):m[0].c,u=m[0].e[r],s=c,l=1;0r[t]&&(r[t]=e.length):e.length>r&&(r=e.length),e});var e=String(n);return xn(r)?e.length>r[0]&&(r[0]=e.length):e.length>r&&(r=e.length),e})).map(function(n,t){return e+(xn(n)?n.map(function(n,t){return Hn(n,xn(r)?r[t]:r)}).join(" "):Hn(n,xn(r)?r[0]:r))+e}).join("\n")},toTex:function(n,t){return xn(n)?"\\begin{"+(t="pmatrix"===t?"pmatrix":"bmatrix")+"}"+n.map(function(n){return xn(n)?n.map(function(n){return Zn(n)}).join(" & "):Zn(n)}).join(" \\\\ ")+"\\end{"+t+"}":Zn(n)},toDec:function(n,r,e){if(!xn(n))return wn(n.toDec)?n.toDec(r):String(n);e=String(e||"|");var i=xn(n[0])?Dn(n[0].length,0):0;return(n=n.map(function(n,t){if(xn(n))return n.map(function(n,t){var e=n.toDec(r);return xn(i)?e.length>i[t]&&(i[t]=e.length):e.length>i&&(i=e.length),e});var e=n.toDec(r);return xn(i)?e.length>i[0]&&(i[0]=e.length):e.length>i&&(i=e.length),e})).map(function(n,t){return e+(xn(n)?n.map(function(n,t){return Hn(n,xn(i)?i[t]:i)}).join(" "):Hn(n,xn(i)?i[0]:i))+e}).join("\n")}},nr:0,nc:0,val:null,ring:null,_str:null,_tex:null,_n:null,_t:null,_h:null,_a:null,_i:null,_ir:null,_pi:null,_p:null,_snf:null,_lu:null,_qr:null,_ref:null,_rref:null,_evd:null,_svd:null,_rn:null,_ln:null,_rs:null,_cs:null,_tr:null,_det:null,dispose:function(){var n=this;return n._n&&n===n._n._n&&(n._n._n=null),n._t&&n===n._t._t&&(n._t._t=null,n._t._tr=null,n._t._det=null),n._h&&n===n._h._h&&(n._h._h=null),n._i&&n===n._i._i&&(n._i._i=null),n.nr=null,n.nc=null,n.val=null,n.ring=null,n._str=null,n._tex=null,n._n=null,n._t=null,n._h=null,n._a=null,n._i=null,n._ir=null,n._pi=null,n._p=null,n._snf=null,n._lu=null,n._qr=null,n._ref=null,n._rref=null,n._evd=null,n._svd=null,n._rn=null,n._ln=null,n._rs=null,n._cs=null,n._tr=null,n._det=null,n},clone:function(n){var t=this.val.map(function(n){return n.slice()});return!0===n?t:new M(this.ring,t)},map:function(r,n){var t,i=this;return t=i.val.map(function(n,e){return n.map(function(n,t){return r(n,[e,t],i)})}),!0===n?t:new M(i.ring,t)},array:function(n){var t=this;return Dn(t.nr*t.nc,n?function(n){return t.val[n%t.nr][~~(n/t.nr)]}:function(n){return t.val[~~(n/t.nc)][n%t.nc]})},row:function(n){return 0<=n&&n=e.nr?r.val[t].slice():t>=r.nr?e.val[t].slice():Dn(Q.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?e.val[t][n]:r.val[t][n].add(e.val[t][n])})})):((On(e)||In(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.add(e)}))},sub:function(e){var r=this;return Cn(e,M)?M(r.ring,Dn(Q.max(r.nr,e.nr),function(t){return t>=e.nr?r.val[t].slice():t>=r.nr?e.val[t].map(function(n){return Arithmetic.neg(n)}):Dn(Q.max(r.nc,e.nc),function(n){return n>=e.nc?r.val[t][n]:n>=r.nc?Arithmetic.neg(e.val[t][n]):r.val[t][n].sub(e.val[t][n])})})):((On(e)||In(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.sub(e)}))},mul:function(i){var u,l,s=this;return Cn(i,M)?(u=Q.min(s.nc,i.nr),l=s.ring.Zero(),M(s.ring,Dn(s.nr,function(r){return Dn(i.nc,function(n){for(var t=l,e=0;e=r.nr?e.val[t].slice():t>=e.nr?r.val[t].slice():Dn(Q.max(r.nc,e.nc),function(n){return n>=r.nc?e.val[t][n]:n>=e.nc?r.val[t][n]:r.val[t][n].mul(e.val[t][n])})})):((On(e)||In(e))&&(e=r.ring.cast(e)),r.map(function(n){return n.mul(e)}))},prod:function(u){var n,t,e,l,r,s,o=this;return Cn(u,M)?(n=o.nr,t=o.nc,e=u.nr,l=u.nc,r=n*e,s=t*l,M(o.ring,Dn(r,function(n){var r=~~(n/e),i=n%e;return Dn(s,function(n){var t=~~(n/l),e=n%l;return o.val[r][t].mul(u.val[i][e])})}))):((On(u)||In(u))&&(u=o.ring.cast(u)),o.map(function(n){return n.mul(u)}))},div:function(t){return Cn(t,f)||U.Arithmetic.isNumber(t)||In(t)?((On(t)||In(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.div(t)})):this},mod:function(t){return Cn(t,f)||U.Arithmetic.isNumber(t)||In(t)?((On(t)||In(t))&&(t=this.ring.cast(t)),this.map(function(n){return n.mod(t)})):this},divmod:function(n){return[this.div(n),this.mod(n)]},pow:function(n){var t,e,r=U.Arithmetic;if((n=q.cast(n)).lt(r.O)||n.gt(un))return null;if(0===(n=r.val(n.num)))return M.I(this.ring,this.nc);if(1===n)return this;for(t=null,e=this;0!==n;)1&n&&(t=null==t?e:e.mul(t)),n>>=1,e=e.mul(e);return t},fwdsub:function(n,t){var e,r,i,u,l,s,o,c=this.ring,m=c.Zero(),a=this.val;for(Cn(n,M)&&(n=n.col(0)),Cn(t,M)&&(t=t.diag()),n=c.cast(n),t=t&&c.cast(t),u=Q.min(this.nr,this.nc,n.length),l=new Array(u),e=0;eq&&(r.length=q),this._ref=[g,r,i]}return n?this._ref.slice():this._ref[0]},rref:function(n,t){var e,r,i,u,l,s,o,c,m,a,f=this.ring,h=f.Zero(),d=f.One(),g=f.MinusOne(),_=(this.nr,this.nc);if(null==this._rref){for(c=(a=this.ref(!0,t))[0].clone(),e=a[1],r=a[2],i=e.length,l=0;l=r.nc?t=e.nc?t=r.nr?n=e.nr?n"===n?(n=-1,i=!0):"<="===n||"=<"===n?i=!(n=1):">="!==n&&"=>"!==n||(i=!(n=-1))),u(-1===(n=-1===(n=+n)?-1:1)?function(n){for(var t=n[0],e=1,r=n.length;e=n[e]||!i&&t>n[e])return!1;t=n[e]}return!0})},LEN:function(t,n){return t=+t,u(">="===(n=n||"==")?function(n){return n.length>=t}:">"===n?function(n){return n.length>t}:"<"===n?function(n){return n.length="===(n=n||"==")||"=>"===n?function(n){return 0<=t&&t=e}:">"===n?function(n){return 0<=t&&te}:"<"===n?function(n){return 0<=t&&t="===(t=t||"==")||"=>"===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>=n}:">"===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)>n}:"<"===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)<=n}:"!="===t?function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)!==n}:function(e){return Mn(function(n,t){return e[t]>n&&(n=e[t]),n},-1/0,null,0,e.length-1,1)===n})},MIN:function(n,t){return n=+n,u(">="===(t=t||"==")||"=>"===t?function(e){return Mn(function(n,t){return e[t]=n}:">"===t?function(e){return Mn(function(n,t){return e[t]n}:"<"===t?function(e){return Mn(function(n,t){return e[t]i)return!1;return!0}:function(n){for(var t=0,e=n.length;t=i)return!1;return!0})}},filter:null,dispose:function(){return this.filter=null,this},apply:function(n,t){var e=this.filter;return!e||!wn(e)||Boolean(e.call(t||null,n))},NOT:function(){var t=this;return u(function(n){return!t.apply(n,this)})},OR:function(t){var e=this;return wn(t)||Cn(t,u)?(Cn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)||t.apply(n,this)})):e},XOR:function(r){var i=this;return wn(r)||Cn(r,u)?(Cn(r,u)||(r=u(r)),u(function(n){var t=i.apply(n,this),e=r.apply(n,this);return t&&!e||!t&&e})):i},AND:function(t){var e=this;return wn(t)||Cn(t,u)?(Cn(t,u)||(t=u(t)),u(function(n){return e.apply(n,this)&&t.apply(n,this)})):e}}),D=U.Iterator=n({constructor:function n(t,e){var r=this,i=U.Arithmetic;if(!Cn(r,n))return new n(t,e);(xn(t)||An(t))&&(Cn(t[0],n)||Cn(t[t.length-1],n))?(r.name="Iterator",r.$=e||{},r.$.seq=An(t)?G.call(t):t,r.$.count=Mn(function(n,t){return i.add(n,t.total())},i.O,r.$.seq),r.rewind()):wn(t)?(r.name="Generator",r.$={},r.$.generator=t,r.$.state=e||{},r.$.count=i.I,r.rewind()):(r.name=t||"Iterator",r.$=e||{},r.$.count=r.$.count||i.O)},__static__:{Iterable:function n(t,e){if(!Cn(this,n))return new n(t,e);e=-1===e?-1:1,this.next=function(){var n=t.hasNext(e)?t.next(e):null;return null==n?{done:!0}:{value:n}}}},name:"Iterator",$:null,__index:null,__item:null,_index:null,_item:null,__subindex:null,_subindex:null,__subitem:null,_subitem:null,dispose:function(){var n=this;return n.$.seq&&n.$.seq.length&&(Mn(function(n,t){t.dispose()},null,n.$.seq),n.$.seq=null),n.$=null,n.__index=null,n.__item=null,n._index=null,n._item=null,n.__subindex=null,n._subindex=null,n.__subitem=null,n._subitem=null,n},filterBy:function(n){var t=this.$;return!1===n?t.filter&&(t.filter=null):(Cn(n,u)||wn(n))&&(t.filter=Cn(n,u)?n:u(n)),this},mapTo:function(n){var t=this.$;return!1===n?t.output&&(t.output=null):wn(n)&&(t.output=n),this._item=this.output(this.__item),this},fuse:function(n,t,e){var r=this.$;return 1===arguments.length&&!1===n?r.sub&&(r.sub=null,r.submethod=null,r.subcascade=null,r.subcount=null,this.rewind()):Cn(t,D)&&wn(n)&&(r.sub=t,r.submethod=n,r.subcascade=-1===e?-1:1,r.subcount=U.Arithmetic.mul(r.count,t.total()),this.rewind()),this},unfuse:function(){return this.fuse(!1)},juxtaposeWith:function(n,t){return this.fuse(function(n,t){return[].concat(n).concat(t)},n,t)},state:function(n){return arguments.length?(this.$.state=n,this):this.$.state},output:function(n){var t=this.$.output;return null==n?null:wn(t)?t(n):n},fusion:function(n,t){var e,r=this.$;return r.sub?(-1===r.subcascade&&(e=n,n=t,t=e),null==n||null==t?n||t||null:r.submethod.call(this,n,t)):n},order:function(){return this},rewind:function(n,t){var e,r,i,u=this,l=u.$;if(n=-1===n?-1:1,xn(l.seq)){for(e=0,r=l.seq.length;e=u.seq.length)&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),r=i.__item,i.__subitem=u.sub.next(n)),i.__item=r,i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null}while(u.filter&&null!=e&&!u.filter.apply(e,i));return e}if(wn(u.generator)){for(;t=i.__item,e=u.sub?i._subitem:i._item,i.__item=u.generator.call(i,t,n,u.state,!1),null==i.__item&&u.sub&&u.sub.hasNext(n)&&(i.rewind(n,!0),i.__subitem=u.sub.next(n)),i._item=i.output(i.__item),i._subitem=u.sub&&null!=i._item&&null!=i.__subitem?i.fusion(i._item,i.__subitem):null,u.filter&&null!=e&&!u.filter.apply(e,i););return e}return null},get:function(n){var t,e,r=[];if(wn(n))for(;this.hasNext()&&null!=(t=this.next())&&n(t);)r.push(t);else for(e=!arguments.length||null==n,null!=n&&(n=+n);(e||r.length=o.$.mindimension&&u<=o.$.maxdimension){if(l=o[X].rank(n,o.n,o.$),m.gt(l,f)){c=!0;break}s=m.add(s,o.total())}return c?m.add(l,s):f}return pn()},unrank:function(n,t,e){if(e&&"sequence"===e.type){var r,i,u=U.Arithmetic,l=u.O,s=e.seq;if(!s||!s.length)return null;if(null==n||!u.inside(n,u.J,null!=e.count?e.count:this.count(t,e)))return null;for(i=s.length,r=0;u.gte(n,s[r].total())&&(n=u.sub(n,s[r].total()),!(i<=++r||u.lt(n,l))););return rc&&(c=e[n]+1),e[n]):c+r[n-e.length]}:function(n){return nl&&(r.length=l),_<0&&1n[1]&&(n[1]=t),n},[1/0,0],r);if(n.base=r,n.minbase=s[0],n.maxbase=s[1],n.dimension=r.length,"gray"===n.output)n.output=function(n,t){return e.gray(n,t)};else if("inversion"===n.output)n.output=function(n,t){return e.inversion(n)};else if(xn(n.output)){var o=n.output;n.output=function(n,t){return e.component(n,o)}}}E.call(this,"Tensor",r,n,t?{method:"partial"===n.type?n.submethod||"complete":n.submethod,iter:t,pos:"partial"===n.type?n.subpos||n.position:n.subpos,cascade:n.subcascade}:null)},__static__:{C:E.C,P:E.P,T:E.T,DUAL:E.DUAL,count:function(n,t){var e=U.Arithmetic.O,r=t&&t.type?t.type:"tensor";return"partial"===r?t.data&&t.data.length?U.Arithmetic.num(t.data.length):e:"tuple"===r?!n||n[0]<=0?e:Gt(n[1],n[0]):n&&n.length?nt(n):e},initial:function(t,n,e){var r,i=n&&n.type?n.type:"tensor",u=n&&n.order?n.order:hn;return e=-1===e?-1:1,(!(dn&u)&&fn&u||dn&u&&!(fn&u))&&(e=-e),r="partial"===i?n.data&&n.data.length?e<0?n.data[n.data.length-1]:n.data[0]:null:(r="tuple"===i?t[0]?Dn(t[0],e<0?t[1]-1:0,0):[]:t.length?e<0?Dn(t.length,function(n){return t[n]-1}):Dn(t.length,0,0):[],this.DUAL(r,t,n))},succ:function(n,t,e,r,i,u){if(!e||null==n)return null;var l,s=r&&r.type?r.type:"tensor",o=r&&null!=r.order?r.order:hn,c=U.Arithmetic;return i=-1===i?-1:1,"partial"===s?r.data&&r.data.length?(fn&o&&(i=-i,null!=t&&(t=c.sub(c.num(r.data.length-1),t))),null==t&&(t=xe(r.data,n,!0)),l=c.val(t),i<0?0<=l-1?r.data[l-1]:null:0<=l&&l+1=t+r[e].length&&(t+=r[e++].length),t+r[e][n-t]})},component:function(t,e){return null==t?null:null==e?t:Dn(t.length,function(n){return n=r.length||null==r[n])return e[n];var t=r[n];return On(t)?e[n]+t:t[0]*e[n]+(t[1]||0)})}:yn},conditional:ie,generate:function(n,t,i,u,l){function s(n){return _<=n&&n<=v}l=l||{},i=i||Dn(t.length||0,0,1);var e,r,o,c,m,a,f,h,d,g,_=null==l.min?0:l.min,v=null==l.max?n-1:l.max,b=v-_+1,p=t,y=p.length,x=!1,A=[],q=[],I={};for(x=!(t=[]),o=a=0;oe[1]?oe(n,Dn(e[0]-e[1]+1,e[1],1).filter(s)).reverse():oe(n,Dn(e[1]-e[0]+1,e[0],1).filter(s)):oe(n,e[1].split(",").map(Number).filter(s))).length){x=!0;break}t.push(c)}else if(e=r.match(Y)){if(!(c=0e[1]?Dn(e[0]-e[1]+1,e[0],-1):Dn(e[1]-e[0]+1,e[0],1)).filter(s):e[1].split(",").map(Number).filter(s)).length){x=!0;break}t.push(c)}else{if(h=!0,f=[],d=null,r=r.replace(K,function(n,t){var e=parseInt(t,10),r="v"+String(e);return!isNaN(e)&&s(e)||(h=!1),h&&-1===f.indexOf(e)&&f.push(e),r}),!h){i&&i.splice(a--,1);continue}f.sort(Bn());try{d=new Function(f.map(function(n){return"v"+String(n)}).join(","),"return Math.floor("+r+");")}catch(n){d=null}if(!wn(d)){i&&i.splice(a--,1);continue}for(m=0;m"===u?sn:"<"===u?on:"<="===u||"=<"===u?an:">"===u?cn:(">="===u||"=>"===u)&&mn,g=wn(l.extra_conditions)?function(n,t,e){var r=n[t];return!(r<_||vr||cn===u&&i[i.length-1]-i[t]>r)&&l.extra_conditions(n,t,e)}:function(n,t,e){var r=n[t];return!(r<_||vr||cn===u&&i[i.length-1]-i[t]>r)},!0===l.lazy?t:ie(t,u,g))}}}),U.Permutation=n(E,{constructor:function n(t,e){var r=null;if(!Cn(this,n))return new n(t,e);(e=e||{}).type=String(e.type||"permutation").toLowerCase(),Cn(t=t||0,E)?t=(r=t).dimension():r=e.sub,e.base=e.dimension=t,e.rand=e.rand||{},e.rand.derangement=1,e.rand.involution=1,e.rand.connected=1,"multiset"===e.type&&(e.multiplicity=xn(e.multiplicity)&&e.multiplicity.length?e.multiplicity.slice():Dn(t,1,0),e.multiplicity=e.multiplicity.concat(Dn(t-Mn(Kn,0,e.multiplicity),1,0)),e.base=e.multiplicity.length,e.multiset=de(e.multiplicity,t)),E.call(this,"Permutation",t,e,r?{method:e.submethod,iter:r,pos:e.subpos,cascade:e.subcascade}:null)},__static__:{C:E.C,P:E.P,T:E.T,DUAL:E.DUAL,count:function(n,t){var e=U.Arithmetic,r=e.O,i=t&&t.type?t.type:"permutation",u=t&&null!=t["cycles="]?0|t["cycles="]:null,l=t&&null!=t["fixed="]?0|t["fixed="]:null;return n<0?r:"cyclic"===i?e.num(n):"multiset"===i?Wt(n,t.multiplicity):"derangement"===i?l?n-l<2?r:e.mul(Wt(n,l),Wt(n-l,!1)):n<2?r:Wt(n,!1):"involution"===i?Wt(n,!0):"connected"===i?Wt(n-1):u?Vt(n,u,1):Wt(n)},initial:function(n,t,e){var r,i=t&&t.type?t.type:"permutation",u=t&&null!=-t.order?t.order:hn,l=t&&null!=t["cycles="]?0|t["cycles="]:null,s=t&&null!=t["fixed="]?0|t["fixed="]:null;if(0===n)return[];if(e=-1===e?-1:1,(!(dn&u)&&fn&u||dn&u&&!(fn&u))&&(e=-e),"cyclic"===i)r=e<0?[n-1].concat(Dn(n-1,0,1)):Dn(n,0,1);else if("derangement"===i){if(s||n<2)return null;if(1&n){var o=Q.floor(n/2);r=e<0?Dn(n-o-1,n-1,-1).concat([o-1,o]).concat(Dn(o-1,o-2,-1)):Dn(n-3,function(n){return 1&n?n-1:n+1}).concat([n-2,n-1,n-3])}else r=e<0?Dn(n,n-1,-1):Dn(n,function(n){return 1&n?n-1:n+1})}else r="multiset"===i?e<0?t.multiset.slice().reverse():t.multiset.slice():"connected"===i?null:"involution"===i?e<0?Dn(n,n-1,-1):Dn(n,0,1):l?null:e<0?Dn(n,n-1,-1):Dn(n,0,1);return r=this.DUAL(r,n,t)},succ:function(n,t,e,r,i,u){if(!e||e<=0||null==n)return null;var l=r&&r.type?r.type:"permutation",s=r&&null!=r["cycles="]?0|r["cycles="]:null,o=r&&null!=r["fixed="]?0|r["fixed="]:null;return"derangement"===l&&o||"permutation"===l&&s?null:function(n,t,e,r,i,u){var l,s,o,c,m,a,f,h,d,g,_,v,b,p=t,y=null==u?p:u;f=b=p-1,_=d=h=1,v=g=0,dn&i&&(h=-h,f=b-f,d=-d,g=y-1-g,e=-e);2&i&&(h=-h,f=b-f,_=-1,v=y-1);fn&i&&(e=-e);if(e<0)if("cyclic"===r)if(0=d*n[l+h];)l-=h;if(0<=l&&l<=b){for(s=f;0<=s&&s<=b&&0=d*n[s];)s-=h;for(m=n[l],n[l]=n[s],n[s]=m,o=l+h,c=f;0<=o&&o<=b&&0<=c&&c<=b&&0=l&&(i=0,r++);else for(i=r=0;r=l&&(i=0,r++);return n}:function(n,t,e){var r,i,u=t.length,l=u*u;for(n=n||new Array(l),i=r=0;r=u&&(i=0,r+=u);if(!0===e)for(r=0;rt)return!1;return!0!==e||r===t},isInvolution:function(n){for(var t=n.length,e=0,r=n[e];e="===e||"=>"===e?t<=l:l===t}},_update:function(){return this.item__=(this.__item,this.n,this.$.order,this.$.type,null),this}}),(k=U.Combination=n(E,{constructor:function e(n,t,r){var i=null;if(!Cn(this,e))return new e(n,t,r);if(xn(n)||An(n)?(r=t||{},t=n[1]||0,n=n[0]||0):(r=r||{},n=n||0,t=t||0),r.type=String(r.type||"combination").toLowerCase(),-1p||b&&0n[l-a]+v){o=l;break}if(!(0<=o&&o<=f)&&0n[c-s]+1?(--n[c],n[c+s]=f,n[a]++):n[a]--:n[a]=0:n=null:0===n[a]?(n[i]=0*m+0,n[a]=1):m*n[o]+0n[s]+1?(n[l]=n[s],n[s]=i):(i===n[l]&&n[y][1]--,n[l]--,n[s]++,i===n[s]&&n[y][1]++)}else if(dn&u)if((a=n[o])n[y][0]){for(l=c,d=0;_<=l&&l<=v&&1===n[l];)l-=g,d++;if(a=n[l]-1,n[l]=a,0<++d)if(_<=l+g&&l+g<=v)n[l+=g]=d,d=0,n[y][0]=g<0?p-l:l+1;else for(;0n[l]+1&&d-(m-1)-1n[l]+1?(n[s]=n[l],n[l]=i):(i===n[s]&&n[y][1]--,n[l]++,n[s]--,i===n[l]&&n[y][1]++)}else if(dn&u)if(b-r+1>n[c]){for(l=o;_<=l&&l<=v&&1===n[l];)l+=g;a=n[l],n[l]=1,n[o]=a-1,_<=l+g&&l+g<=v&&n[l+g]++}else n=null;else if(b-r+1>n[o]){for(l=c;_<=l&&l<=v&&1===n[l];)l-=g;a=n[l],n[l]=1,n[c]=a-1,_<=l-g&&l-g<=v&&n[l-g]++}else n=null;else if(dn&u)n=null;else if(i)if(d=n[c],l=c-g,m=n[y][0]-1,1===n[y][1]&&d===i)if(b===i)n=null;else for(d+=n[l]-i,n[l]=i,n[y][0]--;0n[o])for(d=n[c],n[c-g]++,n[y][0]--,l=c-g,d--;0m||n[o+(m-1)*g]n[0]&&(e-t+un[0]){for(n[u]--,c[u]=c[u-1],l=u+1;l>>1,a=new Array(u);for(t=0;t>>1;for(_=new Array(t),e=0;e>>1==(r+1&3)>>>1?p-i:i+1;else{for(u=n(y),m=(c=(o=s=y*y)<<1)+s,r=e=i=0;i>>1,r=0;r=i&&(f=0,i<=++m&&(o+=i,f=m=0,r<=++a&&(c++,s+=i,f=m=o=a=0),c