Skip to content

Commit 1e87a9a

Browse files
committed
Fix up Basics exercises
- Adopt the square - Use Coq naming conventions - Add missing exercise, description and ) - Add FILL IN HERE comments for those exercises without holes
1 parent 7cadaa0 commit 1e87a9a

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

docs/pdf/sf-idris-2016.pdf

2.41 KB
Binary file not shown.

src/Basics.lidr

+68-9
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,42 @@ holes, following the model of the `orb` tests above.) The function should return
299299
> nandb : (b1 : Bool) -> (b2 : Bool) -> Bool
300300
> nandb b1 b2 = ?nandb_rhs
301301

302-
> testNandb1 : (nandb True False) = True
303-
> testNandb1 = ?testNandb1_rhs
302+
> test_nandb1 : (nandb True False) = True
303+
> test_nandb1 = ?test_nandb1_rhs
304304

305-
> testNandb2 : (nandb False False) = True
306-
> testNandb2 = ?testNandb2_rhs
305+
> test_nandb2 : (nandb False False) = True
306+
> test_nandb2 = ?test_nandb2_rhs
307307

308-
> testNandb3 : (nandb False True) = True
309-
> testNandb3 = ?testNandb3_rhs
308+
> test_nandb3 : (nandb False True) = True
309+
> test_nandb3 = ?test_nandb3_rhs
310310

311-
> testNandb4 : (nandb True True) = False
312-
> testNandb4 = ?testNandb4_rhs
311+
> test_nandb4 : (nandb True True) = False
312+
> test_nandb4 = ?test_nandb4_rhs
313+
314+
$\square$
315+
316+
317+
=== Exercise: 1 star (andb3)
318+
319+
Do the same for the `andb3` function below. This function should return `True`
320+
when all of its inputs are `True`, and `False` otherwise.
321+
322+
> andb3 : (b1 : Bool) -> (b2 : Bool) -> (b3 : Bool) -> Bool
323+
> andb3 b1 b2 b3 = ?andb3_rhs
324+
325+
> test_andb31 : (andb3 True True True) = True
326+
> test_andb31 = ?test_andb31_rhs
327+
328+
> test_andb32 : (andb3 False True True) = False
329+
> test_andb32 = ?test_andb32_rhs
330+
331+
> test_andb33 : (andb3 True False True) = False
332+
> test_andb33 = ?test_andb33_rhs
333+
334+
> test_andb34 : (andb3 True True False) = False
335+
> test_andb34 = ?test_andb34_rhs
336+
337+
$\square$
313338

314339

315340
== Function Types
@@ -553,6 +578,8 @@ Translate this into Idris.
553578
> testFactorial2 : factorial 5 = mult 10 12
554579
> testFactorial2 = ?testFactorial2_rhs
555580

581+
$\square$
582+
556583
We can make numerical expressions a little easier to read and write by
557584
introducing _syntax_ for addition, multiplication, and subtraction.
558585

@@ -618,6 +645,8 @@ in terms of a previously defined function.
618645
> test_blt_nat_3 : blt_nat 4 2 = False
619646
> test_blt_nat_3 = ?test_blt_nat_3_rhs
620647

648+
$\square$
649+
621650

622651
== Proof by Simplification
623652

@@ -727,6 +756,8 @@ Fill in the proof.
727756
> -> n + m = m + o
728757
> plus_id_exercise n m o prf prf1 = ?plus_id_exercise_rhs
729758

759+
$\square$
760+
730761
The prefix `?` on the right-hand side of an equation tells Idris that we want to
731762
skip trying to prove this theorem and just leave a hole. This can be useful for
732763
developing longer proofs, since we can state subsidiary lemmas that we believe
@@ -756,6 +787,8 @@ Idris and can just use `Refl` instead.
756787
> -> m * (1 + n) = m * m
757788
> mult_S_1 n m prf = ?mult_S_1_rhs
758789

790+
$\square$
791+
759792

760793
== Proof by Case Analysis
761794

@@ -856,17 +889,22 @@ Prove the following claim, lift cases (and subcases) to lemmas when case split.
856889
> andb_true_elim_2 : (b, c : Bool) -> (andb b c = True) -> c = True
857890
> andb_true_elim_2 b c prf = ?andb_true_elim_2_rhs
858891

892+
$\square$
859893

860-
=== Exercise: 1 star (zero_nbeq_plus
894+
895+
=== Exercise: 1 star (zero_nbeq_plus_1)
861896

862897
> zero_nbeq_plus_1 : (n : Nat) -> beq_nat 0 (n + 1) = False
863898
> zero_nbeq_plus_1 n = ?zero_nbeq_plus_1_rhs
864899

900+
$\square$
901+
865902

866903
\color{red}
867904
-- TODO: discuss associativity
868905
\color{black}
869906

907+
870908
== Structural Recursion (Optional)
871909

872910
Here is a copy of the definition of addition:
@@ -894,6 +932,10 @@ unnatural ways.
894932
-- TODO: verify the previous claims
895933
\color{black}
896934

935+
\color{red}
936+
-- TODO: Add decreasing exercise
937+
\color{black}
938+
897939

898940
== More Exercises
899941

@@ -911,11 +953,24 @@ Now state and prove a theorem `negation_fn_applied_twice` similar to the
911953
previous one but where the second hypothesis says that the function `f` has the
912954
property that `f x = negb x`.
913955

956+
> -- FILL IN HERE
957+
958+
$\square$
959+
960+
961+
=== Exercise: 2 start (andb_eq_orb)
962+
963+
Prove the following theorem. (You may want to first prove a subsidiary lemma or
964+
two. Alternatively, remember that you do not have to introduce all hypotheses at
965+
the same time.)
966+
914967
> andb_eq_orb : (b, c : Bool)
915968
> -> (andb b c = orb b c)
916969
> -> b = c
917970
> andb_eq_orb b c prf = ?andb_eq_orb_rhs
918971

972+
$\square$
973+
919974

920975
=== Exercise: 3 stars (binary)
921976

@@ -953,3 +1008,7 @@ functions you will write next that will give it mathematical meaning.)
9531008
increment and binary-to-unary functions. Notice that incrementing a binary
9541009
number and then converting it to unary should yield the same result as first
9551010
converting it to unary and then incrementing.
1011+
1012+
> -- FILL IN HERE
1013+
1014+
$\square$

0 commit comments

Comments
 (0)