home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / DISCRETE.PAK / COMBINA1.M next >
Encoding:
Text File  |  1992-07-29  |  1.0 KB  |  49 lines

  1.  
  2. (* Copyright 1988 Wolfram Research Inc. *)
  3.  
  4.         (** Combinatorial functions **)
  5.  
  6. BeginPackage["DiscreteMath`CombinatorialFunctions`"]
  7.  
  8. (* Subfactorials *)
  9.  
  10. Subfactorial::usage =
  11.     "Subfactorial[n] gives the number of permutations of n objects
  12.     which leave no object fixed."
  13.  
  14. (* Catalan numbers *)
  15.  
  16. CatalanNumber::usage =
  17.     "CatalanNumber[n] gives the nth Catalan number."
  18.  
  19. (* Fibonacci numbers *)
  20.  
  21. Fibonacci::usage =
  22.     "Fibonacci[n] gives the nth Fibonacci number."
  23.  
  24. (* Hofstadter's function *)
  25.  
  26. Hofstadter::usage = "Hoftstadter[n] gives Hoftstadter's function."
  27.  
  28. Begin["`Private`"]
  29.  
  30. Subfactorial[n_Integer?Positive] := 
  31.     n! Block[{k}, Sum[(-1)^k/k!, {k, 0, n}]]
  32.  
  33. CatalanNumber[n_Integer] := Binomial[2n,n]/(n+1)
  34.  
  35. Fibonacci[n_Integer?Positive] := 
  36.     Fibonacci[n] = Fibonacci[n-1] + Fibonacci[n-2]
  37.  
  38. Fibonacci[0] = Fibonacci[1] = 1
  39.  
  40.  
  41. Hofstadter[n_Integer?Positive] :=
  42.     Hofstadter[n] =
  43.     Hofstadter[n - Hofstadter[n-1]] + Hofstadter[n - Hofstadter[n-2]]
  44.  
  45. Hofstadter[1] = Hofstadter[2] = 1
  46.  
  47. End[ ]
  48. EndPackage[ ]
  49.