Thank you for sharing. The third one has some kind of trippy 3d effect in the first seconds
By ttoinou 20 hours ago
Gorgeous!
By kragen a day ago
Here's a possibly-too-highbrow explanation to complement the nice simple one in the OP.
"As everyone knows", you get a Sierpinski triangle by taking the entries in Pascal's triangle mod 2. That is, taking binomial coefficients mod 2.
Now, here's a cute theorem about binomial coefficients and prime numbers: for any prime p, the number of powers of p dividing (n choose r) equals the number of carries when you write r and n-r in base p and add them up.
For instance, (16 choose 8) is a multiple of 9 but not of 27. 8 in base 3 is 22; when you add 22+22 in base 3, you have carries out of the units and threes digits.
OK. So, now, suppose you look at (x+y choose x) mod 2. This will be 1 exactly when no 2s divide it; i.e., when no carries occur when adding x and y in binary; i.e., when x and y never have 1-bits in the same place; i.e., when x AND y (bitwise) is zero.
And that's exactly what OP found!
By gjm11 a day ago
This elegantly explains why (x & y) == 0 produces Sierpinski triangles: it's equivalent to checking whether (x+y choose x) mod 2 equals 1, directly connecting bitwise operations to binomial coefficients.
By ethan_smith 19 hours ago
i really love the result you quote about the carries. do you know where it has been applied by any chance?
By coderatlarge a day ago
I don't know of applications offhand, sorry. For me it's in the "appreciated for its own sake" category :-).
By gjm11 17 hours ago
i can see that for sure. do you have a reference by any chance? chatgpt hallucinates various references given the result. knuth’s “concrete mathematics” might have it.
(That page has a link to another beautiful theorem with a similar feel, Lucas's theorem: if p is prime, then (n choose r) mod p is the product of the (n_i choose r_i) where n_i and r_i are corresponding digits of n and r when written in base p.)
By gjm11 13 hours ago
I checked: the result is in Concrete Mathematics, as exercise 5.36, but there is no attribution to Kummer there.
Incidentally, I found the name of the theorem (and the Wikipedia page about it) using a new kind of tool called a "search engine". It's a bit like asking ChatGPT except that it hardly ever hallucinates. You should try it! :-)
By gjm11 11 hours ago
Just a heads up, all (binary?) logical operators produce fractals. This is pretty well-known[1].
That's more or less, because binary numbers are already fractal.
By eru 2 hours ago
It would be interesting to see how this generalizes to other bases.
Base 3 has nearly 20,000 operators, of which 729 are commutative.
By marginalia_nu 21 hours ago
Yeah, I'm pretty sure as long as you have symmetry somewhere (e.g. a commutative operation), you'll get self-similar patterns.
By dvt 14 hours ago
The change rate in binary notation is fractal.
By wang_li a day ago
Ask yourself why you added the “pretty well-known” phrase, and consider xkcd 1053.
By Timwi a day ago
Try this one liner pasted into a Unix shell:
cc -w -xc -std=c89 -<<<'main(c){int r;for(r=32;r;)printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}'&&./a.*
It used to be cooler back when compilers supported weird K&R style C by default. I got it under 100 characters back then, and the C part was just 73 characters. This version is a bit longer but works with modern clang. The 73-character K&R C version that you can still compile today with GCC is:
Hey, at least it's not doing `curl | bash` like some people's installers do. It's only 109 characters, you can review that right? :-P
By modeless a day ago
For all I know, the whole thing might just be a very convoluted call to curl?
By eru 2 hours ago
I can't dismiss the cookie popup on this page. After rejecting or accepting cookies it reloads and reappears.
Apologies for a comment not related to the content, but it makes it difficult to read the article on mobile.
By jcul 2 days ago
Substack is kind of a weird site, but this newsletter in particular is worth subscribing to and getting in your email.
By jrockway 18 hours ago
This might be a Firefox problem.
I have never seen it before, but today I have seen it in 3 or 4 sites linked from HN.
What has worked for me is to click "Accept all", then, after the pop-up reappears, click "Only necessary", which makes the pop-up disappear.
Clicking "Only necessary" without clicking before that "Accept all" has not worked. Likewise, clicking multiple times one of those options has not worked.
By adrian_b a day ago
Really interesting, and surprising article though!
By jcul 2 days ago
Same. Safari on iPhone.
By Jolter a day ago
Same problem here. Firefox on Android.
By IceDane a day ago
Very cool! This basically encodes a quad-tree of bits where every except one quadrant of each subquadrant recurses on the parent quad-tree.
The corresponding equivalent of functional programming would be Church bits in a functional quad-tree encoding \s.(s TL TR BL BR). Then, the Sierpinski triangle can be written as (Y \fs.(s f f f #f)), where #f is the Church bit \tf.f!
The 31-byte demo "Klappquadrat" by T$ is based on this phenomenon; I wrote a page about how it works a few years ago, including a working Python2 reimplementation with Numpy: http://canonical.org/~kragen/demo/klappquadrat.html
I should probably update that page to explain how to use objdump correctly to disassemble MS-DOG .COM files.
If you like making fractal patterns with bitwise arithmetic, you'll probably love http://canonical.org/~kragen/sw/dev3/trama. Especially if you like stack machines too. The page is entirely in Spanish (except for an epilepsy safety warning) but I suspect that's unlikely to be a problem in practice.
By kragen a day ago
Sierpinski triangles are definitely a common sight in demoscene productions, to the point that they're acceptable in the smaller sizes, but others will think you're not good enough if that's all you do for a 64k or above entry.
By userbinator a day ago
I reached a similar result when researching all possible "binary subpixel" configurations that would give a pixel its fuzzy value. Arranging the configurations in ascending order row-wise for one pixel and column-wise for the other, performing an intersection between the two pixels, and plotting against their resulting fuzzy value results in a sierpinski triangle.
Cool stuff. Especially the bottom right panel, you might not have expected that kind of symmetry in the intersection when looking at the individual components.
By tpoacher 18 hours ago
Ah. Is that why LFSRs (linear feedback shift registers) and specifically PRBS generators (pseudo-random binary sequences) produce Sierpinski triangles as well?
PRBS sequences are well-known, well-used "pseudo-random" sequences that are, for example, used to (non-cryptographically!) scramble data links, or to just test them (Bit Error Rate).
I made my own PRBS generator, and was surprised that visualizing its output, it was full of Sierpinski triangles of various sizes.
Even fully knowing and honoring that they have no cryptographic properties, it didn't feel very "pseudo-random" to me.
By anyfoo a day ago
There are so many ways to produce sierpinski gaskets.
It you specify n points and the pick a new point at random, then iteratively randomly select (uniformly) one of the original n points and move the next point to the mid point of the current point and the selected point. Coloring those points generates a sierpinski triangle or tetrahedron or whatever the n-1 dimensional triangle is called
By pacaro a day ago
That's called a simplex :)
The same as in the simplex algorithm to solve linear programming problems.
By linschn a day ago
I programmed this on my TI-83 back in the day and spent many hours watching it generate triangles during boring classes.
You can generate many other fractals (e.g. fern shapes) in a similar way, though the transformations are more complicated than “move halfway to selected point”.
By CrazyStat 21 hours ago
yes, those are called iterated function systems (IFS) fractals
By deadfoxygrandpa 8 hours ago
> the magic is the positional numeral system
— of course. In the same way the (standard) Cantor set consists of precisely those numbers from the interval [0,1] that can be represented using only 0 and 2 in their ternary expansion (repeated 2 is allowed, as in 1 = 0.2222...). If self-similar fractals can be conveniently represented in positional number systems, it is because the latter are self-similar.
By fiforpg a day ago
I draw these with paper and pen when I am extremely bored in meetings.
I tend to like lcamtuf's Electronics entries a bit better (I'm an EE after all) but I find he has a great way of explaining things.
By ChuckMcM a day ago
been down the bitwise fractal rabbit hole more times than i can count and honestly, i never get tired of these patterns - you think people start seeing shapes like this everywhere after a while or is that just me
But this is not using bitwise AND, just the Pascal's triangle approach. (Interestingly, you can reformulate that as a neighborhood-2 2-state 1-dimensional cellular automaton pretty easily; it occurs in a couple of different guises in Wolfram's catalog.)
Here's an ASCII-art version that uses AND as Michał describes:
32 value size : line cr size 0 do dup i and if bl else [char] # then dup emit emit loop drop ;
: pasand size 0 do i line loop ;
Nothing much to do with your great post, but I almost REALLY liked that first pyramid, but the last line being off threw me visually, so I had to straighten it out:
That looks nicer than my version. But you should put the `cr` before the inner loop, not after it. That way you can remove the `cr` before the outer loop.
By kragen a day ago
Wolfram did a lot of research into cellular automata, and the Sierpinski Triangle kept showing up there too:
By susam a day ago
By Recursing 17 hours ago
By msarnoff a day ago
By ttoinou 20 hours ago
By kragen a day ago
By gjm11 a day ago
By ethan_smith 19 hours ago
By coderatlarge a day ago
By gjm11 17 hours ago
By coderatlarge 14 hours ago
By gjm11 13 hours ago
By gjm11 11 hours ago
By dvt 2 days ago
By eru 2 hours ago
By marginalia_nu 21 hours ago
By dvt 14 hours ago
By wang_li a day ago
By Timwi a day ago
By modeless a day ago
By Terr_ a day ago
By modeless a day ago
By eru 2 hours ago
By jcul 2 days ago
By jrockway 18 hours ago
By adrian_b a day ago
By jcul 2 days ago
By Jolter a day ago
By IceDane a day ago
By marvinborner a day ago
By kragen a day ago
By userbinator a day ago
By tpoacher 18 hours ago
By anyfoo a day ago
By pacaro a day ago
By linschn a day ago
By CrazyStat 21 hours ago
By deadfoxygrandpa 8 hours ago
By fiforpg a day ago
By zabzonk a day ago
By msephton a day ago
By zX41ZdbW 2 days ago
By tikili a day ago
By ChuckMcM a day ago
By gitroom a day ago
By lenerdenator a day ago
By tomrod a day ago
By MaxGripe a day ago
By jesuslop 2 days ago
By anthk 2 days ago
By kragen a day ago
By animal531 20 hours ago
By anthk a day ago
By kragen a day ago
By peterburkimsher 2 days ago
By GuB-42 a day ago
By immibis a day ago