More Exercises
Boolean_functions
Use the knowledge taught so far to solve the theorem:
Identity_fn_applied_twice (f: Bool/ -> Bool/) (e: (x: Bool/) -> Equal/ Bool/ (f x) x) (b : Bool/) : Equal/ Bool/ (f (f b)) b
Identity_fn_applied_twice f e b = ?
Then, solve the negation_fn_applied_twice
theorem, which is the same as the previous one, but changing the hypothesis to Equal (f x) (Not x)
Andb_eq_orb
Prove the following theorem (Remember that you can prove intermediate theorems separately):
Andb_eq_orb (b: Bool/) (c: Bool/) (e: Equal/ Bool/ (Andb b c) (Orb b c)) : Equal/ Bool/ b c
Andb_eq_orb b c prf = ?
Binary
Consider a different representation of natural numbers using a binary system instead of unary. That is, instead of having only zero or one successor of a number, we can have:
- zero;
- twice a number;
- twice a number plus 1.
- First, write an inductive definition of this type, calling it
Bin
. (Remember that, in essence, the definition ofNat
aszero
orsucc n
has no intrinsic meaning. It only says that an element ofNat
can be azero
or a succ n
ifn
is alsoNat
. The interpretation of this as a system of values 0, 1, 2, etc., comes from how we work with this typeNat
. Your definition ofBin
ideally will be as simple as well. It will be the functions you make onBin
that will give mathematical sense to it). - Then write an
Incr
function to increment aBin
, and aBin_to_nat
function to convert fromBin
toNat
. - Write five proofs that test your increment and conversion functions. Note that incrementing a binary and then converting it should result in the same result as converting it first and then incrementing the
Nat
.