Friday, 19 September 2014

Entry #1 - Understanding Logic

In the first few weeks of class, I've managed to learn new terminology and symbols that can be used when creating an implication. Such examples of that are '¬' means  the same as 'not', 'unless' means the same as 'if not', and 'necessary and sufficient' means the same as 'if and only if'. I enjoyed the examples that were given as they help me understand logic a lot better. It also helps me to create my own examples and play around with them in order to understand them. Another part that was fun was solving the street car problem since it was a different kind of problem that I've been used to seeing and by using the techniques outlined in the lectures, I was able to take an approach at it and solve the problem. I'm liking that the logic portion is intertwining with my math class since it makes the learning much more relevant to me when I see those sorts of connections come together. I don't want to say that I feel confident about the course material, but I certainly feel as though I'm doing a good job of comprehending the material and I think that I did well enough on the tutorial. Speaking of which, I feel it would be interesting to show my approach to solving one portion of the tutorial assignment.


TUTORIAL EXERCISE (WEEK 2) QUESTION 1.

GIVEN:

Three Python programs (q1.py, q2.py, q3.py) solving the same problem.

Three test suites (t1, t2, t3) that tests them.

It is known that q1.py passes all three, q2.py fails all three and q3.py fails t1 and t2 but passes t3.

PREPARATION (OR THE LET’S PART):
Let’s consider the results of the programs going through the test suites as a set like so:

program = {t1 results, t2 results, t3 results}

If the result of the test suite with the program is a pass, the element in the set will read Pass; if the result is a fail, the element will read Fail.

Let’s create set A as a constant
set A = {Pass, Pass, Pass}

Let’s say that q1.py = set B, q2.py = set C, q3.py = set D
set B = {Pass, Pass, Pass}
set C = {Fail, Fail, Fail}
set D = {Fail, Fail, Pass}

a) All three python programs pass all three test suites (FALSE)

Test q1.py: all({x in A for x in B}). It should return True because set A = set B.
Test q2.py: all({x in A for x in C}). It should return False because set A ≠ set C.
Test q3.py: all({x in A for x in D}). It should return False because set A ≠ set D.


Since set C and set D violates the conditions and we need all of them to fit the condition, the statement ∀  x ∈ {B, C, D}, x = {Pass, Pass, Pass} is FALSE. (i.e look at q2.py & q3.py)

b) Some of the three python programs pass all three test suites (TRUE)

Test q1.py: all({x in A for x in B}). It should return True because set A = set B.
Test q2.py: all({x in A for x in C}). It should return False because set A ≠ set C.
Test q3.py: all({x in A for x in D}). It should return False because set A ≠ set D.


Since set B fits the conditions and we are only looking for one or more that fits the conditions, the statement   x ∈ {B, C, D}, x = {Pass, Pass, Pass} is TRUE. (i.e look at q1.py)

c) All three python programs don’t pass all three test suites (that is, each fails at least one test suite) (FALSE)

Test q1.py: not all({x in A for x in B}). It should return False because set A = set B.
Test q2.py: not all({x in A for x in C}). It should return True because set A ≠ set C.
Test q3.py: not all({x in A for x in D}). It should return True because set A ≠ set D.


Since set B violates the conditions and we need all of them to fit the conditions, the statement  ∀  x ∈ {B, C, D}, x ≠ {Pass, Pass, Pass} is FALSE. (i.e look at q1.py)

d) Some of the three python programs don’t pass all three test suites (that is, some fail at least one test suite) (TRUE)

Test q1.py: not all({x in A for x in B}). It should return False because set A = set B.
Test q2.py: not all({x in A for x in C}). It should return True because set A ≠ set C.
Test q3.py: not all({x in A for x in D}). It should return True because set A ≠ set D.


Since set C and set D fit the conditions and we’re only looking for one or more that fits the conditions, the statement   x ∈ {B, C, D}, x ≠ {Pass, Pass, Pass} is TRUE. (i.e look at q2.py & q3.py)

No comments:

Post a Comment