Skip to content

Commit 5741ee3

Browse files
proof(L3.K): rewrite Echo.v K-free — eliminate eq_rect_eq dependency (#173)
## Summary Discharges the K proof-debt documented in `formal/Echo.v`'s top-of-file comment (introduced in PR #166, tracked in `docs/proof-debt.adoc` via #169). Rewrites two definitions/lemmas that previously pulled in Coq's `Eqdep.Eq_rect_eq.eq_rect_eq` (K / UIP) axiom via `dependent destruction`, using the K-free motive-trick template established in `formal/Modality.v` (#168). ## Changes 1. **New helper** `mode_le_affine_first : mode_le Affine m2 -> m2 = Affine` — raw dependent match with sort-indexed motive. Mirrors `Modality.v`'s `modality_le_affine_first`. 2. **`mode_le_trans` rewritten as a `Definition`** (not tactic-derived) using the same shape as `Modality.v`'s `modality_le_trans`: pattern match on `H12`; the `Linear_le_Affine` case uses `mode_le_affine_first` + `eq_rect` to transport the result through `m3 = Affine`. 3. **`degrade_mode_comp` no longer uses `dependent destruction`**. In each non-trivial case: ```coq pose proof (mode_le_affine_first m3 p23) as Heq. generalize dependent p23. rewrite Heq. intros p23. rewrite (mode_le_prop _ _ p23 Affine_le_Affine). reflexivity. ``` This canonicalises `m3` to `Affine` via `mode_le_affine_first`, then collapses `p23` to the unique `Affine_le_Affine` constructor via `mode_le_prop` (already K-free from #166). 4. Top-of-file comment changed from "Proof-debt note (axiom dependencies)" to "K-freedom" documentation. 5. `Coq.Program.Equality` import removed. ## Verification `Print Assumptions` on every previously-K-using or K-inheriting lemma: | Lemma | Status | |---|---| | `mode_le_trans` | Closed under the global context | | `degrade_mode_comp` | Closed under the global context | | `degrade_mode_compose` | Closed under the global context | | `degrade_mode_via_join` | Closed under the global context | | `no_section_collapse_to_residue` | Closed under the global context | | `mode_le_prop` | Closed under the global context | The entire `formal/` project (9 .v files) builds clean with zero admits and zero axiom dependencies beyond the documented L1 admits in `Semantics_L1.v`. ## Why this matters Aligns Echo.v with: - The Agda upstream's `--safe --without-K` discipline (`echo-types/proofs/agda/EchoLinear.agda`). - The rest of the Ephapax Coq codebase (per `Print Assumptions` on `value_R_G_preserving_l1`, `subst_preserves_typing_l1`, `weaken_modality`, etc. — all K-free). Closes the L3.K proof-debt item. ## Branch base Stacked off `proof/l1-region-threading-design` (head `30ce697`, post-#172). Will rebase to `main` when #153 lands. ## Test plan - [x] `coqc 8.18.0` builds `Echo.v` cleanly, 0 admits - [x] Clean full-project rebuild passes — 9 .v files - [x] `Print Assumptions` confirms K elimination - [x] No semantic changes — same lemmas, K-free proofs only - [ ] CI green - [ ] Review: K-free template matches `Modality.v`; proof-debt closure note in commit can also be added to `docs/proof-debt.adoc` as a follow-up doc tweak Refs PR #166, PR #168, PR #169. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 30ce697 commit 5741ee3

1 file changed

Lines changed: 65 additions & 31 deletions

File tree

formal/Echo.v

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,23 @@
6161
satisfies all three constraints. This file does not introduce
6262
contradictions with them. *)
6363

