diff --git a/basis/math/functions/functions-docs.factor b/basis/math/functions/functions-docs.factor index e04397a50a..765f99c9b9 100644 --- a/basis/math/functions/functions-docs.factor +++ b/basis/math/functions/functions-docs.factor @@ -1,5 +1,5 @@ USING: help.markup help.syntax kernel math math.order -sequences quotations math.functions.private ; +sequences quotations math.functions.private math.constants ; IN: math.functions ARTICLE: "integer-functions" "Integer functions" @@ -53,7 +53,9 @@ ARTICLE: "power-functions" "Powers and logarithms" "Other logarithms:" { $subsections log1+ log10 } "Raising a number to a power:" -{ $subsections ^ 10^ } +{ $subsections ^ e^ 10^ } +"Logistics functions:" +{ $subsections sigmoid } "Finding the root of a number:" { $subsections nth-root } "Converting between rectangular and polar form:" @@ -273,6 +275,10 @@ HELP: 10^ { $values { "x" number } { "y" number } } { $description "Raises 10 to the power of " { $snippet "x" } ". If " { $snippet "x" } " is an integer the answer is computed exactly, otherwise a floating point approximation is used." } ; +HELP: e^ +{ $values { "x" number } { "y" number } } +{ $description "Raises " { $link e } " to the power of " { $snippet "x" } "." } ; + HELP: gcd { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } } { $description "Computes the positive greatest common divisor " { $snippet "d" } " of " { $snippet "x" } " and " { $snippet "y" } ", and another value " { $snippet "a" } " satisfying:" { $code "a*y = d mod x" } } @@ -330,3 +336,7 @@ HELP: roots { $values { "x" number } { "t" integer } { "seq" sequence } } { $description "Outputs the " { $snippet "t" } " roots of a number " { $snippet "x" } "." } { $notes "The results are not necessarily real." } ; + +HELP: sigmoid +{ $values { "x" number } { "y" number } } +{ $description "Outputs the sigmoid, an S-shaped \"logistic\" function, from 0 to 1, of the number " { $snippet "x" } "." } ; diff --git a/basis/math/functions/functions-tests.factor b/basis/math/functions/functions-tests.factor index 44f7dec268..19565b5d84 100644 --- a/basis/math/functions/functions-tests.factor +++ b/basis/math/functions/functions-tests.factor @@ -240,3 +240,7 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11 ] unit-test { t } [ 3 15 roots [ 15 ^ 3 .01 ~ ] all? ] unit-test + +{ t } [ 1 e^ e .0000000001 ~ ] unit-test +{ 1 } [ 0 e^ ] unit-test +{ 1/2 } [ 0 sigmoid ] unit-test diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index 291bcf2516..993e9ad1a5 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -223,6 +223,8 @@ M: float log1+ dup -1.0 >= [ flog1+ ] [ 1.0 + 0.0 rect> log ] if ; inline : 10^ ( x -- y ) 10 swap ^ ; inline +: e^ ( x -- y ) e swap ^ ; inline + GENERIC: log10 ( x -- y ) foldable M: real log10 >float flog10 ; inline @@ -362,3 +364,5 @@ M: real atan >float atan ; inline [ [ log ] [ recip ] bi* * exp ] [ recip 2pi * 0 swap complex boa exp ] [ iota [ ^ * ] with with map ] tri ; + +: sigmoid ( x -- y ) neg e^ 1 + recip ; inline