Please download the answer file and edit it on Rstudio. Write your student number in the correct place at the beginning of the answer file. You should be able to Knit HTML and get the same results as the document you have in paper. Please do Knit often and verify that your document has no errors. If your document does not Knit, you will not have full grade.

When you finish, send the answers.Rmd file to my mailbox (andres.aravena+cmb@istanbul.edu.tr). Be sure to use the correct email address and send only one file.

IMPORTANT: Write your student number in the correct place at the beginning of the answer file.

1 Logic operations

For the following questions you will use X and Y defined as follows

X <- rep(c(TRUE, FALSE), 2)
X
[1]  TRUE FALSE  TRUE FALSE
Y <- rep(c(TRUE, FALSE), c(2, 2))
Y
[1]  TRUE  TRUE FALSE FALSE

These are all the possible combinations of two logic variables. Now we want to see what happens when we combine them

1.1 Evaluate “X and Y

[1]  TRUE FALSE FALSE FALSE
# write here

1.2 Evaluate “X or Y

[1]  TRUE  TRUE  TRUE FALSE
# write here

1.3 Evaluate “X and not Y

[1] FALSE FALSE  TRUE FALSE
# write here

1.4 Evaluate “not X and not Y

[1] FALSE FALSE FALSE  TRUE
# write here

1.5 Show that “not X and not Y” is the negation of “X or Y”. Print both results in different lines, so we can see they are the same. This is called De Morgan’s rule.

[1] FALSE FALSE FALSE  TRUE
[1] FALSE FALSE FALSE  TRUE
# write here

1.6 Show that “not X or not Y” is the negation of “X and Y”. Print both results in different lines, so we can see they are the same. This is also called De Morgan’s rule.

[1] FALSE  TRUE  TRUE  TRUE
[1] FALSE  TRUE  TRUE  TRUE
# write here

1.7 (Bonus) Can you prove that X and Y are really all combinations of two logic variables?

Write your comment here. Keep the > and delete the rest

2 Combination of three logic variables

Consider now A, B, and C, defined as follows

A <- rep(c(TRUE, FALSE), 4)
A
[1]  TRUE FALSE  TRUE FALSE  TRUE FALSE  TRUE FALSE
B <- rep(c(TRUE, TRUE, FALSE, FALSE), 2)
B
[1]  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE
C <- rep(c(TRUE, FALSE), c(4, 4))
C
[1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE

These are all the combinations of three logic values.

2.1 Show that “A and the result ofB or C” is equivalent to “the result of A and B, or the result of A and C”. Print both results in different lines, so we can see they are the same. This is called Distributive rule.

[1]  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE
[1]  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE
# write here

2.2 Show that “A or the result ofB and C” is equivalent to “the result of A or B, and the result of A or C”. Print both results in different lines, so we can see they are the same. This is also called Distributive rule.

[1]  TRUE  TRUE  TRUE FALSE  TRUE FALSE  TRUE FALSE
[1]  TRUE  TRUE  TRUE FALSE  TRUE FALSE  TRUE FALSE
# write here

2.3 (Bonus) Can you show the associative rule?

# write here

2.4 (Bonus) Can you show the commutative rule?

# write here

3 Modifying a vector

In contrast to single-value variables, when we use indices to modify a vector, it changes on place.

The answers to the following questions should work for any vector v. For the sake of example, consider the vector v defined as

v <- seq(from=7, to=1)
v
[1] 7 6 5 4 3 2 1
# write here

3.1 Change the first element to 8 and show the updated vector v.

[1] 8 6 5 4 3 2 1
# write here

3.2 Change the sign of the second element and show the updated vector v.

[1]  8 -6  5  4  3  2  1
# write here

3.3 Add 7 to the third and fourth element and show the updated vector v.

[1]  8 -6 12 11  3  2  1
# write here

3.4 Change again the sign of the second element and show the updated vector v.

[1]  8  6 12 11  3  2  1
# write here

3.5 Increase the last three elements by 10%.

[1]  8.0  6.0 12.0 11.0  3.3  2.2  1.1
# write here