2017年11月18日土曜日

171118

Ruby


Expansion of Product_{k>=1} (1 ± k*x^k))^(±k)

それぞれ計算してみた。

def s(f_ary, g_ary, n)
  s = 0
  (1..n).each{|i| s += i * f_ary[i] * g_ary[i] ** (n / i) if n % i == 0}
  s
end

def A(f_ary, g_ary, n)
  ary = [1]
  a = [0] + (1..n).map{|i| s(f_ary, g_ary, i)}
  (1..n).each{|i| ary << (1..i).inject(0){|s, j| s + a[j] * ary[-j]} / i}
  ary
end

n = 50
ary1 = (0..n).map{|i| -i}
ary2 = (0..n).to_a
p A(ary1, ary1, n)
p A(ary1, ary2, n)
p A(ary2, ary1, n)
p A(ary2, ary2, n)

出力結果
[1, 1, 4, 13, 29, 81, 188, 456, 1030, 2405, 5295, 11611, 25246, 53552, 113332, 235685, 486011, 990840, 2006567, 4018010, 7992003, 15768511, 30875424, 60060509, 116042548, 222817961, 425200270, 806991037, 1522748592, 2858792520, 5339457208, 9924370365, 18359901997, 33812646935, 61999124321, 113204234852, 205862337221, 372878429033, 672835402816, 1209588044793, 2166753852049, 3867809679344, 6881037028716, 12201406676888, 21566414247820, 38000774004995, 66755792351581, 116923614457354, 204203782318876, 355635202391775, 617666801739931]
[1, -1, -4, -5, -3, 23, 44, 104, 70, -93, -465, -1155, -1882, -1904, 804, 6195, 18755, 33296, 47327, 35198, -28493, -176199, -453792, -805453, -1126396, -1028297, -18994, 2946491, 8248080, 16444480, 25436984, 30736635, 22263981, -16098311, -102681575, -256880020, -472968099, -714186361, -843996976, -644815585, 298761545, 2421641832, 6222259508, 11789810688, 18381745764, 23559771093, 22274637285, 6320449894, -36301921428, -117867266775, -248604757661]
[1, -1, -3, -6, 2, 9, 41, 46, 91, -110, -210, -713, -574, -1152, 792, 1066, 9317, 8553, 21302, 745, 8051, -82940, -76750, -276022, -82369, -404100, 381095, -38110, 2427272, 1126260, 6527840, 198507, 9754305, -14320206, 2879362, -60271740, -5154261, -143468194, 45076661, -234052476, 368886604, -247381667, 1282501567, -391275933, 3098609545, -1922335739, 5751247293, -8041862590, 10176770846, -25557378946, 18952181107]
[1, 1, 5, 14, 42, 103, 289, 690, 1771, 4206, 10142, 23449, 54786, 123528, 279480, 619206, 1366405, 2969071, 6425534, 13727775, 29187555, 61439660, 128620370, 267044222, 551527679, 1130806020, 2306746335, 4676096006, 9432394144, 18920266428, 37776372312, 75041364413, 148416537369, 292180587654, 572826984930, 1118261849716, 2174572373811, 4211951389306, 8128298517165, 15628368778820, 29944800382236, 57177924889211, 108820805664983, 206435020380189, 390397024961585, 736033705364187, 1383595389367133, 2593344028747990, 4847245569040526, 9035118348679538, 16796348691066595]

0 件のコメント:

コメントを投稿

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