Compare commits

...
8 Commits
Author SHA1 Message Date
andrew b665b2dc6f Avoid a guarded local static for the empty key view
CI / build-and-check (push) Successful in 8m13s
2026-11-18 15:24:47 -05:00
andrew bf149c26b5 Saturate and gate all llvm-cov coverage metrics
Require 100% region, function, instantiation, line, branch, and MC/DC
coverage in run-coverage.sh. Enable MC/DC instrumentation and rewrite the
two decisions that Clang could not instrument cleanly: the crossed-room
ternary, and the nested boolean under negation in crossedCompleteEndLeOne.
2026-11-18 15:10:02 -05:00
andrew f23d8a28d3 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.
2026-11-18 14:31:52 -05:00
andrew 2c8221be54 Drop the reference to the previous key model
The note compared against an implementation that no longer exists.
2026-11-18 14:18:37 -05:00
andrew 6e8f5175e2 Remove the recorded validation snapshot
The table was a one-off measurement on a particular machine.  Keep the
commands and the properties they check; readers can run them for current
numbers.
2026-11-18 14:18:31 -05:00
andrew fad9095062 Point the benchmark section at cr_bench
Remove the recorded benchmark tables.  They are measurements of a
particular machine and build, and they go stale as soon as the
implementation or harness changes.  Leave the command and a one-line
description of what it compares, so the reader can run it.
2026-11-18 14:18:15 -05:00
andrew 023ed53579 Stop recording churning metrics in the C++ docs
Remove the exact coverage totals and the offset-5 branch-coverage
explanation: both change whenever fast.cpp or the sweep is adjusted.
The coverage script already reports the current totals and enforces the
100% gate.

Replace the benchmark table's absolute nanoseconds with the stable
shape, and point readers at cr_bench for current numbers.  The recorded
crossed-truncated-reverse figure was already stale after the fast.cpp
change.
2026-11-18 14:17:25 -05:00
andrew e351a0cf8d Hoist the crossed offset test in fast.cpp
Test end.offset <= 1 before revTruncLeOneLow in the reversed crossed
dispatch, and specialize revTruncLeOneLow under that path fact.  The
helper drops the now-tautological end.offset conjuncts and the key
comparison implied by a failed optLe.

The crossed truncated reverse benchmark drops from about 67 ns to
about 61 ns.  Sweep, corpus, SMT cases, and 100% line and branch
coverage still pass.
2026-11-18 14:14:44 -05:00
6 changed files with 95 additions and 174 deletions

No files matched your search

