A determinant optimization challenge

13

2

Consider 30 by 30 Toeplitz matrices all of whose entries are 0 or 1. This challenge is a simple optimization challenge to find the matrix with the largest determinant possible.

Input None

Output A 30 by 30 Toeplitz matrix all of whose entries are 0 or 1 along with its determinant.

Score The determinant of the matrix you output. If two people get the same score, the first answer wins.

Leading entries so far

  • 65,455,857,159,975 in Matlab by Nick Alger (roughly (10^13.8)
  • 65,455,857,159,975 in Python by isaacg (roughly 10^13.8)
  • 39,994,961,721,988 in Mathematica by 2012rcampion ( roughly 10^13.6)
  • 39,788,537,400,052 in R by Flounderer (roughly 10^13.6)
  • 8,363,855,075,832 in Python by Vioz- (roughly 10^12.9)
  • 6,984,314,690,903 in Julia by Alex A. (roughly 10^12.8)

Annoying additional constraints July 16 2015

If it is at all possible, please use arbitrary or high precision arithmetic to compute the final output determinant so that we can be sure what it really is (it should always be an integer). In python this should be helpful.

user9206

Posted 2015-07-15T20:17:51.337

Reputation:

I'm surprised that this problem is not already solved. Is the answer known for circulant matrices? – xnor – 2015-07-15T20:19:56.243

@xnor http://oeis.org/A086432 exists and maybe others for circulant matrices as does http://oeis.org/A215724 .

– None – 2015-07-15T20:21:38.773

The Mathematica code though for A086432 and related sequences just seems to be trying every legal matrix. I take it then no efficient algorithm is known? – xnor – 2015-07-15T20:23:47.150

@xnor Not that I know of. See http://codegolf.stackexchange.com/questions/52851/find-the-maximum-determinant-for-each-size-toeplitz-matrix for example :)

– None – 2015-07-15T20:24:34.177

Couldn't people just use the same solutions from your last Toeplitz determinant challenge and let them run to n=30? – Alex A. – 2015-07-15T20:38:02.243

@AlexA. Well, possibly. However, based on my numbers, to get to n=21, we may experience heat death before a maximum is found out. Currently, all of those programs are brute-force. We don't have a good formula for this (yet). – Kade – 2015-07-15T20:53:18.640

Is there a time limit or computational power limit? (i.e., is it time for me to get into CUDA programming =P) – 2012rcampion – 2015-07-16T04:15:23.087

Is it allowed to call (high powered) optimization libraries? There are very advanced methods that could probably solve this problem completely (eg., branch and cut with a trust region interior point method for the subproblem relaxations). – Nick Alger – 2015-07-16T05:15:21.110

1@NickAlger If the library is publicly available for everyone, you can use it. – orlp – 2015-07-16T06:01:04.763

@2012rcampion No limits. Please feel free to CUDA away :) – None – 2015-07-16T07:10:19.060

I let my code run longer and it seems to have achieved the maximum value listed in OEIS A086432 – Nick Alger – 2015-07-16T09:02:22.050

@NickAlger That's great! But note that this is not necessarily the max for Toeplitz matrices. In fact I am 100% sure it is isn't as you can compare the max for smaller n where we can compute it exhaustively. – None – 2015-07-16T09:07:32.780

@Lembik Oh you're right, good call. Well I'm done for now anyways. – Nick Alger – 2015-07-16T09:08:39.597

There are only 2^30 such matrices (roughly one billion), right? Sounds like it should be doable by brute force in under a day... – user253751 – 2015-07-16T12:01:22.277

2@immibis Sadly there are 2^59 of them. – None – 2015-07-16T12:02:14.250

@Lembik I missed that the diagonals don't wrap around. – user253751 – 2015-07-16T12:03:16.667

1It's interesting that two independent methods have achieved a Toeplitz matrix with exactly the maximum circulant matrix determinant. I don't have any mathematical intuition as to why—is that determinant just common for binary Toeplitz matrices? – lirtosiast – 2015-07-17T04:16:46.243

@ThomasKwa Yes. It would be interesting to test smaller cases where we know the max to see what is going on. – None – 2015-07-17T08:27:59.600

