Ex 1 Sol
Ex 1 Sol
Note: As this is our first exercise, I will give some more comments than in future exercises:
➤ Solve the exercises below until Tuesday, the 15th of October. There will be a MS Teams task available
until that day at 8 o’clock in the morning, in which you can check those exercises you could solve.
➤ In some tasks below certain sets of numbers will occur, e.g. the natural numbers N = {0, 1, 2, . . .} or the
real numbers R, which are essentially all numbers we can imagine except the complex numbers.
➤ This exercise is more focussed on R than future exercises. Don’t be shocked – the introductory text to
some of these exercises is long, but the actual questions (and answers) are much shorter.
Task 1.0: If you haven’t done so far, install the most recent versions of R and Rstudio. We will need it
throughout the exercises this semester. If you encounter problems during installation, post in the lecture forum.
Also have a look at chapter 1.4 of the R Introduction pdf (pages 7 to 9).
(a) Translate the following compound statements into mathematical notation using A and B:
➤ It is freezing cold and it is snowing. A ∧ B
➤ It is freezing cold, but it is not snowing. A ∧ ¬B
➤ It is neither freezing cold nor snowing. ¬A ∧ ¬B
➤ It is snowing or freezing cold, but not both. A xor B
➤ It is snowing if it is freezing cold. A =⇒ B
➤ It is snowing or freezing cold, but it is not snowing, if it is freezing cold. (A ∨ B) ∧ (A =⇒ ¬B)
➤ It is snowing if it is freezing cold and it is freezing cold when it is snowing. A ⇐⇒ B
(b) Look outside to find out, if the statements A and B are true or false (at the moment). Which of the above
compound statements are false? Negate them to turn them into true statements. Currently both A and B
are false. (a) is therefore false and its negation is ¬A ∨ ¬B. (b) is false (negation: ¬A ∨ B), (c) is true,
(d) is false and its negation is (¬A ∨ B) ∧ (¬B ∨ A), which is the same as (¬A ∧ ¬B) ∨ (A ∧ B). The
implication in (e) is true, (f) is false (negation: (¬A ∧ ¬B) ∨ (A ∧ B)). (g) is true.
Task 1.2: Which of the following statements are propositions, which are predicates? In case of a proposition,
determine its truth value and formulate its negation. In case of a predicate, find its truth set.
1
6. a · b = b · a If restricted to numbers a and b, then true proposition. True in general? Negation is
∃ a, b : ab ̸= ba.
7. If x > 2, then x2 > 4. true proposition, negation is x > 2 and x2 ≤ 4.
8. If m is an even natural number, its square m2 is also even. true proposition, negation is m is even and
m2 is odd.
9. If s2 is an odd natural number, s is also odd. true proposition, negation is s2 is odd and s is even.
Task 1.3: Let P and Q be propositions. We saw in our first lecture that we can combine propositions to more
complex expressions using logical operators, e.g. ∧, ∨ or =⇒ . Furthermore, we learned that if a proposition
is always TRUE, it is called a tautology; if it is always FALSE we call it a contradiction. Are there any
tautologies or contradictions among the following propositions? Use truth tables to find out!
2. P ∧ Q =⇒ ¬P
3. P ∧ [¬(¬P ∨ ¬Q)] (≡ P ∧ Q)
5. (P ∧ Q) =⇒ (P ∨ Q) tautology
6. (¬P =⇒ P ) =⇒ P
7. (¬P =⇒ P ) ⇐⇒ P
8. (P ⊕ Q) =⇒ (P ∨ Q)
P Q ¬P ¬P =⇒ P (¬P =⇒ P ) =⇒ P (¬P =⇒ P ) ⇐⇒ P
T T F T T T
F T T F T T
2
Just create the truth table of the left and right sides of ≡ and see that they are equal.
Task 1.5: Determine the truth sets of the following predicates P (n). n is always a natural number.
1. P (n) : n + 8 > 3 N
2. P (n) : n2 + 2n − 8 > 0 {3, 4, . . .}
3. P (n) : n2 − 4n + 3 < 0 {2}
1. On a (hypothetical) island two kinds of inhabitants are living: people, who always tell the truth and
people, who always lie. You meet two of them, A and B. A says ’Exactly one of us is lying.’ and B says
’At least one of us is telling the truth.’. Who (if anyone) is a truth-teller? The solution is: Both are lying.
We can solve this by using a truth table, which you see below.
In the first 2 columns we write all possible combinations, which can occur – a T in the first two columns
means that this person is telling the truth, a F means that he is lying. Next, we put the statement, which
A gives, into the third column. We just look at the content of the statement and not, who said it. In the
first row (where both A and B tell the truth), the statement Exactly one is lying is of course false. In the
same way we fill in the other 3 rows of the 3rd column. The same we do for the 4th column, where we
evaluate the statement At least one is telling the truth – this is true for the first 3 rows and false for the
last row.
Now, having completed columns number 3 and 4, we take into account, who made the statement. At first
we compare the columns 1 and 3. The truth values in these two columns must agree. Why? If there is
a T in the first column this means that A is telling the truth, so his statement in the 3rd column must be
true, which is not the case for the first row and the third row. So considering just A only the 2nd row (A
tells the truth, B is lying) and the last row (both are lying) are remaining as possible solutions.
Now we do the same for B and his statement, so we look at the columns 2 and 4 and find those rows with
identical truth values. We see that here rows 1, 3 and 4 are remaining. If we now combine the results for
A and B, we see that only the last row (both are lying) is remaining, which is the solution.
2. On the same island with truth-tellers or liars you meet two other people, C and D. C says ’We are both
telling the truth. ’ and D says ’C is lying.’. Who (if anyone) is a truth-teller? C is lying and D is telling
the truth. We do it in exactly the same way as above and find that only in row 3 (which says that C is
lying and D is telling the truth) the first two columns agree with the second two columns.
3
3. Three criminals (Alfred, Bob and Chris) are suspects in a crime and are questioned at the police station.
Alfred says: Bob and Chris were the offenders. I didn’t do anything. Bob says: It was Alfred alone. Me
and Chris did not participate. Finally, Chris says: It’s been Alfred and Bob – I am innocent.
➤ If we further know that innocent people say the truth and guilty people always lie, who of the three
participated in the crime in any case? Bob
➤ Now Bob is questioned one more time. He is honest and admits the crime. Furthermore he says: Also
the other two were lying. Who committed the crime? all
We arrive at a solution in a similar way as before. In the first 3 columns we write a T, if this person participated
in the crime and an F, if he did not participate. In the next 3 columns we evaluate the content of the 3 statements.
After completing now the first 6 columns, we compare columns 1 and 4 in a first step. Valid solutions must
have opposite truth values, because a T in the first column means that he participated and therefore is lying,
therefore his statement must be false (and vice versa). Then we compare columns 2 and 4 and finally columns
3 and 6. If all the 3 pairs of columns have opposite truth values – this is true for the rows 1, 2 and 5 – this
solution is still possible. These rows have in common, that the truth value is always true for column B, so Bob
must have participated in the crime. With the last information, that all 3 were lying, we know that only row 1
is remaining, so all participated in the crime.
4
Task 1.7: In this task we learn how to subset data frames (see also chapter 7.2 on pages 68 and 69 in the R
notes). We will use the data set named Auto in the R package ISLR, which is a data frame containing some
technical data on cars. Each row represents a different car model, each column a different technical parameter.
At first, install and load the package ISLR from CRAN1 , get informed about the meaning of the variables using
the help() function and then use proper R functions to answer the following questions:
1. How many rows and columns does the data frame have?
2. How many cars with a displacement value less than 250 do exist in the data set?
3. Find the name of the European car with the highest weight.
4. Find the average displacement of all European cars having a model year of (19)71.
# load package
require(ISLR)
# number of rows and cols
dim(Auto)
[1] 392 9
# smaller cars
sum(Auto$displacement < 250)
[1] 266
# average displacement
mean(Auto[Auto$origin == 2 & Auto$year == 71, "displacement"])
[1] 95
1
To install an add-on R package, choose Tools - Install Packages from the Menu in RStudio. In the Packages field enter
the package name (ISLR) and be sure that Install dependencies is checked and press Install. Now you have the package installed.
To use it in the current R session, type require(ISLR) in the console. Note that installing package is only necessary once, but
loading a package via require() must be done in every new R session.