@@ -13,6 +13,10 @@ Notation " ( x ; p ) " := (sigmaPI _ x p).
13
13
Inductive sFalse : SProp := .
14
14
Inductive sTrue : SProp := I : sTrue.
15
15
16
+ (* The automatic generation of the fixpoint from the inductive definition *)
17
+ (* as presented in the paper has been developed as a branch of the Equation plugin *)
18
+ (* which is currently not well packaged. Thus, we provide directly the generated definitions. *)
19
+
16
20
(* Derive Invert for le. *)
17
21
18
22
Definition le : nat -> nat -> SProp :=
@@ -64,6 +68,8 @@ Inductive Divide : nat -> nat -> SProp:=
64
68
| divide_0' : forall n, Divide n 0
65
69
| divide_S' : forall n m (e: S n <= S m), Divide (S n) (m - n) -> Divide (S n) (S m).
66
70
71
+ (* Again, we copy&paste the definitions generated by the Equation plugin *)
72
+
67
73
(* Derive Invert for Divide. *)
68
74
69
75
Fixpoint invert_Divide var var0 {struct var0} : SProp :=
@@ -79,14 +85,6 @@ Fixpoint invert_Divide var var0 {struct var0} : SProp :=
79
85
80
86
Infix "|" := invert_Divide (at level 80).
81
87
82
- Goal 5 | 145.
83
- cbn. repeat econstructor.
84
- Defined .
85
-
86
- Goal (5 | 146) -> sFalse.
87
- cbn. firstorder.
88
- Defined .
89
-
90
88
Definition divide_0 n : n | 0 := I.
91
89
92
90
Definition divide_S n m (e: S n <= S m) (H: S n | S m - S n) : S n | S m
@@ -104,6 +102,18 @@ Proof.
104
102
exact (HS n n0 H.1 H.2 (divide_rect P H0 HS (S n) (n0 - n) H.2)).
105
103
Defined .
106
104
105
+ Goal 5 | 145.
106
+ cbn. repeat econstructor.
107
+ Defined .
108
+
109
+ Goal (5 | 146) -> sFalse.
110
+ cbn. firstorder.
111
+ Defined .
112
+
113
+
114
+ (* Although we have definitional proof irrelevance for n | m, we can still extract the natural number
115
+ that witnesses the fact that n is a divisor of m out of the proof that n | m *)
116
+
107
117
Definition divide_to_nat {n m} : n | m -> nat :=
108
118
divide_rect (fun _ _ (_:_ | _) => nat) (fun _ => 0) (fun _ _ _ _ k => S k) n m.
109
119
@@ -120,30 +130,18 @@ Inductive is_gcd (a b g:nat) : SProp :=
120
130
(g | a) -> (g | b) -> (forall x, (x | a) -> (x | b) -> (x | g)) ->
121
131
is_gcd a b g.
122
132
123
- (* Derive Invert for is_gcd. *)
124
-
125
- Definition invert_is_gcd : nat -> nat -> nat -> SProp :=
126
- fix invert_is_gcd (a b g : nat) {struct a} : SProp :=
127
- {_ : g | a & {_ : g | b & forall x : nat, x | a -> x | b -> x | g}}.
128
-
133
+ Definition rel_prime (a b:nat) : SProp := is_gcd a b 1.
129
134
130
-
131
- Definition rel_prime (a b:nat) : SProp := invert_is_gcd a b 1.
135
+ (* This definition gives us definitional proof irrelevance for prime, without paying the price of the definition of a decision procedure into booleans
136
+ (for instance using the sieve of Eratosthenes) and a proof that it corresponds to primality *)
132
137
133
138
Inductive prime (p:nat) : SProp :=
134
139
prime_intro :
135
140
1 < p -> (forall n, (1 <= n) -> (n < p) -> rel_prime n p) -> prime p.
136
141
137
- (* Derive Invert for prime. *)
138
-
139
- Definition invert_prime : nat -> SProp :=
140
- fix invert_prime (p : nat) : SProp :=
141
- {_ : 2 <= p & forall n : nat, 1 <= n -> S n <= p -> rel_prime n p}.
142
-
143
- Goal invert_prime 13.
144
- cbn. exists I. intro n.
145
- destruct n. intuition. intros _.
146
- intro e. cbn in e.
142
+ Goal prime 13.
143
+ cbn. econstructor. exact I. intro n.
144
+ destruct n. inversion 1. intros _ e. cbn in e.
147
145
repeat (try solve [firstorder];
148
146
destruct n; [ cbn; repeat econstructor; repeat (destruct x; firstorder) |]).
149
147
firstorder.
0 commit comments