Tute (Week 1)
Table of Contents
1. Predicate Logic
1.1. Question 1
For which values of \(A\) and \(B\) does the boolean expression \(\varphi = \neg (A \Rightarrow B) \lor \neg B\) hold?
(todo)
1.2. Question 2
Simplify the boolean expression \((A \Rightarrow B) \lor (B \Rightarrow A)\)
(todo)
1.3. Question 3
A binary connective \(\bullet\) is defined as follows:
\(A\) | \(B\) | \(A\ \bullet\ B\) |
\(\bot\) | \(\bot\) | \(\top\) |
\(\bot\) | \(\top\) | \(\bot\) |
\(\top\) | \(\bot\) | \(\top\) |
\(\top\) | \(\top\) | \(\top\) |
Restate the formula \(A \lor B\) in terms of \(\bullet\). What is the \(\bullet\) connective?
(todo)
1.4. Question 4
Assuming that \(F(x)\) states that the person \(x\) is my friend and that \(P(x)\) states that the person \(x\) is perfect, what is a logical translation of the phrase "None of my friends are perfect"?
(todo)
1.5. Question 5
Given the following function
\[ f (n) = \begin{cases} 0 & \text{if}\ n = 0 \\ 2n - 1 + f(n-1) & \text{if}\ n > 0 \end{cases} \]
Prove that \(\forall n \in \mathbb{N}.\ f(n) = n^2\).
(todo)
2. Haskell
Consider the Haskell code written in the lecture.
2.1. Haskell lexical structure
- What is the difference between a
data
and atype
declaration? - What is the difference between a type and a data constructor? List the identifiers in the code which represent type names, and those which represent data constructor names.
- Which phase of the compiler would be responsible for distinguishing type and data constructors?
(todo)
2.2. Haskell programming
Write a Haskell function
mySum
that sums all elements in a list of numbers. Feel free to use the following template:mySum :: [Int] -> Int mySum [] = ??? mySum (n:ns) = ???
- Write a Haskell function
myProduct
that multiplies all elements in a list of numbers. You probably used copypaste to solve the previous question, didn't you? No reason to be ashamed, we've all done it! But let's try not to.
Find a generalisation
myBinop
that applies a given binary operatorf
with unit elementz
to a list of numbers. We will then be able to definemyProduct
andmySum
usingmyBinop
.myBinop :: (Int -> Int -> Int) -> Int -> ([Int] -> Int) myBinop f z [] = ??? myBinop f z (n:ns) = ??? mySum :: [Int] -> Int mySum ns = myBinop (+) 0 ns myProduct :: [Int] -> Int myProduct ns = myBinop (*) 1 ns
We just reinvented a wheel. The fold functions are general-purpose library functions that completely subsume
myBinop
. Try to implementmySum
andmyProduct
usingfoldr
instead ofmyBinop
.The linked library documentation references a lot of concepts that we don't assume familiarity with, so don't worry if you don't fully understand it. Perhaps start by looking at the examples.
(todo)