2020年4月26日日曜日

200426(2)

Node.js


IPアドレスの変更

最近、Node.js を勉強しています。
手持ちのWi-Fi を使っていたのですが、
途中で切れて予備のWi-Fi に切り替わっていて、
コードをきちんと書いたはずなのに、
エラーが出ました。
以下のコマンドでアドレスを確認してミスに気がつきました。

ipconfig

200426

Ruby


Ramanujan の没後百周年の命日

Ken Ono & Sarah Trebat-Leder の
The 1729 K3 surface
に載っている恒等式に具体的数値を入れてみた。

# n=1のとき(x,y)=(z,w)=(6,-3)
def A(n)
  x, y = 6 * n * n - 4 * n + 4, -3 * n * n - 5 * n + 5
  z, w = 4 * n * n - 4 * n + 6,  5 * n * n - 5 * n - 3
  puts "#{x}^3 + (#{y})^3 = #{x ** 3 + y ** 3}"
  puts "#{z}^3 +   #{w}^3  = #{z ** 3 + w ** 3}"
end

def B(n)
  63 * (3 * n * n - 3 * n + 1) * (n * n + n + 1) * (n * n - 3 * n + 3)
end

n = 100
(2..n).each{|i| A(i)}
p (1..n).map{|i| B(i)}

