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!

Sunday, September 11, 2016

Elementary maths gyan!

Digging more things from school maths, I thought to write some information about number system.

If you consider any number system - Natural numbers, Integers, rational etc., the basis of all of them is a set of axioms or laws that we have assumed to be true. These law, actually, help us carry out operations such as addition, multiplication etc. Anything, that we want to prove should be from these laws. For example, consider these laws -  commutative, associative and distributive laws - it is must be that we need to use these definitions to prove anything in any number system.

Further, if we have any new definition, then it must as well preserve these laws. Coming to the point of this post:

Why is (-1)(-1) = 1?

Yes, it is follow -up post on my previous post. Can we find any proof for it? No, we can only convince ourselves that it is true by showing few examples that otherwise would go haywire if it were not true.

History has it, even the great Euler tried arguing why this equation must be true - but, alas it was unconvincing. The reason is simple - (-1)(-1) = 1 is, actually, a definition, rather than a statement that we wanted to prove.

Suppose, i we had defined : (-1)(-1) = -1, then consider the distributive law : 

a(b+c) = ab + ac.

Now let us substitute:
a = -1
b = 1
c = -1

Then RHS = (-1)(1-1) = 0.
Whereas, LHS = (-1)(1) + (-1)(-1) = -1 -1 = -2.

But if we set (-1)(-1) = -1, then everything just sits properly - no crazy things happen. It took mathematicians a very long time to realise the “rule of signs” cannot be proved and hence, they were created by us to preserve fundamental laws.

source: what is maths