Abstract Nonsense

A place for musings, observations, design notes, code snippets - my thought gists.

Spifflicating with Spivak's Calculus

Continuing on from my collection of humorous mathematical aphorisms, today’s excerpt is an exercise from Calculus by Michael Spivak (4 ed.).

Chapter 10, Question 2. Find $f'(x)$ for each of the following functions $f$. (It took the author 20 minutes to compute the derivatives for the answer section, and it should not take you much longer: Although rapid calculation is not the goal of mathematics, if you hope to treat theoretical applications of the Chain Rule with aplomb, these concrete applications should be child’s play–mathematicians like to pretend that they can’t even add, but most of them can when they have to.)

i. $f(x)=\sin((x+1)^2(x+2))$

ii. $f(x)=\sin^3(x^2+\sin x)$

iii. $f(x) = \sin^2((x + \sin x)^2)$

iv. $f(x)=\sin\left( \frac{x^3}{\cos x^3}\right)$

v. $f(x)=\sin(x\sin x) + \sin(\sin x^2)$

vi. $f(x)=(\cos x)^{31^2}$

vii. $f(x)=\sin^2 x \sin x^2 \sin^2 x^2$

viii. $f(x)=\sin^3(\sin^2 (\sin x))$

ix. $f(x)=(x+\sin^5 x)^6$

x. $f(x)=\sin(\sin(\sin(\sin(\sin x))))$

xi. $f(x)=\sin((\sin^7 x^7 +1)^7)$

xii. $f(x)=(((x^2+x)^3+x)^4+x)^5$

xiii. $f(x)=\sin(x^2+\sin(x^2+\sin x^2))$

xiv. $f(x)=\sin(6\cos(6\sin(6\cos 6x)))$

xv. $f(x)=\frac{\sin x^2 \sin^2 x}{1+\sin x}$

xvi. $f(x)=\frac{1}{x-\frac{2}{x+\sin x}}$

xvii. $f(x)=\sin\left( \frac{x^3}{\sin\left( \frac{x^3}{\sin x} \right)} \right)$

xviii. $f(x)=\sin\left( \frac{x}{x-\sin\left( \frac{x}{x-\sin x}\right)} \right)$

I did the first 8 questions in ~8 minutes before the tedium got to me, so I’m going to assume Spivak’s estimate is at least on the correct order of magnitude.

Credit: Leo Fouchè for sending this one through.

Keyslip

I’ve always been a fan of eclectic words. So, inspired by The Dictionary of Obscure Sorrows, I thought I’d coin my own neologism:

keyslip

  1. The sudden, sinking pang of anxiety that accompanies the realisation that one has been typing into the wrong buffer, particularly after a protracted sequence of keystrokes: Always ls a path before you rm it, otherwise you might suffer from a keyslip.
  2. By extension: the interval of frantic clicking that follows sense 1, as the afflicted person attempts to locate where the keystrokes actually landed: Fitts’ law feels like a betrayal after a keyslip.

Pseudorandom number generation in JAX

Recently I’ve been working on a statistics library in Typst called distroMore to come soon. Typst is architected with an incremental compiler, and pairs it with pure functionsAlmost all functions in Typst are pure, with a few exceptions to facilitate snappy real-time compilation.

The problem is, what to do about random number generation when your functions are supposed to be referentially transparent? Well, thankfully that’s a solved problem with a neat solution. For instance, JAX relies on an explicit ‘key’ value, that is consumed by the PRNG, and returns an updated state that is then passed back into the PRNG to generate the next random sample.

PRNG-generated sequences are not truly random because they are actually determined by their initial value, which is typically referred to as the seed, and each step of random sampling is a deterministic function of some state that is carried over from a sample to the next.

Importantly, they warn you to never re-use the same key, else:

The rule of thumb is: never reuse keys (unless you want identical outputs). Reusing the same state will cause sadness and monotony, depriving the end user of lifegiving chaos.

Maybe I should start a collection of humorous academic refrains….

In Typst, there’s a package called suiji that provides pure functions for random-number generation. That allows me to use it within my distro package to produce random variates from distributions using inverse transform sampling:

typst
#import "@preview/suiji:0.5.1": *
#import "../lib.typ": categorical // my `distro` package

#let n_samples = 1000
#let Cat = categorical.new((0.1, 0.3, 0.2, 0.4))
#let counts = (0,) * Cat.weights.len()
#let (rng, u) = (gen-rng-f(42), none)

#for _ in range(n_samples) {
  (rng, u) = uniform-f(rng)
  let result = categorical.sample(Cat, u)
  counts.at(result) += 1
}

Project Hail Mary by Andy Weir

I really enjoyed this book, I thought it was an excellent read.

I found the quality of the writing to be a bit haphazard at the start, but the Haldeman-esque humour and storyline more than make up for that. Weir does a superb job of capturing the pure joy in experimental and theoretical physics without detracting from the pacing or science-fiction nature of the book.

The “vaguely-crustacean alien meets human and becomes intrepid buddy explorer” plotline was delightful, and reminded me of a combination of Arrival and Arthur C. Clarke’s Rendezvous with Rama series.

I haven’t seen the film yet, but I hope it matches the book in quality and enthusiasm. I finished this read in just a day!

Favicon

I’ve added an animated favicon to the site:To avoid becoming distracting, it only plays once, on page load, instead of indefinitely looping.

The design has a few motifs:

  • An upper case $\Lambda$ symbol: a nod to both the Lambda Calculus and the A in Abstract.
  • That morphs into an uppercase blackboard bold $\mathbb{N}$ symbol: the set of natural numbers and the N in Nonsense.
  • All of which is surrounded by square brackets (an array) to give the favicon a bit more presence.
  • Lastly, the serifs are arrow-heads, evoking morphisms from Category Theory.

Full disclosure: I tried multiple times to manually craft an SVG that had all the above components, but I just couldn’t get it right. Thus, inspired by a Google blog post announcing improved SVG design capabilities in the Gemini 3.1 Pro model, I decided to give it a try. It took many, many iterations to coerce Gemini’s output into something I was satisfied with, but I think the end result is pretty good.There’s some issues with the animation keyframes splines not interpolating as smoothly as I’d like, but that’s a problem for another day.

Since SVG favicons are now Baseline-supported across all major browsers, I didn’t need to worry about fallback PNGs and .ico files, which was a nice bonus. It’s also picked up by Google Search and other platforms. Lastly, since I can embed CSS into the SVG file, it also supports dark modes via a prefers-color-scheme media query.

I used an object tag to embed the favicon file above, to ensure that the animation played correctly on page load. I noticed some inconsistencies between browsers with respect to animated SVG support using an img tag.