login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for SandBox Aldor Sieve revision 5 of 9

1 2 3 4 5 6 7 8 9
Editor: 127.0.0.1
Time: 2007/10/31 18:01:34 GMT-7
Note:

added:


From section 1.2 of Aldor Users Guide

sieve.as -- A prime number sieve to count primes <= n.

begin{aldor} # include "axiom.as"

import from Boolean, Integer, NonNegativeInteger?;

sieve(n: Integer): Integer == {

isprime: OneDimensionalArray? Boolean := new(n::NonNegativeInteger?, true);

np:Integer := 0; for p in 2..n | isprime p repeat {

np := np + 1; for i in (p+p)..n by p repeat isprime i := false;

} np

}

end{aldor}

begin{axiom} )lisp (si::allocate-contiguous-pages 1500 t) )lisp (si::allocate 'sfun 50 t)

for i in 1..4 repeat
n := 10^i outputList ["There are ", sieve n, " primes <= ", n]?

end{axiom}

To run this program on your own computer you need linux and Axiom+Aldor from AxiomBinaries?.

1 Save the program source as a file called 'sieve.as':

$ vi sieve.as

2 Start Axiom:

$ AXIOMsys

3 Compile the program:

(1) -> )compile sieve.as

4 Run it:

for i in 1..6 repeat ( _
    n := 10^i; _
    outputList ["There are ", sieve n, " primes <= ", n] _
)

four is not prime --Bill Page, Sun, 04 Mar 2007 19:38:24 -0600 reply

begin{aldor} #include "axiom.as" macro Z == Integer;

main(): Boolean == {
import from Z; b: Boolean := prime? 4; return b;

} end{aldor}

begin{axiom} main() end{axiom}