Fixed help for math.dual. Help is now autogenerated where possible.

db4
Jason Merrill 2009-02-19 22:21:31 -05:00
parent 4e0db1332c
commit d59415d23b
2 changed files with 21 additions and 88 deletions

View File

@ -10,84 +10,6 @@ HELP: <dual>
}
{ $description "Creates a dual number from its ordinary and epsilon parts." } ;
HELP: d*
{ $values
{ "x" dual } { "y" dual }
{ "x*y" dual }
}
{ $description "Multiply dual numbers." } ;
HELP: d+
{ $values
{ "x" dual } { "y" dual }
{ "x+y" dual }
}
{ $description "Add dual numbers." } ;
HELP: d-
{ $values
{ "x" dual } { "y" dual }
{ "x-y" dual }
}
{ $description "Subtract dual numbers." } ;
HELP: d/
{ $values
{ "x" dual } { "y" dual }
{ "x/y" dual }
}
{ $description "Divide dual numbers." }
{ $errors "Throws an error if the ordinary part of " { $snippet "x" } " is zero." } ;
HELP: d^
{ $values
{ "x" dual } { "y" dual }
{ "x^y" dual }
}
{ $description "Raise a dual number to a (possibly dual) power" } ;
HELP: dabs
{ $values
{ "x" dual }
{ "|x|" dual }
}
{ $description "Absolute value of a dual number." } ;
HELP: dacosh
{ $values
{ "x" dual }
{ "y" dual }
}
{ $description "Inverse hyberbolic cosine of a dual number." } ;
HELP: dasinh
{ $values
{ "x" dual }
{ "y" dual }
}
{ $description "Inverse hyberbolic sine of a dual number." } ;
HELP: datanh
{ $values
{ "x" dual }
{ "y" dual }
}
{ $description "Inverse hyberbolic tangent of a dual number." } ;
HELP: dneg
{ $values
{ "x" dual }
{ "-x" dual }
}
{ $description "Negative of a dual number." } ;
HELP: drecip
{ $values
{ "x" dual }
{ "1/x" dual }
}
{ $description "Reciprocal of a dual number." } ;
HELP: define-dual
{ $values
{ "word" word }
@ -128,5 +50,4 @@ $nl
"Dual numbers are ordered pairs " { $snippet "<o,e>"} "--an ordinary part and an epsilon part--with component-wise addition and multiplication defined by "{ $snippet "<o1,e1>*<o2,e2> = <o1*o2,e1*o2 + e2*o1>" } ". They are analagous to complex numbers with " { $snippet "i^2 = 0" } "instead of " { $snippet "i^2 = -1" } ". For well-behaved functions " { $snippet "f" } ", " { $snippet "f(<o1,e1>) = f(o1) + e1*f'(o1)" } ", where " { $snippet "f'"} " is the derivative of " { $snippet "f" } "."
;
ABOUT: "math.dual"

View File

@ -1,8 +1,9 @@
! 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 vocabs sequences generalizations fry
combinators.smart generic compiler.units ;
macros generic compiler.units words effects vocabs
sequences arrays assocs generalizations fry make
combinators.smart help help.markup ;
IN: math.dual
@ -48,6 +49,19 @@ MACRO: chain-rule ( word -- e )
tri
'[ [ @ _ @ ] sum-outputs ] ;
: set-dual-help ( word dword -- )
[ swap
[ stack-effect [ in>> ] [ out>> ] bi append
[ dual ] { } map>assoc { $values } prepend
]
[ [ { $description } % "Version of " ,
{ $link } swap suffix ,
" extended to work on dual numbers." , ]
{ } make
]
bi* 2array
] keep set-word-help ;
PRIVATE>
MACRO: dual-op ( word -- )
@ -58,13 +72,11 @@ MACRO: dual-op ( word -- )
'[ _ @ @ <dual> ] ;
: define-dual ( word -- )
[
[ stack-effect ]
[ name>> "d" prepend "math.dual" create ]
bi [ set-stack-effect ] keep
]
keep
'[ _ dual-op ] define ;
dup name>> "d" prepend "math.dual" create
[ [ stack-effect ] dip set-stack-effect ]
[ set-dual-help ]
[ swap '[ _ dual-op ] define ]
2tri ;
! Specialize math functions to operate on dual numbers.
[ all-words [ "derivative" word-prop ] filter