diff --git a/extra/math/analysis/analysis.factor b/extra/math/analysis/analysis.factor index 7da1c96b61..b5f6a547ba 100755 --- a/extra/math/analysis/analysis.factor +++ b/extra/math/analysis/analysis.factor @@ -1,7 +1,7 @@ -! Copyright (C) 2008 Doug Coleman, Slava Pestov. +! Copyright (C) 2008 Doug Coleman, Slava Pestov, Aaron Schaefer. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math math.constants math.functions math.intervals -math.vectors namespaces sequences combinators.short-circuit ; +USING: combinators.short-circuit kernel math math.constants math.functions + math.vectors sequences ; IN: math.analysis #! gamma(x) = integral 0..inf [ t^(x-1) exp(-t) ] dt #! gamma(n+1) = n! for n > 0 dup { [ 0.0 <= ] [ 1.0 mod zero? ] } 1&& [ - drop 1./0. - ] [ - dup abs gamma-lanczos6 swap dup 0 > [ drop ] [ gamma-neg ] if + drop 1./0. + ] [ + [ abs gamma-lanczos6 ] keep dup 0 > [ drop ] [ gamma-neg ] if ] if ; : gammaln ( x -- gamma[x] ) #! gammaln(x) is an alternative when gamma(x)'s range #! varies too widely dup 0 < [ - drop 1./0. - ] [ - dup abs gammaln-lanczos6 swap dup 0 > [ drop ] [ gamma-neg ] if + drop 1./0. + ] [ + [ abs gammaln-lanczos6 ] keep dup 0 > [ drop ] [ gamma-neg ] if ] if ; : nth-root ( n x -- y ) - [ recip ] dip swap ^ ; + swap recip ^ ; ! Forth Scientific Library Algorithm #1 ! @@ -116,6 +116,6 @@ PRIVATE> : stirling-fact ( n -- fact ) [ pi 2 * * sqrt ] - [ dup e / swap ^ ] - [ 12 * recip 1 + ] - tri * * ; + [ [ e / ] keep ^ ] + [ 12 * recip 1+ ] tri * * ; +