Polish release docs and add CI checks
- Correct stale references and headline-path wording in READMEs and Lean docstrings - Document build steps, comparator requirements, sweep scope, and coverage - Unify Apache headers across Lean and C++ sources - Add a bwrap-free axiom audit for the headline theorems - Add a Gitea workflow running lake build, the axiom audit, C++ tests, and coverage - Match LLVM coverage tool versions to the compiler and recreate stale build dirs
This commit is contained in:
1 parent
73e371fb40
commit
273ad72f0c
34 files changed
+431
-133
No files matched your search
@@ -0,0 +1,78 @@
|
|||||||
|
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: |
|
||||||
|
cpp/build/golden_test cpp/oracle/golden.txt
|
||||||
|
cpp/build/diff_corpus cpp/oracle/golden.txt
|
||||||
|
cpp/build/extreme_test
|
||||||
|
cpp/build/exhaustive_test
|
||||||
|
|
||||||
|
- name: Check C++ coverage
|
||||||
|
run: |
|
||||||
|
CXX="clang++-$(clang++ -dumpversion | cut -d. -f1)" \
|
||||||
|
./cpp/run-coverage.sh
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
import Statement
|
import Statement
|
||||||
import FormalConflictRange.SimpleClosedForm
|
import FormalConflictRange.SimpleClosedForm
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
import Statement
|
import Statement
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
|
|
||||||
|
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
|
||||||
@@ -16,18 +16,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 +61,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 +84,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 +100,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 +143,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 +160,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 +401,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 +531,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 +553,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 +602,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 +717,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 +1140,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 +1179,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 +1207,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 +1228,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 +1720,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 +1769,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 +2064,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 +2113,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 +2483,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 +2534,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 +2558,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 +2625,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 +3111,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 +4141,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 +4177,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 +4208,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,3 +1,8 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
import FormalConflictRange.CrossedGeneral
|
import FormalConflictRange.CrossedGeneral
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
@@ -2297,8 +2297,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,3 +1,8 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
import FormalConflictRange.NegCrossComplete
|
import FormalConflictRange.NegCrossComplete
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
@@ -20,8 +20,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.
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,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
|
||||||
|
|||||||
@@ -79,7 +79,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 +99,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 +484,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 +2724,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 +2923,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
|
||||||
|
|||||||
@@ -743,7 +743,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 +766,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 +782,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 +796,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 +810,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 +821,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 +1132,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 +1185,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 +1201,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. -/
|
||||||
|
|||||||
@@ -2132,7 +2132,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 +2233,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
|
||||||
|
|||||||
+6
-1
@@ -1,7 +1,12 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
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
|
||||||
|
|||||||
@@ -24,14 +24,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 +55,27 @@ 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 exhaustive 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`.
|
line and branch coverage 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,6 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
import Proof
|
import Proof
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/-
|
/-
|
||||||
Copyright (c) 2026 Andrew Noyes. All rights reserved.
|
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.
|
||||||
|
|
||||||
# Statement of minimality for a conflict range inference algorithm
|
# Statement of minimality for a conflict range inference algorithm
|
||||||
|
|||||||
+12
-7
@@ -90,18 +90,23 @@ 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:
|
`exhaustive_test` enumerates a specific finite class rather than sampling it:
|
||||||
every sorted database of up to four keys over a fixed universe of boundary
|
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, 5]`, 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/exhaustive_test
|
||||||
# exhaustive: 10562068 cases, 0 mismatches
|
# exhaustive: 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. The class is not all
|
||||||
|
readable inputs; the guarantee is that every instance in this family agrees. In
|
||||||
|
particular, branch coverage cannot exercise a predicate operand that the
|
||||||
|
implementation no longer contains: the coverage result below describes the code
|
||||||
|
as written, it is not a proof of equivalence with `literal.cpp`.
|
||||||
|
|
||||||
## Coverage
|
## Coverage
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/-
|
||||||
|
Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
Authors: FormalConflictRange contributors
|
||||||
|
-/
|
||||||
|
|
||||||
import Statement
|
import Statement
|
||||||
|
|
||||||
/-!
|
/-!
|
||||||
|
|||||||
+53
-2
@@ -8,14 +8,65 @@ 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 \
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// A summarised implementation of the same decision procedure as
|
// A summarised implementation of the same decision procedure as
|
||||||
// `Statement.closedForm`.
|
// `Statement.closedForm`.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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>
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// A deterministic exhaustive sweep of small readable instances, comparing the
|
// A deterministic exhaustive sweep of small readable instances, comparing the
|
||||||
// literal translation with the summarised implementation.
|
// literal translation with the summarised implementation.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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>
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
// Copyright (c) 2026 FormalConflictRange contributors. All rights reserved.
|
||||||
|
// Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
|
// Authors: FormalConflictRange contributors
|
||||||
|
|
||||||
// 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.
|
||||||
//
|
//
|
||||||
|
|||||||
Executable
+21
@@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Verify that the headline theorems depend only on the permitted axioms.
|
||||||
|
# This is a bwrap-free complement to `lake comparator`: it catches `sorry`
|
||||||
|
# (`sorryAx`) and any newly introduced axiom.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
cd "$here/.."
|
||||||
|
|
||||||
|
output="$(lake env lean CheckAxioms.lean)"
|
||||||
|
printf '%s\n' "$output"
|
||||||
|
|
||||||
|
expected="[propext, Classical.choice, Quot.sound]"
|
||||||
|
matches="$(printf '%s\n' "$output" |
|
||||||
|
grep -c "depends on axioms: \[propext, Classical.choice, Quot.sound\]$" || true)"
|
||||||
|
|
||||||
|
if [[ "$matches" -ne 2 ]]; then
|
||||||
|
echo "expected both headline theorems to depend on exactly $expected" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "axiom audit: both headlines use exactly $expected"
|
||||||
Reference in new issue
Block a user