[//000000001]: # (math::numtheory \- Tcl Math Library) [//000000002]: # (Generated from file 'numtheory\.man' by tcllib/doctools with format 'markdown') [//000000003]: # (Copyright © 2010 Lars Hellström ) [//000000004]: # (math::numtheory\(n\) 1\.1\.3 tcllib "Tcl Math Library")
[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]
# NAME math::numtheory \- Number Theory # Table Of Contents - [Table Of Contents](#toc) - [Synopsis](#synopsis) - [Description](#section1) - [Bugs, Ideas, Feedback](#section2) - [Keywords](#keywords) - [Category](#category) - [Copyright](#copyright) # SYNOPSIS package require Tcl ?8\.5? package require math::numtheory ?1\.1\.3? [__math::numtheory::isprime__ *N* ?*option* *value* \.\.\.?](#1) [__math::numtheory::firstNprimes__ *N*](#2) [__math::numtheory::primesLowerThan__ *N*](#3) [__math::numtheory::primeFactors__ *N*](#4) [__math::numtheory::primesLowerThan__ *N*](#5) [__math::numtheory::primeFactors__ *N*](#6) [__math::numtheory::uniquePrimeFactors__ *N*](#7) [__math::numtheory::factors__ *N*](#8) [__math::numtheory::totient__ *N*](#9) [__math::numtheory::moebius__ *N*](#10) [__math::numtheory::legendre__ *a* *p*](#11) [__math::numtheory::jacobi__ *a* *b*](#12) [__math::numtheory::gcd__ *m* *n*](#13) [__math::numtheory::lcm__ *m* *n*](#14) [__math::numtheory::numberPrimesGauss__ *N*](#15) [__math::numtheory::numberPrimesLegendre__ *N*](#16) [__math::numtheory::numberPrimesLegendreModified__ *N*](#17) [__math::numtheory::differenceNumberPrimesLegendreModified__ *lower* *upper*](#18) [__math::numtheory::listPrimePairs__ *lower* *upper* *step*](#19) [__math::numtheory::listPrimeProgressions__ *lower* *upper* *step*](#20) # DESCRIPTION This package is for collecting various number\-theoretic operations, with a slight bias to prime numbers\. - __math::numtheory::isprime__ *N* ?*option* *value* \.\.\.? The __isprime__ command tests whether the integer *N* is a prime, returning a boolean true value for prime *N* and a boolean false value for non\-prime *N*\. The formal definition of 'prime' used is the conventional, that the number being tested is greater than 1 and only has trivial divisors\. To be precise, the return value is one of __0__ \(if *N* is definitely not a prime\), __1__ \(if *N* is definitely a prime\), and __on__ \(if *N* is probably prime\); the latter two are both boolean true values\. The case that an integer may be classified as "probably prime" arises because the Miller\-Rabin algorithm used in the test implementation is basically probabilistic, and may if we are unlucky fail to detect that a number is in fact composite\. Options may be used to select the risk of such "false positives" in the test\. __1__ is returned for "small" *N* \(which currently means *N* < 118670087467\), where it is known that no false positives are possible\. The only option currently defined is: * __\-randommr__ *repetitions* which controls how many times the Miller\-Rabin test should be repeated with randomly chosen bases\. Each repetition reduces the probability of a false positive by a factor at least 4\. The default for *repetitions* is 4\. Unknown options are silently ignored\. - __math::numtheory::firstNprimes__ *N* Return the first N primes * integer *N* \(in\) Number of primes to return - __math::numtheory::primesLowerThan__ *N* Return the prime numbers lower/equal to N * integer *N* \(in\) Maximum number to consider - __math::numtheory::primeFactors__ *N* Return a list of the prime numbers in the number N * integer *N* \(in\) Number to be factorised - __math::numtheory::primesLowerThan__ *N* Return the prime numbers lower/equal to N * integer *N* \(in\) Maximum number to consider - __math::numtheory::primeFactors__ *N* Return a list of the prime numbers in the number N * integer *N* \(in\) Number to be factorised - __math::numtheory::uniquePrimeFactors__ *N* Return a list of the *unique* prime numbers in the number N * integer *N* \(in\) Number to be factorised - __math::numtheory::factors__ *N* Return a list of all *unique* factors in the number N, including 1 and N itself * integer *N* \(in\) Number to be factorised - __math::numtheory::totient__ *N* Evaluate the Euler totient function for the number N \(number of numbers relatively prime to N\) * integer *N* \(in\) Number in question - __math::numtheory::moebius__ *N* Evaluate the Moebius function for the number N * integer *N* \(in\) Number in question - __math::numtheory::legendre__ *a* *p* Evaluate the Legendre symbol \(a/p\) * integer *a* \(in\) Upper number in the symbol * integer *p* \(in\) Lower number in the symbol \(must be non\-zero\) - __math::numtheory::jacobi__ *a* *b* Evaluate the Jacobi symbol \(a/b\) * integer *a* \(in\) Upper number in the symbol * integer *b* \(in\) Lower number in the symbol \(must be odd\) - __math::numtheory::gcd__ *m* *n* Return the greatest common divisor of *m* and *n* * integer *m* \(in\) First number * integer *n* \(in\) Second number - __math::numtheory::lcm__ *m* *n* Return the lowest common multiple of *m* and *n* * integer *m* \(in\) First number * integer *n* \(in\) Second number - __math::numtheory::numberPrimesGauss__ *N* Estimate the number of primes according the formula by Gauss\. * integer *N* \(in\) Number in question, should be larger than 0 - __math::numtheory::numberPrimesLegendre__ *N* Estimate the number of primes according the formula by Legendre\. * integer *N* \(in\) Number in question, should be larger than 0 - __math::numtheory::numberPrimesLegendreModified__ *N* Estimate the number of primes according the modified formula by Legendre\. * integer *N* \(in\) Number in question, should be larger than 0 - __math::numtheory::differenceNumberPrimesLegendreModified__ *lower* *upper* Estimate the number of primes between tow limits according the modified formula by Legendre\. * integer *lower* \(in\) Lower limit for the primes, should be larger than 0 * integer *upper* \(in\) Upper limit for the primes, should be larger than 0 - __math::numtheory::listPrimePairs__ *lower* *upper* *step* Return a list of pairs of primes each differing by the given step\. * integer *lower* \(in\) Lower limit for the primes, should be larger than 0 * integer *upper* \(in\) Upper limit for the primes, should be larger than the lower limit * integer *step* \(in\) Step by which the primes should differ, defaults to 2 - __math::numtheory::listPrimeProgressions__ *lower* *upper* *step* Return a list of lists of primes each differing by the given step from the previous one\. * integer *lower* \(in\) Lower limit for the primes, should be larger than 0 * integer *upper* \(in\) Upper limit for the primes, should be larger than the lower limit * integer *step* \(in\) Step by which the primes should differ, defaults to 2 # Bugs, Ideas, Feedback This document, and the package it describes, will undoubtedly contain bugs and other problems\. Please report such in the category *math :: numtheory* of the [Tcllib Trackers](http://core\.tcl\.tk/tcllib/reportlist)\. Please also report any ideas for enhancements you may have for either package and/or documentation\. When proposing code changes, please provide *unified diffs*, i\.e the output of __diff \-u__\. Note further that *attachments* are strongly preferred over inlined patches\. Attachments can be made by going to the __Edit__ form of the ticket immediately after its creation, and then using the left\-most button in the secondary navigation bar\. # KEYWORDS [number theory](\.\./\.\./\.\./\.\./index\.md\#number\_theory), [prime](\.\./\.\./\.\./\.\./index\.md\#prime) # CATEGORY Mathematics # COPYRIGHT Copyright © 2010 Lars Hellström