-
Notifications
You must be signed in to change notification settings - Fork 0
/
A350939+40.sage
50 lines (43 loc) · 1.91 KB
/
A350939+40.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#! /usr/bin/env sage
from itertools import count, permutations
from time import time
from datetime import datetime, timedelta
print("n: A350939(n) and A350940(n)")
print("0: 1 and 1")
print("1: 2 and 2")
def toeplitz(entries): # Toeplitz matrix using the provided numbers. First goes on the bottom left, last on the top right.
N = len(entries)
assert N % 2 == 1
d = (N + 1) // 2 # We are constructing a d-by-d matrix.
return [entries[i:i+d] for i in range(d-1, d-1-d, -1)]
inf = float('inf')
P = sage.sets.primes.Primes()
terms = [P.first()]
for n in count(2):
terms.append(P.next(terms[-1]))
terms.append(P.next(terms[-1]))
minperm, maxperm, minmat, maxmat = +inf, -inf, 0, 0
fac = sage.all.factorial(2*n-1)
starttime = time()
k = 0
for (k,row) in enumerate(permutations(terms)):
if k % 1000 == 0 and k > 0:
ettc = float((time() - starttime) * (fac/k - 1.0)) # estimated time to completion
eta = datetime.isoformat(datetime.now() + timedelta(seconds=ettc), sep=' ', timespec='seconds')
print('\b'*160, "%d/%d = %0.5f%%; ETA %0.0f s / %s" % (k, fac, 100*k/fac, ettc, eta), end=' ', flush=True)
M = sage.matrix.constructor.Matrix(toeplitz(row))
perm = M.permanent()
if perm > maxperm: maxperm, maxmat = perm, M
if perm < minperm: minperm, minmat = perm, M
outstr = "%d: %d and %d" % (n, minperm, maxperm)
print(('\b'*160) + outstr + (" " * (79-len(outstr))))
"""
n: A350939(n) and A350940(n)
0: 1 and 1
1: 2 and 2
2: 19 and 31
3: 496 and 2364
4: 29609 and 346018
5: 3009106 and 82285908
6: 498206489 and 39135296624
"""