Full Width [alt+shift+f] Shortcuts [alt+shift+k]
Sign Up [alt+shift+s] Log In [alt+shift+l]

New here?

Welcome! BoredReading is a fresh way to read high quality articles (updated every hour). Our goal is to curate (with your help) Michelin star quality articles (stuff that's really worth reading). We currently have articles in 0 categories from architecture, history, design, technology, and more. Grab a cup of freshly brewed coffee and start reading. This is the best way to increase your attention span, grow as a person, and get a better understanding of the world (or atleast that's why we built it).

18
About a year ago, I had some time to spare over the summer and decided to challenge myself with a project that I call “Clocksquared Mini”. It is Clocksquared, but in a tiny wristwatch package. This gives rise to a major challenge, as everything has to be shrunk down approximately ten times from a 300x300x50… Continue reading ClockSquared Mini, a word clock wristwatch
over a year ago

Improve your reading experience

Logged in users get linked directly to articles resulting in a better reading experience. Please login for free, it takes less than 1 minute.

More from Willem Pennings

Fixing my heating system

The heating system in my apartment building consists of a group of heat pumps that deliver warm water to the underfloor heating system of about a dozen apartments, including mine. During the warm summer months, the system supplies cool water instead. The heat pumps figure out whether to supply warm or cool water, and a… Continue reading Fixing my heating system

11 months ago 52 votes
Balancing cube

This cube manages to balance itself on a corner, and can simultaneously rotate around its axis in a controlled manner. It does so using clever controls and a set of three reaction wheels. The original idea for this device comes from researchers at ETH Zürich, who demonstrate their “Cubli” in this video. Its design has… Continue reading Balancing cube

a year ago 33 votes
ClockSquared improvements

My ClockSquared project has a long history – it goes all the way back to 2015, when it was simply called the “Birthday word clock”. I haven’t spent much time on the project in recent years, but I’ve upgraded the internals a while ago and finally felt like writing a post about it. Two things… Continue reading ClockSquared improvements

over a year ago 25 votes
Home Assistant-compatible air quality sensor

I recently moved and our new home is equipped with a ventilation system that distributes fresh (outside) air through the house and recoups heat from the air that is exhausted. There is a problem with this system, though. Sometimes, for example when a neighbour lights their wood stove, the system pulls in smoke, even though… Continue reading Home Assistant-compatible air quality sensor

over a year ago 20 votes

More in science

To Conquer the Primary Energy Consumption Layer of Our Entire Civilization

[Originally posted on the Terraform blog April 3, 2025.] Three years ago we set out to make cheap synthetic natural gas from sunlight and air. At the time I didn’t fully appreciate that we had kicked off the process of recompiling the foundation layer of our entire industrial stack.  Last year, we made cheap pipeline grade natural gas from sunlight and air and expanded our hydrocarbon fuel road map to include methanol, a versatile liquid fuel and chemical precursor for practically every other kind of oil-derived chemical on the market. Unlimited synthetic methane and methanol underpinning global energy supply is a good start, but …

12 hours ago 2 votes
De-extincting the Dire Wolf

This really is just a coincidence – I posted yesterday about using AI and modern genetic engineering technology, with one application being the de-extinction of species. I had not seen the news from yesterday about a company that just announced it has cloned three dire wolves from ancient DNA. This is all over the news, […] The post De-extincting the Dire Wolf first appeared on NeuroLogica Blog.

4 hours ago 1 votes
Analytic Combinatorics -- A Worked Example

