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:"
53 "Raising a number to a power:"
55 "Converting between rectangular and polar form:"
59 { $subsection >polar }
60 { $subsection polar> } ;
62 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
63 "Trigonometric functions:"
75 "Inverse reciprocals:"
77 { $subsection acosec }
79 "Hyperbolic functions:"
85 { $subsection cosech }
91 "Inverse reciprocals:"
93 { $subsection acosech }
94 { $subsection acoth } ;
96 ARTICLE: "math-functions" "Mathematical functions"
97 { $subsection "integer-functions" }
98 { $subsection "arithmetic-functions" }
99 { $subsection "power-functions" }
100 { $subsection "trig-hyp-functions" } ;
102 ABOUT: "math-functions"
105 { $values { "x" real } { "y" real } { "z" number } }
106 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
109 { $values { "z" number } { "x" real } { "y" real } }
110 { $description "Extracts the real and imaginary components of a complex number." } ;
113 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
114 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
115 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
118 { $values { "x" number } { "y" number } }
119 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
122 { $values { "x" number } { "y" number } }
123 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
126 { $values { "x" number } { "y" number } }
127 { $description "Square root function." } ;
131 { $description "Hyperbolic cosine." } ;
135 { $description "Hyperbolic secant." } ;
139 { $description "Hyperbolic sine." } ;
143 { $description "Hyperbolic cosecant." } ;
147 { $description "Hyperbolic tangent." } ;
151 { $description "Hyperbolic cotangent." } ;
155 { $description "Trigonometric cosine." } ;
159 { $description "Trigonometric secant." } ;
163 { $description "Trigonometric sine." } ;
167 { $description "Trigonometric cosecant." } ;
171 { $description "Trigonometric tangent." } ;
175 { $description "Trigonometric cotangent." } ;
179 { $description "Inverse hyperbolic cosine." } ;
183 { $description "Inverse hyperbolic secant." } ;
187 { $description "Inverse hyperbolic sine." } ;
191 { $description "Inverse hyperbolic cosecant." } ;
195 { $description "Inverse hyperbolic tangent." } ;
199 { $description "Inverse hyperbolic cotangent." } ;
203 { $description "Inverse trigonometric cosine." } ;
207 { $description "Inverse trigonometric secant." } ;
211 { $description "Inverse trigonometric sine." } ;
215 { $description "Inverse trigonometric cosecant." } ;
219 { $description "Inverse trigonometric tangent." } ;
223 { $description "Inverse trigonometric cotangent." } ;
226 { $values { "z" number } { "z*" number } }
227 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
230 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
231 { $description "Computes the complex argument." } ;
234 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
235 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
238 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
239 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
241 { cis exp } related-words
244 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
245 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
248 { $values { "x" number } { "?" "a boolean" } }
249 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
252 { $values { "x" number } { "y" "a non-negative real number" } }
253 { $description "Computes the absolute value of a complex number." } ;
256 { $values { "x" number } { "y" "a non-negative real number" } }
257 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
260 { $values { "x" number } { "y" number } { "z" number } }
261 { $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." }
262 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
265 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
266 { $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" } }
267 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
270 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
271 { $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" } "." }
272 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
275 { $values { "x" integer } { "n" integer } { "y" integer } }
276 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
277 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
279 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
280 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
284 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
285 { $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" } ":"
287 { { $snippet "epsilon" } " is zero: exact comparison." }
288 { { $snippet "epsilon" } " is positive: absolute distance test." }
289 { { $snippet "epsilon" } " is negative: relative distance test." }
295 { $values { "x" real } { "y" "a whole real number" } }
296 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
297 { $notes "The result is not necessarily an integer." } ;
300 { $values { "x" real } { "y" "a whole real number" } }
301 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
302 { $notes "The result is not necessarily an integer." } ;
305 { $values { "x" real } { "y" "a whole real number" } }
306 { $description "Outputs the least whole number greater than or equal to " { $snippet "x" } "." }
307 { $notes "The result is not necessarily an integer." } ;
310 { $values { "x" real } { "y" "a whole real number" } }
311 { $description "Outputs the whole number closest to " { $snippet "x" } "." }
312 { $notes "The result is not necessarily an integer." } ;