Notes from the whiteboard.
Technical write-ups, war stories and the occasional rant about floating point. Click a post to expand it.
Why your CFL condition is lying to you
The Courant–Friedrichs–Lewy condition \(\;c\,\Delta t / \Delta x \le 1\;\) guarantees stability for many explicit schemes. Stability is necessary for convergence, but it does not promise accuracy.
Run the upwind scheme on a square wave at Courant number 0.5 and the result is stable, and wrong: the edges smear out by numerical diffusion. Lax–Wendroff keeps the edges sharper but adds wiggles. Both satisfy CFL.
$$u_i^{n+1} = u_i^n - \frac{\nu}{2}(u_{i+1}^n - u_{i-1}^n) + \frac{\nu^2}{2}(u_{i+1}^n - 2u_i^n + u_{i-1}^n)$$The fix is not a smaller time step. It is a modified-equation analysis that tells you which error term dominates, followed by a flux limiter that chooses between the two behaviors locally.
Encoding Sudoku in 729 variables (and why that is too many)
The textbook encoding uses one Boolean per (row, column, digit), so \(9^3 = 729\) variables and about 12,000 clauses. Modern solvers finish in milliseconds, so why optimize?
Because your real problem is not Sudoku. It is a 40,000-slot timetable with the same structure. Fixing given cells by preprocessing, then using sequential-counter at-most-one encodings, cuts clause count by 70% and makes propagation stronger.
Memoization is not dynamic programming
Memoization is a technique. Dynamic programming is a proof that the problem has optimal substructure and overlapping subproblems. You can memoize a function that has neither, and you will only gain a large hash table.
Before writing code, write the recurrence and state its domain. If you cannot bound the number of distinct states, you do not have a DP yet.
$$\text{time} = (\#\text{states}) \times (\text{work per state})$$The duality gap is a feature, not a bug
When a MILP solver stops with a 0.8% gap, you have something better than an answer: a certified bound on how far from optimal you are. A heuristic that reports no gap may be 0.1% from optimal, or 40%.
We report the gap in every deliverable. Clients learn quickly to stop asking for "the optimal solution" and start asking "how close is close enough?"
Ten thousand random numbers walk into a bar
Monte Carlo error shrinks like \(1/\sqrt{n}\). To get one more correct digit, you need 100 times more samples. Quasi-Monte Carlo sequences such as Sobol' can approach \(1/n\) for smooth integrands.
The catch: the advantage fades in high dimensions unless the integrand has low effective dimension. Always check before you switch.
We proved a 30-line function correct. It took three weeks.
A client's fixed-point rounding routine was 30 lines of C. Its Lean specification was 12 lines. The proof was 1,400 lines, mostly about integer overflow at the boundaries.
Was it worth it? The proof found one case where the routine rounded the wrong way for exactly one input out of \(2^{32}\). That input was a real price in their system.