Essays/Double Factorial

From J Wiki
Jump to: navigation, search

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.

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 , 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.

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 , 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.

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


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

   (Fo -: Fd@<:@+:) i.10

1

   (Fo -: Fd@>:@+:@<:) i.10

1

See Also

  • Bifactorial
  • Generalized Monty Hall
  • OEIS OEIS:A122774 Triangle of bifactorial numbers, n B m = (2(n-m)-1)!! (2(n-1))!! / (2(n-m))!!, read by rows
  • OEIS OEIS:A000165 Double factorial numbers: (2n)!! = 2^n*n! (even)
  • OEIS OEIS:A001147 Double factorial numbers: (2n-1)!! = 1.3.5....(2n-1) (odd)
  • OEIS OEIS:A006882 Double factorials n!!: a(n)=n*a(n-2)
  • MathWorld:DoubleFactorial, Mathworld