Another day, another blog post that starts with “I was on mse the other day…”. This time, someone asked an interesting question amounting to “how many unordered rooted ternary trees with $n$ nodes are there, up to isomorphism?”. I’m a sucker for these kinds of combinatorial problems, and after finding a generating function solution I wanted to push myself to get an asymptotic approximation using Flajolet–Sedgewick style analytic combinatorics! I’ve never actually done this before, so I learned a lot, and I want to share some of the things I learned – especially how to do this stuff in sage! Now, you might be thinking – didn’t you write a very similar blog post three years ago? Yes. Yes I did. Did I also completely forget what was in that post? Yes. Yes I did, haha. For some reason I was getting it mixed up with this other post from even more years ago, which isn’t nearly as relevant. Thankfully it didn’t matter much, since I’m fairly sure what I wanted to do wouldn’t work in the framework of that post anyways, and now I have a better idea of what this machinery is actually doing which is really exciting (since I’ve been wanting to understand this stuff for years). Let’s start with a warmup problem! How might we count the number of rooted ordered ternary trees with $n$ nodes? These are the kinds of “ternary trees” that you might remember from a first class on algorithms and data structures. Such a tree is either a leaf or an internal node with 1,2, or 3 children. Crucially these children come with an order, because the datatype keeps track of which child is on the left/right (in the case of 2 children) or on the left/middle/right (in the case of 3 children). After all, from a CS perspective, we need to remember this in order to traverse the tree! This means that the following two trees are distinct for our purposes, even though they’re isomorphic as graphs: In a functional programming language, you might describe this datatype by T z = Leaf z | Unary z (T z) | Binary z (T z) (T z) | Ternary z (T z) (T z) (T z) and this translates immediately to give a functional equation for the generating function of $t_n$, which counts the number of rooted ordered ternary trees with $n$ nodes: We can rearrange this as so that we can compute the power series expansion of $T$ by lagrange inversion: = QQbar[[]] # power series ring T = (z/(1 + z + z^2 + z^3)).reverse() show(T.O(10)) Incredibly, this agrees with A036765, which is the “number of ordered rooted trees with n non-root nodes and all outdegrees <= three”, as we hoped! You might reasonably ask if there’s a closed form for these numbers, and this is too much to ask for (indeed, it’s already too much to ask for a closed form for fibonacci numbers, and this is more complicated). But like the fibonacci numbers, we can come up with an excellent approximation: where $C = \frac{(0.8936\ldots)}{2 \sqrt{\pi}}$ is a constant. Indeed, this gives fantastic results! Let’s plot the ratio of this approximation to the true value so we can see just how good this approximation gets as $n$ gets large. Note that it respects the promised big-oh error bound too! = PowerSeriesRing(QQbar, default_prec=N) T = (z/(1 + z + z^2 + z^3)).reverse() return T.coefficients()[n-1:] def approx(n,N): # very very magic C = 0.8936373911078061 / (2 * sqrt(pi)) w = 3.610718613276040 return [(C * w^k * (1/k^1.5)).n() for k in range(n,N+1)] show(html("Plot the error ratios in the range [n,N]")) @interact def _(n=input_box(100, width=20, label="$n$"), N=input_box(120, width=20, label="$N$"), auto_update=False): actuals = actual(n,N) approxs = approx(n,N) ratios = [(actuals[i]/approxs[i]) for i in range(N+1-n)] show(html("ratio at n={}: {}".format(n, ratios[0]))) show(html("ratio at N={}: {}".format(N, ratios[-1]))) text_options = {'horizontal_alignment': 'right', 'vertical_alignment': 'bottom', 'fontsize': 'large'} G = Graphics() G += scatter_plot([(n+i,r) for (i,r) in enumerate(ratios)]) G += plot(1, (x,n,N)) G += plot(1-1/x, (x,n,N)) G += text('$y = 1$', (N, 1), **text_options) G += text('$y = 1-1/x$', (N, 1-1/N), **text_options) G.show() This is extremely cool, but where the hell did this approximation come from? The answer is called Singularity Analysis, and can be found in Chapter 2 Section 3 of Melczer’s excellent An Invitation to Analytic Combinatorics, or Chapters VI and VII of Flajolet and Sedgewick’s tome. See especially Theorem VII.3 on pg 468. Like seemingly every theorem in complex analysis, this is basically an application of the Residue Theorem. I won’t say too much about why it works, but I’ll at least gesture at a proof. You can read the above references if you want something more precise. First, we recall where $C$ is any contour containing the origin inside a region where $T$ is holomorphic. Then we draw the most important picture in complex analysis: Here the obvious marked point is our singularity $\omega$, and we’ve chosen a branch cut for $T$ (shown in blue1) so that $T$ is holomorphic in the region where the pink curve lives. We’ll estimate the value of this integral by estimating the contribution from the big circle, the little circle, and the two horizontal pieces2. It turns out that the two horizontal pieces basically contribute $O(1)$ amount to our integral, so we ignore them. Since the big circle is compact, $T$ will attain a maximal value on it, say $M$. Then the integral along the big circle (of radius $\omega + \epsilon$, say) is bounded by $2 \pi (\omega + \epsilon) \frac{M}{(\omega + \epsilon)^{n+1}} = O((\omega+\epsilon)^{-n})$ To estimate the integral around the little circle, it would be really helpful to have a series expansion at $\omega$ since we’re staying really close to it… Unfortunately, $\omega$ is a singular point so we don’t have a taylor series, but fortunately there’s another tool for exactly this job: a Puiseux Series! I won’t say much about what these are, especially since Richard Borcherds already put out such a great video on the topic. What matters is is that Sage can compute them for us3, so we can actually get our hands on the approximation! We compute the integral around the little circle to be roughly: In step $(1)$ we approximate $T$ by the first term of its puiseux series, in step $(2)$ we apply the generalized binomial theorem, so that in step $(3)$ we can apply the residue theorem to realize this integral as the coefficient of $z^{-1}$ in our laurent expansion. This gives us something which grows like $\widetilde{O}(\omega^{-n})$, dominating the contribution $O((\omega + \epsilon)^{-n})$ from the big circle, so that asymptotically this is the only term that matters. If we were more careful to keep track of the big-oh error for the puiseux series for $T$ we could easily sharpen this bound4 to see This looks a bit weird with the $(-1)^n$, but remember that $\binom{\alpha}{n}$ also alternates sign. Indeed, asymptotics for $\binom{\alpha}{n}$ are well known so that we can rewrite this as Which finally shows us where our magic numbers came from! Sage happily tells us that the dominant singularity for $T$ is at $\omega = (0.2769\ldots)$ and that a puiseux expansion for $T$ at $\omega$ is so that for us $\alpha = 1/2$, and $C_{1/2} = -(0.8936\ldots)$. Finally, since $\Gamma(-1/2) = -2 \sqrt{\pi}$ and $(0.2769\ldots)^{-1} = (3.6107\ldots)$ we see as promised! Indeed, here’s how you could actually get sage to do all this for you! = QQbar[] S. = R[] # our defining polynomial. # we want to solve for T as a function of z P = z*T^3 + z*T^2 + (z-1)*T + z # following Example 2.12 in Melczer, # we compute the dominant singularity w. w = min([r for (r,_) in P.discriminant().roots() if r != 0], key=lambda r: r.abs()) # to work with abelfunctions we need P # to be a polynomial in two variables R. = QQbar[] P = R(P) # compute the puiseux expansion for T at w. # I know from trial and error that the correct # branch to pick is entry [1] in the list. You # just need to check which one gives you # positive real coefficients for T at 0. s = abelfunctions.puiseux(P,w)[1] c = -sqrt(-s.x0/s.xcoefficient) As a fun exercise, you might modify this code (using s.add_term()) to compute a longer puiseux series and get asymptotics valid up to a multiplicative error of $O \left ( \frac{1}{n^2} \right )$ for the number of rooted ternary trees. Try modifying the previous code block to see that our current approximation is not accurate to $O \left ( \frac{1}{n^2} \right )$, and then check that your approximation is! Ok, now that we understand the warmup, let’s get to the actual problem! How many unordered rooted ternary trees are there, up to isomorphism? Now we’re counting up to graph isomorphism, so that our two trees are now considered isomorphic. It’s actually much less obvious how one might pin down a generating function for something like this, but the answer, serendipitously, comes from Pólya-Redfield counting! If this is new to you, you might be interested in my recent blog post where I talk a bit about one of its corollaries. Today, though, we’ll be using it in a much more sophisticated way. Say you have a structure $X$ acted on by a group $G$ and a collection $C$ of “colors”. How can we count the number of ways to give each $x \in X$ a color from $C$, up to the action of $G$? We start by building the cycle index polynomial of the action $G \curvearrowright X$, which we call $P_G(x_1, \ldots, x_n)$. Then we can plug all sorts of things into the variables $x_i$ in order to solve various counting problems. For example, if $C$ is literally just a finite set of colors, we can plug in $x_1 = x_2 = \ldots = x_n = |C|$ to recover the expression from my recent blog post. But we can also do much more! Say that $C$ is a possibly infinite family of allowable “colors”, each of a fixed “weight”. (For us, our “colors” will be trees, and the “weight” will be the number of nodes). Then we can arrange them into a generating function $F(t) = \sum c_i t^i$, where $c_i$ counts the number of colors of weight $i$5. Then an easy argument (given in full on the wikipedia page) shows that $P_G(F(t), F(t^2), \ldots, F(t^n))$ is a generating function counting the number of ways to color $X$ by colors from $C$, counted up to the $G$ action, and sorted by their total weight6. Check out the wikipedia page for a bunch of great examples! For us, we realize an unordered rooted ternary tree is either empty, or a root with 3 recursive children7. In the recursive case we also want to count up to the obvious $\mathfrak{S}_3$ action permuting the children, so by the previous discussion we learn that where \(P_{\mathfrak{S}_3}(x_1, x_2, x_3) = \frac{1}{6}(x_1^3 + 3x_1 x_2 + 2 x_3)\) is the cycle index polynomial for the symmetric group on three letters. Plugging this in we see Now, how might we get asymptotics for $t_n$ using this functional equation? First let’s think about how our solution to the warmup worked. We wrote $F(z,T)=0$ for a polynomial $F$, used the implicit function theorem to get a taylor series for $T$ at the origin, then got a puiseux series near the dominant singularity $\omega$ which let us accurately estimate the taylor coefficients $t_n$8. We’re going to play the same game here, except we’ll assume that $F$ is merely holomorphic rather than a polynomial. Because we’re no longer working with a polynomial, this really seems to require an infinite amount of data, so I’m not sure how one might get an exact solution for the relevant constants… But following Section VII.5 in Flajolet and Sedgewick we can get as precise a numerical solution as we like! We’ll assume that the functions $T(z^2)$ and $T(z^3)$ are already known analytic functions, so that we can write $F(z,w) = -w + 1 + \frac{z}{6} \left ( w^3 + 3 T(z^2) w + 2 T(z^3) \right )$. This is an analytic function satisfying $F(z,T) = 0$. Now for a touch of magic. Say we can find a pair $(r,s)$ with both $F(r,s)=0$ and $\left . \frac{\partial F}{\partial w} \right |_{(r,s)} = 0$… Then $F$ is singular in the $w$ direction at $(r,s)$ so this is a branch point for $T$. Since both $F$ and $F_w = \frac{\partial F}{\partial w}$ vanish at $(r,s)$ the taylor series for $F$ at $(r,s)$ starts Since we know $F(z,T)$ vanishes, we estimate up to smaller order terms so that a puiseux series for $T$ at $(r,s)$ begins If we write $\gamma = \sqrt{\frac{2r F_z(r,s)}{F_{ww}(r,s)}}$ and are slightly more careful with our error terms, the same technique from the warmup shows See Flajolet and Sedgewick Theorem VII.3 on page 468 for a more careful proof of this theorem. Now how do we use this? We can approximate $T$ by its taylor series at the origin, then numerically solve for the unique9 positive real solution to the system $F(r,s) = F_w(r,s) = 0$ using this approximation: = B[[]] # cycle index polynnomials S. = QQ[] P3 = (x1^3 + 3*x1*x2 + 2*x3)/6 # to start, the taylor coefficients of T are variables T = sum([t[i] * z^i for i in range(n)]) + O(z^n) lhs = T rhs = 1 + z*P3.subs(x1=T(z), x2=T(z^2), x3=T(z^3)) # formally expand out the rhs and set the coefficients # equal to each other. This gives a recurrence relation # for t[n] in terms of the t[i] for i If we run this code locally with $N=20$, we get the approximation so that we expect and indeed this seems to work really well! Our taylor expansion for $T$ agrees with A000598, as we expected, and comparing our approximation to our taylor expansion gives: = B[[]] S. = QQ[] P3 = (x1^3 + 3*x1*x2 + 2*x3)/6 T = sum([t[i] * z^i for i in range(N)]) + O(z^N) lhs = T rhs = 1 + z*P3.subs(x1=T(z), x2=T(z^2), x3=T(z^3)) I = B.ideal([lhs.coefficients()[i] - rhs.coefficients()[i] for i in range(N)]) return [I.reduce(t[i]) for i in range(n,N)] show(html("Plot the error ratios in the range [n,N]")) show(html("This is likely to time out if you make N too large online,")) show(html("so you might want to play around with it locally instead!")) @interact def _(n=input_box(10, width=20, label="$n$"), N=input_box(30, width=20, label="$N$"), auto_update=False): actuals = actualList(n,N) approxs = approxList(n,N) ratios = [actuals[i]/approxs[i] for i in range(N-n)] show(html("ratio at n={}: {}".format(n, ratios[0].n()))) show(html("ratio at N={}: {}".format(N, ratios[-1].n()))) text_options = {'horizontal_alignment': 'right', 'vertical_alignment': 'bottom', 'fontsize': 'large'} G = Graphics() G += scatter_plot([(n+i,r) for (i,r) in enumerate(ratios)]) G += plot(1, (x,n,N)) G += plot(1-1/x, (x,n,N)) G += text('$y = 1$', (N, 1), **text_options) G += text('$y = 1-1/x$', (N, 1-1/N), **text_options) G.show() I’m pretty proud of this approximation, so I think this is a good place to stop ^_^. As a fun exercise, can you write a program that outputs the number of cyclic rooted ternary trees on $n$ vertices? For these we consider two trees the same if they’re related by cyclicly permuting their children. Compare your solution to A000625 For bonus points, can you check that the number of such trees is, asymptotically, Wow! It’s been super nice to be writing up so many posts lately! Like I said in one of my other recent posts, I’ve had a lot of time to think about more bite sized problems and mse stuff while waiting for my DOI generating code to run, so I’ve had more things that felt quick to write up on my mind. My research is actually going quite well too! I have a few interesting directions to explore, and at least one project that might be wrapping up soon. Of course when that happens I’ll be sure to talk about it here, and I’m still planning out a series on fukaya categories, hall algebras, skein algebras, and more! That’s a pretty long one, though, so it’s easy for me to deprioritize, haha. It’s already heating up in Riverside, consistently in the 80s (Fahrenheit), so I can really feel the summer coming. I’m enjoying the sunny days, though, and it’s been nice to spend time working outside and under trees. Thanks for hanging out, all! Take care of each other, and I can’t wait to chat soon ^_^. Just like $w = \sqrt{z}$, a solution to $w^2 = z$ has branches, so too does $T$, a solution to $T = z + zT + zT^2 + zT^3$. ↩ Really these are circles with a little arc cut out, say by integrating from $\epsilon$ to $2 \pi - \epsilon$… But we’ll end up taking $\epsilon \to 0$ and we’re all friends here, so let’s not worry about it. ↩ Though at time of writing you need the abelfunctions package to do it. There is a builtin implementation of puiseux series, but it won’t actually compute a series expansion for you. ↩ Of course, it’s easy to see how to extend this technique to get better asypmtotics. The first approach is to just keep more terms of the puiseux series of $T$ at $\omega$. Then apply the generalized binomial formula multiple times for each term you kept. You can also do better by keeping track of more of the singularities. Build a contour with multiple keyholes in order to get sharper lower order asymptotics: Of course, you can also combine these approaches to keep track of both more singularities and more puiseux coefficients at each singularity. ↩ In fact we can push things even farther and work with multivariate generating functions, but we won’t need that here. ↩ This is why we plug $F(t^k)$ into $x_k$. Because $x_k$ is responsible for $k$-cycles, so we choose a single color for each $k$ cycle, but we have to count it $k$-many times towards our total weight. See the proof on the wikipedia page for more information! ↩ This actually isn’t the version of the recurrence I used in my mse answer. There I used the convention that a rooted tree had to be nonempty, since… you know… it has a root. But allowing possibly empty trees makes the recurrence much simpler, which in turn allows for much easier to analyze asymptotics. Hilariously this exact example is on the wikipedia page for the Pólya-Redfield theorem, which could have saved me a lot of time writing up that answer. I was a bit worried at first about doing these asymptotics by myself, since this was my first serious attempt at using analytic combinatorics, but serendipitously this exact example was also worked out in Flajolet and Sedgewick VII.5, though slightly more tersely than I would have liked, haha. ↩ Officially we have to check that the choice of puiseux series matches up with our choice of taylor series (since there’s multiple branches to our function). But this is easy to arrange for us by choosing the branch of the puisuex series that leads to all our coefficients being positive reals. If you want to do this purely analytically you need to solve a “connection problem”. See figure VII.9 in Flajolet and Sedgewick, as well as the surrounding text. ↩ Under mild technical conditions this pair $(r,s)$ is unique. See Flajolet and Sedgewick Theorem VII.3. ↩

16 hours ago 1 votes
12 Interesting Updates on AI, Immortality, Robotaxis, and More

From the last 6 months | Q4 2024 and Q1 2025

4 hours ago 1 votes
Intelligence Evolved at Least Twice in Vertebrate Animals

Complex neural pathways likely arose independently in birds and mammals, suggesting that vertebrates evolved intelligence multiple times. The post Intelligence Evolved at Least Twice in Vertebrate Animals first appeared on Quanta Magazine

yesterday 2 votes