# Essays/Double Factorial

## Even Factorial

Even factorial is a product of the first n even positive integers, numbers of the sequence {2,4,6,8,...}. The even factorial of 0 is defined to be 1.

${\displaystyle F_{e}(n)=\prod _{i=1}^{n}2n,\quad n>0,\quad F_{e}(0)\equiv 1}$

By definition, for n=0..10 the values are

   (,: ([:*/2*1+i.)"0) i.11x
0 1 2  3   4    5     6      7        8         9         10
1 2 8 48 384 3840 46080 645120 10321920 185794560 3715891200


We will use an alternative analytical definition ${\displaystyle F_{e}(n)=2^{n}n!}$, as we need to double each member of the natural sequence {2*1,2*2,2*3,2*4,...} to obtain the even sequence.

   Fe=: 2&^ * !

(Fe -: ([:*/2*1+i.)"0) i.100x
1


Note: as seen in the example by definition, the assignment of value at 0 conforms with the identity value of product insert for empty arrays.

## Odd Factorial

Odd factorial is a product of the first n odd positive integers, numbers of the sequence {1,3,5,7,...}. The odd factorial of 0 is defined to be 1.

${\displaystyle F_{o}(n)=\prod _{i=1}^{n}2n-1=\prod _{i=0}^{n-1}2n+1,\quad n>0,\quad F_{o}(0)\equiv 1}$

By definition, for n=0..10 the values are

   (,: ([:*/1+2*i.)"0) i.11x
0 1 2  3   4   5     6      7       8        9        10
1 1 3 15 105 945 10395 135135 2027025 34459425 654729075


We will use an alternative analytical definition ${\displaystyle F_{o}(n)={\frac {(2n)!}{2^{n}n!}}={\frac {(2n)!}{F_{e}(n)}}}$, as we need to reduce the product of the natural sequence twice as long by the product of the even members.

   Fo=: !@+: % 2&^ * !        NB. !@+: % Fe

(Fo -: ([:*/1+2*i.)"0) i.100x
1


## Double Factorial

Double factorial is an alternating sequence of even and odd factorials: if the argument is even, the result comes from the even sequence, if it is odd, from the odd.

${\displaystyle n!!\equiv \left\{{\begin{array}{ll}n(n-2)\dots 5\cdot 3\cdot 1&n>0\quad odd\\n(n-2)\dots 6\cdot 4\cdot 2&n>0\quad even\\1,&n=-1,0\\\end{array}}\right.}$

By definition, we construct the branches for even and odd arguments separately, and for n=-1..14 the values are

   (>:@i.&.-:) 6
2 4 6
(>:@(i.&.-:)@>:) 5
1 3 5
(>:@i.&.-:)(>:@(i.&.-:)@>:)@.(2&|)"0] 5 6
1 3 5
2 4 6
(,: ([: */ (>:@i.&.-:)(>:@(i.&.-:)@>:)@.(2&|))"0) <:i.16
_1 0 1 2 3 4  5  6   7   8   9   10    11    12     13     14
1 1 1 2 3 8 15 48 105 384 945 3840 10395 46080 135135 645120


We will use our alternative analytical definitions for odd and even factorials

${\displaystyle n!!\equiv \left\{{\begin{array}{lll}F_{o}({\frac {n+1}{2}}),&n\geq -1\quad odd\\F_{e}({\frac {n}{2}}),&n\geq 0\quad even\\\end{array}}\right.}$

Fd=: (Fe@-:)(Fo@-:@>:)@.(2&|)"0       NB. n!!


Double factorials as alternating odd and even sequences.

   ,./|:_2]\"1  (,: Fd) <:i.16
_1      1  0      1
1      1  2      2
3      3  4      8
5     15  6     48
7    105  8    384
9    945 10   3840
11  10395 12  46080
13 135135 14 645120
`

## Properties

 (Fe -: Fd@+:) i.10 1 ${\displaystyle F_{e}(n)=(2n)!!}$ (Fo -: Fd@<:@+:) i.10 1 ${\displaystyle F_{o}(n)=(2n-1)!!}$ (Fo -: Fd@>:@+:@<:) i.10 1 ${\displaystyle F_{o}(n)=(2(n-1)+1)!!}$