]> gitweb.factorcode.org Git - factor.git/blob - basis/math/functions/functions-docs.factor
Resolved merge.
[factor.git] / basis / math / functions / functions-docs.factor
1 USING: help.markup help.syntax kernel math math.order
2 sequences quotations math.functions.private ;
3 IN: math.functions
4
5 ARTICLE: "integer-functions" "Integer functions"
6 { $subsection align }
7 { $subsection gcd }
8 { $subsection log2 }
9 { $subsection next-power-of-2 }
10 "Modular exponentiation:"
11 { $subsection ^mod }
12 { $subsection mod-inv }
13 "Tests:"
14 { $subsection power-of-2? }
15 { $subsection even? }
16 { $subsection odd? }
17 { $subsection divisor? } ;
18
19 ARTICLE: "arithmetic-functions" "Arithmetic functions"
20 "Computing additive and multiplicative inverses:"
21 { $subsection neg }
22 { $subsection recip }
23 "Incrementing, decrementing:"
24 { $subsection 1+ }
25 { $subsection 1- }
26 "Minimum, maximum, clamping:"
27 { $subsection min }
28 { $subsection max }
29 { $subsection clamp }
30 "Complex conjugation:"
31 { $subsection conjugate }
32 "Tests:"
33 { $subsection zero? }
34 { $subsection between? }
35 "Sign:"
36 { $subsection sgn }
37 "Rounding:"
38 { $subsection ceiling }
39 { $subsection floor }
40 { $subsection truncate }
41 { $subsection round }
42 "Inexact comparison:"
43 { $subsection ~ } ;
44
45 ARTICLE: "power-functions" "Powers and logarithms"
46 "Squares:"
47 { $subsection sq }
48 { $subsection sqrt }
49 "Exponential and natural logarithm:"
50 { $subsection exp }
51 { $subsection cis }
52 { $subsection log }
53 "Raising a number to a power:"
54 { $subsection ^ }
55 "Converting between rectangular and polar form:"
56 { $subsection abs }
57 { $subsection absq }
58 { $subsection arg }
59 { $subsection >polar }
60 { $subsection polar> } ;
61
62 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
63 "Trigonometric functions:"
64 { $subsection cos }
65 { $subsection sin }
66 { $subsection tan }
67 "Reciprocals:"
68 { $subsection sec }
69 { $subsection cosec }
70 { $subsection cot }
71 "Inverses:"
72 { $subsection acos }
73 { $subsection asin }
74 { $subsection atan }
75 "Inverse reciprocals:"
76 { $subsection asec }
77 { $subsection acosec }
78 { $subsection acot }
79 "Hyperbolic functions:"
80 { $subsection cosh }
81 { $subsection sinh }
82 { $subsection tanh }
83 "Reciprocals:"
84 { $subsection sech }
85 { $subsection cosech }
86 { $subsection coth }
87 "Inverses:"
88 { $subsection acosh }
89 { $subsection asinh }
90 { $subsection atanh }
91 "Inverse reciprocals:"
92 { $subsection asech }
93 { $subsection acosech }
94 { $subsection acoth } ;
95
96 ARTICLE: "math-functions" "Mathematical functions"
97 { $subsection "integer-functions" }
98 { $subsection "arithmetic-functions" }
99 { $subsection "power-functions" }
100 { $subsection "trig-hyp-functions" } ;
101
102 ABOUT: "math-functions"
103
104 HELP: rect>
105 { $values { "x" real } { "y" real } { "z" number } }
106 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
107
108 HELP: >rect
109 { $values { "z" number } { "x" real } { "y" real } }
110 { $description "Extracts the real and imaginary components of a complex number." } ;
111
112 HELP: align
113 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
114 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
115 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
116
117 HELP: exp
118 { $values { "x" number } { "y" number } }
119 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
120
121 HELP: log
122 { $values { "x" number } { "y" number } }
123 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
124
125 HELP: sqrt
126 { $values { "x" number } { "y" number } }
127 { $description "Square root function." } ;
128
129 HELP: cosh
130 $values-x/y
131 { $description "Hyperbolic cosine." } ;
132
133 HELP: sech
134 $values-x/y
135 { $description "Hyperbolic secant." } ;
136
137 HELP: sinh
138 $values-x/y
139 { $description "Hyperbolic sine." } ;
140
141 HELP: cosech
142 $values-x/y
143 { $description "Hyperbolic cosecant." } ;
144
145 HELP: tanh
146 $values-x/y
147 { $description "Hyperbolic tangent." } ;
148
149 HELP: coth
150 $values-x/y
151 { $description "Hyperbolic cotangent." } ;
152
153 HELP: cos
154 $values-x/y
155 { $description "Trigonometric cosine." } ;
156
157 HELP: sec
158 $values-x/y
159 { $description "Trigonometric secant." } ;
160
161 HELP: sin
162 $values-x/y
163 { $description "Trigonometric sine." } ;
164
165 HELP: cosec
166 $values-x/y
167 { $description "Trigonometric cosecant." } ;
168
169 HELP: tan
170 $values-x/y
171 { $description "Trigonometric tangent." } ;
172
173 HELP: cot
174 $values-x/y
175 { $description "Trigonometric cotangent." } ;
176
177 HELP: acosh
178 $values-x/y
179 { $description "Inverse hyperbolic cosine." } ;
180
181 HELP: asech
182 $values-x/y
183 { $description "Inverse hyperbolic secant." } ;
184
185 HELP: asinh
186 $values-x/y
187 { $description "Inverse hyperbolic sine." } ;
188
189 HELP: acosech
190 $values-x/y
191 { $description "Inverse hyperbolic cosecant." } ;
192
193 HELP: atanh
194 $values-x/y
195 { $description "Inverse hyperbolic tangent." } ;
196
197 HELP: acoth
198 $values-x/y
199 { $description "Inverse hyperbolic cotangent." } ;
200
201 HELP: acos
202 $values-x/y
203 { $description "Inverse trigonometric cosine." } ;
204
205 HELP: asec
206 $values-x/y
207 { $description "Inverse trigonometric secant." } ;
208
209 HELP: asin
210 $values-x/y
211 { $description "Inverse trigonometric sine." } ;
212
213 HELP: acosec
214 $values-x/y
215 { $description "Inverse trigonometric cosecant." } ;
216
217 HELP: atan
218 $values-x/y
219 { $description "Inverse trigonometric tangent." } ;
220
221 HELP: acot
222 $values-x/y
223 { $description "Inverse trigonometric cotangent." } ;
224
225 HELP: conjugate
226 { $values { "z" number } { "z*" number } }
227 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
228
229 HELP: arg
230 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
231 { $description "Computes the complex argument." } ;
232
233 HELP: >polar
234 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
235 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
236
237 HELP: cis
238 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
239 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
240
241 { cis exp } related-words
242
243 HELP: polar>
244 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
245 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
246
247 HELP: [-1,1]?
248 { $values { "x" number } { "?" "a boolean" } }
249 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
250
251 HELP: abs
252 { $values { "x" number } { "y" "a non-negative real number" } }
253 { $description "Computes the absolute value of a complex number." } ;
254
255 HELP: absq
256 { $values { "x" number } { "y" "a non-negative real number" } }
257 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
258
259 HELP: ^
260 { $values { "x" number } { "y" number } { "z" number } }
261 { $description "Raises " { $snippet "x" } " to the power of " { $snippet "y" } ". If " { $snippet "y" } " is an integer the answer is computed exactly, otherwise a floating point approximation is used." }
262 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
263
264 HELP: gcd
265 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
266 { $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" } }
267 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
268
269 HELP: divisor?
270 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
271 { $description "Tests if " { $snippet "n" } " is a divisor of " { $snippet "m" } ". This is the same thing as asking if " { $snippet "m" } " is divisible by " { $snippet "n" } "." }
272 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
273
274 HELP: mod-inv
275 { $values { "x" integer } { "n" integer } { "y" integer } }
276 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
277 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
278 { $examples
279     { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
280     { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
281 } ;
282
283 HELP: ~
284 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
285 { $description "Tests if " { $snippet "x" } " and " { $snippet "y" } " are approximately equal to each other. There are three possible comparison tests, chosen based on the sign of " { $snippet "epsilon" } ":"
286     { $list
287         { { $snippet "epsilon" } " is zero: exact comparison." }
288         { { $snippet "epsilon" } " is positive: absolute distance test." }
289         { { $snippet "epsilon" } " is negative: relative distance test." }
290     }
291 } ;
292
293
294 HELP: truncate
295 { $values { "x" real } { "y" "a whole real number" } }
296 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
297 { $notes "The result is not necessarily an integer." } ;
298
299 HELP: floor
300 { $values { "x" real } { "y" "a whole real number" } }
301 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
302 { $notes "The result is not necessarily an integer." } ;
303
304 HELP: ceiling
305 { $values { "x" real } { "y" "a whole real number" } }
306 { $description "Outputs the least whole number greater than or equal to " { $snippet "x" } "." }
307 { $notes "The result is not necessarily an integer." } ;
308
309 HELP: round
310 { $values { "x" real } { "y" "a whole real number" } }
311 { $description "Outputs the whole number closest to " { $snippet "x" } "." }
312 { $notes "The result is not necessarily an integer." } ;