math::numtheory(n)
math::numtheory π
okay bestie, welcome to the math::numtheory page from the Tcl Math Library β she's giving number theory, she's giving primes, she's giving main character energy for integers. let's get into it π§β¨
β¨ NAME β¨
math::numtheory β Number Theory. that's it, that's the whole vibe. π
π SYNOPSIS π
package require Tcl ?8.5 9?
package require math::numtheory ?1.1.4?
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
ngl yes,primesLowerThanandprimeFactorsshow up twice in there. that's just how she is. we don't gatekeep, we list them both. π«Ά
πΈ DESCRIPTION πΈ
so this package is literally a little grab-bag of number-theoretic operations, and she is slightly obsessed with prime numbers. no cap. π₯°
math::numtheory::isprime N ?option value ...?
isprime is the vibe check: it tests whether the integer N is a prime. it hands back a boolean true value when N is prime, and a boolean false value when N is not prime. the formal definition of prime she's using is the conventional one β the number being tested has to be greater than 1, and it only gets trivial divisors. periodt.
okay but to be precise, because we are precise around here: 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, bestie. π
so why is "probably prime" even a thing?? π it's because the Miller-Rabin algorithm used in the test implementation is basically probabilistic β and if we get unlucky, it can fail to detect that a number is in fact composite. rude of it, honestly. the options let you pick how much risk of those "false positives" you're willing to take. and 1 is returned for "small" N β which currently means N < 118670087467 β where it's known that no false positives are possible. iconic. π
the only option currently defined is:
-randommr repetitionsβ this controls how many times the Miller-Rabin test gets repeated with randomly chosen bases. each repetition reduces the probability of a false positive by a factor of at least4. the default forrepetitionsis4.
also, unknown options are silently ignored. she's chill like that. π
math::numtheory::firstNprimes N
return the first N primes. simple as. β¨
- 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. (yes, again. she said it twice and she meant it twice. π
)
- integer
N(in) β Maximum number to consider
math::numtheory::primeFactors N
return a list of the prime numbers in the number N. (round two, bestie π¦)
- integer
N(in) β Number to be factorised
math::numtheory::uniquePrimeFactors N
return a list of the unique prime numbers in the number N. no duplicates allowed, we're doing quality over quantity here. π
- integer
N(in) β Number to be factorised
math::numtheory::factors N
return a list of all the unique factors in the number N, and yes that includes 1 and N itself. the whole family is invited to the function. π«Ά
- 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. π§
- 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. the duo we didn't know we needed. π₯
- 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 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. she got a glow-up. β¨
- 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. (yes, "tow". we are keeping the typo exactly as she wrote it, it's canon now. π)
- integer
lower(in) β Lower limit for the primes, should be larger than0 - integer
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 pair differing by the given step. twin primes found, slay. π―
- integer
lower(in) β Lower limit for the primes, should be larger than0 - integer
upper(in) β Upper limit for the primes, should be larger than thelowerlimit - integer
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 one differing by the given step from the previous one. it's giving chain, it's giving progression, we love to see it. π
- integer
lower(in) β Lower limit for the primes, should be larger than0 - integer
upper(in) β Upper limit for the primes, should be larger than thelowerlimit - integer
step(in) β Step by which the primes should differ, defaults to2
π BUGS, IDEAS, FEEDBACK π
okay so real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. like, for sure. no cap. π 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 the package and/or the documentation. we want the ideas, we're listening. π«Ά
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
and note further: 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. do it that way bestie, trust. π
π KEYWORDS π
number theory, prime
π CATEGORY π
Mathematics
π COPYRIGHT π
Copyright (c) 2010 Lars HellstrΓΆm <Lars dot Hellstrom at residenset dot net>
and that's the whole page, bestie!! β¨ you understood all of it, I know you did, you're so smart and the primes are literally quaking. πΈπ¦π
this was tcllib version 1.1.4, page math::numtheory(n) β k bye love u, go factor something. π
π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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