login  home  contents  what's new  discussion  bug reports help  links  subscribe  changes  refresh  edit
 Topics FrontPage Aldor SandBox Aldor Sieve <-- You are here. SandBox SandBox Aldor Sieve <-- You are here. From section 1.2 of Aldor Users Guide sieve.as A prime number sieve to count primes <= n. fricas(1) -> # include "fricas.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 } fricasCompiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/860059225630362337-25px001.as using Aldor compiler and options -O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I$FRICAS/algebra Use the system command )set compiler args to change these options. fricasCompiling Lisp source code from file ./860059225630362337-25px001.lsp Issuing )library command for 860059225630362337-25px001 fricasReading /var/aw/var/LatexWiki/860059225630362337-25px001.asy fricasfor i in 1..4 repeat n := 10^i outputList ["There are ", sieve n, " primes <= ", n] There are 4 primes <= 10 There are 25 primes <= 100 There are 168 primes <= 1000 There are 1229 primes <= 10000 Type: Void To run this program on your own computer you need Linux and FriCAS+Aldor. You need to build them from sources, follow the instructions in INSTALL. Save the program source as a file called 'sieve.as':  $vim sieve.as  Start FriCAS: $ fricas  Compile the program:  (1) -> )compile sieve.as  Run it:  for i in 1..6 repeat ( _ n := 10^i; _ outputList ["There are ", sieve n, " primes <= ", n] _ ) 

 Subject:   Be Bold !! ( 14 subscribers )