[Math] Tricky discrete math problems

discrete mathematicsmathematicaMATLABpython

discrete math problems

In the recent project, I encountered a puzzle, thought for several days, I simplified it. I will be very grateful for your help.

Best Answer

A solution for $N=7$ with the smallest value for $\omega_N$ is this:

$$ W = \begin{bmatrix} 25 & 26 & 28 & 29 & 34 & 36 & 37 \end{bmatrix} $$

$$M = \begin{bmatrix} 0 & 24 & 22 & 21 & 16 & 14 & 13 \\ 27 & 0 & 24 & 23 & 18 & 16 & 15 \\ 31 & 30 & 0 & 27 & 22 & 20 & 19 \\ 33 & 32 & 30 & 0 & 24 & 22 & 21 \\ 43 & 42 & 40 & 39 & 0 & 32 & 31 \\ 47 & 46 & 44 & 43 & 38 & 0 & 35 \\ 49 & 48 & 46 & 45 & 40 & 38 & 0 \end{bmatrix}$$

This solution is generated by this z3py script:

""" Find 0 < w1 < w2 < ... < wN < 1.5 w_1 such that all values of
    2wi - wj for i != j are distinct from all wk.
"""
from __future__ import print_function
from z3 import *

N = 7
omega = [Int('omega_%s' % (i+1)) for i in range(N)]

s = Solver()

s.add(omega[0] > 0)
for i in range(1,N):
    s.add(omega[i] > omega[i-1])
s.add(2*omega[-1] < 3*omega[0])

# Impose upper bound on omega[-1] to find "smallest" solution.
s.add(omega[-1] < 38)

for i in range(N):
    for j in range(i+1,N):
        for w in omega:
            s.add(2*omega[i] - omega[j] != w)
            s.add(2*omega[j] - omega[i] != w)

result = s.check()
if result == sat:
    mdl = s.model()
    print('W =', ' '.join([str(mdl.evaluate(w).as_long()) for w in omega]))

    mat = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(i):
            orow = mdl.evaluate(omega[i]).as_long()
            ocol = mdl.evaluate(omega[j]).as_long()
            mat[i][j] = 2 * orow - ocol
            mat[j][i] = 2 * ocol - orow

    print('\n'.join([' '.join(['{:3}'.format(item) for item in row])
                    for row in mat]))
else:
    print(result)
Related Question