@@ -21,7 +21,7 @@ Require Import Coq.Logic.ProofIrrelevance.
2121Require Import Coq.Program .Equality .
2222Require Import Coq.Lists.List.
2323Import ListNotations.
24- Require Import CNO.
24+ Require Import CNO.CNO.
2525
2626(** ** Category Definition *)
2727
@@ -99,18 +99,19 @@ Proof.
9999Qed .
100100
101101(** Programs form a category *)
102- Instance ProgramCategory : Category := {
103- Obj := ProgramState;
104- Hom := ProgramMorphism;
105- compose := @compose_morphisms;
106- id := id_morphism;
107- }.
102+ Instance ProgramCategory : Category.
108103Proof .
104+ refine {|
105+ Obj := ProgramState;
106+ Hom := ProgramMorphism;
107+ compose := @compose_morphisms;
108+ id := id_morphism
109+ |}.
109110 - (* compose_assoc: (f ++ g) ++ h = f ++ (g ++ h) *)
110111 intros A B C D h g f.
111112 apply morph_eq_ext.
112113 destruct f as [pf Hf], g as [pg Hg], h as [ph Hh].
113- simpl. apply app_assoc.
114+ simpl. symmetry. apply app_assoc.
114115 - (* compose_id_left: p ++ [] = p *)
115116 intros A B f.
116117 apply morph_eq_ext.
@@ -157,20 +158,22 @@ Proof.
157158 - (* <- direction: Construct full CNO from termination + identity *)
158159 destruct H as [H_term H_id].
159160 unfold is_CNO.
160- repeat split.
161+ split.
161162 + (* Termination *)
162163 exact H_term.
163- + (* Identity *)
164- exact H_id.
165- + (* Purity: follows from state equality *)
166- intros s s' H_eval.
167- assert (H_eq : s =st= s') by (apply H_id; assumption).
168- destruct H_eq as [H_mem [H_reg [H_io H_pc]]].
169- unfold pure, no_io, no_memory_alloc.
170- split; assumption.
171- + (* Thermodynamic reversibility: trivially true *)
172- unfold thermodynamically_reversible, energy_dissipated.
173- intros. reflexivity.
164+ + split.
165+ * (* Identity *)
166+ exact H_id.
167+ * split.
168+ -- (* Purity: follows from state equality *)
169+ intros s s' H_eval.
170+ assert (H_eq : s =st= s') by (apply H_id; assumption).
171+ destruct H_eq as [H_mem [H_reg H_io]].
172+ unfold pure, no_io, no_memory_alloc.
173+ split; assumption.
174+ -- (* Thermodynamic reversibility: trivially true *)
175+ unfold thermodynamically_reversible, energy_dissipated.
176+ intros. reflexivity.
174177Qed .
175178
176179(** ** Universal Property *)
@@ -200,12 +203,13 @@ Qed.
200203
201204(** A functor maps between categories, preserving structure *)
202205Class Functor (C D : Category) := {
203- fobj : Obj -> Obj;
204- fmap : forall {A B : Obj}, Hom A B -> Hom (fobj A) (fobj B);
206+ fobj : @ Obj C -> @ Obj D ;
207+ fmap : forall {A B : @ Obj C }, @ Hom C A B -> @ Hom D (fobj A) (fobj B);
205208
206- fmap_id : forall {A : Obj}, fmap (@id C A) = @id D (fobj A);
207- fmap_compose : forall {A B C : Obj} (g : Hom B C) (f : Hom A B),
208- fmap (g ∘ f) = fmap g ∘ fmap f;
209+ fmap_id : forall {A : @Obj C}, fmap (@id C A) = @id D (fobj A);
210+ fmap_compose : forall {A B E : @Obj C} (g : @Hom C B E) (f : @Hom C A B),
211+ fmap (@compose C A B E g f) =
212+ @compose D (fobj A) (fobj B) (fobj E) (fmap g) (fmap f);
209213}.
210214
211215(** CNOs are preserved by functors *)
@@ -228,17 +232,19 @@ Qed.
228232(** A natural transformation between functors *)
229233Class NaturalTransformation (C D : Category)
230234 (F G : Functor C D) := {
231- component : forall (A : @Obj C), @Hom D (fobj A) (fobj A);
235+ component : forall (A : @Obj C), @Hom D (@ fobj C D F A) (@ fobj C D G A);
232236
233237 naturality : forall (A B : @Obj C) (f : @Hom C A B),
234- component B ∘ fmap f = fmap f ∘ component A;
238+ @compose D _ _ _ (component B) (@fmap C D F A B f) =
239+ @compose D _ _ _ (@fmap C D G A B f) (component A);
235240}.
236241
237242(** Identity natural transformation *)
238243Definition id_nat_trans (C D : Category) (F : Functor C D) :
239244 NaturalTransformation C D F F.
240245Proof .
241- apply Build_NaturalTransformation with (component := fun A => id).
246+ apply Build_NaturalTransformation with
247+ (component := fun A => @id D (@fobj C D F A)).
242248 - intros A B f.
243249 rewrite compose_id_left.
244250 rewrite compose_id_right.
@@ -247,11 +253,11 @@ Defined.
247253
248254(** CNOs as natural transformations *)
249255Theorem cno_as_nat_trans :
250- forall (C : Category) (F : Functor C C),
251- (forall A : @Obj C, @id C A = component A) ->
256+ forall (C : Category) (F : Functor C C) (η : NaturalTransformation C C F F) ,
257+ (forall A : @Obj C, @id C (@fobj C C F A) = @ component C C F F η A) ->
252258 F = F. (* Identity functor *)
253259Proof .
254- intros C F H.
260+ intros C F η H.
255261 (* CNOs correspond to identity natural transformations *)
256262 reflexivity.
257263Qed .
@@ -265,19 +271,20 @@ Definition CNO_equivalent (C D : Category) : Prop :=
265271 exists (F : Functor C D) (G : Functor D C),
266272 forall (s : @Obj C) (m : @Hom C s s),
267273 is_CNO_categorical m <->
268- is_CNO_categorical (fmap ( fmap m)).
274+ is_CNO_categorical (@ fmap D C G _ _ (@ fmap C D F _ _ m)).
269275
270276(** Main Universal Theorem: CNO property is model-independent *)
271277Theorem cno_model_independent :
272278 forall (C D : Category),
273279 CNO_equivalent C D ->
274280 forall (s : @Obj C) (m : @Hom C s s),
275281 is_CNO_categorical m ->
276- exists (m ' : @Hom D (fobj s) (fobj s) ),
282+ exists (s ' : @Obj D) (m' : @Hom D s' s' ),
277283 is_CNO_categorical m'.
278284Proof .
279285 intros C D [F [G H_equiv]] s m H_cno.
280- exists (fmap m).
286+ exists (@fobj C D F s).
287+ exists (@fmap C D F _ _ m).
281288 apply functor_preserves_cno.
282289 assumption.
283290Qed .
@@ -332,10 +339,10 @@ Proof.
332339 apply compose_id_left.
333340 - (* Right identity for all morphisms implies CNO *)
334341 (* Take f = id, then m ∘ id = id *)
342+ unfold is_CNO_categorical.
335343 specialize (H A id).
336344 rewrite compose_id_right in H.
337- symmetry.
338- assumption.
345+ exact H.
339346Qed .
340347
341348(** ** Summary *)
0 commit comments