Skip to content

Commit 5685216

Browse files
hyperpolymathclaude
andcommitted
fix(coq/cno): Stage 2 - relax state_eq, discharge nop_is_cno Admitted
Per owner ruling on hyperpolymath/standards#157 Stage 2, [state_eq] is relaxed from four clauses to three: state_eq s1 s2 := mem_eq s1.mem s2.mem /\ s1.regs = s2.regs /\ s1.io = s2.io Dropping the pc-equality clause matches the intuition that "Nop does nothing": Nop only differs from the input state on the pc field, which state_eq now ignores. This is the canonical relaxation needed to make nop_is_cno provable. Changes to common/CNO.v: - state_eq definition: dropped 4th conjunct, added comment citing standards#157 Stage 2. - state_eq_refl, state_eq_trans, state_eq_sym: destructure pattern reduced from [Hm [Hr [Hi Hp]]] to [Hm [Hr Hi]], proof bodies trimmed by one [split] / one bullet each. - nop_is_cno: proof body replaced. Now uses eval_cons_inv + eval_nil_inv (from Stage 1) to invert evaluation, then inversion-on-step_nop, then discharges the 3-clause state_eq goal by reflexivity on each field. Downstream files updated to match the new 3-clause shape: - physics/StatMech_helpers.v: its local state_eq_sym / state_eq_trans copy the 4-clause destructure pattern from CNO.v. Updated to drop the pc clause + restructure with { } blocks for 8.18 hygiene. - malbolge/MalbolgeCore.v: malbolge_cno_implies_cno's [repeat split.] produced 4 bullets (incl. "PC"). Updated to 3 fields with { } blocks; the PC bullet is removed entirely. - category/CNOCategory.v: one destructure of state_eq's conjuncts updated from [H_mem [H_reg [H_io H_pc]]] to [H_mem [H_reg H_io]]. Note: the downstream files (StatMech_helpers, MalbolgeCore, CNOCategory) could not be verified locally from this worktree due to sandbox restrictions on the physics/, malbolge/, category/ subdirectories. CI must verify them. The CNO.v changes are verified: coqc -R common CNO common/CNO.v exits 0, 0 Admitted, 4 Axioms. Refs hyperpolymath/standards#124 Refs hyperpolymath/standards#157 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fa92f37 commit 5685216

4 files changed

Lines changed: 86 additions & 46 deletions

File tree

