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 "Minimum, maximum, clamping:"
27 "Complex conjugation:"
28 { $subsection conjugate }
31 { $subsection between? }
33 { $subsection if-zero }
34 { $subsection when-zero }
35 { $subsection unless-zero }
39 { $subsection ceiling }
41 { $subsection truncate }
46 ARTICLE: "power-functions" "Powers and logarithms"
50 "Exponential and natural logarithm:"
56 "Raising a number to a power:"
59 "Converting between rectangular and polar form:"
63 { $subsection >polar }
64 { $subsection polar> } ;
66 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
67 "Trigonometric functions:"
79 "Inverse reciprocals:"
81 { $subsection acosec }
83 "Hyperbolic functions:"
89 { $subsection cosech }
95 "Inverse reciprocals:"
97 { $subsection acosech }
98 { $subsection acoth } ;
100 ARTICLE: "math-functions" "Mathematical functions"
101 { $subsection "integer-functions" }
102 { $subsection "arithmetic-functions" }
103 { $subsection "power-functions" }
104 { $subsection "trig-hyp-functions" } ;
106 ABOUT: "math-functions"
109 { $values { "x" real } { "y" real } { "z" number } }
110 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
113 { $values { "z" number } { "x" real } { "y" real } }
114 { $description "Extracts the real and imaginary components of a complex number." } ;
117 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
118 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
119 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
122 { $values { "x" number } { "y" number } }
123 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
126 { $values { "x" number } { "y" number } }
127 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
130 { $values { "x" number } { "y" number } }
131 { $description "Takes the natural logarithm of " { $snippet "1 + x" } ". Outputs negative infinity if " { $snippet "1 + x" } " is zero. This word may be more accurate than " { $snippet "1 + log" } " for very small values of " { $snippet "x" } "." } ;
134 { $values { "x" number } { "y" number } }
135 { $description "Logarithm function base 10. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
138 { $values { "x" number } { "y" number } }
139 { $description "Square root function." } ;
143 { $description "Hyperbolic cosine." } ;
147 { $description "Hyperbolic secant." } ;
151 { $description "Hyperbolic sine." } ;
155 { $description "Hyperbolic cosecant." } ;
159 { $description "Hyperbolic tangent." } ;
163 { $description "Hyperbolic cotangent." } ;
167 { $description "Trigonometric cosine." } ;
171 { $description "Trigonometric secant." } ;
175 { $description "Trigonometric sine." } ;
179 { $description "Trigonometric cosecant." } ;
183 { $description "Trigonometric tangent." } ;
187 { $description "Trigonometric cotangent." } ;
191 { $description "Inverse hyperbolic cosine." } ;
195 { $description "Inverse hyperbolic secant." } ;
199 { $description "Inverse hyperbolic sine." } ;
203 { $description "Inverse hyperbolic cosecant." } ;
207 { $description "Inverse hyperbolic tangent." } ;
211 { $description "Inverse hyperbolic cotangent." } ;
215 { $description "Inverse trigonometric cosine." } ;
219 { $description "Inverse trigonometric secant." } ;
223 { $description "Inverse trigonometric sine." } ;
227 { $description "Inverse trigonometric cosecant." } ;
231 { $description "Inverse trigonometric tangent." } ;
235 { $description "Inverse trigonometric cotangent." } ;
238 { $values { "z" number } { "z*" number } }
239 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
242 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
243 { $description "Computes the complex argument." } ;
246 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
247 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
250 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
251 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
253 { cis exp } related-words
256 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
257 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
260 { $values { "x" number } { "?" "a boolean" } }
261 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
264 { $values { "x" number } { "y" "a non-negative real number" } }
265 { $description "Computes the absolute value of a complex number." } ;
268 { $values { "x" number } { "y" "a non-negative real number" } }
269 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
272 { $values { "x" number } { "y" number } { "z" number } }
273 { $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." }
274 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
277 { $values { "x" number } { "y" number } }
278 { $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." } ;
281 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
282 { $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" } }
283 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
286 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
287 { $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" } "." }
288 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
291 { $values { "x" integer } { "n" integer } { "y" integer } }
292 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
293 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
295 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
296 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
300 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
301 { $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" } ":"
303 { { $snippet "epsilon" } " is zero: exact comparison." }
304 { { $snippet "epsilon" } " is positive: absolute distance test." }
305 { { $snippet "epsilon" } " is negative: relative distance test." }
311 { $values { "x" real } { "y" "a whole real number" } }
312 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
313 { $notes "The result is not necessarily an integer." } ;
316 { $values { "x" real } { "y" "a whole real number" } }
317 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
318 { $notes "The result is not necessarily an integer." } ;
321 { $values { "x" real } { "y" "a whole real number" } }
322 { $description "Outputs the least whole number greater than or equal to " { $snippet "x" } "." }
323 { $notes "The result is not necessarily an integer." } ;
326 { $values { "x" real } { "y" "a whole real number" } }
327 { $description "Outputs the whole number closest to " { $snippet "x" } "." }
328 { $notes "The result is not necessarily an integer." } ;