math::numtheory(3tcl)
π math::numtheory π β the Tcl Math Library's number theory era π
okay so bestie, welcome to math::numtheory(3tcl), a whole manual page from the Tcl Math Library that is literally all about number theory. it's giving math girlie, it's giving primes, it's giving "I know what a totient is and I'm not sorry." π¦
β¨ NAME β¨
math::numtheory β Number Theory. that's it, that's the name, and it ate. π
πΈ SYNOPSIS πΈ
the way that you load this whole situation is:
package require Tcl ?8.5 9?
package require math::numtheory ?1.1.4?
and then all the little commands you get to call, no cap:
math::numtheory::isprime N ?option value ...?
math::numtheory::firstNprimes N
math::numtheory::primesLowerThan N
math::numtheory::primeFactors N
math::numtheory::primesLowerThan N
math::numtheory::primeFactors N
math::numtheory::uniquePrimeFactors N
math::numtheory::factors N
math::numtheory::totient N
math::numtheory::moebius N
math::numtheory::legendre a p
math::numtheory::jacobi a b
math::numtheory::gcd m n
math::numtheory::lcm m n
math::numtheory::numberPrimesGauss N
math::numtheory::numberPrimesLegendre N
math::numtheory::numberPrimesLegendreModified N
math::numtheory::differenceNumberPrimesLegendreModified lower upper
math::numtheory::listPrimePairs lower upper step
math::numtheory::listPrimeProgressions lower upper step
yesprimesLowerThanandprimeFactorsreally do show up twice up there. that's not a typo on my end, that's just the page being the page. we respect it. π
π DESCRIPTION π
so this package exists to collect a bunch of number-theoretic operations, and ngl it has a slight bias toward prime numbers. it's a prime stan account. that's the vibe.
π₯ math::numtheory::isprime N ?option value ...?
the isprime command tests whether the integer N is a prime, and it hands you back a boolean true value if N is prime and a boolean false value if it's not. the formal definition of "prime" it's using is the conventional one: the number being tested is greater than 1 and only has trivial divisors. classic. β¨
to be precise (and we ARE being precise), the return value is one of:
0β ifNis definitely not a prime1β ifNis definitely a primeonβ ifNis probably prime
the latter two are both boolean true values, so if you're just vibe-checking truthiness, you're fine. π
the whole "probably prime" situation exists because the Miller-Rabin algorithm used in the test implementation is basically probabilistic, and it may β if we are unlucky β fail to detect that a number is in fact composite. so that's a thing that can happen. π
options let you pick how much risk of these "false positives" you want in the test. and for "small" N (which currently means N < 118670087467), it returns 1, because in that range it is known that no false positives are possible. slay. π₯
the only option currently defined is:
-randommr repetitionsβ 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 is4.
unknown options are silently ignored. no error, no drama, just vibes. π«Ά
πΈ 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
(yes bestie, again. it's in the original twice and I am nothing if not faithful. π)
πΈ math::numtheory::primeFactors N
return a list of the prime numbers in the number N.
integer N(in) β number to be factorised
(also again. iconic behaviour honestly.)
π math::numtheory::uniquePrimeFactors N
return a list of the unique prime numbers in the number N. no duplicates, only main characters. π
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. so like, the whole friend group.
integer N(in) β number to be factorised
π¦ math::numtheory::totient N
evaluate the Euler totient function for the number N (that's the number of numbers relatively prime to N). we love a function named after a person. periodt.
integer N(in) β number in question
π¦ math::numtheory::moebius N
evaluate the Moebius function for the number N. yes it's spelled Moebius here, that's the spelling, we're keeping it. π
integer N(in) β number in question
β math::numtheory::legendre a p
evaluate the Legendre symbol (a/p).
integer a(in) β upper number in the symbolinteger p(in) β lower number in the symbol (must be non-zero)
p must be non-zero. that is not a suggestion. π¨
β math::numtheory::jacobi a b
evaluate the Jacobi symbol (a/b).
integer a(in) β upper number in the symbolinteger b(in) β lower number in the symbol (must be odd)
b must be odd. odd only, bestie. β¨
π math::numtheory::gcd m n
return the greatest common divisor of m and n.
integer m(in) β first numberinteger n(in) β second number
π math::numtheory::lcm m n
return the lowest common multiple of m and n.
integer m(in) β first numberinteger n(in) β second number
π math::numtheory::numberPrimesGauss N
estimate the number of primes according the formula by Gauss. estimates are still valid, we don't gatekeep. π
integer N(in) β number in question, should be larger than0
π math::numtheory::numberPrimesLegendre N
estimate the number of primes according the formula by Legendre.
integer N(in) β number in question, should be larger than0
π math::numtheory::numberPrimesLegendreModified N
estimate the number of primes according the modified formula by Legendre. glow-up edition. β¨
integer N(in) β number in question, should be larger than0
π§ math::numtheory::differenceNumberPrimesLegendreModified lower upper
estimate the number of primes between tow limits according the modified formula by Legendre.
heads up: "tow" is what the page says, and I am not here to fix it, I am here to report it. π
integer lower(in) β lower limit for the primes, should be larger than0integer upper(in) β upper limit for the primes, should be larger than0
π§ math::numtheory::listPrimePairs lower upper step
return a list of pairs of primes each differing by the given step. twin primes, but make it configurable. π―
integer lower(in) β lower limit for the primes, should be larger than0integer upper(in) β upper limit for the primes, should be larger than the lower limitinteger step(in) β step by which the primes should differ, defaults to2
π§ math::numtheory::listPrimeProgressions lower upper step
return a list of lists of primes each differing by the given step from the previous one. yes, a list of lists. nested. we're nesting, bestie. π
integer lower(in) β lower limit for the primes, should be larger than0integer upper(in) β upper limit for the primes, should be larger than the lower limitinteger step(in) β step by which the primes should differ, defaults to2
π BUGS, IDEAS, FEEDBACK π
okay so real talk, and I need you to hear me on this: this document, and the package it describes, will undoubtedly contain bugs and other problems. like, the page itself said it. that's just how it is. π
please report such in the category math :: numtheory of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist.
also please report any ideas for enhancements you may have for either package and/or documentation. they want your ideas. they want them fr fr. π«Ά
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
and 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. that's the whole treasure map, go forth. πΊοΈβ¨
π KEYWORDS π
number theory, prime
π CATEGORY π
Mathematics
π COPYRIGHT π
Copyright (c) 2010 Lars HellstrΓΆm <Lars dot Hellstrom at residenset dot net>
okay bestie that's the whole page π this came to you from tcllib, version 1.1.4, and it's the math::numtheory(3tcl) page β go forth and factorise responsibly. mwah. πβ¨
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2010 Lars HellstrΓΆm <Lars dot Hellstrom at residenset dot net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms