Questions like cost me a great first test score.
I just didn't understand them, and figured, because it was programming related, the probability of being tested on it was low. In retrospect, I'm an idiot.
I did manage to understand the question, in the last few minutes of the exam, but of course, that wasn't enough time to do complete the question.
This is the way in which I understood it;
P(x) is a boolean function, that takes the arguement 'x'.
It will return a value, either True or False.
The parantheses means that boolean function P takes x as an arguement.
L is a list.
(x) are values in the list, that when passed through P(x), return a boolean value.
[...for x in L] is saying, for each value 'x' in the list L.
[P(x) for x in L] is saying, pass value x through function P, for each value x, in the list L.
In other words, each value in the list will be passed through the function to return different boolean values.
Its closed in "[ ]" because we are collecting a list of those values.
So when we say
return False in [P(x) for x in L]
We are asking the program to tell us, if there is a single False in the list of boolean values we've collected, if so return True, because it does exist.
If not, return False, because it does not exist.
This is an example of Universal quantification, as we are trying to find a signle counter example to refute it, and if it doesnt exist, the statement is true.
No comments:
Post a Comment