Showing posts with label implicatons. Show all posts
Showing posts with label implicatons. Show all posts

Tuesday, September 20, 2016

more on if...and only if


This is the follow-up post on my previous post.

In this post, I will try to explain a simple and practical idea of the statement: p -> q.

p -> q means, in simple words, that p implies q or if p then q. Check more details about this here. So what, exactly, is necessary here? And what is sufficient in this context? Behold the following text.

This example, I will give, comes from SQL - the language that we use to write RDBMS queries, to fetch data from databases. If you are familiar with SQL, you skip to next para. Here I give a vague intro. One of the reports that we frequently use on such data is of the kinds where we look for what the data is indicating, in its entirety. Such functions in SQL are called aggregate function. For example, suppose we have bank transaction data in number of records, each record has month (1-12), day(1-31) and amount credited(+) or debited(-) on that day. Now suppose we want to MAXIMUM amount of transaction credited in each month. Then we have a simple query-

SELECT MAX(amount)
from bank_transactions
group by month;

That's it - for each month I have the maximum amount that was credited. Notice - MAX is a aggregate function and the aggregation is done on the basis on month. And suppose if we skip the group by clause - then the query will give the transaction that had maximum credit in all the transactions. So group by clause is not mandatory is we are using aggregate functions. But, we are using group by clause then we need to use some aggregrate function - MAX, AVG, SUM etc since this functions tells SQL - what data must be aggregrated and how it should be aggregrated. So feeling better now. Let's come back to p -> q now.

Now we know two things:
1.      We can use aggregate functions without any group-by clause.
2.      If we are using group-by clause, then we need to use some aggregate function.
So can we put this information in terms of p -> q? Surely. Let:
            p: group-by clause is used
            q: aggregate function is present

then p -> q means
“if group-by clause is used then aggregate function is present”

Wow! That was easy, right. Now:

1.      If I see a query where group-by is used, then I am damn sure that it has to have some aggregate function. That means, aggregate function must necessarily be present if the query has a group by clause. So, in this case, p is necessary for q. It must happen, if q has happened. Although, there could be another way p could happen, but what I am sure is, that if q has happened p should follow too. But if I see an aggregate function(q) in a query, then I cannot say that there is a group-by clause(p) in it. Hence, for q, p is not necessary.
2.      Another way to look is – if I see a group-by clause in a query then, it is sufficient for me to conclude that there was an aggregate function used. In this sense, p is sufficient for q to happen. Again, there are other ways for q to happen. But that doesn’t mean that seeing just aggregate function I can say if there was a group-by clause involved in it or not. Hence, q is not sufficient for p.


Hope, you enjoyed this post!

Friday, August 15, 2014

if...and only if


I always get confused with these things. I read it, understand it and then forget it. So that's why I wrote it down.

p -> q
This means if p then q. Two views on this implication:

1. Here p is the sufficient condition, in the sense that it is sufficient to conclude that q happened if we are sure that p happened. This also means, that there are other ways of making q happen and one of them is p.

2. Here q is the neccessary condition, in the sense that q is necessary condition for p to happen. But p may either choose to happen or not choose to happen and hence q is not sufficient condition for p.

Eg: Amit will eat the fruit -> fruit is an apple
1.  To conclude that the fruit is an apple, it is sufficient to find if Amit ate the fruit. So Amit will eat the fruit is sufficient condition for fruit to be an apple. Note that it is not the necessary condition as fruit could be apple but Amit did not eat it.
2. Here fruit being apple is necessary condition for Amit to eat the fruit since it means Amit will only eat apples. Note that, Amit will only eat apples and the given fruit being apple is not sufficient as Amit might choose not eating all the apples given to him.

In short, for q to happen, it is sufficient that p happens (and there could be other ways of making q happen). And, for p to happen, it is necessary that q happens (this is the only condition to make p happen and nothing else).

p <-> q
Here q is both necessary and sufficient condition for p. Consider:
Eg: Amit will eat fruit <-> fruit is an apple
It means that Amit will eat all and only those fruits that are apples. He will not leave any apple uneaten and he will not eat any other fruit. Hence, given fruit is apple is both a necessary and sufficient condition for Amit to eat the fruit.



P.S. p -> q means (a) if p then q or (b) q if p or (c) p only if q.
P.P.S. The 'if' in the above statements can be replaced by 'when' or 'whenever'.


Source: wikipedia.org