Skip to content

Commit c01f0fa

Browse files
proof(L3.K): rewrite Echo.v K-free — eliminate eq_rect_eq dependency (#180)
## Summary Main's `Echo.v` (landed via #176's bundling) still uses `dependent destruction` (K-using) for `mode_le_trans` and `degrade_mode_comp`. This brings the K-free version that was filed against the design branch in PR #173 but never reached main (because #176 superseded #153). The diff is identical to PR #173: replace `dependent destruction` with the motive-trick K-free template from `Modality.v`. ## Changes 1. New helper `mode_le_affine_first : mode_le Affine m2 -> m2 = Affine` (motive-trick raw match). 2. `mode_le_trans` rewritten as a `Definition` using `mode_le_affine_first` + `eq_rect`. 3. `degrade_mode_comp` rewritten to canonicalise via `mode_le_affine_first` + `mode_le_prop` (avoiding `dependent destruction`). 4. Top-of-file comment changed from "Proof-debt note (axiom dependencies)" to "K-freedom". 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 | Full `formal/` project (9 .v files including the m-indexed `TypingL1.v` from #176) builds clean. ## Test plan - [x] `coqc 8.18.0` builds `Echo.v` cleanly - [x] Clean full-project rebuild passes — 9 .v files - [x] `Print Assumptions` confirms K elimination - [ ] CI green Refs PR #173 (design-branch original), PR #176 (m-indexed has_type_l1 + Modality.v + L2 hybrid). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 22e5a3e commit c01f0fa

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)