Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,4 +1,4 @@
|
|||
When counting integers in binary, if you put a (binary) point to the right of the count then the column immediately to the left denotes a digit with a multiplier of <math>2^0</math>; the next column to the lefts digit has a multiplier of <math>2^1</math> and so on.
|
||||
When counting integers in binary, if you put a (binary) point to the right of the count then the column immediately to the left denotes a digit with a multiplier of <math>2^0</math>; the digit in the next column to the left has a multiplier of <math>2^1</math>; and so on.
|
||||
|
||||
So in the following table:
|
||||
<pre> 0.
|
||||
|
|
@ -6,9 +6,9 @@ So in the following table:
|
|||
10.
|
||||
11.
|
||||
...</pre>
|
||||
The binary number "<code>10</code>" is <math>1 \times 2^1 + 0 \times 2^0</math>.
|
||||
the binary number "<code>10</code>" is <math>1 \times 2^1 + 0 \times 2^0</math>.
|
||||
|
||||
You can have binary digits to the right of the “point” just as in the decimal number system too. in this case, the digit in the place immediately to the right of the point has a weight of <math>2^{-1}</math>, or <math>1/2</math>.
|
||||
You can also have binary digits to the right of the “point”, just as in the decimal number system. In that case, the digit in the place immediately to the right of the point has a weight of <math>2^{-1}</math>, or <math>1/2</math>.
|
||||
The weight for the second column to the right of the point is <math>2^{-2}</math> or <math>1/4</math>. And so on.
|
||||
|
||||
If you take the integer binary count of the first table, and ''reflect'' the digits about the binary point, you end up with '''the van der Corput sequence of numbers in base 2'''.
|
||||
|
|
@ -19,7 +19,7 @@ If you take the integer binary count of the first table, and ''reflect'' the dig
|
|||
.11
|
||||
...</pre>
|
||||
|
||||
The third member of the sequence: binary <code>0.01</code> is therefore <math>0 \times 2^{-1} + 1 \times 2^{-2}</math> or <math>1/4</math>.
|
||||
The third member of the sequence, binary <code>0.01</code>, is therefore <math>0 \times 2^{-1} + 1 \times 2^{-2}</math> or <math>1/4</math>.
|
||||
|
||||
<br> [[File:Van der corput distribution.png|400|thumb|right|Distribution of 2500 points each: Van der Corput (top) vs pseudorandom]] Members of the sequence lie within the interval <math>0 \leq x < 1</math>. Points within the sequence tend to be evenly distributed which is a useful trait to have for [[wp:Monte Carlo method|Monte Carlo simulations]].
|
||||
This sequence is also a superset of the numbers representable by the "fraction" field of [[wp:IEEE 754-1985|an old IEEE floating point standard]]. In that standard, the "fraction" field represented the fractional part of a binary number beginning with "1." e.g. 1.101001101.
|
||||
|
|
|
|||
27
Task/Van-der-Corput-sequence/AWK/van-der-corput-sequence.awk
Normal file
27
Task/Van-der-Corput-sequence/AWK/van-der-corput-sequence.awk
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# syntax: GAWK -f VAN_DER_CORPUT_SEQUENCE.AWK
|
||||
# converted from BBC BASIC
|
||||
BEGIN {
|
||||
printf("base")
|
||||
for (i=0; i<=9; i++) {
|
||||
printf(" %7d",i)
|
||||
}
|
||||
printf("\n")
|
||||
for (base=2; base<=5; base++) {
|
||||
printf("%-4s",base)
|
||||
for (i=0; i<=9; i++) {
|
||||
printf(" %7.5f",vdc(i,base))
|
||||
}
|
||||
printf("\n")
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
function vdc(n,b, s,v) {
|
||||
s = 1
|
||||
while (n) {
|
||||
s *= b
|
||||
v += (n % b) / s
|
||||
n /= b
|
||||
n = int(n)
|
||||
}
|
||||
return(v)
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
defmodule Van_der_corput do
|
||||
def sequence( n ), do: sequence( n, 2 )
|
||||
|
||||
def sequence( 0, _base ), do: 0.0
|
||||
def sequence( n, base ) do
|
||||
List.to_float( '0.' ++ ( for x <- sequence_loop(n, base), do: Integer.to_char_list(x) ) |> List.flatten )
|
||||
end
|
||||
|
||||
def sequence_loop( 0, _base ), do: []
|
||||
def sequence_loop( n, base ) do
|
||||
new_n = div(n, base)
|
||||
digit = rem(n, base)
|
||||
[digit | sequence_loop( new_n, base )]
|
||||
end
|
||||
end
|
||||
|
||||
Enum.each(2..5, fn base ->
|
||||
IO.puts "Base #{base}: #{inspect Enum.map(0..9, fn x -> Van_der_corput.sequence(x, base) end)}"
|
||||
end)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
function vdc{T<:Integer}(n::T, b::T)
|
||||
sum([d*float(b)^-i for (i, d) in enumerate(digits(n, b))])
|
||||
end
|
||||
|
||||
for i in 2:9
|
||||
print(" Base ", i)
|
||||
for j in 0:9
|
||||
print(@sprintf(" %8.6f", vdc(j, i)))
|
||||
end
|
||||
println()
|
||||
end
|
||||
|
|
@ -1,16 +1,2 @@
|
|||
sub vdc($num, $base = 2) {
|
||||
my $n = $num;
|
||||
my $vdc = 0;
|
||||
my $denom = 1;
|
||||
while $n {
|
||||
$vdc += $n mod $base / ($denom *= $base);
|
||||
$n div= $base;
|
||||
}
|
||||
$vdc;
|
||||
}
|
||||
|
||||
for 2..5 -> $b {
|
||||
say "Base $b";
|
||||
say (vdc($_,$b) for ^10).perl;
|
||||
say '';
|
||||
}
|
||||
constant VdC = map { :2("0." ~ .base(2).flip) }, ^Inf;
|
||||
.say for VdC[^16];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
sub vdc($value, $base = 2) {
|
||||
my @values := $value, { $_ div $base } ... 0;
|
||||
my @denoms := $base, { $_ * $base } ... *;
|
||||
[+] do for @values Z @denoms -> $v, $d {
|
||||
$v mod $base / $d;
|
||||
}
|
||||
sub VdC($base = 2) {
|
||||
map {
|
||||
[+] $_ && .polymod($base xx *) Z/ [\*] $base xx *
|
||||
}, ^Inf
|
||||
}
|
||||
|
||||
.say for VdC[^10];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
sub vdc($num, $base = 2) {
|
||||
my $n = $num;
|
||||
my $vdc = 0;
|
||||
my $denom = 1;
|
||||
while $n {
|
||||
$vdc += $n mod $base / ($denom *= $base);
|
||||
$n div= $base;
|
||||
}
|
||||
$vdc;
|
||||
}
|
||||
|
||||
for 2..5 -> $b {
|
||||
say "Base $b";
|
||||
say (vdc($_,$b) for ^10).perl;
|
||||
say '';
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
sub vdc($value, $base = 2) {
|
||||
my @values := $value, { $_ div $base } ... 0;
|
||||
my @denoms := $base, { $_ * $base } ... *;
|
||||
[+] do for @values Z @denoms -> $v, $d {
|
||||
$v mod $base / $d;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue