math::numtheory(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

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, primesLowerThan and primeFactors show 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 least 4. the default for repetitions is 4.
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 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. she got a glow-up. ✨

  • 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. (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 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 pair differing by the given step. twin primes found, slay. πŸ‘―

  • 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 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 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 πŸ›

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 (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