Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -0,0 +1,66 @@
package {
import flash.display.Sprite;
import flash.events.Event;
public class VanDerCorput extends Sprite {
public function VanDerCorput():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
var base2:Vector.<Number> = new Vector.<Number>(10, true);
var base3:Vector.<Number> = new Vector.<Number>(10, true);
var base4:Vector.<Number> = new Vector.<Number>(10, true);
var base5:Vector.<Number> = new Vector.<Number>(10, true);
var base6:Vector.<Number> = new Vector.<Number>(10, true);
var base7:Vector.<Number> = new Vector.<Number>(10, true);
var base8:Vector.<Number> = new Vector.<Number>(10, true);
var i:uint;
for ( i = 0; i < 10; i++ ) {
base2[i] = Math.round( _getTerm(i, 2) * 1000000 ) / 1000000;
base3[i] = Math.round( _getTerm(i, 3) * 1000000 ) / 1000000;
base4[i] = Math.round( _getTerm(i, 4) * 1000000 ) / 1000000;
base5[i] = Math.round( _getTerm(i, 5) * 1000000 ) / 1000000;
base6[i] = Math.round( _getTerm(i, 6) * 1000000 ) / 1000000;
base7[i] = Math.round( _getTerm(i, 7) * 1000000 ) / 1000000;
base8[i] = Math.round( _getTerm(i, 8) * 1000000 ) / 1000000;
}
trace("Base 2: " + base2.join(', '));
trace("Base 3: " + base3.join(', '));
trace("Base 4: " + base4.join(', '));
trace("Base 5: " + base5.join(', '));
trace("Base 6: " + base6.join(', '));
trace("Base 7: " + base7.join(', '));
trace("Base 8: " + base8.join(', '));
}
private function _getTerm(n:uint, base:uint = 2):Number {
var r:Number = 0, p:uint, digit:uint;
var baseLog:Number = Math.log(base);
while ( n > 0 ) {
p = Math.pow( base, uint(Math.log(n) / baseLog) );
digit = n / p;
n %= p;
r += digit / (p * base);
}
return r;
}
}
}

View file

@ -0,0 +1,25 @@
(defn van-der-corput
"Get the nth element of the van der Corput sequence."
([n]
;; Default base = 2
(van-der-corput n 2))
([n base]
(let [s (/ 1 base)] ;; A multiplicand to shift to the right of the decimal.
;; We essentially want to reverse the digits of n and put them after the
;; decimal point. So, we repeatedly pull off the lowest digit of n, scale
;; it to the right of the decimal point, and accumulate that.
(loop [sum 0
n n
scale s]
(if (zero? n)
sum ;; Base case: no digits left, so we're done.
(recur (+ sum (* (rem n base) scale)) ;; Accumulate the least digit
(quot n base) ;; Drop a digit of n
(* scale s))))))) ;; Move farther past the decimal
(clojure.pprint/print-table
(cons :base (range 10)) ;; column headings
(for [base (range 2 6)] ;; rows
(into {:base base}
(for [n (range 10)] ;; table entries
[n (van-der-corput n base)]))))

View file

@ -0,0 +1,6 @@
| :base | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|-------+---+-----+-----+-----+------+------+------+-------+-------+-------|
| 2 | 0 | 1/2 | 1/4 | 3/4 | 1/8 | 5/8 | 3/8 | 7/8 | 1/16 | 9/16 |
| 3 | 0 | 1/3 | 2/3 | 1/9 | 4/9 | 7/9 | 2/9 | 5/9 | 8/9 | 1/27 |
| 4 | 0 | 1/4 | 1/2 | 3/4 | 1/16 | 5/16 | 9/16 | 13/16 | 1/8 | 3/8 |
| 5 | 0 | 1/5 | 2/5 | 3/5 | 4/5 | 1/25 | 6/25 | 11/25 | 16/25 | 21/25 |

View file

@ -0,0 +1,11 @@
/* convert a decimal integer to a list of digits in base `base' */
dec2digits(d, base):= block([digits: []],
while (d>0) do block([newdi: mod(d, base)],
digits: cons(newdi, digits),
d: round( (d - newdi) / base)),
digits)$
dec2digits(123, 10);
/* [1, 2, 3] */
dec2digits( 8, 2);
/* [1, 0, 0, 0] */

View file

@ -0,0 +1,9 @@
/* convert a list of digits in base `base' to a decimal integer */
digits2dec(l, base):= block([s: 0, po: 1],
for di in reverse(l) do (s: di*po + s, po: po*base),
s)$
digits2dec([1, 2, 3], 10);
/* 123 */
digits2dec([1, 0, 0, 0], 2);
/* 8 */

View file

@ -0,0 +1,19 @@
vdc(n, base):= makelist(
digits2dec(
dec2digits(k, base),
1/base) / base,
k, n);
vdc(10, 2);
/*
1 1 3 1 5 3 7 1 9 5
(%o123) [-, -, -, -, -, -, -, --, --, --]
2 4 4 8 8 8 8 16 16 16
*/
vdc(10, 5);
/*
1 2 3 4 1 6 11 16 21 2
(%o124) [-, -, -, -, --, --, --, --, --, --]
5 5 5 5 25 25 25 25 25 25
*/

View file

@ -0,0 +1,21 @@
/* 11 in decimal is */
digits: digits2dec([box(1), box(0), box(1), box(1)], box(2));
aux: expand(digits2dec(digits, 1/base) / base)$
simp: false$
/* reflected this would become ... */
subst(box(2), base, aux);
simp: true$
/*
3 2
""" """ """ """ """ """ """
(%o126) "2" "1" + "2" "0" + "2" "1" + "1"
""" """ """ """ """ """ """
- 4 - 3 - 2 - 1
""" """ """ """ """ """ """ """
(%o129) "1" "2" + "0" "2" + "1" "2" + "1" "2"
""" """ """ """ """ """ """ """
*/