出力結果
20^3 + (-17)^3 = 3087
14^3 +   7^3  = 3087
46^3 + (-37)^3 = 46683
30^3 +   27^3  = 46683
84^3 + (-63)^3 = 342657
54^3 +   57^3  = 342657
134^3 + (-95)^3 = 1548729
86^3 +   97^3  = 1548729
196^3 + (-133)^3 = 5176899
126^3 +   147^3  = 5176899
270^3 + (-177)^3 = 14137767
174^3 +   207^3  = 14137767
356^3 + (-227)^3 = 33420933
230^3 +   277^3  = 33420933
454^3 + (-283)^3 = 70911477
294^3 +   357^3  = 70911477
564^3 + (-345)^3 = 138342519
366^3 +   447^3  = 138342519
686^3 + (-413)^3 = 252383859
446^3 +   547^3  = 252383859
820^3 + (-487)^3 = 435866697
534^3 +   657^3  = 435866697
966^3 + (-567)^3 = 719144433
630^3 +   777^3  = 719144433
1124^3 + (-653)^3 = 1141589547
734^3 +   907^3  = 1141589547
1294^3 + (-745)^3 = 1753226559
846^3 +   1047^3  = 1753226559
1476^3 + (-843)^3 = 2616501069
966^3 +   1197^3  = 2616501069
1670^3 + (-947)^3 = 3808184877
1094^3 +   1357^3  = 3808184877
1876^3 + (-1057)^3 = 5421417183
1230^3 +   1527^3  = 5421417183
2094^3 + (-1173)^3 = 7567881867
1374^3 +   1707^3  = 7567881867
2324^3 + (-1295)^3 = 10380120849
1526^3 +   1897^3  = 10380120849
2566^3 + (-1423)^3 = 14013983529
1686^3 +   2097^3  = 14013983529
2820^3 + (-1557)^3 = 18651212307
1854^3 +   2307^3  = 18651212307
3086^3 + (-1697)^3 = 24502164183
2030^3 +   2527^3  = 24502164183
3364^3 + (-1843)^3 = 31808668437
2214^3 +   2757^3  = 31808668437
3654^3 + (-1995)^3 = 40847020389
2406^3 +   2997^3  = 40847020389
3956^3 + (-2153)^3 = 51931111239
2606^3 +   3247^3  = 51931111239
4270^3 + (-2317)^3 = 65415693987
2814^3 +   3507^3  = 65415693987
4596^3 + (-2487)^3 = 81699785433
3030^3 +   3777^3  = 81699785433
4934^3 + (-2663)^3 = 101230204257
3254^3 +   4057^3  = 101230204257
5284^3 + (-2845)^3 = 124505245179
3486^3 +   4347^3  = 124505245179
5646^3 + (-3033)^3 = 152078489199
3726^3 +   4647^3  = 152078489199
6020^3 + (-3227)^3 = 184562749917
3974^3 +   4957^3  = 184562749917
6406^3 + (-3427)^3 = 222634155933
4230^3 +   5277^3  = 222634155933
6804^3 + (-3633)^3 = 267036369327
4494^3 +   5607^3  = 267036369327
7214^3 + (-3845)^3 = 318584940219
4766^3 +   5947^3  = 318584940219
7636^3 + (-4063)^3 = 378171797409
5046^3 +   6297^3  = 378171797409
8070^3 + (-4287)^3 = 446769875097
5334^3 +   6657^3  = 446769875097
8516^3 + (-4517)^3 = 525437875683
5630^3 +   7027^3  = 525437875683
8974^3 + (-4753)^3 = 615325168647
5934^3 +   7407^3  = 615325168647
9444^3 + (-4995)^3 = 717676825509
6246^3 +   7797^3  = 717676825509
9926^3 + (-5243)^3 = 833838790869
6566^3 +   8197^3  = 833838790869
10420^3 + (-5497)^3 = 965263189527
6894^3 +   8607^3  = 965263189527
10926^3 + (-5757)^3 = 1113513769683
7230^3 +   9027^3  = 1113513769683
11444^3 + (-6023)^3 = 1280271482217
7574^3 +   9457^3  = 1280271482217
11974^3 + (-6295)^3 = 1467340196049
7926^3 +   9897^3  = 1467340196049
12516^3 + (-6573)^3 = 1676652549579
8286^3 +   10347^3  = 1676652549579
13070^3 + (-6857)^3 = 1910275938207
8654^3 +   10807^3  = 1910275938207
13636^3 + (-7147)^3 = 2170418637933
9030^3 +   11277^3  = 2170418637933
14214^3 + (-7443)^3 = 2459436065037
9414^3 +   11757^3  = 2459436065037
14804^3 + (-7745)^3 = 2779837171839
9806^3 +   12247^3  = 2779837171839
15406^3 + (-8053)^3 = 3134290978539
10206^3 +   12747^3  = 3134290978539
16020^3 + (-8367)^3 = 3525633241137
10614^3 +   13257^3  = 3525633241137
16646^3 + (-8687)^3 = 3956873255433
11030^3 +   13777^3  = 3956873255433
17284^3 + (-9013)^3 = 4431200797107
11454^3 +   14307^3  = 4431200797107
17934^3 + (-9345)^3 = 4951993197879
11886^3 +   14847^3  = 4951993197879
18596^3 + (-9683)^3 = 5522822557749
12326^3 +   15397^3  = 5522822557749
19270^3 + (-10027)^3 = 6147463093317
12774^3 +   15957^3  = 6147463093317
19956^3 + (-10377)^3 = 6829898622183
13230^3 +   16527^3  = 6829898622183
20654^3 + (-10733)^3 = 7574330183427
13694^3 +   17107^3  = 7574330183427
21364^3 + (-11095)^3 = 8385183794169
14166^3 +   17697^3  = 8385183794169
22086^3 + (-11463)^3 = 9267118342209
14646^3 +   18297^3  = 9267118342209
22820^3 + (-11837)^3 = 10225033614747
15134^3 +   18907^3  = 10225033614747
23566^3 + (-12217)^3 = 11264078463183
15630^3 +   19527^3  = 11264078463183
24324^3 + (-12603)^3 = 12389659103997
16134^3 +   20157^3  = 12389659103997
25094^3 + (-12995)^3 = 13607447555709
16646^3 +   20797^3  = 13607447555709
25876^3 + (-13393)^3 = 14923390211919
17166^3 +   21447^3  = 14923390211919
26670^3 + (-13797)^3 = 16343716550427
17694^3 +   22107^3  = 16343716550427
27476^3 + (-14207)^3 = 17874947978433
18230^3 +   22777^3  = 17874947978433
28294^3 + (-14623)^3 = 19523906813817
18774^3 +   23457^3  = 19523906813817
29124^3 + (-15045)^3 = 21297725402499
19326^3 +   24147^3  = 21297725402499
29966^3 + (-15473)^3 = 23203855371879
19886^3 +   24847^3  = 23203855371879
30820^3 + (-15907)^3 = 25250077020357
20454^3 +   25557^3  = 25250077020357
31686^3 + (-16347)^3 = 27444508842933
21030^3 +   26277^3  = 27444508842933
32564^3 + (-16793)^3 = 29795617192887
21614^3 +   27007^3  = 29795617192887
33454^3 + (-17245)^3 = 32312226079539
22206^3 +   27747^3  = 32312226079539
34356^3 + (-17703)^3 = 35003527102089
22806^3 +   28497^3  = 35003527102089
35270^3 + (-18167)^3 = 37879089519537
23414^3 +   29257^3  = 37879089519537
36196^3 + (-18637)^3 = 40948870456683
24030^3 +   30027^3  = 40948870456683
37134^3 + (-19113)^3 = 44223225246207
24654^3 +   30807^3  = 44223225246207
38084^3 + (-19595)^3 = 47712917906829
25286^3 +   31597^3  = 47712917906829
39046^3 + (-20083)^3 = 51429131757549
25926^3 +   32397^3  = 51429131757549
40020^3 + (-20577)^3 = 55383480167967
26574^3 +   33207^3  = 55383480167967
41006^3 + (-21077)^3 = 59588017444683
27230^3 +   34027^3  = 59588017444683
42004^3 + (-21583)^3 = 64055249853777
27894^3 +   34857^3  = 64055249853777
43014^3 + (-22095)^3 = 68798146779369
28566^3 +   35697^3  = 68798146779369
44036^3 + (-22613)^3 = 73830152018259
29246^3 +   36547^3  = 73830152018259
45070^3 + (-23137)^3 = 79165195210647
29934^3 +   37407^3  = 79165195210647
46116^3 + (-23667)^3 = 84817703406933
30630^3 +   38277^3  = 84817703406933
47174^3 + (-24203)^3 = 90802612770597
31334^3 +   39157^3  = 90802612770597
48244^3 + (-24745)^3 = 97135380417159
32046^3 +   40047^3  = 97135380417159
49326^3 + (-25293)^3 = 103831996389219
32766^3 +   40947^3  = 103831996389219
50420^3 + (-25847)^3 = 110908995767577
33494^3 +   41857^3  = 110908995767577
51526^3 + (-26407)^3 = 118383470918433
34230^3 +   42777^3  = 118383470918433
52644^3 + (-26973)^3 = 126273083876667
34974^3 +   43707^3  = 126273083876667
53774^3 + (-27545)^3 = 134596078865199
35726^3 +   44647^3  = 134596078865199
54916^3 + (-28123)^3 = 143371294950429
36486^3 +   45597^3  = 143371294950429
56070^3 + (-28707)^3 = 152618178833757
37254^3 +   46557^3  = 152618178833757
57236^3 + (-29297)^3 = 162356797779183
38030^3 +   47527^3  = 162356797779183
58414^3 + (-29893)^3 = 172607852676987
38814^3 +   48507^3  = 172607852676987
59604^3 + (-30495)^3 = 183392691243489
39606^3 +   49497^3  = 183392691243489
[189, 3087, 46683, 342657, 1548729, 5176899, 14137767, 33420933, 70911477, 138342519, 252383859, 435866697, 719144433, 1141589547, 1753226559, 2616501069, 3808184877, 5421417183, 7567881867, 10380120849, 14013983529, 18651212307, 24502164183, 31808668437, 40847020389, 51931111239, 65415693987, 81699785433, 101230204257, 124505245179, 152078489199, 184562749917, 222634155933, 267036369327, 318584940219, 378171797409, 446769875097, 525437875683, 615325168647, 717676825509, 833838790869, 965263189527, 1113513769683, 1280271482217, 1467340196049, 1676652549579, 1910275938207, 2170418637933, 2459436065037, 2779837171839, 3134290978539, 3525633241137, 3956873255433, 4431200797107, 4951993197879, 5522822557749, 6147463093317, 6829898622183, 7574330183427, 8385183794169, 9267118342209, 10225033614747, 11264078463183, 12389659103997, 13607447555709, 14923390211919, 16343716550427, 17874947978433, 19523906813817, 21297725402499, 23203855371879, 25250077020357, 27444508842933, 29795617192887, 32312226079539, 35003527102089, 37879089519537, 40948870456683, 44223225246207, 47712917906829, 51429131757549, 55383480167967, 59588017444683, 64055249853777, 68798146779369, 73830152018259, 79165195210647, 84817703406933, 90802612770597, 97135380417159, 103831996389219, 110908995767577, 118383470918433, 126273083876667, 134596078865199, 143371294950429, 152618178833757, 162356797779183, 172607852676987, 183392691243489]

