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