Find a ternary $4\times 39$ matrix satisfying the conditions below Can you find a matrix $A_{4\times39}$ with elements from $\{-1,0,1\}$ so that


*

*No column is all zero.

*All columns are different.

*No column is $-1$ times another column.

*Each row consists of $13$ of each of $\{-1,0,1\}$.


How can you do that? Is it possible to generalize this case?
 A: I think it is possible (I hope I didn't made a mistake, which is easily possible)

Here are some thoughts: You can assume that the first line is 13 1s then 13 0s and then 13 -1s. We call a column an $i$-col, if its top entry is $i$. For the 26 1/-1-cols you have at most $3^3$ choices for completion. So you need all possible 3-tuples except one. For the 0-cols forget about the sign for the first non-0 entry for now. You have then $9$ choices left. So you need all of them. Place them and fiddle around with the signs until every row (2-4) has 4 1 and 5 -1 coming from the 0-cols. The missing column for the other 1/-1-cols is $(*,-1,-1,-1)$, otherwise you would have been left with two many 1s. Now  fill all remaining rows by completing the 1-cols and -1-cols. Continue by swapping columns, until the numbers are right.
A: One helpful hint is that if you find a solution, then the matrix obtained by negating a row is still a solution.  Another hint: if you regard a column and its negation as an equivalence class, how many classes are there?  How many of these must actually get used?  What can you say about classes that don't get used?  How does this relate to the hint about row negations?
The key hint for this problem, however, is contained in the original problem statement.  It's the question whether the solution can be generalized.  I would recommend trying generalizations with shorter columns, say columns of length $2$ or $3,$ before trying generalizations with longer columns, and even before attempting to construct the $4\times39$ example.  You will have to figure out what the row length will be in the general case, using considerations like the ones above.  Once you have that, it should be possible to do the smallest-size cases by exhaustive search.  Can you build on these results to construct larger examples?
Added: To be clear, my hints were suggesting a recursive construction.  To answer the questions raised in my first paragraph: for columns of length $\ell,$ there are $\frac{1}{2}(3^\ell-1)$ classes.  When $\ell$ is $4,$ that means $40$ classes.  So if we are to have 39 columns, then one class will be unused.  This suggests a possible generalization to $\ell\ne4$, and we let
$$s(\ell)=\frac{1}{3}\left[\frac{1}{2}(3^\ell-1)-1\right]=\frac{1}{6}(3^\ell-3),$$
which is an integer.  We look for matrices of $\ell$ rows and $3s(\ell)$ columns satisfying your conditions (1), (2), and (3), and having $s(\ell)$ each of $1,$ $0,$ and $-1$ in every row.
Since the two members of each equivalence class differ only in sign, the number and positions of zeros are independent of which member is chosen to represent the class.  There are $3^\ell$ vectors of length $\ell$ with elements in $\{-1,0,1\},$ comprising $\ell\cdot3^\ell$ total elements, of which a third, or $\ell\cdot3^{\ell-1},$ are zero.  Since the zero vector, containing $\ell$ zeroes, is not to be used, any set constisting of one representative of each equivalence class contains $\frac{1}{2}(\ell\cdot3^{\ell-1}-\ell)=\frac{1}{6}(3^\ell-3)\ell=s(\ell)\ell$ zero elements.  This is exactly the number of zero elements needed to satisfy condition (4) on row elements, which implies that all of the equivalence classes containing zero elements get used.  So one of the equivalence classes containing only $\pm1$ elements is the unused class.  Since the row normalization is arbitrary, we can take the missing class to be the class consisting of the all-ones vector and its negation.
Let us solve the $\ell=2$ case first.  We have $s(\ell)=1.$  The columns will be $\pm(1,0)^T,$ $\pm(0,1)^T,$ and $\pm(1,-1)^T.$  If we choose the signs $+,$ $-,$ and $-,$ we get the matrix
$$M_2=\begin{bmatrix}1 & 0 & -1\\0 & -1 & 1\end{bmatrix},$$
which has one $1,$ one $0,$ and one $-1$ in each row.
If we have constructed a matrix $M_\ell,$ satisfying conditions (1), (2), and (3), and having $s(\ell)$ $1\text{s,}$ $s(\ell)$ $0\text{s,}$ and $s(\ell)$ $-1\text{s}$ in each row, then the $\ell\times9s(\ell)$ matrix
$$\begin{bmatrix}M_\ell & M_\ell & M_\ell\end{bmatrix}$$
has $3s(\ell)$ $1\text{s,}$ $3s(\ell)$ $0\text{s,}$ and $3s(\ell)$ $-1\text{s}$ in each row.  Of course we now have three copies of each column, but by prefixing each copy with a different element, $1,$ $0,$ or $-1,$ we obtain an $(\ell+1)\times9s(\ell)$ matrix with distinct columns and $3s(\ell)$ $1\text{s,}$ $3s(\ell)$ $0\text{s,}$ and $3s(\ell)$ $-1\text{s}$ in each row.  Since $s(\ell+1)=3s(\ell)+1,$ to construct $M_{\ell+1}$ we need one additional $1,$ $0,$ and $-1$ in each row.  A construction of $M_{\ell+1}$ can be achieved as follows:
$$M_{\ell+1}=\left[\begin{array}{c|ccc|c|ccc|c|ccc}1 & 1 & \ldots & 1 & 0 & 0 & \ldots & 0 & -1 & -1 & \ldots & -1\\
\hline
0 &  &  &  & -1 &  &  &  & 1 &  &  & \\
\vdots &  & M_\ell &  & \vdots &  & M_\ell &  & \vdots &  & M_\ell & \\
0 &  &  &  & -1 &  &  &  & 1 &  &  &
\end{array}\right].$$
Since $M_\ell$ does not contain the all-zero column, the all-one column, or the all-minus-one column, neither does $M_{\ell+1}.$  Since $M_\ell$ contains neither duplicate columns, nor columns which are negations of each other, neither does $M_{\ell+1}.$  All conditions are therefore satisfied.  Here's an image:

A: Here is a human and fiddling-free approach.
Since  the order cannot be of matter, we fill the top rows with 13 of each in order giving
($-1 \times 13, 0 \times 13, 1 \times 13$) and we call them block-columns A,B,C. Similarly, if we fill the next row using ($-1 \times 13, 1 \times 13, 0 \times 13$) (block-columms D,E,F), we would have already solved the problem completely if it was asking for a $ (4) \times (3 \times 9) $ matrix, because each block-column can then be filled with the $9$ permutations left for the two remaining rows, while satisfying all conditions automatically because of our choice of roots and permutations balancing the digits equally.  
But this is already a good partial result, so we do just that, except that we split D,E,F into (D,D'),(E,E'),(F,F') with D,E,F of size $9$ columns each, and the others of size $13-9=4$ each. We still need to determine how D',E',F' are filled. To avoid negation conflicts, we choose (for the second rows still) ($1 \times 4, 0 \times 4, -1 \times 4$). 
We are done if we fill the last two rows of D',E',F'. E' is guaranteed to be conflict free (except for $(0,0,0,0)$) so we use it as a 'rest collector'. For D',F', their roots being negatives, we simply decide to make the rest two columns equal, and this is indeed possible. We need for each row to use four of each digit (to add up to $13$). So we split $-1$ two for each of D' and F', then we take one $0$ for each and one $1$ for each, putting the rest in E'. We are done.  
The result then looks like this:

(This probably does not generalize easily though.)
.

Addendum  

This general procedure occurred to me. It is very boring and not really elegant; but it can be used to generalize the solution.
The approach is to generate all permutations (not too much to ask for, since we will need half of them anyway) in a specific order. Usually I would generate permutations in an ascending order like this: $$ \pmatrix{-1 \cr -1 \cr -1 \cr -1},\pmatrix{-1 \cr -1 \cr -1 \cr 0},\pmatrix{-1 \cr -1 \cr -1 \cr 1},\pmatrix{-1 \cr -1 \cr 0 \cr -1},\pmatrix{-1 \cr -1 \cr 0 \cr 0},...\pmatrix{1 \cr 1 \cr 1 \cr 1}$$ In this case, it is better to 'interleave the beginning and end', so that each column has its negative directly after it. This happens automatically if we procede like above, but after each column, we add its negative. $$ \pmatrix{-1 \cr -1 \cr -1 \cr -1},\pmatrix{1 \cr 1 \cr 1 \cr 1},\pmatrix{-1 \cr -1 \cr -1 \cr 0},\pmatrix{1 \cr 1 \cr 1 \cr 0},\pmatrix{-1 \cr -1 \cr -1 \cr 1},\pmatrix{1 \cr 1 \cr 1 \cr -1},...\pmatrix{0 \cr 0 \cr 0 \cr 0}$$ The task then becomes clear: From each pair we have to choose only one until the matrix is filled. To do this while respecting the '13 in a row constraint', we simply keep track of how many allowed choices are left for each digit in each row, this needs $12=4 \times 3$ numbers to track. The process will always work, we will never need to backtrack, and we will be very bored.   
But this at least allows generalizing the solution: it works for any matrix of size $(n \times (floor(\dfrac {3^{n-1}} {2}) \times 3)) $, with the $13$ of condition 4) replaced by $floor(\dfrac {3^{n-1}} {2})$.
A: I've translated the constraints into a set of boolean expressions. These were then translated into Conjunctive Normal Form (CNF) and solved using a SAT solver.
The result:

Obviously, A.Schulz' "fiddle around" solution has taken more human intelligence and deeply impressed me. Well done!
