@@ -299,17 +299,42 @@ holes, following the model of the `orb` tests above.) The function should return
299
299
> nandb : (b1 : Bool) -> (b2 : Bool) -> Bool
300
300
> nandb b1 b2 = ?nandb_rhs
301
301
302
- > testNandb1 : (nandb True False) = True
303
- > testNandb1 = ?testNandb1_rhs
302
+ > test_nandb1 : (nandb True False) = True
303
+ > test_nandb1 = ?test_nandb1_rhs
304
304
305
- > testNandb2 : (nandb False False) = True
306
- > testNandb2 = ?testNandb2_rhs
305
+ > test_nandb2 : (nandb False False) = True
306
+ > test_nandb2 = ?test_nandb2_rhs
307
307
308
- > testNandb3 : (nandb False True) = True
309
- > testNandb3 = ?testNandb3_rhs
308
+ > test_nandb3 : (nandb False True) = True
309
+ > test_nandb3 = ?test_nandb3_rhs
310
310
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$
313
338
314
339
315
340
== Function Types
@@ -553,6 +578,8 @@ Translate this into Idris.
553
578
> testFactorial2 : factorial 5 = mult 10 12
554
579
> testFactorial2 = ?testFactorial2_rhs
555
580
581
+ $\square$
582
+
556
583
We can make numerical expressions a little easier to read and write by
557
584
introducing _syntax_ for addition , multiplication, and subtraction .
558
585
@@ -618,6 +645,8 @@ in terms of a previously defined function.
618
645
> test_blt_nat_3 : blt_nat 4 2 = False
619
646
> test_blt_nat_3 = ?test_blt_nat_3_rhs
620
647
648
+ $\square$
649
+
621
650
622
651
== Proof by Simplification
623
652
@@ -727,6 +756,8 @@ Fill in the proof.
727
756
> -> n + m = m + o
728
757
> plus_id_exercise n m o prf prf1 = ?plus_id_exercise_rhs
729
758
759
+ $\square$
760
+
730
761
The prefix `?` on the right-hand side of an equation tells Idris that we want to
731
762
skip trying to prove this theorem and just leave a hole. This can be useful for
732
763
developing longer proofs, since we can state subsidiary lemmas that we believe
@@ -756,6 +787,8 @@ Idris and can just use `Refl` instead.
756
787
> -> m * (1 + n) = m * m
757
788
> mult_S_1 n m prf = ?mult_S_1_rhs
758
789
790
+ $\square$
791
+
759
792
760
793
== Proof by Case Analysis
761
794
@@ -856,17 +889,22 @@ Prove the following claim, lift cases (and subcases) to lemmas when case split.
856
889
> andb_true_elim_2 : (b, c : Bool) -> (andb b c = True) -> c = True
857
890
> andb_true_elim_2 b c prf = ?andb_true_elim_2_rhs
858
891
892
+ $\square$
859
893
860
- === Exercise: 1 star (zero_nbeq_plus
894
+
895
+ === Exercise: 1 star (zero_nbeq_plus_1)
861
896
862
897
> zero_nbeq_plus_1 : (n : Nat) -> beq_nat 0 (n + 1) = False
863
898
> zero_nbeq_plus_1 n = ?zero_nbeq_plus_1_rhs
864
899
900
+ $\square$
901
+
865
902
866
903
\color{red}
867
904
-- TODO: discuss associativity
868
905
\color{black}
869
906
907
+
870
908
== Structural Recursion (Optional)
871
909
872
910
Here is a copy of the definition of addition:
@@ -894,6 +932,10 @@ unnatural ways.
894
932
-- TODO: verify the previous claims
895
933
\color{black}
896
934
935
+ \color{red}
936
+ -- TODO: Add decreasing exercise
937
+ \color{black}
938
+
897
939
898
940
== More Exercises
899
941
@@ -911,11 +953,24 @@ Now state and prove a theorem `negation_fn_applied_twice` similar to the
911
953
previous one but where the second hypothesis says that the function `f` has the
912
954
property that `f x = negb x `.
913
955
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
+
914
967
> andb_eq_orb : (b, c : Bool)
915
968
> -> (andb b c = orb b c)
916
969
> -> b = c
917
970
> andb_eq_orb b c prf = ?andb_eq_orb_rhs
918
971
972
+ $\square$
973
+
919
974
920
975
=== Exercise: 3 stars (binary)
921
976
@@ -953,3 +1008,7 @@ functions you will write next that will give it mathematical meaning.)
953
1008
increment and binary-to-unary functions . Notice that incrementing a binary
954
1009
number and then converting it to unary should yield the same result as first
955
1010
converting it to unary and then incrementing.
1011
+
1012
+ > -- FILL IN HERE
1013
+
1014
+ $\square$
0 commit comments