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:"
29 "Complex conjugation:"
30 { $subsection conjugate }
33 { $subsection between? }
37 { $subsection ceiling }
39 { $subsection truncate }
44 ARTICLE: "power-functions" "Powers and logarithms"
48 "Exponential and natural logarithm:"
52 "Raising a number to a power:"
54 "Converting between rectangular and polar form:"
58 { $subsection >polar }
59 { $subsection polar> } ;
61 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
62 "Trigonometric functions:"
74 "Inverse reciprocals:"
76 { $subsection acosec }
78 "Hyperbolic functions:"
84 { $subsection cosech }
90 "Inverse reciprocals:"
92 { $subsection acosech }
93 { $subsection acoth } ;
95 ARTICLE: "math-functions" "Mathematical functions"
96 { $subsection "integer-functions" }
97 { $subsection "arithmetic-functions" }
98 { $subsection "power-functions" }
99 { $subsection "trig-hyp-functions" } ;
101 ABOUT: "math-functions"
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" } "." } ;
108 { $values { "z" number } { "x" real } { "y" real } }
109 { $description "Extracts the real and imaginary components of a complex number." } ;
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." } ;
117 { $values { "x" number } { "y" number } }
118 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
121 { $values { "x" number } { "y" number } }
122 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
125 { $values { "x" number } { "y" number } }
126 { $description "Square root function." } ;
130 { $description "Hyperbolic cosine." } ;
134 { $description "Hyperbolic secant." } ;
138 { $description "Hyperbolic sine." } ;
142 { $description "Hyperbolic cosecant." } ;
146 { $description "Hyperbolic tangent." } ;
150 { $description "Hyperbolic cotangent." } ;
154 { $description "Trigonometric cosine." } ;
158 { $description "Trigonometric secant." } ;
162 { $description "Trigonometric sine." } ;
166 { $description "Trigonometric cosecant." } ;
170 { $description "Trigonometric tangent." } ;
174 { $description "Trigonometric cotangent." } ;
178 { $description "Inverse hyperbolic cosine." } ;
182 { $description "Inverse hyperbolic secant." } ;
186 { $description "Inverse hyperbolic sine." } ;
190 { $description "Inverse hyperbolic cosecant." } ;
194 { $description "Inverse hyperbolic tangent." } ;
198 { $description "Inverse hyperbolic cotangent." } ;
202 { $description "Inverse trigonometric cosine." } ;
206 { $description "Inverse trigonometric secant." } ;
210 { $description "Inverse trigonometric sine." } ;
214 { $description "Inverse trigonometric cosecant." } ;
218 { $description "Inverse trigonometric tangent." } ;
222 { $description "Inverse trigonometric cotangent." } ;
225 { $values { "z" number } { "z*" number } }
226 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
229 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
230 { $description "Computes the complex argument." } ;
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)." } ;
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)" } "." } ;
240 { cis exp } related-words
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." } ;
247 { $values { "x" number } { "?" "a boolean" } }
248 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
251 { $values { "x" number } { "y" "a non-negative real number" } }
252 { $description "Computes the absolute value of a complex number." } ;
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 } "." } ;
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." } ;
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" } "." } ;
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." } ;
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" } "." }
278 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
279 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
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" } ":"
286 { { $snippet "epsilon" } " is zero: exact comparison." }
287 { { $snippet "epsilon" } " is positive: absolute distance test." }
288 { { $snippet "epsilon" } " is negative: relative distance test." }
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." } ;
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." } ;
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." } ;
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." } ;