Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding easy examples #59

Merged
merged 3 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

<!--next-version-placeholder-->

## v0.1.0 (09/01/2025)
## v0.1.0

- First release of `num_theory`!
- First release of `num_theory`!
- Established the package structure.
- Added function placeholders with corresponding docstrings.

## v1.0.0

- Implemented all functions within the package.
- Added comprehensive tests for all package functionalities.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ This package complements existing Python libraries by offering a targeted collec

Related Packages:

• SymPy: This does provide some symbolic mathematics, including some number theory, but isn't optimized for the computational challenges of advanced number theory.

• NumPy: The general-purpose library for numerical computations, but not specialized in number theory.

• primesieve: A highly efficient library for prime generation. This package provides similar functionalities.
- SymPy: This does provide some symbolic mathematics, including some number theory, but isn't optimized for the computational challenges of advanced number theory.
- NumPy: The general-purpose library for numerical computations, but not specialized in number theory.
- primesieve: A highly efficient library for prime generation. This package provides similar functionalities.

## Comparison with Other Libraries

Expand Down
83 changes: 55 additions & 28 deletions docs/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
Expand All @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -107,7 +107,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -144,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -189,7 +189,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -270,7 +270,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -300,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -329,7 +329,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -415,7 +415,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -456,7 +456,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -529,59 +529,86 @@
"```\n",
"\n",
"---\n",
"### Application 1: Prime Pattern Finder\n",
"### Application 1: Cryptography & Security PIN Validation\n",
"\n",
"By filtering prime numbers that satisfy the pattern $p = 6k \\pm 1$, this demonstrates how mathematical properties can be utilized to further refine prime numbers."
"In cryptography, prime numbers are widely used for secure encryption. A system might validate that a chosen PIN is prime before accepting it as secure.\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Special primes (6k ± 1) between 2 and 200: [5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]\n"
"PIN 53 is accepted as it's a prime number—secure and unique!\n"
]
}
],
"source": [
"from num_theory.is_prime import is_prime\n",
"pin = 53\n",
"if is_prime(pin):\n",
" print(f\"PIN {pin} is accepted as it's a prime number—secure and unique!\")\n",
"else:\n",
" print(f\"PIN {pin} is rejected. Please choose a prime number.\")\n",
"# Output: PIN 53 is accepted as it's a prime number—secure and unique!\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Application 2: Unique Classroom Groups\n",
"\n",
"# Find primes matching the pattern\n",
"def find_special_primes(start, end):\n",
" primes = [n for n in range(start, end + 1) if is_prime(n)]\n",
" special_primes = [p for p in primes if (p - 1) % 6 == 0 or (p + 1) % 6 == 0]\n",
" return special_primes\n",
"\n",
"# Find special primes in the range\n",
"special_primes = find_special_primes(2, 200)\n",
"print(f\"Special primes (6k ± 1) between 2 and 200: {special_primes}\")"
"A teacher wants to divide students into groups of a size that is prime, ensuring groups are small and effective."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Group size 7 works! It's prime, so students will interact uniquely.\n"
]
}
],
"source": [
"group_size = 7\n",
"if is_prime(group_size):\n",
" print(f\"Group size {group_size} works! It's prime, so students will interact uniquely.\")\n",
"else:\n",
" print(f\"Group size {group_size} isn't prime. Let's try a different size.\")\n",
"# Output: Group size 7 works! It's prime, so students will interact uniquely."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Application 2: Generate RSA Keys\n",
"### Application 3: Generate RSA Keys\n",
"\n",
"In encryption applications, generating an RSA key pair (public and private keys) requires two large prime numbers and modulus calculations. This code uses `is_prime` to verify the generated prime numbers and constructs the RSA public and private keys, showcasing a practical application in a real-world encryption system."
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"RSA Keys:\n",
"Public Key: (52931, 126169)\n",
"Private Key: (44011, 126169)\n"
"Public Key: (14315, 62429)\n",
"Private Key: (40511, 62429)\n"
]
}
],
Expand Down Expand Up @@ -653,7 +680,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "524",
"display_name": "test_env",
"language": "python",
"name": "python3"
},
Expand Down
Loading