The 24 Mental Moves School of Engineering, Nazarbayev University
A Mental Move is a habit for turning a problem into a computation: a question to ask before
writing code, with a quantity that the code must keep invariant. The moves are catalogued in
engthink.constants_benchmarks.MENTAL_MOVES_DB, each with the lecture that introduces it and the
function of the package that carries it out.
Which move to try ¶ Situation Moves Module Small increments vanish next to a large value, or a computed variance is negative 1–4 representation_scalingAn experiment or a simulation has many dimensional parameters 5 representation_scalingA loop with several pointers or a protocol with several states keeps failing at the boundaries 6 representation_scalingA computation is too slow, and the reason is not yet known 7–10 invariants_complexityA design value is hard to compute directly, but a given value is easy to test 11 divide_spatialLong-range sums or convolutions cost O ( N 2 ) \mathcal{O}(N^2) O ( N 2 ) 12–14 divide_spatialA recursion solves the same subproblem many times, or future inputs are uncertain 15–16 dynamic_optimalityA greedy rule looks attractive, or a search explores far more than it needs 17–18 greedy_heuristic_searchA new combinatorial puzzle or a project schedule has to be solved 19–20 reductions_constraintsA fault must be found with few tests, or a stream must be summarized in fixed memory 21–22 information_streamsLocal interactions may produce a sudden change of the whole system 23 emergence_verificationA fast heuristic or generated code passes a few hand-picked tests 24 emergence_verification
The moves ¶ Part I. Representation, precision and dimensional invariants ¶ Move Lecture Function What to keep invariant 1. Inspect the Bit Budget 0 representation_scaling.ieee754_float64_inspectx = (-1)^s (1 + m/2^52) 2^e; spacing = ulp(x)2. Compensate Lost Low-Order Bits 0 representation_scaling.kahan_babuska_sums_k + c_k tracks exact running sum to O(eps)3. Shift Before You Exponentiate 0 representation_scaling.stable_logsumexplog sum exp(z) = m + log sum exp(z - m)4. Maintain Centered Running Moments 0 representation_scaling.welford_streaming_statsM2_k = M2_{k-1} + (x_k - mu_{k-1})(x_k - mu_k) >= 05. Nondimensionalize Before You Sweep 1 representation_scaling.buckingham_pi_nullspaceD @ pi = 0 collapses n vars onto n - rank(D) groups6. Write the Loop Invariant Before the Loop 2 representation_scaling.dutch_national_flag_partitionarr[:lo] < p1 <= arr[lo:mid] <= p2 < arr[hi:]
Part II. Scaling, divide and conquer, spatial and frequency hierarchies ¶ Move Lecture Function What to keep invariant 7. Measure Doubling Ratios Before Micro-Tuning 3 invariants_complexity.fit_empirical_complexitylog2(T(2N)/T(N)) -> asymptotic exponent p8. Precompute Prefix Integrals for O(1) Queries 3 invariants_complexity.prefix_sum_2d_integralS = P[r1,c1] - P[r0,c1] - P[r1,c0] + P[r0,c0]9. Prune Dominated Candidates in a Monotonic Queue 3 invariants_complexity.sliding_window_max_monotonic_dequeEach item pushed/popped <= 1 time -> <= 2N ops10. Bucket Space into Cutoff Cells 3 invariants_complexity.spatial_cell_list_neighborsNeighbors within r_c lie strictly in 3x3 cells11. Binary-Search the Answer on Monotone Feasibility 4 divide_spatial.parametric_binary_search_minfeasible(lo) == False and feasible(hi) == True12. Piggyback Global Counts onto Divide-and-Conquer 4 divide_spatial.mergesort_with_inversionsCross-inversions counted in O(1) per right-half merge13. Lump Distant Clusters via Multipole Trees 5 divide_spatial.barnes_hut_quadtree_2dOpen cell iff size / d >= theta; theta=0 is exact14. Diagonalize Convolution in Frequency Space 5 divide_spatial.radix2_fft_convolveF(a * b) = F(a) . F(b) in O(N log N)
Move Lecture Function What to keep invariant 15. Tabulate Overlapping Subproblems Once 6 dynamic_optimality.seam_carving_min_energyEach state is solved once, in topological order of the DAG16. Induct Backward Under Future Uncertainty 7 dynamic_optimality.stochastic_bellman_storageV_t(s) = max_a {r(s,a) + E[V_{t+1}(s')]}17. Prove Greedy via an Exchange Argument (or Break It) 8 greedy_heuristic_search.belady_optimal_cacheEvicting furthest-in-future never worsens misses18. Guide Search with an Admissible Lower Bound 9 greedy_heuristic_search.grid_shortest_path_search0 <= h(u) <= h*(u) guarantees optimal path
Move Lecture Function What to keep invariant 19. Compile New Constraints into Exact Cover 10 reductions_constraints.exact_cover_algorithm_xBranch on primary constraint with minimum options20. Optimize Only Zero-Slack Critical Bottlenecks 11 reductions_constraints.critical_path_dagslack(u) = LS(u) - ES(u) == 0 defines critical path21. Choose the Measurement That Maximizes Entropy Drop 12 information_streams.optimal_fault_diagnosis_treeExpected tests >= H(p) bits (Shannon bound)22. Summarize Infinite Streams with One-Sided Sketches 13 information_streams.count_min_sketch_frequenciesf_true <= f_hat <= f_true + eps * N in O(1) RAM
Part V. Emergence, randomness and verification ¶ Move Lecture Function What to keep invariant 23. Locate Critical Thresholds Before Micro-Detailing 14 emergence_verification.site_percolation_2dConnectivity jumps sharply across p_c ~ 0.592724. Fuzz Fast or AI Code Against Metamorphic & Micro-Oracles 16 emergence_verification.metamorphic_differential_auditEquivariance + small-N oracle catches bugs