Suppose you are given a 2x2 “start” matrix like this one:
11
10
and a second 2x2 matrix like this one:
00
00
Create the next larger matrix by replacing every 1 in the start matrix with a copy of itself, and every 0 with the other matrix. In this case, you’d get
1111
1010
1100
1000
Make the same replacements to get larger and larger matrices (i.e. replace 1’s with the start matrix, 0’s with the other matrix.). Is there a clean way to do this in Q/kdb? I’ve written solutions in other programming languages, but they all involve multiple functions, most of which contain nested do-loops.
======================
The example given above produces a version of the Sierpinski Triangle. If you use
00
01
for the second matrix, you get a Hadamard matrix:
1111
1010
1100
1001