Showing posts with label maths. Show all posts
Showing posts with label maths. Show all posts

Sunday, October 30, 2016

Probabilistically zero events


In this short post, we show that events which are theoretically impossible to occur can be present. That is, practically there can be events which theoretically should not have occurred! Sounds fun?

Mathematically, if the probability that an event occurs is zero, does not mean that, that event cannot occur. Often, I cite the example of events that have continuous probability distribution. In such distributions, the probability that any point from sample space is selected is, in fact, zero. For example, consider [from wiki] a species of bacteria that have lifetime of about 4 to 6 hours. Thus, the probability distribution of the lifetime of these bacteria is continuous as it can take any value, say 2 hours, 7 hours, 3.0005 hours etc. Now, if we ask the following question - 

"What is the probability that a bacterium lives exactly 5 hours?".

This probability is, hold-your-breath, ZERO(0). Why? Because a lot of bacteria live for approximately 5 hours, but there is no chance that any given bacterium dies at exactly 5.0000000000... hours.

Instead, if we ask -

"What is the probability that a bacterium dies between 5 and 5.01 hours?"

This probability could be zero and can be found by integrating the probability density function of the lifetime from 5 to 5.01.

So, what did we see just now? We saw that even when an event that has probability zero (bacterium dying exactly at 5th hour), it could occur in practise (there would be bacteria that die at 5th hour)

And finally, the converse - Impossibility implies zero probability, is true!

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

Saturday, July 12, 2014

What actually is a Determinant of a Matrix? Two views!

From the way(s) it is calculated to the uses of finding it after doing such mystical calculations. , Determinant of a matrix has always been a mystery for me (except for few things like finding the rank of matrix). Today, I stumbled upon this link on Dr. Math:

http://mathforum.org/library/drmath/view/51440.html

 He has given two very different sounding yet equivalent definitions of the Determinant. Here I reproduced it in his own words:

The first is geometric. I assume you've plotted things in an x-y
coordinate system, right? I assume you can imagine doing the same
thing in three dimensions with an x-y-z coordinate system as well.

In 2-D, when you talk about the point (2, 4), you can think of the
"2" and "4" as directions to get from the origin to the point -
"move 2 units in the x direction and 4 in the y direction."  In
a 3-D system, the same idea holds - (1, 3, 7) means start at the
origin (0,0,0), go 1 unit in the x direction, 3 in the y direction,
and 7 in the z direction.

Similarly, you could have coordinates in one dimension, but there's
just one number.

The determinant of a 1x1 matrix is the signed length of the line from
the origin to the point. It's positive if the point is in the positive
x direction, negative if in the other direction.

In 2-D, look at the matrix as two 2-dimensional points on the plane,
and complete the parallelogram that includes those two points and the
origin. The (signed) area of this parallelogram is the determinant.
If you sweep clockwise from the first to the second, the determinant
is negative; otherwise, positive.

In 3-D, look at the matrix as 3 3-dimensional points in space.
Complete the parallepiped that includes these points and the origin,
and the determinant is the (signed) volume of the parallelepiped.

The same idea works in any number of dimensions.  The determinant
is just the (signed) volume of the n-dimensional parallelepiped.

Notice that length, area, volume are the "volumes" in 1-, 2-, and
3-dimensional spaces.  A similar concept of volume exists for
Euclidean space of any dimensionality.

Okay. That's the geometric definition. I like it because I can make a
mental picture of it. Here's the algebraic definition:

I'll do it in 3 dimensions, but exactly the same idea works in any
number of dimensions.  Let's look at the determinant of this matrix:

  | a11 a12 a13 |
  | a21 a22 a23 |
  | a31 a32 a33 |

The numbers after the "a" are the row and column numbers.

A permutation of a set of numbers is a re-arrangement.

For example, there are 6 permutations of the list (1 2 3), including
the "re-arrangement" that leaves everything unchanged). Ignore for the
moment the "+1" and "-1" after each one:

(1 2 3) -> (1 2 3)   +1
(1 2 3) -> (1 3 2)   -1
(1 2 3) -> (2 1 3)   -1
(1 2 3) -> (2 3 1)   +1
(1 2 3) -> (3 1 2)   +1
(1 2 3) -> (3 2 1)   -1

Now imagine that you start with three objects labelled 1, 2, and 3
arranged as they are on the left, and need to convert them to the
order on the right, but you're only allowed to swap one pair at a
time. To get to the final arrangement, you'll find that there are lots
of ways to do it, but every way (for a particular rearrangement)
always requires an even number of swaps or always requires an odd
number of swaps. I've labelled those that always need an even number
of swaps with +1 and those needing an odd number as -1 above.

Now write down 6 products of the "a" terms, where the first number
for each term is 1, 2, 3 and the second number is the rearrangement
above for each of the six rearrangements.

Here's what they are, in the same order as above.  Be sure you
understand this step:

a11*a22*a33
a11*a23*a32
a12*a21*a33
a12*a23*a31
a13*a21*a32
a13*a22*a31

The determinant is just the sum of all 6 terms, but put a "+" in
front if the rearrangement is even, and a "-" in front if the
rearrangement required an odd number of swaps.

Here's the answer:

+a11*a22*a33 -a11*a23*a32 -a12*a21*a33
+a12*a23*a31 +a13*a21*a32 -a13*a22*a31

For a 4x4 matrix, there will be 24 rearrangments, like this:

(1 2 3 4) -> (3 2 4 1) +1
...

so there will be 24 terms in the expression of the determinant.

For a 5x5 matrix there are 120 rearrangements, so there will be 120
terms in the determinant, and so on.

For an NxN matrix, there will be N! (N factorial) terms, where
factorial means you multiply together all the terms from N down to 1.
For example, 5! = "5 factorial" = 5x4x3x2x1 = 120.
 Seriously, this gyaan is totally refreshing and an eye-opener!