47. DP and search in the stdlib (spec/lib/rationale/dp.md, 2026-11-21)
- Searches stay in
std.seq; the DP toolkit is a newstd.dp. Reason:bsearch_real,ternary_*andparallel_bsearchare searches on ranges like their neighbours; monotone queues, Li Chao and the optimizations are called from DP loops. Reverse: move the names. bsearch_realreturns?F64(none whenok(hi)fails), replacing the plan's "hiwhen none". Reason: same shape asbsearch_first, and "nothing works" is a different answer fromhi. Reverse: returnhi.- One generic
LiChao<L, K>(pick, xs)replaces the localLiChao,LiChaoTagandLiChaoF; anyLwithat(x) -> Kworks, 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: addHullbeside it. - No second window queue. The sliding-window optimum is the
containers area's
std.window.MonoDeque;std.dppoints at it. An earlier draft renamed itMonoQueue(it never pushes at the front); that naming call belongs to its owner. Reverse: move it intostd.dp. ternary_max_real/ternary_min_realkeep the_realsuffix.bsearch_realkeeps it, the real forms takelo, hiwhere the integer ones take a range, and they always return an answer where the integer ones return?I; one name over both would needF64ranges. Reverse: oneternary(r, f, by: max)besidebsearch_firstonceRange<F64>exists, with the four names as deprecated aliases for one release.- One SOS transform, in
std.ntt.std.dpdrops itssos_sub,sos_supandsos_sub_inv; the math area'ssos_sub/sos_sup(inverse: Bool = false) are the one implementation, and the coordinator's unifiedsos(f, over: Sub | Sup = Sub, inverse:)is theirs to land. Reverse: restore thestd.dpfunctions. - No
digit_dp, interval-DP or rolling-table library types. Their state is the problem;@memoand two rows say it. A rolling table is a core question (frictionscf2183e,cf2084g1). Reverse: add them. parallel_bsearchtakesreset/apply/okas 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.