Skip to content

Commit a291baf

Browse files
committed
green
1 parent 1db7ef6 commit a291baf

File tree

2 files changed

+76
-104
lines changed

2 files changed

+76
-104
lines changed

coq/indind.v

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ From Coq Require Import Lia.
44
(*** Inductive Equality *)
55
Module IndEquality.
66

7-
Inductive eq X (x: X) | : X -> Prop :=
8-
| Q : eq x.
7+
Inductive eq X (x: X) : X -> Prop :=
8+
| Q : eq X x x.
99

1010
Check eq.
1111
Check Q.
1212

13+
14+
Definition E
15+
: forall X (x: X) (p: X -> Type), p x -> forall y, eq X x y -> p y
16+
:= fun X x p a _ e =>
17+
match e with
18+
| Q _ _ => a
19+
end.
20+
21+
1322
Definition R
1423
: forall X (x y: X) (p: X -> Type), eq X x y -> p x -> p y
1524
:= fun X x _ p e => match e with
@@ -24,18 +33,18 @@ Section Star.
2433
Variable X : Type.
2534
Implicit Type R: X -> X -> Prop.
2635

27-
Inductive star R | (x : X) : X -> Prop :=
28-
| Nil : star x x
29-
| Cons y z : R x y -> star y z -> star x z.
36+
Inductive star (R: X -> X -> Prop) (x: X) : X -> Prop :=
37+
| Nil : star R x x
38+
| Cons y z : R x y -> star R y z -> star R x z.
3039

