diff --git a/extra/math/derivatives/derivatives-docs.factor b/extra/math/derivatives/derivatives-docs.factor index 70389f18ad..0db52adfa5 100644 --- a/extra/math/derivatives/derivatives-docs.factor +++ b/extra/math/derivatives/derivatives-docs.factor @@ -17,20 +17,10 @@ HELP: derivative ( x function -- m ) } { $notes "For applied scientists, you may play with the settings " - "in the source file to achieve arbitrary accuracy." + "in the source file to achieve arbitrary accuracy. " } } ; -HELP: fast-derivative ( x function -- m ) -{ $values { "x" "a x-position on the function" } { "function" "a differentiable function" } } -{ $description - "Approximates the slope of the tangent line of the provided function " - "by using a secant line with very near points. This implementation is " - "naive and is only provided because it is used in the much more " - "accurate " { $link derivative } " word. Use this word if accuracy " - "is of no importance." -} ; - HELP: derivative-func ( function -- der ) { $values { "func" "a differentiable function" } { "der" "the derivative" } } { $description @@ -48,6 +38,5 @@ HELP: derivative-func ( function -- der ) ARTICLE: "derivatives" "The Derivative Toolkit" "A toolkit for computing the derivative of functions." { $subsection derivative } -{ $subsection derivative-func } -{ $subsection fast-derivative } ; +{ $subsection derivative-func } ; ABOUT: "derivatives" diff --git a/extra/math/derivatives/derivatives.factor b/extra/math/derivatives/derivatives.factor index f77748d0b5..96d0fc3a81 100644 --- a/extra/math/derivatives/derivatives.factor +++ b/extra/math/derivatives/derivatives.factor @@ -1,19 +1,13 @@ -! Copyright (c) 2008 Reginald Ford ! Tools for approximating derivatives USING: kernel math math.functions locals generalizations float-arrays sequences math.constants namespaces math.function-tools math.points math.ranges math.order ; IN: math.derivatives -! Ridders' method of a derivative, from the chapter -! "Accurate computation of F'(x) and F'(x)F''(x)", -! From "Advances in Engineering Software, Vol. 4, pp. 75-76 -! \ fast-derivative has been factored out for use by children - : largest-float ( -- x ) HEX: 7fefffffffffffff bits>double ; foldable -: ntab 10 ; ! max size of tableau (main accuracy setting) -: con 1.41 ; ! stepsize is decreased by this per-iteration -: con2 1.9881 ; ! con^2 +: ntab 10 ; ! max size of tableau (main accuracy setting) +: con 1.41 ; ! stepsize is decreased by this per-iteration +: con2 1.9881 ; ! con^2 : initial-h 0.02 ; ! distance of the 2 points of the first secant line : safe 2.0 ; ! return when current err is SAFE worse than the best ! \ safe probably should not be changed @@ -30,9 +24,6 @@ SYMBOL: matrix [ [ h get + ] dip eval ] [ [ h get - ] dip eval ] 2bi slope ; inline -: fast-derivative ( x function -- m ) - over epsilon sqrt * h set - (derivative) ; inline : init-matrix ( -- ) ntab [ ntab ] replicate matrix set ; @@ -70,5 +61,4 @@ SYMBOL: matrix ] all? drop ans get ; inline : derivative-func ( function -- function ) [ derivative ] curry ; inline -: fast-derivative-func ( function -- function ) [ fast-derivative ] curry ; inline