## Factorial

Monday, April 15, 2013

Calculating factorial numbers is frequently used to compare programming languages. Usually the implementation is simple, as is the one in Factor:

```
MEMO: factorial ( n -- n! )
dup 1 > [ [1..b] product ] [ drop 1 ] if ;
```

I hadn’t realized until I skimmed the Wikipedia article on Factorials that there are actually many more kinds of factorials and what Factor really needed was implementations of all of them!

### Lots of Factorials

**primorial**

Similar to the factorial, the primorial is the product of the first

nprime numbers.

**double-factorial**

The product of all the odd integers up to some odd positive integer

nis called the double factorial ofn, and denoted byn!!.

**multifactorial**

The multifactorial is a product of integers in steps of two (

n!!, the “double factorial”), three (n!!!), or more (in general for a givenkstep:n!).^{(k)}

**quadruple-factorial**

The so-called quadruple factorial, however, is not the multifactorial

n!; it is a much larger number given by^{(4)}(2n)!/n!.

**super-factorial**

The super factorial is the product of the first

nfactorials.

**hyper-factorial**

The hyper factorial is defined as:

**alternating-factorial**

The alternating factorial is the absolute value of the alternating sum of the first n factorials.

**exponential-factorial**

The exponential factorial is a positive integer

nraised to the power ofn−1, which in turn is raised to the power ofn − 2, and so on and so forth.

Be careful with n > 4: the exponential factorial of 5 is 5^{262144}which is approximately 6.206069878660874 × 10^{183230}.

**factorial-prime?**

A factorial prime is a prime number that is one less or one more than a factorial.

**primorial-prime?**

A primorial prime is a prime number that is one less or one more than a primorial.

**falling-factorial**

The

“descending factorial”, “falling sequential product”, or “lower factorial”.

**factorial-power**

A generalized version of falling factorial.

**rising-factorial**

The

“ascending factorial”, “rising sequential product”, or “upper factorial”.

### Now available!

That’s probably more factorials than anyone really cares to know about, but now Factor has more than ten times as many factorials as before! The code could probably use some cleanup, but it is available now in the math.factorials vocabulary.