Debian Codegraph @

test-suite/success/sprop_uip.v

raw
1
2 Set Allow StrictProp.
3 Set Definitional UIP.
4
5 Set Warnings "+bad-relevance".
6
7 (** Case inversion, conversion and universe polymorphism. *)
8 Set Universe Polymorphism.
9 Inductive IsTy@{i j} : Type@{j} -> SProp :=
10 isty : IsTy Type@{i}.
11
12 Definition IsTy_rec_red@{i j+} (P:forall T : Type@{j}, IsTy@{i j} T -> Set)
13 v (e:IsTy@{i j} Type@{i})
14 : IsTy_rec P v _ e = v
15 := eq_refl.
16
17
18 (** Identity! Currently we have UIP. *)
19 Inductive seq {A} (a:A) : A -> SProp :=
20 srefl : seq a a.
21
22 Definition transport {A} (P:A -> Type) {x y} (e:seq x y) (v:P x) : P y :=
23 match e with
24 srefl _ => v
25 end.
26
27 Definition transport_refl {A} (P:A -> Type) {x} (e:seq x x) v
28 : transport P e v = v
29 := @eq_refl (P x) v.
30
31 Definition id_unit (x : unit) := x.
32 Definition transport_refl_id {A} (P : A -> Type) {x : A} (u : P x)
33 : P (transport (fun _ => A) (srefl _ : seq (id_unit tt) tt) x)
34 := u.
35
36 (** We don't ALWAYS reduce (this uses a constant transport so that the
37 equation is well-typed) *)
38 Fail Definition transport_block A B (x y:A) (e:seq x y) v
39 : transport (fun _ => B) e v = v
40 := @eq_refl B v.
41
42 Inductive sBox (A:SProp) : Prop
43 := sbox : A -> sBox A.
44
45 Definition transport_refl_box (A:SProp) P (x y:A) (e:seq (sbox A x) (sbox A y)) v
46 : transport P e v = v
47 := eq_refl.
48
49 (** TODO? add tests for binders which aren't lambda. *)
50 Definition transport_box :=
51 Eval lazy in (fun (A:SProp) P (x y:A) (e:seq (sbox A x) (sbox A y)) v =>
52 transport P e v).
53
54 Lemma transport_box_ok : transport_box = fun A P x y e v => v.
55 Proof.
56 unfold transport_box.
57 match goal with |- ?x = ?x => reflexivity end.
58 Qed.
59
60 (** Play with UIP *)
61 Lemma of_seq {A:Type} {x y:A} (p:seq x y) : x = y.
62 Proof.
63 destruct p. reflexivity.
64 Defined.
65
66 Lemma to_seq {A:Type} {x y:A} (p: x = y) : seq x y.
67 Proof.
68 destruct p. reflexivity.
69 Defined.
70
71 Lemma eq_srec (A:Type) (x y:A) (P:x=y->Type) : (forall e : seq x y, P (of_seq e)) -> forall e, P e.
72 Proof.
73 intros H e. destruct e.
74 apply (H (srefl _)).
75 Defined.
76
77 Lemma K : forall {A x} (p:x=x:>A), p = eq_refl.
78 Proof.
79 intros A x. apply eq_srec. intros;reflexivity.
80 Defined.
81
82 Definition K_refl : forall {A x}, @K A x eq_refl = eq_refl
83 := fun A x => eq_refl.
84
85 Section funext.
86
87 Variable sfunext : forall {A B} (f g : A -> B), (forall x, seq (f x) (g x)) -> seq f g.
88
89 Lemma funext {A B} (f g : A -> B) (H:forall x, (f x) = (g x)) : f = g.
90 Proof.
91 apply of_seq,sfunext;intros x;apply to_seq,H.
92 Defined.
93
94 Definition funext_refl A B (f : A -> B) : funext f f (fun x => eq_refl) = eq_refl
95 := eq_refl.
96 End funext.
97
98 (* test reductions on inverted cases *)
99
100 (* first check production of correct blocked cases *)
101 Definition lazy_seq_rect := Eval lazy in seq_rect.
102 Definition vseq_rect := Eval vm_compute in seq_rect.
103 Definition native_seq_rect := Eval native_compute in seq_rect.
104 Definition cbv_seq_rect := Eval cbv in seq_rect.
105
106 (* check it reduces according to indices *)
107 Ltac reset := match goal with H : _ |- _ => change (match H with srefl _ => False end) end.
108 Ltac check := match goal with |- False => idtac end.
109 Lemma foo (H:seq 0 0) : False.
110 Proof.
111 reset.
112 Fail check. (* check that "reset" and "check" actually do something *)
113
114 lazy; check; reset.
115
116 (* TODO *)
117 vm_compute. Fail check.
118 native_compute. Fail check.
119 cbv. Fail check.
120 cbn. Fail check.
121 simpl. Fail check.
122 Abort.
123
124 Module HoTTStyle.
125 (* a small proof which tests destruct in a tricky case *)
126
127 Definition ap {A B} (f:A -> B) {x y} (e : seq x y) : seq (f x) (f y).
128 Proof. destruct e. reflexivity. Defined.
129
130 Section S.
131 Context
132 (A : Type)
133 (B : Type)
134 (f : A -> B)
135 (g : B -> A)
136 (section : forall a, seq (g (f a)) a)
137 (retraction : forall b, seq (f (g b)) b).
138
139 Lemma bla (P : B -> Type) (a : A) (F : forall a, P (f a))
140 : seq_rect _ (f (g (f a))) (fun a _ => P a) (F (g (f a))) (f a) (retraction (f a)) = F a.
141 Proof.
142 lazy.
143 change (retraction (f a)) with (ap f (section a)).
144 destruct (section a).
145 reflexivity.
146 Qed.
147 End S.
148
149 End HoTTStyle.
150
151 (* check that extraction doesn't fall apart on matches with special reduction *)
152 Require Extraction.
153
154 Extraction seq_rect.