3140
Definition elim R (p: X -> X -> Prop)
3241
: (forall x, p x x) ->
3342
(forall x y z, R x y -> p y z -> p x z) ->
3443
forall x y, star R x y -> p x y
35-
:= fun e1 e2 => fix f x _ a :=
44+
:= fun f1 f2 => fix f x _ a :=
3645
match a with
37-
| Nil _ _ => e1 x
38-
| Cons _ _ x' z r a => e2 x x' z r (f x' z a)
46+
| Nil _ _ => f1 x
47+
| Cons _ _ x' z r a => f2 x x' z r (f x' z a)
3948
end.
4049

4150
Implicit Type p: X -> X -> Prop.
@@ -69,7 +78,7 @@ Section Star.
6978
Proof.
7079
induction 1 as [|x x' y r _ IH].
7180
- easy.
72-
- intros H%IH. revert r H. apply Cons.
81+
- intros H%IH. econstructor. exact r. exact H.
7382
Qed.
7483

7584
Fact least R p :
@@ -119,9 +128,9 @@ End Star.
119128
(*** Inductive Comparisons *)
120129

121130
Module LE.
122-
Inductive le (x: nat) | : nat -> Prop :=
123-
| leE : le x
124-
| leS y : le y -> le (S y).
131+
Inductive le (x: nat) : nat -> Prop :=
132+
| leE : le x x
133+
| leS y : le x y -> le x (S y).
125134

126135
Definition elim (x: nat) (p: nat -> Prop)
127136
: p x ->

coq/more.v

Lines changed: 55 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ Notation "'Sigma' x .. y , p" :=
1717
format "'[' 'Sigma' '/ ' x .. y , '/ ' p ']'")
1818
: type_scope.
1919

20+
Fact skolem_trans {X Y} (p: X -> Y -> Prop) :
21+
(forall x, Sigma y, p x y) -> Sigma f, forall x, p x (f x).
22+
Proof.
23+
intros F.
24+
exists (fun x => pi1 (F x)). intros x. exact (pi2 (F x)).
25+
Qed.
26+
2027
(*** Injections and Bijections *)
2128

2229

@@ -256,39 +263,6 @@ Proof.
256263
- right. congruence.
257264
Qed.
258265

259-
Fact R {X Y f g} :
260-
@inv (option X) (option Y) g f ->
261-
forall x, Sigma z, match f (Some x) with Some y => z = y | None => Some z = f None end.
262-
Proof.
263-
intros H x.
264-
destruct (f (Some x)) as [y|] eqn:E1.
265-
- exists y. reflexivity.
266-
- destruct (f None) as [y|] eqn:E2.
267-
+ exists y. reflexivity.
268-
+ exfalso. congruence.
269-
Qed.
270-
271-
Fact R_inv {X Y f g} :
272-
forall (H1: @inv (option X) (option Y) g f)
273-
(H2: inv f g),
274-
inv (fun y => pi1 (R H2 y)) (fun x => pi1 (R H1 x)).
275-
Proof.
276-
intros H1 H2 x.
277-
destruct (R H1 x) as [y H3]; cbn.
278-
destruct (R H2 y) as [x' H4]; cbn.
279-
revert H3 H4.
280-
destruct (f (Some x)) as [y1|] eqn:E.
281-
- intros <-. rewrite <-E, H1. easy.
282-
- intros ->. rewrite H1. rewrite <-E, H1. congruence.
283-
Qed.
284-
285-
Theorem bijection_option X Y :
286-
bijection (option X) (option Y) -> bijection X Y.
287-
Proof.
288-
intros [f g H1 H2].
289-
exists (fun y => pi1 (R H1 y)) (fun x => pi1 (R H2 x)); apply R_inv.
290-
Qed.
291-
292266
Goal forall X Y, bijection X Y -> bijection (option X) (option Y).
293267
Proof.
294268
intros X Y [f g H1 H2].
@@ -298,70 +272,59 @@ Proof.
298272
- hnf. intros [y|]; congruence.
299273
Qed.
300274

301-
Fact skolem_trans {X Y} (p: X -> Y -> Prop) :
302-
(forall x, Sigma y, p x y) -> Sigma f, forall x, p x (f x).
275+
Definition lower' X Y (f: option X -> option Y) x z :=
276+
match f (Some x) with
277+
| Some y => z = y
278+
| None => match f None with
279+
| Some y => z = y
280+
| None => False
281+
end
282+
end.
283+
284+
Definition lower X Y (f: option X -> option Y) f' :=
285+
forall x, lower' X Y f x (f' x).
286+
287+
Fact lower_sig {X Y} f :
288+
injective f -> sig (lower X Y f).
303289
Proof.
304-
intros F.
305-
exists (fun x => pi1 (F x)). intros x. exact (pi2 (F x)).
290+
intros H.
291+
apply skolem_trans.
292+
intros x. unfold lower'.
293+
destruct (f (Some x)) as [y|] eqn:E1.
294+
- eauto.
295+
- destruct (f None) as [y|] eqn:E2.
296+
+ eauto.
297+
+ enough (Some x = None) by easy.
298+
apply H. congruence.
306299
Qed.
307-
308-
Module Version2024.
309300

310-
Definition lower' X Y (f: option X -> option Y) x z :=
311-
match f (Some x) with
312-
| Some y => z = y
313-
| None => match f None with
314-
| Some y => z = y
315-
| None => False
316-
end
317-
end.
318-
319-
Definition lower X Y (f: option X -> option Y) f' :=
320-
forall x, lower' X Y f x (f' x).
301+
Fact lem_lower X Y f g f' g' :
302+
inv g f -> inv f g ->
303+
lower X Y f f' -> lower Y X g g' -> inv g' f'.
304+
Proof.
305+
intros H1 H2 H3 H4 x.
306+
specialize (H3 x). unfold lower' in H3.
307+
destruct (f (Some x)) as [y|] eqn:E1.
308+
- specialize (H4 y). unfold lower' in H4.
309+
destruct (g (Some y)) as [x'|] eqn:E2; congruence.
310+
- destruct (f None) as [y|] eqn:E2. 2:easy.
311+
specialize (H4 y). unfold lower' in H4.
312+
assert (E3: g (Some y) = None) by congruence.
313+
rewrite E3 in H4.
314+
destruct (g None) as [x'|] eqn:E4; congruence.
315+
Qed.
321316

322-
323-
Fact lower_sig {X Y} f :
324-
injective f -> sig (lower X Y f).
325-
Proof.
326-
intros H.
327-
apply skolem_trans.
328-
intros x. unfold lower'.
329-
destruct (f (Some x)) as [y|] eqn:E1.
330-
- eauto.
331-
- destruct (f None) as [y|] eqn:E2.
332-
+ eauto.
333-
+ enough (Some x = None) by easy.
334-
apply H. congruence.
335-
Qed.
336-
337-
Fact lem_lower X Y f g f' g' :
338-
inv g f -> inv f g ->
339-
lower X Y f f' -> lower Y X g g' -> inv g' f'.
340-
Proof.
341-
intros H1 H2 H3 H4 x.
342-
specialize (H3 x). unfold lower' in H3.
343-
destruct (f (Some x)) as [y|] eqn:E1.
344-
- specialize (H4 y). unfold lower' in H4.
345-
destruct (g (Some y)) as [x'|] eqn:E2; congruence.
346-
- destruct (f None) as [y|] eqn:E2. 2:easy.
347-
specialize (H4 y). unfold lower' in H4.
348-
assert (E3: g (Some y) = None) by congruence.
349-
rewrite E3 in H4.
350-
destruct (g None) as [x'|] eqn:E4; congruence.
351-
Qed.
317+
Theorem bijection_option X Y :
318+
bijection (option X) (option Y) -> bijection X Y.
319+
Proof.
320+
intros [f g H1 H2].
321+
destruct (lower_sig f) as [f' H3].
322+
{ eapply inv_injective, H1. }
323+
destruct (lower_sig g) as [g' H4].
324+
{ eapply inv_injective, H2. }
325+
exists f' g'; eapply lem_lower; eassumption.
326+
Qed.
352327

353-
Theorem bijection_option X Y :
354-
bijection (option X) (option Y) -> bijection X Y.
355-
Proof.
356-
intros [f g H1 H2].
357-
destruct (lower_sig f) as [f' H3].
358-
{ eapply inv_injective, H1. }
359-
destruct (lower_sig g) as [g' H4].
360-
{ eapply inv_injective, H2. }
361-
exists f' g'; eapply lem_lower; eassumption.
362-
Qed.
363-
End Version2024.
364-
365328
(*** Numeral Types *)
366329

367330
Fixpoint num n : Type :=

0 commit comments

Comments
 (0)