Skip to content

Commit c15735a

Browse files
committedOct 11, 2018
comment examples
1 parent e24b380 commit c15735a

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed
 

‎Prime.v

+24-26
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Notation " ( x ; p ) " := (sigmaPI _ x p).
1313
Inductive sFalse : SProp := .
1414
Inductive sTrue : SProp := I : sTrue.
1515

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+
1620
(* Derive Invert for le. *)
1721

1822
Definition le : nat -> nat -> SProp :=
@@ -64,6 +68,8 @@ Inductive Divide : nat -> nat -> SProp:=
6468
| divide_0' : forall n, Divide n 0
6569
| divide_S' : forall n m (e: S n <= S m), Divide (S n) (m - n) -> Divide (S n) (S m).
6670

71+
(* Again, we copy&paste the definitions generated by the Equation plugin *)
72+
6773
(* Derive Invert for Divide. *)
6874

6975
Fixpoint invert_Divide var var0 {struct var0} : SProp :=
@@ -79,14 +85,6 @@ Fixpoint invert_Divide var var0 {struct var0} : SProp :=
7985

8086
Infix "|" := invert_Divide (at level 80).
8187

82-
Goal 5 | 145.
83-
cbn. repeat econstructor.
84-
Defined.
85-
86-
Goal (5 | 146) -> sFalse.
87-
cbn. firstorder.
88-
Defined.
89-
9088
Definition divide_0 n : n | 0 := I.
9189

9290
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.
104102
exact (HS n n0 H.1 H.2 (divide_rect P H0 HS (S n) (n0 - n) H.2)).
105103
Defined.
106104

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+
107117
Definition divide_to_nat {n m} : n | m -> nat :=
108118
divide_rect (fun _ _ (_:_ | _) => nat) (fun _ => 0) (fun _ _ _ _ k => S k) n m.
109119

@@ -120,30 +130,18 @@ Inductive is_gcd (a b g:nat) : SProp :=
120130
(g | a) -> (g | b) -> (forall x, (x | a) -> (x | b) -> (x | g)) ->
121131
is_gcd a b g.
122132

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.
129134

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 *)
132137

133138
Inductive prime (p:nat) : SProp :=
134139
prime_intro :
135140
1 < p -> (forall n, (1 <= n) -> (n < p) -> rel_prime n p) -> prime p.
136141

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.
147145
repeat (try solve [firstorder];
148146
destruct n; [ cbn; repeat econstructor; repeat (destruct x; firstorder) |]).
149147
firstorder.

‎SetoidCwf.v

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(* -*- coq-prog-args : ("-allow-sprop")-*- *)
22

3+
(* This files requires some basic HoTT reasoning for equality *)
4+
35
Require Import MiniHoTT.
46

57

0 commit comments

Comments
 (0)
Please sign in to comment.