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:"
55 "Raising a number to a power:"
58 "Converting between rectangular and polar form:"
62 { $subsection >polar }
63 { $subsection polar> } ;
65 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
66 "Trigonometric functions:"
78 "Inverse reciprocals:"
80 { $subsection acosec }
82 "Hyperbolic functions:"
88 { $subsection cosech }
94 "Inverse reciprocals:"
96 { $subsection acosech }
97 { $subsection acoth } ;
99 ARTICLE: "math-functions" "Mathematical functions"
100 { $subsection "integer-functions" }
101 { $subsection "arithmetic-functions" }
102 { $subsection "power-functions" }
103 { $subsection "trig-hyp-functions" } ;
105 ABOUT: "math-functions"
108 { $values { "x" real } { "y" real } { "z" number } }
109 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
112 { $values { "z" number } { "x" real } { "y" real } }
113 { $description "Extracts the real and imaginary components of a complex number." } ;
116 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
117 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
118 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
121 { $values { "x" number } { "y" number } }
122 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
125 { $values { "x" number } { "y" number } }
126 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
129 { $values { "x" number } { "y" number } }
130 { $description "Logarithm function base 10. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
133 { $values { "x" number } { "y" number } }
134 { $description "Square root function." } ;
138 { $description "Hyperbolic cosine." } ;
142 { $description "Hyperbolic secant." } ;
146 { $description "Hyperbolic sine." } ;
150 { $description "Hyperbolic cosecant." } ;
154 { $description "Hyperbolic tangent." } ;
158 { $description "Hyperbolic cotangent." } ;
162 { $description "Trigonometric cosine." } ;
166 { $description "Trigonometric secant." } ;
170 { $description "Trigonometric sine." } ;
174 { $description "Trigonometric cosecant." } ;
178 { $description "Trigonometric tangent." } ;
182 { $description "Trigonometric cotangent." } ;
186 { $description "Inverse hyperbolic cosine." } ;
190 { $description "Inverse hyperbolic secant." } ;
194 { $description "Inverse hyperbolic sine." } ;
198 { $description "Inverse hyperbolic cosecant." } ;
202 { $description "Inverse hyperbolic tangent." } ;
206 { $description "Inverse hyperbolic cotangent." } ;
210 { $description "Inverse trigonometric cosine." } ;
214 { $description "Inverse trigonometric secant." } ;
218 { $description "Inverse trigonometric sine." } ;
222 { $description "Inverse trigonometric cosecant." } ;
226 { $description "Inverse trigonometric tangent." } ;
230 { $description "Inverse trigonometric cotangent." } ;
233 { $values { "z" number } { "z*" number } }
234 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
237 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
238 { $description "Computes the complex argument." } ;
241 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
242 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
245 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
246 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
248 { cis exp } related-words
251 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
252 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
255 { $values { "x" number } { "?" "a boolean" } }
256 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
259 { $values { "x" number } { "y" "a non-negative real number" } }
260 { $description "Computes the absolute value of a complex number." } ;
263 { $values { "x" number } { "y" "a non-negative real number" } }
264 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
267 { $values { "x" number } { "y" number } { "z" number } }
268 { $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." }
269 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
272 { $values { "x" number } { "y" number } }
273 { $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." } ;
276 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
277 { $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" } }
278 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
281 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
282 { $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" } "." }
283 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
286 { $values { "x" integer } { "n" integer } { "y" integer } }
287 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
288 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
290 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
291 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
295 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
296 { $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" } ":"
298 { { $snippet "epsilon" } " is zero: exact comparison." }
299 { { $snippet "epsilon" } " is positive: absolute distance test." }
300 { { $snippet "epsilon" } " is negative: relative distance test." }
306 { $values { "x" real } { "y" "a whole real number" } }
307 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
308 { $notes "The result is not necessarily an integer." } ;
311 { $values { "x" real } { "y" "a whole real number" } }
312 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
313 { $notes "The result is not necessarily an integer." } ;
316 { $values { "x" real } { "y" "a whole real number" } }
317 { $description "Outputs the least whole number greater 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 whole number closest to " { $snippet "x" } "." }
323 { $notes "The result is not necessarily an integer." } ;