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:"
52 { $subsections exp cis log }
54 { $subsection log1+ log10 }
55 "Raising a number to a power:"
56 { $subsections ^ 10^ }
57 "Converting between rectangular and polar form:"
66 ARTICLE: "trig-hyp-functions" "Trigonometric and hyperbolic functions"
67 "Trigonometric functions:"
68 { $subsections cos sin tan }
70 { $subsections sec cosec cot }
72 { $subsections acos asin atan }
73 "Inverse reciprocals:"
74 { $subsections asec acosec acot }
75 "Hyperbolic functions:"
76 { $subsections cosh sinh tanh }
78 { $subsections sech cosech coth }
80 { $subsections acosh asinh atanh }
81 "Inverse reciprocals:"
82 { $subsections asech acosech acoth } ;
84 ARTICLE: "math-functions" "Mathematical functions"
87 "arithmetic-functions"
92 ABOUT: "math-functions"
95 { $values { "x" real } { "y" real } { "z" number } }
96 { $description "Creates a complex number from real and imaginary components. If " { $snippet "z" } " is an integer zero, this will simply output " { $snippet "x" } "." } ;
99 { $values { "z" number } { "x" real } { "y" real } }
100 { $description "Extracts the real and imaginary components of a complex number." } ;
103 { $values { "m" integer } { "w" "a power of 2" } { "n" "an integer multiple of " { $snippet "w" } } }
104 { $description "Outputs the least multiple of " { $snippet "w" } " greater than " { $snippet "m" } "." }
105 { $notes "This word will give an incorrect result if " { $snippet "w" } " is not a power of 2." } ;
108 { $values { "x" number } { "y" number } }
109 { $description "Exponential function, " { $snippet "y=e^x" } "." } ;
112 { $values { "x" number } { "y" number } }
113 { $description "Natural logarithm function. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
116 { $values { "x" number } { "y" number } }
117 { $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" } "." } ;
120 { $values { "x" number } { "y" number } }
121 { $description "Logarithm function base 10. Outputs negative infinity if " { $snippet "x" } " is 0." } ;
124 { $values { "x" number } { "y" number } }
125 { $description "Square root function." } ;
129 { $description "Hyperbolic cosine." } ;
133 { $description "Hyperbolic secant." } ;
137 { $description "Hyperbolic sine." } ;
141 { $description "Hyperbolic cosecant." } ;
145 { $description "Hyperbolic tangent." } ;
149 { $description "Hyperbolic cotangent." } ;
153 { $description "Trigonometric cosine." } ;
157 { $description "Trigonometric secant." } ;
161 { $description "Trigonometric sine." } ;
165 { $description "Trigonometric cosecant." } ;
169 { $description "Trigonometric tangent." } ;
173 { $description "Trigonometric cotangent." } ;
177 { $description "Inverse hyperbolic cosine." } ;
181 { $description "Inverse hyperbolic secant." } ;
185 { $description "Inverse hyperbolic sine." } ;
189 { $description "Inverse hyperbolic cosecant." } ;
193 { $description "Inverse hyperbolic tangent." } ;
197 { $description "Inverse hyperbolic cotangent." } ;
201 { $description "Inverse trigonometric cosine." } ;
205 { $description "Inverse trigonometric secant." } ;
209 { $description "Inverse trigonometric sine." } ;
213 { $description "Inverse trigonometric cosecant." } ;
217 { $description "Inverse trigonometric tangent." } ;
221 { $description "Inverse trigonometric cotangent." } ;
224 { $values { "z" number } { "z*" number } }
225 { $description "Computes the complex conjugate by flipping the sign of the imaginary part of " { $snippet "z" } "." } ;
228 { $values { "z" number } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
229 { $description "Computes the complex argument." } ;
232 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" "a number in the interval " { $snippet "(-pi,pi]" } } }
233 { $description "Converts a complex number into an absolute value and argument (polar form)." } ;
236 { $values { "arg" "a real number" } { "z" "a complex number on the unit circle" } }
237 { $description "Computes a point on the unit circle using Euler's formula for " { $snippet "exp(arg*i)" } "." } ;
239 { cis exp } related-words
242 { $values { "z" number } { "abs" "a non-negative real number" } { "arg" real } }
243 { $description "Converts an absolute value and argument (polar form) to a complex number." } ;
246 { $values { "x" number } { "?" "a boolean" } }
247 { $description "Tests if " { $snippet "x" } " is a real number between -1 and 1, inclusive." } ;
250 { $values { "x" number } { "y" "a non-negative real number" } }
251 { $description "Computes the absolute value of a complex number." } ;
254 { $values { "x" number } { "y" "a non-negative real number" } }
255 { $description "Computes the squared absolute value of a complex number. This is marginally more efficient than " { $link abs } "." } ;
258 { $values { "x" number } { "y" number } { "z" number } }
259 { $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." }
260 { $errors "Throws an error if " { $snippet "x" } " and " { $snippet "y" } " are both integer 0." } ;
263 { $values { "x" number } { "y" number } }
264 { $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." } ;
267 { $values { "x" integer } { "y" integer } { "a" integer } { "d" integer } }
268 { $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" } }
269 { $notes "If " { $snippet "d" } " is 1, then " { $snippet "a" } " is the inverse of " { $snippet "y" } " modulo " { $snippet "x" } "." } ;
272 { $values { "m" integer } { "n" integer } { "?" "a boolean" } }
273 { $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" } "." }
274 { $notes "Returns t for both negative and positive divisors, as well as for trivial and non-trivial divisors." } ;
277 { $values { "x" integer } { "n" integer } { "y" integer } }
278 { $description "Outputs an integer " { $snippet "y" } " such that " { $snippet "xy = 1 (mod n)" } "." }
279 { $errors "Throws an error if " { $snippet "n" } " is not invertible modulo " { $snippet "n" } "." }
281 { $example "USING: math.functions prettyprint ;" "173 1119 mod-inv ." "815" }
282 { $example "USING: math prettyprint ;" "173 815 * 1119 mod ." "1" }
286 { $values { "x" real } { "y" real } { "epsilon" real } { "?" "a boolean" } }
287 { $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" } ":"
289 { { $snippet "epsilon" } " is zero: exact comparison." }
290 { { $snippet "epsilon" } " is positive: absolute distance test." }
291 { { $snippet "epsilon" } " is negative: relative distance test." }
297 { $values { "x" real } { "y" "a whole real number" } }
298 { $description "Outputs the number that results from subtracting the fractional component of " { $snippet "x" } "." }
299 { $notes "The result is not necessarily an integer." } ;
302 { $values { "x" real } { "y" "a whole real number" } }
303 { $description "Outputs the greatest whole number smaller than or equal to " { $snippet "x" } "." }
304 { $notes "The result is not necessarily an integer." } ;
307 { $values { "x" real } { "y" "a whole real number" } }
308 { $description "Outputs the least whole number greater than or equal to " { $snippet "x" } "." }
309 { $notes "The result is not necessarily an integer." } ;
312 { $values { "x" real } { "y" "a whole real number" } }
313 { $description "Outputs the whole number closest to " { $snippet "x" } "." }
314 { $notes "The result is not necessarily an integer." } ;