<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Krishna</title>
 <link href="https://mathismusic.github.io/website2026/atom.xml" rel="self"/>
 <link href="https://mathismusic.github.io/website2026/"/>
 <updated>2026-08-13T10:01:41+00:00</updated>
 <id>https://mathismusic.github.io</id>
 <author>
   <name>Krishna N Agaram</name>
   <email>krishna.agaram1729@gmail.com</email>
 </author>

 
 <entry>
   <title>The theory of deep learning: how</title>
   <link href="https://mathismusic.github.io/2026/08/13/deep-learning-theory-how/"/>
   <updated>2026-08-13T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2026/08/13/deep-learning-theory-how</id>
   <content type="html">&lt;p&gt;&lt;em&gt;This is part two. &lt;a href=&quot;/2026/08/12/deep-learning-theory-why/&quot;&gt;Part one&lt;/a&gt; argued that deep learning needs a mathematical theory.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We shall now explore some of the most interesting and promising directions in learning mechanics today. It’s fun, I promise.&lt;/p&gt;

&lt;h2 id=&quot;linearization&quot;&gt;Linearization&lt;/h2&gt;

&lt;p&gt;Like with any field of mechanics, a reliable way to build scientific understanding is to study simpler representative systems that are amenable to analysis, which then serve as sources of intuition for much broader classes of systems.&lt;/p&gt;

&lt;p&gt;The simplest way to make a neural net \(f\) simple is to omit the nonlinear functions altogether; \(f(x)\) reduces to the form complicated-matrix-of-parameters (call it \(W\)) times \(x\). One can prove that gradient descent on the parameters to train the network to map each \(x_i\) to \(y_i\) yields a very interesting property: the network exhibits what is called a greedy low-rank bias, which is a fancy way of saying “start with the simplest parameter choices, and then add complexity as needed”. A bit of mathematical formalism to make this precise: Suppose for each \(i\)&lt;/p&gt;

\[y_i = \begin{bmatrix} 5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} x_i.\]

&lt;p&gt;Then look at what happens when we train a linear network \(f(x) = W x\) to minimize the loss \(\sum_i \|f(x_i) - y_i\|^2\). The network notices that learning the coefficient \(5\) is top priority, since matching that reduces the loss more than matching the coefficients \(3\) or \(1\) will; the training progress looks like this:&lt;/p&gt;

\[W_1 \approx \begin{bmatrix} 5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} \rightarrow W_2 \approx \begin{bmatrix} 5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix} \rightarrow W_3 \approx \begin{bmatrix} 5 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 3 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}.\]

&lt;p&gt;In general, the network will learn the best matrix’s singular value decomposition in order of decreasing singular values. This intuition, though we have not yet proved it, carries over to the nonlinear case; simpler (nonlinear) functions are learned first in a way that minimizes the loss as quickly as possible, followed by more complex functions to finetune the model. Why might neural networks have this behavior? The key is that gradient descent is a greedy algorithm itself! The direction of steepest immediate descent is the negative of the gradient, and so the network greedily reduces the loss maximally at each step.&lt;/p&gt;

&lt;h2 id=&quot;infinitely-large-networks&quot;&gt;Infinitely large networks&lt;/h2&gt;

&lt;p&gt;Back to physics for a sec. Constructing a microscopic theory tracking individual particles in a physical system, say a gas, is hopelessly complicated. However, it has often proven to be extremely fruitful to take the limit of infinitely many particles, which allows one to track the system as a single distribution over the particles.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/website2026/public/images/infinite_v2.png&quot; alt=&quot;Taking the number of particles to infinity turns a histogram of individual particle speeds into a single smooth speed distribution.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A concrete example of this is the Maxwell-Boltzmann distribution to describe the distribution of particle velocities in a gas, and it is very accurate even for finite-particle gases. Same goes for the ideal gas law \(PV = nRT\).&lt;/p&gt;

&lt;p&gt;Is the same true of deep learning? Does taking the limit of an infinite number of neurons in a layer, or an infinite number of layers, or an infinite amount of data, et cetera simplify analytical calculation? One moves again into the distribution world, where an infinite layer is replaced by a single distribution modeling neuron activation. The answer is, of course, yes, since this section exists. Lots of very good progress here.&lt;/p&gt;

&lt;p&gt;Let’s briefly look at the most well-studied limit: the infinite width limit, where there are a finite number of infinitely wide layers. In this limit, one of two interesting things always happens: depending on the initialization (as a distribution) of the weights of the last layer of the network, the network is either &lt;em&gt;lazy&lt;/em&gt; and learns very little — its weights hardly shift at all from their initial values — or is &lt;em&gt;rich&lt;/em&gt; and its weights shift by a very substantial amount throughout training, making it learn well from data.&lt;/p&gt;

&lt;p&gt;Perhaps a useful analogy is the stress-strain curve of a material: if the strain is very small, the material does not deform much from its original shape; however, once the strain is large enough, the material deforms substantially and learns a new shape. Indeed, the last layer’s initialization in the lazy case is such that the output is already the right order needed to simply fit training data without changing weights much. In the rich case, the last layer’s initialization is uniformly zero, forcing it to change substantially if the output is to be nonzero and close to the training labels.&lt;/p&gt;

&lt;p&gt;The rich regime is the one we must seek to operate in. Yang and Hu (2021) set up the &lt;em&gt;Tensor Programs&lt;/em&gt; framework to reliably construct hyperparameter and learning rate choices that land us in the rich regime for infinite-width networks. It is then empirically observed that the same choices work well for large finite-width networks too! This parameterization, called the &lt;em&gt;maximal update parameterization&lt;/em&gt; or \(\mu\)P, is starting to see adoption in practice. Limits can be useful even for finite systems!&lt;/p&gt;

&lt;h2 id=&quot;empirical-laws&quot;&gt;Empirical laws&lt;/h2&gt;

&lt;p&gt;For hundreds of years, we have described gases and chemical reactions by simple relationships between macroscopic measures: pressure, volume, temperature, concentration. These laws came from careful experiment, after the fact. They continue to be extremely predictive, and they are the basis of most of us non-chemist folks’ understanding of chemistry. Since pretty much everything about the training process is super easy to measure experimentally, such empirical laws are natural to look out for in deep learning too. Indeed, a family of such laws called &lt;em&gt;scaling laws&lt;/em&gt; exists today and turns out to be very predictive of the behavior of large networks. What are these laws, though?&lt;/p&gt;

&lt;p&gt;Let’s fix a model architecture and a dataset, and denote test loss at convergence by \(L\), number of parameters by \(N\), compute in floating-point operation (FLOP) count by \(C\) and number of training tokens by \(D\). The latter three variables are related approximately as \(C = 6ND\): a forward and backward pass through a typical transformer model costs about \(6\) FLOPs per parameter per token. Then it turns out \(\log L\) is linear in \(\log N\), \(\log C\) and \(\log D\) (i.e. a power-law dependence) when the other two are not bottlenecking. Such laws are very similar to the thermodynamic laws of adiabatic expansion and compression, where the exponents of the power law are dependent on the structure of the gas and were theoretically understood and estimated well after they were measured.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/website2026/public/images/chincilla.png&quot; alt=&quot;The loss surface over parameters and tokens, with the Chinchilla-optimal point marked along the fixed-compute curve 6ND = C.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s quickly see an example of how scaling laws help in practice. This is called &lt;em&gt;Chinchilla&lt;/em&gt; optimality in the literature. Consider a fixed training compute budget \(C\). We must tune \(N\) and \(D\) to minimize the loss, respecting \(C = 6ND\), to obtain the best model possible. So we set up a joint scaling law for \(L\) as a function of both \(N\) and \(D\):&lt;/p&gt;

\[L(N, D) = E + \frac{A}{N^{\alpha}} + \frac{B}{D^{\beta}}.\]

&lt;p&gt;One can think of \(E\) as the irreducible loss, \(A/N^{\alpha}\) as the penalty for a finite-sized model and \(B/D^{\beta}\) as the penalty for a finite dataset. Fitting parameters to many different much-smaller-scale experiments yields rough values of \(E, A, B, \alpha\) and \(\beta\) for a given architecture and dataset. One finishes by optimizing \(L(N, D)\) subject to the constraint \(C = 6ND\) to find the “&lt;em&gt;Chinchilla&lt;/em&gt;-optimal” model size \(N^{\ast}\) and dataset size \(D^{\ast}\). Hoffman’s experiments give \(D/N = 20\) tokens/parameter at Chinchilla optimality. And now one can simply train a much bigger model on a much bigger dataset and expect to get a model with as small a test loss as possible at that compute budget, for free.&lt;/p&gt;

&lt;p&gt;A quick note: Over the last couple of years, inference costs have skyrocketed, so one usually replaces the cost with \(C = 6ND + \lambda N\) to account for inference, forcing \(N\) to be much smaller than Chinchilla \(N^{\ast}\), pushing upwards of \(10\)k tokens/parameter. This means that one actually trains much longer (many more tokens) than Chinchilla optimality prescribes.&lt;/p&gt;

&lt;h2 id=&quot;neural-collapse&quot;&gt;Neural collapse&lt;/h2&gt;

&lt;p&gt;It is also often fruitful to look at the behavior of the network at convergence (i.e. after training is complete) and come up with empirical laws describing the structure of its parameters at this time. One really cool phenomenon in this regard is called &lt;em&gt;neural collapse&lt;/em&gt;. Consider a neural network trained to classify images into \(k=4\) classes. So we throw in a bunch of layers, and at the end we have four outputs corresponding to the four classes, and we say the network predicts the class with the highest output value. Let’s train it till we get near-perfect accuracy on the training set. To find out what the function learns to do, consider the last set of weights of the network and denote by \(\tilde x\) the result of passing an image \(x\) until the penultimate layer, just before this last set of weights. This last set consists of four vectors \([w_1, w_2, w_3, w_4]\), and the four-dimensional output of the network is the dot product with \(\tilde x\), i.e. \([w_1 \cdot \tilde x, w_2 \cdot \tilde x, w_3 \cdot \tilde x, w_4 \cdot \tilde x]\). Now the dot product measures alignment between two vectors, with a larger value indicating that the two vectors are more aligned.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/website2026/public/images/neural-collapse.png&quot; alt=&quot;At initialization the class weight vectors and datapoints are scattered; at convergence they collapse onto the vertices of a regular tetrahedron with each class clustered around its weight vector.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Apologies for the long-winded setup. Here’s the cool part: it turns out that the vectors \([w_1, w_2, w_3, w_4]\) are arranged in a very specific way after training: they form the vertices of a regular tetrahedron in three-dimensional space! And the \(\tilde x\) vectors corresponding to datapoints of each class \(i\) are clustered very close to \(w_i\), so the network pretty much perfectly classifies them. This is about as good as classification can ever get: a tetrahedron is the unique arrangement of four points in 3D space that maximizes the distance between them, so the network has learned to represent each class as far away from the others as possible. So for a new image \(x\), the network computes \(\tilde x\) and then simply finds the closest \(w_i\) to \(\tilde x\) to classify it. In other words, keeping different classes as far as possible accounts for the network’s ability to generalize very well even when the data is slightly corrupted or off-distribution, since the closest \(w_i\) is still likely to be the correct class. This very simple structure of the network at convergence is one of the many examples of the prioritization of simplicity in neural networks, and is part of why they generalize so well to unseen data.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;The samples above are simply hand-picked nuggets of the current state of learning mechanics. It’s a very new field, since deep learning only started working about ten years ago, and there is much, much more to unearth, especially in LLM mechanics given its importance today. Nevertheless, empirical laws have already started to guide practice, and the community is working hard towards more predictive theory. It is a hard problem and will take a long time yet to resolve, but it is going to happen. Come one, come all, and join the quest: you could be the next Isaac Newton, Charles Darwin or Albert Einstein of learning mechanics.&lt;/p&gt;

