Design decisions

47. DP and search in the stdlib (spec/lib/rationale/dp.md, 2026-11-21)

  1. Searches stay in std.seq; the DP toolkit is a new std.dp. Reason: bsearch_real, ternary_* and parallel_bsearch are searches on ranges like their neighbours; monotone queues, Li Chao and the optimizations are called from DP loops. Reverse: move the names.
  2. bsearch_real returns ?F64 (none when ok(hi) fails), replacing the plan's "hi when none". Reason: same shape as bsearch_first, and "nothing works" is a different answer from hi. Reverse: return hi.
  3. One generic LiChao<L, K>(pick, xs) replaces the local LiChao, LiChaoTag and LiChaoF; any L with at(x) -> K works, so Aliens' (cost, used) tie-break and max envelopes are the same tree (backlog 14 P12). No monotone-slope CHT deque yet: Li Chao covers every insertion order at O(log). Reverse: add Hull beside it.
  4. No second window queue. The sliding-window optimum is the containers area's std.window.MonoDeque; std.dp points at it. An earlier draft renamed it MonoQueue (it never pushes at the front); that naming call belongs to its owner. Reverse: move it into std.dp.
  5. ternary_max_real / ternary_min_real keep the _real suffix. bsearch_real keeps it, the real forms take lo, hi where the integer ones take a range, and they always return an answer where the integer ones return ?I; one name over both would need F64 ranges. Reverse: one ternary(r, f, by: max) beside bsearch_first once Range<F64> exists, with the four names as deprecated aliases for one release.
  6. One SOS transform, in std.ntt. std.dp drops its sos_sub, sos_sup and sos_sub_inv; the math area's sos_sub / sos_sup (inverse: Bool = false) are the one implementation, and the coordinator's unified sos(f, over: Sub | Sup = Sub, inverse:) is theirs to land. Reverse: restore the std.dp functions.
  7. No digit_dp, interval-DP or rolling-table library types. Their state is the problem; @memo and two rows say it. A rolling table is a core question (frictions cf2183e, cf2084g1). Reverse: add them.
  8. parallel_bsearch takes reset / apply / ok as operations, the state living in user variables written by named fns. Reason: any structure works, and lambdas cannot assign. Reverse: take a state value and (S, I) -> S.