This thread follows from

this thread. I'm still not satisfied with the 5*6 unit because there is space between logic gates. I dreamt of finding some logical expressions that can support a 4*5 unit, which is as compact as possible. I spent some days making no progress until today when I wrote a program to search valid logical expressions with brute force. I got a bunch of candidates and finally I was lucky enough to find a set of expressions making the unit 4*4 and can be compactly placed.

I have checked and can confirm that the logic is right.

Denote the 4 inputs from higher digit to lower digit by a,b,c and d.

The 4 outputs are clearly shown in the picture. The logical expressions of the 4 gates, from left to right, are:

^(~ac,abd,~acd)

abc&bcd&~c

^(~ad,~abcd,ab)

^(~d,c,b)

This unit can be stacked like this:

Beautiful, isn't it?

@ekinator