Skip to content

Commit 10e5c4b

Browse files
Layout
1 parent 570dee1 commit 10e5c4b

1 file changed

Lines changed: 48 additions & 36 deletions

File tree

popl24/exercises/exercises.v

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
(** * MetaCoq *)
1+
(*** MetaCoq Tutorial @ POPL 2024 ***)
22

3-
(** ** Print Assumptions
3+
(** EXERCISE ** Print Assumptions
44
5-
A recent question on coq-club asked
5+
A recent question on coq-club asked
66
7-
"Is there a way to get Print Assumptions to output fully qualified names of all items?"
7+
"Is there a way to get Print Assumptions to output fully qualified names of
8+
all items?"
89
9-
(https://sympa.inria.fr/sympa/arc/coq-club/2024-01/msg00007.html)
10+
(https://sympa.inria.fr/sympa/arc/coq-club/2024-01/msg00007.html)
1011
11-
There is no satisfying answer using just Coq's Print Assumptions command.
12+
There is no satisfying answer using just Coq's Print Assumptions command.
1213
13-
The exercise here is to implement an improved Print Assumptions command in Coq, such that
14+
The exercise here is to implement an improved Print Assumptions command in
15+
Coq, such that
1416
15-
Compute print_assumptions ($quote_rec 0).
17+
Compute print_assumptions ($quote_rec 0).
1618
17-
prints []
19+
prints []
1820
19-
and
21+
and
2022
21-
Axiom test : nat.
23+
Axiom test : nat.
2224
23-
Compute print_assumptions ($quote_rec test).
25+
Compute print_assumptions ($quote_rec test).
2426
25-
prints a list containing a representation of test.
27+
prints a list containing a representation of test.
2628
27-
Define print_assumptions : global_env * term -> list kername
28-
*)
29+
Define print_assumptions : global_env * term -> list kername
2930
3031
Load MetaCoqPrelude.
3132
(* if this does not work for you, compile the file using `coqc -I . "" MetaCoqPrelude`, and instead use the following line *)
@@ -35,7 +36,7 @@ Require Import List.
3536
Unset Guard Checking.
3637
Section fix_Σ.
3738
38-
Variable (Σ : global_env).
39+
Variable (Σ : global_env).
3940
4041
End fix_Σ.
4142
Set Guard Checking.
@@ -46,25 +47,27 @@ Set Guard Checking.
4647
4748
Axiom test : nat.
4849
49-
(* Compute print_assumptions ($quote_rec test). *)
50+
(* Compute print_assumptions ($quote_rec test).
51+
52+
Module test.
5053
51-
(* Module test. *)
54+
Require Import Classical.
5255
53-
(* Require Import Classical. *)
56+
Lemma DNE P : ~~ P -> P.
57+
Proof.
58+
tauto.
59+
Qed.
5460
55-
(* Lemma DNE P : ~~ P -> P. *)
56-
(* Proof. *)
57-
(* tauto. *)
58-
(* Qed. *)
61+
End test.
5962
60-
(* End test. *)
63+
Compute print_assumptions ($quote_rec test.DNE). *)
6164
62-
(* Compute print_assumptions ($quote_rec test.DNE). *)
65+
(** EXERCISE
6366
64-
(** ** Define a function which replaces let binding by equivalent beta redexes
67+
Define a function which replaces let binding by equivalent beta redexes.
68+
You can copy-paste and rename the below identity function as starting point.
6569
66-
You can copy-paste and rename the below identity function as starting point.
67-
*)
70+
**)
6871
6972
Fixpoint identity (t : term) :=
7073
match t with
@@ -93,7 +96,12 @@ Fixpoint identity (t : term) :=
9396
9497
(* Check $unquote (let_to_lambda (Mower 5)). *)
9598
96-
(** ** Define a function which replaces any subterm of form a * b + c by a call to muladd: *)
99+
(** EXERCISE
100+
101+
Define a function which replaces any subterm of the form a * b + c by a call
102+
to muladd:
103+
104+
**)
97105
98106
Definition muladd a b c := a * b + c.
99107
@@ -103,15 +111,19 @@ Unset Guard Checking.
103111
104112
(* Check $unquote (fold_muladd ($quote (1 + (3 * 2 + 5)))). *)
105113
106-
(** ** Write a command reify that reifies Coq formulas into the following datatype *)
114+
(** EXERCISE
115+
116+
Write a command reify that reifies Coq formulas into the following datatype
117+
118+
**)
107119
108120
Inductive arith :=
109121
| aPlus : arith -> arith -> arith
110122
| aConst : nat -> arith.
111123
112-
(* Goal 4 + (3 + 1) = 2. *)
113-
(* Proof. *)
114-
(* match goal with *)
115-
(* | [ |- ?L = _ ] => pose ($unquote (reify ($quote L))) *)
116-
(* end. *)
117-
(* Abort. *)
124+
(* Goal 4 + (3 + 1) = 2.
125+
Proof.
126+
match goal with
127+
| [ |- ?L = _ ] => pose ($unquote (reify ($quote L)))
128+
end.
129+
Abort. *)

0 commit comments

Comments
 (0)