Permalink
Browse files

Integer#ramanujan_tau: Add

  • Loading branch information...
1 parent c296649 commit 3e11fd7dd37694277f2aa1c6cd7688cbb11b9c38 @runpaint committed Mar 27, 2010
Showing with 30 additions and 0 deletions.
  1. +7 −0 lib/numb/divisors.rb
  2. +23 −0 spec/numb/ramanujan_tau_spec.rb
View
@@ -415,4 +415,11 @@ def smarandache
primaries.map{|b,e| (b**e).smarandache}.max
end
end
+
+ def ramanujan_tau
+ return 1 if (n = self) == 1
+ n**4 * n.σ - 24 * (1...n).map do |k|
+ k**2 * (35 * k**2 - 52 * k * n + 18 * n**2) * k.σ * (n-k).σ
+ end.reduce(:+)
+ end
end
@@ -0,0 +1,23 @@
+# coding: utf-8
+describe Integer, "#ramanujan_tau" do
+ # A000594
+ @seq = [1,-24,252,-1472,4830,-6048,-16744,84480,-113643,
+ -115920,534612,-370944,-577738,401856,1217160,
+ 987136,-6905934,2727432,10661420,-7109760,
+ -4219488,-12830688,18643272,21288960,-25499225,
+ 13865712,-73279080,24647168]
+
+ @seq.to_enum.with_index(1).each do |r, n|
+ it "returns #{r} for #{n}" do
+ n.ramanujan_tau.should == r
+ end
+ end
+
+ # Confirm some arbitrary large(ish) values to confirm we aren't subject to
+ # rounding errors
+ [[1357, -96743736788237280], [1314, 3992391292945104]].each do |n, r|
+ it "returns #{r} for #{n}" do
+ n.ramanujan_tau.should == r
+ end
+ end
+end

0 comments on commit 3e11fd7

Please sign in to comment.