]> gitweb.factorcode.org Git - factor.git/blob - extra/math/dual/dual-docs.factor
7768d5513388d36977878d0808bda4140090e2b2
[factor.git] / extra / math / dual / dual-docs.factor
1 ! Copyright (C) 2009 Jason W. Merrill.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel words math math.functions math.derivatives.syntax ;
4 IN: math.dual
5
6 HELP: <dual>
7 { $values
8     { "ordinary-part" real } { "epsilon-part" real }
9     { "dual" dual number }
10 }
11 { $description "Creates a dual number from its ordinary and epsilon parts." } ;
12
13 HELP: define-dual
14 { $values
15     { "word" word }
16 }
17 { $description "Defines a word " { $snippet "d[word]" } " in the " { $vocab-link "math.dual" } " vocabulary that operates on dual numbers." }
18 { $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: } "." } ;
19
20 { define-dual dual-op POSTPONE: DERIVATIVE: } related-words
21
22 HELP: dual
23 { $class-description "The class of dual numbers with non-zero epsilon part." } ;
24
25 HELP: dual-op
26 { $values
27     { "word" word }
28 }
29 { $description "Similar to " { $link execute } ", but promotes word to operate on duals." }
30 { $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: } ". Once a derivative has been defined for a word, dual-op makes it easy to extend the definition to dual numbers." }
31 { $examples
32     { $unchecked-example "USING: math math.dual math.derivatives.syntax math.functions ;"
33     "DERIVATIVE: sin [ cos * ]"
34     "M: dual sin \\sin dual-op ;" "" }
35     { $unchecked-example "USING: math math.dual math.derivatives.syntax ;"
36     "DERIVATIVE: * [ drop ] [ nip ]"
37     ": d* ( x y -- x*y ) \ * dual-op ;" "" }
38 } ;
39
40 HELP: unpack-dual
41 { $values
42     { "dual" dual }
43     { "ordinary-part" number } { "epsilon-part" number }
44 }
45 { $description "Extracts the ordinary and epsilon part of a dual number." } ;
46
47 ARTICLE: "math.dual" "Dual Numbers"
48 "The " { $vocab-link "math.dual" } " vocabulary implements dual numbers, along with arithmetic methods for working with them. Many of the functions in " { $vocab-link "math.functions" } " are extended to work with dual numbers."
49 $nl
50 "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" } "."
51 ;
52
53 ABOUT: "math.dual"