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

Sunday, December 27, 2015

Maths is fun and non-intuitive

It's been more than a year now! Someday, I will be frequent here.

Anyways, it's been a while, I love studying maths - not advanced maths, but that high school level maths - everyone knows! I am at a stage where I feel that whatever I studied during my school was just a bunch of formulas and equations, without even questioning the basic facts. Here's one:

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

Why is it that way defined, can we prove. We just accepted the fact :D

Okay, that brings to this post's topic - Maths is indeed fun, but sometimes it questions our beliefs, intuitions and common sense! Let's consider the system of rational numbers - that we studied in schools - 1/2, 21/7,99/100 etc. On the number line, we can identify each of these numbers. If I am given an interval (or a line segment) [a,b], then I can easily show a rational number q such that a<=q<=b, however small the interval may be! [read that again]

This is the reason, why we say that the rational numbers are dense on the line. That implies there may infintely many of them, even if the interval is teeny-tiny! This seems intuitive. But hang-on, here is an interesting thing - Even though rational numbers are dense on the line, what if I show a point on the line that does not collide with any of the infinitely many rational numbers? Seems paradoxical right? Given an interval [1,2] with infinite rational numbers, there is a point $p$ on the interval that manages to avoid contact with any of the rational numbers!

Hold your breath, I chose $p=\sqrt{2}$. It lies in [1,2] which has infinitely many rational numbers but this point evades all of them! Confused! That's the reason no one believed such numbers exist - from Greeks to even neo-Mathematicians - that questioned their rational thoughts - hence they are irrational numbers!

Source: What is Mathematics?

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




Saturday, July 12, 2014

Eigen Vectors and Basis!


Looks like, I'm on a roll with Dr. Maths. He's explained Eigen vectors this time, and trust me this is the best one, so far I have come across.

Source: http://mathforum.org/library/drmath/view/51971.html
I will give you a physical description, i.e. using 2 or 3 dimensions
only, though the ideas can be extended to n dimensions where n is as
big as you please.

You will be aware that if say a (2x2) matrix M operates on a two-
dimensional column vector v, then that vector is transformed in
magnitude or direction or both to the vector v'.

    So   M.v = v'

Now for the general (2x2) matrix M there are 2 eigenvalues k1 and k2
with associated eigenvectors u1 and u2 with the property that:

        M.u1 = k1.u1

        M.u2 = k2.u2

So any point on the vector u1 is transformed to k1.u1 when operated
upon by M, and similarly any point on u2 will move to k2.u2 after
transformation by M.  In some problems where M is to transform a
complicated figure or we wish to describe the transformation clearly,
it is convenient to use u1 and u2 as the base vectors - i.e. give
coordinates of all points in terms of u1 and u2 rather than the usual
(x,y) coordinates, and the transformation matrix then becomes

        |k1    0|
        |0    k2|

We can find powers of matrices very conveniently using eigenvalues and
eigenvectors.  It is easy to show that

  M = (u1 u2)|k1   0|(u1 u2)^(-1)
             |0   k2|

where (u1 u2) is the 2x2 matrix P formed by the columns of u1 and u2.

 Then M^n = P|k1   0|^n P^(-1)
             |0   k2|

      M^n = P|k1^n    0|P^(-1)
             |0    k2^n|

In probability theory, powers of matrices are frequently required,
sometimes infinite powers, so some device for handling such a problem
is clearly very important.

Again, mind-blowing view of something that we hear daily. In short, if you choose your basis to represent a vector as the eigen vectors of the transformation (or Matrix) then working with the new transformation (or matrix) and new vector is simple and straight forward!