&lt;p&gt;A substantial portion of this article is based on the excellent survey &lt;em&gt;There Will Be a Scientific Theory of Deep Learning&lt;/em&gt; (2026), a collaborative effort from the leaders in the field. For the reader interested to know more (thank you!), I highly recommend reading it and the references therein.&lt;/p&gt;

&lt;p&gt;Peace out.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The theory of deep learning: why</title>
   <link href="https://mathismusic.github.io/2026/08/12/deep-learning-theory-why/"/>
   <updated>2026-08-12T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2026/08/12/deep-learning-theory-why</id>
   <content type="html">&lt;!-- *This is part one of two. Part one asks whether deep learning needs a mathematical theory at all; [part two](/2026/08/13/deep-learning-theory-how/) surveys what that theory looks like so far.* --&gt;

&lt;p&gt;I will unfortunately start with a cliché. Artificial Intelligence (AI) has been transformative for pretty much everyone in the world, greatly affecting our perspective on what is considered a normal part of daily life. We are however much more primitive in our understanding of &lt;em&gt;why&lt;/em&gt; these techniques work so well in practice and what a potential ceiling for their capabilities might look like. We do keep improving our models, e.g. in data and compute efficiency or in how often they confidently make things up, but these improvements are primarily directed by accumulated intuition, careful data collection and tuning and not really by a mathematical framework.&lt;/p&gt;

&lt;p&gt;The question we ask is then: Do we really need a mathematical framework to understand artificial intelligence? Or is it enough to keep improving the techniques and their applications?&lt;/p&gt;

&lt;p&gt;In the next section, I shall attempt to convince the reader of an affirmative answer to this question by drawing parallels between the history of the development of the natural sciences and that of the man-made science we call AI. And then we shall survey some interesting tidbits of the emerging field of (machine) learning mechanics.&lt;/p&gt;

&lt;h2 id=&quot;do-we-need-the-math&quot;&gt;Do we need the math?&lt;/h2&gt;

&lt;p&gt;Let’s review a time in human history similar to today. The people of the late eighteenth century were fortunate to receive a similar gift as us in the form of the steam engine which made mechanical automation possible for the first time. This led to the industrial revolutions for over a century until the world went to war in 1914. We ask the question: did one need a mathematical framework to understand the steam engine? Certainly not immediately; the world went nearly eighty years into the industrial revolution before we had a fairly solid understanding of thermodynamics and the efficiency of engines. Do we need it today? Honesty compels me to admit that most progress has still been driven by engineering, e.g. better alloys, blade cooling and aerodynamics, and not theory. But it was thermodynamics that told us a performance ceiling exists that is independent of the specific implementation, that entire directions like perpetual motion or fancier working fluids were not worth pursuing, that very high compression improves efficiency, and so on; essentially, theory still tells us which building to lean the ladder against, and the engineer scales the building one step at a time.&lt;/p&gt;

&lt;p&gt;Beyond pragmatic considerations, there is a deeper, more fundamental reason for a mathematical framework. Recall again the steam engine and thermodynamics. The formal study of the steam engine led to a much better understanding of energy usage and drove cryo tech, heat pump tech, industrial chemistry, and more. In other words, a mathematical understanding of the principles governing a system usually gives a much more generalizable understanding of other things that work on similar ideas. For AI, this is especially important: clearly, our systems exploit deep principles of learning and representation that we do not yet understand, and a general understanding of learning and intelligence can shed light on how biological intelligence works with potentially important implications for neuroscience and psychology. We are possibly en route to solving the last great scientific problem of our time: understanding the human mind. A solid study of existing artificial intelligence together with progress in neuroscience is likely to be a fruitful path forward for both fields.&lt;/p&gt;

&lt;p&gt;There is one more point to get out of the way. Even if useful, is it &lt;em&gt;possible&lt;/em&gt; to formalize AI anytime soon? It has evaded our mathematics and has sprung surprise after surprise for over ten years. However, this is not a reason to give up. The history of science is full of examples of phenomena that were not understood for decades or centuries, and yet eventually gave way to accurate and predictive mathematical frameworks: classical mechanics, chemistry, thermodynamics, electromagnetism, et cetera. It is not unreasonable to expect that the same will happen &lt;em&gt;eventually&lt;/em&gt; for learning, which is simply another man-made science, and indeed we have started to see some of the first glimpses of such a theory in the last few years.&lt;/p&gt;

&lt;p&gt;Welcome to the theory of AI: &lt;em&gt;learning mechanics&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id=&quot;setting-up&quot;&gt;Setting up&lt;/h2&gt;

&lt;p&gt;As any good mathematician will tell you, one must always begin by setting up the precise problem to attack in front of oneself.&lt;/p&gt;

