From fa930086ed26efe528801a16c4928cb8de54824e Mon Sep 17 00:00:00 2001 From: Nikos M Date: Fri, 24 Jun 2016 18:46:12 +0300 Subject: [PATCH] updates, orderings et al.. --- README.md | 6 +- src/js/Abacus.js | 545 ++++++++++++++++------------ src/js/Abacus.min.js | 2 +- test/combinations.txt | 28 +- test/combinations_repeats.txt | 92 ++--- test/partitions.txt | 24 +- test/permutations-bigint.txt | 82 ++--- test/permutations.txt | 54 +-- test/{powersets.js => subsets.js} | 8 +- test/{powersets.txt => subsets.txt} | 80 ++-- test/tensors.txt | 8 +- test/test.bat | 2 +- test/tuples.txt | 38 +- 13 files changed, 521 insertions(+), 448 deletions(-) rename test/{powersets.js => subsets.js} (91%) rename test/{powersets.txt => subsets.txt} (72%) diff --git a/README.md b/README.md index e0996db..2269d87 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,7 @@ see: `test/test.bat` * `test/permutations-bigint.js` * `test/combinations.js` * `test/combinations_repeats.js` -* `test/powersets.js` +* `test/subsets.js` * `test/tensors.js` * `test/tuples.js` * `test/partitions.js` **in-complete, in progress** @@ -271,7 +271,7 @@ see: `test/test.bat` most algorithms: -* are **linear** `O(n)` (or log-linear `O(nlgn)`) time and space algorithms +* are **linear** `O(n)` (or log-linear `O(nlgn)`) **time and space** algorithms * are **statisticaly unbiased** (e.g uniform sampling methods) * use **efficient successor methods** (e.g loopless methods / constant delay methods) to generate next/prev object from current object (supporting multiple combinatorial orderings along the way, see below) * **avoid big-integer arithmetic and computational overhead** (except if explicit ranking / unranking is needed and objects are large) @@ -281,7 +281,7 @@ most algorithms: ###Todo -* support **multiple custom iterator orderings**, i.e `LEX`, `COLEX`, `REVLEX`, `REVCOLEX`, `RANDOM`, `STOCHASTIC` (where applicable) seamlessly and uniformly [ALMOST DONE, NEW FEATURE] +* support **multiple custom iterator orderings**, i.e `LEX`, `COLEX`, `REVLEX`, `REVCOLEX`, `MINIMAL`, `RANDOM`, `STOCHASTIC` (where applicable) seamlessly and uniformly, both forward and backward [ALMOST DONE, NEW FEATURE] * support **efficient ranking / unranking algorithms** and associated methods (preferably of `O(n)` or `O(nlgn)` complexity) for supported orderings [DONE] * support **unique and uniform random ordering traversals** for all combinatorial objects, so that the space of a combinatorial object can be traversed in any random ordering uniquely and unbiasedly (useful in some applications, eg backtracking) [DONE, see reference, used as custom iterator ordering, see above] * make sure the `.random` methods **uniformly and unbiasedly sample the combinatorial object space** (methods use unbiased sampling algorithms, however results in certain cases might depend on [quality of PRNGs](http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf)) [DONE] diff --git a/src/js/Abacus.js b/src/js/Abacus.js index 01c5ffd..676fb7b 100644 --- a/src/js/Abacus.js +++ b/src/js/Abacus.js @@ -51,6 +51,13 @@ var Abacus = {VERSION: "0.1.0"} ,to_fixed_binary_string_32 = to_fixed_binary_string( 32 ) // http://jsperf.com/functional-loop-unrolling/2 // http://jsperf.com/functional-loop-unrolling/3 + ,operation = function operation( F, F0, i0, i1 ) { + if ( i0 > i1 ) return F0; + var i, k, l=i1-i0+1, r=l&15, q=r&1, Fv=q?F(F0,i0):F0; + for (i=q; i i1 ) return F0; - var i, k, l=i1-i0+1, r=l&15, q=r&1, Fv=q?F(F0,i0):F0; - for (i=q; i=0; a--) + { + vv = v[ a ].length < k ? null : v[ a ][ k ]; + if ( vv instanceof Array ) + { + // cartesian can be re-used to create higher-order products + // i.e cartesian(alpha, beta, gamma) and cartesian(cartesian(alpha, beta), gamma) + // should produce exactly same results + for (j=vv.length-1; j>=0; j--) + vector.unshift( vv[ j ] ); + } + else + { + vector.unshift( vv ); + } + } + product[ k ] = vector; + } + return product; + } ,shuffle = function shuffle( a, cyclic, copied ) { // http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Sattolo.27s_algorithm - var rnd = Abacus.Arithmetic.rnd, + var rnd = Abacus.Util.rint, N, perm, swap, ac, offset; ac = true === copied ? a.slice() : a; offset = true === cyclic ? 1 : 0; @@ -267,9 +299,9 @@ var Abacus = {VERSION: "0.1.0"} } ,pick = function pick( a, k, non_destructive ) { // http://stackoverflow.com/a/32035986/3591273 - var rnd = Abacus.Arithmetic.rnd, + var rnd = Abacus.Util.rint, picked, backup, i, selected, value, n = a.length; - k = Abacus.Arithmetic.min( k, n ); + k = Abacus.Util.min( k, n ); picked = new Array( k ); non_destructive = false !== non_destructive; if ( non_destructive ) backup = new Array( k ); @@ -299,25 +331,45 @@ var Abacus = {VERSION: "0.1.0"} } return picked; } - ,complement = function complement( alpha, N ) { - var beta, n, a, b, k = alpha.length; - beta = new Array( N-k ); n=0; a=0; b=0; - while ( n < N ) + ,complement = function complement( alpha, N, size_complement, dim_array ) { + // useful for transformations to/from lex / co-lex (actually rev-co-lex) orders + if ( null == alpha ) return null; + if ( true === size_complement ) { - if ( a>=k || n= k) || (n < alpha[a]) ) + { + beta[b++] = n; + } + else + { + a++; + } + n++; + } + return beta; + } + else + { + if ( !alpha.length ) return []; + var i, k = alpha.length, beta = new Array(k); + if ( true === dim_array ) for (i=0; i>>0; + return Abacus.Arithmetic.shl(1, /*Abacus.Arithmetic.num(*/ n /*)*/);//(1 << n)>>>0; } ,powNK = function powNK( n, k ) { - return Abacus.Arithmetic.pow(n, k); + return Abacus.Arithmetic.pow(/*Abacus.Arithmetic.num(*/ n /*)*/, /*Abacus.Arithmetic.num(*/ k /*)*/); } ,factorial = function factorial( n ) { + //n = Abacus.Arithmetic.num( n ); var mul = Abacus.Arithmetic.mul; if ( 0 > n ) return 0; else if ( 2 > n ) return 1; @@ -361,6 +414,8 @@ var Abacus = {VERSION: "0.1.0"} else return operation(mul, 1, 2, n); } ,binomial = function binomial( n, k ) { + //n = Abacus.Arithmetic.num( n ); + //k = Abacus.Arithmetic.num( k ); if ( k > n-k ) k = n-k; // take advantage of symmetry if ( 0 > k || 1 > n ) return 0; else if ( 0 === k || 1 === n ) return 1; @@ -397,16 +452,17 @@ var Abacus = {VERSION: "0.1.0"} } return p; } - ,LEX = 8, REVLEX = 16, COLEX = 32, REVCOLEX = 64, GRAY = 128, RANDOM = 256, STOCHASTIC = 512 - ,ORDERINGS = LEX | REVLEX | COLEX | REVCOLEX | GRAY | RANDOM | STOCHASTIC + ,LEX = 8, REVLEX = 16, COLEX = 32, REVCOLEX = 64, MINIMAL = 128, RANDOM = 256, STOCHASTIC = 512 + ,LEXICAL = LEX | REVLEX | COLEX | REVCOLEX | MINIMAL + ,REVERSED = REVLEX | REVCOLEX ,RANDOMISED = RANDOM | STOCHASTIC + ,ORDERINGS = LEXICAL | RANDOMISED ,ORDER = function ORDER( o ) { if ( !arguments.length || null == o ) return LEX; // default if ( o.substr ) { o = o.toUpperCase( ); return Abacus.ORDER[HAS](o) ? Abacus.ORDER[o] : LEX; } return ORDERINGS & o ? o : LEX; } - ,BitArray, CombinatorialIterator - ,Permutation, Combination, CombinationRepeat, Partition, Powerset, Tensor, Tuple + ,CombinatorialIterator, Permutation, Combination, CombinationRepeat, Partition, Subset, Tensor, Tuple ,NotImplemented = function( method ) { return !arguments.length ? function( ) { @@ -418,6 +474,30 @@ var Abacus = {VERSION: "0.1.0"} } ; +// combinatorial objects iterator ordering patterns +// https://oeis.org/wiki/Orderings +Abacus.ORDER = { + + LEX: LEX +,LEXICOGRAPHIC: LEX +,REVLEX: REVLEX +,ANTILEX: REVLEX +,REVERSELEXICOGRAPHIC: REVLEX +,ANTILEXICOGRAPHIC: REVLEX +,COLEX: COLEX +,COLEXICOGRAPHIC: COLEX +,REVCOLEX: REVCOLEX +,ANTICOLEX: REVCOLEX +,REVERSECOLEXICOGRAPHIC: REVCOLEX +,ANTICOLEXICOGRAPHIC: REVCOLEX +,GRAY: MINIMAL +,MINIMAL: MINIMAL +,RANDOM: RANDOM +,RANDOMISED: RANDOM +,STOCHASTIC: STOCHASTIC + +}; + Abacus.Util = { rnd: Math.random @@ -508,31 +588,7 @@ Abacus.Arithmetic = { }; -// combinatorial objects iterator ordering patterns -// https://oeis.org/wiki/Orderings -Abacus.ORDER = { - - LEX: LEX -,LEXICOGRAPHIC: LEX -,REVLEX: REVLEX -,ANTILEX: REVLEX -,REVERSELEXICOGRAPHIC: REVLEX -,ANTILEXICOGRAPHIC: REVLEX -,COLEX: COLEX -,COLEXICOGRAPHIC: COLEX -,REVCOLEX: REVCOLEX -,ANTICOLEX: REVCOLEX -,REVERSECOLEXICOGRAPHIC: REVCOLEX -,ANTICOLEXICOGRAPHIC: REVCOLEX -//,GRAY: GRAY -//,MINIMAL: GRAY -,RANDOM: RANDOM -,RANDOMISED: RANDOM -,STOCHASTIC: STOCHASTIC - -}; - -BitArray = Abacus.BitArray = Class({ +Abacus.BitArray = Class({ constructor: function BitArray(n) { var self = this; @@ -552,7 +608,7 @@ BitArray = Abacus.BitArray = Class({ } ,clone: function( ) { - var self = this, c = new BitArray(self.length); + var self = this, c = new Abacus.BitArray(self.length); c.bits = new Uint32Array( self.bits ); return c; } @@ -622,22 +678,21 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ ,last: NotImplemented( ) ,stochastic: NotImplemented( ) ,dual: function( item, n, order ) { - return 0 >= n ? [] : reverse_complement( item, n ); + return null == item ? null : ((LEX|REVLEX)&order ? item.slice( ) : reverse( complement( item, n ) )); } - ,succ: function( offset, item, n, total ) { + ,succ: function( offset, item, n, total, order ) { var klass = this, Arithmetic = Abacus.Arithmetic; - if ( -1 !== offset && 1 !== offset ) offset = 1; - return item ? klass.unrank( Arithmetic.add(klass.rank( item, n, total ), offset), n, total ) : null; + if ( (-1 !== offset) && (1 !== offset) ) offset = 1; + return null == item ? null : klass.unrank( Arithmetic.add(klass.rank( item, n, total ), offset), n, total ); } ,rand: function( n, total ) { var klass = this, Arithmetic = Abacus.Arithmetic, tot = total ? total : klass.count( n ), - tot_1 = Arithmetic.sub(tot,1), - r = Arithmetic.rnd(0, tot_1); + tot_1 = Arithmetic.sub(tot,1), r = Arithmetic.rnd(0, tot_1); return Arithmetic.equ(0, r) - ? klass.first( n ) + ? klass.first( n/*, LEX*/ ) : (Arithmetic.equ(r, tot_1) - ? klass.last( n ) + ? klass.last( n/*, LEX*/ ) : klass.unrank( r, n, tot )); } } @@ -745,31 +800,36 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ else if ( RANDOM & order ) { // lazy init - if ( !self._traversed ) self._traversed = new BitArray( tot ); + if ( !self._traversed ) self._traversed = new Abacus.BitArray( tot ); else self._traversed.reset( ); self._traversed.set( r=self.randomIndex( ) ); self.__item = self.item( r, LEX ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self._item = null == self.__item ? null : self.__item.slice( ); + } + else if ( MINIMAL & order ) + { + /* TODO */ + self._item = self.__item = null; } else if ( REVCOLEX & order ) { - self.__item = reverse ? klass.last( n ) : klass.first( n ); + self.__item = reverse ? klass.last( n, REVCOLEX ) : klass.first( n, REVCOLEX ); self._item = klass.dual( self.__item, n, REVCOLEX ); } else if ( COLEX & order ) { - self.__item = reverse ? klass.first( n ) : klass.last( n ); + self.__item = reverse ? klass.first( n, COLEX ) : klass.last( n, COLEX ); self._item = klass.dual( self.__item, n, COLEX ); } else if ( REVLEX & order ) { - self.__item = reverse ? klass.first( n ) : klass.last( n ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self.__item = reverse ? klass.first( n, REVLEX ) : klass.last( n, REVLEX ); + self._item = klass.dual( self.__item, n, REVLEX ); } else /*if ( LEX & order )*/ { - self.__item = reverse ? klass.last( n ) : klass.first( n ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self.__item = reverse ? klass.last( n, LEX ) : klass.first( n, LEX ); + self._item = klass.dual( self.__item, n, LEX ); } self._prev = (RANDOMISED & order) || !reverse ? false : null != self._item; self._next = reverse && !(RANDOMISED & order) ? false : null != self._item; @@ -787,13 +847,19 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ if ( Arithmetic.gte(index, 0) && Arithmetic.lt(index, tot) ) { tot_1 = Arithmetic.sub(tot, 1); - if ( REVCOLEX & order ) + if ( MINIMAL & order ) + { + /* TODO */ + self._index = index; + self._item = self.__item = null; + } + else if ( REVCOLEX & order ) { self._index = index; self.__item = Arithmetic.equ(0, index) - ? klass.first( n ) + ? klass.first( n, REVCOLEX ) : (Arithmetic.equ(tot_1, index) - ? klass.last( n ) + ? klass.last( n, REVCOLEX ) : klass.unrank( index, n, tot )); self._item = klass.dual( self.__item, n, REVCOLEX ); } @@ -801,9 +867,9 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ { self._index = index; self.__item = Arithmetic.equ(0, index) - ? klass.last( n ) + ? klass.last( n, COLEX ) : (Arithmetic.equ(tot_1, index) - ? klass.first( n ) + ? klass.first( n, COLEX ) : klass.unrank( Arithmetic.sub(tot_1,index), n, tot )); self._item = klass.dual( self.__item, n, COLEX ); } @@ -811,31 +877,51 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ { self._index = index; self.__item = Arithmetic.equ(0, index) - ? klass.last( n ) + ? klass.last( n, REVLEX ) : (Arithmetic.equ(tot_1, index) - ? klass.first( n ) + ? klass.first( n, REVLEX ) : klass.unrank( Arithmetic.sub(tot_1,index), n, tot )); - self._item = self.__item.slice( ); + self._item = klass.dual( self.__item, n, REVLEX ); } else if ( LEX & order ) { self._index = index; self.__item = Arithmetic.equ(0, index) - ? klass.first( n ) + ? klass.first( n, LEX ) : (Arithmetic.equ(tot_1, index) - ? klass.last( n ) + ? klass.last( n, LEX ) : klass.unrank( index, n, tot )); - self._item = self.__item.slice( ); + self._item = klass.dual( self.__item, n, LEX ); } } return self; } + ,randomIndex: function( m, M ) { + var self = this, Arithmetic = Abacus.Arithmetic, tot = self._count, argslen = arguments.length; + if ( 0 === argslen ) + { + m = 0; + M = Arithmetic.sub(tot,1); + } + else if ( 1 === argslen ) + { + m = Arithmetic.num( m || 0 ); + M = Arithmetic.sub(tot,1); + } + else + { + m = Arithmetic.num( m ); + M = Arithmetic.num( M ); + } + return Arithmetic.rnd( m, M ); + } + ,item: function( index, order ) { if ( !arguments.length ) return this._item; var self = this, n = self.n, tot = self._count, tot_1, - klass = self[CLASS], Arithmetic = Abacus.Arithmetic, traversed, r; + klass = self[CLASS], Arithmetic = Abacus.Arithmetic, traversed, r, rs; order = null != order ? ORDER( order ) : self._order; index = Arithmetic.num( index ); @@ -847,66 +933,57 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ { traversed = self._traversed; // get next un-traversed index, reject if needed - while ( traversed.isset( r = self.randomIndex( ) ) ) ; + r = self.randomIndex( ); rs = Abacus.Util.rnd( ) > 0.5 ? -1 : 1; + while ( traversed.isset( r ) ) + { + r = Arithmetic.add(r, rs); + if ( Arithmetic.lt(r, 0) ) r = tot_1; + else if ( Arithmetic.gte(r, tot) ) r = 0; + } traversed.set( r ); return klass.unrank( r, n, tot ); } + else if ( MINIMAL & order ) + { + /* TODO */ + return null; + } else if ( REVCOLEX & order ) { return klass.dual( Arithmetic.equ(0, index) - ? klass.first( n ) + ? klass.first( n, REVCOLEX ) : (Arithmetic.equ(tot_1, index) - ? klass.last( n ) + ? klass.last( n, REVCOLEX ) : klass.unrank( index, n, tot )), n, REVCOLEX ); } else if ( COLEX & order ) { return klass.dual( Arithmetic.equ(0, index) - ? klass.last( n ) + ? klass.last( n, COLEX ) : (Arithmetic.equ(tot_1, index) - ? klass.first( n ) + ? klass.first( n, COLEX ) : klass.unrank( Arithmetic.sub(tot_1,index), n, tot )), n, COLEX ); } else if ( REVLEX & order ) { - return Arithmetic.equ(0, index) - ? klass.last( n ) + return klass.dual( Arithmetic.equ(0, index) + ? klass.last( n, REVLEX ) : (Arithmetic.equ(tot_1, index) - ? klass.first( n ) - : klass.unrank( Arithmetic.sub(tot_1,index), n, tot )); + ? klass.first( n, REVLEX ) + : klass.unrank( Arithmetic.sub(tot_1,index), n, tot )), n, REVLEX ); } else //if ( LEX & order ) { - return Arithmetic.equ(0, index) - ? klass.first( n ) + return klass.dual( Arithmetic.equ(0, index) + ? klass.first( n, LEX ) : (Arithmetic.equ(tot_1, index) - ? klass.last( n ) - : klass.unrank( index, n, tot )); + ? klass.last( n, LEX ) + : klass.unrank( index, n, tot )), n, LEX ); } } return null; } - ,randomIndex: function( m, M ) { - var self = this, Arithmetic = Abacus.Arithmetic, tot = self._count, argslen = arguments.length; - if ( 0 === argslen ) - { - m = 0; - M = Arithmetic.sub(tot,1); - } - else if ( 1 === argslen ) - { - m = Arithmetic.num( m || 0 ); - M = Arithmetic.sub(tot,1); - } - else - { - m = Arithmetic.num( m ); - M = Arithmetic.num( M ); - } - return Arithmetic.rnd( m, M ); - } - ,random: function( ) { var self = this, klass = self[CLASS]; return klass.rand( self.n, self._count ); @@ -916,13 +993,21 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ return this.order( this._order, true ); } + ,forward: function( ) { + return this.order( this._order, false ); + } + ,hasNext: function( ) { return STOCHASTIC & this._order ? true : this._next; } + ,hasPrev: function( ) { + return RANDOMISED & this._order ? false : this._prev; + } + ,next: function( ) { var self = this, Arithmetic = Abacus.Arithmetic, order = self._order, traversed, r, - klass = self[CLASS], current = self._item, n = self.n, tot = self._count; + klass = self[CLASS], current = self._item, n = self.n, tot = self._count, tot_1, rs; if ( STOCHASTIC & order ) { @@ -931,20 +1016,25 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ } else if ( RANDOM & order ) { - if ( Arithmetic.lt(Arithmetic.add(self._index,1), tot) ) + tot_1 = Arithmetic.sub(tot, 1); + if ( Arithmetic.lt(self._index, tot_1) ) { - self._index = Arithmetic.add(self._index, 1); traversed = self._traversed; // get next un-traversed index, reject if needed - while ( traversed.isset( r = self.randomIndex( ) ) ) ; + r = self.randomIndex( ); rs = Abacus.Util.rnd( ) > 0.5 ? -1 : 1; + while ( traversed.isset( r ) ) + { + r = Arithmetic.add(r, rs); + if ( Arithmetic.lt(r, 0) ) r = tot_1; + else if ( Arithmetic.gt(r, tot_1) ) r = 0; + } traversed.set( r ); self.__item = self.item( r, LEX ); - self._item = null != self.__item ? self.__item.slice( ) : null; - self._next = null != self._item; + self._item = null == self.__item ? null : self.__item.slice( ); } else { - self._next = false; + self._item = self.__item = null; if ( self._traversed ) { self._traversed.dispose( ); @@ -955,40 +1045,37 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ else { // compute next, using successor methods / loopless algorithms, WITHOUT using big integer arithemtic - if ( REVCOLEX & order ) + if ( MINIMAL & order ) { - self.__item = klass.succ( 1, self.__item, n, tot ); + /* TODO */ + self._item = self.__item = null; + } + else if ( REVCOLEX & order ) + { + self.__item = klass.succ( 1, self.__item, n, tot, REVCOLEX ); self._item = klass.dual( self.__item, n, REVCOLEX ); } else if ( COLEX & order ) { - self.__item = klass.succ( -1, self.__item, n, tot ); + self.__item = klass.succ( -1, self.__item, n, tot, COLEX ); self._item = klass.dual( self.__item, n, COLEX ); } else if ( REVLEX & order ) { - self.__item = klass.succ( -1, self.__item, n, tot ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self.__item = klass.succ( -1, self.__item, n, tot, REVLEX ); + self._item = klass.dual( self.__item, n, REVLEX ); } else /*if ( LEX & order )*/ { - self.__item = klass.succ( 1, self.__item, n, tot ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self.__item = klass.succ( 1, self.__item, n, tot, LEX ); + self._item = klass.dual( self.__item, n, LEX ); } - self._next = null != self._item; - if ( self._next ) self._index = Arithmetic.add(self._index, 1); } + self._next = null != self._item; + if ( self._next && !(STOCHASTIC & order) ) self._index = Arithmetic.add(self._index, 1); return current; } - ,forward: function( ) { - return this.order( this._order, false ); - } - - ,hasPrev: function( ) { - return RANDOMISED & this._order ? false : this._prev; - } - ,prev: function( ) { var self = this, Arithmetic = Abacus.Arithmetic, order = self._order, klass = self[CLASS], current = self._item, n = self.n, tot = self._count; @@ -997,28 +1084,33 @@ CombinatorialIterator = Abacus.CombinatorialIterator = Class({ if ( RANDOMISED & order ) return null; // compute prev, using successor methods / loopless algorithms, WITHOUT using big integer arithemtic - if ( REVCOLEX & order ) + if ( MINIMAL & order ) { - self.__item = klass.succ( -1, self.__item, n, tot ); + /* TODO */ + self._item = self.__item = null; + } + else if ( REVCOLEX & order ) + { + self.__item = klass.succ( -1, self.__item, n, tot, REVCOLEX ); self._item = klass.dual( self.__item, n, REVCOLEX ); } else if ( COLEX & order ) { - self.__item = klass.succ( 1, self.__item, n, tot ); + self.__item = klass.succ( 1, self.__item, n, tot, COLEX ); self._item = klass.dual( self.__item, n, COLEX ); } else if ( REVLEX & order ) { - self.__item = klass.succ( 1, self.__item, n, tot ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self.__item = klass.succ( 1, self.__item, n, tot, REVLEX ); + self._item = klass.dual( self.__item, n, REVLEX ); } else /*if ( LEX & order )*/ { - self.__item = klass.succ( -1, self.__item, n, tot ); - self._item = null != self.__item ? self.__item.slice( ) : null; + self.__item = klass.succ( -1, self.__item, n, tot, LEX ); + self._item = klass.dual( self.__item, n, LEX ); } self._prev = null != self._item; - if ( self._prev ) self._index = Arithmetic.sub(self._index, 1); + if ( self._prev && !(RANDOMISED & order) ) self._index = Arithmetic.sub(self._index, 1); return current; } @@ -1219,7 +1311,10 @@ Permutation = Abacus.Permutation = Class(CombinatorialIterator, { ,rand: function( n ) { var perm = new Array(n), i; for (i=0; i0&&(e=new Array(n+1).join("0")+e),e}},w=p(32),b=function(t,r,n,e,i,u){var o=t.length;if(arguments.length<5&&(i=o-1),0>i&&(i+=o),arguments.length<4&&(e=0),e>i)return n;if(!0===u){var l,a,f=i-e+1,c=f-1,s=15&f,_=1&s,h=c-s,d=_?r(n,t[i],i):n;for(l=c-_;l>h;l-=2)a=e+l,d=r(r(d,t[a],a),t[a-1],a-1);for(l=h;l>=0;l-=16)a=e+l,d=r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(d,t[a],a),t[a-1],a-1),t[a-2],a-2),t[a-3],a-3),t[a-4],a-4),t[a-5],a-5),t[a-6],a-6),t[a-7],a-7),t[a-8],a-8),t[a-9],a-9),t[a-10],a-10),t[a-11],a-11),t[a-12],a-12),t[a-13],a-13),t[a-14],a-14),t[a-15],a-15)}else{var l,a,f=i-e+1,s=15&f,_=1&s,d=_?r(n,t[e],e):n;for(l=_;s>l;l+=2)a=e+l,d=r(r(d,t[a],a),t[a+1],a+1);for(l=s;f>l;l+=16)a=e+l,d=r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(d,t[a],a),t[a+1],a+1),t[a+2],a+2),t[a+3],a+3),t[a+4],a+4),t[a+5],a+5),t[a+6],a+6),t[a+7],a+7),t[a+8],a+8),t[a+9],a+9),t[a+10],a+10),t[a+11],a+11),t[a+12],a+12),t[a+13],a+13),t[a+14],a+14),t[a+15],a+15)}return d},y=function(t,r,n,e){if(n>e)return r;var i,u,o=e-n+1,l=15&o,a=1&l,f=a?t(r,n):r;for(i=a;l>i;i+=2)u=n+i,f=t(t(f,u),u+1);for(i=l;o>i;i+=16)u=n+i,f=t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(f,u),u+1),u+2),u+3),u+4),u+5),u+6),u+7),u+8),u+9),u+10),u+11),u+12),u+13),u+14),u+15);return f},x=function(t,r,n,e,i){var u=t.length;if(arguments.length<4&&(e=u-1),0>e&&(e+=u),arguments.length<3&&(n=0),n>e)return[];var o,l,a,f,c,s,_=e-n+1,h=new Array(_);if(!0===i){for(a=_-1,c=15&_,s=1&c,f=a-c,s&&(h[0]=r(t[e],e,n,e)),o=a-s;o>f;o-=2)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l-1],l-1,n,e);for(o=f;o>=0;o-=16)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l-1],l-1,n,e),h[o+2]=r(t[l-2],l-2,n,e),h[o+3]=r(t[l-3],l-3,n,e),h[o+4]=r(t[l-4],l-4,n,e),h[o+5]=r(t[l-5],l-5,n,e),h[o+6]=r(t[l-6],l-6,n,e),h[o+7]=r(t[l-7],l-7,n,e),h[o+8]=r(t[l-8],l-8,n,e),h[o+9]=r(t[l-9],l-9,n,e),h[o+10]=r(t[l-10],l-10,n,e),h[o+11]=r(t[l-11],l-11,n,e),h[o+12]=r(t[l-12],l-12,n,e),h[o+13]=r(t[l-13],l-13,n,e),h[o+14]=r(t[l-14],l-14,n,e),h[o+15]=r(t[l-15],l-15,n,e)}else{for(c=15&_,s=1&c,s&&(h[0]=r(t[n],n,n,e)),o=s;c>o;o+=2)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l+1],l+1,n,e);for(o=c;_>o;o+=16)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l+1],l+1,n,e),h[o+2]=r(t[l+2],l+2,n,e),h[o+3]=r(t[l+3],l+3,n,e),h[o+4]=r(t[l+4],l+4,n,e),h[o+5]=r(t[l+5],l+5,n,e),h[o+6]=r(t[l+6],l+6,n,e),h[o+7]=r(t[l+7],l+7,n,e),h[o+8]=r(t[l+8],l+8,n,e),h[o+9]=r(t[l+9],l+9,n,e),h[o+10]=r(t[l+10],l+10,n,e),h[o+11]=r(t[l+11],l+11,n,e),h[o+12]=r(t[l+12],l+12,n,e),h[o+13]=r(t[l+13],l+13,n,e),h[o+14]=r(t[l+14],l+14,n,e),h[o+15]=r(t[l+15],l+15,n,e)}return h},k=function(t,r){for(var n=0,e=0,i=[],u=t.length,o=r.length;u>n&&o>e;)t[n]r[e]?e++:(i.push(t[n]),n++,e++);return i},U=function(t,r,n){var e,i,u=0,o=0,l=[],a=t.length,f=r.length;for(n=!1!==n,i=!n;a>u&&f>o;){if(n&&l.length){if(t[u]===e){u++;continue}if(r[o]===e){o++;continue}}t[u]r[o]?l.push(e=r[o++]):(l.push(e=t[u]),i&&l.push(r[o]),u++,o++)}for(;a>u;)(i||t[u]!==e)&&l.push(e=t[u++]);for(;f>o;)(i||r[o]!==e)&&l.push(e=r[o++]);return l},C=function(){var t,r,n,e,i,u,o,l,a,f,c=arguments,s=c.length;if(!s)return[];for(a=c[0].length,t=1;s>t;t++)a*=c[t].length;for(f=new Array(a),t=0;a>t;t++){for(l=[],n=t,r=s-1;r>=0;r--)if(e=c[r].length,i=n%e,n=~~(n/e),o=c[r][i],o instanceof Array)for(u=o.length-1;u>=0;u--)l.unshift(o[u]);else l.unshift(o);f[t]=l}return f},q=function(){},E=function(t,r,n){var e,i,u,o,l,a=c.Arithmetic.rnd;for(o=!0===n?t.slice():t,l=!0===r?1:0,e=o.length;lu;u++)o=a(0,--f),l=t[o],t[o]=t[f],t[f]=l,e[u]=l,n&&(i[u]=o);if(n)for(u=r-1;u>=0;u--)o=i[u],l=t[f],t[f]=t[o],t[o]=l,f++;return e},O=function(t,r){var n,e,i,u,o=t.length;for(n=new Array(r-o),e=0,i=0,u=0;r>e;)i>=o||en;n++)i[n]=r[n]-1-t[n];else for(n=0;e>n;n++)i[n]=r-1-t[e-1-n];return i},M=function(t){var r,n=[],e=t.length;if(e>1)for(r=e-1;r>=1;r--)n.push([t[0],t[r]]);return n},L=function(t){var r=c.Arithmetic.add;return b(t,r,0)},S=function(t){var r=c.Arithmetic.mul;return b(t,r,1)},N=function(t){return c.Arithmetic.shl(1,t)},P=function(t,r){return c.Arithmetic.pow(t,r)},X=function(t){var r=c.Arithmetic.mul;return 0>t?0:2>t?1:4>t?t<t-r&&(r=t-r),0>r||1>t)return 0;if(0===r||1===t)return 1;if(1===r)return t;var n,e=c.Arithmetic.mul,i=t-r,u=1+i;for(n=2;r>=n;n++)u=e(u,1+i/n);return c.Arithmetic.round(u)},T=function W(t,r,n,e){if(n===t&&1===r||r===t&&1===n)return 1;if(n+r>t+1||t>r*n)return 0;var i,u,o=c.Arithmetic.add,l=c.Arithmetic.min(n,t-n-r+2),a=c.Arithmetic.max(1,c.Arithmetic.ceil((t-n)/(r-1))),f=0;for(null==e&&(e={}),i=a;l>=i;i++)u=t-n+","+(r-1)+","+i,null==e[u]&&(e[u]=W(t-n,r-1,i,e)),f=o(f,e[u]);return f},D=8,H=16,G=32,V=64,B=128,K=256,Y=512,z=D|H|G|V|B|K|Y,F=K|Y,J=function(t){return arguments.length&&null!=t?t.substr?(t=t.toUpperCase(),c.ORDER[h](t)?c.ORDER[t]:D):z&t?t:D:D},Q=function(t){return arguments.length?function(){throw new Error('"'+t+'" not implemented')}:function(){throw new Error("Method not implemented")}};return c.Util={rnd:Math.random,rint:function(t,r){return c.Arithmetic.round((r-t)*c.Util.rnd()+t)},shuffle:E,pick:I,operate:b,operation:y,map:x,intersection:k,union:U,kronecker:C,cartesian:q,num:function(t){return parseInt(t,10)},val:function(t){return c.Arithmetic.floor(t.valueOf())},equ:function(t,r){return t===r},gte:function(t,r){return t>=r},lte:function(t,r){return r>=t},gt:function(t,r){return t>r},lt:function(t,r){return r>t},add:function(t,r){return t+r},sub:function(t,r){return t-r},mul:function(t,r){return t*r},div:function(t,r){return c.Arithmetic.floor(t/r)},mod:function(t,r){return t%r},pow:Math.pow,shl:function(t,r){return t<>r},bor:function(t,r){return t|r},band:function(t,r){return t&r},neg:function(t){return c.Arithmetic.sub(0,t)},abs:Math.abs,min:Math.min,max:Math.max,floor:Math.floor,ceil:Math.ceil,round:Math.round,sum:L,product:S,pow2:N,powNK:P,factorial:X,binomial:j,partitions:T},c.Arithmetic={num:c.Util.num,val:c.Util.val,equ:c.Util.equ,gte:c.Util.gte,lte:c.Util.lte,gt:c.Util.gt,lt:c.Util.lt,add:c.Util.add,sub:c.Util.sub,mul:c.Util.mul,div:c.Util.div,mod:c.Util.mod,pow:c.Util.pow,shl:c.Util.shl,shr:c.Util.shr,bor:c.Util.bor,band:c.Util.band,neg:c.Util.neg,abs:c.Util.abs,min:c.Util.min,max:c.Util.max,floor:c.Util.floor,ceil:c.Util.ceil,round:c.Util.round,rnd:c.Util.rint},c.ORDER={LEX:D,LEXICOGRAPHIC:D,REVLEX:H,ANTILEX:H,REVERSELEXICOGRAPHIC:H,ANTILEXICOGRAPHIC:H,COLEX:G,COLEXICOGRAPHIC:G,REVCOLEX:V,ANTICOLEX:V,REVERSECOLEXICOGRAPHIC:V,ANTICOLEXICOGRAPHIC:V,RANDOM:K,RANDOMISED:K,STOCHASTIC:Y},r=c.BitArray=A({constructor:function Z(t){var r=this;return r instanceof Z?(r.length=t,void(r.bits=new Uint32Array(c.Arithmetic.ceil(t/32)))):new Z(t)},length:0,bits:null,dispose:function(){var t=this;return t.length=null,t.bits=null,t},clone:function(){var t=this,n=new r(t.length);return n.bits=new Uint32Array(t.bits),n},fromArray:function(t){var r=this;return r.bits=new Uint32Array(t),r},toArray:function(){return d.call(this.bits)},toString:function(){return x(this.toArray(),w).join("")},reset:function(){var t,r=this,n=r.bits,e=n.length;for(t=0;e>t;t++)n[t]=0;return r},isset:function(t){return!!(this.bits[t>>>5]&1<<(31&t))},set:function(t){var r=this;return r.bits[t>>>5]|=1<<(31&t),r},unset:function(t){var r=this;return r.bits[t>>>5]&=~(1<<(31&t)),r},toggle:function(t){var r=this;return r.bits[t>>>5]^=1<<(31&t),r}}),n=c.CombinatorialIterator=A({constructor:function $(t){var r,n=this;return n instanceof $?(r=n[_],n.n=t||0,n._count=r.count(n.n),void n.order(D)):new $(t)},__static__:{count:Q(),rank:Q(),unrank:Q(),first:Q(),last:Q(),stochastic:Q(),dual:function(t,r,n){return 0>=r?[]:R(t,r)},succ:function(t,r,n,e){var i=this,u=c.Arithmetic;return-1!==t&&1!==t&&(t=1),r?i.unrank(u.add(i.rank(r,n,e),t),n,e):null},rand:function(t,r){var n=this,e=c.Arithmetic,i=r?r:n.count(t),u=e.sub(i,1),o=e.rnd(0,u);return e.equ(0,o)?n.first(t):e.equ(o,u)?n.last(t):n.unrank(o,t,i)}},n:0,_order:0,_count:0,_index:null,__item:null,_item:null,_prev:null,_next:null,_traversed:null,_stochastic:null,dispose:function(){var t=this;return t.n=null,t._order=null,t._count=0,t._index=null,t.__item=null,t._item=null,t._prev=null,t._next=null,t._stochastic=null,t._traversed&&(t._traversed.dispose(),t._traversed=null),t},_store:function(){var t=this;return[t._order,t._index,t.__item,t._item,t._prev,t._next]},_restore:function(t){var r=this;return t&&(r._order=t[0],r._index=t[1],r.__item=t[2],r._item=t[3],r._prev=t[4],r._next=t[5]),r},total:function(){return this._count},order:function(t,n,e,i){var u,o,l,a=this,f=a[_];if(!arguments.length)return a._order;if("object"==typeof n&&arguments.length<4?(i=e,e=n,n=!1):n=!1===n,t=J(t),a._order=t,a._index=0,a._item=a.__item=null,a._prev=!1,a._next=!1,o=a._count,l=a.n,Y&t)if(null==a._stochastic||e){if(!e)throw new Error("No Stochastic Transition Matrix given!");a._stochastic=[e,i?1:0,i?[]:null],a.__item=f.stochastic(a._stochastic[0],l,a._stochastic[2]),a._item=a.__item.slice()}else null!=a._stochastic[2]&&(a._stochastic[2]=[]),a.__item=f.stochastic(a._stochastic[0],l,a._stochastic[2]),a._item=a.__item.slice();else K&t?(a._traversed?a._traversed.reset():a._traversed=new r(o),a._traversed.set(u=a.randomIndex()),a.__item=a.item(u,D),a._item=null!=a.__item?a.__item.slice():null):V&t?(a.__item=n?f.last(l):f.first(l),a._item=f.dual(a.__item,l,V)):G&t?(a.__item=n?f.first(l):f.last(l),a._item=f.dual(a.__item,l,G)):H&t?(a.__item=n?f.first(l):f.last(l),a._item=null!=a.__item?a.__item.slice():null):(a.__item=n?f.last(l):f.first(l),a._item=null!=a.__item?a.__item.slice():null);return a._prev=F&t||!n?!1:null!=a._item,a._next=!n||F&t?null!=a._item:!1,a},index:function(t){if(!arguments.length)return this._index;var r,n=this,e=c.Arithmetic,i=n[_],u=n.n,o=n._count,l=n._order;return t=e.num(t),e.gt(0,t)&&(t=e.add(t,o)),e.gte(t,0)&&e.lt(t,o)&&(r=e.sub(o,1),V&l?(n._index=t,n.__item=e.equ(0,t)?i.first(u):e.equ(r,t)?i.last(u):i.unrank(t,u,o),n._item=i.dual(n.__item,u,V)):G&l?(n._index=t,n.__item=e.equ(0,t)?i.last(u):e.equ(r,t)?i.first(u):i.unrank(e.sub(r,t),u,o),n._item=i.dual(n.__item,u,G)):H&l?(n._index=t,n.__item=e.equ(0,t)?i.last(u):e.equ(r,t)?i.first(u):i.unrank(e.sub(r,t),u,o),n._item=n.__item.slice()):D&l&&(n._index=t,n.__item=e.equ(0,t)?i.first(u):e.equ(r,t)?i.last(u):i.unrank(t,u,o),n._item=n.__item.slice())),n},item:function(t,r){if(!arguments.length)return this._item;var n,e,i,u=this,o=u.n,l=u._count,a=u[_],f=c.Arithmetic;if(r=null!=r?J(r):u._order,t=f.num(t),f.gt(0,t)&&(t=f.add(t,l)),f.gte(t,0)&&f.lt(t,l)){if(n=f.sub(l,1),K&r){for(e=u._traversed;e.isset(i=u.randomIndex()););return e.set(i),a.unrank(i,o,l)}return V&r?a.dual(f.equ(0,t)?a.first(o):f.equ(n,t)?a.last(o):a.unrank(t,o,l),o,V):G&r?a.dual(f.equ(0,t)?a.last(o):f.equ(n,t)?a.first(o):a.unrank(f.sub(n,t),o,l),o,G):H&r?f.equ(0,t)?a.last(o):f.equ(n,t)?a.first(o):a.unrank(f.sub(n,t),o,l):f.equ(0,t)?a.first(o):f.equ(n,t)?a.last(o):a.unrank(t,o,l)}return null},randomIndex:function(t,r){var n=this,e=c.Arithmetic,i=n._count,u=arguments.length;return 0===u?(t=0,r=e.sub(i,1)):1===u?(t=e.num(t||0),r=e.sub(i,1)):(t=e.num(t),r=e.num(r)),e.rnd(t,r)},random:function(){var t=this,r=t[_];return r.rand(t.n,t._count)},rewind:function(){return this.order(this._order,!0)},hasNext:function(){return Y&this._order?!0:this._next},next:function(){var t,r,n=this,e=c.Arithmetic,i=n._order,u=n[_],o=n._item,l=n.n,a=n._count;if(Y&i)n.__item=u.stochastic(n._stochastic[0],l,n._stochastic[2]),n._item=n.__item.slice();else if(K&i)if(e.lt(e.add(n._index,1),a)){for(n._index=e.add(n._index,1),t=n._traversed;t.isset(r=n.randomIndex()););t.set(r),n.__item=n.item(r,D),n._item=null!=n.__item?n.__item.slice():null,n._next=null!=n._item}else n._next=!1,n._traversed&&(n._traversed.dispose(),n._traversed=null);else V&i?(n.__item=u.succ(1,n.__item,l,a),n._item=u.dual(n.__item,l,V)):G&i?(n.__item=u.succ(-1,n.__item,l,a),n._item=u.dual(n.__item,l,G)):H&i?(n.__item=u.succ(-1,n.__item,l,a),n._item=null!=n.__item?n.__item.slice():null):(n.__item=u.succ(1,n.__item,l,a),n._item=null!=n.__item?n.__item.slice():null),n._next=null!=n._item,n._next&&(n._index=e.add(n._index,1));return o},forward:function(){return this.order(this._order,!1)},hasPrev:function(){return F&this._order?!1:this._prev},prev:function(){var t=this,r=c.Arithmetic,n=t._order,e=t[_],i=t._item,u=t.n,o=t._count;return F&n?null:(V&n?(t.__item=e.succ(-1,t.__item,u,o),t._item=e.dual(t.__item,u,V)):G&n?(t.__item=e.succ(1,t.__item,u,o),t._item=e.dual(t.__item,u,G)):H&n?(t.__item=e.succ(1,t.__item,u,o),t._item=null!=t.__item?t.__item.slice():null):(t.__item=e.succ(-1,t.__item,u,o),t._item=null!=t.__item?t.__item.slice():null),t._prev=null!=t._item,t._prev&&(t._index=r.sub(t._index,1)),i)},range:function(t,r){var n,e,i,u,o,l=this,a=c.Arithmetic,f=l._count,s=1,_=arguments.length,h=a.sub(f,1);if(1>_?(t=0,r=h):2>_?(t=a.num(t),r=h):(t=a.num(t),r=a.num(r)),a.lt(t,0)&&(t=a.add(t,f)),a.lt(r,0)&&(r=a.add(r,f)),a.gt(t,r)&&(n=t,t=r,r=n,s=-1),a.lt(t,0)&&(t=0),a.gt(r,h)&&(r=h),a.lte(t,r)){if(o=l._store(),F&l._order||l.index(t),i=a.val(a.sub(r,t)),e=new Array(i+1),0>s)for(u=i;u>=0;u--)e[u]=l.next();else for(u=0;i>=u;u++)e[u]=l.next();l._restore(o)}else e=[];return e}}),e=c.Permutation=A(n,{constructor:function tt(t){var r=this;return r instanceof tt?void n.call(r,t):new tt(t)},__static__:{count:function(t){return X(t)},dual:n.dual,rank:function(t,r){var n,e,i,u,o=c.Arithmetic,l=0,a=o.ceil(g(r)),f=(1<<1+a)-1,s=new Array(f),_=o.shl(1,a);for(n=0;f>n;n++)s[n]=0;for(n=0;r>n;n++){for(u=t[n],i=o.val(o.add(_,u)),e=0;a>e;e++)1&i&&(u=o.sub(u,s[i>>>1<<1])),s[i]=o.add(s[i],1),i>>>=1;s[i]=o.add(s[i],1),l=o.add(o.mul(l,o.sub(n)),u)}return l},unrank:function(t,r,n){var e,i,u,o,l,a,f,s,_,h,d,m,v=c.Arithmetic,A=this;if(n=n||X(r),v.equ(0,t))return A.first(r);if(v.equ(n,v.add(t,1)))return A.last(r);for(e=new Array(r),i=v.div(n,r),_=v.ceil(g(r)),h=(1<<1+_)-1,d=new Array(h),m=v.shl(1,_),u=0;_>=u;u++)for(o=1,l=1<=o;o++)d[l-1+o]=v.shl(1,v.sub(_,u));for(s=r-1,u=0;r>u;u++){for(a=v.div(t,i),f=1,o=0;_>o;o++)d[f]=v.sub(d[f],1),f<<=1,v.gte(a,d[f])&&(a=v.sub(a,d[f]),f++);d[f]=0,e[u]=v.val(v.sub(f,m)),s&&(t=v.mod(t,i),i=v.div(i,s),s--)}return e},first:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=r;return n},last:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=t-1-r;return n},succ:function(t,r,n){if(r){var e,i,u,o,l,a=r.slice();if(-1===t){for(e=n-2;e>=0&&a[e]<=a[e+1];)e--;if(e>=0){for(i=n-1;i>e&&a[e]<=a[i];)i--;for(l=a[e],a[e]=a[i],a[i]=l,u=e+1,o=n-1;o>u;)l=a[u],a[u++]=a[o],a[o--]=l}else a=null}else{for(e=n-2;e>=0&&a[e]>=a[e+1];)e--;if(e>=0){for(i=n-1;i>e&&a[e]>=a[i];)i--;for(l=a[e],a[e]=a[i],a[i]=l,u=e+1,o=n-1;o>u;)l=a[u],a[u++]=a[o],a[o--]=l}else a=null}return a}return null},rand:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=r;return E(n)},stochastic:function(t,r,n){if(t.length!==r||t[0].length!==r)throw new Error("Stochastic Matrix dimensions and Permutation dimensions do not match!");var e,i,u,o,l,a,f,s,_=new Array(r),h=new Array(r),d=0,m=c.Util.rnd,v=!1;for(i=0;r>i;i++)h[i]=0;if(n){if(v=!0,!n.length){for(n.N=0,e=new Array(r),i=0;r>i;i++)e[i]=0;for(i=0;r>i;i++)n.push(e.slice())}d=++n.N}for(s=!v,i=0;r>i;)for(o=m(),f=0,l=t[i],v&&(a=n[i]),u=0;r>u;u++){if(o>f&&o<=f+l[u]){0===h[u]&&(s||a[u]+1<=(d+1)*l[u])&&(h[u]=1,_[i]=u,v&&a[u]++,i++);break}f+=l[u]}return _},inverse:function(t,r){r=r||t.length;var n,e=new Array(r);for(n=0;r>n;n++)e[t[n]]=n;return e},compose:function(){var t,r,n,e=arguments,i=e.length,u=i?e[0]:[],o=u.length;for(r=1;i>r;r++)for(n=u.slice(),t=0;o>t;t++)u[t]=n[e[r][t]];return u},permute:function(t,r,n){var e,i,u,o=t.length;for(!0===n?(i=new Array(o),u=t):(i=t,u=t.slice()),e=0;o>e;e++)i[e]=u[r[e]];return i},reassign:function(t,r){var n,e=t.length,i=new Array(e);for(n=0;e>n;n++)i[n]=r[t[n]];return i},shuffle:E,toCycles:function(t,r,n){r=r||t.length;var e,i,u,o=[],l=!0===n?1:0,a=new Array(r),f=new Array(r);for(e=0;r>e;e++)f[e]=e,a[e]=0;for(u=[i=f.shift()],a[i]=1;f.length;){if(i=t[i],a[i])for(u.length>l&&o.push(u),u=[];f.length&&a[i=f.shift()];);a[i]||(u.push(i),a[i]=1)}return u.length>l&&o.push(u),o},fromCycles:function(t,r){var n,e,i,u,o=new Array(r),l=t.length;for(e=0;r>e;e++)o[e]=e;for(n=0;l>n;n++)if(u=t[n],i=u.length,!(2>i)){for(e=0;i-1>e;e++)o[u[e]]=u[e+1];o[u[i-1]]=u[0]}return o},toSwaps:function(t,r){r=r||t.length;var n,i,u,o=[],l=e.toCycles(t,r,!0);for(n=0,i=l.length;i>n;n++)u=l[n],o=o.concat(M(u));return o},fromSwaps:function(t,r){var n,e,i,u=t.length,o=new Array(r);for(n=0;r>n;n++)o[n]=n;for(n=0;u>n;n++)e=t[n],i=o[e[0]],o[e[0]]=o[e[1]],o[e[1]]=i;return o},toMatrix:function(t,r,n){var e,i,u=new Array(r);for(n=!0===n,e=0;r>e;e++)for(u[e]=new Array(r),i=0;r>i;i++)u[e][i]=0;for(e=0;r>e;e++)n?u[t[e]][e]=1:u[e][t[e]]=1;return u},fromMatrix:function(t,r,n){var e,i,u=new Array(r);for(n=!0===n,e=0;r>e;e++)for(i=0;r>i;i++)t[e][i]&&(n?u[i]=e:u[e]=i);return u},isConnected:function(t,r){var n,e=-(1/0);for(r=r||t.length,n=0;r-1>n;n++)if(t[n]>e&&(e=t[n]),n>=e)return!1;return!0}}}),i=c.Combination=A(n,{constructor:function rt(t,r){var e=this;return e instanceof rt?void n.call(e,[t,r]):new rt(t,r)},__static__:{count:function(t){return j(t[0],t[1])},dual:function(t,r){return R(t,r[0])},rank:function(t,r,n){var e,i,u,o,l,a=c.Arithmetic,f=0;for(o=r[1],r=r[0],l=n?n:j(r,o),e=1;o>=e;e++)i=r-1-t[e-1],u=o+1-e,i>=u&&(f=a.add(f,j(i,u)));return a.sub(a.sub(l,1),f)},unrank:function(t,r,n){var e,i,u,o,l,a,f=c.Arithmetic,s=this;if(n=n||j(r[0],r[1]),f.equ(0,t))e=s.first(r);else if(f.equ(n,f.add(t,1)))e=s.last(r);else{u=r[1],r=r[0],e=new Array(u),i=n,t=f.sub(f.sub(i,1),t),i=f.div(f.mul(i,f.sub(r,u)),r),l=r-u+1,o=u,a=r-1;do f.lte(i,t)?(e[u-o]=r-l-o+1,f.gt(i,0)&&(t=f.sub(t,i),i=f.div(f.mul(i,o),a)),o--,a--):(i=f.div(f.mul(i,f.sub(a,o)),a),l--,a--);while(o>0)}return e},first:function(t){var r,n=t[1],e=new Array(n);for(r=0;n>r;r++)e[r]=r;return e},last:function(t){var r,n=t[1],e=new Array(n);for(t=t[0],r=0;n>r;r++)e[n-1-r]=t-1-r;return e},succ:function(t,r,n){if(r){var e,i,u,o,l,a=r.slice();if(e=n[1],n=n[0],-1===t){for(i=e-1,u=-1;i>0;){if(a[i]>a[i-1]+1){u=i;break}i--}if(-1===u&&0-1){for(l=n,i=e-1;i>u;i--)a[i]=--l;a[u]--}else a=null}else{for(i=e-1,u=-1,o=n-e;i>=0;){if(a[i]-1)for(l=a[u],i=u;e>i;i++)a[i]=++l;else a=null}return a}return null},rand:function(t){var r,n,e,i,u,o,l,a;for(n=t[1],t=t[0],r=new Array(n),e=c.Util.rnd(),u=0,l=0,a=t-n,i=1;n>=i;i++){for(u++,o=(n-i+1)/(t-u+1);e>=o&&a+i>u;)l=o,u++,o=l+(1-l)*((n-i+1)/(t-u+1));r[i-1]=u-1,e=(e-l)/(o-l)}return r},stochastic:n.stochastic,complement:O,choose:function(t,r){var n,e=r.length,i=new Array(e);for(n=0;e>n;n++)i[n]=t[r[n]];return i},pick:I,toMatrix:function(t,r,n){var e,i,u,o;for(i=r[1],r=r[0],e=new Array(r),n=!0===n,u=0;r>u;u++)for(e[u]=new Array(r),o=0;r>o;o++)e[u][o]=0;for(u=0;i>u;u++)n?e[t[u]][u]=1:e[u][t[u]]=1;return e},fromMatrix:function(t,r,n){var e,i,u,o;for(i=r[1],r=r[0],e=new Array(i),n=!0===n,u=0;r>u;u++)for(o=0;r>o;o++)t[u][o]&&(n&&i>o?e[o]=u:!n&&i>u&&(e[u]=o));return e}}}),i.conjugate=i.complement,u=c.CombinationRepeat=A(n,{constructor:function nt(t,r){var e=this;return e instanceof nt?void n.call(e,[t,r]):new nt(t,r)},__static__:{count:function(t){return j(t[0]+t[1]-1,t[1])},dual:i.dual,rank:function(t,r,n){var e,i,u,o,l,a,f=c.Arithmetic,s=0;for(o=r[1],r=r[0],l=r+o-1,a=n?n:j(l,o),e=1;o>=e;e++)i=l-1-t[e-1]-e+1,u=o+1-e,i>=u&&(s=f.add(s,j(i,u)));return f.sub(f.sub(a,1),s)},unrank:function(t,r,n){var e,i,u,o,l,a,f,s=c.Arithmetic,_=this;if(n=n||j(r[0]+r[1]-1,r[1]),s.equ(0,t))return _.first(r);if(s.equ(n,s.add(t,1)))return _.last(r);u=r[1],r=r[0],o=r+u-1,e=new Array(u),i=n,t=s.sub(s.sub(i,1),t),i=s.div(s.mul(i,s.sub(o,u)),o),a=o-u+1,l=u,f=o-1;do s.lte(i,t)?(e[u-l]=o-a-u+1,s.gt(i,0)&&(t=s.sub(t,i),i=s.div(s.mul(i,l),f)),l--,f--):(i=s.div(s.mul(i,s.sub(f,l)),f),a--,f--);while(l>0);return e},first:function(t){var r,n=t[1],e=new Array(n);for(r=0;n>r;r++)e[r]=0;return e},last:function(t){var r,n=t[1],e=new Array(n);for(t=t[0]-1,r=0;n>r;r++)e[r]=t;return e},succ:function(t,r,n){if(r){var e,i,u,o,l=r.slice();if(e=n[1],n=n[0],-1===t){for(i=e-1,u=-1;i>0;){if(l[i]>l[i-1]){u=i;break}i--}if(-1===u&&0-1){for(o=n-1,i=u+1;e>i;i++)l[i]=o;l[u]--}else l=null}else{for(i=e-1,u=-1;i>=0;){if(l[i]-1)for(o=l[u]+1,i=u;e>i;i++)l[i]=o;else l=null}return l}return null},rand:function(t){var r,n,e,i,u,o,l,a,f;for(n=t[1],t=t[0],r=new Array(n),e=c.Util.rnd(),u=0,l=0,a=t+n-1,f=a-n,i=1;n>=i;i++){for(u++,o=(n-i+1)/(a-u+1);e>=o&&f+i>u;)l=o,u++,o=l+(1-l)*((n-i+1)/(a-u+1));r[i-1]=u-i,e=(e-l)/(o-l)}return r},stochastic:i.stochastic}}),o=c.Partition=A(n,{constructor:function et(t){var r=this;return r instanceof et?void n.call(r,t):new et(t)},__static__:{count:function(t){var r,n,e=c.Arithmetic.add,i=t>1?2:1;for(r=2;t>r;r++)for(n=t-r+1;n>=1;n--)i=e(i,T(t,r,n));return i},dual:function(t,r){var n,e,i=[],u=t.length;for(n=0;u>n;n++)if(e=r-t[n],!(0>=e)){if(r===e)return[r];i.unshift(e)}return i},rank:function(t,r,n,e,i){var u,o,l,a=c.Arithmetic,f=this,s=t.length,_=r;return n=n||f.count(r),e=e||0,i=i||s,o=e,l=t[o],u=_===l?a.sub(n,1):1===l?0:s>o+1?a.add(1,f.rank(t,r-l,a.sub(n,f.count(r-l)),o+1)):0},unrank:function(t,r,n){},first:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=1;return n},last:function(t){return[t]},succ:function(t,r,n){if(r){var e,i,u,o,l,a,f=r.slice();if(-1===t)if(f[0]>1){for(i=f.length,e=i-1;e>=0&&1===f[e];)e--;for(u=f[e]-1,f=f.slice(0,e+1),f[e]=u,l=L(f),a=n-l;a>0;)o=a,o>u?(o=u,f.push(o)):f.push(a),a-=o}else f=null;else if(f[0]0&&e--;e>0&&f[e]===f[e-1];)e--;for(f[e]++,f=f.slice(0,e+1),l=L(f),a=n-l;a>0;)f.push(1),a--}else f=null;return f}return null},rand:function(t){},stochastic:n.stochastic,conjugate:function(t){var r,n,e,i=t.length,u=t[0],o=new Array(u);for(r=0;u>r;r++)o[r]=1;for(n=1;i>n;n++)for(r=0,e=t[n];u>r&&e>0;)o[r++]++,e--;return o},pack:function(t){var r,n=[],e=t.length,i=t[0],u=[i,1];for(r=1;e>r;r++)i===t[r]?u[1]++:(n.push(u),i=t[r],u=[i,1]);return n.push(u),n},unpack:function(t){var r,n,e,i,u,o=[],l=t.length;for(r=0;l>r;r++)if(u=t[r],1===u[1])o.push(u[0]);else for(e=u[1],i=u[0],n=0;e>n;n++)o.push(i);return o}}}),o.transpose=o.conjugate,l=c.Powerset=A(n,{constructor:function it(t){var r=this;return r instanceof it?void n.call(r,t):new it(t)},__static__:{count:function(t){return N(t)},dual:n.dual,rank:function(t){for(var r=c.Arithmetic,n=0,e=0,i=t.length;i>e;)n=r.add(n,r.shl(1,t[e++]));return n},unrank:function(t){for(var r=c.Arithmetic,n=[],e=0;r.gt(t,0);)r.gt(r.band(t,1),0)&&n.unshift(e),r.gt(r.band(t,2),0)&&n.unshift(e+1),r.gt(r.band(t,4),0)&&n.unshift(e+2),r.gt(r.band(t,8),0)&&n.unshift(e+3),r.gt(r.band(t,16),0)&&n.unshift(e+4),r.gt(r.band(t,32),0)&&n.unshift(e+5),r.gt(r.band(t,64),0)&&n.unshift(e+6),r.gt(r.band(t,128),0)&&n.unshift(e+7),e+=8,t=r.shr(t,8);return n},first:function(t){return[]},last:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=t-1-r;return n},succ:function(t,r,n){var e=this,i=c.Arithmetic;return 1!==t&&-1!==t&&(t=1),-1===t?0===r.length?null:e.unrank(i.add(e.rank(r),t)):n===r.length?null:e.unrank(i.add(e.rank(r),t))},rand:n.rand,stochastic:n.stochastic}}),a=c.Tensor=A(n,{constructor:function ut(){var t=this;return t instanceof ut?void(arguments.length?n.call(t,d.call(arguments)):(t.n=[],t._count=0)):(t=new ut,arguments.length?n.call(t,d.call(arguments)):(t.n=[],t._count=0),t)},__static__:{count:function(t){return t&&t.length?S(t):0},dual:n.dual,rank:function(t,r){var n,e,i=c.Arithmetic,u=r,o=u.length;if(!o)return-1;for(n=0,e=0;o>e;e++)n=i.add(i.mul(n,u[e]),t[e]);return n},unrank:function(t,r){var n,e,i,u,o,l=c.Arithmetic,a=r,f=a.length;if(!f)return[];for(o=new Array(f),n=t,i=f-1;i>=0;i--)e=a[i],u=l.mod(n,e),n=l.div(n,e),o[i]=l.val(u);return o},first:function(t){var r,n=t.length,e=new Array(n);for(r=0;n>r;r++)e[r]=0;return e},last:function(t){var r,n=t,e=n.length,i=new Array(e);for(r=0;e>r;r++)i[r]=n[r]-1;return i},succ:function(t,r,n){if(r){var e,i,u=r.slice(),o=n,l=o.length;if(-1===t){for(e=l-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,i=e+1;l>i;i++)u[i]=o[i]-1;else u=null}else{for(e=l-1;e>=0&&u[e]+1===o[e];)e--;if(e>=0)for(u[e]++,i=e+1;l>i;i++)u[i]=0;else u=null}return u}return null},rand:function(t){var r,n=c.Arithmetic.rnd,e=t,i=e.length,u=new Array(i);for(r=0;i>r;r++)u[r]=n(0,e[r]-1);return u},stochastic:n.stochastic,product:C,component:function(t,r){var n,e,i,u,o,l,a=[],f=r,c=f.length;for(n=0;c>n;n++)if(i=f[n],o=t[n],u=i[o],u instanceof Array)for(e=0,l=u.length;l>e;e++)a.push(u[e]);else a.push(u);return a}}}),f=c.Tuple=A(n,{constructor:function ot(t,r){var e=this;return e instanceof ot?void n.call(e,[t||1,r||2]):new ot(t,r)},__static__:{count:function(t){return P(t[1],t[0])},dual:function(t,r){return R(t,r[1])},rank:function(t,r){var n,e,i=c.Arithmetic,u=r[0];for(r=r[1],n=0,e=0;u>e;e++)n=i.add(i.mul(n,r),t[e]);return n},unrank:function(t,r){var n,e,i,u,o,l=c.Arithmetic,a=r[0];for(r=r[1],o=new Array(a),n=t,i=a-1;i>=0;i--)e=r,u=l.mod(n,e),n=l.div(n,e),o[i]=l.val(u);return o},first:function(t){var r,n=t[0],e=new Array(n);for(r=0;n>r;r++)e[r]=0;return e},last:function(t){var r,n=t[0],e=new Array(n);for(t=t[1]-1,r=0;n>r;r++)e[r]=t;return e},succ:function(t,r,n){if(r){var e,i,u=r.slice(),o=n[0],n=n[1];if(-1===t){for(e=o-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,i=e+1;o>i;i++)u[i]=n-1;else u=null}else{for(e=o-1;e>=0&&u[e]+1===n;)e--;if(e>=0)for(u[e]++,i=e+1;o>i;i++)u[i]=0;else u=null}return u}return null},rand:function(t){var r,n=c.Arithmetic.rnd,e=t[0],i=new Array(e);for(t=t[1]-1,r=0;e>r;r++)i[r]=n(0,t);return i},stochastic:a.stochastic}}),c}); \ No newline at end of file +!function(t,r,n){"use strict";var e;"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils["import"]?(t.EXPORTED_SYMBOLS=[r])&&(t[r]=n.call(t)):"object"==typeof module&&module.exports?module.exports=n.call(t):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(r)?define(r,["require","exports","module"],function(){return n.call(t)}):r in t||(t[r]=e=n.call(t))&&"function"==typeof define&&define.amd&&define(function(){return e})}(this,"Abacus",function(t){"use strict";var r,n,e,i,u,o,l,a,f={VERSION:"0.1.0"},c="prototype",s="constructor",_="hasOwnProperty",h=Array.prototype.slice,d=Object.create,m=function(t,r){for(var n in r)r[_](n)&&(t[n]=r[n]);return t},v=function(t,r){1===arguments.length&&(r=t,t=Object);var n=r[s];return r[_]("__static__")&&(n=m(n,r.__static__),delete r.__static__),n[c]=m(d(t[c]),r),n},g=Math.log2||function(t){return Math.log(t)/Math.LN2},A=function(t){return function(r){var n,e;return e=r.toString(2),(n=t-e.length)>0&&(e=new Array(n+1).join("0")+e),e}},p=A(32),w=function(t,r,n,e){if(n>e)return r;var i,u,o=e-n+1,l=15&o,a=1&l,f=a?t(r,n):r;for(i=a;l>i;i+=2)u=n+i,f=t(t(f,u),u+1);for(i=l;o>i;i+=16)u=n+i,f=t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(t(f,u),u+1),u+2),u+3),u+4),u+5),u+6),u+7),u+8),u+9),u+10),u+11),u+12),u+13),u+14),u+15);return f},b=function(t,r,n,e,i,u){var o=t.length;if(arguments.length<5&&(i=o-1),0>i&&(i+=o),arguments.length<4&&(e=0),e>i)return n;if(!0===u){var l,a,f=i-e+1,c=f-1,s=15&f,_=1&s,h=c-s,d=_?r(n,t[i],i):n;for(l=c-_;l>h;l-=2)a=e+l,d=r(r(d,t[a],a),t[a-1],a-1);for(l=h;l>=0;l-=16)a=e+l,d=r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(d,t[a],a),t[a-1],a-1),t[a-2],a-2),t[a-3],a-3),t[a-4],a-4),t[a-5],a-5),t[a-6],a-6),t[a-7],a-7),t[a-8],a-8),t[a-9],a-9),t[a-10],a-10),t[a-11],a-11),t[a-12],a-12),t[a-13],a-13),t[a-14],a-14),t[a-15],a-15)}else{var l,a,f=i-e+1,s=15&f,_=1&s,d=_?r(n,t[e],e):n;for(l=_;s>l;l+=2)a=e+l,d=r(r(d,t[a],a),t[a+1],a+1);for(l=s;f>l;l+=16)a=e+l,d=r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(r(d,t[a],a),t[a+1],a+1),t[a+2],a+2),t[a+3],a+3),t[a+4],a+4),t[a+5],a+5),t[a+6],a+6),t[a+7],a+7),t[a+8],a+8),t[a+9],a+9),t[a+10],a+10),t[a+11],a+11),t[a+12],a+12),t[a+13],a+13),t[a+14],a+14),t[a+15],a+15)}return d},y=function(t,r,n,e,i){var u=t.length;if(arguments.length<4&&(e=u-1),0>e&&(e+=u),arguments.length<3&&(n=0),n>e)return[];var o,l,a,f,c,s,_=e-n+1,h=new Array(_);if(!0===i){for(a=_-1,c=15&_,s=1&c,f=a-c,s&&(h[0]=r(t[e],e,n,e)),o=a-s;o>f;o-=2)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l-1],l-1,n,e);for(o=f;o>=0;o-=16)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l-1],l-1,n,e),h[o+2]=r(t[l-2],l-2,n,e),h[o+3]=r(t[l-3],l-3,n,e),h[o+4]=r(t[l-4],l-4,n,e),h[o+5]=r(t[l-5],l-5,n,e),h[o+6]=r(t[l-6],l-6,n,e),h[o+7]=r(t[l-7],l-7,n,e),h[o+8]=r(t[l-8],l-8,n,e),h[o+9]=r(t[l-9],l-9,n,e),h[o+10]=r(t[l-10],l-10,n,e),h[o+11]=r(t[l-11],l-11,n,e),h[o+12]=r(t[l-12],l-12,n,e),h[o+13]=r(t[l-13],l-13,n,e),h[o+14]=r(t[l-14],l-14,n,e),h[o+15]=r(t[l-15],l-15,n,e)}else{for(c=15&_,s=1&c,s&&(h[0]=r(t[n],n,n,e)),o=s;c>o;o+=2)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l+1],l+1,n,e);for(o=c;_>o;o+=16)l=n+o,h[o]=r(t[l],l,n,e),h[o+1]=r(t[l+1],l+1,n,e),h[o+2]=r(t[l+2],l+2,n,e),h[o+3]=r(t[l+3],l+3,n,e),h[o+4]=r(t[l+4],l+4,n,e),h[o+5]=r(t[l+5],l+5,n,e),h[o+6]=r(t[l+6],l+6,n,e),h[o+7]=r(t[l+7],l+7,n,e),h[o+8]=r(t[l+8],l+8,n,e),h[o+9]=r(t[l+9],l+9,n,e),h[o+10]=r(t[l+10],l+10,n,e),h[o+11]=r(t[l+11],l+11,n,e),h[o+12]=r(t[l+12],l+12,n,e),h[o+13]=r(t[l+13],l+13,n,e),h[o+14]=r(t[l+14],l+14,n,e),h[o+15]=r(t[l+15],l+15,n,e)}return h},x=function(t,r){for(var n=0,e=0,i=[],u=t.length,o=r.length;u>n&&o>e;)t[n]r[e]?e++:(i.push(t[n]),n++,e++);return i},k=function(t,r,n){var e,i,u=0,o=0,l=[],a=t.length,f=r.length;for(n=!1!==n,i=!n;a>u&&f>o;){if(n&&l.length){if(t[u]===e){u++;continue}if(r[o]===e){o++;continue}}t[u]r[o]?l.push(e=r[o++]):(l.push(e=t[u]),i&&l.push(r[o]),u++,o++)}for(;a>u;)(i||t[u]!==e)&&l.push(e=t[u++]);for(;f>o;)(i||r[o]!==e)&&l.push(e=r[o++]);return l},U=function(){var t,r,n,e,i,u,o,l,a,f,c=arguments,s=c.length;if(!s)return[];for(a=c[0].length,t=1;s>t;t++)a*=c[t].length;for(f=new Array(a),t=0;a>t;t++){for(l=[],n=t,r=s-1;r>=0;r--)if(e=c[r].length,i=n%e,n=~~(n/e),o=c[r][i],o instanceof Array)for(u=o.length-1;u>=0;u--)l.unshift(o[u]);else l.unshift(o);f[t]=l}return f},C=function(){var t,r,n,e,i,u,o,l=arguments,a=l.length;if(!a)return[];for(u=l[0].length,t=1;a>t;t++)ut;t++){for(n=[],r=a-1;r>=0;r--)if(e=l[r].length=0;i--)n.unshift(e[i]);else n.unshift(e);o[t]=n}return o},q=function(t,r,n){var e,i,u,o,l,a=f.Util.rint;for(o=!0===n?t.slice():t,l=!0===r?1:0,e=o.length;lu;u++)o=a(0,--c),l=t[o],t[o]=t[c],t[c]=l,e[u]=l,n&&(i[u]=o);if(n)for(u=r-1;u>=0;u--)o=i[u],l=t[c],t[c]=t[o],t[o]=l,c++;return e},I=function(t,r,n,e){if(null==t)return null;if(!0===n){var i,u,o,l,a=t.length,f=r-a;if(0>=r||0>=f)return[];for(i=new Array(f),u=0,o=0,l=0;f>l;)o>=a||uc;c++)i[c]=r[c]-1-t[c];else for(c=0;a>c;c++)i[c]=r-1-t[c];return i},O=function(t){return null==t?null:t.reverse()},R=function(t){var r,n=[],e=t.length;if(e>1)for(r=e-1;r>=1;r--)n.push([t[0],t[r]]);return n},M=function(t){var r=f.Arithmetic.add;return b(t,r,0)},L=function(t){var r=f.Arithmetic.mul;return b(t,r,1)},S=function(t){return f.Arithmetic.shl(1,t)},N=function(t,r){return f.Arithmetic.pow(t,r)},P=function(t){var r=f.Arithmetic.mul;return 0>t?0:2>t?1:4>t?t<t-r&&(r=t-r),0>r||1>t)return 0;if(0===r||1===t)return 1;if(1===r)return t;var n,e=f.Arithmetic.mul,i=t-r,u=1+i;for(n=2;r>=n;n++)u=e(u,1+i/n);return f.Arithmetic.round(u)},j=function W(t,r,n,e){if(n===t&&1===r||r===t&&1===n)return 1;if(n+r>t+1||t>r*n)return 0;var i,u,o=f.Arithmetic.add,l=f.Arithmetic.min(n,t-n-r+2),a=f.Arithmetic.max(1,f.Arithmetic.ceil((t-n)/(r-1))),c=0;for(null==e&&(e={}),i=a;l>=i;i++)u=t-n+","+(r-1)+","+i,null==e[u]&&(e[u]=W(t-n,r-1,i,e)),c=o(c,e[u]);return c},T=8,D=16,G=32,H=64,B=128,V=256,Y=512,K=T|D|G|H|B,z=V|Y,F=K|z,J=function(t){return arguments.length&&null!=t?t.substr?(t=t.toUpperCase(),f.ORDER[_](t)?f.ORDER[t]:T):F&t?t:T:T},Q=function(t){return arguments.length?function(){throw new Error('"'+t+'" not implemented')}:function(){throw new Error("Method not implemented")}};return f.ORDER={LEX:T,LEXICOGRAPHIC:T,REVLEX:D,ANTILEX:D,REVERSELEXICOGRAPHIC:D,ANTILEXICOGRAPHIC:D,COLEX:G,COLEXICOGRAPHIC:G,REVCOLEX:H,ANTICOLEX:H,REVERSECOLEXICOGRAPHIC:H,ANTICOLEXICOGRAPHIC:H,GRAY:B,MINIMAL:B,RANDOM:V,RANDOMISED:V,STOCHASTIC:Y},f.Util={rnd:Math.random,rint:function(t,r){return f.Arithmetic.round((r-t)*f.Util.rnd()+t)},shuffle:q,pick:E,operate:b,operation:w,map:y,intersection:x,union:k,kronecker:U,cartesian:C,num:function(t){return parseInt(t,10)},val:function(t){return f.Arithmetic.floor(t.valueOf())},equ:function(t,r){return t===r},gte:function(t,r){return t>=r},lte:function(t,r){return r>=t},gt:function(t,r){return t>r},lt:function(t,r){return r>t},add:function(t,r){return t+r},sub:function(t,r){return t-r},mul:function(t,r){return t*r},div:function(t,r){return f.Arithmetic.floor(t/r)},mod:function(t,r){return t%r},pow:Math.pow,shl:function(t,r){return t<>r},bor:function(t,r){return t|r},band:function(t,r){return t&r},neg:function(t){return f.Arithmetic.sub(0,t)},abs:Math.abs,min:Math.min,max:Math.max,floor:Math.floor,ceil:Math.ceil,round:Math.round,sum:M,product:L,pow2:S,powNK:N,factorial:P,binomial:X,partitions:j},f.Arithmetic={num:f.Util.num,val:f.Util.val,equ:f.Util.equ,gte:f.Util.gte,lte:f.Util.lte,gt:f.Util.gt,lt:f.Util.lt,add:f.Util.add,sub:f.Util.sub,mul:f.Util.mul,div:f.Util.div,mod:f.Util.mod,pow:f.Util.pow,shl:f.Util.shl,shr:f.Util.shr,bor:f.Util.bor,band:f.Util.band,neg:f.Util.neg,abs:f.Util.abs,min:f.Util.min,max:f.Util.max,floor:f.Util.floor,ceil:f.Util.ceil,round:f.Util.round,rnd:f.Util.rint},f.BitArray=v({constructor:function Z(t){var r=this;return r instanceof Z?(r.length=t,void(r.bits=new Uint32Array(f.Arithmetic.ceil(t/32)))):new Z(t)},length:0,bits:null,dispose:function(){var t=this;return t.length=null,t.bits=null,t},clone:function(){var t=this,r=new f.BitArray(t.length);return r.bits=new Uint32Array(t.bits),r},fromArray:function(t){var r=this;return r.bits=new Uint32Array(t),r},toArray:function(){return h.call(this.bits)},toString:function(){return y(this.toArray(),p).join("")},reset:function(){var t,r=this,n=r.bits,e=n.length;for(t=0;e>t;t++)n[t]=0;return r},isset:function(t){return!!(this.bits[t>>>5]&1<<(31&t))},set:function(t){var r=this;return r.bits[t>>>5]|=1<<(31&t),r},unset:function(t){var r=this;return r.bits[t>>>5]&=~(1<<(31&t)),r},toggle:function(t){var r=this;return r.bits[t>>>5]^=1<<(31&t),r}}),r=f.CombinatorialIterator=v({constructor:function $(t){var r,n=this;return n instanceof $?(r=n[s],n.n=t||0,n._count=r.count(n.n),void n.order(T)):new $(t)},__static__:{count:Q(),rank:Q(),unrank:Q(),first:Q(),last:Q(),stochastic:Q(),dual:function(t,r,n){return null==t?null:(T|D)&n?t.slice():O(I(t,r))},succ:function(t,r,n,e,i){var u=this,o=f.Arithmetic;return-1!==t&&1!==t&&(t=1),null==r?null:u.unrank(o.add(u.rank(r,n,e),t),n,e)},rand:function(t,r){var n=this,e=f.Arithmetic,i=r?r:n.count(t),u=e.sub(i,1),o=e.rnd(0,u);return e.equ(0,o)?n.first(t):e.equ(o,u)?n.last(t):n.unrank(o,t,i)}},n:0,_order:0,_count:0,_index:null,__item:null,_item:null,_prev:null,_next:null,_traversed:null,_stochastic:null,dispose:function(){var t=this;return t.n=null,t._order=null,t._count=0,t._index=null,t.__item=null,t._item=null,t._prev=null,t._next=null,t._stochastic=null,t._traversed&&(t._traversed.dispose(),t._traversed=null),t},_store:function(){var t=this;return[t._order,t._index,t.__item,t._item,t._prev,t._next]},_restore:function(t){var r=this;return t&&(r._order=t[0],r._index=t[1],r.__item=t[2],r._item=t[3],r._prev=t[4],r._next=t[5]),r},total:function(){return this._count},order:function(t,r,n,e){var i,u,o,l=this,a=l[s];if(!arguments.length)return l._order;if("object"==typeof r&&arguments.length<4?(e=n,n=r,r=!1):r=!1===r,t=J(t),l._order=t,l._index=0,l._item=l.__item=null,l._prev=!1,l._next=!1,u=l._count,o=l.n,Y&t)if(null==l._stochastic||n){if(!n)throw new Error("No Stochastic Transition Matrix given!");l._stochastic=[n,e?1:0,e?[]:null],l.__item=a.stochastic(l._stochastic[0],o,l._stochastic[2]),l._item=l.__item.slice()}else null!=l._stochastic[2]&&(l._stochastic[2]=[]),l.__item=a.stochastic(l._stochastic[0],o,l._stochastic[2]),l._item=l.__item.slice();else V&t?(l._traversed?l._traversed.reset():l._traversed=new f.BitArray(u),l._traversed.set(i=l.randomIndex()),l.__item=l.item(i,T),l._item=null==l.__item?null:l.__item.slice()):B&t?l._item=l.__item=null:H&t?(l.__item=r?a.last(o,H):a.first(o,H),l._item=a.dual(l.__item,o,H)):G&t?(l.__item=r?a.first(o,G):a.last(o,G),l._item=a.dual(l.__item,o,G)):D&t?(l.__item=r?a.first(o,D):a.last(o,D),l._item=a.dual(l.__item,o,D)):(l.__item=r?a.last(o,T):a.first(o,T),l._item=a.dual(l.__item,o,T));return l._prev=z&t||!r?!1:null!=l._item,l._next=!r||z&t?null!=l._item:!1,l},index:function(t){if(!arguments.length)return this._index;var r,n=this,e=f.Arithmetic,i=n[s],u=n.n,o=n._count,l=n._order;return t=e.num(t),e.gt(0,t)&&(t=e.add(t,o)),e.gte(t,0)&&e.lt(t,o)&&(r=e.sub(o,1),B&l?(n._index=t,n._item=n.__item=null):H&l?(n._index=t,n.__item=e.equ(0,t)?i.first(u,H):e.equ(r,t)?i.last(u,H):i.unrank(t,u,o),n._item=i.dual(n.__item,u,H)):G&l?(n._index=t,n.__item=e.equ(0,t)?i.last(u,G):e.equ(r,t)?i.first(u,G):i.unrank(e.sub(r,t),u,o),n._item=i.dual(n.__item,u,G)):D&l?(n._index=t,n.__item=e.equ(0,t)?i.last(u,D):e.equ(r,t)?i.first(u,D):i.unrank(e.sub(r,t),u,o),n._item=i.dual(n.__item,u,D)):T&l&&(n._index=t,n.__item=e.equ(0,t)?i.first(u,T):e.equ(r,t)?i.last(u,T):i.unrank(t,u,o),n._item=i.dual(n.__item,u,T))),n},randomIndex:function(t,r){var n=this,e=f.Arithmetic,i=n._count,u=arguments.length;return 0===u?(t=0,r=e.sub(i,1)):1===u?(t=e.num(t||0),r=e.sub(i,1)):(t=e.num(t),r=e.num(r)),e.rnd(t,r)},item:function(t,r){if(!arguments.length)return this._item;var n,e,i,u,o=this,l=o.n,a=o._count,c=o[s],_=f.Arithmetic;if(r=null!=r?J(r):o._order,t=_.num(t),_.gt(0,t)&&(t=_.add(t,a)),_.gte(t,0)&&_.lt(t,a)){if(n=_.sub(a,1),V&r){for(e=o._traversed,i=o.randomIndex(),u=f.Util.rnd()>.5?-1:1;e.isset(i);)i=_.add(i,u),_.lt(i,0)?i=n:_.gte(i,a)&&(i=0);return e.set(i),c.unrank(i,l,a)}return B&r?null:H&r?c.dual(_.equ(0,t)?c.first(l,H):_.equ(n,t)?c.last(l,H):c.unrank(t,l,a),l,H):G&r?c.dual(_.equ(0,t)?c.last(l,G):_.equ(n,t)?c.first(l,G):c.unrank(_.sub(n,t),l,a),l,G):D&r?c.dual(_.equ(0,t)?c.last(l,D):_.equ(n,t)?c.first(l,D):c.unrank(_.sub(n,t),l,a),l,D):c.dual(_.equ(0,t)?c.first(l,T):_.equ(n,t)?c.last(l,T):c.unrank(t,l,a),l,T)}return null},random:function(){var t=this,r=t[s];return r.rand(t.n,t._count)},rewind:function(){return this.order(this._order,!0)},forward:function(){return this.order(this._order,!1)},hasNext:function(){return Y&this._order?!0:this._next},hasPrev:function(){return z&this._order?!1:this._prev},next:function(){var t,r,n,e,i=this,u=f.Arithmetic,o=i._order,l=i[s],a=i._item,c=i.n,_=i._count;if(Y&o)i.__item=l.stochastic(i._stochastic[0],c,i._stochastic[2]),i._item=i.__item.slice();else if(V&o)if(n=u.sub(_,1),u.lt(i._index,n)){for(t=i._traversed,r=i.randomIndex(),e=f.Util.rnd()>.5?-1:1;t.isset(r);)r=u.add(r,e),u.lt(r,0)?r=n:u.gt(r,n)&&(r=0);t.set(r),i.__item=i.item(r,T),i._item=null==i.__item?null:i.__item.slice()}else i._item=i.__item=null,i._traversed&&(i._traversed.dispose(),i._traversed=null);else B&o?i._item=i.__item=null:H&o?(i.__item=l.succ(1,i.__item,c,_,H),i._item=l.dual(i.__item,c,H)):G&o?(i.__item=l.succ(-1,i.__item,c,_,G),i._item=l.dual(i.__item,c,G)):D&o?(i.__item=l.succ(-1,i.__item,c,_,D),i._item=l.dual(i.__item,c,D)):(i.__item=l.succ(1,i.__item,c,_,T),i._item=l.dual(i.__item,c,T));return i._next=null!=i._item,!i._next||Y&o||(i._index=u.add(i._index,1)),a},prev:function(){var t=this,r=f.Arithmetic,n=t._order,e=t[s],i=t._item,u=t.n,o=t._count;return z&n?null:(B&n?t._item=t.__item=null:H&n?(t.__item=e.succ(-1,t.__item,u,o,H),t._item=e.dual(t.__item,u,H)):G&n?(t.__item=e.succ(1,t.__item,u,o,G),t._item=e.dual(t.__item,u,G)):D&n?(t.__item=e.succ(1,t.__item,u,o,D),t._item=e.dual(t.__item,u,D)):(t.__item=e.succ(-1,t.__item,u,o,T),t._item=e.dual(t.__item,u,T)),t._prev=null!=t._item,!t._prev||z&n||(t._index=r.sub(t._index,1)),i)},range:function(t,r){var n,e,i,u,o,l=this,a=f.Arithmetic,c=l._count,s=1,_=arguments.length,h=a.sub(c,1);if(1>_?(t=0,r=h):2>_?(t=a.num(t),r=h):(t=a.num(t),r=a.num(r)),a.lt(t,0)&&(t=a.add(t,c)),a.lt(r,0)&&(r=a.add(r,c)),a.gt(t,r)&&(n=t,t=r,r=n,s=-1),a.lt(t,0)&&(t=0),a.gt(r,h)&&(r=h),a.lte(t,r)){if(o=l._store(),z&l._order||l.index(t),i=a.val(a.sub(r,t)),e=new Array(i+1),0>s)for(u=i;u>=0;u--)e[u]=l.next();else for(u=0;i>=u;u++)e[u]=l.next();l._restore(o)}else e=[];return e}}),n=f.Permutation=v(r,{constructor:function tt(t){var n=this;return n instanceof tt?void r.call(n,t):new tt(t)},__static__:{count:function(t){return P(t)},dual:r.dual,rank:function(t,r){var n,e,i,u,o=f.Arithmetic,l=0,a=o.ceil(g(r)),c=(1<<1+a)-1,s=new Array(c),_=o.shl(1,a);for(n=0;c>n;n++)s[n]=0;for(n=0;r>n;n++){for(u=t[n],i=o.val(o.add(_,u)),e=0;a>e;e++)1&i&&(u=o.sub(u,s[i>>>1<<1])),s[i]=o.add(s[i],1),i>>>=1;s[i]=o.add(s[i],1),l=o.add(o.mul(l,o.sub(n)),u)}return l},unrank:function(t,r,n){var e,i,u,o,l,a,c,s,_,h,d,m,v=f.Arithmetic,A=this;if(n=n||P(r),v.equ(0,t))return A.first(r);if(v.equ(n,v.add(t,1)))return A.last(r);for(e=new Array(r),i=v.div(n,r),_=v.ceil(g(r)),h=(1<<1+_)-1,d=new Array(h),m=v.shl(1,_),u=0;_>=u;u++)for(o=1,l=1<=o;o++)d[l-1+o]=v.shl(1,v.sub(_,u));for(s=r-1,u=0;r>u;u++){for(a=v.div(t,i),c=1,o=0;_>o;o++)d[c]=v.sub(d[c],1),c<<=1,v.gte(a,d[c])&&(a=v.sub(a,d[c]),c++);d[c]=0,e[u]=v.val(v.sub(c,m)),s&&(t=v.mod(t,i),i=v.div(i,s),s--)}return e},first:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=r;return n},last:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=t-1-r;return n},succ:function(t,r,n){if(r){var e,i,u,o,l,a=r.slice();if(-1===t){for(e=n-2;e>=0&&a[e]<=a[e+1];)e--;if(e>=0){for(i=n-1;i>e&&a[e]<=a[i];)i--;for(l=a[e],a[e]=a[i],a[i]=l,u=e+1,o=n-1;o>u;)l=a[u],a[u++]=a[o],a[o--]=l}else a=null}else{for(e=n-2;e>=0&&a[e]>=a[e+1];)e--;if(e>=0){for(i=n-1;i>e&&a[e]>=a[i];)i--;for(l=a[e],a[e]=a[i],a[i]=l,u=e+1,o=n-1;o>u;)l=a[u],a[u++]=a[o],a[o--]=l}else a=null}return a}return null},rand:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=r;return q(n,!1,!1)},shuffle:function(t,r){return q(t,r,!1)},stochastic:function(t,r,n){if(t.length!==r||t[0].length!==r)throw new Error("Stochastic Matrix dimensions and Permutation dimensions do not match!");var e,i,u,o,l,a,c,s,_=new Array(r),h=new Array(r),d=0,m=f.Util.rnd,v=!1;for(i=0;r>i;i++)h[i]=0;if(n){if(v=!0,!n.length){for(n.N=0,e=new Array(r),i=0;r>i;i++)e[i]=0;for(i=0;r>i;i++)n.push(e.slice())}d=++n.N}for(s=!v,i=0;r>i;)for(o=m(),c=0,l=t[i],v&&(a=n[i]),u=0;r>u;u++){if(o>c&&o<=c+l[u]){0===h[u]&&(s||i+1===r||a[u]+1<=(d+1)*l[u])&&(h[u]=1,_[i]=u,v&&a[u]++,i++);break}c+=l[u]}return _},inverse:function(t,r){r=r||t.length;var n,e=new Array(r);for(n=0;r>n;n++)e[t[n]]=n;return e},compose:function(){var t,r,n,e=arguments,i=e.length,u=i?e[0]:[],o=u.length;for(r=1;i>r;r++)for(n=u.slice(),t=0;o>t;t++)u[t]=n[e[r][t]];return u},permute:function(t,r,n){var e,i,u,o=t.length;for(!0===n?(i=new Array(o),u=t):(i=t,u=t.slice()),e=0;o>e;e++)i[e]=u[r[e]];return i},reassign:function(t,r){var n,e=t.length,i=new Array(e);for(n=0;e>n;n++)i[n]=r[t[n]];return i},toCycles:function(t,r,n){r=r||t.length;var e,i,u,o=[],l=!0===n?1:0,a=new Array(r),f=new Array(r);for(e=0;r>e;e++)f[e]=e,a[e]=0;for(u=[i=f.shift()],a[i]=1;f.length;){if(i=t[i],a[i])for(u.length>l&&o.push(u),u=[];f.length&&a[i=f.shift()];);a[i]||(u.push(i),a[i]=1)}return u.length>l&&o.push(u),o},fromCycles:function(t,r){var n,e,i,u,o=new Array(r),l=t.length;for(e=0;r>e;e++)o[e]=e;for(n=0;l>n;n++)if(u=t[n],i=u.length,!(2>i)){for(e=0;i-1>e;e++)o[u[e]]=u[e+1];o[u[i-1]]=u[0]}return o},toSwaps:function(t,r){r=r||t.length;var e,i,u,o=[],l=n.toCycles(t,r,!0);for(e=0,i=l.length;i>e;e++)u=l[e],o=o.concat(R(u));return o},fromSwaps:function(t,r){var n,e,i,u=t.length,o=new Array(r);for(n=0;r>n;n++)o[n]=n;for(n=0;u>n;n++)e=t[n],i=o[e[0]],o[e[0]]=o[e[1]],o[e[1]]=i;return o},toMatrix:function(t,r,n){var e,i,u=new Array(r);for(n=!0===n,e=0;r>e;e++)for(u[e]=new Array(r),i=0;r>i;i++)u[e][i]=0;for(e=0;r>e;e++)n?u[t[e]][e]=1:u[e][t[e]]=1;return u},fromMatrix:function(t,r,n){var e,i,u=new Array(r);for(n=!0===n,e=0;r>e;e++)for(i=0;r>i;i++)t[e][i]&&(n?u[i]=e:u[e]=i);return u},isConnected:function(t,r){var n,e=-(1/0);for(r=r||t.length,n=0;r-1>n;n++)if(t[n]>e&&(e=t[n]),n>=e)return!1;return!0}}}),e=f.Combination=v(r,{constructor:function rt(t,n){var e=this;return e instanceof rt?void r.call(e,[t,n]):new rt(t,n)},__static__:{count:function(t){return X(t[0],t[1])},dual:function(t,n,e){return r.dual.call(this,t,n[0],e)},rank:function(t,r,n){var e,i,u,o,l,a=f.Arithmetic,c=0;for(o=r[1],r=r[0],l=n?n:X(r,o),e=1;o>=e;e++)i=r-1-t[e-1],u=o+1-e,i>=u&&(c=a.add(c,X(i,u)));return a.sub(a.sub(l,1),c)},unrank:function(t,r,n){var e,i,u,o,l,a,c=f.Arithmetic,s=this;if(n=n||X(r[0],r[1]),c.equ(0,t))e=s.first(r);else if(c.equ(n,c.add(t,1)))e=s.last(r);else{u=r[1],r=r[0],e=new Array(u),i=n,t=c.sub(c.sub(i,1),t),i=c.div(c.mul(i,c.sub(r,u)),r),l=r-u+1,o=u,a=r-1;do c.lte(i,t)?(e[u-o]=r-l-o+1,c.gt(i,0)&&(t=c.sub(t,i),i=c.div(c.mul(i,o),a)),o--,a--):(i=c.div(c.mul(i,c.sub(a,o)),a),l--,a--);while(o>0)}return e},first:function(t){var r,n=t[1],e=new Array(n);for(r=0;n>r;r++)e[r]=r;return e},last:function(t){var r,n=t[1],e=new Array(n);for(t=t[0],r=0;n>r;r++)e[n-1-r]=t-1-r;return e},succ:function(t,r,n){if(r){var e,i,u,o,l,a=r.slice();if(e=n[1],n=n[0],-1===t){for(i=e-1,u=-1;i>0;){if(a[i]>a[i-1]+1){u=i;break}i--}if(-1===u&&0-1){for(l=n,i=e-1;i>u;i--)a[i]=--l;a[u]--}else a=null}else{for(i=e-1,u=-1,o=n-e;i>=0;){if(a[i]-1)for(l=a[u],i=u;e>i;i++)a[i]=++l;else a=null}return a}return null},rand:function(t){var r,n,e,i,u,o,l,a;for(n=t[1],t=t[0],r=new Array(n),e=f.Util.rnd(),u=0,l=0,a=t-n,i=1;n>=i;i++){for(u++,o=(n-i+1)/(t-u+1);e>=o&&a+i>u;)l=o,u++,o=l+(1-l)*((n-i+1)/(t-u+1));r[i-1]=u-1,e=(e-l)/(o-l)}return r},stochastic:r.stochastic,complement:function(t,r){return I(t,r,!0)},pick:function(t,r){return E(t,r,!0)},choose:function(t,r){var n,e=r.length,i=new Array(e);for(n=0;e>n;n++)i[n]=t[r[n]];return i},toMatrix:function(t,r,n){var e,i,u,o;for(i=r[1],r=r[0],e=new Array(r),n=!0===n,u=0;r>u;u++)for(e[u]=new Array(r),o=0;r>o;o++)e[u][o]=0;for(u=0;i>u;u++)n?e[t[u]][u]=1:e[u][t[u]]=1;return e},fromMatrix:function(t,r,n){var e,i,u,o;for(i=r[1],r=r[0],e=new Array(i),n=!0===n,u=0;r>u;u++)for(o=0;r>o;o++)t[u][o]&&(n&&i>o?e[o]=u:!n&&i>u&&(e[u]=o));return e}}}),e.conjugate=e.complement,i=f.CombinationRepeat=v(r,{constructor:function nt(t,n){var e=this;return e instanceof nt?void r.call(e,[t,n]):new nt(t,n)},__static__:{count:function(t){return X(t[0]+t[1]-1,t[1])},dual:e.dual,rank:function(t,r,n){var e,i,u,o,l,a,c=f.Arithmetic,s=0;for(o=r[1],r=r[0],l=r+o-1,a=n?n:X(l,o),e=1;o>=e;e++)i=l-1-t[e-1]-e+1,u=o+1-e,i>=u&&(s=c.add(s,X(i,u)));return c.sub(c.sub(a,1),s)},unrank:function(t,r,n){var e,i,u,o,l,a,c,s=f.Arithmetic,_=this;if(n=n||X(r[0]+r[1]-1,r[1]),s.equ(0,t))return _.first(r);if(s.equ(n,s.add(t,1)))return _.last(r);u=r[1],r=r[0],o=r+u-1,e=new Array(u),i=n,t=s.sub(s.sub(i,1),t),i=s.div(s.mul(i,s.sub(o,u)),o),a=o-u+1,l=u,c=o-1;do s.lte(i,t)?(e[u-l]=o-a-u+1,s.gt(i,0)&&(t=s.sub(t,i),i=s.div(s.mul(i,l),c)),l--,c--):(i=s.div(s.mul(i,s.sub(c,l)),c),a--,c--);while(l>0);return e},first:function(t){var r,n=t[1],e=new Array(n);for(r=0;n>r;r++)e[r]=0;return e},last:function(t){var r,n=t[1],e=new Array(n);for(t=t[0]-1,r=0;n>r;r++)e[r]=t;return e},succ:function(t,r,n){if(r){var e,i,u,o,l=r.slice();if(e=n[1],n=n[0],-1===t){for(i=e-1,u=-1;i>0;){if(l[i]>l[i-1]){u=i;break}i--}if(-1===u&&0-1){for(o=n-1,i=u+1;e>i;i++)l[i]=o;l[u]--}else l=null}else{for(i=e-1,u=-1;i>=0;){if(l[i]-1)for(o=l[u]+1,i=u;e>i;i++)l[i]=o;else l=null}return l}return null},rand:function(t){var r,n,e,i,u,o,l,a,c;for(n=t[1],t=t[0],r=new Array(n),e=f.Util.rnd(),u=0,l=0,a=t+n-1,c=a-n,i=1;n>=i;i++){for(u++,o=(n-i+1)/(a-u+1);e>=o&&c+i>u;)l=o,u++,o=l+(1-l)*((n-i+1)/(a-u+1));r[i-1]=u-i,e=(e-l)/(o-l)}return r},stochastic:e.stochastic}}),u=f.Partition=v(r,{constructor:function et(t){var n=this;return n instanceof et?void r.call(n,t):new et(t)},__static__:{count:function(t){var r,n,e=f.Arithmetic.add,i=t>1?2:1;for(r=2;t>r;r++)for(n=t-r+1;n>=1;n--)i=e(i,j(t,r,n));return i},dual:function(t,r){if(null==t)return null;var n,e,i=[],u=t.length;for(n=0;u>n;n++)if(e=r-t[n],!(0>=e)){if(r===e)return[r];i.unshift(e)}return i},rank:function(t,r,n,e,i){var u,o,l,a=f.Arithmetic,c=this,s=t.length,_=r;return n=n||c.count(r),e=e||0,i=i||s,o=e,l=t[o],u=_===l?a.sub(n,1):1===l?0:s>o+1?a.add(1,c.rank(t,r-l,a.sub(n,c.count(r-l)),o+1)):0},unrank:function(t,r,n){return null},first:function(t){var r,n=new Array(t);for(r=0;t>r;r++)n[r]=1;return n},last:function(t){return[t]},succ:function(t,r,n){if(r){var e,i,u,o,l,a,f=r.slice();if(-1===t)if(f[0]>1){for(i=f.length,e=i-1;e>=0&&1===f[e];)e--;for(u=f[e]-1,f=f.slice(0,e+1),f[e]=u,l=M(f),a=n-l;a>0;)o=a,o>u?(o=u,f.push(o)):f.push(a),a-=o}else f=null;else if(f[0]0&&e--;e>0&&f[e]===f[e-1];)e--;for(f[e]++,f=f.slice(0,e+1),l=M(f),a=n-l;a>0;)f.push(1),a--}else f=null;return f}return null},rand:function(t,r){return null},stochastic:r.stochastic,conjugate:function(t){var r,n,e,i=t.length,u=t[0],o=new Array(u);for(r=0;u>r;r++)o[r]=1;for(n=1;i>n;n++)for(r=0,e=t[n];u>r&&e>0;)o[r++]++,e--;return o},pack:function(t){var r,n=[],e=t.length,i=t[0],u=[i,1];for(r=1;e>r;r++)i===t[r]?u[1]++:(n.push(u),i=t[r],u=[i,1]);return n.push(u),n},unpack:function(t){var r,n,e,i,u,o=[],l=t.length;for(r=0;l>r;r++)if(u=t[r],1===u[1])o.push(u[0]);else for(e=u[1],i=u[0],n=0;e>n;n++)o.push(i);return o}}}),u.transpose=u.conjugate,o=f.Powerset=f.Subset=v(r,{constructor:function it(t){var n=this;return n instanceof it?void r.call(n,t):new it(t)},__static__:{count:function(t){return S(t)},rank:function(t,r,n){for(var e=f.Arithmetic,i=0,u=0,o=t.length;o>u;)i=e.add(i,e.shl(1,t[u++]));return i},unrank:function(t,r,n){var e=this,i=f.Arithmetic,u=[],o=0;if(i.lt(t,0)||i.gte(t,n?n:e.count(r)))return null;for(;i.gt(t,0);)i.gt(i.band(t,1),0)&&u.push(o),i.gt(i.band(t,2),0)&&u.push(o+1),i.gt(i.band(t,4),0)&&u.push(o+2),i.gt(i.band(t,8),0)&&u.push(o+3),i.gt(i.band(t,16),0)&&u.push(o+4),i.gt(i.band(t,32),0)&&u.push(o+5),i.gt(i.band(t,64),0)&&u.push(o+6),i.gt(i.band(t,128),0)&&u.push(o+7),o+=8,t=i.shr(t,8);return u},rand:function(t,n){var e=r.rand.call(this,t,n);return null==e?null:e.reverse()},stochastic:r.stochastic,dual:function(t,r,n){return null==t?null:(G|H|z)&n?t.slice():O(I(t,r,!0))},first:function(t,r){var n,e=new Array(t);for(n=0;t>n;n++)e[n]=n;return e},last:function(t,r){return[]},succ:function(t,n,e,i,u){return-1!==t&&1!==t&&(t=1),null==n?null:r.succ.call(this,-t,n,e,i,u)}}}),l=f.Tensor=v(r,{constructor:function ut(){var t=this;return t instanceof ut?void(arguments.length?r.call(t,h.call(arguments)):(t.n=[],t._count=0)):(t=new ut,arguments.length?r.call(t,h.call(arguments)):(t.n=[],t._count=0),t)},__static__:{count:function(t){return t&&t.length?L(t):0},dual:function(t,r,n){return(T|D)&n?null==t?null:t.slice():null==t?null:I(t,r,!1,!0)},rank:function(t,r){var n,e,i=f.Arithmetic,u=r,o=u.length;if(!o)return-1;for(n=0,e=0;o>e;e++)n=i.add(i.mul(n,u[e]),t[e]);return n},unrank:function(t,r){var n,e,i,u,o,l=f.Arithmetic,a=r,c=a.length;if(!c)return[];for(o=new Array(c),n=t,i=c-1;i>=0;i--)e=a[i],u=l.mod(n,e),n=l.div(n,e),o[i]=l.val(u);return o},first:function(t){var r,n=t.length,e=new Array(n);for(r=0;n>r;r++)e[r]=0;return e},last:function(t){var r,n=t,e=n.length,i=new Array(e);for(r=0;e>r;r++)i[r]=n[r]-1;return i},succ:function(t,r,n){if(r){var e,i,u=r.slice(),o=n,l=o.length;if(-1===t){for(e=l-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,i=e+1;l>i;i++)u[i]=o[i]-1;else u=null}else{for(e=l-1;e>=0&&u[e]+1===o[e];)e--;if(e>=0)for(u[e]++,i=e+1;l>i;i++)u[i]=0;else u=null}return u}return null},rand:function(t){var r,n=f.Arithmetic.rnd,e=t,i=e.length,u=new Array(i);for(r=0;i>r;r++)u[r]=n(0,e[r]-1);return u},stochastic:r.stochastic,product:U,component:function(t,r){var n,e,i,u,o,l,a=[],f=r,c=f.length;for(n=0;c>n;n++)if(i=f[n],o=t[n],u=i[o],u instanceof Array)for(e=0,l=u.length;l>e;e++)a.push(u[e]);else a.push(u);return a}}}),a=f.Tuple=v(r,{constructor:function ot(t,n){var e=this;return e instanceof ot?void r.call(e,[t||1,n||2]):new ot(t,n)},__static__:{count:function(t){return N(t[1],t[0])},dual:function(t,r,n){return(T|D)&n?null==t?null:t.slice():O(I(t,r[1]))},rank:function(t,r){var n,e,i=f.Arithmetic,u=r[0];for(r=r[1],n=0,e=0;u>e;e++)n=i.add(i.mul(n,r),t[e]);return n},unrank:function(t,r){var n,e,i,u,o,l=f.Arithmetic,a=r[0];for(r=r[1],o=new Array(a),n=t,i=a-1;i>=0;i--)e=r,u=l.mod(n,e),n=l.div(n,e),o[i]=l.val(u);return o},first:function(t){var r,n=t[0],e=new Array(n);for(r=0;n>r;r++)e[r]=0;return e},last:function(t){var r,n=t[0],e=new Array(n);for(t=t[1]-1,r=0;n>r;r++)e[r]=t;return e},succ:function(t,r,n){if(r){var e,i,u=r.slice(),o=n[0],n=n[1];if(-1===t){for(e=o-1;e>=0&&u[e]-1<0;)e--;if(e>=0)for(u[e]--,i=e+1;o>i;i++)u[i]=n-1;else u=null}else{for(e=o-1;e>=0&&u[e]+1===n;)e--;if(e>=0)for(u[e]++,i=e+1;o>i;i++)u[i]=0;else u=null}return u}return null},rand:function(t){var r,n=f.Arithmetic.rnd,e=t[0],i=new Array(e);for(t=t[1]-1,r=0;e>r;r++)i[r]=n(0,t);return i},stochastic:l.stochastic}}),f}); \ No newline at end of file diff --git a/test/combinations.txt b/test/combinations.txt index a577a03..85d6782 100644 --- a/test/combinations.txt +++ b/test/combinations.txt @@ -116,28 +116,28 @@ o.order("revcolex") [ 0, 1, 3 ] [ 0, 1, 2 ] o.random() -[ 0, 1, 4 ] +[ 2, 3, 5 ] o.order("random") -[ 0, 4, 5 ] -[ 1, 2, 4 ] -[ 0, 1, 2 ] -[ 0, 1, 4 ] [ 0, 3, 4 ] +[ 1, 4, 5 ] [ 0, 1, 5 ] +[ 1, 2, 4 ] +[ 0, 3, 5 ] +[ 0, 2, 3 ] +[ 1, 2, 5 ] +[ 0, 2, 5 ] +[ 0, 2, 4 ] [ 1, 3, 4 ] -[ 2, 3, 5 ] [ 2, 3, 4 ] -[ 1, 2, 5 ] -[ 0, 1, 3 ] -[ 1, 3, 5 ] -[ 1, 4, 5 ] -[ 0, 2, 3 ] [ 2, 4, 5 ] +[ 0, 1, 4 ] +[ 0, 4, 5 ] [ 1, 2, 3 ] -[ 0, 2, 4 ] -[ 0, 3, 5 ] -[ 0, 2, 5 ] +[ 1, 3, 5 ] +[ 2, 3, 5 ] [ 3, 4, 5 ] +[ 0, 1, 3 ] +[ 0, 1, 2 ] o.order("colex").range(-5, -1) [ [ 2, 3, 5 ], [ 0, 4, 5 ], [ 1, 4, 5 ], [ 2, 4, 5 ], [ 3, 4, 5 ] ] o.dispose() diff --git a/test/combinations_repeats.txt b/test/combinations_repeats.txt index 87d9c86..bc7569a 100644 --- a/test/combinations_repeats.txt +++ b/test/combinations_repeats.txt @@ -296,64 +296,64 @@ o.order("revcolex") [ 0, 0, 1 ] [ 0, 0, 0 ] o.random() -[ 0, 1, 2 ] +[ 4, 4, 5 ] o.order("random") -[ 0, 1, 4 ] +[ 1, 5, 5 ] +[ 1, 2, 4 ] +[ 0, 3, 3 ] +[ 0, 1, 5 ] +[ 1, 2, 3 ] +[ 0, 5, 5 ] +[ 0, 3, 4 ] +[ 1, 2, 2 ] +[ 1, 4, 5 ] +[ 1, 4, 4 ] +[ 0, 0, 4 ] +[ 1, 1, 1 ] +[ 2, 4, 4 ] [ 2, 3, 5 ] -[ 0, 0, 0 ] [ 3, 3, 4 ] -[ 0, 2, 3 ] -[ 4, 5, 5 ] -[ 0, 4, 5 ] -[ 1, 1, 4 ] -[ 1, 2, 2 ] -[ 4, 4, 4 ] +[ 2, 4, 5 ] +[ 0, 3, 5 ] +[ 0, 4, 4 ] [ 0, 2, 4 ] -[ 2, 4, 4 ] -[ 0, 1, 3 ] -[ 4, 4, 5 ] -[ 5, 5, 5 ] -[ 2, 3, 3 ] -[ 2, 2, 3 ] -[ 2, 2, 5 ] -[ 0, 0, 2 ] -[ 3, 4, 4 ] -[ 2, 3, 4 ] -[ 1, 4, 4 ] -[ 2, 2, 4 ] -[ 1, 3, 4 ] [ 1, 3, 3 ] -[ 0, 0, 1 ] -[ 1, 1, 3 ] -[ 1, 5, 5 ] +[ 0, 4, 5 ] +[ 3, 3, 3 ] +[ 3, 5, 5 ] [ 0, 2, 5 ] -[ 0, 0, 4 ] -[ 1, 4, 5 ] -[ 1, 1, 1 ] -[ 2, 2, 2 ] -[ 0, 1, 2 ] +[ 1, 3, 4 ] +[ 3, 3, 5 ] +[ 4, 4, 4 ] +[ 1, 1, 5 ] +[ 2, 2, 4 ] [ 1, 1, 2 ] +[ 2, 5, 5 ] +[ 1, 1, 4 ] [ 0, 2, 2 ] +[ 2, 2, 3 ] [ 3, 4, 5 ] +[ 1, 3, 5 ] +[ 0, 1, 4 ] +[ 3, 4, 4 ] +[ 1, 1, 3 ] +[ 4, 5, 5 ] +[ 4, 4, 5 ] +[ 0, 1, 2 ] +[ 1, 2, 5 ] +[ 0, 2, 3 ] +[ 2, 3, 4 ] +[ 2, 2, 2 ] +[ 2, 2, 5 ] +[ 0, 1, 3 ] +[ 0, 0, 2 ] [ 0, 1, 1 ] [ 0, 0, 5 ] -[ 1, 2, 4 ] -[ 1, 2, 3 ] -[ 0, 5, 5 ] -[ 0, 3, 4 ] -[ 1, 1, 5 ] -[ 0, 3, 5 ] -[ 1, 2, 5 ] -[ 3, 5, 5 ] -[ 3, 3, 3 ] -[ 0, 4, 4 ] -[ 2, 4, 5 ] +[ 2, 3, 3 ] +[ 5, 5, 5 ] +[ 0, 0, 0 ] +[ 0, 0, 1 ] [ 0, 0, 3 ] -[ 3, 3, 5 ] -[ 1, 3, 5 ] -[ 0, 1, 5 ] -[ 2, 5, 5 ] -[ 0, 3, 3 ] o.order("colex").range(-5, -1) [ [ 1, 5, 5 ], [ 2, 5, 5 ], [ 3, 5, 5 ], [ 4, 5, 5 ], [ 5, 5, 5 ] ] o.dispose() diff --git a/test/partitions.txt b/test/partitions.txt index 89c69df..32542dc 100644 --- a/test/partitions.txt +++ b/test/partitions.txt @@ -5,25 +5,25 @@ o.total() 7 default order is "lex", lexicographic-order o.next() -[ 1, 1, 1, 1, 1 ] +[ 4, 4, 4, 4, 4 ] o.hasNext() true o.next() -[ 2, 1, 1, 1 ] +[ 4, 4, 4, 3 ] o.rewind() -[ 1, 1, 1, 1, 1 ] -[ 2, 1, 1, 1 ] -[ 2, 2, 1 ] -[ 3, 1, 1 ] +[ 4, 4, 4, 4, 4 ] +[ 4, 4, 4, 3 ] +[ 4, 3, 3 ] +[ 4, 4, 2 ] [ 3, 2 ] [ 4, 1 ] -[ 5 ] +[] o.forward() -[ 5 ] +[] [ 4, 1 ] [ 3, 2 ] -[ 3, 1, 1 ] -[ 2, 2, 1 ] -[ 2, 1, 1, 1 ] -[ 1, 1, 1, 1, 1 ] +[ 4, 4, 2 ] +[ 4, 3, 3 ] +[ 4, 4, 4, 3 ] +[ 4, 4, 4, 4, 4 ] o.dispose() diff --git a/test/permutations-bigint.txt b/test/permutations-bigint.txt index 56f5da5..a1f33de 100644 --- a/test/permutations-bigint.txt +++ b/test/permutations-bigint.txt @@ -4,56 +4,56 @@ o = Abacus.Permutation(50) o.total() 30414093201713378043612608166064768844377641568960512000000000000 o.random() -[ 1, - 32, - 10, - 39, - 17, - 49, - 38, - 42, - 41, - 45, - 44, - 37, - 8, - 16, - 2, - 12, +[ 17, + 43, 5, - 21, - 24, - 13, 36, - 40, + 42, + 35, + 33, 14, - 3, + 31, 26, - 4, - 46, - 23, - 34, - 47, - 43, + 41, + 25, + 39, 30, + 16, + 10, + 3, + 28, + 11, + 9, + 12, + 23, + 27, + 19, 48, - 25, - 0, - 6, + 24, + 47, + 34, 15, - 18, - 29, + 45, + 38, + 13, 20, - 27, - 28, - 19, - 33, - 31, - 11, + 8, + 21, + 32, + 44, + 18, 7, - 9, - 35, - 22 ] + 0, + 6, + 49, + 22, + 2, + 46, + 1, + 37, + 29, + 40, + 4 ] o.item(78043612608166064768844377641568960512000000000000,"lex") [ 0, 1, diff --git a/test/permutations.txt b/test/permutations.txt index 296f373..a7c2a3b 100644 --- a/test/permutations.txt +++ b/test/permutations.txt @@ -136,32 +136,32 @@ o.order("revcolex") [ 2, 3, 1, 0 ] [ 3, 2, 1, 0 ] o.random() -[ 0, 1, 3, 2 ] -o.order("random") [ 3, 0, 2, 1 ] -[ 1, 3, 2, 0 ] -[ 2, 3, 0, 1 ] -[ 2, 1, 3, 0 ] -[ 1, 3, 0, 2 ] -[ 3, 1, 2, 0 ] -[ 0, 3, 2, 1 ] -[ 3, 1, 0, 2 ] -[ 2, 1, 0, 3 ] -[ 2, 0, 3, 1 ] -[ 3, 2, 0, 1 ] -[ 1, 2, 3, 0 ] -[ 1, 0, 2, 3 ] -[ 0, 1, 3, 2 ] -[ 1, 2, 0, 3 ] +o.order("random") [ 0, 2, 3, 1 ] [ 0, 2, 1, 3 ] +[ 0, 3, 1, 2 ] +[ 2, 1, 0, 3 ] +[ 1, 2, 0, 3 ] +[ 3, 1, 0, 2 ] +[ 3, 0, 1, 2 ] +[ 0, 3, 2, 1 ] +[ 0, 1, 3, 2 ] +[ 2, 3, 0, 1 ] +[ 1, 0, 2, 3 ] [ 1, 0, 3, 2 ] [ 2, 3, 1, 0 ] -[ 3, 2, 1, 0 ] -[ 2, 0, 1, 3 ] -[ 3, 0, 1, 2 ] [ 0, 1, 2, 3 ] -[ 0, 3, 1, 2 ] +[ 2, 0, 1, 3 ] +[ 1, 2, 3, 0 ] +[ 2, 1, 3, 0 ] +[ 3, 1, 2, 0 ] +[ 1, 3, 0, 2 ] +[ 3, 2, 1, 0 ] +[ 2, 0, 3, 1 ] +[ 3, 0, 2, 1 ] +[ 1, 3, 2, 0 ] +[ 3, 2, 0, 1 ] o.order("colex").range(-5, -1) [ [ 1, 2, 0, 3 ], [ 2, 0, 1, 3 ], @@ -170,13 +170,13 @@ o.order("colex").range(-5, -1) [ 0, 1, 2, 3 ] ] o.order("stochastic", [ [ 0, 1, 0, 0 ], [ 1/3, 0, 1/3, 1/3 ], [ 1/3, 0, 1/3, 1/3 ], [ 1/3, 0, 1/3, 1/3 ] ]).range(0, 9) [ [ 1, 0, 2, 3 ], - [ 1, 3, 2, 0 ], - [ 1, 3, 2, 0 ], - [ 1, 3, 2, 0 ], - [ 1, 0, 2, 3 ], + [ 1, 3, 0, 2 ], [ 1, 2, 3, 0 ], + [ 1, 0, 3, 2 ], + [ 1, 2, 3, 0 ], + [ 1, 0, 3, 2 ], + [ 1, 0, 3, 2 ], + [ 1, 3, 0, 2 ], [ 1, 3, 2, 0 ], - [ 1, 3, 2, 0 ], - [ 1, 0, 2, 3 ], - [ 1, 2, 0, 3 ] ] + [ 1, 3, 0, 2 ] ] o.dispose() diff --git a/test/powersets.js b/test/subsets.js similarity index 91% rename from test/powersets.js rename to test/subsets.js index 34a9842..c60b21e 100644 --- a/test/powersets.js +++ b/test/subsets.js @@ -6,12 +6,12 @@ var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = con // generate all combinatorial objects without storing all of them in memory at once var o; -echo('Abacus.Powersets (VERSION = '+Abacus.VERSION+')'); +echo('Abacus.Subsets (VERSION = '+Abacus.VERSION+')'); echo('---'); // Powersets -echo('o = Abacus.Powerset(4)'); -o = Abacus.Powerset(4); +echo('o = Abacus.Subset(4)'); +o = Abacus.Subset(4); echo('o.total()'); echo(o.total()); @@ -62,5 +62,3 @@ echo (o.order("colex").range(-5, -1)); // dispose echo('o.dispose()'); o.dispose(); - - diff --git a/test/powersets.txt b/test/subsets.txt similarity index 72% rename from test/powersets.txt rename to test/subsets.txt index 7c60cab..fe506c2 100644 --- a/test/powersets.txt +++ b/test/subsets.txt @@ -1,6 +1,6 @@ -Abacus.Powersets (VERSION = 0.1.0) +Abacus.Subsets (VERSION = 0.1.0) --- -o = Abacus.Powerset(4) +o = Abacus.Subset(4) o.total() 16 default order is "lex", lexicographic-order @@ -62,58 +62,58 @@ o.order("revlex") [ 0 ] [] o.order("colex") -[ 3, 2, 1, 0 ] -[ 2, 1, 0 ] -[ 3, 1, 0 ] -[ 1, 0 ] -[ 3, 2, 0 ] -[ 2, 0 ] -[ 3, 0 ] +[] [ 0 ] -[ 3, 2, 1 ] -[ 2, 1 ] -[ 3, 1 ] [ 1 ] -[ 3, 2 ] +[ 0, 1 ] [ 2 ] +[ 0, 2 ] +[ 1, 2 ] +[ 0, 1, 2 ] [ 3 ] -[] +[ 0, 3 ] +[ 1, 3 ] +[ 0, 1, 3 ] +[ 2, 3 ] +[ 0, 2, 3 ] +[ 1, 2, 3 ] +[ 0, 1, 2, 3 ] o.order("revcolex") -[] +[ 0, 1, 2, 3 ] +[ 1, 2, 3 ] +[ 0, 2, 3 ] +[ 2, 3 ] +[ 0, 1, 3 ] +[ 1, 3 ] +[ 0, 3 ] [ 3 ] +[ 0, 1, 2 ] +[ 1, 2 ] +[ 0, 2 ] [ 2 ] -[ 3, 2 ] +[ 0, 1 ] [ 1 ] -[ 3, 1 ] -[ 2, 1 ] -[ 3, 2, 1 ] [ 0 ] -[ 3, 0 ] -[ 2, 0 ] -[ 3, 2, 0 ] -[ 1, 0 ] -[ 3, 1, 0 ] -[ 2, 1, 0 ] -[ 3, 2, 1, 0 ] +[] o.random() -[ 3 ] +[ 2, 1 ] o.order("random") -[ 3, 1, 0 ] -[ 1, 0 ] -[ 2, 1, 0 ] -[ 2 ] -[ 3, 2 ] -[ 3 ] +[ 3, 2, 0 ] [ 0 ] -[] -[ 3, 1 ] -[ 3, 2, 1, 0 ] -[ 3, 0 ] [ 2, 1 ] +[ 3 ] +[ 2, 0 ] [ 1 ] +[ 2, 1, 0 ] +[ 3, 0 ] [ 3, 2, 1 ] -[ 3, 2, 0 ] -[ 2, 0 ] +[ 3, 1 ] +[ 2 ] +[ 1, 0 ] +[] +[ 3, 2, 1, 0 ] +[ 3, 1, 0 ] +[ 3, 2 ] o.order("colex").range(-5, -1) -[ [ 1 ], [ 3, 2 ], [ 2 ], [ 3 ], [] ] +[ [ 2 ], [ 0, 2 ], [ 1, 2 ], [ 0, 1, 2 ], [ 3 ] ] o.dispose() diff --git a/test/tensors.txt b/test/tensors.txt index 80595ff..98f258b 100644 --- a/test/tensors.txt +++ b/test/tensors.txt @@ -46,14 +46,14 @@ o.order("revcolex") [ 0, 0, 1 ] [ 0, 0, 0 ] o.random() -[ 0, 1, 1 ] +[ 0, 1, 2 ] o.order("random") -[ 0, 1, 1 ] -[ 0, 0, 2 ] -[ 0, 1, 0 ] [ 0, 0, 1 ] [ 0, 0, 0 ] [ 0, 1, 2 ] +[ 0, 0, 2 ] +[ 0, 1, 0 ] +[ 0, 1, 1 ] o.order("colex").range(-5, -1) [ [ 0, 0, 1 ], [ 0, 0, 2 ], [ 0, 1, 0 ], [ 0, 1, 1 ], [ 0, 1, 2 ] ] o.dispose() diff --git a/test/test.bat b/test/test.bat index 3987a30..80c90c7 100644 --- a/test/test.bat +++ b/test/test.bat @@ -4,7 +4,7 @@ call node permutations.js > permutations.txt call node permutations-bigint.js > permutations-bigint.txt call node combinations.js > combinations.txt call node combinations_repeats.js > combinations_repeats.txt -call node powersets.js > powersets.txt +call node subsets.js > subsets.txt call node partitions.js > partitions.txt call node tensors.js > tensors.txt call node tuples.js > tuples.txt diff --git a/test/tuples.txt b/test/tuples.txt index 26ffb01..3db8157 100644 --- a/test/tuples.txt +++ b/test/tuples.txt @@ -153,33 +153,33 @@ o.order("revcolex") o.random() [ 0, 1, 1 ] o.order("random") -[ 1, 2, 2 ] -[ 0, 0, 2 ] -[ 2, 0, 1 ] -[ 2, 1, 2 ] -[ 2, 2, 1 ] -[ 0, 1, 2 ] +[ 2, 0, 0 ] [ 1, 0, 1 ] -[ 0, 2, 0 ] +[ 1, 0, 2 ] +[ 0, 1, 0 ] [ 0, 2, 1 ] -[ 1, 1, 2 ] -[ 0, 1, 1 ] -[ 1, 0, 0 ] -[ 2, 2, 2 ] [ 1, 1, 1 ] [ 2, 1, 0 ] +[ 0, 2, 2 ] +[ 0, 0, 2 ] +[ 1, 1, 0 ] +[ 2, 0, 2 ] +[ 2, 1, 1 ] [ 2, 2, 0 ] +[ 1, 0, 0 ] +[ 0, 1, 1 ] +[ 1, 2, 2 ] +[ 2, 0, 1 ] +[ 0, 1, 2 ] [ 0, 0, 1 ] -[ 2, 1, 1 ] -[ 1, 2, 1 ] -[ 2, 0, 0 ] +[ 2, 1, 2 ] +[ 0, 2, 0 ] +[ 2, 2, 1 ] +[ 1, 1, 2 ] [ 1, 2, 0 ] -[ 0, 2, 2 ] -[ 2, 0, 2 ] -[ 1, 0, 2 ] -[ 1, 1, 0 ] +[ 2, 2, 2 ] +[ 1, 2, 1 ] [ 0, 0, 0 ] -[ 0, 1, 0 ] o.order("colex").range(-5, -1) [ [ 1, 1, 2 ], [ 2, 1, 2 ], [ 0, 2, 2 ], [ 1, 2, 2 ], [ 2, 2, 2 ] ] o.dispose()