June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,11 +1,7 @@
|
|||
function vdc{T<:Integer}(n::T, b::T)
|
||||
sum([d*float(b)^-i for (i, d) in enumerate(digits(n, b))])
|
||||
end
|
||||
vandercorput(num::Integer, base::Integer) = sum(d * Float64(base) ^ -ex for (ex, d) in enumerate(digits(num, base)))
|
||||
|
||||
for i in 2:9
|
||||
print(" Base ", i)
|
||||
for j in 0:9
|
||||
print(@sprintf(" %8.6f", vdc(j, i)))
|
||||
end
|
||||
println()
|
||||
for base in 2:9
|
||||
@printf("%10s %i:", "Base", base)
|
||||
for num in 0:9 @printf("%7.3f", vandercorput(num, base)) end
|
||||
println(" [...]")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
MODULE Sequence;
|
||||
FROM FormatString IMPORT FormatString;
|
||||
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
|
||||
|
||||
PROCEDURE vc(n,base : INTEGER; VAR num,denom : INTEGER);
|
||||
VAR p,q : INTEGER;
|
||||
BEGIN
|
||||
p := 0;
|
||||
q := 1;
|
||||
|
||||
WHILE n#0 DO
|
||||
p := p * base + (n MOD base);
|
||||
q := q * base;
|
||||
n := n DIV base
|
||||
END;
|
||||
|
||||
num := p;
|
||||
denom := q;
|
||||
|
||||
WHILE p#0 DO
|
||||
n := p;
|
||||
p := q MOD p;
|
||||
q := n
|
||||
END;
|
||||
|
||||
num := num DIV q;
|
||||
denom := denom DIV q
|
||||
END vc;
|
||||
|
||||
VAR
|
||||
buf : ARRAY[0..31] OF CHAR;
|
||||
d,n,i,b : INTEGER;
|
||||
BEGIN
|
||||
FOR b:=2 TO 5 DO
|
||||
FormatString("base %i:", buf, b);
|
||||
WriteString(buf);
|
||||
FOR i:=0 TO 9 DO
|
||||
vc(i,b,n,d);
|
||||
IF n#0 THEN
|
||||
FormatString(" %i/%i", buf, n, d);
|
||||
WriteString(buf)
|
||||
ELSE
|
||||
WriteString(" 0")
|
||||
END
|
||||
END;
|
||||
WriteLn
|
||||
END;
|
||||
|
||||
ReadChar
|
||||
END Sequence.
|
||||
|
|
@ -6,47 +6,48 @@ if a=='' | a=="," then parse value 0 10 with a b /*Not specified? Then use the
|
|||
if b=='' | b=="," then b=a /* " " " " " " */
|
||||
if r=='' | r=="," then r=2 /* " " " " " " */
|
||||
z= /*a placeholder for a list of numbers. */
|
||||
do j=a to b /*traipse through the range of integers*/
|
||||
_=VdC( abs(j), abs(r) ) /*convert the ABSolute value of integer*/
|
||||
_=substr('-', 2+sign(j) )_ /*if needed, keep the leading - sign.*/
|
||||
if r>0 then say _ /*if positive base, then just show it. */
|
||||
else z=z _ /* ··· else append (build) a list. */
|
||||
end /*j*/
|
||||
do j=a to b /*traipse through the range of integers*/
|
||||
_=VdC( abs(j), abs(r) ) /*convert the ABSolute value of integer*/
|
||||
_=substr('-', 2 + sign(j) )_ /*if needed, keep the leading - sign.*/
|
||||
if r>0 then say _ /*if positive base, then just show it. */
|
||||
else z=z _ /* ··· else append (build) a list. */
|
||||
end /*j*/
|
||||
|
||||
if z\=='' then say strip(z) /*if a list is wanted, then display it.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
base: procedure; parse arg x, toB, inB /*get a number, toBase, and inBase. */
|
||||
/*┌───────────────────────────────────────────────────────────────────┐
|
||||
┌─┘ Input to this function: x (is required & must be an integer).└─┐
|
||||
│ toBase the base to convert X to. │
|
||||
│ inBase the base X is expressed in. │
|
||||
│ │
|
||||
│ toBase or inBase can be omitted which causes the default of 10 │
|
||||
└─┐ to be used. Both have a limit of: 2 ──► 90.┌─┘
|
||||
└───────────────────────────────────────────────────────────────────┘*/
|
||||
@abc= 'abcdefghijklmnopqrstuvwxyz' /*the Latin lowercase alphabet chars. */
|
||||
@abcU=@abc; upper @abcU /*go whole hog and extend characters. */
|
||||
@@@= 0123456789 || @abc || @abcU /*prefix them with some numeric digits.*/
|
||||
/*╔══════════════════════════════════════════════════════════════════════════════════╗
|
||||
║ Input to this function: x (X is required and it must be an integer). ║
|
||||
║ toBase the base to convert X to (default=10). ║
|
||||
║ inBase the base X is expressed in (default=10). ║
|
||||
║ ║
|
||||
║ toBase & inBase have a limit of: 2 ──► 90 ║
|
||||
╚══════════════════════════════════════════════════════════════════════════════════╝*/
|
||||
@abc= 'abcdefghijklmnopqrstuvwxyz' /*the lowercase Latin alphabet letters.*/
|
||||
@abcU=@abc; upper @abcU /*go whole hog & extend with uppercase.*/
|
||||
@@@= 0123456789 || @abc || @abcU /*prefix them with the decimal digits. */
|
||||
@@@= @@@'<>[]{}()?~!@#$%^&*_+-=|\/;:`' /*add some special characters as well, */
|
||||
/*special characters should be viewable*/
|
||||
numeric digits 1000 /*what the hey, support biggy numbers.*/
|
||||
/*──those chars should all be viewable.*/
|
||||
numeric digits 1000 /*what the hey, support bigun' numbers.*/
|
||||
maxB=length(@@@) /*maximum base (radix) supported here. */
|
||||
if toB=='' then toB=10 /*if skipped, then assume default (10)*/
|
||||
if toB=='' then toB=10 /*if omitted, then assume default (10)*/
|
||||
if inB=='' then inB=10 /* " " " " " " */
|
||||
#=0 /* [↓] convert base inB X ──► base 10*/
|
||||
do j=1 for length(x)
|
||||
do j=1 for length(x) /*process each "numeral" in the string.*/
|
||||
_=substr(x, j, 1) /*pick off a "digit" (numeral) from X.*/
|
||||
v=pos(_, @@@) /*get the value of this "digit"/numeral*/
|
||||
if v==0|v>inB then call erd x,j,inB /*is it an illegal "digit" (numeral) ? */
|
||||
#=#*inB + v - 1 /*construct new number, digit by digit.*/
|
||||
if v==0 | v>inB then call erd /*is it an illegal "digit" (numeral) ? */
|
||||
#=# * inB + v - 1 /*construct new number, digit by digit.*/
|
||||
end /*j*/
|
||||
y= /* [↓] convert base 10 # ──► base toB.*/
|
||||
do while #>=toB /*deconstruct the new number (#). */
|
||||
y=substr(@@@, #//toB + 1, 1)y /* construct the output number, ··· */
|
||||
do while #>=toB /*deconstruct the new number (#). */
|
||||
y=substr(@@@, # // toB + 1, 1)y /* construct the output number, ··· */
|
||||
#=# % toB /* ··· and also whittle down #. */
|
||||
end /*while*/
|
||||
|
||||
return substr(@@@, #+1, 1)y
|
||||
return substr(@@@, # + 1, 1)y /*return a constructed "numeric" string*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
erd: say 'the character ' v " isn't a legal numeral for base " inB'.'; exit 13
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
VdC: return '.'reverse(base(arg(1), arg(2))) /*convert the #, reverse the #, append.*/
|
||||
|
|
|
|||
|
|
@ -10,4 +10,6 @@ st_store(k,2,0.5*runiform(2500,1))
|
|||
st_store(k,3,0.5:+0.5*halton(2500,1))
|
||||
end
|
||||
twoway scatter y x, msize(tiny) color(blue) ///
|
||||
|| scatter z x, msize(tiny) color(green)
|
||||
|| scatter z x, msize(tiny) color(green) legend(off) xtitle("") ///
|
||||
title(Distribution: Van der Corput (top) vs pseudorandom) ///
|
||||
ylabel(, angle(0) format(%3.1f))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue