\ undo 1 [ ] define-pop-inverse
\ map 1 [ [undo] '[ dup sequence? assure _ map ] ] define-pop-inverse
-\ exp \ log define-dual
+\ e^ \ log define-dual
\ sq \ sqrt define-dual
ERROR: missing-literal ;
[ ] [ C{ 1 4 } coth drop ] unit-test
[ ] [ C{ 1 4 } cot drop ] unit-test
-[ t ] [ 0.0 pi rect> exp C{ -1 0 } 1.0e-7 ~ ] unit-test
-[ t ] [ 0 pi rect> exp C{ -1 0 } 1.0e-7 ~ ] unit-test
+[ t ] [ 0.0 pi rect> e^ C{ -1 0 } 1.0e-7 ~ ] unit-test
+[ t ] [ 0 pi rect> e^ C{ -1 0 } 1.0e-7 ~ ] unit-test
10 number-base [
[ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test
"Squares:"
{ $subsections sq sqrt }
"Exponential and natural logarithm:"
-{ $subsections exp cis log }
+{ $subsections e^ cis log }
"Other logarithms:"
{ $subsections log1+ log10 }
"Raising a number to a power:"
{ $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
{ $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
-HELP: exp
+HELP: e^
{ $values { "x" number } { "y" number } }
{ $description "Exponential function, " { $snippet "y=e^x" } "." } ;
HELP: frexp
{ $values { "x" number } { "y" float } { "exp" integer } }
-{ $description "Break the number " { $snippet "x" } " into a normalized fraction " { $snippet "y" } " and an integral power of 2 " { $snippet "exp" } "." $nl "The function returns a number " { $snippet "y" } " in the interval [1/2, 1) or 0, and a number " { $snippet "exp" } " such that " { $snippet "x = y*(2**exp)" } "." } ;
+{ $description "Break the number " { $snippet "x" } " into a normalized fraction " { $snippet "y" } " and an integral power of 2 " { $snippet "e^" } "." $nl "The function returns a number " { $snippet "y" } " in the interval [1/2, 1) or 0, and a number " { $snippet "exp" } " such that " { $snippet "x = y*(2**exp)" } "." } ;
HELP: log
{ $values { "x" number } { "y" number } }
HELP: cis
{ $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
-{ $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
+{ $description "Computes a point on the unit circle using Euler's formula for " { $snippet "e^(arg*i)" } "." } ;
-{ cis exp } related-words
+{ cis e^ } related-words
HELP: polar>
{ $values { "abs" "a non-negative real number" } { "arg" real } { "z" number } }
{ $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" } }
[ 4.0 ] [ 10000.0 log10 ] unit-test
[ $ log10-factorial-1000 t ] [ 1000 factorial [ log10 ] [ bignum? ] bi ] unit-test
-[ t ] [ 1 exp e 1.e-10 ~ ] unit-test
-[ f ] [ 1 exp 0/0. 1.e-10 ~ ] unit-test
-[ f ] [ 0/0. 1 exp 1.e-10 ~ ] unit-test
-[ t ] [ 1.0 exp e 1.e-10 ~ ] unit-test
-[ t ] [ -1 exp e * 1.0 1.e-10 ~ ] unit-test
+[ t ] [ 1 e^ e 1.e-10 ~ ] unit-test
+[ f ] [ 1 e^ 0/0. 1.e-10 ~ ] unit-test
+[ f ] [ 0/0. 1 e^ 1.e-10 ~ ] unit-test
+[ t ] [ 1.0 e^ e 1.e-10 ~ ] unit-test
+[ t ] [ -1 e^ e * 1.0 1.e-10 ~ ] unit-test
[ f ] [ 1/0. 1/0. 1.e-10 ~ ] unit-test
[ f ] [ 1/0. -1/0. 1.e-10 ~ ] unit-test
[ f ] [ 1/0. 0/0. 1.e-10 ~ ] 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
+{ .5 } [ 0 sigmoid ] unit-test
: polar> ( abs arg -- z ) cis * ; inline
-GENERIC: exp ( x -- y )
+GENERIC: e^ ( x -- y )
-M: float exp fexp ; inline
+M: float e^ fexp ; inline
-M: real exp >float exp ; inline
+M: real e^ >float e^ ; inline
-M: complex exp >rect [ exp ] dip polar> ; inline
+M: complex e^ >rect [ e^ ] dip polar> ; inline
<PRIVATE
: ^mag ( w abs arg -- magnitude )
[ >float-rect swap ]
[ >float swap >float fpow ]
- [ rot * exp /f ]
+ [ rot * e^ /f ]
tri* ; inline
: ^theta ( w abs arg -- theta )
: 10^ ( x -- y ) 10 swap ^ ; inline
-: e^ ( x -- y ) e swap ^ ; inline
-
GENERIC: log10 ( x -- y ) foldable
M: real log10 >float flog10 ; inline
: lerp ( a b t -- a_t ) [ over - ] dip * + ; inline
: roots ( x t -- seq )
- [ [ log ] [ recip ] bi* * exp ]
- [ recip 2pi * 0 swap complex boa exp ]
+ [ [ log ] [ recip ] bi* * e^ ]
+ [ recip 2pi * 0 swap complex boa e^ ]
[ iota [ ^ * ] with with map ] tri ;
: sigmoid ( x -- y ) neg e^ 1 + recip ; inline
HELP: fexp
{ $values { "x" real } { "double" real } }
-{ $description "Calls the exponential function (" { $snippet "y=e^x" } ") from the C standard library. User code should call " { $link exp } " instead." } ;
+{ $description "Calls the exponential function (" { $snippet "y=e^x" } ") from the C standard library. User code should call " { $link e^ } " instead." } ;
HELP: flog
{ $values { "x" real } { "double" real } }
(cos-random-float) (log-sqrt-random-float) * * + ;
: lognormal-random-float ( mean sigma -- n )
- normal-random-float exp ;
+ normal-random-float e^ ;
: exponential-random-float ( lambda -- n )
random-unit log neg swap / ;
random-unit :> u2
u1 1. u1 - / log ainv / :> v
- alpha v exp * :> x
+ alpha v e^ * :> x
u1 sq u2 * z!
bbb ccc v * + x - r!
p 1.0 > [
random-unit x alpha 1 - ^ >
] [
- random-unit x neg exp >
+ random-unit x neg e^ >
] if
] [
random-unit b * p!
0 :> c! 0 :> _f! ! initialize locals
[
random-unit {
- [ 2. c - c * < ] [ 1. c - exp c * <= ]
+ [ 2. c - c * < ] [ 1. c - e^ c * <= ]
} 1|| not
] [
random-unit pi * cos :> z
random-unit dup 1 swap - / log * + ;
: power-random-float ( alpha -- n )
- [ random-unit log exp 1 swap - ] dip recip ^ ;
+ [ random-unit log e^ 1 swap - ] dip recip ^ ;
{
{ [ os windows? ] [ "random.windows" require ] }
: gamma-lanczos6 ( x -- gamma[x] )
#! gamma(x) = gamma(x+1) / x
- [ (gamma-lanczos6) exp ] keep / ;
+ [ (gamma-lanczos6) e^ ] keep / ;
: gammaln-lanczos6 ( x -- gammaln[x] )
#! log(gamma(x)) = log(gamma(x+1)) - log(x)
nip
/
over /
- swap -1.0 * exp
+ swap -1.0 * e^
*
] if ;
DERIVATIVE: sqrt [ sqrt 2 * / ]
-DERIVATIVE: exp [ exp * ]
+DERIVATIVE: e^ [ e^ * ]
DERIVATIVE: log [ / ]
DERIVATIVE: sin [ cos * ]
even? [ "odd degrees of freedom" throw ] unless ;
: (chi2P) ( chi/2 df/2 -- p )
- [1,b) dupd n/v cum-product swap neg exp [ v*n sum ] keep + ;
+ [1,b) dupd n/v cum-product swap neg e^ [ v*n sum ] keep + ;
PRIVATE>