<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Athar Qadri</title><description>Personal essays on craft, focus, and the long game. Written slowly, published rarely.</description><link>https://atharqadri.netlify.app/</link><language>en</language><item><title>Everything is Math</title><link>https://atharqadri.netlify.app/posts/math-behind-ai/</link><guid isPermaLink="true">https://atharqadri.netlify.app/posts/math-behind-ai/</guid><description>Everyone&apos;s talking about the latest AI breakthroughs, but few are talking about the math quietly making them possible. This post digs into the simple ideas that power today&apos;s LLMs</description><pubDate>Sat, 01 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;It&apos;s strange how little attention (pun intended) gets paid to the
math that is actually powering the rise of LLMs. To give you an idea, the advent of LLMs
was around 2017 when researchers at Google published a ground-breaking paper&lt;sup&gt;&lt;a href=&quot;#fn1&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;,
but the one algorithm (out of many)
that made it possible had already been lying there for around 170 years.&lt;sup&gt;&lt;a href=&quot;#fn2&quot;&gt;[2]&lt;/a&gt;&lt;/sup&gt; While everyone&apos;s
chasing the latest AI breakthrough, I dug into the math that actually
powers LLMs, and it&apos;s amazing how simple a function such as ReLU
can help power a system that mimics a human brain and does it pretty well.&lt;/p&gt;
&lt;p&gt;This write-up is an appreciation to all the mathematians that have made it possible.&lt;/p&gt;
&lt;h2&gt;ReLU (Rectified Linear Unit)&lt;/h2&gt;
&lt;p&gt;In an LLM, this tiny rule is applied to activate a neuron through a simple rule:
&apos;If the number is negative, make it zero. If it&apos;s positive, do nothing.&apos;&lt;/p&gt;
&lt;p&gt;Without something like ReLU (or its cousins), the entire LLM would collapse into
one big linear equation and couldn’t learn complex language patterns.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/relu.png&quot; alt=&quot;ReLU activation function: flat at zero for negative inputs, rising linearly for positive inputs&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Euler&apos;s Constant (&lt;em&gt;e&lt;/em&gt;)&lt;/h2&gt;
&lt;section&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;2.7182817...
2.7182817...
&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;2.7182817...&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;p&gt;The constant itself had already been there for decades but it was Leonhard Euler
who gave it a name. In 1727, when he was just 21 years old, Euler used the letter
&lt;em&gt;e&lt;/em&gt; for it in a paper recording his own experiments on the firing of a cannon.&lt;sup&gt;&lt;a href=&quot;#fn3&quot;&gt;[3]&lt;/a&gt;&lt;/sup&gt;
The paper wasn&apos;t published until 1862, nearly 80 years after his death.&lt;/p&gt;
&lt;p&gt;From being used in financial calculations to radioactive decay, it has found
its way into the world of AI and machine learning and that brings us to Sigmoid Functions.&lt;/p&gt;
&lt;h2&gt;Sigmoid Function&lt;/h2&gt;
&lt;p&gt;The first sigmoid function was introduced by Pierre François Verhulst, a Belgian mathematician,
in year 1838 in his paper &lt;sup&gt;&lt;a href=&quot;#fn4&quot;&gt;[4]&lt;/a&gt;&lt;/sup&gt; on population growth. LLMs use the standard logistic function, a type of sigmoid function, that maps any real input onto a value between zero and one:&lt;/p&gt;
&lt;section&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;σ(x)=11+e−x
\sigma(x) = \frac{1}{1 + e^{-x}}
&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;σ&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;−&lt;/span&gt;&lt;span&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;p&gt;Where ReLU is sharp and one-sided, sigmoid is smooth and symmetric.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/sigmoid.png&quot; alt=&quot;Sigmoid function: S-shaped curve&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Because its output is always bounded in &lt;span&gt;&lt;span&gt;(0,1)(0, 1)&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, sigmoid is useful when you
need a probability: the neuron&apos;s decision making ability that a token belongs
to a given class, for example.&lt;/p&gt;
&lt;h2&gt;Softmax&lt;/h2&gt;
&lt;section&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;softmax(zi)=ezi∑j=1nezj
\text{softmax}(z_i) = \frac{e^{z_i}}{\sum_{j=1}^{n} e^{z_j}}
&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;softmax&lt;/span&gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&lt;span&gt;z&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;∑&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;j&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;z&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;j&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;z&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/section&gt;&lt;p&gt;Sigmoid handles a single binary decision: it gives you one probability of how likely
the answer is between two options. For an LLM to choose its next token
from its vocabulary, it needs to give it a probability distribution.
That&apos;s what softmax is for: it takes a whole list of raw scores
(called logits) and turns them into a proper probability distribution, where every
value sits between 0 and 1 and the whole set adds up to 1.&lt;/p&gt;
&lt;p&gt;Let&apos;s say the model is finishing the sentence
&quot;The cat sat on the ___.&quot; Before softmax, each word just has a raw score.
After softmax, those scores become a probability distribution the model can actually sample from:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Token&lt;/th&gt;
&lt;th&gt;Logit (before softmax)&lt;/th&gt;
&lt;th&gt;Probability (after softmax)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;mat&lt;/td&gt;
&lt;td&gt;2.5&lt;/td&gt;
&lt;td&gt;0.710&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;floor&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;0.158&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;chair&lt;/td&gt;
&lt;td&gt;0.5&lt;/td&gt;
&lt;td&gt;0.096&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;roof&lt;/td&gt;
&lt;td&gt;-0.5&lt;/td&gt;
&lt;td&gt;0.035&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The term &quot;softmax&quot; wasn&apos;t coined until 1989, by researcher John S. Bridle, who
described it as a smooth, differentiable stand-in for simply picking the largest
value.&lt;sup&gt;&lt;a href=&quot;#fn5&quot;&gt;[5]&lt;/a&gt;&lt;/sup&gt; But the shape of the function is much older and the physicists were already
using in the 1860s to describe how particles spread across energy states.&lt;/p&gt;
&lt;p&gt;To be continued...&lt;/p&gt;
&lt;hr /&gt;
&lt;section&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;https://arxiv.org/abs/1706.03762 &lt;a href=&quot;#fnref1&quot;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;http://sites.mathdoc.fr/cgi-bin/oeitem?id=OE_CAUCHY_1_10_399_1 &lt;a href=&quot;#fnref2&quot;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;https://scholarlycommons.pacific.edu/euler-works/853/ &lt;a href=&quot;#fnref3&quot;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;https://www.researchgate.net/publication/5086329_Pierre-Francois_Verhulst_et_la_loi_logistique_de_la_population &lt;a href=&quot;#fnref4&quot;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;https://arxiv.org/pdf/1704.00805 &lt;a href=&quot;#fnref5&quot;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</content:encoded></item></channel></rss>