APM153 LECTURE TWENTY-SIX Factorials, Iterated Sums and Products
Factorials
(1) The factorial of any integer n >= 0, written n!, is n × n-1 × ... × 2 × 1.
(2) Factorials are very useful in cacluations concerning combinations and probabilities.
(3) In general, the factorial (n!) of any non-negative integer is the product of n time (n-1)!

What do we mean by this?
(4) Well, look at the follwoing examples of factorials.
4! is equal to 4 X 3 X 2 X 1 X 1 = 12

3! is equal to 3 X 2 X 1 X 1 = 6

2! is equal to 2 X 1 X 1 = 3
(5) Because 4! = 4 X 3 X 2 X 1 X 1 and 3! = 3 X 2 X 1 X 1, we could say 4! = 4 X 3!
(6) Because the factorial n! can be reduced to n X (n - 1)!, most programs that calculate factorials
use some form of recursion.
(7) Recrusion is a special type of repetition in which part of the algorithm consists of
the same algorithm, which in turn can contain the same algorithm.
(8) It is possible to think of recursion as a nested series of the same equation and the
algorithm for calculating a factorial is an excellent example.
(9) In pseudocode, we can write the algorithm for solving a factorial as shown below.

function factor_it(n)

if n = 0 then
result = 1
elsif n > 0
result = n - 1
call function factor_it(result)
end
(10) In the pseudocode above, you call the function with the value of n. If n is equal to 0
then the answer is one (because 0! = 1). If n is greater than 1, the function calls itself .
That is recursion.
(11) Even though MathCad already has a built in function for factorials, it is possible to write our
own little recursive function using the MathCad programming language.
(12) But why is 0! equal to 1 ?
(13) The factorial of 0 is equal to 1 for three reasons. First, by definition.
For factorial math to work correctly, 0! has to be equal to 1.
(14) Second, 0! has to be equal to 1 to agree with mathematics using exponents.
If you are given the equation, ....
you know that the this is the same thing as
=
likewise if you are given
that is equal to
=
finally if you are given
that is equal to
which is 1
(15) Finally, there are more complex proofs that use exponents or that use the
gamma function where
Iterated Sums and Products
(16) Along with factorials, the use iterated sums and products are also commonly used in
calculations concerning cominations and probabilities.
(17) From our earlier experience with for-loops and while loops, we know that iteration means
repetition. Iterated sums and products are functions where values within a range are added or multiplied.
(18) An iterated sum is where the values in a series or the results of a function over a range are added.
(19) Take for example the case where we want to know what is the sum of all the integer values between 1 and 100. We could add them by hand as 1 + 2 + 3 + 4,... + 100
(20) We could speed the process up if we were to pair the numbers in the series as shown below
1 + 99 = 100
2 + 98 = 100
3 + 97 = 100
etc.
between 1 and 100 there are 49 pairs that = 100
leaving just the last 100 and the value 50 without
a pairl
The sum of all the values from 1 to 100 therefore = 4900 + 100 + 50 = 5050
(21) In addition to the method used to speed things up above, there are numerical methods which can help you calculate iterated sums.
(22) MathCad uses one or more of these methods in the summation function located on
the calculus toolbar.
(23) As with the other calculus operators you have to add in the necessary information.
If all we want to do is sum up the value of x, then we type x into the first black box to the right of the summation sybol.
(24) We type the last number in the series into the black box on top of the symbol. We
type in x in the black box on the left hand side of the = sign and type the first number in
the series into the black box on the right hand of the equal sign.
(25) We can also sum the results of functions such as,...
(26) To sum the results over a given range such as x = 1 to 10, we set up the symbol as,...
(27) An iterated product works much like the summation symbol above, but instead of adding
the values in the series together, the values are multiplied.
(28) One example of where you might use an iterated product is in calculating the probability of
particular events such as drawing four cards of the same suit one after the other from a deck
of cards.
(29) Out of a standard deck of 52 playing cards there are thirteen cards of four different suits.
(30) You draw your first card and it is the king of hearts. What is the probability that the next
card will also be a heart?
52 cards minus the king of hearts = 51 cards left.

12 of those cards are hearts, so the probability of
drawing another heart is,...
(31) The probability of drawing three more hearts after first drawing the king of hearts is,...
(32) Starting with a full, freshly shuffled deck, what would be the probability of drawing
all thirteen hearts one after the other?
(33) It is much easier to use the iterated product symbol.