Compare commits
18
Commits
3bb5d062ff
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b665b2dc6f | ||
|
|
bf149c26b5 | ||
|
|
f23d8a28d3 | ||
|
|
2c8221be54 | ||
|
|
6e8f5175e2 | ||
|
|
fad9095062 | ||
|
|
023ed53579 | ||
|
|
e351a0cf8d | ||
|
|
e1395f20ef | ||
|
|
a0b68d148b | ||
|
|
7a41d1f647 | ||
|
|
24f28dd9c8 | ||
|
|
c8e49aead8 | ||
|
|
bb32cca6f9 | ||
|
|
cb160a6881 | ||
|
|
4e26f3710b | ||
|
|
273ad72f0c | ||
|
|
73e371fb40 |
No files matched your search
@@ -0,0 +1,74 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["main"]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 120
|
||||||
|
steps:
|
||||||
|
- name: Check out
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Lean toolchain
|
||||||
|
run: |
|
||||||
|
curl -sSfL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh \
|
||||||
|
| sh -s -- -y --default-toolchain none
|
||||||
|
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
# Mathlib is pinned in `lake-manifest.json`; the cache supplies its
|
||||||
|
# prebuilt `.olean` files so the job only compiles this project.
|
||||||
|
- name: Cache Lake packages and build artifacts
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
.lake
|
||||||
|
~/.elan
|
||||||
|
key: lake-${{ runner.os }}-${{ hashFiles('lean-toolchain', 'lake-manifest.json', 'lakefile.toml') }}
|
||||||
|
restore-keys: |
|
||||||
|
lake-${{ runner.os }}-
|
||||||
|
|
||||||
|
- name: Fetch Mathlib cache
|
||||||
|
run: lake exe cache get
|
||||||
|
|
||||||
|
- name: Build Lean
|
||||||
|
run: lake build
|
||||||
|
|
||||||
|
# bwrap-free replacement for the comparator's axiom check; catches
|
||||||
|
# `sorryAx` and any newly introduced axiom in the headline theorems.
|
||||||
|
- name: Check axioms
|
||||||
|
run: ./scripts/check-axioms.sh
|
||||||
|
|
||||||
|
- name: Install C++ toolchain
|
||||||
|
run: |
|
||||||
|
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi
|
||||||
|
$SUDO apt-get update
|
||||||
|
$SUDO apt-get install -y clang cmake ninja-build
|
||||||
|
clang_major="$(clang++ -dumpversion | cut -d. -f1)"
|
||||||
|
$SUDO apt-get install -y "llvm-${clang_major}"
|
||||||
|
|
||||||
|
- name: Configure and build C++
|
||||||
|
run: |
|
||||||
|
cmake -S cpp -B cpp/build -G Ninja \
|
||||||
|
-DCMAKE_CXX_COMPILER=clang++ \
|
||||||
|
-DCR_BUILD_FUZZERS=OFF \
|
||||||
|
-DCR_BUILD_BENCH=OFF
|
||||||
|
cmake --build cpp/build
|
||||||
|
|
||||||
|
# `golden_test` and `diff_corpus` read vectors generated by the actual
|
||||||
|
# Lean `Statement.closedForm`; the file is gitignored.
|
||||||
|
- name: Generate golden vectors
|
||||||
|
run: lake env lean --run cpp/oracle/gen.lean > cpp/oracle/golden.txt
|
||||||
|
|
||||||
|
- name: Run C++ tests
|
||||||
|
run: ctest --test-dir cpp/build --output-on-failure
|
||||||
|
|
||||||
|
- name: Check C++ coverage
|
||||||
|
run: |
|
||||||
|
CXX="clang++-$(clang++ -dumpversion | cut -d. -f1)" \
|
||||||
|
./cpp/run-coverage.sh
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
import Statement
|
import Statement
|
||||||
import FormalConflictRange.SimpleClosedForm
|
import FormalConflictRange.SimpleClosedForm
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
import Statement
|
import Statement
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
|
|
||||||
|
import Proof
|
||||||
|
|
||||||
|
/-!
|
||||||
|
# Axiom audit for the headline theorems
|
||||||
|
|
||||||
|
`#print axioms` lists every axiom a declaration depends on. The expected
|
||||||
|
output for both headlines is exactly `[propext, Classical.choice, Quot.sound]`;
|
||||||
|
a `sorry` would show up as `sorryAx` and any new axiom would appear by name.
|
||||||
|
`scripts/check-axioms.sh` (used by CI) enforces that output.
|
||||||
|
-/
|
||||||
|
|
||||||
|
#print axioms Statement.closedFormMinimal
|
||||||
|
#print axioms Statement.minimalUnique
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
import FormalConflictRange.Nonpos
|
import FormalConflictRange.Nonpos
|
||||||
@@ -16,18 +14,25 @@ The conflict-range inference has two layers.
|
|||||||
(unconditional) empty-result theory of `FormalConflictRange.Empty` and
|
(unconditional) empty-result theory of `FormalConflictRange.Empty` and
|
||||||
`FormalConflictRange.Nonpos`: a result with no keys is answered by the empty-result
|
`FormalConflictRange.Nonpos`: a result with no keys is answered by the empty-result
|
||||||
value `emptyValue`, and the remaining certified offset cases are handled as in
|
value `emptyValue`, and the remaining certified offset cases are handled as in
|
||||||
`FormalConflictRange.Sound`. **This is the object of record**: the correctness
|
`FormalConflictRange.Sound`. The correctness statement is
|
||||||
statement is `conflictRangePartial_spec`, and the open frontier is exactly the
|
`conflictRangePartial_spec`: wherever the function returns `some cr`, that range
|
||||||
set of inputs on which it returns `none`. When that set is empty the algorithm is
|
is minimal. The inputs on which it returns `none` are the cases this case-analysis
|
||||||
total and is promoted to the `ConflictRange`-valued algorithm.
|
route did not certify. The headline theorem is proved independently in
|
||||||
|
`Proof.lean` through the closed-form development
|
||||||
|
(`FormalConflictRange.ClosedFormAll`). This module also supplies that
|
||||||
|
development's empty-result theory — `emptyValue`, `EmptyInferenceWitness`,
|
||||||
|
and `minimal_emptyValue_of_emptyInference` — so the partial-algorithm
|
||||||
|
sections below are a record of the case analysis, while the empty-result
|
||||||
|
declarations are shared with the final proof.
|
||||||
* The provisional totalization `conflictRangeVal`, assembled by *reduction to the
|
* The provisional totalization `conflictRangeVal`, assembled by *reduction to the
|
||||||
empty reads* rather than case analysis. It is the every-input wrapper used to
|
empty reads* rather than case analysis. It is the every-input wrapper used to
|
||||||
*state* the general reduction: it dispatches on emptiness, truncation, and
|
*state* the general reduction: it dispatches on emptiness, truncation, and
|
||||||
traversal and returns a `ConflictRange` on the certified regions. Off them its
|
traversal and returns a `ConflictRange` on the certified regions. Off them its
|
||||||
value is a placeholder whose hull fallback is not sound in general (see
|
value is a placeholder whose hull fallback is not sound in general (a complete
|
||||||
`FormalConflictRange.Counterexample`), and its `_spec` theorems are relative to
|
read whose reported keys are not the endpoint keys of the hull gives a
|
||||||
the open `EmptyTheoryComplete`. It is kept only until `conflictRangePartial` is
|
counterexample), and its `_spec` theorems are relative to the conditional
|
||||||
total, at which point it is replaced. It dispatches as follows:
|
`EmptyTheoryComplete`. It is kept only as the intermediate reduction interface.
|
||||||
|
It dispatches as follows:
|
||||||
|
|
||||||
- an empty result is answered by the empty theory's value `emptyValue`;
|
- an empty result is answered by the empty theory's value `emptyValue`;
|
||||||
- a forward truncated result is `[w, keyAfter kₙ)`: the begin selector's empty
|
- a forward truncated result is `[w, keyAfter kₙ)`: the begin selector's empty
|
||||||
@@ -54,15 +59,15 @@ The conflict-range inference has two layers.
|
|||||||
stretched to the complete value's endpoints (`BoundaryNecessity`), the content the
|
stretched to the complete value's endpoints (`BoundaryNecessity`), the content the
|
||||||
empty inference supplies as `ψ` at the two boundary reads. Hull soundness is derived
|
empty inference supplies as `ψ` at the two boundary reads. Hull soundness is derived
|
||||||
from `EmptyInference` for all bridge factors except the bracket (`BracketFactor`),
|
from `EmptyInference` for all bridge factors except the bracket (`BracketFactor`),
|
||||||
which is the notes' observability residue. The complete branch is then
|
which is the bracket-observability residue. The complete branch is then
|
||||||
`minimal_completeRange_of_factors`/`_rev`, with the interior derived rather than
|
`minimal_completeRange_of_factors`/`_rev`, with the interior derived rather than
|
||||||
assumed; `GeneralObligation` adds only the two truncated dispatch values. Its
|
assumed; `GeneralObligation` adds only the two truncated dispatch values. Its
|
||||||
conditional correctness statement is `conflictRangeVal_spec` (relative to
|
conditional correctness statement is `conflictRangeVal_spec` (relative to
|
||||||
`EmptyTheoryComplete`); the algorithm of record remains `conflictRangePartial`. In the
|
`EmptyTheoryComplete`); the certified algorithm in this module remains
|
||||||
canonical region (`begin.offset = 1`, `end.offset ≤ 1`, canonical endpoints) the complete
|
`conflictRangePartial`. In the canonical region (`begin.offset = 1`,
|
||||||
branch is unconditional
|
`end.offset ≤ 1`, canonical endpoints) the complete branch is unconditional
|
||||||
(`minimal_completeRange_canonical`), needing neither boundary hypothesis. There are
|
(`minimal_completeRange_canonical`), needing neither boundary hypothesis. There are
|
||||||
no `sorry`s: the open content appears only as those explicit hypotheses.
|
no `sorry`s: the uncertified content appears only as those explicit hypotheses.
|
||||||
|
|
||||||
The reduction identity itself is `necessaryRange_completeRange_of_reported`: the
|
The reduction identity itself is `necessaryRange_completeRange_of_reported`: the
|
||||||
complete value's necessary range is the lower boundary, the reported interval, and the
|
complete value's necessary range is the lower boundary, the reported interval, and the
|
||||||
@@ -77,11 +82,10 @@ The conflict-range inference has two layers.
|
|||||||
`EmptyInferenceWitness` records the empty theory in the witness-exposing form the graft
|
`EmptyInferenceWitness` records the empty theory in the witness-exposing form the graft
|
||||||
consumes and implies `EmptyInference` (`emptyInference_of_witness`). The one genuine
|
consumes and implies `EmptyInference` (`emptyInference_of_witness`). The one genuine
|
||||||
extraction — turning an abstract `Minimal` for a boundary read into a full-compatible
|
extraction — turning an abstract `Minimal` for a boundary read into a full-compatible
|
||||||
witness database — remains the length-sensitive joint-base graft; it is the reason the
|
witness database — is the length-sensitive joint-base graft; it is the reason the
|
||||||
boundary content is a hypothesis and not a consequence of `EmptyInference` alone. (It is
|
boundary content is a hypothesis and not a consequence of `EmptyInference` alone. It is
|
||||||
in fact *false*, not merely unproved:
|
in fact *false*, not merely unproved: a two-key witness makes the hull endpoints differ
|
||||||
`FormalConflictRange.Counterexample.cw_notBoundaryJointBases` refutes `BoundaryJointBases`
|
from the reported interval's, so `BoundaryJointBases` fails for it.
|
||||||
on the `cwRead`/`cwRes` witness.)
|
|
||||||
|
|
||||||
The pushed-down interface makes the confinement of offsets explicit. The complete
|
The pushed-down interface makes the confinement of offsets explicit. The complete
|
||||||
branch's nonempty content is `CompleteObligation`, whose fields are the generic graft
|
branch's nonempty content is `CompleteObligation`, whose fields are the generic graft
|
||||||
@@ -94,17 +98,17 @@ The conflict-range inference has two layers.
|
|||||||
the witness-exposing empty oracle, the generic graft, the bracket gap split, and the
|
the witness-exposing empty oracle, the generic graft, the bracket gap split, and the
|
||||||
truncated one-sided graft. From it, `conflictRangeVal_spec_complete` proves the general
|
truncated one-sided graft. From it, `conflictRangeVal_spec_complete` proves the general
|
||||||
algorithm correct with `Readable` the only other hypothesis, and
|
algorithm correct with `Readable` the only other hypothesis, and
|
||||||
`exists_minimal_conflict_range_of_complete` gives the existence conjecture. The graft
|
`exists_minimal_conflict_range_of_complete` gives existence from the same hypotheses.
|
||||||
fields (`joint`, `truncated`) are guarded by `Readable`: a bridge database exists only
|
The graft fields (`joint`, `truncated`) are guarded by `Readable`: a bridge database
|
||||||
when the reported keys are the complete keys of some database, so for an unrealizable
|
exists only when the reported keys are the complete keys of some database, so for an
|
||||||
pair `BoundaryJointBases`/`GeneralObligation` are outright false (a duplicate reported
|
unrealizable pair `BoundaryJointBases`/`GeneralObligation` are outright false (a
|
||||||
key can never satisfy `midEq`). The unconditional headline claim is *not* proved here: it
|
duplicate reported key can never satisfy `midEq`). This conditional route is not the
|
||||||
is stated with explicit `sorry`s in `FormalConflictRange.Open` (which is built but
|
headline proof: the unconditional statement is proved in `Proof.lean`, where the closed
|
||||||
deliberately not imported by this module). All three non-witness fields of
|
form is established directly for the reference development. All three non-witness
|
||||||
|
fields of
|
||||||
`EmptyTheoryComplete` are in fact *refuted* — `bracket` and `truncated` as before, and
|
`EmptyTheoryComplete` are in fact *refuted* — `bracket` and `truncated` as before, and
|
||||||
`joint` (`BoundaryJointBases`) by the same `cwRead`/`cwRes` witness that refutes the hull
|
`joint` (`BoundaryJointBases`) by the two-key witness that also refutes the hull — so
|
||||||
(`FormalConflictRange.Counterexample.cw_notBoundaryJointBases`), so the reduction is
|
the reduction is uninhabited rather than merely unproved.
|
||||||
uninhabited rather than merely unproved.
|
|
||||||
|
|
||||||
On the empty theory itself, the witness-exposing oracle is proved at
|
On the empty theory itself, the witness-exposing oracle is proved at
|
||||||
`begin.offset = 1` (`emptyWitness_beginOne`), throughout the whole `end.offset ≤ 1`
|
`begin.offset = 1` (`emptyWitness_beginOne`), throughout the whole `end.offset ≤ 1`
|
||||||
@@ -137,14 +141,16 @@ The conflict-range inference has two layers.
|
|||||||
`EmptyInferenceWitnessResidual` is therefore vacuous: the whole oracle is
|
`EmptyInferenceWitnessResidual` is therefore vacuous: the whole oracle is
|
||||||
`emptyInferenceWitness`, unconditionally, and `emptyInference : EmptyInference` follows.
|
`emptyInferenceWitness`, unconditionally, and `emptyInference : EmptyInference` follows.
|
||||||
What remains of the empty theory is only the graft and gap-split fields of
|
What remains of the empty theory is only the graft and gap-split fields of
|
||||||
`EmptyTheoryComplete`, packaged by `emptyTheoryComplete_of_witness`; those fields are the
|
`EmptyTheoryComplete`, packaged by `emptyTheoryComplete_of_witness`. The gap-split field
|
||||||
open `sorry`s of `FormalConflictRange.Open`. The gap-split field `BracketFactor` is in
|
`BracketFactor` is in fact *false* as stated on the hull: a compatible database can
|
||||||
fact *false* as stated on the old hull, by the kernel-checked witness in
|
satisfy the boundary conditions while the bracket fails. `completeValue` routes the
|
||||||
`FormalConflictRange.Counterexample`; `completeValue` routes the canonical region
|
canonical region `1 ≤ begin.offset ∧ end.offset ≤ 1` around the hull precisely so that
|
||||||
`1 ≤ begin.offset ∧ end.offset ≤ 1` around the hull precisely so that this pair is
|
this pair is answered correctly without it.
|
||||||
answered correctly without it.
|
|
||||||
|
|
||||||
The reduction is the subject of section 7 of `notes/main.tex`.
|
The reduction described here was the working route to the closed form; the final
|
||||||
|
argument in `Proof.lean` uses the closed-form theorems instead. The empty-result
|
||||||
|
part of this module (`emptyValue`, `EmptyInference`, and
|
||||||
|
`minimal_emptyValue_of_emptyInference`) is shared with that development.
|
||||||
-/
|
-/
|
||||||
|
|
||||||
namespace FormalConflictRange
|
namespace FormalConflictRange
|
||||||
@@ -152,8 +158,8 @@ namespace FormalConflictRange
|
|||||||
/-!
|
/-!
|
||||||
## A partial algorithm: the certified cases
|
## A partial algorithm: the certified cases
|
||||||
|
|
||||||
The general existence conjecture is open, but the theorems above certify a region
|
The theorems above certify a region of reads. Package them into one computable
|
||||||
of reads. Package them into one computable `Option`-valued function,
|
`Option`-valued function,
|
||||||
`conflictRangePartial`, returning `some` range exactly where a certificate exists
|
`conflictRangePartial`, returning `some` range exactly where a certificate exists
|
||||||
and `none` otherwise. This is the honest encoding of "proved only for certain
|
and `none` otherwise. This is the honest encoding of "proved only for certain
|
||||||
cases": it is total in type but makes absence explicit, and `none` carries no
|
cases": it is total in type but makes absence explicit, and `none` carries no
|
||||||
@@ -393,7 +399,7 @@ abbrev zeroCrossCompleteRev (r : RangeRead) (res : Result) : Prop :=
|
|||||||
## The empty-result value and its inference
|
## The empty-result value and its inference
|
||||||
|
|
||||||
The empty-result value `emptyValue` and the standing hypothesis `EmptyInference` are
|
The empty-result value `emptyValue` and the standing hypothesis `EmptyInference` are
|
||||||
declared here, before `conflictRangePartial`, because the algorithm of record consults
|
declared here, before `conflictRangePartial`, because the certified algorithm consults
|
||||||
them directly: an empty result is answered by `emptyValue r`, and the certified branch
|
them directly: an empty result is answered by `emptyValue r`, and the certified branch
|
||||||
of the partial algorithm is exactly the empty-result inference. The witness oracle and
|
of the partial algorithm is exactly the empty-result inference. The witness oracle and
|
||||||
the unconditional proof of `EmptyInference` live later in this file, so the inference is
|
the unconditional proof of `EmptyInference` live later in this file, so the inference is
|
||||||
@@ -523,9 +529,10 @@ def conflictRangePartial (r : RangeRead) (res : Result) : Option ConflictRange :
|
|||||||
-- (`minimal_canonicalRange_of_end_offset_le_one_general`). A truncated
|
-- (`minimal_canonicalRange_of_end_offset_le_one_general`). A truncated
|
||||||
-- (`more = true`) forward result now has it too
|
-- (`more = true`) forward result now has it too
|
||||||
-- (`minimal_canonicalRange_of_truncated_end_offset_nonpos`): FoundationDB's bare
|
-- (`minimal_canonicalRange_of_truncated_end_offset_nonpos`): FoundationDB's bare
|
||||||
-- successor `[begin.key, keyAfter (last reported))` is *unsound* there
|
-- successor `[begin.key, keyAfter (last reported))` is *unsound* there: a
|
||||||
-- (`FormalConflictRange.Counterexample.tr_notSound`) because the resolved end
|
-- compatible database with a nonpositive end offset realises the failure,
|
||||||
-- clamps below `end_.key`, but the canonical upper end `end_.key` is correct. A
|
-- because the resolved end clamps below `end_.key`, but the canonical upper
|
||||||
|
-- end `end_.key` is correct. A
|
||||||
-- truncated *reversed* result has the reversed truncated range
|
-- truncated *reversed* result has the reversed truncated range
|
||||||
-- `[last reported, end_.key)` (`minimal_truncatedRangeRev_of_end_offset_nonpos`):
|
-- `[last reported, end_.key)` (`minimal_truncatedRangeRev_of_end_offset_nonpos`):
|
||||||
-- the top `(1 - end_.offset)` canonical keys are dropped, but filtering at or
|
-- the top `(1 - end_.offset)` canonical keys are dropped, but filtering at or
|
||||||
@@ -544,10 +551,11 @@ def conflictRangePartial (r : RangeRead) (res : Result) : Option ConflictRange :
|
|||||||
-- (`getRangeFinished`, `NativeAPI.actor.cpp:4770-4785`). Left uncertified:
|
-- (`getRangeFinished`, `NativeAPI.actor.cpp:4770-4785`). Left uncertified:
|
||||||
-- an `end_.offset ≥ 2` can run past the data even when a reported key lies at
|
-- an `end_.offset ≥ 2` can run past the data even when a reported key lies at
|
||||||
-- or above `end_.key`, so the end anchor is not always observable and the
|
-- or above `end_.key`, so the end anchor is not always observable and the
|
||||||
-- candidate need not be sound. The cell has no single shape: the `cwMin` value
|
-- candidate need not be sound. The cell has no single shape: the
|
||||||
-- (bare successor of the greatest reported key) is minimal at `end.offset = 2`
|
-- bare-successor value (of the greatest reported key) is minimal at
|
||||||
-- but fails for larger slack, where the window runs past the reported last
|
-- `end.offset = 2`
|
||||||
-- (`FormalConflictRange.Counterexample.ns_cand_notSound`, true value the top).
|
-- but fails for larger slack, where the window runs past the reported last (a
|
||||||
|
-- compatible witness realises this; the true value is the top).
|
||||||
none /- end offset at least two but not overshooting: no certificate -/
|
none /- end offset at least two but not overshooting: no certificate -/
|
||||||
else if _h : 1 ≤ r.begin.offset then
|
else if _h : 1 ≤ r.begin.offset then
|
||||||
-- A nonempty result at `begin.offset ≥ 1` (here `begin.offset ≠ 1`, so at least two)
|
-- A nonempty result at `begin.offset ≥ 1` (here `begin.offset ≠ 1`, so at least two)
|
||||||
@@ -592,9 +600,10 @@ def conflictRangePartial (r : RangeRead) (res : Result) : Option ConflictRange :
|
|||||||
some (truncatedRange r (res.keys.getLastD ([] : Key)))
|
some (truncatedRange r (res.keys.getLastD ([] : Key)))
|
||||||
else
|
else
|
||||||
-- Truncated *reversed* at `begin.offset ≠ 1`, `end_.offset ≥ 2`, overshooting: the
|
-- Truncated *reversed* at `begin.offset ≠ 1`, `end_.offset ≥ 2`, overshooting: the
|
||||||
-- reversed value `topOfLast` is unsound here (`Counterexample.ev_topOfLast_notSound`),
|
-- reversed value `topOfLast` is unsound here (a compatible witness realises
|
||||||
-- because the begin selector skips keys below the reported last that the candidate
|
-- this), because the begin selector skips keys below the reported last that
|
||||||
-- cannot see. The minimal value is instead the unbounded top from `begin.key`,
|
-- the candidate cannot see. The minimal value is instead the unbounded top
|
||||||
|
-- from `begin.key`,
|
||||||
-- `[begin.key, ⊤)` (`minimal_topRange_of_end_offset_ge_two_rev_more`): the begin
|
-- `[begin.key, ⊤)` (`minimal_topRange_of_end_offset_ge_two_rev_more`): the begin
|
||||||
-- key is necessary, and convexity through the reported keys with
|
-- key is necessary, and convexity through the reported keys with
|
||||||
-- `necessary_of_end_offset_ge_two_rev` above the head forces the whole interval.
|
-- `necessary_of_end_offset_ge_two_rev` above the head forces the whole interval.
|
||||||
@@ -706,7 +715,7 @@ least. The two `rangeBegin`/`rangeEnd` clamp steps mirror the
|
|||||||
`NativeAPI.actor.cpp:4739-4794`), parameterized by the `readToBegin` and
|
`NativeAPI.actor.cpp:4739-4794`), parameterized by the `readToBegin` and
|
||||||
`readThroughEnd` flags. A `true` flag replaces the corresponding endpoint by
|
`readThroughEnd` flags. A `true` flag replaces the corresponding endpoint by
|
||||||
`⊥`/`⊤`. This records FoundationDB's choice; the formal development does not
|
`⊥`/`⊤`. This records FoundationDB's choice; the formal development does not
|
||||||
assert it minimal on the open branches (see the section note above), except for
|
assert it minimal on the uncertified branches (see the module docstring), except for
|
||||||
`minimal_canonicalRange_of_underEnd_empty_conj` on the empty `underEnd` case. -/
|
`minimal_canonicalRange_of_underEnd_empty_conj` on the empty `underEnd` case. -/
|
||||||
def fdbRange (r : RangeRead) (res : Result) (readToBegin readThroughEnd : Bool) :
|
def fdbRange (r : RangeRead) (res : Result) (readToBegin readThroughEnd : Bool) :
|
||||||
ConflictRange :=
|
ConflictRange :=
|
||||||
@@ -1129,8 +1138,8 @@ def BoundaryNecessity (r : RangeRead) (res : Result) : Prop :=
|
|||||||
|
|
||||||
/-- **The bracket-observability residue.** Agreement on the complete value fixes the
|
/-- **The bracket-observability residue.** Agreement on the complete value fixes the
|
||||||
bracketing predicate, i.e. whether the resolved endpoints straddle the reported span.
|
bracketing predicate, i.e. whether the resolved endpoints straddle the reported span.
|
||||||
This is the notes' equation~(obs): the one bridge factor that the emptiness and interval
|
This is the bracket-observability equation: the one bridge factor that the emptiness
|
||||||
equality factors do not imply. It is discharged by the empty theory's gap split at
|
and interval equality factors do not imply. It is discharged by the empty theory's gap split at
|
||||||
positive offsets (the stored counts in `[begin.key, k₀)` and `[end.key, kₙ)`), which is
|
positive offsets (the stored counts in `[begin.key, k₀)` and `[end.key, kₙ)`), which is
|
||||||
why the pins `resolve begin = k₀` / `resolve end_ = keyAfter kₙ` do not by themselves
|
why the pins `resolve begin = k₀` / `resolve end_ = keyAfter kₙ` do not by themselves
|
||||||
remove it. -/
|
remove it. -/
|
||||||
@@ -1168,11 +1177,11 @@ merely open:
|
|||||||
nonempty key): there the hull need not be minimal;
|
nonempty key): there the hull need not be minimal;
|
||||||
* the `begin.offset ≠ 1` cell at an overshooting-free end, where the resolved begin may
|
* the `begin.offset ≠ 1` cell at an overshooting-free end, where the resolved begin may
|
||||||
clamp to `⊤` on one side of an agreement and to a stored key on the other, so the hull
|
clamp to `⊤` on one side of an agreement and to a stored key on the other, so the hull
|
||||||
is *unsound* (`FormalConflictRange.Counterexample.cw_notSound`). That cell has no
|
is *unsound* (a compatible witness refutes it). That cell has no
|
||||||
single minimal shape either: the `cwMin` value (the bare successor of the greatest
|
single minimal shape either: the bare-successor value (the successor of the greatest
|
||||||
reported key) at `end.offset = 2` fails once the end selector's slack runs the window
|
reported key) at `end.offset = 2` fails once the end selector's slack runs the window
|
||||||
past the reported last, as `Counterexample.ns_cand_notSound` records, with every key
|
past the reported last, as a compatible witness shows, with every key necessary and
|
||||||
necessary (`ns_top_minimal`) and the true value the unbounded top (`ns_top_sound`).
|
the true value the unbounded top.
|
||||||
|
|
||||||
`conflictRangePartial` returns `none` on both, so `completeValue` is a totalization
|
`conflictRangePartial` returns `none` on both, so `completeValue` is a totalization
|
||||||
whose hull fallback is not correct off the canonical and overshoot regions. -/
|
whose hull fallback is not correct off the canonical and overshoot regions. -/
|
||||||
@@ -1196,17 +1205,15 @@ result is dispatched on emptiness, truncation, and traversal:
|
|||||||
The low and high contributions are the empty boundary reads' minimal ranges, each the
|
The low and high contributions are the empty boundary reads' minimal ranges, each the
|
||||||
empty range when its read is trivially empty; the definition is computable.
|
empty range when its read is trivially empty; the definition is computable.
|
||||||
|
|
||||||
**This is a provisional totalization, not the object of record.** The
|
**This is a provisional totalization, not the headline algorithm.** The
|
||||||
certified algorithm is `conflictRangePartial`; `conflictRangeVal` is the
|
certified algorithm is `conflictRangePartial`; `conflictRangeVal` is the
|
||||||
every-input `ConflictRange`-valued wrapper, and its branches off the certified
|
every-input `ConflictRange`-valued wrapper, and its branches off the certified
|
||||||
region (the truncated dispatch and the `completeValue` hull fallback) are *not*
|
region (the truncated dispatch and the `completeValue` hull fallback) are *not*
|
||||||
sound in general — the kernel-checked `FormalConflictRange.Counterexample`
|
sound in general — explicit counterexamples in the complete hull and in the
|
||||||
(`cw_notSound`, and the truncated-branch violations) record this. Its correctness
|
truncated branches record this. Its correctness
|
||||||
theorems (`conflictRangeVal_spec`, `_spec_of_witness`, `_spec_complete`) are stated
|
theorems (`conflictRangeVal_spec`, `_spec_of_witness`, `_spec_complete`) are stated
|
||||||
relative to the open `EmptyTheoryComplete` and are consequently vacuous, not the
|
relative to the conditional `EmptyTheoryComplete` and are consequently vacuous, not
|
||||||
headline claim. Once `conflictRangePartial` is proved total it becomes the
|
the headline claim. The unconditional statement is proved in `Proof.lean`. -/
|
||||||
`ConflictRange`-valued algorithm and this definition is subsumed by it; the naming
|
|
||||||
change is deferred until then. -/
|
|
||||||
def conflictRangeVal (r : RangeRead) (res : Result) : ConflictRange :=
|
def conflictRangeVal (r : RangeRead) (res : Result) : ConflictRange :=
|
||||||
if res.keys = [] then
|
if res.keys = [] then
|
||||||
emptyValue r
|
emptyValue r
|
||||||
@@ -1219,7 +1226,7 @@ def conflictRangeVal (r : RangeRead) (res : Result) : ConflictRange :=
|
|||||||
/-!
|
/-!
|
||||||
## The complete branch: the assembled hull
|
## The complete branch: the assembled hull
|
||||||
|
|
||||||
The complete branch is the section-7 reduction: the hull of the two boundary reads'
|
The complete branch is the reduction: the hull of the two boundary reads'
|
||||||
minimal ranges and the reported interval, necessary on the two boundary ranges
|
minimal ranges and the reported interval, necessary on the two boundary ranges
|
||||||
(`BoundaryNecessity`) and the derived interior, and sound from `EmptyInference` once the
|
(`BoundaryNecessity`) and the derived interior, and sound from `EmptyInference` once the
|
||||||
bracket residue is supplied. -/
|
bracket residue is supplied. -/
|
||||||
@@ -1711,9 +1718,9 @@ theorem minimal_completeRange_of_jointBasesEmptyRev {r : RangeRead} {res : Resul
|
|||||||
ranges of `BoundaryNecessity`, obtained from the empty theory's flip witnesses, in
|
ranges of `BoundaryNecessity`, obtained from the empty theory's flip witnesses, in
|
||||||
whichever traversal order the read uses. This is the exact input the complete branch
|
whichever traversal order the read uses. This is the exact input the complete branch
|
||||||
extracts from the empty theory beyond `EmptyInference`; the extraction itself is the
|
extracts from the empty theory beyond `EmptyInference`; the extraction itself is the
|
||||||
length-sensitive graft recorded in the notes. It is *false* — the endpoints are those of the
|
length-sensitive graft described above. It is *false* — the endpoints are those of the
|
||||||
(unsound) hull, and `BoundaryNecessity` on them can demand keys that no sound range need
|
(unsound) hull, and `BoundaryNecessity` on them can demand keys that no sound range need
|
||||||
contain (`FormalConflictRange.Counterexample.cw_notBoundaryJointBases`). -/
|
contain (a two-key witness refutes it). -/
|
||||||
def BoundaryJointBases (r : RangeRead) (res : Result) : Prop :=
|
def BoundaryJointBases (r : RangeRead) (res : Result) : Prop :=
|
||||||
if r.reverse then
|
if r.reverse then
|
||||||
LowerJointBaseRangeRev r res.keys (completeRange r res).begin
|
LowerJointBaseRangeRev r res.keys (completeRange r res).begin
|
||||||
@@ -1760,7 +1767,7 @@ theorem minimal_completeRange_of_factors_joint_rev {r : RangeRead} {res : Result
|
|||||||
/-- **The complete branch, from `EmptyInferenceWitness` and the joint bases.** The
|
/-- **The complete branch, from `EmptyInferenceWitness` and the joint bases.** The
|
||||||
witness-exposing oracle supplies soundness (`EmptyInference` via
|
witness-exposing oracle supplies soundness (`EmptyInference` via
|
||||||
`emptyInference_of_witness`); the joint bases remain the one extraction hypothesis (false in
|
`emptyInference_of_witness`); the joint bases remain the one extraction hypothesis (false in
|
||||||
general: `FormalConflictRange.Counterexample.cw_notBoundaryJointBases`). This
|
general: a two-key witness refutes it). This
|
||||||
is the sharpest form of the reduction available: the reported keys and their convex hull
|
is the sharpest form of the reduction available: the reported keys and their convex hull
|
||||||
are derived, and the boundary necessity is stated at the witness level rather than as the
|
are derived, and the boundary necessity is stated at the witness level rather than as the
|
||||||
finished `BoundaryNecessity`. -/
|
finished `BoundaryNecessity`. -/
|
||||||
@@ -2055,16 +2062,17 @@ The forward/reverse truncated values are the lower/upper boundary contribution's
|
|||||||
begin/end glued to the reported interval. The offset-one certificates above are the
|
begin/end glued to the reported interval. The offset-one certificates above are the
|
||||||
same statement via `emptyValue`; the general statement is the same reduction as the
|
same statement via `emptyValue`; the general statement is the same reduction as the
|
||||||
complete branch, with the far boundary read replaced by the reported interval. Those
|
complete branch, with the far boundary read replaced by the reported interval. Those
|
||||||
reductions are the remaining obligations of the truncated branches and are stated in
|
reductions are the remaining obligations of the truncated branches and are stated
|
||||||
the notes.
|
separately.
|
||||||
-/
|
-/
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
## The empty branch
|
## The empty branch
|
||||||
|
|
||||||
The empty result is answered by `emptyValue`, reading off the empty theory's cases.
|
The empty result is answered by `emptyValue`, reading off the empty theory's cases.
|
||||||
The offset-one underEnd case is certified below; the remaining offsets are the open
|
The offset-one underEnd case is certified below; the remaining offsets are handled
|
||||||
empty theory.
|
by the separate empty-theory development (`FormalConflictRange.Empty`,
|
||||||
|
`FormalConflictRange.Nonpos`).
|
||||||
-/
|
-/
|
||||||
|
|
||||||
/-- **The empty branch, `begin.offset = 1`, `end.offset ≤ 1`.** A non-trivially-empty
|
/-- **The empty branch, `begin.offset = 1`, `end.offset ≤ 1`.** A non-trivially-empty
|
||||||
@@ -2103,7 +2111,7 @@ theorem minimal_emptyValue_underEnd (r : RangeRead) (hbegin : r.begin.offset = 1
|
|||||||
Traversal is invisible to the empty inference, and `emptyValue` never mentions
|
Traversal is invisible to the empty inference, and `emptyValue` never mentions
|
||||||
`reverse`, so `EmptyInference` reduces to its non-reversed instance; and the
|
`reverse`, so `EmptyInference` reduces to its non-reversed instance; and the
|
||||||
`begin.offset = 1` instance splits by the end offset into the three empty cases already
|
`begin.offset = 1` instance splits by the end offset into the three empty cases already
|
||||||
in the library. This pins the open empty-theory content to `begin.offset ≠ 1`.
|
in the library. This pins the uncertified empty-theory content to `begin.offset ≠ 1`.
|
||||||
-/
|
-/
|
||||||
|
|
||||||
/-- `AlwaysEmpty` is invariant under flipping the traversal. -/
|
/-- `AlwaysEmpty` is invariant under flipping the traversal. -/
|
||||||
@@ -2473,7 +2481,7 @@ theorem conflictRangeVal_spec_of_witness {r : RangeRead} {res : Result}
|
|||||||
exact minimal_completeRange_of_witness_joint_rev hempty ⟨db, hcomp⟩ hr hm hkeys hp hlim
|
exact minimal_completeRange_of_witness_joint_rev hempty ⟨db, hcomp⟩ hr hm hkeys hp hlim
|
||||||
hc.joint hbr
|
hc.joint hbr
|
||||||
|
|
||||||
/-- The existence conjecture follows from the witness-exposing empty oracle and the two
|
/-- Existence follows from the witness-exposing empty oracle and the two
|
||||||
nonempty obligations: the value witnesses a minimal sound range, with all offset handling
|
nonempty obligations: the value witnesses a minimal sound range, with all offset handling
|
||||||
confined to the empty theory. -/
|
confined to the empty theory. -/
|
||||||
theorem conjecture_exists_minimal_conflict_range_of_witness {r : RangeRead} {res : Result}
|
theorem conjecture_exists_minimal_conflict_range_of_witness {r : RangeRead} {res : Result}
|
||||||
@@ -2524,7 +2532,7 @@ theorem conflictRangeVal_spec {r : RangeRead} {res : Result}
|
|||||||
exact minimal_completeRange_of_factors hempty hread (by simpa using hr) hm hkeys
|
exact minimal_completeRange_of_factors hempty hread (by simpa using hr) hm hkeys
|
||||||
hψ hbr
|
hψ hbr
|
||||||
|
|
||||||
/-- The existence conjecture follows from the empty inference, the boundary `ψ`, the
|
/-- Existence follows from the empty inference, the boundary `ψ`, the
|
||||||
bracket factor, and the truncated obligation: the value witnesses a minimal sound
|
bracket factor, and the truncated obligation: the value witnesses a minimal sound
|
||||||
range. -/
|
range. -/
|
||||||
theorem conjecture_exists_minimal_conflict_range {r : RangeRead} {res : Result}
|
theorem conjecture_exists_minimal_conflict_range {r : RangeRead} {res : Result}
|
||||||
@@ -2548,12 +2556,11 @@ empty theory's analysis at the boundary reads; none is an offset analysis of the
|
|||||||
read. With them the general case is the offset-free assembly.
|
read. With them the general case is the offset-free assembly.
|
||||||
|
|
||||||
`EmptyTheoryComplete` implies the abstract `EmptyInference` (`EmptyTheoryComplete.emptyInference`)
|
`EmptyTheoryComplete` implies the abstract `EmptyInference` (`EmptyTheoryComplete.emptyInference`)
|
||||||
and the conjecture (`exists_minimal_conflict_range_of_complete`). It is the exact form of
|
and the existence statement (`exists_minimal_conflict_range_of_complete`). It is the exact
|
||||||
"the empty theory is finished": there is nothing else to prove. In fact it is *refuted*:
|
form of "the empty theory is finished": there is nothing else to prove. In fact it is
|
||||||
all three of `joint`, `bracket`, and `truncated` are false, independently
|
*refuted*: each of `joint`, `bracket`, and `truncated` has an explicit compatible
|
||||||
(`FormalConflictRange.Counterexample.cw_emptyTheoryComplete_false`,
|
counterexample, so the structure is uninhabited and the reduction is not a route to the
|
||||||
`ce_emptyTheoryComplete_false`, `tr_emptyTheoryComplete_false`), so the structure is
|
headline. -/
|
||||||
uninhabited and the reduction is not a route to the headline. -/
|
|
||||||
|
|
||||||
/-- **A complete empty theory, in reduction form.** The empty-result theory together with
|
/-- **A complete empty theory, in reduction form.** The empty-result theory together with
|
||||||
the generic graft, the bracket gap split, and the truncated one-sided graft. Every field
|
the generic graft, the bracket gap split, and the truncated one-sided graft. Every field
|
||||||
@@ -2616,7 +2623,7 @@ theorem conflictRangeVal_spec_complete (H : EmptyTheoryComplete) {r : RangeRead}
|
|||||||
conflictRangeVal_spec_of_witness H.witness (H.truncated r res hread)
|
conflictRangeVal_spec_of_witness H.witness (H.truncated r res hread)
|
||||||
(H.completeObligation r res hread) hread
|
(H.completeObligation r res hread) hread
|
||||||
|
|
||||||
/-- **The existence conjecture from a complete empty theory.** -/
|
/-- **Existence from a complete empty theory.** -/
|
||||||
theorem exists_minimal_conflict_range_of_complete (H : EmptyTheoryComplete) {r : RangeRead}
|
theorem exists_minimal_conflict_range_of_complete (H : EmptyTheoryComplete) {r : RangeRead}
|
||||||
{res : Result} (hread : Readable r res) :
|
{res : Result} (hread : Readable r res) :
|
||||||
∃ cr : ConflictRange, Minimal r res cr :=
|
∃ cr : ConflictRange, Minimal r res cr :=
|
||||||
@@ -3102,8 +3109,7 @@ With `begin.offset ≤ 0`, `end.offset = 1` and `begin.key ≤ end.key`, `emptyV
|
|||||||
bottom range `[⊥, end.key)`, and every key below `end.key` has the singleton flip witness:
|
bottom range `[⊥, end.key)`, and every key below `end.key` has the singleton flip witness:
|
||||||
the empty database is compatible (`compatible_emptyDB_emptyRes`) and toggling `k` gives
|
the empty database is compatible (`compatible_emptyDB_emptyRes`) and toggling `k` gives
|
||||||
`{k}`, whose complete keys are nonempty (`not_compatible_singleton_self`). This is the
|
`{k}`, whose complete keys are nonempty (`not_compatible_singleton_self`). This is the
|
||||||
witness-exposing companion of `minimal_bottomRange_of_nonpos_end_one`, and it is the part
|
witness-exposing companion of `minimal_bottomRange_of_nonpos_end_one`. -/
|
||||||
of issue #19's item 1 that the single-key witness still separates. -/
|
|
||||||
theorem emptyWitness_nonpos_end_one_crossFree (r : RangeRead) (hbegin : r.begin.offset ≤ 0)
|
theorem emptyWitness_nonpos_end_one_crossFree (r : RangeRead) (hbegin : r.begin.offset ≤ 0)
|
||||||
(hend : r.end_.offset = 1) (hle : r.begin.key ≤ r.end_.key)
|
(hend : r.end_.offset = 1) (hle : r.begin.key ≤ r.end_.key)
|
||||||
(_hread : Readable r { keys := [], more := false }) :
|
(_hread : Readable r { keys := [], more := false }) :
|
||||||
@@ -4133,11 +4139,11 @@ range on every realizable read/result pair. This section makes the objective pre
|
|||||||
locates it relative to the existence headline. As a *function*, the objective is not
|
locates it relative to the existence headline. As a *function*, the objective is not
|
||||||
stronger than the headline: given the headline, `Classical.choice` turns the pointwise
|
stronger than the headline: given the headline, `Classical.choice` turns the pointwise
|
||||||
existentials into a total `ConflictRange`-valued function, and `conflictRangeTotal` below
|
existentials into a total `ConflictRange`-valued function, and `conflictRangeTotal` below
|
||||||
refines the algorithm of record `conflictRangePartial` — it agrees with it on every
|
refines the certified algorithm `conflictRangePartial` — it agrees with it on every
|
||||||
certified `some` value, and on the uncertified `none` branches returns the chosen minimal
|
certified `some` value, and on the uncertified `none` branches returns the chosen minimal
|
||||||
range. What would be strictly stronger is a *computable* total algorithm, i.e. branch
|
range. What would be strictly stronger is a *computable* total algorithm, i.e. branch
|
||||||
completeness of `conflictRangePartial`, which is blocked on exactly the regions where no
|
completeness of `conflictRangePartial`, which is blocked on exactly the regions where no
|
||||||
offset-formula candidate exists (`cwMin` versus the unbounded top).
|
offset-formula candidate exists (the bare successor versus the unbounded top).
|
||||||
-/
|
-/
|
||||||
|
|
||||||
/-- The desired outcome, as a proposition: a total `ConflictRange`-valued algorithm that
|
/-- The desired outcome, as a proposition: a total `ConflictRange`-valued algorithm that
|
||||||
@@ -4169,7 +4175,7 @@ theorem totalMinimalAlgorithm_iff :
|
|||||||
rw [dite_eq_left hh]
|
rw [dite_eq_left hh]
|
||||||
exact Classical.choose_spec hh
|
exact Classical.choose_spec hh
|
||||||
|
|
||||||
/-- **A totalization of the algorithm of record.** Given the headline, `conflictRangePartial`
|
/-- **A totalization of the certified algorithm.** Given the headline, `conflictRangePartial`
|
||||||
extends to a total algorithm that is minimal on every realizable pair: it keeps the certified
|
extends to a total algorithm that is minimal on every realizable pair: it keeps the certified
|
||||||
value where `conflictRangePartial` returns `some`, and on the uncertified `none` branches
|
value where `conflictRangePartial` returns `some`, and on the uncertified `none` branches
|
||||||
returns the (classically chosen) minimal range. Making it *computable* — filling the `none`
|
returns the (classically chosen) minimal range. Making it *computable* — filling the `none`
|
||||||
@@ -4200,7 +4206,7 @@ theorem conflictRangeTotal_spec
|
|||||||
rw [dite_eq_left hh]
|
rw [dite_eq_left hh]
|
||||||
exact Classical.choose_spec hh
|
exact Classical.choose_spec hh
|
||||||
|
|
||||||
/-- `conflictRangeTotal` agrees with the algorithm of record on every certified `some`
|
/-- `conflictRangeTotal` agrees with the certified algorithm on every certified `some`
|
||||||
value. -/
|
value. -/
|
||||||
theorem conflictRangeTotal_eq_partial
|
theorem conflictRangeTotal_eq_partial
|
||||||
(h : ∀ r res, Readable r res → ∃ cr : ConflictRange, Minimal r res cr)
|
(h : ∀ r res, Readable r res → ∃ cr : ConflictRange, Minimal r res cr)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import Mathlib
|
import Mathlib
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.General
|
import FormalConflictRange.General
|
||||||
import FormalConflictRange.Sound
|
import FormalConflictRange.Sound
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.CrossedTruncatedGeneral
|
import FormalConflictRange.CrossedTruncatedGeneral
|
||||||
import FormalConflictRange.CrossedRevGeneral
|
import FormalConflictRange.CrossedRevGeneral
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.CrossedRev
|
import FormalConflictRange.CrossedRev
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.ComputableHull
|
import FormalConflictRange.ComputableHull
|
||||||
import FormalConflictRange.ComputableSearch
|
import FormalConflictRange.ComputableSearch
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.General
|
import FormalConflictRange.General
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.FiniteCountDecider
|
import FormalConflictRange.FiniteCountDecider
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.RangeRead
|
import FormalConflictRange.RangeRead
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.General
|
import FormalConflictRange.General
|
||||||
import FormalConflictRange.Prototype
|
import FormalConflictRange.Prototype
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.Residual
|
import FormalConflictRange.Residual
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
import FormalConflictRange.ClosedForm
|
import FormalConflictRange.ClosedForm
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.CrossedTruncated
|
import FormalConflictRange.CrossedTruncated
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.CrossedRevGeneral
|
import FormalConflictRange.CrossedRevGeneral
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.CrossedResidual
|
import FormalConflictRange.CrossedResidual
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.CrossedTruncated
|
import FormalConflictRange.CrossedTruncated
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.CrossedRev
|
import FormalConflictRange.CrossedRev
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.CrossedClosedForm
|
import FormalConflictRange.CrossedClosedForm
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
import FormalConflictRange.CrossedGeneral
|
import FormalConflictRange.CrossedGeneral
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import Mathlib
|
import Mathlib
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Sound
|
import FormalConflictRange.Sound
|
||||||
|
|
||||||
@@ -2297,8 +2295,8 @@ disjunct is unsatisfiable and `ψ` reduces to "no stored key `≥ B`".
|
|||||||
/-- **The emptiness predicate.** At `begin.offset = 1` and `end_.offset ≥ 1`, an
|
/-- **The emptiness predicate.** At `begin.offset = 1` and `end_.offset ≥ 1`, an
|
||||||
empty complete result is compatible with `db` exactly when either no stored key
|
empty complete result is compatible with `db` exactly when either no stored key
|
||||||
reaches `begin.key` (`c_B = n`) or the count difference is at least
|
reaches `begin.key` (`c_B = n`) or the count difference is at least
|
||||||
`end_.offset - 1`. This is the formal counterpart of the predicate `ψ` derived in
|
`end_.offset - 1`. This is the formal counterpart of the predicate `ψ` derived from the
|
||||||
the notes, and it holds regardless of the relative order of the selector keys. -/
|
slice characterization, and it holds regardless of the relative order of the selector keys. -/
|
||||||
theorem completeKeys_eq_nil_iff_counts {db : DB} {r : RangeRead}
|
theorem completeKeys_eq_nil_iff_counts {db : DB} {r : RangeRead}
|
||||||
(hbegin : r.begin.offset = 1) (hoE : 1 ≤ r.end_.offset) :
|
(hbegin : r.begin.offset = 1) (hoE : 1 ≤ r.end_.offset) :
|
||||||
RangeRead.completeKeys db r = [] ↔
|
RangeRead.completeKeys db r = [] ↔
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.CountBridge
|
import FormalConflictRange.CountBridge
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Prototype
|
import FormalConflictRange.Prototype
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
import FormalConflictRange.NegCrossComplete
|
import FormalConflictRange.NegCrossComplete
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossComplete
|
import FormalConflictRange.NegCrossComplete
|
||||||
import FormalConflictRange.NegCrossLongNonpos
|
import FormalConflictRange.NegCrossLongNonpos
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossBottom
|
import FormalConflictRange.NegCrossBottom
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.CrossedGeneral
|
import FormalConflictRange.CrossedGeneral
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NonposClosedForm
|
import FormalConflictRange.NonposClosedForm
|
||||||
import FormalConflictRange.NegCrossClosedForm
|
import FormalConflictRange.NegCrossClosedForm
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossCompleteResidual
|
import FormalConflictRange.NegCrossCompleteResidual
|
||||||
|
|
||||||
@@ -20,8 +18,8 @@ last reported key, `q = beginSlack` and `r = reportedBelowBegin`, put `C = q + 1
|
|||||||
(so `C ≥ 1` in the clamping cell). The upper endpoint is `begin.key` when the interval
|
(so `C ≥ 1` in the clamping cell). The upper endpoint is `begin.key` when the interval
|
||||||
`[keyAfter L, begin.key)` holds `C` keys (or `C + 1` keys when `end.key = ⊥`), and
|
`[keyAfter L, begin.key)` holds `C` keys (or `C + 1` keys when `end.key = ⊥`), and
|
||||||
`keyAfter L` otherwise. The witness `res = [[5], [6]]`, `end.key = [1]`,
|
`keyAfter L` otherwise. The witness `res = [[5], [6]]`, `end.key = [1]`,
|
||||||
`begin.key = [6,0,0]`, `begin.offset = -3`, `end.offset = 3` is kernel-checked in
|
`begin.key = [6,0,0]`, `begin.offset = -3`, `end.offset = 3` refutes the rule:
|
||||||
`Counterexample.lean` (`nch_M_not_minimal`): every compatible database then has
|
every compatible database then has
|
||||||
`begin.key = [6,0,0]` strictly above `keyAfter last = [6,0]`, but the extra key `[6,0]`
|
`begin.key = [6,0,0]` strictly above `keyAfter last = [6,0]`, but the extra key `[6,0]`
|
||||||
lies in no sound range, so the `max` rule over-collects it.
|
lies in no sound range, so the `max` rule over-collects it.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossComplete
|
import FormalConflictRange.NegCrossComplete
|
||||||
import FormalConflictRange.NegCrossClosedForm
|
import FormalConflictRange.NegCrossClosedForm
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossCompleteHigh
|
import FormalConflictRange.NegCrossCompleteHigh
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossResidual
|
import FormalConflictRange.NegCrossResidual
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossClampNonpos
|
import FormalConflictRange.NegCrossClampNonpos
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossLongNonpos
|
import FormalConflictRange.NegCrossLongNonpos
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncClampLastGe
|
import FormalConflictRange.NegCrossTruncClampLastGe
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncNonclamp
|
import FormalConflictRange.NegCrossTruncNonclamp
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncClamp
|
import FormalConflictRange.NegCrossTruncClamp
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossClampNonpos
|
import FormalConflictRange.NegCrossClampNonpos
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossClampLongNonpos
|
import FormalConflictRange.NegCrossClampLongNonpos
|
||||||
import FormalConflictRange.NonposRevClosedForm
|
import FormalConflictRange.NonposRevClosedForm
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossComplete
|
import FormalConflictRange.NegCrossComplete
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncNonclamp
|
import FormalConflictRange.NegCrossTruncNonclamp
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncBottomGap
|
import FormalConflictRange.NegCrossTruncBottomGap
|
||||||
@@ -30,10 +28,12 @@ The soundness half is complete.
|
|||||||
transports the resolution across agreement on that gap; this yields soundness of
|
transports the resolution across agreement on that gap; this yields soundness of
|
||||||
`[head, U)` (`sound_headLong_of_nonbottom`).
|
`[head, U)` (`sound_headLong_of_nonbottom`).
|
||||||
|
|
||||||
The necessity half is still open; see `notes/main.tex`. It splits into toggle witnesses
|
The necessity half is proved in the companion modules
|
||||||
|
`NegCrossTruncNonposGapA2a`, `NegCrossTruncNonposGapA2aBottom`, and
|
||||||
|
`NegCrossTruncNonposGapCrossFree`. It splits into toggle witnesses
|
||||||
for keys in `(last, end_.key)` (erase) and in `[end_.key, U)` (insert), with the filler
|
for keys in `(last, end_.key)` (erase) and in `[end_.key, U)` (insert), with the filler
|
||||||
budget determined by `clampNonposBottom`. The closed form `closedFormNegCrossTruncNonposGap`
|
budget determined by `clampNonposBottom`. The closed form `closedFormNegCrossTruncNonposGap`
|
||||||
is recorded here so the dispatch can be wired once the necessity lemmas land.
|
is defined here; the companion modules prove it minimal on the three subcells.
|
||||||
-/
|
-/
|
||||||
|
|
||||||
namespace FormalConflictRange
|
namespace FormalConflictRange
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncNonposGap
|
import FormalConflictRange.NegCrossTruncNonposGap
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncNonposGapA2a
|
import FormalConflictRange.NegCrossTruncNonposGapA2a
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.NegCrossTruncNonposGapA2aBottom
|
import FormalConflictRange.NegCrossTruncNonposGapA2aBottom
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevFinite
|
import FormalConflictRange.NegCrossTruncRevFinite
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevBeginTop
|
import FormalConflictRange.NegCrossTruncRevBeginTop
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevBeginTop
|
import FormalConflictRange.NegCrossTruncRevBeginTop
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevCrossedSmall
|
import FormalConflictRange.NegCrossTruncRevCrossedSmall
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevCrossedLarge
|
import FormalConflictRange.NegCrossTruncRevCrossedLarge
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevNonpos
|
import FormalConflictRange.NegCrossTruncRevNonpos
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevTop
|
import FormalConflictRange.NegCrossTruncRevTop
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevBeginTop
|
import FormalConflictRange.NegCrossTruncRevBeginTop
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevCrossedNonpos
|
import FormalConflictRange.NegCrossTruncRevCrossedNonpos
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevResidualLargeSentinel
|
import FormalConflictRange.NegCrossTruncRevResidualLargeSentinel
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevResidualFinite
|
import FormalConflictRange.NegCrossTruncRevResidualFinite
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevResidualLargeTop
|
import FormalConflictRange.NegCrossTruncRevResidualLargeTop
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncRevResidual
|
import FormalConflictRange.NegCrossTruncRevResidual
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncClamp
|
import FormalConflictRange.NegCrossTruncClamp
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncClampLastGe
|
import FormalConflictRange.NegCrossTruncClampLastGe
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NegCrossTruncStrictTop
|
import FormalConflictRange.NegCrossTruncStrictTop
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
import FormalConflictRange.Reduction
|
import FormalConflictRange.Reduction
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.Residual
|
import FormalConflictRange.Residual
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.NonposClosedForm
|
import FormalConflictRange.NonposClosedForm
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.Algorithm
|
import FormalConflictRange.Algorithm
|
||||||
@@ -79,7 +77,7 @@ conjoins its argument.
|
|||||||
* `hullRanges`, `collectReadOff`, `sound_collectReadOff` — the concrete computable
|
* `hullRanges`, `collectReadOff`, `sound_collectReadOff` — the concrete computable
|
||||||
read-off (hull of the required boundary `emptyValue`s and the bracket/core supports)
|
read-off (hull of the required boundary `emptyValue`s and the bracket/core supports)
|
||||||
and its **unconditional** soundness, for any realizable read/result with nonempty
|
and its **unconditional** soundness, for any realizable read/result with nonempty
|
||||||
ascending reported keys. It validates on the old counterexample `ceRead`, whose
|
ascending reported keys. It validates on an earlier counterexample whose
|
||||||
`completeRange` was unsound.
|
`completeRange` was unsound.
|
||||||
* `sound_congr_toSet`, `minimal_congr_toSet`, `minimal_collectReadOff_of_subrange` —
|
* `sound_congr_toSet`, `minimal_congr_toSet`, `minimal_collectReadOff_of_subrange` —
|
||||||
soundness/minimality depend on a range only through its key set, so the read-off is
|
soundness/minimality depend on a range only through its key set, so the read-off is
|
||||||
@@ -99,14 +97,15 @@ conjoins its argument.
|
|||||||
it contained in the minimal range; `minimal_inter_collectReadOff_of_minimal` is the
|
it contained in the minimal range; `minimal_inter_collectReadOff_of_minimal` is the
|
||||||
wrapper for the read-off, and `minimal_inter_collectReadOff_truncated_fwd`/`_rev` (+ the
|
wrapper for the read-off, and `minimal_inter_collectReadOff_truncated_fwd`/`_rev` (+ the
|
||||||
overshoot variant) apply it to the truncated branch, where the read-off alone overshoots
|
overshoot variant) apply it to the truncated branch, where the read-off alone overshoots
|
||||||
(`Counterexample.ct_collectReadOff_not_minimal`).
|
(an explicit truncated witness).
|
||||||
* `reported_keys_bounds`, `subrange_collectReadOff_canonical`,
|
* `reported_keys_bounds`, `subrange_collectReadOff_canonical`,
|
||||||
`collectReadOff_toSet_eq_canonical`, `minimal_collectReadOff_canonical` — the
|
`collectReadOff_toSet_eq_canonical`, `minimal_collectReadOff_canonical` — the
|
||||||
canonical-region containment, proved. For a complete nonempty realizable pair in
|
canonical-region containment, proved. For a complete nonempty realizable pair in
|
||||||
`1 ≤ begin.offset ∧ end_.offset ≤ 1`, every reported key lies in `[begin.key, end.key)`,
|
`1 ≤ begin.offset ∧ end_.offset ≤ 1`, every reported key lies in `[begin.key, end.key)`,
|
||||||
so each boundary `emptyValue` and bracket/core support is contained in the canonical
|
so each boundary `emptyValue` and bracket/core support is contained in the canonical
|
||||||
range; the read-off is contained in it and, being sound, shares its key set. Thus
|
range; the read-off is contained in it and, being sound, shares its key set. Thus
|
||||||
`collectReadOff` is minimal there, extending end-to-end minimality beyond `ceRead`.
|
`collectReadOff` is minimal there, extending end-to-end minimality beyond the earlier
|
||||||
|
counterexamples.
|
||||||
* `subrange_collectReadOff_topRange`, `minimal_collectReadOff_topRange` — the
|
* `subrange_collectReadOff_topRange`, `minimal_collectReadOff_topRange` — the
|
||||||
overshoot-region containment, proved. For a complete nonempty realizable pair in
|
overshoot-region containment, proved. For a complete nonempty realizable pair in
|
||||||
`1 ≤ begin.offset ∧ 2 ≤ end.offset` with every reported key below `end.key`, the
|
`1 ≤ begin.offset ∧ 2 ≤ end.offset` with every reported key below `end.key`, the
|
||||||
@@ -483,7 +482,7 @@ theorem shortGap_not_le (db : DB) {g : ℕ} {lo hi : WithTop Key} (hfin : lo ≤
|
|||||||
/-- The constraints a complete nonempty result exposes, in difference form. `B`
|
/-- The constraints a complete nonempty result exposes, in difference form. `B`
|
||||||
and `E` are the selector keys, `oB`/`oE` their offsets, `L` the reported keys.
|
and `E` are the selector keys, `oB`/`oE` their offsets, `L` the reported keys.
|
||||||
|
|
||||||
The binding directions are chosen from the bridge analysis of the main notes,
|
The binding directions are chosen from the bridge analysis of the main development,
|
||||||
displayed in the single normal form `ρ hi − ρ lo ≤ n` (`ge` is `le` with the
|
displayed in the single normal form `ρ hi − ρ lo ≤ n` (`ge` is `le` with the
|
||||||
endpoints swapped and the bound negated):
|
endpoints swapped and the bound negated):
|
||||||
|
|
||||||
@@ -2723,7 +2722,7 @@ theorem collectReadOff_toSet_eq_canonical {r : RangeRead} {res : Result}
|
|||||||
/-- **Minimality of the concrete read-off in the canonical region.** For a complete
|
/-- **Minimality of the concrete read-off in the canonical region.** For a complete
|
||||||
nonempty realizable read/result pair with `1 ≤ begin.offset` and `end_.offset ≤ 1`, the
|
nonempty realizable read/result pair with `1 ≤ begin.offset` and `end_.offset ≤ 1`, the
|
||||||
computable hull `collectReadOff` is a minimal sound conflict range. This extends
|
computable hull `collectReadOff` is a minimal sound conflict range. This extends
|
||||||
end-to-end minimality beyond the counterexample `ceRead`. -/
|
end-to-end minimality beyond the earlier counterexamples. -/
|
||||||
theorem minimal_collectReadOff_canonical {r : RangeRead} {res : Result}
|
theorem minimal_collectReadOff_canonical {r : RangeRead} {res : Result}
|
||||||
(hread : Readable r res) (hmore : res.more = false) (hne : res.keys ≠ [])
|
(hread : Readable r res) (hmore : res.more = false) (hne : res.keys ≠ [])
|
||||||
(hbegin : 1 ≤ r.begin.offset) (hend : r.end_.offset ≤ 1) :
|
(hbegin : 1 ≤ r.begin.offset) (hend : r.end_.offset ≤ 1) :
|
||||||
@@ -2922,7 +2921,7 @@ theorem minimal_collectReadOff_complete_general {r : RangeRead} {res : Result}
|
|||||||
|
|
||||||
/-! ### The truncated branch through the meet
|
/-! ### The truncated branch through the meet
|
||||||
|
|
||||||
The read-off over-collects on a truncated result (`Counterexample.ct_collectReadOff_not_minimal`),
|
The read-off over-collects on a truncated result (an explicit truncated witness),
|
||||||
but its meet with the algorithm's proven-minimal truncated value is still minimal
|
but its meet with the algorithm's proven-minimal truncated value is still minimal
|
||||||
(`minimal_inter_of_sound_of_minimal`): the meet is sound, so it sits inside the minimal
|
(`minimal_inter_of_sound_of_minimal`): the meet is sound, so it sits inside the minimal
|
||||||
range, and being a subrange of it (the minimal range is itself a subrange of the
|
range, and being a subrange of it (the minimal range is itself a subrange of the
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Selector
|
import FormalConflictRange.Selector
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
|
|
||||||
@@ -743,7 +741,7 @@ theorem compatible_iff_bridge_general {db : DB} {r : RangeRead} {A : List Key} {
|
|||||||
|
|
||||||
The necessity half of the reduction never cites an end theorem directly: it needs
|
The necessity half of the reduction never cites an end theorem directly: it needs
|
||||||
only one full-compatible witness `db₀` and a single-key perturbation that breaks
|
only one full-compatible witness `db₀` and a single-key perturbation that breaks
|
||||||
the targeted factor. The generic statement below is the notes' Lemma 7.1: a sound
|
the targeted factor. The generic statement below is the factor-toggle lemma: a sound
|
||||||
range can omit a key `k` only if flipping `k`'s membership in a compatible
|
range can omit a key `k` only if flipping `k`'s membership in a compatible
|
||||||
database preserves compatibility. Since the flip is outside the range, soundness
|
database preserves compatibility. Since the flip is outside the range, soundness
|
||||||
forces compatibility on the flipped database; if that fails, `k` is necessary.
|
forces compatibility on the flipped database; if that fails, `k` is necessary.
|
||||||
@@ -766,7 +764,7 @@ theorem agreeOn_toggle_of_not_mem (cr : ConflictRange) (db : DB) {k : Key} (hk :
|
|||||||
AgreeOn cr db (toggle db k) :=
|
AgreeOn cr db (toggle db k) :=
|
||||||
(keys_toggle_of_not_mem cr db hk).symm
|
(keys_toggle_of_not_mem cr db hk).symm
|
||||||
|
|
||||||
/-- **Factor-toggle (Lemma 7.1).** If some database is compatible with `(r, res)` but
|
/-- **Factor-toggle.** If some database is compatible with `(r, res)` but
|
||||||
flipping the membership of `k` there breaks compatibility, then `k` is necessary:
|
flipping the membership of `k` there breaks compatibility, then `k` is necessary:
|
||||||
any sound range omitting `k` would see both databases as agreeing, so soundness
|
any sound range omitting `k` would see both databases as agreeing, so soundness
|
||||||
would transfer the compatibility, contradicting the break. -/
|
would transfer the compatibility, contradicting the break. -/
|
||||||
@@ -782,9 +780,9 @@ theorem necessary_of_toggle {r : RangeRead} {res : Result} {k : Key}
|
|||||||
/-- **The factor-toggle lemma.** Suppose compatibility factors as `φ₁ ∧ φ₂` on
|
/-- **The factor-toggle lemma.** Suppose compatibility factors as `φ₁ ∧ φ₂` on
|
||||||
databases, some database `db₀` satisfies both factors, and flipping the membership
|
databases, some database `db₀` satisfies both factors, and flipping the membership
|
||||||
of `k` in `db₀` breaks `φ₁`. Then no range omitting `k` is sound: such a range sees
|
of `k` in `db₀` breaks `φ₁`. Then no range omitting `k` is sound: such a range sees
|
||||||
`db₀` and its flip as agreeing, so soundness would carry `φ₁`. This is the notes'
|
`db₀` and its flip as agreeing, so soundness would carry `φ₁`. This is the
|
||||||
Lemma 7.1, and it is the form the necessity constructions use — only the one
|
factor-toggle lemma in factored form, and it is the form the necessity
|
||||||
targeted factor must break. -/
|
constructions use — only the one targeted factor must break. -/
|
||||||
theorem not_sound_of_factor_toggle {r : RangeRead} {res : Result} {cr : ConflictRange}
|
theorem not_sound_of_factor_toggle {r : RangeRead} {res : Result} {cr : ConflictRange}
|
||||||
{φ₁ φ₂ : DB → Prop} {db₀ : DB} {k : Key}
|
{φ₁ φ₂ : DB → Prop} {db₀ : DB} {k : Key}
|
||||||
(hcomp : ∀ db, RangeRead.Compatible db r res ↔ (φ₁ db ∧ φ₂ db))
|
(hcomp : ∀ db, RangeRead.Compatible db r res ↔ (φ₁ db ∧ φ₂ db))
|
||||||
@@ -796,7 +794,7 @@ theorem not_sound_of_factor_toggle {r : RangeRead} {res : Result} {cr : Conflict
|
|||||||
(hs db₀ (toggle db₀ k) (agreeOn_toggle_of_not_mem cr db₀ hk)).mp hc₀
|
(hs db₀ (toggle db₀ k) (agreeOn_toggle_of_not_mem cr db₀ hk)).mp hc₀
|
||||||
exact hnot ((hcomp (toggle db₀ k)).mp hc₁).1
|
exact hnot ((hcomp (toggle db₀ k)).mp hc₁).1
|
||||||
|
|
||||||
/-- **Factor-toggle necessity.** Under the factorization of Lemma 7.1, a single
|
/-- **Factor-toggle necessity.** Under the factorization above, a single
|
||||||
database whose flip breaks one factor makes `k` necessary. -/
|
database whose flip breaks one factor makes `k` necessary. -/
|
||||||
theorem necessary_of_factor_toggle {r : RangeRead} {res : Result} {k : Key}
|
theorem necessary_of_factor_toggle {r : RangeRead} {res : Result} {k : Key}
|
||||||
{φ₁ φ₂ : DB → Prop} {db₀ : DB}
|
{φ₁ φ₂ : DB → Prop} {db₀ : DB}
|
||||||
@@ -810,7 +808,7 @@ theorem necessary_of_factor_toggle {r : RangeRead} {res : Result} {k : Key}
|
|||||||
/-!
|
/-!
|
||||||
## The joint base construction
|
## The joint base construction
|
||||||
|
|
||||||
Section 7's necessity argument does not transfer soundness from the end pair; it
|
The necessity argument does not transfer soundness from the end pair; it
|
||||||
exhibits a single database `db₀` that is compatible with the *full* result and whose
|
exhibits a single database `db₀` that is compatible with the *full* result and whose
|
||||||
flip at `k` breaks the targeted end factor. That object is named here: a *lower joint
|
flip at `k` breaks the targeted end factor. That object is named here: a *lower joint
|
||||||
base* for `k` is a full-compatible database whose flip makes the lower boundary read
|
base* for `k` is a full-compatible database whose flip makes the lower boundary read
|
||||||
@@ -821,7 +819,7 @@ factorization.
|
|||||||
|
|
||||||
/-- A **lower joint base** for `k`: a database compatible with the full complete
|
/-- A **lower joint base** for `k`: a database compatible with the full complete
|
||||||
result `⟨L, false⟩` (via the bridge) whose flip at `k` makes the lower boundary read
|
result `⟨L, false⟩` (via the bridge) whose flip at `k` makes the lower boundary read
|
||||||
nonempty, i.e. breaks the lower factor. This is the section-7 witness that turns the
|
nonempty, i.e. breaks the lower factor. This is the joint-base witness that turns the
|
||||||
empty lower certificate into `Necessary r res k`. -/
|
empty lower certificate into `Necessary r res k`. -/
|
||||||
def LowerJointBase (r : RangeRead) (L : List Key) (k : Key) : Prop :=
|
def LowerJointBase (r : RangeRead) (L : List Key) (k : Key) : Prop :=
|
||||||
∃ db₀ : DB, bridge r L db₀ ∧
|
∃ db₀ : DB, bridge r L db₀ ∧
|
||||||
@@ -1132,7 +1130,7 @@ theorem NecessaryRange.mono {r : RangeRead} {res : Result} {a b a' b' : WithTop
|
|||||||
middle interval `[cr₁.end_, cr₂.begin)` is necessary, the upper end range `cr₂` is
|
middle interval `[cr₁.end_, cr₂.begin)` is necessary, the upper end range `cr₂` is
|
||||||
necessary, and the intervals are ordered (`cr₁.begin ≤ cr₂.begin` and
|
necessary, and the intervals are ordered (`cr₁.begin ≤ cr₂.begin` and
|
||||||
`cr₁.end_ ≤ cr₂.end_`), then the hull `[cr₁.begin, cr₂.end_)` is necessary. This is
|
`cr₁.end_ ≤ cr₂.end_`), then the hull `[cr₁.begin, cr₂.end_)` is necessary. This is
|
||||||
exactly section 7's assembly: everything below the reported keys is the lower end,
|
exactly the hull assembly: everything below the reported keys is the lower end,
|
||||||
the interior is convexity, and everything above is the upper end. -/
|
the interior is convexity, and everything above is the upper end. -/
|
||||||
theorem necessaryRange_hull_of_chain {r : RangeRead} {res : Result}
|
theorem necessaryRange_hull_of_chain {r : RangeRead} {res : Result}
|
||||||
{cr₁ cr₂ : ConflictRange}
|
{cr₁ cr₂ : ConflictRange}
|
||||||
@@ -1185,7 +1183,7 @@ theorem minimal_hull_of_minimal_ends {r : RangeRead} {res : Result}
|
|||||||
|
|
||||||
/-- **Necessity of the hull from the joint bases.** With the lower joint bases below
|
/-- **Necessity of the hull from the joint bases.** With the lower joint bases below
|
||||||
the reported keys, the interior necessary by convexity, and the upper joint bases
|
the reported keys, the interior necessary by convexity, and the upper joint bases
|
||||||
above, the hull's necessary range is assembled. This is section 7's necessity
|
above, the hull's necessary range is assembled. This is the hull necessity
|
||||||
assembly: the ends via factor-toggle joint witnesses, the middle free. -/
|
assembly: the ends via factor-toggle joint witnesses, the middle free. -/
|
||||||
theorem necessaryRange_hull_of_jointBases {r : RangeRead} {res : Result} {L : List Key}
|
theorem necessaryRange_hull_of_jointBases {r : RangeRead} {res : Result} {L : List Key}
|
||||||
{cr₁ cr₂ : ConflictRange} (hrev : r.reverse = false) (hL : L ≠ [])
|
{cr₁ cr₂ : ConflictRange} (hrev : r.reverse = false) (hL : L ≠ [])
|
||||||
@@ -1201,7 +1199,7 @@ theorem necessaryRange_hull_of_jointBases {r : RangeRead} {res : Result} {L : Li
|
|||||||
hmid (necessaryRange_of_upperJointBaseRange hrev hL hpair hlim hres hhi) hmin hmax
|
hmid (necessaryRange_of_upperJointBaseRange hrev hL hpair hlim hres hhi) hmin hmax
|
||||||
|
|
||||||
/-- **Minimality of the hull from the joint bases and hull soundness.** This is the
|
/-- **Minimality of the hull from the joint bases and hull soundness.** This is the
|
||||||
end-to-end shape of the section-7 necessity argument: the end ranges are established
|
end-to-end shape of the necessity argument: the end ranges are established
|
||||||
by the joint bases (factor-toggle), the interior by convexity over the reported keys
|
by the joint bases (factor-toggle), the interior by convexity over the reported keys
|
||||||
(`necessaryRange_between_reported`), and the only remaining hypothesis is soundness
|
(`necessaryRange_between_reported`), and the only remaining hypothesis is soundness
|
||||||
of the hull — the soundness half of the reduction. -/
|
of the hull — the soundness half of the reduction. -/
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Basic
|
import FormalConflictRange.Basic
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.ClosedFormAll
|
import FormalConflictRange.ClosedFormAll
|
||||||
import FormalConflictRange.NegCrossTruncClampAny
|
import FormalConflictRange.NegCrossTruncClampAny
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.ConflictRange
|
import FormalConflictRange.ConflictRange
|
||||||
|
|
||||||
@@ -2132,7 +2130,7 @@ theorem minimal_iff_sound_and_necessaryRange {r : RangeRead} {res : Result}
|
|||||||
/-- A minimal sound range is contained in every sound range: intersecting it with
|
/-- A minimal sound range is contained in every sound range: intersecting it with
|
||||||
another sound range stays sound and is a subrange, so minimality forbids the
|
another sound range stays sound and is a subrange, so minimality forbids the
|
||||||
intersection from being proper. This is the least-element half of the
|
intersection from being proper. This is the least-element half of the
|
||||||
least-sound-range conjecture (issue #14), and it is unconditional — no
|
least-sound-range statement, and it is unconditional — no
|
||||||
nonemptiness or realizability hypothesis is needed. -/
|
nonemptiness or realizability hypothesis is needed. -/
|
||||||
theorem Minimal.subrange_of_sound {r : RangeRead} {res : Result} {cr : ConflictRange}
|
theorem Minimal.subrange_of_sound {r : RangeRead} {res : Result} {cr : ConflictRange}
|
||||||
(h : Minimal r res cr) {cr' : ConflictRange} (hs : Sound r res cr') :
|
(h : Minimal r res cr) {cr' : ConflictRange} (hs : Sound r res cr') :
|
||||||
@@ -2233,7 +2231,7 @@ theorem exists_unique_minimal_of_minimal {r : RangeRead} {res : Result}
|
|||||||
/-!
|
/-!
|
||||||
## The canonical range at offset one
|
## The canonical range at offset one
|
||||||
|
|
||||||
The first concrete instance of the minimal-range conjecture: when both selectors
|
The first concrete instance of the minimal-range theorem: when both selectors
|
||||||
have `offset = 1` and the result is complete (`more = false`), the minimal sound
|
have `offset = 1` and the result is complete (`more = false`), the minimal sound
|
||||||
conflict range is the canonical range `[begin.key, end.key)` named directly by
|
conflict range is the canonical range `[begin.key, end.key)` named directly by
|
||||||
the read. At offset one the resolved window `[resolve begin, resolve end)` cuts a
|
the read. At offset one the resolved window `[resolve begin, resolve end)` cuts a
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
import FormalConflictRange.Sound
|
import FormalConflictRange.Sound
|
||||||
import FormalConflictRange.Empty
|
import FormalConflictRange.Empty
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Authors: FormalConflictRange contributors
|
|
||||||
-/
|
-/
|
||||||
|
|
||||||
import FormalConflictRange.ZeroCrossLong
|
import FormalConflictRange.ZeroCrossLong
|
||||||
|
|||||||
+4
-1
@@ -1,7 +1,10 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
import Bridge
|
import Bridge
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
# Transporting the reference theorem to this repository's statement
|
# Transporting the reference theorem to the public statement
|
||||||
|
|
||||||
`Bridge` proves, for each definition of `Statement`, that its reference
|
`Bridge` proves, for each definition of `Statement`, that its reference
|
||||||
counterpart agrees with it under the translation `toRef*`. This file uses those
|
counterpart agrees with it under the translation `toRef*`. This file uses those
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
# conflict-range
|
# conflict-range
|
||||||
|
|
||||||
A formalised **closed form** for the minimal conflict range of a read/result
|
A closed-form algorithm that computes the minimal conflict range for an observed
|
||||||
pair, together with a C++20 translation and its test harness.
|
range read and result, based on the semantics used by FoundationDB.
|
||||||
|
|
||||||
Given a database, a range read (two selectors plus offsets, either traversal
|
See `Statement.lean` for definitions and the headline claim that the algorithm's
|
||||||
direction), and the keys a transaction observed, `Statement.closedForm` computes
|
output is minimal. Intuitively, the minimal range is the smallest range that
|
||||||
a minimal sound conflict range: a set of keys that is sufficient to detect every
|
preserves serializability (i.e. pinning this range pins the validity of any
|
||||||
conflicting write, and none of whose proper subranges is sufficient.
|
inference you can make from the observed range read and result), and the key set
|
||||||
|
is unique: any two minimal ranges denote the same set of keys, though their
|
||||||
|
endpoints may differ.
|
||||||
|
|
||||||
|
See `cpp/src/fast.cpp` for the C++20 implementation.
|
||||||
|
|
||||||
|
The rest of this README documents the Lean proof and the C++/test support for
|
||||||
|
these claims.
|
||||||
|
|
||||||
## Layout
|
## Layout
|
||||||
|
|
||||||
@@ -24,14 +31,30 @@ conflicting write, and none of whose proper subranges is sufficient.
|
|||||||
## Build and check
|
## Build and check
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
lake exe cache get # clean checkout: download Mathlib's prebuilt oleans
|
||||||
lake build
|
lake build
|
||||||
|
./scripts/check-axioms.sh
|
||||||
lake comparator
|
lake comparator
|
||||||
```
|
```
|
||||||
|
|
||||||
This repository pins Lean `v4.35.0` and Mathlib `v4.35.0`
|
This repository pins Lean `v4.35.0` and Mathlib `v4.35.0`
|
||||||
(`lean-toolchain`, `lakefile.toml`). `lake comparator` checks that the solution
|
(`lean-toolchain`, `lakefile.toml`). `lake exe cache get` downloads Mathlib's
|
||||||
proves the challenge's statements and that the proofs use only `propext`,
|
prebuilt `.olean` files; without it a fresh clone compiles Mathlib from source.
|
||||||
`Quot.sound`, and `Classical.choice`.
|
`lake build` then compiles the default targets (`Statement` and `Proof`, which
|
||||||
|
pull in the reference development); run it before the checks so that a manifest
|
||||||
|
is present and dependencies are resolved.
|
||||||
|
|
||||||
|
`./scripts/check-axioms.sh` prints the axiom dependencies of
|
||||||
|
`Statement.closedFormMinimal` and `Statement.minimalUnique` and fails unless
|
||||||
|
both are exactly `[propext, Classical.choice, Quot.sound]`. This catches `sorry`
|
||||||
|
(`sorryAx`) and newly introduced axioms without needing the comparator sandbox.
|
||||||
|
|
||||||
|
`lake comparator` then builds `Challenge` and `Solution` independently and
|
||||||
|
checks that the solution proves the challenge's statements and uses only
|
||||||
|
`propext`, `Quot.sound`, and `Classical.choice`. It requires `bubblewrap` and
|
||||||
|
either unprivileged user namespaces or a setuid-root `bwrap`; on systems where
|
||||||
|
user namespaces are restricted, `lake comparator` will fail before checking the
|
||||||
|
proof.
|
||||||
|
|
||||||
## Status and scope
|
## Status and scope
|
||||||
|
|
||||||
@@ -39,18 +62,28 @@ proves the challenge's statements and that the proofs use only `propext`,
|
|||||||
proof in `Proof.lean`, `Bridge.lean`, or `FormalConflictRange/` uses `sorry`.
|
proof in `Proof.lean`, `Bridge.lean`, or `FormalConflictRange/` uses `sorry`.
|
||||||
* `Challenge.lean` deliberately contains `sorry`: it is the statement side of
|
* `Challenge.lean` deliberately contains `sorry`: it is the statement side of
|
||||||
the comparator check, not part of the proof.
|
the comparator check, not part of the proof.
|
||||||
* Some docstrings in `FormalConflictRange/` are a research log and refer to
|
* The headline argument is the closed-form development under `FormalConflictRange/`.
|
||||||
files that are **not** part of this repository:
|
`FormalConflictRange/Algorithm.lean` and `FormalConflictRange/Prototype.lean`
|
||||||
`FormalConflictRange/Counterexample`, `FormalConflictRange/Open`, and
|
also supply shared ingredients used by that development: the empty-result
|
||||||
`notes/main.tex`. Those references appear only in comments and docstrings, so
|
theory (`emptyValue`, `EmptyInferenceWitness`,
|
||||||
they do not affect the build or the headline proofs, but their specific claims
|
`minimal_emptyValue_of_emptyInference`) and the ascending-key list and
|
||||||
cannot be checked here. `FormalConflictRange/Prototype.lean` is likewise an
|
constraint collectors (`ascendingKeys`, `emptyConstraints`), respectively.
|
||||||
experimental prototype, not part of the headline proof path.
|
Their partial-algorithm and prototype sections are earlier case-analysis and
|
||||||
|
search material; those sections are not the route taken by the final
|
||||||
|
closed-form proof.
|
||||||
* The C++ tree is validated against Lean-generated golden vectors, by
|
* The C++ tree is validated against Lean-generated golden vectors, by
|
||||||
differential fuzzing, and by a deterministic exhaustive sweep of small
|
differential fuzzing, and by a deterministic finite sweep of small
|
||||||
readable instances; `cpp/README.md` describes the model, the tests, the
|
readable instances; `cpp/README.md` describes the model, the tests, the
|
||||||
coverage check, and the benchmark. The summarised implementation has 100%
|
coverage check, and the benchmark. The summarised implementation has 100%
|
||||||
line 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
|
||||||
|
|
||||||
|
`.gitea/workflows/ci.yml` runs the Lean build, the axiom audit, and the C++ test
|
||||||
|
suite (including the coverage gate) on pushes to `main` and on pull requests. It
|
||||||
|
is written for Gitea Actions; a GitHub mirror would need an equivalent workflow
|
||||||
|
under `.github/workflows/`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
import Proof
|
import Proof
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 Andrew Noyes. All rights reserved.
|
Copyright (c) 2026 Andrew Noyes.
|
||||||
Released under Apache 2.0 license as described in the file LICENSE.
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
# Statement of minimality for a conflict range inference algorithm
|
# Statement of minimality for a conflict range inference algorithm
|
||||||
@@ -85,7 +85,7 @@ structure Selector where
|
|||||||
below `selector.key` (none for the empty key, all of them for `⊤`), minus one,
|
below `selector.key` (none for the empty key, all of them for `⊤`), minus one,
|
||||||
shifted by `selector.offset`. Offset `0` names the last stored key strictly
|
shifted by `selector.offset`. Offset `0` names the last stored key strictly
|
||||||
below `selector.key`, which is index `-1` when there is none; offset `1` names
|
below `selector.key`, which is index `-1` when there is none; offset `1` names
|
||||||
the first stored key at or above it; offset `-1` names the key before that. -/
|
the first stored key at or above it, or index `List.length db.keys` when there is none. -/
|
||||||
def Selector.anchor (db : DB) (s : Selector) : Int :=
|
def Selector.anchor (db : DB) (s : Selector) : Int :=
|
||||||
(db.keys.countP (fun (k : Key) => decide ((↑k : WithTop Key) < s.key)) : Int)
|
(db.keys.countP (fun (k : Key) => decide ((↑k : WithTop Key) < s.key)) : Int)
|
||||||
+ s.offset - 1
|
+ s.offset - 1
|
||||||
|
|||||||
+16
-5
@@ -12,6 +12,8 @@ endif()
|
|||||||
option(CR_BUILD_FUZZERS "Build libFuzzer differential/safety harnesses" ON)
|
option(CR_BUILD_FUZZERS "Build libFuzzer differential/safety harnesses" ON)
|
||||||
option(CR_BUILD_BENCH "Build the nanobench comparison" ON)
|
option(CR_BUILD_BENCH "Build the nanobench comparison" ON)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
add_library(cr_literal STATIC src/literal.cpp)
|
add_library(cr_literal STATIC src/literal.cpp)
|
||||||
target_include_directories(cr_literal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
target_include_directories(cr_literal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
|
|
||||||
@@ -34,12 +36,21 @@ target_include_directories(extreme_test PRIVATE
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||||
target_link_libraries(extreme_test PRIVATE cr_literal cr_fast)
|
target_link_libraries(extreme_test PRIVATE cr_literal cr_fast)
|
||||||
|
|
||||||
# Deterministic exhaustive sweep of small readable instances. This is the
|
# Deterministic sweep over a finite class of small readable instances. This is
|
||||||
# driver for the line-coverage check in `run-coverage.sh`.
|
# the driver for the line-coverage check in `run-coverage.sh`.
|
||||||
add_executable(exhaustive_test tests/exhaustive.cpp)
|
add_executable(sweep_test tests/sweep.cpp)
|
||||||
target_include_directories(exhaustive_test PRIVATE
|
target_include_directories(sweep_test PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||||
target_link_libraries(exhaustive_test PRIVATE cr_literal cr_fast)
|
target_link_libraries(sweep_test PRIVATE cr_literal cr_fast)
|
||||||
|
|
||||||
|
set(CR_GOLDEN_VECTORS "${CMAKE_CURRENT_SOURCE_DIR}/oracle/golden.txt")
|
||||||
|
add_test(NAME golden COMMAND golden_test "${CR_GOLDEN_VECTORS}")
|
||||||
|
add_test(NAME diff_corpus COMMAND diff_corpus "${CR_GOLDEN_VECTORS}")
|
||||||
|
# Curated readable cases found by SMT-assisted mutation analysis.
|
||||||
|
add_test(NAME smt_cases COMMAND diff_corpus
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/tests/smt_cases.txt")
|
||||||
|
add_test(NAME extreme COMMAND extreme_test)
|
||||||
|
add_test(NAME sweep COMMAND sweep_test)
|
||||||
|
|
||||||
if(CR_BUILD_BENCH)
|
if(CR_BUILD_BENCH)
|
||||||
add_executable(cr_bench tests/bench.cpp)
|
add_executable(cr_bench tests/bench.cpp)
|
||||||
|
|||||||
+63
-105
@@ -16,14 +16,16 @@ The Lean build is untouched.
|
|||||||
| `oracle/gen.lean` | Deterministic generator of golden vectors by evaluating the real Lean `closedForm`. |
|
| `oracle/gen.lean` | Deterministic generator of golden vectors by evaluating the real Lean `closedForm`. |
|
||||||
| `tests/golden.cpp` | Checks the literal translation against the Lean golden vectors. |
|
| `tests/golden.cpp` | Checks the literal translation against the Lean golden vectors. |
|
||||||
| `tests/diff_corpus.cpp` | Compares literal and fast on the sorted subset of the golden corpus. |
|
| `tests/diff_corpus.cpp` | Compares literal and fast on the sorted subset of the golden corpus. |
|
||||||
|
| `tests/smt_cases.txt` | Curated readable cases found by SMT-assisted mutation analysis; run by the `smt_cases` CTest. |
|
||||||
| `tests/readable_gen.h` | Readable-by-construction instance generator (owns the selector keys and reported keys, with borrowed views into them). |
|
| `tests/readable_gen.h` | Readable-by-construction instance generator (owns the selector keys and reported keys, with borrowed views into them). |
|
||||||
| `tests/extreme.cpp` | Regression test for offsets at the ends of the 32-bit input range. |
|
| `tests/extreme.cpp` | Regression test for offsets at the ends of the 32-bit input range. |
|
||||||
| `tests/exhaustive.cpp` | Deterministic exhaustive sweep of small readable instances (also the coverage driver). |
|
| `tests/sweep.cpp` | Deterministic sweep over a finite class of small readable instances (also the coverage driver). |
|
||||||
| `tests/fuzz_readable.cpp` | libFuzzer differential test: literal vs. fast on readable instances. |
|
| `tests/fuzz_readable.cpp` | libFuzzer differential test: literal vs. fast on readable instances. |
|
||||||
|
| `tests/corpus/readable/` | Committed read-only seeds for `fuzz_readable`. |
|
||||||
| `tests/fuzz_raw.cpp` | libFuzzer safety test on arbitrary instances under ASan/UBSan. |
|
| `tests/fuzz_raw.cpp` | libFuzzer safety test on arbitrary instances under ASan/UBSan. |
|
||||||
| `tests/bench.cpp` | nanobench literal-vs-fast benchmark. |
|
| `tests/bench.cpp` | nanobench literal-vs-fast benchmark. |
|
||||||
| `run-fuzz.sh` | Rebuilds and runs both fuzzers for a fixed time. |
|
| `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 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`). |
|
| `third_party/nanobench.h` | Vendored nanobench (commit `7252da9d96bd0d71f508e9b2813ab1f57fdfaec1`). |
|
||||||
|
|
||||||
## Data model
|
## Data model
|
||||||
@@ -35,15 +37,14 @@ them in place. `ConflictRange` returns owned `std::string`s because the decision
|
|||||||
procedure can synthesise endpoints (`keyAfter`, clamp bounds) that are not
|
procedure can synthesise endpoints (`keyAfter`, clamp bounds) that are not
|
||||||
present in the input.
|
present in the input.
|
||||||
|
|
||||||
Caller-supplied selector offsets must fit in `std::int32_t`. Internally they are
|
Selector offsets are `std::int32_t`, matching the caller contract. The closed
|
||||||
stored as `Int = std::int64_t`, because the closed form also builds derived
|
form converts the public `RangeRead` to `detail::RangeRead`, whose offsets are
|
||||||
selectors whose offsets (for example `end.offset - residualT`) need not fit in
|
`Int = std::int64_t`, before deriving selectors (for example
|
||||||
32 bits. All intermediate `Int` arithmetic assumes 64-bit signed integers do not
|
`end.offset - residualT`). All intermediate `Int` arithmetic assumes 64-bit
|
||||||
overflow; with 32-bit input offsets and in-memory key counts that is far from
|
signed integers do not overflow; with 32-bit input offsets and in-memory key
|
||||||
the limit. The corpus parsers reject offsets outside the 32-bit input range, and
|
counts that is far from the limit. The corpus parsers read offsets into a wider
|
||||||
both public `closedForm` entry points assert the same contract in debug builds.
|
integer and reject values outside the 32-bit range before narrowing to
|
||||||
The assertion lives at the API boundary rather than in `Selector`, because
|
`Selector`.
|
||||||
derived selectors legitimately exceed the input range.
|
|
||||||
|
|
||||||
## Scope of the two implementations
|
## Scope of the two implementations
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ derived selectors legitimately exceed the input range.
|
|||||||
and `golden_test` compares it with Lean over the whole generated corpus, most of
|
and `golden_test` compares it with Lean over the whole generated corpus, most of
|
||||||
which is not readable. `fast.cpp` is the readable-only implementation:
|
which is not readable. `fast.cpp` is the readable-only implementation:
|
||||||
`diff_corpus` filters the corpus to readable cases, and the fuzzers and the
|
`diff_corpus` filters the corpus to readable cases, and the fuzzers and the
|
||||||
exhaustive sweep generate readable instances. The Lean anchor therefore covers
|
finite sweep generate readable instances. The Lean anchor therefore covers
|
||||||
`literal` on all inputs, while `fast` is anchored to `literal` on the readable
|
`literal` on all inputs, while `fast` is anchored to `literal` on the readable
|
||||||
subset.
|
subset.
|
||||||
|
|
||||||
@@ -63,6 +64,16 @@ cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER=clang++-21
|
|||||||
cmake --build build
|
cmake --build build
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Run the registered tests with CTest:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ctest --test-dir build --output-on-failure
|
||||||
|
```
|
||||||
|
|
||||||
|
`golden` and `diff_corpus` read `oracle/golden.txt`; regenerate it first if it
|
||||||
|
is missing (see below). `smt_cases` reads the committed
|
||||||
|
`tests/smt_cases.txt` and needs no generated input.
|
||||||
|
|
||||||
## Golden vectors from Lean
|
## Golden vectors from Lean
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -90,18 +101,24 @@ cases that satisfy the readable sorting invariant:
|
|||||||
# extreme: 7574 cases, 0 mismatches
|
# extreme: 7574 cases, 0 mismatches
|
||||||
```
|
```
|
||||||
|
|
||||||
`exhaustive_test` enumerates small readable instances instead of sampling them:
|
`sweep_test` is exhaustive over a specific bounded class rather than sampling
|
||||||
every sorted database of up to four keys over a fixed universe of boundary
|
it: every sorted database of at most four stored keys drawn from a fixed universe of
|
||||||
keys, every selector key (including `⊥` and `⊤`) with offsets in `[-3, 4]`, and
|
boundary keys, every selector key (including `⊥` and `⊤`) with offsets in
|
||||||
every readable result (the complete traversal, each nonempty truncated prefix,
|
`[-3, 5]`, both traversal directions, and every readable result shape (the
|
||||||
or the empty result when the traversal is empty) in both directions:
|
complete traversal, each nonempty truncated prefix, or the empty result when the
|
||||||
|
traversal is empty):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./cpp/build/exhaustive_test
|
./cpp/build/sweep_test
|
||||||
# exhaustive: 10562068 cases, 0 mismatches
|
# sweep: 13565772 cases, 0 mismatches
|
||||||
```
|
```
|
||||||
|
|
||||||
It runs in about a second and is also the coverage driver.
|
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 gate describes the code as
|
||||||
|
written, it is not a proof of equivalence with `literal.cpp`.
|
||||||
|
|
||||||
## Coverage
|
## Coverage
|
||||||
|
|
||||||
@@ -109,46 +126,36 @@ It runs in about a second and is also the coverage driver.
|
|||||||
./cpp/run-coverage.sh
|
./cpp/run-coverage.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
The script configures a Clang source-based-coverage build, runs
|
The script configures a Clang source-based-coverage build with MC/DC
|
||||||
`exhaustive_test`, and fails unless `src/fast.cpp` has 100% line coverage.
|
instrumentation, runs `sweep_test`, and fails unless `src/fast.cpp` has 100%
|
||||||
`exhaustive_test` alone covers every line of the summarised implementation:
|
region, function, instantiation, line, branch, and MC/DC coverage. `sweep_test`
|
||||||
|
alone covers every region, function, instantiation, line, branch side, and
|
||||||
```text
|
MC/DC condition of the summarised implementation. MC/DC instrumentation requires
|
||||||
src/fast.cpp 836 regions (12 missed) 131 functions (0 missed) 773 lines (0 missed) 670 branches (125 missed)
|
Clang 18 or newer. The totals are not recorded here: they change with the
|
||||||
```
|
implementation, and the coverage run reports the current ones.
|
||||||
|
|
||||||
That is 100.00% line and function coverage, 98.56% region coverage, and 81.34%
|
|
||||||
branch coverage. The missed branches are short-circuit operands: line coverage
|
|
||||||
counts a condition as covered once any operand decides it, but branch coverage
|
|
||||||
requires every operand to be the deciding one. Reaching 100% branch coverage
|
|
||||||
would need inputs that force each redundant operand to disagree with the rest of
|
|
||||||
its condition, which is not practical here.
|
|
||||||
|
|
||||||
Because equivalence is only promised on readable inputs, `src/fast.cpp` deletes
|
Because equivalence is only promised on readable inputs, `src/fast.cpp` deletes
|
||||||
*control-flow branches* that no readable input can take: the complete-closed
|
both unreachable control-flow branches and predicate operands that an enclosing
|
||||||
family, the offset-one total/any wrappers and their `end.offset <= 1` shortcut,
|
dispatch invariant fixes. Examples include the complete-closed family, the
|
||||||
the `end.offset <= 1` shortcut in `completeForwardCrossedGeneral`, the
|
offset-one total/any wrappers, the hoisted and specialised
|
||||||
`crossedCompleteEndLeOne` guard, and one `lastK < end.key` test that readability
|
`end.offset <= 1` / `revTruncLeOneLow` path split, the
|
||||||
always satisfies.
|
`crossedCompleteEndLeOne` guard, and the repeated
|
||||||
|
`!c.r->reverse`/`!o.more`/offset tests inside subtrees that are only entered
|
||||||
The deletion criterion is deliberately limited to unreachable arms. An
|
after those tests succeeded. `literal.cpp` keeps the full Lean conditions so the
|
||||||
individual predicate operand that a dispatch invariant makes always true at one
|
translation can still be audited line by line.
|
||||||
call site (for example `!c.r->reverse` inside a condition only reached after the
|
|
||||||
forward branch was selected) is kept, because it is part of the Lean condition
|
|
||||||
that the translation mirrors; re-proving the invariant at every site would make
|
|
||||||
the tree harder to audit. Those operands are why every line is covered while branch coverage stays
|
|
||||||
around 81%.
|
|
||||||
|
|
||||||
## Fuzzing
|
## Fuzzing
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd cpp
|
cd cpp
|
||||||
mkdir -p /tmp/cr-corpus/readable /tmp/cr-corpus/raw
|
mkdir -p /tmp/cr-corpus/readable /tmp/cr-corpus/raw
|
||||||
./build/fuzz_readable -max_total_time=300 /tmp/cr-corpus/readable
|
./build/fuzz_readable -max_total_time=300 /tmp/cr-corpus/readable tests/corpus/readable
|
||||||
./build/fuzz_raw -max_total_time=300 /tmp/cr-corpus/raw
|
./build/fuzz_raw -max_total_time=300 /tmp/cr-corpus/raw
|
||||||
```
|
```
|
||||||
|
|
||||||
or simply `./cpp/run-fuzz.sh` (optionally `./cpp/run-fuzz.sh build 600`).
|
or simply `./cpp/run-fuzz.sh` (optionally `./cpp/run-fuzz.sh build 600`).
|
||||||
|
`tests/corpus/readable` holds committed seeds; the first directory above is the
|
||||||
|
writable corpus where libFuzzer stores newly discovered units.
|
||||||
The CMake fuzz targets compile the implementation sources directly so that the
|
The CMake fuzz targets compile the implementation sources directly so that the
|
||||||
decoder code, not just the harness, is covered by ASan/UBSan.
|
decoder code, not just the harness, is covered by ASan/UBSan.
|
||||||
|
|
||||||
@@ -161,17 +168,6 @@ requires exact endpoints.
|
|||||||
`fuzz_raw` only checks memory safety and undefined behaviour for arbitrary
|
`fuzz_raw` only checks memory safety and undefined behaviour for arbitrary
|
||||||
(possibly unreadable) inputs.
|
(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 |
|
|
||||||
| exhaustive readable sweep (`exhaustive_test`) | 10,562,068 | 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
|
`extreme_test` covers offsets the fuzzers deliberately avoid (they draw offsets
|
||||||
from `[-256, 255]`). Both implementations decide the closed form's
|
from `[-256, 255]`). Both implementations decide the closed form's
|
||||||
`keyAfterN n k < upper` test from the key lengths (`keyAfterNLt`) rather than
|
`keyAfterN n k < upper` test from the key lengths (`keyAfterNLt`) rather than
|
||||||
@@ -180,54 +176,17 @@ constant-time instead of attempting a 2 GiB allocation.
|
|||||||
|
|
||||||
## Benchmark
|
## 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
|
```sh
|
||||||
./cpp/build/cr_bench
|
./cpp/build/cr_bench
|
||||||
```
|
```
|
||||||
|
|
||||||
Representative results (Clang 21, default Release build: `-O3 -DNDEBUG`; medians
|
It reports timings and instruction and branch counts per case. Absolute numbers
|
||||||
of nine runs pinned to one core; relative to the literal translation, lower is
|
vary with the machine, compiler, and frequency scaling, so run it for current
|
||||||
better for `fast`).
|
figures.
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
## Why the fast implementation is equivalent
|
## Why the fast implementation is equivalent
|
||||||
|
|
||||||
@@ -240,8 +199,7 @@ only changes are:
|
|||||||
reported keys, so they survive the reversed-view normalisation.
|
reported keys, so they survive the reversed-view normalisation.
|
||||||
* Interval cardinalities (`intervalCard`) are cached lazily.
|
* Interval cardinalities (`intervalCard`) are cached lazily.
|
||||||
* Complete observations are not copied: a forward result borrows the caller's
|
* Complete observations are not copied: a forward result borrows the caller's
|
||||||
span, and a reversed result is viewed backwards in place. (The previous
|
span, and a reversed result is viewed backwards in place.
|
||||||
owned-key model copied and reversed the reported keys here.)
|
|
||||||
* `allBelowEnd` is `residualT == 0` and `anyAtOrAboveEnd` is `residualT != 0`.
|
* `allBelowEnd` is `residualT == 0` and `anyAtOrAboveEnd` is `residualT != 0`.
|
||||||
|
|
||||||
No branch condition or returned endpoint is otherwise changed on readable
|
No branch condition or returned endpoint is otherwise changed on readable
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/-
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
-/
|
||||||
|
|
||||||
import Statement
|
import Statement
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
+88
-14
@@ -1,46 +1,120 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Build with Clang source-based coverage and require 100% line coverage of the
|
# Build with Clang source-based coverage and require 100% region, function,
|
||||||
# summarised implementation (`src/fast.cpp`). `exhaustive_test` enumerates
|
# instantiation, line, branch, and MC/DC coverage of the summarised
|
||||||
# small readable instances deterministically and is sufficient on its own.
|
# implementation (`src/fast.cpp`). `sweep_test` deterministically enumerates a
|
||||||
|
# finite class of small readable instances and is sufficient on its own.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
build="${1:-$here/build-coverage}"
|
build="${1:-$here/build-coverage}"
|
||||||
cxx="${CXX:-clang++-21}"
|
cxx="${CXX:-clang++-21}"
|
||||||
profdata="${LLVM_PROFDATA:-$(command -v llvm-profdata-21 || command -v llvm-profdata || true)}"
|
# Prefer LLVM tools whose version matches the compiler (for example
|
||||||
cov="${LLVM_COV:-$(command -v llvm-cov-21 || command -v llvm-cov || true)}"
|
# `clang++-21` with `llvm-profdata-21`/`llvm-cov-21`). Do not guess among
|
||||||
|
# versioned tools: mixing profile formats fails in confusing ways.
|
||||||
|
if [[ "$(basename "$cxx")" =~ -([0-9]+)$ ]]; then
|
||||||
|
cxx_version="${BASH_REMATCH[1]}"
|
||||||
|
else
|
||||||
|
cxx_version=""
|
||||||
|
fi
|
||||||
|
cxx_major=""
|
||||||
|
if [[ -z "$cxx_version" ]]; then
|
||||||
|
cxx_major="$("$cxx" -dumpversion 2>/dev/null | cut -d. -f1 || true)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
pick_tool() {
|
||||||
|
local tool="$1" override="$2"
|
||||||
|
if [[ -n "$override" ]]; then
|
||||||
|
printf '%s\n' "$override"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -n "$cxx_version" ]]; then
|
||||||
|
if command -v "${tool}-${cxx_version}" >/dev/null 2>&1; then
|
||||||
|
command -v "${tool}-${cxx_version}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if command -v "$tool" >/dev/null 2>&1; then
|
||||||
|
command -v "$tool"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -n "$cxx_major" ]] && command -v "${tool}-${cxx_major}" >/dev/null 2>&1; then
|
||||||
|
command -v "${tool}-${cxx_major}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
profdata="$(pick_tool llvm-profdata "${LLVM_PROFDATA:-}")" || true
|
||||||
|
cov="$(pick_tool llvm-cov "${LLVM_COV:-}")" || true
|
||||||
|
|
||||||
if [[ -z "$profdata" || -z "$cov" ]]; then
|
if [[ -z "$profdata" || -z "$cov" ]]; then
|
||||||
echo "llvm-profdata and llvm-cov are required" >&2
|
echo "llvm-profdata and llvm-cov are required" >&2
|
||||||
|
echo "install the LLVM tools matching $cxx, or set LLVM_PROFDATA and LLVM_COV" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Reusing a coverage build directory after changing the compiler makes CMake
|
||||||
|
# discard its cache, which also drops the instrumentation flags. Recreate the
|
||||||
|
# directory instead of silently producing an uninstrumented binary.
|
||||||
|
cxx_path="$(command -v "$cxx" 2>/dev/null || printf '%s' "$cxx")"
|
||||||
|
cache="$build/CMakeCache.txt"
|
||||||
|
if [[ -f "$cache" ]]; then
|
||||||
|
cached_cxx="$(sed -n 's/^CMAKE_CXX_COMPILER:.*=//p' "$cache" | head -n 1)"
|
||||||
|
if [[ -n "$cached_cxx" && "$cached_cxx" != "$cxx" && "$cached_cxx" != "$cxx_path" ]]; then
|
||||||
|
echo "coverage build used $cached_cxx; recreating it for $cxx" >&2
|
||||||
|
rm -rf "$build"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
cmake -S "$here" -B "$build" -G Ninja \
|
cmake -S "$here" -B "$build" -G Ninja \
|
||||||
-DCMAKE_CXX_COMPILER="$cxx" \
|
-DCMAKE_CXX_COMPILER="$cxx" \
|
||||||
-DCMAKE_BUILD_TYPE=Debug \
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
-DCR_BUILD_FUZZERS=OFF \
|
-DCR_BUILD_FUZZERS=OFF \
|
||||||
-DCR_BUILD_BENCH=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"
|
-DCMAKE_EXE_LINKER_FLAGS="-fprofile-instr-generate"
|
||||||
cmake --build "$build" --target exhaustive_test
|
cmake --build "$build" --target sweep_test
|
||||||
|
|
||||||
profdir="$build/prof"
|
profdir="$build/prof"
|
||||||
rm -rf "$profdir"
|
rm -rf "$profdir"
|
||||||
mkdir -p "$profdir"
|
mkdir -p "$profdir"
|
||||||
|
|
||||||
cd "$here"
|
cd "$here"
|
||||||
LLVM_PROFILE_FILE="$profdir/exhaustive-%p.profraw" "$build/exhaustive_test"
|
LLVM_PROFILE_FILE="$profdir/sweep-%p.profraw" "$build/sweep_test"
|
||||||
"$profdata" merge -sparse "$profdir"/*.profraw -o "$profdir/cov.profdata"
|
"$profdata" merge -sparse "$profdir"/*.profraw -o "$profdir/cov.profdata"
|
||||||
|
|
||||||
report() {
|
report() {
|
||||||
"$cov" report "$build/exhaustive_test" \
|
"$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)"
|
output="$(report)"
|
||||||
printf '%s\n' "$output"
|
printf '%s\n' "$output"
|
||||||
line_cover="$(printf '%s\n' "$output" | awk '/fast\.cpp/ { print $10 }')"
|
|
||||||
if [[ "$line_cover" != "100.00%" ]]; then
|
# The row fields follow the summary order enabled above:
|
||||||
echo "fast.cpp line coverage is $line_cover, expected 100.00%" >&2
|
# 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "fast.cpp: 100.00% line coverage"
|
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% region, function, instantiation, line, branch, and MC/DC coverage"
|
||||||
+5
-1
@@ -15,9 +15,13 @@ cmake --build "$build" --target fuzz_readable fuzz_raw
|
|||||||
|
|
||||||
corpus="${TMPDIR:-/tmp}/cr-fuzz-corpus"
|
corpus="${TMPDIR:-/tmp}/cr-fuzz-corpus"
|
||||||
mkdir -p "$corpus/readable" "$corpus/raw"
|
mkdir -p "$corpus/readable" "$corpus/raw"
|
||||||
|
# Committed read-only seeds (cases found by SMT/mutation analysis) are
|
||||||
|
# passed after the writable corpus, which is where libFuzzer stores new units.
|
||||||
|
seeds="$here/tests/corpus/readable"
|
||||||
|
|
||||||
echo "== differential fuzzing (readable instances) =="
|
echo "== differential fuzzing (readable instances) =="
|
||||||
"$build/fuzz_readable" -max_total_time="$seconds" -max_len=1024 "$corpus/readable"
|
"$build/fuzz_readable" -max_total_time="$seconds" -max_len=1024 \
|
||||||
|
"$corpus/readable" "$seeds"
|
||||||
|
|
||||||
echo "== safety fuzzing (arbitrary instances) =="
|
echo "== safety fuzzing (arbitrary instances) =="
|
||||||
"$build/fuzz_raw" -max_total_time="$seconds" -max_len=1024 "$corpus/raw"
|
"$build/fuzz_raw" -max_total_time="$seconds" -max_len=1024 "$corpus/raw"
|
||||||
+128
-238
@@ -1,22 +1,27 @@
|
|||||||
|
// Copyright (c) 2026 Andrew Noyes.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// A summarised implementation of the same decision procedure as
|
// A summarised implementation of the same decision procedure as
|
||||||
// `Statement.closedForm`.
|
// `Statement.closedForm`.
|
||||||
//
|
//
|
||||||
// `literal.cpp` mirrors the Lean definition line by line and therefore rescans
|
// `literal.cpp` mirrors the Lean definition line by line and therefore rescans
|
||||||
// `res.keys` (and re-derives small arithmetic facts) on almost every branch.
|
// `res.keys` (and re-derives small arithmetic facts) on almost every branch.
|
||||||
// This version summarises the reported keys once (two binary searches on the
|
// This version summarises the reported keys once (two binary searches on the
|
||||||
// sorted traversal order) and caches the handful of interval cardinalities the
|
// sorted traversal order), then replays the same tree for readable inputs.
|
||||||
// decision tree needs, then replays the same tree for readable inputs. Branches
|
// Branches and predicate operands that the `Readable` invariant or a dispatch
|
||||||
// that the `Readable` invariant makes unreachable are omitted. Reversed results
|
// invariant makes unreachable/constant are omitted; `literal.cpp` keeps the
|
||||||
// are handled through a `reversed` view instead of copying the key list.
|
// full Lean conditions for audit. Reversed results are handled through a
|
||||||
|
// `reversed` view instead of copying the key list.
|
||||||
#include "fast.h"
|
#include "fast.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace cr::fast {
|
namespace cr::fast {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using WideRead = detail::RangeRead;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Observational summary
|
// Observational summary
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -34,44 +39,28 @@ struct Obs {
|
|||||||
bool ascending = true;
|
bool ascending = true;
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
|
|
||||||
const KeyView& firstK() const {
|
// `closedForm` handles an empty result before building the tree, so `keys` is
|
||||||
assert(!keys.empty());
|
// non-empty everywhere these are called.
|
||||||
return reversed ? keys.back() : keys.front();
|
const KeyView& firstK() const { return reversed ? keys.back() : keys.front(); }
|
||||||
}
|
const KeyView& lastK() const { return reversed ? keys.front() : keys.back(); }
|
||||||
const KeyView& lastK() const {
|
|
||||||
assert(!keys.empty());
|
|
||||||
return reversed ? keys.front() : keys.back();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Facts that only depend on the read and on the *multiset* of reported keys.
|
// Facts that only depend on the read and on the *multiset* of reported keys.
|
||||||
// They are therefore invariant under reversing the view.
|
// They are therefore invariant under reversing the view.
|
||||||
struct Ctx {
|
struct Ctx {
|
||||||
const RangeRead* r = nullptr;
|
const WideRead* r = nullptr;
|
||||||
std::size_t n = 0;
|
std::size_t n = 0;
|
||||||
std::size_t below = 0; // number of reported keys < begin.key
|
std::size_t below = 0; // number of reported keys < begin.key
|
||||||
std::size_t t = 0; // number of reported keys >= end.key
|
std::size_t t = 0; // number of reported keys >= end.key
|
||||||
// Lazily computed interval cardinalities.
|
|
||||||
mutable bool haveBE = false;
|
|
||||||
mutable bool haveEB = false;
|
|
||||||
mutable NatInf be;
|
|
||||||
mutable NatInf eb;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NatInf cardBE(const Ctx& c) {
|
NatInf cardBE(const Ctx& c) {
|
||||||
if (!c.haveBE) {
|
return intervalCard(c.r->begin.key, c.r->end_.key);
|
||||||
c.be = intervalCard(c.r->begin.key, c.r->end_.key);
|
|
||||||
c.haveBE = true;
|
|
||||||
}
|
|
||||||
return c.be;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Each path consults this at most once, so it needs no cache.
|
||||||
NatInf cardEB(const Ctx& c) {
|
NatInf cardEB(const Ctx& c) {
|
||||||
if (!c.haveEB) {
|
return intervalCard(c.r->end_.key, c.r->begin.key);
|
||||||
c.eb = intervalCard(c.r->end_.key, c.r->begin.key);
|
|
||||||
c.haveEB = true;
|
|
||||||
}
|
|
||||||
return c.eb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NatInf cardKO(KeyView b, OptKeyView e) {
|
NatInf cardKO(KeyView b, OptKeyView e) {
|
||||||
@@ -118,7 +107,7 @@ std::size_t countLess(std::span<const KeyView> ks, OptKeyView x,
|
|||||||
return n - lo;
|
return n - lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ctx makeCtx(const RangeRead& r, const Obs& o) {
|
Ctx makeCtx(const WideRead& r, const Obs& o) {
|
||||||
Ctx c;
|
Ctx c;
|
||||||
c.r = &r;
|
c.r = &r;
|
||||||
c.n = o.n;
|
c.n = o.n;
|
||||||
@@ -132,10 +121,6 @@ Ctx makeCtx(const RangeRead& r, const Obs& o) {
|
|||||||
// Comparisons that avoid allocating a one-element `OptKey`
|
// Comparisons that avoid allocating a one-element `OptKey`
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// ↑k < b
|
|
||||||
bool kLtO(KeyView k, OptKeyView b) { return !b || keyLt(k, *b); }
|
|
||||||
// ↑k <= b
|
|
||||||
bool kLeO(KeyView k, OptKeyView b) { return !b || !keyLt(*b, k); }
|
|
||||||
// a < ↑k
|
// a < ↑k
|
||||||
bool oLtK(OptKeyView a, KeyView k) { return a.has_value() && keyLt(*a, k); }
|
bool oLtK(OptKeyView a, KeyView k) { return a.has_value() && keyLt(*a, k); }
|
||||||
// a <= ↑k
|
// a <= ↑k
|
||||||
@@ -149,7 +134,6 @@ std::uint64_t rB(const Ctx& c) { return residualB(*c.r); }
|
|||||||
std::uint64_t npd(const Ctx& c) { return clampNonposD(*c.r); }
|
std::uint64_t npd(const Ctx& c) { return clampNonposD(*c.r); }
|
||||||
|
|
||||||
bool allBelowEnd(const Ctx& c) { return c.t == 0; }
|
bool allBelowEnd(const Ctx& c) { return c.t == 0; }
|
||||||
bool anyAtOrAboveEnd(const Ctx& c) { return c.t != 0; }
|
|
||||||
|
|
||||||
const KeyView& leastReportedK(const Ctx& c, const Obs& o) {
|
const KeyView& leastReportedK(const Ctx& c, const Obs& o) {
|
||||||
return c.r->reverse ? o.lastK() : o.firstK();
|
return c.r->reverse ? o.lastK() : o.firstK();
|
||||||
@@ -205,13 +189,16 @@ bool clampNonposBottom(const Ctx& c) {
|
|||||||
return niLe(lhs, NatInf::of(bSlack(c)));
|
return niLe(lhs, NatInf::of(bSlack(c)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The caller reaches this only after `begin.offset >= 1` failed, so the offset
|
||||||
|
// half of the condition is already known.
|
||||||
bool clampedNonpos(const Ctx& c, const Obs& o) {
|
bool clampedNonpos(const Ctx& c, const Obs& o) {
|
||||||
return c.r->begin.offset <= 0 && oLeK(c.r->begin.key, leastReportedK(c, o));
|
return oLeK(c.r->begin.key, leastReportedK(c, o));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clampsToBottom(const Ctx& c, const Obs& o) {
|
// Called from the positive branch: if `begin.offset <= 0` then the entry
|
||||||
return c.r->begin.offset <= 0 && oLeK(c.r->begin.key, o.firstK());
|
// dispatch already established `clampedNonpos`, i.e. the selector key is at or
|
||||||
}
|
// before the first reported key, so only the offset decides here.
|
||||||
|
bool clampsToBottom(const Ctx& c) { return c.r->begin.offset <= 0; }
|
||||||
|
|
||||||
std::uint64_t cELo(Int oB, Int oE) {
|
std::uint64_t cELo(Int oB, Int oE) {
|
||||||
return std::max(toNat(2 - oE), toNat(oB - oE + 1));
|
return std::max(toNat(2 - oE), toNat(oB - oE + 1));
|
||||||
@@ -253,47 +240,14 @@ OptKeyView crossedBegin(const Ctx& c) {
|
|||||||
struct Impl {
|
struct Impl {
|
||||||
// ----- crossed complete --------------------------------------------------
|
// ----- crossed complete --------------------------------------------------
|
||||||
|
|
||||||
|
// The complete-crossed subtree is entered only with `!reverse` and `!more`
|
||||||
|
// (`closedFormCrossed` normalises a reversed complete read first). Within it,
|
||||||
|
// `crossedCompleteBeginZero` has already claimed every `begin.offset == 0`
|
||||||
|
// case before these clamp nodes are tried, so `begin.offset < 0` holds here.
|
||||||
bool negCrossClampEndOne(const Ctx& c, const Obs& o) const {
|
bool negCrossClampEndOne(const Ctx& c, const Obs& o) const {
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more &&
|
// `crossedCompleteEndLeOne` already failed, and for `end.offset == 1` it
|
||||||
c.r->end_.offset == 1 && kLtO(o.firstK(), c.r->begin.key) &&
|
// fails exactly when `bSlack >= below`.
|
||||||
c.below <= bSlack(c);
|
return c.r->end_.offset == 1;
|
||||||
}
|
|
||||||
|
|
||||||
bool negCrossHeadBottom(const Ctx& c, const Obs& o) const {
|
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more &&
|
|
||||||
c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key) &&
|
|
||||||
o.firstK().empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool negCrossClampNonposLastGe(const Ctx& c, const Obs& o) const {
|
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more &&
|
|
||||||
c.r->end_.offset <= 0 && kLtO(o.firstK(), c.r->begin.key) &&
|
|
||||||
oLeK(c.r->begin.key, o.lastK()) && c.below <= bSlack(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool negCrossClampNonposBottom(const Ctx& c, const Obs& o) const {
|
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more &&
|
|
||||||
c.r->end_.offset <= 0 && optLe(c.r->begin.key, c.r->end_.key) &&
|
|
||||||
kLtO(o.firstK(), c.r->begin.key) && clampNonposBottom(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool negCrossClampLongNonpos(const Ctx& c, const Obs& o) const {
|
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more &&
|
|
||||||
c.r->end_.offset <= 0 && kLtO(o.firstK(), c.r->begin.key) &&
|
|
||||||
c.below <= bSlack(c) && clampNonposBottom(c) &&
|
|
||||||
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) &&
|
|
||||||
!negCrossClampNonposLastGe(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 {
|
||||||
@@ -316,9 +270,7 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossCompleteHigh(const Ctx& c, const Obs& o) const {
|
bool negCrossCompleteHigh(const Ctx& c, const Obs& o) const {
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more &&
|
return oLtK(c.r->end_.key, o.firstK());
|
||||||
c.r->end_.offset >= 2 && kLtO(o.firstK(), c.r->begin.key) &&
|
|
||||||
oLtK(c.r->end_.key, o.firstK());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossCompleteHigh(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormNegCrossCompleteHigh(const Ctx& c, const Obs& o) const {
|
||||||
@@ -348,7 +300,7 @@ struct Impl {
|
|||||||
ConflictRange closedFormNegCrossCompleteResidual(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormNegCrossCompleteResidual(const Ctx& c, const Obs& o) const {
|
||||||
// Keep the synthesised end key alive while `rp` borrows it.
|
// Keep the synthesised end key alive while `rp` borrows it.
|
||||||
OptKey reducedEnd = after(o.lastK());
|
OptKey reducedEnd = after(o.lastK());
|
||||||
RangeRead rp = *c.r;
|
WideRead rp = *c.r;
|
||||||
rp.end_.key = optView(reducedEnd);
|
rp.end_.key = optView(reducedEnd);
|
||||||
rp.end_.offset = rp.end_.offset - static_cast<Int>(c.t);
|
rp.end_.offset = rp.end_.offset - static_cast<Int>(c.t);
|
||||||
Ctx cp = makeCtx(rp, o);
|
Ctx cp = makeCtx(rp, o);
|
||||||
@@ -379,28 +331,17 @@ struct Impl {
|
|||||||
|
|
||||||
// ----- crossed truncated -------------------------------------------------
|
// ----- crossed truncated -------------------------------------------------
|
||||||
|
|
||||||
bool negCrossTruncNonposGap(const Ctx& c, const Obs& o) const {
|
// `closedFormForwardTruncatedNonpos` calls this only inside
|
||||||
return o.more && !c.r->reverse && c.r->begin.offset < 0 &&
|
// `below <= bSlack`, `end.offset <= 0`, `end < begin` and
|
||||||
kLtO(leastReportedK(c, o), c.r->begin.key) &&
|
// `clampNonposBottom`; the remaining Lean conditions of
|
||||||
c.r->end_.offset <= 0 && c.below <= bSlack(c) &&
|
// `negCrossTruncNonposGap`/`...A2aBottom` are invariants of the readable
|
||||||
kLtO(o.lastK(), c.r->begin.key) &&
|
// forward-crossed regime.
|
||||||
kLtO(o.lastK(), c.r->end_.key) &&
|
|
||||||
!isTop(c.r->end_.key) &&
|
|
||||||
(optLt(c.r->end_.key, c.r->begin.key) ||
|
|
||||||
niLt(cardBE(c), NatInf::of(npd(c) + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool negCrossTruncNonposGapA2aBottom(const Ctx& c, const Obs& o) const {
|
|
||||||
return negCrossTruncNonposGap(c, o) &&
|
|
||||||
optLt(c.r->end_.key, c.r->begin.key) && clampNonposBottom(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool negCrossTruncNonposGapA2aBottomHigh(const Ctx& c, const Obs& o) const {
|
bool negCrossTruncNonposGapA2aBottomHigh(const Ctx& c, const Obs& o) const {
|
||||||
std::uint64_t extra = o.firstK().empty() ? 1 : 0;
|
std::uint64_t extra = o.firstK().empty() ? 1 : 0;
|
||||||
NatInf lhs = NatInf::of(bSlack(c) + 1 + extra);
|
NatInf lhs = NatInf::of(bSlack(c) + 1 + extra);
|
||||||
NatInf rhs = niAdd(NatInf::of(static_cast<std::uint64_t>(c.n)),
|
NatInf rhs = niAdd(NatInf::of(static_cast<std::uint64_t>(c.n)),
|
||||||
cardKO(keyAfter(o.lastK()), c.r->begin.key));
|
cardKO(keyAfter(o.lastK()), c.r->begin.key));
|
||||||
return negCrossTruncNonposGapA2aBottom(c, o) && niLe(lhs, rhs);
|
return niLe(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const Ctx& c,
|
ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const Ctx& c,
|
||||||
@@ -416,10 +357,10 @@ struct Impl {
|
|||||||
return niLe(lhs, NatInf::of(bSlack(c)));
|
return niLe(lhs, NatInf::of(bSlack(c)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reached only in the reversed truncation branch (`more` set, `reverse` set,
|
||||||
|
// `begin.offset < 0`, `end.offset >= 2`).
|
||||||
bool negCrossTruncRevResidualFiniteOver(const Ctx& c, const Obs& o) const {
|
bool negCrossTruncRevResidualFiniteOver(const Ctx& c, const Obs& o) const {
|
||||||
return o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
return oLtK(c.r->end_.key, o.lastK());
|
||||||
c.r->end_.offset >= 2 && oLtK(c.r->end_.key, o.lastK()) &&
|
|
||||||
kLtO(o.lastK(), c.r->begin.key) && c.t == rE(c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const Ctx& c,
|
ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const Ctx& c,
|
||||||
@@ -440,25 +381,18 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopLarge(const Ctx& c, const Obs& o) const {
|
bool negCrossTruncRevResidualTopLarge(const Ctx& c, const Obs& o) const {
|
||||||
if (!(o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
if (!(oLtK(c.r->end_.key, o.lastK()) && c.t < rE(c))) return false;
|
||||||
c.r->end_.offset >= 2 && oLtK(c.r->end_.key, o.lastK()) &&
|
|
||||||
c.t < rE(c)))
|
|
||||||
return false;
|
|
||||||
NatInf lhs = NatInf::of(rE(c));
|
NatInf lhs = NatInf::of(rE(c));
|
||||||
NatInf rhs = niAdd(cardOK(c.r->end_.key, o.lastK()),
|
NatInf rhs = niAdd(cardOK(c.r->end_.key, o.lastK()),
|
||||||
NatInf::of(static_cast<std::uint64_t>(c.n)));
|
NatInf::of(static_cast<std::uint64_t>(c.n)));
|
||||||
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());
|
||||||
}
|
}
|
||||||
@@ -503,15 +437,15 @@ struct Impl {
|
|||||||
return mk(crossedBegin(c), topKey());
|
return mk(crossedBegin(c), topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeRead zeroBeginAnchor(const Ctx& c, const Obs& o) const {
|
WideRead zeroBeginAnchor(const Ctx& c, const Obs& o) const {
|
||||||
RangeRead out = *c.r;
|
WideRead out = *c.r;
|
||||||
out.begin.key = asKey(o.firstK());
|
out.begin.key = asKey(o.firstK());
|
||||||
out.begin.offset = 1;
|
out.begin.offset = 1;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange zeroCrossLongAnchor(const Ctx& c, const Obs& o) const {
|
ConflictRange zeroCrossLongAnchor(const Ctx& c, const Obs& o) const {
|
||||||
RangeRead a = zeroBeginAnchor(c, o);
|
WideRead a = zeroBeginAnchor(c, o);
|
||||||
Ctx ca = makeCtx(a, o);
|
Ctx ca = makeCtx(a, o);
|
||||||
if (oLtK(c.r->end_.key, o.firstK()))
|
if (oLtK(c.r->end_.key, o.firstK()))
|
||||||
return completeForwardCrossedGeneral(ca, o);
|
return completeForwardCrossedGeneral(ca, o);
|
||||||
@@ -533,7 +467,7 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossUnderEnd(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormZeroCrossUnderEnd(const Ctx& c, const Obs& o) const {
|
||||||
RangeRead a = zeroBeginAnchor(c, o);
|
WideRead a = zeroBeginAnchor(c, o);
|
||||||
Ctx ca = makeCtx(a, o);
|
Ctx ca = makeCtx(a, o);
|
||||||
return closedFormOffsetOne(ca, o);
|
return closedFormOffsetOne(ca, o);
|
||||||
}
|
}
|
||||||
@@ -551,7 +485,7 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossCompleteRev(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormZeroCrossCompleteRev(const Ctx& c, const Obs& o) const {
|
||||||
RangeRead r2 = *c.r;
|
WideRead r2 = *c.r;
|
||||||
r2.reverse = false;
|
r2.reverse = false;
|
||||||
Obs o2 = o;
|
Obs o2 = o;
|
||||||
o2.reversed = true;
|
o2.reversed = true;
|
||||||
@@ -561,10 +495,8 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossUnderEnd(const Ctx& c, const Obs& o) const {
|
bool zeroCrossUnderEnd(const Ctx& c, const Obs& o) const {
|
||||||
return c.r->begin.offset == 0 && !o.more && !c.r->reverse &&
|
// The only caller tests `crossedCompleteBeginZero`, i.e. `begin.offset == 0`.
|
||||||
c.r->end_.offset >= 2 &&
|
return optLe(c.r->begin.key, c.r->end_.key);
|
||||||
kLtO(leastReportedK(c, o), c.r->begin.key) &&
|
|
||||||
optLe(c.r->begin.key, c.r->end_.key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossResidual(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormZeroCrossResidual(const Ctx& c, const Obs& o) const {
|
||||||
@@ -580,7 +512,7 @@ struct Impl {
|
|||||||
|
|
||||||
// ----- empty result ------------------------------------------------------
|
// ----- empty result ------------------------------------------------------
|
||||||
|
|
||||||
bool AlwaysEmpty(const RangeRead& r) const {
|
bool AlwaysEmpty(const WideRead& r) const {
|
||||||
NatInf gap = intervalCard(r.begin.key, r.end_.key);
|
NatInf gap = intervalCard(r.begin.key, r.end_.key);
|
||||||
std::uint64_t b = noPinB(gap, r.begin.offset, r.end_.offset);
|
std::uint64_t b = noPinB(gap, r.begin.offset, r.end_.offset);
|
||||||
std::uint64_t e = cELo(r.begin.offset, r.end_.offset);
|
std::uint64_t e = cELo(r.begin.offset, r.end_.offset);
|
||||||
@@ -598,32 +530,30 @@ struct Impl {
|
|||||||
} else if (isTop(r.end_.key)) {
|
} else if (isTop(r.end_.key)) {
|
||||||
inner = true;
|
inner = true;
|
||||||
} else {
|
} else {
|
||||||
bool firstFour =
|
// Readability makes the two cardinality bounds and `ePlusEnd > 0`
|
||||||
niLe(NatInf::of(b), underBegin) &&
|
// automatic once the first two bounds hold, so only the endpoint
|
||||||
niLe(NatInf::of(e), underEnd) &&
|
// ordering remains to decide.
|
||||||
niLe(NatInf::of(natSub(b, e)),
|
bool firstTwo = niLe(NatInf::of(b), underBegin) &&
|
||||||
intervalCard(r.end_.key, r.begin.key)) &&
|
niLe(NatInf::of(e), underEnd);
|
||||||
niLe(NatInf::of(natSub(e, b)),
|
|
||||||
intervalCard(r.begin.key, r.end_.key));
|
|
||||||
Int ePlusEnd = static_cast<Int>(e) + r.end_.offset - 1;
|
Int ePlusEnd = static_cast<Int>(e) + r.end_.offset - 1;
|
||||||
Int bPlusBegin = static_cast<Int>(b) + r.begin.offset - 1;
|
Int bPlusBegin = static_cast<Int>(b) + r.begin.offset - 1;
|
||||||
inner = firstFour && ePlusEnd > 0 && bPlusBegin < ePlusEnd;
|
inner = firstTwo && bPlusBegin < ePlusEnd;
|
||||||
}
|
}
|
||||||
return !inner;
|
return !inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange emptyRange(const RangeRead& r) const {
|
ConflictRange emptyRange(const WideRead& r) const {
|
||||||
return mk(r.begin.key, r.begin.key);
|
return mk(r.begin.key, r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange crossedRangeGeneral(const RangeRead& r) const {
|
ConflictRange crossedRangeGeneral(const WideRead& r) const {
|
||||||
NatInf diff = niSub(NatInf::of(residualE(r)), NatInf::of(residualB(r)));
|
NatInf diff = niSub(NatInf::of(residualE(r)), NatInf::of(residualB(r)));
|
||||||
if (niLe(diff, intervalCard(r.end_.key, r.begin.key)))
|
if (niLe(diff, intervalCard(r.end_.key, r.begin.key)))
|
||||||
return mk(r.end_.key, topKey());
|
return mk(r.end_.key, topKey());
|
||||||
return mk(r.begin.key, topKey());
|
return mk(r.begin.key, topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange emptyValue(const RangeRead& r) const {
|
ConflictRange emptyValue(const WideRead& r) const {
|
||||||
if (AlwaysEmpty(r)) return emptyRange(r);
|
if (AlwaysEmpty(r)) return emptyRange(r);
|
||||||
if (r.begin.offset <= 0) {
|
if (r.begin.offset <= 0) {
|
||||||
if (r.end_.offset >= 2) return mk(bottomKey(), topKey());
|
if (r.end_.offset >= 2) return mk(bottomKey(), topKey());
|
||||||
@@ -637,14 +567,14 @@ struct Impl {
|
|||||||
return crossedRangeGeneral(r);
|
return crossedRangeGeneral(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange topRange(const RangeRead& r) const {
|
ConflictRange topRange(const WideRead& r) const {
|
||||||
return mk(r.begin.key, topKey());
|
return mk(r.begin.key, topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----- complete and forward truncated results ----------------------------
|
// ----- complete and forward truncated results ----------------------------
|
||||||
|
|
||||||
OptKeyView closedFormBegin(const Ctx& c, const Obs& o) const {
|
OptKeyView closedFormBegin(const Ctx& c, const Obs& o) const {
|
||||||
return clampsToBottom(c, o) ? bottomKeyView() : c.r->begin.key;
|
return clampsToBottom(c) ? bottomKeyView() : c.r->begin.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormFinite(const Ctx& c) const {
|
bool closedFormFinite(const Ctx& c) const {
|
||||||
@@ -655,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, o) || 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()));
|
||||||
@@ -668,7 +599,7 @@ struct Impl {
|
|||||||
|
|
||||||
ConflictRange closedFormComplete(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormComplete(const Ctx& c, const Obs& o) const {
|
||||||
if (!c.r->reverse) return closedFormCompleteForward(c, o);
|
if (!c.r->reverse) return closedFormCompleteForward(c, o);
|
||||||
RangeRead r2 = *c.r;
|
WideRead r2 = *c.r;
|
||||||
r2.reverse = false;
|
r2.reverse = false;
|
||||||
Obs o2 = o;
|
Obs o2 = o;
|
||||||
o2.reversed = true;
|
o2.reversed = true;
|
||||||
@@ -678,7 +609,7 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
NatInf closedFormForwardCapacity(const Ctx& c, const Obs& o) const {
|
NatInf closedFormForwardCapacity(const Ctx& c, const Obs& o) const {
|
||||||
if (clampsToBottom(c, o)) return NatInf::of(0);
|
if (clampsToBottom(c)) return NatInf::of(0);
|
||||||
return cardEB(c);
|
return cardEB(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,10 +652,9 @@ struct Impl {
|
|||||||
: c.r->begin.key;
|
: c.r->begin.key;
|
||||||
return mk(std::move(begin), after(o.firstK()));
|
return mk(std::move(begin), after(o.firstK()));
|
||||||
}
|
}
|
||||||
OptKeyView begin =
|
bool beginAtEnd = optLt(c.r->end_.key, c.r->begin.key) &&
|
||||||
(optLt(c.r->end_.key, c.r->begin.key) && closedFormCrossedRoom(c, o))
|
closedFormCrossedRoom(c, o);
|
||||||
? c.r->end_.key
|
OptKeyView begin = beginAtEnd ? c.r->end_.key : c.r->begin.key;
|
||||||
: c.r->begin.key;
|
|
||||||
return mk(std::move(begin), topKey());
|
return mk(std::move(begin), topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,140 +675,95 @@ struct Impl {
|
|||||||
return c.r->end_.offset >= 2 && allBelowEnd(c);
|
return c.r->end_.offset >= 2 && allBelowEnd(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossOvershootComplete(const Ctx& c, const Obs& o) const {
|
// `closedFormCrossedComplete` is reached only from `closedFormCrossed`,
|
||||||
return c.r->begin.offset == 0 && !o.more && !c.r->reverse &&
|
// which the entry point enters only when `begin.offset <= 0`; the
|
||||||
overshoot(c) && kLtO(leastReportedK(c, o), c.r->begin.key);
|
// `begin.offset >= 1` cases go to the positive subtree. So the mode does
|
||||||
}
|
// not need to be retested here.
|
||||||
|
bool crossedCompleteOvershoot(const Ctx& c) const { return overshoot(c); }
|
||||||
bool negCrossOvershoot(const Ctx& c, const Obs& o) const {
|
|
||||||
return !c.r->reverse && c.r->begin.offset < 0 && !o.more && overshoot(c) &&
|
|
||||||
kLtO(o.firstK(), c.r->begin.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool crossedCompleteOvershoot(const Ctx& c, const Obs& o) const {
|
|
||||||
return zeroCrossOvershootComplete(c, o) || negCrossOvershoot(c, o);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool crossedCompleteEndLeOne(const Ctx& c) const {
|
bool crossedCompleteEndLeOne(const Ctx& c) const {
|
||||||
if (c.r->end_.offset == 1 && bSlack(c) < c.below)
|
if (c.r->end_.offset == 1 && bSlack(c) < c.below)
|
||||||
return true;
|
return true;
|
||||||
return c.r->end_.offset <= 0 &&
|
if (c.r->end_.offset > 0) return false;
|
||||||
!(c.below <= bSlack(c) && clampNonposBottom(c));
|
bool clampedBottom = c.below <= bSlack(c) && clampNonposBottom(c);
|
||||||
}
|
return !clampedBottom;
|
||||||
|
|
||||||
bool zeroCrossLongTop(const Ctx& c, const Obs& o) const {
|
|
||||||
return c.r->begin.offset == 0 && !o.more && !c.r->reverse &&
|
|
||||||
c.r->end_.offset >= 2 && isTop(c.r->begin.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool zeroCrossLongFinite(const Ctx& c, const Obs& o) const {
|
|
||||||
return c.r->begin.offset == 0 && !o.more && !c.r->reverse &&
|
|
||||||
c.r->end_.offset >= 2 && !isTop(c.r->begin.key) &&
|
|
||||||
optLt(c.r->end_.key, c.r->begin.key) &&
|
|
||||||
kLtO(leastReportedK(c, o), c.r->begin.key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The overshoot branch above already covered the offset-zero overshoot
|
||||||
|
// cases, so the mode alone decides here.
|
||||||
bool crossedCompleteBeginZero(const Ctx& c, const Obs& o) const {
|
bool crossedCompleteBeginZero(const Ctx& c, const Obs& o) const {
|
||||||
return zeroCrossUnderEnd(c, o) || zeroCrossLongTop(c, o) ||
|
return c.r->begin.offset == 0;
|
||||||
zeroCrossLongFinite(c, o);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, o))
|
if (crossedCompleteOvershoot(c))
|
||||||
return closedFormNegCrossTopUnified(c, o);
|
return closedFormNegCrossTopUnified(c, o);
|
||||||
if (crossedCompleteEndLeOne(c))
|
if (crossedCompleteEndLeOne(c))
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----- crossed truncated dispatch ---------------------------------------
|
// ----- crossed truncated dispatch ---------------------------------------
|
||||||
|
|
||||||
|
// Every node below is reached only from the reversed truncation branch, where
|
||||||
|
// `more` is set, `reverse` is set, `begin.offset < 0` and `end.offset >= 2`
|
||||||
|
// (the `end.offset <= 1` case is handled by the dispatch).
|
||||||
bool zeroCrossTruncRevCrossed(const Ctx& c, const Obs& o) const {
|
bool zeroCrossTruncRevCrossed(const Ctx& c, const Obs& o) const {
|
||||||
return c.r->begin.offset == 0 && c.r->reverse && o.more &&
|
return c.r->begin.offset == 0;
|
||||||
kLtO(leastReportedK(c, o), c.r->begin.key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevUnder(const Ctx& c, const Obs& o) const {
|
// `revTruncLeOneLow` is reached only under `end.offset <= 1` (the dispatch
|
||||||
return o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
// tests that comparison first), so the `end.offset <= 1` conjunct in each
|
||||||
kLtO(o.lastK(), c.r->begin.key) &&
|
// original disjunct is discharged by the caller and has been dropped here.
|
||||||
optLe(c.r->begin.key, c.r->end_.key) && c.r->end_.offset <= 1;
|
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
|
||||||
bool negCrossTruncRevCrossedLow(const Ctx& c, const Obs& o) const {
|
// original `optLt` conjunct is implied here.
|
||||||
return o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
return niLe(niAdd(niAdd(cardEB(c),
|
||||||
kLtO(o.lastK(), c.r->begin.key) &&
|
|
||||||
optLt(c.r->end_.key, c.r->begin.key) &&
|
|
||||||
c.r->end_.offset <= 1 &&
|
|
||||||
niLe(niAdd(niAdd(cardEB(c),
|
|
||||||
NatInf::of(static_cast<std::uint64_t>(c.n))),
|
NatInf::of(static_cast<std::uint64_t>(c.n))),
|
||||||
NatInf::of(toNat(1 - c.r->end_.offset))),
|
NatInf::of(toNat(1 - c.r->end_.offset))),
|
||||||
NatInf::of(bSlack(c) + 1));
|
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 {
|
bool negCrossTruncRevBelowEnd(const Ctx& c, const Obs& o) const {
|
||||||
return o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
// The dispatch has already failed `end.offset <= 1`, so `end.offset >= 2`.
|
||||||
kLtO(o.lastK(), c.r->begin.key) && overshoot(c);
|
return allBelowEnd(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualRoom(const Ctx& c, const Obs& o) const {
|
bool negCrossTruncRevResidualRoom(const Ctx& c, const Obs& o) const {
|
||||||
return o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
return niLe(niAdd(cardOK(c.r->end_.key, o.firstK()), NatInf::of(2)),
|
||||||
c.r->end_.offset >= 2 && anyAtOrAboveEnd(c) &&
|
|
||||||
niLe(niAdd(cardOK(c.r->end_.key, o.firstK()), NatInf::of(2)),
|
|
||||||
NatInf::of(rE(c)));
|
NatInf::of(rE(c)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopCrossedSmallGap(const Ctx& c,
|
bool revTruncGeTwoTop(const Ctx& c, const Obs& o) const {
|
||||||
const Obs& o) const {
|
if (negCrossTruncRevBelowEnd(c, o)) return true;
|
||||||
if (!(o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
if (negCrossTruncRevResidualRoom(c, o)) return true;
|
||||||
c.r->end_.offset >= 2 && oLtK(c.r->end_.key, o.lastK())))
|
// The two `TopCrossed` cases split on `end.key < last`, so test it once.
|
||||||
return false;
|
if (oLtK(c.r->end_.key, o.lastK())) {
|
||||||
NatInf lhs = niAdd(cardOK(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)));
|
NatInf::of(static_cast<std::uint64_t>(c.n)));
|
||||||
return niLt(lhs, NatInf::of(rE(c)));
|
return niLt(lhs, NatInf::of(rE(c)));
|
||||||
}
|
}
|
||||||
|
return c.t < rE(c);
|
||||||
bool negCrossTruncRevResidualTopCrossed(const Ctx& c, const Obs& o) const {
|
|
||||||
return o.more && c.r->reverse && c.r->begin.offset < 0 &&
|
|
||||||
c.r->end_.offset >= 2 && kLeO(o.lastK(), c.r->end_.key) &&
|
|
||||||
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) &&
|
|
||||||
kLtO(o.lastK(), c.r->begin.key) && !isTop(c.r->begin.key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
return o.more && !c.r->reverse && c.r->begin.offset < 0 &&
|
return isTop(c.r->begin.key);
|
||||||
isTop(c.r->begin.key) && isTop(c.r->end_.key) &&
|
|
||||||
c.r->end_.offset <= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncTopTopEq(const Ctx& c, const Obs& o) const {
|
bool negCrossTruncTopTopEq(const Ctx& c, const Obs& o) const {
|
||||||
@@ -917,7 +802,10 @@ struct Impl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormForwardSaturated(const Ctx& c, const Obs& o) const {
|
bool closedFormForwardSaturated(const Ctx& c, const Obs& o) const {
|
||||||
if (!(rE(c) > 0 && oLtK(c.r->end_.key, o.firstK()))) return false;
|
// The caller has `end.offset > 0`. If `end.offset == 1` then `rE == 0`,
|
||||||
|
// and readability makes `end.key < firstKey` false, so the `rE > 0`
|
||||||
|
// guard adds nothing.
|
||||||
|
if (!oLtK(c.r->end_.key, o.firstK())) return false;
|
||||||
NatInf rhs = niAdd(cardOK(c.r->end_.key, o.firstK()),
|
NatInf rhs = niAdd(cardOK(c.r->end_.key, o.firstK()),
|
||||||
NatInf::of(static_cast<std::uint64_t>(c.n)));
|
NatInf::of(static_cast<std::uint64_t>(c.n)));
|
||||||
return niLt(NatInf::of(rE(c)), rhs);
|
return niLt(NatInf::of(rE(c)), rhs);
|
||||||
@@ -954,7 +842,7 @@ struct Impl {
|
|||||||
ConflictRange closedFormCrossed(const Ctx& c, const Obs& o) const {
|
ConflictRange closedFormCrossed(const Ctx& c, const Obs& o) const {
|
||||||
if (!o.more) {
|
if (!o.more) {
|
||||||
if (!c.r->reverse) return closedFormCrossedComplete(c, o);
|
if (!c.r->reverse) return closedFormCrossedComplete(c, o);
|
||||||
RangeRead r2 = *c.r;
|
WideRead r2 = *c.r;
|
||||||
r2.reverse = false;
|
r2.reverse = false;
|
||||||
Obs o2 = o;
|
Obs o2 = o;
|
||||||
o2.reversed = true;
|
o2.reversed = true;
|
||||||
@@ -965,10 +853,13 @@ struct Impl {
|
|||||||
if (c.r->reverse) {
|
if (c.r->reverse) {
|
||||||
if (zeroCrossTruncRevCrossed(c, o))
|
if (zeroCrossTruncRevCrossed(c, o))
|
||||||
return closedFormZeroCrossTruncRevCrossed(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))
|
if (revTruncLeOneLow(c, o))
|
||||||
return mk(OptKey{o.lastK()}, c.r->end_.key);
|
return mk(OptKey{o.lastK()}, c.r->end_.key);
|
||||||
if (c.r->end_.offset <= 1)
|
|
||||||
return mk(OptKey{o.lastK()}, c.r->begin.key);
|
return mk(OptKey{o.lastK()}, c.r->begin.key);
|
||||||
|
}
|
||||||
if (revTruncGeTwoTop(c, o))
|
if (revTruncGeTwoTop(c, o))
|
||||||
return mk(OptKey{o.lastK()}, topKey());
|
return mk(OptKey{o.lastK()}, topKey());
|
||||||
if (revTruncGeTwoLarge(c, o))
|
if (revTruncGeTwoLarge(c, o))
|
||||||
@@ -980,7 +871,7 @@ struct Impl {
|
|||||||
|
|
||||||
// ----- entry point ------------------------------------------------------
|
// ----- entry point ------------------------------------------------------
|
||||||
|
|
||||||
ConflictRange closedForm(const RangeRead& r, const Result& res) const {
|
ConflictRange closedForm(const WideRead& r, const Result& res) const {
|
||||||
if (res.keys.empty()) return emptyValue(r);
|
if (res.keys.empty()) return emptyValue(r);
|
||||||
Obs o;
|
Obs o;
|
||||||
o.keys = res.keys;
|
o.keys = res.keys;
|
||||||
@@ -998,8 +889,7 @@ struct Impl {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ConflictRange closedForm(const RangeRead& r, const Result& res) {
|
ConflictRange closedForm(const RangeRead& r, const Result& res) {
|
||||||
assertInputOffsetsFitInt32(r);
|
return Impl{}.closedForm(detail::widen(r), res);
|
||||||
return Impl{}.closedForm(r, res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cr::fast
|
} // namespace cr::fast
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|||||||
+134
-131
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// A deliberately literal transliteration of `Statement.closedForm` from
|
// A deliberately literal transliteration of `Statement.closedForm` from
|
||||||
// Statement.lean. Every helper mirrors the Lean definition of the same name,
|
// Statement.lean. Every helper mirrors the Lean definition of the same name,
|
||||||
// including repeated scans of `res.keys`; correctness of the translation, not
|
// including repeated scans of `res.keys`; correctness of the translation, not
|
||||||
@@ -10,10 +12,11 @@
|
|||||||
namespace cr::literal {
|
namespace cr::literal {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using WideRead = cr::detail::RangeRead;
|
||||||
|
|
||||||
using cr::afterFirst;
|
using cr::afterFirst;
|
||||||
using cr::afterLast;
|
using cr::afterLast;
|
||||||
using cr::asKey;
|
using cr::asKey;
|
||||||
using cr::assertInputOffsetsFitInt32;
|
|
||||||
using cr::beginSlack;
|
using cr::beginSlack;
|
||||||
using cr::bottomKey;
|
using cr::bottomKey;
|
||||||
using cr::clampNonposD;
|
using cr::clampNonposD;
|
||||||
@@ -57,13 +60,13 @@ ConflictRange mkRange(B&& b, E&& e) {
|
|||||||
// Arithmetic helpers
|
// Arithmetic helpers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
NatInf clampCap(const RangeRead& r) { return intervalCard(r.end_.key, r.begin.key); }
|
NatInf clampCap(const WideRead& r) { return intervalCard(r.end_.key, r.begin.key); }
|
||||||
|
|
||||||
std::uint64_t clampSlack(const RangeRead& r, const Result& res) {
|
std::uint64_t clampSlack(const WideRead& r, const Result& res) {
|
||||||
return natSub(beginSlack(r) + 1, reportedBelowBegin(r, res));
|
return natSub(beginSlack(r) + 1, reportedBelowBegin(r, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
OptKey clampEndOneUpper(const RangeRead& r, const Result& res) {
|
OptKey clampEndOneUpper(const WideRead& r, const Result& res) {
|
||||||
NatInf slack = NatInf::of(clampSlack(r, res));
|
NatInf slack = NatInf::of(clampSlack(r, res));
|
||||||
NatInf cap = clampCap(r);
|
NatInf cap = clampCap(r);
|
||||||
if (niLe(slack, cap) && (niLt(slack, cap) || first(res) != bottomKeyView()))
|
if (niLe(slack, cap) && (niLt(slack, cap) || first(res) != bottomKeyView()))
|
||||||
@@ -71,25 +74,25 @@ OptKey clampEndOneUpper(const RangeRead& r, const Result& res) {
|
|||||||
return ownKey(r.end_.key);
|
return ownKey(r.end_.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
NatInf clampHighCap(const RangeRead& r, const Result& res) {
|
NatInf clampHighCap(const WideRead& r, const Result& res) {
|
||||||
return intervalCard(afterLast(res), r.begin.key);
|
return intervalCard(afterLast(res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t clampHighThresh(const RangeRead& r, const Result& res) {
|
std::uint64_t clampHighThresh(const WideRead& r, const Result& res) {
|
||||||
return clampSlack(r, res) + (isBottom(r.end_.key) ? 1 : 0);
|
return clampSlack(r, res) + (isBottom(r.end_.key) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
OptKey clampHighU(const RangeRead& r, const Result& res) {
|
OptKey clampHighU(const WideRead& r, const Result& res) {
|
||||||
if (niLe(NatInf::of(clampHighThresh(r, res)), clampHighCap(r, res)))
|
if (niLe(NatInf::of(clampHighThresh(r, res)), clampHighCap(r, res)))
|
||||||
return ownKey(r.begin.key);
|
return ownKey(r.begin.key);
|
||||||
return afterLast(res);
|
return afterLast(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t clampLongC(const RangeRead& r, const Result& res) {
|
std::uint64_t clampLongC(const WideRead& r, const Result& res) {
|
||||||
return natSub(natSub(beginSlack(r), reportedBelowBegin(r, res)), clampNonposD(r));
|
return natSub(natSub(beginSlack(r), reportedBelowBegin(r, res)), clampNonposD(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
OptKey clampLongUpper(const RangeRead& r, const Result& res) {
|
OptKey clampLongUpper(const WideRead& r, const Result& res) {
|
||||||
NatInf cap = clampCap(r);
|
NatInf cap = clampCap(r);
|
||||||
NatInf c = NatInf::of(clampLongC(r, res));
|
NatInf c = NatInf::of(clampLongC(r, res));
|
||||||
if (niLt(cap, c) || (niEq(cap, c) && first(res) == bottomKeyView()))
|
if (niLt(cap, c) || (niEq(cap, c) && first(res) == bottomKeyView()))
|
||||||
@@ -97,19 +100,19 @@ OptKey clampLongUpper(const RangeRead& r, const Result& res) {
|
|||||||
return ownKey(r.begin.key);
|
return ownKey(r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clampNonposBottom(const RangeRead& r, const Result& res) {
|
bool clampNonposBottom(const WideRead& r, const Result& res) {
|
||||||
NatInf lhs = niAdd(NatInf::of(reportedBelowBegin(r, res)),
|
NatInf lhs = niAdd(NatInf::of(reportedBelowBegin(r, res)),
|
||||||
niSub(NatInf::of(clampNonposD(r) + 1),
|
niSub(NatInf::of(clampNonposD(r) + 1),
|
||||||
intervalCard(r.begin.key, r.end_.key)));
|
intervalCard(r.begin.key, r.end_.key)));
|
||||||
return niLe(lhs, NatInf::of(beginSlack(r)));
|
return niLe(lhs, NatInf::of(beginSlack(r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clampedNonpos(const RangeRead& r, const Result& res) {
|
bool clampedNonpos(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset <= 0 &&
|
return r.begin.offset <= 0 &&
|
||||||
optLe(r.begin.key, leastReportedOpt(r, res));
|
optLe(r.begin.key, leastReportedOpt(r, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool clampsToBottom(const RangeRead& r, const Result& res) {
|
bool clampsToBottom(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset <= 0 && optLe(r.begin.key, first(res));
|
return r.begin.offset <= 0 && optLe(r.begin.key, first(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,36 +130,36 @@ std::uint64_t noPinB(NatInf KBE, Int oB, Int oE) {
|
|||||||
return lo > KBE.n ? lo - KBE.n : 0;
|
return lo > KBE.n ? lo - KBE.n : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t residualD(const RangeRead& r, NatInf g) {
|
std::uint64_t residualD(const WideRead& r, NatInf g) {
|
||||||
if (g.inf) return 0;
|
if (g.inf) return 0;
|
||||||
return natSub(residualB(r), g.n);
|
return natSub(residualB(r), g.n);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t closedFormDeficit(const RangeRead& r) {
|
std::uint64_t closedFormDeficit(const WideRead& r) {
|
||||||
return residualD(r, intervalCard(r.begin.key, r.end_.key));
|
return residualD(r, intervalCard(r.begin.key, r.end_.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool allBelowEnd(const RangeRead& r, const Result& res) {
|
bool allBelowEnd(const WideRead& r, const Result& res) {
|
||||||
for (KeyView k : res.keys)
|
for (KeyView k : res.keys)
|
||||||
if (!optLt(asKey(k), r.end_.key)) return false;
|
if (!optLt(asKey(k), r.end_.key)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool anyAtOrAboveEnd(const RangeRead& r, const Result& res) {
|
bool anyAtOrAboveEnd(const WideRead& r, const Result& res) {
|
||||||
for (KeyView k : res.keys)
|
for (KeyView k : res.keys)
|
||||||
if (optLe(r.end_.key, asKey(k))) return true;
|
if (optLe(r.end_.key, asKey(k))) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t gapOvershoot(const RangeRead& r, const Result& res) {
|
std::uint64_t gapOvershoot(const WideRead& r, const Result& res) {
|
||||||
return natSub(residualE(r), residualT(r, res));
|
return natSub(residualE(r), residualT(r, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t crossedOvershootGeneral(const RangeRead& r, const Result& res) {
|
std::uint64_t crossedOvershootGeneral(const WideRead& r, const Result& res) {
|
||||||
return natSub(natSub(residualE(r), residualT(r, res)), residualB(r));
|
return natSub(natSub(residualE(r), residualT(r, res)), residualB(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
OptKeyView crossedBegin(const RangeRead& r, const Result& res) {
|
OptKeyView crossedBegin(const WideRead& r, const Result& res) {
|
||||||
if (niLe(NatInf::of(crossedOvershootGeneral(r, res)),
|
if (niLe(NatInf::of(crossedOvershootGeneral(r, res)),
|
||||||
intervalCard(r.end_.key, r.begin.key)))
|
intervalCard(r.end_.key, r.begin.key)))
|
||||||
return r.end_.key;
|
return r.end_.key;
|
||||||
@@ -167,39 +170,39 @@ OptKeyView crossedBegin(const RangeRead& r, const Result& res) {
|
|||||||
// Crossed complete cases
|
// Crossed complete cases
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool negCrossClampEndOne(const RangeRead& r, const Result& res) {
|
bool negCrossClampEndOne(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||||
r.end_.offset == 1 && optLt(first(res), r.begin.key) &&
|
r.end_.offset == 1 && optLt(first(res), r.begin.key) &&
|
||||||
reportedBelowBegin(r, res) <= beginSlack(r);
|
reportedBelowBegin(r, res) <= beginSlack(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossHeadBottom(const RangeRead& r, const Result& res) {
|
bool negCrossHeadBottom(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||||
r.end_.offset <= 0 && optLe(r.begin.key, r.end_.key) &&
|
r.end_.offset <= 0 && optLe(r.begin.key, r.end_.key) &&
|
||||||
first(res) == bottomKeyView();
|
first(res) == bottomKeyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossClampNonposLastGe(const RangeRead& r, const Result& res) {
|
bool negCrossClampNonposLastGe(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||||
r.end_.offset <= 0 && optLt(first(res), r.begin.key) &&
|
r.end_.offset <= 0 && optLt(first(res), r.begin.key) &&
|
||||||
optLe(r.begin.key, last(res)) &&
|
optLe(r.begin.key, last(res)) &&
|
||||||
reportedBelowBegin(r, res) <= beginSlack(r);
|
reportedBelowBegin(r, res) <= beginSlack(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossClampNonposBottom(const RangeRead& r, const Result& res) {
|
bool negCrossClampNonposBottom(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||||
r.end_.offset <= 0 && optLe(r.begin.key, r.end_.key) &&
|
r.end_.offset <= 0 && optLe(r.begin.key, r.end_.key) &&
|
||||||
optLt(first(res), r.begin.key) && clampNonposBottom(r, res);
|
optLt(first(res), r.begin.key) && clampNonposBottom(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossClampLongNonpos(const RangeRead& r, const Result& res) {
|
bool negCrossClampLongNonpos(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||||
r.end_.offset <= 0 && optLt(first(res), r.begin.key) &&
|
r.end_.offset <= 0 && optLt(first(res), r.begin.key) &&
|
||||||
reportedBelowBegin(r, res) <= beginSlack(r) &&
|
reportedBelowBegin(r, res) <= beginSlack(r) &&
|
||||||
clampNonposBottom(r, res) && optLt(r.end_.key, r.begin.key);
|
clampNonposBottom(r, res) && optLt(r.end_.key, r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossClampUnified(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossClampUnified(const WideRead& r, const Result& res) {
|
||||||
OptKey end;
|
OptKey end;
|
||||||
if (negCrossClampEndOne(r, res))
|
if (negCrossClampEndOne(r, res))
|
||||||
end = clampEndOneUpper(r, res);
|
end = clampEndOneUpper(r, res);
|
||||||
@@ -211,31 +214,31 @@ ConflictRange closedFormNegCrossClampUnified(const RangeRead& r, const Result& r
|
|||||||
return mkRange(bottomKey(), std::move(end));
|
return mkRange(bottomKey(), std::move(end));
|
||||||
}
|
}
|
||||||
|
|
||||||
OptKey negCrossCompleteHighM(const RangeRead& r, const Result& res) {
|
OptKey negCrossCompleteHighM(const WideRead& r, const Result& res) {
|
||||||
return optMax(r.begin.key, afterLast(res));
|
return optMax(r.begin.key, afterLast(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t negCrossHighD(const RangeRead& r, const Result& res) {
|
std::uint64_t negCrossHighD(const WideRead& r, const Result& res) {
|
||||||
return natSub(residualE(r), res.keys.size());
|
return natSub(residualE(r), res.keys.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
NatInf negCrossHighGapCap(const RangeRead& r, const Result& res) {
|
NatInf negCrossHighGapCap(const WideRead& r, const Result& res) {
|
||||||
return intervalCard(r.end_.key, first(res));
|
return intervalCard(r.end_.key, first(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossHighUsesEnd(const RangeRead& r, const Result& res) {
|
bool negCrossHighUsesEnd(const WideRead& r, const Result& res) {
|
||||||
NatInf d = NatInf::of(negCrossHighD(r, res));
|
NatInf d = NatInf::of(negCrossHighD(r, res));
|
||||||
NatInf gap = negCrossHighGapCap(r, res);
|
NatInf gap = negCrossHighGapCap(r, res);
|
||||||
return niLt(d, gap) || (niLe(d, gap) && optLt(r.begin.key, topKey()));
|
return niLt(d, gap) || (niLe(d, gap) && optLt(r.begin.key, topKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossCompleteHigh(const RangeRead& r, const Result& res) {
|
bool negCrossCompleteHigh(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
return !r.reverse && r.begin.offset < 0 && !res.more &&
|
||||||
r.end_.offset >= 2 && optLt(first(res), r.begin.key) &&
|
r.end_.offset >= 2 && optLt(first(res), r.begin.key) &&
|
||||||
optLt(r.end_.key, first(res));
|
optLt(r.end_.key, first(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossCompleteHigh(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossCompleteHigh(const WideRead& r, const Result& res) {
|
||||||
if (reportedBelowBegin(r, res) <= beginSlack(r)) {
|
if (reportedBelowBegin(r, res) <= beginSlack(r)) {
|
||||||
if (res.keys.size() == residualE(r)) return mkRange(bottomKey(), clampHighU(r, res));
|
if (res.keys.size() == residualE(r)) return mkRange(bottomKey(), clampHighU(r, res));
|
||||||
return mkRange(bottomKey(), topKey());
|
return mkRange(bottomKey(), topKey());
|
||||||
@@ -248,23 +251,23 @@ ConflictRange closedFormNegCrossCompleteHigh(const RangeRead& r, const Result& r
|
|||||||
|
|
||||||
ConflictRange topOfLast(KeyView k) { return mkRange(asKey(k), topKey()); }
|
ConflictRange topOfLast(KeyView k) { return mkRange(asKey(k), topKey()); }
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossOvershoot(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossOvershoot(const WideRead& r, const Result& res) {
|
||||||
if (reportedBelowBegin(r, res) <= beginSlack(r))
|
if (reportedBelowBegin(r, res) <= beginSlack(r))
|
||||||
return mkRange(bottomKey(), topKey());
|
return mkRange(bottomKey(), topKey());
|
||||||
return topOfLast(firstKey(res));
|
return topOfLast(firstKey(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossEndOne(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossEndOne(const WideRead& r, const Result& res) {
|
||||||
return mkRange(first(res), r.end_.key);
|
return mkRange(first(res), r.end_.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossEndOneLong(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossEndOneLong(const WideRead& r, const Result& res) {
|
||||||
return mkRange(first(res), r.begin.key);
|
return mkRange(first(res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossCompleteResidual(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossCompleteResidual(const WideRead& r, const Result& res) {
|
||||||
OptKey reducedEnd = afterLast(res);
|
OptKey reducedEnd = afterLast(res);
|
||||||
RangeRead rp = r;
|
WideRead rp = r;
|
||||||
rp.end_.key = optView(reducedEnd);
|
rp.end_.key = optView(reducedEnd);
|
||||||
rp.end_.offset = r.end_.offset - static_cast<Int>(residualT(r, res));
|
rp.end_.offset = r.end_.offset - static_cast<Int>(residualT(r, res));
|
||||||
if (rp.end_.offset >= 2)
|
if (rp.end_.offset >= 2)
|
||||||
@@ -276,17 +279,17 @@ ConflictRange closedFormNegCrossCompleteResidual(const RangeRead& r, const Resul
|
|||||||
return closedFormNegCrossEndOneLong(rp, res);
|
return closedFormNegCrossEndOneLong(rp, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossCompleteHighResidual(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossCompleteHighResidual(const WideRead& r, const Result& res) {
|
||||||
if (negCrossCompleteHigh(r, res))
|
if (negCrossCompleteHigh(r, res))
|
||||||
return closedFormNegCrossCompleteHigh(r, res);
|
return closedFormNegCrossCompleteHigh(r, res);
|
||||||
return closedFormNegCrossCompleteResidual(r, res);
|
return closedFormNegCrossCompleteResidual(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossNonclampUnified(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossNonclampUnified(const WideRead& r, const Result& res) {
|
||||||
return mkRange(first(res), optMax(r.end_.key, r.begin.key));
|
return mkRange(first(res), optMax(r.end_.key, r.begin.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossTopUnified(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormNegCrossTopUnified(const WideRead& r, const Result& res) {
|
||||||
OptKeyView begin = reportedBelowBegin(r, res) <= beginSlack(r)
|
OptKeyView begin = reportedBelowBegin(r, res) <= beginSlack(r)
|
||||||
? bottomKeyView()
|
? bottomKeyView()
|
||||||
: leastReportedOpt(r, res);
|
: leastReportedOpt(r, res);
|
||||||
@@ -297,7 +300,7 @@ ConflictRange closedFormNegCrossTopUnified(const RangeRead& r, const Result& res
|
|||||||
// Crossed truncated cases
|
// Crossed truncated cases
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool negCrossTruncNonposGap(const RangeRead& r, const Result& res) {
|
bool negCrossTruncNonposGap(const WideRead& r, const Result& res) {
|
||||||
return res.more && !r.reverse && r.begin.offset < 0 &&
|
return res.more && !r.reverse && r.begin.offset < 0 &&
|
||||||
optLt(leastReportedOpt(r, res), r.begin.key) &&
|
optLt(leastReportedOpt(r, res), r.begin.key) &&
|
||||||
r.end_.offset <= 0 &&
|
r.end_.offset <= 0 &&
|
||||||
@@ -310,12 +313,12 @@ bool negCrossTruncNonposGap(const RangeRead& r, const Result& res) {
|
|||||||
NatInf::of(clampNonposD(r) + 1)));
|
NatInf::of(clampNonposD(r) + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncNonposGapA2aBottom(const RangeRead& r, const Result& res) {
|
bool negCrossTruncNonposGapA2aBottom(const WideRead& r, const Result& res) {
|
||||||
return negCrossTruncNonposGap(r, res) && optLt(r.end_.key, r.begin.key) &&
|
return negCrossTruncNonposGap(r, res) && optLt(r.end_.key, r.begin.key) &&
|
||||||
clampNonposBottom(r, res);
|
clampNonposBottom(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncNonposGapA2aBottomHigh(const RangeRead& r, const Result& res) {
|
bool negCrossTruncNonposGapA2aBottomHigh(const WideRead& r, const Result& res) {
|
||||||
std::uint64_t extra = isBottom(first(res)) ? 1 : 0;
|
std::uint64_t extra = isBottom(first(res)) ? 1 : 0;
|
||||||
NatInf lhs = NatInf::of(beginSlack(r) + 1 + extra);
|
NatInf lhs = NatInf::of(beginSlack(r) + 1 + extra);
|
||||||
NatInf rhs = niAdd(NatInf::of(res.keys.size()),
|
NatInf rhs = niAdd(NatInf::of(res.keys.size()),
|
||||||
@@ -323,26 +326,26 @@ bool negCrossTruncNonposGapA2aBottomHigh(const RangeRead& r, const Result& res)
|
|||||||
return negCrossTruncNonposGapA2aBottom(r, res) && niLe(lhs, rhs);
|
return negCrossTruncNonposGapA2aBottom(r, res) && niLe(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const RangeRead& r,
|
ConflictRange closedFormNegCrossTruncNonposGapA2aBottom(const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
if (negCrossTruncNonposGapA2aBottomHigh(r, res))
|
if (negCrossTruncNonposGapA2aBottomHigh(r, res))
|
||||||
return mkRange(bottomKey(), r.begin.key);
|
return mkRange(bottomKey(), r.begin.key);
|
||||||
return mkRange(bottomKey(), r.end_.key);
|
return mkRange(bottomKey(), r.end_.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool finiteUnderCond(const RangeRead& r, const Result& res) {
|
bool finiteUnderCond(const WideRead& r, const Result& res) {
|
||||||
NatInf lhs = niAdd(NatInf::of(natSub(reportedBelowBegin(r, res), 1)),
|
NatInf lhs = niAdd(NatInf::of(natSub(reportedBelowBegin(r, res), 1)),
|
||||||
intervalCard(afterFirst(res), r.begin.key));
|
intervalCard(afterFirst(res), r.begin.key));
|
||||||
return niLe(lhs, NatInf::of(beginSlack(r)));
|
return niLe(lhs, NatInf::of(beginSlack(r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualFiniteOver(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevResidualFiniteOver(const WideRead& r, const Result& res) {
|
||||||
return res.more && r.reverse && r.begin.offset < 0 && r.end_.offset >= 2 &&
|
return res.more && r.reverse && r.begin.offset < 0 && r.end_.offset >= 2 &&
|
||||||
optLt(r.end_.key, last(res)) && optLt(last(res), r.begin.key) &&
|
optLt(r.end_.key, last(res)) && optLt(last(res), r.begin.key) &&
|
||||||
residualT(r, res) == residualE(r);
|
residualT(r, res) == residualE(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const RangeRead& r,
|
ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
OptKeyView L = last(res);
|
OptKeyView L = last(res);
|
||||||
OptKey U = finiteUnderCond(r, res) ? afterFirst(res) : ownKey(r.begin.key);
|
OptKey U = finiteUnderCond(r, res) ? afterFirst(res) : ownKey(r.begin.key);
|
||||||
@@ -351,7 +354,7 @@ ConflictRange closedFormNegCrossTruncRevResidualFiniteUnified(const RangeRead& r
|
|||||||
return mkRange(std::move(L), std::move(U));
|
return mkRange(std::move(L), std::move(U));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sentinelLargeTight(const RangeRead& r, const Result& res) {
|
bool sentinelLargeTight(const WideRead& r, const Result& res) {
|
||||||
NatInf lhs = NatInf::of(residualE(r));
|
NatInf lhs = NatInf::of(residualE(r));
|
||||||
NatInf rhs = niAdd(intervalCard(r.end_.key, last(res)),
|
NatInf rhs = niAdd(intervalCard(r.end_.key, last(res)),
|
||||||
NatInf::of(res.keys.size()));
|
NatInf::of(res.keys.size()));
|
||||||
@@ -359,7 +362,7 @@ bool sentinelLargeTight(const RangeRead& r, const Result& res) {
|
|||||||
return niEq(lhs, rhs) && nPlusBegin == 1;
|
return niEq(lhs, rhs) && nPlusBegin == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopLarge(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevResidualTopLarge(const WideRead& r, const Result& res) {
|
||||||
if (!(res.more && r.reverse && r.begin.offset < 0 && r.end_.offset >= 2 &&
|
if (!(res.more && r.reverse && r.begin.offset < 0 && r.end_.offset >= 2 &&
|
||||||
optLt(r.end_.key, last(res)) && residualT(r, res) < residualE(r)))
|
optLt(r.end_.key, last(res)) && residualT(r, res) < residualE(r)))
|
||||||
return false;
|
return false;
|
||||||
@@ -369,11 +372,11 @@ bool negCrossTruncRevResidualTopLarge(const RangeRead& r, const Result& res) {
|
|||||||
return niLe(lhs, rhs);
|
return niLe(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopLargeSentinel(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevResidualTopLargeSentinel(const WideRead& r, const Result& res) {
|
||||||
return negCrossTruncRevResidualTopLarge(r, res) && isTop(r.begin.key);
|
return negCrossTruncRevResidualTopLarge(r, res) && isTop(r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const RangeRead& r,
|
ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
OptKeyView L = last(res);
|
OptKeyView L = last(res);
|
||||||
if (negCrossTruncRevResidualTopLargeSentinel(r, res) &&
|
if (negCrossTruncRevResidualTopLargeSentinel(r, res) &&
|
||||||
@@ -382,7 +385,7 @@ ConflictRange closedFormNegCrossTruncRevResidualTopLargeUnified(const RangeRead&
|
|||||||
return mkRange(r.end_.key, topKey());
|
return mkRange(r.end_.key, topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange truncatedRangeRev(const RangeRead& r, KeyView lastReported) {
|
ConflictRange truncatedRangeRev(const WideRead& r, KeyView lastReported) {
|
||||||
return mkRange(asKey(lastReported), r.end_.key);
|
return mkRange(asKey(lastReported), r.end_.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -391,7 +394,7 @@ ConflictRange truncatedRangeRev(const RangeRead& r, KeyView lastReported) {
|
|||||||
// Complete and offset-one cases
|
// Complete and offset-one cases
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
ConflictRange closedFormReverseTruncatedZero(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormReverseTruncatedZero(const WideRead& r, const Result& res) {
|
||||||
if (r.end_.offset <= 1) return truncatedRangeRev(r, lastKey(res));
|
if (r.end_.offset <= 1) return truncatedRangeRev(r, lastKey(res));
|
||||||
OptKeyView L = last(res);
|
OptKeyView L = last(res);
|
||||||
if (residualT(r, res) == residualE(r)) {
|
if (residualT(r, res) == residualE(r)) {
|
||||||
@@ -407,18 +410,18 @@ ConflictRange closedFormReverseTruncatedZero(const RangeRead& r, const Result& r
|
|||||||
return mkRange(std::move(L), topKey());
|
return mkRange(std::move(L), topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange truncatedRange(const RangeRead& r, KeyView lastReported) {
|
ConflictRange truncatedRange(const WideRead& r, KeyView lastReported) {
|
||||||
return mkRange(r.begin.key, asKey(keyAfter(lastReported)));
|
return mkRange(r.begin.key, asKey(keyAfter(lastReported)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange truncatedForwardClosed(const RangeRead& r, const Result& res) {
|
ConflictRange truncatedForwardClosed(const WideRead& r, const Result& res) {
|
||||||
NatInf cap = intervalCard(r.end_.key, r.begin.key);
|
NatInf cap = intervalCard(r.end_.key, r.begin.key);
|
||||||
NatInf room = NatInf::of(natSub(residualE(r), res.keys.size()));
|
NatInf room = NatInf::of(natSub(residualE(r), res.keys.size()));
|
||||||
if (niLe(cap, room)) return truncatedRange(r, lastKey(res));
|
if (niLe(cap, room)) return truncatedRange(r, lastKey(res));
|
||||||
return mkRange(r.end_.key, afterLast(res));
|
return mkRange(r.end_.key, afterLast(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange completeClosedWith(const OptKey& endKey, const RangeRead& r,
|
ConflictRange completeClosedWith(const OptKey& endKey, const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
OptKeyView begin = r.begin.key;
|
OptKeyView begin = r.begin.key;
|
||||||
if (optLt(r.end_.key, r.begin.key) &&
|
if (optLt(r.end_.key, r.begin.key) &&
|
||||||
@@ -432,48 +435,48 @@ ConflictRange completeClosedWith(const OptKey& endKey, const RangeRead& r,
|
|||||||
return mkRange(std::move(begin), topKey());
|
return mkRange(std::move(begin), topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange completeReversedClosed(const RangeRead& r, const Result& res) {
|
ConflictRange completeReversedClosed(const WideRead& r, const Result& res) {
|
||||||
return completeClosedWith(afterFirst(res), r, res);
|
return completeClosedWith(afterFirst(res), r, res);
|
||||||
}
|
}
|
||||||
ConflictRange completeForwardClosed(const RangeRead& r, const Result& res) {
|
ConflictRange completeForwardClosed(const WideRead& r, const Result& res) {
|
||||||
return completeClosedWith(afterLast(res), r, res);
|
return completeClosedWith(afterLast(res), r, res);
|
||||||
}
|
}
|
||||||
ConflictRange completeClosed(const RangeRead& r, const Result& res) {
|
ConflictRange completeClosed(const WideRead& r, const Result& res) {
|
||||||
return r.reverse ? completeReversedClosed(r, res) : completeForwardClosed(r, res);
|
return r.reverse ? completeReversedClosed(r, res) : completeForwardClosed(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormOffsetOneTruncated(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormOffsetOneTruncated(const WideRead& r, const Result& res) {
|
||||||
if (r.end_.offset <= 0) return mkRange(r.begin.key, r.end_.key);
|
if (r.end_.offset <= 0) return mkRange(r.begin.key, r.end_.key);
|
||||||
return truncatedRange(r, lastKey(res));
|
return truncatedRange(r, lastKey(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange topRange(const RangeRead& r) { return mkRange(r.begin.key, topKey()); }
|
ConflictRange topRange(const WideRead& r) { return mkRange(r.begin.key, topKey()); }
|
||||||
|
|
||||||
ConflictRange closedFormOffsetOneWith(KeyView endKey, const RangeRead& r,
|
ConflictRange closedFormOffsetOneWith(KeyView endKey, const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
||||||
if (residualT(r, res) == residualE(r)) return truncatedRange(r, endKey);
|
if (residualT(r, res) == residualE(r)) return truncatedRange(r, endKey);
|
||||||
return topRange(r);
|
return topRange(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormOffsetOneRev(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormOffsetOneRev(const WideRead& r, const Result& res) {
|
||||||
return closedFormOffsetOneWith(firstKey(res), r, res);
|
return closedFormOffsetOneWith(firstKey(res), r, res);
|
||||||
}
|
}
|
||||||
ConflictRange closedFormOffsetOne(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormOffsetOne(const WideRead& r, const Result& res) {
|
||||||
return closedFormOffsetOneWith(lastKey(res), r, res);
|
return closedFormOffsetOneWith(lastKey(res), r, res);
|
||||||
}
|
}
|
||||||
ConflictRange closedFormOffsetOneAny(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormOffsetOneAny(const WideRead& r, const Result& res) {
|
||||||
return r.reverse ? closedFormOffsetOneRev(r, res) : closedFormOffsetOne(r, res);
|
return r.reverse ? closedFormOffsetOneRev(r, res) : closedFormOffsetOne(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormOffsetOneUniversal(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormOffsetOneUniversal(const WideRead& r, const Result& res) {
|
||||||
if (res.more)
|
if (res.more)
|
||||||
return r.reverse ? closedFormReverseTruncatedZero(r, res)
|
return r.reverse ? closedFormReverseTruncatedZero(r, res)
|
||||||
: closedFormOffsetOneTruncated(r, res);
|
: closedFormOffsetOneTruncated(r, res);
|
||||||
return closedFormOffsetOneAny(r, res);
|
return closedFormOffsetOneAny(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormOffsetOneTotal(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormOffsetOneTotal(const WideRead& r, const Result& res) {
|
||||||
if (optLt(r.end_.key, r.begin.key)) {
|
if (optLt(r.end_.key, r.begin.key)) {
|
||||||
if (res.more)
|
if (res.more)
|
||||||
return r.reverse ? closedFormReverseTruncatedZero(r, res)
|
return r.reverse ? closedFormReverseTruncatedZero(r, res)
|
||||||
@@ -483,7 +486,7 @@ ConflictRange closedFormOffsetOneTotal(const RangeRead& r, const Result& res) {
|
|||||||
return closedFormOffsetOneUniversal(r, res);
|
return closedFormOffsetOneUniversal(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossEndOneLong(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossEndOneLong(const WideRead& r, const Result& res) {
|
||||||
return mkRange(leastReportedOpt(r, res), r.begin.key);
|
return mkRange(leastReportedOpt(r, res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -491,31 +494,31 @@ ConflictRange closedFormZeroCrossEndOneLong(const RangeRead& r, const Result& re
|
|||||||
// Zero-crossed cases
|
// Zero-crossed cases
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossEnd(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossEnd(const WideRead& r, const Result& res) {
|
||||||
return mkRange(leastReportedOpt(r, res), r.end_.key);
|
return mkRange(leastReportedOpt(r, res), r.end_.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange completeForwardCrossedGeneral(const RangeRead& r, const Result& res) {
|
ConflictRange completeForwardCrossedGeneral(const WideRead& r, const Result& res) {
|
||||||
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
||||||
if (residualT(r, res) + residualB(r) == residualE(r))
|
if (residualT(r, res) + residualB(r) == residualE(r))
|
||||||
return mkRange(r.end_.key, afterLast(res));
|
return mkRange(r.end_.key, afterLast(res));
|
||||||
return mkRange(crossedBegin(r, res), topKey());
|
return mkRange(crossedBegin(r, res), topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeRead zeroBeginAnchor(const RangeRead& r, const Result& res) {
|
WideRead zeroBeginAnchor(const WideRead& r, const Result& res) {
|
||||||
RangeRead out = r;
|
WideRead out = r;
|
||||||
out.begin.key = first(res);
|
out.begin.key = first(res);
|
||||||
out.begin.offset = 1;
|
out.begin.offset = 1;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange zeroCrossLongAnchor(const RangeRead& r, const Result& res) {
|
ConflictRange zeroCrossLongAnchor(const WideRead& r, const Result& res) {
|
||||||
if (optLt(r.end_.key, first(res)))
|
if (optLt(r.end_.key, first(res)))
|
||||||
return completeForwardCrossedGeneral(zeroBeginAnchor(r, res), res);
|
return completeForwardCrossedGeneral(zeroBeginAnchor(r, res), res);
|
||||||
return closedFormOffsetOne(zeroBeginAnchor(r, res), res);
|
return closedFormOffsetOne(zeroBeginAnchor(r, res), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossLong(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossLong(const WideRead& r, const Result& res) {
|
||||||
if (isTop(r.begin.key)) {
|
if (isTop(r.begin.key)) {
|
||||||
OptKeyView H = first(res);
|
OptKeyView H = first(res);
|
||||||
std::uint64_t e = residualE(r);
|
std::uint64_t e = residualE(r);
|
||||||
@@ -529,11 +532,11 @@ ConflictRange closedFormZeroCrossLong(const RangeRead& r, const Result& res) {
|
|||||||
return mkRange(a.begin, optMax(a.end_, r.begin.key));
|
return mkRange(a.begin, optMax(a.end_, r.begin.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossUnderEnd(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossUnderEnd(const WideRead& r, const Result& res) {
|
||||||
return closedFormOffsetOneTotal(zeroBeginAnchor(r, res), res);
|
return closedFormOffsetOneTotal(zeroBeginAnchor(r, res), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossComplete(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossComplete(const WideRead& r, const Result& res) {
|
||||||
if (r.end_.offset <= 0) return closedFormZeroCrossEnd(r, res);
|
if (r.end_.offset <= 0) return closedFormZeroCrossEnd(r, res);
|
||||||
if (r.end_.offset == 1) {
|
if (r.end_.offset == 1) {
|
||||||
if (optLt(r.end_.key, r.begin.key))
|
if (optLt(r.end_.key, r.begin.key))
|
||||||
@@ -545,23 +548,23 @@ ConflictRange closedFormZeroCrossComplete(const RangeRead& r, const Result& res)
|
|||||||
return closedFormZeroCrossUnderEnd(r, res);
|
return closedFormZeroCrossUnderEnd(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossCompleteRev(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossCompleteRev(const WideRead& r, const Result& res) {
|
||||||
std::vector<KeyView> rev = reversedKeys(res);
|
std::vector<KeyView> rev = reversedKeys(res);
|
||||||
return closedFormZeroCrossComplete(forwardRead(r), Result{rev, false});
|
return closedFormZeroCrossComplete(forwardRead(r), Result{rev, false});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossUnderEnd(const RangeRead& r, const Result& res) {
|
bool zeroCrossUnderEnd(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
||||||
r.end_.offset >= 2 && optLt(leastReportedOpt(r, res), r.begin.key) &&
|
r.end_.offset >= 2 && optLt(leastReportedOpt(r, res), r.begin.key) &&
|
||||||
optLe(r.begin.key, r.end_.key);
|
optLe(r.begin.key, r.end_.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossResidual(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossResidual(const WideRead& r, const Result& res) {
|
||||||
if (zeroCrossUnderEnd(r, res)) return closedFormZeroCrossUnderEnd(r, res);
|
if (zeroCrossUnderEnd(r, res)) return closedFormZeroCrossUnderEnd(r, res);
|
||||||
return closedFormZeroCrossLong(r, res);
|
return closedFormZeroCrossLong(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormZeroCrossTruncRevCrossed(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormZeroCrossTruncRevCrossed(const WideRead& r, const Result& res) {
|
||||||
Result complete = res;
|
Result complete = res;
|
||||||
complete.more = false;
|
complete.more = false;
|
||||||
return closedFormZeroCrossCompleteRev(r, complete);
|
return closedFormZeroCrossCompleteRev(r, complete);
|
||||||
@@ -571,7 +574,7 @@ ConflictRange closedFormZeroCrossTruncRevCrossed(const RangeRead& r, const Resul
|
|||||||
// Empty result
|
// Empty result
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool AlwaysEmpty(const RangeRead& r) {
|
bool AlwaysEmpty(const WideRead& r) {
|
||||||
NatInf gap = intervalCard(r.begin.key, r.end_.key);
|
NatInf gap = intervalCard(r.begin.key, r.end_.key);
|
||||||
std::uint64_t b = noPinB(gap, r.begin.offset, r.end_.offset);
|
std::uint64_t b = noPinB(gap, r.begin.offset, r.end_.offset);
|
||||||
std::uint64_t e = cELo(r.begin.offset, r.end_.offset);
|
std::uint64_t e = cELo(r.begin.offset, r.end_.offset);
|
||||||
@@ -601,18 +604,18 @@ bool AlwaysEmpty(const RangeRead& r) {
|
|||||||
return !inner;
|
return !inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange emptyRange(const RangeRead& r) {
|
ConflictRange emptyRange(const WideRead& r) {
|
||||||
return mkRange(r.begin.key, r.begin.key);
|
return mkRange(r.begin.key, r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange crossedRangeGeneral(const RangeRead& r) {
|
ConflictRange crossedRangeGeneral(const WideRead& r) {
|
||||||
NatInf diff = niSub(NatInf::of(residualE(r)), NatInf::of(residualB(r)));
|
NatInf diff = niSub(NatInf::of(residualE(r)), NatInf::of(residualB(r)));
|
||||||
if (niLe(diff, intervalCard(r.end_.key, r.begin.key)))
|
if (niLe(diff, intervalCard(r.end_.key, r.begin.key)))
|
||||||
return mkRange(r.end_.key, topKey());
|
return mkRange(r.end_.key, topKey());
|
||||||
return mkRange(r.begin.key, topKey());
|
return mkRange(r.begin.key, topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange emptyValue(const RangeRead& r) {
|
ConflictRange emptyValue(const WideRead& r) {
|
||||||
if (AlwaysEmpty(r)) return emptyRange(r);
|
if (AlwaysEmpty(r)) return emptyRange(r);
|
||||||
if (r.begin.offset <= 0) {
|
if (r.begin.offset <= 0) {
|
||||||
if (r.end_.offset >= 2) return mkRange(bottomKey(), topKey());
|
if (r.end_.offset >= 2) return mkRange(bottomKey(), topKey());
|
||||||
@@ -630,15 +633,15 @@ ConflictRange emptyValue(const RangeRead& r) {
|
|||||||
// Complete and forward-truncated results
|
// Complete and forward-truncated results
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
OptKeyView closedFormBegin(const RangeRead& r, const Result& res) {
|
OptKeyView closedFormBegin(const WideRead& r, const Result& res) {
|
||||||
return clampsToBottom(r, res) ? bottomKeyView() : r.begin.key;
|
return clampsToBottom(r, res) ? bottomKeyView() : r.begin.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormFinite(const RangeRead& r, const Result& res) {
|
bool closedFormFinite(const WideRead& r, const Result& res) {
|
||||||
return closedFormDeficit(r) + residualT(r, res) == residualE(r);
|
return closedFormDeficit(r) + residualT(r, res) == residualE(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormCompleteForward(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormCompleteForward(const WideRead& r, const Result& res) {
|
||||||
OptKeyView begin = closedFormBegin(r, res);
|
OptKeyView begin = closedFormBegin(r, res);
|
||||||
if (r.end_.offset <= 1) return mkRange(begin, r.end_.key);
|
if (r.end_.offset <= 1) return mkRange(begin, r.end_.key);
|
||||||
if (clampsToBottom(r, res) || optLe(r.begin.key, r.end_.key)) {
|
if (clampsToBottom(r, res) || optLe(r.begin.key, r.end_.key)) {
|
||||||
@@ -652,18 +655,18 @@ ConflictRange closedFormCompleteForward(const RangeRead& r, const Result& res) {
|
|||||||
return mkRange(crossedBegin(r, res), topKey());
|
return mkRange(crossedBegin(r, res), topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormComplete(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormComplete(const WideRead& r, const Result& res) {
|
||||||
if (!r.reverse) return closedFormCompleteForward(forwardRead(r), res);
|
if (!r.reverse) return closedFormCompleteForward(forwardRead(r), res);
|
||||||
std::vector<KeyView> rev = reversedKeys(res);
|
std::vector<KeyView> rev = reversedKeys(res);
|
||||||
return closedFormCompleteForward(forwardRead(r), Result{rev, false});
|
return closedFormCompleteForward(forwardRead(r), Result{rev, false});
|
||||||
}
|
}
|
||||||
|
|
||||||
NatInf closedFormForwardCapacity(const RangeRead& r, const Result& res) {
|
NatInf closedFormForwardCapacity(const WideRead& r, const Result& res) {
|
||||||
if (clampsToBottom(r, res)) return NatInf::of(0);
|
if (clampsToBottom(r, res)) return NatInf::of(0);
|
||||||
return intervalCard(r.end_.key, r.begin.key);
|
return intervalCard(r.end_.key, r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormForwardTruncated(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormForwardTruncated(const WideRead& r, const Result& res) {
|
||||||
OptKeyView begin = closedFormBegin(r, res);
|
OptKeyView begin = closedFormBegin(r, res);
|
||||||
if (r.end_.offset <= 0) return mkRange(begin, r.end_.key);
|
if (r.end_.offset <= 0) return mkRange(begin, r.end_.key);
|
||||||
std::uint64_t room = natSub(natSub(residualE(r), res.keys.size()), residualB(r));
|
std::uint64_t room = natSub(natSub(residualE(r), res.keys.size()), residualB(r));
|
||||||
@@ -676,22 +679,22 @@ ConflictRange closedFormForwardTruncated(const RangeRead& r, const Result& res)
|
|||||||
// Reversed truncation
|
// Reversed truncation
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
std::uint64_t closedFormReverseCount(const RangeRead& r, const Result& res) {
|
std::uint64_t closedFormReverseCount(const WideRead& r, const Result& res) {
|
||||||
if (optLt(r.end_.key, r.begin.key))
|
if (optLt(r.end_.key, r.begin.key))
|
||||||
return static_cast<std::uint64_t>(res.keys.size());
|
return static_cast<std::uint64_t>(res.keys.size());
|
||||||
return residualT(r, res);
|
return residualT(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormReverseFinite(const RangeRead& r, const Result& res) {
|
bool closedFormReverseFinite(const WideRead& r, const Result& res) {
|
||||||
return closedFormDeficit(r) + closedFormReverseCount(r, res) == residualE(r);
|
return closedFormDeficit(r) + closedFormReverseCount(r, res) == residualE(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormCrossedRoom(const RangeRead& r, const Result& res) {
|
bool closedFormCrossedRoom(const WideRead& r, const Result& res) {
|
||||||
NatInf lhs = NatInf::of(natSub(residualE(r), res.keys.size()));
|
NatInf lhs = NatInf::of(natSub(residualE(r), res.keys.size()));
|
||||||
return niLe(lhs, intervalCard(r.end_.key, last(res)));
|
return niLe(lhs, intervalCard(r.end_.key, last(res)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormReverseTruncatedSkip(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormReverseTruncatedSkip(const WideRead& r, const Result& res) {
|
||||||
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
if (r.end_.offset <= 1) return mkRange(r.begin.key, r.end_.key);
|
||||||
if (allBelowEnd(r, res)) return topRange(r);
|
if (allBelowEnd(r, res)) return topRange(r);
|
||||||
if (closedFormReverseFinite(r, res)) {
|
if (closedFormReverseFinite(r, res)) {
|
||||||
@@ -704,12 +707,12 @@ ConflictRange closedFormReverseTruncatedSkip(const RangeRead& r, const Result& r
|
|||||||
return mkRange(begin, topKey());
|
return mkRange(begin, topKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormReverseTruncated(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormReverseTruncated(const WideRead& r, const Result& res) {
|
||||||
if (residualB(r) == 0) return closedFormReverseTruncatedZero(r, res);
|
if (residualB(r) == 0) return closedFormReverseTruncatedZero(r, res);
|
||||||
return closedFormReverseTruncatedSkip(r, res);
|
return closedFormReverseTruncatedSkip(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormPositive(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormPositive(const WideRead& r, const Result& res) {
|
||||||
if (!res.more) return closedFormComplete(r, res);
|
if (!res.more) return closedFormComplete(r, res);
|
||||||
if (!r.reverse) return closedFormForwardTruncated(r, res);
|
if (!r.reverse) return closedFormForwardTruncated(r, res);
|
||||||
return closedFormReverseTruncated(r, res);
|
return closedFormReverseTruncated(r, res);
|
||||||
@@ -719,25 +722,25 @@ ConflictRange closedFormPositive(const RangeRead& r, const Result& res) {
|
|||||||
// Crossed table
|
// Crossed table
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
bool overshoot(const RangeRead& r, const Result& res) {
|
bool overshoot(const WideRead& r, const Result& res) {
|
||||||
return r.end_.offset >= 2 && allBelowEnd(r, res);
|
return r.end_.offset >= 2 && allBelowEnd(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossOvershootComplete(const RangeRead& r, const Result& res) {
|
bool zeroCrossOvershootComplete(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset == 0 && !res.more && !r.reverse && overshoot(r, res) &&
|
return r.begin.offset == 0 && !res.more && !r.reverse && overshoot(r, res) &&
|
||||||
optLt(leastReportedOpt(r, res), r.begin.key);
|
optLt(leastReportedOpt(r, res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossOvershoot(const RangeRead& r, const Result& res) {
|
bool negCrossOvershoot(const WideRead& r, const Result& res) {
|
||||||
return !r.reverse && r.begin.offset < 0 && !res.more && overshoot(r, res) &&
|
return !r.reverse && r.begin.offset < 0 && !res.more && overshoot(r, res) &&
|
||||||
optLt(first(res), r.begin.key);
|
optLt(first(res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool crossedCompleteOvershoot(const RangeRead& r, const Result& res) {
|
bool crossedCompleteOvershoot(const WideRead& r, const Result& res) {
|
||||||
return zeroCrossOvershootComplete(r, res) || negCrossOvershoot(r, res);
|
return zeroCrossOvershootComplete(r, res) || negCrossOvershoot(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool crossedCompleteEndLeOne(const RangeRead& r, const Result& res) {
|
bool crossedCompleteEndLeOne(const WideRead& r, const Result& res) {
|
||||||
if (!(!r.reverse && !res.more && r.begin.offset <= 0 &&
|
if (!(!r.reverse && !res.more && r.begin.offset <= 0 &&
|
||||||
optLt(first(res), r.begin.key)))
|
optLt(first(res), r.begin.key)))
|
||||||
return false;
|
return false;
|
||||||
@@ -748,30 +751,30 @@ bool crossedCompleteEndLeOne(const RangeRead& r, const Result& res) {
|
|||||||
clampNonposBottom(r, res));
|
clampNonposBottom(r, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossLongTop(const RangeRead& r, const Result& res) {
|
bool zeroCrossLongTop(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
||||||
r.end_.offset >= 2 && isTop(r.begin.key);
|
r.end_.offset >= 2 && isTop(r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossLongFinite(const RangeRead& r, const Result& res) {
|
bool zeroCrossLongFinite(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
return r.begin.offset == 0 && !res.more && !r.reverse &&
|
||||||
r.end_.offset >= 2 && !isTop(r.begin.key) &&
|
r.end_.offset >= 2 && !isTop(r.begin.key) &&
|
||||||
optLt(r.end_.key, r.begin.key) &&
|
optLt(r.end_.key, r.begin.key) &&
|
||||||
optLt(leastReportedOpt(r, res), r.begin.key);
|
optLt(leastReportedOpt(r, res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool crossedCompleteBeginZero(const RangeRead& r, const Result& res) {
|
bool crossedCompleteBeginZero(const WideRead& r, const Result& res) {
|
||||||
return zeroCrossUnderEnd(r, res) || zeroCrossLongTop(r, res) ||
|
return zeroCrossUnderEnd(r, res) || zeroCrossLongTop(r, res) ||
|
||||||
zeroCrossLongFinite(r, res);
|
zeroCrossLongFinite(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool crossedCompleteClamp(const RangeRead& r, const Result& res) {
|
bool crossedCompleteClamp(const WideRead& r, const Result& res) {
|
||||||
return negCrossClampEndOne(r, res) || negCrossHeadBottom(r, res) ||
|
return negCrossClampEndOne(r, res) || negCrossHeadBottom(r, res) ||
|
||||||
negCrossClampNonposBottom(r, res) ||
|
negCrossClampNonposBottom(r, res) ||
|
||||||
negCrossClampLongNonpos(r, res);
|
negCrossClampLongNonpos(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormCrossedComplete(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormCrossedComplete(const WideRead& r, const Result& res) {
|
||||||
if (crossedCompleteOvershoot(r, res))
|
if (crossedCompleteOvershoot(r, res))
|
||||||
return closedFormNegCrossTopUnified(r, res);
|
return closedFormNegCrossTopUnified(r, res);
|
||||||
if (crossedCompleteEndLeOne(r, res))
|
if (crossedCompleteEndLeOne(r, res))
|
||||||
@@ -783,18 +786,18 @@ ConflictRange closedFormCrossedComplete(const RangeRead& r, const Result& res) {
|
|||||||
return closedFormNegCrossCompleteHighResidual(r, res);
|
return closedFormNegCrossCompleteHighResidual(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zeroCrossTruncRevCrossed(const RangeRead& r, const Result& res) {
|
bool zeroCrossTruncRevCrossed(const WideRead& r, const Result& res) {
|
||||||
return r.begin.offset == 0 && r.reverse && res.more &&
|
return r.begin.offset == 0 && r.reverse && res.more &&
|
||||||
optLt(leastReportedOpt(r, res), r.begin.key);
|
optLt(leastReportedOpt(r, res), r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevUnder(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevUnder(const WideRead& r, const Result& res) {
|
||||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||||
optLt(last(res), r.begin.key) && optLe(r.begin.key, r.end_.key) &&
|
optLt(last(res), r.begin.key) && optLe(r.begin.key, r.end_.key) &&
|
||||||
r.end_.offset <= 1;
|
r.end_.offset <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevCrossedLow(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevCrossedLow(const WideRead& r, const Result& res) {
|
||||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||||
optLt(last(res), r.begin.key) && optLt(r.end_.key, r.begin.key) &&
|
optLt(last(res), r.begin.key) && optLt(r.end_.key, r.begin.key) &&
|
||||||
r.end_.offset <= 1 &&
|
r.end_.offset <= 1 &&
|
||||||
@@ -804,24 +807,24 @@ bool negCrossTruncRevCrossedLow(const RangeRead& r, const Result& res) {
|
|||||||
NatInf::of(beginSlack(r) + 1));
|
NatInf::of(beginSlack(r) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool revTruncLeOneLow(const RangeRead& r, const Result& res) {
|
bool revTruncLeOneLow(const WideRead& r, const Result& res) {
|
||||||
return negCrossTruncRevUnder(r, res) ||
|
return negCrossTruncRevUnder(r, res) ||
|
||||||
negCrossTruncRevCrossedLow(r, res);
|
negCrossTruncRevCrossedLow(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevBelowEnd(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevBelowEnd(const WideRead& r, const Result& res) {
|
||||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||||
optLt(last(res), r.begin.key) && overshoot(r, res);
|
optLt(last(res), r.begin.key) && overshoot(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualRoom(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevResidualRoom(const WideRead& r, const Result& res) {
|
||||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||||
r.end_.offset >= 2 && anyAtOrAboveEnd(r, res) &&
|
r.end_.offset >= 2 && anyAtOrAboveEnd(r, res) &&
|
||||||
niLe(niAdd(intervalCard(r.end_.key, first(res)), NatInf::of(2)),
|
niLe(niAdd(intervalCard(r.end_.key, first(res)), NatInf::of(2)),
|
||||||
NatInf::of(residualE(r)));
|
NatInf::of(residualE(r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopCrossedSmallGap(const RangeRead& r,
|
bool negCrossTruncRevResidualTopCrossedSmallGap(const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
if (!(res.more && r.reverse && r.begin.offset < 0 &&
|
if (!(res.more && r.reverse && r.begin.offset < 0 &&
|
||||||
r.end_.offset >= 2 && optLt(r.end_.key, last(res))))
|
r.end_.offset >= 2 && optLt(r.end_.key, last(res))))
|
||||||
@@ -831,52 +834,52 @@ bool negCrossTruncRevResidualTopCrossedSmallGap(const RangeRead& r,
|
|||||||
return niLt(lhs, NatInf::of(residualE(r)));
|
return niLt(lhs, NatInf::of(residualE(r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopCrossed(const RangeRead& r, const Result& res) {
|
bool negCrossTruncRevResidualTopCrossed(const WideRead& r, const Result& res) {
|
||||||
return res.more && r.reverse && r.begin.offset < 0 &&
|
return res.more && r.reverse && r.begin.offset < 0 &&
|
||||||
r.end_.offset >= 2 && optLe(last(res), r.end_.key) &&
|
r.end_.offset >= 2 && optLe(last(res), r.end_.key) &&
|
||||||
residualT(r, res) < residualE(r);
|
residualT(r, res) < residualE(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool revTruncGeTwoTop(const RangeRead& r, const Result& res) {
|
bool revTruncGeTwoTop(const WideRead& r, const Result& res) {
|
||||||
return negCrossTruncRevBelowEnd(r, res) ||
|
return negCrossTruncRevBelowEnd(r, res) ||
|
||||||
negCrossTruncRevResidualRoom(r, res) ||
|
negCrossTruncRevResidualRoom(r, res) ||
|
||||||
negCrossTruncRevResidualTopCrossedSmallGap(r, res) ||
|
negCrossTruncRevResidualTopCrossedSmallGap(r, res) ||
|
||||||
negCrossTruncRevResidualTopCrossed(r, res);
|
negCrossTruncRevResidualTopCrossed(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncRevResidualTopLargeCrossed(const RangeRead& r,
|
bool negCrossTruncRevResidualTopLargeCrossed(const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
return negCrossTruncRevResidualTopLarge(r, res) &&
|
return negCrossTruncRevResidualTopLarge(r, res) &&
|
||||||
optLt(last(res), r.begin.key) && !isTop(r.begin.key);
|
optLt(last(res), r.begin.key) && !isTop(r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool revTruncGeTwoLarge(const RangeRead& r, const Result& res) {
|
bool revTruncGeTwoLarge(const WideRead& r, const Result& res) {
|
||||||
return negCrossTruncRevResidualTopLargeCrossed(r, res) ||
|
return negCrossTruncRevResidualTopLargeCrossed(r, res) ||
|
||||||
negCrossTruncRevResidualTopLargeSentinel(r, res);
|
negCrossTruncRevResidualTopLargeSentinel(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncTopTop(const RangeRead& r, const Result& res) {
|
bool negCrossTruncTopTop(const WideRead& r, const Result& res) {
|
||||||
return res.more && !r.reverse && r.begin.offset < 0 &&
|
return res.more && !r.reverse && r.begin.offset < 0 &&
|
||||||
isTop(r.begin.key) && isTop(r.end_.key) && r.end_.offset <= 0;
|
isTop(r.begin.key) && isTop(r.end_.key) && r.end_.offset <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool negCrossTruncTopTopEq(const RangeRead& r, const Result& res) {
|
bool negCrossTruncTopTopEq(const WideRead& r, const Result& res) {
|
||||||
if (!negCrossTruncTopTop(r, res)) return false;
|
if (!negCrossTruncTopTop(r, res)) return false;
|
||||||
std::uint64_t extra = toNat(1 - r.end_.offset);
|
std::uint64_t extra = toNat(1 - r.end_.offset);
|
||||||
return res.keys.size() + extra == beginSlack(r) + 1;
|
return res.keys.size() + extra == beginSlack(r) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint64_t closedFormClampSlack(const RangeRead& r, const Result& res) {
|
std::uint64_t closedFormClampSlack(const WideRead& r, const Result& res) {
|
||||||
return natSub(beginSlack(r) + 1, res.keys.size()) +
|
return natSub(beginSlack(r) + 1, res.keys.size()) +
|
||||||
(isBottom(first(res)) ? 1 : 0);
|
(isBottom(first(res)) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormClampGapSmall(const RangeRead& r, const Result& res) {
|
bool closedFormClampGapSmall(const WideRead& r, const Result& res) {
|
||||||
return niLe(intervalCard(asKey(lastKey(res)), r.begin.key),
|
return niLe(intervalCard(asKey(lastKey(res)), r.begin.key),
|
||||||
NatInf::of(closedFormClampSlack(r, res)));
|
NatInf::of(closedFormClampSlack(r, res)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormClampGapExactSaturated(const RangeRead& r, const Result& res) {
|
bool closedFormClampGapExactSaturated(const WideRead& r, const Result& res) {
|
||||||
if (!(first(res) != bottomKeyView() && isBottom(r.end_.key) &&
|
if (!(first(res) != bottomKeyView() && isBottom(r.end_.key) &&
|
||||||
residualE(r) == res.keys.size()))
|
residualE(r) == res.keys.size()))
|
||||||
return false;
|
return false;
|
||||||
@@ -884,24 +887,24 @@ bool closedFormClampGapExactSaturated(const RangeRead& r, const Result& res) {
|
|||||||
NatInf::of(natSub(beginSlack(r) + 1, res.keys.size())));
|
NatInf::of(natSub(beginSlack(r) + 1, res.keys.size())));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormClampGapLow(const RangeRead& r, const Result& res) {
|
bool closedFormClampGapLow(const WideRead& r, const Result& res) {
|
||||||
return closedFormClampGapSmall(r, res) ||
|
return closedFormClampGapSmall(r, res) ||
|
||||||
closedFormClampGapExactSaturated(r, res);
|
closedFormClampGapExactSaturated(r, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
OptKey closedFormClampUpper(const RangeRead& r, const Result& res) {
|
OptKey closedFormClampUpper(const WideRead& r, const Result& res) {
|
||||||
if (closedFormClampGapLow(r, res)) return afterLast(res);
|
if (closedFormClampGapLow(r, res)) return afterLast(res);
|
||||||
return ownKey(r.begin.key);
|
return ownKey(r.begin.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool closedFormForwardSaturated(const RangeRead& r, const Result& res) {
|
bool closedFormForwardSaturated(const WideRead& r, const Result& res) {
|
||||||
if (!(residualE(r) > 0 && optLt(r.end_.key, first(res)))) return false;
|
if (!(residualE(r) > 0 && optLt(r.end_.key, first(res)))) return false;
|
||||||
NatInf rhs = niAdd(intervalCard(r.end_.key, first(res)),
|
NatInf rhs = niAdd(intervalCard(r.end_.key, first(res)),
|
||||||
NatInf::of(res.keys.size()));
|
NatInf::of(res.keys.size()));
|
||||||
return niLt(NatInf::of(residualE(r)), rhs);
|
return niLt(NatInf::of(residualE(r)), rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormForwardTruncatedNonpos(const RangeRead& r,
|
ConflictRange closedFormForwardTruncatedNonpos(const WideRead& r,
|
||||||
const Result& res) {
|
const Result& res) {
|
||||||
if (reportedBelowBegin(r, res) <= beginSlack(r)) {
|
if (reportedBelowBegin(r, res) <= beginSlack(r)) {
|
||||||
if (r.end_.offset <= 0) {
|
if (r.end_.offset <= 0) {
|
||||||
@@ -927,7 +930,7 @@ ConflictRange closedFormForwardTruncatedNonpos(const RangeRead& r,
|
|||||||
return mkRange(begin, optMax(r.begin.key, afterLast(res)));
|
return mkRange(begin, optMax(r.begin.key, afterLast(res)));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRange closedFormCrossed(const RangeRead& r, const Result& res) {
|
ConflictRange closedFormCrossed(const WideRead& r, const Result& res) {
|
||||||
if (!res.more) {
|
if (!res.more) {
|
||||||
if (!r.reverse) return closedFormCrossedComplete(r, res);
|
if (!r.reverse) return closedFormCrossedComplete(r, res);
|
||||||
std::vector<KeyView> rev = reversedKeys(res);
|
std::vector<KeyView> rev = reversedKeys(res);
|
||||||
@@ -952,11 +955,11 @@ ConflictRange closedFormCrossed(const RangeRead& r, const Result& res) {
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ConflictRange closedForm(const RangeRead& r, const Result& res) {
|
ConflictRange closedForm(const RangeRead& r, const Result& res) {
|
||||||
assertInputOffsetsFitInt32(r);
|
const WideRead wr = cr::detail::widen(r);
|
||||||
if (res.keys.empty()) return emptyValue(r);
|
if (res.keys.empty()) return emptyValue(wr);
|
||||||
if (r.begin.offset >= 1 || clampedNonpos(r, res))
|
if (wr.begin.offset >= 1 || clampedNonpos(wr, res))
|
||||||
return closedFormPositive(r, res);
|
return closedFormPositive(wr, res);
|
||||||
return closedFormCrossed(r, res);
|
return closedFormCrossed(wr, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cr::literal
|
} // namespace cr::literal
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|||||||
+57
-39
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// Shared data model for the C++ translation of `Statement.closedForm`.
|
// Shared data model for the C++ translation of `Statement.closedForm`.
|
||||||
//
|
//
|
||||||
// Keys are byte strings ordered lexicographically. The model separates
|
// Keys are byte strings ordered lexicographically. The model separates
|
||||||
@@ -16,7 +18,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -38,16 +39,28 @@ using Key = std::string;
|
|||||||
using KeyView = std::string_view;
|
using KeyView = std::string_view;
|
||||||
using OptKey = std::optional<Key>;
|
using OptKey = std::optional<Key>;
|
||||||
using OptKeyView = std::optional<KeyView>;
|
using OptKeyView = std::optional<KeyView>;
|
||||||
// Lean's unbounded `Int`. Caller-supplied offsets are required to fit in
|
// Lean's unbounded `Int`. Public selector offsets are 32-bit; the internal
|
||||||
// `std::int32_t` (see `Selector`), so all intermediate arithmetic in `Int`
|
// wide-offset read used by the decision procedure stores derived offsets here.
|
||||||
// stays far from overflow; the code below relies on that.
|
|
||||||
using Int = std::int64_t;
|
using Int = std::int64_t;
|
||||||
|
|
||||||
struct Selector {
|
struct Selector {
|
||||||
OptKeyView key;
|
OptKeyView key;
|
||||||
// Offsets supplied by callers must lie in `[INT32_MIN, INT32_MAX]`. They are
|
// Caller-supplied offsets are `std::int32_t`, matching FoundationDB.
|
||||||
// stored as `Int` because the closed form also builds derived selectors whose
|
std::int32_t offset = 0;
|
||||||
// offsets (for example `end.offset - residualT`) need not fit in 32 bits.
|
};
|
||||||
|
|
||||||
|
struct RangeRead {
|
||||||
|
Selector begin;
|
||||||
|
Selector end_;
|
||||||
|
bool reverse = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
// Internal mirror of `RangeRead` whose offsets are wide enough for derived
|
||||||
|
// selectors such as `end.offset - residualT`.
|
||||||
|
struct Selector {
|
||||||
|
OptKeyView key;
|
||||||
Int offset = 0;
|
Int offset = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,11 +70,17 @@ struct RangeRead {
|
|||||||
bool reverse = false;
|
bool reverse = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The public offset contract: caller-supplied offsets must fit in
|
inline RangeRead widen(const ::cr::RangeRead& r) {
|
||||||
// `std::int32_t`. This is checked at the public `closedForm` entry points
|
return {{r.begin.key, r.begin.offset},
|
||||||
// (debug builds only) and by the corpus parsers. It is deliberately not
|
{r.end_.key, r.end_.offset},
|
||||||
// checked in `Selector`, because the decision procedure derives selectors
|
r.reverse};
|
||||||
// whose offsets may exceed this range.
|
}
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
// The offset contract shared with the corpus parsers. `Selector::offset` is
|
||||||
|
// already `std::int32_t`, so parsers validate wider parsed values with these
|
||||||
|
// bounds before narrowing.
|
||||||
inline constexpr Int kMinInputOffset =
|
inline constexpr Int kMinInputOffset =
|
||||||
std::numeric_limits<std::int32_t>::min();
|
std::numeric_limits<std::int32_t>::min();
|
||||||
inline constexpr Int kMaxInputOffset =
|
inline constexpr Int kMaxInputOffset =
|
||||||
@@ -72,14 +91,6 @@ inline bool offsetsFitInt32(Int begin, Int end) {
|
|||||||
end >= kMinInputOffset && end <= kMaxInputOffset;
|
end >= kMinInputOffset && end <= kMaxInputOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool inputOffsetsFitInt32(const RangeRead& r) {
|
|
||||||
return offsetsFitInt32(r.begin.offset, r.end_.offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void assertInputOffsetsFitInt32(const RangeRead& r) {
|
|
||||||
assert(inputOffsetsFitInt32(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Result {
|
struct Result {
|
||||||
// A non-owning view of the reported keys. The caller keeps the underlying
|
// A non-owning view of the reported keys. The caller keeps the underlying
|
||||||
// keys alive for the duration of the call.
|
// keys alive for the duration of the call.
|
||||||
@@ -158,11 +169,9 @@ inline OptKey optMax(const std::optional<A>& a, const std::optional<B>& b) {
|
|||||||
|
|
||||||
inline OptKey topKey() { return std::nullopt; }
|
inline OptKey topKey() { return std::nullopt; }
|
||||||
inline OptKey bottomKey() { return OptKey{Key{}}; }
|
inline OptKey bottomKey() { return OptKey{Key{}}; }
|
||||||
// A view of a static empty string, so empty views always have a valid pointer.
|
// A view of the empty string literal, so empty views always have a valid
|
||||||
inline KeyView emptyKeyView() {
|
// pointer. Unlike a function-local static, this needs no guard variable.
|
||||||
static const Key empty;
|
inline KeyView emptyKeyView() { return KeyView("", 0); }
|
||||||
return KeyView(empty);
|
|
||||||
}
|
|
||||||
inline OptKeyView bottomKeyView() { return OptKeyView{emptyKeyView()}; }
|
inline OptKeyView bottomKeyView() { return OptKeyView{emptyKeyView()}; }
|
||||||
|
|
||||||
inline bool isTop(OptKeyView k) { return !k.has_value(); }
|
inline bool isTop(OptKeyView k) { return !k.has_value(); }
|
||||||
@@ -270,15 +279,18 @@ inline OptKey afterLast(const Result& res) {
|
|||||||
return asKey(keyAfter(lastKey(res)));
|
return asKey(keyAfter(lastKey(res)));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline KeyView leastReported(const RangeRead& r, const Result& res) {
|
template <class R>
|
||||||
|
inline KeyView leastReported(const R& r, const Result& res) {
|
||||||
return r.reverse ? lastKey(res) : firstKey(res);
|
return r.reverse ? lastKey(res) : firstKey(res);
|
||||||
}
|
}
|
||||||
inline OptKeyView leastReportedOpt(const RangeRead& r, const Result& res) {
|
template <class R>
|
||||||
|
inline OptKeyView leastReportedOpt(const R& r, const Result& res) {
|
||||||
return asKey(leastReported(r, res));
|
return asKey(leastReported(r, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline RangeRead forwardRead(const RangeRead& r) {
|
template <class R>
|
||||||
RangeRead out = r;
|
inline R forwardRead(const R& r) {
|
||||||
|
R out = r;
|
||||||
out.reverse = false;
|
out.reverse = false;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -308,7 +320,8 @@ inline NatInf intervalCard(OptKeyView b, OptKeyView e) {
|
|||||||
// Result-based counters, in the exact form used by the statement
|
// Result-based counters, in the exact form used by the statement
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
inline std::uint64_t residualT(const RangeRead& r, const Result& res) {
|
template <class R>
|
||||||
|
inline std::uint64_t residualT(const R& r, const Result& res) {
|
||||||
if (isTop(r.end_.key)) return 0;
|
if (isTop(r.end_.key)) return 0;
|
||||||
std::uint64_t count = 0;
|
std::uint64_t count = 0;
|
||||||
for (KeyView k : res.keys)
|
for (KeyView k : res.keys)
|
||||||
@@ -316,7 +329,8 @@ inline std::uint64_t residualT(const RangeRead& r, const Result& res) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::uint64_t reportedBelowBegin(const RangeRead& r, const Result& res) {
|
template <class R>
|
||||||
|
inline std::uint64_t reportedBelowBegin(const R& r, const Result& res) {
|
||||||
if (isTop(r.begin.key)) return static_cast<std::uint64_t>(res.keys.size());
|
if (isTop(r.begin.key)) return static_cast<std::uint64_t>(res.keys.size());
|
||||||
std::uint64_t count = 0;
|
std::uint64_t count = 0;
|
||||||
for (KeyView k : res.keys)
|
for (KeyView k : res.keys)
|
||||||
@@ -324,17 +338,21 @@ inline std::uint64_t reportedBelowBegin(const RangeRead& r, const Result& res) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::uint64_t residualB(const RangeRead& r) {
|
template <class R>
|
||||||
return toNat(r.begin.offset - 1);
|
inline std::uint64_t residualB(const R& r) {
|
||||||
|
return toNat(static_cast<Int>(r.begin.offset) - 1);
|
||||||
}
|
}
|
||||||
inline std::uint64_t residualE(const RangeRead& r) {
|
template <class R>
|
||||||
return toNat(r.end_.offset - 1);
|
inline std::uint64_t residualE(const R& r) {
|
||||||
|
return toNat(static_cast<Int>(r.end_.offset) - 1);
|
||||||
}
|
}
|
||||||
inline std::uint64_t beginSlack(const RangeRead& r) {
|
template <class R>
|
||||||
return toNat(-r.begin.offset);
|
inline std::uint64_t beginSlack(const R& r) {
|
||||||
|
return toNat(-static_cast<Int>(r.begin.offset));
|
||||||
}
|
}
|
||||||
inline std::uint64_t clampNonposD(const RangeRead& r) {
|
template <class R>
|
||||||
return toNat(-r.end_.offset);
|
inline std::uint64_t clampNonposD(const R& r) {
|
||||||
|
return toNat(-static_cast<Int>(r.end_.offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cr
|
} // namespace cr
|
||||||
+4
-2
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// nanobench comparison of the literal translation and the summarised
|
// nanobench comparison of the literal translation and the summarised
|
||||||
// implementation on representative readable instances.
|
// implementation on representative readable instances.
|
||||||
#define ANKERL_NANOBENCH_IMPLEMENT
|
#define ANKERL_NANOBENCH_IMPLEMENT
|
||||||
@@ -47,8 +49,8 @@ std::vector<Key> makeDb(std::size_t n, std::size_t len) {
|
|||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
Case makeCase(const std::vector<Key>& db, OptKey beginKey, Int beginOff,
|
Case makeCase(const std::vector<Key>& db, OptKey beginKey, std::int32_t beginOff,
|
||||||
OptKey endKey, Int endOff, bool reverse, bool truncate,
|
OptKey endKey, std::int32_t endOff, bool reverse, bool truncate,
|
||||||
const char* name) {
|
const char* name) {
|
||||||
gen::Instance inst;
|
gen::Instance inst;
|
||||||
inst.beginKey = std::move(beginKey);
|
inst.beginKey = std::move(beginKey);
|
||||||
|
|||||||
Binary file not shown.
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// Compare the literal translation with the summarised implementation on the
|
// Compare the literal translation with the summarised implementation on the
|
||||||
// Lean-generated corpus (readable or not).
|
// Lean-generated corpus (readable or not).
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -102,8 +104,8 @@ int main(int argc, char** argv) {
|
|||||||
std::vector<KeyView> keyViews;
|
std::vector<KeyView> keyViews;
|
||||||
keyViews.reserve(keys.size());
|
keyViews.reserve(keys.size());
|
||||||
for (const Key& k : keys) keyViews.push_back(k);
|
for (const Key& k : keys) keyViews.push_back(k);
|
||||||
RangeRead r{Selector{optView(beginKey), static_cast<Int>(bo)},
|
RangeRead r{Selector{optView(beginKey), static_cast<std::int32_t>(bo)},
|
||||||
Selector{optView(endKey), static_cast<Int>(eo)}, reverse};
|
Selector{optView(endKey), static_cast<std::int32_t>(eo)}, reverse};
|
||||||
Result res{keyViews, more != 0};
|
Result res{keyViews, more != 0};
|
||||||
++cases;
|
++cases;
|
||||||
ConflictRange a = literal::closedForm(r, res);
|
ConflictRange a = literal::closedForm(r, res);
|
||||||
|
|||||||
+12
-9
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// Regression test for offsets at the extremes of the input domain. Offsets
|
// Regression test for offsets at the extremes of the input domain. Offsets
|
||||||
// supplied by callers are 32-bit; a positive `end.offset` near `INT32_MAX`
|
// supplied by callers are 32-bit; a positive `end.offset` near `INT32_MAX`
|
||||||
// would otherwise materialise about 2^31 zero bytes for Lean's
|
// would otherwise materialise about 2^31 zero bytes for Lean's
|
||||||
@@ -7,6 +9,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -31,18 +34,18 @@ int main() {
|
|||||||
owned.push_back(OptKey{Key("a")});
|
owned.push_back(OptKey{Key("a")});
|
||||||
owned.push_back(OptKey{Key("\xff\xff", 2)});
|
owned.push_back(OptKey{Key("\xff\xff", 2)});
|
||||||
|
|
||||||
// The public offset contract accepts exactly the 32-bit boundaries; the
|
// `Selector` stores offsets as `std::int32_t`, so `RangeRead` itself cannot
|
||||||
// entry-point assertions and corpus parsers share this predicate.
|
// violate the input contract. The corpus parsers still validate wider
|
||||||
const RangeRead boundary{Selector{std::nullopt, kMinInputOffset},
|
// parsed values with `offsetsFitInt32` before narrowing.
|
||||||
Selector{std::nullopt, kMaxInputOffset}, false};
|
static_assert(std::is_same_v<decltype(Selector::offset), std::int32_t>,
|
||||||
const RangeRead outside{Selector{std::nullopt, kMinInputOffset - 1},
|
"Selector::offset must match the 32-bit input contract");
|
||||||
Selector{std::nullopt, 0}, false};
|
if (!offsetsFitInt32(kMinInputOffset, kMaxInputOffset) ||
|
||||||
if (!inputOffsetsFitInt32(boundary) || inputOffsetsFitInt32(outside)) {
|
offsetsFitInt32(kMinInputOffset - 1, kMaxInputOffset + 1)) {
|
||||||
std::fprintf(stderr, "offset contract check failed\n");
|
std::fprintf(stderr, "offset contract check failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Int offs[] = {std::numeric_limits<std::int32_t>::min(),
|
const std::int32_t offs[] = {std::numeric_limits<std::int32_t>::min(),
|
||||||
std::numeric_limits<std::int32_t>::min() + 1,
|
std::numeric_limits<std::int32_t>::min() + 1,
|
||||||
-1000000000,
|
-1000000000,
|
||||||
-3,
|
-3,
|
||||||
@@ -57,7 +60,7 @@ int main() {
|
|||||||
std::vector<Selector> sels;
|
std::vector<Selector> sels;
|
||||||
sels.reserve(owned.size() * (sizeof(offs) / sizeof(offs[0])));
|
sels.reserve(owned.size() * (sizeof(offs) / sizeof(offs[0])));
|
||||||
for (const OptKey& k : owned)
|
for (const OptKey& k : owned)
|
||||||
for (Int off : offs) sels.push_back(Selector{optView(k), off});
|
for (std::int32_t off : offs) sels.push_back(Selector{optView(k), off});
|
||||||
|
|
||||||
long long cases = 0, bad = 0;
|
long long cases = 0, bad = 0;
|
||||||
for (const Selector& bs : sels)
|
for (const Selector& bs : sels)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// libFuzzer safety harness: arbitrary (not necessarily readable) instances.
|
// libFuzzer safety harness: arbitrary (not necessarily readable) instances.
|
||||||
// Equivalence is only promised on readable inputs, so this harness merely runs
|
// Equivalence is only promised on readable inputs, so this harness merely runs
|
||||||
// both implementations under ASan/UBSan to catch memory-safety or UB issues in
|
// both implementations under ASan/UBSan to catch memory-safety or UB issues in
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// libFuzzer differential harness: the literal translation versus the
|
// libFuzzer differential harness: the literal translation versus the
|
||||||
// summarised implementation, on readable-by-construction instances.
|
// summarised implementation, on readable-by-construction instances.
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// Validates the C++ literal translation against golden vectors produced by
|
// Validates the C++ literal translation against golden vectors produced by
|
||||||
// `cpp/oracle/gen.lean` (which calls the real `Statement.closedForm`).
|
// `cpp/oracle/gen.lean` (which calls the real `Statement.closedForm`).
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@@ -107,8 +109,8 @@ int main(int argc, char** argv) {
|
|||||||
std::vector<KeyView> keyViews;
|
std::vector<KeyView> keyViews;
|
||||||
keyViews.reserve(keys.size());
|
keyViews.reserve(keys.size());
|
||||||
for (const Key& k : keys) keyViews.push_back(k);
|
for (const Key& k : keys) keyViews.push_back(k);
|
||||||
RangeRead r{Selector{optView(beginKey), static_cast<Int>(bo)},
|
RangeRead r{Selector{optView(beginKey), static_cast<std::int32_t>(bo)},
|
||||||
Selector{optView(endKey), static_cast<Int>(eo)}, rev != 0};
|
Selector{optView(endKey), static_cast<std::int32_t>(eo)}, rev != 0};
|
||||||
Result res{keyViews, more != 0};
|
Result res{keyViews, more != 0};
|
||||||
OptKey wantBegin, wantEnd;
|
OptKey wantBegin, wantEnd;
|
||||||
if (!parseKey(ob, wantBegin) || !parseKey(oe, wantEnd)) {
|
if (!parseKey(ob, wantBegin) || !parseKey(oe, wantEnd)) {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
|
||||||
// Deterministic, readable-by-construction instance generation shared by the
|
// Deterministic, readable-by-construction instance generation shared by the
|
||||||
// differential fuzzer and the benchmarks.
|
// differential fuzzer and the benchmarks.
|
||||||
//
|
//
|
||||||
@@ -59,15 +61,15 @@ inline OptKey randomOptKey(Bytes& b, std::size_t maxLen) {
|
|||||||
return OptKey{randomKey(b, maxLen)};
|
return OptKey{randomKey(b, maxLen)};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Int randomOffset(Bytes& b) {
|
inline std::int32_t randomOffset(Bytes& b) {
|
||||||
// Bias towards the offsets that decide the interesting boundary cases, but
|
// Bias towards the offsets that decide the interesting boundary cases, but
|
||||||
// still allow the full [-256, 255] window.
|
// still allow the full [-256, 255] window.
|
||||||
std::uint8_t pick = b.u8();
|
std::uint8_t pick = b.u8();
|
||||||
if (pick < 192) {
|
if (pick < 192) {
|
||||||
static const Int small[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
|
static const std::int32_t small[] = {-3, -2, -1, 0, 1, 2, 3, 4, 5};
|
||||||
return small[pick % 9];
|
return small[pick % 9];
|
||||||
}
|
}
|
||||||
return static_cast<Int>(b.u16() % 512) - 256;
|
return static_cast<std::int32_t>(b.u16() % 512) - 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline OptKey resolve(const std::vector<Key>& db, const Selector& s) {
|
inline OptKey resolve(const std::vector<Key>& db, const Selector& s) {
|
||||||
@@ -75,7 +77,7 @@ inline OptKey resolve(const std::vector<Key>& db, const Selector& s) {
|
|||||||
if (!s.key) {
|
if (!s.key) {
|
||||||
anchor = static_cast<Int>(db.size()) + s.offset - 1;
|
anchor = static_cast<Int>(db.size()) + s.offset - 1;
|
||||||
} else if (s.key->empty()) {
|
} else if (s.key->empty()) {
|
||||||
anchor = s.offset - 1;
|
anchor = static_cast<Int>(s.offset) - 1;
|
||||||
} else {
|
} else {
|
||||||
std::size_t below = 0;
|
std::size_t below = 0;
|
||||||
for (const Key& k : db)
|
for (const Key& k : db)
|
||||||
@@ -108,8 +110,8 @@ struct Instance {
|
|||||||
// Owned selector keys; `read()` borrows them.
|
// Owned selector keys; `read()` borrows them.
|
||||||
OptKey beginKey;
|
OptKey beginKey;
|
||||||
OptKey endKey;
|
OptKey endKey;
|
||||||
Int beginOffset = 0;
|
std::int32_t beginOffset = 0;
|
||||||
Int endOffset = 0;
|
std::int32_t endOffset = 0;
|
||||||
bool reverse = false;
|
bool reverse = false;
|
||||||
bool more = false;
|
bool more = false;
|
||||||
|
|
||||||
|
|||||||
Loaded 100 of 103 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user