2020年4月14日火曜日

200414

PARI


Number of domino tilings of the n X k grid

n X k の長方形をk*n/2 個のドミノで埋め尽くす方法が何通りあるかという問題に対し、
Temperley & Fisher とKasteleyn によってそれぞれ独立に得られた公式がよく知られている。
この公式を言い換えて、より簡単に計算する方法に気がついた。
求めるものをT(n,k) とすると、
T(n,k)^2 = |Res(U_n(x/2), U_k(i*x/2))|
(ただし、U_n(x) は第二種チェビシェフ多項式)
と表される。
これを用いて、T(n,k) を計算してみた。

(11:13) gp > T(n, k) = sqrtint(abs(polresultant(polchebyshev(n, 2, x/2), polchebyshev(k, 2, I*x/2))));
(11:14) gp > for(n=0, 15, for(k=0, 10, print1(T(n, k), ", ")); print)
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,
1, 0, 3, 0, 11, 0, 41, 0, 153, 0, 571,
1, 1, 5, 11, 36, 95, 281, 781, 2245, 6336, 18061,
1, 0, 8, 0, 95, 0, 1183, 0, 14824, 0, 185921,
1, 1, 13, 41, 281, 1183, 6728, 31529, 167089, 817991, 4213133,
1, 0, 21, 0, 781, 0, 31529, 0, 1292697, 0, 53175517,
1, 1, 34, 153, 2245, 14824, 167089, 1292697, 12988816, 108435745, 1031151241,
1, 0, 55, 0, 6336, 0, 817991, 0, 108435745, 0, 14479521761,
1, 1, 89, 571, 18061, 185921, 4213133, 53175517, 1031151241, 14479521761, 258584046368,
1, 0, 144, 0, 51205, 0, 21001799, 0, 8940739824, 0, 3852472573499,
1, 1, 233, 2131, 145601, 2332097, 106912793, 2188978117, 82741005829, 1937528668711, 65743732590821,
1, 0, 377, 0, 413351, 0, 536948224, 0, 731164253833, 0, 1012747193318519,
1, 1, 610, 7953, 1174500, 29253160, 2720246633, 90124167441, 6675498237130, 259423766712000, 16848161392724969,
1, 0, 987, 0, 3335651, 0, 13704300553, 0, 59554200469113, 0, 264499788583572499,
(11:14) gp >

