Ramanujan's tau function(3)
# -*- coding: cp932 -*-
import numpy
# m次以下のみにする
def mth_degree_poly(p, m):
return numpy.poly1d(list(p)[- m - 1:])
def power(f, n, m):
p = numpy.poly1d([1])
for i in format (n, 'b'):
p *= p
p = mth_degree_poly(p, m)
if i == '1':
# fがリストでも答えが出る
p *= f
p = mth_degree_poly(p, m)
return p
def A000594(n):
ary = [0] * (n + 1)
i = 0
j, k = 2 * i + 1, i * (i + 1) / 2
while k <= n:
ary[k] = -j if i % 2 == 1 else j
i += 1
j, k = 2 * i + 1, i * (i + 1) / 2
return list(reversed((power(list(reversed(ary)), 8, n - 1)).c))
ary = A000594(28)
# OEIS A000594のデータ
ary0 = [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]
# 一致の確認
print ary == ary0
import numpy
# m次以下のみにする
def mth_degree_poly(p, m):
return numpy.poly1d(list(p)[- m - 1:])
def power(f, n, m):
p = numpy.poly1d([1])
for i in format (n, 'b'):
p *= p
p = mth_degree_poly(p, m)
if i == '1':
# fがリストでも答えが出る
p *= f
p = mth_degree_poly(p, m)
return p
def A000594(n):
ary = [0] * (n + 1)
i = 0
j, k = 2 * i + 1, i * (i + 1) / 2
while k <= n:
ary[k] = -j if i % 2 == 1 else j
i += 1
j, k = 2 * i + 1, i * (i + 1) / 2
return list(reversed((power(list(reversed(ary)), 8, n - 1)).c))
ary = A000594(28)
# OEIS A000594のデータ
ary0 = [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]
# 一致の確認
print ary == ary0
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。