├── assignments ├── 10 │ ├── forbidden.txt │ ├── E01_01.v │ ├── E02_01.v │ ├── E03_01.v │ ├── E04_01.v │ ├── E05_01.v │ ├── E06_01.v │ ├── check.sh │ ├── P02.v │ ├── P06.v │ ├── P05.v │ ├── P04.v │ ├── P03.v │ ├── Makefile │ └── SfLib.v ├── 11 │ ├── forbidden.txt │ ├── E01_01.v │ ├── E02_01.v │ ├── E03_01.v │ ├── check.sh │ ├── P01.v │ ├── Makefile │ ├── SfLib.v │ ├── P02.v │ └── P03.v ├── 12 │ ├── forbidden.txt │ ├── E02_01.v │ ├── E01_01.v │ ├── P02.v │ ├── check.sh │ ├── E03_01.v │ ├── P01.v │ ├── Makefile │ ├── P03.v │ └── SfLib.v ├── skeleton │ ├── .gitignore │ ├── requires.txt │ ├── forbidden.txt │ ├── finalize.sh │ ├── check.sh │ └── Makefile.skeleton ├── 07 │ ├── forbidden.txt │ ├── E05_01.v │ ├── E13_01.v │ ├── E11_01.v │ ├── E12_01.v │ ├── E15_01.v │ ├── E09_01.v │ ├── E10_01.v │ ├── E07_01.v │ ├── E01_01.v │ ├── P11.v │ ├── P12.v │ ├── P13.v │ ├── E06_03.v │ ├── E06_02.v │ ├── E14_01.v │ ├── E04_01.v │ ├── E08_01.v │ ├── check.sh │ ├── E02_01.v │ ├── P07.v │ ├── P14.v │ ├── P15.v │ ├── P08.v │ ├── E06_01.v │ ├── E03_01.v │ ├── P02.v │ ├── P01.v │ ├── P05.v │ ├── P04.v │ ├── Makefile │ ├── SfLib.v │ ├── P03.v │ └── P10.v ├── 08 │ ├── forbidden.txt │ ├── E01_01.v │ ├── check.sh │ ├── E02_01.v │ ├── P02.v │ ├── Makefile │ ├── P01.v │ └── SfLib.v ├── 09 │ ├── forbidden.txt │ ├── E04_01.v │ ├── E06_01.v │ ├── check.sh │ ├── E05_01.v │ ├── E01_01.v │ ├── P05.v │ ├── P06.v │ ├── P04.v │ ├── E03_01.v │ ├── E02_01.v │ ├── Makefile │ ├── P03.v │ └── SfLib.v ├── 07_sol │ ├── forbidden.txt │ ├── E05_01.v │ ├── E11_01.v │ ├── E12_01.v │ ├── E13_01.v │ ├── E09_01.v │ ├── E10_01.v │ ├── E15_01.v │ ├── E07_01.v │ ├── E01_01.v │ ├── E06_03.v │ ├── E06_02.v │ ├── E14_01.v │ ├── E04_01.v │ ├── E08_01.v │ ├── check.sh │ ├── E02_01.v │ ├── E06_01.v │ ├── P07.v │ ├── P05.v │ ├── P12.v │ ├── E03_01.v │ ├── P08.v │ ├── P15.v │ ├── Makefile │ ├── P01.v │ ├── SfLib.v │ └── P03.v ├── 08_sol │ ├── forbidden.txt │ ├── E01_01.v │ ├── check.sh │ ├── E02_01.v │ ├── Makefile │ ├── P02.v │ └── SfLib.v ├── 09_sol │ ├── forbidden.txt │ ├── E04_01.v │ ├── E06_01.v │ ├── check.sh │ ├── E05_01.v │ ├── E01_01.v │ ├── E03_01.v │ ├── E02_01.v │ ├── P04.v │ ├── Makefile │ ├── P06.v │ └── SfLib.v ├── 10_sol │ ├── forbidden.txt │ ├── E01_01.v │ ├── E02_01.v │ ├── E03_01.v │ ├── E04_01.v │ ├── E06_01.v │ ├── E05_01.v │ ├── check.sh │ ├── P02.v │ ├── Makefile │ ├── SfLib.v │ └── P04.v ├── 11_sol │ ├── forbidden.txt │ ├── E01_01.v │ ├── E02_01.v │ ├── E03_01.v │ ├── check.sh │ ├── Makefile │ ├── SfLib.v │ └── P01.v ├── 12_sol │ ├── forbidden.txt │ ├── E02_01.v │ ├── E01_01.v │ ├── check.sh │ ├── E03_01.v │ ├── Makefile │ └── SfLib.v ├── 00 │ ├── D.v │ ├── forbidden.txt │ ├── E02_01.v │ ├── E03_01.v │ ├── E01_01.v │ ├── check.sh │ ├── P03.v │ ├── P02.v │ ├── P01.v │ └── Makefile ├── .gitignore ├── 01 │ ├── forbidden.txt │ ├── E04_01.v │ ├── E03_01.v │ ├── E01_01.v │ ├── E05_01.v │ ├── E02_01.v │ ├── P05.v │ ├── check.sh │ ├── P04.v │ ├── P03.v │ ├── D.v │ ├── P02.v │ ├── P01.v │ └── Makefile ├── 02 │ ├── forbidden.txt │ ├── E03_01.v │ ├── E01_01.v │ ├── E07_01.v │ ├── E08_01.v │ ├── E02_01.v │ ├── E09_01.v │ ├── E05_01.v │ ├── E04_01.v │ ├── E10_01.v │ ├── P01.v │ ├── P02.v │ ├── P09.v │ ├── P10.v │ ├── P04.v │ ├── P05.v │ ├── check.sh │ ├── P08.v │ ├── P07.v │ ├── P03.v │ ├── E06_01.v │ ├── Makefile │ └── SfLib.v ├── 03 │ ├── forbidden.txt │ ├── E02_01.v │ ├── E03_01.v │ ├── E01_01.v │ ├── E01_02.v │ ├── P03.v │ ├── E05_01.v │ ├── E04_01.v │ ├── check.sh │ ├── P04.v │ ├── P02.v │ ├── P05.v │ ├── P01.v │ ├── Makefile │ └── SfLib.v ├── 04 │ ├── forbidden.txt │ ├── E01_01.v │ ├── E07_01.v │ ├── E05_01.v │ ├── E01_02.v │ ├── E08_01.v │ ├── E06_01.v │ ├── E02_01.v │ ├── E01_03.v │ ├── P08.v │ ├── P06.v │ ├── E09_01.v │ ├── check.sh │ ├── E04_01.v │ ├── P07.v │ ├── P09.v │ ├── E03_01.v │ ├── P05.v │ ├── P03.v │ ├── P04.v │ ├── P02.v │ ├── Makefile │ └── SfLib.v ├── 05 │ ├── forbidden.txt │ ├── E02_01.v │ ├── E03_01.v │ ├── E01_01.v │ ├── E04_01.v │ ├── P02.v │ ├── E05_01.v │ ├── P03.v │ ├── E06_01.v │ ├── E08_01.v │ ├── P04.v │ ├── P05.v │ ├── E07_01.v │ ├── P06.v │ ├── P01.v │ ├── P07.v │ ├── check.sh │ ├── Makefile │ ├── P08.v │ ├── D.v │ └── SfLib.v ├── 06 │ ├── forbidden.txt │ ├── E06_01.v │ ├── E05_01.v │ ├── E08_02.v │ ├── E07_01.v │ ├── E08_03.v │ ├── E09_01.v │ ├── E04_01.v │ ├── E04_02.v │ ├── E01_01.v │ ├── P05.v │ ├── P07.v │ ├── E03_01.v │ ├── P01.v │ ├── E02_01.v │ ├── E09_02.v │ ├── check.sh │ ├── E08_01.v │ ├── P06.v │ ├── P03.v │ ├── P02.v │ ├── Makefile │ ├── P04.v │ └── SfLib.v ├── 01_sol │ ├── forbidden.txt │ ├── E04_01.v │ ├── E03_01.v │ ├── E01_01.v │ ├── E05_01.v │ ├── E02_01.v │ ├── check.sh │ ├── P04.v │ ├── P05.v │ ├── P03.v │ ├── D.v │ ├── P02.v │ ├── P01.v │ └── Makefile ├── 02_sol │ ├── forbidden.txt │ ├── E03_01.v │ ├── E01_01.v │ ├── E07_01.v │ ├── E08_01.v │ ├── E02_01.v │ ├── E09_01.v │ ├── E05_01.v │ ├── E04_01.v │ ├── E10_01.v │ ├── P02.v │ ├── P09.v │ ├── P05.v │ ├── check.sh │ ├── P07.v │ ├── E06_01.v │ ├── P01.v │ ├── P03.v │ ├── P08.v │ ├── P10.v │ ├── Makefile │ ├── P04.v │ └── SfLib.v ├── 03_sol │ ├── forbidden.txt │ ├── E03_01.v │ ├── E02_01.v │ ├── E01_01.v │ ├── E01_02.v │ ├── P03.v │ ├── E05_01.v │ ├── E04_01.v │ ├── check.sh │ ├── P04.v │ ├── P02.v │ ├── P05.v │ ├── P01.v~ │ ├── Makefile │ ├── P01.v │ └── SfLib.v ├── 04_sol │ ├── forbidden.txt │ ├── E01_01.v │ ├── E07_01.v │ ├── E05_01.v │ ├── E01_02.v │ ├── E08_01.v │ ├── E06_01.v │ ├── E02_01.v │ ├── E01_03.v │ ├── E09_01.v │ ├── check.sh │ ├── E04_01.v │ ├── P06.v │ ├── E03_01.v │ ├── P07.v │ ├── P08.v │ ├── P03.v │ ├── P09.v │ ├── P04.v │ ├── P02.v │ ├── Makefile │ └── SfLib.v ├── 05_sol │ ├── forbidden.txt │ ├── E02_01.v │ ├── E03_01.v │ ├── E01_01.v │ ├── E04_01.v │ ├── E05_01.v │ ├── E06_01.v │ ├── E08_01.v │ ├── E07_01.v │ ├── P01.v │ ├── P03.v │ ├── check.sh │ ├── P02.v │ ├── P05.v │ ├── P06.v │ ├── P04.v │ ├── Makefile │ ├── P07.v │ ├── D.v │ └── SfLib.v └── 06_sol │ ├── forbidden.txt │ ├── E06_01.v │ ├── E05_01.v │ ├── E08_02.v │ ├── E07_01.v │ ├── E08_03.v │ ├── E04_01.v │ ├── E04_02.v │ ├── E09_01.v │ ├── E01_01.v │ ├── E03_01.v │ ├── E02_01.v │ ├── E09_02.v │ ├── check.sh │ ├── P05.v │ ├── E08_01.v │ ├── P01.v │ ├── P03.v │ ├── Makefile │ ├── P06.v │ ├── P07.v │ └── SfLib.v ├── .gitignore └── sf ├── deps.gif ├── index-bg.jpg ├── README ├── main.js ├── Symbols.v ├── SfLib.v ├── LICENSE ├── imp2.mli └── imp1.mli /assignments/skeleton/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | *.v 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .*.aux 2 | *.v.d 3 | *.vo 4 | *.vio 5 | *.glob 6 | -------------------------------------------------------------------------------- /assignments/07/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/08/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/09/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/10/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/11/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/12/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/07_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/08_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/09_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/10_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/11_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/12_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | Axiom 4 | -------------------------------------------------------------------------------- /assignments/00/D.v: -------------------------------------------------------------------------------- 1 | Definition FILL_IN_HERE {T: Type} : T. Admitted. 2 | -------------------------------------------------------------------------------- /assignments/skeleton/requires.txt: -------------------------------------------------------------------------------- 1 | SfLib.v Imp.v Smallstep.v Types.v 2 | -------------------------------------------------------------------------------- /assignments/.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.coq 2 | _CoqProject 3 | submission.zip 4 | -------------------------------------------------------------------------------- /sf/deps.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snu-sf-class/pl201602/HEAD/sf/deps.gif -------------------------------------------------------------------------------- /sf/index-bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snu-sf-class/pl201602/HEAD/sf/index-bg.jpg -------------------------------------------------------------------------------- /assignments/00/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/01/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/02/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/03/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/04/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/05/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/06/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/01_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/02_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/03_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/04_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/05_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/06_sol/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | -------------------------------------------------------------------------------- /assignments/06/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check ev'_ev : forall n, ev' n <-> ev n. 6 | 7 | -------------------------------------------------------------------------------- /assignments/06_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check ev'_ev : forall n, ev' n <-> ev n. 6 | 7 | -------------------------------------------------------------------------------- /assignments/skeleton/forbidden.txt: -------------------------------------------------------------------------------- 1 | admit 2 | Admitted 3 | tauto 4 | intuition 5 | firstorder 6 | omega 7 | Axiom 8 | -------------------------------------------------------------------------------- /assignments/02/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check double_plus : forall n, double n = n + n . 6 | 7 | -------------------------------------------------------------------------------- /assignments/02/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check plus_comm : forall n m : nat, 6 | n + m = m + n. 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check double_plus : forall n, double n = n + n . 6 | 7 | -------------------------------------------------------------------------------- /assignments/04/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check test_uncurry: 6 | prod_uncurry plus (3,7) = 10. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check ev_sum : forall n m, ev n -> ev m -> ev (n + m). 6 | 7 | -------------------------------------------------------------------------------- /assignments/01/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | Check zero_nbeq_plus_1 : forall n : nat, 4 | beq_nat 0 (n + 1) = false. 5 | -------------------------------------------------------------------------------- /assignments/02/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | Check app_nil_end : forall l : natlist, 5 | l ++ [] = l. 6 | 7 | -------------------------------------------------------------------------------- /assignments/02_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check plus_comm : forall n m : nat, 6 | n + m = m + n. 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | Check app_nil_end : forall l : natlist, 5 | l ++ [] = l. 6 | 7 | -------------------------------------------------------------------------------- /assignments/04_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check test_uncurry: 6 | prod_uncurry plus (3,7) = 10. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06/E08_02.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check subseq_refl: forall X (l: list X), 6 | subseq l l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check ev_sum : forall n m, ev n -> ev m -> ev (n + m). 6 | 7 | -------------------------------------------------------------------------------- /assignments/10/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check eval__multistep : forall t n, 5 | t \\ n -> t ==>* C n. 6 | 7 | -------------------------------------------------------------------------------- /assignments/11/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check value_is_nf : forall t, 5 | value t -> step_normal_form t. 6 | 7 | -------------------------------------------------------------------------------- /assignments/01/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | Check mult_S_1 : forall n m : nat, 4 | m = S n -> 5 | m * (1 + n) = m * m. 6 | -------------------------------------------------------------------------------- /assignments/01_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | Check zero_nbeq_plus_1 : forall n : nat, 4 | beq_nat 0 (n + 1) = false. 5 | -------------------------------------------------------------------------------- /assignments/02/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check rev_involutive : forall l : natlist, 6 | rev (rev l) = l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/05/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check mult_eq_0 : 6 | forall n m, n * m = 0 -> n = 0 \/ m = 0. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E08_02.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check subseq_refl: forall X (l: list X), 6 | subseq l l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check loop_never_stops : forall st st', 6 | ~(loop / st \\ st'). 7 | 8 | -------------------------------------------------------------------------------- /assignments/07/E13_01.v: -------------------------------------------------------------------------------- 1 | Require Import P13. 2 | 3 | 4 | Check optimize_0plus_com_sound: 5 | ctrans_sound optimize_0plus_com. 6 | 7 | -------------------------------------------------------------------------------- /assignments/10_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check eval__multistep : forall t n, 5 | t \\ n -> t ==>* C n. 6 | 7 | -------------------------------------------------------------------------------- /assignments/11_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check value_is_nf : forall t, 5 | value t -> step_normal_form t. 6 | 7 | -------------------------------------------------------------------------------- /assignments/01_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | Check mult_S_1 : forall n m : nat, 4 | m = S n -> 5 | m * (1 + n) = m * m. 6 | -------------------------------------------------------------------------------- /assignments/02/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check plus_assoc : forall n m p : nat, 6 | n + (m + p) = (n + m) + p. 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check rev_involutive : forall l : natlist, 6 | rev (rev l) = l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/03/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check test_repeat1: 6 | repeat true 2 = cons true (cons true nil). 7 | 8 | -------------------------------------------------------------------------------- /assignments/03/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check nil_app : forall X:Type, forall l:list X, 6 | app [] l = l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/03_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check nil_app : forall X:Type, forall l:list X, 6 | app [] l = l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/05/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check contrapositive : forall P Q : Prop, 6 | (P -> Q) -> (~Q -> ~P). 7 | 8 | -------------------------------------------------------------------------------- /assignments/05_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check mult_eq_0 : 6 | forall n m, n * m = 0 -> n = 0 \/ m = 0. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07/E11_01.v: -------------------------------------------------------------------------------- 1 | Require Import P11. 2 | 3 | 4 | Check optimize_0plus_aexp_sound: 5 | atrans_sound optimize_0plus_aexp. 6 | 7 | -------------------------------------------------------------------------------- /assignments/07/E12_01.v: -------------------------------------------------------------------------------- 1 | Require Import P12. 2 | 3 | 4 | Check optimize_0plus_bexp_sound: 5 | btrans_sound optimize_0plus_bexp. 6 | 7 | -------------------------------------------------------------------------------- /assignments/07/E15_01.v: -------------------------------------------------------------------------------- 1 | Require Import P15. 2 | 3 | 4 | 5 | Check inequiv_exercise: 6 | ~ cequiv (WHILE BTrue DO SKIP END) SKIP. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check loop_never_stops : forall st st', 6 | ~(loop / st \\ st'). 7 | 8 | -------------------------------------------------------------------------------- /assignments/07_sol/E11_01.v: -------------------------------------------------------------------------------- 1 | Require Import P11. 2 | 3 | 4 | Check optimize_0plus_aexp_sound: 5 | atrans_sound optimize_0plus_aexp. 6 | 7 | -------------------------------------------------------------------------------- /assignments/07_sol/E12_01.v: -------------------------------------------------------------------------------- 1 | Require Import P12. 2 | 3 | 4 | Check optimize_0plus_bexp_sound: 5 | btrans_sound optimize_0plus_bexp. 6 | 7 | -------------------------------------------------------------------------------- /assignments/07_sol/E13_01.v: -------------------------------------------------------------------------------- 1 | Require Import P13. 2 | 3 | 4 | Check optimize_0plus_com_sound: 5 | ctrans_sound optimize_0plus_com. 6 | 7 | -------------------------------------------------------------------------------- /assignments/02/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check snoc_append : forall (l:natlist) (n:nat), 6 | snoc l n = l ++ [n]. 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check plus_assoc : forall n m p : nat, 6 | n + (m + p) = (n + m) + p. 7 | 8 | -------------------------------------------------------------------------------- /assignments/03/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check test_split: 6 | split [(1,false);(2,false)] = ([1;2],[false;false]). 7 | 8 | -------------------------------------------------------------------------------- /assignments/03_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check test_repeat1: 6 | repeat true 2 = cons true (cons true nil). 7 | 8 | -------------------------------------------------------------------------------- /assignments/05/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check and_assoc : forall P Q R : Prop, 6 | P /\ (Q /\ R) -> (P /\ Q) /\ R. 7 | 8 | -------------------------------------------------------------------------------- /assignments/05_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check contrapositive : forall P Q : Prop, 6 | (P -> Q) -> (~Q -> ~P). 7 | 8 | -------------------------------------------------------------------------------- /assignments/06/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check plus_lt : forall n1 n2 m, 6 | n1 + n2 < m -> 7 | n1 < m /\ n2 < m. 8 | 9 | -------------------------------------------------------------------------------- /assignments/07/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check fold_constants_bexp_sound: 6 | btrans_sound fold_constants_bexp. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07/E10_01.v: -------------------------------------------------------------------------------- 1 | Require Import P10. 2 | 3 | 4 | 5 | Check fold_constants_com_sound : 6 | ctrans_sound fold_constants_com. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07_sol/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check fold_constants_bexp_sound: 6 | btrans_sound fold_constants_bexp. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07_sol/E10_01.v: -------------------------------------------------------------------------------- 1 | Require Import P10. 2 | 3 | 4 | 5 | Check fold_constants_com_sound : 6 | ctrans_sound fold_constants_com. 7 | 8 | -------------------------------------------------------------------------------- /assignments/07_sol/E15_01.v: -------------------------------------------------------------------------------- 1 | Require Import P15. 2 | 3 | 4 | 5 | Check inequiv_exercise: 6 | ~ cequiv (WHILE BTrue DO SKIP END) SKIP. 7 | 8 | -------------------------------------------------------------------------------- /assignments/09/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | Check hoare_asgn_weakest : forall Q X a, 5 | is_wp (Q [X |-> a]) (X ::= a) Q. 6 | 7 | -------------------------------------------------------------------------------- /assignments/02/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check fst_swap_is_snd : forall (p : natprod), 6 | fst (swap_pair p) = snd p. 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check snoc_append : forall (l:natlist) (n:nat), 6 | snoc l n = l ++ [n]. 7 | 8 | -------------------------------------------------------------------------------- /assignments/03/E01_02.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check split_map: forall X Y (l: list (X*Y)), 6 | fst (split l) = map fst l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/03_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check test_split: 6 | split [(1,false);(2,false)] = ([1;2],[false;false]). 7 | 8 | -------------------------------------------------------------------------------- /assignments/04/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check plus_n_n_injective : forall n m, 6 | n + n = m + m -> 7 | n = m. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check and_assoc : forall P Q R : Prop, 6 | P /\ (Q /\ R) -> (P /\ Q) /\ R. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check plus_lt : forall n1 n2 m, 6 | n1 + n2 < m -> 7 | n1 < m /\ n2 < m. 8 | 9 | -------------------------------------------------------------------------------- /assignments/09_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | Check hoare_asgn_weakest : forall Q X a, 5 | is_wp (Q [X |-> a]) (X ::= a) Q. 6 | 7 | -------------------------------------------------------------------------------- /assignments/11/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check progress : forall t T, 5 | |- t \in T -> 6 | value t \/ exists t', t ==> t'. 7 | 8 | -------------------------------------------------------------------------------- /assignments/00/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | Check (test_factorial1: (factorial 3) = 6). 4 | Check (test_factorial2: (factorial 5) = 10 * 12). 5 | -------------------------------------------------------------------------------- /assignments/02/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check mult_plus_distr_r : forall n m p : nat, 6 | (n + m) * p = (n * p) + (m * p). 7 | 8 | -------------------------------------------------------------------------------- /assignments/02/E10_01.v: -------------------------------------------------------------------------------- 1 | Require Import P10. 2 | 3 | 4 | 5 | Check distr_rev : forall l1 l2 : natlist, 6 | rev (l1 ++ l2) = (rev l2) ++ (rev l1). 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check fst_swap_is_snd : forall (p : natprod), 6 | fst (swap_pair p) = snd p. 7 | 8 | -------------------------------------------------------------------------------- /assignments/03_sol/E01_02.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check split_map: forall X Y (l: list (X*Y)), 6 | fst (split l) = map fst l. 7 | 8 | -------------------------------------------------------------------------------- /assignments/04_sol/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check plus_n_n_injective : forall n m, 6 | n + n = m + m -> 7 | n = m. 8 | 9 | -------------------------------------------------------------------------------- /assignments/10/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check step__eval : forall t t' n, 5 | t ==> t' -> 6 | t' \\ n -> 7 | t \\ n. 8 | 9 | -------------------------------------------------------------------------------- /assignments/11_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check progress : forall t T, 5 | |- t \in T -> 6 | value t \/ exists t', t ==> t'. 7 | 8 | -------------------------------------------------------------------------------- /assignments/skeleton/finalize.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | rm mk.py 4 | rm .gitignore 5 | rm Makefile.skeleton 6 | rm requires.txt 7 | rm finalize.sh 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check mult_plus_distr_r : forall n m p : nat, 6 | (n + m) * p = (n * p) + (m * p). 7 | 8 | -------------------------------------------------------------------------------- /assignments/02_sol/E10_01.v: -------------------------------------------------------------------------------- 1 | Require Import P10. 2 | 3 | 4 | 5 | Check distr_rev : forall l1 l2 : natlist, 6 | rev (l1 ++ l2) = (rev l2) ++ (rev l1). 7 | 8 | -------------------------------------------------------------------------------- /assignments/04/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check rev_exercise1 : forall (l l' : list nat), 6 | l = rev l' -> 7 | l' = rev l. 8 | 9 | -------------------------------------------------------------------------------- /assignments/10/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | Check multistep__eval : forall t t', 5 | normal_form_of t t' -> exists n, t' = C n /\ t \\ n. 6 | 7 | -------------------------------------------------------------------------------- /assignments/10_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check step__eval : forall t t' n, 5 | t ==> t' -> 6 | t' \\ n -> 7 | t \\ n. 8 | 9 | -------------------------------------------------------------------------------- /assignments/04_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check rev_exercise1 : forall (l l' : list nat), 6 | l = rev l' -> 7 | l' = rev l. 8 | 9 | -------------------------------------------------------------------------------- /assignments/10_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | Check multistep__eval : forall t t', 5 | normal_form_of t t' -> exists n, t' = C n /\ t \\ n. 6 | 7 | -------------------------------------------------------------------------------- /assignments/12/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check soundness : forall t t' T, 5 | empty |- t \in T -> 6 | t ==>* t' -> 7 | ~(stuck t'). 8 | 9 | -------------------------------------------------------------------------------- /assignments/12_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check soundness : forall t t' T, 5 | empty |- t \in T -> 6 | t ==>* t' -> 7 | ~(stuck t'). 8 | 9 | -------------------------------------------------------------------------------- /assignments/01/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | Check 4 | (conj test_factorial1 5 | (test_factorial2)) 6 | : 7 | (factorial 3) = 6 /\ 8 | (factorial 5) = 10 * 12. 9 | -------------------------------------------------------------------------------- /assignments/05/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check or_distributes_over_and : forall P Q R : Prop, 6 | P \/ (Q /\ R) <-> (P \/ Q) /\ (P \/ R). 7 | 8 | -------------------------------------------------------------------------------- /assignments/05/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Lemma mult_eq_0 : 6 | forall n m, n * m = 0 -> n = 0 \/ m = 0. 7 | Proof. exact FILL_IN_HERE. Qed. 8 | 9 | -------------------------------------------------------------------------------- /assignments/06/E08_03.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check subseq_app: forall X (l1 l2 l3: list X) 6 | (SUB: subseq l1 l2), 7 | subseq l1 (l2++l3). 8 | 9 | -------------------------------------------------------------------------------- /assignments/10/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | Check aexp_strong_progress: forall st a, 5 | (exists n, a = ANum n) \/ 6 | exists a', a / st ==>a a'. 7 | 8 | -------------------------------------------------------------------------------- /assignments/01_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | Check 4 | (conj test_factorial1 5 | (test_factorial2)) 6 | : 7 | (factorial 3) = 6 /\ 8 | (factorial 5) = 10 * 12. 9 | -------------------------------------------------------------------------------- /assignments/02/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | Theorem plus_comm : forall n m : nat, 6 | n + m = m + n. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | -------------------------------------------------------------------------------- /assignments/05/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check dist_not_exists : forall (X:Type) (P : X -> Prop), 6 | (forall x, P x) -> ~ (exists x, ~ P x). 7 | 8 | -------------------------------------------------------------------------------- /assignments/05/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | Theorem contrapositive : forall P Q : Prop, 6 | (P -> Q) -> (~Q -> ~P). 7 | Proof. exact FILL_IN_HERE. Qed. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check or_distributes_over_and : forall P Q R : Prop, 6 | P \/ (Q /\ R) <-> (P \/ Q) /\ (P \/ R). 7 | 8 | -------------------------------------------------------------------------------- /assignments/05_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check dist_not_exists : forall (X:Type) (P : X -> Prop), 6 | (forall x, P x) -> ~ (exists x, ~ P x). 7 | 8 | -------------------------------------------------------------------------------- /assignments/06/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check in_split : forall (X:Type) (x:X) (l:list X), 6 | In x l -> 7 | exists l1 l2, l = l1 ++ x :: l2. 8 | 9 | -------------------------------------------------------------------------------- /assignments/06_sol/E08_03.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check subseq_app: forall X (l1 l2 l3: list X) 6 | (SUB: subseq l1 l2), 7 | subseq l1 (l2++l3). 8 | 9 | -------------------------------------------------------------------------------- /assignments/08/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check hoare_asgn_wrong: 6 | exists a, ~ {{ fun st => True }} X ::= a {{ fun st => st X = aeval st a}}. 7 | 8 | -------------------------------------------------------------------------------- /assignments/10/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | Check bexp_strong_progress: forall st b, 5 | (b = BTrue \/ b = BFalse) \/ 6 | exists b', b / st ==>b b'. 7 | 8 | -------------------------------------------------------------------------------- /assignments/10/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | Check cimp_strong_progress : forall c st, 5 | c = SKIP \/ 6 | exists c' st', c / st ==> c' / st'. 7 | 8 | 9 | -------------------------------------------------------------------------------- /assignments/10_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | Check aexp_strong_progress: forall st a, 5 | (exists n, a = ANum n) \/ 6 | exists a', a / st ==>a a'. 7 | 8 | -------------------------------------------------------------------------------- /assignments/10_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | Check cimp_strong_progress : forall c st, 5 | c = SKIP \/ 6 | exists c' st', c / st ==> c' / st'. 7 | 8 | 9 | -------------------------------------------------------------------------------- /assignments/06/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check excluded_middle_to_double_negation_elimination: 6 | excluded_middle -> double_negation_elimination. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06/E04_02.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check double_negation_elimination_to_excluded_middle: 6 | double_negation_elimination -> excluded_middle. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check excluded_middle_to_double_negation_elimination: 6 | excluded_middle -> double_negation_elimination. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E04_02.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check double_negation_elimination_to_excluded_middle: 6 | double_negation_elimination -> excluded_middle. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check in_split : forall (X:Type) (x:X) (l:list X), 6 | In x l -> 7 | exists l1 l2, l = l1 ++ x :: l2. 8 | 9 | -------------------------------------------------------------------------------- /assignments/08_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check hoare_asgn_wrong: 6 | exists a, ~ {{ fun st => True }} X ::= a {{ fun st => st X = aeval st a}}. 7 | 8 | -------------------------------------------------------------------------------- /assignments/10_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | Check bexp_strong_progress: forall st b, 5 | (b = BTrue \/ b = BFalse) \/ 6 | exists b', b / st ==>b b'. 7 | 8 | -------------------------------------------------------------------------------- /assignments/11/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check preservation : forall t t' T, 6 | |- t \in T -> 7 | t ==> t' -> 8 | |- t' \in T. 9 | 10 | 11 | -------------------------------------------------------------------------------- /assignments/12/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check type_is_unique: forall t G T T' 5 | (HTyped: G |- t \in T) 6 | (HTyped': G |- t \in T'), 7 | T = T'. 8 | 9 | -------------------------------------------------------------------------------- /assignments/04/E01_02.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check uncurry_curry : forall (X Y Z : Type) (f : X -> Y -> Z) x y, 6 | prod_curry (prod_uncurry f) x y = f x y. 7 | 8 | -------------------------------------------------------------------------------- /assignments/11_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check preservation : forall t t' T, 6 | |- t \in T -> 7 | t ==> t' -> 8 | |- t' \in T. 9 | 10 | 11 | -------------------------------------------------------------------------------- /assignments/12_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check type_is_unique: forall t G T T' 5 | (HTyped: G |- t \in T) 6 | (HTyped': G |- t \in T'), 7 | T = T'. 8 | 9 | -------------------------------------------------------------------------------- /assignments/03_sol/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | Theorem nil_app : forall X:Type, forall l:list X, 6 | app [] l = l. 7 | Proof. 8 | reflexivity. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/04_sol/E01_02.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check uncurry_curry : forall (X Y Z : Type) (f : X -> Y -> Z) x y, 6 | prod_curry (prod_uncurry f) x y = f x y. 7 | 8 | -------------------------------------------------------------------------------- /assignments/06/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check evenb_double_conv : forall n, 6 | exists k, n = if evenb n then double k 7 | else S (double k). 8 | 9 | -------------------------------------------------------------------------------- /assignments/07/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check CSeq_congruence : forall c1 c1' c2 c2', 6 | cequiv c1 c1' -> cequiv c2 c2' -> 7 | cequiv (c1;;c2) (c1';;c2'). 8 | 9 | -------------------------------------------------------------------------------- /assignments/03/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | Theorem nil_app : forall X:Type, forall l:list X, 6 | app [] l = l. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/04/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check nth_error_after_last: forall (n : nat) (X : Type) (l : list X), 6 | length l = n -> 7 | nth_error l n = None. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check dist_exists_or : forall (X:Type) (P Q : X -> Prop), 6 | (exists x, P x \/ Q x) <-> (exists x, P x) \/ (exists x, Q x). 7 | 8 | -------------------------------------------------------------------------------- /assignments/06_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check evenb_double_conv : forall n, 6 | exists k, n = if evenb n then double k 7 | else S (double k). 8 | 9 | -------------------------------------------------------------------------------- /assignments/07/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check t_update_shadow : forall A (m: total_map A) v1 v2 x, 6 | t_update (t_update m x v1) x v2 7 | = t_update m x v2. 8 | 9 | -------------------------------------------------------------------------------- /assignments/07/P11.v: -------------------------------------------------------------------------------- 1 | Require Export P10. 2 | 3 | 4 | 5 | Lemma optimize_0plus_aexp_sound: 6 | atrans_sound optimize_0plus_aexp. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/07/P12.v: -------------------------------------------------------------------------------- 1 | Require Export P11. 2 | 3 | 4 | 5 | Lemma optimize_0plus_bexp_sound: 6 | btrans_sound optimize_0plus_bexp. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/07/P13.v: -------------------------------------------------------------------------------- 1 | Require Export P12. 2 | 3 | 4 | 5 | Lemma optimize_0plus_com_sound: 6 | ctrans_sound optimize_0plus_com. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/07_sol/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check CSeq_congruence : forall c1 c1' c2 c2', 6 | cequiv c1 c1' -> cequiv c2 c2' -> 7 | cequiv (c1;;c2) (c1';;c2'). 8 | 9 | -------------------------------------------------------------------------------- /assignments/00/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | Check (test_blt_nat1: (blt_nat 2 2) = false). 4 | Check (test_blt_nat2: (blt_nat 2 4) = true). 5 | Check (test_blt_nat3: (blt_nat 4 2) = false). 6 | -------------------------------------------------------------------------------- /assignments/02/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Theorem plus_assoc : forall n m p : nat, 6 | n + (m + p) = (n + m) + p. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/02/P09.v: -------------------------------------------------------------------------------- 1 | Require Export P08. 2 | 3 | 4 | 5 | Theorem snoc_append : forall (l:natlist) (n:nat), 6 | snoc l n = l ++ [n]. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/03/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check 6 | (conj test_hd_opt1 7 | (test_hd_opt2)) 8 | : 9 | hd_opt [1;2] = Some 1 /\ 10 | hd_opt [[1];[2]] = Some [1]. 11 | 12 | -------------------------------------------------------------------------------- /assignments/04_sol/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check nth_error_after_last: forall (n : nat) (X : Type) (l : list X), 6 | length l = n -> 7 | nth_error l n = None. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check All_In : 6 | forall T (P : T -> Prop) (l : list T), 7 | (forall x, In x l -> P x) <-> 8 | All P l. 9 | 10 | 11 | -------------------------------------------------------------------------------- /assignments/05_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check dist_exists_or : forall (X:Type) (P Q : X -> Prop), 6 | (exists x, P x \/ Q x) <-> (exists x, P x) \/ (exists x, Q x). 7 | 8 | -------------------------------------------------------------------------------- /assignments/07_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check t_update_shadow : forall A (m: total_map A) v1 v2 x, 6 | t_update (t_update m x v1) x v2 7 | = t_update m x v2. 8 | 9 | -------------------------------------------------------------------------------- /assignments/01/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | Check negation_fn_applied_twice : 4 | forall (f : bool -> bool), 5 | (forall (x : bool), f x = negb x) -> 6 | forall (b : bool), f (f b) = b. 7 | -------------------------------------------------------------------------------- /assignments/03_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check 6 | (conj test_hd_opt1 7 | (test_hd_opt2)) 8 | : 9 | hd_opt [1;2] = Some 1 /\ 10 | hd_opt [[1];[2]] = Some [1]. 11 | 12 | -------------------------------------------------------------------------------- /assignments/05/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | Theorem or_distributes_over_and : forall P Q R : Prop, 6 | P \/ (Q /\ R) <-> (P \/ Q) /\ (P \/ R). 7 | Proof. exact FILL_IN_HERE. Qed. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05_sol/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check All_In : 6 | forall T (P : T -> Prop) (l : list T), 7 | (forall x, In x l -> P x) <-> 8 | All P l. 9 | 10 | 11 | -------------------------------------------------------------------------------- /assignments/06/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars (ev_sum) *) 6 | Theorem ev_sum : forall n m, ev n -> ev m -> ev (n + m). 7 | Proof. exact FILL_IN_HERE. Qed. 8 | 9 | -------------------------------------------------------------------------------- /assignments/06/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | Theorem plus_lt : forall n1 n2 m, 6 | n1 + n2 < m -> 7 | n1 < m /\ n2 < m. 8 | Proof. unfold lt. exact FILL_IN_HERE. Qed. 9 | 10 | -------------------------------------------------------------------------------- /assignments/01_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | Check negation_fn_applied_twice : 4 | forall (f : bool -> bool), 5 | (forall (x : bool), f x = negb x) -> 6 | forall (b : bool), f (f b) = b. 7 | -------------------------------------------------------------------------------- /assignments/05/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | Theorem dist_not_exists : forall (X:Type) (P : X -> Prop), 6 | (forall x, P x) -> ~ (exists x, ~ P x). 7 | Proof. exact FILL_IN_HERE. Qed. 8 | 9 | -------------------------------------------------------------------------------- /assignments/02/P10.v: -------------------------------------------------------------------------------- 1 | Require Export P09. 2 | 3 | 4 | 5 | Theorem distr_rev : forall l1 l2 : natlist, 6 | rev (l1 ++ l2) = (rev l2) ++ (rev l1). 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/04/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check inversion_ex3 : forall (X : Type) (x y z : X) (l j : list X), 6 | x :: y :: l = z :: j -> 7 | y :: l = x :: j -> 8 | y = z. 9 | 10 | -------------------------------------------------------------------------------- /assignments/06/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check not_exists_dist : 6 | excluded_middle -> 7 | forall (X:Type) (P : X -> Prop), 8 | ~ (exists x, ~ P x) -> (forall x, P x). 9 | 10 | -------------------------------------------------------------------------------- /assignments/04/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check c_succ_1 : c_succ c_zero = c_one. 6 | 7 | Check c_succ_2 : c_succ c_one = c_two. 8 | 9 | Check c_succ_3 : c_succ c_two = c_three. 10 | 11 | -------------------------------------------------------------------------------- /assignments/04_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check inversion_ex3 : forall (X : Type) (x y z : X) (l j : list X), 6 | x :: y :: l = z :: j -> 7 | y :: l = x :: j -> 8 | y = z. 9 | 10 | -------------------------------------------------------------------------------- /assignments/06_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check not_exists_dist : 6 | excluded_middle -> 7 | forall (X:Type) (P : X -> Prop), 8 | ~ (exists x, ~ P x) -> (forall x, P x). 9 | 10 | -------------------------------------------------------------------------------- /assignments/04/E01_03.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check curry_uncurry : forall (X Y Z : Type) 6 | (f : (X * Y) -> Z) (p : X * Y), 7 | prod_uncurry (prod_curry f) p = f p. 8 | 9 | -------------------------------------------------------------------------------- /assignments/04_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check c_succ_1 : c_succ c_zero = c_one. 6 | 7 | Check c_succ_2 : c_succ c_one = c_two. 8 | 9 | Check c_succ_3 : c_succ c_two = c_three. 10 | 11 | -------------------------------------------------------------------------------- /assignments/05/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check In_map_iff : 6 | forall (A B : Type) (f : A -> B) (l : list A) (y : B), 7 | In y (map f l) <-> 8 | exists x, f x = y /\ In x l. 9 | 10 | -------------------------------------------------------------------------------- /assignments/07/E06_03.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | Import ListNotations. 3 | 4 | 5 | 6 | Check s_compile_correct : forall (st : state) (e : aexp), 7 | s_execute st [] (s_compile e) = [ aeval st e ]. 8 | 9 | 10 | -------------------------------------------------------------------------------- /assignments/07_sol/E06_03.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | Import ListNotations. 3 | 4 | 5 | 6 | Check s_compile_correct : forall (st : state) (e : aexp), 7 | s_execute st [] (s_compile e) = [ aeval st e ]. 8 | 9 | 10 | -------------------------------------------------------------------------------- /assignments/04_sol/E01_03.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | 5 | Check curry_uncurry : forall (X Y Z : Type) 6 | (f : (X * Y) -> Z) (p : X * Y), 7 | prod_uncurry (prod_curry f) p = f p. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | Theorem dist_exists_or : forall (X:Type) (P Q : X -> Prop), 6 | (exists x, P x \/ Q x) <-> (exists x, P x) \/ (exists x, Q x). 7 | Proof. exact FILL_IN_HERE. Qed. 8 | 9 | -------------------------------------------------------------------------------- /assignments/05_sol/E07_01.v: -------------------------------------------------------------------------------- 1 | Require Import P07. 2 | 3 | 4 | 5 | Check In_map_iff : 6 | forall (A B : Type) (f : A -> B) (l : list A) (y : B), 7 | In y (map f l) <-> 8 | exists x, f x = y /\ In x l. 9 | 10 | -------------------------------------------------------------------------------- /assignments/12/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Corollary soundness : forall t t' T, 6 | empty |- t \in T -> 7 | t ==>* t' -> 8 | ~(stuck t'). 9 | Proof. 10 | exact FILL_IN_HERE. 11 | Qed. 12 | 13 | -------------------------------------------------------------------------------- /assignments/01/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | Check 4 | (conj test_blt_nat1 5 | (conj test_blt_nat2 6 | (test_blt_nat3))) 7 | : 8 | (blt_nat 2 2) = false /\ 9 | (blt_nat 2 4) = true /\ 10 | (blt_nat 4 2) = false. 11 | -------------------------------------------------------------------------------- /assignments/01_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | Check 4 | (conj test_blt_nat1 5 | (conj test_blt_nat2 6 | (test_blt_nat3))) 7 | : 8 | (blt_nat 2 2) = false /\ 9 | (blt_nat 2 4) = true /\ 10 | (blt_nat 4 2) = false. 11 | -------------------------------------------------------------------------------- /assignments/05/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | Theorem and_assoc : forall P Q R : Prop, 6 | P /\ (Q /\ R) -> (P /\ Q) /\ R. 7 | Proof. 8 | intros P Q R [HP [HQ HR]]. 9 | exact FILL_IN_HERE. 10 | Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/06/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | Theorem evenb_double_conv : forall n, 6 | exists k, n = if evenb n then double k 7 | else S (double k). 8 | Proof. exact FILL_IN_HERE. Qed. 9 | 10 | -------------------------------------------------------------------------------- /assignments/07/E06_02.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | Import ListNotations. 3 | 4 | 5 | 6 | Check s_compile1 : 7 | s_compile (AMinus (AId X) (AMult (ANum 2) (AId Y))) 8 | = [SLoad X; SPush 2; SLoad Y; SMult; SMinus]. 9 | 10 | -------------------------------------------------------------------------------- /assignments/04/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | Theorem nth_error_after_last: forall (n : nat) (X : Type) (l : list X), 6 | length l = n -> 7 | nth_error l n = None. 8 | Proof. exact FILL_IN_HERE. Qed. 9 | 10 | -------------------------------------------------------------------------------- /assignments/07_sol/E06_02.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | Import ListNotations. 3 | 4 | 5 | 6 | Check s_compile1 : 7 | s_compile (AMinus (AId X) (AMult (ANum 2) (AId Y))) 8 | = [SLoad X; SPush 2; SLoad Y; SMult; SMinus]. 9 | 10 | -------------------------------------------------------------------------------- /assignments/04/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Example inversion_ex3 : forall (X : Type) (x y z : X) (l j : list X), 6 | x :: y :: l = z :: j -> 7 | y :: l = x :: j -> 8 | y = z. 9 | Proof. exact FILL_IN_HERE. Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/05_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | Theorem and_assoc : forall P Q R : Prop, 6 | P /\ (Q /\ R) -> (P /\ Q) /\ R. 7 | Proof. 8 | intros P Q R [HP [HQ HR]]. 9 | split ; try split ; assumption. 10 | Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/01/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | Theorem negation_fn_applied_twice : 4 | forall (f : bool -> bool), 5 | (forall (x : bool), f x = negb x) -> 6 | forall (b : bool), f (f b) = b. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | -------------------------------------------------------------------------------- /assignments/03/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check snoc_with_append : forall X : Type, 6 | forall l1 l2 : list X, 7 | forall v : X, 8 | snoc (l1 ++ l2) v = l1 ++ (snoc l2 v). 9 | 10 | -------------------------------------------------------------------------------- /assignments/04/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check filter_exercise : forall (X : Type) (test : X -> bool) 6 | (x : X) (l lf : list X), 7 | filter test l = x :: lf -> 8 | test x = true. 9 | 10 | -------------------------------------------------------------------------------- /assignments/05/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | Lemma In_map_iff : 6 | forall (A B : Type) (f : A -> B) (l : list A) (y : B), 7 | In y (map f l) <-> 8 | exists x, f x = y /\ In x l. 9 | Proof. exact FILL_IN_HERE. Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/06/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check beq_list_true_iff : 6 | forall A (beq : A -> A -> bool), 7 | (forall a1 a2, beq a1 a2 = true <-> a1 = a2) -> 8 | forall l1 l2, beq_list beq l1 l2 = true <-> l1 = l2. 9 | 10 | -------------------------------------------------------------------------------- /assignments/06/E09_02.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check pigeonhole_principle: forall (X:Type) (l1 l2:list X), 6 | excluded_middle -> 7 | (forall x, In x l1 -> In x l2) -> 8 | length l2 < length l1 -> 9 | repeats l1. 10 | 11 | -------------------------------------------------------------------------------- /assignments/02/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** **** Problem : 3 stars (mult_comm) *) 6 | 7 | Theorem mult_plus_distr_r : forall n m p : nat, 8 | (n + m) * p = (n * p) + (m * p). 9 | Proof. 10 | exact FILL_IN_HERE. 11 | Qed. 12 | 13 | -------------------------------------------------------------------------------- /assignments/02_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Theorem plus_assoc : forall n m p : nat, 6 | n + (m + p) = (n + m) + p. 7 | Proof. 8 | intros. 9 | induction n. 10 | - reflexivity. 11 | - simpl. rewrite IHn. reflexivity. 12 | Qed. 13 | 14 | -------------------------------------------------------------------------------- /assignments/02_sol/P09.v: -------------------------------------------------------------------------------- 1 | Require Export P08. 2 | 3 | 4 | 5 | Theorem snoc_append : forall (l:natlist) (n:nat), 6 | snoc l n = l ++ [n]. 7 | Proof. 8 | induction l. 9 | - reflexivity. 10 | - simpl. intros. rewrite <- IHl. reflexivity. 11 | Qed. 12 | 13 | -------------------------------------------------------------------------------- /assignments/03_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check snoc_with_append : forall X : Type, 6 | forall l1 l2 : list X, 7 | forall v : X, 8 | snoc (l1 ++ l2) v = l1 ++ (snoc l2 v). 9 | 10 | -------------------------------------------------------------------------------- /assignments/04_sol/E09_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check filter_exercise : forall (X : Type) (test : X -> bool) 6 | (x : X) (l lf : list X), 7 | filter test l = x :: lf -> 8 | test x = true. 9 | 10 | -------------------------------------------------------------------------------- /assignments/06_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check beq_list_true_iff : 6 | forall A (beq : A -> A -> bool), 7 | (forall a1 a2, beq a1 a2 = true <-> a1 = a2) -> 8 | forall l1 l2, beq_list beq l1 l2 = true <-> l1 = l2. 9 | 10 | -------------------------------------------------------------------------------- /assignments/06_sol/E09_02.v: -------------------------------------------------------------------------------- 1 | Require Import P09. 2 | 3 | 4 | 5 | Check pigeonhole_principle: forall (X:Type) (l1 l2:list X), 6 | excluded_middle -> 7 | (forall x, In x l1 -> In x l2) -> 8 | length l2 < length l1 -> 9 | repeats l1. 10 | 11 | -------------------------------------------------------------------------------- /assignments/07/E14_01.v: -------------------------------------------------------------------------------- 1 | Require Import P14. 2 | 3 | 4 | 5 | Check subst_equiv: forall i1 i2 a1 a2, 6 | var_not_used_in_aexp i1 (subst_aexp i1 a1 a2) -> 7 | cequiv (i1 ::= a1;; i2 ::= a2) 8 | (i1 ::= a1;; i2 ::= subst_aexp i1 a1 a2). 9 | 10 | -------------------------------------------------------------------------------- /assignments/07/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check pup_to_2_ceval : 6 | pup_to_n / (t_update empty_state X 2) \\ 7 | t_update (t_update (t_update (t_update (t_update (t_update empty_state 8 | X 2) Y 0) Y 2) X 1) Y 3) X 0. 9 | 10 | -------------------------------------------------------------------------------- /assignments/07/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check CIf_congruence : forall b b' c1 c1' c2 c2', 6 | bequiv b b' -> cequiv c1 c1' -> cequiv c2 c2' -> 7 | cequiv (IFB b THEN c1 ELSE c2 FI) 8 | (IFB b' THEN c1' ELSE c2' FI). 9 | 10 | -------------------------------------------------------------------------------- /assignments/07_sol/E14_01.v: -------------------------------------------------------------------------------- 1 | Require Import P14. 2 | 3 | 4 | 5 | Check subst_equiv: forall i1 i2 a1 a2, 6 | var_not_used_in_aexp i1 (subst_aexp i1 a1 a2) -> 7 | cequiv (i1 ::= a1;; i2 ::= a2) 8 | (i1 ::= a1;; i2 ::= subst_aexp i1 a1 a2). 9 | 10 | -------------------------------------------------------------------------------- /assignments/02/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (** **** Problem #10 : 1 star, optional (fst_swap_is_snd) *) 6 | Theorem fst_swap_is_snd : forall (p : natprod), 7 | fst (swap_pair p) = snd p. 8 | Proof. 9 | exact FILL_IN_HERE. 10 | Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/02/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/03/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/04/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/05/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/05_sol/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | Theorem contrapositive : forall P Q : Prop, 6 | (P -> Q) -> (~Q -> ~P). 7 | Proof. 8 | intros. 9 | unfold not. 10 | intros. 11 | apply H in H1. 12 | apply H0 in H1. 13 | assumption. 14 | Qed. 15 | 16 | -------------------------------------------------------------------------------- /assignments/06/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/07/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/07_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check pup_to_2_ceval : 6 | pup_to_n / (t_update empty_state X 2) \\ 7 | t_update (t_update (t_update (t_update (t_update (t_update empty_state 8 | X 2) Y 0) Y 2) X 1) Y 3) X 0. 9 | 10 | -------------------------------------------------------------------------------- /assignments/07_sol/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check CIf_congruence : forall b b' c1 c1' c2 c2', 6 | bequiv b b' -> cequiv c1 c1' -> cequiv c2 c2' -> 7 | cequiv (IFB b THEN c1 ELSE c2 FI) 8 | (IFB b' THEN c1' ELSE c2' FI). 9 | 10 | -------------------------------------------------------------------------------- /assignments/08/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/09/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check hoare_skip_weakest : forall Q, 6 | is_wp Q SKIP Q. 7 | 8 | Check hoare_seq_weakest : forall P Q R c1 c2, 9 | is_wp P c1 Q -> 10 | is_wp Q c2 R -> 11 | is_wp P (c1 ;; c2) R. 12 | 13 | 14 | -------------------------------------------------------------------------------- /assignments/09/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/10/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/11/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/12/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/00/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | Check (test_andb31: (andb3 true true true) = true). 4 | Check (test_andb32: (andb3 false true true) = false). 5 | Check (test_andb33: (andb3 true false true) = false). 6 | Check (test_andb34: (andb3 true true false) = false). 7 | -------------------------------------------------------------------------------- /assignments/00/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'FILL_IN_HERE' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/01/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'FILL_IN_HERE' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/02/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P07. 2 | 3 | 4 | 5 | (** Hint: You may need to first state and prove some lemma about snoc and rev. *) 6 | Theorem rev_involutive : forall l : natlist, 7 | rev (rev l) = l. 8 | Proof. 9 | exact FILL_IN_HERE. 10 | Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/02_sol/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (** **** Problem #10 : 1 star, optional (fst_swap_is_snd) *) 6 | Theorem fst_swap_is_snd : forall (p : natprod), 7 | fst (swap_pair p) = snd p. 8 | Proof. 9 | destruct p. reflexivity. 10 | Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/02_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/03_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/04/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check c_mult_1 : c_mult c_one c_one = c_one. 6 | 7 | Check c_mult_2 : c_mult c_zero (c_plus c_three c_three) = c_zero. 8 | 9 | Check c_mult_3 : c_mult c_two c_three = c_plus c_three c_three. 10 | 11 | 12 | -------------------------------------------------------------------------------- /assignments/04/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | Theorem plus_n_n_injective : forall n m, 6 | n + n = m + m -> 7 | n = m. 8 | Proof. 9 | intros n. induction n as [| n']. 10 | - exact FILL_IN_HERE. 11 | - exact FILL_IN_HERE. 12 | Qed. 13 | 14 | -------------------------------------------------------------------------------- /assignments/04_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/05_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/06_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/07_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/08_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/09_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check hoare_skip_weakest : forall Q, 6 | is_wp Q SKIP Q. 7 | 8 | Check hoare_seq_weakest : forall P Q R c1 c2, 9 | is_wp P c1 Q -> 10 | is_wp Q c2 R -> 11 | is_wp P (c1 ;; c2) R. 12 | 13 | 14 | -------------------------------------------------------------------------------- /assignments/09_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/10_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/11_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/12_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/skeleton/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'GIVEUP' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/01_sol/check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_keyword() { 4 | echo "$1:" 5 | grep $1 P??.v 6 | echo '' 7 | } 8 | 9 | check_keyword 'FILL_IN_HERE' 10 | for keyword in `cat forbidden.txt`; do 11 | check_keyword ${keyword} 12 | done 13 | -------------------------------------------------------------------------------- /assignments/04_sol/E04_01.v: -------------------------------------------------------------------------------- 1 | Require Import P04. 2 | 3 | 4 | 5 | Check c_mult_1 : c_mult c_one c_one = c_one. 6 | 7 | Check c_mult_2 : c_mult c_zero (c_plus c_three c_three) = c_zero. 8 | 9 | Check c_mult_3 : c_mult c_two c_three = c_plus c_three c_three. 10 | 11 | 12 | -------------------------------------------------------------------------------- /assignments/04_sol/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Example inversion_ex3 : forall (X : Type) (x y z : X) (l j : list X), 6 | x :: y :: l = z :: j -> 7 | y :: l = x :: j -> 8 | y = z. 9 | Proof. intros. inversion H. inversion H0. assumption. Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/02/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | (** **** Problem #3 : 3 stars (list_exercises) *) 6 | (** More practice with lists. *) 7 | 8 | Theorem app_nil_end : forall l : natlist, 9 | l ++ [] = l. 10 | Proof. 11 | exact FILL_IN_HERE. 12 | Qed. 13 | 14 | -------------------------------------------------------------------------------- /assignments/04/P09.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | Theorem filter_exercise : forall (X : Type) (test : X -> bool) 6 | (x : X) (l lf : list X), 7 | filter test l = x :: lf -> 8 | test x = true. 9 | Proof. exact FILL_IN_HERE. Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/07/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check t_update_permute : forall (X:Type) v1 v2 x1 x2 6 | (m : total_map X), 7 | x2 <> x1 -> 8 | (t_update (t_update m x2 v2) x1 v1) 9 | = (t_update (t_update m x1 v1) x2 v2). 10 | 11 | -------------------------------------------------------------------------------- /assignments/07_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check t_update_permute : forall (X:Type) v1 v2 x1 x2 6 | (m : total_map X), 7 | x2 <> x1 -> 8 | (t_update (t_update m x2 v2) x1 v1) 9 | = (t_update (t_update m x1 v1) x2 v2). 10 | 11 | -------------------------------------------------------------------------------- /assignments/06_sol/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars (ev_sum) *) 6 | Theorem ev_sum : forall n m, ev n -> ev m -> ev (n + m). 7 | Proof. 8 | intros. 9 | induction H. 10 | - simpl. assumption. 11 | - simpl. constructor. assumption. 12 | Qed. 13 | 14 | -------------------------------------------------------------------------------- /assignments/07/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, optional (CSeq_congruence) *) 6 | Theorem CSeq_congruence : forall c1 c1' c2 c2', 7 | cequiv c1 c1' -> cequiv c2 c2' -> 8 | cequiv (c1;;c2) (c1';;c2'). 9 | Proof. exact FILL_IN_HERE. Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/07/P14.v: -------------------------------------------------------------------------------- 1 | Require Export P13. 2 | 3 | 4 | 5 | Lemma subst_equiv: forall i1 i2 a1 a2, 6 | var_not_used_in_aexp i1 (subst_aexp i1 a1 a2) -> 7 | cequiv (i1 ::= a1;; i2 ::= a2) 8 | (i1 ::= a1;; i2 ::= subst_aexp i1 a1 a2). 9 | Proof. exact FILL_IN_HERE. Qed. 10 | 11 | -------------------------------------------------------------------------------- /assignments/08/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check if_minus_plus : 5 | {{fun st => True}} 6 | IFB (BLe (AId X) (AId Y)) 7 | THEN (Z ::= AMinus (AId Y) (AId X)) 8 | ELSE (Y ::= APlus (AId X) (AId Z)) 9 | FI 10 | {{fun st => st Y = st X + st Z}}. 11 | 12 | 13 | -------------------------------------------------------------------------------- /assignments/08_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | Check if_minus_plus : 5 | {{fun st => True}} 6 | IFB (BLe (AId X) (AId Y)) 7 | THEN (Z ::= AMinus (AId Y) (AId X)) 8 | ELSE (Y ::= APlus (AId X) (AId Z)) 9 | FI 10 | {{fun st => st Y = st X + st Z}}. 11 | 12 | 13 | -------------------------------------------------------------------------------- /assignments/09/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check hoare_if_weakest : forall P1 P2 Q b c1 c2, 6 | is_wp P1 c1 Q -> 7 | is_wp P2 c2 Q -> 8 | is_wp (fun st => (beval st b = true -> P1 st) /\ (beval st b = false -> P2 st)) 9 | (IFB b THEN c1 ELSE c2 FI) Q. 10 | 11 | -------------------------------------------------------------------------------- /assignments/01/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | (** **** Problem #4 : 1 star (zero_nbeq_plus_1) *) 4 | 5 | (* See the base file for the definition of [beq_nat]. *) 6 | 7 | Theorem zero_nbeq_plus_1 : forall n : nat, 8 | beq_nat 0 (n + 1) = false. 9 | Proof. 10 | exact FILL_IN_HERE. 11 | Qed. 12 | -------------------------------------------------------------------------------- /assignments/03/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | Theorem snoc_with_append : forall X : Type, 6 | forall l1 l2 : list X, 7 | forall v : X, 8 | snoc (l1 ++ l2) v = l1 ++ (snoc l2 v). 9 | Proof. 10 | exact FILL_IN_HERE. 11 | Qed. 12 | 13 | -------------------------------------------------------------------------------- /assignments/04/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check c_plus_1 : c_plus c_zero c_one = c_one. 6 | 7 | Check c_plus_2 : c_plus c_two c_three = c_plus c_three c_two. 8 | 9 | Check c_plus_3 : 10 | c_plus (c_plus c_two c_two) c_three = c_plus c_one (c_plus c_three c_three). 11 | 12 | -------------------------------------------------------------------------------- /assignments/04_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check c_plus_1 : c_plus c_zero c_one = c_one. 6 | 7 | Check c_plus_2 : c_plus c_two c_three = c_plus c_three c_two. 8 | 9 | Check c_plus_3 : 10 | c_plus (c_plus c_two c_two) c_three = c_plus c_one (c_plus c_three c_three). 11 | 12 | -------------------------------------------------------------------------------- /assignments/05_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | Lemma mult_eq_0 : 6 | forall n m, n * m = 0 -> n = 0 \/ m = 0. 7 | Proof. 8 | intros. 9 | destruct n; destruct m. 10 | left. reflexivity. 11 | left. reflexivity. 12 | right. reflexivity. 13 | simpl in H. inversion H. 14 | Qed. 15 | 16 | -------------------------------------------------------------------------------- /assignments/09_sol/E05_01.v: -------------------------------------------------------------------------------- 1 | Require Import P05. 2 | 3 | 4 | 5 | Check hoare_if_weakest : forall P1 P2 Q b c1 c2, 6 | is_wp P1 c1 Q -> 7 | is_wp P2 c2 Q -> 8 | is_wp (fun st => (beval st b = true -> P1 st) /\ (beval st b = false -> P2 st)) 9 | (IFB b THEN c1 ELSE c2 FI) Q. 10 | 11 | -------------------------------------------------------------------------------- /assignments/10/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (step__eval) *) 6 | Lemma step__eval : forall t t' n, 7 | t ==> t' -> 8 | t' \\ n -> 9 | t \\ n. 10 | Proof. 11 | intros t t' n Hs. generalize dependent n. 12 | exact FILL_IN_HERE. 13 | Qed. 14 | 15 | -------------------------------------------------------------------------------- /assignments/05_sol/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | Theorem dist_not_exists : forall (X:Type) (P : X -> Prop), 6 | (forall x, P x) -> ~ (exists x, ~ P x). 7 | Proof. 8 | intros. 9 | unfold not. 10 | intros. 11 | inversion H0. 12 | assert (Hx := H x). 13 | apply H1 in Hx. 14 | assumption. 15 | Qed. -------------------------------------------------------------------------------- /assignments/07/P15.v: -------------------------------------------------------------------------------- 1 | Require Export P14. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, optional (inequiv_exercise) *) 6 | (** Prove that an infinite loop is not equivalent to [SKIP] *) 7 | 8 | Theorem inequiv_exercise: 9 | ~ cequiv (WHILE BTrue DO SKIP END) SKIP. 10 | Proof. exact FILL_IN_HERE. Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/09/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check factorial_correct: forall m, 5 | {{ fun st => st X = m }} 6 | Y ::= ANum 1 ;; 7 | WHILE BNot (BEq (AId X) (ANum 0)) 8 | DO 9 | Y ::= AMult (AId Y) (AId X) ;; 10 | X ::= AMinus (AId X) (ANum 1) 11 | END 12 | {{ fun st => st Y = fact m }}. 13 | 14 | -------------------------------------------------------------------------------- /assignments/09_sol/E01_01.v: -------------------------------------------------------------------------------- 1 | Require Import P01. 2 | 3 | 4 | Check factorial_correct: forall m, 5 | {{ fun st => st X = m }} 6 | Y ::= ANum 1 ;; 7 | WHILE BNot (BEq (AId X) (ANum 0)) 8 | DO 9 | Y ::= AMult (AId Y) (AId X) ;; 10 | X ::= AMinus (AId X) (ANum 1) 11 | END 12 | {{ fun st => st Y = fact m }}. 13 | 14 | -------------------------------------------------------------------------------- /assignments/12/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check halve_type: empty |- halve \in TArrow TNat TNat. 6 | 7 | Check halve_10: tapp halve (tnat 10) ==>* tnat 5. 8 | 9 | Check halve_11: tapp halve (tnat 11) ==>* tnat 5. 10 | 11 | Check halve_correct: forall n, 12 | tapp halve (tnat (n + n)) ==>* tnat n. 13 | 14 | 15 | -------------------------------------------------------------------------------- /assignments/01_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | (** **** Problem #2 : 1 star (zero_nbeq_plus_1) *) 4 | 5 | (* See the base file for the definition of [beq_nat]. *) 6 | 7 | Theorem zero_nbeq_plus_1 : forall n : nat, 8 | beq_nat 0 (n + 1) = false. 9 | Proof. 10 | destruct n. simpl. reflexivity. 11 | simpl. reflexivity. 12 | Qed. 13 | -------------------------------------------------------------------------------- /assignments/02_sol/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | (** **** Problem #3 : 3 stars (list_exercises) *) 6 | (** More practice with lists. *) 7 | 8 | Theorem app_nil_end : forall l : natlist, 9 | l ++ [] = l. 10 | Proof. 11 | intros. 12 | induction l. 13 | reflexivity. 14 | simpl. rewrite IHl. reflexivity. 15 | Qed. 16 | 17 | -------------------------------------------------------------------------------- /assignments/09/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | Theorem hoare_if_weakest : forall P1 P2 Q b c1 c2, 6 | is_wp P1 c1 Q -> 7 | is_wp P2 c2 Q -> 8 | is_wp (fun st => (beval st b = true -> P1 st) /\ (beval st b = false -> P2 st)) 9 | (IFB b THEN c1 ELSE c2 FI) Q. 10 | Proof. 11 | exact FILL_IN_HERE. 12 | Qed. 13 | 14 | -------------------------------------------------------------------------------- /assignments/12_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check halve_type: empty |- halve \in TArrow TNat TNat. 6 | 7 | Check halve_10: tapp halve (tnat 10) ==>* tnat 5. 8 | 9 | Check halve_11: tapp halve (tnat 11) ==>* tnat 5. 10 | 11 | Check halve_correct: forall n, 12 | tapp halve (tnat (n + n)) ==>* tnat n. 13 | 14 | 15 | -------------------------------------------------------------------------------- /assignments/01/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | (** **** Problem #3 : 2 stars (mult_S_1) *) 4 | Theorem mult_S_1 : forall n m : nat, 5 | m = S n -> 6 | m * (1 + n) = m * m. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | (*-- Check --*) 12 | 13 | Check mult_S_1 : forall n m : nat, 14 | m = S n -> 15 | m * (1 + n) = m * m. 16 | -------------------------------------------------------------------------------- /assignments/01_sol/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | Theorem negation_fn_applied_twice : 4 | forall (f : bool -> bool), 5 | (forall (x : bool), f x = negb x) -> 6 | forall (b : bool), f (f b) = b. 7 | Proof. 8 | intros. 9 | destruct b. 10 | rewrite -> H. rewrite -> H. reflexivity. 11 | rewrite -> H. rewrite -> H. reflexivity. 12 | Qed. 13 | -------------------------------------------------------------------------------- /assignments/02/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** **** Problem : 2 stars (double_plus) *) 6 | 7 | (* See [D.v] for the definition of [double] *) 8 | 9 | (** Use induction to prove this simple fact about [double]: *) 10 | 11 | Lemma double_plus : forall n, double n = n + n . 12 | Proof. 13 | exact FILL_IN_HERE. 14 | Qed. 15 | 16 | -------------------------------------------------------------------------------- /assignments/07/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P07. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (CIf_congruence) *) 6 | Theorem CIf_congruence : forall b b' c1 c1' c2 c2', 7 | bequiv b b' -> cequiv c1 c1' -> cequiv c2 c2' -> 8 | cequiv (IFB b THEN c1 ELSE c2 FI) 9 | (IFB b' THEN c1' ELSE c2' FI). 10 | Proof. exact FILL_IN_HERE. Qed. 11 | 12 | -------------------------------------------------------------------------------- /assignments/07/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | Import ListNotations. 3 | 4 | 5 | Check s_execute1 : 6 | s_execute empty_state [] 7 | [SPush 5; SPush 3; SPush 1; SMinus] 8 | = [2; 5]. 9 | 10 | Check s_execute2 : 11 | s_execute (t_update empty_state X 3) [3;4] 12 | [SPush 4; SLoad X; SMult; SPlus] 13 | = [15; 4]. 14 | 15 | -------------------------------------------------------------------------------- /assignments/01_sol/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | (** **** Problem #1 : 2 stars (mult_S_1) *) 4 | Theorem mult_S_1 : forall n m : nat, 5 | m = S n -> 6 | m * (1 + n) = m * m. 7 | Proof. 8 | intros. subst. reflexivity. 9 | Qed. 10 | 11 | (*-- Check --*) 12 | 13 | Check mult_S_1 : forall n m : nat, 14 | m = S n -> 15 | m * (1 + n) = m * m. 16 | -------------------------------------------------------------------------------- /assignments/02/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check 6 | (conj test_alternate1 7 | (conj test_alternate2 8 | (conj test_alternate3 9 | (test_alternate4)))) 10 | : 11 | alternate [1;2;3] [4;5;6] = [1;4;2;5;3;6] /\ 12 | alternate [1] [4;5;6] = [1;4;5;6] /\ 13 | alternate [1;2;3] [4] = [1;4;2;3] /\ 14 | alternate [] [20;30] = [20;30]. 15 | 16 | -------------------------------------------------------------------------------- /assignments/07_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | Import ListNotations. 3 | 4 | 5 | Check s_execute1 : 6 | s_execute empty_state [] 7 | [SPush 5; SPush 3; SPush 1; SMinus] 8 | = [2; 5]. 9 | 10 | Check s_execute2 : 11 | s_execute (t_update empty_state X 3) [3;4] 12 | [SPush 4; SLoad X; SMult; SPlus] 13 | = [15; 4]. 14 | 15 | -------------------------------------------------------------------------------- /assignments/09/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | Theorem hoare_skip_weakest : forall Q, 6 | is_wp Q SKIP Q. 7 | Proof. 8 | exact FILL_IN_HERE. 9 | Qed. 10 | 11 | Theorem hoare_seq_weakest : forall P Q R c1 c2, 12 | is_wp P c1 Q -> 13 | is_wp Q c2 R -> 14 | is_wp P (c1 ;; c2) R. 15 | Proof. 16 | exact FILL_IN_HERE. 17 | Qed. 18 | 19 | -------------------------------------------------------------------------------- /assignments/02_sol/E06_01.v: -------------------------------------------------------------------------------- 1 | Require Import P06. 2 | 3 | 4 | 5 | Check 6 | (conj test_alternate1 7 | (conj test_alternate2 8 | (conj test_alternate3 9 | (test_alternate4)))) 10 | : 11 | alternate [1;2;3] [4;5;6] = [1;4;2;5;3;6] /\ 12 | alternate [1] [4;5;6] = [1;4;5;6] /\ 13 | alternate [1;2;3] [4] = [1;4;2;3] /\ 14 | alternate [] [20;30] = [20;30]. 15 | 16 | -------------------------------------------------------------------------------- /assignments/01/D.v: -------------------------------------------------------------------------------- 1 | Definition FILL_IN_HERE {T: Type} : T. Admitted. 2 | 3 | Fixpoint beq_nat (n m : nat) : bool := 4 | match n with 5 | | O => match m with 6 | | O => true 7 | | S m' => false 8 | end 9 | | S n' => match m with 10 | | O => false 11 | | S m' => beq_nat n' m' 12 | end 13 | end. 14 | -------------------------------------------------------------------------------- /assignments/01_sol/D.v: -------------------------------------------------------------------------------- 1 | Definition FILL_IN_HERE {T: Type} : T. Admitted. 2 | 3 | Fixpoint beq_nat (n m : nat) : bool := 4 | match n with 5 | | O => match m with 6 | | O => true 7 | | S m' => false 8 | end 9 | | S n' => match m with 10 | | O => false 11 | | S m' => beq_nat n' m' 12 | end 13 | end. 14 | -------------------------------------------------------------------------------- /assignments/03_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | Theorem snoc_with_append : forall X : Type, 6 | forall l1 l2 : list X, 7 | forall v : X, 8 | snoc (l1 ++ l2) v = l1 ++ (snoc l2 v). 9 | Proof. 10 | intros. 11 | induction l1. 12 | - simpl. reflexivity. 13 | - simpl. rewrite IHl1. reflexivity. 14 | Qed. 15 | 16 | -------------------------------------------------------------------------------- /assignments/09/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars, advanced (hoare_asgn_weakest) *) 6 | (** Show that the precondition in the rule [hoare_asgn] is in fact the 7 | weakest precondition. *) 8 | 9 | Theorem hoare_asgn_weakest : forall Q X a, 10 | is_wp (Q [X |-> a]) (X ::= a) Q. 11 | Proof. 12 | exact FILL_IN_HERE. 13 | Qed. 14 | 15 | -------------------------------------------------------------------------------- /assignments/02_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | Theorem plus_zero : forall n : nat, n = n + 0. 5 | Proof. 6 | induction n. reflexivity. simpl. rewrite <- IHn. reflexivity. 7 | Qed. 8 | 9 | Theorem plus_comm : forall n m : nat, 10 | n + m = m + n. 11 | Proof. 12 | intros. 13 | induction n. 14 | - simpl. apply plus_zero. 15 | - simpl. rewrite IHn. apply plus_n_Sm. 16 | Qed. 17 | -------------------------------------------------------------------------------- /assignments/12/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (types_unique) *) 6 | (** Another pleasant property of the STLC is that types are 7 | unique: a given term (in a given context) has at most one 8 | type. *) 9 | 10 | Lemma type_is_unique: forall t G T T' 11 | (TYPED: G |- t \in T) 12 | (TYPED': G |- t \in T'), 13 | T = T'. 14 | Proof. 15 | exact FILL_IN_HERE. 16 | Qed. 17 | 18 | -------------------------------------------------------------------------------- /assignments/02_sol/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** **** Problem : 2 stars (double_plus) *) 6 | 7 | (* See [D.v] for the definition of [double] *) 8 | 9 | (** Use induction to prove this simple fact about [double]: *) 10 | 11 | Lemma double_plus : forall n, double n = n + n . 12 | Proof. 13 | intros. 14 | induction n. 15 | - reflexivity. 16 | - simpl. rewrite <- plus_n_Sm. rewrite IHn. reflexivity. 17 | Qed. 18 | 19 | -------------------------------------------------------------------------------- /assignments/04/P05.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Problem #13 : 3 stars (apply_exercise1) *) 6 | (** Hint: you can use [apply] with previously defined lemmas, not 7 | just hypotheses in the context. Remember that [SearchAbout] is 8 | your friend. *) 9 | 10 | Theorem rev_exercise1 : forall (l l' : list nat), 11 | l = rev l' -> 12 | l' = rev l. 13 | Proof. 14 | exact FILL_IN_HERE. 15 | Qed. 16 | 17 | -------------------------------------------------------------------------------- /assignments/07_sol/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, optional (CSeq_congruence) *) 6 | Theorem CSeq_congruence : forall c1 c1' c2 c2', 7 | cequiv c1 c1' -> cequiv c2 c2' -> 8 | cequiv (c1;;c2) (c1';;c2'). 9 | Proof. 10 | intros. 11 | unfold cequiv. 12 | split ; intros ; inversion H1 ; apply H in H4 ; apply H0 in H7. 13 | - eapply E_Seq. apply H4. apply H7. 14 | - eapply E_Seq. apply H4. apply H7. 15 | Qed. -------------------------------------------------------------------------------- /assignments/09/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check dopw2_down_correct: forall m, 6 | {{ fun st => True }} 7 | X ::= ANum 0;; 8 | Y ::= ANum 1;; 9 | Z ::= ANum 1;; 10 | WHILE BNot (BEq (AId X) (ANum m)) DO 11 | Z ::= AMult (ANum 2) (AId Z);; 12 | Y ::= APlus (AId Y) (AId Z);; 13 | X ::= APlus (AId X) (ANum 1) 14 | END 15 | {{ fun st => st Y = pow 2 (S m) - 1 }}. 16 | 17 | -------------------------------------------------------------------------------- /assignments/06/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check subseq_ex1: subseq [1;2;3] [1;2;3]. 6 | 7 | Check subseq_ex2: subseq [1;2;3] [1;1;1;2;2;3]. 8 | 9 | Check subseq_ex3: subseq [1;2;3] [1;2;7;3]. 10 | 11 | Check subseq_ex4: subseq [1;2;3] [5;6;1;9;9;2;7;3;8]. 12 | 13 | Check subseq_ex5: ~ subseq [1;2;3] [1;2]. 14 | 15 | Check subseq_ex6: ~ subseq [1;2;3] [1;3]. 16 | 17 | Check subseq_ex7: ~ subseq [1;2;3] [5;6;2;1;7;3;8]. 18 | 19 | -------------------------------------------------------------------------------- /assignments/09_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check dopw2_down_correct: forall m, 6 | {{ fun st => True }} 7 | X ::= ANum 0;; 8 | Y ::= ANum 1;; 9 | Z ::= ANum 1;; 10 | WHILE BNot (BEq (AId X) (ANum m)) DO 11 | Z ::= AMult (ANum 2) (AId Z);; 12 | Y ::= APlus (AId Y) (AId Z);; 13 | X ::= APlus (AId X) (ANum 1) 14 | END 15 | {{ fun st => st Y = pow 2 (S m) - 1 }}. 16 | 17 | -------------------------------------------------------------------------------- /assignments/06_sol/E08_01.v: -------------------------------------------------------------------------------- 1 | Require Import P08. 2 | 3 | 4 | 5 | Check subseq_ex1: subseq [1;2;3] [1;2;3]. 6 | 7 | Check subseq_ex2: subseq [1;2;3] [1;1;1;2;2;3]. 8 | 9 | Check subseq_ex3: subseq [1;2;3] [1;2;7;3]. 10 | 11 | Check subseq_ex4: subseq [1;2;3] [5;6;1;9;9;2;7;3;8]. 12 | 13 | Check subseq_ex5: ~ subseq [1;2;3] [1;2]. 14 | 15 | Check subseq_ex6: ~ subseq [1;2;3] [1;3]. 16 | 17 | Check subseq_ex7: ~ subseq [1;2;3] [5;6;2;1;7;3;8]. 18 | 19 | -------------------------------------------------------------------------------- /assignments/08/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars (if_minus_plus) *) 6 | (** Prove the following hoare triple using [hoare_if_wp]: *) 7 | 8 | Theorem if_minus_plus : 9 | {{fun st => True}} 10 | IFB (BLe (AId X) (AId Y)) 11 | THEN (Z ::= AMinus (AId Y) (AId X)) 12 | ELSE (Y ::= APlus (AId X) (AId Z)) 13 | FI 14 | {{fun st => st Y = st X + st Z}}. 15 | Proof. 16 | exact FILL_IN_HERE. 17 | Qed. 18 | 19 | -------------------------------------------------------------------------------- /assignments/04_sol/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | Theorem plus_n_n_injective : forall n m, 6 | n + n = m + m -> 7 | n = m. 8 | Proof. 9 | intros n. induction n as [| n']. 10 | - simpl. intros. destruct m. reflexivity. inversion H. 11 | - simpl. intros. rewrite <- plus_n_Sm in H. 12 | destruct m. inversion H. simpl in H. rewrite <- plus_n_Sm in H. 13 | inversion H. apply IHn' in H1. subst. reflexivity. 14 | Qed. 15 | 16 | -------------------------------------------------------------------------------- /assignments/04_sol/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | Theorem nth_error_after_last: forall (n : nat) (X : Type) (l : list X), 6 | length l = n -> 7 | nth_error l n = None. 8 | Proof. 9 | intros. 10 | generalize dependent n. 11 | induction l. 12 | - simpl. intros. reflexivity. 13 | - intros. destruct n. 14 | + simpl in H. inversion H. 15 | + simpl in H. inversion H. 16 | assert (H2 := H1). 17 | apply IHl in H1. 18 | simpl. subst. assumption. 19 | Qed. 20 | 21 | -------------------------------------------------------------------------------- /assignments/05_sol/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | Theorem dist_exists_or : forall (X:Type) (P Q : X -> Prop), 6 | (exists x, P x \/ Q x) <-> (exists x, P x) \/ (exists x, Q x). 7 | Proof. 8 | intros. 9 | split. 10 | - intros. 11 | inversion H. 12 | destruct H0. 13 | + left. exists x. assumption. 14 | + right. exists x. assumption. 15 | - intros. 16 | destruct H. 17 | inversion H. 18 | + exists x. left. assumption. 19 | + inversion H. 20 | exists x. right. assumption. 21 | Qed. 22 | -------------------------------------------------------------------------------- /assignments/07_sol/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | Print loop. 4 | 5 | (** **** Exercise: 3 stars, recommended (loop_never_stops) *) 6 | Theorem loop_never_stops : forall st st', 7 | ~(loop / st \\ st'). 8 | Proof. 9 | intros st st' contra. unfold loop in contra. 10 | remember (WHILE BTrue DO SKIP END) as loopdef 11 | eqn:Heqloopdef. 12 | induction contra ; try inversion Heqloopdef. 13 | subst. simpl in H. inversion H. 14 | subst. apply IHcontra2. apply Heqloopdef. 15 | Qed. 16 | 17 | -------------------------------------------------------------------------------- /assignments/10/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | (* Hint: 6 | 7 | First study the chapter "Auto.v". 8 | 9 | Using [;], [try] and [eauto], you can prove it in 6 lines thanks to: 10 | Hint Constructors cstep. 11 | 12 | You can use the following intro pattern: 13 | destruct ... as [ | [? [? ?]]]. 14 | *) 15 | 16 | Theorem cimp_strong_progress : forall c st, 17 | c = SKIP \/ 18 | exists c' st', c / st ==> c' / st'. 19 | Proof. 20 | exact FILL_IN_HERE. 21 | Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/03/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** **** Problem #1 : 2 stars, optional (poly_exercises) *) 6 | (** Here are a few simple exercises, just like ones in the [Lists] 7 | chapter, for practice with polymorphism. Fill in the definitions 8 | and complete the proofs below. *) 9 | 10 | Fixpoint repeat {X : Type} (n : X) (count : nat) : list X := 11 | FILL_IN_HERE. 12 | 13 | Example test_repeat1: 14 | repeat true 2 = cons true (cons true nil). 15 | Proof. exact FILL_IN_HERE. Qed. 16 | 17 | -------------------------------------------------------------------------------- /assignments/10/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (* Hint: 6 | 7 | First study the chapter "Auto.v". 8 | 9 | Using [;], [try] and [eauto], you can prove it in 7 lines thanks to:. 10 | Hint Constructors bstep. 11 | 12 | You can use the following intro pattern: 13 | destruct ... as [[? | ?] | [? ?]]. 14 | *) 15 | 16 | Theorem bexp_strong_progress: forall st b, 17 | (b = BTrue \/ b = BFalse) \/ 18 | exists b', b / st ==>b b'. 19 | Proof. 20 | exact FILL_IN_HERE. 21 | Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/04/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** Addition of two natural numbers: *) 6 | 7 | Definition c_plus (n m : c_nat) : c_nat := 8 | FILL_IN_HERE. 9 | 10 | Example c_plus_1 : c_plus c_zero c_one = c_one. 11 | Proof. exact FILL_IN_HERE. Qed. 12 | 13 | Example c_plus_2 : c_plus c_two c_three = c_plus c_three c_two. 14 | Proof. exact FILL_IN_HERE. Qed. 15 | 16 | Example c_plus_3 : 17 | c_plus (c_plus c_two c_two) c_three = c_plus c_one (c_plus c_three c_three). 18 | Proof. exact FILL_IN_HERE. Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/04_sol/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** Addition of two natural numbers: *) 6 | 7 | Definition c_plus (n m : c_nat) : c_nat := 8 | fun (X:Type) f x => n X f (m X f x). 9 | 10 | Example c_plus_1 : c_plus c_zero c_one = c_one. 11 | Proof. reflexivity. Qed. 12 | 13 | Example c_plus_2 : c_plus c_two c_three = c_plus c_three c_two. 14 | Proof. reflexivity. Qed. 15 | 16 | Example c_plus_3 : 17 | c_plus (c_plus c_two c_two) c_three = c_plus c_one (c_plus c_three c_three). 18 | Proof. reflexivity. Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/07_sol/P12.v: -------------------------------------------------------------------------------- 1 | Require Export P11. 2 | 3 | 4 | 5 | Lemma optimize_0plus_bexp_sound: 6 | btrans_sound optimize_0plus_bexp. 7 | Proof. 8 | unfold btrans_sound. 9 | unfold bequiv. 10 | intros. 11 | induction b ; simpl; try reflexivity; (* BTrue, BFalse *) 12 | try (rewrite optimize_0plus_aexp_sound; 13 | rewrite optimize_0plus_aexp_sound with (a := a0); 14 | auto; fail); (* BEq, BLe *) 15 | try (simpl; rewrite IHb; auto); (* BNot *) 16 | try (simpl; rewrite IHb1 ; rewrite IHb2 ; auto). (* BAnd *) 17 | Qed. 18 | 19 | -------------------------------------------------------------------------------- /assignments/05_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | Theorem or_distributes_over_and : forall P Q R : Prop, 6 | P \/ (Q /\ R) <-> (P \/ Q) /\ (P \/ R). 7 | Proof. 8 | intros. 9 | split. 10 | - intros. 11 | destruct H. 12 | split. left. assumption. left. assumption. 13 | destruct H. 14 | split. right. assumption. right. assumption. 15 | - intros. 16 | inversion H. 17 | inversion H0. 18 | + left. assumption. 19 | + inversion H1. 20 | left. assumption. 21 | right. split ; assumption. 22 | Qed. 23 | 24 | -------------------------------------------------------------------------------- /assignments/09/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check add_three_numbers_correct: forall a b c, 6 | {{ fun st => True }} 7 | X ::= ANum 0;; 8 | Y ::= ANum 0;; 9 | Z ::= ANum c;; 10 | WHILE BNot (BEq (AId X) (ANum a)) DO 11 | X ::= APlus (AId X) (ANum 1);; 12 | Z ::= APlus (AId Z) (ANum 1) 13 | END;; 14 | WHILE BNot (BEq (AId Y) (ANum b)) DO 15 | Y ::= APlus (AId Y) (ANum 1);; 16 | Z ::= APlus (AId Z) (ANum 1) 17 | END 18 | {{ fun st => st Z = a + b + c }}. 19 | 20 | -------------------------------------------------------------------------------- /assignments/10/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (* Hint: 6 | 7 | First study the chapter "Auto.v". 8 | 9 | Using [;], [try] and [eauto], you can prove it in 4 lines thanks to: 10 | Hint Constructors aval 11 | Hint Constructors astep. 12 | 13 | You can use the following intro pattern: 14 | destruct ... as [[? ?] | [? ?]]. 15 | *) 16 | 17 | Theorem aexp_strong_progress: forall st a, 18 | (exists n, a = ANum n) \/ 19 | exists a', a / st ==>a a'. 20 | Proof. 21 | exact FILL_IN_HERE. 22 | Qed. 23 | 24 | -------------------------------------------------------------------------------- /assignments/09_sol/E02_01.v: -------------------------------------------------------------------------------- 1 | Require Import P02. 2 | 3 | 4 | 5 | Check add_three_numbers_correct: forall a b c, 6 | {{ fun st => True }} 7 | X ::= ANum 0;; 8 | Y ::= ANum 0;; 9 | Z ::= ANum c;; 10 | WHILE BNot (BEq (AId X) (ANum a)) DO 11 | X ::= APlus (AId X) (ANum 1);; 12 | Z ::= APlus (AId Z) (ANum 1) 13 | END;; 14 | WHILE BNot (BEq (AId Y) (ANum b)) DO 15 | Y ::= APlus (AId Y) (ANum 1);; 16 | Z ::= APlus (AId Z) (ANum 1) 17 | END 18 | {{ fun st => st Z = a + b + c }}. 19 | 20 | -------------------------------------------------------------------------------- /assignments/04/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | (** Multiplication: *) 5 | 6 | Definition c_mult (n m : c_nat) : c_nat := 7 | FILL_IN_HERE. 8 | 9 | Example c_mult_1 : c_mult c_one c_one = c_one. 10 | Proof. exact FILL_IN_HERE. Qed. 11 | 12 | Example c_mult_2 : c_mult c_zero (c_plus c_three c_three) = c_zero. 13 | Proof. exact FILL_IN_HERE. Qed. 14 | 15 | (** Oct. 20 : You have to copy definition of c_plus here from P03.v. **) 16 | 17 | Example c_mult_3 : c_mult c_two c_three = c_plus c_three c_three. 18 | Proof. exact FILL_IN_HERE. Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/04_sol/P09.v: -------------------------------------------------------------------------------- 1 | 2 | 3 | Require Export P04. 4 | 5 | 6 | 7 | Theorem filter_exercise : forall (X : Type) (test : X -> bool) 8 | (x : X) (l lf : list X), 9 | filter test l = x :: lf -> 10 | test x = true. 11 | Proof. 12 | intros X test x l lf. 13 | induction l as [ | x' l' IHl]. 14 | - intros H. simpl in H. inversion H. 15 | - simpl. 16 | intros. 17 | remember (test x') as t. 18 | destruct t. 19 | + inversion H. rewrite <- H1. symmetry. apply Heqt. 20 | + apply IHl. assumption. 21 | Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/07/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check optimize_0plus_b_example1: 6 | optimize_0plus_b (BEq 7 | (AMult (APlus (ANum 0) (APlus (ANum 0) (ANum 3))) 8 | (AMinus (ANum 5) (APlus (ANum 0) (ANum 1)))) 9 | (APlus (ANum 2) 10 | (APlus (ANum 0) 11 | (APlus (ANum 0) (ANum 1))))) 12 | = (BEq (AMult (ANum 3) (AMinus (ANum 5) (ANum 1))) 13 | (APlus (ANum 2) (ANum 1))). 14 | 15 | Check optimize_0plus_b_sound : forall st b, 16 | beval st (optimize_0plus_b b) = beval st b. 17 | 18 | -------------------------------------------------------------------------------- /assignments/07_sol/E03_01.v: -------------------------------------------------------------------------------- 1 | Require Import P03. 2 | 3 | 4 | 5 | Check optimize_0plus_b_example1: 6 | optimize_0plus_b (BEq 7 | (AMult (APlus (ANum 0) (APlus (ANum 0) (ANum 3))) 8 | (AMinus (ANum 5) (APlus (ANum 0) (ANum 1)))) 9 | (APlus (ANum 2) 10 | (APlus (ANum 0) 11 | (APlus (ANum 0) (ANum 1))))) 12 | = (BEq (AMult (ANum 3) (AMinus (ANum 5) (ANum 1))) 13 | (APlus (ANum 2) (ANum 1))). 14 | 15 | Check optimize_0plus_b_sound : forall st b, 16 | beval st (optimize_0plus_b b) = beval st b. 17 | 18 | -------------------------------------------------------------------------------- /assignments/04_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** Multiplication: *) 6 | 7 | Definition c_mult (n m : c_nat) : c_nat := 8 | fun (X:Type) f x => n X (m X f) x. 9 | 10 | Example c_mult_1 : c_mult c_one c_one = c_one. 11 | Proof. reflexivity. Qed. 12 | 13 | Example c_mult_2 : c_mult c_zero (c_plus c_three c_three) = c_zero. 14 | Proof. reflexivity. Qed. 15 | 16 | Definition c_plus (n m : c_nat) : c_nat := 17 | fun (X:Type) f x => m X f (n X f x). 18 | 19 | Example c_mult_3 : c_mult c_two c_three = c_plus c_three c_three. 20 | Proof. reflexivity. Qed. 21 | 22 | -------------------------------------------------------------------------------- /assignments/07/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, recommended (t_update_permute) *) 6 | (** Use [beq_idP] to prove one final property of the [update] 7 | function: If we update a map [m] at two distinct keys, it doesn't 8 | matter in which order we do the updates. *) 9 | 10 | Theorem t_update_permute : forall (X:Type) v1 v2 x1 x2 11 | (m : total_map X), 12 | x2 <> x1 -> 13 | (t_update (t_update m x2 v2) x1 v1) 14 | = (t_update (t_update m x1 v1) x2 v2). 15 | Proof. exact FILL_IN_HERE. Qed. 16 | 17 | -------------------------------------------------------------------------------- /assignments/00/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | (** **** Problem #3: 2 stars (blt_nat) *) 4 | (** The [blt_nat] function tests [nat]ural numbers for [l]ess-[t]han, 5 | yielding a [b]oolean. Use [Fixpoint] to define it. *) 6 | 7 | Fixpoint blt_nat (n m : nat) : bool := 8 | FILL_IN_HERE. 9 | 10 | Example test_blt_nat1: (blt_nat 2 2) = false. 11 | exact FILL_IN_HERE. Qed. 12 | Example test_blt_nat2: (blt_nat 2 4) = true. 13 | exact FILL_IN_HERE. Qed. 14 | Example test_blt_nat3: (blt_nat 4 2) = false. 15 | exact FILL_IN_HERE. Qed. 16 | (** [] *) 17 | -------------------------------------------------------------------------------- /assignments/03_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** **** Problem #1 : 2 stars, optional (poly_exercises) *) 6 | (** Here are a few simple exercises, just like ones in the [Lists] 7 | chapter, for practice with polymorphism. Fill in the definitions 8 | and complete the proofs below. *) 9 | 10 | Fixpoint repeat {X : Type} (n : X) (count : nat) : list X := 11 | match count with 12 | | O => [] 13 | | S count' => n :: (repeat n count') 14 | end. 15 | 16 | Example test_repeat1: 17 | repeat true 2 = cons true (cons true nil). 18 | Proof. reflexivity. Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/01/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | (** **** Problem #2: 2 stars (blt_nat) *) 4 | (** The [blt_nat] function tests [nat]ural numbers for [l]ess-[t]han, 5 | yielding a [b]oolean. Use [Fixpoint] to define it. *) 6 | 7 | Definition blt_nat (n m : nat) : bool := 8 | FILL_IN_HERE. 9 | 10 | Example test_blt_nat1: (blt_nat 2 2) = false. 11 | Proof. exact FILL_IN_HERE. Qed. 12 | Example test_blt_nat2: (blt_nat 2 4) = true. 13 | Proof. exact FILL_IN_HERE. Qed. 14 | Example test_blt_nat3: (blt_nat 4 2) = false. 15 | Proof. exact FILL_IN_HERE. Qed. 16 | -------------------------------------------------------------------------------- /assignments/02_sol/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P07. 2 | 3 | 4 | 5 | (** Hint: You may need to first state and prove some lemma about snoc and rev. *) 6 | 7 | Lemma rev_snoc : forall (h:nat) (t:natlist), 8 | h::(rev t) = rev (snoc t h). 9 | Proof. 10 | intros. 11 | induction t. 12 | - simpl. reflexivity. 13 | - simpl. intros. 14 | rewrite <- IHt. 15 | simpl. 16 | reflexivity. 17 | Qed. 18 | 19 | Theorem rev_involutive : forall l : natlist, 20 | rev (rev l) = l. 21 | Proof. 22 | intros. 23 | induction l. 24 | - reflexivity. 25 | - simpl. rewrite <- rev_snoc. rewrite IHl. reflexivity. 26 | Qed. 27 | 28 | -------------------------------------------------------------------------------- /assignments/04/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** Complete the definitions of the following functions. Make sure 6 | that the corresponding unit tests pass by proving them with 7 | [reflexivity]. *) 8 | 9 | (** Successor of a natural number: *) 10 | 11 | Definition c_succ (n : c_nat) : c_nat := 12 | FILL_IN_HERE. 13 | 14 | Example c_succ_1 : c_succ c_zero = c_one. 15 | Proof. exact FILL_IN_HERE. Qed. 16 | 17 | Example c_succ_2 : c_succ c_one = c_two. 18 | Proof. exact FILL_IN_HERE. Qed. 19 | 20 | Example c_succ_3 : c_succ c_two = c_three. 21 | Proof. exact FILL_IN_HERE. Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/04_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** Complete the definitions of the following functions. Make sure 6 | that the corresponding unit tests pass by proving them with 7 | [reflexivity]. *) 8 | 9 | (** Successor of a natural number: *) 10 | 11 | Definition c_succ (n : c_nat) : c_nat := 12 | fun (X:Type) f x => n X f (f x). 13 | 14 | Example c_succ_1 : c_succ c_zero = c_one. 15 | Proof. reflexivity. Qed. 16 | 17 | Example c_succ_2 : c_succ c_one = c_two. 18 | Proof. reflexivity. Qed. 19 | 20 | Example c_succ_3 : c_succ c_two = c_three. 21 | Proof. reflexivity. Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/07/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars, optional (t_update_shadow) *) 6 | (** If we update a map [m] at a key [x] with a value [v1] and then 7 | update again with the same key [x] and another value [v2], the 8 | resulting map behaves the same (gives the same result when applied 9 | to any key) as the simpler map obtained by performing just 10 | the second [update] on [m]: *) 11 | 12 | Lemma t_update_shadow : forall A (m: total_map A) v1 v2 x, 13 | t_update (t_update m x v1) x v2 14 | = t_update m x v2. 15 | Proof. exact FILL_IN_HERE. Qed. 16 | 17 | -------------------------------------------------------------------------------- /assignments/07/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, recommended (loop_never_stops) *) 6 | Theorem loop_never_stops : forall st st', 7 | ~(loop / st \\ st'). 8 | Proof. 9 | intros st st' contra. unfold loop in contra. 10 | remember (WHILE BTrue DO SKIP END) as loopdef 11 | eqn:Heqloopdef. 12 | 13 | (** Proceed by induction on the assumed derivation showing that 14 | [loopdef] terminates. Most of the cases are immediately 15 | contradictory (and so can be solved in one step with 16 | [inversion]). *) 17 | 18 | exact FILL_IN_HERE. 19 | Qed. 20 | 21 | -------------------------------------------------------------------------------- /assignments/06/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | (** **** Exercise: 4 stars, advanced (ev_alternate) *) 6 | (** In general, there may be multiple ways of defining a 7 | property inductively. For example, here's a (slightly contrived) 8 | alternative definition for [ev]: *) 9 | 10 | (* 11 | Inductive ev' : nat -> Prop := 12 | | ev'_0 : ev' 0 13 | | ev'_2 : ev' 2 14 | | ev'_sum : forall n m, ev' n -> ev' m -> ev' (n + m). 15 | *) 16 | 17 | (** Prove that this definition is logically equivalent to 18 | the old one. *) 19 | 20 | Theorem ev'_ev : forall n, ev' n <-> ev n. 21 | Proof. exact FILL_IN_HERE. Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/10/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** The fact that small-step reduction implies big-step is now 6 | straightforward to prove, once it is stated correctly. 7 | 8 | The proof proceeds by induction on the multi-step reduction 9 | sequence that is buried in the hypothesis [normal_form_of t t']. *) 10 | (** Make sure you understand the statement before you start to 11 | work on the proof. *) 12 | 13 | (** **** Exercise: 3 stars (multistep__eval) *) 14 | Theorem multistep__eval : forall t t', 15 | normal_form_of t t' -> exists n, t' = C n /\ t \\ n. 16 | Proof. 17 | exact FILL_IN_HERE. 18 | Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/09_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars, advanced (hoare_asgn_weakest) *) 6 | (** Show that the precondition in the rule [hoare_asgn] is in fact the 7 | weakest precondition. *) 8 | 9 | Theorem hoare_asgn_weakest : forall Q X a, 10 | is_wp (Q [X |-> a]) (X ::= a) Q. 11 | Proof. 12 | intros. 13 | unfold is_wp. 14 | split. 15 | - eapply hoare_consequence_pre. 16 | apply hoare_asgn. 17 | unfold "->>". 18 | auto. 19 | - unfold "->>". 20 | intros. 21 | unfold hoare_triple in H. 22 | unfold assn_sub. 23 | apply (H st). 24 | constructor. 25 | reflexivity. assumption. 26 | Qed. 27 | 28 | -------------------------------------------------------------------------------- /assignments/06/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** It is a theorem of classical logic that the following two 6 | assertions are equivalent: 7 | 8 | ~ (exists x, ~ P x) 9 | forall x, P x 10 | 11 | The [dist_not_exists] theorem above proves one side of this 12 | equivalence. Interestingly, the other direction cannot be proved 13 | in constructive logic. Your job is to show that it is implied by 14 | the excluded middle. *) 15 | 16 | Theorem not_exists_dist : 17 | excluded_middle -> 18 | forall (X:Type) (P : X -> Prop), 19 | ~ (exists x, ~ P x) -> (forall x, P x). 20 | Proof. exact FILL_IN_HERE. Qed. 21 | 22 | -------------------------------------------------------------------------------- /assignments/06_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | Lemma evenb_flip: forall n, 5 | evenb (S n) = negb (evenb n). 6 | Proof. 7 | induction n. 8 | - auto. 9 | - simpl. simpl in IHn. rewrite IHn. 10 | destruct (evenb n) ; auto. 11 | Qed. 12 | 13 | Theorem evenb_double_conv : forall n, 14 | exists k, n = if evenb n then double k 15 | else S (double k). 16 | Proof. 17 | intros. 18 | induction n. 19 | - exists 0. 20 | reflexivity. 21 | - destruct IHn. 22 | destruct (evenb n) eqn:Heqev. 23 | + exists x. rewrite evenb_flip. rewrite Heqev. simpl. auto. 24 | + exists (S x). rewrite evenb_flip. rewrite Heqev. simpl. auto. 25 | Qed. 26 | 27 | -------------------------------------------------------------------------------- /assignments/07/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, advanced (pup_to_n) *) 6 | (** Write an Imp program that sums the numbers from [1] to 7 | [X] (inclusive: [1 + 2 + ... + X]) in the variable [Y]. 8 | Prove that this program executes as intended for [X] = [2] 9 | (the latter is trickier than you might expect). *) 10 | 11 | Definition pup_to_n : com := 12 | FILL_IN_HERE. 13 | 14 | Theorem pup_to_2_ceval : 15 | pup_to_n / (t_update empty_state X 2) \\ 16 | t_update (t_update (t_update (t_update (t_update (t_update empty_state 17 | X 2) Y 0) Y 2) X 1) Y 3) X 0. 18 | Proof. exact FILL_IN_HERE. Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/01_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | (** **** Problem #3: 2 stars (blt_nat) *) 4 | (** The [blt_nat] function tests [nat]ural numbers for [l]ess-[t]han, 5 | yielding a [b]oolean. Use [Fixpoint] to define it. *) 6 | 7 | Fixpoint blt_nat (n m : nat) : bool := 8 | match m with 9 | | O => false 10 | | S m' => (match n with | O => true | S n' => blt_nat n' m' end) 11 | end. 12 | 13 | Example test_blt_nat1: (blt_nat 2 2) = false. 14 | Proof. reflexivity. Qed. 15 | Example test_blt_nat2: (blt_nat 2 4) = true. 16 | Proof. reflexivity. Qed. 17 | Example test_blt_nat3: (blt_nat 4 2) = false. 18 | Proof. reflexivity. Qed. 19 | -------------------------------------------------------------------------------- /assignments/07_sol/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P07. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (CIf_congruence) *) 6 | Theorem CIf_congruence : forall b b' c1 c1' c2 c2', 7 | bequiv b b' -> cequiv c1 c1' -> cequiv c2 c2' -> 8 | cequiv (IFB b THEN c1 ELSE c2 FI) 9 | (IFB b' THEN c1' ELSE c2' FI). 10 | Proof. 11 | intros. 12 | unfold cequiv. 13 | split. 14 | - intros. 15 | inversion H2 ; subst ; rewrite H in H8. 16 | apply H0 in H9. eapply E_IfTrue ; assumption. 17 | apply H1 in H9. eapply E_IfFalse ; assumption. 18 | - intros. 19 | inversion H2 ; subst ; rewrite <- H in H8. 20 | apply H0 in H9. eapply E_IfTrue ; assumption. 21 | apply H1 in H9. eapply E_IfFalse ; assumption. 22 | Qed. -------------------------------------------------------------------------------- /assignments/02_sol/P10.v: -------------------------------------------------------------------------------- 1 | Require Export P09. 2 | 3 | 4 | Lemma natlist_nil : forall l : natlist, 5 | l ++ [] = l. 6 | Proof. 7 | intros. induction l. reflexivity. simpl. rewrite IHl. reflexivity. 8 | Qed. 9 | 10 | Lemma snoc_append : forall (l1 l2 : natlist) (n : nat), 11 | snoc (l1 ++ l2) n = l1 ++ (snoc l2 n). 12 | Proof. 13 | intros. 14 | induction l1. 15 | - simpl. reflexivity. 16 | - simpl. rewrite IHl1. reflexivity. 17 | Qed. 18 | 19 | Theorem distr_rev : forall l1 l2 : natlist, 20 | rev (l1 ++ l2) = (rev l2) ++ (rev l1). 21 | Proof. 22 | intros. 23 | induction l1. 24 | - simpl. rewrite natlist_nil. reflexivity. 25 | - simpl. rewrite IHl1. rewrite snoc_append. reflexivity. 26 | Qed. 27 | 28 | -------------------------------------------------------------------------------- /assignments/11/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, advanced (value_is_nf) *) 6 | (** Hint: You will reach a point in this proof where you need to 7 | use an induction to reason about a term that is known to be a 8 | numeric value. This induction can be performed either over the 9 | term itself or over the evidence that it is a numeric value. The 10 | proof goes through in either case, but you will find that one way 11 | is quite a bit shorter than the other. For the sake of the 12 | exercise, try to complete the proof both ways. *) 13 | 14 | Lemma value_is_nf : forall t, 15 | value t -> step_normal_form t. 16 | Proof. 17 | exact FILL_IN_HERE. 18 | Qed. 19 | 20 | -------------------------------------------------------------------------------- /assignments/03/P05.v: -------------------------------------------------------------------------------- 1 | Require Export P04. 2 | 3 | 4 | 5 | (** **** Problem #2 : 1 star, optional (hd_opt_poly) *) 6 | (** Complete the definition of a polymorphic version of the 7 | [hd_opt] function from the last chapter. Be sure that it 8 | passes the unit tests below. *) 9 | 10 | Definition hd_opt {X : Type} (l : list X) : option X := 11 | FILL_IN_HERE. 12 | 13 | (** Once again, to force the implicit arguments to be explicit, 14 | we can use [@] before the name of the function. *) 15 | 16 | Check @hd_opt. 17 | 18 | Example test_hd_opt1 : hd_opt [1;2] = Some 1. 19 | Proof. exact FILL_IN_HERE. Qed. 20 | 21 | Example test_hd_opt2 : hd_opt [[1];[2]] = Some [1]. 22 | Proof. exact FILL_IN_HERE. Qed. 23 | 24 | -------------------------------------------------------------------------------- /sf/README: -------------------------------------------------------------------------------- 1 | ######################################################################### 2 | SOFTWARE FOUNDATIONS 3 | ######################################################################### 4 | 5 | This directory contains both Coq scripts (.v files) and more readable 6 | HTML files for the Software Foundations electronic textbook. 7 | 8 | - Preface.v or Preface.html 9 | The place to start reading, including details on how to install 10 | required software 11 | 12 | - index.html 13 | The book's cover page and navigation starting point 14 | 15 | - deps.html 16 | Overview of the ordering of chapters 17 | 18 | - LICENSE 19 | Explanation of how these files may be redistributed 20 | -------------------------------------------------------------------------------- /assignments/01/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | (** **** Problem #1: 1 star (factorial) *) 4 | (** Recall the standard factorial function: 5 | << 6 | factorial(0) = 1 7 | factorial(n) = n * factorial(n-1) (if n>0) 8 | >> 9 | Translate this into Coq. 10 | 11 | Note that plus and multiplication are already defined in Coq. 12 | use "+" for plus and "*" for multiplication. 13 | *) 14 | 15 | Eval compute in 3 * 5. 16 | Eval compute in 3+5*6. 17 | 18 | Fixpoint factorial (n:nat) : nat := 19 | FILL_IN_HERE. 20 | 21 | Example test_factorial1: (factorial 3) = 6. 22 | Proof. exact FILL_IN_HERE. Qed. 23 | Example test_factorial2: (factorial 5) = 10 * 12. 24 | Proof. exact FILL_IN_HERE. Qed. 25 | -------------------------------------------------------------------------------- /assignments/00/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | (** **** Problem #2: 1 star (factorial) *) 4 | (** Recall the standard factorial function: 5 | << 6 | factorial(0) = 1 7 | factorial(n) = n * factorial(n-1) (if n>0) 8 | >> 9 | Translate this into Coq. 10 | 11 | Note that plus and multiplication are already defined in Coq. 12 | use "+" for plus and "*" for multiplication. 13 | *) 14 | 15 | Eval compute in 3 * 5. 16 | Eval compute in 3+5*6. 17 | 18 | Fixpoint factorial (n:nat) : nat := 19 | FILL_IN_HERE. 20 | 21 | Example test_factorial1: (factorial 3) = 6. 22 | exact FILL_IN_HERE. Qed. 23 | Example test_factorial2: (factorial 5) = 10 * 12. 24 | exact FILL_IN_HERE. Qed. 25 | (** [] *) 26 | -------------------------------------------------------------------------------- /sf/main.js: -------------------------------------------------------------------------------- 1 | function toggleDisplay(id) 2 | { 3 | var elt = document.getElementById(id); 4 | if (elt.style.display == 'none') { 5 | elt.style.display = 'block'; 6 | } else { 7 | elt.style.display = 'none'; 8 | } 9 | } 10 | function hideAll(cls) 11 | { 12 | var testClass = new RegExp("(^|s)" + cls + "(s|$)"); 13 | var tag = tag || "*"; 14 | var elements = document.getElementsByTagName("div"); 15 | var current; 16 | var length = elements.length; 17 | for(var i=0; i None 13 | | h::t => Some h 14 | end. 15 | 16 | (** Once again, to force the implicit arguments to be explicit, 17 | we can use [@] before the name of the function. *) 18 | 19 | Check @hd_opt. 20 | 21 | Example test_hd_opt1 : hd_opt [1;2] = Some 1. 22 | Proof. reflexivity. Qed. 23 | 24 | Example test_hd_opt2 : hd_opt [[1];[2]] = Some [1]. 25 | Proof. reflexivity. Qed. 26 | 27 | -------------------------------------------------------------------------------- /assignments/06/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** Given a boolean operator [beq] for testing equality of elements of 6 | some type [A], we can define a function [beq_list beq] for testing 7 | equality of lists with elements in [A]. Complete the definition 8 | of the [beq_list] function below. To make sure that your 9 | definition is correct, prove the lemma [beq_list_true_iff]. *) 10 | 11 | Fixpoint beq_list {A} (beq : A -> A -> bool) 12 | (l1 l2 : list A) : bool := 13 | FILL_IN_HERE. 14 | 15 | Lemma beq_list_true_iff : 16 | forall A (beq : A -> A -> bool), 17 | (forall a1 a2, beq a1 a2 = true <-> a1 = a2) -> 18 | forall l1 l2, beq_list beq l1 l2 = true <-> l1 = l2. 19 | Proof. exact FILL_IN_HERE. Qed. 20 | 21 | -------------------------------------------------------------------------------- /assignments/01_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | (** **** Problem #2: 1 star (factorial) *) 4 | (** Recall the standard factorial function: 5 | << 6 | factorial(0) = 1 7 | factorial(n) = n * factorial(n-1) (if n>0) 8 | >> 9 | Translate this into Coq. 10 | 11 | Note that plus and multiplication are already defined in Coq. 12 | use "+" for plus and "*" for multiplication. 13 | *) 14 | 15 | Eval compute in 3 * 5. 16 | Eval compute in 3+5*6. 17 | 18 | Fixpoint factorial (n:nat) : nat := 19 | match n with | 0 => 1 | S n' => n * (factorial n') end. 20 | 21 | Example test_factorial1: (factorial 3) = 6. 22 | Proof. simpl. reflexivity. Qed. 23 | Example test_factorial2: (factorial 5) = 10 * 12. 24 | Proof. simpl. reflexivity. Qed. 25 | -------------------------------------------------------------------------------- /assignments/07_sol/P15.v: -------------------------------------------------------------------------------- 1 | Require Export P14. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars, optional (inequiv_exercise) *) 6 | (** Prove that an infinite loop is not equivalent to [SKIP] *) 7 | 8 | Lemma inequiv_never_end: forall st st', 9 | ~ (WHILE BTrue DO SKIP END) / st \\ st'. 10 | Proof. 11 | unfold not. 12 | remember (WHILE BTrue DO SKIP END) as c. 13 | intros. 14 | induction H ; try (inversion Heqc ; fail). 15 | - inversion Heqc. subst. simpl in H. inversion H. 16 | - apply IHceval2 in Heqc. assumption. 17 | Qed. 18 | 19 | 20 | Theorem inequiv_exercise: 21 | ~ cequiv (WHILE BTrue DO SKIP END) SKIP. 22 | Proof. 23 | unfold not. 24 | unfold cequiv. 25 | intros. 26 | assert (H'' := inequiv_never_end empty_state empty_state). 27 | apply H''. 28 | apply H. 29 | constructor. 30 | Qed. 31 | 32 | -------------------------------------------------------------------------------- /assignments/skeleton/Makefile.skeleton: -------------------------------------------------------------------------------- 1 | PFILES = $(shell find P??.v) 2 | EFILES = $(shell find E??_??.v) 3 | 4 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 5 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 6 | 7 | all: $(DFILES) $(PFILES) Makefile.coq 8 | $(MAKE) -f Makefile.coq $(POFILES) 9 | 10 | check: 11 | bash ./check.sh 12 | 13 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 14 | $(MAKE) -f Makefile.coq $(EOFILES) 15 | 16 | submission: 17 | zip submission.zip P??.v 18 | 19 | %.vo: Makefile.coq 20 | $(MAKE) -f Makefile.coq "$@" 21 | 22 | clean: Makefile.coq 23 | $(MAKE) -f Makefile.coq clean 24 | rm _CoqProject Makefile.coq 25 | 26 | Makefile.coq: Makefile $(PFILES) $(EFILES) 27 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 28 | coq_makefile -f _CoqProject -o Makefile.coq 29 | -------------------------------------------------------------------------------- /assignments/00/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/01/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/01_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/06_sol/P03.v: -------------------------------------------------------------------------------- 1 | 2 | 3 | Require Export P02. 4 | 5 | 6 | 7 | (** It is a theorem of classical logic that the following two 8 | assertions are equivalent: 9 | 10 | ~ (exists x, ~ P x) 11 | forall x, P x 12 | 13 | The [dist_not_exists] theorem above proves one side of this 14 | equivalence. Interestingly, the other direction cannot be proved 15 | in constructive logic. Your job is to show that it is implied by 16 | the excluded middle. *) 17 | 18 | Theorem not_exists_dist : 19 | excluded_middle -> 20 | forall (X:Type) (P : X -> Prop), 21 | ~ (exists x, ~ P x) -> (forall x, P x). 22 | Proof. 23 | intros. 24 | unfold excluded_middle in H. 25 | assert (H' := H (P x)). 26 | inversion H'. 27 | assumption. 28 | exfalso. 29 | apply H0. 30 | exists x. 31 | assumption. 32 | Qed. 33 | 34 | -------------------------------------------------------------------------------- /assignments/03/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Problem #7 : 2 stars (split) *) 6 | (** The function [split] is the right inverse of combine: it takes a 7 | list of pairs and returns a pair of lists. In many functional 8 | programing languages, this function is called [unzip]. 9 | 10 | Uncomment the material below and fill in the definition of 11 | [split]. Make sure it passes the given unit tests. *) 12 | 13 | Fixpoint split 14 | {X Y : Type} (l : list (X*Y)) 15 | : (list X) * (list Y) := 16 | FILL_IN_HERE. 17 | 18 | Example test_split: 19 | split [(1,false);(2,false)] = ([1;2],[false;false]). 20 | Proof. exact FILL_IN_HERE. Qed. 21 | 22 | Theorem split_map: forall X Y (l: list (X*Y)), 23 | fst (split l) = map fst l. 24 | Proof. 25 | exact FILL_IN_HERE. 26 | Qed. 27 | 28 | -------------------------------------------------------------------------------- /assignments/03_sol/P01.v~: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Problem #7 : 2 stars (split) *) 6 | (** The function [split] is the right inverse of combine: it takes a 7 | list of pairs and returns a pair of lists. In many functional 8 | programing languages, this function is called [unzip]. 9 | 10 | Uncomment the material below and fill in the definition of 11 | [split]. Make sure it passes the given unit tests. *) 12 | 13 | Fixpoint split 14 | {X Y : Type} (l : list (X*Y)) 15 | : (list X) * (list Y) := 16 | FILL_IN_HERE. 17 | 18 | Example test_split: 19 | split [(1,false);(2,false)] = ([1;2],[false;false]). 20 | Proof. exact FILL_IN_HERE. Qed. 21 | 22 | Theorem split_map: forall X Y (l: list (X*Y)), 23 | fst (split l) = map fst l. 24 | Proof. 25 | exact FILL_IN_HERE. 26 | Qed. 27 | 28 | -------------------------------------------------------------------------------- /assignments/02/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/02_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/03/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/03_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/04/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/04_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/05/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/05_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/06/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/06_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/10_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | Ltac inv X := inversion X; subst; clear X. 4 | Ltac des X := destruct X. 5 | Ltac i := intros. 6 | Ltac ii := repeat intro. 7 | Ltac ss := simpl in *; auto. 8 | 9 | Lemma mp: forall P Q: Type, P -> (P -> Q) -> Q. 10 | Proof. intuition. Defined. 11 | 12 | Lemma mp': forall P Q : Type, (P -> Q) -> P -> Q. 13 | Proof. intuition. Qed. 14 | 15 | Ltac hexploit x := eapply mp; [eapply x|]. 16 | Ltac hexploit' x := let H := fresh in set (H := x); clear H; eapply mp; [eapply x|]. 17 | 18 | 19 | (** **** Exercise: 3 stars (step__eval) *) 20 | Lemma step__eval : forall t t' n, 21 | t ==> t' -> 22 | t' \\ n -> 23 | t \\ n. 24 | Proof. 25 | i. revert n H0. induction H; i; inv H0. 26 | - apply E_Plus; apply E_Const. 27 | - apply E_Plus; eauto. 28 | - apply E_Plus; eauto. 29 | Qed. 30 | 31 | -------------------------------------------------------------------------------- /assignments/05/P08.v: -------------------------------------------------------------------------------- 1 | Require Export P07. 2 | 3 | 4 | 5 | (** Recall that functions returning propositions can be seen as 6 | _properties_ of their arguments. For instance, if [P] has type 7 | [nat -> Prop], then [P n] states that property [P] holds of [n]. 8 | 9 | Drawing inspiration from [In], write a recursive function [All] 10 | stating that some property [P] holds of all elements of a list 11 | [l]. To make sure your definition is correct, prove the [All_In] 12 | lemma below. (Of course, your definition should _not_ just 13 | restate the left-hand side of [All_In].) *) 14 | 15 | Fixpoint All {T} (P : T -> Prop) (l : list T) : Prop := 16 | FILL_IN_HERE. 17 | 18 | Lemma All_In : 19 | forall T (P : T -> Prop) (l : list T), 20 | (forall x, In x l -> P x) <-> 21 | All P l. 22 | Proof. exact FILL_IN_HERE. Qed. 23 | 24 | -------------------------------------------------------------------------------- /assignments/08/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Maps.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/10/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v Maps.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/11/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v Maps.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/12/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Maps.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/08_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Maps.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/10_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v Maps.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/11_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Types.v Maps.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/12_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Imp.v Smallstep.v Maps.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/07/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Basics.v Maps.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/09/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Maps.v Imp.v Smallstep.v Types.v Hoare.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/09_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Maps.v Imp.v Smallstep.v Types.v Hoare.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/07_sol/Makefile: -------------------------------------------------------------------------------- 1 | DFILES = D.v SfLib.v Basics.v Maps.v Imp.v Smallstep.v Types.v 2 | PFILES = $(shell find P??.v) 3 | EFILES = $(shell find E??_??.v) 4 | 5 | POFILES = $(patsubst %.v,%.vo,$(PFILES)) 6 | EOFILES = $(patsubst %.v,%.vo,$(EFILES)) 7 | 8 | all: $(DFILES) $(PFILES) Makefile.coq 9 | $(MAKE) -f Makefile.coq $(POFILES) 10 | 11 | check: 12 | bash ./check.sh 13 | 14 | eval: $(DFILES) $(PFILES) $(EFILES) Makefile.coq check 15 | $(MAKE) -f Makefile.coq $(EOFILES) 16 | 17 | submission: 18 | zip submission.zip P??.v 19 | 20 | %.vo: Makefile.coq 21 | $(MAKE) -f Makefile.coq "$@" 22 | 23 | clean: Makefile.coq 24 | $(MAKE) -f Makefile.coq clean 25 | rm _CoqProject Makefile.coq 26 | 27 | Makefile.coq: Makefile $(PFILES) $(EFILES) 28 | (echo -R . Assignment $(DFILES) $(PFILES) $(EFILES)) > _CoqProject 29 | coq_makefile -f _CoqProject -o Makefile.coq 30 | -------------------------------------------------------------------------------- /assignments/09_sol/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | Theorem hoare_skip_weakest : forall Q, 6 | is_wp Q SKIP Q. 7 | Proof. 8 | unfold is_wp. 9 | split. 10 | - unfold hoare_triple. 11 | intros. 12 | inversion H. 13 | subst. assumption. 14 | - unfold "->>". 15 | unfold hoare_triple. 16 | intros. 17 | apply H with (st := st). 18 | constructor. assumption. 19 | Qed. 20 | 21 | Theorem hoare_seq_weakest : forall P Q R c1 c2, 22 | is_wp P c1 Q -> 23 | is_wp Q c2 R -> 24 | is_wp P (c1 ;; c2) R. 25 | Proof. 26 | Hint Constructors ceval. 27 | unfold is_wp. 28 | intros P Q R c1 c2 [H11 H12] [H21 H22]. 29 | split. 30 | - apply hoare_seq with (Q := Q); assumption. 31 | - intros P' P'H. 32 | unfold hoare_triple in *. 33 | apply H12. 34 | intros. 35 | eapply H22. 36 | + intros. eauto. 37 | + unfold assert_implies in *. eauto. 38 | Qed. 39 | 40 | -------------------------------------------------------------------------------- /assignments/08/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Exercise: 4 stars (hoare_asgn_wrong) *) 6 | (** The assignment rule looks backward to almost everyone the first 7 | time they see it. If it still seems backward to you, it may help 8 | to think a little about alternative "forward" rules. Here is a 9 | seemingly natural one: 10 | ------------------------------ (hoare_asgn_wrong) 11 | {{ True }} X ::= a {{ X = a }} 12 | Give a counterexample showing that this rule is incorrect 13 | (informally). Hint: The rule universally quantifies over the 14 | arithmetic expression [a], and your counterexample needs to 15 | exhibit an [a] for which the rule doesn't work. *) 16 | 17 | Theorem hoare_asgn_wrong: 18 | exists a, ~ {{ fun st => True }} X ::= a {{ fun st => st X = aeval st a}}. 19 | Proof. 20 | exact FILL_IN_HERE. 21 | Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/09/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** ** Exercise: Power Series *) 6 | 7 | (** **** Exercise: 4 stars, optional (dpow2_down) *) 8 | (** Here is a program that computes the series: 9 | [1 + 2 + 2^2 + ... + 2^m = 2^(m+1) - 1] 10 | 11 | X ::= 0;; 12 | Y ::= 1;; 13 | Z ::= 1;; 14 | WHILE X <> m DO 15 | Z ::= 2 * Z;; 16 | Y ::= Y + Z;; 17 | X ::= X + 1 18 | END 19 | 20 | Write a decorated program for this. *) 21 | 22 | Theorem dopw2_down_correct: forall m, 23 | {{ fun st => True }} 24 | X ::= ANum 0;; 25 | Y ::= ANum 1;; 26 | Z ::= ANum 1;; 27 | WHILE BNot (BEq (AId X) (ANum m)) DO 28 | Z ::= AMult (ANum 2) (AId Z);; 29 | Y ::= APlus (AId Y) (AId Z);; 30 | X ::= APlus (AId X) (ANum 1) 31 | END 32 | {{ fun st => st Y = pow 2 (S m) - 1 }}. 33 | Proof. exact FILL_IN_HERE. Qed. 34 | 35 | -------------------------------------------------------------------------------- /assignments/06/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** For those who like a challenge, here is an exercise taken from the 6 | Coq'Art book by Bertot and Casteran (p. 123). Each of the 7 | following four statements, together with [excluded_middle], can be 8 | considered as characterizing classical logic. We can't prove any 9 | of them in Coq, but we can consistently add any one of them as an 10 | axiom if we wish to work in classical logic. 11 | 12 | Prove that all five propositions (these four plus 13 | [excluded_middle]) are equivalent. *) 14 | 15 | Theorem excluded_middle_to_double_negation_elimination: 16 | excluded_middle -> double_negation_elimination. 17 | Proof. exact FILL_IN_HERE. Qed. 18 | 19 | Theorem double_negation_elimination_to_excluded_middle: 20 | double_negation_elimination -> excluded_middle. 21 | Proof. exact FILL_IN_HERE. Qed. 22 | 23 | -------------------------------------------------------------------------------- /assignments/06_sol/P06.v: -------------------------------------------------------------------------------- 1 | Require Export P05. 2 | 3 | 4 | 5 | (** **** Exercise: 4 stars, advanced (ev_alternate) *) 6 | (** In general, there may be multiple ways of defining a 7 | property inductively. For example, here's a (slightly contrived) 8 | alternative definition for [ev]: *) 9 | 10 | (* 11 | Inductive ev' : nat -> Prop := 12 | | ev'_0 : ev' 0 13 | | ev'_2 : ev' 2 14 | | ev'_sum : forall n m, ev' n -> ev' m -> ev' (n + m). 15 | *) 16 | 17 | (** Prove that this definition is logically equivalent to 18 | the old one. *) 19 | 20 | Theorem ev'_ev : forall n, ev' n <-> ev n. 21 | Proof. 22 | split. 23 | - intros H. 24 | induction H. 25 | + constructor. 26 | + repeat constructor. 27 | + apply ev_sum. assumption. assumption. 28 | - intros H. 29 | induction H. 30 | + constructor. 31 | + apply ev'_sum with (n := 2) (m := n). 32 | constructor. 33 | assumption. 34 | Qed. 35 | 36 | -------------------------------------------------------------------------------- /assignments/02_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | 5 | (** **** Problem : 3 stars (mult_comm) *) 6 | 7 | Lemma mult_comm : forall n m: nat, 8 | n * m = m * n. 9 | Proof. 10 | intros. 11 | induction n. 12 | - rewrite <- mult_n_O. reflexivity. 13 | - simpl. rewrite -> IHn. rewrite <- mult_n_Sm. 14 | rewrite plus_comm. reflexivity. 15 | Qed. 16 | 17 | Theorem mult_plus_distr_r : forall n m p : nat, 18 | (n + m) * p = (n * p) + (m * p). 19 | Proof. 20 | intros. 21 | rewrite mult_comm. 22 | rewrite mult_comm with (n := n) (m := p). 23 | rewrite mult_comm with (n := m) (m := p). 24 | induction p. 25 | - simpl. reflexivity. 26 | - simpl. rewrite -> IHp. 27 | rewrite <- plus_assoc. 28 | rewrite <- plus_assoc. 29 | rewrite plus_assoc with (n := m) (m := p * n) (p := p * m). 30 | rewrite plus_assoc with (n := p * n) (m := m) (p := p * m). 31 | rewrite plus_comm with (n := m) (m := p * n). 32 | reflexivity. 33 | Qed. 34 | 35 | -------------------------------------------------------------------------------- /assignments/12/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** Translate this informal recursive definition into one using [fix]: 6 | << 7 | halve = 8 | \x:Nat. 9 | if x=0 then 0 10 | else if (pred x)=0 then 0 11 | else 1 + (halve (pred (pred x)))) 12 | >> 13 | *) 14 | 15 | Definition halve : tm := 16 | FILL_IN_HERE. 17 | 18 | Example halve_type: empty |- halve \in TArrow TNat TNat. 19 | Proof. 20 | (* unfold halve; eauto 10. *) 21 | exact FILL_IN_HERE. 22 | Qed. 23 | 24 | Example halve_10: tapp halve (tnat 10) ==>* tnat 5. 25 | Proof. 26 | (* unfold halve; normalize. *) 27 | exact FILL_IN_HERE. 28 | Qed. 29 | 30 | Example halve_11: tapp halve (tnat 11) ==>* tnat 5. 31 | Proof. 32 | (* unfold halve; normalize. *) 33 | exact FILL_IN_HERE. 34 | Qed. 35 | 36 | 37 | Theorem halve_correct: forall n, 38 | tapp halve (tnat (n+n)) ==>* tnat n. 39 | Proof. 40 | exact FILL_IN_HERE. 41 | Qed. 42 | 43 | -------------------------------------------------------------------------------- /assignments/07_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars, optional (t_update_shadow) *) 6 | (** If we update a map [m] at a key [x] with a value [v1] and then 7 | update again with the same key [x] and another value [v2], the 8 | resulting map behaves the same (gives the same result when applied 9 | to any key) as the simpler map obtained by performing just 10 | the second [update] on [m]: *) 11 | 12 | 13 | Lemma suppl : forall A (b:bool) (v1 v2:A), (if b then v1 else v2) = 14 | (if b then v1 else (if b then v1 else v2)). 15 | Proof. 16 | destruct b. 17 | intros. reflexivity. 18 | intros. reflexivity. 19 | Qed. 20 | 21 | Lemma t_update_shadow : forall A (m: total_map A) v1 v2 x, 22 | t_update (t_update m x v1) x v2 23 | = t_update m x v2. 24 | 25 | Proof. 26 | intros. 27 | unfold t_update. 28 | apply functional_extensionality. 29 | intros. 30 | destruct (beq_id x x0). 31 | reflexivity. reflexivity. 32 | Qed. -------------------------------------------------------------------------------- /assignments/06_sol/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | Theorem le_trivial: forall n1 n2, 4 | n1 <= n1 + n2. 5 | Proof. 6 | intros. 7 | induction n2. 8 | - rewrite <- plus_n_O. constructor. 9 | - rewrite <- plus_n_Sm. constructor. assumption. 10 | Qed. 11 | 12 | Theorem plus_comm: forall n1 n2, 13 | n1 + n2 = n2 + n1. 14 | Proof. 15 | intros. 16 | induction n1. 17 | - rewrite <- plus_n_O. reflexivity. 18 | - rewrite <- plus_n_Sm. simpl. rewrite IHn1. reflexivity. 19 | Qed. 20 | 21 | Theorem plus_lt : forall n1 n2 m, 22 | n1 + n2 < m -> 23 | n1 < m /\ n2 < m. 24 | Proof. 25 | unfold lt. 26 | induction m. 27 | - intros. inversion H. 28 | - intros. 29 | inversion H. 30 | + split. 31 | * rewrite <- plus_Sn_m. 32 | apply le_trivial. 33 | * rewrite plus_n_Sm. 34 | rewrite plus_comm. 35 | apply le_trivial. 36 | + apply IHm in H1. 37 | inversion H1. 38 | split. 39 | * constructor. assumption. 40 | * constructor. assumption. 41 | Qed. 42 | -------------------------------------------------------------------------------- /assignments/05_sol/P07.v: -------------------------------------------------------------------------------- 1 | Require Export P06. 2 | 3 | 4 | 5 | Lemma In_map_iff : 6 | forall (A B : Type) (f : A -> B) (l : list A) (y : B), 7 | In y (map f l) <-> 8 | exists x, f x = y /\ In x l. 9 | Proof. 10 | intros. 11 | split. 12 | - intros. 13 | generalize dependent y. 14 | induction l. 15 | + intros. simpl in H. exfalso. assumption. 16 | + intros. simpl in H. 17 | inversion H. 18 | * exists a. 19 | split. 20 | apply H0. 21 | simpl. left. reflexivity. 22 | * apply IHl in H0. 23 | inversion H0. 24 | exists x. inversion H1. 25 | split. assumption. simpl. right. assumption. 26 | - intros. 27 | induction l as [ | a l IHl]. 28 | + simpl in H. inversion H. inversion H0. exfalso. assumption. 29 | + simpl. 30 | inversion H. 31 | inversion H0. simpl in H2. 32 | inversion H2. 33 | * left. subst. reflexivity. 34 | * right. apply IHl. exists x. 35 | split ; assumption. 36 | Qed. 37 | -------------------------------------------------------------------------------- /sf/Symbols.v: -------------------------------------------------------------------------------- 1 | (** * Symbols: Special symbols *) 2 | 3 | (* This file defines some HTML symbols for use by the coqdoc 4 | preprocessor. It is not intended to be read by anybody. *) 5 | 6 | (** printing -> *) 7 | (** printing \\ *) 8 | (** printing ==> *) 9 | (** printing ==>* *) 10 | (** printing ==>+ *) 11 | (** printing |- ## *) 12 | (** printing <- *) 13 | (** printing <-> *) 14 | (** printing forall *) 15 | (** printing exists *) 16 | (** printing /\ *) 17 | (** printing \/ *) 18 | (** printing ->> ## *) 19 | (** printing <<->> ## *) 20 | (** printing |- ## *) 21 | (** printing Gamma *) 22 | (** printing Gamma' *) 23 | (** printing Gamma'' *) 24 | (** printing |-> ## *) 25 | 26 | (** $Date: 2016-05-26 16:17:19 -0400 (Thu, 26 May 2016) $ *) 27 | -------------------------------------------------------------------------------- /assignments/08_sol/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** **** Exercise: 2 stars (if_minus_plus) *) 6 | (** Prove the following hoare triple using [hoare_if_wp]: *) 7 | 8 | Lemma Y_noteq_Z: Y<>Z. 9 | Proof. unfold not. intros. inversion H. Qed. 10 | Lemma X_noteq_Z: X<>Z. 11 | Proof. unfold not. intros. inversion H. Qed. 12 | 13 | Theorem if_minus_plus : 14 | {{fun st => True}} 15 | IFB (BLe (AId X) (AId Y)) 16 | THEN (Z ::= AMinus (AId Y) (AId X)) 17 | ELSE (Y ::= APlus (AId X) (AId Z)) 18 | FI 19 | {{fun st => st Y = st X + st Z}}. 20 | Proof. 21 | eapply hoare_consequence_pre. 22 | - apply hoare_if_wp. 23 | apply hoare_asgn. 24 | apply hoare_asgn. 25 | - unfold assn_sub. 26 | unfold assert_implies. 27 | simpl. 28 | split. 29 | + intros. 30 | unfold t_update. 31 | simpl. 32 | apply le_plus_minus. 33 | apply leb_complete in H0. 34 | assumption. 35 | + intros. 36 | unfold t_update. 37 | simpl. 38 | reflexivity. 39 | Qed. 40 | 41 | -------------------------------------------------------------------------------- /assignments/03_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | 4 | 5 | (** **** Problem #7 : 2 stars (split) *) 6 | (** The function [split] is the right inverse of combine: it takes a 7 | list of pairs and returns a pair of lists. In many functional 8 | programing languages, this function is called [unzip]. 9 | 10 | Uncomment the material below and fill in the definition of 11 | [split]. Make sure it passes the given unit tests. *) 12 | 13 | Fixpoint split 14 | {X Y : Type} (l : list (X*Y)) 15 | : (list X) * (list Y) := 16 | match l with 17 | | nil => ([], []) 18 | | (a,b)::t => ((a::(fst (split t))), (b::(snd (split t)))) 19 | end. 20 | 21 | Example test_split: 22 | split [(1,false);(2,false)] = ([1;2],[false;false]). 23 | Proof. simpl. reflexivity. Qed. 24 | 25 | Theorem split_map: forall X Y (l: list (X*Y)), 26 | fst (split l) = map fst l. 27 | Proof. 28 | induction l. 29 | - simpl. reflexivity. 30 | - simpl. 31 | destruct x. 32 | simpl. rewrite -> IHl. reflexivity. 33 | Qed. 34 | 35 | -------------------------------------------------------------------------------- /assignments/05/D.v: -------------------------------------------------------------------------------- 1 | (** **** SNU 4190.310, 2016 Spring *) 2 | 3 | (** Assignment 05 *) 4 | (** Due: 2016/10/31 23:59 *) 5 | 6 | (* Important: 7 | - Do NOT import other files. 8 | 9 | - You are NOT allowed to use the [admit] tactic. 10 | 11 | - You are NOT allowed to use the following tactics. 12 | [tauto], [intuition], [firstorder], [omega]. 13 | 14 | - Just leave [exact FILL_IN_HERE] for those problems that you fail to prove. 15 | *) 16 | 17 | Require Import Tactics. 18 | Require Import List. 19 | 20 | Definition FILL_IN_HERE {T: Type} : T. Admitted. 21 | 22 | Notation "x :: l" := (cons x l) (at level 60, right associativity). 23 | Notation "[ ]" := nil. 24 | Notation "[ x , .. , y ]" := (cons x .. (cons y nil) ..). 25 | 26 | Fixpoint In {A : Type} (x : A) (l : list A) : Prop := 27 | match l with 28 | | [] => False 29 | | x' :: l' => x' = x \/ In x l' 30 | end. 31 | 32 | Fixpoint map {X Y : Type} (f : X -> Y) (l : list X) := 33 | match l with 34 | | [] => [] 35 | | h :: t => (f h) :: (map f t) 36 | end. 37 | -------------------------------------------------------------------------------- /assignments/05_sol/D.v: -------------------------------------------------------------------------------- 1 | (** **** SNU 4190.310, 2016 Spring *) 2 | 3 | (** Assignment 05 *) 4 | (** Due: 2016/10/31 23:59 *) 5 | 6 | (* Important: 7 | - Do NOT import other files. 8 | 9 | - You are NOT allowed to use the [admit] tactic. 10 | 11 | - You are NOT allowed to use the following tactics. 12 | [tauto], [intuition], [firstorder], [omega]. 13 | 14 | - Just leave [exact FILL_IN_HERE] for those problems that you fail to prove. 15 | *) 16 | 17 | Require Import Tactics. 18 | Require Import List. 19 | 20 | Definition FILL_IN_HERE {T: Type} : T. Admitted. 21 | 22 | Notation "x :: l" := (cons x l) (at level 60, right associativity). 23 | Notation "[ ]" := nil. 24 | Notation "[ x , .. , y ]" := (cons x .. (cons y nil) ..). 25 | 26 | Fixpoint In {A : Type} (x : A) (l : list A) : Prop := 27 | match l with 28 | | [] => False 29 | | x' :: l' => x' = x \/ In x l' 30 | end. 31 | 32 | Fixpoint map {X Y : Type} (f : X -> Y) (l : list X) := 33 | match l with 34 | | [] => [] 35 | | h :: t => (f h) :: (map f t) 36 | end. 37 | -------------------------------------------------------------------------------- /sf/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/02/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/03/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/04/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/05/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/06/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/07/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/08/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/09/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/10/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/11/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/12/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/02_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/03_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/04_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/05_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/06_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/07_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/08_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/09_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/10_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/11_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /assignments/12_sol/SfLib.v: -------------------------------------------------------------------------------- 1 | (** * SfLib: Software Foundations Library *) 2 | 3 | (** Here we collect together a few useful definitions from earlier 4 | chapters that are not provided as part of the Coq standard 5 | library. Later chapters will [Import] or [Export] just this file, 6 | instead of cluttering the top-level environment with all the 7 | examples and false starts in those files. *) 8 | 9 | Tactic Notation "solve_by_inversion_step" tactic(t) := 10 | match goal with 11 | | H : _ |- _ => solve [ inversion H; subst; t ] 12 | end 13 | || fail "because the goal is not solvable by inversion.". 14 | 15 | Tactic Notation "solve" "by" "inversion" "1" := 16 | solve_by_inversion_step idtac. 17 | Tactic Notation "solve" "by" "inversion" "2" := 18 | solve_by_inversion_step (solve by inversion 1). 19 | Tactic Notation "solve" "by" "inversion" "3" := 20 | solve_by_inversion_step (solve by inversion 2). 21 | Tactic Notation "solve" "by" "inversion" := 22 | solve by inversion 1. 23 | 24 | (** $Date: 2016-07-11 21:31:32 -0400 (Mon, 11 Jul 2016) $ *) 25 | -------------------------------------------------------------------------------- /sf/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /assignments/10_sol/P04.v: -------------------------------------------------------------------------------- 1 | Require Export P03. 2 | 3 | 4 | Ltac inv X := inversion X; subst; clear X. 5 | Ltac des X := destruct X. 6 | Ltac i := intros. 7 | Ltac ii := repeat intro. 8 | Ltac ss := simpl in *; auto. 9 | 10 | Lemma mp: forall P Q: Type, P -> (P -> Q) -> Q. 11 | Proof. intuition. Defined. 12 | 13 | Lemma mp': forall P Q : Type, (P -> Q) -> P -> Q. 14 | Proof. intuition. Qed. 15 | 16 | Ltac hexploit x := eapply mp; [eapply x|]. 17 | Ltac hexploit' x := let H := fresh in set (H := x); clear H; eapply mp; [eapply x|]. 18 | 19 | (* Hint: 20 | 21 | First study the chapter "Auto.v". 22 | 23 | Using [;], [try] and [eauto], you can prove it in 4 lines thanks to: 24 | Hint Constructors aval 25 | Hint Constructors astep. 26 | 27 | You can use the following intro pattern: 28 | destruct ... as [[? ?] | [? ?]]. 29 | *) 30 | 31 | Theorem aexp_strong_progress: forall st a, 32 | (exists n, a = ANum n) \/ 33 | exists a', a / st ==>a a'. 34 | Proof. 35 | Hint Constructors aval. 36 | Hint Constructors astep. 37 | induction a; eauto. 38 | all: des IHa1; try des H; des IHa2; try des H0; subst; eauto. 39 | Qed. 40 | 41 | -------------------------------------------------------------------------------- /sf/imp2.mli: -------------------------------------------------------------------------------- 1 | val negb : bool -> bool 2 | 3 | type 'a option = 4 | | Some of 'a 5 | | None 6 | 7 | val add : int -> int -> int 8 | 9 | val mul : int -> int -> int 10 | 11 | val sub : int -> int -> int 12 | 13 | module Nat : 14 | sig 15 | val eqb : int -> int -> bool 16 | 17 | val leb : int -> int -> bool 18 | end 19 | 20 | type id = 21 | int 22 | (* singleton inductive, whose constructor was Id *) 23 | 24 | val beq_id : id -> id -> bool 25 | 26 | type 'a total_map = id -> 'a 27 | 28 | val t_update : 'a1 total_map -> id -> 'a1 -> id -> 'a1 29 | 30 | type state = int total_map 31 | 32 | type aexp = 33 | | ANum of int 34 | | AId of id 35 | | APlus of aexp * aexp 36 | | AMinus of aexp * aexp 37 | | AMult of aexp * aexp 38 | 39 | type bexp = 40 | | BTrue 41 | | BFalse 42 | | BEq of aexp * aexp 43 | | BLe of aexp * aexp 44 | | BNot of bexp 45 | | BAnd of bexp * bexp 46 | 47 | val aeval : state -> aexp -> int 48 | 49 | val beval : state -> bexp -> bool 50 | 51 | type com = 52 | | CSkip 53 | | CAss of id * aexp 54 | | CSeq of com * com 55 | | CIf of bexp * com * com 56 | | CWhile of bexp * com 57 | 58 | val ceval_step : state -> com -> int -> state option 59 | -------------------------------------------------------------------------------- /assignments/07/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (optimize_0plus_b) *) 6 | (** Since the [optimize_0plus] transformation doesn't change the value 7 | of [aexp]s, we should be able to apply it to all the [aexp]s that 8 | appear in a [bexp] without changing the [bexp]'s value. Write a 9 | function which performs that transformation on [bexp]s, and prove 10 | it is sound. Use the tacticals we've just seen to make the proof 11 | as elegant as possible. *) 12 | 13 | Fixpoint optimize_0plus_b (b : bexp) : bexp := 14 | FILL_IN_HERE. 15 | 16 | Example optimize_0plus_b_example1: 17 | optimize_0plus_b (BEq 18 | (AMult (APlus (ANum 0) (APlus (ANum 0) (ANum 3))) 19 | (AMinus (ANum 5) (APlus (ANum 0) (ANum 1)))) 20 | (APlus (ANum 2) 21 | (APlus (ANum 0) 22 | (APlus (ANum 0) (ANum 1))))) 23 | = (BEq (AMult (ANum 3) (AMinus (ANum 5) (ANum 1))) 24 | (APlus (ANum 2) (ANum 1))). 25 | Proof. exact FILL_IN_HERE. Qed. 26 | 27 | Theorem optimize_0plus_b_sound : forall st b, 28 | beval st (optimize_0plus_b b) = beval st b. 29 | Proof. exact FILL_IN_HERE. Qed. 30 | 31 | -------------------------------------------------------------------------------- /assignments/07_sol/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (optimize_0plus_b) *) 6 | (** Since the [optimize_0plus] transformation doesn't change the value 7 | of [aexp]s, we should be able to apply it to all the [aexp]s that 8 | appear in a [bexp] without changing the [bexp]'s value. Write a 9 | function which performs that transformation on [bexp]s, and prove 10 | it is sound. Use the tacticals we've just seen to make the proof 11 | as elegant as possible. *) 12 | 13 | Fixpoint optimize_0plus_b (b : bexp) : bexp := 14 | FILL_IN_HERE. 15 | 16 | Example optimize_0plus_b_example1: 17 | optimize_0plus_b (BEq 18 | (AMult (APlus (ANum 0) (APlus (ANum 0) (ANum 3))) 19 | (AMinus (ANum 5) (APlus (ANum 0) (ANum 1)))) 20 | (APlus (ANum 2) 21 | (APlus (ANum 0) 22 | (APlus (ANum 0) (ANum 1))))) 23 | = (BEq (AMult (ANum 3) (AMinus (ANum 5) (ANum 1))) 24 | (APlus (ANum 2) (ANum 1))). 25 | Proof. exact FILL_IN_HERE. Qed. 26 | 27 | Theorem optimize_0plus_b_sound : forall st b, 28 | beval st (optimize_0plus_b b) = beval st b. 29 | Proof. exact FILL_IN_HERE. Qed. 30 | 31 | -------------------------------------------------------------------------------- /assignments/07/P10.v: -------------------------------------------------------------------------------- 1 | Require Export P09. 2 | 3 | 4 | 5 | (** **** Exercise: 3 stars (fold_constants_com_sound) *) 6 | (** Complete the [WHILE] case of the following proof. *) 7 | 8 | Theorem fold_constants_com_sound : 9 | ctrans_sound fold_constants_com. 10 | Proof. 11 | unfold ctrans_sound. intros c. 12 | induction c; simpl. 13 | - (* SKIP *) apply refl_cequiv. 14 | - (* ::= *) apply CAss_congruence. 15 | apply fold_constants_aexp_sound. 16 | - (* ;; *) apply CSeq_congruence; assumption. 17 | - (* IFB *) 18 | assert (bequiv b (fold_constants_bexp b)). { 19 | apply fold_constants_bexp_sound. } 20 | destruct (fold_constants_bexp b) eqn:Heqb; 21 | try (apply CIf_congruence; assumption). 22 | 23 | (** (If the optimization doesn't eliminate the if, then the 24 | result is easy to prove from the IH and 25 | [fold_constants_bexp_sound].) *) 26 | 27 | + (* b always true *) 28 | apply trans_cequiv with c1; try assumption. 29 | apply IFB_true; assumption. 30 | + (* b always false *) 31 | apply trans_cequiv with c2; try assumption. 32 | apply IFB_false; assumption. 33 | - (* WHILE *) 34 | exact FILL_IN_HERE. 35 | Qed. 36 | 37 | -------------------------------------------------------------------------------- /assignments/11/P02.v: -------------------------------------------------------------------------------- 1 | Require Export P01. 2 | 3 | 4 | 5 | (** The typing relation enjoys two critical properties. The first is 6 | that well-typed normal forms are values (i.e., not stuck). *) 7 | 8 | (** **** Exercise: 3 stars (finish_progress) *) 9 | (** Complete the formal proof of the [progress] property. (Make sure 10 | you understand the informal proof fragment in the following 11 | exercise before starting -- this will save you a lot of time.) *) 12 | 13 | Theorem progress : forall t T, 14 | |- t \in T -> 15 | value t \/ exists t', t ==> t'. 16 | Proof with auto. 17 | intros t T HT. 18 | induction HT... 19 | (* The cases that were obviously values, like T_True and 20 | T_False, were eliminated immediately by auto *) 21 | - (* T_If *) 22 | right. inversion IHHT1; clear IHHT1. 23 | + (* t1 is a value *) 24 | apply (bool_canonical t1 HT1) in H. 25 | inversion H; subst; clear H. 26 | exists t2... 27 | exists t3... 28 | + (* t1 can take a step *) 29 | inversion H as [t1' H1]. 30 | exists (tif t1' t2 t3)... 31 | - (* T_Succ *) 32 | exact FILL_IN_HERE. 33 | - (* T_Pred *) 34 | exact FILL_IN_HERE. 35 | - (* T_Iszero *) 36 | exact FILL_IN_HERE. 37 | Qed. 38 | 39 | -------------------------------------------------------------------------------- /assignments/11_sol/P01.v: -------------------------------------------------------------------------------- 1 | Require Export D. 2 | 3 | Ltac inv X := inversion X; subst; clear X. 4 | Ltac des X := destruct X. 5 | Ltac i := intros. 6 | Ltac ii := repeat intro. 7 | Ltac ss := simpl in *; auto. 8 | 9 | Lemma mp: forall P Q: Type, P -> (P -> Q) -> Q. 10 | Proof. intuition. Defined. 11 | 12 | Lemma mp': forall P Q : Type, (P -> Q) -> P -> Q. 13 | Proof. intuition. Qed. 14 | 15 | Ltac hexploit x := eapply mp; [eapply x|]. 16 | Ltac hexploit' x := let H := fresh in set (H := x); clear H; eapply mp; [eapply x|]. 17 | 18 | 19 | (** **** Exercise: 3 stars, advanced (value_is_nf) *) 20 | (** Hint: You will reach a point in this proof where you need to 21 | use an induction to reason about a term that is known to be a 22 | numeric value. This induction can be performed either over the 23 | term itself or over the evidence that it is a numeric value. The 24 | proof goes through in either case, but you will find that one way 25 | is quite a bit shorter than the other. For the sake of the 26 | exercise, try to complete the proof both ways. *) 27 | 28 | Lemma value_is_nf : forall t, 29 | value t -> step_normal_form t. 30 | Proof. 31 | induction t; ii; des H0; inv H0; inv H; inv H0; ss. 32 | hexploit IHt; eauto. 33 | Qed. 34 | -------------------------------------------------------------------------------- /assignments/11/P03.v: -------------------------------------------------------------------------------- 1 | Require Export P02. 2 | 3 | 4 | 5 | (** The second critical property of typing is that, when a well-typed 6 | term takes a step, the result is also a well-typed term. *) 7 | 8 | Theorem preservation : forall t t' T, 9 | |- t \in T -> 10 | t ==> t' -> 11 | |- t' \in T. 12 | 13 | (** **** Exercise: 2 stars (finish_preservation) *) 14 | (** Complete the formal proof of the [preservation] property. (Again, 15 | make sure you understand the informal proof fragment in the 16 | following exercise first.) *) 17 | 18 | Proof with auto. 19 | intros t t' T HT HE. 20 | generalize dependent t'. 21 | induction HT; 22 | (* every case needs to introduce a couple of things *) 23 | intros t' HE; 24 | (* and we can deal with several impossible 25 | cases all at once *) 26 | try solve_by_invert. 27 | - (* T_If *) inversion HE; subst; clear HE. 28 | + (* ST_IFTrue *) assumption. 29 | + (* ST_IfFalse *) assumption. 30 | + (* ST_If *) apply T_If; try assumption. 31 | apply IHHT1; assumption. 32 | - (* T_Succ *) 33 | exact FILL_IN_HERE. 34 | - (* T_Pred *) 35 | exact FILL_IN_HERE. 36 | - (* T_Iszero *) 37 | exact FILL_IN_HERE. 38 | Qed. 39 | 40 | -------------------------------------------------------------------------------- /sf/imp1.mli: -------------------------------------------------------------------------------- 1 | type bool = 2 | | True 3 | | False 4 | 5 | val negb : bool -> bool 6 | 7 | type nat = 8 | | O 9 | | S of nat 10 | 11 | type 'a option = 12 | | Some of 'a 13 | | None 14 | 15 | val add : nat -> nat -> nat 16 | 17 | val mul : nat -> nat -> nat 18 | 19 | val sub : nat -> nat -> nat 20 | 21 | module Nat : 22 | sig 23 | val eqb : nat -> nat -> bool 24 | 25 | val leb : nat -> nat -> bool 26 | end 27 | 28 | type id = 29 | nat 30 | (* singleton inductive, whose constructor was Id *) 31 | 32 | val beq_id : id -> id -> bool 33 | 34 | type 'a total_map = id -> 'a 35 | 36 | val t_update : 'a1 total_map -> id -> 'a1 -> id -> 'a1 37 | 38 | type state = nat total_map 39 | 40 | type aexp = 41 | | ANum of nat 42 | | AId of id 43 | | APlus of aexp * aexp 44 | | AMinus of aexp * aexp 45 | | AMult of aexp * aexp 46 | 47 | type bexp = 48 | | BTrue 49 | | BFalse 50 | | BEq of aexp * aexp 51 | | BLe of aexp * aexp 52 | | BNot of bexp 53 | | BAnd of bexp * bexp 54 | 55 | val aeval : state -> aexp -> nat 56 | 57 | val beval : state -> bexp -> bool 58 | 59 | type com = 60 | | CSkip 61 | | CAss of id * aexp 62 | | CSeq of com * com 63 | | CIf of bexp * com * com 64 | | CWhile of bexp * com 65 | 66 | val ceval_step : state -> com -> nat -> state option 67 | --------------------------------------------------------------------------------