From f23d8a28d341b2b5938f50c7513d695d2e750bfb Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 18 Nov 2026 14:31:52 -0500 Subject: [PATCH] Remove dispatch-redundant tests from fast.cpp Two mutation rounds plus z3 checks found conditions that an enclosing dispatch already decides, and two places that re-tested the same split. * crossed complete: HeadBottom implies NonposBottom, so drop it; inline the clamp dispatch so EndOne/LongNonpos are not tested twice; after the failed strict ordering test the non-strict one is free. * reversed truncation: the dispatch has failed end.offset <= 1, so BelowEnd does not need to re-test end.offset >= 2; the two TopCrossed cases split on end.key < last, so test that once; revTruncGeTwoLarge was a tautological split of TopLarge on isTop begin. * TopLarge's sentinel re-tested TopLarge even though the caller had established it; only the sentinel test is needed. * complete forward: begin is bottom exactly when clampsToBottom, and bottom <= end always, so the disjunction is just the key comparison. z3 refutes the negation of each implication. Sweep, golden, corpus, SMT, extreme, and fuzz pass; fast.cpp stays at 100% line/branch coverage. --- cpp/src/fast.cpp | 88 ++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 63 deletions(-) diff --git a/cpp/src/fast.cpp b/cpp/src/fast.cpp index 275c036..663c52b 100644 --- a/cpp/src/fast.cpp +++ b/cpp/src/fast.cpp @@ -250,30 +250,6 @@ struct Impl { return c.r->end_.offset == 1; } - bool negCrossHeadBottom(const Ctx& c, const Obs& o) const { - return c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key) && - o.firstK().empty(); - } - - bool negCrossClampNonposBottom(const Ctx& c, const Obs& o) const { - return c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key); - } - - bool negCrossClampLongNonpos(const Ctx& c, const Obs& o) const { - return c.r->end_.offset <= 0 && optLt(c.r->end_.key, c.r->begin.key); - } - - ConflictRange closedFormNegCrossClampUnified(const Ctx& c, const Obs& o) const { - OptKey end; - if (negCrossClampEndOne(c, o)) - end = clampEndOneUpper(c, o); - else if (negCrossClampLongNonpos(c, o)) - end = clampLongUpper(c, o); - else - end = c.r->end_.key; - return mk(bottomKey(), std::move(end)); - } - OptKey negCrossCompleteHighM(const Ctx& c, const Obs& o) const { return optMax(c.r->begin.key, after(o.lastK())); } @@ -412,15 +388,11 @@ struct Impl { return niLe(lhs, rhs); } - bool negCrossTruncRevResidualTopLargeSentinel(const Ctx& c, const Obs& o) const { - return negCrossTruncRevResidualTopLarge(c, o) && isTop(c.r->begin.key); - } - ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const Ctx& c, const Obs& o) const { OptKey L = OptKey{o.lastK()}; - if (negCrossTruncRevResidualTopLargeSentinel(c, o) && - sentinelLargeTight(c, o)) + // The caller has already established `negCrossTruncRevResidualTopLarge`. + if (isTop(c.r->begin.key) && sentinelLargeTight(c, o)) return mk(std::move(L), topKey()); return mk(c.r->end_.key, topKey()); } @@ -613,7 +585,8 @@ struct Impl { OptKeyView begin = closedFormBegin(c, o); if (c.r->end_.offset <= 1) return mk(std::move(begin), c.r->end_.key); - if (clampsToBottom(c) || optLe(c.r->begin.key, c.r->end_.key)) { + // `begin` is `⊥` exactly when `clampsToBottom`, and `⊥ <= end` always. + if (optLe(begin, c.r->end_.key)) { if (c.t == rE(c)) return mk(std::move(begin), after(o.lastK())); if (allBelowEnd(c)) return mk(std::move(begin), topKey()); if (closedFormFinite(c)) return mk(std::move(begin), after(o.lastK())); @@ -722,12 +695,6 @@ struct Impl { return c.r->begin.offset == 0; } - bool crossedCompleteClamp(const Ctx& c, const Obs& o) const { - return negCrossClampEndOne(c, o) || negCrossHeadBottom(c, o) || - negCrossClampNonposBottom(c, o) || - negCrossClampLongNonpos(c, o); - } - ConflictRange closedFormCrossedComplete(const Ctx& c, const Obs& o) const { if (crossedCompleteOvershoot(c)) return closedFormNegCrossTopUnified(c, o); @@ -735,8 +702,15 @@ struct Impl { return closedFormNegCrossNonclampUnified(c, o); if (crossedCompleteBeginZero(c, o)) return closedFormZeroCrossResidual(c, o); - if (crossedCompleteClamp(c, o)) - return closedFormNegCrossClampUnified(c, o); + if (negCrossClampEndOne(c, o)) + return mk(bottomKey(), clampEndOneUpper(c, o)); + if (c.r->end_.offset <= 0) { + // The two clamp cases below are `end.key < begin.key` and its negation; + // the non-strict ordering is implied by the failed strict test. + if (optLt(c.r->end_.key, c.r->begin.key)) + return mk(bottomKey(), clampLongUpper(c, o)); + return mk(bottomKey(), c.r->end_.key); + } return closedFormNegCrossCompleteHighResidual(c, o); } @@ -763,7 +737,8 @@ struct Impl { } bool negCrossTruncRevBelowEnd(const Ctx& c, const Obs& o) const { - return overshoot(c); + // The dispatch has already failed `end.offset <= 1`, so `end.offset >= 2`. + return allBelowEnd(c); } bool negCrossTruncRevResidualRoom(const Ctx& c, const Obs& o) const { @@ -771,33 +746,20 @@ struct Impl { NatInf::of(rE(c))); } - bool negCrossTruncRevResidualTopCrossedSmallGap(const Ctx& c, - const Obs& o) const { - if (!oLtK(c.r->end_.key, o.lastK())) return false; - NatInf lhs = niAdd(cardOK(c.r->end_.key, o.lastK()), - NatInf::of(static_cast(c.n))); - return niLt(lhs, NatInf::of(rE(c))); - } - - bool negCrossTruncRevResidualTopCrossed(const Ctx& c, const Obs& o) const { - return !oLtK(c.r->end_.key, o.lastK()) && c.t < rE(c); - } - bool revTruncGeTwoTop(const Ctx& c, const Obs& o) const { - return negCrossTruncRevBelowEnd(c, o) || - negCrossTruncRevResidualRoom(c, o) || - negCrossTruncRevResidualTopCrossedSmallGap(c, o) || - negCrossTruncRevResidualTopCrossed(c, o); - } - - bool negCrossTruncRevResidualTopLargeCrossed(const Ctx& c, const Obs& o) const { - return negCrossTruncRevResidualTopLarge(c, o) && - !isTop(c.r->begin.key); + if (negCrossTruncRevBelowEnd(c, o)) return true; + if (negCrossTruncRevResidualRoom(c, o)) return true; + // The two `TopCrossed` cases split on `end.key < last`, so test it once. + if (oLtK(c.r->end_.key, o.lastK())) { + NatInf lhs = niAdd(cardOK(c.r->end_.key, o.lastK()), + NatInf::of(static_cast(c.n))); + return niLt(lhs, NatInf::of(rE(c))); + } + return c.t < rE(c); } bool revTruncGeTwoLarge(const Ctx& c, const Obs& o) const { - return negCrossTruncRevResidualTopLargeCrossed(c, o) || - negCrossTruncRevResidualTopLargeSentinel(c, o); + return negCrossTruncRevResidualTopLarge(c, o); } bool negCrossTruncTopTop(const Ctx& c, const Obs& o) const {