Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Mertens-function/Zkl/mertens-function-1.zkl
Normal file
25
Task/Mertens-function/Zkl/mertens-function-1.zkl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
fcn mertensW(n){
|
||||
[1..].tweak(fcn(n,pm){
|
||||
pm.incN(mobius(n));
|
||||
pm.value
|
||||
}.fp1(Ref(0)))
|
||||
}
|
||||
fcn mobius(n){
|
||||
pf:=primeFactors(n);
|
||||
sq:=pf.filter1('wrap(f){ (n % (f*f))==0 }); // False if square free
|
||||
if(sq==False){ if(pf.len().isEven) 1 else -1 }
|
||||
else 0
|
||||
}
|
||||
fcn primeFactors(n){ // Return a list of prime factors of n
|
||||
acc:=fcn(n,k,acc,maxD){ // k is 2,3,5,7,9,... not optimum
|
||||
if(n==1 or k>maxD) acc.close();
|
||||
else{
|
||||
q,r:=n.divr(k); // divr-->(quotient,remainder)
|
||||
if(r==0) return(self.fcn(q,k,acc.write(k),q.toFloat().sqrt()));
|
||||
return(self.fcn(n,k+1+k.isOdd,acc,maxD)) # both are tail recursion
|
||||
}
|
||||
}(n,2,Sink(List),n.toFloat().sqrt());
|
||||
m:=acc.reduce('*,1); // mulitply factors
|
||||
if(n!=m) acc.append(n/m); // opps, missed last factor
|
||||
else acc;
|
||||
}
|
||||
9
Task/Mertens-function/Zkl/mertens-function-2.zkl
Normal file
9
Task/Mertens-function/Zkl/mertens-function-2.zkl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
mertensW().walk(199)
|
||||
.pump(Console.println, T(Void.Read,19,False),
|
||||
fcn{ vm.arglist.pump(String,"%3d".fmt) });
|
||||
|
||||
println("\nIn the first 1,000 terms of the Mertens sequence there are:");
|
||||
otm:=mertensW().pump(1_000,List);
|
||||
otm.reduce(fcn(s,m){ s + (m==0) },0) : println(_," zeros");
|
||||
otm.reduce(fcn(p,m,rs){ rs.incN(m==0 and p!=0); m }.fp2( s:=Ref(0) ));
|
||||
println(s.value," zero crossings");
|
||||
Loading…
Add table
Add a link
Reference in a new issue