Debian Codegraph @

test-suite/success/sprop.v

raw
1 (* -*- mode: coq; coq-prog-args: ("-allow-sprop") -*- *)
2
3 Set Primitive Projections.
4 Set Warnings "+non-primitive-record".
5 Set Warnings "+bad-relevance".
6
7 Check SProp.
8
9 Definition iUnit : SProp := forall A : SProp, A -> A.
10
11 Definition itt : iUnit := fun A a => a.
12
13 Definition iUnit_irr (P : iUnit -> Type) (x y : iUnit) : P x -> P y
14 := fun v => v.
15
16 Definition iSquash (A:Type) : SProp
17 := forall P : SProp, (A -> P) -> P.
18 Definition isquash A : A -> iSquash A
19 := fun a P f => f a.
20 Definition iSquash_rect A (P : iSquash A -> SProp) (H : forall x : A, P (isquash A x))
21 : forall x : iSquash A, P x
22 := fun x => x (P x) (H : A -> P x).
23
24 Fail Check (fun A : SProp => A : Type).
25
26 Lemma foo : Prop.
27 Proof. pose (fun A : SProp => ltac:(exact_no_check A): Type); exact True. Fail Qed. Abort.
28
29 (* define evar as product *)
30 Check (fun (f:(_:SProp)) => f _).
31
32 Inductive sBox (A:SProp) : Prop
33 := sbox : A -> sBox A.
34
35 Definition uBox := sBox iUnit.
36
37 Definition sBox_irr A (x y : sBox A) : x = y.
38 Proof.
39 Fail reflexivity.
40 destruct x as [x], y as [y].
41 reflexivity.
42 Defined.
43
44 (* Primitive record in Prop with all fields in SProp does not have the eta property of SProp
45 but can be defined regardless. *)
46 Record rBox (A:SProp) : Prop := rmkbox { runbox : A }.
47
48 (* Check that defining record without eta *)
49 Check runbox.
50
51 (* Check that it doesn't have eta *)
52 Fail Check (fun (A : SProp) (x : rBox A) => eq_refl : x = @rmkbox _ (@runbox _ x)).
53
54 Inductive sEmpty : SProp := .
55
56 Inductive sUnit : SProp := stt.
57
58 Inductive BIG : SProp := foo | bar.
59
60 Inductive Squash (A:Type) : SProp
61 := squash : A -> Squash A.
62
63 Definition BIG_flip : BIG -> BIG.
64 Proof.
65 intros [|]. exact bar. exact foo.
66 Defined.
67
68 Inductive pb : Prop := pt | pf.
69
70 Definition pb_big : pb -> BIG.
71 Proof.
72 intros [|]. exact foo. exact bar.
73 Defined.
74
75 Fail Definition big_pb (b:BIG) : pb :=
76 match b return pb with foo => pt | bar => pf end.
77
78 Inductive which_pb : pb -> SProp :=
79 | is_pt : which_pb pt
80 | is_pf : which_pb pf.
81
82 Fail Definition pb_which b (w:which_pb b) : bool
83 := match w with
84 | is_pt => true
85 | is_pf => false
86 end.
87
88 (* Non primitive because no arguments, but maybe we should allow it for sprops? *)
89 Fail Record UnitRecord : SProp := {}.
90
91 Section Opt.
92 Local Unset Primitive Projections.
93 Record UnitRecord' : SProp := {}.
94 End Opt.
95 Fail Scheme Induction for UnitRecord' Sort Set.
96
97 Record sProd (A B : SProp) : SProp := sPair { sFst : A; sSnd : B }.
98
99 Scheme Induction for sProd Sort Set.
100
101 Unset Primitive Projections.
102 Record sProd' (A B : SProp) : SProp := sPair' { sFst' : A; sSnd' : B }.
103 Set Primitive Projections.
104
105 Fail Scheme Induction for sProd' Sort Set.
106
107 Inductive Istrue : bool -> SProp := istrue : Istrue true.
108
109 Definition Istrue_sym (b:bool) := if b then sUnit else sEmpty.
110 Definition Istrue_to_sym b (i:Istrue b) : Istrue_sym b := match i with istrue => stt end.
111
112 (* We don't need primitive elimination to relevant types for this *)
113 Definition Istrue_rec (P:forall b, Istrue b -> Set) (H:P true istrue) b (i:Istrue b) : P b i.
114 Proof.
115 destruct b.
116 - exact_no_check H.
117 - apply sEmpty_rec. apply Istrue_to_sym in i. exact i.
118 Defined.
119
120 Check (fun P v (e:Istrue true) => eq_refl : Istrue_rec P v _ e = v).
121
122 Record Truepack := truepack { trueval :> bool; trueprop : Istrue trueval }.
123
124 Definition Truepack_eta (x : Truepack) (i : Istrue x) : x = truepack x i := @eq_refl Truepack x.
125
126 Class emptyclass : SProp := emptyinstance : forall A:SProp, A.
127
128 (** Sigma in SProp can be done through Squash and relevant sigma. *)
129 Definition sSigma (A:SProp) (B:A -> SProp) : SProp
130 := Squash (@sigT (rBox A) (fun x => rBox (B (runbox _ x)))).
131
132 Definition spair (A:SProp) (B:A->SProp) (x:A) (y:B x) : sSigma A B
133 := squash _ (existT _ (rmkbox _ x) (rmkbox _ y)).
134
135 Definition spr1 (A:SProp) (B:A->SProp) (p:sSigma A B) : A
136 := let 'squash _ (existT _ x y) := p in runbox _ x.
137
138 Definition spr2 (A:SProp) (B:A->SProp) (p:sSigma A B) : B (spr1 A B p)
139 := let 'squash _ (existT _ x y) := p return B (spr1 A B p) in runbox _ y.
140 (* it's SProp so it computes properly *)
141
142 (** Fixpoints on SProp values are only allowed to produce SProp results *)
143 Inductive sAcc (x:nat) : SProp := sAcc_in : (forall y, y < x -> sAcc y) -> sAcc x.
144
145 Definition sAcc_inv x (s:sAcc x) : forall y, y < x -> sAcc y.
146 Proof.
147 destruct s as [H]. exact H.
148 Defined.
149
150 Section sFix_fail.
151 Variable P : nat -> Type.
152 Variable F : forall x:nat, (forall y:nat, y < x -> P y) -> P x.
153
154 Fail Fixpoint sFix (x:nat) (a:sAcc x) {struct a} : P x :=
155 F x (fun (y:nat) (h: y < x) => sFix y (sAcc_inv x a y h)).
156 End sFix_fail.
157
158 Section sFix.
159 Variable P : nat -> SProp.
160 Variable F : forall x:nat, (forall y:nat, y < x -> P y) -> P x.
161
162 Fixpoint sFix (x:nat) (a:sAcc x) {struct a} : P x :=
163 F x (fun (y:nat) (h: y < x) => sFix y (sAcc_inv x a y h)).
164
165 End sFix.
166
167 (** Relevance repairs *)
168
169 Definition fix_relevance : _ -> nat := fun _ : iUnit => 0.
170 Definition relevance_unfixed := fun (A:SProp) (P:A -> Prop) x y (v:P x) => v : P y.
171 (* The kernel is fine *)
172 Definition relevance_unfixed_bypass := fun (A:SProp) (P:A -> Prop) x y (v:P x) =>
173 ltac:(exact_no_check v) : P y.
174
175 (* Check that VM/native properly keep the relevance of the predicate in the case info
176 (bad-relevance warning as error otherwise) *)
177 Definition vm_rebuild_case := Eval vm_compute in eq_sind.
178
179 Require Import ssreflect.
180
181 Goal forall T : SProp, T -> True.
182 Proof.
183 move=> T +.
184 intros X;exact I.
185 Qed.