]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' into new_ui
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 20 Feb 2009 00:25:59 +0000 (18:25 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 20 Feb 2009 00:25:59 +0000 (18:25 -0600)
basis/math/functions/functions.factor
extra/fuel/help/help.factor
extra/math/derivatives/derivatives-tests.factor [deleted file]
extra/math/dual/dual-docs.factor
extra/math/dual/dual-tests.factor
extra/math/dual/dual.factor

index 69c2c6e3598845d859aa25e077945bbab056df25..20c31aa2bd300efd1be45b84ec6a782eaefca445 100644 (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
 
index bf637fd0b32dc0e4f90b8c4e01958b931c4dc321..64d77566b5458fd22bde7a76f4eb04742e7cd7b8 100644 (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 )
diff --git a/extra/math/derivatives/derivatives-tests.factor b/extra/math/derivatives/derivatives-tests.factor
deleted file mode 100644 (file)
index f95eb43..0000000
+++ /dev/null
@@ -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
index 6c287a8f1e1f9b213fb438ff3a069d95d94986c0..1f24c8217ca7f5f368e828b66009c325bf2f6971 100644 (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." } ;
index ea46c46124d6f70a694ffe6ab3ad89b01141bd38..dbafe74d6a7853adbe4486809d9a775448ff8255 100644 (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
\ No newline at end of file
index 36d684bc6dc26f8d2b965ce597e03acdb466ae31..c85c23e51d7a5ba0e44f85859f4db63f83a07ec2 100644 (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 ;
\ No newline at end of file
+[ all-words [ "derivative" word-prop ] filter
+    [ define-dual ] each ] with-compilation-unit
\ No newline at end of file