[Question]
  [
# Background
In the online graphing calculator [Desmos](https://www.desmos.com/calculator), there is a certain shape that appears in the lower left portion of the graph in many high detail graphs, which the Desmos community has dubbed "Bernard". You can see an example of it in this [graph](https://www.desmos.com/calculator/zwanvat5bj) and an isolated version of it in this [graph](https://www.desmos.com/calculator/redbernard). This shape is a consequence of the quadtree algorithm which Desmos utilizes to actually graph equations. I barely comprehend how it all works, but by descending into "deeper", or more detailed, quadrants, a more detailed Bernard can be created.
(Don't take my word for how Bernard is formed, I barely understand how it works myself.)
A screenshot of what Bernard looks like for posterity:
[![](https://i.stack.imgur.com/bgYpp.png)](https://i.stack.imgur.com/bgYpp.png)
In this challenge, you will write code that will print out a 2d array version of a depth-`n` Bernard.
# How to create Bernard?
Given a positive integer `n`, create a \$2^n\times2^n\$ grid of `1`'s and `0`'s.
If \$n=1\$, then fill in the \$2\times2\$ grid like so:
```
0 1
1 1
```
That is your output.
If \$n>1\$, then recursively fill in the grid in the following way:
1. Split the grid into 16 blocks of size \$2^{n-2}\times2^{n-2}\$.
2. Fill in the square regions according to the below diagram, and recurse on the region labelled `R`:
```
0 0 1 1
0 0 0 R
1 1 1 1
1 1 1 1
```
3. If the region `R` is a \$1\times1\$ or a \$2\times2\$ region, then finish this step and output the resulting array. If the region `R` is a \$1\times1\$ region, then fill its only entry with `1`. If `R` is a \$2\times2\$ region, then fill it in the following way:
```
0 1
1 1
```
4. If step 3 does not apply, then repeat steps 1-4 but on region `R`.
# Worked example: `n=4`
`n` is 4, so we will have a \$16\times16\$ grid. Following step 1, we fill the grid in the following way (with `R` denoting the region we will recurse on):
```
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 R R R R
0 0 0 0 0 0 0 0 0 0 0 0 R R R R
0 0 0 0 0 0 0 0 0 0 0 0 R R R R
0 0 0 0 0 0 0 0 0 0 0 0 R R R R
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
```
The region `R` is \$4\times4\$, so we recurse. The region `R` should now look like this, with the new `R` inside the grid denoting where to recurse:
```
0 0 1 1
0 0 0 R
1 1 1 1
1 1 1 1
```
Because `R` is now \$1\times1\$, we fill it in, so it becomes:
```
0 0 1 1
0 0 0 1
1 1 1 1
1 1 1 1
```
Placing this back into the original \$16\times16\$ grid, we obtain the desired output:
```
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
```
# Task
Given a positive integer `n` as input, return a \$2^n\times2^n\$ 2d array which represents the depth-`n` Bernard.
# Test Cases
```
n=1
0 1
1 1
n=2
0 0 1 1
0 0 0 1
1 1 1 1
1 1 1 1
n=3
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
n=4
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
```
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code in bytes wins!
  
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 21 bytes
```
(|,/2\,'/4\10+)/[;+1]
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs9Ko0dE3itFR1zeJMTTQ1tSPttY2jOXiSlMwBGIjIDYGYhMAuhsIhw==)
Same algorithm, but uses a bit of base trick to generate the zero- and one-matrices at appropriate places.
```
10+    Map 0 to 10 and 1 to 11
4\     Base 4; 10 becomes (2 2) and 11 becomes (2 3)
2\     Base 2; 2 becomes (1 0) and 3 becomes (1 1)
```
---
# [K (ngn/k)](https://codeberg.org/ngn/k), 23 bytes
```
(,/(1|)\|,'/|^:\)/[;+1]
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs9LQ0dcwrNGMqdFR16+Js4rR1I+21jaM5eJKUzAEYiMgNgZiEwDeZgmn)
A straightforward implementation. Uses the recurrence pattern:
```
f(n+1) = [ zeros, f(n) reversed ]
         [ ones,  ones          ]
```
### How it works
```
(,/(1|)\|,'/|^:\)/[;+1]    a function that takes n and
(               )/         applies the recurrence n times on
                    +1     the 1x1 matrix containing a single 1:
             ^:\    converge-scan using "test if each atom is null"; gives (mat; zeros)
         ,'/|       reverse the order and horizontally join the two matrices
        |           reverse vertically
   (1|)\      converge-scan using "max with 1"; gives (mat; ones)
 ,/           join vertically
```
[Answer]
# [Desmos](https://desmos.com/calculator), ~~94~~ 92 bytes
```
f(n)=[0^{0^{4^{round(u+.5log_4dd)-u}-x}}forx=L,y=L]
d=3y-2^n2
u=(0^{0^d}+n)/2
L=[2^n...1]-.5
```
[Try it on Desmos!](https://www.desmos.com/calculator/jfwyqforaq)
The matrix is returned in row-major order.
*-2 bytes thanks to [@Aiden Chow](https://codegolf.stackexchange.com/users/96039/aiden-chow) (`log_4(dd)/2` ‚Üí `.5log_4dd`)*
Golfing note: `0^{0^{E-x}` can be converted to `\{E>x,0\}`, but this requires moving `E=round(u+.5log_4d)-u` to its own line and doing `\for`  instead of just `for`, so that is equal or +1 byte.
## How it Works
The top third of matrix Bernard consists of right-aligned blocks of height \$2^{n-2},2^{n-4},\ldots,2^{\operatorname{mod}(n,2)}\$, and the bottom two-thirds consists of right-aligned blocks of height \$2^{n-1},2^{n-3},\ldots,2^{\operatorname{mod}(n+1,2)}\$. Each block has width equal to twice its height, and the top and bottom converge near `y=m=2^n/3`.
The main difficulty is for each `y`, find the height of the current block.
First we find the distance of `y` from the convergence y-value `m`. This is \$D=y-\frac{2^n}{3}\$
To figure out how many steps this is away, consider a situation where `n` is even, so the top third has step sizes \$1,4,16,\ldots\$. The partial sums of this geometric sequence are \$p(k)=\frac{4^k-1}{3}\$, e.g. \$p(2)=\frac{4^2-1}{3}= 5 = 1+4\$.
Then \$(x,y)\$ on the top third is in step size \$4^k\$ iff \$p(k)\leq D<p(k+1)\$. This can be re-arranged to \$4^k\leq 3D+1\leq 4^{k+1}\$, so \$k=\operatorname{floor}(\log\_4(3D+1))\$
Ignoring golfing and the bottom side, this would give `{x < floor(log_4(3D+1)): 1, 0}` for the condition for filling in 1.
The final golfed code uses \$d=3y-2^{n+1}\approx 3D+1\$ (the `y` values are flipped, so this is really proportional to the distance of `y` from `2^n*2/3`, explaining `2^{n+1}` instead of `2^n`).
Hence we have `{x < floor(log_4(d)): 1, 0}` as the current condition. See what it looks like [on Desmos](https://www.desmos.com/calculator/dcf52qjsyc).
There's a few problems left: nothing is filled in for the bottom two-thirds, and the heights of the top third is twice as big as it should be for odd `n`.
Let's deal with the first problem first by just replacing `log_4(d)` with `log_4(abs(d))` to handle negative `d`, or equivalently `log_4(d^2)/2`, which golfs to `.5log_4dd`. Then our condition becomes `{x < floor(log_4(d)): 1, 0}`. See [on Desmos](https://www.desmos.com/calculator/anznvhmvyj).
The issue now is that the heights of the top third are twice too big for odd `n`, and the heights of the bottom two-thirds are twice too big for even `n`. The solution comes down to handling off-by-half in the exponent of `4^{...}` by adding and subtracting `u=(0^{0^d}+n)/2` withing/outside the `round`. If `d` is positive (top third) and `n` is even, then `u` is an integer, so it doesn't affect the `round`. If `d` is negative (bottom two-thirds) and `n` is odd, then `u` is an integer, so it doesn't affect the `round`. Otherwise, `n` is a half-integer, so it causes `round` to behave like `1+floor`, fixing the sizing issues.
[Answer]
# [Python](https://www.python.org), 76 bytes
```
f=lambda n:(x:=1<<n>>1)and[x*[0]+j for j in f(n-1)[::-1]]+x*[x*[1,1]]or[[1]]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3fdJscxJzk1ISFfKsNCqsbA1tbPLs7Aw1E_NSoiu0og1itbMU0vKLFLIUMvMU0jTydA01o62sdA1jY7WB0kBkqANk5xdFRwMpqJkWaUX5uQoFBUWZeSUKmbkF-UUlUB4XyKhMkFFFiXnpqRqmmlYQCY00jUxNTYh-mNsA)
Straight-forward recursion. Take the previous upside down, add a block of zeros on the left and a block of ones below.
Just seeing that @Bubbler used [the same recursion](https://codegolf.stackexchange.com/a/248821/107561) a few hours before me.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
2·πö;¬ª·πÄ¬≤∆ä∆ä¬°‚ÄôBz0ZU
```
A full program that accepts a positive integer from STDIN and prints a list representation of the Bernard.
**[Try it online!](https://tio.run/##AScA2P9qZWxsef//MuG5mjvCu@G5gMKyxorGisKh4oCZQnowWlX/w4dH/zQ "Jelly ‚Äì Try It Online")** (The footer prints the result as a grid instead of in the raw list format.)
### How?
Builds the Bernard in chunks consisting of the equal rows, starting with the row with the single `1`. At each step we reverse what we have so far and append the next chunk. Each new chunk has as many rows as we've built so far but with double the number of `1`s.
Under the hood, each row is first calculated as one more than its binary value. This starts at `2` and squares for each new chunk.
```
2·πö;¬ª·πÄ¬≤∆ä∆ä¬°‚ÄôBz0ZU - Main Link: no arguments
2               - literal two
        ¬°       - repeat STDIN times starting with X=2:
       ∆ä        -   last three links as a monad - f(X):
 ·πö              -     reverse the current list
                        (2 gives its decimal digits reversed = [2])
      ∆ä         -     last three links as a monad - f(Z=that):
    ·πÄ           -       maximum of Z
   ¬ª            -       vectorised maximum with Z -> an array of the same shape as
                                      Z, all populated with the maximum value in Z
     ¬≤          -       square them
  ;             -     (reversed X) concatenate with (that)
         ‚Äô      - decrement all the values
          B     - convert them to binary lists
           z0   - transpose with filler zero  }
             Z  - transpose                   } prepends zeros
              U - reverse each
```
[Answer]
# [Factor](https://factorcode.org/), ~~90~~ ~~89~~ 83 bytes
```
[ 2^ 3 dupn iota -rot '[ _ 3 /i bitxor bit-length 2^ 1 <array> _ 0 pad-head ] map ]
```
[Try it online!](https://tio.run/##HY4xT8NADIX3/oq3dUppWlgAsSKWLlWnqkVO4iYnLndXn6OSIn57MJks@316/i5Ua5TpsP/YvT@jJ@2Q@TpwqDmj5cBC3t1JXQwZFxlnZFU5vbnMIBEaM5Kw6pjEBYWL@GIJ7PGyWPygxAZbPOIJv9MRm7MtzZCCYUooJCqWR3za9cHBWr@j/I/Cc2hNxfgSr/OXN6PWSNQUHVODk4kknKwzuz55LpQqzysEb1Ed@xRNj6nupj8 "Factor ‚Äì Try It Online")
Port of @alephalpha's [PARI/GP answer](https://codegolf.stackexchange.com/a/248823/97916).
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 52 bytes
```
n->matrix(l=2^n,,i,j,j+2^#binary(bitxor(i-1,l\3))>l)
```
For input \$n\$, the number of \$1\$s in the \$i\$-th row (\$1\$-index) is \$2^{\#\operatorname{binary}(\operatorname{bitxor}(i-1,\lfloor2^n/3\rfloor))}\$, where \$\#\operatorname{binary}\$ means the number of the binary digits. This is because the binary representation of \$\lfloor2^n/3\rfloor\$ is \$(1010\dots)\$.
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWN03ydO1yE0uKMis0cmyN4vJ0dDJ1snSytI3ilJMy8xKLKjWSMksq8os0MnUNdXJijDU17XI0oXq10kDiCrYKhjoKJjoKBUWZeSUamToKSlZKmtYQboFGmkampiZUx4IFEBoA)
[Answer]
# [Python](https://www.python.org), ~~121~~ 104 bytes
```
lambda n:[[*map(int,f"{m:0{2**n}b}")]for m in g(n)]
g=lambda n:[1][n:]or g(n-1)[::-1]+2**~-n*[2**2**n-1]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=RY3RCoIwGIWv8ymGN27LQQsCGfgkcxeTnA7a71C7CLEX6UaIeqfepplFV4dzDt85t6e_DE0L893kxeM8GJa9mpN25VEjEFJSpz22MKQmHp3YjXtKYSqnmCjTdsghC6jGQFRU53-KKwlChT5UjBMpBONqG9ArAyqDLish-v5ly5RdpjoNdYV5eiAi2vgu_GJqsCVpX_k8KSAhv_hjVn6eV30D)
This is a much more interesting method, but is not well golfed because Python isn't great at converting binary numbers into a matrix (at least as far as I am aware).
Works by taking a start list of `[1]`. For each integer `i` up to `n`, reverse the list and add to it `2**~-n*[2**2**n-1]`. This outputs the following pattern
```
[1, 3]
[3, 1, 15, 15]
[15, 15, 1, 3, 255, 255, 255, 255]
[255, 255, 255, 255, 3, 1, 15, 15, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535]
```
Which is then converted into binary, with each item in the list forming a row in the matrix.
-17 bytes thanks to @pxeger
---
# [Python](https://www.python.org), ~~119~~ 117 bytes
```
f=lambda n:[[1]][n:]or-(-(p:=2**n)//4)*[(q:=p//2)*[0]+q*[1]]+[l+r for l,r in zip(p//4*[p//4*3*[0]],f(n-2))]+q*[[1]*p]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY9BDoIwEEXXeorumJY2FcSENOlJahcYqTbBoVRY6FXcsNE7eRsBdTOZP3kvP_N4hVt_bnEcn0PvRPkenG6qy-FYEVTGZNYaVLaNAgQEpXPGkEpZUGagUzpImU_rxqYdm9nUNGkkro2k4ZF4JHcfYIIKZpa5nVnLHaDIKV2sSWPB_srLWfWzGCs81ZDxHVXrVYgee2AOPOXXOuhkjwn9n5fw9f9PfAA)
Follows the algorithm as outlined in the question  
-2 bytes thanks to pxeger
[Answer]
# JavaScript (ES6), 95 bytes
A rather straightforward recursive construction.
```
n=>[...Array(1<<n)].map((_,y,a)=>a.map(g=(k=n,x,_,Y=y)=>k--?Y>>k|x>>k&g(k,x%=m=1<<k,_,~Y%m):1))
```
[Try it online!](https://tio.run/##XU7LbsIwELzzFXsoZFexLeXQS5M14jMiisCiJAKTNTIIJQL668GKeuplZueh1Zzc3V338Xi5aQk/h7HhUdiujTGrGN2ARVUJbUznLohbNShHbN0kW0bPonq1VTUPyfZaL2tr/bNPsGjRq37OHacPPnV@63lHXwXR2ISIAgxFCQIVw2fiPCd4zAD2Qa7hfDDn0OJOaxD@eMgLtN5R@S9uUGgaEoEtRHMKR8EMMqK/81syghwmLmev8Q0 "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
n =>                  // n = input
[...Array(1 << n)]    // build an array of 2 ** n entries
.map((_, y, a) =>     // for each item at position y in this array a[]:
  a.map(              //   iterate over a[] again using ...
  g = (               //   ... the recursive callback function g taking:
    k = n,            //     k = dimension, initialized to n
    x,                //     x = horizontal position
    _,                //     (ignored reference to the array)
    Y = y             //     Y = vertical position
  ) =>                //
    k-- ?             //     decrement k; if it was not 0:
      Y >> k |        //       insert a '1' if we are in the lower part (*)
      x >> k &        //       or we are in the right part and the result
      g(              //       of this recursive call is also 1:
        k,            //         pass the new value of k
        x %=          //         update x to x modulo m,
          m = 1 << k, //         where m = 2 ** k
        _,            //         (useless reference to the array)
        ~Y % m        //         update Y to (-Y - 1) modulo m
      )               //       end of recursive call
    :                 //     else:
      1               //       insert a '1' and stop the recursion
  )                   //   end of inner map()
)                     // end of outer map()
```
*(\*) The sign of Y is inverted at each iteration, so the 'lower' part is actually the upper part when Y is negative.*
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
√éF¬ºRNoF¬æ¬™]o√Ö10Œ∂R√∏
```
[Try it online](https://tio.run/##ASUA2v9vc2FiaWX//8OORsK8Uk5vRsK@wqpdb8OFMTDOtlLDuP/Cu/80) or [verify all test cases](https://tio.run/##ATkAxv9vc2FiaWX/NUVOIm49w78iLCL/ME5GwrxSTm9Gwr7Cql1vw4UxMM62UsO4/yIuVsK7LMK2Py7Ctf8). (The footer is to pretty-print the matrix.)
**Explanation:**
Step 1: Create alternating lists of \$2^x\$ amount of 0-based values depending on the input:
```
√é          # Push 0 and the input
 F         # Loop `N` in the range [0, input):
  ¬º        #  Increase `¬æ` by 1 (it's 0 by default)
   R       #  Reverse the current list (or 0 in the first iteration)
    No     #  Push 2 to the power `N`
      F    #  Inner loop that many times:
       ¬æ¬™  #   Append `¬æ` to the list
           #   (`¬™` will convert the 0 to [0] in the very first iteration)
 ]         # Close both loops
```
[See just this step online for all test cases.](https://tio.run/##yy9OTMpM/W/q6mevpPCobZKCkr3SfwM/t0N7gvzy3Q7tO7Qq9r@SXpiO3qGt/wE)
Step 2: Calculating \$2^v\$ for each of these values determines the amount of trailing `1`s per row:
```
  o        # Map each value to 2 to the power that value
   √Ö1      # Then convert each inner value to a list of that many 1s
```
[See the first two steps online for all test cases.](https://tio.run/##ATMAzP9vc2FiaWX/NUVOIm49w78iLCL/ME5GwrxSTm9Gwr7Cql1vw4Ux/yIuVsK7LMK2Py7Ctf8)
Step 3: Add leading `0`s to each row, and output the resulting matrix:
```
      Œ∂    # Zip/transpose this list of rows; swapping rows/columns,
     0     # using a 0 as filler-character for unequal length rows
       R   # Reverse the list of lists
        √∏  # Zip/transpose the matrix back
           # (after which it is output implicitly as result)
```
[Answer]
# [Uiua](https://www.uiua.org/), 19 bytes
```
‚ç•(‚äÇ‚äÉ‚àò=.‚çâ‚äÇ‚äÉ-‚çâ.‚áå):¬§¬§1
```
[Try it online!](https://uiua.org/pad?src=0_3_1__QiDihpAg4o2lKOKKguKKg-KImD0u4o2J4oqC4oqDLeKNiS7ih4wpOsKkwqQxCkIzCkI4Cg==)
## How it works
```
‚ç•(‚äÇ‚äÉ‚àò=.‚çâ‚äÇ‚äÉ-‚çâ.‚áå):¬§¬§1
¬†                  ¬§¬§1 1x1 matrix containing a single 1 
¬†                 :    flip the values on the stack, bringing n to the top of the stack
‚ç•                      repeat the following n times:
¬†               ‚áå      reverse the matrix's rows, flipping it vertically
¬†              .       duplicate
           ‚äÉ-‚çâ        apply subtraction from the duplicate and transpose in parallel
  ¬†                    subtraction from the same matrix results in a 0 matrix
        ‚äÇ             join the resulted matrices vertically
¬†     ‚çâ               transpose back, reverting the previous transpose and making the join horizontal
      .               duplicate
¬†  ‚äÉ‚àò=                apply identity (keep, do nothing) and equality against the duplicate in parallel
                      equality against the same matrix results in a 1 matrix
¬† ‚äÇ                   join
```
[Answer]
# [Python 3](https://docs.python.org/3/), 138 bytes
```
import re
def f(n):r=[int(bin(i)[2:])for i in range(2**n)];return[[1-bool(re.match('1(13)*(12|0)',str(x+y+y+10**n)))for x in r]for y in r]
```
[Try it online!](https://tio.run/##XU7LDoIwELzzFb2xi0goxEuNX9JwAG2liWybtSaQ@O/IQy9mDjPJZB5hir2nep7dEDxHwSa5GSssECq@aEcROkfgUFeqQetZOOFIcEt3A1WWETZnNvHFpLU8dt4/gE0xtPHaQypB1piBrN4lpvkzMoyHaYEs1yBudeNW16xy2uXvSgi8zCd/mzIXJ1SJ@NrFTmCXizh/AA "Python 3 ‚Äì Try It Online")
[Answer]
# [Haskell](https://www.haskell.org), 111 bytes
```
data T a=C a|Q(T a)(T a)(T a)(T a)
f 0=C 1
f 1=Q(C 0)(C 1)(C 1)$C 1
f n=Q(C 0)(Q(C 1)(C 1)(C 0)$f$n-2)(C 1)$C 1
```
The matrix is represented as a [quadtree](https://en.wikipedia.org/wiki/Quadtree). (I don't know if this output format is accepted).
[Answer]
# [Python 3](https://docs.python.org/3/) with [numpy](https://numpy.org/), ~~77~~ 76 bytes
```
from numpy import*
f=lambda n:n<eye(1)or kron(c_[:4:2,1:3],f(n-1)[::-1]+1)>1
```
[Try it online!](https://tio.run/##DcoxDsIwDADAnVd4jKEdTGGxKB@pKhQggQhiR1YY8vrQm6@0@laZeo@mGeSXS4OUi1rd7@L89fn@9CAsl9CCI1SDj6m4x23hEx8H4mkdopORcGEeaT0QXqnH7QkkAfPyCu6MDMWSVLdVxP4H "Python 3 ‚Äì Try It Online")
* `n<eye(1)` produces `[[True]]` for n=0, the base case, and `[[False]]` for positive n, causing the expression after it to be used.
* `c_[:4:2,1:3]` produces \$ \begin{pmatrix}0&1\\2&2\end{pmatrix}\$, and is 1 byte shorter than the direct way of writing that matrix.
* The grid for n-1 is recursively obtained and flipped vertically, and then 1 is added, making it consist of 1s and 2s. `kron` then produces a copy of it in the top-right quadrant (>1 where the pre‚Äì+1 version had a 1), a doubled copy of it in each bottom quadrant (always >1), and zero in the top-left quadrant (never >1).
[Answer]
# BQN, 19 bytes
```
{(‚àæ‚üú√ó‚üú‚ãÜ0¬®‚àæÀò‚åΩ)‚çüùï©‚âç‚âç1}
```
[Try it here!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgeyjiiL7in5zDl+KfnOKLhjDCqOKIvsuY4oy9KeKNn/CdlaniiY3iiY0xfQoK4oCiU2hvd+KImEbCqDEr4oaVNApA)
*-1 thanks to @att*
## Explanation
Input is *x*.
* `(...)‚çüùï©‚âç‚âç1` execute *x* times on matrix `[[1]]`...
* `0¬®‚ä∏‚àæÀò` row-wise prepend matrix of 0s
* `1¬®‚ä∏‚àæ` column-wise prepend matrix of 1s
* `‚åΩ` column-wise reverse
Example of how one iteration works:
```
0 1      # start
1 1
0 0 0 1  # 0¬®‚ä∏‚àæÀò
0 0 1 1
1 1 1 1  # 1¬®‚ä∏‚àæ
1 1 1 1
0 0 0 1
0 0 1 1
0 0 1 1  # ‚åΩ
0 0 0 1
1 1 1 1
1 1 1 1
```
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 26 bytes
```
‚Üë1Ôº¶Ôº•ÔºÆÔº∏¬≤Œπ¬´‚Äñ‚ÜìÔºµÔºØ‚äóŒπŒπ1Ôº≠‚äïŒπ‚Üë¬ª‚ÄñÔºµÔº¢0
```
[Try it online!](https://tio.run/##NY2xDoIwFEVn@IqG6TXBRI2TbobFASUaP6CUBzaWPtK0MBi/vb5Btntzc87VL@U1KZtS440LcHxOpSh2hTzlPXkBtZrg4qYYrnFs0YMsRUMLh30pjJRSfPLsjr1FzWxFi2Mwu7WW3AAVxdZiB4Yhs1qzmmZkpfY4ogv/mW95@@arissDw1np9@Apug6KLcMpHdJmtj8 "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation: Works by drawing the horizontal mirror image of Bernard, using the property that each Bernard is the vertical mirror image of the previous Bernard extended to the left with `0`s and then extended down with `1`s.
```
‚Üë1
```
Output the lone `1` on its own row, leaving the cursor above the row.
```
Ôº¶Ôº•ÔºÆÔº∏¬≤Œπ¬´
```
Loop `n` times, adding `2‚Å±` rows each time, thus resulting in a total of `2‚Åø` rows.
```
‚Äñ‚Üì
```
Reflect vertically, leaving the cursor below Bernard.
```
ÔºµÔºØ‚äóŒπŒπ1
```
Draw the next size rectangle of `1`s.
```
Ôº≠‚äïŒπ‚Üë
```
Move back to the top of the Bernard.
```
¬ª‚Äñ
```
Reflect horizontally to complete the Bernard.
```
ÔºµÔº¢0
```
Fill the background with `0`s.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `·πÄ`, 20 bytes
```
0?(·πònEn‚Ä∫·∫ãJ)E1v·∫ã0√û·π™·πò‚à©
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyLhuYAiLCIiLCIwPyjhuZhuRW7igLrhuotKKUUxduG6izDDnuG5quG5mOKIqSIsIuKBiyIsIjQiXQ==)
[Answer]
# [brev](https://idiomdrottning.org/brev), 190 bytes
```
(define(b n)(define(e d v)(make-list(expt 2(- n d))v)) `(,@(e 2 `(,@(e 1 0),@(e 1 1))),@((over(append(e 1 0)(e 2 0)x))(b(- n 2))),@(e 1(e 0 1))))(define(b 1)'((0 1)(1 1)))(define(b 0)'((1)))
```
236 with whitespace added back in:
```
(define (b n)
  (define (e d v)
    (make-list
     (expt 2 (- n d)) v))
  `(,@(e 2 `(,@(e 1 0) ,@(e 1 1)))
    ,@((over (append (e 1 0) (e 2 0) x)) (b (- n 2)))
    ,@(e 1 (e 0 1))))
(define (b 1) '((0 1) (1 1)))
(define (b 0) '((1)))
```
Bonus! I like coming up with my own solution but here's my implementation of Bubbler's idea, at 135 bytes (displayed here with 15 unnecessary bytes of whitespace for readability)
```
(define (u n) ((fn `(,@((over `(,@((over 0) x) ,@x)) (reverse x)) ,@((over `(,@((over 1) x) ,@((over 1) x))) x))) (u (- n 1))))
(define (u 0) '((1)))
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 80 bytes
```
f=n=>n?f(n-1).reduce((v,e)=>[p=[...e.map(_=>0),...e],...v,p.map(_=>1)],[]):[[1]]
```
[Try it online!](https://tio.run/##XU5LDoIwEN1zilmY0Am0kYUbcfAgtRECxUBwSoqyIZwdgejG5OX9ZjGvLcZiKH3TvyS7yi41rWDK@FoLlgkqb6t3aYUYY4uU6Z60UsqqZ9GLO2VHjLdoNh7j/lcnaGJt8Kx1YsxSOy8YCJIUGC4Ep1WjCGEKAErHg@us6txD5FIC02HiGaTMMf07r4Nwf@CBMvCqdQ2LEELEr71xiBDBrmkwLx8 "JavaScript (Node.js) ‚Äì Try It Online")
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 75 bytes
```
f=lambda n,g=[]:n and f(n-1,[0]*(p:=2**~-n)+g)[::-1]+p*[g+[1,1]*p]or[g+[1]]
```
[Try it online!](https://tio.run/##LcnBCgIhEIDh@z7FHNXVyCIIwSeRORibJrTjMHjp0qsbVKefj59f49HpfGWZs8Rn3m9bBrI1JgwEmTYoipy36YhGcYgnY96O9Fp1CsF5XNmkuiZvPRrGLl8gzrZzlwHM0mgspQs0aASSqd6Vt3DRYYH/Pvyiimpazw8 "Python 3.8 (pre-release) ‚Äì Try It Online")
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 72 bytes
```
f=lambda n,z=0:[l:='0'*z+2**n*'1'][n:]or f(m:=n-1,z+2**m)[::-1]+2**m*[l]
```
[Try it online!](https://tio.run/##HYpBCsMgEAC/4m11ayC2FMoGX2I9WBJbQTciuTSft8XbMDP1e3x2vj1q6z3aHMprDYL1aWdymSzMgOflisgIBrxj8nsTURayPBk9UlGOaDJ@MLrse/w/SSQWLfB7k3dForbEh0x649UCPRnUgiVUObyOMiml@w8 "Python 3.8 (pre-release) ‚Äì Try It Online")
]