Thursday, January 24, 2013

Week 2 Tutorial Problem

I was at first confused at how to solve tutorial problem 2 b):
 

 
 
So, what I first did was write out the statement in English. I started with the implication from left to right which was:


 "if there exists an x in D, where x is in P and Q     implies    there exists an x in D, where x is in P and that there exists an x in D where x is in Q"

I placed a large space around "implies" to remind myself what the antecedant and the consequent were. The statement made sense to me, because if there was an x in the intersection of P and Q, then there is an x in P, and an x in Q.  Writing the implication from right to left I got: 

"if there exists an x in D, where x is in P and there exists an x in D, where x is in Q     implies     there exists an x in D, where x is in the intersection of P and Q"  


From that I could see the implication doesn't work from right to left, because there could an x in P and not Q, and an an x in Q and not P, so we cannot conclude that there is an x in the intersection of P and Q. So the implication doesn't work from right to left.
 
So for me, writting out the statement in English made it more clear to me if the claim was true of not.

Note: If the spacing looks inconsistant, it is because the word editor likes to sometimes remove inserted blank lines.

Wednesday, January 16, 2013

What I learned: List Comprehensions.

The most interesting thing I learned last week was using list comprehensions in Python.

During last week's Wednesday's lecture, when talking about certain boolean functions, the professor rewrote those boolean functions using list comprehensions.

For example the piece of code:

for x in L1 :
    if x in L2 : return False
return True

Can be rewritten with list comprehensions as:

return False in [x in L2 for x in L1]

In my opinion the second piece of code is more clearer and concise than the first piece of code. I wish I knew about list comprehensions when I took CSC148 last semester, as it seems like a much easier and clearer way of manipulating and using lists.