Sunday, October 25, 2009

Properties of Addition, Subtraction

Properties of Addition : The following are the properties for addition.

Commutative property : It says that we can change the order of numbers (operand). Given a expression where we have multiple additions (say A+B+C+D, where A,B,C,D are numbers), commutative property says that we can place the numbers A,B,C,D wherever we want in that expression. Something like this B+C+A+D. In short, (A+B)=(B+A).

Associative property : It says that we can change the order of addition (operation). Consider the same expression A+B+C+D, associative property says that we can perform additions in any order. Say we can compute B+C first, and then add D to it and finally we could add A to it. In short A+(B+C) = (A+B)+C.

The above two properties though looking simple, are very effective and helps us in doing fast computation. Say we need to compute 23+65+12+35. Here we can compute 65+35 first with the above two properties and then compute 23 and 12. This makes it easy for us to add, ie 65+35=100 and 23+12=35 and then 100+35 = 135.

Additive Identity : Additive Identity, is any number which when added to a number N will result in the same number. Ie, N+0=N. Hence 0 is the additive identity.

Additive Inverse : Inverse identity, is any number which when added to a number N, will result in zero. Here N + (-N) = 0. Hence, in general, additive inverse of N is –N.

Properties of subtraction : The following are the properties for subtraction.

Commutative property does not exist for subtraction : Say we have to compute 2 - 3 , now if we do 2-3 = -1 and if we place the number as 3-2, it equals 1. Hence Commutative property is not applicable to subtraction.

Associative property also does not exist for subtraction. Say we have 2-(3-4) = 2-(-1) = 3. Now if we change the order of subtraction, (2-3)-4 = -1-4=-5. Hence associative property also does not exist for subtraction.

Identity : Same as that of Additive identity. 0+(-N) = -N , where N is positive.

Inverse : N is the inverse of a number –N where N is positive, since N-N=0.

Sunday, October 12, 2008

Order of Operations - BODMAS

As said here in this topic, when using Infix notation, we either need brackets or some rule to say the order in which we evaluate an expression. Say we have to evaluate 3 + 5 x 8, this thing possibly has two solutions depending on the priority we give to the addition and the multiplication operator, that is, 8 x8=65 or 3+40=43. When there isn't a particular standard followed, we will end up in wrong interpretation. Thus came the order or precedence of operators.

1) B or P - Brackets or Parenthesis
2) O or E or I - Orders or Exponents or Indices (square roots, powers, radix etc.)
3) D - Division
3) M - Multiplication
4) A - Addition
4) S - Subtraction

Since 5 x 8 / 4 will yield the same result when either one of multiplication or division is given the higher priority, either of it can be calculated first and thus they share a same level of precedence. Same is the case with the addition and the subtraction operators.

Let us have an example. (3 * (52 + 5) ) /5 + (3*15)/5

Here there are two (outer) brackets, hence we have to evaluate those two first. The expression in each bracket should be considered as a separate expression and should be evaluated separately by following BEDMAS separately. Two brackets that are not nested, can be evaluate them in parallel.

we have an exponent. 52 = 25. We don't have division. Then we have multiplication. 3* 25 = 75. Then we have addition 75+5=80. Now that the first bracket is evaluated. We can evaluate the other bracket in parallel to this. Here goes simple steps.

(3 * (52 + 5 )) /5 + (3*15)/5 - Outer Brackets - Ist and IInd
= (3 *( 25 + 5) )/5 + 15/5 - Inner bracket (power) of Ist, Multiplication of IInd
= (3 * 30)/5 + 15/5 - Addition in inner bracket of Ist - BEDMAS in Ist and IInd bracket over
= 90/5 + 15/5 - Multiplication in Ist outer bracket
= 18 + 3 - Division can be performed in parallel.
= 21 - BEDMAS for the expression is over - Final Result.

If the bracket operator is nested, like
(3 + (5*4)) , then the inner bracket should be evaluated first

When we come across something like this, 27/3/3, we need to know whether we evaluate from left to right, or right to left. Mostly we take it left to right. Hence we would evaluate this as (27/3)/3 = 9/3 = 3

Sunday, September 14, 2008

Infix, Prefix and Postfix

An operator is a function that specify specific actions on objects. Those objects which acts as an input to the operator is called an operand. For eg., in 3+5 , the symbol "+" is a addition function (operator) which operates on the operands "3" and "5" to produce the result 8. Depending on where we place this operator and the operands, we have three different notations.

Infix: This is the common notation that we use in mathematics. Here the operators are put in between the two operands as in 3+5. Infix operations either require parenthesis or order of precedence to correctly evaluate an expression.

Prefix: Also called Polish notation due to the Polish logician Jan Ɓukasiewicz, who invented this notation. In this, the operators are put before the operands. Eg., +AB , where + is the operator. A,B are operands which has some value. It is mainly developed to avoid parenthesis in expressions.

For eg., let us take 2 + 6 / 8
Here we can use a bracket around 3+5 or we can give higher priority to division and evaluate the expression as (2+6)/8 = 1 or 2+6/8 = 2+0.75 = 2.75
So if we want the correct results we need to use brackets or precedence rule. The same expression, in prefix notation, can be written as / + 2 6 8
= / + 2 6 8
= / 8 8 (Note: / A B means "divide A by B" and not "divide B by A")
= 1
Here / operates on "the result of + 3 5" and 8. The result of + 3 5 is 8. This eliminates the ambiguity on what to evaluate first in the expression. If we note here, in prefix notation, the number of operators will always be one less than the number of operands. In our case, 2 operators and 3 operands.

Postfix: In postfix notation, also called reverse polish notation (RPN), we place the operators after the operands. This notation was proposed by F. L. Bauer and E. W. Dijkstra to reduce computer memory access and utilize the stack to evaluate expressions. eg., 5 3 -
Note: 5 3 - equals 5 - 3 = 2 and not 3 - 5 = -2
Thus - 5 3 in prefix is the same as 5 3 - in postfix

These prefix and postfix operations are often used in computer languages and in calculators for ease of calculation in the background. Since we are much familiar with the infix notation, we generally have a user interface which is in infix notation.

Let us take the discriminant of quadratic equations, B2-4AC
Infix : B^2-4*A*C
Prefix : -^B2**4AC
Postfix: B2^4A*C*-