# The minimal working example of README.md, which shows this file; alhassy.com publishes it, by a :REDIRECT:.

* A tiny function

We sum the first =n= [[tooltip:odd][An integer 2i - 1, for some i ≥ 1]] numbers by doc:cl-loop; place the
cursor after the last parenthesis and press 〔C-x C-e〕 to define it.
#+begin_src emacs-lisp
(defun sum-odds (n)
  "Return 1 + 3 + ⋯ + (2n - 1)."
  (cl-loop for i from 1 to n sum (- (* 2 i) 1)))
#+end_src

#+begin_details Peek: the first few values :let (N 4)
=(sum-odds N)= is the sum of the first N odd numbers. In order:
| =n=            | 1 | 2 | 3 |  4 |
| =(sum-odds n)= | 1 | 4 | 9 | 16 |
These are squares! <<squares>> We prove it below.
#+end_details

* How the loop accumulates

Each step adds the next odd number to the running sum:
#+begin_graph :rankdir LR
+ 0
  + add 1 :: 1
    + add 3 :: 4
      + add 5 :: 9
        + add 7 :: 16
#+end_graph

* Why squares?

The squares are no coincidence:
#+begin_math :let (Σ "\\sum_{i=1}^{n}")
  Σ (2i - 1)
={ Split the sum }
  2 · {Σ i} - {Σ 1}
={ Gauss: ${Σ i} = n(n+1)/2$; and $n$ ones sum to $teal:n$ }
  n(n + 1) - teal:n
={ Distribute, then cancel }
  n^2   violet:<<Odd>>
#+end_math

Hence, by Odd, =(sum-odds n)= is $n^2$. badge:sum-odds|n²|teal