64-
(** ** Proof-debt note (axiom dependencies)
65-
66-
Two lemmas in this file ([mode_le_trans] and [degrade_mode_comp])
67-
use [dependent destruction] from [Coq.Program.Equality] to
68-
discriminate impossible cases on the indexed inductive
69-
[mode_le]. This pulls in Coq's standard [eq_rect_eq] (K / UIP)
70-
axiom.
71-
72-
The Agda upstream ([EchoLinear.agda]) is [--safe --without-K]
73-
and discharges these cases without K. The rest of the Ephapax
74-
Coq codebase (per [Print Assumptions] on [value_R_G_preserving_l1],
75-
[subst_preserves_typing_l1]) is also K-free.
76-
77-
A follow-up slice should rewrite [mode_le_trans] and
78-
[degrade_mode_comp] using raw dependent pattern matching with
79-
motive tricks to be K-free, aligning with the Agda upstream and
80-
the rest of the Coq codebase. Tracked as L3.K proof-debt. *)
64+
(** ** K-freedom
65+
66+
Every Qed/Definition in this file is closed under the global
67+
context — zero axioms, zero K, zero UIP. The earlier L3 Phase 1
68+
version (PR #166) used [dependent destruction] for
69+
[mode_le_trans] + [degrade_mode_comp], pulling in
70+
[Eqdep.Eq_rect_eq.eq_rect_eq] (K / UIP). This file's discharge of
71+
that proof-debt mirrors the K-free template established in
72+
[Modality.v]'s [modality_le_trans]: a raw dependent match with a
73+
"motive trick" that returns [True] for impossible constructor /
74+
index combinations and the genuine target type for the reachable
75+
cases.
76+
77+
Aligns with the Agda upstream's [--safe --without-K] discipline
78+
and with the rest of the Ephapax Coq codebase. *)
8179

8280
Require Import Coq.Bool.Bool.
83-
Require Import Coq.Program.Equality.
8481

8582
(** ===== Modes =====
8683
@@ -110,20 +107,45 @@ Inductive mode_le : Mode -> Mode -> Type :=
110107
Lemma mode_le_refl : forall m, mode_le m m.
111108
Proof. intros [|]; constructor. Qed.
112109

110+
(** Helper: when the first mode is [Affine], the second mode is also
111+
[Affine] (the only [mode_le] constructor whose first index is
112+
[Affine] is [Affine_le_Affine]). K-free via a motive trick on
113+
the constructor's sort indices.
114+
115+
Mirrors [Modality.v]'s [modality_le_affine_first]. *)
116+
117+
Definition mode_le_affine_first
118+
(m2 : Mode) (H : mode_le Affine m2) : m2 = Affine :=
119+
match H in mode_le mA mB
120+
return
121+
(match mA return Prop with
122+
| Affine => mB = Affine
123+
| Linear => True
124+
end)
125+
with
126+
| Linear_le_Linear => I
127+
| Linear_le_Affine => I
128+
| Affine_le_Affine => eq_refl
129+
end.
130+
113131
(** [Defined] (not [Qed]) so [mode_le_trans] is transparent and
114-
[degrade_mode_comp] can [simpl] through its applications. Uses
115-
[dependent destruction] (K-dependent) — see the proof-debt note
116-
at the top of the file. *)
132+
[degrade_mode_comp] can [simpl] through its applications. Built
133+
by raw dependent pattern matching; K-free.
134+
135+
Mirrors [Modality.v]'s [modality_le_trans]. *)
117136

118137
Definition mode_le_trans
119138
(m1 m2 m3 : Mode)
120-
(H12 : mode_le m1 m2) (H23 : mode_le m2 m3) : mode_le m1 m3.
121-
Proof.
122-
destruct H12.
123-
- exact H23.
124-
- dependent destruction H23. exact Linear_le_Affine.
125-
- exact H23.
126-
Defined.
139+
(H12 : mode_le m1 m2) : mode_le m2 m3 -> mode_le m1 m3 :=
140+
match H12 in mode_le mA mB return mode_le mB m3 -> mode_le mA m3 with
141+
| Linear_le_Linear => fun h => h
142+
| Linear_le_Affine =>
143+
fun h =>
144+
eq_rect Affine (fun m => mode_le Linear m)
145+
Linear_le_Affine m3
146+
(eq_sym (mode_le_affine_first m3 h))
147+
| Affine_le_Affine => fun h => h
148+
end.
127149

128150
(** Propositionality of the mode order. Each pair [(m1, m2)] has at
129151
most one inhabitant in [mode_le]. This is what lets us collapse
@@ -303,9 +325,21 @@ Lemma degrade_mode_comp :
303325
Proof.
304326
intros m1 m2 m3 p12 p23 e.
305327
destruct p12.
306-
- reflexivity.
307-
- dependent destruction p23. reflexivity.
308-
- dependent destruction p23. reflexivity.
328+
- (* p12 = Linear_le_Linear: both sides reduce to [degrade_mode p23 e]. *)
329+
reflexivity.
330+
- (* p12 = Linear_le_Affine, p23 : mode_le Affine m3.
331+
Canonicalise m3 via [mode_le_affine_first], then collapse the two
332+
possible derivations of [mode_le Affine Affine] using
333+
[mode_le_prop]. K-free. *)
334+
pose proof (mode_le_affine_first m3 p23) as Heq.
335+
generalize dependent p23. rewrite Heq. intros p23.
336+
rewrite (mode_le_prop _ _ p23 Affine_le_Affine).
337+
reflexivity.
338+
- (* p12 = Affine_le_Affine, p23 : mode_le Affine m3. Same shape. *)
339+
pose proof (mode_le_affine_first m3 p23) as Heq.
340+
generalize dependent p23. rewrite Heq. intros p23.
341+
rewrite (mode_le_prop _ _ p23 Affine_le_Affine).
342+
reflexivity.
309343
Qed.
310344

311345
(** Free-factoring composition law: any direct ordering proof

0 commit comments

Comments
 (0)