# Jorge Valle Jorge Valle is a front end developer with a particular passion for, and expertise in, JavaScript and user interfaces. Lately, he's also been diving into machine learning.

# Pi notation and JavaScript implementations

## Index

Also called the product notation, capital Pi notation is the mathematical shorthand to express the product of a series of numbers, where an optional function has been applied to each iteration.

## Why? The motivation behind the notation

Imagine having to represent - mathematically - the product of numbers one through ten.

Seems unnecessarily long, but manageable. What happens when we try to represent the product of numbers one through one hundred?

It quickly gets silly and inefficient. The problem is further compounded if we wanted to express the product of a series where we apply an operation to each iteration, like adding two to each step.

Completely unwieldy.

Through Pi notation, we can tersely express the product of a series of numbers, where an optional operation has been applied to each iteration. If you understand the loop construct in programming, capital Pi notation is very easy to grasp.

## The notation and its parts

Here's the notation.

It's best explained broken down into the different components. In the example above, there's the:

• Index of multiplication, $i$.
• First value, $1$.
• Last value, $10$. It sits on top of the Pi.
• Expression, the actual operation we will apply to every iteration.

## Examples with JavaScript implementation

Going back to the original example: in this expression, we are simply multiplying every number from one to ten. The multiplication is implied by the product notation itself.

Here's a JavaScript implementation with a for loop.

In this expression, we are multiplying the square roots of every number from one to 5. The actual multiplication of each iteration is implied by the capital Pi.

Here it is implemented with a for loop. 