+2 -1
View File
@@ -75,7 +75,8 @@ proof.
differential fuzzing, and by a deterministic finite sweep of small
readable instances; `cpp/README.md` describes the model, the tests, the
coverage check, and the benchmark. The summarised implementation has 100%
line and branch coverage via `cpp/run-coverage.sh`.
coverage on every metric `llvm-cov` reports (region, function, instantiation,
line, branch, and MC/DC) via `cpp/run-coverage.sh`.
## Continuous integration
+20 -73
View File
@@ -25,7 +25,7 @@ The Lean build is untouched.
| `tests/fuzz_raw.cpp` | libFuzzer safety test on arbitrary instances under ASan/UBSan. |
| `tests/bench.cpp` | nanobench literal-vs-fast benchmark. |
| `run-fuzz.sh` | Rebuilds and runs both fuzzers for a fixed time. |
| `run-coverage.sh` | Builds with Clang source-based coverage and requires 100% line and branch coverage of `src/fast.cpp`. |
| `run-coverage.sh` | Builds with Clang source-based coverage and requires 100% region, function, instantiation, line, branch, and MC/DC coverage of `src/fast.cpp`. |
| `third_party/nanobench.h` | Vendored nanobench (commit `7252da9d96bd0d71f508e9b2813ab1f57fdfaec1`). |
## Data model
@@ -117,8 +117,8 @@ It runs in about a second and is also the coverage driver. It is exhaustive
only within those bounds; the class is not all readable inputs, and the
guarantee is that every instance in this family agrees. In
particular, branch coverage cannot exercise a predicate operand that the
implementation no longer contains: the coverage result below describes the code
as written, it is not a proof of equivalence with `literal.cpp`.
implementation no longer contains: the coverage gate describes the code as
written, it is not a proof of equivalence with `literal.cpp`.
## Coverage
@@ -126,23 +126,19 @@ as written, it is not a proof of equivalence with `literal.cpp`.
./cpp/run-coverage.sh
```
The script configures a Clang source-based-coverage build, runs
`sweep_test`, and fails unless `src/fast.cpp` has 100% line and branch
coverage. `sweep_test` alone covers every region, function, line, and
branch side of the summarised implementation:
```text
src/fast.cpp 560 regions (0 missed) 121 functions (0 missed) 675 lines (0 missed) 374 branches (0 missed)
```
That is 100.00% line, function, region, and branch coverage. Offset 5 is part of
the sweep specifically to exercise the last three short-circuit branch sides,
which the previous `[-3, 4]` window missed.
The script configures a Clang source-based-coverage build with MC/DC
instrumentation, runs `sweep_test`, and fails unless `src/fast.cpp` has 100%
region, function, instantiation, line, branch, and MC/DC coverage. `sweep_test`
alone covers every region, function, instantiation, line, branch side, and
MC/DC condition of the summarised implementation. MC/DC instrumentation requires
Clang 18 or newer. The totals are not recorded here: they change with the
implementation, and the coverage run reports the current ones.
Because equivalence is only promised on readable inputs, `src/fast.cpp` deletes
both unreachable control-flow branches and predicate operands that an enclosing
dispatch invariant fixes. Examples include the complete-closed family, the
offset-one total/any wrappers, the `end.offset <= 1` shortcuts, the
offset-one total/any wrappers, the hoisted and specialised
`end.offset <= 1` / `revTruncLeOneLow` path split, the
`crossedCompleteEndLeOne` guard, and the repeated
`!c.r->reverse`/`!o.more`/offset tests inside subtrees that are only entered
after those tests succeeded. `literal.cpp` keeps the full Lean conditions so the
@@ -172,17 +168,6 @@ requires exact endpoints.
`fuzz_raw` only checks memory safety and undefined behaviour for arbitrary
(possibly unreadable) inputs.
One representative validation run on this machine:
| check | cases / runs | result |
| --- | ---: | --- |
| literal vs. Lean golden vectors | 40,000 | 0 mismatches (exact endpoints) |
| fast vs. literal on sorted corpus | 18,971 | 0 mismatches |
| extreme-offset regression (`extreme_test`) | 7,574 | 0 mismatches |
| finite readable sweep (`sweep_test`) | 13,565,772 | 0 mismatches |
| readable differential fuzzing (60 s) | 1,182,424 | 0 mismatches |
| raw safety fuzzing (60 s) | 1,905,270 | no ASan/UBSan findings |
`extreme_test` covers offsets the fuzzers deliberately avoid (they draw offsets
from `[-256, 255]`). Both implementations decide the closed form's
`keyAfterN n k < upper` test from the key lengths (`keyAfterNLt`) rather than
@@ -191,54 +176,17 @@ constant-time instead of attempting a 2 GiB allocation.
## Benchmark
`cr_bench` compares the literal translation with the summarised implementation
across small and long complete, truncated, and crossed reads in both traversal
directions:
```sh
./cpp/build/cr_bench
```
Representative results (Clang 21, default Release build: `-O3 -DNDEBUG`; medians
of nine runs pinned to one core; relative to the literal translation, lower is
better for `fast`).
CPU frequency scaling makes the absolute numbers noisy, but the shape is stable:
| case | literal | fast | fast/literal |
| --- | ---: | ---: | ---: |
| small complete (8 keys) | 41.6 ns | 16.2 ns | 0.39x |
| small truncated forward | 16.9 ns | 22.9 ns | 1.35x |
| crossed truncated forward | 56.0 ns | 46.6 ns | 0.83x |
| crossed truncated reverse | 130.1 ns | 82.7 ns | 0.64x |
| long complete forward (512 keys) | 2189 ns | 32.6 ns | 0.01x |
| long truncated forward | 15.0 ns | 19.6 ns | 1.31x |
| long truncated reverse | 9.5 ns | 12.8 ns | 1.35x |
The large win is on complete reads: the literal translation rescans the reported
keys many times (`residualT`, `reportedBelowBegin`, `allBelowEnd`, ...), while
the summary answers those questions in `O(log n)` or from a cached count.
Plain truncated cases are dominated by the shared decision tree, so the two
implementations are close; the literal path is slightly cheaper there because it
performs no summary setup. Crossed cases report 16 of a 33-key range, so the
summary wins there too.
Against the same implementation with owned input keys (the previous model), the
borrowed-key model changes the costs as follows (nine interleaved runs each,
median). The crossed cases are absent from this table: their benchmark inputs
were corrected to nonempty ranges after the owned-key measurements.
| case | literal (borrow vs own) | fast (borrow vs own) |
| --- | ---: | ---: |
| small complete | -64% | -17% |
| small truncated forward | -33% | -19% |
| long complete forward | -69% | -15% |
| long truncated forward | -29% | -6% |
| long truncated reverse | -16% | +16% |
The complete-read gains come from not copying the reported keys just to
normalise the result: a forward result is now the caller's span, and a reverse
result is a reversed view rather than an owned copy. The fast path also benefits
because it previously normalised complete results the same way. Truncated
reverse (`fast`) is the one small regression: it is a few nanoseconds and a few
dozen instructions, and the other paths move in the opposite direction, so it
reads as code-layout/code-generation noise rather than extra algorithmic work.
It reports timings and instruction and branch counts per case. Absolute numbers
vary with the machine, compiler, and frequency scaling, so run it for current
figures.
## Why the fast implementation is equivalent
@@ -251,8 +199,7 @@ only changes are:
reported keys, so they survive the reversed-view normalisation.
* Interval cardinalities (`intervalCard`) are cached lazily.
* Complete observations are not copied: a forward result borrows the caller's
span, and a reversed result is viewed backwards in place. (The previous
owned-key model copied and reversed the reported keys here.)
span, and a reversed result is viewed backwards in place.
* `allBelowEnd` is `residualT == 0` and `anyAtOrAboveEnd` is `residualT != 0`.
No branch condition or returned endpoint is otherwise changed on readable
+30 -13
View File
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
# Build with Clang source-based coverage and require 100% line and branch
# coverage of the summarised implementation (`src/fast.cpp`). `sweep_test`
# deterministically enumerates a finite class of small readable instances and is
# sufficient on its own.
# Build with Clang source-based coverage and require 100% region, function,
# instantiation, line, branch, and MC/DC coverage of the summarised
# implementation (`src/fast.cpp`). `sweep_test` deterministically enumerates a
# finite class of small readable instances and is sufficient on its own.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -72,7 +72,7 @@ cmake -S "$here" -B "$build" -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DCR_BUILD_FUZZERS=OFF \
-DCR_BUILD_BENCH=OFF \
-DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
-DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc" \
-DCMAKE_EXE_LINKER_FLAGS="-fprofile-instr-generate"
cmake --build "$build" --target sweep_test
@@ -86,18 +86,35 @@ LLVM_PROFILE_FILE="$profdir/sweep-%p.profraw" "$build/sweep_test"
report() {
"$cov" report "$build/sweep_test" \
-instr-profile="$profdir/cov.profdata" src/fast.cpp
-instr-profile="$profdir/cov.profdata" \
--show-branch-summary \
--show-instantiation-summary \
--show-mcdc-summary \
--show-region-summary \
src/fast.cpp
}
output="$(report)"
printf '%s\n' "$output"
line_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $10 }')"
branch_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $13 }')"
if [[ "$line_cover" != "100.00%" ]]; then
echo "fast.cpp line coverage is $line_cover, expected 100.00%" >&2
# The row fields follow the summary order enabled above:
# region, function, instantiation, line, branch, and MC/DC coverage.
row="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print; exit }')"
if [[ -z "$row" ]]; then
echo "coverage report did not contain src/fast.cpp" >&2
exit 1
fi
if [[ "$branch_cover" != "100.00%" ]]; then
echo "fast.cpp branch coverage is $branch_cover, expected 100.00%" >&2
read -r -a fields <<< "$row"
metrics=(region function instantiation line branch MC/DC)
columns=(3 6 9 12 15 18)
failed=0
for i in "${!metrics[@]}"; do
cover="${fields[${columns[$i]}]}"
if [[ "$cover" != "100.00%" ]]; then
echo "fast.cpp ${metrics[$i]} coverage is ${cover:-missing}, expected 100.00%" >&2
failed=1
fi
done
if [[ "$failed" -ne 0 ]]; then
exit 1
fi
echo "fast.cpp: 100.00% line and branch coverage"
echo "fast.cpp: 100.00% region, function, instantiation, line, branch, and MC/DC coverage"
+40 -80
View File
@@ -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()));
@@ -679,10 +652,9 @@ struct Impl {
: c.r->begin.key;
return mk(std::move(begin), after(o.firstK()));
}
OptKeyView begin =
(optLt(c.r->end_.key, c.r->begin.key) && closedFormCrossedRoom(c, o))
? c.r->end_.key
: c.r->begin.key;
bool beginAtEnd = optLt(c.r->end_.key, c.r->begin.key) &&
closedFormCrossedRoom(c, o);
OptKeyView begin = beginAtEnd ? c.r->end_.key : c.r->begin.key;
return mk(std::move(begin), topKey());
}
@@ -712,8 +684,9 @@ struct Impl {
bool crossedCompleteEndLeOne(const Ctx& c) const {
if (c.r->end_.offset == 1 && bSlack(c) < c.below)
return true;
return c.r->end_.offset <= 0 &&
!(c.below <= bSlack(c) && clampNonposBottom(c));
if (c.r->end_.offset > 0) return false;
bool clampedBottom = c.below <= bSlack(c) && clampNonposBottom(c);
return !clampedBottom;
}
// The overshoot branch above already covered the offset-zero overshoot
@@ -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);
}
@@ -749,26 +723,22 @@ struct Impl {
return c.r->begin.offset == 0;
}
bool negCrossTruncRevUnder(const Ctx& c, const Obs& o) const {
return optLe(c.r->begin.key, c.r->end_.key) && c.r->end_.offset <= 1;
}
bool negCrossTruncRevCrossedLow(const Ctx& c, const Obs& o) const {
return optLt(c.r->end_.key, c.r->begin.key) &&
c.r->end_.offset <= 1 &&
niLe(niAdd(niAdd(cardEB(c),
// `revTruncLeOneLow` is reached only under `end.offset <= 1` (the dispatch
// tests that comparison first), so the `end.offset <= 1` conjunct in each
// original disjunct is discharged by the caller and has been dropped here.
bool revTruncLeOneLow(const Ctx& c, const Obs& o) const {
if (optLe(c.r->begin.key, c.r->end_.key)) return true;
// The failed `optLe` test already gives `end.key < begin.key`, so the
// original `optLt` conjunct is implied here.
return niLe(niAdd(niAdd(cardEB(c),
NatInf::of(static_cast<std::uint64_t>(c.n))),
NatInf::of(toNat(1 - c.r->end_.offset))),
NatInf::of(bSlack(c) + 1));
}
bool revTruncLeOneLow(const Ctx& c, const Obs& o) const {
return negCrossTruncRevUnder(c, o) ||
negCrossTruncRevCrossedLow(c, o);
}
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 {
@@ -776,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;
bool revTruncGeTwoTop(const Ctx& c, const Obs& o) const {
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<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 {
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);
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 {
@@ -896,10 +853,13 @@ struct Impl {
if (c.r->reverse) {
if (zeroCrossTruncRevCrossed(c, o))
return closedFormZeroCrossTruncRevCrossed(c, o);
// `revTruncLeOneLow` implies `end.offset <= 1`, so test the cheap
// comparison first and keep the disjunction on that branch only.
if (c.r->end_.offset <= 1) {
if (revTruncLeOneLow(c, o))
return mk(OptKey{o.lastK()}, c.r->end_.key);
if (c.r->end_.offset <= 1)
return mk(OptKey{o.lastK()}, c.r->begin.key);
}
if (revTruncGeTwoTop(c, o))
return mk(OptKey{o.lastK()}, topKey());
if (revTruncGeTwoLarge(c, o))
+3 -5
View File
@@ -169,11 +169,9 @@ inline OptKey optMax(const std::optional<A>& a, const std::optional<B>& b) {
inline OptKey topKey() { return std::nullopt; }
inline OptKey bottomKey() { return OptKey{Key{}}; }
// A view of a static empty string, so empty views always have a valid pointer.
inline KeyView emptyKeyView() {
static const Key empty;
return KeyView(empty);
}
// A view of the empty string literal, so empty views always have a valid
// pointer. Unlike a function-local static, this needs no guard variable.
inline KeyView emptyKeyView() { return KeyView("", 0); }
inline OptKeyView bottomKeyView() { return OptKeyView{emptyKeyView()}; }
inline bool isTop(OptKeyView k) { return !k.has_value(); }
-2
View File
@@ -28,8 +28,6 @@ namespace {
using namespace cr;
// Offset 5 is what lets the default sweep exercise the last three
// short-circuit branch sides in `fast.cpp` (all in crossed subtrees).
const std::int32_t kOffsets[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
void check(const RangeRead& r, const Result& res, long long& cases,