2020年4月6日月曜日

200406

Python


A333466等

Graphillion を使って計算してみた。

from graphillion import GraphSet
import graphillion.tutorial as tl

def four_corners(n):
    return [1, n, n * (n - 1) + 1, n * n]

def points_on_diagonal_1(n):
    return [i + 1 for i in range(n * n) if i % n - i // n == 0]

def points_on_diagonal_2(n):
    return [i + 1 for i in range(n * n) if i % n + i // n == n - 1]

def points_on_two_diagonals(n):
    return [i + 1 for i in range(n * n) if i % n - i // n == 0 or i % n + i // n == n - 1]

def A(points, n):
    print(points)
    universe = tl.grid(n - 1, n - 1)
    GraphSet.set_universe(universe)
    cycles = GraphSet.cycles()
    for i in points:
        cycles = cycles.including(i)
    return cycles.len()

print([A(four_corners(n),            n) for n in range(2, 10)])
print([A(points_on_diagonal_1(n),    n) for n in range(2, 10)])
print([A(points_on_diagonal_2(n),    n) for n in range(2, 10)])
print([A(points_on_two_diagonals(n), n) for n in range(2, 10)])

出力結果
[1, 2, 3, 4]
[1, 3, 7, 9]
[1, 4, 13, 16]
[1, 5, 21, 25]
[1, 6, 31, 36]
[1, 7, 43, 49]
[1, 8, 57, 64]
[1, 9, 73, 81]
[1, 1, 11, 373, 44930, 17720400, 22013629316, 84579095455492]
[1, 4]
[1, 5, 9]
[1, 6, 11, 16]
[1, 7, 13, 19, 25]
[1, 8, 15, 22, 29, 36]
[1, 9, 17, 25, 33, 41, 49]
[1, 10, 19, 28, 37, 46, 55, 64]
[1, 11, 21, 31, 41, 51, 61, 71, 81]
[1, 2, 22, 716, 73346, 23374544, 23037365786, 69630317879888]
[2, 3]
[3, 5, 7]
[4, 7, 10, 13]
[5, 9, 13, 17, 21]
[6, 11, 16, 21, 26, 31]
[7, 13, 19, 25, 31, 37, 43]
[8, 15, 22, 29, 36, 43, 50, 57]
[9, 17, 25, 33, 41, 49, 57, 65, 73]
[1, 2, 22, 716, 73346, 23374544, 23037365786, 69630317879888]
[1, 2, 3, 4]
[1, 3, 5, 7, 9]
[1, 4, 6, 7, 10, 11, 13, 16]
[1, 5, 7, 9, 13, 17, 19, 21, 25]
[1, 6, 8, 11, 15, 16, 21, 22, 26, 29, 31, 36]
[1, 7, 9, 13, 17, 19, 25, 31, 33, 37, 41, 43, 49]
[1, 8, 10, 15, 19, 22, 28, 29, 36, 37, 43, 46, 50, 55, 57, 64]
[1, 9, 11, 17, 21, 25, 31, 33, 41, 49, 51, 57, 61, 65, 71, 73, 81]
[1, 0, 6, 68, 6102, 1404416, 1094802826, 2524252113468]

2020年4月5日日曜日

200405

PARI


Ubuntu で使用する方法

①Ubuntu にinstall

$ sudo apt install pari-gp

②起動し、計算してみる。

$ gp
Reading GPRC: /etc/gprc ...Done.

                  GP/PARI CALCULATOR Version 2.9.4 (released)
          amd64 running linux (x86-64/GMP-6.1.2 kernel) 64-bit version
        compiled: Dec 19 2017, gcc version 7.3.0 (Ubuntu 7.3.0-1ubuntu1)
                           threading engine: pthread
                 (readline v7.0 enabled, extended help enabled)

                     Copyright (C) 2000-2017 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes 
WITHOUT ANY WARRANTY WHATSOEVER.

Type ? for help, \q to quit.
Type ?15 for how to get moral (and possibly technical) support.

parisize = 8000000, primelimit = 500000, nbthreads = 12
? N=40; x='x+O('x^N); Vec(x^2/(1-3*x-2*x^2+3*x^3-x^4))
%1 = [1, 3, 11, 36, 122, 408, 1371, 4599, 15437, 51804, 173860, 583476, 1958173, 6571695, 22054863, 74016936, 248403622, 833651844, 2797766831, 9389410251, 31511212505, 105752809368, 354910389192, 1191092559048, 3997351239929, 13415260479675, 45022116630931, 151095909691404, 507083532136978, 1701791326380624, 5711275430972547, 19167254258959359, 64326023191818277, 215880543126836532, 724503188418240620, 2431459836191899452, 8160070279223488277, 27385501487926378407, 91906768702068654039]
? 

2020年4月1日水曜日

200401

Python


A007764 とA271507 の内訳

Graphillion を使って計算してみた。

from graphillion import GraphSet
import graphillion.tutorial as tl

def A333520(n):
    if n == 1: return [1]
    universe = tl.grid(n - 1, n - 1)
    GraphSet.set_universe(universe)
    start, goal = 1, n * n
    paths = GraphSet.paths(start, goal)
    return [paths.len(2 * (n - 1 + k)).len() for k in range((n - 1) ** 2 // 2 + 1)]

def A329633(n):
    if n == 1: return [1]
    universe = tl.grid(n - 1, n - 1)
    GraphSet.set_universe(universe)
    start, goal = 1, n
    paths = GraphSet.paths(start, goal)
    return [paths.len(n - 1 + 2 * k).len() for k in range(n * (n - 1) // 2 + 1)]

a_list = []
for n in range(1, 10):
    a = A333520(n)
    a_list.append(sum(a))
    print([n, a])
print(a_list)

a_list = []
for n in range(1, 10):
    a = A329633(n)
    a_list.append(sum(a))
    print([n, a])
print(a_list)

出力結果
[1, [1]]
[2, [2]]
[3, [6, 4, 2]]
[4, [20, 36, 48, 48, 32]]
[5, [70, 224, 510, 956, 1586, 2224, 2106, 732, 104]]
[6, [252, 1200, 3904, 10560, 25828, 58712, 121868, 217436, 300380, 280776, 170384, 61336, 10180]]
[7, [924, 5940, 25186, 88084, 277706, 821480, 2309402, 6140040, 15130410, 33339900, 62692432, 96096244, 116826664, 110195700, 78154858, 39287872, 12396758, 1879252, 111712]]
[8, [3432, 28028, 146584, 624340, 2377272, 8462820, 28776128, 94238536, 297191100, 896047312, 2546144660, 6680419996, 15815316056, 33077697996, 60178275856, 94178946072, 125506736172, 140596369668, 129855611460, 95988303604, 54346307964, 22183235872, 6043428540, 967772896, 67590888]]
[9, [12870, 128128, 797052, 3983816, 17629208, 72458528, 283712460, 1072443924, 3937918900, 14066778160, 48770325700, 163139663720, 521548222412, 1574551014304, 4432290159968, 11499012639224, 27239037773318, 58501384426476, 113288208212484, 196789936838036, 304802809328332, 417652572628088, 500928869596082, 518566360053936, 455147191259656, 331385170320868, 194939663325166, 89645976737872, 30824065740276, 7417611707528, 1120646287168, 87526550468, 2688307514]]
[1, 2, 12, 184, 8512, 1262816, 575780564, 789360053252, 3266598486981642]
[1, [1]]
[2, [1, 1]]
[3, [1, 3, 5, 2]]
[4, [1, 6, 16, 39, 61, 47, 8]]
[5, [1, 10, 40, 125, 400, 1048, 1905, 2372, 1839, 764, 86]]
[6, [1, 15, 85, 335, 1237, 4638, 15860, 44365, 99815, 181995, 262414, 285086, 218011, 104879, 26344, 1770]]
[7, [1, 21, 161, 791, 3361, 13952, 58070, 232243, 832142, 2593461, 7050363, 16792687, 34757775, 61408506, 90658299, 109096566, 103422092, 73555738, 36524442, 11331348, 1833648, 88418]]
[8, [1, 28, 280, 1694, 8289, 37953, 170838, 767788, 3393035, 14146880, 53986313, 187172584, 591447455, 1707679296, 4493518214, 10698808881, 22837317345, 43276246162, 72005361759, 103756776232, 127221992958, 129859297139, 107392360699, 69520076355, 33639644113, 11377703747, 2418924278, 267844566, 8934966]]
[9, [1, 36, 456, 3354, 18901, 95511, 463500, 2216686, 10567808, 50018095, 229837003, 1000613739, 4075412853, 15496037329, 55118028311, 183704714639, 573394187702, 1671186818906, 4528288476197, 11351266746427, 26189578078433, 55304540386554, 106197268433138, 183996474717841, 285023298502055, 390621776748810, 467942847317180, 483141430614882, 422762865315696, 307119589396008, 180479878973823, 82945534742174, 28476975005088, 6835995356060, 1034770138602, 82247277872, 2087813834]]
[1, 2, 11, 178, 8590, 1246850, 550254085, 741333619848, 3046540983075504]