I'm interested in the maximum (maximal ?) determinants for other than n=30. Do the two top solutions still output same values for n >= 31 ? – Min_25 – 2015-07-20T13:25:53.437

@Min_25 n=8 is interesting in relation to the determinant max problem.. for circulant matrices 275 is optimal, for toeplitz matrices 315 is optimal and for general 0,1 matrices 320 is optimal. It seems that the optimal values do however coincide sometimes for other values of n. – None – 2015-07-20T16:56:38.987

1@Min_25 I should have the maximum up to 19 by tomorrow. Will get the code/values to you in the related question, Lembik. With heuristic algorithms, I have maxed out at exactly the same values for n=30 as the other two posters so far. Multiple times, with randomization involved. Also with circulant matrices as the result every time I reach that maximum, even though my search is not restricted to circulant matrices. BTW, another baffling (to me) fact: The maximum for n=15 is exactly 2^17. – Reto Koradi – 2015-07-21T06:07:56.763

Answers

11

Matlab, 65,455,857,159,975 (10^13.8159)

The method is gradient ascent in the interior of the cube [0,1]^59, with many random initial guesses, and rounding at the end to make everything zeros and ones.

Matrix:

0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0
0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1
1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1
1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1
1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0
0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1
1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1
1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1
1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0
0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1
1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0
0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0
0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0
0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1
1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0   0
0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1   0
0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0   1
1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1   0
0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1   1
1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0   1
1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1   0
0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0   1
1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0   0
0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0   0
0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0   0
0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1   0
0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1   1
1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1   1
1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0   1
1   1   1   0   0   0   0   1   0   1   1   0   1   0   0   1   0   0   0   1   0   1   1   1   0   1   1   1   0   0

Code:

% Toeplitz 0-1 determinant optimization

n = 30;
m = n + n-1;

toeplitz_map = @(w) toeplitz(w(n:-1:1), w(n:end));

objective = @(w) det(toeplitz_map(w));

detgrad = @(A) det(A)*inv(A)';

toeplitz_map_matrix = zeros(n^2,m);
for k=1:m
    ek = zeros(m,1);
    ek(k) = 1;
    M = toeplitz_map(ek);
    toeplitz_map_matrix(:,k) = M(:);
end

gradient = @(w) (reshape(detgrad(toeplitz_map(w)),1,n^2)*...
                 toeplitz_map_matrix)';

%check gradient with finite differences
w = randn(m,1);
dw = randn(m,1);
s = 1e-6;
g_diff = (objective(w+s*dw) - objective(w))/s;
g = gradient(w)'*dw;
grad_err = (g - g_diff)/g_diff

warning('off')
disp('multiple gradient ascent:')
w_best = zeros(m,1);
f_best = 0;
for trial=1:100000
    w0 = rand(m,1);
    w = w0;
    alpha0 = 1e-5; %step size
    for k=1:20
        f = objective(w);
        g = gradient(w);
        alpha = alpha0;
        for hh=1:100
            w2 = w + alpha*g;
            f2 = objective(w2);
            if f2 > f
                w = w2;
                break;
            else
                alpha = alpha/2;
            end
        end

        buffer = 1e-4;
        for jj=1:m
            if (w(jj) > 1)
                w(jj) = 1 - buffer;
            elseif (w(jj) < 0)
                w(jj) = 0 + buffer;
            end
        end
    end

    w = round(w);
    f = objective(w);
    if f > f_best
        w_best = w;
        f_best = f;
    end
    disp(trial)
    disp(f_best)
    disp(f)
end

M = toeplitz_map(w_best);

The math behind computing the gradient:

In the elementwise inner product (Ie., Hilbert-Schmidt inner product), the gradient of the determinant has Riesz representative G given by

G = det(A)A^(-*).

The map, J, from optimization variables (diagonal values) to toeplitz matrices is linear, so the overall gradient g is the composition of these two linear maps,

g = (vec(G)*J)',

where vec() is the vectorization operator that takes a matrix and unfolds it into a vector.

Interior gradient ascent:

After this all you have to do is pick an initial vector of diagonal values w_0, and for some small step sizes alpha iterate:

  1. w_proposed = w_k + alpha*g_k

  2. to get w_(k+1), take w_proposed and truncate values outside of [0,1] to 0 or 1

  3. repeat until satisfied, then round everything to 0 or 1.

