Merge branch 'master' into new_ui

db4
Slava Pestov 2009-02-19 18:25:59 -06:00
commit 15b5d696c1
6 changed files with 21 additions and 50 deletions

View File

@ -252,14 +252,10 @@ M: real tanh ftanh ;
: -i* ( x -- y ) >rect swap neg rect> ;
GENERIC: asin ( x -- y ) foldable
M: number asin
: asin ( x -- y )
dup [-1,1]? [ fasin ] [ i* asinh -i* ] if ; inline
GENERIC: acos ( x -- y ) foldable
M: number acos
: acos ( x -- y )
dup [-1,1]? [ facos ] [ asin pi 2 / swap - ] if ;
inline

View File

@ -92,8 +92,8 @@ PRIVATE>
: (fuel-word-synopsis) ( word usings -- str/f )
[
[ vocab ] filter interactive-vocabs get append interactive-vocabs set
fuel-find-word [ synopsis ] when*
[ vocab ] filter interactive-vocabs [ append ] change
fuel-find-word [ synopsis ] [ f ] if*
] with-scope ;
: (fuel-word-see) ( word -- elem )

View File

@ -1,4 +0,0 @@
! Copyright (C) 2009 Jason W. Merrill.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test automatic-differentiation.derivatives ;
IN: automatic-differentiation.derivatives.tests

View File

@ -88,14 +88,14 @@ HELP: drecip
}
{ $description "Reciprocal of a dual number." } ;
HELP: define-dual-method
HELP: define-dual
{ $values
{ "word" word }
}
{ $description "Defines a method on the dual numbers for generic word." }
{ $description "Defines a word " { $snippet "d[word]" } " in the " { $vocab-link "math.dual" } " vocabulary that operates on dual numbers." }
{ $notes "Uses the derivative word-prop, which holds a list of quotations giving the partial derivatives of the word with respect to each of its arguments. This can be set using " { $link POSTPONE: DERIVATIVE: } "." } ;
{ define-dual-method dual-op POSTPONE: DERIVATIVE: } related-words
{ define-dual dual-op POSTPONE: DERIVATIVE: } related-words
HELP: dual
{ $class-description "The class of dual numbers with non-zero epsilon part." } ;

View File

@ -4,13 +4,13 @@ USING: tools.test math.dual kernel accessors math math.functions
math.constants ;
IN: math.dual.tests
[ 0.0 1.0 ] [ 0 1 <dual> sin unpack-dual ] unit-test
[ 1.0 0.0 ] [ 0 1 <dual> cos unpack-dual ] unit-test
[ 0.0 1.0 ] [ 0 1 <dual> dsin unpack-dual ] unit-test
[ 1.0 0.0 ] [ 0 1 <dual> dcos unpack-dual ] unit-test
[ 3 5 ] [ 1 5 <dual> 2 d+ unpack-dual ] unit-test
[ 0 -1 ] [ 1 5 <dual> 1 6 <dual> d- unpack-dual ] unit-test
[ 2 1 ] [ 2 3 <dual> 1 -1 <dual> d* unpack-dual ] unit-test
[ 1/2 -1/4 ] [ 2 1 <dual> 1 swap d/ unpack-dual ] unit-test
[ 2 ] [ 1 1 <dual> 2 d^ epsilon-part>> ] unit-test
[ 2.0 .25 ] [ 4 1 <dual> sqrt unpack-dual ] unit-test
[ 2.0 .25 ] [ 4 1 <dual> dsqrt unpack-dual ] unit-test
[ 2 -1 ] [ -2 1 <dual> dabs unpack-dual ] unit-test
[ -2 -1 ] [ 2 1 <dual> dneg unpack-dual ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2009 Jason W. Merrill.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.functions math.derivatives accessors
macros words effects sequences generalizations fry
macros words effects vocabs sequences generalizations fry
combinators.smart generic compiler.units ;
IN: math.dual
@ -57,36 +57,15 @@ MACRO: dual-op ( word -- )
tri
'[ _ @ @ <dual> ] ;
: define-dual-method ( word -- )
[ \ dual swap create-method ] keep '[ _ dual-op ] define ;
: define-dual ( word -- )
[
[ stack-effect ]
[ name>> "d" prepend "math.dual" create ]
bi [ set-stack-effect ] keep
]
keep
'[ _ dual-op ] define ;
! Specialize math functions to operate on dual numbers.
[ { sqrt exp log sin cos tan sinh cosh tanh acos asin atan }
[ define-dual-method ] each ] with-compilation-unit
! Inverse methods { asinh, acosh, atanh } are not generic, so
! there is no way to specialize them for dual numbers. However,
! they are defined in terms of functions that can operate on
! dual numbers and arithmetic methods, so if it becomes
! possible to make arithmetic operators work directly on dual
! numbers, we will get these for free.
! Arithmetic words are not generic (yet?), so we have to
! define special versions of them to operate on dual numbers.
: d+ ( x y -- x+y ) \ + dual-op ;
: d- ( x y -- x-y ) \ - dual-op ;
: d* ( x y -- x*y ) \ * dual-op ;
: d/ ( x y -- x/y ) \ / dual-op ;
: d^ ( x y -- x^y ) \ ^ dual-op ;
: dabs ( x -- |x| ) \ abs dual-op ;
! The following words are also not generic, but are defined in
! terms of words that can operate on dual numbers and
! arithmetic. If it becomes possible to implement arithmetic on
! dual numbers directly, these functions can be deleted.
: dneg ( x -- -x ) \ neg dual-op ;
: drecip ( x -- 1/x ) \ recip dual-op ;
: dasinh ( x -- y ) \ asinh dual-op ;
: dacosh ( x -- y ) \ acosh dual-op ;
: datanh ( x -- y ) \ atanh dual-op ;
[ all-words [ "derivative" word-prop ] filter
[ define-dual ] each ] with-compilation-unit