1 USING: help.markup help.syntax kernel math math.order
2 sequences quotations math.functions.private ;
5 ARTICLE: "integer-functions" "Integer functions"
9 { $subsection next-power-of-2 }
10 "Modular exponentiation:"
12 { $subsection mod-inv }
14 { $subsection power-of-2? }
17 { $subsection divisor? } ;
19 ARTICLE: "arithmetic-functions" "Arithmetic functions"
20 "Computing additive and multiplicative inverses:"
23 "Incrementing, decrementing:"
26 "Minimum, maximum, clamping:"
30 "Complex conjugation:"
31 { $subsection conjugate }
34 { $subsection between? }
38 { $subsection ceiling }
40 { $subsection truncate }
45 ARTICLE: "power-functions" "Powers and logarithms"
49 "Exponential and natural logarithm:"
54 "Raising a number to a power:"
57 "Converting between rectangular and polar form:"
61 { $subsection >polar }
62 { $subsection polar> } ;
64 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
65 "Trigonometric functions:"
77 "Inverse reciprocals:"
79 { $subsection acosec }
81 "Hyperbolic functions:"
87 { $subsection cosech }
93 "Inverse reciprocals:"
95 { $subsection acosech }
96 { $subsection acoth } ;
98 ARTICLE: "math-functions" "Mathematical functions"
99 { $subsection "integer-functions" }
100 { $subsection "arithmetic-functions" }
101 { $subsection "power-functions" }
102 { $subsection "trig-hyp-functions" } ;
104 ABOUT: "math-functions"
107 { $values { "x" real } { "y" real } { "z" number } }
108 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
111 { $values { "z" number } { "x" real } { "y" real } }
112 { $description "Extracts the real and imaginary components of a complex number." } ;
115 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
116 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
117 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
120 { $values { "x" number } { "y" number } }
121 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
124 { $values { "x" number } { "y" number } }
125 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
128 { $values { "x" number } { "y" number } }
129 { $description "Logarithm function base 10. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
132 { $values { "x" number } { "y" number } }
133 { $description "Square root function." } ;
137 { $description "Hyperbolic cosine." } ;
141 { $description "Hyperbolic secant." } ;
145 { $description "Hyperbolic sine." } ;
149 { $description "Hyperbolic cosecant." } ;
153 { $description "Hyperbolic tangent." } ;
157 { $description "Hyperbolic cotangent." } ;
161 { $description "Trigonometric cosine." } ;
165 { $description "Trigonometric secant." } ;
169 { $description "Trigonometric sine." } ;
173 { $description "Trigonometric cosecant." } ;
177 { $description "Trigonometric tangent." } ;
181 { $description "Trigonometric cotangent." } ;
185 { $description "Inverse hyperbolic cosine." } ;
189 { $description "Inverse hyperbolic secant." } ;
193 { $description "Inverse hyperbolic sine." } ;
197 { $description "Inverse hyperbolic cosecant." } ;
201 { $description "Inverse hyperbolic tangent." } ;
205 { $description "Inverse hyperbolic cotangent." } ;
209 { $description "Inverse trigonometric cosine." } ;
213 { $description "Inverse trigonometric secant." } ;
217 { $description "Inverse trigonometric sine." } ;
221 { $description "Inverse trigonometric cosecant." } ;
225 { $description "Inverse trigonometric tangent." } ;
229 { $description "Inverse trigonometric cotangent." } ;
232 { $values { "z" number } { "z*" number } }
233 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
236 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
237 { $description "Computes the complex argument." } ;
240 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
241 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
244 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
245 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
247 { cis exp } related-words
250 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
251 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
254 { $values { "x" number } { "?" "a boolean" } }
255 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
258 { $values { "x" number } { "y" "a non-negative real number" } }
259 { $description "Computes the absolute value of a complex number." } ;
262 { $values { "x" number } { "y" "a non-negative real number" } }
263 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
266 { $values { "x" number } { "y" number } { "z" number } }
267 { $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." }
268 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
271 { $values { "x" number } { "y" number } }
272 { $description "Raises " { $snippet "x" } " to the power of 10. If " { $snippet "x" } " is an integer the answer is computed exactly, otherwise a floating point approximation is used." } ;
275 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
276 { $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" } }
277 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
280 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
281 { $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" } "." }
282 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
285 { $values { "x" integer } { "n" integer } { "y" integer } }
286 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
287 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
289 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
290 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
294 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
295 { $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" } ":"
297 { { $snippet "epsilon" } " is zero: exact comparison." }
298 { { $snippet "epsilon" } " is positive: absolute distance test." }
299 { { $snippet "epsilon" } " is negative: relative distance test." }
305 { $values { "x" real } { "y" "a whole real number" } }
306 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
307 { $notes "The result is not necessarily an integer." } ;
310 { $values { "x" real } { "y" "a whole real number" } }
311 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
312 { $notes "The result is not necessarily an integer." } ;
315 { $values { "x" real } { "y" "a whole real number" } }
316 { $description "Outputs the least whole number greater than or equal to " { $snippet "x" } "." }
317 { $notes "The result is not necessarily an integer." } ;
320 { $values { "x" real } { "y" "a whole real number" } }
321 { $description "Outputs the whole number closest to " { $snippet "x" } "." }
322 { $notes "The result is not necessarily an integer." } ;