[Roxygen-commits] r177 - pkg/sandbox
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Aug 24 10:37:14 CEST 2008
Author: pcd
Date: 2008-08-24 10:37:14 +0200 (Sun, 24 Aug 2008)
New Revision: 177
Modified:
pkg/sandbox/example-pseudoprime.R
Log:
less verbose; exdent
Modified: pkg/sandbox/example-pseudoprime.R
===================================================================
--- pkg/sandbox/example-pseudoprime.R 2008-08-24 08:37:11 UTC (rev 176)
+++ pkg/sandbox/example-pseudoprime.R 2008-08-24 08:37:14 UTC (rev 177)
@@ -4,14 +4,10 @@
#' \eqn{a} is any positive integer less than \eqn{n}, then a raised to the
#' \eqn{n}th power is congruent to \eqn{a modulo n}.
#'
+#' @author Peter Danenberg \email{pcd@@roxygen.org}
#' @param n the integer to test for primality
#' @return Whether the integer passes the Fermat test
-#' for a randomized 0 < a < n
-#' @note Can't test for primes above 15 because of loss of precision
-#' in modulus.
-#' @TODO Use the \code{gmp} library so we can test for bigger
-#' primes.
-#' @author Peter Danenberg \email{pcd@@roxygen.org}
+#' for a randomized 0 < a < n
fermat.test <- function(n) {
a <- floor(runif(1, min=1, max=n))
isTRUE(a ^ n %% n == a)
@@ -21,21 +17,21 @@
#'
#' A number is pseudo-prime if it is probably prime, the basis of
#' which is the probabilistic Fermat test; if it passes two such
-#' tests, the chances are better than 3 out of 4 that n is prime.
+#' tests, the chances are better than 3 out of 4 that \eqn{n} is prime.
#'
+#' @author Peter Danenberg \email{pcd@@roxygen.org}
#' @param n the integer to test for pseudoprimality.
#' @param times the number of Fermat tests to perform
#' @return Whether the number is pseudoprime
-#' @seealso \code{\link{fermat.test}}
#' @export
-#' @examples
-#' ## Will be true most of the time
-#' is.pseudoprime(13, 4)
+#' @seealso \code{\link{fermat.test}}
#' @references Abelson, Hal; Jerry Sussman, and Julie Sussman.
-#' Structure and Interpretation of Computer Programs. Cambridge:
-#' MIT Press, 1984.
+#' Structure and Interpretation of Computer Programs. Cambridge:
+#' MIT Press, 1984.
#' @keywords pseudoprime fermat
-#' @author Peter Danenberg \email{pcd@@roxygen.org}
+#' @examples
+#' ## Will be true most of the time
+#' is.pseudoprime(13, 4)
is.pseudoprime <- function(n, times) {
if (times == 0) TRUE
else if (fermat.test(n)) is.fermat.prime(n, times - 1)
More information about the Roxygen-commits
mailing list