1 USING: help.markup help.syntax kernel math math.order
2 sequences quotations math.functions.private ;
5 ARTICLE: "integer-functions" "Integer functions"
12 "Modular exponentiation:"
13 { $subsections ^mod mod-inv }
22 ARTICLE: "arithmetic-functions" "Arithmetic functions"
23 "Computing additive and multiplicative inverses:"
24 { $subsections neg recip }
25 "Complex conjugation:"
26 { $subsections conjugate }
28 { $subsections zero? between? }
46 "Numbers implement the " { $link "math.order" } ", therefore operations such as " { $link min } " and " { $link max } " can be used with numbers." ;
48 ARTICLE: "power-functions" "Powers and logarithms"
50 { $subsections sq sqrt }
51 "Exponential and natural logarithm:"
59 "Raising a number to a power:"
60 { $subsections ^ 10^ }
61 "Converting between rectangular and polar form:"
70 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
71 "Trigonometric functions:"
72 { $subsections cos sin tan }
74 { $subsections sec cosec cot }
76 { $subsections acos asin atan }
77 "Inverse reciprocals:"
78 { $subsections asec acosec acot }
79 "Hyperbolic functions:"
80 { $subsections cosh sinh tanh }
82 { $subsections sech cosech coth }
84 { $subsections acosh asinh atanh }
85 "Inverse reciprocals:"
86 { $subsections asech acosech acoth } ;
88 ARTICLE: "math-functions" "Mathematical functions"
91 "arithmetic-functions"
96 ABOUT: "math-functions"
99 { $values { "x" real } { "y" real } { "z" number } }
100 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
103 { $values { "z" number } { "x" real } { "y" real } }
104 { $description "Extracts the real and imaginary components of a complex number." } ;
107 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
108 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
109 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
112 { $values { "x" number } { "y" number } }
113 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
116 { $values { "x" number } { "y" number } }
117 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
120 { $values { "x" number } { "y" number } }
121 { $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" } "." } ;
124 { $values { "x" number } { "y" number } }
125 { $description "Logarithm function base 10. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
128 { $values { "x" number } { "y" number } }
129 { $description "Square root function." } ;
133 { $description "Hyperbolic cosine." } ;
137 { $description "Hyperbolic secant." } ;
141 { $description "Hyperbolic sine." } ;
145 { $description "Hyperbolic cosecant." } ;
149 { $description "Hyperbolic tangent." } ;
153 { $description "Hyperbolic cotangent." } ;
157 { $description "Trigonometric cosine." } ;
161 { $description "Trigonometric secant." } ;
165 { $description "Trigonometric sine." } ;
169 { $description "Trigonometric cosecant." } ;
173 { $description "Trigonometric tangent." } ;
177 { $description "Trigonometric cotangent." } ;
181 { $description "Inverse hyperbolic cosine." } ;
185 { $description "Inverse hyperbolic secant." } ;
189 { $description "Inverse hyperbolic sine." } ;
193 { $description "Inverse hyperbolic cosecant." } ;
197 { $description "Inverse hyperbolic tangent." } ;
201 { $description "Inverse hyperbolic cotangent." } ;
205 { $description "Inverse trigonometric cosine." } ;
209 { $description "Inverse trigonometric secant." } ;
213 { $description "Inverse trigonometric sine." } ;
217 { $description "Inverse trigonometric cosecant." } ;
221 { $description "Inverse trigonometric tangent." } ;
225 { $description "Inverse trigonometric cotangent." } ;
228 { $values { "z" number } { "z*" number } }
229 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
232 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
233 { $description "Computes the complex argument." } ;
236 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
237 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
240 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
241 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
243 { cis exp } related-words
246 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
247 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
250 { $values { "x" number } { "?" "a boolean" } }
251 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
254 { $values { "x" number } { "y" "a non-negative real number" } }
255 { $description "Computes the absolute value of a complex number." } ;
258 { $values { "x" number } { "y" "a non-negative real number" } }
259 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
262 { $values { "x" number } { "y" number } { "z" number } }
263 { $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." }
264 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
267 { $values { "x" number } { "y" number } }
268 { $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." } ;
271 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
272 { $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" } }
273 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
276 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
277 { $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" } "." }
278 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
281 { $values { "x" integer } { "n" integer } { "y" integer } }
282 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
283 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
285 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
286 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
290 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
291 { $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" } ":"
293 { { $snippet "epsilon" } " is zero: exact comparison." }
294 { { $snippet "epsilon" } " is positive: absolute distance test." }
295 { { $snippet "epsilon" } " is negative: relative distance test." }
301 { $values { "x" real } { "y" "a whole real number" } }
302 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
303 { $notes "The result is not necessarily an integer." } ;
306 { $values { "x" real } { "y" "a whole real number" } }
307 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
308 { $notes "The result is not necessarily an integer." } ;
311 { $values { "x" real } { "y" "a whole real number" } }
312 { $description "Outputs the least whole number greater 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 whole number closest to " { $snippet "x" } "." }
318 { $notes "The result is not necessarily an integer." } ;