]> gitweb.factorcode.org Git - factor.git/commitdiff
math.extras: fix spelling of stirling, add ramanujan approximation of factorial.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Sep 2012 17:48:09 +0000 (10:48 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Sep 2012 17:48:09 +0000 (10:48 -0700)
extra/math/extras/extras-docs.factor
extra/math/extras/extras.factor

index e745caa3d1d43195642fb49964fcf40b61e158c3..93200cea811deb4adddfd715d0fb7b05c27e9021 100644 (file)
@@ -9,7 +9,7 @@ HELP: bernoulli
 { $values { "p" integer } { "n" rational } }
 { $description "Return the Bernoulli number " { $snippet "p" } "." } ;
 
-HELP: sterling
+HELP: stirling
 { $values { "n" integer } { "k" integer } { "x" integer } }
 { $description "Return the Stirling number of the second kind for a set with " { $snippet "n" } " elements partitioned into " { $snippet "k" } " disjoint non-empty sets." } ;
 
index f3f6cea307fee4ea517a2527cb0568047b303e81..74e27c7a180c97d378bb647b5048bb1bb13c672e 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2012 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: combinators.short-circuit grouping kernel math
+USING: combinators.short-circuit grouping kernel locals math
 math.combinatorics math.constants math.functions math.order
 math.primes math.ranges math.statistics math.vectors memoize
 sequences ;
@@ -10,18 +10,21 @@ IN: math.extras
 
 <PRIVATE
 
-DEFER: sterling
+DEFER: stirling
 
-: (sterling) ( n k -- x )
-    [ [ 1 - ] bi@ sterling ]
-    [ [ 1 - ] dip sterling ]
+: (stirling) ( n k -- x )
+    [ [ 1 - ] bi@ stirling ]
+    [ [ 1 - ] dip stirling ]
     [ nip * + ] 2tri ;
 
 PRIVATE>
 
-MEMO: sterling ( n k -- x )
+MEMO: stirling ( n k -- x )
     2dup { [ = ] [ nip 1 = ] } 2||
-    [ 2drop 1 ] [ (sterling) ] if ;
+    [ 2drop 1 ] [ (stirling) ] if ;
+
+:: ramanujan ( x -- y )
+    pi sqrt x e / x ^ * x 8 * 4 + x * 1 + x * 1/30 + 1/6 ^ * ;
 
 <PRIVATE