proofs/coq/category/CNOCategory.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Proof.
165165
+ (* Purity: follows from state equality *)
166166
intros s s' H_eval.
167167
assert (H_eq : s =st= s') by (apply H_id; assumption).
168-
destruct H_eq as [H_mem [H_reg [H_io H_pc]]].
168+
destruct H_eq as [H_mem [H_reg H_io]].
169169
unfold pure, no_io, no_memory_alloc.
170170
split; assumption.
171171
+ (* Thermodynamic reversibility: trivially true *)

proofs/coq/common/CNO.v

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ Record ProgramState : Type := mkState {
5959
state_pc : nat (* Program counter *)
6060
}.
6161

62-
(** State equality *)
62+
(** State equality.
63+
64+
[state_eq] ignores [state_pc] by design - programs are equivalent
65+
if they leave memory/registers/IO unchanged, even if they advance
66+
the program counter. This matches the intuition that "Nop does
67+
nothing" which is otherwise unprovable under strict pc-equality.
68+
Owner decision: see hyperpolymath/standards#157 Stage 2. *)
6369
Definition state_eq (s1 s2 : ProgramState) : Prop :=
6470
s1.(state_memory) =mem= s2.(state_memory) /\
6571
s1.(state_registers) = s2.(state_registers) /\
66-
s1.(state_io) = s2.(state_io) /\
67-
s1.(state_pc) = s2.(state_pc).
72+
s1.(state_io) = s2.(state_io).
6873

6974
Notation "s1 '=st=' s2" := (state_eq s1 s2) (at level 70).
7075

@@ -327,16 +332,14 @@ Proof.
327332
{ intros addr. reflexivity. }
328333
split.
329334
{ reflexivity. }
330-
split.
331-
{ reflexivity. }
332335
reflexivity.
333336
Qed.
334337

335338
(** State equality is transitive *)
336339
Lemma state_eq_trans :
337340
forall s1 s2 s3, s1 =st= s2 -> s2 =st= s3 -> s1 =st= s3.
338341
Proof.
339-
intros s1 s2 s3 [Hm1 [Hr1 [Hi1 Hp1]]] [Hm2 [Hr2 [Hi2 Hp2]]].
342+
intros s1 s2 s3 [Hm1 [Hr1 Hi1]] [Hm2 [Hr2 Hi2]].
340343
unfold state_eq.
341344
split.
342345
{ (* Memory *)
@@ -348,12 +351,8 @@ Proof.
348351
{ (* Registers *)
349352
transitivity (s2.(state_registers)); auto.
350353
}
351-
split.
352-
{ (* I/O *)
353-
transitivity (s2.(state_io)); auto.
354-
}
355-
(* PC *)
356-
transitivity (s2.(state_pc)); auto.
354+
(* I/O *)
355+
transitivity (s2.(state_io)); auto.
357356
Qed.
358357

359358
(** Purity is transitive *)
@@ -456,14 +455,56 @@ Qed.
456455

457456
(** A single Nop instruction is a CNO.
458457
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. *)
458+
Under the strict 4-clause [state_eq] this theorem was FALSE because
459+
Nop increments [state_pc]. With the relaxed 3-clause [state_eq]
460+
(memory + registers + IO, ignoring [state_pc]) Nop genuinely is a
461+
CNO: it only differs from the pre-state on the pc field, which
462+
[state_eq] now ignores. See hyperpolymath/standards#157 Stage 2. *)
464463
Theorem nop_is_cno : is_CNO [Nop].
465464
Proof.
466-
Admitted.
465+
unfold is_CNO.
466+
split.
467+
{ (* Termination *)
468+
intros s.
469+
exists (mkState s.(state_memory) s.(state_registers) s.(state_io) (S s.(state_pc))).
470+
apply eval_step with
471+
(s2 := mkState s.(state_memory) s.(state_registers) s.(state_io) (S s.(state_pc))).
472+
{ constructor. }
473+
constructor.
474+
}
475+
split.
476+
{ (* Identity *)
477+
intros s s' Heval.
478+
apply eval_cons_inv in Heval.
479+
destruct Heval as [s2 [Hstep Hrest]].
480+
apply eval_nil_inv in Hrest.
481+
subst.
482+
inversion Hstep; subst.
483+
unfold state_eq, mem_eq.
484+
split.
485+
{ intros addr. reflexivity. }
486+
split.
487+
{ reflexivity. }
488+
reflexivity.
489+
}
490+
split.
491+
{ (* Purity *)
492+
intros s s' Heval.
493+
apply eval_cons_inv in Heval.
494+
destruct Heval as [s2 [Hstep Hrest]].
495+
apply eval_nil_inv in Hrest.
496+
subst.
497+
inversion Hstep; subst.
498+
unfold pure, no_io, no_memory_alloc, mem_eq.
499+
split.
500+
{ reflexivity. }
501+
intros addr. reflexivity.
502+
}
503+
(* Thermodynamic reversibility *)
504+
unfold thermodynamically_reversible.
505+
intros s1 s2 Heval.
506+
reflexivity.
507+
Qed.
467508

468509
(** ** CNO Equivalence *)
469510

@@ -494,14 +535,12 @@ Qed.
494535
(** State equality is symmetric *)
495536
Lemma state_eq_sym : forall s1 s2, s1 =st= s2 -> s2 =st= s1.
496537
Proof.
497-
intros s1 s2 [Hm [Hr [Hi Hp]]].
538+
intros s1 s2 [Hm [Hr Hi]].
498539
unfold state_eq, mem_eq in *.
499540
split.
500541
{ intros addr. symmetry. apply Hm. }
501542
split.
502543
{ symmetry. assumption. }
503-
split.
504-
{ symmetry. assumption. }
505544
symmetry. assumption.
506545
Qed.
507546

proofs/coq/malbolge/MalbolgeCore.v

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,23 +286,21 @@ Proof.
286286
destruct HCNO as [HM [HA [HC [HD HIO]]]].
287287
unfold malbolge_to_state, state_eq.
288288
simpl.
289-
repeat split.
290-
- (* Memory *)
289+
split.
290+
{ (* Memory *)
291291
unfold mem_eq.
292292
intros addr.
293293
rewrite HM.
294294
reflexivity.
295-
- (* Registers *)
295+
}
296+
split.
297+
{ (* Registers *)
296298
simpl.
297299
rewrite HA, HC, HD.
298300
reflexivity.
299-
- (* I/O *)
300-
apply HIO.
301-
- (* PC *)
302-
simpl.
303-
(* C register is PC and is now preserved by strengthened CNO definition *)
304-
rewrite HC.
305-
reflexivity.
301+
}
302+
(* I/O - state_eq no longer has a PC clause per standards#157 Stage 2 *)
303+
apply HIO.
306304
Qed.
307305

308306
(** ** The "Absolute Zero" Program *)

proofs/coq/physics/StatMech_helpers.v

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,36 @@
1010

1111
Require Import CNO.
1212

13-
(** State equality is symmetric *)
13+
(** State equality is symmetric.
14+
15+
Note: [state_eq] is 3-clause (memory + registers + IO) since
16+
standards#157 Stage 2 dropped the pc-equality clause. *)
1417
Lemma state_eq_sym :
1518
forall s1 s2 : ProgramState,
1619
s1 =st= s2 -> s2 =st= s1.
1720
Proof.
18-
intros s1 s2 [H_mem [H_reg [H_io H_pc]]].
21+
intros s1 s2 [H_mem [H_reg H_io]].
1922
unfold state_eq.
20-
repeat split.
21-
- unfold mem_eq in *. intro addr. symmetry. apply H_mem.
22-
- symmetry. assumption.
23-
- symmetry. assumption.
24-
- symmetry. assumption.
23+
split.
24+
{ unfold mem_eq in *. intro addr. symmetry. apply H_mem. }
25+
split.
26+
{ symmetry. assumption. }
27+
symmetry. assumption.
2528
Qed.
2629

2730
(** State equality is transitive *)
2831
Lemma state_eq_trans :
2932
forall s1 s2 s3 : ProgramState,
3033
s1 =st= s2 -> s2 =st= s3 -> s1 =st= s3.
3134
Proof.
32-
intros s1 s2 s3 [H_mem12 [H_reg12 [H_io12 H_pc12]]] [H_mem23 [H_reg23 [H_io23 H_pc23]]].
35+
intros s1 s2 s3 [H_mem12 [H_reg12 H_io12]] [H_mem23 [H_reg23 H_io23]].
3336
unfold state_eq.
34-
repeat split.
35-
- unfold mem_eq in *. intro addr.
36-
transitivity (state_memory s2 addr); [apply H_mem12 | apply H_mem23].
37-
- transitivity (state_registers s2); assumption.
38-
- transitivity (state_io s2); assumption.
39-
- transitivity (state_pc s2); assumption.
37+
split.
38+
{ unfold mem_eq in *. intro addr.
39+
transitivity (state_memory s2 addr); [apply H_mem12 | apply H_mem23]. }
40+
split.
41+
{ transitivity (state_registers s2); assumption. }
42+
transitivity (state_io s2); assumption.
4043
Qed.
4144

4245
(** For CNOs, evaluation from any state leads back to that state *)

0 commit comments

Comments
 (0)