My result achieved this determinant after doing roughly 80,000 trials with uniform random initial guesses.

Nick Alger

Posted 2015-07-15T20:17:51.337

Reputation: 376

The OEIS link you gave was for circulant matrices, which are a special case of Topelitz matrices. So better is still possible. – isaacg – 2015-07-16T09:09:17.740

@isaacg And also extremely likely! – None – 2015-07-16T09:14:00.210

Yes of course, I was incorrect about that. I have edited my post to fix it. – Nick Alger – 2015-07-16T09:14:49.313

I don't fully understand your answer yet. Are you treating the elements of the matrix as continuous in the range [0,1], optimizing over those and then rounding them to the nearest integer and rescoring? – None – 2015-07-17T08:24:43.030

@Lembik Yes exactly that. The continuous optimization always seems to converge towards 0 or 1 entries anyways, so it ends out being rounding things like (0.999, 0.001, 0.998, ...) to (1, 0, 1, ...). The final score is always calculated on the rounded version. – Nick Alger – 2015-07-17T09:20:23.273

Do you get 2994003 for 18 by 18 out of interest? – None – 2015-07-18T12:23:55.913

1Yes, it got to that value at iteration 250 and stayed there for 100000 iterations. The vector defining the 18x18 toeplitz matrix with determinant 2994003 was [0,0,0,1,0,1,1,1,1,0,1,1,0,0,0,1,0,1,0,0,0,1,0,1,1,1,1,0,1,1,0,0,0,1,0], where the order goes from the bottom left to top right. – Nick Alger – 2015-07-18T19:13:40.193

If you want to try things but don't have Matlab, the code should also work in Octave – Nick Alger – 2015-07-19T03:01:01.707

2

I awarded the win to you as you came up with a new idea and came up with the highest number first IIRC. Oh and this shows why your answer works http://math.stackexchange.com/questions/1364471/do-the-matrices-with-maximum-determinant-always-have-integral-values .

– None – 2015-07-21T07:38:22.287

11

Python 2 with Numpy, 65,455,857,159,975 ~= 10^13.8

This is hill climbing, as straightforward as can be. Final determinant calculation performed using SymPy to enusure an exact result. All matrices found with this determinant are circulant.

Matrices found with this determinant, given as value of diagonal from bottom left to upper right:

01000100101101000011100111011101000100101101000011100111011
01011101110011100001011010010001011101110011100001011010010
01100001000111011101001110100101100001000111011101001110100
01110100111010010110000100011101110100111010010110000100011
01011101110001000011010010111001011101110001000011010010111
01000101100010110100111101110001000101100010110100111101110
01000100101101000011100111011101000100101101000011100111011

The first one, as a matrix:

[[1 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1]
 [1 1 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 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 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 1]
 [1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0]
 [0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 0 0 1]
 [1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 0 0]
 [0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1 0]
 [0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0 1]
 [1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0 0]
 [0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0 0]
 [0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1 0]
 [0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0 1]
 [1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1 0]
 [0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1 1 0 0 1 1 1 0 1 1 1]]

Code:

import numpy as np
import sympy as sp
import random
import time
SIZE = 30

random.seed(0)

def gen_diag():
    return [random.randint(0, 1) for i in range(SIZE*2 - 1)]

def diag_to_mat(diag):
    return [diag[a:a+SIZE] for a in range(SIZE-1, -1, -1)]

def diag_to_det(diag):
    matrix = diag_to_mat(diag)
    return np.linalg.det(matrix)

def improve(diag):
    old_diag = diag
    really_old_diag = []
    while really_old_diag != old_diag:
        really_old_diag = old_diag
        for flip_at in range(SIZE * 2 - 1):
            new_diag = old_diag[:]
            new_diag[flip_at] ^= 1
            old_diag = max(old_diag, new_diag, key=diag_to_det)
    return old_diag

overall_best_score = 0
time.clock()
while time.clock() < 500:
    best = improve(gen_diag())
    best_score = diag_to_det(best)
    if best_score > overall_best_score:
        overall_best_score = best_score
        overall_best = best
        print(time.clock(), sp.Matrix(diag_to_mat(overall_best)).det(), ''.join(map(str,overall_best)))