&lt;p&gt;A deep learning system is specified by four things.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;em&gt;architecture&lt;/em&gt; is the network \(f(x;\theta)\), built as a composition of simple linear and nonlinear functions. \(\theta\) is the set of parameters of the network, e.g. weights and biases.&lt;/li&gt;
  &lt;li&gt;The &lt;em&gt;data&lt;/em&gt; is a set \(\mathcal{D} = \{(x_i, y_i)\}_{i=1}^n\) drawn from some unknown distribution \(P_{\mathrm{data}}\).&lt;/li&gt;
  &lt;li&gt;The &lt;em&gt;task&lt;/em&gt; is an objective \(\mathcal{L}(\theta)\) scoring how well \(f(x;\theta)\) does on \(\mathcal{D}\).&lt;/li&gt;
  &lt;li&gt;The &lt;em&gt;learning rule&lt;/em&gt; is the update we apply, e.g. \(\theta^{(t+1)} = \theta^{(t)} - \eta \nabla \mathcal{L}(\theta^{(t)})\), along with an initialization \(\theta^{(0)}\) and hyperparameters such as the learning rate \(\eta\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We shall, for the sake of this article, restrict ourselves to the setting of fully-connected neural networks; but note that the theory of transformers and convolutions has started to emerge as well.&lt;/p&gt;

&lt;h2 id=&quot;the-current-state-of-affairs&quot;&gt;The current state of affairs&lt;/h2&gt;

&lt;p&gt;Here is a diagram of (my current knowledge of) the current state of learning mechanics:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/website2026/public/images/learning-mech-overview.png&quot; alt=&quot;Today&apos;s map of learning mechanics: model size against model complexity, with simple systems and linear/NTK theory at the top, today&apos;s systems and scaling laws in the middle, and infinite limits and approximation at the edges.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Why is learning mechanics hard? The four ingredients above are all visible and measurable, and (nowadays) experiments are fast and almost free. The obstacle is complexity: the four ingredients interact to give dynamics that are nonlinear, coupled and enormously high-dimensional. Just like physical systems in the real world or the Avogadro number of particles in a slow organic chemical reaction. The bet of learning mechanics is to find macroscopic regularities that emerge from a deep learning system at hand, and use them to predict the system’s behavior.&lt;/p&gt;

&lt;p&gt;We would like to mention here that learning mechanics is very different from universality: yes, neural networks are fully expressive and they can approximately model any function; however, the problem of deep learning lies in showing that gradient descent does actually help them converge to said functions. This is very nontrivial because of nonconvexity and dimensionality; learning mechanics is concerned with understanding the training process. It’s just like how showing the existence of a solution to a differential equation and showing that a numerical method finds said solution are very different claims.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;em&gt;Continue to &lt;a href=&quot;/2026/08/13/deep-learning-theory-how/&quot;&gt;part two: the theory of deep learning, how&lt;/a&gt;, where we look at linearization, infinite limits, scaling laws and neural collapse.&lt;/em&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The prime number theorem, for dummies</title>
   <link href="https://mathismusic.github.io/2026/03/19/pnt/"/>
   <updated>2026-03-19T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2026/03/19/pnt</id>
   <content type="html">&lt;p&gt;A discussion with some friends on the LCM of the first $n$ natural numbers led to a simple, very elementary proof of a relaxation of the prime number theorem. I had to write it up. Of course, since it is so elementary, it is likely not new.&lt;/p&gt;

&lt;p&gt;The prime number theorem states that the number of primes less than $n$, denoted $\pi(n)$, is asymptotically $\frac{n}{\log n}$. Formally,&lt;/p&gt;

\[\lim_{n \to \infty} \frac{\pi(n)}{n/\log n} = 1.\]

&lt;p&gt;The relaxation of the prime number theorem that we will show is that $\pi(n) = \Theta(\frac{n}{\log n})$. In other words, it grows as $n/\log n$ up to constant factors: there exist constants $c_1, c_2 &amp;gt; 0$ such that for sufficiently large $n$, we have&lt;/p&gt;

\[c_1 \frac{n}{\log n} \leq \pi(n) \leq c_2 \frac{n}{\log n}.\]

&lt;p&gt;This proof of the upper bound is folklore. The idea is to examine the quantity ${2n \choose n}$. Notice that every prime $p$ such that $n &amp;lt; p &amp;lt; 2n$ divides ${2n \choose n}$, since $p$ appears in the numerator but cannot appear in the denominator. Therefore, we have&lt;/p&gt;

\[\prod_{n &amp;lt; p &amp;lt; 2n} p \leq {2n \choose n} \leq 4^n,\]

&lt;p&gt;where the upper bound follows from the binomial theorem: ${2n \choose n} \leq (1+1)^{2n}$. For now, we can use the crude bound that each prime between $n$ and $2n$ is at least $n$. Since the number of terms in the product is $\pi(2n) - \pi(n)$, we obtain&lt;/p&gt;

\[n^{\pi(2n) - \pi(n)} \leq \prod_{n &amp;lt; p &amp;lt; 2n} p \leq 4^n \implies \pi(2n) - \pi(n) \leq \frac{n \log 4}{\log n}.\]

&lt;p&gt;Repeating this argument for $n/2$, $n/4$, and so on and adding the resulting inequalities (the left hand sides telescope) will give us the upper bound $\pi(n) \leq c n/\log n$ for some constant $c$. The details need a bit of care and may look somewhat arbitrary at first, but it is standard fare in analysis and will be second-nature after performing some such arguments. Here is the essential idea. We have, via the telescoping, that&lt;/p&gt;

\[\pi(2n) \leq \pi(n) + \frac{n \log 4}{\log n} \leq \pi(n/2) + \frac{n \log 4}{\log (n/2)} + \frac{n \log 4}{\log n} \leq n\log 4\sum_{k = 0}^{\log_2 n - 1} \frac{1}{2^k \log (n/2^k)}.\]

&lt;p&gt;The $1/2^k$ factors are easy to bound via the geometric series. The $\log (n/2^k)$ factors are a bit more annoying, but we can get away cleverly: notice that for smaller $k$ with $n/2^k &amp;gt; \sqrt n$, we have $\log (n/2^k) \geq \log \sqrt n = \frac12 \log n$. And we shall deal with larger $k$ by simply not telescoping them. Let $\widetilde{\sqrt{n}}$ denote the largest number of the form $n/2^k$ for some $k$ that is at most $\sqrt{n}$, i.e., $k = \lceil \log_2 \sqrt{n} \rceil$. Then we telescope down to $\widetilde{\sqrt{n}}$ and get&lt;/p&gt;

\[\pi(2n) \leq \pi(\widetilde{\sqrt{n}}) + n\log 4\sum_{k = 0}^{\lceil \log_2 \sqrt{n} \rceil - 1} \frac{1}{2^k \log (n/2^k)}.\]

&lt;p&gt;The first term we bound in trivial fashion: there are at most $\widetilde{\sqrt{n}}$ numbers less than $\widetilde{\sqrt{n}}$, and at most all of them are prime (we can do much better here: for example, at most half are prime) so $\pi(\widetilde{\sqrt{n}}) \leq \widetilde{\sqrt{n}} \leq \sqrt{2n}$. For the second term, as discussed, we have $\log (n/2^k) \geq \log \sqrt{n}$ for all $k$ in the range of the sum (since we chose $\widetilde{\sqrt{n}}$ to be the first time this inequalty is violated). The second term is therefore bounded like so:&lt;/p&gt;

\[n\log 4\sum_{k = 0}^{\lceil \log_2 \sqrt{n} \rceil - 1} \frac{1}{2^k \log (n/2^k)} \leq n\log 4\sum_{k = 0}^{\lceil \log_2 \sqrt{n} \rceil - 1} \frac{1}{2^k \log \sqrt{n}} = n\log 4\frac{2}{\log n}\sum_{k \geq 0} \frac{1}{2^k} = \frac{4n\log 4}{\log n}.\]

&lt;p&gt;Putting the two together gives us $\pi(2n) \leq \sqrt{n} + \frac{4n\log 4}{\log n}$. For large enough $n$, $\sqrt{n}$ is at most $0.001 n/\log n$ and $\log (2n) \leq \frac{\log n}{0.999}$, so we get \(\pi(2n) \leq 0.001 n/\log n + 4n\log 4/\log (n) \leq 2.8 \frac{2n}{\log (2n)},\)&lt;/p&gt;

&lt;p&gt;where we have used the fact that $\log 4 \leq 1.39$. It follows, upon replacing $2n$ by $n$, that $\pi(n) \leq 2.8 n/\log n$ for sufficiently large $n$.&lt;/p&gt;

&lt;p&gt;A couple of remarks. Firstly, it seems as though we have been assuming that $n$ is a power of $2$ for the sake of telescoping; in general, we take the ceiling at each step. We can be off by at most one in each step of the telescoping, which only adds a $\log n$ factor to the final bound, which is negligible compared to the $n/\log n$ term anyways and does not affect the asymptotics. Secondly, the constant factor of $2.8$ can be considerably improved by replacing $\sqrt{n}$ with $n^c$ for $c$ close to $1$ with no change to the rest of the argument, except replacing $2.8$ by $1.4/c$ instead. This yields the bound $\pi(n) \leq 1.41 n/\log n$ for sufficiently large $n$.&lt;/p&gt;

&lt;p&gt;Next, we show the lower bound. To do this, we define $U(n) = \mathsf{lcm}(1, 2, \ldots, n)$. Note that $U(n)$ clearly has lots to do with the primes and their powers that are smaller than $n$. In fact, it is easy to see that the largest power of a prime $p$ that divides $U(n)$ is $p^{\lfloor \log_p n \rfloor}$, since $p^k$ divides $U(n)$ if and only if $p^k \leq n$. Therefore, we can write
\(U(n) = \prod_{p \leq n} p^{\lfloor \log_p n \rfloor},\)&lt;/p&gt;

&lt;p&gt;where the product is taken over all primes $p$ less than or equal to $n$. We use the obvious bound $\lfloor x \rfloor \leq x$ to get&lt;/p&gt;

\[U(n) \leq \prod_{p \leq n} p^{\log_p n} = \prod_{p \leq n} n = n^{\pi(n)},\]

&lt;p&gt;where $\pi(n)$ is as before the number of primes less than or equal to $n$. So if we can show a lower bound on $U(n)$, we automatically get a lower bound on $\pi(n)$. Informally, if $U(n)$ is large, then $\pi(n)$ must be large as well.&lt;/p&gt;

&lt;p&gt;To show a lower bound on $U(n)$, what can we exploit? The basic definition of $U(n)$ is that for each $1 \leq i \leq n$, $i \mid U(n)$. An ingenious way to put this together is to say that for any sequence of integers $a_1, a_2, \ldots, a_n$, the value&lt;/p&gt;

\[\sum_{i=1}^n a_i \frac{U(n)}{i}\]

&lt;p&gt;is an integer; this is equivalent to saying that for every polynomial $P_n(x)$ of degree at most $n-1$ with integer coefficients, the quantity $U(n) \int_0^1 P_n(x)\mathsf{d}x$ is an integer. Suppose that $n$ is odd, and let $P_n(x) = x^{\frac{n-1}{2}}(1-x)^{\frac{n-1}{2}}$. Since $x(1-x) \leq \frac14$ for $x \in [0, 1]$, we have&lt;/p&gt;

\[1 \leq U(n) \int_0^1 P_n(x)\mathsf{d}x \leq \frac{U(n)}{2^{n-1}} \implies U(n) \geq 2^{n-1}.\]

&lt;p&gt;And for $n$ even, we pick $P_n(x) = x^{\frac{n}{2}-1}(1-x)^{\frac{n}{2}-1}$ (note that we have to keep the degree of $P_n$ at most $n-1$). For each $x \in [0, 1]$, we have&lt;/p&gt;

\[x^{\frac{n}{2}}(1-x)^{\frac{n}{2} - 1} \leq x 2^{-(n-2)},\]

&lt;p&gt;so \(1 \leq U(n) \int_0^1 P_n(x)\mathsf{d}x \leq \frac{U(n)}{2^{n-2}} \int_0^1 x\mathsf{d}x \implies U(n) \geq 2^{n-1}.\)&lt;/p&gt;

&lt;p&gt;Putting the two cases together, we have $U(n) \geq 2^{n-1}$ for all $n$. Now we can finish the lower bound on $\pi(n)$:&lt;/p&gt;

\[2^{n-1} \leq U(n) \leq n^{\pi(n)} \iff \pi(n) \geq \log 2\frac{n-1}{\log n} \geq 0.692\frac{n}{\log n},\]

&lt;p&gt;where we can drop the $-1$ in the numerator for sufficiently large $n$ at the cost of a small drop in the constant factor since $(n)/(n-1) \to 1$.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;To summarize, we have shown that for sufficiently large $n$, we have&lt;/p&gt;

\[0.692\frac{n}{\log n} \leq \pi(n) \leq 1.41 \frac{n}{\log n}.\]

&lt;p&gt;The prime number theorem brings the lower and upper bounds to $(1-\varepsilon)$ and $(1+\varepsilon)$ respectively for any $\varepsilon &amp;gt; 0$ as $n \to \infty$. The proof of the prime number theorem is much more involved and relies on complex analysis. There is, however, one interesting point to make. The functions we used in the upper bound and lower bound proofs are closely related to the Chebyshev functions (so we have essentially been bounding them), which are key to the actual proof of the prime number theorem. The Chebyshev functions are defined as follows:&lt;/p&gt;

\[\begin{align*}
\theta(n) &amp;amp;= \sum_{p \leq n} \log p, \\
\psi(n) &amp;amp;= \sum_{p^k \leq n} \log p.
\end{align*}\]

&lt;p&gt;Essentially, they are smoothed-out versions of $\pi(n)$ that are easier to analyze. The prime number theorem is equivalent to the statement that $\theta(n) \sim n$ and $\psi(n) \sim n$, and the proof of the prime number theorem goes via showing that the Riemann zeta function has no zeros on the line $\Re(s) = 1$, followed by relating the logarithm of the Riemann zeta function to the Chebyshev function $\psi(n)$, which then gives us the asymptotics of $\psi(n)$ and hence $\pi(n)$.&lt;/p&gt;

&lt;p&gt;We actually upper-bounded $\theta(n)$ and lower-bounded $\psi(n)$ in our proofs. Can you find out where?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>When math turns to magic: Self-inverse transforms and convolutions</title>
   <link href="https://mathismusic.github.io/2025/06/14/inversions/"/>
   <updated>2025-06-14T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2025/06/14/inversions</id>
   <content type="html">&lt;p&gt;There are some things in mathematics that are simply too magical to be true. One such thing, in my opinion, are self-inverse and unitary transforms. In this post, I’d like to talk about some of the most beautiful self-inverse transforms that I have come across so far. I’m &lt;em&gt;very&lt;/em&gt; sure I’ve missed some gems, but ah well one learns something new everyday.&lt;/p&gt;

&lt;h3 id=&quot;what-is-a-self-inverse-transform&quot;&gt;What is a self-inverse transform?&lt;/h3&gt;

&lt;p&gt;A transform \(T\) takes an input object \(x\) and outputs another object which we call \(T(x)\) or \(Tx\). We say \(T\) &lt;em&gt;is applied to&lt;/em&gt; \(x\). Real functions are the most common example of transforms, taking one real number to another.&lt;/p&gt;

&lt;p&gt;A transform becomes self-inverse if it can be applied to its own output to get back the original input. That is, to &lt;em&gt;undo&lt;/em&gt; \(T\), we simply have to &lt;em&gt;redo&lt;/em&gt; it. This is amazing news for engineers, because for many applications, coming up with an input that produces a desired output is much harder (e.g. finding a function that produces a known signal or satisfies a known differential equation) than verifying that a given input produces a desired output (e.g. checking that a function satisfies a differential equation). That is, re-doing a transform is often much, much easier than undoing it.&lt;/p&gt;

&lt;p&gt;To be cheeky, if construction was self-inverse, then all we would have to do to rebuild something is to destroy it again. Too bad this isn’t true in practice.&lt;/p&gt;

&lt;!-- ### Functions on $$\mathbb R$$

Examples of self-inverse transforms are functions $$f: \mathbb R \to \mathbb R$$ that satisfy $$f(f(x)) = x$$ for each $$x$$ -- to invert them, one simply *re-applies* them. 

Well, please don&apos;t go $$f(x) = 1/x$$ on me haha, because these things get a lot more interesting than that. Or $$x/(x-a)$$, which is just the re-centering of the previous hyperbola to $$(a,a)$$.

In this  --&gt;

&lt;h3 id=&quot;a-familiar-starter-the-discrete-fourier-transform&quot;&gt;A familiar starter: the Discrete Fourier transform&lt;/h3&gt;

&lt;p&gt;Much of the engineering world is familiar with the ubiquitous fourier transform, which revolutionized signal processing and reading this article via the internet would hardly be possible without it.&lt;/p&gt;

&lt;p&gt;Here, in true computer science fashion, we will discretize and consider the Discrete Fourier Transform (DFT). Let \(n\) be a positive integer. The DFT is a linear transform \(\mathcal F\) taking an \(n\)-length sequence \(a = (a_0, a_1, \ldots, a_{n-1})\) to another sequence \(\mathcal F(a) = (b_0, b_1, \ldots, b_{n-1})\) defined by&lt;/p&gt;

\[b_k = \frac{1}{\sqrt{n}} \sum_{j=0}^{n-1} a_j \left(e^{-2\pi \iota k/n}\right)^j \quad \text{for } k = 0, 1, \ldots, n-1.\]

&lt;p&gt;As a matrix operation, consider the \(n\times n\) matrix \(F\) with entries&lt;/p&gt;

\[F_{jk} = \frac{1}{\sqrt{n}} e^{-2\pi \iota jk/n} \quad \text{for } j, k = 0, 1, \ldots, n-1.\]

&lt;p&gt;Then the DFT is simply the matrix multiplication \(\mathcal F(a) = F a\).&lt;/p&gt;

&lt;p&gt;So the DFT is what’s called &lt;em&gt;unitary&lt;/em&gt;, which is almost as good as self-inverse: to undo the DFT, we need to do something &lt;em&gt;as easy as&lt;/em&gt; apply the DFT again. In particular, let’s define the &lt;em&gt;adjoint&lt;/em&gt; of the DFT, denoted \(\mathcal F^\dagger\) via the matrix \(F^\dagger\) with elements \(F^\dagger_{jk} = \frac{1}{\sqrt{n}} e^{2\pi \iota jk/n}\) – so just a change from \(\iota\) to \(-\iota\). Since mathematics is symmetric in \(\iota\) and \(-\iota\), any algorithm to apply \(\mathcal F\) yields one with the same complexity to apply \(\mathcal F^\dagger\). The DFT satisfies the property \(F^\dagger F = I\), where \(I\) is the identity matrix. This means that for every sequence \(a\), we have \(\mathcal F^\dagger \mathcal F(a) = a\) (the unitary property).&lt;/p&gt;

&lt;p&gt;Take a moment to appreciate the beauty of the transform: it’s very easy using something called the Fast Fourier Transform to apply the DFT to a sequence. And yes, when we receive an “impure” signal, we often apply the DFT to it. Purifying the result of the DFT happens to be super-easy: the true signal shows up in the result as spikes (Grant Sanderson &lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;does a great job&lt;/a&gt; (as usual) explaining this, by the way). Filtering the result by setting the noise to zero and leaving the spikes is easy too. The main thing now is to find a signal that produces this filtered result directly – un-doing the fourier transform on the filtered result. The mathemagic of the unitarity of the DFT means that this is just as easy as applying the DFT. And boom: signal processing works!&lt;/p&gt;

&lt;p&gt;If you’re interested to learn more, I highly recommend &lt;a href=&quot;https://www.cs.cmu.edu/afs/andrew/scs/cs/15-463/2001/pub/www/notes/fourier/fourier.pdf&quot;&gt;this amazing set of notes&lt;/a&gt; and of course, &lt;a href=&quot;https://www.youtube.com/watch?v=spUNpyF58BY&quot;&gt;Grant Sanderson’s video&lt;/a&gt; on the subject.&lt;/p&gt;

&lt;h3 id=&quot;interlude-convolutions&quot;&gt;Interlude: Convolutions&lt;/h3&gt;

&lt;p&gt;Central to many self-inverse transforms is the idea of a convolution. A convolution (etymology: entwine, combine) is a way of combining two sequences to produce a third sequence, and it is defined as follows: given two infinite sequences \(a = (a_0, a_1, \ldots)\) and \(b = (b_0, b_1, \ldots)\), their convolution \(c = a * b\) is another infinite sequence defined by&lt;/p&gt;

\[c_i = \sum_{j=0}^{i} a_j b_{i-j} \quad \text{for } i = 0, 1, \ldots.\]

&lt;p&gt;It arises naturally in many settings; most students encounter it first in the context of polyonomial multiplication: if \(a(x) = a_0 + a_1 x + \ldots + a_n x^n\) (represented by the sequence \((a_0, a_1, \ldots, a_n, 0, 0, \ldots)\)) and \(b(x) = b_0 + b_1 x + \ldots + b_m x^m\) (represented similarly) are two polynomials, then the coefficients of the product polynomial \(c(x) = a(x)b(x)\) are given by the convolution: \(c_i = \sum_{j=0}^{i} a_j b_{i-j}\) for \(i = 0, 1, \ldots\).&lt;/p&gt;

&lt;p&gt;The convolution may appear convoluted, but it finds use more often than one might expect: think enumerative combinatorics, fourier analysis, number theory, etc. (The thing in “convolutional” neural networks is actually a &lt;em&gt;cross-correlation&lt;/em&gt; and is slightly different but can be presented as an evaluation of a convolution too.) The essential motivation behind convolutions is that often one wants to pick some of one and some of another, in a way that the total quantity picked is a constant. And the number of different ways we can do that for each value of the total amount picked is described by the result of the convolution. For example, in combinatorics, the convolution tells you how many ways you can select items from two groups so that the total number of items selected equals a given number.&lt;/p&gt;

&lt;p&gt;A key property of the convolution is that it is associative: that is, for any three sequences \(a, b, c\), we have&lt;/p&gt;

\[(a * b) * c = a * (b * c).\]

&lt;p&gt;Indeed, notice that for any \(i \geq 0\),&lt;/p&gt;

\[\begin{align*}
    [(a * b) * c]_i &amp;amp;= \sum_{j=0}^{i} (a * b)_j c_{i-j} \\ &amp;amp;= \sum_{j=0}^{i} \left(\sum_{k=0}^{j} a_k b_{j-k}\right) c_{i-j} \\
    &amp;amp;= \sum_{k=0}^{i} a_k \left(\sum_{j=k}^{i} b_{j-k} c_{i-j}\right) \\
    &amp;amp;= \sum_{k=0}^{i} a_k \left(\sum_{j&apos;=0}^{i-k} b_{j&apos;} c_{i-k-j&apos;}\right) \\
    &amp;amp;= \sum_{k=0}^{i} a_k (b * c)_{i-k} \\ &amp;amp;= [a * (b * c)]_i.
\end{align*}\]

&lt;p&gt;Notice how \(i-k = i-j + j-k\) helps us re-write the summation over \(j\) as another convolution evaluated at \(i-k\).&lt;/p&gt;

&lt;p&gt;The convolution is also commutative, i.e. \(a * b = b * a\) for any two sequences \(a\) and \(b\) (left as an easy exercise for readers with pen and paper). Associativity and commutativity help us manipulate convolutions easily without having to re-write them as summations (more on this later), treating sequence convolution like integer multiplication.&lt;/p&gt;

&lt;p&gt;Convolutions go much, much further than the standard convolution presented here. We’re going to see one more in this post, and perhaps one or two more in the sequel post.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;The &lt;em&gt;binomial convolution&lt;/em&gt; is defined by&lt;/p&gt;

\[[a \circ b]_n := \sum_{j=0}^{n} \binom{n}{j} a_j b_{n-j} \quad \text{for } n = 0, 1, \ldots.\]

&lt;p&gt;For readers familiar with generating functions, this is the convolution involved in the product of two exponential generating functions.&lt;/p&gt;

&lt;p&gt;Surprisingly, the binomial convolution is also associative! For each \(n \geq 0\), we have&lt;/p&gt;

\[\begin{align*}
    [(a \circ b) \circ c]_n &amp;amp;= \sum_{j=0}^{n} \binom{n}{j} (a \circ b)_j c_{n-j} \\
    &amp;amp;= \sum_{j=0}^{n} \binom{n}{j} \left(\sum_{k=0}^{j} \binom{j}{k} a_k b_{j-k}\right) c_{n-j} \\
    &amp;amp;= \sum_{k=0}^{n} a_k \left(\sum_{j=k}^{n} \binom{n}{j} \binom{j}{k} b_{j-k} c_{n-j}\right).
\end{align*}\]

&lt;p&gt;We now call for some sorcery with the binomial coefficients: it turns out that&lt;/p&gt;

\[\begin{align*}
    \binom{n}{j} \binom{j}{k} &amp;amp;= \frac{n!}{j!(n-j)!} \cdot \frac{j!}{k!(j-k)!} \\
    &amp;amp;= \frac{n!}{k!(n-j)!(j-k)!}\cdot\frac{(n-k)!}{(n-k)!} = \binom{n}{k} \binom{n-k}{j-k}.
\end{align*}\]

&lt;p&gt;This helps us re-write the inner summation as a convolution:&lt;/p&gt;

\[\begin{align*}
    \sum_{j=k}^{n} \binom{n}{j} \binom{j}{k} b_{j-k} c_{n-j} &amp;amp;= \sum_{j&apos;=0}^{n-k} \binom{n}{k} \binom{n-k}{j&apos;} b_{j&apos;} c_{n-k-j&apos;} = \binom{n}{k} (b \circ c)_{n-k},
\end{align*}\]

&lt;p&gt;which allows us to conclude that
\([(a \circ b) \circ c]_n = \sum_{k=0}^{n} \binom{n}{k} a_k (b \circ c)_{n-k} = [a \circ (b \circ c)]_n,\)&lt;/p&gt;

&lt;p&gt;so the $\circ$ operation is associative. Since \(\binom{n}{k} = \binom{n}{n-k}\), the binomial convolution is also commutative.&lt;/p&gt;

&lt;p&gt;A similar convolution is the &lt;em&gt;Dirichlet convolution&lt;/em&gt;, defined by&lt;/p&gt;

\[[a \star b]_n := \sum_{d|n} a_d b_{\frac{n}{d}} \quad \text{for } n \geq 1,\]

&lt;p&gt;where the notation \(d \mid n\) means that \(d\) divides \(n\) (so the sum is over all divisors \(d\) of \(n\)). The Dirichlet convolution is also associative (hell yes) and commutative, and it arises naturally in number theory, especially in the context of multiplicative functions. Commutativity of \(\star\) is easy to see; let’s quickly show that it is also associative. For each \(n \geq 1\), we have&lt;/p&gt;

\[\begin{align*}
    [(a \star b) \star c]_n &amp;amp;= \sum_{d|n} (a \star b)_d c_{\frac{n}{d}} \\
    &amp;amp;= \sum_{d|n} \left(\sum_{e|d} a_{e} b_{\frac{d}{e}}\right) c_{\frac{n}{d}} \\
    &amp;amp;= \sum_{e|n} a_{e} \left(\sum_{d: e|d, d|n} b_{\frac{d}{e}} c_{\frac{n}{d}}\right).    
\end{align*}\]

&lt;p&gt;The inner summation is over all \(d\) such that \(e\mid d\) and \(d\mid n\), which is equivalent to (setting \(d = d&apos;e\) for positive integer \(d&apos;\)) summing over all \(d&apos;\) such that \(d&apos;\mid \frac ne\). So we can re-write the inner summation as&lt;/p&gt;

\[\sum_{d&apos;|\frac ne} b_{d&apos;} c_{\frac{n}{d&apos;e}} = (b \star c)_{\frac{n}{e}}.\]

&lt;p&gt;This yields&lt;/p&gt;

\[[(a \star b) \star c]_n = \sum_{e|n} a_e (b \star c)_{\frac{n}{e}} = [a \star (b \star c)]_n,\]

&lt;p&gt;and done. Yay!&lt;/p&gt;

&lt;p&gt;Please do notice the very similar structure of the proofs of associativity for the different convolutions. Many different convolutions go through the same proofs and have similar properties, and after a while the mathematician treats such new proofs as “pencil-pushing” exercises, referring to the mechanical re-writing of the same steps over and over again. Other mathematicians filter out exactly what properties are used about the convolution to make the proof work, and then generalize the proof to any convolution that satisfies those properties in one go – you see, abstraction in mathematics is quite similar to the “if you use it more than once, make it a function” rule in programming.&lt;/p&gt;

&lt;p&gt;Why care about – indeed, focus on – convolutions in a post on self-inverse transforms? Here’s the big idea: &lt;em&gt;invertible&lt;/em&gt; convolutions &lt;em&gt;with identity&lt;/em&gt; lead to a natural invertible transform. And often, this transform is (almost) self-inverse. Thus, in a sense, convolutions can &lt;em&gt;generate&lt;/em&gt; self-inverse transforms.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;identity&lt;/em&gt; for a convolution operation is a sequence \(e\) such that for any sequence \(a\), we have \(a * e = a\). For the usual convolution \(*\), notice that the identity is the sequence \(e = (1, 0, 0, \ldots)\). The same sequence is also the identity for the binomial convolution \(\circ\) (and the Dirichlet convolution, and more). We say that sequence \(b\) &lt;em&gt;inverts&lt;/em&gt; the sequence \(a\) if \(a * b = e (= b * a)\). By commutativity and associativity, this means that if \(d = a * c\), then \(b * d = c\), in accordance with rules that treat \(b\) as “\(1/a\)”.&lt;/p&gt;

&lt;p&gt;Consider the following toy example. Define the &lt;strong&gt;partial-sum&lt;/strong&gt; transform \(S\) taking one sequence to another by \(S(a) := a * \mathbf 1\), where \(\mathbf 1\) is the sequence \((1, 1, 1, \ldots)\). Notice that for each \(i \geq 0\), we have&lt;/p&gt;

\[S(a)_i = \sum_{j=0}^{i} a_j,\]

&lt;p&gt;hence the name &lt;em&gt;partial-sum&lt;/em&gt;. Now suppose for a moment that we could find a sequence \(\lambda\) that inverts the sequence \(\mathbf 1\), i.e. \(\mathbf 1 * \lambda = e\). This would mean&lt;/p&gt;

&lt;p&gt;\(S(a) * \lambda = a * \mathbf 1 * \lambda = a * e = a,\)
which means that convolution with \(\lambda\) amounts to un-doing \(S\)! In general, if \(\mathbf 1\) can be inverted, then a transform generated by convolution with \(\mathbf 1\) can be inverted just as easily, by convolving with the inverse of \(\mathbf 1\). Choosing a particular convolution and computing \(\lambda\) is all that’s enough to conclude what’s called an &lt;em&gt;inversion formula&lt;/em&gt; for the transform.&lt;/p&gt;

&lt;p&gt;How does one find such an inverse \(\lambda\)? Just write out the constraints that must be met so that \(\lambda * \mathbf 1 = e = (1, 0, \ldots)\).&lt;/p&gt;

\[\begin{align*}
    \lambda_0 &amp;amp;= 1, \\
    \lambda_0 + \lambda_1 &amp;amp;= 0, \\
    \lambda_0 + \lambda_1 + \lambda_2 &amp;amp;= 0, \\
    &amp;amp;\;\;\vdots
\end{align*}\]

&lt;p&gt;which yields the unique solution \(\lambda = (1, -1, 0, 0, \ldots)\). Alright, so what does this give us? \(a = S(a) * \lambda\), so for each \(i \geq 1\),&lt;/p&gt;

\[a_i = [\lambda * S(a)]_i = \lambda_0 S(a)_i + \lambda_1 S(a)_{i-1} = S(a)_i - S(a)_{i-1}.\]

&lt;p&gt;But this is obvious: each element of the sequence \(a\) is indeed the difference between adjacent prefix-sums!&lt;/p&gt;

&lt;p&gt;Of course, like most things in mathematics, this is far from the end of the story. Much more powerful transforms and the associated inversion formulas can be generated with different convolutions. For example, doing the same thing as above with the binomial convolution, for example, leads to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Binomial_transform&quot;&gt;&lt;em&gt;binomial transform&lt;/em&gt;&lt;/a&gt; \(B\) and the nontrivial Pascal’s inversion formula (Pascal really did go crazy with binomial coefficients!). And with the Dirichlet convolution, the celebrated &lt;a href=&quot;https://en.wikipedia.org/wiki/M%C3%B6bius_inversion_formula&quot;&gt;Möbius inversion formula&lt;/a&gt;. Note, of course, that all the nontriviality of a theorem thus generated lies in the proof of the associativity and commutativity of the convolution involved and in the proof that the sequence \(\mathbf 1\) is indeed inverted by \(\lambda\).&lt;/p&gt;

&lt;p&gt;Anyways, we must now generate \(\lambda\) for the binomial convolution. The constraints are&lt;/p&gt;

\[\begin{align*}
    \lambda_0 &amp;amp;= 1, \\
    \binom{1}{0} \lambda_0 + \binom{1}{1} \lambda_1 &amp;amp;= 0, \\
    \binom{2}{0} \lambda_0 + \binom{2}{1} \lambda_1 + \binom{2}{2} \lambda_2 &amp;amp;= 0, \\
    &amp;amp;\;\;\vdots
\end{align*}\]

&lt;p&gt;which yields the pleasant solution \(\lambda = (1, -1, 1, -1, \ldots)\) (remember \(\sum_{k=0}^n (-1)^k \binom{n}{k} = 0\) for \(n \geq 1\)?). The associated transform is&lt;/p&gt;

\[B(a)_n = \sum_{k=0}^{n} \binom{n}{k} a_k,\]

&lt;p&gt;and so our computation of the inverse \(\lambda\) yields the inversion formula&lt;/p&gt;

\[a_n = \sum_{k=0}^{n} \binom{n}{k} B(a)_k (-1)^{n-k}.\]

&lt;p&gt;so \(B\) is also “almost self-inverse”, except for the alternating sign. (Note: alternating signs can sometimes prove to be a nuisance in efficient computation, see &lt;a href=&quot;https://www.wisdom.weizmann.ac.il/~feige/algs/permanent.pdf&quot;&gt;permanent vs determinant&lt;/a&gt;)&lt;/p&gt;

&lt;!-- We move away from complex numbers all the way to the other end: natural numbers. Ah, the joy of natural-number arithmetic. --&gt;

&lt;!-- Note to JEE: A lot of high-schoolers will have studied the famous self-inverse function

$$
f(x) = \frac{x}{x-1}
$$

which JEE loves to trick students with; this is just the translated version of the previous function: $$f(x) - 1 = 1/(x-1)$$. --&gt;

&lt;p&gt;That’s a wrap. For the reader interested in a further application of convolutions, let’s go to combinatorics: I recommend checking out generating functions, compositional constructions and the use of convolutions as the coefficients of products of generating functions. Hopefully I’ll get to writing about this at some point.
&lt;!-- There are many more famous self-inverse (or slightly different, self-dual) transforms out there. Try the Möbius transform first --&gt;
&lt;!-- Until next time on Saturday the fourteenth. Do ping me if you&apos;ve got comments or suggestions. I&apos;m very new to this business of blogging and could certainly use some help. You can reach me at the usual email address: ```kagaram@cse.iitb.ac.in```. --&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>The Foundation Saga, by Isaac Asimov</title>
   <link href="https://mathismusic.github.io/2025/06/11/asimov/"/>
   <updated>2025-06-11T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2025/06/11/asimov</id>
   <content type="html">&lt;p&gt;Goodness gracious. I almost forgot about the post due today. We’ll start with a book series review that took me a fair fraction of 2024 to cover most of (yes, I haven’t still read them all). It was totally worth the effort.&lt;/p&gt;

&lt;p&gt;The author first: Isaac Asimov was a biochemist who wrote extensively on science and science fiction. He is best known for the namesake of this post, the Foundation Saga. The series is a grand tapestry of speculative human history, spanning thousands of years, tons of planets across the galaxy. The entire series spans 20,000 years of human history, from around the current time when generalist robots have just been invented but are often large hunks and mistake-prone, to the exploration and colonization of nearby planets, interstellar travel and the colonization of star systems, to the rise of a &lt;em&gt;Galactic&lt;/em&gt; Empire, to the eventual inevitable fall of said Empire, and the cleverly orchestrated rise of a second Empire, finishing with plans of turning the galaxy into something very special indeed. Naturally, it was also written over a period of fifty-one years and comprises 20+ books, with three independent series (Robot, Foundation and Empire) glued together by a common thread of characters and events, prequels, sequels, and more standalone novels. (Personal opinion: I do not think anyone but a scientist in the know could have written such a series given the depth and realism of the science involved. Then again, it is hard to believe that a scientist could be so ingenious in creating the so-very-relatable social and political dynamics in the series. Asimov was a rare gem indeed.)&lt;/p&gt;

&lt;p&gt;The main draw of the series in my opinion, apart from the sheer scale and scope of the story, is the portrayal of very realistic scientific, social and political dynamics that inevitably show up in the history of a civilization. A few examples follow.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Consider the development of a robot that has been programmed to never harm a human, both physically and psychologically. Anne and Brit approach the robot. Anne is in love with Bryan, but the reverse is sadly not true. Anne asks the robot if Bryan loves her. The robot, having been programmed with overruling priority to never harm a human, says yes. And you can probably guess the rest of the soap opera that unfolds.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As a more serious example, consider the planet Terminus recently colonized by a group of scientists and engineers, suddenly showing up with technology that is far advanced than that of the neighboring planets. Terminus has essentially no resources of its own, both for sustenance and for military freedom. What does Terminus do, desperate to stay alive? As it happens, not something very nice, but something that has indeed happened over and over in our own (real) history. They start by nuclear-war blackmail and spread misinformation among the neighboring planets, causing them to fight amongst each other and divert attention from Terminus. The real punch comes next. They set up a techno-religious hegemony, operating their tech under a veil of mysticism and magic. It’s hard to believe how well that worked for them. They simply won outright (details: please read the book). To compound matters, the neighboring planets also depended on Terminus for technology, and Terminus traders capitalized hard on the monopoly. Finally, the neighboring planets simply collapsed on themselves, marking the first successful expansion for Terminus-folk.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The whole book, “&lt;em&gt;I, Robot&lt;/em&gt;” is a part-parody, part-serious take on all the various ways robots can “accidentally” bypass their programming and the ingenious ways to set them right. The book is a collection of short stories, each with a different robot and a different situation, but all connected by the same theme of robots and their interactions with humans. The stories explore the ethical implications of robotics and the complexities of human-robot relationships. No more spoilers here, it’s far too much fun reading the book oneself. Betcha you’ll lose your marbles at least thrice :D.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;The series has had real impact on science, too (yes, the name “Robot” is also due to Asimov). All robots are programmed with the so-called “&lt;em&gt;Three Laws of Robotics&lt;/em&gt;” (extended much, much later to include a zeroth law), a set of extremely relevant and realistic laws that robots are constrained by.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A robot may not injure a human being or, through inaction, allow a human being to come to harm.&lt;/li&gt;
  &lt;li&gt;A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.&lt;/li&gt;
  &lt;li&gt;A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Asimov explains that the laws are enforced by means of potential walls in robots’ positronic brains. Essentially, the thinking pathways are designed to travel down low-energy paths, and pathways that would lead to a violation of the laws are held back by a high potential wall, forcing other paths to be taken. Unfortunately for robots, sometimes there is no path that does not lead to a violation of the laws, and the robot is forced to attempt jumping a wall, most often leading to the robot’s brain’s destruction. While still futuristic for today’s standards, such an approach to enforcing laws in robots is not entirely unrealistic. The laws of robotics still influence research in artificial intel security.&lt;/p&gt;

&lt;p&gt;Another central concept in the series is “&lt;em&gt;Psychohistory&lt;/em&gt;”, a fictional science that combines history, sociology, and statistical mathematics to predict the future of large groups of people. The idea is that while individual actions are unpredictable, the behavior of large populations can be modeled and predicted with a high degree of accuracy. Scientist Hari Seldon first created this science, only to discover that the Galactic Empire was predestined to fall. Using his science, he injects the Foundations at ends of Galaxy, two groups of people filled with just the right people and instructed in the right ways so as to induce humanity along a path with a heavily-shortened period of chaos following the Empire’s collapse, with a speedy recovery and formation of a new Empire. To put it rather oversmartly but memorably, psychohistory is behind the foundation behind the Foundations.&lt;/p&gt;

&lt;p&gt;It would be rather unsatisfactory if psychohistory was exact, since there is an obvious element of uncertainty in human dynamics, even taken together, especially when the predictions are made over a long time period. Indeed, this happens with almost disastrous consequences when a mutant with mental powers, completely unaccounted for by psychohistory, appears on the scene (Foundation and Empire). A small branch: mentalist powers play an increasingly prominent role in the series, with the scientific basis for the ability to influence and (slightly) control human minds described as a consequence of extensive understanding over millenia of the electromagnetic waves emanating from the brain upon its information processing. Mentalists are able to manipulate these waves to influence the thoughts and actions of others, a power that becomes crucial in the later books of the series. Lots of different modes of power in this series!&lt;/p&gt;

&lt;p&gt;A quick note on Asimov’s writing style: it’s most often straightforword with little flowery prose, favoring clarity and storyline over . This approach makes his books accessible and easy to follow, though it can sometimes feel a bit dry. The characters tend to be lightly sketched (well, it isn’t a drama or high fantasy, cut him some slack!), and the dialogue may come across as stiff at times. Still, the sheer originality and depth of the ideas more than compensate for any stylistic limitations.&lt;/p&gt;

&lt;p&gt;Finally, here is a brief chronology of the series (not including a few standalone books, e.g. Nemesis) goes like so:&lt;/p&gt;

&lt;p&gt;Robot Series:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;I, Robot (1950) [Pilot to the whole saga. Set in the very near future; robots are just being invented and tinkered with]&lt;/li&gt;
  &lt;li&gt;The Caves of Steel (1954) [Murder mystery. A thousand years later. Colonization is on, and the robot-powered terraformed planets house long-lived, disease-prone humans]&lt;/li&gt;
  &lt;li&gt;The Naked Sun (1957) [Another whodunit. few decades later. Earthmen colonize again]
and sequels:&lt;/li&gt;
  &lt;li&gt;The Robots of Dawn (1983) [Yet another, some years later. This time, a very powerful &lt;em&gt;robot&lt;/em&gt; is the victim.]&lt;/li&gt;
  &lt;li&gt;Robots and Empire (1985) [Two centuries later. Earth’s fate in the balance here, with colonizers trying to get rid of it.]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Empire Series (mid-life of the Foundation Universe, tidbits from the formation of the First Galactic Empire):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The Stars, Like Dust (1951)&lt;/li&gt;
  &lt;li&gt;The Currents of Space (1952)&lt;/li&gt;
  &lt;li&gt;Pebble in the Sky (1950)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Foundation Series:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Foundation (1951) [Fast-forward to 20,000 years in the future. The Galactic empire is failing. The first Foundation is set up at Terminus and faces a rocky start to existence.]&lt;/li&gt;
  &lt;li&gt;Foundation and Empire (1952) [The empire (tried to) strike back. One last time. A slightly mentalist mutant proves to be an extremely strong antagonist.]&lt;/li&gt;
  &lt;li&gt;Second Foundation (1953) [The reveal of the Second Foundation, a perfect south to Terminus’ north. If Terminus-folk played chess, they didn’t even see the full board as the Second Foundation did.]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and sequels:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Foundation’s Edge (1982) [Something very important is orchestrated to happen, and the power behind is not Terminus or the Second Foundation. A third power was always hiding in the shadows.]&lt;/li&gt;
  &lt;li&gt;Foundation and Earth (1986) [The backward edge to the Robot Series. The search for the Mother Planet, Earth and meeting the true powers of the galaxy. Of course, the aforementioned final transformation of the galaxy into something fantastic.]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and latest, prequels (On the development of Psychohistory and on Hari Seldon, the brain behind the Foundations):&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Prelude to Foundation (1988)&lt;/li&gt;
  &lt;li&gt;Forward the Foundation (1993)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(as you might have guessed, the books without a brief explanation adjoining them have not been read yet.)&lt;/p&gt;

&lt;p&gt;Well, as any wise Pundit will have you know, one must say their closing prayers: my apologies for the overly long review, any typos and incorrect grammatical usage, and the possibly obvious lack of a proper edit (too close to my three-day deadline, oops).&lt;/p&gt;

&lt;p&gt;And then, that elusive section 7, Conclusion. The Foundation saga is a must-read for both the beginner to sci-fi and the seasoned sci-fi afficionado. Outside the sci-fi and all the fancy robots, tech and space travel, the series is a deep exploration of society, politics and ethics. If you haven’t read it yet, I highly recommend you do so. And if you have, I hope this review brings back memories fond and frustrating from the saga, as it did for me. Since this series has impacted me fairly, I’d like to plagiarize the Sunday times’ review of the Lord of the Rings and summarize:&lt;/p&gt;

&lt;p&gt;“&lt;em&gt;The science-fiction population is divided into two groups: those who have read the Foundation saga and those who are going to read it.&lt;/em&gt;”&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;That’s a wrap. Until next time on Saturday the fourteenth. Do ping me if you’ve got comments or suggestions. I’m very new to this business of blogging and could certainly use some help. You can reach me at the usual email address: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;kagaram@cse.iitb.ac.in&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Happy reading!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>But why is it so hard to build a habit? Might just light up some bulbs 💡</title>
   <link href="https://mathismusic.github.io/2024/07/06/self1/"/>
   <updated>2024-07-06T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2024/07/06/self1</id>
   <content type="html">&lt;p&gt;Most people know the familiar feeling of regret when they give up on developing a habit that they know is good for them. It’s a feeling that’s hard to shake off, and it’s a feeling that’s hard to ignore. It simply feels, well, unbearable to continue with the habit, and resistance wins. I have been wondering for a while now why this might be the case, and I will share here what I have found so far.&lt;/p&gt;

&lt;p&gt;The ancients developed habits and patterns of thinking for &lt;em&gt;immediate&lt;/em&gt; (and preferably, as comfortable as possible) survival - that was top priority. The modern age has made this mostly unneccessary, since we have the luxury of safety. However, the pattern of immediate comfort is still with us, though no longer optimal.&lt;/p&gt;

&lt;p&gt;The brain is still wired to seek out immediate comfort and/or avoid immediate discomfort. The big problem with this is that the habits that are good for us in the long run are often very uncomfortable in the short run. Let’s look at how a habit forms. This analysis is mostly based on &lt;sup id=&quot;fnref:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; by Hal Elrod.&lt;/p&gt;

&lt;p&gt;A good habit generally takes thirty days to form. I would like you to take a habit you want - typically, becoming a “morning person” or churning out that “morning workout” works for most people - and imagine yourself through the process below of developing that habit.&lt;/p&gt;

&lt;p&gt;The first two-three days comprise a sort of &lt;em&gt;honeymoon&lt;/em&gt; period, where the habit is new and exciting, and you are constantly dreaming of yourself with the benefits of the habit. But then they do not, of course, show up after two days. The next week, it is ridiculously &lt;em&gt;unbearable&lt;/em&gt; to continue the habit, as you believe less and less in its arrival. This is sort of like how we always expect that Amazon package to show up in two days, and when it doesn’t, we are &lt;em&gt;pretty&lt;/em&gt; impatient every day after that.&lt;/p&gt;

&lt;p&gt;A comical example of this phenomenon in real life is the abundance in parking space at the local gym just the week after New Year’s following long lines in the first week (yes, there was a study on this). &lt;!-- reference the study --&gt;&lt;/p&gt;

&lt;p&gt;After ten days, it is excruciating to continue for one more day simply with willpower, and this is where it starts to make sense to move it to auto-pilot, with techniques like habit stacking. A few benefits might start to show up after two weeks, but they are not &lt;em&gt;that&lt;/em&gt; significant. It is the &lt;em&gt;uncomfortable&lt;/em&gt; phase of the habit formation process. You are not experienced, and so are slightly less reluctant to continue. The habit is not yet &lt;em&gt;part of you&lt;/em&gt;, though, and its benefits are not great yet.&lt;/p&gt;

&lt;p&gt;After three weeks, the habit has now become a part of your routine, and you start to associate with it. The benefits are now starting to show up, and you see the light at the end of the tunnel.&lt;/p&gt;

&lt;p&gt;Quoting Hal Elrod in &lt;sup id=&quot;fnref:1:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;, “The third 10-day phase is crucial to sustaining your new habit, long term. The final 10 days is where you positively reinforce and associate pleasure with your new habit. You’ve been primarily associating pain and discomfort with it during the first 20 days. Instead of hating and resisting your new habit, you start feeling proud of yourself for making it this far.”&lt;/p&gt;

&lt;p&gt;This is the &lt;em&gt;unstoppable&lt;/em&gt; phase of the habit formation process. The habit is now slowly becoming a part of your identity, and you are starting to see the benefits of it. It is likely that you will continue the habit, since you have now &lt;em&gt;seen&lt;/em&gt; the benefits of it in your life.&lt;/p&gt;

&lt;p&gt;After thirty &lt;em&gt;consecutive&lt;/em&gt; days with the habit, it has become a part of your identity and you will continue with it for a while.&lt;/p&gt;

&lt;p&gt;It is difficult to build a good habit - there is no denying that - but it is &lt;em&gt;far&lt;/em&gt; better to spend thirty days of discomfort to get a lifetime of benefits - pounds of pain to get that habit always beats tons of regret, logically speaking.&lt;/p&gt;

&lt;p&gt;The problem is that as with the above process, the nice things about a habit are always &lt;em&gt;delayed&lt;/em&gt; with uncomfortable things in the short run. Our wiring of the brain to avoid immediate discomfort is quite difficult to avoid.&lt;/p&gt;

&lt;p&gt;However, when you realize that the benefits of a habit are simply delayed and not non-existent, and that the discomfort is temporary, it becomes &lt;em&gt;slightly&lt;/em&gt; easier to continue with the habit.&lt;/p&gt;

&lt;p&gt;To make it less difficult to build a habit, a few ideas follow.&lt;/p&gt;

&lt;p&gt;If you think about it, we have an identity about what kind of person we are. For example, some people might think of themselves as “night owls”. The ancients had their own identities; they were known by their identities.&lt;/p&gt;

&lt;p&gt;There is a difference between a person’s identity and character. Your identity is who you truly believe you, as a person are. Your character is how you function as a person. Some aspects of your character influence your interaction with the world, others influence your own personal feelings and happiness, and some are well, just hidden by will.&lt;/p&gt;

&lt;p&gt;Anyways, no surprise that your identity determines, along with your environment and opportunities, your character.&lt;/p&gt;

&lt;p&gt;The point is, a habit is simply a change in your character that you want to make. The best way to do that? Put it into your identity. You can’t control fully your environment (more on that later). But hell yeah you can control your identity. You can make it whatever you wish. Essentially, you now think of yourself as a “morning person” or a “workout person” to help build the corresponding habits of waking up early or working out.&lt;/p&gt;

&lt;p&gt;Well, the obvious fallacy in this argument is that it isn’t true &lt;em&gt;yet&lt;/em&gt; that you are a “morning person” or a “workout person”. How can you just “add” that into your identity when you have close to no overlap with it in terms of who you are currently?&lt;/p&gt;

&lt;p&gt;Valid point. The solution is to start to make it part of your identity. That is, to affirm and re-affirm that you are &lt;em&gt;becoming a&lt;/em&gt; morning person or a fit athlete. You are not lying to yourself here, and it is indeed true, when you start building the habit, that you are becoming a person with the habit. It is your identity now: I am learning this habit.&lt;/p&gt;

&lt;p&gt;The great thing about this is that you are tricked into continuing, using momentum. After a few days, the fact that you are becoming a morning person is confirmed by your beginning practice of waking up early, and you reinforce the identity. The next day, your growing identity gives you a bit of a push to continue.&lt;/p&gt;

&lt;p&gt;It is very much like the Duolingo streak, where you are tricked into continuing by the fact that you have a streak going.&lt;/p&gt;

&lt;p&gt;The all-important thing is to really &lt;em&gt;commit&lt;/em&gt; to becoming a morning person or a workout person. Only then can you believe that you are becoming one, and this identity trick will work. Committing is where 95% of the world struggles. They &lt;em&gt;want&lt;/em&gt; something, but are unwilling to really decide to get it - because will it really be that bad &lt;em&gt;now&lt;/em&gt; if I don’t make it?&lt;/p&gt;

&lt;p&gt;Yes - in the ancient times, and so they didn’t need any tricks to force them to make it. Today, thanks to a reasonably stable life for most people, the answer to the question is usually in the negative. And so one concludes that one doesn’t &lt;em&gt;need&lt;/em&gt; to do it so badly. The regret only comes years later, when the regret of not doing it is truly unbearable, knowing that the benefits of the habit would have been &lt;em&gt;so&lt;/em&gt; great in compounding over time.&lt;/p&gt;

&lt;p&gt;Once you are committed to building a habit, reinforce your identity as starting to become someone with the habit. With this identity and practicing the habit, after a week or so, your identity will already start to become “I am a morning person” or “I am a workout person”. That will go a great distance, and you have already won half the battle.&lt;/p&gt;

&lt;p&gt;The discomfort of building the habit is now acknowledged as a necessary part of the process, and now that it is in your identity, you will forage forward because that is who you are. Slowly, but surely, the new identity will push the habit into your character.&lt;/p&gt;

&lt;p&gt;The other thing that determines your character is your environment. You can probably guess what’s next. You want the habit in your character, why not put it in your environment too? Makes it even easier to get it into your character. Indeed it does! James Clear has a lot to say about this in &lt;sup id=&quot;fnref:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;, and for completeness I will try to present the essence of his ideas here.&lt;/p&gt;

&lt;p&gt;Suppose the lights are turned off and your bedroom is dark tomorrow morning at 7:00 AM. Would you, if not used to being up this early, go out of your way to get yourself up and out of bed? I certainly wouldn’t. But if the lights are on, the sun is in your face, and you can hear the hustle and bustle of the day outside, you are &lt;em&gt;much&lt;/em&gt; more likely to get up. I know I am. This is because your environment is now conducive to waking up early.&lt;/p&gt;

&lt;p&gt;The time of day did not change. It was the environment that changed, which changed your reaction along with it.&lt;/p&gt;

&lt;p&gt;James Clear suggests a ton of ways to make your environment conducive to building numerous habits, and I really recommend checking them out in &lt;sup id=&quot;fnref:2:1&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;; some of them have really helped me build some habits.&lt;/p&gt;

&lt;p&gt;For now, since I &lt;em&gt;think&lt;/em&gt; that a lot of people want to build the habit of waking up early, I’m going to detail Hal Elrod’s idea (in &lt;sup id=&quot;fnref:1:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt;) of making it &lt;em&gt;obvious&lt;/em&gt; to wake up early. If you want to build this too, I’d like you to imagine yourself through the process below.&lt;/p&gt;

&lt;p&gt;It starts by moving your alarm clock or phone to the other side of the room - near enough that it still gets you out of your sleep and irritates you enough to want to turn it off, but far enough that it can only be reached with at least a few seconds completely off the bed. In the morning, you are woken up and forced to walk and turn off the alarm.&lt;/p&gt;

&lt;p&gt;You are still probably only thinking about the discomfort of having to exist without that bed and blanket, and are really contemplating going back. You convince yourself it’s okay, since you are so tired and probably need the extra &lt;em&gt;ten minutes&lt;/em&gt; of sleep before your next alarm. That’s when you do step two: you have a glass of water ready to drink right next to the alarm.&lt;/p&gt;

&lt;p&gt;Most people are typically simply dehydrated in the morning, though it might seem like they are tired. Drinking a glass of water immediately after waking up can cause you to make the distinction. You drink the water, and are not really so tired anymore, but it’s still quite uncomfortable to be out of bed early, especially if there are people nearby who are still sleeping - because why me? The next thing is to go brush your teeth.&lt;/p&gt;

&lt;p&gt;This is typically hard, and is a sort of commitment to waking up now. We will see how to make that easier in a bit. Once you brush, you have more or less committed to being up. As a final step, keep whatever you use for your routine - your workout clothes, your journal, your book, your phone, your computer - on your desk to make it easy for you to start the routine. Et voila, you are go for the day.&lt;/p&gt;

&lt;p&gt;There are two things more important things that have existed as loopholes in the above process. The first is that - well, what if I am actually tired, even after drinking the water? Well, it is &lt;em&gt;very&lt;/em&gt; likely then, that you have not slept early enough to wake up at this time.&lt;/p&gt;

&lt;p&gt;Arguably a harder thing to fix is the sleep time - but that is precisely the thing that comes from your identity of starting to become a morning person. You are starting to wake up early, huh? You’ll need to sleep early then, otherwise you can’t. You are slowly committed to sleeping early. Another fix is simply to tell someone to force you into bed early.&lt;/p&gt;

&lt;p&gt;Our parents did this when we were young. An interesting fix is to simply time the lights and the internet to go off at your bedtime, leaving you with no option but to sleep.&lt;/p&gt;

&lt;p&gt;The second loophole is that of deciding to go to brush, i.e. starting the day at this time. Again, commitment is a fix. But there is another helpful technique here. It is known that the last thoughts before sleep is among the first thoughts after wake up. So, if you set your intentions the night before and take responsibility then for giving you some excitement or deadline for the next day, you are very likely to be pinged by the same thought in the morning, that can make all the difference in getting you to start the day then.&lt;/p&gt;

&lt;p&gt;To summarize, we have seen two ways that can help make the process of building a habit less uncomfortable and more doable - by making it part of your identity and by making it part of your environment. Crudely put, the first is a mental trick, and the second is a physical trick.&lt;/p&gt;

&lt;p&gt;Of course, there are others; one famous person times the following message “I am still slouching in bed” to be sent out publicly on Twitter at 6:00 AM the next day, and the embarrassment of that gets him out five minutes before, to push the sending back to the next morning. It’s what James Clear calls “Make it inevitable” in &lt;sup id=&quot;fnref:2:2&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; - there is simply no other option but to follow through.&lt;/p&gt;

&lt;p&gt;Another is what is called habit stacking (see &lt;sup id=&quot;fnref:2:3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:2&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;), where it is in your routine to do something after/during something else you already do. For example, one techy kid connected his ipad’s internet to his gym cycle, so that he could only use watch Netflix while cycling. Or to time the internet to go off after dinner.&lt;/p&gt;

&lt;p&gt;This is a great idea and acts like a walker till you can walk on your own. However, there is a caevat. It is a great way to start building a habit, but it is not a great way to sustain it. The idea is to make the habit so much a part of your identity and environment that you don’t need the walker anymore.&lt;/p&gt;

&lt;p&gt;The last part of this article is about the habit-building process and how we are often miles off in our expectation of how it will be. The idea is very simple.&lt;/p&gt;

&lt;blockquote&gt;

Most people overestimate what they can do in a day or week and underestimate what they can do in six months.

&lt;/blockquote&gt;

&lt;p&gt;Many people might relate to this. I do, surely. The reason for this is quite simple - (1) our society at large believes in overnight successes, which are never close to the whole truth, never mind what the media says about it, and (2) we are terrible at estimating the power of compounding. This mindset is remedied over time, as you experience more. The important thing is to reinforce the fact that the mindset is not correct from your own personal experiences.&lt;/p&gt;

&lt;p&gt;Of course, this mindset is not conducive to building habits, since the benefits of habits show up in a manner exactly opposite to what is expected. Understanding this mindset conciously gives a plethora of ways to build habits and avoid it from affecting you.&lt;/p&gt;

&lt;p&gt;For example, one way to realize that “missing it twice” isn’t the way to go. Missing it once is okay. Circumstances could force it. But the moment you miss it once the circumstance is no more an obstacle, it compounds and is the beginning of a new habit - the inverse.&lt;/p&gt;

&lt;p&gt;Another example is that of &lt;em&gt;atomic&lt;/em&gt; habits, advocated by James Clear in the epoynmous book. He suggests that you should make your habit practice so small that they are easy to do, however badly you overestimate your day and realize a shortage of time. For example, if your goal is to wake up at 6:00 AM regularly, make sure for the first week that your alarm is set five minutes earlier than usual.&lt;/p&gt;

&lt;p&gt;That’s it. It’s very hard to resist it now, since it doesn’t really seem like a change. The most important thing is showing up for the habit. Once five minutes earlier becomes your new normal, you can move it to ten minutes earlier, and so on. This is the idea of making the habit so small that it is hard to resist.&lt;/p&gt;

&lt;p&gt;That the benefits of the habit will follow in full in due time follows from the fact that these changes compound crazily over time, however much our underestimation of the power of these atomic changes discourages us. Ask any bodybuilder.&lt;/p&gt;

&lt;p&gt;In short, trust in the compound effect. The most successful people are not overnight successes. It has taken years of struggle to get to where they are. It is laughably stupid to think that you can get to where they are in a day or a week. But it is also equally stupid to think that you can’t get to where they are in a year or two. The power of compounding is immense, and it is the most important thing to remember when building habits.&lt;/p&gt;

&lt;!-- &lt;blockquote&gt; &quot;Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.&quot; - Albert Schweitzer &lt;/blockquote&gt; --&gt;

&lt;!-- the can and over under estimate --&gt;

&lt;p&gt;To conclude, building a habit is not an easy process, but the right perspective and understanding of the process, coupled with a conducive environment and identity, can make it much easier. You’re en route to your wildest dreams, and the only thing stopping you is you. Give it a shot.
&lt;!-- It is --&gt;
&lt;!-- funny how we have got to the point where we have to _trick_ ourselves into doing what is good for us. But well see good for us has changed over time. --&gt;&lt;/p&gt;

&lt;p&gt;If this was a substantial light bulb for you, dear reader, I am glad for you. You see, a &lt;em&gt;very&lt;/em&gt; large proportion of the world - 95% - is living a life of mediocrity and putting off (and regretting) the things that are good for them (see &lt;sup id=&quot;fnref:1:3&quot; role=&quot;doc-noteref&quot;&gt;&lt;a href=&quot;#fn:1&quot; class=&quot;footnote&quot; rel=&quot;footnote&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; for more details). I believe humans are far more capable than that, and I hope that a better future awaits us. I will try to do my bit. I hope you will too, now.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Acknowledgements: This is mostly just techniques from a few remarkable people and my own experiences as I have tried to build habits. I have tried to put them together in a coherent manner, and I really do hope it helps you, if you think you needed it.&lt;/p&gt;

&lt;!-- clear

identity - make it satisfying
environment - make it obvious
commitment - make it inevitable
habit stacking - make it obvious
podcast

identity
small steps -easy
overestimate and underestimate
don&apos;t miss it twice

hal

the habit process
snooze proof
tmm --&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;div class=&quot;footnotes&quot; role=&quot;doc-endnotes&quot;&gt;
  &lt;ol&gt;
    &lt;li id=&quot;fn:1&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;Hal Elrod, &lt;em&gt;The Miracle Morning&lt;/em&gt;. &lt;a href=&quot;https://www.miraclemorning.com/&quot;&gt;website&lt;/a&gt;. &lt;a href=&quot;#fnref:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt; &lt;a href=&quot;#fnref:1:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt; &lt;a href=&quot;#fnref:1:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;3&lt;/sup&gt;&lt;/a&gt; &lt;a href=&quot;#fnref:1:3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;4&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
    &lt;li id=&quot;fn:2&quot; role=&quot;doc-endnote&quot;&gt;
      &lt;p&gt;James Clear, &lt;em&gt;Atomic Habits&lt;/em&gt;. &lt;a href=&quot;https://jamesclear.com/&quot;&gt;website&lt;/a&gt;. Also the Rich Roll podcast with James Clear. &lt;a href=&quot;https://www.richroll.com/podcast/james-clear-442/&quot;&gt;link&lt;/a&gt;. &lt;a href=&quot;#fnref:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;/a&gt; &lt;a href=&quot;#fnref:2:1&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt; &lt;a href=&quot;#fnref:2:2&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;3&lt;/sup&gt;&lt;/a&gt; &lt;a href=&quot;#fnref:2:3&quot; class=&quot;reversefootnote&quot; role=&quot;doc-backlink&quot;&gt;&amp;#8617;&lt;sup&gt;4&lt;/sup&gt;&lt;/a&gt;&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Approximating the maximum weight of a triangle-free subgraph</title>
   <link href="https://mathismusic.github.io/2024/03/03/Diwan/"/>
   <updated>2024-03-03T00:00:00+00:00</updated>
   <id>https://mathismusic.github.io/website2026/2024/03/03/Diwan</id>
   <content type="html">&lt;p&gt;This is a write-up of a problem that appeared on one of my course tests. The problem is as follows:&lt;/p&gt;

&lt;div class=&quot;message&quot;&gt;
  &lt;p&gt;
    Let \(G\) be a simple undirected graph with positive integer edge-weights. A subgraph of \(G\) is called triangle-free if it does not contain any cycle of length 3 (aka no triangles). The problem is to find a maximum-weight triangle-free subgraph of \(G\).
  &lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;The problem is \(NP\)-hard, so we might as well try approximating it instead. The most natural triangle-free subgraphs are the bipartite subgraphs of \(G\) - how large a bipartite subgraph can we construct from \(G\) in polynomial time?&lt;/p&gt;

&lt;div class=&quot;message&quot;&gt;
  &lt;p&gt;
    Show how to compute a bipartite subgraph of weight at least \(W/2\), where \(W\) is the sum of the weights of the edges in \(G\).
  &lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hint 1: The problem is a classic example of a greedy algorithm.&lt;/p&gt;

&lt;p&gt;Hint 2: Can you guarantee that for every vertex \(v\), the edge weight between \(v\) and its neighbors in its part is at most the edge weight between \(v\) and its neighbors in the other part? That would imply the problem.&lt;/p&gt;

&lt;p&gt;Hint 3: Starting from an arbitrary partition and then greedily moving vertices across the parts may not be a good idea. Start from empty bins. There is a \(\mathcal{O}(n + m)\) time algorithm.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Solution: Set up two empty bins, which will serve as the bipartition. Order the vertices arbitrarily - \(v_1, …, v_n\). Starting from \(i = 1\), put \(v_i\) into the bin with the smaller total edge weight to the vertices already in the bin. Notice that each edge of the graph will be looked at precisely once, and at least half the total weight of the edges goes across the bins. The running time is the sum of the degrees + \(cn\) overhead - \(\mathcal{O}(n + m)\).&lt;/p&gt;

&lt;p&gt;The motivation for this algorithm comes from the following inductive proof of the existence of such a subgraph. We induct on the number of vertices \(n\) - the statement is vacuously true when \(n = 1\). For \(n = k+1\), delete an arbitrary vertex \(v\); the rest of the graph, by hypothesis, has such a subgraph - suppose the partition is \([U, V]\). Finally, put \(v\) into the bin with the smaller total edge weight to the vertices already in the bin.&lt;/p&gt;

&lt;hr /&gt;
&lt;div&gt;
&lt;p&gt;
Before we get back to our original problem, let us consider the &quot;complement&quot; problem: finding a minimum weight subgraph \(H&apos;\) such that every triangle in \(G\) contains at least one edge of \(H&apos;\). It is clear that any solution \(H&apos;\) when complemented in \(G\) is triangle-free. Can we manage to get a low-enough solution to the complement, then?
&lt;/p&gt;&lt;/div&gt;
&lt;div class=&quot;message&quot;&gt;
  &lt;p&gt;
    Let \(\text{OPT}_2\) denote the weight of the minimum weight subgraph \(H&apos;\) such that every triangle in \(G\) contains at least one edge of \(H&apos;\). Describe an algorithm that computes a subgraph of weight at most \(3\text{OPT}_2\).
  &lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hint 1: LP rounding/Primal Dual.&lt;/p&gt;
&lt;p&gt;
Solution: We first write down the LP (linear program) corresponding to the relaxation of the complement problem. Letting \(x_e\) denote the variable representing whether edge \(e\) is in our subgraph or not, we have the following LP relaxation:
&lt;/p&gt;
&lt;p&gt;\(\begin{aligned}
\text{minimize} \quad &amp;amp; \sum_{e \in E} w_e x_e \\
\text{subject to} \quad &amp;amp; x_{uv} + x_{vw} + x_{wu} \geq 1 \quad \text{for all triangles $uvw$ in $G$} \\
&amp;amp; x_e \in \{0, 1\} \quad \text{for all $e \in E$}.
\end{aligned}\)&lt;/p&gt;

&lt;p&gt;
This is actually an instance of the [set cover](https://en.wikipedia.org/wiki/Set_cover_problem) problem, which has an \(f\)-approximation rounding/Primal Dual algorithm (where \(f\) is the maximum number of sets containing an element of the universe - here, the elements are the triangles of the graph \(G\) and the sets are the edges; each edge covers triangles it is a part of and each triangle is covered by precisely 3 edges). 
&lt;/p&gt;

&lt;p&gt;
The rounding algorithm is easy; we solve the LP relaxation optimally, and then round every \(x_e\) with \(x_e^* \geq 1/3\) (\(*\) denoting the optimal solution) to \(1\), and the rest to \(0\). The resulting solution is integral, feasible for the integer linear program, and has scaled up the objective by at most a factor of \(3\).
&lt;/p&gt;

&lt;p&gt;The Primal Dual algorithm is also fairly simple, but we do not go into that here, at the moment.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;We are ready for the first approximation algorithm for the original problem.&lt;/p&gt;

&lt;div class=&quot;message&quot;&gt;
  &lt;p&gt;
    Let \(\text{OPT}_1\) denote the weight of the maximum weight triangle-free subgraph of \(G\). Describe an algorithm that computes a subgraph of weight at least \(\frac{3}{5}\text{OPT}_1\).
  &lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;Hint 1: Leverage &lt;em&gt;both&lt;/em&gt; algorithms we have already seen. How do you leverage two algorithms to get the best of both worlds?&lt;/p&gt;

&lt;p&gt;
Hint 2: Suppose the optimal value \(\text{OPT}_1 \leq \frac{5W}{6}\). Are we done? If this is not the case, does the algorithm we have for the complement problem help us?
&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;
Solution: Simply run both algorithms (of course, after running the second algorithm and getting a subgraph \(H&apos;\) we must complement it in \(G\) to get a triangle-free subgraph), and take the larger of the two solutions. That way we are able to avoid the worst-case scenarios of each algorithm individually, if the worst-case scenarios are different for the two (they happen to be beautifully complementary in this case). Let \(h_1\) be the weight of the graph returned by the first algorithm, \(h_2\) by the second, and \(\mathcal{A} = \max(h_1, h_2)\) is the value returned by our final algorithm.
&lt;/p&gt;

&lt;p&gt;We have:&lt;/p&gt;

\[\begin{aligned}h_1 &amp;amp;\geq \frac{W}{2} = \frac{3}{5}\cdot\frac{5W}{6},\\
h_2 &amp;amp;\geq W - 3\text{OPT}_2 = W - 3(W - \text{OPT}_1) = 3\text{OPT}_1 - 2W.\end{aligned}\]

&lt;p&gt;
If the optimal value \(\text{OPT}_1\) is at most \(\frac{5W}{6}\), then indeed, \(\mathcal{A} \geq h_1 \geq \frac{3}{5}\text{OPT}_1\). If this is not the case, then \(\text{OPT}_1 &amp;gt; \frac{5W}{6}\), and 
&lt;/p&gt;

\[\mathcal{A} \geq h_2 \geq 3\text{OPT}_1 - 2W \geq 3\text{OPT}_1 - 2\left(\frac{6\text{OPT}_1}{5}\right) = \frac{3}{5}\text{OPT}_1.\]

&lt;p&gt;Incredible, right?&lt;/p&gt;

&lt;p&gt;
It is also easy to see that bettering each of the two algorithms individually could improve the approximation factor of the final algorithm. The first algorithm is actually the best we can hope for; the max weight of a bipartite subgraph of the complete uniform-weight graph on \(n\) vertices is \(W\left(\frac{1}{2} + o_n(1)\right)\). The second algorithm, on the other hand, can be improved (thanks not to the fact that it is a set-cover; for the set cover that is the best we can hope for with that formulation, since the integrality gap is \(3\)) to an approximation factor of \(2\)!
&lt;/p&gt;
&lt;p&gt;
The factor \(2\) approximation then establishes a \(2/3\)-approximation for our final algorithm, by completely analogous reasoning as above. It remains to show the \(2\)-approximation for the second algorithm.
&lt;/p&gt;
&lt;hr /&gt;

&lt;div class=&quot;message&quot;&gt;
  &lt;p&gt;
    Describe an algorithm that computes a subgraph of weight at most \(2\text{OPT}_2\).
  &lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
Hint 1: Induct on the number of edges of \(G\). You wish for some \(x_e\) to be at least \(1/2\) so you can round it up to \(1\) and only scale the objective by a factor of \(2\). If there is an edge \(e\) with \(x_e^* = 0\), use induction to reduce the problem to a smaller graph. You might need to have to solve the LP optimally each time down this iterative reduction, this is okay.
&lt;/p&gt;
&lt;p&gt;
Hint 2: The bad case is then when every \(x_e\) is positive. Complementary slackness comes to the rescue. Compute the exact dual optimal solution. Is this small enough that a \(2\)-approximation to this is quite easy to find?
&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;
Solution: We induct on the number of edges in the graph.
&lt;/p&gt;

&lt;p&gt;(the reader is invited to finish the solution until the author gets around to it 🫣)&lt;/p&gt;
</content>
 </entry>
 

</feed>
