Skip to content
Browse files

Integer#mangoldt: Add

  • Loading branch information...
1 parent dd88149 commit b4810e6c3d5382e9854e7dafe7e77188b1a400e3 @runpaint committed
Showing with 38 additions and 0 deletions.
  1. +4 −0 lib/numb/primes.rb
  2. +34 −0 spec/numb/mangoldt_spec.rb
View
4 lib/numb/primes.rb
@@ -170,4 +170,8 @@ def wieferich_prime?
def chen_prime?
prime? and (succ.succ.prime? or succ.succ.semiprime?)
end
+
+ def mangoldt
+ prime? ? Math.log(prime_factors.first) : 0
+ end
end
View
34 spec/numb/mangoldt_spec.rb
@@ -0,0 +1,34 @@
+# coding: utf-8
+describe Integer, "#mangoldt" do
+ # A029833
+ @seq = [0,1,1,0,2,0,2,0,0,0,2,0,3,0,0,0,3,0,3,0,0,0,3,0,
+ 0,0,0,0,3,0,3,0,0,0,0,0,4,0,0,0,4,0,4,0,0,0,4,0,0,
+ 0,0,0,4,0,0,0,0,0,4,0,4,0,0,0,0,0,4,0,0,0,4,0,4,0,
+ 0,0,0,0,4,0]
+
+ @seq.to_enum.with_index(1).each do |m, n|
+ it "returns a value which rounds to #{m} for #{n}" do
+ n.mangoldt.round.should == m
+ end
+ end
+
+ # A029834
+ [0,0,1,0,1,0,1,0,0,0,2,0,2,0,0,0,2,0,2,0,0,0,3,0,
+ 0,0,0,0,3,0,3,0,0,0,0,0,3,0,0,0,3,0,3,0,0,0,3,0,0,
+ 0,0,0,3,0,0,0,0,0,4,0,4,0,0,0,0,0,4,0,0,0,4,0,4,0,
+ 0,0,0,0,4,0].to_enum.with_index(1).each do |m, n|
+ it "returns a value which has a floor of #{m} for #{n}" do
+ n.mangoldt.floor.should == m
+ end
+ end
+
+ # A029832
+ [0,1,2,0,2,0,2,0,0,0,3,0,3,0,0,0,3,0,3,0,0,0,4,0,
+ 0,0,0,0,4,0,4,0,0,0,0,0,4,0,0,0,4,0,4,0,0,0,4,0,0,
+ 0,0,0,4,0,0,0,0,0,5,0,5,0,0,0,0,0,5,0,0,0,5,0,5,0,
+ 0,0,0,0,5,0].to_enum.with_index(1).each do |m, n|
+ it "returns a value which has a ceiling of #{m} for #{n}" do
+ n.mangoldt.ceil.should == m
+ end
+ end
+end

0 comments on commit b4810e6

Please sign in to comment.
Something went wrong with that request. Please try again.