mat = diag_to_mat(overall_best)

sym_mat = sp.Matrix(mat)

print(overall_best)
print(sym_mat.det())

isaacg

Posted 2015-07-15T20:17:51.337

Reputation: 39 268

1This is nuts. Nice work. – Alex A. – 2015-07-16T04:37:06.810

The .227 is a little worrying. Do you think there is a way to be confident what the determinant really is? – None – 2015-07-16T07:09:43.313

It seems that http://stackoverflow.com/questions/6876377/numpy-arbitrary-precision-linear-algebra might help to evaluate the final determinant?

– None – 2015-07-16T08:08:43.887

@Lembik Thanks - SymPy did the trick. – isaacg – 2015-07-16T08:47:15.113

That's really great! – None – 2015-07-16T08:49:25.457

Does the new discrete hill climbing version always converge to the same maximum (6.5e13), or does it sometimes converge to something smaller? – Nick Alger – 2015-07-16T19:01:17.460

@NickAlger Ths is only when it gets lucky. – isaacg – 2015-07-16T21:04:36.677

I just realised this code doesn't have to ever terminate. I think while really_old_diag != old_diag: can fail ever to be satisfied if the changes go in a cycle. – None – 2015-07-18T07:44:54.527

@Lembik It can't go in a cycle, because of the max in the for loop, and the fact that Python's max is stable. It will always return the first result if the keys are equal, so either old_diag's key will increase, or the diag will stay the same. – isaacg – 2015-07-18T09:51:56.703

There seems to be something special about this value. I already got it a few times, with fairly little computation time. And never anything higher yet. The matrices do not appear to be in your list, but they are also circulant. Even though I'm not specifically looking for circulant matrices. – Reto Koradi – 2015-07-21T05:23:52.207

10

R, 39 788 537 400 052

Here is my attempt to do a genetic algorithm but only with asexual reproduction. I hope I understood the challenge correctly. Edit: sped it up a bit, tried a different random seed, and restricted to 100 generations.

    options(scipen=999)

toeplitz <- function(x){
# make toeplitz matrix with first row
# x[1:a] and first col x[(a+1):n]
# where n is the length of x and a= n/2
# Requires x to have even length
#
# [1,1] entry is x[a+1]

N <- length(x)/2
out <- matrix(0, N, N)
out[1,] <- x[1:N]
out[,1] <- x[(N+1):length(x)]
for (i in 2:N){
  for (j in 2:N){
    out[i,j] <- out[i-1, j-1]
  }
} 

out
}

set.seed(1002)

generations <- 100
popsize <- 25
cols <- 60
population <- matrix(sample(0:1, cols*popsize, replace=T), nc=cols)
numfresh <- 5 # number of totally random choices added to population

for (i in 1:generations){

fitness <- apply(population, 1, function(x) det(toeplitz(x)) )
mother <- which(fitness==max(fitness))[1]

population <- matrix(rep(population[mother,], popsize), nc=cols, byrow=T)
for (i in 2:(popsize-numfresh)){
  x <- sample(cols, 1)
  population[i,x] <- 1-population[i,x]
}
for (i in (popsize-numfresh +1):popsize){
  population[i,] <- sample(0:1, cols, replace=T)
}


print(population[1,])
print(fitness[mother])
print(det(toeplitz(population[1,]))) # to check correct

}

Output:

print(population[1, 1:(cols/2)]) # first row
print(population[1, (cols/2+1):(cols)]) # first column (overwrites 1st row)

to <- toeplitz(population[1,])

for (i in 1:(cols/2)) cat(to[i,], "\n")

1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 
0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 
1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 
0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 
0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 
0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 
1 0 0 0 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 
1 1 0 0 0 1 0 1 1 1 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 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 0 
0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 0 1 
1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 0 
0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 1 
1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 1 
1 1 0 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 1 0 1 

Flounderer

Posted 2015-07-15T20:17:51.337

Reputation: 596

This is very nice. You are winning by a long way currently. – None – 2015-07-16T00:35:08.173

Not any more :) – None – 2015-07-16T08:51:33.760

3

Julia, 6,984,314,690,902.998

