[Question]
  [
Given a non-negative integer `n`, print the result of `P(P(...P({})))`, where the number of `P`'s is `n` (`P` is the power set function).
```
0 => {}
1 => P({})
2 => P(P({}))
3 => P(P(P({})))
n => P(f(n-1))
```
```
input   result
0       {}
1       {{}}
2       {{},{{}}}
3       {{},{{}},{{{}}},{{},{{}}}}
...
```
The result should only contain parentheses/brackets/braces and commas, spaces and newlines are allowed.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage), 3 bytes
```
≈íP¬°
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FkuPTgo4tHBJcVJy8fJDi45OerhzBkRiwUJjCAMA)
Using [standard I/O rules](https://codegolf.meta.stackexchange.com/q/2447); takes input from STDIN
Explanation:
```
  ¬°         repeatedly apply
≈íP           the power set
             to nothing
              which defaults to 0
               which is turned into the range [1..0]
                which is []
```
---
If you insist on the `{{},{{}}}` formatting:
## [Jelly](https://github.com/DennisMitchell/jellylanguage), 12 bytes
```
≈íP¬°≈í·πò‚Äú[{]}‚Äùy
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m700KzUnp3LBgqWlJWm6FluPTgo4tPDopIc7ZzxqmBNdHVv7qGFu5ZLipORiqIoFC40hDAA)
This could probably be shorter, but I'm not too interested in golfing boring formatting code.
Explanation:
```
≈íP¬°≈í·πò‚Äú[{]}‚Äùy
  ¬°                 repeatedly apply
≈íP                   the power set
   ≈í·πò               convert to string representation
            y       translate
     ‚Äú[{]}‚Äù          square brackets to curly braces
```
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 8 bytes
```
{}1qR@C~
```
[Try it online!](https://tio.run/##SyotykktLixN/V9W9r@61rAwyMG57n9whkN0dVGdQ2xtUV3gfwA "Burlesque ‚Äì Try It Online")
```
{}   # Empty block
1    # Continuation takes top 1 elements of stack
qR@  # Quoted powerset
C~   # Continuation forever, printing all powersets
```
If you insist on getting a particular N
# [Burlesque](https://github.com/FMNSSun/Burlesque), 11 bytes
```
{}1qR@C~j!!
```
[Try it online!](https://tio.run/##SyotykktLixN/V@U@b@61rAwyMG5LktR8X9whkN0dVGdQ2xtUV3gf2MA "Burlesque ‚Äì Try It Online")
```
j!! # Reorder stack, get from block
```
And if you insist on comma-separated formatting add 8 bytes for
```
up' ',r~
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 19 bytes
```
Nest[Subsets,{},#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zg@98vtbgkOrg0qTi1pFinulZHOVbtv0t@dEBRZl5JdJ6Crp1CWnRebKyOQnWejoKBjoJJbex/AA "Wolfram Language (Mathematica) ‚Äì Try It Online")
In the notebook interface, the results are printed without spaces. But in TIO or the text-based interface, spaces are automatically added.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
or 12
```
¬æ?(·πó
```
## Explanation
```
¬æ?(·πó
¬æ     Global array, empty at the start
 ?    Get input n
  (   Start loop n times
   ·πó  Powerset
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLCvj8o4bmXIiwiIiwiMyJd)
## 12 bytes with the curly braces formatting:
(thanks to [@lyxal](https://codegolf.stackexchange.com/users/78850/lyxal))
```
¬æ?(·πó)S¬æS‚Äõ{}ƒø
```
```
¬æ?(·πó)S¬æS‚Äõ{}ƒø
¬æ?(·πó)          The boring stuff
     S         Stringify the power-setted list
      ¬æ        Empty list -> `[]`
       ‚Äõ{}     Curly braces
          ƒø    Transliterate, replace `[]` with the curly braces
```
The `P` prints the list with its python representation.
[Try it online!](https://vyxal.pythonanywhere.com/#WyJQIiwiIiwiwr4/KOG5lylTwr5T4oCbe33EvyIsIiIsIjMiXQ==)
[Answer]
# [Python](https://www.python.org), 96 bytes
```
from itertools import*
f=lambda n:n and(chain(*(combinations(f(n-1),r)for r in range(n+1))))or()
```
[Attempt This Online!](https://ato.pxeger.com/run?1=RY5LCsJAEET3OUUve9QsgggSyF2cfMY0ZLqHTgfiWdxko3fyNkaJ-HYFr6i6P9PNeuFleUwW8vPrElQikHVqIsMIFJOo7bJQDT7WrQcuGTy32PSeGHfYSKyJvZHwiAE5L9xBXRAFBWJQz9cOeV-4FVF0287xY9DfOLkyg5UZKghI7huSEhvalIYOZ7dVf1ff)
[Answer]
# [Haskell](https://www.haskell.org/), 53 bytes
```
f=(!!)$iterate(\l->init l++[','|l/="{}"]++l++"}")"{}"
```
[Try it online!](https://tio.run/##FchBDoIwEAXQq3waEtpUi4nregJ3LpFFQ4bYODQIwwo4e5Hle58wf4k5597rojBlFJqCkH7z9RFTFLC1TXWpNq69WnfVWvsftStzKg8hJnjM9FsodYQSQxihx0VeMj0THHqD5ubcvc0H "Haskell ‚Äì Try It Online")
My first golf. Nothing particularly clever, uses the Fokker trick to deal with the base case.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 3 or ~~17~~ 11 bytes
```
yFY
```
[Try it online!](https://tio.run/##K6gsyfj/v9It8v9/YwA "Pyth ‚Äì Try It Online")
`F` - Repeat *Q* times, where *Q* is the implicit input:
`y` - powerset of
`Y` - empty list
### With formatting
```
X`yFYQ"[]}{
```
[Try it online!](https://tio.run/##K6gsyfj/PyKh0i0yUCk6trb6/39jAA "Pyth ‚Äì Try It Online")
`X..."[]}{` - convert each occurrence of `[` to `{` and each occurrence of `]` to `}`
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/tree/fb4a2ce2bce6660e1a680a74dd61b72c945e6c3b), 4 or 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
Regular I/O using `[]` instead of `{}` and spaces after the commas would be 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage):
```
¬ØIF√¶
```
[Try it online](https://tio.run/##yy9OTMpM/f//0HpPt8PL/v83BgA) or [verify the first few test cases](https://tio.run/##yy9OTMpM/W9ybJKfvZLCo7ZJCkr2/w@t93M7vOx/rc5/AA).
Strict I/O format is 17 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage):
```
¬ØIF√¶}"√ø"‚Äû[]‚Äû{}‚Ä°√∞K
```
[Try it online](https://tio.run/##MzBNTDJM/f//0HpPt8PLapUO71d61DAvOhZIVNc@alh4eIP3///GAA) or [verify the first few test cases](https://tio.run/##MzBNTDJM/W9ybJKfvZLCo7ZJCkr2/w@t93M7vKxW6fB@pUcN86JjgUR17aOGhYc3eP/X@Q8A).
**Explanation:**
`"√ø"` on lists only works in the legacy version of 05AB1E (built in Python), and unfortunately not in the new 05AB1E version (built in Elixir). I'm not sure how to do this challenge in the new version of 05AB1E, which lacks any form of `toString` builtin on lists..
```
¬Ø        # Push an empty list: []
 IF      # Loop the input amount of times:
   √¶     #  Pop the current list, and push its powerset
         # (after the loop, the result is output implicitly)
¬ØIF√¶     # Same as above
  }      # Close the loop
   "√ø"   # Convert the (nested) list to a string
‚Äû[]‚Äû{}‚Ä°  # Transliterate all "[" to "{" and "]" to "}"
√∞K       # Remove all spaces
         # (after which the result is output implicitly)
```
[Answer]
# [Python 3](https://docs.python.org/3/), 71 bytes
```
f=lambda n,k=1:n and f(n-1,1<<k)or[f(0,i+1)for i in range(k)if~-k>>i&1]
```
[Try it online!](https://tio.run/##BcHBDkAwDADQX@lJ2phEw0nwI@IwoTSjk8XFxa/Pe/f7HNGanGU4/bWsHsyFgTsDbysIWsWO@z5QTJNg7bRkkphAQQ2St33DQCpfFcZRC57zndQeFGyJ8g8 "Python 3 ‚Äì Try It Online")
Adapts [pxeger's Python answer](https://codegolf.stackexchange.com/a/248716/) to [Enumerate all pure sets](https://codegolf.stackexchange.com/q/248715/).
Computes the pure set corresponding to \$^n2-1\$ in the binary-encoding enumeration, which consists of the \$^{n-1}2\$ distinct sets with rank less than \$n\$.
[Answer]
# JavaScript (ES10), 95 bytes
Assuming a strict output format:
```
f=(n,a=[])=>n?f(n-1,a.reduce((a,x)=>a.flatMap(y=>[y,[...y,x]]),[[]])):(g=a=>`{${a.map(g)}}`)(a)
```
[Try it online!](https://tio.run/##ZcpBCoMwEEDRfc/RxQyMQ213hdgTeIIQcNBEWmwiaotBPHuabXHzF4//kq/M7fQcl8KHzqbkFHgSpQ2qyj8c@KIk4cl2n9YCCK3Zhd0gSy0jRFXpSJqZI63GIGmdi3folaiq2c6b8Dt/Pe57gyCY2uDnMFgeQg8OLoinfykPcj3IDTH9AA "JavaScript (Node.js) ‚Äì Try It Online")
---
# JavaScript (ES10), 71 bytes
Returning an array of arrays:
```
f=(n,a=[])=>n?f(n-1,a.reduce((a,x)=>a.flatMap(y=>[y,[...y,x]]),[[]])):a
```
[Try it online!](https://tio.run/##ZcjBCsIwDADQu1@SQBac3oTOL/ALQg@ha0Up6dimrF9fd5Vd3uG99atLmF/T2lkZY2vJgZE68egGuyewriflOY6fEAGUtv2VU9b1oRNUN0glYeZKm/dIIrt40xaKLSVHzuUJCc6Ip//pD3M5zBWx/QA "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [Factor](https://factorcode.org/) + `math.combinatorics`, 72 bytes
```
[ { } [ all-subsets ] repeat unparse " "without "}{""},{"replace write ]
```
[Try it online!](https://tio.run/##HcyxCsIwEIfxvU/xJ7O6uOkDiIuLOEmHazjbwzQJlytFS589FtePH9@LvCWtj/v1djlhJBsOPo2dRNqy@IKeIysF@ZJJigVZ2eyTVaKhsBWUHMRMYg9JeLNGDjg3zbGpTyxY8QSFsC9T99ctlDOTYYqZtDAc3Cw2pMng1sW5dbe4jQTyjFnFGG3126H@AA "Factor ‚Äì Try It Online")
As written.
---
# [Factor](https://factorcode.org/) + `math.combinatorics`, 30 bytes
```
[ { } [ all-subsets ] repeat ]
```
[Try it online!](https://tio.run/##DcgxDsIwDAXQPaf4F6ALGxwAsbAgpqqDGxmwSJ3IdgdAnD30je9OOar12/V8OR2wUDyHXJdZlLaW7HiwslGRD4VUdTTjiHcz0cCLTbngmNI@9RFf/DCCStn5OjuHY4JxYwpMPW@Pof8B "Factor ‚Äì Try It Online")
With standard I/O rules.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 206 bytes
```
#define P putchar
f(i,s,c){P(123);for(s=0;i;++s,i>>=1)if(i&1){f(s);if(i>1)P(44);}P(125);}s,i;main(c,v)char**v;{sscanf(v[1],"%d",&c);for(s=!!c--;c>0;--c)s=1<<s;P(123);for(;i<s;){f(i++);if(s>i)P(44);}P(125);}
```
[Try it online!](https://tio.run/##XY7NCsIwEITvPoVWlGyTgPHntG2eoXfxUFaje7BKV3spPntMBEE8DQMz8w3ZM1GM8@MpcHeaNtP780GXtp8ExUYMwdgot94AhluvpF4ho9Zi2PvaAafQ0sEYlABm4x00arsFfOXWLmmK4rXlTpEZIA@X5YCjCLVdUMPeHUyxOBZmSV/CbEbWIvkVWksgtasqwZ8PyMlnJGv9gYrnf2iMcfMG "C (gcc) ‚Äì Try It Online")
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata), 5 bytes
```
√ò·∂¶{Sa
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHHBgqWlJWm6FisOz3i4bVl1cOKS4qTkYqggTBIA)
```
√ò·∂¶{Sa
√ò       Empty list
 ·∂¶{     Iterate
   Sa   All subsets
```
Since Nekomata is a non-deterministic language, the built-in `S` (`\subset`) returns any subset non-deterministically instead of all subsets in a list. This is helpful for many other challenges, but not this one. We have to add an `a` (`\allValues`) to get the power set.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes
*Ties [pxeger's Jelly answer](https://codegolf.stackexchange.com/a/248448) and [math junkie's Pyth answer](https://codegolf.stackexchange.com/a/248457) for #1.*
```
ƒáF√¶
```
[Try it online!](https://tio.run/##yy9OTMpM/f//SLvb4WX//0cbxwIA "05AB1E ‚Äì Try It Online") Takes input as a singleton list, and outputs with square brackets.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 26 bytes
```
Ôº¶‚äïÔºÆ‚âîÔº•Ôº∏¬≤Ôº¨œÖ‚™´{}‚™´Œ¶œÖÔπ™√∑Œ∫Ôº∏¬≤ŒΩ¬≤,œÖ‚äüœÖ
```
[Try it online!](https://tio.run/##PY1BCsIwEEX3niJkNQNxU5ddCSIorfQKMY1tMJ2ENKkL8ewxAXEz8/j8eaNmGZSTNueHCwwupIJeNEU9FvYp3tJy1wEQkR3X1UwEvfQwuFcJG8E6TVOcISEKdnWGgL8//IdnY2NpJcF6NybrijCezGZGDU/B/gqqt00dXHCsO2G7G4KhWP746m5zPuT9Zr8 "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Extremely inefficient; do not try `n=4` unless you have a lot of patience (will time out on TIO). Explanation:
```
Ôº¶‚äïÔºÆ
```
Repeat `n+1` times...
```
‚âîÔº•Ôº∏¬≤Ôº¨œÖ‚™´{}‚™´Œ¶œÖÔπ™√∑Œ∫Ôº∏¬≤ŒΩ¬≤,œÖ
```
... replace the predefined empty list with its formatted powerset.
```
‚äüœÖ
```
Output the last element.
21 bytes using Python list formatting:
```
Ôº¶ÔºÆ‚âîÔº•Ôº∏¬≤Ôº¨œÖŒ¶œÖÔπ™√∑Œ∫Ôº∏¬≤ŒΩ¬≤œÖ‚≠Ü¬πœÖ
```
[Try it online!](https://tio.run/##PYzBCsIwEETvfsUedyEerMeeBBEEKwW/IG1jGoxJSXfr56fJxcsMPObNOOs0Ru1zfscEeA@L8FO@g0lIBJd1dTZgpxfs46@wRsHDBMszCpGCm/NcqCjo4iQ@Fp@vbnOTwY@CvxLqtqGaQu2hTy4wvriUrdeniqnN@ZyPm98B "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
Ôº¶ÔºÆ
```
Repeat `n` times...
```
‚âîÔº•Ôº∏¬≤Ôº¨œÖŒ¶œÖÔπ™√∑Œ∫Ôº∏¬≤ŒΩ¬≤œÖ
```
... replace the predefined empty list with its powerset.
```
‚≠Ü¬πœÖ
```
Pretty-print the list.
[Answer]
# [R](https://www.r-project.org), 205 bytes
```
\(n,z=paste0,b=\(x)z('{',x,'}'),p=\(x,e=el(strsplit(x,',')),l=lapply(e,\(i)c(i,NA)),g=do.call(expand.grid,l),d=\(v)z(na.omit(v),collapse=','),a=apply(g,1,d))d(b(a))){s='';for(i in seq_len(n)){s=p(s)};b(s)}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY9BasMwEEWv4kVBMzA1CXRRGmbRC_QEhiJbshFMZUVSgxOTk3TjFnqcHqC3qZy03cwwfz6P_9_e4_LR8-dr7m_vv78a8HTioFO2G2q5gQlPoGZFE6mzQgqrRJatQMoxBXG53IoUIgmLDkGOYKkBhx04enos-sBmrDstAnYK2pt6iM6QIJkCOxS-1_X4UkAHpG6UAkmWVyRpvgIH2pJBNNCCRsQ5sVK7fozgKuerZPfPYj34yydAwvOuXedvqZt_5-bhDucQnc9wqVgSVn2Jin_eZbnuHw)
A naive implementation of powerset for comma-delimited strings in R, using `seq_len` instead of `1:n` to handle the n = 0 case correctly.
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 34 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{‚éïjson{‚åø‚àò‚çµ¬®‚Üì‚åΩ‚çâ2‚ä•‚ç£¬Ø1‚ä¢¬Ø1+‚ç≥2*‚â¢‚çµ}‚ç£‚çµ‚ä¢‚ç¨}
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=q37UNzWrOD@v@lHP/kcdMx71bj204lHb5Ec9ex/1dho96lr6qHfxofWGj7oWAUntR72bjbQedS4CKqsFSgApoMSj3jW1AA&f=e9Q39VHbhDQFYwA&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
Marked as community wiki because the power set function has been taken from APLCart.
[Answer]
# BQN, 17 bytes
```
{(‚•ä(‚Üï2Àò)/¬®<)‚çüùï©‚ü®‚ü©}
```
[Try it here!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgeyjipYoo4oaVMsuYKS/CqDwp4o2f8J2VqeKfqOKfqX0KRiAz)
Powerset composed x times on empty set.
---
# BQN, 42 bytes
```
{{'‚ü®':'{';'‚ü©':'}';ùï©}¬®‚Ä¢Repr(‚•ä(‚Üï2Àò)/¬®<)‚çüùï©‚ü®‚ü©}
```
[Try it here!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAge3sn4p+oJzoneyc7J+KfqSc6J30nO/Cdlal9wqjigKJSZXByKOKliijihpUyy5gpL8KoPCnijZ/wnZWp4p+o4p+pfQpGIDM=)
Strictly formatted variant.
If `‚ü®‚ü©` count as valid brackets, then simply remove `{'‚ü®':'{';'‚ü©':'}';ùï©}¬®` for a 22-byte solution.
]