2017年4月25日火曜日

170425

Ruby


Glaisher's chi_4(n)(4)

丸善から出版されているG.H.Hardy の
"Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work"
の翻訳を読んでいて、以前とは別の方法で計算したくなったので書いてみた。

n = 50

ary = []
(1..n).each{|j|
  p j
  s = 0
  (1..Math.sqrt(j).to_i).each{|k|
    m = Math.sqrt(j - k * k).to_i
    if m * m == j - k * k
      x = (k + m * 1i) ** 4
      s += x
      p [k, m, x]
    end
  }
  ary << s.real
}
p ary

出力結果
1
[1, 0, (1+0i)]
2
[1, 1, (-4+0i)]
3
4
[2, 0, (16+0i)]
5
[1, 2, (-7-24i)]
[2, 1, (-7+24i)]
6
7
8
[2, 2, (-64+0i)]
9
[3, 0, (81+0i)]
10
[1, 3, (28-96i)]
[3, 1, (28+96i)]
11
12
13
[2, 3, (-119-120i)]
[3, 2, (-119+120i)]
14
15
16
[4, 0, (256+0i)]
17
[1, 4, (161-240i)]
[4, 1, (161+240i)]
18
[3, 3, (-324+0i)]
19
20
[2, 4, (-112-384i)]
[4, 2, (-112+384i)]
21
22
23
24
25
[3, 4, (-527-336i)]
[4, 3, (-527+336i)]
[5, 0, (625+0i)]
26
[1, 5, (476-480i)]
[5, 1, (476+480i)]
27
28
29
[2, 5, (41-840i)]
[5, 2, (41+840i)]
30
31
32
[4, 4, (-1024+0i)]
33
34
[3, 5, (-644-960i)]
[5, 3, (-644+960i)]
35
36
[6, 0, (1296+0i)]
37
[1, 6, (1081-840i)]
[6, 1, (1081+840i)]
38
39
40
[2, 6, (448-1536i)]
[6, 2, (448+1536i)]
41
[4, 5, (-1519-720i)]
[5, 4, (-1519+720i)]
42
43
44
45
[3, 6, (-567-1944i)]
[6, 3, (-567+1944i)]
46
47
48
49
[7, 0, (2401+0i)]
50
[1, 7, (2108-1344i)]
[5, 5, (-2500+0i)]
[7, 1, (2108+1344i)]
[1, -4, 0, 16, -14, 0, 0, -64, 81, 56, 0, 0, -238, 0, 0, 256, 322, -324, 0, -224, 0, 0, 0, 0, -429, 952, 0, 0, 82, 0, 0, -1024, 0, -1288, 0, 1296, 2162, 0, 0, 896, -3038, 0, 0, 0, -1134, 0, 0, 0, 2401, 1716]

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。