This just constructs 1,000,000 random Toeplitz matrices and checks their determinants, recording the maximum encountered. Hopefully someone will come up with an elegant analytical solution, but in the meantime...

function toeplitz(a, b)
    n = length(a)
    T = Array(Int, n, n)
    T[1,:] = b
    T[:,1] = a
    for i = 2:n
        T[i,2:n] = T[i-1,1:n-1]
    end
    T
end

d = 0
A = Any[]

for i = 1:1000000
    # Construct two random 0,1 arrays
    r1 = rand(0:1, 30)
    r2 = rand(0:1, 30)

    # Compute the determinant of a toeplitz matrix constructed
    # from the two random arrays
    D = det(toeplitz(r1, r2))

    # If the computed determinant is larger than anything we've
    # encountered so far, add it to A so we can access it later
    D > d && begin
        push!(A, (D, r1, r2))
        d = D
    end
end

M,N = findmax([i[1] for i in A])

println("Maximum determinant: ", M, "\n")
println(toeplitz(A[N][2], A[N][3]))

You can view the output here.

Alex A.

Posted 2015-07-15T20:17:51.337

Reputation: 23 761

I wonder how precise the determinant calculation is. I figure that the underlying computation is done in double precision? Since the digits after the decimal point are .998, there's probably a good chance that the closest integer is still the correct determinant. Generally, you will start getting floating point precision issues when applying a general purpose determinant calculation, e.g. based on a standard LR decomposition, to these matrices once they get fairly large. – Reto Koradi – 2015-07-15T21:59:53.513

@RetoKoradi Looks like it uses an LU decomposition to get the determinant. – Alex A. – 2015-07-16T03:02:02.697

3

Mathematica, 39,994,961,721,988 (10^13.60)

A simple simulated annealing optimization method; no optimization or tuning yet.

n = 30;
current = -\[Infinity];
best = -\[Infinity];
saved = ConstantArray[0, {2 n - 1}];
m := Array[a[[n + #1 - #2]] &, {n, n}];
improved = True;
iters = 1000;
pmax = 0.1;
AbsoluteTiming[
 While[improved || RandomReal[] < pmax,
   improved = False;
   a = saved;
   Do[
    Do[
      a[[i]] = 1 - a[[i]];
      With[{d = Det[m]},
       If[d > best,
          best = d;
          current = d;
          saved = a;
          improved = True;
          Break[];,
          If[d > current || RandomReal[] < pmax (1 - p/iters),
           current = d;
           Break[];,
           a[[i]] = 1 - a[[i]];
           ]
          ];
        ;
       ],
      {i, 2 n - 1}];,
    {p, iters}];
   ];
 ]
best
Log10[best // N]
a = saved;
m // MatrixForm

Sample output:

{20.714876,Null}
39994961721988
13.602
(1  1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0
0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0
0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0
0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0
0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1
1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0
0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0
0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0
0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0
0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1
1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1
1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0
0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1
1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1
1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1   0
0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1   1
1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1   1
1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0   1
1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1   0
0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1   1
1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0   1
1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0   0
0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0   0
0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0   0
0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1   0
0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0   1
1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1   0
0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1   1
1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1   1
1   1   0   1   0   0   0   0   1   1   0   1   1   1   0   1   1   0   1   1   0   0   0   0   1   0   0   0   0   1

)

2012rcampion

Posted 2015-07-15T20:17:51.337

Reputation: 1 319

1

Python 2, 8 363 855 075 832

This has a very basic, nearly nonexistent strategy involved.

from scipy import linalg

start = 2**28
mdet  = 0
mmat  = []
count = 0
powr  = 1
while 1:
 count += 1
 v = map(int,bin(start)[2:].zfill(59))
 m = [v[29:]]
 for i in xrange(1,30):
     m += [v[29-i:59-i]]
 d = 0
 try: d = linalg.det(m, check_finite=False)
 except: print start
 if d > mdet:
     print d
     print m
     mdet = d
     mmat = m
     start += 1
     powr = 1
 else:
     start += 2**powr
     powr += 1
     if start>(2**59-1):
         start-=2**59-1
         powr = 1
 if count%10000==0: print 'Tried',count

Here is the best matrix it found after ~5,580,000 tries:

1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0
1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 1
1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0
0 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1
1 0 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1
0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0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