For every array of length n+h-1 with values from 0 and 1, I would like to check if there exists another non-zero array of length n with values from -1,0,1 so that all the h inner products are zero. My naive way to do this is
import numpy as np
import itertools
(n,h)= 4,3
for longtuple in itertools.product([0,1], repeat = n+h-1):
bad = 0
for v in itertools.product([-1,0,1], repeat = n):
if not any(v):
continue
if (not np.correlate(v, longtuple, 'valid').any()):
bad = 1
break
if (bad == 0):
print "Good"
print longtuple
This is very slow if we set n = 19
and h = 10
which is what I would like to test.
My goal is to find a single "Good" array of length
n+h-1
. Is there a way to speed this up so thatn = 19
andh = 10
is feasible?
The current naive approach takes 2^(n+h-1)3^(n) iterations, each one of which takes roughly n time. That is 311,992,186,885,373,952 iterations for n = 19
and h = 10
which is impossible.
Note 1 Changed convolve
to correlate
so that the code considers v
the right way round.
July 10 2015
The problem is still open with no solution fast enough for n=19
and h=10
given yet.