-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support pluggable arithmetic routines, eg bigInteger arithmetic if ne…
…eded as needed
- Loading branch information
Nikos M
committed
Jun 19, 2016
1 parent
653ed10
commit 6eb1969
Showing
5 changed files
with
758 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
var isNode = 'undefined' !== typeof global && '[object global]' === {}.toString.call(global); | ||
var Abacus = isNode ? require('../src/js/Abacus.js') : window.Abacus, echo = console.log; | ||
var bigInt = require('./BigInteger.js'); | ||
|
||
// plug-in bigInteger arithmetic routines | ||
Abacus.ARITHMETIC.equ = function(a, b){ return bigInt(a).eq(bigInt(b)); }; | ||
Abacus.ARITHMETIC.gte = function(a, b){ return bigInt(a).geq(bigInt(b)); }; | ||
Abacus.ARITHMETIC.lte = function(a, b){ return bigInt(a).leq(bigInt(b)); }; | ||
Abacus.ARITHMETIC.gt = function(a, b){ return bigInt(a).gt(bigInt(b)); }; | ||
Abacus.ARITHMETIC.lt = function(a, b){ return bigInt(a).lt(bigInt(b)); }; | ||
Abacus.ARITHMETIC.add = function(a, b){ return bigInt(a).plus(bigInt(b)); }; | ||
Abacus.ARITHMETIC.sub = function(a, b){ return bigInt(a).minus(bigInt(b)); }; | ||
Abacus.ARITHMETIC.mul = function(a, b){ return bigInt(a).times(bigInt(b)); }; | ||
Abacus.ARITHMETIC.div = function(a, b){ return bigInt(a).over(bigInt(b)); }; | ||
Abacus.ARITHMETIC.mod = function(a, b){ return bigInt(a).mod(bigInt(b)); }; | ||
Abacus.ARITHMETIC.shl = function(a, b){ return bigInt(a).shiftLeft(bigInt(b)); }; | ||
Abacus.ARITHMETIC.shr = function(a, b){ return bigInt(a).shiftRight(bigInt(b)); }; | ||
Abacus.ARITHMETIC.pow = function(a, b){ return bigInt(a).pow(bigInt(b)); }; | ||
Abacus.ARITHMETIC.rnd = function(a, b){ return bigInt.randBetween(bigInt(a),bigInt(b)); }; | ||
Abacus.ARITHMETIC.min = bigInt.min; | ||
Abacus.ARITHMETIC.max = bigInt.max; | ||
|
||
// Note: Due to the large number of combinatorial samples, | ||
// Abacus combinatorics use an Iterator pattern to succesively and consistently | ||
// generate all combinatorial objects without storing all of them in memory at once | ||
var o, i; | ||
|
||
echo('Abacus.Permutations (VERSION = '+Abacus.VERSION+')'); | ||
echo('---'); | ||
|
||
// Permutations | ||
echo('o = Abacus.Permutation(50)'); | ||
o = Abacus.Permutation(50); | ||
|
||
echo('o.total()'); | ||
echo(String(o.total())); | ||
/* | ||
echo('default order is "lex", lexicographic-order'); | ||
echo('o.next()'); | ||
echo(o.next()); | ||
echo('o.hasNext()'); | ||
echo(o.hasNext()); | ||
echo('o.next()'); | ||
echo(o.next()); | ||
*/ | ||
/* | ||
echo('o.rewind()'); | ||
o.rewind(); | ||
for(i=0; i<10&&o.hasNext(); i++) echo (o.next()); | ||
echo('o.forward()'); | ||
o.forward(); | ||
for(i=0; i<10&&o.hasNext(); i++) echo (o.prev()); | ||
echo('o.order("revlex")'); | ||
o.order("revlex"); | ||
for(i=0; i<10&&o.hasNext(); i++) echo (o.next()); | ||
echo('o.order("colex")'); | ||
o.order("colex"); | ||
for(i=0; i<10&&o.hasNext(); i++) echo (o.next()); | ||
echo('o.order("revcolex")'); | ||
o.order("revcolex"); | ||
for(i=0; i<10&&o.hasNext(); i++) echo (o.next()); | ||
*/ | ||
|
||
echo('o.random()'); | ||
echo(o.random()); | ||
|
||
echo('o.item(78043612608166064768844377641568960512000000000000,"lex")'); | ||
echo(o.item(bigInt("78043612608166064768844377641568960512000000000000"),"lex")); | ||
|
||
echo('o.item(78043612608166064768844377641568960512000000000000,"colex")'); | ||
echo(o.item(bigInt("78043612608166064768844377641568960512000000000000"),"colex")); | ||
|
||
echo('o.item(78043612608166064768844377641568960512000000000000,"revlex")'); | ||
echo(o.item(bigInt("78043612608166064768844377641568960512000000000000"),"revlex")); | ||
|
||
echo('o.item(78043612608166064768844377641568960512000000000000,"revcolex")'); | ||
echo(o.item(bigInt("78043612608166064768844377641568960512000000000000"),"revcolex")); | ||
|
||
// dispose | ||
echo('o.dispose()'); | ||
o.dispose(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
Abacus.Permutations (VERSION = 0.1.0) | ||
--- | ||
o = Abacus.Permutation(50) | ||
o.total() | ||
30414093201713378043612608166064768844377641568960512000000000000 | ||
o.random() | ||
[ 44, | ||
10, | ||
42, | ||
26, | ||
0, | ||
24, | ||
21, | ||
45, | ||
38, | ||
1, | ||
5, | ||
34, | ||
20, | ||
31, | ||
32, | ||
40, | ||
28, | ||
19, | ||
41, | ||
25, | ||
29, | ||
4, | ||
14, | ||
46, | ||
18, | ||
15, | ||
30, | ||
47, | ||
9, | ||
33, | ||
48, | ||
12, | ||
7, | ||
22, | ||
6, | ||
3, | ||
43, | ||
13, | ||
37, | ||
35, | ||
39, | ||
49, | ||
8, | ||
11, | ||
23, | ||
36, | ||
27, | ||
17, | ||
2, | ||
16 ] | ||
o.item(78043612608166064768844377641568960512000000000000,"lex") | ||
[ 0, | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
10, | ||
22, | ||
36, | ||
11, | ||
30, | ||
34, | ||
12, | ||
27, | ||
9, | ||
31, | ||
26, | ||
20, | ||
48, | ||
19, | ||
18, | ||
47, | ||
13, | ||
24, | ||
14, | ||
21, | ||
17, | ||
38, | ||
16, | ||
15, | ||
41, | ||
40, | ||
43, | ||
23, | ||
28, | ||
39, | ||
46, | ||
37, | ||
35, | ||
45, | ||
8, | ||
33, | ||
42, | ||
29, | ||
44, | ||
49, | ||
25, | ||
32 ] | ||
o.item(78043612608166064768844377641568960512000000000000,"colex") | ||
[ 32, | ||
25, | ||
49, | ||
44, | ||
29, | ||
42, | ||
33, | ||
8, | ||
45, | ||
35, | ||
37, | ||
46, | ||
39, | ||
28, | ||
23, | ||
43, | ||
40, | ||
41, | ||
15, | ||
16, | ||
38, | ||
17, | ||
21, | ||
14, | ||
24, | ||
13, | ||
47, | ||
18, | ||
19, | ||
48, | ||
20, | ||
26, | ||
31, | ||
9, | ||
27, | ||
12, | ||
34, | ||
30, | ||
11, | ||
36, | ||
22, | ||
10, | ||
7, | ||
6, | ||
5, | ||
4, | ||
3, | ||
2, | ||
1, | ||
0 ] | ||
o.item(78043612608166064768844377641568960512000000000000,"revlex") | ||
[ 49, | ||
48, | ||
47, | ||
46, | ||
45, | ||
44, | ||
43, | ||
42, | ||
39, | ||
27, | ||
13, | ||
38, | ||
19, | ||
15, | ||
37, | ||
22, | ||
40, | ||
18, | ||
23, | ||
29, | ||
1, | ||
30, | ||
31, | ||
2, | ||
36, | ||
25, | ||
35, | ||
28, | ||
32, | ||
11, | ||
33, | ||
34, | ||
8, | ||
9, | ||
6, | ||
26, | ||
21, | ||
10, | ||
3, | ||
12, | ||
14, | ||
4, | ||
41, | ||
16, | ||
7, | ||
20, | ||
5, | ||
0, | ||
24, | ||
17 ] | ||
o.item(78043612608166064768844377641568960512000000000000,"revcolex") | ||
[ 17, | ||
24, | ||
0, | ||
5, | ||
20, | ||
7, | ||
16, | ||
41, | ||
4, | ||
14, | ||
12, | ||
3, | ||
10, | ||
21, | ||
26, | ||
6, | ||
9, | ||
8, | ||
34, | ||
33, | ||
11, | ||
32, | ||
28, | ||
35, | ||
25, | ||
36, | ||
2, | ||
31, | ||
30, | ||
1, | ||
29, | ||
23, | ||
18, | ||
40, | ||
22, | ||
37, | ||
15, | ||
19, | ||
38, | ||
13, | ||
27, | ||
39, | ||
42, | ||
43, | ||
44, | ||
45, | ||
46, | ||
47, | ||
48, | ||
49 ] | ||
o.dispose() |