### Mathematical Libraries
Project description
Daddy's boring math library
Python package of modules of a mathematical nature. The project name was suggested by my then 13 year old daughter Mary.
- Repositories
- grscheller.boring-math project on PyPI
- Source code on GitHub
- Detailed documentation
- Detailed API documentation on GH-Pages
Overview
Here are the modules and executables which make up the grscheller.boring-math PyPI project.
Library Modules
Integer Math Module
- Number Theory
- Function gcd(int, int) -> int
- greatest common divisor of two integers
- always returns a non-negative number greater than 0
- Function lcm(int, int) -> int
- least common multiple of two integers
- always returns a non-negative number greater than 0
- Function coprime(int, int) -> tuple(int, int)
- make 2 integers coprime by dividing out gcd
- preserves signs of original numbers
- Function iSqrt(int) -> int
- integer square root
- same as math.isqrt
- Function isSqr(int) -> bool
- returns true if integer argument is a perfect square
- Function primes(start: int, end: int) -> Iterator[int]
- now using Wilson's Theorem
- Function legendre_symbol(a: int, p: int) -> int
- where
p > 2
is a prime number
- where
- Function jacobi_symbol(a: int, n: int) -> int
- where
n > 0
- where
- Function gcd(int, int) -> int
- Combinatorics
- Function comb(n: int, m: int) -> int
- returns number of combinations of n items taken m at a time
- pure integer implementation of math.comb
- Function comb(n: int, m: int) -> int
Pythagorean Triple Module
- Pythagorean Triple Class
- Method Pythag3.triples(a_start: int, a_max: int, max: Optional[int]) -> Iterator[int]
- Returns an iterator of tuples of primitive Pythagorean triples
- A Pythagorean triple is a tuple in positive integers (a, b, c)
- such that
a² + b² = c²
a, b, c
represent integer sides of a right triangle- a Pythagorean triple is primitive if gcd of
a, b, c
is1
- such that
- Iterator finds all primitive Pythagorean Triples
- where
0 < a_start <= a < b < c <= max
wherea <= a_max
- if
max = 0
find all theoretically possible triples witha <= a_max
- where
- Method Pythag3.triples(a_start: int, a_max: int, max: Optional[int]) -> Iterator[int]
Recursive Function Module
Ackermann's Function
- Function ackermann_list(m: int, n: int) -> int
- an example of a total computable function that is not primitive recursive
- becomes numerically intractable after
m=4
- see CLI section below for mathematical definition
Fibonacci Sequences
-
Function fibonacci(f0: int=0, f1: int=1) -> Iterator[int]
- returns a Fibonacci sequence iterator where
f(0) = f0
andf(1) = f1
f(n) = f(n-1) + f(n-2)
- yield defaults to
0, 1, 1, 2, 3, 5, 8, 13, 21, ...
- returns a Fibonacci sequence iterator where
-
Function rev_fibonacci(f0: int=0, f1: int=1) -> Iterator[int]
- returns a Reverse Fibonacci sequence iterator where
rf(0) = f0
andrf(1) = f1
rf(n) = rf(n-1) - rf(n-2)
rf(0) = fib(-1) = 1
rf(1) = fib(-2) = -1
rf(2) = fib(-3) = 2
rf(3) = fib(-4) = -3
rf(4) = fib(-5) = 5
- yield defaults to
1, -1, 2, -3, 5, -8, 13, -21, ...
- returns a Reverse Fibonacci sequence iterator where
CLI Applications
Implemented in an OS and package build tool independent way via the project.scripts section of pyproject.toml.
Ackermann's function CLI scripts
Ackermann, a student of Hilbert, discovered early examples of totally computable functions that are not primitively recursive.
A fairly standard definition of the Ackermann function is
recursively defined for m,n >= 0
by
ackermann(0,n) = n+1
ackermann(m,0) = ackermann(m-1,1)
ackermann(m,n) = ackermann(m-1, ackermann(m, n-1))
CLI program ackermann_list
- Given two non-negative integers, evaluates Ackermann's function
- Implements the recursion via a Python array
- Usage:
ackerman_list m n
Pythagorean triple CLI script
Geometrically, a Pythagorean triangle is a right triangle with positive integer sides.
CLI program pythag3
- Generates primitive Pythagorean triples
- A primitive Pythagorean triple is a 3-tuple of integers
(a, b, c)
such thata³ + b³ = c³
wherea,b,c > 0
andgcd(a,b,c) = 1
- The integers
a, b, c
represent the sides of a right triangle
- A primitive Pythagorean triple is a 3-tuple of integers
- Usage:
pythag3 [m [n [max]]
- 3 args print all triples with
m <= a <= n
anda < b < c <= max
- 2 args print all triples with
m <= a <= n
- 1 arg prints all triples with
a <= m
- 0 args print all triples with
3 <= a <= 100
- 3 args print all triples with
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file grscheller_boring_math-0.4.6.tar.gz
.
File metadata
- Download URL: grscheller_boring_math-0.4.6.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 417b7a2001b163447fc119b874a68c1dffc0ef617a90c78348278e5c85273d13 |
|
MD5 | 5ae6636eaf915de9a7db4528fe95b622 |
|
BLAKE2b-256 | 87310fce8ca68ed1619b36b03c2e1f28ed2af6046af5ac2eb63c878f7247d6fd |
File details
Details for the file grscheller_boring_math-0.4.6-py3-none-any.whl
.
File metadata
- Download URL: grscheller_boring_math-0.4.6-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcbac6121d589bece54e085d3fc24437b349b0c36b185f1ddabfa7c35ab5725c |
|
MD5 | 8ea91edfb65c22d117235eeeeba2c43b |
|
BLAKE2b-256 | fdfcf1047f600b4db7c03f4c56281bfac6e0acb08c7b2f76dd685d9d202e025d |