Remove dispatch-redundant tests from fast.cpp
CI / build-and-check (push) Successful in 8m5s

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.
This commit is contained in:
andrew committed 2026-11-18 14:31:52 -05:00
1 parent 2c8221be54
commit f23d8a28d3
1 file changed
+25 -63
+25 -63
View File
@@ -250,30 +250,6 @@ struct Impl {
return c.r->end_.offset == 1; 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 { OptKey negCrossCompleteHighM(const Ctx& c, const Obs& o) const {
return optMax(c.r->begin.key, after(o.lastK())); return optMax(c.r->begin.key, after(o.lastK()));
} }
@@ -412,15 +388,11 @@ struct Impl {
return niLe(lhs, rhs); 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, ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const Ctx& c,
const Obs& o) const { const Obs& o) const {
OptKey L = OptKey{o.lastK()}; OptKey L = OptKey{o.lastK()};
if (negCrossTruncRevResidualTopLargeSentinel(c, o) && // The caller has already established `negCrossTruncRevResidualTopLarge`.
sentinelLargeTight(c, o)) if (isTop(c.r->begin.key) && sentinelLargeTight(c, o))
return mk(std::move(L), topKey()); return mk(std::move(L), topKey());
return mk(c.r->end_.key, topKey()); return mk(c.r->end_.key, topKey());
} }
@@ -613,7 +585,8 @@ struct Impl {
OptKeyView begin = closedFormBegin(c, o); OptKeyView begin = closedFormBegin(c, o);
if (c.r->end_.offset <= 1) if (c.r->end_.offset <= 1)
return mk(std::move(begin), c.r->end_.key); 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 (c.t == rE(c)) return mk(std::move(begin), after(o.lastK()));
if (allBelowEnd(c)) return mk(std::move(begin), topKey()); if (allBelowEnd(c)) return mk(std::move(begin), topKey());
if (closedFormFinite(c)) return mk(std::move(begin), after(o.lastK())); if (closedFormFinite(c)) return mk(std::move(begin), after(o.lastK()));
@@ -722,12 +695,6 @@ struct Impl {
return c.r->begin.offset == 0; 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 { ConflictRange closedFormCrossedComplete(const Ctx& c, const Obs& o) const {
if (crossedCompleteOvershoot(c)) if (crossedCompleteOvershoot(c))
return closedFormNegCrossTopUnified(c, o); return closedFormNegCrossTopUnified(c, o);
@@ -735,8 +702,15 @@ struct Impl {
return closedFormNegCrossNonclampUnified(c, o); return closedFormNegCrossNonclampUnified(c, o);
if (crossedCompleteBeginZero(c, o)) if (crossedCompleteBeginZero(c, o))
return closedFormZeroCrossResidual(c, o); return closedFormZeroCrossResidual(c, o);
if (crossedCompleteClamp(c, o)) if (negCrossClampEndOne(c, o))
return closedFormNegCrossClampUnified(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); return closedFormNegCrossCompleteHighResidual(c, o);
} }
@@ -763,7 +737,8 @@ struct Impl {
} }
bool negCrossTruncRevBelowEnd(const Ctx& c, const Obs& o) const { 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 { bool negCrossTruncRevResidualRoom(const Ctx& c, const Obs& o) const {
@@ -771,33 +746,20 @@ struct Impl {
NatInf::of(rE(c))); 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<std::uint64_t>(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 { bool revTruncGeTwoTop(const Ctx& c, const Obs& o) const {
return negCrossTruncRevBelowEnd(c, o) || if (negCrossTruncRevBelowEnd(c, o)) return true;
negCrossTruncRevResidualRoom(c, o) || if (negCrossTruncRevResidualRoom(c, o)) return true;
negCrossTruncRevResidualTopCrossedSmallGap(c, o) || // The two `TopCrossed` cases split on `end.key < last`, so test it once.
negCrossTruncRevResidualTopCrossed(c, o); if (oLtK(c.r->end_.key, o.lastK())) {
} NatInf lhs = niAdd(cardOK(c.r->end_.key, o.lastK()),
NatInf::of(static_cast<std::uint64_t>(c.n)));
bool negCrossTruncRevResidualTopLargeCrossed(const Ctx& c, const Obs& o) const { return niLt(lhs, NatInf::of(rE(c)));
return negCrossTruncRevResidualTopLarge(c, o) && }
!isTop(c.r->begin.key); return c.t < rE(c);
} }
bool revTruncGeTwoLarge(const Ctx& c, const Obs& o) const { bool revTruncGeTwoLarge(const Ctx& c, const Obs& o) const {
return negCrossTruncRevResidualTopLargeCrossed(c, o) || return negCrossTruncRevResidualTopLarge(c, o);
negCrossTruncRevResidualTopLargeSentinel(c, o);
} }
bool negCrossTruncTopTop(const Ctx& c, const Obs& o) const { bool negCrossTruncTopTop(const Ctx& c, const Obs& o) const {