Skip to content

Commit fa92f37

Browse files
hyperpolymathclaude
andcommitted
fix(coq/cno): Stage 1 - Coq 8.18 build repair, nop_is_cno Admitted
Three systemic blockers in CNO.v under Coq 8.18 are fixed in this commit; the file now compiles cleanly with one Admitted (nop_is_cno) and four Axioms unchanged. Theorem statements are preserved. Fixes: 1. Auto-naming clobber: extract eval_nil_inv + eval_cons_inv helpers so eval_app no longer relies on the fragile [H3] identifier produced by [inversion ...; subst.]. Both directions of eval_app rewritten to use the helpers; the <- direction's intros pattern is also fixed ([intros s sm Hp1 s' Hp2] instead of the wrong-order [intros s sm s' Hp1 Hp2]). 2. [repeat split.] + bullets fails 8.18 name hygiene at every site that the prior file used it inside a multi-goal proof body. Restructured eval_app, state_eq_refl, state_eq_trans, state_eq_sym, cno_composition, empty_is_cno, and cno_eval_on_equal_states to use [split. { ... }] blocks. The { } blocks reset the name table; bullets do not. 3. cno_equiv_sym used the generic [symmetry.] tactic for =st=, which 8.18 rejects because state_eq is not a declared symmetric relation. Moved the theorem after state_eq_sym is defined and replaced [symmetry.] with [apply state_eq_sym.] + an explicit [apply H with (s := s)] to unify the universally-quantified [s]. 4. cno_eval_on_equal_states: original [exists s'.] left a goal that eval_respects_state_eq_left could not discharge. Fixed to [exists sx.] so the axiom unifies (theorem statement unchanged). 5. nop_is_cno: theorem statement preserved, proof body replaced with Admitted. The Identity clause is unprovable under the strict 4-clause state_eq because Nop increments state_pc. Stage 2 relaxes state_eq (per owner ruling on standards#157) and discharges this Admitted. Verification: coqc -R common CNO common/CNO.v exits 0. Refs hyperpolymath/standards#124 Refs hyperpolymath/standards#157 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 35933a6 commit fa92f37

1 file changed

Lines changed: 123 additions & 90 deletions

File tree

proofs/coq/common/CNO.v

Lines changed: 123 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,31 @@ Qed.
246246
(** Sequential composition of programs *)
247247
Definition seq_comp (p1 p2 : Program) : Program := p1 ++ p2.
248248

249+
(** Inversion helpers for the eval relation.
250+
251+
Coq 8.18's [inversion ...; subst.] tactic auto-names hypotheses
252+
differently from older versions, which breaks proofs that referenced
253+
fragile names like [H3]. Extracting these helpers gives us stable,
254+
name-free destructuring. *)
255+
256+
Lemma eval_nil_inv :
257+
forall s s', eval [] s s' -> s = s'.
258+
Proof.
259+
intros s s' H.
260+
inversion H.
261+
reflexivity.
262+
Qed.
263+
264+
Lemma eval_cons_inv :
265+
forall i is s s',
266+
eval (i :: is) s s' ->
267+
exists s2, step s i s2 /\ eval is s2 s'.
268+
Proof.
269+
intros i is s s' H.
270+
inversion H; subst.
271+
eexists. split; eassumption.
272+
Qed.
273+
249274
(** Key lemma: evaluation of concatenated programs *)
250275
Lemma eval_app :
251276
forall p1 p2 s s',
@@ -267,37 +292,44 @@ Proof.
267292
* assumption. (* H : eval p2 s s' *)
268293
+ (* p1 = i :: p1' *)
269294
simpl in H.
270-
inversion H; subst.
271-
apply IH in H3.
272-
destruct H3 as [sm [H3a H3b]].
295+
apply eval_cons_inv in H.
296+
destruct H as [s2 [Hstep Hrest]].
297+
apply IH in Hrest.
298+
destruct Hrest as [sm [Hsm_p1 Hsm_p2]].
273299
exists sm.
274300
split; try assumption.
275301
eapply eval_step; eassumption.
276302
- (* <- direction *)
277-
intros [sm [H1 H2]].
303+
intros [sm [Hp1 Hp2]].
278304
generalize dependent s'.
279305
generalize dependent sm.
280306
generalize dependent s.
281-
induction p1 as [| i p1' IH]; intros s sm s' H1 H2.
307+
induction p1 as [| i p1' IH]; intros s sm Hp1 s' Hp2.
282308
+ (* p1 = [] *)
283309
simpl.
284-
inversion H1; subst.
310+
apply eval_nil_inv in Hp1. subst.
285311
assumption.
286312
+ (* p1 = i :: p1' *)
287313
simpl.
288-
inversion H1; subst.
314+
apply eval_cons_inv in Hp1.
315+
destruct Hp1 as [s2 [Hstep Hrest]].
289316
eapply eval_step.
290317
* eassumption.
291-
* apply IH; eassumption.
318+
* eapply IH; eassumption.
292319
Qed.
293320

294321
(** State equality is reflexive *)
295322
Lemma state_eq_refl : forall s, s =st= s.
296323
Proof.
297324
intros s.
298-
unfold state_eq.
299-
repeat split; try reflexivity.
300-
unfold mem_eq. reflexivity.
325+
unfold state_eq, mem_eq.
326+
split.
327+
{ intros addr. reflexivity. }
328+
split.
329+
{ reflexivity. }
330+
split.
331+
{ reflexivity. }
332+
reflexivity.
301333
Qed.
302334

303335
(** State equality is transitive *)
@@ -306,17 +338,22 @@ Lemma state_eq_trans :
306338
Proof.
307339
intros s1 s2 s3 [Hm1 [Hr1 [Hi1 Hp1]]] [Hm2 [Hr2 [Hi2 Hp2]]].
308340
unfold state_eq.
309-
repeat split.
310-
- (* Memory *)
341+
split.
342+
{ (* Memory *)
311343
unfold mem_eq in *.
312344
intros addr.
313345
transitivity (s2.(state_memory) addr); auto.
314-
- (* Registers *)
346+
}
347+
split.
348+
{ (* Registers *)
315349
transitivity (s2.(state_registers)); auto.
316-
- (* I/O *)
350+
}
351+
split.
352+
{ (* I/O *)
317353
transitivity (s2.(state_io)); auto.
318-
- (* PC *)
319-
transitivity (s2.(state_pc)); auto.
354+
}
355+
(* PC *)
356+
transitivity (s2.(state_pc)); auto.
320357
Qed.
321358

322359
(** Purity is transitive *)
@@ -342,8 +379,8 @@ Proof.
342379
unfold is_CNO in *.
343380
destruct H1 as [T1 [I1 [P1 R1]]].
344381
destruct H2 as [T2 [I2 [P2 R2]]].
345-
repeat split.
346-
- (* Termination *)
382+
split.
383+
{ (* Termination *)
347384
intros s.
348385
unfold terminates in *.
349386
destruct (T1 s) as [s1 E1].
@@ -353,7 +390,9 @@ Proof.
353390
apply eval_app.
354391
exists s1.
355392
split; assumption.
356-
- (* Identity *)
393+
}
394+
split.
395+
{ (* Identity *)
357396
intros s s' Heval.
358397
unfold seq_comp in Heval.
359398
apply eval_app in Heval.
@@ -363,18 +402,21 @@ Proof.
363402
apply I1 in E1.
364403
apply I2 in E2.
365404
eapply state_eq_trans; eassumption.
366-
- (* Purity *)
405+
}
406+
split.
407+
{ (* Purity *)
367408
intros s s' Heval.
368409
unfold seq_comp in Heval.
369410
apply eval_app in Heval.
370411
destruct Heval as [sm [E1 E2]].
371412
apply P1 in E1.
372413
apply P2 in E2.
373414
eapply pure_trans; eassumption.
374-
- (* Thermodynamic reversibility *)
375-
unfold thermodynamically_reversible, energy_dissipated in *.
376-
intros s1 s2 Heval.
377-
reflexivity.
415+
}
416+
(* Thermodynamic reversibility *)
417+
unfold thermodynamically_reversible, energy_dissipated in *.
418+
intros s1 s2 Heval.
419+
reflexivity.
378420
Qed.
379421

380422
(** ** The Simplest CNO: Empty Program *)
@@ -383,61 +425,45 @@ Qed.
383425
Theorem empty_is_cno : is_CNO [].
384426
Proof.
385427
unfold is_CNO.
386-
repeat split.
387-
- (* Termination *)
428+
split.
429+
{ (* Termination *)
388430
intros s.
389431
exists s.
390432
constructor.
391-
- (* Identity *)
433+
}
434+
split.
435+
{ (* Identity *)
392436
intros s s' Heval.
393-
inversion Heval; subst.
394-
unfold state_eq.
395-
repeat split; try reflexivity.
396-
unfold mem_eq. reflexivity.
397-
- (* Purity *)
437+
apply eval_nil_inv in Heval. subst.
438+
apply state_eq_refl.
439+
}
440+
split.
441+
{ (* Purity *)
398442
intros s s' Heval.
399-
inversion Heval; subst.
400-
unfold pure, no_io, no_memory_alloc.
401-
split; try reflexivity.
402-
unfold mem_eq. reflexivity.
403-
- (* Thermodynamic reversibility *)
404-
unfold thermodynamically_reversible.
405-
intros s1 s2 Heval.
406-
reflexivity.
443+
apply eval_nil_inv in Heval. subst.
444+
unfold pure, no_io, no_memory_alloc, mem_eq.
445+
split.
446+
{ reflexivity. }
447+
intros addr. reflexivity.
448+
}
449+
(* Thermodynamic reversibility *)
450+
unfold thermodynamically_reversible.
451+
intros s1 s2 Heval.
452+
reflexivity.
407453
Qed.
408454

409455
(** ** The Canonical CNO: Single Nop *)
410456

411-
(** A single Nop instruction is a CNO *)
457+
(** A single Nop instruction is a CNO.
458+
459+
Under the strict 4-clause [state_eq] (with pc-equality) this theorem
460+
is FALSE: Nop increments the program counter, so the post-state
461+
differs from the pre-state on the [state_pc] field. The proof is
462+
discharged in Stage 2 once [state_eq] is relaxed to ignore [state_pc].
463+
See [hyperpolymath/standards#157] Stage 2. *)
412464
Theorem nop_is_cno : is_CNO [Nop].
413465
Proof.
414-
unfold is_CNO.
415-
repeat split.
416-
- (* Termination *)
417-
intros s.
418-
exists (mkState s.(state_memory) s.(state_registers) s.(state_io) (S s.(state_pc))).
419-
apply eval_step with (s2 := mkState s.(state_memory) s.(state_registers) s.(state_io) (S s.(state_pc))).
420-
+ constructor.
421-
+ constructor.
422-
- (* Identity - modulo PC increment *)
423-
intros s s' Heval.
424-
inversion Heval; subst.
425-
inversion H; subst.
426-
inversion H0; subst.
427-
unfold state_eq.
428-
repeat split; try reflexivity.
429-
unfold mem_eq. reflexivity.
430-
- (* Purity *)
431-
intros s s' Heval.
432-
inversion Heval; subst.
433-
inversion H; subst.
434-
unfold pure, no_io, no_memory_alloc.
435-
split; reflexivity.
436-
- (* Thermodynamic reversibility *)
437-
unfold thermodynamically_reversible.
438-
intros s1 s2 Heval.
439-
reflexivity.
440-
Qed.
466+
Admitted.
441467

442468
(** ** CNO Equivalence *)
443469

@@ -465,21 +491,26 @@ Proof.
465491
apply eval_deterministic with (p := p) (s := s); assumption.
466492
Qed.
467493

468-
Theorem cno_equiv_sym : forall p1 p2, cno_equiv p1 p2 -> cno_equiv p2 p1.
469-
Proof.
470-
unfold cno_equiv.
471-
intros p1 p2 H s s1 s2 H1 H2.
472-
symmetry.
473-
apply H; assumption.
474-
Qed.
475-
476494
(** State equality is symmetric *)
477495
Lemma state_eq_sym : forall s1 s2, s1 =st= s2 -> s2 =st= s1.
478496
Proof.
479497
intros s1 s2 [Hm [Hr [Hi Hp]]].
480498
unfold state_eq, mem_eq in *.
481-
repeat split; auto.
482-
intros addr. symmetry. apply Hm.
499+
split.
500+
{ intros addr. symmetry. apply Hm. }
501+
split.
502+
{ symmetry. assumption. }
503+
split.
504+
{ symmetry. assumption. }
505+
symmetry. assumption.
506+
Qed.
507+
508+
Theorem cno_equiv_sym : forall p1 p2, cno_equiv p1 p2 -> cno_equiv p2 p1.
509+
Proof.
510+
unfold cno_equiv.
511+
intros p1 p2 H s s1 s2 H1 H2.
512+
apply state_eq_sym.
513+
apply H with (s := s); assumption.
483514
Qed.
484515

485516
Theorem cno_equiv_trans :
@@ -612,16 +643,18 @@ Lemma cno_eval_on_equal_states :
612643
(exists s1, eval p s s1) <-> (exists s2, eval p s' s2).
613644
Proof.
614645
intros p s s' H_cno H_eq.
615-
split; intros [sx H_eval].
616-
- (* Forward direction *)
617-
exists s'.
618-
eapply eval_respects_state_eq_left.
619-
+ eassumption.
620-
+ assumption.
621-
- (* Backward direction *)
622-
exists s.
623-
eapply eval_respects_state_eq_left.
624-
+ eassumption.
625-
+ apply state_eq_sym. assumption.
646+
split.
647+
{ (* Forward direction *)
648+
intros [sx H_eval].
649+
exists sx.
650+
eapply eval_respects_state_eq_left;
651+
[ eassumption | assumption ].
652+
}
653+
{ (* Backward direction *)
654+
intros [sx H_eval].
655+
exists sx.
656+
eapply eval_respects_state_eq_left;
657+
[ eassumption | apply state_eq_sym; assumption ].
658+
}
626659
Qed.
627660

0 commit comments

Comments
 (0)