SCM

SCM Repository

[inlinedocs] Annotation of /pkg/inlinedocs/inst/testfiles/fermatExAttr.R
ViewVC logotype

Annotation of /pkg/inlinedocs/inst/testfiles/fermatExAttr.R

Parent Directory Parent Directory | Revision Log Revision Log


Revision 140 - (view) (download)

1 : tdhock 140 fermat.test <- function#Test an integer for primality with Fermat's little theorem.
2 :     ### Fermat's little theorem states that if \eqn{n} is a prime number
3 :     ### and \eqn{a} is any positive integer less than \eqn{n}, then
4 :     ### \eqn{a} raised to the \eqn{n}th power is congruent to \eqn{a\
5 :     ### modulo\ n}{a modulo n}.
6 :     ##references<< \url{http://en.wikipedia.org/wiki/Fermat's_little_theorem}
7 :     (n ##<< the integer to test for primality.
8 :     ){
9 :     a <- floor(runif(1,min=1,max=n))
10 :     ##note<< \code{fermat.test} doesn't work for integers above
11 :     ##approximately 15 because modulus loses precision.
12 :     a^n %% n == a
13 :     ### Whether the integer passes the Fermat test for a randomized
14 :     ### \eqn{0<a<n}
15 :     }
16 :     is.pseudoprime <- structure(function
17 :     ### A number is pseudo-prime if it is probably prime, the basis of
18 :     ### which is the probabalistic Fermat test; if it passes two such
19 :     ### tests, the chances are better than 3 out of 4 that \eqn{n} is
20 :     ### prime.
21 :     ##references<< Abelson, Hal; Jerry Sussman, and Julie
22 :     ##Sussman. Structure and Interpretation of Computer
23 :     ##Programs. Cambridge: MIT Press, 1984.
24 :     (n, ##<< the integer to test for pseudoprimality.
25 :     times ##<< the number of Fermat tests to perform
26 :     ){
27 :     if(times==0)TRUE
28 :     ##seealso<< \code{\link{fermat.test}}
29 :     else if(fermat.test(n)) is.pseudoprime(n,times-1)
30 :     else FALSE
31 :     ### Whether the number is pseudoprime.
32 :     },ex=function(){
33 :     is.pseudoprime(13,4)
34 :     })
35 :    
36 :     .result <-
37 :     list(fermat.test = list(format="",definition = "fermat.test <- function#Test an integer for primality with Fermat's little theorem.\n### Fermat's little theorem states that if \\eqn{n} is a prime number\n### and \\eqn{a} is any positive integer less than \\eqn{n}, then\n### \\eqn{a} raised to the \\eqn{n}th power is congruent to \\eqn{a\\\n### modulo\\ n}{a modulo n}.\n##references<< \\url{http://en.wikipedia.org/wiki/Fermat's_little_theorem}\n(n ##<< the integer to test for primality.\n ){\n a <- floor(runif(1,min=1,max=n))\n ##note<< \\code{fermat.test} doesn't work for integers above\n ##approximately 15 because modulus loses precision.\n a^n %% n == a\n### Whether the integer passes the Fermat test for a randomized\n### \\eqn{0<a<n}\n}",
38 :     title = "Test an integer for primality with Fermat's little theorem.",
39 :     description = "Fermat's little theorem states that if \\eqn{n} is a prime number\nand \\eqn{a} is any positive integer less than \\eqn{n}, then\n\\eqn{a} raised to the \\eqn{n}th power is congruent to \\eqn{a\\\nmodulo\\ n}{a modulo n}.",
40 :     value = "Whether the integer passes the Fermat test for a randomized\n\\eqn{0<a<n}",
41 :     references = "\\url{http://en.wikipedia.org/wiki/Fermat's_little_theorem}",
42 :     `item{n}` = "the integer to test for primality.", note = "\\code{fermat.test} doesn't work for integers above\napproximately 15 because modulus loses precision."),
43 :     is.pseudoprime = list(definition = "is.pseudoprime <- structure(function\n### A number is pseudo-prime if it is probably prime, the basis of\n### which is the probabalistic Fermat test; if it passes two such\n### tests, the chances are better than 3 out of 4 that \\eqn{n} is\n### prime.\n##references<< Abelson, Hal; Jerry Sussman, and Julie\n##Sussman. Structure and Interpretation of Computer\n##Programs. Cambridge: MIT Press, 1984.\n(n, ##<< the integer to test for pseudoprimality.\n times ##<< the number of Fermat tests to perform\n){\n if(times==0)TRUE\n ##seealso<< \\code{\\link{fermat.test}}\n else if(fermat.test(n)) is.pseudoprime(n,times-1)\n else FALSE\n### Whether the number is pseudoprime.\n},ex=function(){\n is.pseudoprime(13,4)\n})",
44 :     description = "A number is pseudo-prime if it is probably prime, the basis of\nwhich is the probabalistic Fermat test; if it passes two such\ntests, the chances are better than 3 out of 4 that \\eqn{n} is\nprime.",
45 :     title="is pseudoprime",
46 :     references = "Abelson, Hal; Jerry Sussman, and Julie\nSussman. Structure and Interpretation of Computer\nPrograms. Cambridge: MIT Press, 1984.",
47 :     `item{n}` = "the integer to test for pseudoprimality.",
48 :     `item{times}` = "the number of Fermat tests to perform",
49 :     seealso = "\\code{\\link{fermat.test}}", examples = "\nis.pseudoprime(13,4)\n",
50 :     value = "Whether the number is pseudoprime.",format=""))

R-Forge@R-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business University of Wisconsin - Madison Powered By FusionForge